aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp')
-rw-r--r--src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp50
1 files changed, 43 insertions, 7 deletions
diff --git a/src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp b/src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp
index 83940c93..ac17ee3e 100644
--- a/src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp
+++ b/src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp
@@ -8,6 +8,8 @@
#include "ui_MainUI.h"
#include <LuminaX11.h>
+#include <QMessageBox>
+
MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){
ui->setupUi(this); //load the designer file
@@ -17,13 +19,16 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){
ui->scrollArea->setWidget(IMG);
ui->tabWidget->setCurrentWidget(ui->tab_view);
ppath = QDir::homePath();
-
+ ui->label_zoom_percent->setMinimumWidth( ui->label_zoom_percent->fontMetrics().width("200%") );
setupIcons();
ui->spin_monitor->setMaximum(QApplication::desktop()->screenCount());
if(ui->spin_monitor->maximum()<2){
ui->spin_monitor->setEnabled(false);
ui->radio_monitor->setEnabled(false);
}
+ scaleTimer = new QTimer(this);
+ scaleTimer->setSingleShot(true);
+ scaleTimer->setInterval(200); //~1/5 second
//Setup the connections
connect(ui->tool_save, SIGNAL(clicked()), this, SLOT(saveScreenshot()) );
@@ -35,6 +40,9 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){
connect(ui->actionTake_Screenshot, SIGNAL(triggered()), this, SLOT(startScreenshot()) );
connect(ui->tool_crop, SIGNAL(clicked()), IMG, SLOT(cropImage()) );
connect(IMG, SIGNAL(selectionChanged(bool)), this, SLOT(imgselchanged(bool)) );
+ connect(IMG, SIGNAL(scaleFactorChanged(int)), this, SLOT(imgScalingChanged(int)) );
+ connect(ui->slider_zoom, SIGNAL(valueChanged(int)), this, SLOT(sliderChanged()) );
+ connect(scaleTimer, SIGNAL(timeout()), this, SLOT(imgScalingChanged()) );
settings = new QSettings("lumina-desktop", "lumina-screenshot",this);
if(settings->value("screenshot-target", "window").toString() == "window") {
@@ -48,6 +56,7 @@ MainUI::MainUI() : QMainWindow(), ui(new Ui::MainUI){
this->show();
IMG->setDefaultSize(ui->scrollArea->maximumViewportSize());
IMG->LoadImage( QApplication::screens().at(0)->grabWindow(QApplication::desktop()->winId()).toImage() ); //initial screenshot
+ lastScreenShot = QDateTime::currentDateTime();
//ui->label_screenshot->setPixmap( cpic.scaled(ui->label_screenshot->size(), Qt::KeepAspectRatio, Qt::SmoothTransformation) );
}
@@ -69,26 +78,36 @@ void MainUI::setupIcons(){
//ui->actionEdit->setIcon( LXDG::findIcon("applications-graphics","") );
}
+void MainUI::showSaveError(QString path){
+ QMessageBox::warning(this, tr("Could not save screenshot"), tr("The screenshot could not be saved. Please check directory permissions or pick a different directory")+"\n\n"+path);
+}
//==============
// PRIVATE SLOTS
//==============
void MainUI::saveScreenshot(){
if(mousegrabbed){ return; }
- QString filepath = QFileDialog::getSaveFileName(this, tr("Save Screenshot"), ppath, tr("PNG Files (*.png);;AllFiles (*)") );
+ 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.endsWith(".png")){ filepath.append(".png"); }
- IMG->image().save(filepath, "png");
- ppath = filepath;
+ if( !IMG->image().save(filepath, "png") ){
+ showSaveError(filepath);
+ }else{
+ ppath = filepath.section("/",0,-2); //just the directory
+ }
}
+
void MainUI::quicksave(){
if(mousegrabbed){ return; }
QString savedir = QDir::homePath()+"/";
if(QFile::exists(savedir + "Pictures/")){ savedir.append("Pictures/"); }
else if(QFile::exists(savedir + "Images/")){ savedir.append("Images/"); }
- QString path = savedir + QString( "Screenshot-%1.png" ).arg( QDateTime::currentDateTime().toString("yyyy-MM-dd-hh-mm-ss") );
- IMG->image().save(path, "png");
- QProcess::startDetached("lumina-open \""+path+"\"");
+ QString path = savedir + QString( "Screenshot-%1.png" ).arg( lastScreenShot.toString("yyyy-MM-dd-hh-mm-ss") );
+ if(IMG->image().save(path, "png") ){
+ QProcess::startDetached("lumina-open \""+path+"\"");
+ }else{
+ showSaveError(path);
+ }
}
void MainUI::startScreenshot(){
@@ -104,6 +123,22 @@ void MainUI::imgselchanged(bool hassel){
ui->tool_resize->setEnabled(hassel);
}
+void MainUI::imgScalingChanged(int percent){
+ //qDebug() << "Scale Changed:" << percent;
+ if(percent<0){
+ //Changed by user interaction
+ IMG->setScaling(ui->slider_zoom->value());
+ }else{
+ ui->slider_zoom->setValue(percent);
+ }
+ ui->label_zoom_percent->setText( QString::number(ui->slider_zoom->value())+"%");
+}
+
+void MainUI::sliderChanged(){
+ ui->label_zoom_percent->setText( QString::number(ui->slider_zoom->value())+"%");
+ scaleTimer->start();
+}
+
bool MainUI::getWindow(){
//Use this function to set cwin
cwin = 0;
@@ -145,6 +180,7 @@ void MainUI::getPixmap(){
this->show();
this->setGeometry(lastgeom);
ui->tabWidget->setCurrentWidget(ui->tab_view); //view it right now
+ lastScreenShot = QDateTime::currentDateTime();
//Now display the pixmap on the label as well
IMG->LoadImage( cpic.toImage() );
}
bgstack15