Mac and high-dpi displays: Add workaround in ActivityItemDelegate to show full uncrop...
authorMichael Schuster <michael@schuster.ms>
Thu, 19 Dec 2019 19:41:48 +0000 (20:41 +0100)
committerMichael Schuster <48932272+misch7@users.noreply.github.com>
Thu, 19 Dec 2019 21:07:30 +0000 (22:07 +0100)
Signed-off-by: Michael Schuster <michael@schuster.ms>
src/gui/activityitemdelegate.cpp

index 54bc0b2143ca9c65e98f4818868e0f8afeec2618..f034fcf09205cf8d488dc58b1b2fd85fe63f84aa 100644 (file)
 #include <QPainter>
 #include <QApplication>
 
+#define FIXME_USE_HIGH_DPI_RATIO
+#ifdef FIXME_USE_HIGH_DPI_RATIO
+    // FIXME: Find a better way to calculate the text width on high-dpi displays (Retina).
+    #include <QDesktopWidget>
+#endif
+
 #define HASQT5_11 (QT_VERSION >= QT_VERSION_CHECK(5,11,0))
 
 namespace OCC {
@@ -97,6 +103,11 @@ void ActivityItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
     int iconOffset = qRound(fm.height() / 4.0 * 7.0);
     int offset = 4;
     const bool isSelected = (option.state & QStyle::State_Selected);
+#ifdef FIXME_USE_HIGH_DPI_RATIO
+    // FIXME: Find a better way to calculate the text width on high-dpi displays (Retina).
+    const int device_pixel_ration = QApplication::desktop()->devicePixelRatio();
+    int pixel_ratio = (device_pixel_ration > 1 ? device_pixel_ration : 1);
+#endif
 
     // get the data
     Activity::Type activityType = qvariant_cast<Activity::Type>(index.data(ActionRole));
@@ -134,6 +145,10 @@ void ActivityItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
     actionTextBox.setTop(option.rect.top() + margin + offset/2);
     actionTextBox.setHeight(fm.height());
     actionTextBox.setLeft(actionIconRect.right() + margin);
+#ifdef FIXME_USE_HIGH_DPI_RATIO
+    // FIXME: Find a better way to calculate the text width on high-dpi displays (Retina).
+    actionTextBoxWidth *= pixel_ratio;
+#endif
     actionTextBox.setRight(actionTextBox.left() + actionTextBoxWidth + margin);
 
     // message text rect
@@ -167,6 +182,10 @@ void ActivityItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
     timeBox.setTop(timeTop);
     timeBox.setHeight(fm.height());
     timeBox.setBottom(timeBox.top() + fm.height());
+#ifdef FIXME_USE_HIGH_DPI_RATIO
+    // FIXME: Find a better way to calculate the text width on high-dpi displays (Retina).
+    timeTextWidth *= pixel_ratio;
+#endif
     timeBox.setRight(timeBox.left() + timeTextWidth + margin);
 
     // buttons - default values