From 227683b0116dce54502b081b8932781a20fe437a Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Fri, 15 Mar 2019 00:56:41 +0100 Subject: More precise program and memory tableviews column width calculation. This should resolve text elide problem experienced on some combination of desktop/fonts setting. Signed-off-by: Pavel Pisa --- qtmips_gui/programtableview.cpp | 42 +++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) (limited to 'qtmips_gui/programtableview.cpp') diff --git a/qtmips_gui/programtableview.cpp b/qtmips_gui/programtableview.cpp index a684692..b6259dc 100644 --- a/qtmips_gui/programtableview.cpp +++ b/qtmips_gui/programtableview.cpp @@ -41,8 +41,10 @@ #include #include "programtableview.h" #include "programmodel.h" +#include "hinttabledelegate.h" ProgramTableView::ProgramTableView(QWidget *parent, QSettings *settings) : Super(parent) { + setItemDelegate(new HintTableDelegate); connect(verticalScrollBar() , SIGNAL(valueChanged(int)), this, SLOT(adjust_scroll_pos_check())); connect(this , SIGNAL(adjust_scroll_pos_queue()), @@ -57,28 +59,44 @@ void ProgramTableView::addr0_save_change(std::uint32_t val) { } void ProgramTableView::adjustColumnCount() { - int cwidth; + QModelIndex idx; + int cwidth_dh; int totwidth; + ProgramModel *m = dynamic_cast(model()); if (m == nullptr) return; - QFontMetrics fm(*m->getFont()); - cwidth = fm.width("Bp"); - totwidth = cwidth; + HintTableDelegate *delegate = dynamic_cast(itemDelegate()); + if (delegate == nullptr) + return; + + idx = m->index(0, 0); + cwidth_dh = delegate->sizeHintForText(viewOptions(), idx, + "Bp").width() + 2; horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed); - horizontalHeader()->resizeSection(0, cwidth); - cwidth = fm.width("0x00000000"); - totwidth += cwidth; + horizontalHeader()->resizeSection(0, cwidth_dh); + totwidth = cwidth_dh; + + idx = m->index(0, 1); + cwidth_dh = delegate->sizeHintForText(viewOptions(), idx, + "0x00000000").width() + 2; horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed); - horizontalHeader()->resizeSection(1, cwidth); - totwidth += cwidth; - cwidth = fm.width("00000000"); + horizontalHeader()->resizeSection(1, cwidth_dh); + totwidth += cwidth_dh; + + idx = m->index(0, 2); + cwidth_dh = delegate->sizeHintForText(viewOptions(), idx, + "00000000").width() + 2; horizontalHeader()->setSectionResizeMode(2, QHeaderView::Fixed); - horizontalHeader()->resizeSection(2, cwidth); + horizontalHeader()->resizeSection(2, cwidth_dh); + totwidth += cwidth_dh; + horizontalHeader()->setSectionResizeMode(3, QHeaderView::Stretch); - totwidth += fm.width("BEQ $18, $17, 0x80020058"); + idx = m->index(0, 3); + totwidth += delegate->sizeHintForText(viewOptions(), idx, + "BEQ $18, $17, 0x80020058").width() + 2; totwidth += verticalHeader()->width(); setColumnHidden(2, totwidth > width()); -- cgit v1.2.3