From f48aca47a589972a2606429da1097e1b5cbd7306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Thu, 12 Dec 2013 14:17:26 +0100 Subject: [PATCH] [kwin] Use ui-file for ShortcutDialog At the same time switching to QKeySequenceEdit for capturing the shortcut. This allows to get rid of xmlgui. --- CMakeLists.txt | 6 ++- shortcutdialog.ui | 104 ++++++++++++++++++++++++++++++++++++++++++++++ useractions.cpp | 58 ++++++++++---------------- useractions.h | 12 ++---- 4 files changed, 133 insertions(+), 47 deletions(-) create mode 100644 shortcutdialog.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index ae322c3f6..14b95e897 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -226,6 +226,10 @@ qt5_add_dbus_interface( kwin_KDEINIT_SRCS qt5_add_resources( kwin_KDEINIT_SRCS resources.qrc ) +kde4_add_ui_files(kwin_KDEINIT_SRCS + shortcutdialog.ui +) + ########### target link libraries ############### set(kwin_OWN_LIBS @@ -244,6 +248,7 @@ set(kwin_QT_LIBS set(kwin_KDE_LIBS KF5::ConfigCore KF5::CoreAddons + KF5::ConfigWidgets KF5::Crash KF5::GlobalAccel KF5::I18n @@ -251,7 +256,6 @@ set(kwin_KDE_LIBS KF5::Service KF5::Plasma KF5::WindowSystem - KF5::XmlGui ) set(kwin_XLIB_LIBS diff --git a/shortcutdialog.ui b/shortcutdialog.ui new file mode 100644 index 000000000..3121c543c --- /dev/null +++ b/shortcutdialog.ui @@ -0,0 +1,104 @@ + + + ShortcutDialog + + + + 0 + 0 + 200 + 100 + + + + Dialog + + + + + + + + + + + ... + + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + ShortcutDialog + accept() + + + 195 + 85 + + + 157 + 99 + + + + + buttonBox + rejected() + ShortcutDialog + reject() + + + 195 + 91 + + + 199 + 99 + + + + + clearButton + clicked() + keySequenceEdit + clear() + + + 181 + 19 + + + 146 + 15 + + + + + diff --git a/useractions.cpp b/useractions.cpp index a97a67332..564609944 100755 --- a/useractions.cpp +++ b/useractions.cpp @@ -49,7 +49,6 @@ along with this program. If not, see . #include #endif -#include #include #include @@ -66,11 +65,7 @@ along with this program. If not, see . #include #include #include -#include -#include -#include #include -#include #include #include @@ -812,33 +807,17 @@ void UserActionsMenu::slotToggleOnActivity(QAction *action) //**************************************** ShortcutDialog::ShortcutDialog(const QKeySequence& cut) : _shortcut(cut) - , m_buttons(new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this)) { - QWidget *vBoxContainer = new QWidget(this); - vBoxContainer->setLayout(new QVBoxLayout(vBoxContainer)); - vBoxContainer->layout()->addWidget(widget = new KKeySequenceWidget(vBoxContainer)); - vBoxContainer->layout()->addWidget(warning = new QLabel(vBoxContainer)); - warning->hide(); - widget->setKeySequence(cut); - - // To not check for conflicting shortcuts. The widget would use a message - // box which brings down kwin. - widget->setCheckForConflictsAgainst(KKeySequenceWidget::None); - // It's a global shortcut so don't allow multikey shortcuts - widget->setMultiKeyShortcutsAllowed(false); + m_ui.setupUi(this); + m_ui.keySequenceEdit->setKeySequence(cut); + m_ui.warning->hide(); // Listen to changed shortcuts - connect( - widget, SIGNAL(keySequenceChanged(QKeySequence)), - SLOT(keySequenceChanged(QKeySequence))); - - QVBoxLayout *mainLayout = new QVBoxLayout(this); - mainLayout->addWidget(vBoxContainer); - m_buttons->button(QDialogButtonBox::Ok)->setDefault(true); - connect(m_buttons, &QDialogButtonBox::accepted, this, &ShortcutDialog::accept); - connect(m_buttons, &QDialogButtonBox::rejected, this, &QDialog::reject); - mainLayout->addWidget(m_buttons); - widget->setFocus(); + connect(m_ui.keySequenceEdit, &QKeySequenceEdit::editingFinished, this, &ShortcutDialog::keySequenceChanged); + connect(m_ui.clearButton, &QToolButton::clicked, [this]{ + _shortcut = QKeySequence(); + }); + m_ui.keySequenceEdit->setFocus(); setWindowFlags(Qt::Popup | Qt::X11BypassWindowManagerHint); } @@ -854,7 +833,7 @@ void ShortcutDialog::accept() if (seq[0] == Qt::Key_Space || (seq[0] & Qt::KeyboardModifierMask) == 0) { // clear - widget->clearKeySequence(); + m_ui.keySequenceEdit->clear(); QDialog::accept(); return; } @@ -868,9 +847,10 @@ void ShortcutDialog::done(int r) emit dialogDone(r == Accepted); } -void ShortcutDialog::keySequenceChanged(const QKeySequence &seq) +void ShortcutDialog::keySequenceChanged() { activateWindow(); // where is the kbd focus lost? cause of popup state? + QKeySequence seq = m_ui.keySequenceEdit->keySequence(); if (_shortcut == seq) return; // don't try to update the same @@ -878,6 +858,10 @@ void ShortcutDialog::keySequenceChanged(const QKeySequence &seq) _shortcut = seq; return; } + if (seq.count() > 1) { + seq = QKeySequence(seq[0]); + m_ui.keySequenceEdit->setKeySequence(seq); + } // Check if the key sequence is used currently QString sc = seq.toString(); @@ -885,15 +869,15 @@ void ShortcutDialog::keySequenceChanged(const QKeySequence &seq) QList conflicting = KGlobalAccel::getGlobalShortcutsByKey(seq); if (!conflicting.isEmpty()) { const KGlobalShortcutInfo &conflict = conflicting.at(0); - warning->setText(i18nc("'%1' is a keyboard shortcut like 'ctrl+w'", + m_ui.warning->setText(i18nc("'%1' is a keyboard shortcut like 'ctrl+w'", "%1 is already in use", sc)); - warning->setToolTip(i18nc("keyboard shortcut '%1' is used by action '%2' in application '%3'", + m_ui.warning->setToolTip(i18nc("keyboard shortcut '%1' is used by action '%2' in application '%3'", "%1 is used by %2 in %3", sc, conflict.friendlyName(), conflict.componentFriendlyName())); - warning->show(); - widget->setKeySequence(shortcut()); + m_ui.warning->show(); + m_ui.keySequenceEdit->setKeySequence(shortcut()); } else if (seq != _shortcut) { - warning->hide(); - if (QPushButton *ok = m_buttons->button(QDialogButtonBox::Ok)) + m_ui.warning->hide(); + if (QPushButton *ok = m_ui.buttonBox->button(QDialogButtonBox::Ok)) ok->setFocus(); } diff --git a/useractions.h b/useractions.h index a5968b308..fa6a2dc9c 100644 --- a/useractions.h +++ b/useractions.h @@ -19,17 +19,13 @@ along with this program. If not, see . *********************************************************************/ #ifndef KWIN_USERACTIONS_H #define KWIN_USERACTIONS_H +#include "ui_shortcutdialog.h" // Qt #include #include -#include -class KKeySequenceWidget; class QAction; -class QDialogButtonBox; -class QLabel; -class QMenu; class QRect; namespace KWin @@ -269,16 +265,14 @@ public: virtual void accept(); QKeySequence shortcut() const; public Q_SLOTS: - void keySequenceChanged(const QKeySequence &seq); + void keySequenceChanged(); Q_SIGNALS: void dialogDone(bool ok); protected: virtual void done(int r); private: - KKeySequenceWidget* widget; + Ui::ShortcutDialog m_ui; QKeySequence _shortcut; - QLabel *warning; - QDialogButtonBox *m_buttons; }; } // namespace