From a3d314ca4ef99990b1168034a58079c251f394fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Wed, 2 Feb 2005 18:57:21 +0000 Subject: [PATCH] Make the 'Edit' button for shortcut in window-specific settings do at least something. svn path=/trunk/kdebase/kwin/; revision=385467 --- kcmkwin/kwinrules/Makefile.am | 2 +- kcmkwin/kwinrules/editshortcutbase.ui | 164 ++++++++++++++++++++++++++ kcmkwin/kwinrules/ruleswidget.cpp | 77 +++++++++++- kcmkwin/kwinrules/ruleswidget.h | 35 ++++++ kcmkwin/kwinrules/ruleswidgetbase.ui | 2 +- useractions.cpp | 10 +- workspace.h | 2 +- 7 files changed, 282 insertions(+), 10 deletions(-) create mode 100644 kcmkwin/kwinrules/editshortcutbase.ui diff --git a/kcmkwin/kwinrules/Makefile.am b/kcmkwin/kwinrules/Makefile.am index 7bc21b79a8..804aabc5da 100644 --- a/kcmkwin/kwinrules/Makefile.am +++ b/kcmkwin/kwinrules/Makefile.am @@ -9,7 +9,7 @@ kde_module_LTLIBRARIES = kcm_kwinrules.la noinst_LTLIBRARIES = libkwinrules.la libkwinrules_la_SOURCES = ruleswidget.cpp ruleslist.cpp kwinsrc.cpp detectwidget.cpp \ - ruleswidgetbase.ui ruleslistbase.ui detectwidgetbase.ui + ruleswidgetbase.ui ruleslistbase.ui detectwidgetbase.ui editshortcutbase.ui libkwinrules_la_LDFLAGS = $(all_libraries) -no-undefined libkwinrules_la_LIBADD = $(LIB_KDEUI) diff --git a/kcmkwin/kwinrules/editshortcutbase.ui b/kcmkwin/kwinrules/editshortcutbase.ui new file mode 100644 index 0000000000..c6071ffcbb --- /dev/null +++ b/kcmkwin/kwinrules/editshortcutbase.ui @@ -0,0 +1,164 @@ + +EditShortcutBase + + + EditShortcutBase + + + + 0 + 0 + 587 + 402 + + + + + unnamed + + + + textLabel2 + + + A single shortcut can be easily assigned or cleared using the two buttons. Only shortcuts with modifiers can be used.<p> +It is possible to have several possible shortcuts, and the first available shortcut will be used. The shortcuts are specified using space-separated shortcut sets. One set is specified as <i>base</i>+(<i>list</i>), where base are modifiers and list is a list of keys.<br> +For example "<b>Shift+Alt+(123) Shift+Ctrl+(ABC)</b>" will first try <b>Shift+Alt+1</b>, then others with <b>Shift+Ctrl+C</b> as the last one. + + + RichText + + + + + line1 + + + HLine + + + Sunken + + + Horizontal + + + + + shortcut + + + + + layout2 + + + + unnamed + + + + spacer1 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + pushButton1 + + + &Single shortcut + + + + + spacer2 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + pushButton2 + + + C&lear + + + + + spacer3 + + + Horizontal + + + Expanding + + + + 40 + 20 + + + + + + + + line2 + + + HLine + + + Sunken + + + Horizontal + + + + + + + pushButton1 + clicked() + EditShortcutBase + editShortcut() + + + pushButton2 + clicked() + EditShortcutBase + clearShortcut() + + + + editShortcut() + clearShortcut() + + + + diff --git a/kcmkwin/kwinrules/ruleswidget.cpp b/kcmkwin/kwinrules/ruleswidget.cpp index 3b1f713b4d..97118f46a0 100644 --- a/kcmkwin/kwinrules/ruleswidget.cpp +++ b/kcmkwin/kwinrules/ruleswidget.cpp @@ -653,11 +653,14 @@ void RulesWidget::prepareWindowSpecific( WId window ) void RulesWidget::shortcutEditClicked() { -// TODO + EditShortcutDialog dlg( topLevelWidget()); + dlg.setShortcut( shortcut->text()); + if( dlg.exec() == QDialog::Accepted ) + shortcut->setText( dlg.shortcut()); } RulesDialog::RulesDialog( QWidget* parent, const char* name ) -: KDialogBase( parent, name, true, "", Ok | Cancel ) +: KDialogBase( parent, name, true, i18n( "Edit window-specific settings" ), Ok | Cancel ) { widget = new RulesWidget( this ); setMainWidget( widget ); @@ -683,6 +686,76 @@ void RulesDialog::accept() KDialogBase::accept(); } +EditShortcut::EditShortcut( QWidget* parent, const char* name ) +: EditShortcutBase( parent, name ) + { + } + +void EditShortcut::editShortcut() + { + ShortcutDialog dlg( KShortcut( shortcut->text()), topLevelWidget()); + if( dlg.exec() == QDialog::Accepted ) + shortcut->setText( dlg.shortcut().toString()); + } + +void EditShortcut::clearShortcut() + { + shortcut->setText( "" ); + } + +EditShortcutDialog::EditShortcutDialog( QWidget* parent, const char* name ) +: KDialogBase( parent, name, true, i18n( "Edit Shortcut" ), Ok | Cancel ) + { + widget = new EditShortcut( this ); + setMainWidget( widget ); + } + +void EditShortcutDialog::setShortcut( const QString& cut ) + { + widget->shortcut->setText( cut ); + } + +QString EditShortcutDialog::shortcut() const + { + return widget->shortcut->text(); + } + +ShortcutDialog::ShortcutDialog( const KShortcut& cut, QWidget* parent, const char* name ) + : KShortcutDialog( cut, false /*TODO???*/, parent, name ) + { + } + +void ShortcutDialog::accept() + { + for( int i = 0; + ; + ++i ) + { + KKeySequence seq = shortcut().seq( i ); + if( seq.isNull()) + break; + if( seq.key( 0 ) == Key_Escape ) + { + reject(); + return; + } + if( seq.key( 0 ) == Key_Space ) + { // clear + setShortcut( KShortcut()); + KShortcutDialog::accept(); + return; + } + if( seq.key( 0 ).modFlags() == 0 ) + { // no shortcuts without modifiers + KShortcut cut = shortcut(); + cut.setSeq( i, KKeySequence()); + setShortcut( cut ); + return; + } + } + KShortcutDialog::accept(); + } + } // namespace #include "ruleswidget.moc" diff --git a/kcmkwin/kwinrules/ruleswidget.h b/kcmkwin/kwinrules/ruleswidget.h index 7ac952c5f6..89581c4360 100644 --- a/kcmkwin/kwinrules/ruleswidget.h +++ b/kcmkwin/kwinrules/ruleswidget.h @@ -22,8 +22,10 @@ #include #include +#include #include "ruleswidgetbase.h" +#include "editshortcutbase.h" namespace KWinInternal { @@ -105,6 +107,39 @@ class RulesDialog Rules* rules; }; +class EditShortcut + : public EditShortcutBase + { + Q_OBJECT + public: + EditShortcut( QWidget* parent = NULL, const char* name = NULL ); + protected: + void editShortcut(); + void clearShortcut(); + }; + +class EditShortcutDialog + : public KDialogBase + { + Q_OBJECT + public: + EditShortcutDialog( QWidget* parent = NULL, const char* name = NULL ); + void setShortcut( const QString& cut ); + QString shortcut() const; + private: + EditShortcut* widget; + }; + +// slightly duped from utils.cpp +class ShortcutDialog + : public KShortcutDialog + { + Q_OBJECT + public: + ShortcutDialog( const KShortcut& cut, QWidget* parent = NULL, const char* name = NULL ); + virtual void accept(); + }; + } // namespace #endif diff --git a/kcmkwin/kwinrules/ruleswidgetbase.ui b/kcmkwin/kwinrules/ruleswidgetbase.ui index 00811cf433..78938d5626 100644 --- a/kcmkwin/kwinrules/ruleswidgetbase.ui +++ b/kcmkwin/kwinrules/ruleswidgetbase.ui @@ -1746,7 +1746,7 @@ shortcut_edit - Edit + Edit... diff --git a/useractions.cpp b/useractions.cpp index c0887d07dd..ed8a516db1 100644 --- a/useractions.cpp +++ b/useractions.cpp @@ -959,9 +959,9 @@ void Client::setShortcut( const QString& _cut ) if( cut.isEmpty()) return setShortcutInternal( KShortcut()); // Format: -// *base+[abcdef]|base+[abcdef] -// E.g. Alt+Ctrl+[ABCDEF]|Win+X,Win+[ABCDEF] - if( cut[ 0 ] != '*' ) +// base+(abcdef)base+(abcdef) +// E.g. Alt+Ctrl+(ABCDEF) Win+X,Win+(ABCDEF) + if( !cut.contains( '(' ) && !cut.contains( ')' ) && !cut.contains( ' ' )) { if( workspace()->shortcutAvailable( KShortcut( cut ))) setShortcutInternal( KShortcut( cut )); @@ -970,12 +970,12 @@ void Client::setShortcut( const QString& _cut ) return; } QValueList< KShortcut > keys; - QStringList groups = QStringList::split( '|', cut.mid( 1 )); + QStringList groups = QStringList::split( ' ', cut ); for( QStringList::ConstIterator it = groups.begin(); it != groups.end(); ++it ) { - QRegExp reg( "(.*\\+)\\[(.*)\\]" ); + QRegExp reg( "(.*\\+)\\((.*)\\)" ); if( reg.search( *it ) > -1 ) { QString base = reg.cap( 1 ); diff --git a/workspace.h b/workspace.h index 8af4d4e460..804c35d6bc 100644 --- a/workspace.h +++ b/workspace.h @@ -530,7 +530,7 @@ class Workspace : public QObject, public KWinInterface, public KDecorationDefine KGlobalAccel *keys; KGlobalAccel *client_keys; - KShortcutDialog* client_keys_dialog; + ShortcutDialog* client_keys_dialog; Client* client_keys_client; WId root;