From dd9179e59a699f096f8373a6ae56c91f303b14b6 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Mon, 23 Jan 2017 12:50:27 -0500 Subject: Add a check/warning when closing the screenshot tool when the current screenshot has not been saved to disk yet. Also add an option to the settings tab to turn off that popup warning as desired. --- src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp | 25 +- src-qt5/desktop-utils/lumina-screenshot/MainUI.h | 4 +- src-qt5/desktop-utils/lumina-screenshot/MainUI.ui | 277 ++++++++++++--------- 3 files changed, 193 insertions(+), 113 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-screenshot') diff --git a/src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp b/src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp index 57314249..40c9857b 100644 --- a/src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp +++ b/src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp @@ -14,6 +14,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ ui->setupUi(this); //load the designer file mousegrabbed = false; + picSaved = false; XCB = new LXCB(); IMG = new ImageEditor(this); ui->scrollArea->setWidget(IMG); @@ -51,7 +52,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ connect(ui->slider_zoom, SIGNAL(valueChanged(int)), this, SLOT(sliderChanged()) ); connect(scaleTimer, SIGNAL(timeout()), this, SLOT(imgScalingChanged()) ); connect(tabbar, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)) ); - + connect(ui->check_show_popups, SIGNAL(toggled(bool)), this, SLOT(showPopupsChanged(bool)) ); settings = new QSettings("lumina-desktop", "lumina-screenshot",this); if(settings->value("screenshot-target", "window").toString() == "window") { ui->radio_window->setChecked(true); @@ -59,6 +60,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){ ui->radio_all->setChecked(true); } ui->spin_delay->setValue(settings->value("screenshot-delay", 0).toInt()); + ui->check_show_popups->setChecked( settings->value("showPopupWarnings",true).toBool() ); ui->tool_resize->setVisible(false); //not implemented yet this->show(); @@ -99,6 +101,7 @@ void MainUI::saveScreenshot(){ if( !IMG->image().save(filepath, "png") ){ showSaveError(filepath); }else{ + picSaved = true; ppath = filepath.section("/",0,-2); //just the directory } } @@ -111,10 +114,12 @@ void MainUI::quicksave(){ QString path = savedir + QString( "Screenshot-%1.png" ).arg( lastScreenShot.toString("yyyy-MM-dd-hh-mm-ss") ); if(IMG->image().save(path, "png") ){ + picSaved = true; QProcess::startDetached("lumina-open -select \""+path+"\""); }else{ showSaveError(path); } + } void MainUI::startScreenshot(){ @@ -152,6 +157,10 @@ void MainUI::tabChanged(int tab){ ui->frame_modify->setVisible(tab==0); } +void MainUI::showPopupsChanged(bool show){ + settings->setValue("showPopupWarnings", show); +} + bool MainUI::getWindow(){ //Use this function to set cwin cwin = 0; @@ -194,6 +203,7 @@ void MainUI::getPixmap(){ this->setGeometry(lastgeom); lastScreenShot = QDateTime::currentDateTime(); //Now display the pixmap on the label as well + picSaved = false; IMG->LoadImage( cpic.toImage() ); } @@ -228,3 +238,16 @@ void MainUI::mouseReleaseEvent(QMouseEvent *ev){ void MainUI::resizeEvent(QResizeEvent*){ IMG->setDefaultSize( ui->scrollArea->maximumViewportSize() ); } + +void MainUI::closeEvent(QCloseEvent *ev){ + //qDebug() << "Close Event:" << ui->check_show_popups->isChecked() << picSaved; + if(ui->check_show_popups->isChecked() && !picSaved){ + //Ask what to do about the unsaved changed + if(QMessageBox::Yes != QMessageBox::warning(this, tr("Unsaved Screenshot"), tr("The current screenshot has not been saved yet. Do you want to quit anyway?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) ){ + //cancelled close of window + ev->ignore(); + return; + } + } + QMainWindow::closeEvent(ev); +} diff --git a/src-qt5/desktop-utils/lumina-screenshot/MainUI.h b/src-qt5/desktop-utils/lumina-screenshot/MainUI.h index cb740d33..396bfafe 100644 --- a/src-qt5/desktop-utils/lumina-screenshot/MainUI.h +++ b/src-qt5/desktop-utils/lumina-screenshot/MainUI.h @@ -41,7 +41,7 @@ public slots: private: Ui::MainUI *ui; - bool mousegrabbed; + bool mousegrabbed, picSaved; QRect lastgeom; QString ppath; //previous file path WId cwin; //current window to screenshot @@ -71,6 +71,7 @@ private slots: void sliderChanged(); void tabChanged(int); + void showPopupsChanged(bool); //Utility functions to perform a screenshot bool getWindow(); //set the "cwin" variable as appropriate @@ -79,6 +80,7 @@ private slots: protected: void mouseReleaseEvent(QMouseEvent *ev); void resizeEvent(QResizeEvent *ev); + void closeEvent( QCloseEvent *ev); }; #endif diff --git a/src-qt5/desktop-utils/lumina-screenshot/MainUI.ui b/src-qt5/desktop-utils/lumina-screenshot/MainUI.ui index 5e3aabb4..cddee009 100644 --- a/src-qt5/desktop-utils/lumina-screenshot/MainUI.ui +++ b/src-qt5/desktop-utils/lumina-screenshot/MainUI.ui @@ -244,121 +244,176 @@ QLayout::SetMinimumSize - - - 0 + + + Screen Capture Settings - - QLayout::SetMinimumSize - - - - - - 0 - 0 - - - - Entire Session - - - - - - - - 0 - 0 - - - - Sec Delay - - - - - - 20 - - - - - - - - - 0 - - - QLayout::SetMinimumSize - - - - - - 0 - 0 - - - - Single Screen - - - - - - - - 0 - 0 - - - - # - - - 1 - - - - + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + 0 + + + QLayout::SetMinimumSize + + + + + + 0 + 0 + + + + Entire Session + + + + + + + + 0 + 0 + + + + Sec Delay + + + + + + 20 + + + + + + + + + 0 + + + QLayout::SetMinimumSize + + + + + + 0 + 0 + + + + Single Screen + + + + + + + + 0 + 0 + + + + # + + + 1 + + + + + + + + + 0 + + + QLayout::SetMinimumSize + + + + + + 0 + 0 + + + + Single Window + + + + + + + + 0 + 0 + + + + Include Borders + + + + + + + - - - 0 + + + General Settings - - QLayout::SetMinimumSize - - - - - - 0 - 0 - - - - Single Window - - - - - - - - 0 - 0 - - - - Include Borders - - - - + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + + + Show popup warnings about unsaved screenshots + + + + + -- cgit