aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src-qt5/desktop-utils/lumina-screenshot/ImageEditor.cpp31
-rw-r--r--src-qt5/desktop-utils/lumina-screenshot/ImageEditor.h5
-rw-r--r--src-qt5/desktop-utils/lumina-screenshot/MainUI.cpp15
-rw-r--r--src-qt5/desktop-utils/lumina-screenshot/MainUI.h2
-rw-r--r--src-qt5/desktop-utils/lumina-screenshot/MainUI.ui83
5 files changed, 112 insertions, 24 deletions
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 @@
</rect>
</property>
<property name="windowTitle">
- <string>Take Screenshot</string>
+ <string>Lumina Screenshot</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
@@ -188,21 +188,70 @@
<number>1</number>
</property>
<item>
- <widget class="QScrollArea" name="scrollArea">
- <property name="widgetResizable">
- <bool>true</bool>
- </property>
- <widget class="QWidget" name="scrollAreaWidgetContents">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>341</width>
- <height>171</height>
- </rect>
- </property>
- </widget>
- </widget>
+ <layout class="QHBoxLayout" name="horizontalLayout_4">
+ <item>
+ <layout class="QVBoxLayout" name="verticalLayout_4">
+ <item>
+ <widget class="QLabel" name="label_zoom_percent">
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="text">
+ <string notr="true"/>
+ </property>
+ <property name="alignment">
+ <set>Qt::AlignCenter</set>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSlider" name="slider_zoom">
+ <property name="minimum">
+ <number>5</number>
+ </property>
+ <property name="maximum">
+ <number>200</number>
+ </property>
+ <property name="singleStep">
+ <number>5</number>
+ </property>
+ <property name="value">
+ <number>100</number>
+ </property>
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="tickPosition">
+ <enum>QSlider::TicksBothSides</enum>
+ </property>
+ <property name="tickInterval">
+ <number>20</number>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QScrollArea" name="scrollArea">
+ <property name="widgetResizable">
+ <bool>true</bool>
+ </property>
+ <widget class="QWidget" name="scrollAreaWidgetContents">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>306</width>
+ <height>173</height>
+ </rect>
+ </property>
+ </widget>
+ </widget>
+ </item>
+ </layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
@@ -274,7 +323,7 @@
<x>0</x>
<y>0</y>
<width>349</width>
- <height>23</height>
+ <height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
bgstack15