-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglradiolist.cpp
More file actions
127 lines (105 loc) · 3.48 KB
/
Copy pathglradiolist.cpp
File metadata and controls
127 lines (105 loc) · 3.48 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
#include "glradiolist.h"
GlRadioList::GlRadioList(GlObject* parent) : GlObject(parent)
{
setGeometry(2,90,796,438);
setBackGroundPixmap(QPixmap(":/images/backgroundRadio.png"));
borderColor = QColor(66, 74, 90);
gradientColorAt0 = QColor(40,40,40);
gradientColorAt1 = QColor(96,112,144);
border = 1;
borderRadius = 10;
fontColor = QColor(255,255,255,128);
fontSize = 30;
itemHeight = fontSize + 10;
currentItem = -1;
GlRadioListItem* item = new GlRadioListItem(this);
item->setText("Radio Unartig");
item->setUrl("http://www.unart.tv:8000");
connect(item, SIGNAL(clicked(QString)), this, SIGNAL(radioItemClicked(QString)));
connect(item, SIGNAL(clicked(GlRadioListItem*)), this, SLOT(itemClicked(GlRadioListItem*)));
list.append(item);
item = new GlRadioListItem(this);
item->setText("SWR 3");
item->setUrl("http://swr.ic.llnwd.net/stream/swr_mp3_m_swr3a");
connect(item, SIGNAL(clicked(QString)), this, SIGNAL(radioItemClicked(QString)));
connect(item, SIGNAL(clicked(GlRadioListItem*)), this, SLOT(itemClicked(GlRadioListItem*)));
list.append(item);
}
void GlRadioList::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);
drawBackGroundPixmap(p);
QFont font = p->font();
font.setPixelSize(fontSize);
font.setBold(true);
p->setFont(font);
p->setPen(fontColor);
int pos = (list.size() * itemHeight) / 2;
pos = getHeight()/2 - pos/2;
for(int i = 0; i < 14; i++)
{
if(i < list.size())
{
QRect re(10, getY() + pos + i * itemHeight,
getWidth()- 20, itemHeight);
list.at(i)->setGeometry(re.x(),re.y(), re.width(), re.height());
p->drawText(re, Qt::AlignHCenter, list.at(i)->getText());
if( list.at(i) == cItem)
{
p->fillRect(re, QColor(0,0,0,125));
}
}
}
}
void GlRadioList::itemClicked(GlRadioListItem* item)
{
cItem = item;
newChildToDraw(this);
}
void GlRadioList::mouseReleaseEvent(QMouseEvent *event)
{
QRect rect;
for(int i = 0; i < listChilds.size(); i++)
{
rect = listChilds.at(i)->geometry();
if(listChilds.at(i)->isVisible() && rect.contains(event->pos()))
{
listChilds.at(i)->mouseReleaseEvent(event);
}
}
}
void GlRadioList::setLarge()
{
fontSize = (int)(fontSize * 1.28);
itemHeight = fontSize + 10;
int newX, newY, newHeight, newWidth;
QPoint c;
newHeight = (int)(getHeight() * 1.28);
newWidth = (int)(getWidth() * 1.28);
c = getCenter();
newX = (int)(c.x() * 1.28) - (int)(newWidth / 2);
newY = (int)(c.y() * 1.28) - (int)(newHeight / 2);
setGeometry(newX, newY, newWidth, newHeight);
backGroundPixmap = backGroundPixmap.scaled(newWidth,newHeight);
}
GlRadioListItem::GlRadioListItem(GlObject *parent) : GlObject(parent)
{
}
void GlRadioListItem::mouseReleaseEvent(QMouseEvent *event)
{
Q_UNUSED(event);
clicked(url);
clicked(this);
}