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);
25 Quill::setDBusThumbnailingEnabled(true);
26 Quill::setThumbnailCreationEnabled(true);
32 QuillItem::~QuillItem() {
33 delete m_file; m_file = 0;
36 void QuillItem::componentComplete() {
37 QDeclarativeItem::componentComplete();
42 QUrl QuillItem::source() const {
46 void QuillItem::setSource(const QUrl& src) {
47 if (src == source()) {
53 if (isComponentComplete()) {
60 QString QuillItem::mimeType() const {
64 void QuillItem::setMimeType(const QString& mime) {
65 if (mimeType() == mime) {
71 if (isComponentComplete()) {
75 emit mimeTypeChanged();
78 bool QuillItem::error() const {
82 void QuillItem::recreate() {
89 m_file->deleteLater();
92 m_file = new QuillFile(m_url.toLocalFile(), m_type);
94 QObject::connect(m_file, SIGNAL(error(QuillError)),
95 this, SLOT(fileError()), Qt::QueuedConnection);
96 QObject::connect(m_file, SIGNAL(imageAvailable(QuillImageList)),
97 this, SLOT(fileLoaded()), Qt::QueuedConnection);
98 QObject::connect(m_file, SIGNAL(removed()),
99 m_file, SLOT(deleteLater()), Qt::QueuedConnection);
105 m_file->setDisplayLevel(0);
112 void QuillItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
119 QImage image = m_file->image(0);
121 if (!image.isNull()) {
122 painter->drawImage(option->rect, image);
126 void QuillItem::fileLoaded() {
130 bool QuillItem::fileError() {
135 QuillError err = m_file->error();
137 if (err.errorCode() != QuillError::NoError) {
138 qWarning() << "Error loading file" << m_file->fileName() << err.errorCode();
140 QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
141 Q_ARG(QString, err.errorData()));
142 m_file->deleteLater(); m_file = 0;