aboutsummaryrefslogtreecommitdiffstats
path: root/qt-ui
diff options
context:
space:
mode:
authorGravatar Giuseppe Bilotta <giuseppe.bilotta@gmail.com>2014-10-19 16:15:21 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-10-19 07:24:08 -0700
commit58ac3b8f86549ca9f373b3ef2a54fe2d71667719 (patch)
treebf1c0f2f14d6c0d16aeedf6e462a6b91956086f3 /qt-ui
parentdfec501e7a1cd26dc2ff4d675a3c8d91ac86aaa5 (diff)
downloadsubsurface-58ac3b8f86549ca9f373b3ef2a54fe2d71667719.tar.gz
Fix tableview margins
The previous hard-coded solution for GTK+ didn't work on HiDPI, and a comment hinted that even on Mac OS X it might need tuning. Find a more generic solution that should work regardless of platform and style, based purely on the geometries reported by the style itself. Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r--qt-ui/tableview.cpp30
1 files changed, 25 insertions, 5 deletions
diff --git a/qt-ui/tableview.cpp b/qt-ui/tableview.cpp
index 423fcc766..8232fb604 100644
--- a/qt-ui/tableview.cpp
+++ b/qt-ui/tableview.cpp
@@ -24,11 +24,31 @@ TableView::TableView(QWidget *parent) : QGroupBox(parent)
metrics.rm_col_width = metrics.icon->sz_small + 2*metrics.icon->spacing;
metrics.header_ht = text_ht + 10; // TODO DPI
- /* There`s mostly a need for a Mac fix here too. */
- if (qApp->style()->objectName() == "gtk+")
- layout()->setContentsMargins(0, 9, 0, 0);
- else
- layout()->setContentsMargins(0, 0, 0, 0);
+ /* We want to get rid of the margin around the table, but
+ * we must be careful with some styles (e.g. GTK+) where the top
+ * margin is actually used to hold the label. We thus check the
+ * rectangles for the label and contents to make sure they do not
+ * overlap, and adjust the top contentsMargin accordingly
+ */
+
+ // start by setting all the margins at zero
+ QMargins margins;
+
+ // grab the label and contents dimensions and positions
+ 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::SC_GroupBoxContents, this);
+
+ /* we need to ensure that the bottom of the label is higher
+ * than the top of the contents */
+ int delta = contentsRect.top() - labelRect.bottom();
+ const int min_gap = metrics.icon->spacing;
+ if (delta <= min_gap) {
+ margins.setTop(min_gap - delta);
+ }
+ layout()->setContentsMargins(margins);
+
QIcon plusIcon(":plus");
plusBtn = new QPushButton(plusIcon, QString(), this);
plusBtn->setFlat(true);