[vlc-commits] Qt: simplify too complex UI for keys
Jean-Baptiste Kempf
git at videolan.org
Thu Nov 17 00:55:20 CET 2011
vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Thu Nov 17 00:21:33 2011 +0100| [756eb4fe379e8fdef27961af5b90ae217e993d98] | committer: Jean-Baptiste Kempf
Qt: simplify too complex UI for keys
Noone understood this UI, but me...
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=756eb4fe379e8fdef27961af5b90ae217e993d98
---
modules/gui/qt4/components/preferences_widgets.cpp | 84 +++++++------------
modules/gui/qt4/components/preferences_widgets.hpp | 34 ++-------
2 files changed, 37 insertions(+), 81 deletions(-)
diff --git a/modules/gui/qt4/components/preferences_widgets.cpp b/modules/gui/qt4/components/preferences_widgets.cpp
index f9cf579..9597bef 100644
--- a/modules/gui/qt4/components/preferences_widgets.cpp
+++ b/modules/gui/qt4/components/preferences_widgets.cpp
@@ -1297,7 +1297,7 @@ KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
qtr( "Select an action to change the associated hotkey") );
QLabel *searchLabel = new QLabel( qtr( "Search" ) );
- actionSearch = new SearchLineEdit( keyContainer );
+ SearchLineEdit *actionSearch = new SearchLineEdit( keyContainer );
table = new QTreeWidget;
table->setColumnCount(3);
@@ -1307,27 +1307,17 @@ KeySelectorControl::KeySelectorControl( vlc_object_t *_p_this,
table->setAlternatingRowColors( true );
table->setSelectionBehavior( QAbstractItemView::SelectItems );
- shortcutValue = new KeyShortcutEdit;
- shortcutValue->setReadOnly(true);
+ table->installEventFilter( this );
- QPushButton *clearButton = new QPushButton( qtr( "Clear" ) );
- QPushButton *setButton = new QPushButton( qtr( "Apply" ) );
- setButton->setDefault( true );
finish();
gLayout->addWidget( label, 0, 0, 1, 4 );
gLayout->addWidget( searchLabel, 1, 0, 1, 2 );
gLayout->addWidget( actionSearch, 1, 2, 1, 2 );
gLayout->addWidget( table, 2, 0, 1, 4 );
- gLayout->addWidget( clearButton, 3, 0, 1, 1 );
- gLayout->addWidget( shortcutValue, 3, 1, 1, 2 );
- gLayout->addWidget( setButton, 3, 3, 1, 1 );
l->addWidget( keyContainer, line, 0, 1, -1 );
- CONNECT( clearButton, clicked(), shortcutValue, clear() );
- CONNECT( clearButton, clicked(), this, setTheKey() );
- BUTTONACT( setButton, setTheKey() );
CONNECT( actionSearch, textChanged( const QString& ),
this, filter( const QString& ) );
}
@@ -1396,14 +1386,8 @@ void KeySelectorControl::finish()
table->resizeColumnToContents( 0 );
- CONNECT( table, itemDoubleClicked( QTreeWidgetItem *, int ),
+ CONNECT( table, itemActivated( QTreeWidgetItem *, int ),
this, selectKey( QTreeWidgetItem *, int ) );
- CONNECT( table, itemClicked( QTreeWidgetItem *, int ),
- this, select( QTreeWidgetItem *, int) );
- CONNECT( table, itemSelectionChanged(),
- this, select1Key() );
-
- CONNECT( shortcutValue, pressed(), this, selectKey() );
}
void KeySelectorControl::filter( const QString &qs_search )
@@ -1417,20 +1401,6 @@ void KeySelectorControl::filter( const QString &qs_search )
}
}
-void KeySelectorControl::select( QTreeWidgetItem *, int column )
-{
- shortcutValue->setGlobal( column == 2 );
-}
-
-/* Show the key selected from the table in the keySelector */
-void KeySelectorControl::select1Key()
-{
- QTreeWidgetItem *keyItem = table->currentItem();
- shortcutValue->setText( keyItem->text( 1 ) );
- shortcutValue->setValue( keyItem->data( 1, Qt::UserRole ).toString() );
- shortcutValue->setGlobal( false );
-}
-
void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
{
/* This happens when triggered by ClickEater */
@@ -1452,10 +1422,8 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
if( d->result() == QDialog::Accepted )
{
QString newKey = VLCKeyToString( d->keyValue );
- shortcutValue->setText( newKey );
- shortcutValue->setValue( newKey );
- shortcutValue->setGlobal( b_global );
+ /* In case of conflict, reset other keys*/
if( d->conflicts )
{
QTreeWidgetItem *it;
@@ -1470,22 +1438,14 @@ void KeySelectorControl::selectKey( QTreeWidgetItem *keyItem, int column )
it->setText( 1 + b_global, qtr( "Unset" ) );
}
}
- /* We already made an OK once. */
- setTheKey();
}
+
+ keyItem->setText( column, newKey );
+ keyItem->setData( column, Qt::UserRole, newKey );
}
delete d;
}
-void KeySelectorControl::setTheKey()
-{
- if( !table->currentItem() ) return;
- table->currentItem()->setText( shortcutValue->getGlobal() ? 2 : 1,
- shortcutValue->text() );
- table->currentItem()->setData( shortcutValue->getGlobal() ? 2 : 1,
- Qt::UserRole, shortcutValue->getValue() );
-}
-
void KeySelectorControl::doApply()
{
QTreeWidgetItem *it;
@@ -1504,6 +1464,29 @@ void KeySelectorControl::doApply()
}
}
+bool KeySelectorControl::eventFilter( QObject *obj, QEvent *e )
+{
+ if( obj != table || e->type() != QEvent::KeyPress )
+ return ConfigControl::eventFilter(obj, e);
+
+ QKeyEvent *keyEv = static_cast<QKeyEvent*>(e);
+ QTreeWidget *aTable = static_cast<QTreeWidget *>(obj);
+ if( keyEv->key() == Qt::Key_Escape )
+ {
+ aTable->clearFocus();
+ return true;
+ }
+ else if( keyEv->key() == Qt::Key_Return ||
+ keyEv->key() == Qt::Key_Enter )
+ {
+ selectKey( aTable->currentItem(), aTable->currentColumn() );
+ return true;
+ }
+ else
+ return false;
+}
+
+
/**
* Class KeyInputDialog
**/
@@ -1521,7 +1504,7 @@ KeyInputDialog::KeyInputDialog( QTreeWidget *_table,
+ qtr( "Hotkey for " ) + keyToChange );
setWindowRole( "vlc-key-input" );
- vLayout = new QVBoxLayout( this );
+ QVBoxLayout *vLayout = new QVBoxLayout( this );
selected = new QLabel( qtr( "Press the new keys for " ) + keyToChange );
vLayout->addWidget( selected , Qt::AlignCenter );
@@ -1586,8 +1569,3 @@ void KeyInputDialog::wheelEvent( QWheelEvent *e )
keyValue = i_vlck;
}
-void KeyShortcutEdit::mousePressEvent( QMouseEvent *)
-{
- emit pressed();
-}
-
diff --git a/modules/gui/qt4/components/preferences_widgets.hpp b/modules/gui/qt4/components/preferences_widgets.hpp
index 9006152..fd7f7b7 100644
--- a/modules/gui/qt4/components/preferences_widgets.hpp
+++ b/modules/gui/qt4/components/preferences_widgets.hpp
@@ -446,26 +446,6 @@ private slot:
/**********************************************************************
* Key selector widget
**********************************************************************/
-class KeyShortcutEdit: public QLineEdit
-{
- Q_OBJECT
-public:
- void setValue( const QString& value ){ this->value = value; }
- QString getValue() const { return value; }
-
- void setGlobal( bool _value ) { b_global = _value; }
- bool getGlobal() const { return b_global; }
-public slots:
- virtual void clear(void) { value = qfu(""); QLineEdit::clear(); }
-private:
- QString value;
- bool b_global;
- virtual void mousePressEvent( QMouseEvent *event );
-signals:
- void pressed();
-};
-
-class SearchLineEdit;
class KeySelectorControl : public ConfigControl
{
Q_OBJECT
@@ -476,18 +456,15 @@ public:
virtual void hide() { table->hide(); if( label ) label->hide(); }
virtual void show() { table->show(); if( label ) label->show(); }
virtual void doApply();
+protected:
+ virtual bool eventFilter( QObject *, QEvent * );
private:
void finish();
QLabel *label;
QTreeWidget *table;
- KeyShortcutEdit *shortcutValue;
QList<module_config_t *> values;
- SearchLineEdit *actionSearch;
private slots:
- void setTheKey();
void selectKey( QTreeWidgetItem * = NULL, int column = 1 );
- void select( QTreeWidgetItem * = NULL, int column = 1 );
- void select1Key();
void filter( const QString & );
};
@@ -497,14 +474,15 @@ public:
KeyInputDialog( QTreeWidget *, const QString&, QWidget *, bool b_global = false);
int keyValue;
bool conflicts;
+
private:
QTreeWidget *table;
+ QLabel *selected, *warning;
+ QDialogButtonBox *buttonBox;
+
void checkForConflicts( int i_vlckey );
void keyPressEvent( QKeyEvent *);
void wheelEvent( QWheelEvent *);
- QLabel *selected, *warning;
- QVBoxLayout *vLayout;
- QDialogButtonBox *buttonBox;
bool b_global;
};
#endif
More information about the vlc-commits
mailing list