[kwin] Use ui-file for ShortcutDialog
At the same time switching to QKeySequenceEdit for capturing the shortcut. This allows to get rid of xmlgui.
This commit is contained in:
parent
ed4a0d0319
commit
f48aca47a5
4 changed files with 133 additions and 47 deletions
|
@ -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
|
||||
|
|
104
shortcutdialog.ui
Normal file
104
shortcutdialog.ui
Normal 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>
|
|
@ -49,7 +49,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <kactivities/info.h>
|
||||
#endif
|
||||
|
||||
#include <KDE/KKeySequenceWidget>
|
||||
#include <KDE/KProcess>
|
||||
#include <KDE/KToolInvocation>
|
||||
|
||||
|
@ -66,11 +65,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <KDE/KLocalizedString>
|
||||
#include <kconfig.h>
|
||||
#include <QRegExp>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QLabel>
|
||||
#include <QLayout>
|
||||
#include <QMenu>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidgetAction>
|
||||
#include <kauthorized.h>
|
||||
|
||||
|
@ -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<KGlobalShortcutInfo> 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'",
|
||||
"<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()));
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,17 +19,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*********************************************************************/
|
||||
#ifndef KWIN_USERACTIONS_H
|
||||
#define KWIN_USERACTIONS_H
|
||||
#include "ui_shortcutdialog.h"
|
||||
|
||||
// Qt
|
||||
#include <QDialog>
|
||||
#include <QObject>
|
||||
#include <QWeakPointer>
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue