Very basic, rough and extremely limited post capture view
authorMohammed Sameer <msameer@foolab.org>
Mon, 10 Sep 2012 13:40:51 +0000 (16:40 +0300)
committerMohammed Sameer <msameer@foolab.org>
Mon, 10 Sep 2012 13:40:51 +0000 (16:40 +0300)
qml/ImagePage.qml
qml/PostCapturePage.qml [new file with mode: 0644]
qml/VideoPage.qml
src/main.cpp
src/quillitem.cpp [new file with mode: 0644]
src/quillitem.h [new file with mode: 0644]
src/src.pro

index 1b48b15..d96e665 100644 (file)
@@ -72,6 +72,20 @@ CameraPage {
 //                }
         }
 
-        // TODO: filenaming.
+        Button {
+                id: cameraRoll
+                anchors.top: parent.top
+                anchors.right: parent.right
+                anchors.topMargin: 20
+                anchors.rightMargin: 20
+                width: 56
+                height: 56
+
+                opacity: 0.5
+                iconSource: "image://theme/icon-m-camera-roll"
+                onClicked: openFile("PostCapturePage.qml");
+                visible: controlsVisible
+        }
+
         // TODO: metadata
 }
diff --git a/qml/PostCapturePage.qml b/qml/PostCapturePage.qml
new file mode 100644 (file)
index 0000000..3ab19c7
--- /dev/null
@@ -0,0 +1,64 @@
+// -*- qml -*-
+import QtQuick 1.1
+import com.nokia.meego 1.1
+import QtCamera 1.0
+import QtSparql 1.0
+import CameraPlus 1.0
+
+// QML QtGallery stuff is crap.
+// Most of the ideas (and some code) for loading and displaying images are stolen from
+// N9QmlPhotoPicker https://github.com/petrumotrescu/N9QmlPhotoPicker
+
+// TODO: this is really basic.
+
+Page {
+        id: page
+        property Camera cam: null
+
+        Rectangle {
+                color: "black"
+                anchors.fill: parent
+        }
+
+        ListView {
+                // TODO: ListView does not loop and seems one has to use PathView.
+                id: view
+                anchors.fill: parent
+                orientation: ListView.Horizontal
+                snapMode: ListView.SnapOneItem
+                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)"
+
+                        connection: SparqlConnection {
+                                id: connection
+                                driver: "QTRACKER_DIRECT"
+                                onStatusChanged: checkStatus(status)
+
+                                function checkStatus(status) {
+                                        if (status == SparqlConnection.Error)
+                                        console.log("Error = "+connection.errorString());
+                                }
+                        }
+                }
+
+                delegate: QuillItem {
+                        source: url
+                        width: view.width
+                        height: view.height
+                        // TODO: does not work because of preloading
+//                        onError: showError(qsTr("Failed to load image"));
+                }
+        }
+
+        ToolBar {
+                id: toolBar
+                opacity: 0.8
+                anchors.bottom: parent.bottom
+                tools: ToolBarLayout {
+                        id: layout
+                        ToolIcon { iconId: "icon-m-toolbar-back"; onClicked: pageStack.pop(); }
+                }
+        }
+}
index ef983c7..59bb14a 100644 (file)
@@ -79,4 +79,19 @@ CameraPage {
                 anchors.topMargin: 10
                 anchors.leftMargin: 20
         }
+
+        Button {
+                id: cameraRoll
+                anchors.top: parent.top
+                anchors.right: parent.right
+                anchors.topMargin: 20
+                anchors.rightMargin: 20
+                width: 56
+                height: 56
+
+                opacity: 0.5
+                iconSource: "image://theme/icon-m-camera-roll"
+                onClicked: openFile("PostCapturePage.qml");
+                visible: controlsVisible && !videoMode.recording
+        }
 }
index 0c3df6d..e8d1802 100644 (file)
@@ -10,6 +10,7 @@
 
 #include "settings.h"
 #include "filenaming.h"
