[kwin] Use ui-file for ShortcutDialog

At the same time switching to QKeySequenceEdit for capturing the
shortcut. This allows to get rid of xmlgui.
icc-effect-5.14.5
Martin Gräßlin 2013-12-12 14:17:26 +01:00
parent ed4a0d0319
commit f48aca47a5
4 changed files with 133 additions and 47 deletions

View File

@ -226,6 +226,10 @@ qt5_add_dbus_interface( kwin_KDEINIT_SRCS
qt5_add_resources( kwin_KDEINIT_SRCS resources.qrc ) qt5_add_resources( kwin_KDEINIT_SRCS resources.qrc )
kde4_add_ui_files(kwin_KDEINIT_SRCS
shortcutdialog.ui
)
########### target link libraries ############### ########### target link libraries ###############
set(kwin_OWN_LIBS set(kwin_OWN_LIBS
@ -244,6 +248,7 @@ set(kwin_QT_LIBS
set(kwin_KDE_LIBS set(kwin_KDE_LIBS
KF5::ConfigCore KF5::ConfigCore
KF5::CoreAddons KF5::CoreAddons
KF5::ConfigWidgets
KF5::Crash KF5::Crash
KF5::GlobalAccel KF5::GlobalAccel
KF5::I18n KF5::I18n
@ -251,7 +256,6 @@ set(kwin_KDE_LIBS
KF5::Service KF5::Service
KF5::Plasma KF5::Plasma
KF5::WindowSystem KF5::WindowSystem
KF5::XmlGui
) )
set(kwin_XLIB_LIBS set(kwin_XLIB_LIBS

104
shortcutdialog.ui Normal file
View File

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ShortcutDialog</class>
<widget class="QDialog" name="ShortcutDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>200</width>
<height>100</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QKeySequenceEdit" name="keySequenceEdit"/>
</item>
<item>
<widget class="QToolButton" name="clearButton">
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset theme="edit-clear-locationbar-rtl"/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="warning">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ShortcutDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>195</x>
<y>85</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>99</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ShortcutDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>195</x>
<y>91</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>99</y>
</hint>
</hints>
</connection>
<connection>
<sender>clearButton</sender>
<signal>clicked()</signal>
<receiver>keySequenceEdit</receiver>
<slot>clear()</slot>
<hints>
<hint type="sourcelabel">
<x>181</x>
<y>19</y>
</hint>
<hint type="destinationlabel">
<x>146</x>
<y>15</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -49,7 +49,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <kactivities/info.h> #include <kactivities/info.h>
#endif #endif
#include <KDE/KKeySequenceWidget>
#include <KDE/KProcess> #include <KDE/KProcess>
#include <KDE/KToolInvocation> #include <KDE/KToolInvocation>
@ -66,11 +65,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KDE/KLocalizedString> #include <KDE/KLocalizedString>
#include <kconfig.h> #include <kconfig.h>
#include <QRegExp> #include <QRegExp>
#include <QDialogButtonBox>
#include <QLabel>
#include <QLayout>
#include <QMenu> #include <QMenu>
#include <QVBoxLayout>
#include <QWidgetAction> #include <QWidgetAction>
#include <kauthorized.h> #include <kauthorized.h>
@ -812,33 +807,17 @@ void UserActionsMenu::slotToggleOnActivity(QAction *action)
//**************************************** //****************************************
ShortcutDialog::ShortcutDialog(const QKeySequence& cut) ShortcutDialog::ShortcutDialog(const QKeySequence& cut)
: _shortcut(cut) : _shortcut(cut)
, m_buttons(new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this))
{ {
QWidget *vBoxContainer = new QWidget(this); m_ui.setupUi(this);
vBoxContainer->setLayout(new QVBoxLayout(vBoxContainer)); m_ui.keySequenceEdit->setKeySequence(cut);
vBoxContainer->layout()->addWidget(widget = new KKeySequenceWidget(vBoxContainer)); m_ui.warning->hide();
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);
// Listen to changed shortcuts // Listen to changed shortcuts
connect( connect(m_ui.keySequenceEdit, &QKeySequenceEdit::editingFinished, this, &ShortcutDialog::keySequenceChanged);
widget, SIGNAL(keySequenceChanged(QKeySequence)), connect(m_ui.clearButton, &QToolButton::clicked, [this]{
SLOT(keySequenceChanged(QKeySequence))); _shortcut = QKeySequence();
});
QVBoxLayout *mainLayout = new QVBoxLayout(this); m_ui.keySequenceEdit->setFocus();
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();
setWindowFlags(Qt::Popup | Qt::X11BypassWindowManagerHint); setWindowFlags(Qt::Popup | Qt::X11BypassWindowManagerHint);
} }
@ -854,7 +833,7 @@ void ShortcutDialog::accept()
if (seq[0] == Qt::Key_Space if (seq[0] == Qt::Key_Space
|| (seq[0] & Qt::KeyboardModifierMask) == 0) { || (seq[0] & Qt::KeyboardModifierMask) == 0) {
// clear // clear
widget->clearKeySequence(); m_ui.keySequenceEdit->clear();
QDialog::accept(); QDialog::accept();
return; return;
} }
@ -868,9 +847,10 @@ void ShortcutDialog::done(int r)
emit dialogDone(r == Accepted); emit dialogDone(r == Accepted);
} }
void ShortcutDialog::keySequenceChanged(const QKeySequence &seq) void ShortcutDialog::keySequenceChanged()
{ {
activateWindow(); // where is the kbd focus lost? cause of popup state? activateWindow(); // where is the kbd focus lost? cause of popup state?
QKeySequence seq = m_ui.keySequenceEdit->keySequence();
if (_shortcut == seq) if (_shortcut == seq)
return; // don't try to update the same return; // don't try to update the same
@ -878,6 +858,10 @@ void ShortcutDialog::keySequenceChanged(const QKeySequence &seq)
_shortcut = seq; _shortcut = seq;
return; return;
} }
if (seq.count() > 1) {
seq = QKeySequence(seq[0]);
m_ui.keySequenceEdit->setKeySequence(seq);
}
// Check if the key sequence is used currently // Check if the key sequence is used currently
QString sc = seq.toString(); QString sc = seq.toString();
@ -885,15 +869,15 @@ void ShortcutDialog::keySequenceChanged(const QKeySequence &seq)
QList<KGlobalShortcutInfo> conflicting = KGlobalAccel::getGlobalShortcutsByKey(seq); QList<KGlobalShortcutInfo> conflicting = KGlobalAccel::getGlobalShortcutsByKey(seq);
if (!conflicting.isEmpty()) { if (!conflicting.isEmpty()) {
const KGlobalShortcutInfo &conflict = conflicting.at(0); 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'",
"<b>%1</b> is already in use", sc)); "<b>%1</b> 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'",
"<b>%1</b> is used by %2 in %3", sc, conflict.friendlyName(), conflict.componentFriendlyName())); "<b>%1</b> is used by %2 in %3", sc, conflict.friendlyName(), conflict.componentFriendlyName()));
warning->show(); m_ui.warning->show();
widget->setKeySequence(shortcut()); m_ui.keySequenceEdit->setKeySequence(shortcut());
} else if (seq != _shortcut) { } else if (seq != _shortcut) {
warning->hide(); m_ui.warning->hide();
if (QPushButton *ok = m_buttons->button(QDialogButtonBox::Ok)) if (QPushButton *ok = m_ui.buttonBox->button(QDialogButtonBox::Ok))
ok->setFocus(); ok->setFocus();
} }

