From 5bedc7e5673928ff0424da1b2719f0d75f62a8cf Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Tue, 22 Nov 2016 15:45:14 -0500 Subject: Fix up the scaling options in the UI for lumina-screenshot. --- .../lumina-screenshot/ImageEditor.cpp | 31 ++++++-- .../desktop-utils/lumina-screenshot/ImageEditor.h | 5 +- src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp | 15 +++- src-qt5/desktop-utils/lumina-screenshot/MainUI.h | 2 + src-qt5/desktop-utils/lumina-screenshot/MainUI.ui | 83 +++++++++++++++++----- 5 files changed, 112 insertions(+), 24 deletions(-) (limited to 'src-qt5/desktop-utils/lumina-screenshot') diff --git a/src-qt5/desktop-utils/lumina-screenshot/ImageEditor.cpp b/src-qt5/desktop-utils/lumina-screenshot/ImageEditor.cpp index 7516f204..fa5a7318 100644 --- a/src-qt5/desktop-utils/lumina-screenshot/ImageEditor.cpp +++ b/src-qt5/desktop-utils/lumina-screenshot/ImageEditor.cpp @@ -27,6 +27,7 @@ void ImageEditor::LoadImage(QImage img){ this->update(); //trigger paint event selRect = QRect(); emit selectionChanged(false); + emit scaleFactorChanged(getScaleFactor()*100); } void ImageEditor::setDefaultSize(QSize sz){ @@ -53,24 +54,37 @@ QImage ImageEditor::image(){ return fullIMG; } +int ImageEditor::getScalingValue(){ + return (getScaleFactor() *100); +} + // === PRIVATE SLOTS === void ImageEditor::showMenu(){ contextMenu->popup(QCursor::pos()); } // === PUBLIC SLOTS === +void ImageEditor::setScaling(int perc){ + qreal sf = ((qreal) perc)/100.0; + if(sf<0.05){ sf = 0.05; } //5% minimum + else if(sf>2){ sf = 2.0; } //200% maximum + rescaleImage(sf); +} + void ImageEditor::scaleUp(int val){ qreal sf = getScaleFactor(); sf+= ((qreal) val)/100.0; if(sf>2){ sf = 2.0; } rescaleImage(sf); + emit scaleFactorChanged(sf*100); } void ImageEditor::scaleDown(int val){ qreal sf = getScaleFactor(); sf-= ((qreal) val)/100.0; - if(sf<0.1){ sf = 0.1; } + if(sf<0.05){ sf = 0.05; } rescaleImage(sf); + emit scaleFactorChanged(sf*100); } void ImageEditor::cropImage(){ @@ -81,6 +95,7 @@ void ImageEditor::cropImage(){ scaledIMG = fullIMG.scaled( defaultSize, Qt::KeepAspectRatio,Qt::SmoothTransformation); selRect = QRect(); emit selectionChanged(false); + emit scaleFactorChanged(getScaleFactor()*100); this->update(); //trigger paint event } @@ -94,28 +109,34 @@ void ImageEditor::resizeImage(){ void ImageEditor::mousePressEvent(QMouseEvent *ev){ selRect = QRect(); //reset it emit selectionChanged(false); - selPoint = ev->pos(); //widget-relative coords + if(scaledIMG.rect().contains(ev->pos())){ + selPoint = ev->pos(); //widget-relative coords + }else{ + selPoint = QPoint(); + } } void ImageEditor::mouseMoveEvent(QMouseEvent *ev){ - if( !this->geometry().contains(ev->pos()) ){ selRect = QRect(); } + if( selPoint.isNull() ){ return; } else if(selPoint.x() < ev->pos().x()){ if(selPoint.y() < ev->pos().y()){ //init point is upper-left corner - selRect = QRect(selPoint, ev->pos()); + selRect = QRect(selPoint, ev->pos()).intersected(scaledIMG.rect()); }else{ //init point is lower-left corner selRect.setBottomLeft(selPoint); selRect.setTopRight(ev->pos()); + selRect = selRect.intersected(scaledIMG.rect()); } }else{ if(selPoint.y() < ev->pos().y()){ //init point is upper-right corner selRect.setBottomLeft(ev->pos()); selRect.setTopRight(selPoint); + selRect = selRect.intersected(scaledIMG.rect()); }else{ //init point is lower-right corner - selRect = QRect(ev->pos(), selPoint); + selRect = QRect(ev->pos(), selPoint).intersected(scaledIMG.rect()); } } this->update(); diff --git a/src-qt5/desktop-utils/lumina-screenshot/ImageEditor.h b/src-qt5/desktop-utils/lumina-screenshot/ImageEditor.h index 58a16e56..869c49fc 100644 --- a/src-qt5/desktop-utils/lumina-screenshot/ImageEditor.h +++ b/src-qt5/desktop-utils/lumina-screenshot/ImageEditor.h @@ -28,6 +28,8 @@ public: bool hasSelection(); QImage image(); + int getScalingValue(); + private: QImage fullIMG, scaledIMG; //Note: the aspect ratio between the two images must be preserved!! QSize defaultSize; //for loading new images @@ -53,6 +55,7 @@ private slots: void showMenu(); public slots: + void setScaling(int perc); //10% <--> 200% range is valid void scaleUp(int val = 10); //10% change by default void scaleDown(int val = 10); //10% change by default @@ -67,6 +70,6 @@ protected: signals: void selectionChanged(bool); //true if there is a selection - + void scaleFactorChanged(int); }; #endif diff --git a/src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp b/src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp index 16e7c77b..9dd6c9d3 100644 --- a/src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp +++ b/src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp @@ -19,7 +19,7 @@ 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){ @@ -37,6 +37,8 @@ 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(imgScalingChanged()) ); settings = new QSettings("lumina-desktop", "lumina-screenshot",this); if(settings->value("screenshot-target", "window").toString() == "window") { @@ -117,6 +119,17 @@ 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())+"%"); +} + bool MainUI::getWindow(){ //Use this function to set cwin cwin = 0; diff --git a/src-qt5/desktop-utils/lumina-screenshot/MainUI.h b/src-qt5/desktop-utils/lumina-screenshot/MainUI.h index 69c9bf26..f7319541 100644 --- a/src-qt5/desktop-utils/lumina-screenshot/MainUI.h +++ b/src-qt5/desktop-utils/lumina-screenshot/MainUI.h @@ -64,6 +64,8 @@ private slots: void startScreenshot(); void imgselchanged(bool hassel); + void imgScalingChanged(int percent = -1); + //Utility functions to perform a screenshot bool getWindow(); //set the "cwin" variable as appropriate void getPixmap(); //set the "cpic" variable to the new screenshot diff --git a/src-qt5/desktop-utils/lumina-screenshot/MainUI.ui b/src-qt5/desktop-utils/lumina-screenshot/MainUI.ui index db1c0cee..22b99b72 100644 --- a/src-qt5/desktop-utils/lumina-screenshot/MainUI.ui +++ b/src-qt5/desktop-utils/lumina-screenshot/MainUI.ui @@ -11,7 +11,7 @@ - Take Screenshot + Lumina Screenshot @@ -188,21 +188,70 @@ 1 - - - true - - - - - 0 - 0 - 341 - 171 - - - - + + + + + + + + 0 + 0 + + + + + + + Qt::AlignCenter + + + + + + + 5 + + + 200 + + + 5 + + + 100 + + + Qt::Vertical + + + QSlider::TicksBothSides + + + 20 + + + + + + + + + true + + + + + 0 + 0 + 306 + 173 + + + + + + @@ -274,7 +323,7 @@ 0 0 349 - 23 + 22 -- cgit