-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBaseWidget.h
67 lines (57 loc) · 1.97 KB
/
BaseWidget.h
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
#ifndef BASE_WIDGET_H
#define BASE_WIDGET_H
#include <QWidget>
#include <QLabel>
#include <QStyle>
#include <QApplication>
//template<class T>
class BaseWidget : public QLabel {
Q_OBJECT
bool contentvisible;
public:
QSizePolicy::Policy vpolicy;
BaseWidget(QWidget *parent = 0) : QLabel(parent) {
contentvisible = false;
vpolicy = QSizePolicy::Expanding;
}
~BaseWidget() {
}
void Toggle(bool visible) {
QWidget *parent = this->parentWidget();
if (parent) {
parent->setUpdatesEnabled(false);
BaseWidget *image = (BaseWidget *)parent->findChild<QLabel *>("image");
if (image) {
QStyle *l_style = QApplication::style();
if (l_style) {
if (visible)
image->setText(QChar(0x25BC)); //setPixmap(l_style->standardPixmap(QStyle::SP_ArrowDown));
else
image->setText(QChar(0x25BA)); //setPixmap(l_style->standardPixmap(QStyle::SP_ArrowUp));
}
image->contentvisible = visible;
}
QWidget *container = parent->findChild<QWidget *>("container");
if (container)
container->setVisible(visible);
BaseWidget *label = (BaseWidget *)parent->findChild<QLabel *>("label");
if (label)
label->contentvisible = visible;
if (visible) {
QSizePolicy qs = parent->sizePolicy();
qs.setVerticalPolicy(vpolicy);
parent->setSizePolicy(qs);
} else {
QSizePolicy qs = parent->sizePolicy();
vpolicy = qs.verticalPolicy();
qs.setVerticalPolicy(QSizePolicy::Fixed);
parent->setSizePolicy(qs);
}
parent->setUpdatesEnabled(true);
}
}
void mousePressEvent(QMouseEvent *k) {
Toggle(!contentvisible);
}
};
#endif