Pass the mime type to QuillItem and request images that are 10 pixels smaller so...
authorMohammed Sameer <msameer@foolab.org>
Tue, 11 Sep 2012 20:14:32 +0000 (23:14 +0300)
committerMohammed Sameer <msameer@foolab.org>
Tue, 11 Sep 2012 20:14:32 +0000 (23:14 +0300)
qml/PostCapturePage.qml
src/main.cpp
src/quillitem.cpp
src/quillitem.h

index 3ab19c7..bf5da1a 100644 (file)
@@ -29,7 +29,7 @@ Page {
                 cacheBuffer: view.width * 2
 
                 model: SparqlListModel {
-                        query: "SELECT nie:url(?urn) AS ?url tracker:id(?urn) AS ?trackerid nie:mimeType(?urn) AS mimeType WHERE { ?urn rdf:type nfo:Media .  ?urn nfo:equipment \"urn:equipment:Nokia:N950:\" ; tracker:available \"true\"^^xsd:boolean  }  ORDER BY DESC (?created)"
+                        query: "SELECT nie:url(?urn) AS ?url tracker:id(?urn) AS ?trackerid nie:mimeType(?urn) AS ?mime WHERE { ?urn rdf:type nfo:Media .  ?urn nfo:equipment \"urn:equipment:Nokia:N950:\" ; tracker:available \"true\"^^xsd:boolean  }  ORDER BY DESC (?created)"
 
                         connection: SparqlConnection {
                                 id: connection
@@ -43,12 +43,19 @@ Page {
                         }
                 }
 
-                delegate: QuillItem {
-                        source: url
+                delegate: Item {
                         width: view.width
                         height: view.height
-                        // TODO: does not work because of preloading
-//                        onError: showError(qsTr("Failed to load image"));
+
+                        QuillItem {
+                                source: url
+                                mimeType: mime
+                                width: view.width - 10
+                                height: view.height
+                                anchors.centerIn: parent
+                                // TODO: does not work because of preloading
+                                //                        onError: showError(qsTr("Failed to load image"));
+                                }
                 }
         }
 
index e8d1802..5cb7d81 100644 (file)
@@ -10,7 +10,7 @@
 
 #include "settings.h"
 #include "filenaming.h"
-#import "quillitem.h"
+#include "quillitem.h"
 
 Q_DECL_EXPORT int main(int argc, char *argv[]) {
   XInitThreads();
index c6e02ac..79f6912 100644 (file)
@@ -13,8 +13,8 @@ QuillItem::QuillItem(QDeclarativeItem *parent) :
   static bool init = false;
   if (!init) {
     Quill::setPreviewLevelCount(1);
-    Quill::setPreviewSize(0, QSize(864, 480)); // TODO:
-    Quill::setMinimumPreviewSize(0, QSize(864, 480)); // TODO:
+    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);
@@ -30,12 +30,14 @@ QuillItem::~QuillItem() {
   delete m_file; m_file = 0;
 }
 
-QUrl QuillItem::source() const {
-  if (m_file) {
-    return QUrl::fromLocalFile(m_file->fileName());
-  }
+void QuillItem::componentComplete() {
+  QDeclarativeItem::componentComplete();
 
-  return QUrl();
+  recreate();
+}
+
+QUrl QuillItem::source() const {
+  return m_url;
 }
 
 void QuillItem::setSource(const QUrl& src) {
@@ -43,11 +45,39 @@ void QuillItem::setSource(const QUrl& src) {
     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();
+}
+
+void QuillItem::recreate() {
   if (m_file) {
     m_file->deleteLater();
   }
 
-  m_file = new QuillFile(src.toLocalFile());
+  m_file = new QuillFile(m_url.toLocalFile(), m_type);
 
   QObject::connect(m_file, SIGNAL(error(QuillError)),
          this, SLOT(fileError()), Qt::QueuedConnection);
@@ -65,8 +95,6 @@ void QuillItem::setSource(const QUrl& src) {
   if (fileError()) {
     return;
   }
-
-  emit sourceChanged();
 }
 
 void QuillItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
@@ -93,8 +121,9 @@ bool QuillItem::fileError() {
   }
 
   QuillError err = m_file->error();
+
   if (err.errorCode() != QuillError::NoError) {
-    qWarning() << "Error loading file" << m_file->fileName() << err.errorData();
+    qWarning() << "Error loading file" << m_file->fileName() << err.errorCode();
 
     QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
                              Q_ARG(QString, err.errorData()));
index f72fbf9..ac197f5 100644 (file)
@@ -11,6 +11,7 @@ class QuillItem : public QDeclarativeItem {
   Q_OBJECT
 
   Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged);
+  Q_PROPERTY(QString mimeType READ mimeType WRITE setMimeType NOTIFY mimeTypeChanged);
 
 public:
   QuillItem(QDeclarativeItem *parent = 0);
@@ -19,18 +20,28 @@ public:
   QUrl source() const;
   void setSource(const QUrl& src);
 
+  QString mimeType() const;
+  void setMimeType(const QString& mime);
+
   void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
 
+  virtual void componentComplete();
+
 signals:
   void sourceChanged();
   void error(const QString& err);
+  void mimeTypeChanged();
 
 private slots:
   void fileLoaded();
   bool fileError();
 
 private:
+  void recreate();
+
   QuillFile *m_file;
+  QUrl m_url;
+  QString m_type;
 };
 
 #endif /* QUILL_ITEM_H */