From 1180b5d2d37119b39f2dccdfdd2e58955d3ee160 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Fri, 17 Oct 2014 21:22:49 +0200 Subject: Fix plus icon position based on the theme I hope this time I got it right. basically, the old code tried to guess where the plus icon should be with a fairly bad set of defauults. This one patch asks for the Qt style where everything is and uses that knowledge to make it be in a more sane position. Signed-off-by: Tomaz Canabrava Signed-off-by: Giuseppe Bilotta Signed-off-by: Dirk Hohndel --- qt-ui/tableview.cpp | 25 +++++++++++-------------- qt-ui/tableview.h | 3 +-- qt-ui/tableview.ui | 46 +++++++++++----------------------------------- 3 files changed, 23 insertions(+), 51 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/tableview.cpp b/qt-ui/tableview.cpp index a05b1744c..242141c26 100644 --- a/qt-ui/tableview.cpp +++ b/qt-ui/tableview.cpp @@ -7,8 +7,9 @@ #include #include #include +#include -TableView::TableView(QWidget *parent) : QWidget(parent) +TableView::TableView(QWidget *parent) : QGroupBox(parent) { ui.setupUi(this); ui.tableView->setItemDelegate(new DiveListDelegate(this)); @@ -25,15 +26,15 @@ TableView::TableView(QWidget *parent) : QWidget(parent) /* There`s mostly a need for a Mac fix here too. */ if (qApp->style()->objectName() == "gtk+") - ui.groupBox->layout()->setContentsMargins(0, 9, 0, 0); + layout()->setContentsMargins(0, 9, 0, 0); else - ui.groupBox->layout()->setContentsMargins(0, 0, 0, 0); - + layout()->setContentsMargins(0, 0, 0, 0); QIcon plusIcon(":plus"); - plusBtn = new QPushButton(plusIcon, QString(), ui.groupBox); + plusBtn = new QPushButton(plusIcon, QString(), this); plusBtn->setFlat(true); plusBtn->setToolTip(tr("Add cylinder")); plusBtn->setIconSize(QSize(metrics.icon->sz_small, metrics.icon->sz_small)); + plusBtn->resize(metrics.icon->sz_med, metrics.icon->sz_med); connect(plusBtn, SIGNAL(clicked(bool)), this, SIGNAL(addButtonClicked())); } @@ -65,11 +66,6 @@ void TableView::setBtnToolTip(const QString &tooltip) plusBtn->setToolTip(tooltip); } -void TableView::setTitle(const QString &title) -{ - ui.groupBox->setTitle(title); -} - void TableView::setModel(QAbstractItemModel *model) { ui.tableView->setModel(model); @@ -89,10 +85,11 @@ void TableView::setModel(QAbstractItemModel *model) void TableView::fixPlusPosition() { - int x = ui.groupBox->contentsRect().width() - 2*metrics.icon->sz_small + metrics.icon->spacing; - int y = metrics.icon->spacing; - int sz = metrics.icon->sz_med; - plusBtn->setGeometry(x, y, sz, sz); + QStyleOptionGroupBox option; + initStyleOption(&option); + QRect labelRect = style()->subControlRect(QStyle::CC_GroupBox, &option, QStyle::SC_GroupBoxLabel, this); + QRect contentsRect = style()->subControlRect(QStyle::CC_GroupBox, &option, QStyle::QStyle::SC_GroupBoxFrame, this); + plusBtn->setGeometry( contentsRect.width() - plusBtn->width(), labelRect.y(), plusBtn->width(), labelRect.height()); } // We need to manually position the 'plus' on cylinder and weight. diff --git a/qt-ui/tableview.h b/qt-ui/tableview.h index 93134b206..36eef907a 100644 --- a/qt-ui/tableview.h +++ b/qt-ui/tableview.h @@ -16,7 +16,7 @@ class QAbstractItemModel; class QModelIndex; class QTableView; -class TableView : public QWidget { +class TableView : public QGroupBox { Q_OBJECT struct TableMetrics { @@ -28,7 +28,6 @@ class TableView : public QWidget { public: TableView(QWidget *parent = 0); virtual ~TableView(); - void setTitle(const QString &title); /* The model is expected to have a 'remove' slot, that takes a QModelIndex as parameter. * It's also expected to have the column '1' as a trash icon. I most probably should create a * proxy model and add that column, will mark that as TODO. see? marked. diff --git a/qt-ui/tableview.ui b/qt-ui/tableview.ui index baa86fdd7..73867231e 100644 --- a/qt-ui/tableview.ui +++ b/qt-ui/tableview.ui @@ -1,48 +1,24 @@ TableView - + 0 0 - 410 - 309 + 400 + 300 - - - 0 - - - 0 - + + GroupBox + + + GroupBox + + - - - - - - - 0 - - - 0 - - - 10 - - - 0 - - - 0 - - - - - - + -- cgit v1.2.3-70-g09d2