diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2015-09-30 16:38:10 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2015-09-30 16:38:10 +0000 |
| commit | 97adebbb8689671e6045d09f84456f28566aa3ed (patch) | |
| tree | e4202f9e64512ceb82f7be8bac42076b1af22bbe /src/plugins/Ui/skinned/timeindicator.cpp | |
| parent | e3da4a8739f801d83ee4386a559e9cd010398101 (diff) | |
| download | qmmp-97adebbb8689671e6045d09f84456f28566aa3ed.tar.gz qmmp-97adebbb8689671e6045d09f84456f28566aa3ed.tar.bz2 qmmp-97adebbb8689671e6045d09f84456f28566aa3ed.zip | |
skinned: improved time indicator in shaded mode (Thomas Perl) (#811)
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@5621 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/Ui/skinned/timeindicator.cpp')
| -rw-r--r-- | src/plugins/Ui/skinned/timeindicator.cpp | 170 |
1 files changed, 106 insertions, 64 deletions
diff --git a/src/plugins/Ui/skinned/timeindicator.cpp b/src/plugins/Ui/skinned/timeindicator.cpp index 30eed148e..fb6b84d81 100644 --- a/src/plugins/Ui/skinned/timeindicator.cpp +++ b/src/plugins/Ui/skinned/timeindicator.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006-2009 by Ilya Kotov * + * Copyright (C) 2006-2015 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -20,93 +20,89 @@ #include <QPainter> #include <QSettings> #include <QMouseEvent> -#include <QTimer> #include <qmmp/qmmp.h> #include "skin.h" #include "timeindicator.h" -TimeIndicator::TimeIndicator (QWidget *parent) - : PixmapWidget (parent) + +TimeIndicatorModel::TimeIndicatorModel(QObject *parent) + : QObject (parent) + , m_position (0) + , m_duration (0) + , m_elapsed (true) + , m_visible (false) { - m_skin = Skin::instance(); - m_pixmap = QPixmap (65 * m_skin->ratio(),13 * m_skin->ratio()); - m_elapsed = true; - m_time = m_songDuration = 0; readSettings(); - m_needToShowTime = false; - updateSkin(); - reset(); - connect(m_skin, SIGNAL(skinChanged()), this, SLOT(updateSkin())); - m_timer = new QTimer(this); - m_timer->setInterval(125); - m_timer->setSingleShot (true); - connect(m_timer, SIGNAL(timeout()),SLOT(reset())); } -void TimeIndicator::setTime (int t) +TimeIndicatorModel::~TimeIndicatorModel() { - m_time = t; - m_pixmap.fill (Qt::transparent); - int r = m_skin->ratio(); - QPainter paint (&m_pixmap); + writeSettings(); +} - if (!m_elapsed) +void TimeIndicatorModel::setPosition(int position) +{ + if (m_position != position) { - t = m_songDuration - t; - paint.drawPixmap(r*2,0,m_skin->getNumber(10)); + m_position = position; + emit changed(); } - if (t < 0) - t = 0; - - if(t >= 3600) - t /= 60; - - paint.drawPixmap(r*13,0,m_skin->getNumber(t/600%10)); - paint.drawPixmap(r*26,0,m_skin->getNumber(t/60%10)); - paint.drawPixmap(r*43,0,m_skin->getNumber(t%60/10)); - paint.drawPixmap(r*56,0,m_skin->getNumber(t%60%10)); - - setPixmap (m_pixmap); - } -void TimeIndicator::reset() +void TimeIndicatorModel::setDuration(int duration) { - m_pixmap.fill (Qt::transparent); - QPainter paint (&m_pixmap); - setPixmap (m_pixmap ); + if (m_duration != duration) { + m_duration = duration; + emit changed(); + } } -void TimeIndicator::mousePressEvent(QMouseEvent* e) +void TimeIndicatorModel::setElapsed(bool elapsed) { - if (m_needToShowTime && e->button() & Qt::LeftButton) - { - m_elapsed = m_elapsed ? false : true; - setTime(m_time); + if (m_elapsed != elapsed) { + m_elapsed = elapsed; + emit changed(); } - PixmapWidget::mousePressEvent(e); } -void TimeIndicator::setSongDuration(int d) +void TimeIndicatorModel::setVisible(bool visible) { - m_songDuration = d; + if (m_visible != visible) + { + m_visible = visible; + emit changed(); + } } -TimeIndicator::~TimeIndicator() +int TimeIndicatorModel::displayTime() { - writeSettings(); -} + int t = m_position; + + if (t < 0) + { + return 0; + } + if (!m_elapsed) + { + t = m_position - m_duration; + } -void TimeIndicator::updateSkin() + if(qAbs(t) >= 3600) + { + t /= 60; + } + + return t; +} + +void TimeIndicatorModel::toggleElapsed() { - m_pixmap = QPixmap (65 * m_skin->ratio(),13 * m_skin->ratio()); - if (m_needToShowTime) - setTime(m_time); + setElapsed(!elapsed()); } -void TimeIndicator::readSettings() +void TimeIndicatorModel::readSettings() { QSettings settings(Qmmp::configFile(), QSettings::IniFormat); settings.beginGroup("Skinned"); @@ -114,7 +110,7 @@ void TimeIndicator::readSettings() settings.endGroup(); } -void TimeIndicator::writeSettings() +void TimeIndicatorModel::writeSettings() { QSettings settings(Qmmp::configFile(), QSettings::IniFormat); settings.beginGroup("Skinned"); @@ -122,13 +118,59 @@ void TimeIndicator::writeSettings() settings.endGroup(); } -void TimeIndicator::setNeedToShowTime(bool need) + +TimeIndicator::TimeIndicator (TimeIndicatorModel *model, QWidget *parent) + : PixmapWidget (parent) + , m_model (model) { - m_needToShowTime = need; - if (!need) - m_timer->start(); - else - m_timer->stop(); + m_skin = Skin::instance(); + updateSkin(); + connect(m_skin, SIGNAL(skinChanged()), this, SLOT(updateSkin())); + connect(m_model, SIGNAL(changed()), this, SLOT(modelChanged())); +} + +void TimeIndicator::modelChanged() +{ + m_pixmap.fill (Qt::transparent); + + if (m_model->visible()) { + int r = m_skin->ratio(); + QPainter paint (&m_pixmap); + + if (!m_model->elapsed()) + { + paint.drawPixmap(r*2,0,m_skin->getNumber(10)); + } + + int t = qAbs(m_model->displayTime()); + + paint.drawPixmap(r*13,0,m_skin->getNumber(t/600%10)); + paint.drawPixmap(r*26,0,m_skin->getNumber(t/60%10)); + paint.drawPixmap(r*43,0,m_skin->getNumber(t%60/10)); + paint.drawPixmap(r*56,0,m_skin->getNumber(t%60%10)); + } + + setPixmap (m_pixmap); +} + +void TimeIndicator::mousePressEvent(QMouseEvent* e) +{ + if (m_model->visible() && e->button() & Qt::LeftButton) + { + m_model->toggleElapsed(); + } + PixmapWidget::mousePressEvent(e); +} + +TimeIndicator::~TimeIndicator() +{ +} + + +void TimeIndicator::updateSkin() +{ + m_pixmap = QPixmap (65 * m_skin->ratio(),13 * m_skin->ratio()); + modelChanged(); } void TimeIndicator::mouseMoveEvent(QMouseEvent *) |
