-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patheditorui.cpp
More file actions
171 lines (135 loc) · 4.58 KB
/
Copy patheditorui.cpp
File metadata and controls
171 lines (135 loc) · 4.58 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
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
165
166
167
168
169
170
171
#include "editorui.h"
#include "redohandler.h"
#include "themeeditor.h"
EditorUI::EditorUI(QWidget *parent)
{
transPix.load(":/pics/resources/pics/transparent.png");
searchBar = new QLineEdit(this);
searchBar->setHidden(true);
searchBar->setStyleSheet("color: #adadad;"
"border-color: #3f3f3f;"
"selection-color: #535353;"
"border-radius:10px;"
"background-color:#202022");
searchBar->setPlaceholderText("Search...");
searchBar->setFixedHeight(40);
dataList = new QListView(this);
dataList->setHidden(true);
dataList->setStyleSheet("background-color:#2a2a2a;"
"color: #c0c0c3; "
"font-size:15px; color:#c0c0c3;"
"border-radius:20px;");
dataList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
dataList->setModel(itemModel = new QStandardItemModel);
dataList->setEditTriggers(QAbstractItemView::NoEditTriggers);
vLayout = new QVBoxLayout(this);
vLayout->addWidget(searchBar);
vLayout->addWidget(dataList);
// 初始化控件
//searchBar->installEventFilter(this); // 设置eventFilter
// 信号与槽
connect(searchBar,&QLineEdit::textChanged,
this,&EditorUI::TextChanged);
connect(dataList,&QListView::doubleClicked,
this,&EditorUI::ItemDoubleClicked);
}
void EditorUI::ThemeDataChanged(ThemeData* td)
{
themeData = td;
itemModel->clear();
if(!td)
{
searchBar->setHidden(true);
dataList->setHidden(true);
return;
}
searchBar->setHidden(false);
dataList->setHidden(false);
for(uint i=0,s = themeData->size();i<s;++i)
{
auto& tag = themeData->at(i);
if(tag.type!=ThemeData::rgb && tag.type != ThemeData::rgba)
{
continue;
}
auto item = new QStandardItem;
//设置子项相关信息
item->setSizeHint(QSize(0, 48));
item->setText(tag.name);
uint c = tag.i;
if(tag.type==ThemeData::rgba)c = (c>>8)|((c&0xff)<<24);
else c|=0xff000000;
if((c&0xff)+((c>>8)&0xff)+((c>>16)&0xff)>300)item->setForeground(Qt::black);
else item->setForeground(Qt::white);
SetItemColor(item,c);
item->setData(i);
itemModel->appendRow(item);
}
}
void EditorUI::TextChanged(const QString &text)
{
auto match = itemModel->findItems(text, Qt::MatchContains);
for(uint i=0,s=itemModel->rowCount();i<s;++i)
{
auto it = itemModel->item(i);
it->setFlags(it->flags() & ~Qt::ItemIsEnabled);
// 实现搜索隐藏不相关条目的功能
if(!match.contains(it))
it->setSizeHint(QSize(0, 0)); // 曲线救国:将w和h直接设置为0
else
it->setSizeHint(QSize(0, 48));
}
for(auto& item:match)
{
item->setFlags(item->flags() | Qt::ItemIsEnabled);
}
}
void EditorUI::ItemDoubleClicked(const QModelIndex &modelIndex)
{
QStandardItem *item = itemModel->itemFromIndex(modelIndex);
uint index = item->data().toUInt();
auto& tag = themeData->at(index);
uint c = tag.i;
QColorDialog colorDiag(this);
colorDiag.setStyleSheet("color:#c0c0c3;");
colorDiag.setWindowTitle(tag.name);
if(tag.type==ThemeData::rgba)
{
colorDiag.setOption(QColorDialog::ShowAlphaChannel);
colorDiag.setCurrentColor(QColor((c>>24)&0xff,(c>>16)&0xff,(c>>8)&0xff,c&0xff));
colorDiag.exec();
if (colorDiag.result() == QDialog::Accepted) {
if (editor != nullptr) {
editor->getRedoHandler()->pushFileSnapshot(themeData);
}
uint c = colorDiag.currentColor().rgba();
themeData->Modify(index, c = (c>>8)|((c&0xff)<<24));
SetItemColor(item,c);
}
}
else
{
colorDiag.setCurrentColor(c);
colorDiag.exec();
if (colorDiag.result() == QDialog::Accepted) {
if (editor != nullptr) {
editor->getRedoHandler()->pushFileSnapshot(themeData);
}
uint c = colorDiag.currentColor().rgb();
themeData->Modify(index, c);
SetItemColor(item,c);
}
}
}
void EditorUI::SetItemColor(QStandardItem* item, uint c)
{
QPixmap tmp = transPix;
QPainter pt(&tmp);
pt.setOpacity(1.0*(c>>24)/0xff);
pt.fillRect(tmp.rect(),c);
pt.end();
item->setBackground(QBrush(tmp));
}
void EditorUI::setThemeEditor(ThemeEditor* _editor) {
editor = _editor;
}