-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyListWidget.cpp
More file actions
135 lines (115 loc) · 3.15 KB
/
MyListWidget.cpp
File metadata and controls
135 lines (115 loc) · 3.15 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
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
#include "MyListWidget.h"
#include <QMouseEvent>
#include "ThemeSetting.h"
#include <QListWidgetItem>
#include "Settings.h"
#include "HelperFunc.h"
MyListWidget::MyListWidget(QWidget *parent):
QListWidget(parent)
{
setTheme();
}
void MyListWidget::mousePressEvent(QMouseEvent *me)
{
QListWidget::mousePressEvent(me);
if (me->button() == Qt::RightButton)
{
emit sigMouseRight();
}
else if (me->button() == Qt::LeftButton)
{
emit sigMouseLeft();
}
}
int MyListWidget::number()
{
int num = this->count();
for (int i = 0; i < this->count(); i++)
{
QListWidgetItem* item = this->item(i);
if (item->isHidden())
{
num--;
}
}
return num;
}
void MyListWidget::setTheme(QColor mainColorForImage)
{
QColor childWinColor = GetThemeSetting()->resolvedChildWinColor(mainColorForImage);
QColor scrollbarColor = GetThemeSetting()->resolvedScrollbarColor(mainColorForImage);
QColor selectedColor = GetThemeSetting()->resolvedItemSelectedColor(mainColorForImage);
// 选中项高亮色(柔和偏移)
QColor hoverColor = selectedColor;
hoverColor.setAlpha(128);
QString hoverStyle;
if (GetSettings()->m_disableMouse)
{
hoverStyle = "";
}
else
{
hoverStyle = QString("QListWidget::Item:hover{background: %1;}").arg(selectedColor.name());
}
QString scrollStyle = ThemeSetting::scrollbarStyleSheet(scrollbarColor, childWinColor);
QString styleSheet = QString(
"%1"
"QListWidget{background-color: %2; border: none; outline: none;}"
"QListWidget::Item{background-color: %2; border: none; padding-left: 2px;}"
"QListWidget::Item:selected{background-color: %3; border-left: 3px solid %4;}"
"%5"
).arg(scrollStyle)
.arg(childWinColor.name())
.arg(selectedColor.name())
.arg(GetThemeSetting()->isDarkTheme(mainColorForImage) ? scrollbarColor.lighter(120).name() : scrollbarColor.darker(150).name())
.arg(hoverStyle);
setStyleSheet(styleSheet);
}
ResultItem* MyListWidget::getCurrentItem()
{
QListWidgetItem *curItem = currentItem();
if (!curItem)
{
return NULL;
}
ResultItem* item = (ResultItem*)(itemWidget(curItem));
if (!item)
{
return NULL;
}
return item;
}
ResultItem* MyListWidget::getItem(int index)
{
QListWidgetItem* widgetItem = item(index);
ResultItem* resultItem = (ResultItem*)itemWidget(widgetItem);
return resultItem;
}
void MyListWidget::addItemWidget(ResultItem *item,bool hide)
{
QListWidgetItem* widgetItem = new QListWidgetItem();
widgetItem->setSizeHint(QSize(item->width(),item->height()));
addItem(widgetItem);
setItemWidget(widgetItem,item);
if (hide)
{
widgetItem->setHidden(true);
}
}
void MyListWidget::showItem(int index)
{
QListWidgetItem* widgetItem = item(index);
widgetItem->setHidden(false);
}
void MyListWidget::hideItem(int index)
{
QListWidgetItem* widgetItem = item(index);
widgetItem->setHidden(true);
}
void MyListWidget::hideAll()
{
for (int i = 0; i < count(); i++)
{
hideItem(i);
}
}