+#import "quillitem.h"
 
 Q_DECL_EXPORT int main(int argc, char *argv[]) {
   XInitThreads();
@@ -24,6 +25,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) {
   Plugin::registerTypes(view.engine());
   qmlRegisterType<Settings>("CameraPlus", 1, 0, "Settings");
   qmlRegisterType<FileNaming>("CameraPlus", 1, 0, "FileNaming");
+  qmlRegisterType<QuillItem>("CameraPlus", 1, 0, "QuillItem");
 
   QUrl sourceUrl = QUrl::fromLocalFile(QDir::currentPath() + "/main.qml");
   view.setSource(sourceUrl);
diff --git a/src/quillitem.cpp b/src/quillitem.cpp
new file mode 100644 (file)
index 0000000..c6e02ac
--- /dev/null
@@ -0,0 +1,106 @@
+#include "quillitem.h"
+#include <QuillFile>
+#include <QUrl>
+#include <QPainter>
+#include <QStyleOptionGraphicsItem>
+#include <QDir>
+
+QuillItem::QuillItem(QDeclarativeItem *parent) :
+  QDeclarativeItem(parent), m_file(0) {
+
+  setFlag(QGraphicsItem::ItemHasNoContents, false);
+
+  static bool init = false;
+  if (!init) {
+    Quill::setPreviewLevelCount(1);
+    Quill::setPreviewSize(0, QSize(864, 480)); // TODO:
+    Quill::setMinimumPreviewSize(0, QSize(864, 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);
+    init = true;
+  }
+}
+
+QuillItem::~QuillItem() {
+  delete m_file; m_file = 0;
+}
+
+QUrl QuillItem::source() const {
+  if (m_file) {
+    return QUrl::fromLocalFile(m_file->fileName());
+  }
+
+  return QUrl();
+}
+
+void QuillItem::setSource(const QUrl& src) {
+  if (src == source()) {
+    return;
+  }
+
+  if (m_file) {
+    m_file->deleteLater();
+  }
+
+  m_file = new QuillFile(src.toLocalFile());
+
+  QObject::connect(m_file, SIGNAL(error(QuillError)),
+         this, SLOT(fileError()), Qt::QueuedConnection);
+  QObject::connect(m_file, SIGNAL(imageAvailable(QuillImageList)),
+         this, SLOT(fileLoaded()), Qt::QueuedConnection);
+  QObject::connect(m_file, SIGNAL(removed()),
+                  m_file, SLOT(deleteLater()), Qt::QueuedConnection);
+
+  if (fileError()) {
+    return;
+  }
+
+  m_file->setDisplayLevel(0);
+
+  if (fileError()) {
+    return;
+  }
+
+  emit sourceChanged();
+}
+
+void QuillItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
+  Q_UNUSED(widget);
+
+  if (!m_file) {
+    return;
+  }
+
+  QImage image = m_file->image(0);
+
+  if (!image.isNull()) {
+    painter->drawImage(option->rect, image);
+  }
+}
+
+void QuillItem::fileLoaded() {
+  update();
+}
+
+bool QuillItem::fileError() {
+  if (!m_file) {
+    return true;
+  }
+
+  QuillError err = m_file->error();
+  if (err.errorCode() != QuillError::NoError) {
+    qWarning() << "Error loading file" << m_file->fileName() << err.errorData();
+
+    QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
+                             Q_ARG(QString, err.errorData()));
+    m_file->deleteLater(); m_file = 0;
+    return true;
+  }
+
+  return false;
+}
diff --git a/src/quillitem.h b/src/quillitem.h
new file mode 100644 (file)
index 0000000..f72fbf9
--- /dev/null
@@ -0,0 +1,36 @@
+// -*- c++ -*-
+
+#ifndef QUILL_ITEM_H
+#define QUILL_ITEM_H
+
+#include <QDeclarativeItem>
+
+class QuillFile;
+
+class QuillItem : public QDeclarativeItem {
+  Q_OBJECT
+
+  Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged);
+
+public:
+  QuillItem(QDeclarativeItem *parent = 0);
+  ~QuillItem();
+
+  QUrl source() const;
+  void setSource(const QUrl& src);
+
+  void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
+
+signals:
+  void sourceChanged();
+  void error(const QString& err);
+
+private slots:
+  void fileLoaded();
+  bool fileError();
+
+private:
+  QuillFile *m_file;
+};
+
+#endif /* QUILL_ITEM_H */
index 0b3e059..2f38feb 100644 (file)
@@ -8,9 +8,9 @@ QT += declarative opengl
 CONFIG += link_pkgconfig debug static
 
 PKGCONFIG = gstreamer-0.10 gstreamer-interfaces-0.10 gstreamer-video-0.10 gstreamer-tag-0.10 \
-            gstreamer-pbutils-0.10 meego-gstreamer-interfaces-0.10
+            gstreamer-pbutils-0.10 meego-gstreamer-interfaces-0.10 quill
 
 LIBS +=  -L../imports/ -limports -L../lib/ -lqtcamera
 
-SOURCES += main.cpp settings.cpp filenaming.cpp
-HEADERS += settings.h filenaming.h
+SOURCES += main.cpp settings.cpp filenaming.cpp quillitem.cpp
+HEADERS += settings.h filenaming.h quillitem.h