]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/FancyLineEdit.h
Make the InsetInfo dialog a bit less esoteric.
[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 <QLineEdit>
18 #include <QAbstractButton>
19
20 namespace lyx {
21 namespace frontend {
22
23 class FancyLineEditPrivate;
24
25 class IconButton: public QAbstractButton
26 {
27         Q_OBJECT
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)
31 public:
32         explicit IconButton(QWidget *parent = 0);
33         void paintEvent(QPaintEvent *event);
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);
39
40         void setAutoHide(bool hide) { m_autoHide = hide; }
41         bool hasAutoHide() const { return m_autoHide; }
42 private:
43         float m_iconOpacity;
44         bool m_autoHide;
45         QPixmap m_pixmap;
46 };
47
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
53  * valid user input).
54  */
55 class FancyLineEdit : public QLineEdit
56 {
57         Q_DISABLE_COPY(FancyLineEdit)
58         Q_OBJECT
59         Q_ENUMS(Side)
60
61 public:
62         enum Side {Left = 0, Right = 1};
63
64 Q_SIGNALS:
65         void buttonClicked(Side side);
66         void leftButtonClicked();
67         void rightButtonClicked();
68         void downPressed();
69
70 public:
71         explicit FancyLineEdit(QWidget *parent = 0);
72         ~FancyLineEdit();
73
74         QPixmap buttonPixmap(Side side) const;
75         void setButtonPixmap(Side side, const QPixmap &pixmap);
76
77         QMenu *buttonMenu(Side side) const;
78         void setButtonMenu(Side side, QMenu *menu);
79
80         void setButtonVisible(Side side, bool visible);
81         bool isButtonVisible(Side side) const;
82
83         void setButtonToolTip(Side side, const QString &);
84         void setButtonFocusPolicy(Side side, Qt::FocusPolicy policy);
85
86         // Set whether tabbing in will trigger the menu.
87         void setMenuTabFocusTrigger(Side side, bool v);
88         bool hasMenuTabFocusTrigger(Side side) const;
89
90         // Set if icon should be hidden when text is empty
91         void setAutoHideButton(Side side, bool h);
92         bool hasAutoHideButton(Side side) const;
93
94 private Q_SLOTS:
95         void checkButtons(const QString &);
96         void iconClicked();
97
98 protected:
99         virtual void resizeEvent(QResizeEvent *e);
100         virtual void keyPressEvent(QKeyEvent *e);
101
102 private:
103         void updateMargins();
104         void updateButtonPositions();
105
106         FancyLineEditPrivate *m_d;
107         QString m_oldText;
108 };
109
110 } // namespace frontend
111 } // namespace lyx
112
113 #endif // FANCYLINEEDIT_H