add protected mode

This commit is contained in:
Gary Wang 2019-10-05 13:21:49 +08:00
parent 1b646a5183
commit 9f4db60f82
3 changed files with 27 additions and 2 deletions

View File

@ -1,7 +1,7 @@
environment: environment:
matrix: matrix:
- build_name: mingw53_32_qt5_11_3 - build_name: mingw73_32_qt5_12_4
QTPATH: C:\Qt\5.11.3\mingw53_32 QTPATH: C:\Qt\5.12.4\mingw73_32
MINGW32: C:\Qt\Tools\mingw530_32 MINGW32: C:\Qt\Tools\mingw530_32
# - build_name: msvc2017_64 # - build_name: msvc2017_64
# QTPATH: C:\Qt\5.11.2\msvc2017_64 # QTPATH: C:\Qt\5.11.2\msvc2017_64

View File

@ -13,6 +13,7 @@
#include <QStyle> #include <QStyle>
#include <QScreen> #include <QScreen>
#include <QGraphicsOpacityEffect> #include <QGraphicsOpacityEffect>
#include <QMenu>
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
@ -246,6 +247,22 @@ void MainWindow::resizeEvent(QResizeEvent *event)
return QMainWindow::resizeEvent(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) bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
{ {
#ifdef _WIN32 #ifdef _WIN32
@ -362,3 +379,9 @@ void MainWindow::updateWidgetsPosition()
height() - m_bottomButtonGroup->height()); height() - m_bottomButtonGroup->height());
m_gv->move(width() - m_gv->width(), height() - m_gv->height()); m_gv->move(width() - m_gv->width(), height() - m_gv->height());
} }
void MainWindow::toggleProtectedMode()
{
m_protectedMode = !m_protectedMode;
m_closeButton->setVisible(!m_protectedMode);
}

View File

@ -35,12 +35,14 @@ protected slots:
void mouseDoubleClickEvent(QMouseEvent *event) override; void mouseDoubleClickEvent(QMouseEvent *event) override;
void wheelEvent(QWheelEvent *event) override; void wheelEvent(QWheelEvent *event) override;
void resizeEvent(QResizeEvent *event) override; void resizeEvent(QResizeEvent *event) override;
void contextMenuEvent(QContextMenuEvent *event) override;
bool nativeEvent(const QByteArray& eventType, void* message, long* result) override; bool nativeEvent(const QByteArray& eventType, void* message, long* result) override;
void centerWindow(); void centerWindow();
void closeWindow(); void closeWindow();
void updateWidgetsPosition(); void updateWidgetsPosition();
void toggleProtectedMode();
private: private:
QPoint m_oldMousePos; QPoint m_oldMousePos;