forked from vnotex/vnote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalltagspanel.cpp
More file actions
72 lines (56 loc) · 1.54 KB
/
valltagspanel.cpp
File metadata and controls
72 lines (56 loc) · 1.54 KB
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
#include "valltagspanel.h"
#include <QtWidgets>
#include "vtaglabel.h"
#include "utils/vimnavigationforwidget.h"
VAllTagsPanel::VAllTagsPanel(QWidget *p_parent)
: QWidget(p_parent)
{
m_list = new QListWidget(this);
QVBoxLayout *layout = new QVBoxLayout();
layout->addWidget(m_list);
setLayout(layout);
}
void VAllTagsPanel::clear()
{
while (m_list->count() > 0) {
removeItem(m_list->item(0));
}
}
void VAllTagsPanel::removeItem(QListWidgetItem *p_item)
{
QWidget *wid = m_list->itemWidget(p_item);
m_list->removeItemWidget(p_item);
wid->deleteLater();
int row = m_list->row(p_item);
Q_ASSERT(row >= 0);
m_list->takeItem(row);
delete p_item;
}
VTagLabel *VAllTagsPanel::addTag(const QString &p_text)
{
VTagLabel *label = new VTagLabel(p_text, true, this);
QSize sz = label->sizeHint();
sz.setHeight(sz.height() * 2 + 10);
QListWidgetItem *item = new QListWidgetItem();
item->setSizeHint(sz);
connect(label, &VTagLabel::removalRequested,
this, [this, item](const QString &p_text) {
removeItem(item);
emit tagRemoved(p_text);
});
m_list->addItem(item);
m_list->setItemWidget(item, label);
return label;
}
void VAllTagsPanel::showEvent(QShowEvent *p_event)
{
QWidget::showEvent(p_event);
m_list->setFocus();
}
void VAllTagsPanel::keyPressEvent(QKeyEvent *p_event)
{
if (VimNavigationForWidget::injectKeyPressEventForVim(m_list, p_event)) {
return;
}
QWidget::keyPressEvent(p_event);
}