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"
20#include <QNetworkReply>
21#include <QNetworkRequest>
26CroppedImageSizer::CroppedImageSizer()
29 m_sourceSize(QSize(-1, -1))
31 connect(this, &CroppedImageSizer::inputParamsChanged, this, &CroppedImageSizer::calculateSourceSize);
34CroppedImageSizer::~CroppedImageSizer()
37 m_reply->deleteLater();
41QUrl CroppedImageSizer::source() const
46void CroppedImageSizer::setSource(const QUrl &source)
48 if (source != m_source) {
50 Q_EMIT inputParamsChanged();
54qreal CroppedImageSizer::width() const
59void CroppedImageSizer::setWidth(qreal width)
61 if (width != m_width) {
63 Q_EMIT inputParamsChanged();
67qreal CroppedImageSizer::height() const
72void CroppedImageSizer::setHeight(qreal height)
74 if (height != m_height) {
76 Q_EMIT inputParamsChanged();
80QSize CroppedImageSizer::sourceSize() const
85void CroppedImageSizer::calculateSourceSize()
87 if (m_source.isValid() && m_width > 0 && m_height > 0 && qmlEngine(this) && qmlEngine(this)->networkAccessManager()) {
90 m_reply->deleteLater();
92 QNetworkRequest request(m_source);
93 m_reply = qmlEngine(this)->networkAccessManager()->get(request);
94 connect(m_reply, &QNetworkReply::finished, this, &CroppedImageSizer::requestFinished);
95 } else if (m_sourceSize != QSize(-1, -1)) {
96 m_sourceSize = QSize(-1, -1);
101void CroppedImageSizer::requestFinished()
103 QImageReader m_reader(m_reply);
104 const QSize imageSize = m_reader.size();
105 if (imageSize.isValid()) {
106 const qreal ar = width() / height();
107 const qreal ssar = imageSize.width() / imageSize.height();
109 m_sourceSize = QSize(m_width, 0);
111 m_sourceSize = QSize(0, m_height);
114 qWarning() << "Could not find size of" << m_source;
115 m_sourceSize = QSize(0, 0);
119 m_reply->deleteLater();
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