2 * Copyright (C) 2014 Canonical, Ltd.
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.
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.
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/>.
17#include "croppedimagesizer.h"
19#include "croppedimagesizerasyncworker.h"
21#include <QNetworkAccessManager>
22#include <QNetworkRequest>
26CroppedImageSizer::CroppedImageSizer()
29 m_sourceSize(QSize(-1, -1)),
32 connect(this, &CroppedImageSizer::inputParamsChanged, this, &CroppedImageSizer::calculateSourceSize);
33 connect(this, &CroppedImageSizer::sourceChanged, this, &CroppedImageSizer::requestImage);
36CroppedImageSizer::~CroppedImageSizer()
43QUrl CroppedImageSizer::source() const
48void CroppedImageSizer::setSource(const QUrl &source)
50 if (source != m_source) {
52 Q_EMIT sourceChanged();
56qreal CroppedImageSizer::width() const
61void CroppedImageSizer::setWidth(qreal width)
63 if (width != m_width) {
65 Q_EMIT inputParamsChanged();
69qreal CroppedImageSizer::height() const
74void CroppedImageSizer::setHeight(qreal height)
76 if (height != m_height) {
78 Q_EMIT inputParamsChanged();
82QSize CroppedImageSizer::sourceSize() const
87void CroppedImageSizer::setSourceSize(const QSize &sourceSize)
89 if (sourceSize != m_sourceSize) {
90 m_sourceSize = sourceSize;
91 Q_EMIT sourceSizeChanged();
95void CroppedImageSizer::setImageSize(const QSize &imageSize)
97 m_imageSize = imageSize;
99 calculateSourceSize();
102void CroppedImageSizer::requestImage()
109 if (m_source.isValid() && qmlEngine(this) && qmlEngine(this)->networkAccessManager()) {
110 QNetworkRequest request(m_source);
111 QNetworkReply *reply = qmlEngine(this)->networkAccessManager()->get(request);
112 m_worker = new CroppedImageSizerAsyncWorker(this, reply);
114 setSourceSize(QSize(-1, -1));
118void CroppedImageSizer::calculateSourceSize()
120 if (m_source.isValid() && m_width > 0 && m_height > 0 && !m_worker) {
121 if (!m_imageSize.isEmpty()) {
122 const qreal ar = m_width / m_height;
123 const qreal ssar = m_imageSize.width() / (qreal)m_imageSize.height();
125 setSourceSize(QSize(m_width, 0));
127 setSourceSize(QSize(0, m_height));
130 qWarning() << "Invalid size for " << m_source << m_imageSize;
131 setSourceSize(QSize(0, 0));
134 setSourceSize(QSize(-1, -1));
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list