Port KWin::ShortcutDialog from KDialog to QDialog

This commit is contained in:
Martin Gräßlin 2013-08-19 12:44:30 +02:00
parent c2e0c13b7b
commit caae057649
2 changed files with 18 additions and 13 deletions

View file

@ -72,7 +72,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <kglobalaccel.h> #include <kglobalaccel.h>
#include <kapplication.h> #include <kapplication.h>
#include <QRegExp> #include <QRegExp>
#include <QDialogButtonBox>
#include <QLabel> #include <QLabel>
#include <QLayout>
#include <QMenu> #include <QMenu>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <kauthorized.h> #include <kauthorized.h>
@ -838,6 +840,7 @@ 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); QWidget *vBoxContainer = new QWidget(this);
vBoxContainer->setLayout(new QVBoxLayout(vBoxContainer)); vBoxContainer->setLayout(new QVBoxLayout(vBoxContainer));
@ -857,14 +860,15 @@ ShortcutDialog::ShortcutDialog(const QKeySequence& cut)
widget, SIGNAL(keySequenceChanged(QKeySequence)), widget, SIGNAL(keySequenceChanged(QKeySequence)),
SLOT(keySequenceChanged(QKeySequence))); SLOT(keySequenceChanged(QKeySequence)));
setMainWidget(vBoxContainer); 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(); widget->setFocus();
// make it a popup, so that it has the grab setWindowFlags(Qt::Popup | Qt::X11BypassWindowManagerHint);
XSetWindowAttributes attrs;
attrs.override_redirect = True;
XChangeWindowAttributes(display(), winId(), CWOverrideRedirect, &attrs);
setWindowFlags(Qt::Popup);
} }
void ShortcutDialog::accept() void ShortcutDialog::accept()
@ -879,16 +883,16 @@ void ShortcutDialog::accept()
|| (seq[0] & Qt::KeyboardModifierMask) == 0) { || (seq[0] & Qt::KeyboardModifierMask) == 0) {
// clear // clear
widget->clearKeySequence(); widget->clearKeySequence();
KDialog::accept(); QDialog::accept();
return; return;
} }
} }
KDialog::accept(); QDialog::accept();
} }
void ShortcutDialog::done(int r) void ShortcutDialog::done(int r)
{ {
KDialog::done(r); QDialog::done(r);
emit dialogDone(r == Accepted); emit dialogDone(r == Accepted);
} }
@ -917,7 +921,7 @@ void ShortcutDialog::keySequenceChanged(const QKeySequence &seq)
widget->setKeySequence(shortcut()); widget->setKeySequence(shortcut());
} else if (seq != _shortcut) { } else if (seq != _shortcut) {
warning->hide(); warning->hide();
if (QPushButton *ok = button(KDialog::Ok)) if (QPushButton *ok = m_buttons->button(QDialogButtonBox::Ok))
ok->setFocus(); ok->setFocus();
} }

View file

@ -20,14 +20,14 @@ 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
// KDE
#include <KDE/KDialog>
// Qt // Qt
#include <QDialog>
#include <QObject> #include <QObject>
#include <QWeakPointer> #include <QWeakPointer>
class KKeySequenceWidget; class KKeySequenceWidget;
class QAction; class QAction;
class QDialogButtonBox;
class QLabel; class QLabel;
class QMenu; class QMenu;
class QRect; class QRect;
@ -261,7 +261,7 @@ private:
}; };
class ShortcutDialog class ShortcutDialog
: public KDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
@ -278,6 +278,7 @@ private:
KKeySequenceWidget* widget; KKeySequenceWidget* widget;
QKeySequence _shortcut; QKeySequence _shortcut;
QLabel *warning; QLabel *warning;
QDialogButtonBox *m_buttons;
}; };
} // namespace } // namespace