Debian Codegraph @

src/djwidget.cpp

raw symbols SCIP
1 /*
2 Copyright (C) 2005-2014 Mario Stephan <[email protected]>
3
4 This library is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include "djwidget.h"
19 #include "ui_djwidget.h"
20
21 #include <QMouseEvent>
22 #include <QSettings>
23 #include <QTimer>
24 #include <qdebug.h>
25
26 struct DjWidgetPrivate {
27 Dj* dj;
28 bool isActive;
29 QTimer* timerSlide;
30 int targetWidth;
31 };
32
33 DjWidget::DjWidget(QWidget* parent)
34 : QWidget(parent)
35 , ui(new Ui::DjWidget)
36 , p(new DjWidgetPrivate)
37 {
38 setFocusPolicy(Qt::ClickFocus);
39 ui->setupUi(this);
40 ui->lblDesciption->setText(QString::null);
41 ui->widgetClose->setMinimumWidth(0);
42 ui->widgetClose->setMaximumWidth(0);
43
44 QFont font = ui->lblDesciption->font();
45 #if defined(Q_OS_DARWIN)
46 int newSize = font.pointSize() - 4;
47 #else
48 int newSize = font.pointSize() - 1;
49 #endif
50 font.setPointSize(newSize);
51 ui->lblDesciption->setFont(font);
52
53 p->timerSlide = new QTimer(this);
54 p->timerSlide->setInterval(10);
55 connect(p->timerSlide, SIGNAL(timeout()), SLOT(timerSlide_timeOut()));
56 }
57
58 DjWidget::~DjWidget()
59 {
60 delete ui;
61 delete p;
62 }
63
64 void DjWidget::changeEvent(QEvent* event)
65 {
66 QWidget::changeEvent(event);
67 switch (event->type()) {
68 case QEvent::LanguageChange:
69 ui->retranslateUi(this);
70 break;
71 default:
72 break;
73 }
74 }
75
76 void DjWidget::mousePressEvent(QMouseEvent* event)
77 {
78
79 if (ui->widgetClose->geometry().contains(event->pos())) {
80 Q_EMIT deleted();
81 } else {
82 slideCloseWidget(false);
83 Q_EMIT activated();
84 }
85 }
86
87 void DjWidget::setDj(Dj* dj)
88 {
89 qDebug() << Q_FUNC_INFO;
90 p->dj = dj;
91
92 connect(p->dj, SIGNAL(countChanged()), this, SLOT(updateView()));
93 deactivateDJ();
94 }
95
96 Dj* DjWidget::dj()
97 {
98 return p->dj;
99 }
100
101 // auto connect slot
102 void DjWidget::on_lblName_linkActivated(const QString& link)
103 {
104 Q_UNUSED(link);
105 Q_EMIT activated();
106 }
107
108 void DjWidget::clicked()
109 {
110 Q_EMIT activated();
111 }
112
113 void DjWidget::activateDJ()
114 {
115 p->isActive = true;
116 updateView();
117 }
118
119 void DjWidget::deactivateDJ()
120 {
121 p->isActive = false;
122 updateView();
123 }
124
125 void DjWidget::updateView()
126 {
127 // Filter description and count update
128
129 // update Labels
130 setToolTip(tr("This Dj plays: ") + p->dj->description());
131 QString strCase = (p->dj->filters().count() > 1) ? tr("cases") : tr("case");
132
133 ui->lblDesciption->setText(QString::number(p->dj->filters().count()) + " " + strCase + " "
134 + QString::number(p->dj->countTracks()) + " " + tr("tracks") + " "
135 + Track::prettyTime(p->dj->lengthTracks(), true) + " " + tr("hours"));
136
137 // active/passive look differentiation
138 QString activeStyle;
139 if (p->isActive) {
140 activeStyle = "color:#ff6464;'>";
141 this->setStyleSheet("#frameDj{ background: qlineargradient("
142 "x1:0, y1:0, x2:0, y2:1,"
143 "stop: 0.01 #202020,"
144 "stop:0.11 #505050,"
145 "stop:1 #505050"
146 ");}");
147 } else {
148 activeStyle = "color:#eeeeee;'>";
149 this->setStyleSheet("#frameDj{ background: qlineargradient("
150 "x1:0, y1:0, x2:0, y2:1,"
151 "stop: 0.01 #202020,"
152 "stop:0.11 #404040,"
153 "stop:1 #404040"
154 ");}");
155 }
156
157 ui->lblName->setText("<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0//EN' 'http://www.w3.org/TR/REC-html40/strict.dtd'>"
158 "<html><head><meta name='qrichtext' content='1' /><style type='text/css'>p, li { white-space: pre-wrap; }"
159 "</style></head><body style='font-size:8.25pt; font-weight:400; font-style:normal;'><p style=' margin-top:0px; "
160 "margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;'>"
161 "<a href='fdadfaf'><span style=' font-size:12pt;font-style:normal;font-weight:bold; text-decoration: underline; "
162 + activeStyle
163 + p->dj->name + "</span></a></p></body></html>");
164 }
165
166 // esc key for exit close
167 void DjWidget::keyPressEvent(QKeyEvent* e)
168 {
169 if (e->key() == Qt::Key_Escape)
170 slideCloseWidget(false);
171 else
172 QWidget::keyPressEvent(e);
173 }
174
175 void DjWidget::on_butPlayWidget_pressed()
176 {
177 Q_EMIT started();
178 }
179
180 void DjWidget::on_pushClose_clicked()
181 {
182 slideCloseWidget((ui->widgetClose->minimumWidth() < 50));
183 }
184
185 void DjWidget::slideCloseWidget(bool open)
186 {
187 p->targetWidth = (open) ? 70 : 0;
188 p->timerSlide->start();
189 }
190
191 void DjWidget::timerSlide_timeOut()
192 {
193 int mWidth = ui->widgetClose->minimumWidth();
194 if (p->targetWidth > mWidth) {
195 ui->widgetClose->setMinimumWidth(mWidth + 5);
196 ui->widgetClose->setMaximumWidth(mWidth + 5);
197 } else if (p->targetWidth < mWidth) {
198 ui->widgetClose->setMinimumWidth(mWidth - 5);
199 ui->widgetClose->setMaximumWidth(mWidth - 5);
200 } else {
201 p->timerSlide->stop();
202 }
203 }