From 3e1359a8bc4003c0f2c5695c22f885caea31ef8b Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Thu, 3 Nov 2011 18:23:26 +0100 Subject: [PATCH] use a system KDialog for QueryDialog --- .../plasmacomponents/CMakeLists.txt | 3 +- .../plasmacomponents/kdialogproxy.cpp | 150 ++++++++++++++++++ .../plasmacomponents/kdialogproxy.h | 88 ++++++++++ .../plasmacomponentsplugin.cpp | 3 + 4 files changed, 243 insertions(+), 1 deletion(-) create mode 100644 declarativeimports/plasmacomponents/kdialogproxy.cpp create mode 100644 declarativeimports/plasmacomponents/kdialogproxy.h diff --git a/declarativeimports/plasmacomponents/CMakeLists.txt b/declarativeimports/plasmacomponents/CMakeLists.txt index e60727554..a8605950a 100644 --- a/declarativeimports/plasmacomponents/CMakeLists.txt +++ b/declarativeimports/plasmacomponents/CMakeLists.txt @@ -6,6 +6,7 @@ set(plasmacomponents_SRCS enums.cpp qmenu.cpp qmenuitem.cpp + kdialogproxy.cpp ) INCLUDE_DIRECTORIES( @@ -18,7 +19,7 @@ qt4_automoc(${plasmacomponents_SRCS}) add_library(plasmacomponentsplugin SHARED ${plasmacomponents_SRCS}) -target_link_libraries(plasmacomponentsplugin ${QT_QTCORE_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY} ${QT_QTGUI_LIBRARY}) +target_link_libraries(plasmacomponentsplugin ${QT_QTCORE_LIBRARY} ${QT_QTDECLARATIVE_LIBRARY} ${QT_QTGUI_LIBRARY} ${KDE4_KDEUI_LIBRARY}) install(TARGETS plasmacomponentsplugin DESTINATION ${IMPORTS_INSTALL_DIR}/org/kde/plasma/components) diff --git a/declarativeimports/plasmacomponents/kdialogproxy.cpp b/declarativeimports/plasmacomponents/kdialogproxy.cpp new file mode 100644 index 000000000..89b7aa4cf --- /dev/null +++ b/declarativeimports/plasmacomponents/kdialogproxy.cpp @@ -0,0 +1,150 @@ +/* +* Copyright (C) 2011 by Marco MArtin +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Library General Public License as +* published by the Free Software Foundation; either version 2, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Library General Public License for more details +* +* You should have received a copy of the GNU Library General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include "kdialogproxy.h" + +#include + +#include + +KDialogProxy::KDialogProxy (QObject *parent) + : QObject(parent), + m_status(DialogStatus::Closed) +{ + m_dialog = new KDialog(0); + m_label = new QLabel(m_dialog); + m_label->setWordWrap(true); + m_dialog->setMainWidget(m_label); + m_dialog->setButtons( KDialog::Ok | KDialog::Cancel); + connect(m_dialog, SIGNAL(okClicked()), this, SIGNAL(accepted())); + connect(m_dialog, SIGNAL(cancelClicked()), this, SIGNAL(rejected())); +} + +KDialogProxy::~KDialogProxy() +{ + delete m_dialog; +} + + +void KDialogProxy::setTitleText(const QString &text) +{ + if (text == m_titleText) { + return; + } + + m_dialog->setCaption(text); + m_titleText = text; + emit titleTextChanged(); +} + +QString KDialogProxy::titleText() const +{ + return m_titleText; +} + + +void KDialogProxy::setTitleIcon(const QString &icon) +{ + if (icon == m_titleIcon) { + return; + } + + m_dialog->setWindowIcon(KIcon(icon)); + m_titleIcon = icon; + emit titleIconChanged(); +} + +QString KDialogProxy::titleIcon() const +{ + return m_titleIcon; +} + + +void KDialogProxy::setMessage(const QString &message) +{ + if (message == m_message) { + return; + } + + m_label->setText(message); + m_message = message; + emit messageChanged(); +} + +QString KDialogProxy::message() const +{ + return m_message; +} + + +void KDialogProxy::setAcceptButtonText(const QString &text) +{ + if (text == m_acceptButtonText) { + return; + } + + m_dialog->setButtonText(KDialog::Ok, text); + m_acceptButtonText = text; + emit acceptButtonTextChanged(); +} + +QString KDialogProxy::acceptButtonText() const +{ + return m_acceptButtonText; +} + + +void KDialogProxy::setRejectButtonText(const QString &text) +{ + if (text == m_rejectButtonText) { + return; + } + + m_dialog->setButtonText(KDialog::Cancel, text); + m_rejectButtonText = text; + emit rejectButtonTextChanged(); +} + +QString KDialogProxy::rejectButtonText() const +{ + return m_rejectButtonText; +} + + +DialogStatus::Status KDialogProxy::status() const +{ + return m_status; +} + +void KDialogProxy::open() +{ + m_dialog->show(); + m_status = DialogStatus::Open; + emit statusChanged(); +} + +void KDialogProxy::close() +{ + m_dialog->hide(); + m_status = DialogStatus::Closed; + emit statusChanged(); +} + +#include "kdialogproxy.moc" + diff --git a/declarativeimports/plasmacomponents/kdialogproxy.h b/declarativeimports/plasmacomponents/kdialogproxy.h new file mode 100644 index 000000000..19e4ffa8f --- /dev/null +++ b/declarativeimports/plasmacomponents/kdialogproxy.h @@ -0,0 +1,88 @@ +/* +* Copyright (C) 2011 by Marco MArtin +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU Library General Public License as +* published by the Free Software Foundation; either version 2, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Library General Public License for more details +* +* You should have received a copy of the GNU Library General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#ifndef KDIALOG_PROXY_H +#define KDIALOG_PROXY_H + +#include +#include +#include "kdialogproxy.h" +#include "enums.h" + +class QLabel; + +class KDialogProxy : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QString titleText READ titleText WRITE setTitleText NOTIFY titleTextChanged) + Q_PROPERTY(QString titleIcon READ titleIcon WRITE setTitleIcon NOTIFY titleIconChanged) + Q_PROPERTY(QString message READ message WRITE setMessage NOTIFY messageChanged) + Q_PROPERTY(QString acceptButtonText READ acceptButtonText WRITE setAcceptButtonText NOTIFY acceptButtonTextChanged) + Q_PROPERTY(QString rejectButtonText READ rejectButtonText WRITE setRejectButtonText NOTIFY rejectButtonTextChanged) + Q_PROPERTY(DialogStatus::Status status READ status NOTIFY statusChanged) + +public: + KDialogProxy(QObject *parent = 0); + ~KDialogProxy(); + + void setTitleText(const QString &text); + QString titleText() const; + + void setTitleIcon(const QString &icon); + QString titleIcon() const; + + void setMessage(const QString &message); + QString message() const; + + void setAcceptButtonText(const QString &text); + QString acceptButtonText() const; + + void setRejectButtonText(const QString &text); + QString rejectButtonText() const; + + void setStatus(DialogStatus::Status status); + DialogStatus::Status status() const; + + Q_INVOKABLE void open(); + Q_INVOKABLE void close(); + +Q_SIGNALS: + void titleTextChanged(); + void titleIconChanged(); + void messageChanged(); + void acceptButtonTextChanged(); + void rejectButtonTextChanged(); + void statusChanged(); + void accepted(); + void rejected(); + +private: + KDialog *m_dialog; + QLabel *m_label; + QString m_titleText; + QString m_titleIcon; + QString m_message; + QString m_acceptButtonText; + QString m_rejectButtonText; + DialogStatus::Status m_status; +}; + +#endif //KDIALOG_PROXY_H + diff --git a/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp b/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp index 0ee5a0a98..87c1cca0c 100644 --- a/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp +++ b/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp @@ -26,6 +26,7 @@ #include "enums.h" #include "qmenu.h" #include "qmenuitem.h" +#include "kdialogproxy.h" void PlasmaComponentsPlugin::registerTypes(const char *uri) @@ -37,6 +38,8 @@ void PlasmaComponentsPlugin::registerTypes(const char *uri) qmlRegisterType(uri, 0, 1, "ContextMenu"); qmlRegisterType(uri, 0, 1, "MenuItem"); + qmlRegisterType(uri, 0, 1, "QueryDialog"); + qmlRegisterType(uri, 0, 1, "RangeModel"); qmlRegisterUncreatableType(uri, 0, 1, "DialogStatus", "");