+++ /dev/null
-// -*- qml -*-
-
-/*!
- * This file is part of CameraPlus.
- *
- * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-import QtQuick 1.1
-import com.nokia.meego 1.1
-import CameraPlus 1.0
-
-QuillItem {
- id: item
- source: url
- mimeType: mimetype
-
- Component.onCompleted: console.log("Created " + url)
-
- function stop() {
- // No-op
- }
-
- MouseArea {
- id: mouse
- anchors.fill: parent
- enabled: true
- onClicked: toolBar.visible = !toolBar.visible
- }
-}
id: item
property bool isImage: mimetype.toLowerCase().search("video") < 0
property bool error: false
- property bool currentItem: PathView.isCurrentItem
- onCurrentItemChanged: {
- if (currentItem) {
- page.currentItem = item
- }
- }
-
- function stop() {
- if (loader.item) {
- loader.item.stop();
- }
- }
Label {
anchors.fill: parent
- visible: (loader.status == Loader.Error || item.error) && page.status == PageStatus.Active
+ visible: image.error && page.status == PageStatus.Active
text: qsTr("Failed to load preview");
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 32
}
- Loader {
- id: loader
+ QuillItem {
+ id: image
anchors.fill: parent
- source: isImage ? Qt.resolvedUrl("PostCaptureImage.qml") : Qt.resolvedUrl("PostCaptureVideo.qml")
- }
+ visible: page.status == PageStatus.Activating || page.status == PageStatus.Active
- Binding {
- target: loader.item
- value: page.status == PageStatus.Activating || page.status == PageStatus.Active
- property: "visible"
- }
+ Component.onCompleted: initialize(url, mimetype);
- Binding {
- target: item
- value: loader.item ? loader.item.error : false
- property: "error"
+ MouseArea {
+ id: mouse
+ anchors.fill: parent
+ enabled: true
+ onClicked: toolBar.visible = !toolBar.visible
+ }
}
}
CameraPage {
id: page
- property Item currentItem: null
- property Item previousItem: null
-
controlsVisible: false
policyMode: CameraResources.PostCapture
- needsPipeline: true
-
- onCurrentItemChanged: {
- if (previousItem) {
- previousItem.stop();
- }
-
- previousItem = currentItem
- }
-
- onStatusChanged: {
- if (status == PageStatus.Active) {
- cam.stop();
- }
- }
-
- Connections {
- // Unlikely that we need this.
- target: cam
- onIdleChanged: {
- if (cam.idle && page.status == PageStatus.Active) {
- cam.stop();
- }
- }
- }
+ needsPipeline: false
Rectangle {
color: "black"
anchors.fill: parent
path: Path {
- startX: 0
+ startX: - view.width
startY: view.height / 2
- PathLine { x: view.width; y: view.height / 2 }
+ PathLine { x: view.width * 2; y: view.height / 2 }
}
flickDeceleration: 999999 // Insanely high value to prevent panning multiple images
preferredHighlightBegin: 0.5
preferredHighlightEnd: 0.5
highlightRangeMode: PathView.StrictlyEnforceRange
- pathItemCount: 1
+ pathItemCount: 3
model: SparqlListModel {
// This is the exact query used by Harmattan gallery.
anchors.bottom: parent.bottom
tools: ToolBarLayout {
id: layout
- ToolIcon { iconId: "icon-m-toolbar-back"; onClicked: { page.stop(); pageStack.pop(); } }
+ ToolIcon { iconId: "icon-m-toolbar-back"; onClicked: { pageStack.pop(); } }
}
}
+++ /dev/null
-// -*- qml -*-
-
-/*!
- * This file is part of CameraPlus.
- *
- * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-import QtQuick 1.1
-import QtMultimediaKit 1.1
-
-Video {
- id: video
- source: url
-
- Component.onCompleted: console.log("Created " + url)
- onError: console.log("ERROR");
-
- MouseArea {
- anchors.fill: parent
- onClicked: {
- video.play()
- console.log("DDDDDDDDDDDDDDDDDDDDD " + url)
- }
- }
-}
void QuillItem::componentComplete() {
QDeclarativeItem::componentComplete();
-
- recreate();
-}
-
-QUrl QuillItem::source() const {
- return m_url;
-}
-
-void QuillItem::setSource(const QUrl& src) {
- if (src == source()) {
- 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();
-}
-
-bool QuillItem::error() const {
- return m_error;
}
-void QuillItem::recreate() {
+void QuillItem::initialize(const QUrl& url, const QString& mimeType) {
if (m_error) {
m_error = false;
emit errorChanged();
m_file->deleteLater();
}
- m_file = new QuillFile(m_url.toLocalFile(), m_type);
+ m_file = new QuillFile(url.toLocalFile(), mimeType);
QObject::connect(m_file, SIGNAL(error(QuillError)),
- this, SLOT(fileError()), Qt::QueuedConnection);
+ this, SLOT(fileError()), Qt::QueuedConnection);
QObject::connect(m_file, SIGNAL(imageAvailable(QuillImageList)),
- this, SLOT(fileLoaded()), Qt::QueuedConnection);
+ this, SLOT(fileLoaded()), Qt::QueuedConnection);
QObject::connect(m_file, SIGNAL(removed()),
m_file, SLOT(deleteLater()), Qt::QueuedConnection);
}
}
+bool QuillItem::error() const {
+ return m_error;
+}
+
void QuillItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) {
Q_UNUSED(widget);
+ QRectF rect = boundingRect();
+ painter->fillRect(rect, Qt::black);
+
if (!m_file) {
return;
}
- QImage image = m_file->image(0);
+ if (m_image.isNull()) {
+ return;
+ }
- if (!image.isNull()) {
- painter->drawImage(option->rect, image);
+ QPoint pos((rect.width() - m_image.width()) / 2, (rect.height() - m_image.height()) / 2);
+ if (!m_image.isNull()) {
+ painter->drawImage(pos, m_image);
}
}
+void QuillItem::geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry) {
+ // TODO: rotation animation looks weird
+ QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
+
+ m_image = QImage();
+
+ updateImage();
+}
+
void QuillItem::fileLoaded() {
+ updateImage();
update();
}
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,
Q_ARG(QString, err.errorData()));
+
m_file->deleteLater(); m_file = 0;
if (!m_error) {
return false;
}
+
+void QuillItem::updateImage() {
+ if (!m_file) {
+ return;
+ }
+
+ QImage image = m_file->image(0);
+
+ if (image.isNull()) {
+ return;
+ }
+
+ m_image = image.scaled(boundingRect().size().toSize(),
+ Qt::KeepAspectRatio, Qt::SmoothTransformation);
+}
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);
Q_PROPERTY(bool error READ error NOTIFY errorChanged);
public:
QuillItem(QDeclarativeItem *parent = 0);
~QuillItem();
- 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();
bool error() const;
+public slots:
+ void initialize(const QUrl& url, const QString& mimeType);
+
signals:
void sourceChanged();
void error(const QString& err);
void mimeTypeChanged();
void errorChanged();
+protected:
+ void geometryChanged(const QRectF& newGeometry, const QRectF& oldGeometry);
+
private slots:
void fileLoaded();
bool fileError();
private:
void recreate();
+ void updateImage();
QuillFile *m_file;
QUrl m_url;
QString m_type;
bool m_error;
+ QImage m_image;
};
#endif /* QUILL_ITEM_H */