Debian Codegraph @

src/djfilterwidget.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 "djfilterwidget.h"
19 #include "ui_djfilterwidget.h"
20 #include <qfiledialog.h>
21
22 #include <QMouseEvent>
23 #include <QTimer>
24 #include <qdebug.h>
25
26 struct DjFilterWidgetPrivate {
27 Filter* filter;
28 QTimer* timerSlide;
29 int targetWidth;
30 bool ready;
31 };
32
33 DjFilterWidget::DjFilterWidget(QWidget* parent)
34 : QWidget(parent)
35 , ui(new Ui::DjFilterWidget)
36 , p(new DjFilterWidgetPrivate)
37
38 {
39 setFocusPolicy(Qt::ClickFocus);
40 ui->setupUi(this);
41 ui->ledActive->setLook(QLed::Flat);
42 ui->ledActive->setShape(QLed::Rectangular);
43 ui->ledActive->setColor(QColor(35, 119, 246));
44 ui->ledActive->off();
45 ui->txtPath->setAttribute(Qt::WA_MacShowFocusRect, false);
46 ui->cmbGenres->setAttribute(Qt::WA_MacShowFocusRect, false);
47 ui->cmbArtists->setAttribute(Qt::WA_MacShowFocusRect, false);
48
49 ui->lblFilterValue->setText(QString::null);
50 ui->stackDisplay->setCount(0);
51
52 ui->stackDisplay->setBarColor(QColor(196, 196, 210));
53 ui->widgetClose->setMinimumWidth(0);
54 ui->widgetClose->setMaximumWidth(0);
55
56 timer = new QTimer(this);
57 timer->stop();
58 timer->setInterval(300);
59 timer->setSingleShot(true);
60 connect(timer, SIGNAL(timeout()), this, SLOT(slotSetFilter()));
61
62 p->timerSlide = new QTimer(this);
63 p->timerSlide->setInterval(10);
64 connect(p->timerSlide, SIGNAL(timeout()), SLOT(timerSlide_timeOut()));
65 ui->sliFilterValue->setRange(0, 10);
66 }
67
68 DjFilterWidget::~DjFilterWidget()
69 {
70 delete ui;
71 delete p;
72 }
73
74 void DjFilterWidget::changeEvent(QEvent* e)
75 {
76 QWidget::changeEvent(e);
77 switch (e->type()) {
78 case QEvent::LanguageChange:
79 ui->retranslateUi(this);
80 break;
81 default:
82 break;
83 }
84 }
85
86 void DjFilterWidget::mousePressEvent(QMouseEvent* event)
87 {
88
89 if (ui->widgetClose->geometry().contains(event->pos())) {
90 Q_EMIT deleted();
91 } else {
92 slideCloseWidget(false);
93 }
94 }
95 void DjFilterWidget::slotSetFilter()
96 {
97 qDebug() << Q_FUNC_INFO;
98 timer->stop();
99 p->filter->setPath(ui->txtPath->text());
100 p->filter->setGenre(ui->cmbGenres->currentText());
101 p->filter->setArtist(ui->cmbArtists->currentText());
102 p->filter->update();
103 }
104
105 void DjFilterWidget::setAllArtists(QStringList values)
106 {
107 ui->cmbArtists->addItems(values);
108 }
109
110 void DjFilterWidget::setAllGenres(QStringList& values)
111 {
112 ui->cmbGenres->addItems(values);
113 }
114
115 void DjFilterWidget::setID(QString value)
116 {
117 ui->lblNumber->setText(value);
118 }
119
120 void DjFilterWidget::setFilter(Filter* filter)
121 {
122 qDebug() << Q_FUNC_INFO << "START";
123
124 timer->stop();
125 p->ready = false;
126 p->filter = filter;
127 onFilterCountChanged();
128 onFilterMaxUsageChanged();
129 ui->txtPath->setText(p->filter->path());
130 ui->cmbGenres->setEditText(p->filter->genre());
131 ui->cmbArtists->setEditText(p->filter->artist());
132 connect(p->filter, SIGNAL(statusChanged(bool)),
133 this, SLOT(onFilterStatusChanged(bool)));
134 connect(p->filter, SIGNAL(countChanged()),
135 this, SLOT(onFilterCountChanged()));
136 connect(p->filter, SIGNAL(usageChanged()),
137 this, SLOT(onFilterUsageChanged()));
138 connect(p->filter, SIGNAL(maxUsageChanged()),
139 this, SLOT(onFilterMaxUsageChanged()));
140 p->ready = true;
141 qDebug() << Q_FUNC_INFO << "END";
142 }
143
144 Filter* DjFilterWidget::filter()
145 {
146 return p->filter;
147 }
148
149 void DjFilterWidget::on_sliFilterValue_valueChanged(int value)
150 {
151 ui->lblFilterValue->setText(QString("%1 %2").arg(value).arg(QString(tr("of"))));
152 p->filter->setMaxUsage(ui->sliFilterValue->value());
153 }
154
155 void DjFilterWidget::on_txtPath_textChanged(QString)
156 {
157 if (p->ready) {
158 if (timer->isActive())
159 timer->stop();
160 timer->start();
161 }
162 }
163
164 void DjFilterWidget::on_cmbGenres_editTextChanged(QString)
165 {
166 if (p->ready) {
167 if (timer->isActive())
168 timer->stop();
169 timer->start();
170 }
171 }
172
173 void DjFilterWidget::on_cmbArtists_editTextChanged(QString)
174 {
175 if (p->ready) {
176 if (timer->isActive())
177 timer->stop();
178 timer->start();
179 }
180 }
181
182 void DjFilterWidget::on_pushActivate_clicked()
183 {
184 p->filter->setActive(true);
185 }
186
187 void DjFilterWidget::onFilterStatusChanged(bool b)
188 {
189 if (b)
190 ui->ledActive->on();
191 else {
192 ui->ledActive->off();
193 ui->stackDisplay->setSelected(-1);
194 }
195 }
196
197 void DjFilterWidget::onFilterCountChanged()
198 {
199 ui->lblCount->setText(QString("%1").arg(p->filter->count()));
200 }
201
202 void DjFilterWidget::onFilterMaxUsageChanged()
203 {
204 ui->lblFilterValue->setText(QString("%1 %2").arg(p->filter->maxUsage()).arg(tr("of")));
205 ui->sliFilterValue->setValue(p->filter->maxUsage());
206 ui->stackDisplay->setCount(p->filter->maxUsage());
207 }
208
209 void DjFilterWidget::onFilterUsageChanged()
210 {
211 ui->stackDisplay->setCount(p->filter->maxUsage());
212 ui->stackDisplay->setSelected(p->filter->usage());
213 }
214
215 void DjFilterWidget::on_lbl1_linkActivated(const QString& link)
216 {
217 QFileDialog dialog(this);
218 dialog.setFileMode(QFileDialog::DirectoryOnly);
219 if (dialog.exec())
220 ui->txtPath->setText(dialog.selectedFiles().first());
221 }
222
223 // esc key for exit close
224 void DjFilterWidget::keyPressEvent(QKeyEvent* e)
225 {
226 if (e->key() == Qt::Key_Escape)
227 slideCloseWidget(false);
228 else
229 QWidget::keyPressEvent(e);
230 }
231
232 void DjFilterWidget::on_pushClose_clicked()
233 {
234 slideCloseWidget((ui->widgetClose->minimumWidth() < 50));
235 }
236
237 void DjFilterWidget::slideCloseWidget(bool open)
238 {
239 p->targetWidth = (open) ? 70 : 0;
240 p->timerSlide->start();
241 }
242
243 void DjFilterWidget::timerSlide_timeOut()
244 {
245 int mWidth = ui->widgetClose->minimumWidth();
246 if (p->targetWidth > mWidth) {
247 ui->widgetClose->setMinimumWidth(mWidth + 5);
248 ui->widgetClose->setMaximumWidth(mWidth + 5);
249 } else if (p->targetWidth < mWidth) {
250 ui->widgetClose->setMinimumWidth(mWidth - 5);
251 ui->widgetClose->setMaximumWidth(mWidth - 5);
252 } else {
253 p->timerSlide->stop();
254 }
255 }