Permalink
Browse files

QML "ClassicPrint" item as controller

  • Loading branch information...
1 parent ca9d872 commit 83319fb8d56f0b57aa550bebf62493ad357179aa @thp thp committed May 18, 2012
Showing with 387 additions and 30 deletions.
  1. +5 −0 ClassicPrintDeclarative.cpp
  2. +159 −0 ClassicPrintDeclarative.h
  3. +26 −16 ClassicPrintProvider.h
  4. +19 −1 classicprintqml.cpp
  5. +2 −0 classicprintqml.pro
  6. +176 −13 classicprintqml.qml
@@ -0,0 +1,5 @@
+
+#include "ClassicPrintDeclarative.h"
+
+ClassicPrint *ClassicPrintDeclarative::classicPrint;
+
@@ -0,0 +1,159 @@
+#ifndef CLASSICPRINTQML_CLASSICPRINTDECLARATIVE_H
+#define CLASSICPRINTQML_CLASSICPRINTDECLARATIVE_H
+
+#include <QtCore>
+#include <QtGui>
+#include <QtDeclarative>
+
+#include "ClassicPrint.h"
+#include "ClassicPrintProcessing.h"
+
+class ClassicPrintDeclarative : public QObject {
+ Q_OBJECT
+
+ public:
+ ClassicPrintDeclarative(QObject *parent=NULL)
+ : QObject(parent),
+ m_sequence(0),
+ m_timer()
+ {
+ m_timer.setInterval(500);
+ m_timer.setSingleShot(true);
+
+ QObject::connect(&m_timer, SIGNAL(timeout()),
+ this, SIGNAL(sequenceChanged()));
+
+ QObject::connect(this, SIGNAL(contrastChanged()),
+ this, SLOT(contentUpdated()));
+
+ QObject::connect(this, SIGNAL(colourisationChanged()),
+ this, SLOT(contentUpdated()));
+
+ QObject::connect(this, SIGNAL(frameSizeChanged()),
+ this, SLOT(contentUpdated()));
+
+ QObject::connect(this, SIGNAL(lightLeakChanged()),
+ this, SLOT(contentUpdated()));
+ }
+
+ static void init() {
+ classicPrint = new ClassicPrint;
+ classicPrint->load(":/classicPrintData/settings.xml");
+ qmlRegisterType<ClassicPrintDeclarative>("org.maemo.classicprint",
+ 1, 0, "ClassicPrint");
+ }
+
+ static ClassicPrint *getClassicPrint() {
+ return classicPrint;
+ }
+
+ qreal contrast() {
+ return getClassicPrint()->getCurrentProcessing()->contrast()/100.;
+ }
+
+ void setContrast(qreal contrast) {
+ getClassicPrint()->getCurrentProcessing()->setContrast(contrast*100.);
+ emit contrastChanged();
+ }
+
+ Q_PROPERTY(qreal contrast
+ READ contrast
+ WRITE setContrast
+ NOTIFY contrastChanged)
+
+ qreal colourisation() {
+ return getClassicPrint()->getCurrentProcessing()->colourisationPercent()/100.;
+ }
+
+ void setColourisation(qreal colourisation) {
+ getClassicPrint()->getCurrentProcessing()->setColourisationPercent(colourisation*100.);
+ emit colourisationChanged();
+ }
+
+ Q_PROPERTY(qreal colourisation
+ READ colourisation
+ WRITE setColourisation
+ NOTIFY colourisationChanged)
+
+ qreal frameSize() {
+ return getClassicPrint()->getCurrentProcessing()->frameSizePercent()/15.;
+ }
+
+ void setFrameSize(qreal frameSize) {
+ getClassicPrint()->getCurrentProcessing()->setFrameSizePercent(frameSize*15.);
+ emit frameSizeChanged();
+ }
+
+ Q_PROPERTY(qreal frameSize
+ READ frameSize
+ WRITE setFrameSize
+ NOTIFY frameSizeChanged)
+
+ int lightLeak() {
+ QString value = getClassicPrint()->getCurrentProcessing()->lightLeak();
+ if (value == "Light Leak 1.jpg") {
+ return 1;
+ } else if (value == "Light Leak 3.jpg") {
+ return 2;
+ } else if (value == "Random") {
+ return -1;
+ } else {
+ return 0;
+ }
+ }
+
+ void setLightLeak(int lightLeak) {
+ if (this->lightLeak() != lightLeak) {
+ QString value;
+ switch (lightLeak) {
+ case 1:
+ value = "Light Leak 1.jpg";
+ break;
+ case 2:
+ value = "Light Leak 3.jpg";
+ break;
+ case -1:
+ value = "Random";
+ break;
+ default:
+ value = "";
+ break;
+ }
+
+ getClassicPrint()->getCurrentProcessing()->setLightLeak(value);
+ emit lightLeakChanged();
+ }
+ }
+
+ Q_PROPERTY(int lightLeak
+ READ lightLeak
+ WRITE setLightLeak
+ NOTIFY lightLeakChanged)
+
+
+ int sequence() { return m_sequence; }
+ Q_PROPERTY(int sequence READ sequence NOTIFY sequenceChanged)
+
+ signals:
+ void contrastChanged();
+ void colourisationChanged();
+ void frameSizeChanged();
+ void lightLeakChanged();
+
+ void sequenceChanged();
+
+ public slots:
+ void contentUpdated() {
+ m_sequence++;
+ // wait a bit to avoid too many updates
+ m_timer.start();
+ }
+
+ private:
+ static ClassicPrint *classicPrint;
+
+ int m_sequence;
+ QTimer m_timer;
+};
+
+#endif
@@ -6,17 +6,13 @@
#include <QtDeclarative>
#include "ClassicPrint.h"
+#include "ClassicPrintDeclarative.h"
class ClassicPrintProvider : public QDeclarativeImageProvider {
- private:
- ClassicPrint classicPrint;
-
public:
ClassicPrintProvider()
- : QDeclarativeImageProvider(QDeclarativeImageProvider::Image),
- classicPrint()
+ : QDeclarativeImageProvider(QDeclarativeImageProvider::Image)
{
- classicPrint.load(":/classicPrintData/settings.xml");
}
QImage requestImage(const QString &id, QSize *size,
@@ -26,24 +22,38 @@ class ClassicPrintProvider : public QDeclarativeImageProvider {
return QImage();
}
- QImage source("/" + id);
+ QString filename(id);
+ int pos = -1;
+ if ((pos = id.lastIndexOf("#")) != -1) {
+ filename = filename.mid(0, pos);
+ }
+
+ QImage source(filename);
size->setWidth(source.width());
size->setHeight(source.height());
- QImage destination(requestedSize, source.format());
- classicPrint.process(source.scaled(requestedSize,
- Qt::KeepAspectRatio),
- requestedSize.width(),
- requestedSize.height(),
+ QSize targetSize(requestedSize);
+
+ if (targetSize.width() == 0) {
+ targetSize.setWidth(source.width()*targetSize.height()/
+ source.height());
+ } else if (targetSize.height() == 0) {
+ targetSize.setHeight(source.height()*targetSize.width()/
+ source.width());
+ }
+
+ QImage destination(targetSize, source.format());
+ ClassicPrintDeclarative::getClassicPrint()->process(
+ source.scaled(targetSize,
+ Qt::KeepAspectRatio,
+ Qt::SmoothTransformation),
+ targetSize.width(),
+ targetSize.height(),
destination);
return destination;
}
- static void init() {
- ClassicPrint::init();
- }
-
static void addToView(QDeclarativeView *view) {
view->engine()->addImageProvider(QLatin1String("classicPrint"),
new ClassicPrintProvider);
View
@@ -2,20 +2,32 @@
#include <QtGui>
#include <QtDeclarative>
+#include "ClassicPrint.h"
#include "ClassicPrintProvider.h"
+#include "ClassicPrintDeclarative.h"
+
+//#define CLASSICPRINTQML_DESKTOP
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
+ ClassicPrint::init();
+ ClassicPrintDeclarative::init();
+
QDeclarativeView view;
- ClassicPrintProvider::init();
ClassicPrintProvider::addToView(&view);
QStringList fileModel;
+
+#if defined(CLASSICPRINTQML_DESKTOP)
+ QDir dcim("/home/thp/Pictures/Webcam/");
+#else
QDir dcim("/home/user/MyDocs/DCIM/");
+#endif
+
QStringList photos;
photos << "*.jpg" << "*.png";
@@ -27,7 +39,13 @@ int main(int argc, char *argv[])
view.rootContext()->setContextProperty("fileModel", fileModel);
view.setSource(QUrl("qrc:/classicprintqml.qml"));
+#if defined(CLASSICPRINTQML_DESKTOP)
+ view.scale(.8, .8);
+ view.resize(view.size() * .8);
+ view.show();
+#else
view.showFullScreen();
+#endif
return app.exec();
}
View
@@ -1,6 +1,8 @@
TEMPLATE = app
+CONFIG += debug
+
QT += declarative xml
OBJECTS_DIR = build
Oops, something went wrong.

0 comments on commit 83319fb

Please sign in to comment.