Changeset View
Changeset View
Standalone View
Standalone View
src/imagedocument.cpp
Show All 14 Lines | |||||
15 | * License along with this program; if not, write to the | 15 | * License along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | 16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "imagedocument.h" | 20 | #include "imagedocument.h" | ||
21 | #include <QMatrix> | 21 | #include <QMatrix> | ||
22 | #include <QUrl> | 22 | #include <QUrl> | ||
23 | #include <QFileInfo> | ||||
23 | 24 | | |||
24 | ImageDocument::ImageDocument() | 25 | ImageDocument::ImageDocument() | ||
25 | { | 26 | { | ||
26 | m_image = new QImage(); | 27 | m_image = new QImage(); | ||
27 | connect( this, &ImageDocument::pathChanged, | 28 | connect( this, &ImageDocument::pathChanged, | ||
28 | this, [this] (const QString &url) { | 29 | this, [this] (const QString &url) { | ||
29 | delete m_image; | | |||
30 | /** Since the url passed by the model in the ImageViewer.qml contains 'file://' prefix */ | 30 | /** Since the url passed by the model in the ImageViewer.qml contains 'file://' prefix */ | ||
31 | QString location = QUrl( url).path(); | 31 | QString location = QUrl( url).path(); | ||
32 | m_image = new QImage( location); | 32 | m_image->load( location); | ||
33 | emit visualImageChanged(); | 33 | emit visualImageChanged(); | ||
34 | }); | 34 | }); | ||
35 | } | 35 | } | ||
36 | 36 | | |||
37 | ImageDocument::~ImageDocument() | 37 | ImageDocument::~ImageDocument() | ||
38 | { | 38 | { | ||
39 | delete m_image; | 39 | delete m_image; | ||
40 | } | 40 | } | ||
Show All 14 Lines | 54 | { | |||
55 | return *m_image; | 55 | return *m_image; | ||
56 | } | 56 | } | ||
57 | 57 | | |||
58 | void ImageDocument::rotate(int angle) | 58 | void ImageDocument::rotate(int angle) | ||
59 | { | 59 | { | ||
60 | QMatrix matrix; | 60 | QMatrix matrix; | ||
61 | matrix.rotate( angle); | 61 | matrix.rotate( angle); | ||
62 | *m_image = m_image->transformed( matrix); | 62 | *m_image = m_image->transformed( matrix); | ||
63 | QString location = QUrl( m_path).path(); | ||||
64 | if (QFileInfo( location).isWritable()) { | ||||
65 | m_image->save( location); | ||||
66 | } | ||||
67 | | ||||
63 | emit visualImageChanged(); | 68 | emit visualImageChanged(); | ||
64 | } | 69 | } | ||
65 | 70 | | |||
66 | #include "moc_imagedocument.cpp" | 71 | #include "moc_imagedocument.cpp" |