]> git.lyx.org Git - features.git/commitdiff
Implement down key press in FancyLineEdit
authorGuillaume Munch <gm@lyx.org>
Sun, 26 Feb 2017 21:15:50 +0000 (22:15 +0100)
committerGuillaume Munch <gm@lyx.org>
Sun, 26 Feb 2017 21:16:10 +0000 (22:16 +0100)
src/frontends/qt4/FancyLineEdit.cpp
src/frontends/qt4/FancyLineEdit.h
src/frontends/qt4/GuiCitation.cpp
src/frontends/qt4/GuiRef.cpp
src/frontends/qt4/GuiSelectionManager.cpp
src/frontends/qt4/PanelStack.cpp
src/frontends/qt4/qt_helpers.cpp
src/frontends/qt4/qt_helpers.h

index 1238afd26218429c5de623101308b37c82fc67eb..118a9b876fbe25839c9eddd820b8135f9c841847 100644 (file)
@@ -199,6 +199,16 @@ void FancyLineEdit::resizeEvent(QResizeEvent *)
     updateButtonPositions();
 }
 
+
+void FancyLineEdit::keyPressEvent(QKeyEvent * e)
+{
+       if (e->type() == QEvent::KeyPress && e->key() == Qt::Key_Down)
+               Q_EMIT downPressed();
+       else
+               QLineEdit::keyPressEvent(e);
+}
+
+
 void FancyLineEdit::setButtonPixmap(Side side, const QPixmap &buttonPixmap)
 {
     m_d->m_iconbutton[side]->setPixmap(buttonPixmap);
index ae62c8539ed448ebb174b99d78f7a24da429d456..cd3c6b5951c25208d9615ee43890b39b0e60a585 100644 (file)
@@ -22,7 +22,6 @@ namespace frontend {
 
 class FancyLineEditPrivate;
 
-#if QT_VERSION >= 0x040600
 class IconButton: public QAbstractButton
 {
        Q_OBJECT
@@ -45,7 +44,6 @@ private:
     bool m_autoHide;
     QPixmap m_pixmap;
 };
-#endif
 
 /* A line edit with an embedded pixmap on one side that is connected to
  * a menu. Additionally, it can display a grayed hintText (like "Type Here to")
@@ -67,8 +65,8 @@ Q_SIGNALS:
     void buttonClicked(Side side);
     void leftButtonClicked();
     void rightButtonClicked();
+       void downPressed();
 
-#if QT_VERSION >= 0x040600
 public:
     explicit FancyLineEdit(QWidget *parent = 0);
     ~FancyLineEdit();
@@ -99,6 +97,7 @@ private Q_SLOTS:
 
 protected:
     virtual void resizeEvent(QResizeEvent *e);
+       virtual void keyPressEvent(QKeyEvent *e);
 
 private:
     void updateMargins();
@@ -106,12 +105,6 @@ private:
 
     FancyLineEditPrivate *m_d;
     QString m_oldText;
-#else
-public:
-       explicit FancyLineEdit(QWidget *parent = 0) 
-               : QLineEdit(parent) 
-       {}
-#endif // QT_VERSION >= 0x040600*/
 };
 
 }
index ee125e43d29606fd393f7cb3c33a673b32f5a2c6..f19837e3dc4eeeb57fc4d4db2d7a56c1080f8766 100644 (file)
@@ -155,6 +155,13 @@ GuiCitation::GuiCitation(GuiView & lv)
                this, SLOT(filterChanged(QString)));
        connect(filter_, SIGNAL(returnPressed()),
                this, SLOT(filterPressed()));
