mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
aDD scroll page tabs ON MACos, Thanks Giovanni
This commit is contained in:
@@ -810,7 +810,11 @@ void ProjectView::initWidgets() {
|
|||||||
fallback_label_ -> setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
|
fallback_label_ -> setAlignment(Qt::AlignVCenter | Qt::AlignHCenter);
|
||||||
|
|
||||||
// initialize tabs
|
// initialize tabs
|
||||||
|
#ifdef Q_OS_MACOS
|
||||||
|
m_tab = new WheelEnabledTabBar(this);
|
||||||
|
#else
|
||||||
m_tab = new QTabWidget(this);
|
m_tab = new QTabWidget(this);
|
||||||
|
#endif
|
||||||
m_tab -> setMovable(true);
|
m_tab -> setMovable(true);
|
||||||
|
|
||||||
QToolButton *add_new_diagram_button = new QToolButton;
|
QToolButton *add_new_diagram_button = new QToolButton;
|
||||||
|
|||||||
@@ -19,10 +19,51 @@
|
|||||||
#define PROJECT_VIEW_H
|
#define PROJECT_VIEW_H
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QtWidgets>
|
||||||
|
|
||||||
|
|
||||||
#include "templatelocation.h"
|
#include "templatelocation.h"
|
||||||
#include "qetresult.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 QETProject;
|
||||||
class DiagramView;
|
class DiagramView;
|
||||||
class Diagram;
|
class Diagram;
|
||||||
@@ -31,6 +72,7 @@ class QTabWidget;
|
|||||||
class QLabel;
|
class QLabel;
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This class provides a widget displaying the diagrams of a particular
|
This class provides a widget displaying the diagrams of a particular
|
||||||
project using tabs.
|
project using tabs.
|
||||||
@@ -131,10 +173,17 @@ class ProjectView : public QWidget
|
|||||||
QVBoxLayout *layout_;
|
QVBoxLayout *layout_;
|
||||||
QWidget *fallback_widget_;
|
QWidget *fallback_widget_;
|
||||||
QLabel *fallback_label_;
|
QLabel *fallback_label_;
|
||||||
|
|
||||||
|
#ifdef Q_OS_MACOS
|
||||||
|
WheelEnabledTabBar *m_tab;
|
||||||
|
#else
|
||||||
QTabWidget *m_tab;
|
QTabWidget *m_tab;
|
||||||
|
#endif
|
||||||
|
|
||||||
QMap<int, DiagramView *> m_diagram_ids;
|
QMap<int, DiagramView *> m_diagram_ids;
|
||||||
int m_previous_tab_index = -1;
|
int m_previous_tab_index = -1;
|
||||||
QList<DiagramView *> m_diagram_view_list;
|
QList<DiagramView *> m_diagram_view_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user