able to toggle stay on top

This commit is contained in:
Gary Wang 2019-10-06 12:57:38 +08:00
parent 443ec1d8a7
commit 5d35de4e84
2 changed files with 19 additions and 0 deletions

View File

@ -250,12 +250,19 @@ void MainWindow::resizeEvent(QResizeEvent *event)
void MainWindow::contextMenuEvent(QContextMenuEvent *event) void MainWindow::contextMenuEvent(QContextMenuEvent *event)
{ {
QMenu * menu = new QMenu; QMenu * menu = new QMenu;
QAction * stayOnTopMode = new QAction(tr("Stay on top"));
connect(stayOnTopMode, &QAction::triggered, this, [ = ](){
toggleStayOnTop();
});
stayOnTopMode->setCheckable(true);
stayOnTopMode->setChecked(stayOnTop());
QAction * protectedMode = new QAction(tr("Protected mode")); QAction * protectedMode = new QAction(tr("Protected mode"));
connect(protectedMode, &QAction::triggered, this, [ = ](){ connect(protectedMode, &QAction::triggered, this, [ = ](){
toggleProtectedMode(); toggleProtectedMode();
}); });
protectedMode->setCheckable(true); protectedMode->setCheckable(true);
protectedMode->setChecked(m_protectedMode); protectedMode->setChecked(m_protectedMode);
menu->addAction(stayOnTopMode);
menu->addAction(protectedMode); menu->addAction(protectedMode);
menu->exec(mapToGlobal(event->pos())); menu->exec(mapToGlobal(event->pos()));
menu->deleteLater(); menu->deleteLater();
@ -385,3 +392,13 @@ void MainWindow::toggleProtectedMode()
m_protectedMode = !m_protectedMode; m_protectedMode = !m_protectedMode;
m_closeButton->setVisible(!m_protectedMode); m_closeButton->setVisible(!m_protectedMode);
} }
void MainWindow::toggleStayOnTop()
{
setWindowFlag(Qt::WindowStaysOnTopHint, !stayOnTop());
}
bool MainWindow::stayOnTop()
{
return windowFlags().testFlag(Qt::WindowStaysOnTopHint);
}

View File

@ -43,6 +43,8 @@ protected slots:
void closeWindow(); void closeWindow();
void updateWidgetsPosition(); void updateWidgetsPosition();
void toggleProtectedMode(); void toggleProtectedMode();
void toggleStayOnTop();
bool stayOnTop();
private: private:
QPoint m_oldMousePos; QPoint m_oldMousePos;