X-Git-Url: http://cgit.sxemacs.org/?a=blobdiff_plain;f=src%2Fquillitem.cpp;h=6732b1790fe5c59388a72021e2fabe30133c8f47;hb=c89b1028e57a5262a12bfaafeb0a8d0b4d919c32;hp=ad0603b73865089cf47662446bf0ed745efc007b;hpb=7b5b3b4d8f8435a9e60de7a4732ed648034e50b7;p=harmattan%2Fcameraplus diff --git a/src/quillitem.cpp b/src/quillitem.cpp index ad0603b..6732b17 100644 --- a/src/quillitem.cpp +++ b/src/quillitem.cpp @@ -1,3 +1,23 @@ +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012 Mohammed Sameer + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + #include "quillitem.h" #include #include @@ -9,77 +29,13 @@ QuillItem::QuillItem(QDeclarativeItem *parent) : QDeclarativeItem(parent), m_file(0), m_error(false) { setFlag(QGraphicsItem::ItemHasNoContents, false); - - static bool init = false; - if (!init) { - Quill::setPreviewLevelCount(1); - Quill::setPreviewSize(0, QSize(854, 480)); // TODO: - Quill::setMinimumPreviewSize(0, QSize(854, 480)); // TODO: - Quill::setThumbnailExtension("jpeg"); // TODO: - Quill::setThumbnailFlavorName(0, "screen"); - Quill::setBackgroundRenderingColor(Qt::black); - QString tempPath(QDir::homePath() + QDir::separator() + ".config" + - QDir::separator() + "quill" + QDir::separator() + "tmp"); - QDir().mkpath(tempPath); - Quill::setTemporaryFilePath(tempPath); - Quill::setDBusThumbnailingEnabled(true); - Quill::setThumbnailCreationEnabled(true); - - init = true; - } } QuillItem::~QuillItem() { delete m_file; m_file = 0; } -void QuillItem::componentComplete() { - QDeclarativeItem::componentComplete(); - - recreate(); -} - -QUrl QuillItem::source() const { - return m_url; -} - -void QuillItem::setSource(const QUrl& src) { - if (src == source()) { - return; - } - - m_url = src; - - if (isComponentComplete()) { - recreate(); - } - - emit sourceChanged(); -} - -QString QuillItem::mimeType() const { - return m_type; -} - -void QuillItem::setMimeType(const QString& mime) { - if (mimeType() == mime) { - return; - } - - m_type = mime; - - if (isComponentComplete()) { - recreate(); - } - - emit mimeTypeChanged(); -} - -bool QuillItem::error() const { - return m_error; -} - -void QuillItem::recreate() { +void QuillItem::initialize(const QUrl& url, const QString& mimeType) { if (m_error) { m_error = false; emit errorChanged(); @@ -89,12 +45,12 @@ void QuillItem::recreate() { m_file->deleteLater(); } - m_file = new QuillFile(m_url.toLocalFile(), m_type); + m_file = new QuillFile(url.toLocalFile(), mimeType); QObject::connect(m_file, SIGNAL(error(QuillError)), - this, SLOT(fileError()), Qt::QueuedConnection); + this, SLOT(fileError()), Qt::QueuedConnection); QObject::connect(m_file, SIGNAL(imageAvailable(QuillImageList)), - this, SLOT(fileLoaded()), Qt::QueuedConnection); + this, SLOT(fileLoaded()), Qt::QueuedConnection); QObject::connect(m_file, SIGNAL(removed()), m_file, SLOT(deleteLater()), Qt::QueuedConnection); @@ -109,8 +65,16 @@ void QuillItem::recreate() { } } +bool QuillItem::error() const { + return m_error; +} + void QuillItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(widget); + Q_UNUSED(option); + + QRectF rect = boundingRect(); + painter->fillRect(rect, Qt::black); if (!m_file) { return; @@ -118,9 +82,18 @@ void QuillItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QImage image = m_file->image(0); - if (!image.isNull()) { - painter->drawImage(option->rect, image); + if (image.isNull()) { + return; } + + QSizeF imageSize = QSizeF(image.size()); + QSizeF widgetSize = rect.size(); + imageSize.scale(widgetSize, Qt::KeepAspectRatio); + + QPointF pos = QPointF(widgetSize.width() - imageSize.width(), + widgetSize.height() - imageSize.height()) / 2; + + painter->drawImage(QRectF(pos, imageSize), image, QRect(0, 0, image.width(), image.height())); } void QuillItem::fileLoaded() { @@ -140,6 +113,7 @@ bool QuillItem::fileError() { QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, Q_ARG(QString, err.errorData())); + m_file->deleteLater(); m_file = 0; if (!m_error) {