Skip to content

Commit

Permalink
Add support for restoring dock widgets status
Browse files Browse the repository at this point in the history
Fixes #63
  • Loading branch information
wh201906 committed Apr 6, 2024
1 parent b57a47c commit c88b47e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ void MainWindow::keyReleaseEvent(QKeyEvent* e)
QMainWindow::keyReleaseEvent(e);
}

void MainWindow::closeEvent(QCloseEvent *event)
{
Q_UNUSED(event);
const QString windowStateData = QString::fromLatin1(saveState().toBase64());
settings->beginGroup("SerialTest");
settings->setValue("WindowState", windowStateData);
settings->endGroup();
}

void MainWindow::onStateButtonClicked()
{
if(IOConnection->state() != Connection::Unconnected)
Expand Down Expand Up @@ -216,7 +225,9 @@ void MainWindow::initUI()
bool dockEnabled = settings->value("Android_Dock", false).toBool();
settings->endGroup();
if(dockEnabled)
{
dockInit();
}
#else
onTopBox = new QCheckBox(tr("On Top"));
connect(onTopBox, &QCheckBox::clicked, this, &MainWindow::onTopBoxClicked);
Expand Down Expand Up @@ -589,6 +600,8 @@ void MainWindow::dockInit()
dock->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
widget = ui->funcTab->widget(0);
dock->setWidget(widget);
// For saveState()/restoreState()
dock->setObjectName(widget->objectName() + "DockWidget");
connect(dock, &QDockWidget::topLevelChanged, this, &MainWindow::onDockTopLevelChanged);
dock->installEventFilter(this);
addDockWidget(Qt::BottomDockWidgetArea, dock);
Expand All @@ -600,6 +613,15 @@ void MainWindow::dockInit()
ui->centralwidget->hide();
dockList[0]->setVisible(true);
dockList[0]->raise();

// Restore the geometry and the state of dock widgets
settings->beginGroup("SerialTest");
const QByteArray windowStateData = QByteArray::fromBase64(settings->value("WindowState", "").toString().toLatin1());
settings->endGroup();
if(!windowStateData.isEmpty())
{
restoreState(windowStateData);
}
}


Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public slots:
bool eventFilter(QObject *watched, QEvent *event) override;
void contextMenuEvent(QContextMenuEvent *event) override;
void keyReleaseEvent(QKeyEvent* e) override;
void closeEvent(QCloseEvent* event) override;
private slots:
void readData();
void onStateButtonClicked();
Expand Down

0 comments on commit c88b47e

Please sign in to comment.