Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving movement inside workspace #7595

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
21 changes: 18 additions & 3 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 Down Expand Up @@ -57,7 +58,7 @@ class MainWindow : public QMainWindow
public:
QMdiArea* workspace()
{
return m_workspace;
return static_cast<QMdiArea*>(m_workspace);
}

QWidget* toolBar()
Expand Down Expand Up @@ -203,7 +204,22 @@ private slots:
bool guiSaveProject();
bool guiSaveProjectAs( const QString & filename );

QMdiArea * m_workspace;
class MovableQMdiArea : public QMdiArea
{
public:
MovableQMdiArea(QWidget* parent = nullptr);
~MovableQMdiArea() {}
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;
};

MovableQMdiArea * m_workspace;

QWidget * m_toolBar;
QGridLayout * m_toolBarLayout;
Expand Down Expand Up @@ -258,7 +274,6 @@ private slots:

} ;


} // namespace gui

} // namespace lmms
Expand Down
42 changes: 39 additions & 3 deletions 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 MovableQMdiArea(splitter);

// Load background
emit initProgress(tr("Loading background picture"));
Expand Down Expand Up @@ -531,8 +531,6 @@ void MainWindow::finalize()
}




int MainWindow::addWidgetToToolBar( QWidget * _w, int _row, int _col )
{
int col = ( _col == -1 ) ? m_toolBarLayout->columnCount() + 7 : _col;
Expand Down Expand Up @@ -1611,5 +1609,43 @@ void MainWindow::onProjectFileNameChanged()
this->resetWindowTitle();
}

MainWindow::MovableQMdiArea::MovableQMdiArea(QWidget* parent) :
QMdiArea(parent),
m_isBeingMoved(false),
m_lastX(0),
m_lastY(0)
{}

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)
{
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 MainWindow::MovableQMdiArea::mouseReleaseEvent(QMouseEvent* event)
{
setCursor(Qt::ArrowCursor);
m_isBeingMoved = false;
}

} // namespace lmms::gui
Loading