Skip to content

Commit

Permalink
DockModeMenu: a better menu to handle dock panels
Browse files Browse the repository at this point in the history
Closes #529.
  • Loading branch information
KitsuneRal committed Aug 27, 2023
1 parent f0d77a8 commit fe77cc7
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 15 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ set(quaternion_SRCS
client/logindialog.cpp
client/networkconfigdialog.cpp
client/roomdialogs.cpp
client/dockmodemenu.cpp
client/mainwindow.cpp
client/roomlistdock.cpp
client/userlistdock.cpp
Expand Down
46 changes: 46 additions & 0 deletions client/dockmodemenu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include "dockmodemenu.h"

#include <QtWidgets/QDockWidget>

DockModeMenu::DockModeMenu(QString name, QDockWidget* w)
: QMenu(name)
, dockWidget(w)
, offAction(addAction(tr("&Off", "The dock panel is hidden"),
[this] { dockWidget->setVisible(false); }))
, dockedAction(addAction(tr("&Docked"),
[this] {
dockWidget->setVisible(true);
dockWidget->setFloating(false);
}))
, floatingAction(addAction(
tr("&Floating", "The dock panel is floating, aka undocked"), [this] {
dockWidget->setVisible(true);
dockWidget->setFloating(true);
}))
{
offAction->setStatusTip(tr("Completely hide this list"));
offAction->setCheckable(true);
dockedAction->setStatusTip(tr("The list is shown within the main window"));
dockedAction->setCheckable(true);
floatingAction->setStatusTip(
tr("The list is shown separately from the main window"));
floatingAction->setCheckable(true);
auto* radioGroup = new QActionGroup(this);
for (auto* a : { offAction, dockedAction, floatingAction })
radioGroup->addAction(a);
connect(dockWidget, &QDockWidget::visibilityChanged, this,
&DockModeMenu::updateMode);
connect(dockWidget, &QDockWidget::topLevelChanged, this,
&DockModeMenu::updateMode);
updateMode();
}

void DockModeMenu::updateMode()
{
if (dockWidget->isHidden())
offAction->setChecked(true);
else if (dockWidget->isFloating())
floatingAction->setChecked(true);
else
dockedAction->setChecked(true);
}
20 changes: 20 additions & 0 deletions client/dockmodemenu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <QtWidgets/QMenu>

class QDockWidget;

class DockModeMenu : public QMenu {
Q_OBJECT
public:
DockModeMenu(QString name, QDockWidget* w);

private slots:
void updateMode();

private:
QDockWidget* dockWidget;
QAction* offAction;
QAction* dockedAction;
QAction* floatingAction;
};
23 changes: 8 additions & 15 deletions client/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "roomlistdock.h"
#include "userlistdock.h"
#include "dockmodemenu.h"
#include "chatroomwidget.h"
#include "timelinewidget.h"
#include "quaternionroom.h"
Expand Down Expand Up @@ -95,7 +96,8 @@ MainWindow::MainWindow()
connect(userListDock, &UserListDock::userMentionRequested,
chatRoomWidget, &ChatRoomWidget::insertMention);

createMenu();
loadSettings(); // Only GUI, account settings will be loaded in invokeLogin
createMenu(); // Assumes loadSettings() is done, to set flags on menu items
createWinId(); // TODO: check that it's actually needed
systemTrayIcon = new SystemTrayIcon(this);
systemTrayIcon->show();
Expand All @@ -106,7 +108,6 @@ MainWindow::MainWindow()
statusBar()->setSizeGripEnabled(false);
statusBar()->addPermanentWidget(busyLabel);
statusBar()->showMessage(tr("Loading..."));
loadSettings(); // Only GUI, account settings will be loaded in invokeLogin

busyLabel->show();
busyIndicator->start();
Expand Down Expand Up @@ -201,19 +202,6 @@ void MainWindow::createMenu()
// View menu
auto viewMenu = menuBar()->addMenu(tr("&View"));

viewMenu->addSeparator();
auto dockPanesMenu = viewMenu->addMenu(
QIcon::fromTheme("labplot-editvlayout"),
tr("Dock &panels", "Panels of the dock, not 'to dock the panels'"));
roomListDock->toggleViewAction()
->setStatusTip(tr("Show/hide Rooms dock panel"));
dockPanesMenu->addAction(roomListDock->toggleViewAction());
userListDock->toggleViewAction()
->setStatusTip(tr("Show/hide Users dock panel"));
dockPanesMenu->addAction(userListDock->toggleViewAction());

viewMenu->addSeparator();

auto showEventsMenu = viewMenu->addMenu(tr("&Display in timeline"));
addUiOptionCheckbox(
showEventsMenu,
Expand Down Expand Up @@ -327,6 +315,11 @@ void MainWindow::createMenu()
sg.setValue("quote_type", list.indexOf(newType));
});

viewMenu->addSection(
tr("Dock &panels", "Panels of the dock, not 'to dock the panels'"));
viewMenu->addMenu(new DockModeMenu(tr("&Room list"), roomListDock));
viewMenu->addMenu(new DockModeMenu(tr("&Member list"), userListDock));

// Room menu
auto roomMenu = menuBar()->addMenu(tr("&Room"));

Expand Down

0 comments on commit fe77cc7

Please sign in to comment.