+#if (QT_VERSION < 0x050000)
+       connect(filter_, SIGNAL(downPressed()),
+               availableLV, SLOT(setFocus()));
+#else
+       connect(filter_, &FancyLineEdit::downPressed,
+               availableLV, [=](){ focusAndHighlight(availableLV); });
+#endif
        connect(regexp_, SIGNAL(triggered()),
                this, SLOT(regexChanged()));
        connect(casesense_, SIGNAL(triggered()),
index 58aa435efaa5ab4d039fe49522cce2e910a8db28..3d3cdded27e2ccbe1bff185bd34a1ea3ae3ff05a 100644 (file)
@@ -59,6 +59,13 @@ GuiRef::GuiRef(GuiView & lv)
        filter_->setAutoHideButton(FancyLineEdit::Right, true);
        filter_->setPlaceholderText(qt_("All available labels"));
        filter_->setToolTip(qt_("Enter string to filter the list of available labels"));
+#if (QT_VERSION < 0x050000)
+       connect(filter_, SIGNAL(downPressed()),
+               refsTW, SLOT(setFocus()));
+#else
+       connect(filter_, &FancyLineEdit::downPressed,
+               refsTW, [=](){ focusAndHighlight(refsTW); });
+#endif
 
        filterBarL->addWidget(filter_, 0);
        findKeysLA->setBuddy(filter_);
index 5bdec941c173daa50b5704fc13452b082eb390a2..c85104134f533f9d6259926a060f8057fb4e182d 100644 (file)
@@ -15,6 +15,7 @@
 #include <config.h>
 
 #include "GuiSelectionManager.h"
+#include "qt_helpers.h"
 
 #include "support/debug.h"
 
@@ -403,8 +404,7 @@ bool GuiSelectionManager::eventFilter(QObject * obj, QEvent * event)
                                return true;
                        }
                        else if (keyPressed == Qt::Key_Right) {
-                               selectedLV->setFocus();
-                               selectedLV->setCurrentIndex(selectedLV->currentIndex());
+                               focusAndHighlight(selectedLV);
                                event->accept();
                                return true;
                        }
@@ -452,8 +452,7 @@ bool GuiSelectionManager::eventFilter(QObject * obj, QEvent * event)
                                }
                        }
                        else if (keyPressed == Qt::Key_Left) {
-                               availableLV->setFocus();
-                               availableLV->setCurrentIndex(availableLV->currentIndex());
+                               focusAndHighlight(availableLV);
                                event->accept();
                                return true;
                        }
index 3036b1e4d35385687847813eb710dfb9cbd62e23..d7089527976ca177ecea5c7b17d248c942379033 100644 (file)
@@ -81,6 +81,8 @@ PanelStack::PanelStack(QWidget * parent)
 #endif
        connect(search_, SIGNAL(rightButtonClicked()), this, SLOT(resetSearch()));
        connect(search_, SIGNAL(textEdited(QString)), this, SLOT(filterChanged(QString)));
+       connect(search_, SIGNAL(downPressed()),
+               list_, SLOT(setFocus()));
 
        // Create the output layout, horizontal plus a VBox on the left with the search
        // box and the tree
index 92b1187317fa9654cdc8ec1561e35761948639c0..dee6bd4bfed355a9a9a481110f9cfbbdd78c9bb0 100644 (file)
@@ -230,6 +230,15 @@ void setValid(QWidget * widget, bool valid)
        }
 }
 
+
+void focusAndHighlight(QAbstractItemView * w)
+{
+       w->setFocus();
+       w->setCurrentIndex(w->currentIndex());
+       w->scrollTo(w->currentIndex());
+}
+
+
 /// wrapper to hide the change of method name to setSectionResizeMode
 void setSectionResizeMode(QHeaderView * view,
     int logicalIndex, QHeaderView::ResizeMode mode) {
index 90f2017f43330a625e4fe8af337567aea5c997cb..f59b22ee76c28a46a9142d03ca5e19a8a0d2a374 100644 (file)
@@ -80,6 +80,9 @@ bool ColorSorter(ColorCode lhs, ColorCode rhs);
 /// colors a widget red if invalid
 void setValid(QWidget * widget, bool valid);
 
+// set focus and highlight the current item if there is no selection already
+void focusAndHighlight(QAbstractItemView * w);
+
 /// Qt5 changed setSectionMode to setSectionResizeMode
 /// These wrappers work for Qt4 and Qt5
 void setSectionResizeMode(QHeaderView * view,