Make the 'Edit' button for shortcut in window-specific settings
do at least something. svn path=/trunk/kdebase/kwin/; revision=385467
This commit is contained in:
parent
bafac3e99e
commit
a3d314ca4e
7 changed files with 282 additions and 10 deletions
|
@ -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)
|
||||
|
||||
|
|
164
kcmkwin/kwinrules/editshortcutbase.ui
Normal file
164
kcmkwin/kwinrules/editshortcutbase.ui
Normal file
|
@ -0,0 +1,164 @@
|
|||
<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
|
||||
<class>EditShortcutBase</class>
|
||||
<widget class="QWidget">
|
||||
<property name="name">
|
||||
<cstring>EditShortcutBase</cstring>
|
||||
</property>
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>587</width>
|
||||
<height>402</height>
|
||||
</rect>
|
||||
</property>
|
||||
<vbox>
|
||||
<property name="name">
|
||||
<cstring>unnamed</cstring>
|
||||
</property>
|
||||
<widget class="QLabel">
|
||||
<property name="name">
|
||||
<cstring>textLabel2</cstring>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>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.</string>
|
||||
</property>
|
||||
<property name="textFormat">
|
||||
<enum>RichText</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="Line">
|
||||
<property name="name">
|
||||
<cstring>line1</cstring>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>HLine</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>Sunken</enum>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="KLineEdit">
|
||||
<property name="name">
|
||||
<cstring>shortcut</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLayoutWidget">
|
||||
<property name="name">
|
||||
<cstring>layout2</cstring>
|
||||
</property>
|
||||
<hbox>
|
||||
<property name="name">
|
||||
<cstring>unnamed</cstring>
|
||||
</property>
|
||||
<spacer>
|
||||
<property name="name">
|
||||
<cstring>spacer1</cstring>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
<widget class="QPushButton">
|
||||
<property name="name">
|
||||
<cstring>pushButton1</cstring>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Single shortcut</string>
|
||||
</property>
|
||||
</widget>
|
||||
<spacer>
|
||||
<property name="name">
|
||||
<cstring>spacer2</cstring>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
<widget class="QPushButton">
|
||||
<property name="name">
|
||||
<cstring>pushButton2</cstring>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>C&lear</string>
|
||||
</property>
|
||||
</widget>
|
||||
<spacer>
|
||||
<property name="name">
|
||||
<cstring>spacer3</cstring>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</hbox>
|
||||
</widget>
|
||||
<widget class="Line">
|
||||
<property name="name">
|
||||
<cstring>line2</cstring>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>HLine</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>Sunken</enum>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</vbox>
|
||||
</widget>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>pushButton1</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>EditShortcutBase</receiver>
|
||||
<slot>editShortcut()</slot>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>pushButton2</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>EditShortcutBase</receiver>
|
||||
<slot>clearShortcut()</slot>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot access="protected" specifier="pure virtual">editShortcut()</slot>
|
||||
<slot access="protected" specifier="pure virtual">clearShortcut()</slot>
|
||||
</slots>
|
||||
<layoutdefaults spacing="6" margin="11"/>
|
||||
<layoutfunctions spacing="KDialog::spacingHint" margin="KDialog::marginHint"/>
|
||||
</UI>
|
|
@ -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"
|
||||
|
|
|
@ -22,8 +22,10 @@
|
|||
|
||||
#include <kdialogbase.h>
|
||||
#include <kwin.h>
|
||||
#include <kshortcutdialog.h>
|
||||
|
||||
#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
|
||||
|
|
|
@ -1746,7 +1746,7 @@
|
|||
<cstring>shortcut_edit</cstring>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
<string>Edit...</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="KRestrictedLine" row="9" column="2" rowspan="1" colspan="3">
|
||||
|
|
|
@ -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)<space>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 );
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue