Commit 44022166 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt: correctly implement the Global Hotkey saving.

Close blocker #2723
parent fab56e28
...@@ -1237,8 +1237,8 @@ void KeySelectorControl::finish() ...@@ -1237,8 +1237,8 @@ void KeySelectorControl::finish()
table->resizeColumnToContents( 0 ); table->resizeColumnToContents( 0 );
CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ), CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
this, selectKey( QTreeWidgetItem * ) ); this, selectKey( QTreeWidgetItem *, int ) );
CONNECT( table, itemSelectionChanged (), CONNECT( table, itemSelectionChanged(),
this, select1Key() ); this, select1Key() );
CONNECT( shortcutValue, pressed(), this, selectKey() ); CONNECT( shortcutValue, pressed(), this, selectKey() );
...@@ -1261,9 +1261,10 @@ void KeySelectorControl::select1Key() ...@@ -1261,9 +1261,10 @@ void KeySelectorControl::select1Key()
QTreeWidgetItem *keyItem = table->currentItem(); QTreeWidgetItem *keyItem = table->currentItem();
shortcutValue->setText( keyItem->text( 1 ) ); shortcutValue->setText( keyItem->text( 1 ) );
shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toInt() ); shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toInt() );
shortcutValue->setGlobal( false );
} }
void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem ) void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
{ {
/* This happens when triggered by ClickEater */ /* This happens when triggered by ClickEater */
if( keyItem == NULL ) keyItem = table->currentItem(); if( keyItem == NULL ) keyItem = table->currentItem();
...@@ -1272,8 +1273,13 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem ) ...@@ -1272,8 +1273,13 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
and the shortcutValue is clicked */ and the shortcutValue is clicked */
if( !keyItem ) return; if( !keyItem ) return;
/* If clicked on the first column, assuming user wants the normal hotkey */
if( column == 0 ) column = 1;
bool b_global = ( column == 2 );
/* 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 ), widget ); KeyInputDialog *d = new KeyInputDialog( table, keyItem->text( 0 ), widget, b_global );
d->exec(); d->exec();
if( d->result() == QDialog::Accepted ) if( d->result() == QDialog::Accepted )
...@@ -1281,6 +1287,7 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem ) ...@@ -1281,6 +1287,7 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
int newValue = d->keyValue; int newValue = d->keyValue;
shortcutValue->setText( VLCKeyToString( newValue ) ); shortcutValue->setText( VLCKeyToString( newValue ) );
shortcutValue->setValue( newValue ); shortcutValue->setValue( newValue );
shortcutValue->setGlobal( b_global );
if( d->conflicts ) if( d->conflicts )
{ {
...@@ -1288,11 +1295,11 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem ) ...@@ -1288,11 +1295,11 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
for( int i = 0; i < table->topLevelItemCount() ; i++ ) for( int i = 0; i < table->topLevelItemCount() ; i++ )
{ {
it = table->topLevelItem(i); it = table->topLevelItem(i);
if( ( keyItem != it ) if( ( keyItem != it ) &&
&& ( it->data( 1, Qt::UserRole ).toInt() == newValue ) ) ( it->data( b_global ? 2: 1, Qt::UserRole ).toInt() == newValue ) )
{ {
it->setData( 1, Qt::UserRole, QVariant( -1 ) ); it->setData( b_global ? 2 : 1, Qt::UserRole, QVariant( -1 ) );
it->setText( 1, qtr( "Unset" ) ); it->setText( b_global ? 2 : 1, qtr( "Unset" ) );
} }
} }
/* We already made an OK once. */ /* We already made an OK once. */
...@@ -1305,8 +1312,10 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem ) ...@@ -1305,8 +1312,10 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem )
void KeySelectorControl::setTheKey() void KeySelectorControl::setTheKey()
{ {
if( !table->currentItem() ) return; if( !table->currentItem() ) return;
table->currentItem()->setText( 1, shortcutValue->text() ); table->currentItem()->setText( shortcutValue->getGlobal() ? 2 : 1,
table->currentItem()->setData( 1, Qt::UserRole, shortcutValue->getValue() ); shortcutValue->text() );
table->currentItem()->setData( shortcutValue->getGlobal() ? 2 : 1,
Qt::UserRole, shortcutValue->getValue() );
} }
void KeySelectorControl::doApply() void KeySelectorControl::doApply()
...@@ -1319,19 +1328,29 @@ void KeySelectorControl::doApply() ...@@ -1319,19 +1328,29 @@ void KeySelectorControl::doApply()
config_PutInt( p_this, config_PutInt( p_this,
qtu( it->data( 0, Qt::UserRole ).toString() ), qtu( it->data( 0, Qt::UserRole ).toString() ),
it->data( 1, Qt::UserRole ).toInt() ); it->data( 1, Qt::UserRole ).toInt() );
if( it->data( 2, Qt::UserRole ).toInt() >= 0 )
config_PutInt( p_this,
qtu( "global-" + it->data( 0, Qt::UserRole ).toString() ),
it->data( 2, Qt::UserRole ).toInt() );
} }
} }
/**
* Class KeyInputDialog
**/
KeyInputDialog::KeyInputDialog( QTreeWidget *_table, KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
const QString& keyToChange, const QString& keyToChange,
QWidget *_parent ) : QWidget *_parent,
QDialog( _parent ), keyValue(0) bool _b_global ) :
QDialog( _parent ), keyValue(0), b_global( _b_global )
{ {
setModal( true ); setModal( true );
conflicts = false; conflicts = false;
table = _table; table = _table;
setWindowTitle( qtr( "Hotkey for " ) + keyToChange ); setWindowTitle( b_global ? qtr( "Global" ): ""
+ qtr( "Hotkey for " ) + keyToChange );
vLayout = new QVBoxLayout( this ); vLayout = new QVBoxLayout( this );
selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange ); selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
...@@ -1358,10 +1377,11 @@ KeyInputDialog::KeyInputDialog( QTreeWidget *_table, ...@@ -1358,10 +1377,11 @@ KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
void KeyInputDialog::checkForConflicts( int i_vlckey ) void KeyInputDialog::checkForConflicts( int i_vlckey )
{ {
QList<QTreeWidgetItem *> conflictList = QList<QTreeWidgetItem *> conflictList =
table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly, 1 ); table->findItems( VLCKeyToString( i_vlckey ), Qt::MatchExactly,
b_global ? 2 : 1 );
if( conflictList.size() && if( conflictList.size() &&
conflictList[0]->data( 1, Qt::UserRole ).toInt() > 1 ) conflictList[0]->data( b_global ? 2 : 1, Qt::UserRole ).toInt() > 1 )
/* Avoid 0 or -1 that are the "Unset" states */ /* Avoid 0 or -1 that are the "Unset" states */
{ {
warning->setText( qtr("Warning: the key is already assigned to \"") + warning->setText( qtr("Warning: the key is already assigned to \"") +
......
...@@ -421,14 +421,18 @@ private slot: ...@@ -421,14 +421,18 @@ private slot:
**********************************************************************/ **********************************************************************/
class KeyShortcutEdit: public QLineEdit class KeyShortcutEdit: public QLineEdit
{ {
Q_OBJECT Q_OBJECT;
public: public:
void setValue( int _value ){ value = _value; } void setValue( int _value ){ value = _value; }
int getValue() const { return value; } int getValue() const { return value; }
void setGlobal( bool _value ) { b_global = _value; }
bool getGlobal() const { return b_global; }
public slots: public slots:
virtual void clear(void) { value = 0; QLineEdit::clear(); } virtual void clear(void) { value = 0; QLineEdit::clear(); b_global = false;}
private: private:
int value; int value;
bool b_global;
virtual void mousePressEvent( QMouseEvent *event ); virtual void mousePressEvent( QMouseEvent *event );
signals: signals:
void pressed(); void pressed();
...@@ -455,7 +459,7 @@ private: ...@@ -455,7 +459,7 @@ private:
SearchLineEdit *actionSearch; SearchLineEdit *actionSearch;
private slots: private slots:
void setTheKey(); void setTheKey();
void selectKey( QTreeWidgetItem * = NULL ); void selectKey( QTreeWidgetItem * = NULL, int column = 1 );
void select1Key(); void select1Key();
void filter( const QString & ); void filter( const QString & );
}; };
...@@ -463,7 +467,7 @@ private slots: ...@@ -463,7 +467,7 @@ private slots:
class KeyInputDialog : public QDialog class KeyInputDialog : public QDialog
{ {
public: public:
KeyInputDialog( QTreeWidget *, const QString&, QWidget * ); KeyInputDialog( QTreeWidget *, const QString&, QWidget *, bool b_global = false);
int keyValue; int keyValue;
bool conflicts; bool conflicts;
private: private:
...@@ -474,5 +478,6 @@ private: ...@@ -474,5 +478,6 @@ private:
QLabel *selected, *warning; QLabel *selected, *warning;
QVBoxLayout *vLayout; QVBoxLayout *vLayout;
QDialogButtonBox *buttonBox; QDialogButtonBox *buttonBox;
bool b_global;
}; };
#endif #endif
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