summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Habacker <[email protected]>2015-06-02 13:24:54 +0200
committerRalf Habacker <[email protected]>2015-06-02 14:11:09 +0200
commit639c0367f818c36ff4cf0c947ae7288055d0eb50 (patch)
tree50a6c46c5b5c294a42856be66b2bb8ec7c13ac74
parent2246666e355a9f63e1709a758a42ab5de6640f3a (diff)
Merge in Qt5 variant of OverwriteDialog from frameworks branch.
Base on the required Qt 5 fixes OverwriteDialog has been refactored to use SinglePageDialogBase and SingleDialogPageBase has gotten the required Qt5 changes.
-rw-r--r--umbrello/dialogs/overwritedialog.cpp55
-rw-r--r--umbrello/dialogs/overwritedialog.h14
-rw-r--r--umbrello/dialogs/singlepagedialogbase.cpp48
-rw-r--r--umbrello/dialogs/singlepagedialogbase.h6
4 files changed, 71 insertions, 52 deletions
diff --git a/umbrello/dialogs/overwritedialog.cpp b/umbrello/dialogs/overwritedialog.cpp
index 8d04d5d..9182e59 100644
--- a/umbrello/dialogs/overwritedialog.cpp
+++ b/umbrello/dialogs/overwritedialog.cpp
@@ -16,45 +16,36 @@
// qt includes
#include <QCheckBox>
+#include <QDialogButtonBox>
#include <QLabel>
#include <QLayout>
+#include <QPushButton>
#include <QVBoxLayout>
/**
* Constructor sets up the dialog, adding checkbox and label.
*/
-OverwriteDialog::OverwriteDialog(
- const QString& fileName,
- const QString& outputDirectory,
- bool applyToAllRemaining, QWidget* parent)
- : KDialog(parent)
+OverwriteDialog::OverwriteDialog(const QString& fileName, const QString& outputDirectory,
+ bool applyToAllRemaining, QWidget* parent)
+ : SinglePageDialogBase(parent, true)
{
setCaption(i18n("Destination File Already Exists"));
- setButtons(Ok | Apply | Cancel);
- setDefaultButton(Yes);
+ setButtonText(Ok, i18n("&Overwrite"));
+ setButtonText(Apply, i18n("&Generate Similar File Name"));
+ setButtonText(Cancel, i18n("&Do Not Generate File"));
setModal(true);
- showButtonSeparator(true);
QFrame *frame = new QFrame(this);
- setMainWidget(frame);
-
QVBoxLayout* layout = new QVBoxLayout(frame);
- layout->setSpacing(spacingHint());
layout->setMargin(0);
- QLabel* dialogueLabel = new QLabel(i18n("The file %1 already exists in %2.\n\nUmbrello can overwrite the file, generate a similar\nfile name or not generate this file.", fileName, outputDirectory), frame);
+ QLabel* dialogueLabel = new QLabel(i18n("The file %1 already exists in %2.\n\nUmbrello can overwrite the file, generate a similar\nfile name or not generate this file.", fileName, outputDirectory));
layout->addWidget(dialogueLabel);
- m_applyToAllRemaining = new QCheckBox(i18n("&Apply to all remaining files"), frame);
+ m_applyToAllRemaining = new QCheckBox(i18n("&Apply to all remaining files"));
m_applyToAllRemaining->setChecked(applyToAllRemaining);
layout->addWidget(m_applyToAllRemaining);
-
- setButtonText(KDialog::Ok, i18n("&Overwrite"));
- setButtonText(KDialog::Apply, i18n("&Generate Similar File Name"));
- setButtonText(KDialog::Cancel, i18n("&Do Not Generate File"));
- connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
- connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
- connect(this, SIGNAL(cancelClicked()), this, SLOT(slotCancel()));
+ setMainWidget(frame);
}
/**
@@ -65,28 +56,12 @@ OverwriteDialog::~OverwriteDialog()
}
/**
- * Overrides standard operation to call QDialog::done(Yes).
- * This is a kludge, see note in class description.
- */
-void OverwriteDialog::slotOk()
-{
- done(Yes);
-}
-
-/**
- * Overrides standard operation to call QDialog::done(No).
- */
-void OverwriteDialog::slotApply()
-{
- done(No);
-}
-
-/**
- * Overrides standard operation to call QDialog::done(Cancel).
+ * Apply the dialog
+ * @return true apply succeeds
*/
-void OverwriteDialog::slotCancel()
+bool OverwriteDialog::apply()
{
- done(Cancel);
+ return true;
}
/**
diff --git a/umbrello/dialogs/overwritedialog.h b/umbrello/dialogs/overwritedialog.h
index 533ad4c..6a89d72 100644
--- a/umbrello/dialogs/overwritedialog.h
+++ b/umbrello/dialogs/overwritedialog.h
@@ -11,7 +11,7 @@
#ifndef OVERWRITEDIALOG_H
#define OVERWRITEDIALOG_H
-#include <kdialog.h>
+#include "singlepagedialogbase.h"
class QCheckBox;
@@ -21,26 +21,22 @@ class QCheckBox;
* or cancel. Gives an option to apply the choice to all remaining files.
*
* Uses OK and Apply buttons but overrides their text and behaviour, probably
- * better to use user defined buttons but I couldn't work out how. KDialogBase guru needed.
+ * better to use user defined buttons but I couldn't work out how.
*
* @author Jonathan Riddell <[email protected]>
* Bugs and comments to [email protected] or http://bugs.kde.org
*/
-class OverwriteDialog: public KDialog
+class OverwriteDialog: public SinglePageDialogBase
{
Q_OBJECT
public:
OverwriteDialog(const QString& fileName, const QString& outputDirectory,
- bool applyToAllRemaining, QWidget* parent=0);
+ bool applyToAllRemaining, QWidget* parent = 0);
~OverwriteDialog();
+ bool apply();
bool applyToAllRemaining();
-protected slots:
- virtual void slotOk();
- virtual void slotApply();
- virtual void slotCancel();
-
private:
QCheckBox* m_applyToAllRemaining;
};
diff --git a/umbrello/dialogs/singlepagedialogbase.cpp b/umbrello/dialogs/singlepagedialogbase.cpp
index cff5fd7..6dc1afe 100644
--- a/umbrello/dialogs/singlepagedialogbase.cpp
+++ b/umbrello/dialogs/singlepagedialogbase.cpp
@@ -35,8 +35,8 @@ SinglePageDialogBase::SinglePageDialogBase(QWidget *parent, bool withApplyButton
m_buttonBox = new QDialogButtonBox(buttons);
if (withSearchButton)
m_buttonBox->button(QDialogButtonBox::Ok)->setText(i18n("Search"));
- connect(m_buttonBox, SIGNAL(accepted()), this, SLOT(slotOk()));
- connect(m_buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+
+ connect(m_buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(slotClicked(QAbstractButton*)));
mainWidget();
}
#else
@@ -110,6 +110,26 @@ void SinglePageDialogBase::setMainWidget(QWidget *widget)
}
/**
+ * Set the text of a dedicated button.
+ * @param code button code
+ * @param text button text
+ */
+void SinglePageDialogBase::setButtonText(SinglePageDialogBase::ButtonCode code, const QString &text)
+{
+ switch(code) {
+ case Ok:
+ m_buttonBox->button(QDialogButtonBox::Ok)->setText(text);
+ break;
+ case Apply:
+ m_buttonBox->button(QDialogButtonBox::Apply)->setText(text);
+ break;
+ case Cancel:
+ m_buttonBox->button(QDialogButtonBox::Cancel)->setText(text);
+ break;
+ }
+}
+
+/**
* @return The current main widget. Will create a QWidget as the mainWidget
* if none was set before. This way you can write
* \code
@@ -132,6 +152,7 @@ QWidget *SinglePageDialogBase::mainWidget()
void SinglePageDialogBase::slotApply()
{
apply();
+ done(Apply);
}
/**
@@ -140,12 +161,33 @@ void SinglePageDialogBase::slotApply()
void SinglePageDialogBase::slotOk()
{
if (apply()) {
- accept();
+ done(Ok);
}
}
#if QT_VERSION >= 0x050000
/**
+ * Used when the Cancel button is clicked.
+ */
+void SinglePageDialogBase::slotCancel()
+{
+ done(Cancel);
+}
+
+/**
+ * Used when the Cancel button is clicked.
+ */
+void SinglePageDialogBase::slotClicked(QAbstractButton *button)
+{
+ if (button == m_buttonBox->button(QDialogButtonBox::Apply))
+ slotApply();
+ else if (button == m_buttonBox->button(QDialogButtonBox::Ok))
+ slotOk();
+ else if (button == m_buttonBox->button(QDialogButtonBox::Cancel))
+ slotCancel();
+}
+
+/**
* Enable the ok button.
* @param enable the enable value
*/
diff --git a/umbrello/dialogs/singlepagedialogbase.h b/umbrello/dialogs/singlepagedialogbase.h
index b69038e..3487ecf 100644
--- a/umbrello/dialogs/singlepagedialogbase.h
+++ b/umbrello/dialogs/singlepagedialogbase.h
@@ -41,16 +41,22 @@ public:
virtual bool apply();
#if QT_VERSION >= 0x050000
+ typedef enum { Cancel = 0, Ok = 1, Apply = 2, No = 2 } ButtonCode;
// keep in sync with MultiPageDialogBase
void setCaption(const QString &caption);
QWidget *mainWidget();
void setMainWidget(QWidget *widget);
+ void setButtonText(ButtonCode code, const QString &text);
#endif
protected slots:
void slotApply();
void slotOk();
+#if QT_VERSION >= 0x050000
+ void slotCancel();
+ void slotClicked(QAbstractButton*);
+#endif
protected:
#if QT_VERSION >= 0x050000