From 81e27b6db9aba39dd80d7c9ec5ae6e01d5966075 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 25 May 2013 20:04:31 -0700 Subject: [PATCH] Try to make the equipment tab more compact My attempts to actually set the width of the columns with the SizeHintRole all failed - so I gave up on that and am forcing things to work by making the texts in the header somewhat longer and then resizing to that. Definitely not what I wanted to do - but that plus reducing the font size gives us a much more reasonable / compact look. I really hope that someone else can explain to me how to get the SizeHintRole to affect the width (and not just the height - that part worked just fine) of a the cells in a column. Then we can replace this hack by a much better solution (that won't fail if the translated strings look different). Signed-off-by: Dirk Hohndel --- qt-ui/maintab.cpp | 3 ++- qt-ui/models.cpp | 60 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 4710c048a..ca2f18ef0 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -80,7 +80,8 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), connect(ui->weights, SIGNAL(clicked(QModelIndex)), ui->weights->model(), SLOT(remove(QModelIndex))); ui->cylinders->setColumnWidth(CylindersModel::REMOVE, 24); - ui->cylinders->horizontalHeader()->setResizeMode (CylindersModel::REMOVE , QHeaderView::Fixed); + ui->cylinders->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); + ui->cylinders->horizontalHeader()->setResizeMode(CylindersModel::REMOVE, QHeaderView::Fixed); ui->cylinders->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate()); ui->weights->setColumnWidth(WeightModel::REMOVE, 24); ui->weights->horizontalHeader()->setResizeMode (WeightModel::REMOVE , QHeaderView::Fixed); diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 6c6d0b133..38ef8938c 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -21,10 +21,16 @@ CylindersModel::CylindersModel(QObject* parent): QAbstractTableModel(parent), cu QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, int role) const { QVariant ret; + QFont font; + if (orientation == Qt::Vertical) return ret; - if (role == Qt::DisplayRole) { + switch (role) { + case Qt::FontRole: + font.setPointSizeF(font.pointSizeF() * 0.8); + return font; + case Qt::DisplayRole: switch(section) { case TYPE: ret = tr("Type"); @@ -36,16 +42,16 @@ QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, in ret = tr("WorkPress"); break; case START: - ret = tr("Start"); + ret = tr("StartPress"); break; case END: - ret = tr("End"); + ret = tr("EndPress "); break; case O2: - ret = tr("O2%"); + ret = tr("O2% "); break; case HE: - ret = tr("He%"); + ret = tr("He% "); break; } } @@ -60,12 +66,22 @@ int CylindersModel::columnCount(const QModelIndex& parent) const QVariant CylindersModel::data(const QModelIndex& index, int role) const { QVariant ret; + QFont font; + if (!index.isValid() || index.row() >= MAX_CYLINDERS) return ret; cylinder_t *cyl = ¤t->cylinder[index.row()]; - - if (role == Qt::DisplayRole || role==Qt::EditRole) { + switch (role) { + case Qt::FontRole: + font.setPointSizeF(font.pointSizeF() * 0.80); + ret = font; + break; + case Qt::TextAlignmentRole: + ret = Qt::AlignRight; + break; + case Qt::DisplayRole: + case Qt::EditRole: switch(index.column()) { case TYPE: ret = QString(cyl->type.description); @@ -101,11 +117,12 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const ret = QString("%1%").arg((cyl->gasmix.he.permille + 5) / 10); break; } - } else if (role == Qt::DecorationRole) { + break; + case Qt::DecorationRole: if (index.column() == REMOVE) ret = QIcon(":trash"); + break; } - return ret; } @@ -333,12 +350,22 @@ int WeightModel::columnCount(const QModelIndex& parent) const QVariant WeightModel::data(const QModelIndex& index, int role) const { QVariant ret; + QFont font; if (!index.isValid() || index.row() >= MAX_WEIGHTSYSTEMS) return ret; weightsystem_t *ws = ¤t->weightsystem[index.row()]; - if (role == Qt::DisplayRole || role == Qt::EditRole) { + switch (role) { + case Qt::FontRole: + font.setPointSizeF(font.pointSizeF() * 0.80); + ret = font; + break; + case Qt::TextAlignmentRole: + ret = Qt::AlignRight; + break; + case Qt::DisplayRole: + case Qt::EditRole: switch(index.column()) { case TYPE: ret = QString(ws->description); @@ -347,9 +374,11 @@ QVariant WeightModel::data(const QModelIndex& index, int role) const ret = get_weight_string(ws->weight, TRUE); break; } - } else if (role == Qt::DecorationRole) { + break; + case Qt::DecorationRole: if (index.column() == REMOVE) ret = QIcon(":trash"); + break; } return ret; } @@ -414,10 +443,16 @@ int WeightModel::rowCount(const QModelIndex& parent) const QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int role) const { QVariant ret; + QFont font; if (orientation == Qt::Vertical) return ret; - if (role == Qt::DisplayRole) { + switch (role) { + case Qt::FontRole: + font.setPointSizeF(font.pointSizeF() * 0.8); + ret = font; + break; + case Qt::DisplayRole: switch(section) { case TYPE: ret = tr("Type"); @@ -426,6 +461,7 @@ QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int r ret = tr("Weight"); break; } + break; } return ret; }