-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgltracklist.cpp
More file actions
175 lines (148 loc) · 4.38 KB
/
Copy pathgltracklist.cpp
File metadata and controls
175 lines (148 loc) · 4.38 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
172
173
174
175
#include "gltracklist.h"
GlTrackList::GlTrackList(GlObject* parent) : GlObject(parent)
{
borderColor = QColor(66, 74, 90);
gradientColorAt0 = QColor(40,40,40);
gradientColorAt1 = QColor(96,112,144);
border = 1;
borderRadius = 10;
startPos = 0;
fontColor = QColor(255,255,255,128);
fontSize = 20;
itemHeight = fontSize + 10;
}
void GlTrackList::clear()
{
listItem.clear();
currentItem = 0;
newChildToDraw(this);
}
void GlTrackList::draw(QPainter* p)
{
p->fillRect(geometry(), Qt::black);
QLinearGradient gradient( getWidth()/2, getY(),
getWidth()/2, getY() + getHeight());
gradient.setColorAt(0, gradientColorAt0);
gradient.setColorAt(1, gradientColorAt1);
p->setBrush(QBrush(gradient));
QPainterPath pa;
QRect rect = geometry();
pa.addRoundedRect(rect, borderRadius, borderRadius);
pen.setWidth(border); //Strichbreite
pen.setColor(borderColor); //Strichfarbe
p->setPen(pen);
p->drawPath(pa);
for(int i = 0; i < 14; i++)
{
if(i + startPos < listItem.size())
{
QRect re(10, getY() + i * itemHeight,
getWidth()/2 - 20, itemHeight);
drawTextLeft(p, re, listItem.at(i+startPos)->title());
re = QRect(getWidth()/2 + 10, getY() + i * itemHeight,
getWidth()/2 -20, itemHeight);
drawTextRight(p, re, listItem.at(i+startPos)->interpret());
if( (i + startPos) == currentItem)
{
p->fillRect(QRect(10, getY() + 2 + itemHeight * i, getWidth() - 20 , itemHeight - 4), QColor(0,0,0,125));
}
}
}
}
void GlTrackList::drawTextLeft(QPainter *p, QRect rect, QString text)
{
/*Text in die Liste schreiben
- Font von QPainter holen und mit eigenen Werten überschreiben
- Den Stift von QPainter mit der Schriftfarbe setzten
- Text in ein Rechteck schreiben*/
QFont font = p->font();
font.setPixelSize(fontSize);
font.setBold(true);
p->setFont(font);
p->setPen(fontColor);
p->drawText(rect,Qt::AlignLeft | Qt::AlignVCenter,text);
}
void GlTrackList::drawTextRight(QPainter *p, QRect rect, QString text)
{
/*Text in die Liste schreiben
- Font von QPainter holen und mit eigenen Werten überschreiben
- Den Stift von QPainter mit der Schriftfarbe setzten
- Text in ein Rechteck schreiben*/
QFont font = p->font();
font.setPixelSize(fontSize);
font.setBold(true);
p->setFont(font);
p->setPen(fontColor);
p->drawText(rect,Qt::AlignRight | Qt::AlignVCenter,text);
}
MetaPaket GlTrackList::nextItem()
{
MetaPaket mp;
mp.isEmpty = true;
if(currentItem + 1 < listItem.size())
{
currentItem++;
mp = listItem.at(currentItem)->getMetaPaket();
}
return mp;
}
void GlTrackList::mouseReleaseEvent(QMouseEvent *event)
{
/*Wurde die Maus innerhalb des eigenen Rechtecks gedrückt wird in
der Liste nach einem Button oder Listeneintrag gesucht und seine
Funktion mouseReleaseEvent aufgerufen*/
QRect rect = geometry();
if(rect.contains(event->pos()))
{
//qDebug() << QString("%1").arg((event->pos().y() - listY) / itemHeight);
int i = ((event->pos().y() - getY()) / itemHeight) + startPos;
if(i < listItem.size())
{
itemClicked(listItem.at(i)->getMetaPaket());
currentItem = i;
newChildToDraw(this);
}
}
}
void GlTrackList::newTracks(QList<MetaPaket>list)
{
MetaPaket mp;
GlTrackListItem* item;
foreach(mp, list)
{
item = new GlTrackListItem(this);
item->setMetaPaket(mp);
listItem.append(item);
}
}
void GlTrackList::newTrack(MetaPaket mp)
{
GlTrackListItem* item = new GlTrackListItem(this);
item->setMetaPaket(mp);
listItem.append(item);
}
MetaPaket GlTrackList::prevItem()
{
MetaPaket mp;
mp.isEmpty = true;
if(currentItem - 1 < listItem.size() && currentItem > 0)
{
currentItem--;
mp = listItem.at(currentItem)->getMetaPaket();
}
return mp;
}
int GlTrackList::indexOf(MetaPaket mp)
{
MetaPaket tmp;
for( int i = 0; i < listItem.size(); i++)
{
tmp = listItem.at(i)->getMetaPaket();
if(tmp.url == mp.url)
return i;
}
return -1;
}
GlTrackListItem::GlTrackListItem(GlObject *parent) : GlObject(parent)
{
}