@@ -159,7 +159,7 @@ MainWindow::MainWindow() :
159159 sideBar->appendTab (new FileBrowser (root_paths.join (" *" ), FileItem::defaultFilters (), title,
160160 embed::getIconPixmap (" computer" ).transformed (QTransform ().rotate (90 )), splitter, dirs_as_items));
161161
162- m_workspace = new QMdiArea (splitter);
162+ m_workspace = new MovableQMdiArea (splitter);
163163
164164 // Load background
165165 emit initProgress (tr (" Loading background picture" ));
@@ -179,8 +179,8 @@ MainWindow::MainWindow() :
179179 }
180180
181181 m_workspace->setOption ( QMdiArea::DontMaximizeSubWindowOnActivation );
182- m_workspace->setHorizontalScrollBarPolicy ( Qt::ScrollBarAsNeeded );
183- m_workspace->setVerticalScrollBarPolicy ( Qt::ScrollBarAsNeeded );
182+ m_workspace->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff );
183+ m_workspace->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff );
184184
185185 hbox->addWidget (sideBar);
186186 hbox->addWidget (splitter);
@@ -531,8 +531,6 @@ void MainWindow::finalize()
531531}
532532
533533
534-
535-
536534int MainWindow::addWidgetToToolBar ( QWidget * _w, int _row, int _col )
537535{
538536 int col = ( _col == -1 ) ? m_toolBarLayout->columnCount () + 7 : _col;
@@ -944,12 +942,6 @@ void MainWindow::toggleWindow( QWidget *window, bool forceShow )
944942 parent->hide ();
945943 refocus ();
946944 }
947-
948- // Workaround for Qt Bug #260116
949- m_workspace->setHorizontalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
950- m_workspace->setVerticalScrollBarPolicy ( Qt::ScrollBarAlwaysOff );
951- m_workspace->setHorizontalScrollBarPolicy ( Qt::ScrollBarAsNeeded );
952- m_workspace->setVerticalScrollBarPolicy ( Qt::ScrollBarAsNeeded );
953945}
954946
955947
@@ -1601,4 +1593,64 @@ void MainWindow::onProjectFileNameChanged()
16011593}
16021594
16031595
1596+ MainWindow::MovableQMdiArea::MovableQMdiArea (QWidget* parent) :
1597+ QMdiArea (parent),
1598+ m_isBeingMoved (false ),
1599+ m_lastX (0 ),
1600+ m_lastY (0 )
1601+ {}
1602+
1603+ void MainWindow::MovableQMdiArea::mousePressEvent (QMouseEvent* event)
1604+ {
1605+ m_lastX = event->x ();
1606+ m_lastY = event->y ();
1607+ m_isBeingMoved = true ;
1608+ setCursor (Qt::ClosedHandCursor);
1609+ }
1610+
1611+ void MainWindow::MovableQMdiArea::mouseMoveEvent (QMouseEvent* event)
1612+ {
1613+ if (m_isBeingMoved == false ) { return ; }
1614+
1615+ int minXBoundary = window ()->width () - 100 ;
1616+ int maxXBoundary = 100 ;
1617+ int minYBoundary = window ()->height () - 100 ;
1618+ int maxYBoundary = 100 ;
1619+
1620+ int minX = minXBoundary;
1621+ int maxX = maxXBoundary;
1622+ int minY = minYBoundary;
1623+ int maxY = maxYBoundary;
1624+
1625+ auto subWindows = subWindowList ();
1626+ for (auto * curWindow : subWindows)
1627+ {
1628+ if (curWindow->isVisible ())
1629+ {
1630+ minX = std::min (minX, curWindow->x ());
1631+ maxX = std::max (maxX, curWindow->x () + curWindow->width ());
1632+ minY = std::min (minY, curWindow->y ());
1633+ maxY = std::max (maxY, curWindow->y () + curWindow->height ());
1634+ }
1635+ }
1636+
1637+ int scrollX = m_lastX - event->x ();
1638+ int scrollY = m_lastY - event->y ();
1639+
1640+ scrollX = scrollX < 0 && minX >= minXBoundary ? 0 : scrollX;
1641+ scrollX = scrollX > 0 && maxX <= maxXBoundary ? 0 : scrollX;
1642+ scrollY = scrollY < 0 && minY >= minYBoundary ? 0 : scrollY;
1643+ scrollY = scrollY > 0 && maxY <= maxYBoundary ? 0 : scrollY;
1644+
1645+ scrollContentsBy (-scrollX, -scrollY);
1646+ m_lastX = event->x ();
1647+ m_lastY = event->y ();
1648+ }
1649+
1650+ void MainWindow::MovableQMdiArea::mouseReleaseEvent (QMouseEvent* event)
1651+ {
1652+ setCursor (Qt::ArrowCursor);
1653+ m_isBeingMoved = false ;
1654+ }
1655+
16041656} // namespace lmms::gui
0 commit comments