From f4808484d588b00d42a2f5437d1d3b2b47d8707a Mon Sep 17 00:00:00 2001 From: szeli1 <143485814+szeli1@users.noreply.github.com> Date: Sat, 23 Nov 2024 12:33:34 +0100 Subject: [PATCH 01/10] MainWindow_implementing_custom_QMdiArea --- include/MainWindow.h | 20 ++++++++++++++++++-- src/gui/MainWindow.cpp | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/include/MainWindow.h b/include/MainWindow.h index 6c140a1e61d..d51fc0eb8cd 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -29,6 +29,7 @@ #include #include #include +#include #include "ConfigManager.h" @@ -45,6 +46,7 @@ class ConfigManager; namespace gui { +class CustomQMdiArea; class PluginView; class SubWindow; class ToolButton; @@ -57,7 +59,7 @@ class MainWindow : public QMainWindow public: QMdiArea* workspace() { - return m_workspace; + return reinterpret_cast(m_workspace); } QWidget* toolBar() @@ -203,7 +205,7 @@ private slots: bool guiSaveProject(); bool guiSaveProjectAs( const QString & filename ); - QMdiArea * m_workspace; + CustomQMdiArea * m_workspace; QWidget * m_toolBar; QGridLayout * m_toolBarLayout; @@ -258,6 +260,20 @@ private slots: } ; +class CustomQMdiArea : public QMdiArea +{ +public: + CustomQMdiArea(QWidget* parent = nullptr); + ~CustomQMdiArea() {} +protected: + void mousePressEvent(QMouseEvent* event) override; + void mouseMoveEvent(QMouseEvent* event) override; + void mouseReleaseEvent(QMouseEvent* event) override; +private: + bool m_isBeingMoved; + int m_lastX; + int m_lastY; +}; } // namespace gui diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 48d2ddb3025..2db833b8273 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -159,7 +159,7 @@ MainWindow::MainWindow() : sideBar->appendTab(new FileBrowser(root_paths.join("*"), FileItem::defaultFilters(), title, embed::getIconPixmap("computer").transformed(QTransform().rotate(90)), splitter, dirs_as_items)); - m_workspace = new QMdiArea(splitter); + m_workspace = new CustomQMdiArea(splitter); // Load background emit initProgress(tr("Loading background picture")); @@ -1611,5 +1611,36 @@ void MainWindow::onProjectFileNameChanged() this->resetWindowTitle(); } +CustomQMdiArea::CustomQMdiArea(QWidget* parent) : + QMdiArea(parent), + m_isBeingMoved(false) +{ + +} +void CustomQMdiArea::mousePressEvent(QMouseEvent* event) +{ + m_lastX = event->x(); + m_lastY = event->y(); + m_isBeingMoved = true; +} +void CustomQMdiArea::mouseMoveEvent(QMouseEvent* event) +{ + if (m_isBeingMoved == false) { return; } + if (m_lastX != event->x()) + { + horizontalScrollBar()->setValue(horizontalScrollBar()->value() + m_lastX - event->x()); + m_lastX = event->x(); + } + if (m_lastY != event->y()) + { + verticalScrollBar()->setValue(verticalScrollBar()->value() + m_lastY - event->y()); + //verticalScrollBar()->setValue(newScroll); + m_lastY = event->y(); + } +} +void CustomQMdiArea::mouseReleaseEvent(QMouseEvent* event) +{ + m_isBeingMoved = false; +} } // namespace lmms::gui From e857a2f812fc9b63747df79dfd90e8b1855767e8 Mon Sep 17 00:00:00 2001 From: szeli1 <143485814+szeli1@users.noreply.github.com> Date: Sat, 23 Nov 2024 12:34:47 +0100 Subject: [PATCH 02/10] MainWindow_style_changes --- src/gui/MainWindow.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 2db833b8273..38bff2623c4 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1614,15 +1614,15 @@ void MainWindow::onProjectFileNameChanged() CustomQMdiArea::CustomQMdiArea(QWidget* parent) : QMdiArea(parent), m_isBeingMoved(false) -{ - -} +{} + void CustomQMdiArea::mousePressEvent(QMouseEvent* event) { m_lastX = event->x(); m_lastY = event->y(); m_isBeingMoved = true; } + void CustomQMdiArea::mouseMoveEvent(QMouseEvent* event) { if (m_isBeingMoved == false) { return; } @@ -1638,6 +1638,7 @@ void CustomQMdiArea::mouseMoveEvent(QMouseEvent* event) m_lastY = event->y(); } } + void CustomQMdiArea::mouseReleaseEvent(QMouseEvent* event) { m_isBeingMoved = false; From 7f0a2fd0d8d85f6f2b6463f23f8341399df1505c Mon Sep 17 00:00:00 2001 From: szeli1 <143485814+szeli1@users.noreply.github.com> Date: Sat, 23 Nov 2024 12:49:57 +0100 Subject: [PATCH 03/10] MainWindow_removing_comment --- src/gui/MainWindow.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 38bff2623c4..7f8660089e1 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1634,7 +1634,6 @@ void CustomQMdiArea::mouseMoveEvent(QMouseEvent* event) if (m_lastY != event->y()) { verticalScrollBar()->setValue(verticalScrollBar()->value() + m_lastY - event->y()); - //verticalScrollBar()->setValue(newScroll); m_lastY = event->y(); } } From 89cc7a174b5a0fe946186655848dd0920ac56c20 Mon Sep 17 00:00:00 2001 From: szeli1 <143485814+szeli1@users.noreply.github.com> Date: Sat, 23 Nov 2024 17:19:03 +0100 Subject: [PATCH 04/10] MainWindow_fixing_casting_and_style --- include/MainWindow.h | 2 +- src/gui/MainWindow.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/MainWindow.h b/include/MainWindow.h index d51fc0eb8cd..c5405a8376c 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -59,7 +59,7 @@ class MainWindow : public QMainWindow public: QMdiArea* workspace() { - return reinterpret_cast(m_workspace); + return static_cast(m_workspace); } QWidget* toolBar() diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 7f8660089e1..ed2ab84d41d 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1613,7 +1613,9 @@ void MainWindow::onProjectFileNameChanged() CustomQMdiArea::CustomQMdiArea(QWidget* parent) : QMdiArea(parent), - m_isBeingMoved(false) + m_isBeingMoved(false), + m_lastX(0), + m_lastY(0) {} void CustomQMdiArea::mousePressEvent(QMouseEvent* event) @@ -1626,11 +1628,14 @@ void CustomQMdiArea::mousePressEvent(QMouseEvent* event) void CustomQMdiArea::mouseMoveEvent(QMouseEvent* event) { if (m_isBeingMoved == false) { return; } + + if (m_lastX != event->x()) { horizontalScrollBar()->setValue(horizontalScrollBar()->value() + m_lastX - event->x()); m_lastX = event->x(); } + if (m_lastY != event->y()) { verticalScrollBar()->setValue(verticalScrollBar()->value() + m_lastY - event->y()); From ef037774af904b5c1f74414e7a04ebcaf513df04 Mon Sep 17 00:00:00 2001 From: szeli1 <143485814+szeli1@users.noreply.github.com> Date: Sat, 23 Nov 2024 17:27:08 +0100 Subject: [PATCH 05/10] MainWindow_fix_casting --- include/MainWindow.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/MainWindow.h b/include/MainWindow.h index c5405a8376c..d51fc0eb8cd 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -59,7 +59,7 @@ class MainWindow : public QMainWindow public: QMdiArea* workspace() { - return static_cast(m_workspace); + return reinterpret_cast(m_workspace); } QWidget* toolBar() From 477600cc236ec95563ed39bb59ad445903b34727 Mon Sep 17 00:00:00 2001 From: szeli1 <143485814+szeli1@users.noreply.github.com> Date: Sat, 23 Nov 2024 18:20:45 +0100 Subject: [PATCH 06/10] MainWindow_moving_class_and_fixing_casting --- include/MainWindow.h | 35 ++++++++++++++++------------------- src/gui/MainWindow.cpp | 13 ++++++++----- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/MainWindow.h b/include/MainWindow.h index d51fc0eb8cd..c3c804a0699 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -57,10 +57,7 @@ class MainWindow : public QMainWindow { Q_OBJECT public: - QMdiArea* workspace() - { - return reinterpret_cast(m_workspace); - } + QMdiArea* workspace(); QWidget* toolBar() { @@ -205,6 +202,21 @@ private slots: bool guiSaveProject(); bool guiSaveProjectAs( const QString & filename ); + class CustomQMdiArea : public QMdiArea + { + public: + CustomQMdiArea(QWidget* parent = nullptr); + ~CustomQMdiArea() {} + protected: + void mousePressEvent(QMouseEvent* event) override; + void mouseMoveEvent(QMouseEvent* event) override; + void mouseReleaseEvent(QMouseEvent* event) override; + private: + bool m_isBeingMoved; + int m_lastX; + int m_lastY; + }; + CustomQMdiArea * m_workspace; QWidget * m_toolBar; @@ -260,21 +272,6 @@ private slots: } ; -class CustomQMdiArea : public QMdiArea -{ -public: - CustomQMdiArea(QWidget* parent = nullptr); - ~CustomQMdiArea() {} -protected: - void mousePressEvent(QMouseEvent* event) override; - void mouseMoveEvent(QMouseEvent* event) override; - void mouseReleaseEvent(QMouseEvent* event) override; -private: - bool m_isBeingMoved; - int m_lastX; - int m_lastY; -}; - } // namespace gui } // namespace lmms diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index ed2ab84d41d..b64da0f999b 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -531,7 +531,10 @@ void MainWindow::finalize() } - +QMdiArea* MainWindow::workspace() +{ + return static_cast(m_workspace); +} int MainWindow::addWidgetToToolBar( QWidget * _w, int _row, int _col ) { @@ -1611,21 +1614,21 @@ void MainWindow::onProjectFileNameChanged() this->resetWindowTitle(); } -CustomQMdiArea::CustomQMdiArea(QWidget* parent) : +MainWindow::CustomQMdiArea::CustomQMdiArea(QWidget* parent) : QMdiArea(parent), m_isBeingMoved(false), m_lastX(0), m_lastY(0) {} -void CustomQMdiArea::mousePressEvent(QMouseEvent* event) +void MainWindow::CustomQMdiArea::mousePressEvent(QMouseEvent* event) { m_lastX = event->x(); m_lastY = event->y(); m_isBeingMoved = true; } -void CustomQMdiArea::mouseMoveEvent(QMouseEvent* event) +void MainWindow::CustomQMdiArea::mouseMoveEvent(QMouseEvent* event) { if (m_isBeingMoved == false) { return; } @@ -1643,7 +1646,7 @@ void CustomQMdiArea::mouseMoveEvent(QMouseEvent* event) } } -void CustomQMdiArea::mouseReleaseEvent(QMouseEvent* event) +void MainWindow::CustomQMdiArea::mouseReleaseEvent(QMouseEvent* event) { m_isBeingMoved = false; } From 8480d1ca26dd8b1e24638445188a720c7fb04163 Mon Sep 17 00:00:00 2001 From: szeli1 <143485814+szeli1@users.noreply.github.com> Date: Sat, 23 Nov 2024 18:25:37 +0100 Subject: [PATCH 07/10] MainWindow_renaming_CustomQMdiArea_to_MovableQMdiArea --- include/MainWindow.h | 9 ++++----- src/gui/MainWindow.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/include/MainWindow.h b/include/MainWindow.h index c3c804a0699..99e6228bdee 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -46,7 +46,6 @@ class ConfigManager; namespace gui { -class CustomQMdiArea; class PluginView; class SubWindow; class ToolButton; @@ -202,11 +201,11 @@ private slots: bool guiSaveProject(); bool guiSaveProjectAs( const QString & filename ); - class CustomQMdiArea : public QMdiArea + class MovableQMdiArea : public QMdiArea { public: - CustomQMdiArea(QWidget* parent = nullptr); - ~CustomQMdiArea() {} + MovableQMdiArea(QWidget* parent = nullptr); + ~MovableQMdiArea() {} protected: void mousePressEvent(QMouseEvent* event) override; void mouseMoveEvent(QMouseEvent* event) override; @@ -217,7 +216,7 @@ private slots: int m_lastY; }; - CustomQMdiArea * m_workspace; + MovableQMdiArea * m_workspace; QWidget * m_toolBar; QGridLayout * m_toolBarLayout; diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index b64da0f999b..32de9b6f79b 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -159,7 +159,7 @@ MainWindow::MainWindow() : sideBar->appendTab(new FileBrowser(root_paths.join("*"), FileItem::defaultFilters(), title, embed::getIconPixmap("computer").transformed(QTransform().rotate(90)), splitter, dirs_as_items)); - m_workspace = new CustomQMdiArea(splitter); + m_workspace = new MovableQMdiArea(splitter); // Load background emit initProgress(tr("Loading background picture")); @@ -1614,21 +1614,21 @@ void MainWindow::onProjectFileNameChanged() this->resetWindowTitle(); } -MainWindow::CustomQMdiArea::CustomQMdiArea(QWidget* parent) : +MainWindow::MovableQMdiArea::MovableQMdiArea(QWidget* parent) : QMdiArea(parent), m_isBeingMoved(false), m_lastX(0), m_lastY(0) {} -void MainWindow::CustomQMdiArea::mousePressEvent(QMouseEvent* event) +void MainWindow::MovableQMdiArea::mousePressEvent(QMouseEvent* event) { m_lastX = event->x(); m_lastY = event->y(); m_isBeingMoved = true; } -void MainWindow::CustomQMdiArea::mouseMoveEvent(QMouseEvent* event) +void MainWindow::MovableQMdiArea::mouseMoveEvent(QMouseEvent* event) { if (m_isBeingMoved == false) { return; } @@ -1646,7 +1646,7 @@ void MainWindow::CustomQMdiArea::mouseMoveEvent(QMouseEvent* event) } } -void MainWindow::CustomQMdiArea::mouseReleaseEvent(QMouseEvent* event) +void MainWindow::MovableQMdiArea::mouseReleaseEvent(QMouseEvent* event) { m_isBeingMoved = false; } From 72c3e457128b416f592f86b4806b1dbc8597691c Mon Sep 17 00:00:00 2001 From: szeli1 <143485814+szeli1@users.noreply.github.com> Date: Sat, 23 Nov 2024 21:03:29 +0100 Subject: [PATCH 08/10] MainWindow_moving_function --- include/MainWindow.h | 5 ++++- src/gui/MainWindow.cpp | 5 ----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/include/MainWindow.h b/include/MainWindow.h index 99e6228bdee..b08e7b2c26b 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -56,7 +56,10 @@ class MainWindow : public QMainWindow { Q_OBJECT public: - QMdiArea* workspace(); + inline QMdiArea* workspace() + { + return static_cast(m_workspace); + } QWidget* toolBar() { diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 32de9b6f79b..be17411af8c 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -531,11 +531,6 @@ void MainWindow::finalize() } -QMdiArea* MainWindow::workspace() -{ - return static_cast(m_workspace); -} - int MainWindow::addWidgetToToolBar( QWidget * _w, int _row, int _col ) { int col = ( _col == -1 ) ? m_toolBarLayout->columnCount() + 7 : _col; From cef80a6422a4785f557fba13f027c423865d4cba Mon Sep 17 00:00:00 2001 From: szeli1 <143485814+szeli1@users.noreply.github.com> Date: Sun, 24 Nov 2024 10:53:16 +0100 Subject: [PATCH 09/10] MainWindow_changing_cursor --- include/MainWindow.h | 2 +- src/gui/MainWindow.cpp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/MainWindow.h b/include/MainWindow.h index b08e7b2c26b..1330de8c5cb 100644 --- a/include/MainWindow.h +++ b/include/MainWindow.h @@ -56,7 +56,7 @@ class MainWindow : public QMainWindow { Q_OBJECT public: - inline QMdiArea* workspace() + QMdiArea* workspace() { return static_cast(m_workspace); } diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index be17411af8c..0e952c9771e 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1614,13 +1614,16 @@ MainWindow::MovableQMdiArea::MovableQMdiArea(QWidget* parent) : m_isBeingMoved(false), m_lastX(0), m_lastY(0) -{} +{ + setSizeAdjustPolicy(QAbstractScrollArea::AdjustIgnored); +} void MainWindow::MovableQMdiArea::mousePressEvent(QMouseEvent* event) { m_lastX = event->x(); m_lastY = event->y(); m_isBeingMoved = true; + setCursor(Qt::ClosedHandCursor); } void MainWindow::MovableQMdiArea::mouseMoveEvent(QMouseEvent* event) @@ -1643,6 +1646,7 @@ void MainWindow::MovableQMdiArea::mouseMoveEvent(QMouseEvent* event) void MainWindow::MovableQMdiArea::mouseReleaseEvent(QMouseEvent* event) { + setCursor(Qt::ArrowCursor); m_isBeingMoved = false; } From 217148859e136408d15a39c4d4988f3652e5a02d Mon Sep 17 00:00:00 2001 From: szeli1 <143485814+szeli1@users.noreply.github.com> Date: Sun, 24 Nov 2024 12:46:56 +0100 Subject: [PATCH 10/10] MainWindow_removing_code_from_constructor --- src/gui/MainWindow.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 0e952c9771e..18c33d616c8 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -1614,9 +1614,7 @@ MainWindow::MovableQMdiArea::MovableQMdiArea(QWidget* parent) : m_isBeingMoved(false), m_lastX(0), m_lastY(0) -{ - setSizeAdjustPolicy(QAbstractScrollArea::AdjustIgnored); -} +{} void MainWindow::MovableQMdiArea::mousePressEvent(QMouseEvent* event) {