diff options
author | Alexis Menard <alexis.menard@openbossa.org> | 2012-07-18 17:05:55 -0300 |
---|---|---|
committer | Alexis Menard <alexis.menard@openbossa.org> | 2012-07-18 18:12:00 -0300 |
commit | 5edf17a3922fa3185a28cf442c00cd6a448c1dbf (patch) | |
tree | 113cfcf44798d8b23ec4364da0e584c569cc3f18 | |
parent | 696deb40372244242681bf7b5e94f8d23c453c44 (diff) | |
download | snowshoe-5edf17a3922fa3185a28cf442c00cd6a448c1dbf.tar.gz |
Implement color dialog chooser when you select an <input type="color">.
Reviewed-by: Rafael Brandao
-rw-r--r-- | src/desktop/DialogRunner.cpp | 16 | ||||
-rw-r--r-- | src/desktop/DialogRunner.h | 6 | ||||
-rw-r--r-- | src/desktop/qml/PageWidget.qml | 15 |
3 files changed, 37 insertions, 0 deletions
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() |