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

Qt: better unsetting of keys in preferences

Close #6640
parent 14793f5c
...@@ -1202,8 +1202,8 @@ void KeySelectorControl::finish() ...@@ -1202,8 +1202,8 @@ void KeySelectorControl::finish()
QString keys = qfu( p_config_item->value.psz ); QString keys = qfu( p_config_item->value.psz );
treeItem->setText( 1, keys ); treeItem->setText( 1, keys );
treeItem->setToolTip( 1, qtr("Double click to change") ); treeItem->setToolTip( 1, qtr("Double click to change.\nDelete key to remove.") );
treeItem->setToolTip( 2, qtr("Double click to change") ); treeItem->setToolTip( 2, qtr("Double click to change.\nDelete key to remove.") );
treeItem->setData( 1, Qt::UserRole, QVariant( keys ) ); treeItem->setData( 1, Qt::UserRole, QVariant( keys ) );
table->addTopLevelItem( treeItem ); table->addTopLevelItem( treeItem );
continue; continue;
...@@ -1285,9 +1285,8 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column ) ...@@ -1285,9 +1285,8 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
if( ( keyItem != it ) && if( ( keyItem != it ) &&
( it->data( 1 + b_global, Qt::UserRole ).toString() == newKey ) ) ( it->data( 1 + b_global, Qt::UserRole ).toString() == newKey ) )
{ {
it->setData( 1 + b_global, Qt::UserRole, it->setText( 1 + b_global, NULL );
QVariant( qfu( "Unset" ) ) ); it->setData( 1 + b_global, Qt::UserRole, QVariant() );
it->setText( 1 + b_global, qtr( "Unset" ) );
} }
} }
} }
...@@ -1295,6 +1294,12 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column ) ...@@ -1295,6 +1294,12 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
keyItem->setText( column, newKey ); keyItem->setText( column, newKey );
keyItem->setData( column, Qt::UserRole, newKey ); keyItem->setData( column, Qt::UserRole, newKey );
} }
else if( d->result() == 2 )
{
keyItem->setText( 1 + b_global, NULL );
keyItem->setData( 1 + b_global, Qt::UserRole, QVariant() );
}
delete d; delete d;
} }
...@@ -1376,18 +1381,21 @@ KeyInputDialog::KeyInputDialog( QTreeWidget *_table, ...@@ -1376,18 +1381,21 @@ KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
warning->hide(); warning->hide();
vLayout->insertWidget( 1, warning ); vLayout->insertWidget( 1, warning );
buttonBox = new QDialogButtonBox; QDialogButtonBox *buttonBox = new QDialogButtonBox;
QPushButton *ok = new QPushButton( qtr("Assign") ); ok = new QPushButton( qtr("Assign") );
QPushButton *cancel = new QPushButton( qtr("Cancel") ); QPushButton *cancel = new QPushButton( qtr("Cancel") );
unset = new QPushButton( qtr("Unset") );
buttonBox->addButton( ok, QDialogButtonBox::AcceptRole ); buttonBox->addButton( ok, QDialogButtonBox::AcceptRole );
buttonBox->addButton( unset, QDialogButtonBox::ActionRole );
buttonBox->addButton( cancel, QDialogButtonBox::RejectRole ); buttonBox->addButton( cancel, QDialogButtonBox::RejectRole );
ok->setDefault( true ); ok->setDefault( true );
vLayout->addWidget( buttonBox ); vLayout->addWidget( buttonBox );
buttonBox->hide(); ok->hide();
CONNECT( buttonBox, accepted(), this, accept() ); CONNECT( buttonBox, accepted(), this, accept() );
CONNECT( buttonBox, rejected(), this, reject() ); CONNECT( buttonBox, rejected(), this, reject() );
BUTTONACT( unset, unsetAction() );
} }
void KeyInputDialog::checkForConflicts( int i_vlckey ) void KeyInputDialog::checkForConflicts( int i_vlckey )
...@@ -1403,7 +1411,8 @@ void KeyInputDialog::checkForConflicts( int i_vlckey ) ...@@ -1403,7 +1411,8 @@ void KeyInputDialog::checkForConflicts( int i_vlckey )
warning->setText( qtr("Warning: this key or combination is already assigned to ") + warning->setText( qtr("Warning: this key or combination is already assigned to ") +
QString( "\"<b>%1</b>\"" ).arg( conflictList[0]->text( 0 ) ) ); QString( "\"<b>%1</b>\"" ).arg( conflictList[0]->text( 0 ) ) );
warning->show(); warning->show();
buttonBox->show(); ok->show();
unset->hide();
conflicts = true; conflicts = true;
} }
...@@ -1433,3 +1442,5 @@ void KeyInputDialog::wheelEvent( QWheelEvent *e ) ...@@ -1433,3 +1442,5 @@ void KeyInputDialog::wheelEvent( QWheelEvent *e )
checkForConflicts( i_vlck ); checkForConflicts( i_vlck );
keyValue = i_vlck; keyValue = i_vlck;
} }
void KeyInputDialog::unsetAction() { done( 2 ); };
...@@ -512,6 +512,7 @@ private slots: ...@@ -512,6 +512,7 @@ private slots:
class KeyInputDialog : public QDialog class KeyInputDialog : public QDialog
{ {
Q_OBJECT
public: public:
KeyInputDialog( QTreeWidget *, const QString&, QWidget *, bool b_global = false); KeyInputDialog( QTreeWidget *, const QString&, QWidget *, bool b_global = false);
int keyValue; int keyValue;
...@@ -520,11 +521,13 @@ public: ...@@ -520,11 +521,13 @@ public:
private: private:
QTreeWidget *table; QTreeWidget *table;
QLabel *selected, *warning; QLabel *selected, *warning;
QDialogButtonBox *buttonBox; QPushButton *ok, *unset;
void checkForConflicts( int i_vlckey ); void checkForConflicts( int i_vlckey );
void keyPressEvent( QKeyEvent *); void keyPressEvent( QKeyEvent *);
void wheelEvent( QWheelEvent *); void wheelEvent( QWheelEvent *);
bool b_global; bool b_global;
private slots:
void unsetAction();
}; };
#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