2 * \file fancylineedit.h
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Nokia Corporation (qt-info@nokia.com)
8 * Full author contact details are available in file CREDITS.
12 // Code taken from the Qt Creator project and customized a little
14 #ifndef FANCYLINEEDIT_H
15 #define FANCYLINEEDIT_H
18 #include <QAbstractButton>
23 class FancyLineEditPrivate;
25 class IconButton: public QAbstractButton
28 Q_PROPERTY(float iconOpacity READ iconOpacity WRITE setIconOpacity)
29 Q_PROPERTY(bool autoHide READ hasAutoHide WRITE setAutoHide)
30 Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
32 explicit IconButton(QWidget *parent = 0);
33 void paintEvent(QPaintEvent *event) override;
34 void setPixmap(const QPixmap &pixmap) { m_pixmap = pixmap; update(); }
35 QPixmap pixmap() const { return m_pixmap; }
36 float iconOpacity() { return m_iconOpacity; }
37 void setIconOpacity(float value) { m_iconOpacity = value; update(); }
38 void animateShow(bool visible);
40 void setAutoHide(bool hide) { m_autoHide = hide; }
41 bool hasAutoHide() const { return m_autoHide; }
48 /* A line edit with an embedded pixmap on one side that is connected to
49 * a menu. Additionally, it can display a grayed hintText (like "Type Here to")
50 * when not focused and empty. When connecting to the changed signals and
51 * querying text, one has to be aware that the text is set to that hint
52 * text if isShowingHintText() returns true (that is, does not contain
55 class FancyLineEdit : public QLineEdit
57 Q_DISABLE_COPY(FancyLineEdit)
62 enum Side {Left = 0, Right = 1};
65 void buttonClicked(Side side);
66 void leftButtonClicked();
67 void rightButtonClicked();
71 explicit FancyLineEdit(QWidget *parent = 0);
74 /// Set a button to clear contents
75 void setClearButton(bool visible);
77 QPixmap buttonPixmap(Side side) const;
78 void setButtonPixmap(Side side, const QPixmap &pixmap);
80 QMenu *buttonMenu(Side side) const;
81 void setButtonMenu(Side side, QMenu *menu);
83 void setButtonVisible(Side side, bool visible);
84 bool isButtonVisible(Side side) const;
86 void setButtonToolTip(Side side, const QString &);
87 void setButtonFocusPolicy(Side side, Qt::FocusPolicy policy);
89 // Set whether tabbing in will trigger the menu.
90 void setMenuTabFocusTrigger(Side side, bool v);
91 bool hasMenuTabFocusTrigger(Side side) const;
93 // Set if icon should be hidden when text is empty
94 void setAutoHideButton(Side side, bool h);
95 bool hasAutoHideButton(Side side) const;
98 void checkButtons(const QString &);
102 void resizeEvent(QResizeEvent *e) override;
103 void keyPressEvent(QKeyEvent *e) override;
106 void updateMargins();
107 void updateButtonPositions();
109 FancyLineEditPrivate *m_d;
113 } // namespace frontend
116 #endif // FANCYLINEEDIT_H