forked from goldendict/goldendict
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextlineedit.hh
78 lines (58 loc) · 1.91 KB
/
extlineedit.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* This file is (c) 2012 Tvangeste <[email protected]>
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#ifndef EXTLINEEDIT_H
#define EXTLINEEDIT_H
#include <QLineEdit>
#include <QAbstractButton>
class IconButton: public QAbstractButton
{
Q_OBJECT
Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
Q_PROPERTY(float opacity READ opacity WRITE setOpacity)
public:
explicit IconButton(QWidget * parent = 0);
void paintEvent(QPaintEvent * event);
void animate(bool visible);
void setPixmap(const QPixmap & pixmap) { m_pixmap = pixmap; update(); }
QPixmap pixmap() const { return m_pixmap; }
void setAutoHide(bool autohide) { m_autohide = autohide; update(); }
bool isAutoHide() const { return m_autohide; }
float opacity() { return m_opacity; }
void setOpacity(float opacity) { m_opacity = opacity; update(); }
private:
QPixmap m_pixmap;
bool m_autohide;
float m_opacity;
};
class ExtLineEdit : public QLineEdit
{
Q_OBJECT
Q_ENUMS(Side)
public:
enum Side { Left = 0, Right = 1 };
explicit ExtLineEdit(QWidget * parent = 0);
~ExtLineEdit();
QPixmap buttonPixmap(Side side) const;
void setButtonPixmap(Side side, const QPixmap &pixmap);
void setButtonVisible(Side side, bool visible);
bool isButtonVisible(Side side) const;
void setButtonToolTip(Side side, const QString &);
void setButtonFocusPolicy(Side side, Qt::FocusPolicy policy);
void setButtonAutoHide(Side side, bool autohide);
signals:
void leftButtonClicked();
void rightButtonClicked();
private slots:
void iconClicked();
void updateButtons(QString text);
protected:
virtual void resizeEvent( QResizeEvent * e );
private:
void updateMargins();
void updateButtonPositions();
QPixmap pixmaps[2];
IconButton * iconButtons[2];
bool iconEnabled[2];
QString oldText;
};
#endif // EXTLINEEDIT_H