]> cloud.milkyroute.net Git - dolphin.git/commitdiff
[Places Item Edit Dialog] Fix accepting dialog with Return
authorKai Uwe Broulik <kde@privat.broulik.de>
Fri, 28 Oct 2016 11:40:50 +0000 (13:40 +0200)
committerKai Uwe Broulik <kde@privat.broulik.de>
Fri, 28 Oct 2016 11:40:50 +0000 (13:40 +0200)
By setting a parent for the QDialogButtonBox we let QDialog handle everything by itself.
Also, store the dialog button box as a member rather than just the OK button.

This removes the need to set the OK button as default manually (which didn't work anyway)
and fixes pressing Return while the input is focused erroneously opening the folder browser
rather than accepting the dialog.

REVIEW: 129213

src/panels/places/placesitemeditdialog.cpp
src/panels/places/placesitemeditdialog.h

index 7d365310f6f7e0275be4f2741edd396d19afb0f6..ffcac4c8f73f2b0df64a6ab8e8ab28e7d28375aa 100644 (file)
@@ -47,7 +47,8 @@ PlacesItemEditDialog::PlacesItemEditDialog(QWidget* parent) :
     m_urlEdit(0),
     m_textEdit(0),
     m_iconButton(0),
-    m_appLocal(0)
+    m_appLocal(0),
+    m_buttonBox(nullptr)
 {
 }
 
@@ -106,7 +107,7 @@ bool PlacesItemEditDialog::event(QEvent* event)
 
 void PlacesItemEditDialog::slotUrlChanged(const QString& text)
 {
-    m_okButton->setEnabled(!text.isEmpty());
+    m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.isEmpty());
 }
 
 PlacesItemEditDialog::~PlacesItemEditDialog()
@@ -115,20 +116,16 @@ PlacesItemEditDialog::~PlacesItemEditDialog()
 
 void PlacesItemEditDialog::initialize()
 {
-    QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
-    m_okButton = buttonBox->button(QDialogButtonBox::Ok);
-    m_okButton->setDefault(true);
-    m_okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
-    connect(buttonBox, &QDialogButtonBox::accepted, this, &PlacesItemEditDialog::accept);
-    connect(buttonBox, &QDialogButtonBox::rejected, this, &PlacesItemEditDialog::reject);
+    m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, this);
+    connect(m_buttonBox, &QDialogButtonBox::accepted, this, &PlacesItemEditDialog::accept);
+    connect(m_buttonBox, &QDialogButtonBox::rejected, this, &PlacesItemEditDialog::reject);
     setModal(true);
-    m_okButton->setDefault(true);
 
     QVBoxLayout *mainLayout = new QVBoxLayout;
     setLayout(mainLayout);
     QWidget* mainWidget = new QWidget(this);
     mainLayout->addWidget(mainWidget);
-    mainLayout->addWidget(buttonBox);
+    mainLayout->addWidget(m_buttonBox);
 
     QVBoxLayout* vBox = new QVBoxLayout(mainWidget);
 
index 8a0dc0471ff7437914c2572059b67aa5b10f88b2..f2d69781a592d901485cef3c4cc3123f9651f2f4 100644 (file)
@@ -31,7 +31,7 @@ class KIconButton;
 class KUrlRequester;
 class QLineEdit;
 class QCheckBox;
-class QPushButton;
+class QDialogButtonBox;
 
 class PlacesItemEditDialog: public QDialog
 {
@@ -72,7 +72,7 @@ private:
     QLineEdit* m_textEdit;
     KIconButton* m_iconButton;
     QCheckBox* m_appLocal;
-    QPushButton *m_okButton;
+    QDialogButtonBox *m_buttonBox;
 };
 
 #endif