From f9b4c6b889e2444533af1baabdee3687020c1e7b Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Sun, 16 Jun 2013 12:33:27 -0300 Subject: Better handling of default sizes on the Cylinder and Weight widgets Better handling of default sizes on the Cylinder and weight widgets, the weigth widget didn't had a CSS applied so it looked odd compared to the cylinder one, also the default behavior for the combobox delegate didn't worked very well with the css applied, being too small. this patch fixes that. Signed-off-by: Tomaz Canabrava --- qt-ui/maintab.cpp | 5 ++++- qt-ui/maintab.ui | 36 ++++++++++++++++++++++++++++++++++-- qt-ui/modeldelegates.cpp | 11 +++++++++++ qt-ui/modeldelegates.h | 1 + qt-ui/models.cpp | 6 +++++- qt-ui/models.h | 2 ++ 6 files changed, 57 insertions(+), 4 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index ea1687a33..6f63b3574 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -79,12 +79,15 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), connect(ui->cylinders, SIGNAL(clicked(QModelIndex)), ui->cylinders->model(), SLOT(remove(QModelIndex))); connect(ui->weights, SIGNAL(clicked(QModelIndex)), ui->weights->model(), SLOT(remove(QModelIndex))); + QFontMetrics metrics(defaultModelFont()); + ui->cylinders->setColumnWidth(CylindersModel::REMOVE, 24); - ui->cylinders->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); ui->cylinders->horizontalHeader()->setResizeMode(CylindersModel::REMOVE, QHeaderView::Fixed); + ui->cylinders->verticalHeader()->setDefaultSectionSize( metrics.height() +8 ); ui->cylinders->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate()); ui->weights->setColumnWidth(WeightModel::REMOVE, 24); ui->weights->horizontalHeader()->setResizeMode (WeightModel::REMOVE , QHeaderView::Fixed); + ui->weights->verticalHeader()->setDefaultSectionSize( metrics.height() +8 ); ui->weights->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate()); } diff --git a/qt-ui/maintab.ui b/qt-ui/maintab.ui index 733a605ea..d792edce0 100644 --- a/qt-ui/maintab.ui +++ b/qt-ui/maintab.ui @@ -14,7 +14,7 @@ TabWidget - 0 + 1 @@ -202,7 +202,39 @@ - + + + QTableView { + show-decoration-selected: 1; + } + + QTableView::item { + border: 1px solid #d9d9d9; + border-top-color: transparent; + border-bottom-color: transparent; + padding: 2px; + } + + QTableView::item:hover { + background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #e7effd, stop: 1 #cbdaf1); + border: 1px solid #bfcde4; + } + + QTableView::item:selected { + border: 1px solid #567dbc; + } + + QTableView::item:selected:active{ + background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6ea1f1, stop: 1 #567dbc); + } + + QTableView::item:selected:!active { + background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #6b9be8, stop: 1 #577fbf); + } + + + + diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp index d201337b4..01f5197ce 100644 --- a/qt-ui/modeldelegates.cpp +++ b/qt-ui/modeldelegates.cpp @@ -76,6 +76,17 @@ QWidget* ComboBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewI return comboDelegate; } +void ComboBoxDelegate::updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + QRect defaultRect = option.rect; + defaultRect.setX( defaultRect.x() -1); + defaultRect.setY( defaultRect.y() -1); + defaultRect.setWidth( defaultRect.width() + 2); + defaultRect.setHeight( defaultRect.height() + 2); + editor->setGeometry(defaultRect); +} + + void TankInfoDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& thisindex) const { QComboBox *c = qobject_cast(editor); diff --git a/qt-ui/modeldelegates.h b/qt-ui/modeldelegates.h index 00436d874..a33fc891b 100644 --- a/qt-ui/modeldelegates.h +++ b/qt-ui/modeldelegates.h @@ -19,6 +19,7 @@ public: explicit ComboBoxDelegate(QAbstractItemModel *model, QObject* parent = 0); virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const; virtual void setEditorData(QWidget* editor, const QModelIndex& index) const; + virtual void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const; protected: QAbstractItemModel *model; }; diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 21c89ee15..dd8bac078 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -68,7 +68,7 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const ret = defaultModelFont(); break; case Qt::TextAlignmentRole: - ret = Qt::AlignRight; + ret = Qt::AlignHCenter; break; case Qt::DisplayRole: case Qt::EditRole: @@ -656,6 +656,10 @@ QVariant TankInfoModel::data(const QModelIndex& index, int role) const if (!index.isValid()) { return ret; } + if (role == Qt::FontRole){ + return defaultModelFont(); + } + struct tank_info *info = &tank_info[index.row()]; int ml = info->ml; diff --git a/qt-ui/models.h b/qt-ui/models.h index a012ec6bd..09a2c6a68 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -14,6 +14,8 @@ #include "../dive.h" #include "../divelist.h" +QFont defaultModelFont(); + /* Encapsulates the tank_info global variable * to show on Qt's Model View System.*/ class TankInfoModel : public QAbstractTableModel { -- cgit v1.2.3-70-g09d2