aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src-qt5/core-utils/lumina-config/AppDialog.h40
-rw-r--r--src-qt5/core-utils/lumina-config/AppDialog.ui42
-rw-r--r--src-qt5/core-utils/lumina-config/pages/page_defaultapps.cpp195
-rw-r--r--src-qt5/core-utils/lumina-config/pages/page_defaultapps.h6
-rw-r--r--src-qt5/core-utils/lumina-config/pages/page_interface_panels.cpp35
-rw-r--r--src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp34
-rw-r--r--src-qt5/desktop-utils/lumina-screenshot/MainUI.h2
7 files changed, 166 insertions, 188 deletions
diff --git a/src-qt5/core-utils/lumina-config/AppDialog.h b/src-qt5/core-utils/lumina-config/AppDialog.h
index ea7615e2..2b03fc76 100644
--- a/src-qt5/core-utils/lumina-config/AppDialog.h
+++ b/src-qt5/core-utils/lumina-config/AppDialog.h
@@ -23,13 +23,22 @@ private:
Ui::AppDialog *ui;
public:
- AppDialog(QWidget *parent = 0) : QDialog(parent), ui(new Ui::AppDialog){
+ AppDialog(QWidget *parent = 0, QString defaultPath = "") : QDialog(parent), ui(new Ui::AppDialog){
ui->setupUi(this); //load the designer file
appreset = false;
- ui->comboBox->clear();
+ ui->listApps->clear();
+ QListWidgetItem *defaultItem = nullptr;
QList<XDGDesktop*> APPS = LXDG::sortDesktopNames(APPSLIST->apps(false,false)); //Don't show all/hidden
for(int i=0; i<APPS.length(); i++){
- ui->comboBox->addItem( LXDG::findIcon(APPS[i]->icon,"application-x-executable"), APPS[i]->name, APPS[i]->filePath);
+ QListWidgetItem *app = new QListWidgetItem(LXDG::findIcon(APPS[i]->icon,"application-x-executable"), APPS[i]->name);
+ app->setData(Qt::UserRole, APPS[i]->filePath);
+ ui->listApps->addItem(app);
+ if(APPS[i]->filePath == defaultPath){
+ defaultItem = app;
+ }
+ }
+ if(ui->listApps->count()){
+ ui->listApps->setCurrentItem(defaultItem != nullptr ? defaultItem : ui->listApps->item(0));
}
this->setWindowIcon( LXDG::findIcon("system-search","") );
if(parent!=0){
@@ -56,7 +65,10 @@ public:
private slots:
void on_buttonBox_accepted(){
- appselected = ui->comboBox->currentData().toString();
+ QListWidgetItem *item = ui->listApps->currentItem();
+ if(item != nullptr){
+ appselected = item->data(Qt::UserRole).toString();
+ }
this->close();
}
void on_buttonBox_rejected(){
@@ -68,6 +80,26 @@ private slots:
this->close();
}
}
+ void on_listApps_itemDoubleClicked(QListWidgetItem *item){
+ appselected = item->data(Qt::UserRole).toString();
+ this->close();
+ }
+ void on_lineSearch_textChanged(const QString &term){
+ QListWidgetItem *first_visible = nullptr;
+ for(int i = 0; i < ui->listApps->count(); i++){
+ QListWidgetItem *item = ui->listApps->item(i);
+ bool visible = item->text().contains(term, Qt::CaseInsensitive);
+ item->setHidden(!visible);
+ if(visible && first_visible == nullptr){
+ first_visible = item;
+ }
+ }
+ //Select the first app
+ ui->listApps->setCurrentItem(first_visible);
+ if(first_visible != nullptr){
+ ui->listApps->scrollToItem(first_visible);
+ }
+ }
};
#endif
diff --git a/src-qt5/core-utils/lumina-config/AppDialog.ui b/src-qt5/core-utils/lumina-config/AppDialog.ui
index 63323f7d..ec7de974 100644
--- a/src-qt5/core-utils/lumina-config/AppDialog.ui
+++ b/src-qt5/core-utils/lumina-config/AppDialog.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>348</width>
- <height>91</height>
+ <height>300</height>
</rect>
</property>
<property name="windowTitle">
@@ -15,46 +15,14 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
- <spacer name="verticalSpacer_2">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QComboBox" name="comboBox">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="iconSize">
- <size>
- <width>32</width>
- <height>32</height>
- </size>
+ <widget class="QLineEdit" name="lineSearch">
+ <property name="placeholderText">
+ <string>Search for....</string>
</property>
</widget>
</item>
<item>
- <spacer name="verticalSpacer">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>40</height>
- </size>
- </property>
- </spacer>
+ <widget class="QListWidget" name="listApps"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
diff --git a/src-qt5/core-utils/lumina-config/pages/page_defaultapps.cpp b/src-qt5/core-utils/lumina-config/pages/page_defaultapps.cpp
index b2a0896c..a21653c9 100644
--- a/src-qt5/core-utils/lumina-config/pages/page_defaultapps.cpp
+++ b/src-qt5/core-utils/lumina-config/pages/page_defaultapps.cpp
@@ -42,92 +42,23 @@ void page_defaultapps::LoadSettings(int){
emit HasPendingChanges(false);
emit ChangePageTitle( tr("Default Applications") );
-//First load the lumina-open specific defaults
- // - Default File Manager
- QString tmp = LXDG::findDefaultAppForMime("inode/directory");
- if(tmp.isEmpty()){ tmp = "lumina-fm"; }
- if( !QFile::exists(tmp) && !LUtils::isValidBinary(tmp) ){ qDebug() << "Invalid Settings:" << tmp; tmp.clear(); } //invalid settings
- if(tmp.endsWith(".desktop")){
- XDGDesktop file(tmp);
- if(file.type == XDGDesktop::BAD){
- //Might be a binary - just print out the raw "path"
- ui->tool_default_filemanager->setText(tmp.section("/",-1));
- ui->tool_default_filemanager->setIcon( LXDG::findIcon("application-x-executable","") );
- }else{
- ui->tool_default_filemanager->setText(file.name);
- ui->tool_default_filemanager->setIcon(LXDG::findIcon(file.icon,"") );
- }
- }else if(tmp.isEmpty()){
- ui->tool_default_filemanager->setText(tr("Click to Set"));
- ui->tool_default_filemanager->setIcon( LXDG::findIcon("system-help","") );
- }else{
- //Might be a binary - just print out the raw "path"
- ui->tool_default_filemanager->setText(tmp.section("/",-1));
- ui->tool_default_filemanager->setIcon( LXDG::findIcon("application-x-executable","") );
- }
+ //First load the lumina-open specific defaults
+ // - Default File Manager
+ defaultFileManager = LXDG::findDefaultAppForMime("inode/directory");
+ if(defaultFileManager.isEmpty()){ defaultFileManager = "lumina-fm"; }
+ updateDefaultButton(ui->tool_default_filemanager, defaultFileManager);
+
// - Default Terminal
- tmp =LXDG::findDefaultAppForMime("application/terminal"); //sessionsettings->value("default-terminal", "xterm").toString();
- if( !QFile::exists(tmp) && !LUtils::isValidBinary(tmp) ){ qDebug() << "Invalid Settings:" << tmp; tmp.clear(); } //invalid settings
- if(tmp.endsWith(".desktop")){
- XDGDesktop file(tmp);
- if(file.type == XDGDesktop::BAD){
- //Might be a binary - just print out the raw "path"
- ui->tool_default_terminal->setText(tmp.section("/",-1));
- ui->tool_default_terminal->setIcon( LXDG::findIcon("application-x-executable","") );
- }else{
- ui->tool_default_terminal->setText(file.name);
- ui->tool_default_terminal->setIcon(LXDG::findIcon(file.icon,"") );
- }
- }else if(tmp.isEmpty()){
- ui->tool_default_terminal->setText(tr("Click to Set"));
- ui->tool_default_terminal->setIcon( LXDG::findIcon("system-help","") );
- }else{
- //Might be a binary - just print out the raw "path"
- ui->tool_default_terminal->setText(tmp.section("/",-1));
- ui->tool_default_terminal->setIcon( LXDG::findIcon("application-x-executable","") );
- }
+ defaultTerminal = LXDG::findDefaultAppForMime("application/terminal"); //sessionsettings->value("default-terminal", "xterm").toString();
+ updateDefaultButton(ui->tool_default_terminal, defaultTerminal);
+
// - Default Web Browser
- tmp = LXDG::findDefaultAppForMime("x-scheme-handler/http"); //appsettings->value("default/webbrowser", "").toString();
- if( !QFile::exists(tmp) && !LUtils::isValidBinary(tmp) ){ qDebug() << "Invalid Settings:" << tmp; tmp.clear(); } //invalid settings
- if(tmp.endsWith(".desktop")){
- XDGDesktop file(tmp);
- if(file.type == XDGDesktop::BAD){
- //Might be a binary - just print out the raw "path"
- ui->tool_default_webbrowser->setText(tmp.section("/",-1));
- ui->tool_default_webbrowser->setIcon( LXDG::findIcon("application-x-executable","") );
- }else{
- ui->tool_default_webbrowser->setText(file.name);
- ui->tool_default_webbrowser->setIcon(LXDG::findIcon(file.icon,"") );
- }
- }else if(tmp.isEmpty()){
- ui->tool_default_webbrowser->setText(tr("Click to Set"));
- ui->tool_default_webbrowser->setIcon( LXDG::findIcon("system-help","") );
- }else{
- //Might be a binary - just print out the raw "path"
- ui->tool_default_webbrowser->setText(tmp.section("/",-1));
- ui->tool_default_webbrowser->setIcon( LXDG::findIcon("application-x-executable","") );
- }
+ defaultBrowser = LXDG::findDefaultAppForMime("x-scheme-handler/http"); //appsettings->value("default/webbrowser", "").toString();
+ updateDefaultButton(ui->tool_default_webbrowser, defaultBrowser);
+
// - Default Email Client
- tmp = LXDG::findDefaultAppForMime("application/email"); //appsettings->value("default/email", "").toString();
- if( !QFile::exists(tmp) && !LUtils::isValidBinary(tmp) ){ qDebug() << "Invalid Settings:" << tmp; tmp.clear(); } //invalid settings
- if(tmp.endsWith(".desktop")){
- XDGDesktop file(tmp);
- if(file.type == XDGDesktop::BAD){
- //Might be a binary - just print out the raw "path"
- ui->tool_default_email->setText(tmp.section("/",-1));
- ui->tool_default_email->setIcon( LXDG::findIcon("application-x-executable","") );
- }else{
- ui->tool_default_email->setText(file.name);
- ui->tool_default_email->setIcon(LXDG::findIcon(file.icon,"") );
- }
- }else if(tmp.isEmpty()){
- ui->tool_default_email->setText(tr("Click to Set"));
- ui->tool_default_email->setIcon( LXDG::findIcon("system-help","") );
- }else{
- //Might be a binary - just print out the raw "path"
- ui->tool_default_email->setText(tmp.section("/",-1));
- ui->tool_default_email->setIcon( LXDG::findIcon("application-x-executable","") );
- }
+ defaultEmail = LXDG::findDefaultAppForMime("application/email"); //appsettings->value("default/email", "").toString();
+ updateDefaultButton(ui->tool_default_email, defaultEmail);
//Now load the XDG mime defaults
ui->tree_defaults->clear();
@@ -135,7 +66,7 @@ void page_defaultapps::LoadSettings(int){
//qDebug() << "Mime List:\n" << defMimeList.join("\n");
defMimeList.sort(); //sort by group/mime
//Now fill the tree by group/mime
- QTreeWidgetItem *group = new QTreeWidgetItem(0); //nothing at the moment
+ QTreeWidgetItem *group = nullptr;
QString ccat;
for(int i=0; i<defMimeList.length(); i++){
//Get the info from this entry
@@ -145,37 +76,38 @@ void page_defaultapps::LoadSettings(int){
QString def = defMimeList[i].section("::::",2,2);
QString comment = defMimeList[i].section("::::",3,50);
//Now check if this is a new category
- if(ccat!=cat){
- //New group
- group = new QTreeWidgetItem(0);
+ if(group == nullptr || ccat!=cat){
+ //New group
+ group = new QTreeWidgetItem(0);
group->setText(0, cat); //add translations for known/common groups later
- ui->tree_defaults->addTopLevelItem(group);
- ccat = cat;
+ ui->tree_defaults->addTopLevelItem(group);
+ ccat = cat;
}
//Now create the entry
QTreeWidgetItem *it = new QTreeWidgetItem();
- it->setWhatsThis(0,mime); // full mimetype
- it->setText(0, QString(tr("%1 (%2)")).arg(mime.section("/",-1), extlist) );
- it->setText(2,comment);
- it->setToolTip(0, comment); it->setToolTip(1,comment);
- //Now load the default (if there is one)
- it->setWhatsThis(1,def); //save for later
- if(def.endsWith(".desktop")){
- XDGDesktop file(def);
- if(file.type == XDGDesktop::BAD){
- //Might be a binary - just print out the raw "path"
- it->setText(1,def.section("/",-1));
- it->setIcon(1, LXDG::findIcon("application-x-executable","") );
- }else{
- it->setText(1, file.name);
- it->setIcon(1, LXDG::findIcon(file.icon,"") );
- }
- }else if(!def.isEmpty()){
- //Binary/Other default
- it->setText(1, def.section("/",-1));
- it->setIcon(1, LXDG::findIcon("application-x-executable","") );
+ it->setWhatsThis(0,mime); // full mimetype
+ it->setText(0, QString(tr("%1 (%2)")).arg(mime.section("/",-1), extlist) );
+ it->setText(2,comment);
+ it->setToolTip(0, comment); it->setToolTip(1,comment);
+ //Now load the default (if there is one)
+ it->setWhatsThis(1,def); //save for later
+ it->setData(1, Qt::UserRole, def);
+ if(def.endsWith(".desktop")){
+ XDGDesktop file(def);
+ if(file.type == XDGDesktop::BAD){
+ //Might be a binary - just print out the raw "path"
+ it->setText(1, def.section("/",-1));
+ it->setIcon(1, LXDG::findIcon("application-x-executable","") );
+ }else{
+ it->setText(1, file.name);
+ it->setIcon(1, LXDG::findIcon(file.icon,"") );
}
- group->addChild(it);
+ }else if(!def.isEmpty()){
+ //Binary/Other default
+ it->setText(1, def.section("/",-1));
+ it->setIcon(1, LXDG::findIcon("application-x-executable","") );
+ }
+ group->addChild(it);
}
ui->tree_defaults->sortItems(0,Qt::AscendingOrder);
@@ -194,8 +126,8 @@ void page_defaultapps::updateIcons(){
//=================
// PRIVATE
//=================
-QString page_defaultapps::getSysApp(bool allowreset){
- AppDialog dlg(this);
+QString page_defaultapps::getSysApp(bool allowreset, QString defaultPath){
+ AppDialog dlg(this, defaultPath);
dlg.allowReset(allowreset);
dlg.exec();
if(dlg.appreset && allowreset){
@@ -206,6 +138,7 @@ QString page_defaultapps::getSysApp(bool allowreset){
}
void page_defaultapps::updateDefaultButton(QToolButton *button, QString app){
+ if( !QFile::exists(app) && !LUtils::isValidBinary(app) ){ qDebug() << "Invalid Settings:" << app; app.clear(); } //invalid settings
if(app.endsWith(".desktop")){
XDGDesktop file(app);
if(file.type == XDGDesktop::BAD){
@@ -231,10 +164,11 @@ void page_defaultapps::updateDefaultButton(QToolButton *button, QString app){
//=================
void page_defaultapps::changeDefaultBrowser(){
//Prompt for the new app
- QString app = getSysApp(true);
- if(app.isEmpty()){ return; }//nothing selected
- if(app=="reset"){ app.clear(); }
+ QString app = getSysApp(true, defaultBrowser);
+ if(app.isEmpty()){ return; }//nothing selected
+ if(app=="reset"){ app.clear(); }
//save the new app setting and adjust the button appearance
+ defaultBrowser = app;
LXDG::setDefaultAppForMime("x-scheme-handler/http", app.section("/",-1));
LXDG::setDefaultAppForMime("x-scheme-handler/https", app.section("/",-1));
updateDefaultButton(ui->tool_default_webbrowser, app);
@@ -242,30 +176,33 @@ void page_defaultapps::changeDefaultBrowser(){
void page_defaultapps::changeDefaultEmail(){
//Prompt for the new app
- QString app = getSysApp(true);
- if(app.isEmpty()){ return; }//nothing selected
- if(app=="reset"){ app.clear(); }
+ QString app = getSysApp(true, defaultEmail);
+ if(app.isEmpty()){ return; }//nothing selected
+ if(app=="reset"){ app.clear(); }
//save the new app setting and adjust the button appearance
+ defaultEmail = app;
LXDG::setDefaultAppForMime("application/email",app.section("/",-1));
updateDefaultButton(ui->tool_default_email, app);
}
void page_defaultapps::changeDefaultFileManager(){
//Prompt for the new app
- QString app = getSysApp(true);
- if(app.isEmpty()){ return; }//nothing selected
- if(app=="reset"){ app = "lumina-fm"; }
+ QString app = getSysApp(true, defaultFileManager);
+ if(app.isEmpty()){ return; }//nothing selected
+ if(app=="reset"){ app = "lumina-fm"; }
//save the new app setting and adjust the button appearance
+ defaultFileManager = app;
LXDG::setDefaultAppForMime("inode/directory", app.section("/",-1));
updateDefaultButton(ui->tool_default_filemanager, app);
}
void page_defaultapps::changeDefaultTerminal(){
//Prompt for the new app
- QString app = getSysApp(true);
- if(app.isEmpty()){ return; }//nothing selected
- if(app=="reset"){ app = "xterm"; }
+ QString app = getSysApp(true, defaultTerminal);
+ if(app.isEmpty()){ return; }//nothing selected
+ if(app=="reset"){ app = "xterm"; }
//save the new app setting and adjust the button appearance
+ defaultTerminal = app;
LXDG::setDefaultAppForMime("application/terminal", app.section("/",-1) );
updateDefaultButton(ui->tool_default_terminal, app);
}
@@ -292,14 +229,19 @@ void page_defaultapps::cleardefaultitem(){
void page_defaultapps::setdefaultitem(){
QTreeWidgetItem *it = ui->tree_defaults->currentItem();
+ QString path;
if(it==0){ return; } //no item selected
QList<QTreeWidgetItem*> list;
for(int i=0; i<it->childCount(); i++){
list << it->child(i);
}
- if(list.isEmpty()){ list << it; } //just do the current item
+ if(list.isEmpty()){
+ //just do the current item
+ list << it;
+ path = it->data(1, Qt::UserRole).toString();
+ }
//Prompt for which application to use
- QString app = getSysApp(false); //no "reset" option
+ QString app = getSysApp(false, path); //no "reset" option
if(app.isEmpty()){ return; }//nothing selected
//Now set the items
for(int i=0; i<list.length(); i++){
@@ -310,6 +252,7 @@ void page_defaultapps::setdefaultitem(){
list[i]->setWhatsThis(1,app); //app path
list[i]->setIcon(1,LXDG::findIcon(desk.icon,"")); //reset the icon
list[i]->setText(1,desk.name); //reset the name
+ list[i]->setData(1, Qt::UserRole, app);
}
}
diff --git a/src-qt5/core-utils/lumina-config/pages/page_defaultapps.h b/src-qt5/core-utils/lumina-config/pages/page_defaultapps.h
index f80ea1ab..d8e2bcde 100644
--- a/src-qt5/core-utils/lumina-config/pages/page_defaultapps.h
+++ b/src-qt5/core-utils/lumina-config/pages/page_defaultapps.h
@@ -26,8 +26,12 @@ public slots:
private:
Ui::page_defaultapps *ui;
+ QString defaultBrowser;
+ QString defaultEmail;
+ QString defaultFileManager;
+ QString defaultTerminal;
- QString getSysApp(bool allowreset);
+ QString getSysApp(bool allowreset, QString defaultPath = "");
void updateDefaultButton(QToolButton *button, QString app);
diff --git a/src-qt5/core-utils/lumina-config/pages/page_interface_panels.cpp b/src-qt5/core-utils/lumina-config/pages/page_interface_panels.cpp
index 827061af..3c355aa7 100644
--- a/src-qt5/core-utils/lumina-config/pages/page_interface_panels.cpp
+++ b/src-qt5/core-utils/lumina-config/pages/page_interface_panels.cpp
@@ -21,6 +21,13 @@ page_interface_panels::page_interface_panels(QWidget *parent) : PageWidget(paren
connect(ui->tool_panels_add, SIGNAL(clicked()), this, SLOT(newPanel()) );
updateIcons();
setupProfiles();
+
+ //Create panels container
+ QHBoxLayout *panels_layout = new QHBoxLayout();
+ panels_layout->setContentsMargins(0,0,0,0);
+ panels_layout->setAlignment(Qt::AlignLeft);
+ panels_layout->addStretch();
+ ui->scroll_panels->widget()->setLayout(panels_layout);
}
page_interface_panels::~page_interface_panels(){
@@ -53,28 +60,30 @@ void page_interface_panels::LoadSettings(int screennum){
QString screenID = QApplication::screens().at(cscreen)->name();
QString DPrefix = "desktop-"+screenID+"/";
int panelnumber = settings->value(DPrefix+"panels",-1).toInt();
+ QBoxLayout *panels_layout = static_cast<QHBoxLayout*>(ui->scroll_panels->widget()->layout());
-//First clean any current panels
- for(int i=0; i<PANELS.length(); i++){ delete PANELS.takeAt(i); i--; }
- //Now create new panels
- if(ui->scroll_panels->widget()->layout()==0){
- ui->scroll_panels->widget()->setLayout( new QHBoxLayout() );
- ui->scroll_panels->widget()->layout()->setContentsMargins(0,0,0,0);
+ //Remove extra panels (if any)
+ for(int i=panelnumber; i<PANELS.length(); i++){
+ PanelWidget *tmp = PANELS.takeAt(i);
+ delete tmp;
+ i--;
}
- ui->scroll_panels->widget()->layout()->setAlignment(Qt::AlignLeft);
- //Clear anything left over in the layout
- for(int i=0; i<ui->scroll_panels->widget()->layout()->count(); i++){
- delete ui->scroll_panels->widget()->layout()->takeAt(i);
+
+ int current_count = panels_layout->count()-1;
+
+ //Update current panels
+ for(int i=0; i<current_count; i++) {
+ PANELS[i]->LoadSettings(settings, cscreen, i);
}
- for(int i=0; i<panelnumber; i++){
+ //Create new panels
+ for(int i=current_count; i<panelnumber; i++){
PanelWidget *tmp = new PanelWidget(ui->scroll_panels->widget(), this, PINFO);
tmp->LoadSettings(settings, cscreen, i);
PANELS << tmp;
connect(tmp, SIGNAL(PanelChanged()), this, SLOT(panelValChanged()) );
connect(tmp, SIGNAL(PanelRemoved(int)), this, SLOT(removePanel(int)) );
- ui->scroll_panels->widget()->layout()->addWidget(tmp);
+ panels_layout->insertWidget(panels_layout->count()-1, tmp);
}
- static_cast<QHBoxLayout*>(ui->scroll_panels->widget()->layout())->addStretch();
QApplication::processEvents();
loading = false;
diff --git a/src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp b/src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp
index 2c5dc700..25f4cc62 100644
--- a/src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp
+++ b/src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp
@@ -11,10 +11,13 @@
#include <QMessageBox>
#include <QClipboard>
-MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){
+MainUI::MainUI()
+ : QMainWindow(), ui(new Ui::MainUI),
+ mousegrabbed(false),
+ picSaved(false),
+ closeOnSave(false)
+{
ui->setupUi(this); //load the designer file
- mousegrabbed = false;
- picSaved = false;
XCB = new LXCB();
IMG = new ImageEditor(this);
ui->scrollArea->setWidget(IMG);
@@ -96,13 +99,22 @@ void MainUI::showSaveError(QString path){
void MainUI::saveScreenshot(){
if(mousegrabbed){ return; }
QString filepath = QFileDialog::getSaveFileName(this, tr("Save Screenshot"), ppath+"/"+QString( "Screenshot-%1.png" ).arg( lastScreenShot.toString("yyyy-MM-dd-hh-mm-ss")), tr("PNG Files (*.png);;AllFiles (*)") );
- if(filepath.isEmpty()){ return; }
+ if(filepath.isEmpty()){
+ closeOnSave = false;
+ return;
+ }
if(!filepath.endsWith(".png")){ filepath.append(".png"); }
if( !IMG->image().save(filepath, "png") ){
+ closeOnSave = false;
showSaveError(filepath);
}else{
picSaved = true;
ppath = filepath.section("/",0,-2); //just the directory
+ if (closeOnSave) {
+ // We came here from close, now we need to close *after* handling
+ // the current screen event.
+ QTimer::singleShot(0, this, SLOT(close()));
+ }
}
}
@@ -249,8 +261,18 @@ 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
+ const int messageRet = QMessageBox::warning(this, tr("Unsaved Screenshot"),
+ tr("The current screenshot has not been saved yet. Do you want to save or discard your changes?"),
+ QMessageBox::Discard | QMessageBox::Save |QMessageBox::Cancel, QMessageBox::Cancel);
+ switch (messageRet) {
+ case QMessageBox::Discard:
+ // Just close, we don't care about the file.
+ break;
+ case QMessageBox::Save:
+ closeOnSave = true;
+ saveScreenshot();
+ // fall through
+ case QMessageBox::Cancel:
ev->ignore();
return;
}
diff --git a/src-qt5/desktop-utils/lumina-screenshot/MainUI.h b/src-qt5/desktop-utils/lumina-screenshot/MainUI.h
index 5ff496a5..4a18ef74 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, picSaved;
+ bool mousegrabbed, picSaved, closeOnSave;
QRect lastgeom;
QString ppath; //previous file path
WId cwin; //current window to screenshot
bgstack15