Make side panel resizable and allow moving it to the other side

This commit is contained in:
Martchus 2023-10-23 20:42:26 +02:00
parent d3e01264b9
commit 8c86ca05c0
3 changed files with 28 additions and 29 deletions

View File

@ -2,32 +2,15 @@
<ui version="4.0">
<class>GuiSidePanel</class>
<widget class="QWidget" name="GuiSidePanel">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>443</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<height>16777215</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout">
<layout class="QVBoxLayout" name="_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>4</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>9</number>
<number>4</number>
</property>
<property name="bottomMargin">
<number>0</number>

View File

@ -107,21 +107,35 @@ QtWindow::QtWindow(CSettings *settings, QtUtilities::QtSettings *qtSettings, QWi
m_song = m_glWidget->getSongObject();
m_score = m_glWidget->getScoreObject();
QHBoxLayout *mainLayout = new QHBoxLayout;
QVBoxLayout *columnLayout = new QVBoxLayout;
// setup dock widget with side panel
m_sidePanelDockWidget = new QDockWidget(this);
#if defined(Q_OS_WINDOWS) || defined(Q_OS_MAC)
constexpr auto dockFeatures = QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable;
#else
auto dockFeatures = static_cast<QDockWidget::DockWidgetFeatures>(QDockWidget::DockWidgetMovable);
if (QGuiApplication::platformName().compare(QLatin1String("wayland"), Qt::CaseInsensitive)) {
// enable floating windows only on non-Wayland platforms as one can never put a floating window back under Wayland
dockFeatures |= QDockWidget::DockWidgetFloatable;
} else {
// ensure currently floating windows (e.g. from the last X11 session) aren't floating anymore under Wayland
m_sidePanelDockWidget->setFloating(false);
}
#endif
m_sidePanelDockWidget->setFeatures(dockFeatures);
m_sidePanelDockWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
m_sidePanelDockWidget->setWidget(m_sidePanel = new GuiSidePanel(this, m_settings));
m_sidePanelDockWidget->setWindowTitle(tr("Options"));
m_sidePanel = new GuiSidePanel(this, m_settings);
m_topBar = new GuiTopBar(this, m_settings);
m_tutorWindow = new QTextBrowser(this);
m_tutorWindow->hide();
m_settings->init(this, m_song, m_sidePanel, m_topBar);
mainLayout->addWidget(m_sidePanel);
QVBoxLayout *columnLayout = new QVBoxLayout;
columnLayout->addWidget(m_topBar);
columnLayout->addWidget(m_glWidget);
columnLayout->addWidget(m_tutorWindow);
mainLayout->addLayout(columnLayout);
m_song->init2(m_score, m_settings);
@ -129,9 +143,10 @@ QtWindow::QtWindow(CSettings *settings, QtUtilities::QtSettings *qtSettings, QWi
m_topBar->init(m_song);
QWidget *centralWin = new QWidget();
centralWin->setLayout(mainLayout);
centralWin->setLayout(columnLayout);
setCentralWidget(centralWin);
addDockWidget(Qt::LeftDockWidgetArea, m_sidePanelDockWidget);
m_glWidget->setFocus(Qt::ActiveWindowFocusReason);

View File

@ -111,7 +111,7 @@ private slots:
void toggleSidePanel()
{
m_sidePanel->setVisible(m_sidePanelStateAct->isChecked());
m_sidePanelDockWidget->setVisible(m_sidePanelStateAct->isChecked());
}
void onViewPianoKeyboard(){
@ -193,6 +193,7 @@ private:
QtUtilities::QtSettings *m_qtSettings;
QtUtilities::SettingsDialog *m_settingsDlg;
QDockWidget *m_sidePanelDockWidget;
GuiSidePanel *m_sidePanel;
GuiTopBar *m_topBar;
QTextBrowser *m_tutorWindow;