5 #include <QStyleOptionGraphicsItem>
8 QuillItem::QuillItem(QDeclarativeItem *parent) :
9 QDeclarativeItem(parent), m_file(0), m_error(false) {
11 setFlag(QGraphicsItem::ItemHasNoContents, false);
13 static bool init = false;
15 Quill::setPreviewLevelCount(1);
16 Quill::setPreviewSize(0, QSize(854, 480)); // TODO:
17 Quill::setMinimumPreviewSize(0, QSize(854, 480)); // TODO:
18 Quill::setThumbnailExtension("jpeg"); // TODO:
19 Quill::setThumbnailFlavorName(0, "screen");
20 Quill::setBackgroundRenderingColor(Qt::black);
21 QString tempPath(QDir::homePath() + QDir::separator() + ".config" +
22 QDir::separator() + "quill" + QDir::separator() + "tmp");
23 QDir().mkpath(tempPath);
24 Quill::setTemporaryFilePath(tempPath);
29 QuillItem::~QuillItem() {
30 delete m_file; m_file = 0;
33 void QuillItem::componentComplete() {
34 QDeclarativeItem::componentComplete();
39 QUrl QuillItem::source() const {
43 void QuillItem::setSource(const QUrl& src) {
44 if (src == source()) {
50 if (isComponentComplete()) {
57 QString QuillItem::mimeType() const {
61 void QuillItem::setMimeType(const QString& mime) {
62 if (mimeType() == mime) {
68 if (isComponentComplete()) {
72 emit mimeTypeChanged();
75 bool QuillItem::error() const {
79 void QuillItem::recreate() {
86 m_file->deleteLater();
89 m_file = new QuillFile(m_url.toLocalFile(), m_type);
91 QObject::connect(m_file, SIGNAL(error(QuillError)),
92 this, SLOT(fileError()), Qt::QueuedConnection);
93 QObject::connect(m_file, SIGNAL(imageAvailable(QuillImageList)),
94 this, SLOT(fileLoaded()), Qt::QueuedConnection);
95 QObject::connect(m_file, SIGNAL(removed()),
96 m_file, SLOT(deleteLater()), Qt::QueuedConnection);
102 m_file->setDisplayLevel(0);
109 void QuillItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
116 QImage image = m_file->image(0);
118 if (!image.isNull()) {
119 painter->drawImage(option->rect, image);
123 void QuillItem::fileLoaded() {
127 bool QuillItem::fileError() {
132 QuillError err = m_file->error();
134 if (err.errorCode() != QuillError::NoError) {
135 qWarning() << "Error loading file" << m_file->fileName() << err.errorCode();
137 QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
138 Q_ARG(QString, err.errorData()));
139 m_file->deleteLater(); m_file = 0;