forked from Smorodov/CaffeGui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qnetools.h
62 lines (51 loc) · 1.13 KB
/
qnetools.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
#ifndef QNETOOLS_H
#define QNETOOLS_H
#include <QGraphicsPathItem>
#include <QGraphicsPixmapItem>
#include <QtXml/QDomDocument>
#include <QMainWindow>
#include <QtWidgets>
#include "qnetools.h"
class ToolItem : public QWidget
{
public:
ToolItem(const QString &title, QWidget *item) : item(item)
{
QVBoxLayout *layout = new QVBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(new QLabel(title));
layout->addWidget(item);
setLayout(layout);
item->setVisible(false);
}
protected:
void mousePressEvent(QMouseEvent *event)
{
item->setVisible(!item->isVisible());
}
private:
QWidget *item;
};
class ToolBox : public QWidget
{
public:
ToolBox() : layout(new QVBoxLayout)
{
setLayout(layout);
}
void addItem(ToolItem *item)
{
// Remove last spacer item if present.
int count = layout->count();
if (count > 1)
{
layout->removeItem(layout->itemAt(count - 1));
}
// Add item and make sure it stretches the remaining space.
layout->addWidget(item);
layout->addStretch();
}
private:
QVBoxLayout *layout;
};
#endif // QNETOOLS_H