From 257bc67f61a29424b0a91a14f549d9430a45f52d Mon Sep 17 00:00:00 2001 From: Alexis Delhaie Date: Fri, 28 Aug 2020 14:47:21 +0200 Subject: [PATCH] Main window frameless + Switching to MSVC2019 --- Chronos.pro | 6 +- Chronos.pro.user | 22 ++++---- sources/mainwindow.cpp | 26 +++++++++ sources/mainwindow.h | 12 ++++ ui/aboutbox.ui | 9 ++- ui/mainwindow.ui | 124 ++++++++++++++++++++++++++++++++++++----- 6 files changed, 169 insertions(+), 30 deletions(-) diff --git a/Chronos.pro b/Chronos.pro index 3f2a2de..685f641 100644 --- a/Chronos.pro +++ b/Chronos.pro @@ -7,10 +7,10 @@ CONFIG += c++17 # remove possible other optimization flags QMAKE_CXXFLAGS_RELEASE -= -O QMAKE_CXXFLAGS_RELEASE -= -O1 -QMAKE_CXXFLAGS_RELEASE -= -O2 +QMAKE_CXXFLAGS_RELEASE *= -O2 -# add the desired -O3 if not present -QMAKE_CXXFLAGS_RELEASE *= -O3 +# add the desired -O3 if not present, MinGW only +# QMAKE_CXXFLAGS_RELEASE *= -O3 RC_ICONS = icon.ico diff --git a/Chronos.pro.user b/Chronos.pro.user index b052a60..ba16706 100644 --- a/Chronos.pro.user +++ b/Chronos.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -74,17 +74,17 @@ ProjectExplorer.Project.Target.0 - Desktop Qt 5.15.0 MinGW 64-bit - Desktop Qt 5.15.0 MinGW 64-bit - qt.qt5.5150.win64_mingw81_kit + Desktop Qt 5.15.0 MSVC2019 64bit + Desktop Qt 5.15.0 MSVC2019 64bit + qt.qt5.5150.win64_msvc2019_64_kit 1 0 0 true 0 - C:\Users\robof\OneDrive\Documents\build-Chronos-Desktop_Qt_5_15_0_MinGW_64_bit-Debug - C:/Users/robof/OneDrive/Documents/build-Chronos-Desktop_Qt_5_15_0_MinGW_64_bit-Debug + C:\Users\robof\OneDrive\Documents\build-Chronos-Desktop_Qt_5_15_0_MSVC2019_64bit-Debug + C:/Users/robof/OneDrive/Documents/build-Chronos-Desktop_Qt_5_15_0_MSVC2019_64bit-Debug true @@ -134,8 +134,8 @@ true 2 - C:\Users\robof\OneDrive\Documents\build-Chronos-Desktop_Qt_5_15_0_MinGW_64_bit-Release - C:/Users/robof/OneDrive/Documents/build-Chronos-Desktop_Qt_5_15_0_MinGW_64_bit-Release + C:\Users\robof\OneDrive\Documents\build-Chronos-Desktop_Qt_5_15_0_MSVC2019_64bit-Release + C:/Users/robof/OneDrive/Documents/build-Chronos-Desktop_Qt_5_15_0_MSVC2019_64bit-Release true @@ -185,8 +185,8 @@ true 0 - C:\Users\robof\OneDrive\Documents\build-Chronos-Desktop_Qt_5_15_0_MinGW_64_bit-Profile - C:/Users/robof/OneDrive/Documents/build-Chronos-Desktop_Qt_5_15_0_MinGW_64_bit-Profile + C:\Users\robof\OneDrive\Documents\build-Chronos-Desktop_Qt_5_15_0_MSVC2019_64bit-Profile + C:/Users/robof/OneDrive/Documents/build-Chronos-Desktop_Qt_5_15_0_MSVC2019_64bit-Profile true @@ -320,7 +320,7 @@ false true - C:/Users/robof/OneDrive/Documents/build-Chronos-Desktop_Qt_5_15_0_MinGW_64_bit-Release + C:/Users/robof/OneDrive/Documents/build-Chronos-Desktop_Qt_5_15_0_MSVC2019_64bit-Release 1 diff --git a/sources/mainwindow.cpp b/sources/mainwindow.cpp index 94db832..c2fa241 100644 --- a/sources/mainwindow.cpp +++ b/sources/mainwindow.cpp @@ -6,9 +6,31 @@ MainWindow::MainWindow(QWidget *parent) , ui(new Ui::MainWindow) { ui->setupUi(this); + ui->window_title->setText(this->windowTitle()); + this->setWindowFlags(Qt::FramelessWindowHint); init(); } +void MainWindow::mousePressEvent(QMouseEvent *event) { + m_nMouseClick_X_Coordinate = event->x(); + m_nMouseClick_Y_Coordinate = event->y(); +} + +void MainWindow::mouseMoveEvent(QMouseEvent *event) { + if (isWidgetIsTitleBar()) { + move(event->globalX() - m_nMouseClick_X_Coordinate , + event->globalY() - m_nMouseClick_Y_Coordinate); + } + +} + +bool MainWindow::isWidgetIsTitleBar() { + return (m_nMouseClick_X_Coordinate >= xmin && + m_nMouseClick_X_Coordinate < xmax && + m_nMouseClick_Y_Coordinate >= ymin && + m_nMouseClick_Y_Coordinate < ymax); +} + MainWindow::~MainWindow() { delete ui; @@ -33,6 +55,10 @@ void MainWindow::init() { objectId.insert(ui->wed_button->objectName(), Identifier::wed); objectId.insert(ui->thu_button->objectName(), Identifier::thu); objectId.insert(ui->fri_button->objectName(), Identifier::fri); + xmax = ui->window_title->x() + ui->window_title->width(); + xmin = ui->window_title->x(); + ymax = ui->window_title->x() + ui->window_title->height(); + ymin = ui->window_title->y(); connect(ui->aboutButton, &QPushButton::clicked, this, &MainWindow::open_about); connect(ui->template_settings_button, &QPushButton::clicked, this, &MainWindow::edit_template); connect(ui->dateEdit, &QDateEdit::dateTimeChanged, this, &MainWindow::compute_week_number); diff --git a/sources/mainwindow.h b/sources/mainwindow.h index 4c64b3d..31a4385 100644 --- a/sources/mainwindow.h +++ b/sources/mainwindow.h @@ -7,6 +7,8 @@ #define SAVE_FILE_VERSION 1 #define KEY_SAVE_FILE_VERSION "version" +#include +#include #include #include #include @@ -59,6 +61,16 @@ private: QMap weeks; QMap objectId; + void mousePressEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); + int m_nMouseClick_X_Coordinate; + int m_nMouseClick_Y_Coordinate; + int xmax; + int xmin; + int ymax; + int ymin; + inline bool isWidgetIsTitleBar(); + public slots: void compute_week_number(const QDateTime &dt); void compute_time(); diff --git a/ui/aboutbox.ui b/ui/aboutbox.ui index 0dd8016..743d11d 100644 --- a/ui/aboutbox.ui +++ b/ui/aboutbox.ui @@ -91,7 +91,7 @@ font-size: 12px; - Version: 1.0.0 (Beta 3) + Version: 1.0.0 (Beta 4) @@ -107,7 +107,7 @@ font-size: 12px; - <html><head/><body><p>Made with Qt 5.15.0 MinGW 64bit (C++17) (<a href="https://github.com/alexlegarnd/Chronos"><span style=" text-decoration: underline; color:#0000ff;">Source Github</span></a>)</p></body></html> + <html><head/><body><p>Made with Qt 5.15.0 MSVC2019 64bit (C++17) (<a href="https://github.com/alexlegarnd/Chronos"><span style=" text-decoration: underline; color:#0000ff;">Source Github</span></a>)</p></body></html> @@ -122,6 +122,9 @@ + + font-size: 12px; + false @@ -132,7 +135,7 @@ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd"> <html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:7.5pt; font-weight:400; font-style:normal;"> +</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:12px; font-weight:400; font-style:normal;"> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">Application icon: Alexis Delhaie (me)</span></p> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;"><br /></p> <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:10pt;">About box banner: Alexis Delhaie (me)</span></p> diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 8e5342a..36ce0a9 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -7,19 +7,19 @@ 0 0 1206 - 649 + 662 1206 - 649 + 662 1206 - 649 + 662 @@ -42,7 +42,7 @@ 192 - 19 + 41 20 81 @@ -55,7 +55,7 @@ 236 - 29 + 51 151 61 @@ -117,7 +117,7 @@ color: white; 40 - 29 + 51 161 61 @@ -179,7 +179,7 @@ color: white; 1022 - 23 + 45 153 61 @@ -258,7 +258,7 @@ color: white; 427 - 30 + 52 161 61 @@ -320,7 +320,7 @@ color: white; 378 - 20 + 42 20 81 @@ -333,7 +333,7 @@ color: white; 930 - 600 + 622 261 31 @@ -346,7 +346,7 @@ color: white; 140 - 160 + 182 921 391 @@ -1341,7 +1341,7 @@ font-size: 22px; 20 - 588 + 610 44 44 @@ -1371,8 +1371,106 @@ font-size: 22px; true + + + + 10 + -1 + 1081 + 41 + + + + TextLabel + + + + + + 1156 + 0 + 51 + 31 + + + + + Segoe MDL2 Assets + -1 + + + + border: none; +font-size: 14px; + + + + + + true + + + + + + 1101 + 0 + 51 + 31 + + + + + Segoe MDL2 Assets + -1 + + + + border: none; +font-size: 14px; + + + + + + true + + - + + + closeButton + clicked() + MainWindow + close() + + + 1186 + 10 + + + 602 + 330 + + + + + minimizeButton + clicked() + MainWindow + showMinimized() + + + 1126 + 15 + + + 602 + 330 + + + +