-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistwidget.cpp
164 lines (141 loc) · 2.95 KB
/
listwidget.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Copyright 2022-present Contributors to the jobman project.
// SPDX-License-Identifier: BSD-3-Clause
// https://github.com/mikaelsundell/jobman
#include "listwidget.h"
#include "urlfilter.h"
#include <QCheckBox>
#include <QLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPointer>
#include <QMouseEvent>
class PairItemPrivate : public QObject
{
Q_OBJECT
public:
PairItemPrivate();
void init();
public:
void enabled(bool enabled) {
nameedit->setEnabled(enabled);
valueedit->setEnabled(enabled);
}
QString name;
QString value;
QCheckBox* checkbox;
QLineEdit* nameedit;
QLineEdit* valueedit;
QScopedPointer<Urlfilter> urlfilter;
QPointer<PairItem> item;
};
PairItemPrivate::PairItemPrivate()
{
}
void
PairItemPrivate::init()
{
// ui
checkbox = new QCheckBox(item.data());
checkbox->setChecked(true);
nameedit = new QLineEdit(name, item.data());
valueedit = new QLineEdit(value, item.data());
nameedit->setFixedWidth(100);
QHBoxLayout *layout = new QHBoxLayout(item.data());
layout->addWidget(checkbox);
layout->addWidget(nameedit);
layout->addWidget(valueedit);
layout->setContentsMargins(0, 0, 0, 0);
item->setLayout(layout);
// url filter
urlfilter.reset(new Urlfilter);
valueedit->installEventFilter(urlfilter.data());
// connect
connect(checkbox, &QCheckBox::toggled, this, [this](bool checked) {
this->enabled(checked);
});
}
PairItem::PairItem(QWidget* parent)
: QWidget(parent)
, p(new PairItemPrivate())
{
p->item = this;
p->init();
}
PairItem::PairItem(const QString& name, const QString& value, QWidget* parent)
: QWidget(parent)
, p(new PairItemPrivate())
{
p->name = name;
p->value = value;
p->item = this;
p->init();
}
PairItem::~PairItem()
{
}
QString
PairItem::name() const
{
return p->nameedit->text();
}
QString
PairItem::value() const
{
return p->valueedit->text();
}
bool
PairItem::isChecked() const
{
return p->checkbox->isChecked();
}
void
PairItem::setName(const QString& name)
{
p->nameedit->setText(name);
}
void
PairItem::setValue(const QString& value)
{
p->valueedit->setText(value);
}
void
PairItem::setChecked(bool checked)
{
p->checkbox->setChecked(checked);
}
class ListWidgetPrivate : public QObject
{
Q_OBJECT
public:
ListWidgetPrivate();
void init();
public:
QPointer<ListWidget> widget;
};
ListWidgetPrivate::ListWidgetPrivate()
{
}
void
ListWidgetPrivate::init()
{
}
#include "listwidget.moc"
ListWidget::ListWidget(QWidget* parent)
: QListWidget(parent)
, p(new ListWidgetPrivate())
{
p->widget = this;
p->init();
}
ListWidget::~ListWidget()
{
}
void
ListWidget::mousePressEvent(QMouseEvent *event)
{
QListWidget::mousePressEvent(event);
if (itemAt(event->pos()) == nullptr) {
clearSelection();
emit itemSelectionChanged();
}
}