From 5ec4f51601bcdf369ac66100f6cfbca579d1d2af Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 2 Feb 2016 12:05:33 +0200 Subject: [PATCH] Grab user attention if measurements was changed. Related to issue #440. --HG-- branch : develop --- ChangeLog.txt | 1 + src/app/valentina/mainwindow.cpp | 30 +++++++++++++++++++++++++++++- src/app/valentina/mainwindow.h | 2 ++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 0ca732c63..c775aa8c0 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1,4 +1,5 @@ # Version 0.5.0 +- Show additional message dialog if measurements was changed. Related to issue [#440]. - [#132] Intersect Curves. - Added language Chinese (China). - New icon for VAL file. Updated Tape logo. Updated ico for standard measurements. diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index d9aaeb147..e6255c045 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -98,7 +98,8 @@ const QString autosavePrefix = QStringLiteral(".autosave"); MainWindow::MainWindow(QWidget *parent) :MainWindowsNoGUI(parent), ui(new Ui::MainWindow), watcher(new QFileSystemWatcher(this)), currentTool(Tool::Arrow), lastUsedTool(Tool::Arrow), sceneDraw(nullptr), sceneDetails(nullptr), - mouseCoordinate(nullptr), helpLabel(nullptr), isInitialized(false), mChanges(false), patternReadOnly(false), + mouseCoordinate(nullptr), helpLabel(nullptr), isInitialized(false), mChanges(false), mChangesAsked(true), + patternReadOnly(false), dialogTable(nullptr), dialogTool(nullptr), dialogHistory(nullptr), comboBoxDraws(nullptr), patternPieceLabel(nullptr), mode(Draw::Calculation), @@ -150,6 +151,7 @@ MainWindow::MainWindow(QWidget *parent) ui->dockWidgetLayoutPages->setVisible(false); connect(watcher, &QFileSystemWatcher::fileChanged, this, &MainWindow::MeasurementsChanged); + connect(qApp, &QApplication::focusChanged, this, &MainWindow::OnWindowFocusChanged); #if defined(Q_OS_MAC) // On Mac deafault icon size is 32x32. @@ -1358,6 +1360,7 @@ void MainWindow::MeasurementsChanged(const QString &path) if (checkFile.exists()) { mChanges = true; + mChangesAsked = false; } else { @@ -1366,6 +1369,7 @@ void MainWindow::MeasurementsChanged(const QString &path) if (checkFile.exists()) { mChanges = true; + mChangesAsked = false; break; } else @@ -1397,6 +1401,7 @@ void MainWindow::SyncMeasurements() VWidgetPopup::PopupMessage(this, msg); doc->LiteParseTree(Document::LiteParse); mChanges = false; + mChangesAsked = true; UpdateWindowTitle(); ui->actionSyncMeasurements->setEnabled(mChanges); } @@ -1407,6 +1412,29 @@ void MainWindow::SyncMeasurements() } } +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::OnWindowFocusChanged(QWidget *old, QWidget *now) +{ + if (old == nullptr && isAncestorOf(now) == true) + {// focus IN + if (mChanges && not mChangesAsked) + { + const auto answer = QMessageBox::question(this, tr("Measurements"), + tr("Measurements was changed. Do you want to sync measurements now?"), + QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes); + if (answer == QMessageBox::Yes) + { + SyncMeasurements(); + } + mChangesAsked = true; + } + } + + // In case we will need it + // else if (isAncestorOf(old) == true && now == nullptr) + // focus OUT +} + //--------------------------------------------------------------------------------------------------------------------- #if defined(Q_OS_MAC) void MainWindow::OpenAt(QAction *where) diff --git a/src/app/valentina/mainwindow.h b/src/app/valentina/mainwindow.h index 4bb5e4b86..17d776d30 100644 --- a/src/app/valentina/mainwindow.h +++ b/src/app/valentina/mainwindow.h @@ -172,6 +172,7 @@ private slots: void ShowMeasurements(); void MeasurementsChanged(const QString &path); void SyncMeasurements(); + void OnWindowFocusChanged(QWidget* old, QWidget* now); #if defined(Q_OS_MAC) void OpenAt(QAction *where); #endif //defined(Q_OS_MAC) @@ -209,6 +210,7 @@ private: /** @brief mChanges true if measurement file was changed. */ bool mChanges; + bool mChangesAsked; bool patternReadOnly;