Commit e564f592 authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: hotkeys: add check for app's menu shortcuts (fix #7930)

parent 7117284e
...@@ -51,6 +51,8 @@ ...@@ -51,6 +51,8 @@
#include <QDialogButtonBox> #include <QDialogButtonBox>
#include <QKeyEvent> #include <QKeyEvent>
#include <QColorDialog> #include <QColorDialog>
#include <QAction>
#include <QKeySequence>
#define MINWIDTH_BOX 90 #define MINWIDTH_BOX 90
#define LAST_COLUMN 10 #define LAST_COLUMN 10
...@@ -1144,6 +1146,12 @@ KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this, ...@@ -1144,6 +1146,12 @@ KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
table->installEventFilter( this ); table->installEventFilter( this );
/* Find the top most widget */
QWidget *parent, *rootWidget = p;
while( parent = rootWidget->parentWidget() )
rootWidget = parent;
buildAppHotkeysList( rootWidget );
finish(); finish();
CONNECT( actionSearch, textChanged( const QString& ), CONNECT( actionSearch, textChanged( const QString& ),
...@@ -1162,6 +1170,17 @@ void KeySelectorControl::fillGrid( QGridLayout *l, int line ) ...@@ -1162,6 +1170,17 @@ void KeySelectorControl::fillGrid( QGridLayout *l, int line )
int KeySelectorControl::getType() const { return CONFIG_ITEM_KEY; } 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() void KeySelectorControl::finish()
{ {
if( label && p_item->psz_longtext ) if( label && p_item->psz_longtext )
...@@ -1269,6 +1288,7 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column ) ...@@ -1269,6 +1288,7 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
/* Launch a small dialog to ask for a new key */ /* Launch a small dialog to ask for a new key */
KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), table, b_global ); KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), table, b_global );
d->setExistingkeysSet( &existingkeys );
d->exec(); d->exec();
if( d->result() == QDialog::Accepted ) if( d->result() == QDialog::Accepted )
...@@ -1366,6 +1386,7 @@ KeyInputDialog::KeyInputDialog( QTreeWidget *_table, ...@@ -1366,6 +1386,7 @@ KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
{ {
setModal( true ); setModal( true );
conflicts = false; conflicts = false;
existingkeys = NULL;
table = _table; table = _table;
setWindowTitle( ( b_global ? qtr( "Global" ) + QString(" ") : "" ) setWindowTitle( ( b_global ? qtr( "Global" ) + QString(" ") : "" )
...@@ -1398,7 +1419,12 @@ KeyInputDialog::KeyInputDialog( QTreeWidget *_table, ...@@ -1398,7 +1419,12 @@ KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
BUTTONACT( unset, unsetAction() ); 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 = QList<QTreeWidgetItem *> conflictList =
table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly, table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly,
...@@ -1416,6 +1442,19 @@ void KeyInputDialog::checkForConflicts( int i_vlckey ) ...@@ -1416,6 +1442,19 @@ void KeyInputDialog::checkForConflicts( int i_vlckey )
conflicts = true; 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(); else accept();
} }
...@@ -1429,9 +1468,10 @@ void KeyInputDialog::keyPressEvent( QKeyEvent *e ) ...@@ -1429,9 +1468,10 @@ void KeyInputDialog::keyPressEvent( QKeyEvent *e )
e->key() == Qt::Key_AltGr ) e->key() == Qt::Key_AltGr )
return; return;
int i_vlck = qtEventToVLCKey( e ); int i_vlck = qtEventToVLCKey( e );
QKeySequence sequence( e->key() | e->modifiers() );
selected->setText( qtr( "Key or combination: " ) selected->setText( qtr( "Key or combination: " )
+ QString("<b>%1</b>").arg( VLCKeyToString( i_vlck ) ) ); + QString("<b>%1</b>").arg( VLCKeyToString( i_vlck ) ) );
checkForConflicts( i_vlck ); checkForConflicts( i_vlck, sequence.toString() );
keyValue = i_vlck; keyValue = i_vlck;
} }
...@@ -1439,7 +1479,7 @@ void KeyInputDialog::wheelEvent( QWheelEvent *e ) ...@@ -1439,7 +1479,7 @@ void KeyInputDialog::wheelEvent( QWheelEvent *e )
{ {
int i_vlck = qtWheelEventToVLCKey( e ); int i_vlck = qtWheelEventToVLCKey( e );
selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) ); selected->setText( qtr( "Key: " ) + VLCKeyToString( i_vlck ) );
checkForConflicts( i_vlck ); checkForConflicts( i_vlck, QString() );
keyValue = i_vlck; keyValue = i_vlck;
} }
......
...@@ -486,10 +486,12 @@ private slot: ...@@ -486,10 +486,12 @@ private slot:
class KeySelectorControl : public ConfigControl class KeySelectorControl : public ConfigControl
{ {
Q_OBJECT Q_OBJECT
public: public:
KeySelectorControl( vlc_object_t *, module_config_t *, QWidget * ); explicit KeySelectorControl( vlc_object_t *, module_config_t *, QWidget * );
virtual int getType() const; virtual int getType() const;
virtual void doApply(); virtual void doApply();
protected: protected:
virtual bool eventFilter( QObject *, QEvent * ); virtual bool eventFilter( QObject *, QEvent * );
virtual void changeVisibility( bool b ) virtual void changeVisibility( bool b )
...@@ -498,13 +500,17 @@ protected: ...@@ -498,13 +500,17 @@ protected:
if ( label ) label->setVisible( b ); if ( label ) label->setVisible( b );
} }
virtual void fillGrid( QGridLayout*, int ); virtual void fillGrid( QGridLayout*, int );
private: private:
void buildAppHotkeysList( QWidget *rootWidget );
void finish(); void finish();
QLabel *label; QLabel *label;
QLabel *searchLabel; QLabel *searchLabel;
SearchLineEdit *actionSearch; SearchLineEdit *actionSearch;
QTreeWidget *table; QTreeWidget *table;
QList<module_config_t *> values; QList<module_config_t *> values;
QSet<QString> existingkeys;
private slots: private slots:
void selectKey( QTreeWidgetItem * = NULL, int column = 1 ); void selectKey( QTreeWidgetItem * = NULL, int column = 1 );
void filter( const QString & ); void filter( const QString & );
...@@ -513,20 +519,24 @@ private slots: ...@@ -513,20 +519,24 @@ private slots:
class KeyInputDialog : public QDialog class KeyInputDialog : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
KeyInputDialog( QTreeWidget *, const QString&, QWidget *, bool b_global = false); explicit KeyInputDialog( QTreeWidget *, const QString&, QWidget *, bool b_global = false );
int keyValue; int keyValue;
bool conflicts; bool conflicts;
void setExistingkeysSet( const QSet<QString> *keyset = NULL );
private: private:
QTreeWidget *table; QTreeWidget *table;
QLabel *selected, *warning; QLabel *selected, *warning;
QPushButton *ok, *unset; QPushButton *ok, *unset;
void checkForConflicts( int i_vlckey ); void checkForConflicts( int i_vlckey, const QString &sequence );
void keyPressEvent( QKeyEvent *); void keyPressEvent( QKeyEvent *);
void wheelEvent( QWheelEvent *); void wheelEvent( QWheelEvent *);
bool b_global; bool b_global;
const QSet<QString> *existingkeys;
private slots: private slots:
void unsetAction(); void unsetAction();
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment