From 5ec3f5d1277bfc9686ded94b3df5b4effeb49cd6 2017-11-15 16:20:12 From: Thibaud Rabillard Date: 2017-11-15 16:20:12 Subject: [PATCH] New style on mac to keep the scrollbars visible --- diff --git a/gui/include/Visualization/MacScrollBarStyle.h b/gui/include/Visualization/MacScrollBarStyle.h new file mode 100644 index 0000000..9ddebc3 --- /dev/null +++ b/gui/include/Visualization/MacScrollBarStyle.h @@ -0,0 +1,18 @@ +#ifndef SCIQLOP_MACSCROLLBARSTYLE_H +#define SCIQLOP_MACSCROLLBARSTYLE_H + +#include + +/** + * @brief Special style to always display the scrollbars on MAC. + */ +class MacScrollBarStyle : public QProxyStyle { + +public: + int styleHint(StyleHint hint, const QStyleOption *option, const QWidget *widget, + QStyleHintReturn *returnData) const; + + void selfInstallOn(QWidget *widget, bool installOnSubWidgets); +}; + +#endif // SCIQLOP_MACSCROLLBARSTYLE_H diff --git a/gui/meson.build b/gui/meson.build index 85fdd4e..a3bf57f 100644 --- a/gui/meson.build +++ b/gui/meson.build @@ -78,7 +78,8 @@ gui_sources = [ 'src/Visualization/VisualizationDragDropContainer.cpp', 'src/Visualization/VisualizationDragWidget.cpp', 'src/Visualization/AxisRenderingUtils.cpp', - 'src/Visualization/PlottablesRenderingUtils.cpp' + 'src/Visualization/PlottablesRenderingUtils.cpp', + 'src/Visualization/MacScrollBarStyle.cpp' ] gui_inc = include_directories(['include']) diff --git a/gui/src/Visualization/MacScrollBarStyle.cpp b/gui/src/Visualization/MacScrollBarStyle.cpp new file mode 100644 index 0000000..57686a1 --- /dev/null +++ b/gui/src/Visualization/MacScrollBarStyle.cpp @@ -0,0 +1,40 @@ +#include "Visualization/MacScrollBarStyle.h" + +#include + +int MacScrollBarStyle::styleHint(QStyle::StyleHint hint, const QStyleOption *option, + const QWidget *widget, QStyleHintReturn *returnData) const +{ + switch (hint) { + case SH_ScrollBar_Transient: + return false; // Makes the scrollbar always visible + case SH_ScrollView_FrameOnlyAroundContents: + return true; // Avoid that the scrollbar is drawn on top of the widget + default: + break; + } + + return QProxyStyle::styleHint(hint, option, widget, returnData); +} + +void MacScrollBarStyle::selfInstallOn(QWidget *widget, bool installOnSubWidgets) +{ + // Note: a style can be installed on a particular widget but it is not automatically applied its + // children widgets. + + QList widgetsToStyle{widget}; + while (!widgetsToStyle.isEmpty()) { + + auto widget = widgetsToStyle.takeFirst(); + widget->setStyle(this); + + if (installOnSubWidgets) { + for (auto child : widget->children()) { + auto childWidget = qobject_cast(child); + if (childWidget) { + widgetsToStyle << childWidget; + } + } + } + } +} diff --git a/gui/src/Visualization/VisualizationTabWidget.cpp b/gui/src/Visualization/VisualizationTabWidget.cpp index b706f40..136412e 100644 --- a/gui/src/Visualization/VisualizationTabWidget.cpp +++ b/gui/src/Visualization/VisualizationTabWidget.cpp @@ -5,6 +5,8 @@ #include "Visualization/VisualizationGraphWidget.h" #include "Visualization/VisualizationZoneWidget.h" +#include "Visualization/MacScrollBarStyle.h" + #include "Variable/VariableController.h" #include "Common/MimeTypesDef.h" @@ -55,6 +57,10 @@ struct VisualizationTabWidget::VisualizationTabWidgetPrivate { QString m_Name; +#ifdef Q_OS_MAC + std::unique_ptr m_MacScrollBarStyle = std::make_unique(); +#endif + void dropGraph(int index, VisualizationTabWidget *tabWidget); void dropZone(int index, VisualizationTabWidget *tabWidget); void dropVariables(const QList > &variables, int index, @@ -68,6 +74,10 @@ VisualizationTabWidget::VisualizationTabWidget(const QString &name, QWidget *par { ui->setupUi(this); +#ifdef Q_OS_MAC + impl->m_MacScrollBarStyle->selfInstallOn(ui->scrollArea, true); +#endif + ui->dragDropContainer->setPlaceHolderType(DragDropHelper::PlaceHolderType::Zone, "Zone"); ui->dragDropContainer->layout()->setContentsMargins(0, 0, 0, 5); ui->dragDropContainer->addAcceptedMimeType(