/
filterwrapper.cpp
84 lines (76 loc) · 2.43 KB
/
filterwrapper.cpp
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
79
80
81
82
83
84
#include <QWidget>
#include <QVBoxLayout>
#include <QToolButton>
#include "filterwrapper.h"
FilterWrapper::FilterWrapper(IFilter *filter, QWidget *parent) :
QWidget(parent), m_filter(filter), m_button(0),
m_controlButtons(0), m_applyButton(0)
{
QVBoxLayout *layout = new QVBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
setLayout(layout);
m_controlButtons = new QWidget(this);
QHBoxLayout *cbLayout = new QHBoxLayout();
cbLayout->setContentsMargins(0, 0, 0, 0);
cbLayout->setSpacing(0);
m_controlButtons->setLayout(cbLayout);
layout->addWidget(m_controlButtons);
// Main button
m_button = new QToolButton(this);
m_button->setText(m_filter->filterName());
m_button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
m_button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
cbLayout->addWidget(m_button);
if (m_filter->hasSettings())
{
// Main button: toggle settings
m_button->setArrowType(Qt::RightArrow);
m_button->setCheckable(true);
connect(m_button, SIGNAL(toggled(bool)), SLOT(buttonToggled(bool)));
// Apply button needed
m_applyButton = new QToolButton(this);
m_applyButton->setText(tr("Apply"));
QFont fnt = m_applyButton->font();
fnt.setBold(true);
m_applyButton->setFont(fnt);
m_applyButton->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred);
cbLayout->addWidget(m_applyButton);
connect(m_applyButton, SIGNAL(clicked()), SIGNAL(apply()));
m_applyButton->hide();
// Insert settings widget
m_filter->settingsWidget()->setParent(this);
layout->addWidget(m_filter->settingsWidget());
layout->addStrut(m_filter->settingsWidget()->minimumSizeHint().width()); // Fix size hopping
m_filter->settingsWidget()->hide();
}
else
// Main button: apply filter
connect(m_button, SIGNAL(clicked()), SIGNAL(apply()));
}
void FilterWrapper::buttonToggled(bool isPressed)
{
if (isPressed)
{
emit activated();
if (m_filter->hasSettings())
{
m_filter->settingsWidget()->show();
m_button->setArrowType(Qt::DownArrow);
m_applyButton->show();
}
}
else
{
if (m_filter->hasSettings())
{
m_filter->settingsWidget()->hide();
m_button->setArrowType(Qt::RightArrow);
m_applyButton->hide();
}
}
}
void FilterWrapper::collapse()
{
m_button->setChecked(false);
}