]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/FancyLineEdit.cpp
rename buffer parameter math_number_before to math_numbering_side
[lyx.git] / src / frontends / qt4 / FancyLineEdit.cpp
index 527740a3ebdf4bf59e5934e0cc44ca1da028ab31..0e35ebb6cec5daae3bfa30f258164813b55cd2e9 100644 (file)
 
 // Code taken from the Qt Creator project and customized a little
 
+#include <config.h>
+
 #include "FancyLineEdit.h"
 
 #if QT_VERSION >= 0x040600
 
-#include <QtCore/QEvent>
-#include <QtCore/QDebug>
-#include <QtCore/QString>
-#include <QtCore/QPropertyAnimation>
-#include <QtGui/QApplication>
-#include <QtGui/QMenu>
-#include <QtGui/QMouseEvent>
-#include <QtGui/QLabel>
-#include <QtGui/QAbstractButton>
-#include <QtGui/QPainter>
-#include <QtGui/QStyle>
-#include <QtGui/QPaintEvent>
+#include <QEvent>
+#include <QDebug>
+#include <QString>
+#include <QPropertyAnimation>
+#include <QApplication>
+#include <QMenu>
+#include <QMouseEvent>
+#include <QLabel>
+#include <QAbstractButton>
+#include <QPainter>
+#include <QStyle>
+#include <QPaintEvent>
 
 enum { margin = 6 };
 
@@ -102,9 +104,12 @@ FancyLineEdit::FancyLineEdit(QWidget *parent) :
     ensurePolished();
     updateMargins();
 
-    connect(this, SIGNAL(textChanged(QString)), this, SLOT(checkButtons(QString)));
-    connect(m_d->m_iconbutton[Left], SIGNAL(clicked()), this, SLOT(iconClicked()));
-    connect(m_d->m_iconbutton[Right], SIGNAL(clicked()), this, SLOT(iconClicked()));
+    connect(this, SIGNAL(textChanged(QString)),
+            this, SLOT(checkButtons(QString)));
+    connect(m_d->m_iconbutton[Left], SIGNAL(clicked()),
+            this, SLOT(iconClicked()));
+    connect(m_d->m_iconbutton[Right], SIGNAL(clicked()),
+            this, SLOT(iconClicked()));
 }
 
 void FancyLineEdit::checkButtons(const QString &text)
@@ -184,10 +189,12 @@ void FancyLineEdit::updateButtonPositions()
 
         if (iconpos == FancyLineEdit::Right) {
             const int iconoffset = textMargins().right() + 4;
-            m_d->m_iconbutton[i]->setGeometry(contentRect.adjusted(width() - iconoffset, 0, 0, 0));
+            m_d->m_iconbutton[i]->
+                   setGeometry(contentRect.adjusted(width() - iconoffset, 0, 0, 0));
         } else {
             const int iconoffset = textMargins().left() + 4;
-            m_d->m_iconbutton[i]->setGeometry(contentRect.adjusted(0, 0, -width() + iconoffset, 0));
+            m_d->m_iconbutton[i]->
+                   setGeometry(contentRect.adjusted(0, 0, -width() + iconoffset, 0));
         }
     }
 }
@@ -197,6 +204,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);
@@ -262,7 +279,7 @@ void FancyLineEdit::setButtonFocusPolicy(Side side, Qt::FocusPolicy policy)
 // IconButton - helper class to represent a clickable icon
 
 IconButton::IconButton(QWidget *parent)
-    : QAbstractButton(parent), m_autoHide(false)
+    : QAbstractButton(parent), m_iconOpacity(0.0), m_autoHide(false)
 {
     setCursor(Qt::ArrowCursor);
     setFocusPolicy(Qt::NoFocus);
@@ -271,11 +288,6 @@ IconButton::IconButton(QWidget *parent)
 void IconButton::paintEvent(QPaintEvent *)
 {
     QPainter painter(this);
-    // Note isDown should really use the active state but in most styles
-    // this has no proper feedback
-    QIcon::Mode state = QIcon::Disabled;
-    if (isEnabled())
-        state = isDown() ? QIcon::Selected : QIcon::Normal;
     QRect pixmapRect = QRect(0, 0, m_pixmap.width(), m_pixmap.height());
     pixmapRect.moveCenter(rect().center());
 
@@ -288,12 +300,14 @@ void IconButton::paintEvent(QPaintEvent *)
 void IconButton::animateShow(bool visible)
 {
     if (visible) {
-        QPropertyAnimation *animation = new QPropertyAnimation(this, "iconOpacity");
+        QPropertyAnimation *animation =
+               new QPropertyAnimation(this, "iconOpacity");
         animation->setDuration(FADE_TIME);
         animation->setEndValue(1.0);
         animation->start(QAbstractAnimation::DeleteWhenStopped);
     } else {
-        QPropertyAnimation *animation = new QPropertyAnimation(this, "iconOpacity");
+        QPropertyAnimation *animation =
+               new QPropertyAnimation(this, "iconOpacity");
         animation->setDuration(FADE_TIME);
         animation->setEndValue(0.0);
         animation->start(QAbstractAnimation::DeleteWhenStopped);