[gegl-qt] Examples: Make operations listing example interactive
- From: Jon Nordby <jonnor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl-qt] Examples: Make operations listing example interactive
- Date: Mon, 30 Apr 2012 23:32:28 +0000 (UTC)
commit 160c66fc0c518bec22b08d97e3b859da9281a752
Author: Jon Nordby <jononor gmail com>
Date: Tue Apr 3 01:00:00 2012 +0200
Examples: Make operations listing example interactive
Note to self:
When QML elements have an undefined width/height, it will default
to 0. However, because QML elements do not clip to their geometry
by default this can lead to an element being visually OK, but
not responding to any events (because the event area is something by 0).
examples/common/operations.cpp | 25 ++++++++
examples/common/operations.h | 19 ++++++
examples/qml-operations/OperationView.qml | 47 ++++++++++++++
examples/qml-operations/SingleOperationView.qml | 43 +++++++++++++
examples/qml-operations/qml-operations.cpp | 8 +--
examples/qml-operations/qml-operations.pro | 4 +-
examples/qml-operations/qml-operations.qml | 76 ++--------------------
examples/qml-operations/qmloperations.qrc | 2 +
8 files changed, 149 insertions(+), 75 deletions(-)
---
diff --git a/examples/common/operations.cpp b/examples/common/operations.cpp
index dabfdc3..bccd8cd 100644
--- a/examples/common/operations.cpp
+++ b/examples/common/operations.cpp
@@ -209,3 +209,28 @@ QObjectList Operation::properties()
return list;
}
+
+OperationsBrowser::OperationsBrowser(QObject *parent)
+ : QObject(parent)
+{
+ mAllOperations = Operations::all();
+}
+
+void OperationsBrowser::selectOperation(const QString &operationName)
+{
+ if (mSelectedOperation == operationName) {
+ return;
+ }
+ mSelectedOperation = operationName;
+ Q_EMIT selectedOperationChanged();
+}
+
+Operation *OperationsBrowser::selectedOperation()
+{
+ return mAllOperations.value(mSelectedOperation);
+}
+
+QStringList OperationsBrowser::availableOperations()
+{
+ return mAllOperations.keys();
+}
diff --git a/examples/common/operations.h b/examples/common/operations.h
index 3a5566d..2cd9900 100644
--- a/examples/common/operations.h
+++ b/examples/common/operations.h
@@ -72,6 +72,25 @@ public:
static QMap<QString, Operation*> all();
};
+class OperationsBrowser : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit OperationsBrowser(QObject *parent = 0);
+
+ Operation *selectedOperation();
+ QStringList availableOperations();
+ Q_INVOKABLE void selectOperation(const QString &operationName);
+ Q_SIGNAL void selectedOperationChanged();
+
+ Q_PROPERTY (QObject * selectedOperation READ selectedOperation NOTIFY selectedOperationChanged)
+ Q_PROPERTY (QStringList availableOperations READ availableOperations CONSTANT)
+
+private:
+ QString mSelectedOperation;
+ QMap<QString, Operation*> mAllOperations;
+};
#endif // OPERATIONS_H
diff --git a/examples/qml-operations/OperationView.qml b/examples/qml-operations/OperationView.qml
new file mode 100644
index 0000000..b7acff1
--- /dev/null
+++ b/examples/qml-operations/OperationView.qml
@@ -0,0 +1,47 @@
+import QtQuick 1.0
+
+Rectangle {
+
+ Text {
+ height: 40
+ text: "Available operations"
+ font.pixelSize: 25
+ }
+
+ ListView {
+ id: operationsView
+ y: 50
+ height: 200
+ width: parent.width
+ model: browser.availableOperations
+ delegate: operationListDelegate
+
+ //focus: true
+ }
+
+ Component {
+ id: operationListDelegate
+
+ Rectangle {
+ id: operationListDelegateRoot
+ width: parent.width
+ height: 15
+
+ Text {
+ text: modelData
+ }
+
+ MouseArea {
+ anchors.fill: operationListDelegateRoot
+ onClicked: {
+ console.log("clickity")
+ operationsView.currentIndex = index
+ browser.selectOperation(modelData)
+ }
+ }
+
+ }
+ }
+
+}
+
diff --git a/examples/qml-operations/SingleOperationView.qml b/examples/qml-operations/SingleOperationView.qml
new file mode 100644
index 0000000..4dd0793
--- /dev/null
+++ b/examples/qml-operations/SingleOperationView.qml
@@ -0,0 +1,43 @@
+import QtQuick 1.0
+
+Rectangle {
+ id: singleOperationView
+
+ Rectangle {
+ height: 440
+ width: 250
+
+ Text {
+ height: 40
+ text: "Operation: " + browser.selectedOperation.name
+ font.pixelSize: 25
+ }
+ ListView {
+ y: 50
+ height: 400
+ width: parent.width
+
+ model: browser.selectedOperation.properties
+ delegate: propertyDelegate
+
+ }
+ }
+
+ Component {
+ id: propertyDelegate
+
+ Item {
+ height: 80
+
+ Column {
+ Text { text: modelData.name }
+ Text { text: modelData.shortDescription }
+ Text { text: modelData.defaultValue }
+ Text { text: modelData.minValue }
+ Text { text: modelData.maxValue }
+ }
+
+ }
+
+ }
+}
diff --git a/examples/qml-operations/qml-operations.cpp b/examples/qml-operations/qml-operations.cpp
index dcf7d3a..3635356 100644
--- a/examples/qml-operations/qml-operations.cpp
+++ b/examples/qml-operations/qml-operations.cpp
@@ -30,15 +30,13 @@ int main(int argc, char *argv[])
gegl_init(&argc, &argv);
Q_INIT_RESOURCE(qmloperations);
- QMap<QString, Operation *> operationMap = Operations::all();
- QStringList operations = operationMap.keys();
- Operation *selectedOperation = operationMap.value("gegl:dropshadow");
+ OperationsBrowser browser;
+ browser.selectOperation(browser.availableOperations().at(2));
QDeclarativeView view;
- view.rootContext()->setContextProperty("availableOperations", QVariant::fromValue(operations));
- view.rootContext()->setContextProperty("selectedOperation", selectedOperation);
+ view.rootContext()->setContextProperty("browser", &browser);
view.setSource(QUrl("qrc:/qml-operations.qml"));
view.show();
diff --git a/examples/qml-operations/qml-operations.pro b/examples/qml-operations/qml-operations.pro
index 24e0699..b67e905 100644
--- a/examples/qml-operations/qml-operations.pro
+++ b/examples/qml-operations/qml-operations.pro
@@ -3,4 +3,6 @@ include(../examples-common.pri)
SOURCES += qml-operations.cpp
RESOURCES += qmloperations.qrc
-OTHER_FILES += qml-operations.qml
+OTHER_FILES += qml-operations.qml \
+ OperationView.qml \
+ SingleOperationView.qml
diff --git a/examples/qml-operations/qml-operations.qml b/examples/qml-operations/qml-operations.qml
index ba155a5..ee4977f 100644
--- a/examples/qml-operations/qml-operations.qml
+++ b/examples/qml-operations/qml-operations.qml
@@ -4,78 +4,16 @@ import QtQuick 1.0
Rectangle {
width: 500
height: 500
- x: 0
- y: 0
-
- ListView {
- anchors.left: parent.left
- anchors.top: parent.top
- anchors.bottom: parent.bottom
- width: parent.width/2
-
- Component {
- id: operationListDelegate
-
- Rectangle {
- height: 15
-
- color: "black"
-
- Text {
- text: modelData
- }
- MouseArea {
- anchors.fill: parent
- onClicked: {
- ListView.currentIndex = index
- }
- }
- }
- }
-
- id: operationsView
- model: availableOperations
- delegate: operationListDelegate
-
- focus: true
+ OperationView {
+ id: operationsList
+ width: 300 // parent.width / 0.6
}
- Component {
- id: propertyDelegate
-
- Item {
- height: 80
-
- Column {
- Text { text: modelData.name }
- Text { text: modelData.shortDescription }
- Text { text: modelData.defaultValue }
- Text { text: modelData.minValue }
- Text { text: modelData.maxValue }
- }
-
- }
-
-
-
+ SingleOperationView {
+ id: singleOperation
+ width: 200 // parent.width / 0.4
+ anchors.left: operationsList.right
}
-
- ListView {
- anchors.left: operationsView.right
- anchors.right: parent.right
- anchors.top: parent.top
- anchors.bottom: parent.bottom
-
- id: singleOperationView
- model: selectedOperation.properties
- delegate: propertyDelegate
-
- }
}
-
-
-
-
-
diff --git a/examples/qml-operations/qmloperations.qrc b/examples/qml-operations/qmloperations.qrc
index bf31d20..492a3c4 100644
--- a/examples/qml-operations/qmloperations.qrc
+++ b/examples/qml-operations/qmloperations.qrc
@@ -1,5 +1,7 @@
<RCC>
<qresource prefix="/">
<file>qml-operations.qml</file>
+ <file>SingleOperationView.qml</file>
+ <file>OperationView.qml</file>
</qresource>
</RCC>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]