aDD scroll page tabs ON MACos, Thanks Giovanni

This commit is contained in:
Laurent Trinques
2019-09-08 18:06:52 +02:00
parent 76ba2aa3eb
commit 83eba80445
2 changed files with 53 additions and 0 deletions

View File

@@ -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;

View File

@@ -19,10 +19,51 @@
#define PROJECT_VIEW_H
#include <QWidget>
#include <QtWidgets>
#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<int, DiagramView *> m_diagram_ids;
int m_previous_tab_index = -1;
QList<DiagramView *> m_diagram_view_list;
};
#endif