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