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);
32 connect(this, &CroppedImageSizer::sourceChanged, this, &CroppedImageSizer::updateImageSize);
35CroppedImageSizer::~CroppedImageSizer()
38 m_reply->deleteLater();
42QUrl CroppedImageSizer::source() const
47void CroppedImageSizer::setSource(const QUrl &source)
49 if (source != m_source) {
51 Q_EMIT sourceChanged();
55qreal CroppedImageSizer::width() const
60void CroppedImageSizer::setWidth(qreal width)
62 if (width != m_width) {
64 Q_EMIT inputParamsChanged();
68qreal CroppedImageSizer::height() const
73void CroppedImageSizer::setHeight(qreal height)
75 if (height != m_height) {
77 Q_EMIT inputParamsChanged();
81QSize CroppedImageSizer::sourceSize() const
86void CroppedImageSizer::setSourceSize(const QSize &sourceSize)
88 if (sourceSize != m_sourceSize) {
89 m_sourceSize = sourceSize;
90 Q_EMIT sourceSizeChanged();
94void CroppedImageSizer::updateImageSize()
97 m_reply->disconnect();
99 m_reply->deleteLater();
103 if (m_source.isValid() && qmlEngine(this) && qmlEngine(this)->networkAccessManager()) {
104 QNetworkRequest request(m_source);
105 m_reply = qmlEngine(this)->networkAccessManager()->get(request);
106 connect(m_reply, &QNetworkReply::finished, this, &CroppedImageSizer::requestFinished);
108 setSourceSize(QSize(-1, -1));
112void CroppedImageSizer::requestFinished()
114 QImageReader m_reader(m_reply);
115 m_imageSize = m_reader.size();
117 m_reply->deleteLater();
120 calculateSourceSize();
123void CroppedImageSizer::calculateSourceSize()
125 if (m_source.isValid() && m_width > 0 && m_height > 0 && !m_reply) {
126 if (!m_imageSize.isEmpty()) {
127 const qreal ar = m_width / m_height;
128 const qreal ssar = m_imageSize.width() / (qreal)m_imageSize.height();
130 setSourceSize(QSize(m_width, 0));
132 setSourceSize(QSize(0, m_height));
135 qWarning() << "Invalid size for " << m_source << m_imageSize << m_reply;
136 setSourceSize(QSize(0, 0));
139 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