Unity 8
croppedimagesizer.h
1 /*
2  * Copyright (C) 2014 Canonical, Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef CROPPEDIMAGESIZER_H
18 #define CROPPEDIMAGESIZER_H
19 
20 #include <QImageReader>
21 #include <QObject>
22 #include <QSize>
23 #include <QUrl>
24 
25 class CroppedImageSizerAsyncWorker;
26 
27 class CroppedImageSizer : public QObject
28 {
29  Q_OBJECT
30 
31  Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
32  Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY inputParamsChanged)
33  Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY inputParamsChanged)
34  Q_PROPERTY(QSize sourceSize READ sourceSize NOTIFY sourceSizeChanged)
35 
36 public:
37  CroppedImageSizer();
38  ~CroppedImageSizer();
39 
40  QUrl source() const;
41  void setSource(const QUrl &source);
42 
43  qreal width() const;
44  void setWidth(qreal width);
45 
46  qreal height() const;
47  void setHeight(qreal height);
48 
49  QSize sourceSize() const;
50  void setSourceSize(const QSize &sourceSize);
51 
52  Q_INVOKABLE void setImageSize(const QSize &imageSize);
53 
54 Q_SIGNALS:
55  void inputParamsChanged();
56  void sourceChanged();
57  void sourceSizeChanged();
58 
59 private Q_SLOT:
60  void calculateSourceSize();
61  void requestImage();
62 
63 private:
64  QUrl m_source;
65  qreal m_width;
66  qreal m_height;
67  QSize m_sourceSize;
68  QSize m_imageSize;
69  QPointer<CroppedImageSizerAsyncWorker> m_worker;
70 };
71 
72 #endif