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

Add horizontal scrolling to MainWindow QMdiArea #5174

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions include/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,32 @@
#include <QtCore/QTimer>
#include <QtCore/QList>
#include <QMainWindow>
#include <QMdiArea>

#include "ConfigManager.h"
#include "SubWindow.h"

class QAction;
class QDomElement;
class QGridLayout;
class QMdiArea;

class ConfigManager;
class PluginView;
class ToolButton;


class ScrollFixMdiArea : public QMdiArea
{
Q_OBJECT
protected:
virtual void wheelEvent(QWheelEvent * we);
public:
ScrollFixMdiArea(QWidget* parent = nullptr) :
QMdiArea(parent)
{ /* only need to init QMdiArea */ }
};


class MainWindow : public QMainWindow
{
Q_OBJECT
Expand Down Expand Up @@ -191,7 +203,7 @@ private slots:
bool guiSaveProject();
bool guiSaveProjectAs( const QString & filename );

QMdiArea * m_workspace;
ScrollFixMdiArea * m_workspace;

QWidget * m_toolBar;
QGridLayout * m_toolBarLayout;
Expand Down
23 changes: 22 additions & 1 deletion src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ MainWindow::MainWindow() :
embed::getIconPixmap( "computer" ).transformed( QTransform().rotate( 90 ) ),
splitter, dirs_as_items) );

m_workspace = new QMdiArea(splitter);
m_workspace = new ScrollFixMdiArea(splitter);

// Load background
emit initProgress(tr("Loading background picture"));
Expand Down Expand Up @@ -1702,3 +1702,24 @@ void MainWindow::onProjectFileNameChanged()
{
this->resetWindowTitle();
}




void ScrollFixMdiArea::wheelEvent(QWheelEvent * we)
{
QPoint deg = we->angleDelta();
QScrollBar* bar = we->modifiers() & Qt::ShiftModifier
? horizontalScrollBar()
: verticalScrollBar();
int multiplier = we->modifiers() & Qt::ControlModifier
? 2
: 1;
if (!bar->isVisible())
{
we->ignore();
return;
}
bar->setValue(bar->value() - (deg.y() * multiplier));
we->accept();
}
23 changes: 22 additions & 1 deletion src/gui/TrackContainerView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,28 @@ void TrackContainerView::scrollArea::wheelEvent( QWheelEvent * _we )
m_trackContainerView->wheelEvent( _we );
if( !_we->isAccepted() )
{
QScrollArea::wheelEvent( _we );
// Handle Shift+Wheel orientation of QWheelEvent
if (_we->modifiers() & Qt::ShiftModifier
&& _we->orientation() == Qt::Vertical)
{
// copy QWheelEvent but change orientation to Horizontal
QWheelEvent we(
_we->posF(), _we->globalPosF(), _we->pixelDelta(),
_we->angleDelta(), _we->delta(), Qt::Horizontal,
_we->buttons(), _we->modifiers(), _we->phase(),
#if (QT_VERSION >= QT_VERSION_CHECK(5, 7, 0))
_we->source(), _we->inverted()
#else
_we->source()
#endif
);
QScrollArea::wheelEvent(&we);
}
else
{
// Normal scroll event
QScrollArea::wheelEvent(_we);
}
}
}

Expand Down
30 changes: 26 additions & 4 deletions src/gui/editors/AutomationEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1738,13 +1738,35 @@ void AutomationEditor::wheelEvent(QWheelEvent * we )
}
else if(we->modifiers() & Qt::ShiftModifier)
{
m_leftRightScroll->setValue(m_leftRightScroll->value() -
we->angleDelta().y() * 2 / 15);
auto cur_pos = m_leftRightScroll->value();
auto new_pos = cur_pos - we->angleDelta().y() * 2 / 15;
// If we are already at the limits of scrolling value, check if the new
// position is less/greater than min/max in order to allow the parent
// to process the wheelEvent
if (
(cur_pos == m_leftRightScroll->minimum() && new_pos < m_leftRightScroll->minimum())
|| (cur_pos == m_leftRightScroll->maximum() && new_pos > m_leftRightScroll->maximum())
)
{
we->ignore();
return;
}
m_leftRightScroll->setValue(new_pos);
}
else
{
m_topBottomScroll->setValue(m_topBottomScroll->value() -
(we->angleDelta().x() + we->angleDelta().y()) / 30);
auto cur_pos = m_topBottomScroll->value();
auto new_pos = cur_pos - ((we->angleDelta().x() + we->angleDelta().y()) / 30);
// same as above comment for m_leftRightScroll
if (
(cur_pos == m_topBottomScroll->minimum() && new_pos < m_topBottomScroll->minimum())
|| (cur_pos == m_topBottomScroll->maximum() && new_pos > m_topBottomScroll->maximum())
)
{
we->ignore();
return;
}
m_topBottomScroll->setValue(new_pos);
}
}

Expand Down
30 changes: 26 additions & 4 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3537,13 +3537,35 @@ void PianoRoll::wheelEvent(QWheelEvent * we )
}
else if(we->modifiers() & Qt::ShiftModifier)
{
m_leftRightScroll->setValue(m_leftRightScroll->value() -
we->angleDelta().y() * 2 / 15);
auto cur_pos = m_leftRightScroll->value();
auto new_pos = cur_pos - we->angleDelta().y() * 2 / 15;
// If we are already at the limits of scrolling value, check if the new
// position is less/greater than min/max in order to allow the parent
// to process the wheelEvent
if (
(cur_pos == m_leftRightScroll->minimum() && new_pos < m_leftRightScroll->minimum())
|| (cur_pos == m_leftRightScroll->maximum() && new_pos > m_leftRightScroll->maximum())
)
{
we->ignore();
return;
}
m_leftRightScroll->setValue(new_pos);
}
else
{
m_topBottomScroll->setValue(m_topBottomScroll->value() -
we->angleDelta().y() / 30);
auto cur_pos = m_topBottomScroll->value();
auto new_pos = cur_pos - we->angleDelta().y() / 30;
// same as above comment for m_leftRightScroll
if (
(cur_pos == m_topBottomScroll->minimum() && new_pos < m_topBottomScroll->minimum())
|| (cur_pos == m_topBottomScroll->maximum() && new_pos > m_topBottomScroll->maximum())
)
{
we->ignore();
return;
}
m_topBottomScroll->setValue(new_pos);
}
}

Expand Down
16 changes: 14 additions & 2 deletions src/gui/editors/SongEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,20 @@ void SongEditor::wheelEvent( QWheelEvent * we )
}
else if(we->modifiers() & Qt::ShiftModifier)
{
m_leftRightScroll->setValue(m_leftRightScroll->value() -
we->angleDelta().y() / 30);
auto cur_pos = m_leftRightScroll->value();
auto new_pos = cur_pos - we->angleDelta().y() / 30;
// If we are already at the limits of scrolling value, check if the new
// position is less/greater than min/max in order to allow the parent
// to process the wheelEvent
if (
(cur_pos == m_leftRightScroll->minimum() && new_pos < m_leftRightScroll->minimum())
|| (cur_pos == m_leftRightScroll->maximum() && new_pos > m_leftRightScroll->maximum())
)
{
we->ignore();
return;
}
m_leftRightScroll->setValue(new_pos);
}
else
{
Expand Down