-
Notifications
You must be signed in to change notification settings - Fork 2
/
macroiconsgraphicsview.cpp
111 lines (83 loc) · 3.42 KB
/
macroiconsgraphicsview.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
#include "macroiconsgraphicsview.h"
#include <QDebug>
#include <QMouseEvent>
#include <QXmlStreamReader>
#include <QGraphicsRectItem>
#include "macroitemrect.h"
MacroIconsGraphicsView::MacroIconsGraphicsView(QWidget *parent) :
QGraphicsView(parent), currentSelectedIcon(NULL) {
}
void MacroIconsGraphicsView::mousePressEvent(QMouseEvent *event) {
QGraphicsView::mousePressEvent(event);
}
void MacroIconsGraphicsView::iconClicked(MacroItemRect* name) {
if (currentSelectedIcon == name)
return;
if (currentSelectedIcon != NULL) {
currentSelectedIcon->unselectIcon();
currentSelectedIcon = NULL;
}
currentSelectedIcon = name;
}
void MacroIconsGraphicsView::setCurrentIcon(const QString& name) {
MacroItemRect* icon = icons.value(name, NULL);
if (icon != NULL) {
icon->selectIcon();
}
}
void MacroIconsGraphicsView::parseIconMetadata() {
QFile file(":/files/icons.xml");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
/*QMessageBox::critical(this,
"QXSRExample::parseXML",
"Couldn't open example.xml",
QMessageBox::Ok);*/
qDebug() << "could not open icons.xml";
return;
}
QXmlStreamReader xml(&file);
while(!xml.atEnd() &&
!xml.hasError()) {
QXmlStreamReader::TokenType token = xml.readNext();
if(token == QXmlStreamReader::StartDocument) {
continue;
}
if(token == QXmlStreamReader::StartElement) {
//qDebug() << xml.name() << " data " << xml.attributes().size();
if (xml.name() != "ImageStyle") {
continue;
}
QXmlStreamAttributes attributes = xml.attributes();
QString source = attributes.value("Source").toString();
if (source != "ui_rebel_icons")
continue;
QString sourceRect = attributes.value("SourceRect").toString();
QString name = attributes.value("Name").toString();
if (sourceRect.isEmpty())
continue;
QStringList rectValues = sourceRect.split(",");
if (rectValues.size() < 4)
continue;
// int x = rectValues.at(0).toInt();
// int y = rectValues.at(1).toInt();
// int hash = ((x << 16) & 0xFFFF0000) | y;
MacroItemRect* rectangle = new MacroItemRect(name, rectValues.at(0).toInt(),
rectValues.at(1).toInt(),
rectValues.at(2).toInt() - rectValues.at(0).toInt(),
rectValues.at(3).toInt() - rectValues.at(1).toInt());
connect(rectangle, SIGNAL(iconClicked(MacroItemRect*)), this, SLOT(iconClicked(MacroItemRect*)));
icons.insert(name, rectangle);
//rectangle->set
QPen pen = rectangle->pen();
pen.setWidth(2);
pen.setStyle(Qt::NoPen);
pen.setColor(Qt::white);
rectangle->setPen(pen);
this->scene()->addItem(rectangle);
// }
}
}
if (xml.hasError()) {
qDebug() << "xml error:" << xml.errorString();
}
}