From 537a27d09805d2acd1657d865b1c63180fa859f1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 14 Dec 2019 11:15:33 +0530 Subject: [PATCH] macOS; Use transient scrollbars unless they are disabled in system preferences --- src/calibre/gui2/__init__.py | 8 +++++++- .../gui2/progress_indicator/QProgressIndicator.cpp | 9 ++++++--- src/calibre/gui2/progress_indicator/QProgressIndicator.h | 2 +- .../gui2/progress_indicator/QProgressIndicator.sip | 4 ++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 8b39593939..38dd4f707a 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -1104,7 +1104,13 @@ class Application(QApplication): pcache[v] = p v = pcache[v] icon_map[getattr(QStyle, 'SP_'+k)] = v - self.pi.load_style(icon_map) + transient_scroller = 0 + if isosx: + transient_scroller = plugins['cocoa'][0].transient_scroller() + try: + self.pi.load_style(icon_map, transient_scroller) + except TypeError: + self.pi.load_style(icon_map) def _send_file_open_events(self): with self._file_open_lock: diff --git a/src/calibre/gui2/progress_indicator/QProgressIndicator.cpp b/src/calibre/gui2/progress_indicator/QProgressIndicator.cpp index 05cec87e57..7f5e6c5e7c 100644 --- a/src/calibre/gui2/progress_indicator/QProgressIndicator.cpp +++ b/src/calibre/gui2/progress_indicator/QProgressIndicator.cpp @@ -138,9 +138,10 @@ class CalibreStyle: public QProxyStyle { QHash icon_map; QByteArray desktop_environment; QDialogButtonBox::ButtonLayout button_layout; + int transient_scroller; public: - CalibreStyle(QStyle *base, QHash icmap) : QProxyStyle(base), icon_map(icmap) { + CalibreStyle(QStyle *base, QHash icmap, int transient_scroller) : QProxyStyle(base), icon_map(icmap), transient_scroller(transient_scroller) { setObjectName(QString("calibre")); desktop_environment = detectDesktopEnvironment(); button_layout = static_cast(QProxyStyle::styleHint(SH_DialogButtonLayout)); @@ -163,6 +164,8 @@ class CalibreStyle: public QProxyStyle { return button_layout; case SH_FormLayoutFieldGrowthPolicy: return QFormLayout::FieldsStayAtSizeHint; // Do not have fields expand to fill all available space in QFormLayout + case SH_ScrollBar_Transient: + return transient_scroller; default: break; } @@ -320,9 +323,9 @@ class CalibreStyle: public QProxyStyle { } }; -int load_style(QHash icon_map) { +int load_style(QHash icon_map, int transient_scroller) { QStyle *base_style = QStyleFactory::create(QString("Fusion")); - QApplication::setStyle(new CalibreStyle(base_style, icon_map)); + QApplication::setStyle(new CalibreStyle(base_style, icon_map, transient_scroller)); return 0; } diff --git a/src/calibre/gui2/progress_indicator/QProgressIndicator.h b/src/calibre/gui2/progress_indicator/QProgressIndicator.h index 657ec154e3..7e50086e92 100644 --- a/src/calibre/gui2/progress_indicator/QProgressIndicator.h +++ b/src/calibre/gui2/progress_indicator/QProgressIndicator.h @@ -77,6 +77,6 @@ private: QColor m_dark, m_light; }; -int load_style(QHash icon_map); +int load_style(QHash icon_map, int transient_scroller=0); void set_no_activate_on_click(QWidget *widget); void draw_snake_spinner(QPainter &painter, QRect rect, int angle, const QColor & light, const QColor & dark); diff --git a/src/calibre/gui2/progress_indicator/QProgressIndicator.sip b/src/calibre/gui2/progress_indicator/QProgressIndicator.sip index 7d2f1bd9d3..559f2b19d1 100644 --- a/src/calibre/gui2/progress_indicator/QProgressIndicator.sip +++ b/src/calibre/gui2/progress_indicator/QProgressIndicator.sip @@ -7,7 +7,7 @@ %ModuleHeaderCode #include -int load_style(QHash icon_map); +int load_style(QHash icon_map, int transient_scroller); void set_no_activate_on_click(QWidget *widget); void draw_snake_spinner(QPainter &painter, QRect rect, int angle, const QColor & light, const QColor & dark); %End @@ -55,6 +55,6 @@ protected: }; -int load_style(QHash icon_map); +int load_style(QHash icon_map, int transient_scroller); void set_no_activate_on_click(QWidget *widget); void draw_snake_spinner(QPainter &painter, QRect rect, int angle, const QColor & light, const QColor & dark);