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 <tomaz.canabrava@intel.com>
Signed-off-by: Giuseppe Bilotta <giuseppe.bilota@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-10-17 21:22:49 +02:00 committed by Dirk Hohndel
parent 32ab2b34d3
commit 1180b5d2d3
3 changed files with 23 additions and 51 deletions

View file

@ -7,8 +7,9 @@
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>
#include <QSettings> #include <QSettings>
#include <QStyle>
TableView::TableView(QWidget *parent) : QWidget(parent) TableView::TableView(QWidget *parent) : QGroupBox(parent)
{ {
ui.setupUi(this); ui.setupUi(this);
ui.tableView->setItemDelegate(new DiveListDelegate(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. */ /* There`s mostly a need for a Mac fix here too. */
if (qApp->style()->objectName() == "gtk+") if (qApp->style()->objectName() == "gtk+")
ui.groupBox->layout()->setContentsMargins(0, 9, 0, 0); layout()->setContentsMargins(0, 9, 0, 0);
else else
ui.groupBox->layout()->setContentsMargins(0, 0, 0, 0); layout()->setContentsMargins(0, 0, 0, 0);
QIcon plusIcon(":plus"); QIcon plusIcon(":plus");
plusBtn = new QPushButton(plusIcon, QString(), ui.groupBox); plusBtn = new QPushButton(plusIcon, QString(), this);
plusBtn->setFlat(true); plusBtn->setFlat(true);
plusBtn->setToolTip(tr("Add cylinder")); plusBtn->setToolTip(tr("Add cylinder"));
plusBtn->setIconSize(QSize(metrics.icon->sz_small, metrics.icon->sz_small)); 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())); connect(plusBtn, SIGNAL(clicked(bool)), this, SIGNAL(addButtonClicked()));
} }
@ -65,11 +66,6 @@ void TableView::setBtnToolTip(const QString &tooltip)
plusBtn->setToolTip(tooltip); plusBtn->setToolTip(tooltip);
} }
void TableView::setTitle(const QString &title)
{
ui.groupBox->setTitle(title);
}
void TableView::setModel(QAbstractItemModel *model) void TableView::setModel(QAbstractItemModel *model)
{ {
ui.tableView->setModel(model); ui.tableView->setModel(model);
@ -89,10 +85,11 @@ void TableView::setModel(QAbstractItemModel *model)
void TableView::fixPlusPosition() void TableView::fixPlusPosition()
{ {
int x = ui.groupBox->contentsRect().width() - 2*metrics.icon->sz_small + metrics.icon->spacing; QStyleOptionGroupBox option;
int y = metrics.icon->spacing; initStyleOption(&option);
int sz = metrics.icon->sz_med; QRect labelRect = style()->subControlRect(QStyle::CC_GroupBox, &option, QStyle::SC_GroupBoxLabel, this);
plusBtn->setGeometry(x, y, sz, sz); 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. // We need to manually position the 'plus' on cylinder and weight.

View file

@ -16,7 +16,7 @@ class QAbstractItemModel;
class QModelIndex; class QModelIndex;
class QTableView; class QTableView;
class TableView : public QWidget { class TableView : public QGroupBox {
Q_OBJECT Q_OBJECT
struct TableMetrics { struct TableMetrics {
@ -28,7 +28,6 @@ class TableView : public QWidget {
public: public:
TableView(QWidget *parent = 0); TableView(QWidget *parent = 0);
virtual ~TableView(); virtual ~TableView();
void setTitle(const QString &title);
/* The model is expected to have a 'remove' slot, that takes a QModelIndex as parameter. /* 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 * 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. * proxy model and add that column, will mark that as TODO. see? marked.

View file

@ -1,48 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>TableView</class> <class>TableView</class>
<widget class="QWidget" name="TableView"> <widget class="QGroupBox" name="TableView">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>410</width> <width>400</width>
<height>309</height> <height>300</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <property name="windowTitle">
<property name="spacing"> <string>GroupBox</string>
<number>0</number> </property>
</property> <property name="title">
<property name="margin"> <string>GroupBox</string>
<number>0</number> </property>
</property> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QTableView" name="tableView"/>
<property name="title">
<string/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>10</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTableView" name="tableView"/>
</item>
</layout>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>