]> git.lyx.org Git - features.git/blob - src/frontends/qt4/FancyLineEdit.h
dbf216fdf2a2f37a67624dd93c539db3a2fcee04
[features.git] / src / frontends / qt4 / FancyLineEdit.h
1 /**\r
2  * \file fancylineedit.h\r
3  * This file is part of LyX, the document processor.\r
4  * Licence details can be found in the file COPYING.\r
5  *\r
6  * \author Nokia Corporation (qt-info@nokia.com)\r
7  *\r
8  * Full author contact details are available in file CREDITS.\r
9  *\r
10  */\r
11 \r
12 // Code taken from the Qt Creator project and customized a little\r
13 \r
14 #ifndef FANCYLINEEDIT_H\r
15 #define FANCYLINEEDIT_H\r
16 \r
17 #include <QtGui/QLineEdit>\r
18 #include <QtGui/QAbstractButton>\r
19 \r
20 namespace lyx {\r
21 namespace frontend {\r
22 \r
23 class FancyLineEditPrivate;\r
24 \r
25 class IconButton: public QAbstractButton\r
26 {\r
27         Q_OBJECT\r
28         Q_PROPERTY(float iconOpacity READ iconOpacity WRITE setIconOpacity)\r
29         Q_PROPERTY(bool autoHide READ hasAutoHide WRITE setAutoHide)\r
30         Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)\r
31 public:\r
32     explicit IconButton(QWidget *parent = 0);\r
33     void paintEvent(QPaintEvent *event);\r
34     void setPixmap(const QPixmap &pixmap) { m_pixmap = pixmap; update(); }\r
35     QPixmap pixmap() const { return m_pixmap; }\r
36     float iconOpacity() { return m_iconOpacity; }\r
37     void setIconOpacity(float value) { m_iconOpacity = value; update(); }\r
38     void animateShow(bool visible);\r
39 \r
40     void setAutoHide(bool hide) { m_autoHide = hide; }\r
41     bool hasAutoHide() const { return m_autoHide; }\r
42 private:\r
43     float m_iconOpacity;\r
44     bool m_autoHide;\r
45     QPixmap m_pixmap;\r
46 };\r
47 \r
48 \r
49 /* A line edit with an embedded pixmap on one side that is connected to\r
50  * a menu. Additionally, it can display a grayed hintText (like "Type Here to")\r
51  * when not focused and empty. When connecting to the changed signals and\r
52  * querying text, one has to be aware that the text is set to that hint\r
53  * text if isShowingHintText() returns true (that is, does not contain\r
54  * valid user input).\r
55  */\r
56 class FancyLineEdit : public QLineEdit\r
57 {\r
58         Q_DISABLE_COPY(FancyLineEdit)\r
59         Q_OBJECT\r
60         Q_ENUMS(Side)\r
61 \r
62 public:\r
63     enum Side {Left = 0, Right = 1};\r
64 \r
65     explicit FancyLineEdit(QWidget *parent = 0);\r
66     ~FancyLineEdit();\r
67 \r
68     QPixmap buttonPixmap(Side side) const;\r
69     void setButtonPixmap(Side side, const QPixmap &pixmap);\r
70 \r
71     QMenu *buttonMenu(Side side) const;\r
72     void setButtonMenu(Side side, QMenu *menu);\r
73 \r
74     void setButtonVisible(Side side, bool visible);\r
75     bool isButtonVisible(Side side) const;\r
76 \r
77     void setButtonToolTip(Side side, const QString &);\r
78     void setButtonFocusPolicy(Side side, Qt::FocusPolicy policy);\r
79 \r
80     // Set whether tabbing in will trigger the menu.\r
81     void setMenuTabFocusTrigger(Side side, bool v);\r
82     bool hasMenuTabFocusTrigger(Side side) const;\r
83 \r
84     // Set if icon should be hidden when text is empty\r
85     void setAutoHideButton(Side side, bool h);\r
86     bool hasAutoHideButton(Side side) const;\r
87 \r
88 Q_SIGNALS:\r
89         void buttonClicked(Side side);\r
90     void leftButtonClicked();\r
91     void rightButtonClicked();\r
92 \r
93 private Q_SLOTS:\r
94     void checkButtons(const QString &);\r
95     void iconClicked();\r
96 \r
97 protected:\r
98     virtual void resizeEvent(QResizeEvent *e);\r
99 \r
100 private:\r
101     void updateMargins();\r
102         void updateButtonPositions();\r
103 \r
104     FancyLineEditPrivate *m_d;\r
105     QString m_oldText;\r
106 };\r
107 \r
108 }\r
109 }\r
110 \r
111 #endif // FANCYLINEEDIT_H\r