diff --git a/sources/projectview.cpp b/sources/projectview.cpp index d9a9330d1..76aeb817f 100644 --- a/sources/projectview.cpp +++ b/sources/projectview.cpp @@ -810,7 +810,11 @@ void ProjectView::initWidgets() { fallback_label_ -> setAlignment(Qt::AlignVCenter | Qt::AlignHCenter); // initialize tabs +#ifdef Q_OS_MACOS + m_tab = new WheelEnabledTabBar(this); +#else m_tab = new QTabWidget(this); +#endif m_tab -> setMovable(true); QToolButton *add_new_diagram_button = new QToolButton; diff --git a/sources/projectview.h b/sources/projectview.h index f1becd5ba..2f0c8d80f 100644 --- a/sources/projectview.h +++ b/sources/projectview.h @@ -19,10 +19,51 @@ #define PROJECT_VIEW_H #include +#include + #include "templatelocation.h" #include "qetresult.h" + +#ifdef Q_OS_MACOS +class WheelEnabledTabBar : public QTabWidget +{ + + // It works on Mac using arrows keys, button arrows and mouse + // Maybe it needs to use only scroll right-left, not up-down + +public: + WheelEnabledTabBar(QWidget *parent = nullptr) +// : QTabBar(parent) + : QTabWidget(parent) + {} + + double temp_index = 0; + + void wheelEvent(QWheelEvent *event) override + { + int index = currentIndex(); + double delta = 0; + double scale_factor = 0.005; // Decrease or increase speed of mouse wheel (0.04 = decrease) + + if ((index != -1) && (event->orientation() == Qt::Horizontal)) { + delta = event->delta() * scale_factor; // Read and scale the scroll value + if (delta > 0 && (temp_index > -1)) temp_index = temp_index - abs(delta); + if (delta < 0 && (temp_index < count())) temp_index = temp_index + abs(delta); + + index = int (temp_index); + qDebug() << "index" << index << "temp_index" << temp_index << " " << event->delta() << delta; + + if (index >= 0 && index < count()) + setCurrentIndex(index); + +// qDebug() << currentIndex(); + } + } +}; +#endif + class QETProject; class DiagramView; class Diagram; @@ -31,6 +72,7 @@ class QTabWidget; class QLabel; class QVBoxLayout; + /** This class provides a widget displaying the diagrams of a particular project using tabs. @@ -131,10 +173,17 @@ class ProjectView : public QWidget QVBoxLayout *layout_; QWidget *fallback_widget_; QLabel *fallback_label_; + +#ifdef Q_OS_MACOS + WheelEnabledTabBar *m_tab; +#else QTabWidget *m_tab; +#endif + QMap m_diagram_ids; int m_previous_tab_index = -1; QList m_diagram_view_list; }; + #endif