Skip to content
20 changes: 18 additions & 2 deletions include/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <QTimer>
#include <QList>
#include <QMainWindow>
#include <QMdiArea>

#include "ConfigManager.h"

Expand All @@ -45,6 +46,7 @@ class ConfigManager;
namespace gui
{

class CustomQMdiArea;
class PluginView;
class SubWindow;
class ToolButton;
Expand All @@ -57,7 +59,7 @@ class MainWindow : public QMainWindow
public:
QMdiArea* workspace()
{
return m_workspace;
return reinterpret_cast<QMdiArea*>(m_workspace);
}

QWidget* toolBar()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down
33 changes: 32 additions & 1 deletion src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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());
m_lastY = event->y();
}
}

void CustomQMdiArea::mouseReleaseEvent(QMouseEvent* event)
{
m_isBeingMoved = false;
}

} // namespace lmms::gui
Loading