From 9f4db60f828cba78c2f9de1622c4daebe01cb932 Mon Sep 17 00:00:00 2001 From: Gary Wang Date: Sat, 5 Oct 2019 13:21:49 +0800 Subject: [PATCH] add protected mode --- appveyor.yml | 4 ++-- mainwindow.cpp | 23 +++++++++++++++++++++++ mainwindow.h | 2 ++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 8d017c7..2d80bc5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ environment: matrix: - - build_name: mingw53_32_qt5_11_3 - QTPATH: C:\Qt\5.11.3\mingw53_32 + - build_name: mingw73_32_qt5_12_4 + QTPATH: C:\Qt\5.12.4\mingw73_32 MINGW32: C:\Qt\Tools\mingw530_32 # - build_name: msvc2017_64 # QTPATH: C:\Qt\5.11.2\msvc2017_64 diff --git a/mainwindow.cpp b/mainwindow.cpp index 9af8818..ce52483 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #ifdef _WIN32 #include @@ -246,6 +247,22 @@ void MainWindow::resizeEvent(QResizeEvent *event) return QMainWindow::resizeEvent(event); } +void MainWindow::contextMenuEvent(QContextMenuEvent *event) +{ + QMenu * menu = new QMenu; + QAction * protectedMode = new QAction(tr("Protected mode")); + connect(protectedMode, &QAction::triggered, this, [ = ](){ + toggleProtectedMode(); + }); + protectedMode->setCheckable(true); + protectedMode->setChecked(m_protectedMode); + menu->addAction(protectedMode); + menu->exec(mapToGlobal(event->pos())); + menu->deleteLater(); + + return QMainWindow::contextMenuEvent(event); +} + bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result) { #ifdef _WIN32 @@ -362,3 +379,9 @@ void MainWindow::updateWidgetsPosition() height() - m_bottomButtonGroup->height()); m_gv->move(width() - m_gv->width(), height() - m_gv->height()); } + +void MainWindow::toggleProtectedMode() +{ + m_protectedMode = !m_protectedMode; + m_closeButton->setVisible(!m_protectedMode); +} diff --git a/mainwindow.h b/mainwindow.h index 72c03a6..3c47175 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -35,12 +35,14 @@ protected slots: void mouseDoubleClickEvent(QMouseEvent *event) override; void wheelEvent(QWheelEvent *event) override; void resizeEvent(QResizeEvent *event) override; + void contextMenuEvent(QContextMenuEvent *event) override; bool nativeEvent(const QByteArray& eventType, void* message, long* result) override; void centerWindow(); void closeWindow(); void updateWidgetsPosition(); + void toggleProtectedMode(); private: QPoint m_oldMousePos;