aboutsummaryrefslogtreecommitdiff
path: root/qtmips_gui/programtableview.cpp
diff options
context:
space:
mode:
authorPavel Pisa <pisa@cmp.felk.cvut.cz>2019-03-15 00:56:41 +0100
committerPavel Pisa <pisa@cmp.felk.cvut.cz>2019-03-15 00:56:41 +0100
commit227683b0116dce54502b081b8932781a20fe437a (patch)
tree5d57bca95867f822af675d9557675e0abcc3145c /qtmips_gui/programtableview.cpp
parent36747de2c73d3c11e30abd7b371cc5a5cf91a331 (diff)
downloadqtmips-227683b0116dce54502b081b8932781a20fe437a.tar.gz
qtmips-227683b0116dce54502b081b8932781a20fe437a.tar.bz2
qtmips-227683b0116dce54502b081b8932781a20fe437a.zip
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 <pisa@cmp.felk.cvut.cz>
Diffstat (limited to 'qtmips_gui/programtableview.cpp')
-rw-r--r--qtmips_gui/programtableview.cpp42
1 files changed, 30 insertions, 12 deletions
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 <QApplication>
#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<ProgramModel*>(model());
if (m == nullptr)
return;
- QFontMetrics fm(*m->getFont());
- cwidth = fm.width("Bp");
- totwidth = cwidth;
+ HintTableDelegate *delegate = dynamic_cast<HintTableDelegate*>(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());