Debian Codegraph @

src/playlistwidget.cpp

raw symbols SCIP
1 #include "playlistwidget.h"
2 #include "ui_playlistwidget.h"
3
4 #include <QMouseEvent>
5 #include <QTimer>
6 #include <qdebug.h>
7
8 class PlaylistWidgetPrivate {
9 public:
10 QString name;
11 QString description;
12 bool isActive;
13 QTimer* timerSlide;
14 int targetWidth;
15 bool isRemovable;
16 };
17
18 PlaylistWidget::PlaylistWidget(QWidget* parent)
19 : QWidget(parent)
20 , ui(new Ui::PlaylistWidget)
21 {
22 ui->setupUi(this);
23 ui->lblDesciption->setText(QString::null);
24 ui->widgetClose->setMinimumWidth(0);
25 ui->widgetClose->setMaximumWidth(0);
26
27 setFocusPolicy(Qt::ClickFocus);
28
29 p = new PlaylistWidgetPrivate;
30 p->isActive = false;
31 p->isRemovable = true;
32
33 QFont font = ui->lblDesciption->font();
34 #if defined(Q_OS_DARWIN)
35 int newSize = font.pointSize() - 4;
36 #else
37 int newSize = font.pointSize() - 1;
38 #endif
39 font.setPointSize(newSize);
40 ui->lblDesciption->setFont(font);
41
42 p->timerSlide = new QTimer(this);
43 p->timerSlide->setInterval(10);
44 connect(p->timerSlide, SIGNAL(timeout()), SLOT(timerSlide_timeOut()));
45 }
46
47 PlaylistWidget::~PlaylistWidget()
48 {
49 delete ui;
50 delete p;
51 }
52
53 // auto connect slot
54 void PlaylistWidget::on_lblName_linkActivated(const QString& link)
55 {
56 Q_UNUSED(link);
57 Q_EMIT activated();
58 }
59
60 bool PlaylistWidget::isRemovable()
61 {
62 return p->isRemovable;
63 }
64
65 void PlaylistWidget::setRemovable(bool value)
66 {
67 p->isRemovable = value;
68 ui->pushClose->setVisible(value);
69 // if (!value)
70 // r ui->horizontalSpacer->changeSize(42,0);
71 }
72
73 QString
74 PlaylistWidget::name()
75 {
76 return p->name;
77 }
78
79 void PlaylistWidget::setName(QString value)
80 {
81 p->name = value;
82 updateView();
83 }
84
85 QString
86 PlaylistWidget::description()
87 {
88 return p->description;
89 }
90
91 void PlaylistWidget::setDescription(QString value)
92 {
93 p->description = value;
94 updateView();
95 }
96
97 void PlaylistWidget::activate()
98 {
99 p->isActive = true;
100 updateView();
101 }
102
103 void PlaylistWidget::deactivate()
104 {
105 p->isActive = false;
106 updateView();
107 }
108
109 void PlaylistWidget::mousePressEvent(QMouseEvent* event)
110 {
111 if (ui->widgetClose->geometry().contains(event->pos())) {
112 Q_EMIT deleted();
113 } else {
114 slideCloseWidget(false);
115 Q_EMIT activated();
116 }
117 }
118
119 void PlaylistWidget::updateView()
120 {
121 // update Labels
122 ui->lblDesciption->setText(p->description);
123
124 // active/passive look differentiation
125 QString activeStyle;
126 if (p->isActive) {
127 activeStyle = "color:#ff6464;'>";
128 ui->framePlaylistWidget->setStyleSheet(
129 "#framePlaylistWidget { background: qlineargradient("
130 "x1:0, y1:0, x2:0, y2:1,"
131 "stop: 0.01 #202020,"
132 "stop:0.11 #505050,"
133 "stop:1 #505050"
134 ");}");
135 } else {
136 activeStyle = "color:#eeeeee;'>";
137 ui->framePlaylistWidget->setStyleSheet(
138 "#framePlaylistWidget { background: qlineargradient("
139 "x1:0, y1:0, x2:0, y2:1,"
140 "stop: 0.01 #202020,"
141 "stop:0.11 #404040,"
142 "stop:1 #404040"
143 ");}");
144 }
145
146 ui->lblName->setText(
147 "<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN' "
148 "'http://www.w3.org/TR/REC-html40/strict.dtd'>"
149 "<html><head><meta name='qrichtext' content='1' /><style "
150 "type='text/css'>p, li { white-space: pre-wrap; }"
151 "</style></head><body style='font-size:8.25pt; font-weight:400; "
152 "font-style:normal;'><p style=' margin-top:0px; "
153 "margin-bottom:0px; margin-left:0px; margin-right:0px; "
154 "-qt-block-indent:0; text-indent:0px;'>"
155 "<a href='fdadfaf'><span style=' "
156 "font-size:12pt;font-style:normal;font-weight:bold; text-decoration: "
157 "underline; "
158 + activeStyle + p->name + "</span></a></p></body></html>");
159 }
160
161 void PlaylistWidget::on_butPlayWidget_pressed()
162 {
163 Q_EMIT started();
164 }
165
166 // esc key for exit close
167 void PlaylistWidget::keyPressEvent(QKeyEvent* e)
168 {
169 if (e->key() == Qt::Key_Escape)
170 slideCloseWidget(false);
171 else
172 QWidget::keyPressEvent(e);
173 }
174
175 void PlaylistWidget::on_pushClose_clicked()
176 {
177 slideCloseWidget((ui->widgetClose->minimumWidth() < 50));
178 }
179
180 void PlaylistWidget::slideCloseWidget(bool open)
181 {
182 p->targetWidth = (open) ? 70 : 0;
183 p->timerSlide->start();
184 }
185
186 void PlaylistWidget::timerSlide_timeOut()
187 {
188 int mWidth = ui->widgetClose->minimumWidth();
189 if (p->targetWidth > mWidth) {
190 ui->widgetClose->setMinimumWidth(mWidth + 5);
191 ui->widgetClose->setMaximumWidth(mWidth + 5);
192 } else if (p->targetWidth < mWidth) {
193 ui->widgetClose->setMinimumWidth(mWidth - 5);
194 ui->widgetClose->setMaximumWidth(mWidth - 5);
195 } else {
196 p->timerSlide->stop();
197 }
198 }