Changeset View
Changeset View
Standalone View
Standalone View
src/imagedocument.cpp
Show All 21 Lines | |||||
22 | #include <QUrl> | 22 | #include <QUrl> | ||
23 | #include <QFileInfo> | 23 | #include <QFileInfo> | ||
24 | 24 | | |||
25 | ImageDocument::ImageDocument() | 25 | ImageDocument::ImageDocument() | ||
26 | { | 26 | { | ||
27 | m_image = new QImage(); | 27 | m_image = new QImage(); | ||
28 | connect( this, &ImageDocument::pathChanged, | 28 | connect( this, &ImageDocument::pathChanged, | ||
29 | this, [this] (const QString &url) { | 29 | this, [this] (const QString &url) { | ||
30 | emit resetHandle(); | ||||
30 | /** Since the url passed by the model in the ImageViewer.qml contains 'file://' prefix */ | 31 | /** Since the url passed by the model in the ImageViewer.qml contains 'file://' prefix */ | ||
31 | QString location = QUrl( url).path(); | 32 | QString location = QUrl( url).path(); | ||
32 | m_image->load( location); | 33 | m_image->load( location); | ||
34 | m_originalImage = *m_image; | ||||
35 | m_edited = false; | ||||
36 | emit editedChanged(); | ||||
33 | emit visualImageChanged(); | 37 | emit visualImageChanged(); | ||
34 | }); | 38 | }); | ||
35 | } | 39 | } | ||
36 | 40 | | |||
37 | ImageDocument::~ImageDocument() | 41 | ImageDocument::~ImageDocument() | ||
38 | { | 42 | { | ||
39 | delete m_image; | 43 | delete m_image; | ||
40 | } | 44 | } | ||
Show All 9 Lines | 52 | { | |||
50 | emit pathChanged( url); | 54 | emit pathChanged( url); | ||
51 | } | 55 | } | ||
52 | 56 | | |||
53 | QImage ImageDocument::visualImage() | 57 | QImage ImageDocument::visualImage() | ||
54 | { | 58 | { | ||
55 | return *m_image; | 59 | return *m_image; | ||
56 | } | 60 | } | ||
57 | 61 | | |||
62 | bool ImageDocument::edited() | ||||
63 | { | ||||
64 | return m_edited; | ||||
65 | } | ||||
66 | | ||||
58 | void ImageDocument::rotate(int angle) | 67 | void ImageDocument::rotate(int angle) | ||
59 | { | 68 | { | ||
60 | QMatrix matrix; | 69 | QMatrix matrix; | ||
61 | matrix.rotate( angle); | 70 | matrix.rotate( angle); | ||
62 | *m_image = m_image->transformed( matrix); | 71 | *m_image = m_image->transformed( matrix); | ||
63 | QString location = QUrl( m_path).path(); | 72 | QString location = QUrl( m_path).path(); | ||
64 | if (QFileInfo( location).isWritable()) { | 73 | if (QFileInfo( location).isWritable()) { | ||
65 | m_image->save( location); | 74 | m_image->save( location); | ||
66 | } | 75 | } | ||
76 | emit visualImageChanged(); | ||||
77 | } | ||||
78 | | ||||
79 | void ImageDocument::changeBrightness( bool isIncrease) | ||||
80 | { | ||||
81 | if( isIncrease) { | ||||
82 | for( int i = 0; i < m_image->rect().width() ; i++ ) | ||||
83 | { | ||||
84 | for( int j = 0; j < m_image->rect().height(); j++ ) | ||||
85 | { | ||||
86 | m_image->setPixelColor(i, j , m_image->pixelColor( i , j).lighter( 120)); | ||||
87 | } | ||||
88 | } | ||||
89 | } else { | ||||
90 | for( int i = 0; i < m_image->rect().width() ; i++ ) | ||||
91 | { | ||||
92 | for( int j = 0; j < m_image->rect().height(); j++ ) | ||||
93 | { | ||||
94 | m_image->setPixelColor(i, j , m_image->pixelColor( i , j).darker( 120)); | ||||
95 | } | ||||
96 | } | ||||
97 | } | ||||
98 | m_edited = true; | ||||
99 | emit editedChanged(); | ||||
100 | emit visualImageChanged(); | ||||
101 | } | ||||
102 | | ||||
103 | void ImageDocument::save() | ||||
104 | { | ||||
105 | QString location = QUrl( m_path).path(); | ||||
106 | if( QFileInfo( location).isWritable()) { | ||||
107 | m_image->save( location); | ||||
108 | m_edited = false; | ||||
109 | emit editedChanged(); | ||||
110 | } | ||||
111 | } | ||||
67 | 112 | | |||
113 | void ImageDocument::cancel() | ||||
114 | { | ||||
115 | m_image = &m_originalImage; | ||||
116 | m_edited = false; | ||||
117 | emit editedChanged(); | ||||
68 | emit visualImageChanged(); | 118 | emit visualImageChanged(); | ||
69 | } | 119 | } | ||
70 | 120 | | |||
71 | #include "moc_imagedocument.cpp" | 121 | #include "moc_imagedocument.cpp" |