diff --git a/qmlUiKirigami/ImageViewer.qml b/qmlUiKirigami/ImageViewer.qml --- a/qmlUiKirigami/ImageViewer.qml +++ b/qmlUiKirigami/ImageViewer.qml @@ -24,6 +24,7 @@ import QtQuick 2.7 import QtQuick.Window 2.2 import QtQuick.Controls 2.0 as Controls +import QtQuick.Layouts 1.3 import org.kde.kirigami 2.0 as Kirigami import org.kde.koko 0.1 as Koko import org.kde.kquickcontrolsaddons 2.0 as KQA @@ -48,6 +49,7 @@ Koko.ImageDocument { id: imageDoc path: listView.currentItem.currentImageSource + onResetHandle: brightnessSlider.value = 0.5 } Kirigami.ContextDrawer { @@ -95,6 +97,55 @@ ] } + ColumnLayout { + anchors.top: root.top + width: root.width + z: listView.z + 1 + + Controls.Slider { + id: brightnessSlider + property real previousValue: 0.5 + Layout.fillWidth: true + visible: applicationWindow().controlsVisible + from: 0 + to: 1.0 + value: 0.5 + stepSize: 0.1 + z: listView.z + 1 + snapMode: Controls.Slider.SnapAlways + hoverEnabled: true + Controls.ToolTip { + parent: brightnessSlider + visible: brightnessSlider.hovered + text: i18n("Brightness Controller") + } + onValueChanged: { + if( value > previousValue) { + imageDoc.changeBrightness( true) + } else if( value < previousValue) { + imageDoc.changeBrightness( false) + } + previousValue = value + listView.forceActiveFocus() + } + } + + RowLayout { + Layout.fillWidth: true + visible: imageDoc.edited + Controls.Button { + Layout.fillWidth: true + text: i18n("Save") + onClicked: imageDoc.save() + } + Controls.Button { + Layout.fillWidth: true + text: i18n("Cancel") + onClicked: imageDoc.cancel() + } + } + } + //FIXME: HACK property bool wasDrawerOpen Component.onCompleted: { @@ -260,6 +311,7 @@ MouseArea { anchors.fill: parent onClicked: { + contextDrawer.drawerOpen = false doubleClickTimer.restart(); } onDoubleClicked: { diff --git a/src/imagedocument.h b/src/imagedocument.h --- a/src/imagedocument.h +++ b/src/imagedocument.h @@ -27,6 +27,7 @@ Q_OBJECT Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged) Q_PROPERTY(QImage visualImage READ visualImage NOTIFY visualImageChanged) + Q_PROPERTY(bool edited READ edited NOTIFY editedChanged) public: ImageDocument(); ~ImageDocument(); @@ -36,15 +37,24 @@ QImage visualImage(); + bool edited(); + Q_INVOKABLE void rotate( int angle); + Q_INVOKABLE void changeBrightness( bool isIncrease); + Q_INVOKABLE void save(); + Q_INVOKABLE void cancel(); signals: void pathChanged(const QString &url); void visualImageChanged(); + void editedChanged(); + void resetHandle(); private: QString m_path; QImage *m_image; + QImage m_originalImage; + bool m_edited; }; #endif diff --git a/src/imagedocument.cpp b/src/imagedocument.cpp --- a/src/imagedocument.cpp +++ b/src/imagedocument.cpp @@ -26,10 +26,14 @@ { m_image = new QImage(); connect( this, &ImageDocument::pathChanged, - this, [this] (const QString &url) { + this, [this] (const QString &url) { + emit resetHandle(); /** Since the url passed by the model in the ImageViewer.qml contains 'file://' prefix */ QString location = QUrl( url).path(); m_image->load( location); + m_originalImage = *m_image; + m_edited = false; + emit editedChanged(); emit visualImageChanged(); }); } @@ -55,6 +59,11 @@ return *m_image; } +bool ImageDocument::edited() +{ + return m_edited; +} + void ImageDocument::rotate(int angle) { QMatrix matrix; @@ -64,7 +73,48 @@ if (QFileInfo( location).isWritable()) { m_image->save( location); } - + emit visualImageChanged(); +} + +void ImageDocument::changeBrightness( bool isIncrease) +{ + if( isIncrease) { + for( int i = 0; i < m_image->rect().width() ; i++ ) + { + for( int j = 0; j < m_image->rect().height(); j++ ) + { + m_image->setPixelColor(i, j , m_image->pixelColor( i , j).lighter( 120)); + } + } + } else { + for( int i = 0; i < m_image->rect().width() ; i++ ) + { + for( int j = 0; j < m_image->rect().height(); j++ ) + { + m_image->setPixelColor(i, j , m_image->pixelColor( i , j).darker( 120)); + } + } + } + m_edited = true; + emit editedChanged(); + emit visualImageChanged(); +} + +void ImageDocument::save() +{ + QString location = QUrl( m_path).path(); + if( QFileInfo( location).isWritable()) { + m_image->save( location); + m_edited = false; + emit editedChanged(); + } +} + +void ImageDocument::cancel() +{ + m_image = &m_originalImage; + m_edited = false; + emit editedChanged(); emit visualImageChanged(); }