[PATCH] Implement color dialog chooser when you select an <input type="color">.

12 views
Skip to first unread message

Alexis Menard

unread,
Jul 18, 2012, 4:06:42 PM7/18/12
to snowsh...@googlegroups.com
Reviewed-by: ???
---
src/desktop/DialogRunner.cpp | 16 ++++++++++++++++
src/desktop/DialogRunner.h | 6 ++++++
src/desktop/qml/PageWidget.qml | 15 +++++++++++++++
3 files changed, 37 insertions(+)

diff --git a/src/desktop/DialogRunner.cpp b/src/desktop/DialogRunner.cpp
index 17442fc..edf1fe2 100644
--- a/src/desktop/DialogRunner.cpp
+++ b/src/desktop/DialogRunner.cpp
@@ -44,3 +44,19 @@ void DialogRunner::openFileDialog(QObject* filePickerModel)
m_fileDialog->open();
}

+void DialogRunner::openColorDialog(QObject* colorDialogModel)
+{
+ if (!colorDialogModel)
+ return;
+
+ if (!m_colorDialog) {
+ m_colorDialog.reset(new QColorDialog);
+ connect(m_colorDialog.data(), SIGNAL(rejected()), this, SIGNAL(colorDialogRejected()));
+ connect(m_colorDialog.data(), SIGNAL(colorSelected(const QColor&)), this, SIGNAL(colorDialogAccepted(const QColor&)));
+ }
+
+ m_colorDialog->setCurrentColor(colorDialogModel->property("currentColor").value<QColor>());
+ m_colorDialog->setWindowTitle(QLatin1String("Choose Color - Snowshoe"));
+ m_colorDialog->open();
+}
+
diff --git a/src/desktop/DialogRunner.h b/src/desktop/DialogRunner.h
index 750d4ee..c99f9e5 100644
--- a/src/desktop/DialogRunner.h
+++ b/src/desktop/DialogRunner.h
@@ -17,6 +17,7 @@
#ifndef DialogRunner_h
#define DialogRunner_h

+#include <QColorDialog>
#include <QFileDialog>
#include <QObject>
#include <QStringList>
@@ -27,13 +28,18 @@ public:
explicit DialogRunner(QObject* parent = 0);

Q_INVOKABLE void openFileDialog(QObject* filePickerModel);
+ Q_INVOKABLE void openColorDialog(QObject* colorDialogModel);

Q_SIGNALS:
void fileDialogAccepted(const QStringList& selectedFiles);
void fileDialogRejected();

+ void colorDialogAccepted(const QColor& selectedColor);
+ void colorDialogRejected();
+
private:
QScopedPointer<QFileDialog> m_fileDialog;
+ QScopedPointer<QColorDialog> m_colorDialog;
};

#endif // DialogRunner_h
diff --git a/src/desktop/qml/PageWidget.qml b/src/desktop/qml/PageWidget.qml
index 7add516..0434bcb 100644
--- a/src/desktop/qml/PageWidget.qml
+++ b/src/desktop/qml/PageWidget.qml
@@ -104,6 +104,21 @@ Item {
}
}

+ experimental.colorChooser: Item {
+ id: colorChooser
+ // We can't use the model directly in the Connection below.
+ property QtObject colorChooserModel: model
+ Connections {
+ target: DialogRunner
+ onColorDialogAccepted: colorChooser.colorChooserModel.accept(selectedColor)
+ onColorDialogRejected: colorChooser.colorChooserModel.reject()
+ }
+
+ Component.onCompleted: {
+ DialogRunner.openColorDialog(colorChooserModel)
+ }
+ }
+
experimental.onDownloadRequested: {
downloadItem.destinationPath = BrowserWindow.decideDownloadPath(downloadItem.suggestedFilename)
downloadItem.start()
--
1.7.11.2

Rafael Brandao

unread,
Jul 18, 2012, 4:19:39 PM7/18/12
to snowsh...@googlegroups.com
Seems legit. :-) But just a question (inline).

r=me

Why not? Is it a bug on Qt?
 
+            property QtObject colorChooserModel: model
+            Connections {
+                target: DialogRunner
+                onColorDialogAccepted: colorChooser.colorChooserModel.accept(selectedColor)
+                onColorDialogRejected: colorChooser.colorChooserModel.reject()
+            }
+
+            Component.onCompleted: {
+                DialogRunner.openColorDialog(colorChooserModel)
+            }
+        }
+
         experimental.onDownloadRequested: {
             downloadItem.destinationPath = BrowserWindow.decideDownloadPath(downloadItem.suggestedFilename)
             downloadItem.start()
--
1.7.11.2




--
Rafael Brandao @ INdT

Rafael Brandao

unread,
Jul 18, 2012, 4:35:56 PM7/18/12
to snowsh...@googlegroups.com
Alexis explained personally the reason behind it: the name "model" is also used on a component creation context, or something like that.
Reply all
Reply to author
Forward
0 new messages