Alexis Menard
unread,Jul 18, 2012, 4:56:58 PM7/18/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to snowsh...@googlegroups.com
Reviewed-by: ??
---
src/desktop/DialogRunner.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++
src/desktop/DialogRunner.h | 18 +++++++++++++
src/desktop/qml/PageWidget.qml | 45 ++++++++++++++++++++++++++++++++
3 files changed, 122 insertions(+)
diff --git a/src/desktop/DialogRunner.cpp b/src/desktop/DialogRunner.cpp
index edf1fe2..f0693d5 100644
--- a/src/desktop/DialogRunner.cpp
+++ b/src/desktop/DialogRunner.cpp
@@ -60,3 +60,62 @@ void DialogRunner::openColorDialog(QObject* colorDialogModel)
m_colorDialog->open();
}
+void DialogRunner::openAlert(QObject* alertModel)
+{
+ ensureMessageBox();
+ m_messageBox->setText(alertModel->property("message").toString());
+ m_messageBox->setIcon(QMessageBox::Warning);
+ m_messageBox->setStandardButtons(QMessageBox::Ok);
+ openMessageBox(alertModel);
+}
+
+void DialogRunner::openConfirm(QObject* confirmModel)
+{
+ ensureMessageBox();
+ m_messageBox->setText(confirmModel->property("message").toString());
+ m_messageBox->setIcon(QMessageBox::Question);
+ m_messageBox->setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
+ openMessageBox(confirmModel);
+}
+
+void DialogRunner::openPrompt(QObject* promptModel)
+{
+ if (!promptModel)
+ return;
+
+ if (!m_inputDialog)
+ m_inputDialog.reset(new QInputDialog);
+
+ m_inputDialog->setInputMode(QInputDialog::TextInput);
+ m_inputDialog->setLabelText(promptModel->property("message").toString());
+ m_inputDialog->setTextValue(promptModel->property("defaultValue").toString());
+ connect(m_inputDialog.data(), SIGNAL(rejected()), this, SIGNAL(inputDialogRejected()));
+ connect(m_inputDialog.data(), SIGNAL(textValueSelected(const QString&)), this, SIGNAL(inputDialogAccepted(const QString&)));
+ m_inputDialog->open();
+}
+
+void DialogRunner::ensureMessageBox()
+{
+ if (!m_messageBox)
+ m_messageBox.reset(new QMessageBox);
+}
+
+void DialogRunner::openMessageBox(QObject* model)
+{
+ if (!model)
+ return;
+
+ connect(m_messageBox.data(), SIGNAL(buttonClicked(QAbstractButton*)), this, SLOT(onMessageBoxButtonClicked(QAbstractButton*)));
+
+ m_messageBox->setWindowTitle(QLatin1String("Snowshoe"));
+ m_messageBox->open();
+}
+
+void DialogRunner::onMessageBoxButtonClicked(QAbstractButton* button)
+{
+ QMessageBox::ButtonRole role = m_messageBox->buttonRole(button);
+ if (role == QMessageBox::AcceptRole)
+ emit messageBoxAccepted();
+ if (role == QMessageBox::RejectRole)
+ emit messageBoxRejected();
+}
diff --git a/src/desktop/DialogRunner.h b/src/desktop/DialogRunner.h
index c99f9e5..49e3f6f 100644
--- a/src/desktop/DialogRunner.h
+++ b/src/desktop/DialogRunner.h
@@ -19,6 +19,8 @@
#include <QColorDialog>
#include <QFileDialog>
+#include <QInputDialog>
+#include <QMessageBox>
#include <QObject>
#include <QStringList>
@@ -29,6 +31,9 @@ public:
Q_INVOKABLE void openFileDialog(QObject* filePickerModel);
Q_INVOKABLE void openColorDialog(QObject* colorDialogModel);
+ Q_INVOKABLE void openAlert(QObject* alertModel);
+ Q_INVOKABLE void openConfirm(QObject* confirmModel);
+ Q_INVOKABLE void openPrompt(QObject* promptModel);
Q_SIGNALS:
void fileDialogAccepted(const QStringList& selectedFiles);
@@ -37,9 +42,22 @@ Q_SIGNALS:
void colorDialogAccepted(const QColor& selectedColor);
void colorDialogRejected();
+ void messageBoxAccepted();
+ void messageBoxRejected();
+
+ void inputDialogAccepted(const QString& text);
+ void inputDialogRejected();
+
+private slots:
+ void onMessageBoxButtonClicked(QAbstractButton*);
+
private:
+ void ensureMessageBox();
+ void openMessageBox(QObject*);
QScopedPointer<QFileDialog> m_fileDialog;
QScopedPointer<QColorDialog> m_colorDialog;
+ QScopedPointer<QMessageBox> m_messageBox;
+ QScopedPointer<QInputDialog> m_inputDialog;
};
#endif // DialogRunner_h
diff --git a/src/desktop/qml/PageWidget.qml b/src/desktop/qml/PageWidget.qml
index 0434bcb..b32b1fb 100644
--- a/src/desktop/qml/PageWidget.qml
+++ b/src/desktop/qml/PageWidget.qml
@@ -119,6 +119,51 @@ Item {
}
}
+ experimental.alertDialog: Item {
+ id: alertBox
+ // We can't use the model directly in the Connection below.
+ property QtObject alertBoxModel: model
+ Connections {
+ target: DialogRunner
+ onMessageBoxRejected: alertBox.alertBoxModel.dismiss()
+ onMessageBoxAccepted: alertBox.alertBoxModel.dismiss()
+ }
+
+ Component.onCompleted: {
+ DialogRunner.openAlert(alertBoxModel)
+ }
+ }
+
+ experimental.confirmDialog: Item {
+ id: confirmBox
+ // We can't use the model directly in the Connection below.
+ property QtObject confirmBoxModel: model
+ Connections {
+ target: DialogRunner
+ onMessageBoxRejected: confirmBox.confirmBoxModel.reject()
+ onMessageBoxAccepted: confirmBox.confirmBoxModel.accept()
+ }
+
+ Component.onCompleted: {
+ DialogRunner.openConfirm(confirmBoxModel)
+ }
+ }
+
+ experimental.promptDialog: Item {
+ id: promptDialog
+ // We can't use the model directly in the Connection below.
+ property QtObject promptDialogModel: model
+ Connections {
+ target: DialogRunner
+ onInputDialogRejected: promptDialog.promptDialogModel.reject()
+ onInputDialogAccepted: promptDialog.promptDialogModel.accept(text)
+ }
+
+ Component.onCompleted: {
+ DialogRunner.openPrompt(promptDialogModel)
+ }
+ }
+
experimental.onDownloadRequested: {
downloadItem.destinationPath = BrowserWindow.decideDownloadPath(downloadItem.suggestedFilename)
downloadItem.start()
--
1.7.11.2