summaryrefslogtreecommitdiffstats
path: root/qt-ui/modeldelegates.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-10-15 13:45:24 -0300
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-10-15 09:49:12 -0700
commit34f2a5ecc7c7bef15e3f29f1dc5def8a1d2e9965 (patch)
treea41190c6366b542ae4fead842f7b2f647ab30f8f /qt-ui/modeldelegates.cpp
parent6ccb541f1dc22295e61195aeac532f9f46cb0253 (diff)
downloadsubsurface-34f2a5ecc7c7bef15e3f29f1dc5def8a1d2e9965.tar.gz
Fixed the Tab behavior on the QCombobox Delegate
This Patch fixes the tab behavior on the QComboBox delegate. For a QComboBox, tab was being treated as 'cancel' action on edit, but since it will send a editingFinished() signal, and the Qt::Key_Return will also send a editingFinished() signal, I couldn't use that method and had to do a little hack around it. The code is mostly clean and works. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/modeldelegates.cpp')
-rw-r--r--qt-ui/modeldelegates.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
index a4f457f79..d1e283911 100644
--- a/qt-ui/modeldelegates.cpp
+++ b/qt-ui/modeldelegates.cpp
@@ -22,6 +22,7 @@
// Gets the index of the model in the currentRow and column.
// currCombo is defined below.
#define IDX( XX ) mymodel->index(currCombo.currRow, XX)
+static bool keyboardFinished = false;
StarWidgetsDelegate::StarWidgetsDelegate(QWidget* parent):
QStyledItemDelegate(parent),
@@ -91,11 +92,12 @@ QWidget* ComboBoxDelegate::createEditor(QWidget* parent, const QStyleOptionViewI
comboDelegate->lineEdit()->installEventFilter( const_cast<QObject*>(qobject_cast<const QObject*>(this)));
comboDelegate->view()->installEventFilter( const_cast<QObject*>(qobject_cast<const QObject*>(this)));
connect(comboDelegate, SIGNAL(highlighted(QString)), this, SLOT(testActivation(QString)));
- connect(comboDelegate->lineEdit(), SIGNAL(editingFinished()), this, SLOT(testActivation()));
connect(comboDelegate, SIGNAL(activated(QString)), this, SLOT(fakeActivation()));
+ connect(this, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), this, SLOT(fixTabBehavior()));
currCombo.comboEditor = comboDelegate;
currCombo.currRow = index.row();
currCombo.model = const_cast<QAbstractItemModel*>(index.model());
+ keyboardFinished = false;
// Current display of things on Gnome3 looks like shit, so
// let`s fix that.
@@ -137,6 +139,16 @@ void ComboBoxDelegate::fakeActivation(){
QStyledItemDelegate::eventFilter(currCombo.comboEditor, &ev);
}
+// This 'reverts' the model data to what we actually choosed,
+// becaus e a TAB is being understood by Qt as 'cancel' while
+// we are on a QComboBox ( but not on a QLineEdit.
+void ComboBoxDelegate::fixTabBehavior()
+{
+ if(keyboardFinished){
+ setModelData(0,0,QModelIndex());
+ }
+}
+
bool ComboBoxDelegate::eventFilter(QObject* object, QEvent* event)
{
// Reacts on Key_UP and Key_DOWN to show the QComboBox - list of choices.
@@ -147,6 +159,10 @@ bool ComboBoxDelegate::eventFilter(QObject* object, QEvent* event)
currCombo.ignoreSelection = true;
currCombo.comboEditor->showPopup();
}
+ if(ev->key() == Qt::Key_Tab || ev->key() == Qt::Key_Enter || ev->key() == Qt::Key_Return){
+ currCombo.activeText = currCombo.comboEditor->currentText();
+ keyboardFinished = true;
+ }
}
else{ // the 'Drop Down Menu' part.
QKeyEvent *ev = static_cast<QKeyEvent*>(event);