Skip to content

Commit

Permalink
Merge pull request #58 from KitsuneRal/save-window-state
Browse files Browse the repository at this point in the history
Save geometry of the main window and state of dock widgets
  • Loading branch information
KitsuneRal authored Sep 11, 2016
2 parents e07368c + ad36fca commit be73028
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 26 deletions.
74 changes: 48 additions & 26 deletions client/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,47 +48,69 @@ MainWindow::MainWindow()
connect( roomListDock, &RoomListDock::roomSelected, chatRoomWidget, &ChatRoomWidget::setRoom );
connect( roomListDock, &RoomListDock::roomSelected, userListDock, &UserListDock::setRoom );
systemTray = new SystemTray(this);
systemTray->show();
createMenu();
loadSettings();
show();
systemTray->show();
QTimer::singleShot(0, this, SLOT(initialize()));
}

MainWindow::~MainWindow()
{
}

void MainWindow::enableDebug()
void MainWindow::createMenu()
{
chatRoomWidget->enableDebug();
}
// Connection menu
auto connectionMenu = menuBar()->addMenu(tr("&Connection"));

void MainWindow::initialize()
{
auto menuBar = new QMenuBar();
{ // Connection menu
auto connectionMenu = menuBar->addMenu(tr("&Connection"));
loginAction = connectionMenu->addAction(tr("&Login..."));
connect( loginAction, &QAction::triggered, [=]{ showLoginWindow(); } );

loginAction = connectionMenu->addAction(tr("&Login..."));
connect( loginAction, &QAction::triggered, [=]{ showLoginWindow(); } );
logoutAction = connectionMenu->addAction(tr("&Logout"));
connect( logoutAction, &QAction::triggered, [=]{ logout(); } );
logoutAction->setEnabled(false); // we start in a logged out state

logoutAction = connectionMenu->addAction(tr("&Logout"));
connect( logoutAction, &QAction::triggered, this, &MainWindow::logout );
logoutAction->setEnabled(false); // we start in a logged out state
connectionMenu->addSeparator();

connectionMenu->addSeparator();
auto quitAction = connectionMenu->addAction(tr("&Quit"));
quitAction->setShortcut(QKeySequence::Quit);
connect( quitAction, &QAction::triggered, qApp, &QApplication::closeAllWindows );

auto quitAction = connectionMenu->addAction(tr("&Quit"));
quitAction->setShortcut(QKeySequence::Quit);
connect( quitAction, &QAction::triggered, qApp, &QApplication::quit );
}
{ // Room menu
auto roomMenu = menuBar->addMenu(tr("&Room"));
// Room menu
auto roomMenu = menuBar()->addMenu(tr("&Room"));

auto joinRoomAction = roomMenu->addAction(tr("&Join Room..."));
connect( joinRoomAction, &QAction::triggered, this, &MainWindow::showJoinRoomDialog );
}
auto joinRoomAction = roomMenu->addAction(tr("&Join Room..."));
connect( joinRoomAction, &QAction::triggered, [=]{ showJoinRoomDialog(); } );
}

void MainWindow::loadSettings()
{
QMatrixClient::SettingsGroup sg("UI/MainWindow");
if (sg.contains("normal_geometry"))
setGeometry(sg.value("normal_geometry").toRect());
if (sg.value("maximized").toBool())
showMaximized();
if (sg.contains("parts_state"))
restoreState(sg.value("window_parts_state").toByteArray());
}

void MainWindow::saveSettings() const
{
QMatrixClient::SettingsGroup sg("UI/MainWindow");
sg.setValue("normal_geometry", normalGeometry());
sg.setValue("maximized", isMaximized());
sg.setValue("window_parts_state", saveState());
sg.sync();
}

void MainWindow::enableDebug()
{
chatRoomWidget->enableDebug();
}

setMenuBar(menuBar);
void MainWindow::initialize()
{
invokeLogin();
}

Expand Down Expand Up @@ -211,7 +233,7 @@ void MainWindow::connectionError(QString error)
void MainWindow::closeEvent(QCloseEvent* event)
{
setConnection(nullptr);

saveSettings();
event->accept();
}

Expand Down
3 changes: 3 additions & 0 deletions client/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ class MainWindow: public QMainWindow

SystemTray* systemTray;

void createMenu();
void invokeLogin();
void loadSettings();
void saveSettings() const;
};

#endif // MAINWINDOW_H

0 comments on commit be73028

Please sign in to comment.