[vlc-commits] Qt: hotkeys: add check for app's menu shortcuts (fix #7930)
Francois Cartegnie
git at videolan.org
Sat Dec 22 15:37:48 CET 2012
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sat Dec 22 15:33:51 2012 +0100| [e564f592ee556d468ec0d1bdc6169593ac58a3ca] | committer: Francois Cartegnie
Qt: hotkeys: add check for app's menu shortcuts (fix #7930)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=e564f592ee556d468ec0d1bdc6169593ac58a3ca
---
modules/gui/qt4/components/preferences_widgets.cpp | 46 ++++++++++++++++++--
modules/gui/qt4/components/preferences_widgets.hpp | 16 +++++--
2 files changed, 56 insertions(+), 6 deletions(-)
diff --git a/modules/gui/qt4/components/preferences_widgets.cpp b/modules/gui/qt4/components/preferences_widgets.cpp
index ecebebe..fed7e07 100644
--- a/modules/gui/qt4/components/preferences_widgets.cpp
+++ b/modules/gui/qt4/components/preferences_widgets.cpp
@@ -51,6 +51,8 @@
#include <QDialogButtonBox>
#include <QKeyEvent>
#include <QColorDialog>
+#include <QAction>
+#include <QKeySequence>
#define MINWIDTH_BOX 90
#define LAST_COLUMN 10
@@ -1144,6 +1146,12 @@ KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
table->installEventFilter( this );
+ /* Find the top most widget */
+ QWidget *parent, *rootWidget = p;
+ while( parent = rootWidget->parentWidget() )
+ rootWidget = parent;
+ buildAppHotkeysList( rootWidget );
+
finish();
CONNECT( actionSearch, textChanged( const QString& ),
@@ -1162,6 +1170,17 @@ void KeySelectorControl::fillGrid( QGridLayout *l, int line )
int KeySelectorControl::getType() const { return CONFIG_ITEM_KEY; }
+void KeySelectorControl::buildAppHotkeysList( QWidget *rootWidget )
+{
+ QList<QAction *> actionsList = rootWidget->findChildren<QAction *>();
+ foreach( const QAction *action, actionsList )
+ {
+ const QList<QKeySequence> shortcuts = action->shortcuts();
+ foreach( const QKeySequence &keySequence, shortcuts )
+ existingkeys << keySequence.toString();
+ }
+}
+
void KeySelectorControl::finish()
{
if( label && p_item->psz_longtext )
@@ -1269,6 +1288,7 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
/* Launch a small dialog to ask for a new key */
KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), table, b_global );
+ d->setExistingkeysSet( &existingkeys );
d->exec();
if( d->result() == QDialog::Accepted )
@@ -1366,6 +1386,7 @@ KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
{
setModal( true );
conflicts = false;
+ existingkeys = NULL;
table = _table;
setWindowTitle( ( b_global ? qtr( "Global" ) + QString(" ") : "" )
@@ -1398,7 +1419,12 @@ KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
BUTTONACT( unset, unsetAction() );
}
-void KeyInputDialog::checkForConflicts( int i_vlckey )
+void KeyInputDialog::setExistingkeysSet( const QSet<QString> *keyset )
+{
+ existingkeys = keyset;
+}
+
+void KeyInputDialog::checkForConflicts( int i_vlckey, const QString &sequence )
{
QList<QTreeWidgetItem *> conflictList =
table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly,
@@ -1416,6 +1442,19 @@ void KeyInputDialog::checkForConflicts( int i_vlckey )
conflicts = true;
}
+ else if( existingkeys && !sequence.isEmpty()
+ && existingkeys->contains( sequence ) )
+ {
+ warning->setText(
+ qtr( "Warning: <b>%1</b> is already an application menu shortcut" )
+ .arg( sequence )
+ );
+ warning->show();
+ ok->show();
+ unset->hide();
+
+ conflicts = true;
+ }
else accept();
}
@@ -1429,9 +1468,10 @@ void KeyInputDialog::keyPressEvent( QKeyEvent *e )
e->key() == Qt::Key_AltGr )
return;
int i_vlck = qtEventToVLCKey( e );
+ QKeySequence sequence( e->key() | e->modifiers() );
selected->setText( qtr( "Key or combination: " )
+ QString("<b>%1</b>").arg( VLCKeyToString( i_vlck ) ) );
- checkForConflicts( i_vlck );
+ checkForConflicts( i_vlck, sequence.toString() );
keyValue = i_vlck;
}
@@ -1439,7 +1479,7 @@ void KeyInputDialog::wheelEvent( QWheelEvent *e )
{
int i_vlck = qtWheelEventToVLCKey( e );
selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
- checkForConflicts( i_vlck );
+ checkForConflicts( i_vlck, QString() );
keyValue = i_vlck;
}
diff --git a/modules/gui/qt4/components/preferences_widgets.hpp b/modules/gui/qt4/components/preferences_widgets.hpp
index 1370a73..d6bff28 100644
--- a/modules/gui/qt4/components/preferences_widgets.hpp
+++ b/modules/gui/qt4/components/preferences_widgets.hpp
@@ -486,10 +486,12 @@ private slot:
class KeySelectorControl : public ConfigControl
{
Q_OBJECT
+
public:
- KeySelectorControl( vlc_object_t *, module_config_t *, QWidget * );
+ explicit KeySelectorControl( vlc_object_t *, module_config_t *, QWidget * );
virtual int getType() const;
virtual void doApply();
+
protected:
virtual bool eventFilter( QObject *, QEvent * );
virtual void changeVisibility( bool b )
@@ -498,13 +500,17 @@ protected:
if ( label ) label->setVisible( b );
}
virtual void fillGrid( QGridLayout*, int );
+
private:
+ void buildAppHotkeysList( QWidget *rootWidget );
void finish();
QLabel *label;
QLabel *searchLabel;
SearchLineEdit *actionSearch;
QTreeWidget *table;
QList<module_config_t *> values;
+ QSet<QString> existingkeys;
+
private slots:
void selectKey( QTreeWidgetItem * = NULL, int column = 1 );
void filter( const QString & );
@@ -513,20 +519,24 @@ private slots:
class KeyInputDialog : public QDialog
{
Q_OBJECT
+
public:
- KeyInputDialog( QTreeWidget *, const QString&, QWidget *, bool b_global = false);
+ explicit KeyInputDialog( QTreeWidget *, const QString&, QWidget *, bool b_global = false );
int keyValue;
bool conflicts;
+ void setExistingkeysSet( const QSet<QString> *keyset = NULL );
private:
QTreeWidget *table;
QLabel *selected, *warning;
QPushButton *ok, *unset;
- void checkForConflicts( int i_vlckey );
+ void checkForConflicts( int i_vlckey, const QString &sequence );
void keyPressEvent( QKeyEvent *);
void wheelEvent( QWheelEvent *);
bool b_global;
+ const QSet<QString> *existingkeys;
+
private slots:
void unsetAction();
};
More information about the vlc-commits
mailing list