Changeset View
Changeset View
Standalone View
Standalone View
src/manageheaderbar.cpp
Show All 13 Lines | |||||
14 | * You should have received a copy of the GNU Lesser General Public License | 14 | * You should have received a copy of the GNU Lesser General Public License | ||
15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | 15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
16 | */ | 16 | */ | ||
17 | 17 | | |||
18 | #include "manageheaderbar.h" | 18 | #include "manageheaderbar.h" | ||
19 | 19 | | |||
20 | #include <QTime> | 20 | #include <QTime> | ||
21 | #include <QTimer> | 21 | #include <QTimer> | ||
22 | #include <QDebug> | | |||
23 | | ||||
24 | #include <cstdlib> | | |||
25 | 22 | | |||
26 | ManageHeaderBar::ManageHeaderBar(QObject *parent) | 23 | ManageHeaderBar::ManageHeaderBar(QObject *parent) | ||
27 | : QObject(parent) | 24 | : QObject(parent) | ||
28 | { | 25 | { | ||
29 | } | 26 | } | ||
30 | 27 | | |||
31 | void ManageHeaderBar::setArtistRole(int value) | 28 | void ManageHeaderBar::setArtistRole(int value) | ||
32 | { | 29 | { | ||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Line(s) | |||||
201 | { | 198 | { | ||
202 | if (!mCurrentTrack.isValid()) { | 199 | if (!mCurrentTrack.isValid()) { | ||
203 | return false; | 200 | return false; | ||
204 | } | 201 | } | ||
205 | 202 | | |||
206 | return mCurrentTrack.data(mIsValidRole).toBool(); | 203 | return mCurrentTrack.data(mIsValidRole).toBool(); | ||
207 | } | 204 | } | ||
208 | 205 | | |||
209 | int ManageHeaderBar::remainingTracks() const | | |||
210 | { | | |||
211 | if (!mCurrentTrack.isValid()) { | | |||
212 | return 0; | | |||
213 | } | | |||
214 | | ||||
215 | return mPlayListModel->rowCount(mCurrentTrack.parent()) - mCurrentTrack.row() - 1; | | |||
216 | } | | |||
217 | | ||||
218 | int ManageHeaderBar::isValidRole() const | 206 | int ManageHeaderBar::isValidRole() const | ||
219 | { | 207 | { | ||
220 | return mIsValidRole; | 208 | return mIsValidRole; | ||
221 | } | 209 | } | ||
222 | 210 | | |||
223 | QPersistentModelIndex ManageHeaderBar::currentTrack() const | 211 | QPersistentModelIndex ManageHeaderBar::currentTrack() const | ||
224 | { | 212 | { | ||
225 | return mCurrentTrack; | 213 | return mCurrentTrack; | ||
226 | } | 214 | } | ||
227 | 215 | | |||
228 | void ManageHeaderBar::playListLayoutChanged(const QList<QPersistentModelIndex> &parents, QAbstractItemModel::LayoutChangeHint hint) | | |||
229 | { | | |||
230 | Q_UNUSED(parents); | | |||
231 | Q_UNUSED(hint); | | |||
232 | | ||||
233 | qDebug() << "ManageHeaderBar::playListLayoutChanged" << "not implemented"; | | |||
234 | } | | |||
235 | | ||||
236 | void ManageHeaderBar::tracksInserted(const QModelIndex &parent, int first, int last) | | |||
237 | { | | |||
238 | Q_UNUSED(parent); | | |||
239 | Q_UNUSED(first); | | |||
240 | Q_UNUSED(last); | | |||
241 | | ||||
242 | if (!mCurrentTrack.isValid()) { | | |||
243 | return; | | |||
244 | } | | |||
245 | | ||||
246 | if (mCurrentTrack.row() >= first) { | | |||
247 | return; | | |||
248 | } | | |||
249 | | ||||
250 | Q_EMIT remainingTracksChanged(); | | |||
251 | mOldRemainingTracks = remainingTracks(); | | |||
252 | } | | |||
253 | | ||||
254 | void ManageHeaderBar::tracksDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles) | | |||
255 | { | | |||
256 | if (!mCurrentTrack.isValid()) { | | |||
257 | return; | | |||
258 | } | | |||
259 | | ||||
260 | if (mCurrentTrack.row() > bottomRight.row() || mCurrentTrack.row() < topLeft.row()) { | | |||
261 | return; | | |||
262 | } | | |||
263 | | ||||
264 | if (mCurrentTrack.column() > bottomRight.column() || mCurrentTrack.column() < topLeft.column()) { | | |||
265 | return; | | |||
266 | } | | |||
267 | | ||||
268 | if (roles.isEmpty()) { | | |||
269 | notifyArtistProperty(); | | |||
270 | notifyTitleProperty(); | | |||
271 | notifyAlbumProperty(); | | |||
272 | notifyAlbumArtistProperty(); | | |||
273 | notifyFileNameProperty(); | | |||
274 | notifyImageProperty(); | | |||
275 | notifyDatabaseIdProperty(); | | |||
276 | notifyAlbumIdProperty(); | | |||
277 | notifyIsValidProperty(); | | |||
278 | } else { | | |||
279 | for(auto oneRole : roles) { | | |||
280 | if (oneRole == mArtistRole) { | | |||
281 | notifyArtistProperty(); | | |||
282 | } | | |||
283 | if (oneRole == mTitleRole) { | | |||
284 | notifyTitleProperty(); | | |||
285 | } | | |||
286 | if (oneRole == mAlbumRole) { | | |||
287 | notifyAlbumProperty(); | | |||
288 | } | | |||
289 | if (oneRole == mAlbumArtistRole) { | | |||
290 | notifyAlbumArtistProperty(); | | |||
291 | } | | |||
292 | if (oneRole == mFileNameRole) { | | |||
293 | notifyFileNameProperty(); | | |||
294 | } | | |||
295 | if (oneRole == mImageRole) { | | |||
296 | notifyImageProperty(); | | |||
297 | } | | |||
298 | if (oneRole == mDatabaseIdRole) { | | |||
299 | notifyDatabaseIdProperty(); | | |||
300 | } | | |||
301 | if (oneRole == mAlbumIdRole) { | | |||
302 | notifyAlbumIdProperty(); | | |||
303 | } | | |||
304 | if (oneRole == mIsValidRole) { | | |||
305 | notifyIsValidProperty(); | | |||
306 | } | | |||
307 | } | | |||
308 | } | | |||
309 | } | | |||
310 | | ||||
311 | void ManageHeaderBar::tracksAboutToBeMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row) | | |||
312 | { | | |||
313 | Q_UNUSED(parent); | | |||
314 | Q_UNUSED(start); | | |||
315 | Q_UNUSED(end); | | |||
316 | Q_UNUSED(destination); | | |||
317 | Q_UNUSED(row); | | |||
318 | | ||||
319 | mOldRemainingTracks = remainingTracks(); | | |||
320 | } | | |||
321 | | ||||
322 | void ManageHeaderBar::tracksMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row) | | |||
323 | { | | |||
324 | Q_UNUSED(parent); | | |||
325 | Q_UNUSED(start); | | |||
326 | Q_UNUSED(end); | | |||
327 | Q_UNUSED(destination); | | |||
328 | Q_UNUSED(row); | | |||
329 | | ||||
330 | auto newRemainingTracks = remainingTracks(); | | |||
331 | if (mOldRemainingTracks != newRemainingTracks) { | | |||
332 | Q_EMIT remainingTracksChanged(); | | |||
333 | } | | |||
334 | } | | |||
335 | | ||||
336 | void ManageHeaderBar::tracksRemoved(const QModelIndex &parent, int first, int last) | | |||
337 | { | | |||
338 | Q_UNUSED(parent); | | |||
339 | Q_UNUSED(first); | | |||
340 | Q_UNUSED(last); | | |||
341 | | ||||
342 | if (!mCurrentTrack.isValid()) { | | |||
343 | notifyArtistProperty(); | | |||
344 | notifyTitleProperty(); | | |||
345 | notifyAlbumProperty(); | | |||
346 | notifyAlbumArtistProperty(); | | |||
347 | notifyFileNameProperty(); | | |||
348 | notifyImageProperty(); | | |||
349 | notifyDatabaseIdProperty(); | | |||
350 | notifyAlbumIdProperty(); | | |||
351 | notifyIsValidProperty(); | | |||
352 | notifyRemainingTracksProperty(); | | |||
353 | | ||||
354 | return; | | |||
355 | } | | |||
356 | | ||||
357 | notifyRemainingTracksProperty(); | | |||
358 | } | | |||
359 | | ||||
360 | void ManageHeaderBar::notifyArtistProperty() | 216 | void ManageHeaderBar::notifyArtistProperty() | ||
361 | { | 217 | { | ||
362 | auto newArtistValue = mCurrentTrack.data(mArtistRole); | 218 | auto newArtistValue = mCurrentTrack.data(mArtistRole); | ||
363 | if (mOldArtist != newArtistValue) { | 219 | if (mOldArtist != newArtistValue) { | ||
364 | Q_EMIT artistChanged(); | 220 | Q_EMIT artistChanged(); | ||
365 | 221 | | |||
mgallien: Unrelated change | |||||
366 | mOldArtist = newArtistValue; | 222 | mOldArtist = newArtistValue; | ||
367 | } | 223 | } | ||
368 | } | 224 | } | ||
369 | 225 | | |||
370 | void ManageHeaderBar::notifyTitleProperty() | 226 | void ManageHeaderBar::notifyTitleProperty() | ||
371 | { | 227 | { | ||
372 | auto newTitleValue = mCurrentTrack.data(mTitleRole); | 228 | auto newTitleValue = mCurrentTrack.data(mTitleRole); | ||
373 | if (mOldTitle != newTitleValue) { | 229 | if (mOldTitle != newTitleValue) { | ||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Line(s) | 307 | { | |||
452 | auto newIsValidValue = mCurrentTrack.data(mIsValidRole).toBool(); | 308 | auto newIsValidValue = mCurrentTrack.data(mIsValidRole).toBool(); | ||
453 | if (mOldIsValid != newIsValidValue) { | 309 | if (mOldIsValid != newIsValidValue) { | ||
454 | Q_EMIT isValidChanged(); | 310 | Q_EMIT isValidChanged(); | ||
455 | 311 | | |||
456 | mOldIsValid = newIsValidValue; | 312 | mOldIsValid = newIsValidValue; | ||
457 | } | 313 | } | ||
458 | } | 314 | } | ||
459 | 315 | | |||
460 | void ManageHeaderBar::notifyRemainingTracksProperty() | | |||
461 | { | | |||
462 | auto newRemainingTracksValue = remainingTracks(); | | |||
463 | if (mOldRemainingTracks != newRemainingTracksValue) { | | |||
464 | Q_EMIT remainingTracksChanged(); | | |||
465 | | ||||
466 | mOldRemainingTracks = newRemainingTracksValue; | | |||
467 | } | | |||
468 | } | | |||
469 | | ||||
470 | void ManageHeaderBar::setIsValidRole(int isValidRole) | 316 | void ManageHeaderBar::setIsValidRole(int isValidRole) | ||
471 | { | 317 | { | ||
472 | mIsValidRole = isValidRole; | 318 | mIsValidRole = isValidRole; | ||
473 | emit isValidRoleChanged(); | 319 | emit isValidRoleChanged(); | ||
474 | } | 320 | } | ||
475 | 321 | | |||
476 | void ManageHeaderBar::setCurrentTrack(const QPersistentModelIndex ¤tTrack) | 322 | void ManageHeaderBar::setCurrentTrack(const QPersistentModelIndex ¤tTrack) | ||
477 | { | 323 | { | ||
478 | if (mCurrentTrack == currentTrack) { | | |||
479 | return; | | |||
480 | } | | |||
481 | | ||||
482 | auto oldRemainingTracksCount = remainingTracks(); | | |||
483 | | ||||
484 | mCurrentTrack = currentTrack; | 324 | mCurrentTrack = currentTrack; | ||
485 | Q_EMIT currentTrackChanged(); | 325 | Q_EMIT currentTrackChanged(); | ||
486 | 326 | | |||
487 | if (mCurrentTrack.isValid() && oldRemainingTracksCount != remainingTracks()) { | | |||
488 | Q_EMIT remainingTracksChanged(); | | |||
489 | mOldRemainingTracks = remainingTracks(); | | |||
490 | } | | |||
491 | | ||||
492 | notifyArtistProperty(); | 327 | notifyArtistProperty(); | ||
493 | notifyTitleProperty(); | 328 | notifyTitleProperty(); | ||
494 | notifyAlbumProperty(); | 329 | notifyAlbumProperty(); | ||
495 | notifyAlbumArtistProperty(); | 330 | notifyAlbumArtistProperty(); | ||
496 | notifyFileNameProperty(); | 331 | notifyFileNameProperty(); | ||
497 | notifyImageProperty(); | 332 | notifyImageProperty(); | ||
498 | notifyDatabaseIdProperty(); | 333 | notifyDatabaseIdProperty(); | ||
499 | notifyAlbumIdProperty(); | 334 | notifyAlbumIdProperty(); | ||
500 | notifyIsValidProperty(); | 335 | notifyIsValidProperty(); | ||
501 | } | 336 | } | ||
502 | 337 | | |||
503 | void ManageHeaderBar::setPlayListModel(QAbstractItemModel *aPlayListModel) | | |||
504 | { | | |||
505 | if (mPlayListModel) { | | |||
506 | disconnect(mPlayListModel, &QAbstractItemModel::rowsInserted, this, &ManageHeaderBar::tracksInserted); | | |||
507 | disconnect(mPlayListModel, &QAbstractItemModel::rowsAboutToBeMoved, this, &ManageHeaderBar::tracksAboutToBeMoved); | | |||
508 | disconnect(mPlayListModel, &QAbstractItemModel::rowsMoved, this, &ManageHeaderBar::tracksMoved); | | |||
509 | disconnect(mPlayListModel, &QAbstractItemModel::rowsRemoved, this, &ManageHeaderBar::tracksRemoved); | | |||
510 | disconnect(mPlayListModel, &QAbstractItemModel::dataChanged, this, &ManageHeaderBar::tracksDataChanged); | | |||
511 | disconnect(mPlayListModel, &QAbstractItemModel::layoutChanged, this, &ManageHeaderBar::playListLayoutChanged); | | |||
512 | } | | |||
513 | | ||||
514 | mPlayListModel = aPlayListModel; | | |||
515 | | ||||
516 | if (mPlayListModel) { | | |||
517 | connect(mPlayListModel, &QAbstractItemModel::rowsInserted, this, &ManageHeaderBar::tracksInserted); | | |||
518 | connect(mPlayListModel, &QAbstractItemModel::rowsAboutToBeMoved, this, &ManageHeaderBar::tracksAboutToBeMoved); | | |||
519 | connect(mPlayListModel, &QAbstractItemModel::rowsMoved, this, &ManageHeaderBar::tracksMoved); | | |||
520 | connect(mPlayListModel, &QAbstractItemModel::rowsRemoved, this, &ManageHeaderBar::tracksRemoved); | | |||
521 | connect(mPlayListModel, &QAbstractItemModel::dataChanged, this, &ManageHeaderBar::tracksDataChanged); | | |||
522 | connect(mPlayListModel, &QAbstractItemModel::layoutChanged, this, &ManageHeaderBar::playListLayoutChanged); | | |||
523 | } | | |||
524 | | ||||
525 | Q_EMIT playListModelChanged(); | | |||
526 | } | | |||
527 | | ||||
528 | QAbstractItemModel *ManageHeaderBar::playListModel() const | | |||
529 | { | | |||
530 | return mPlayListModel; | | |||
531 | } | | |||
532 | | ||||
533 | | ||||
534 | #include "moc_manageheaderbar.cpp" | 338 | #include "moc_manageheaderbar.cpp" |
Unrelated change