From a5271d409de8ae6b8100e61140981145b22c82dd Mon Sep 17 00:00:00 2001 From: Le Tan Date: Tue, 29 May 2018 19:53:14 +0800 Subject: [PATCH] support stay-on-top --- src/resources/icons/stay_on_top.svg | 11 ++++++++++ src/vmainwindow.cpp | 31 +++++++++++++++++++++++++++++ src/vmainwindow.h | 2 ++ src/vnote.qrc | 1 + 4 files changed, 45 insertions(+) create mode 100644 src/resources/icons/stay_on_top.svg diff --git a/src/resources/icons/stay_on_top.svg b/src/resources/icons/stay_on_top.svg new file mode 100644 index 00000000..9036a5de --- /dev/null +++ b/src/resources/icons/stay_on_top.svg @@ -0,0 +1,11 @@ + + + + + + diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index a67755aa..fe175217 100644 --- a/src/vmainwindow.cpp +++ b/src/vmainwindow.cpp @@ -381,6 +381,14 @@ void VMainWindow::initViewToolBar(QSize p_iconSize) } }); + QAction *stayOnTopAct = new QAction(VIconUtils::toolButtonIcon(":/resources/icons/stay_on_top.svg"), + tr("Stay On Top"), + this); + stayOnTopAct->setStatusTip(tr("Toggle stay-on-top")); + stayOnTopAct->setCheckable(true); + connect(stayOnTopAct, &QAction::triggered, + this, &VMainWindow::stayOnTop); + QAction *menuBarAct = new QAction(VIconUtils::toolButtonIcon(":/resources/icons/menubar.svg"), tr("Menu Bar"), this); @@ -396,6 +404,7 @@ void VMainWindow::initViewToolBar(QSize p_iconSize) QMenu *viewMenu = new QMenu(this); viewMenu->setToolTipsVisible(true); viewMenu->addAction(fullScreenAct); + viewMenu->addAction(stayOnTopAct); viewMenu->addAction(menuBarAct); expandViewAct = new QAction(VIconUtils::toolButtonIcon(":/resources/icons/expand.svg"), @@ -3187,3 +3196,25 @@ void VMainWindow::showNotebookPanel() changePanelView(PanelViewState::VerticalMode); m_naviBox->setCurrentIndex(NAVI_BOX_NOTEBOOKS_IDX, false); } + +void VMainWindow::stayOnTop(bool p_enabled) +{ + bool shown = isVisible(); + Qt::WindowFlags flags = this->windowFlags(); + +#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) + Qt::WindowFlags magicFlag = Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint; +#else + Qt::WindowFlags magicFlag = Qt::WindowStaysOnTopHint; +#endif + + if (p_enabled) { + setWindowFlags(flags | magicFlag); + } else { + setWindowFlags(flags ^ magicFlag); + } + + if (shown) { + show(); + } +} diff --git a/src/vmainwindow.h b/src/vmainwindow.h index 67d3412a..d283408f 100644 --- a/src/vmainwindow.h +++ b/src/vmainwindow.h @@ -193,6 +193,8 @@ private slots: // Activate Universal Entry. void activateUniversalEntry(); + void stayOnTop(bool p_enabled); + protected: void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE; diff --git a/src/vnote.qrc b/src/vnote.qrc index 9061676c..ba21e652 100644 --- a/src/vnote.qrc +++ b/src/vnote.qrc @@ -223,5 +223,6 @@ resources/icons/open_location.svg resources/icons/unstar.svg resources/icons/explore_root.svg + resources/icons/stay_on_top.svg