View File

@ -19,17 +19,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/ *********************************************************************/
#ifndef KWIN_USERACTIONS_H #ifndef KWIN_USERACTIONS_H
#define KWIN_USERACTIONS_H #define KWIN_USERACTIONS_H
#include "ui_shortcutdialog.h"
// Qt // Qt
#include <QDialog> #include <QDialog>
#include <QObject> #include <QObject>
#include <QWeakPointer>
class KKeySequenceWidget;
class QAction; class QAction;
class QDialogButtonBox;
class QLabel;
class QMenu;
class QRect; class QRect;
namespace KWin namespace KWin
@ -269,16 +265,14 @@ public:
virtual void accept(); virtual void accept();
QKeySequence shortcut() const; QKeySequence shortcut() const;
public Q_SLOTS: public Q_SLOTS:
void keySequenceChanged(const QKeySequence &seq); void keySequenceChanged();
Q_SIGNALS: Q_SIGNALS:
void dialogDone(bool ok); void dialogDone(bool ok);
protected: protected:
virtual void done(int r); virtual void done(int r);
private: private:
KKeySequenceWidget* widget; Ui::ShortcutDialog m_ui;
QKeySequence _shortcut; QKeySequence _shortcut;
QLabel *warning;
QDialogButtonBox *m_buttons;
}; };
} // namespace } // namespace