2 * This file is part of CameraPlus.
4 * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "quillitem.h"
25 #include <QStyleOptionGraphicsItem>
28 QuillItem::QuillItem(QDeclarativeItem *parent) :
29 QDeclarativeItem(parent), m_file(0), m_error(false) {
31 setFlag(QGraphicsItem::ItemHasNoContents, false);
33 static bool init = false;
35 Quill::setPreviewLevelCount(1);
36 Quill::setPreviewSize(0, QSize(854, 480)); // TODO:
37 Quill::setMinimumPreviewSize(0, QSize(854, 480)); // TODO:
38 Quill::setThumbnailExtension("jpeg"); // TODO:
39 Quill::setThumbnailFlavorName(0, "screen");
40 Quill::setBackgroundRenderingColor(Qt::black);
41 QString tempPath(QDir::homePath() + QDir::separator() + ".config" +
42 QDir::separator() + "quill" + QDir::separator() + "tmp");
43 QDir().mkpath(tempPath);
44 Quill::setTemporaryFilePath(tempPath);
45 Quill::setDBusThumbnailingEnabled(true);
46 Quill::setThumbnailCreationEnabled(true);
52 QuillItem::~QuillItem() {
53 delete m_file; m_file = 0;
56 void QuillItem::componentComplete() {
57 QDeclarativeItem::componentComplete();
62 QUrl QuillItem::source() const {
66 void QuillItem::setSource(const QUrl& src) {
67 if (src == source()) {
73 if (isComponentComplete()) {
80 QString QuillItem::mimeType() const {
84 void QuillItem::setMimeType(const QString& mime) {
85 if (mimeType() == mime) {
91 if (isComponentComplete()) {
95 emit mimeTypeChanged();
98 bool QuillItem::error() const {
102 void QuillItem::recreate() {
109 m_file->deleteLater();
112 m_file = new QuillFile(m_url.toLocalFile(), m_type);
114 QObject::connect(m_file, SIGNAL(error(QuillError)),
115 this, SLOT(fileError()), Qt::QueuedConnection);
116 QObject::connect(m_file, SIGNAL(imageAvailable(QuillImageList)),
117 this, SLOT(fileLoaded()), Qt::QueuedConnection);
118 QObject::connect(m_file, SIGNAL(removed()),
119 m_file, SLOT(deleteLater()), Qt::QueuedConnection);
125 m_file->setDisplayLevel(0);
132 void QuillItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
139 QImage image = m_file->image(0);
141 if (!image.isNull()) {
142 painter->drawImage(option->rect, image);
146 void QuillItem::fileLoaded() {
150 bool QuillItem::fileError() {
155 QuillError err = m_file->error();
157 if (err.errorCode() != QuillError::NoError) {
158 qWarning() << "Error loading file" << m_file->fileName()
159 << "Code" << err.errorCode() << "Source" << err.errorSource();
161 QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
162 Q_ARG(QString, err.errorData()));
163 m_file->deleteLater(); m_file = 0;