aboutsummaryrefslogtreecommitdiff
path: root/src/ui/textscroller.cpp
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2008-07-04 08:39:23 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2008-07-04 08:39:23 +0000
commit8b6b8eba5ecd95826cf07071f8f63a97d34796a8 (patch)
tree32f05e7275b52588e5ba1dd17b69826520ce88e2 /src/ui/textscroller.cpp
parent8cc55a4feeb218f0362a97eec3b1a3e43b6263c4 (diff)
downloadqmmp-8b6b8eba5ecd95826cf07071f8f63a97d34796a8.tar.gz
qmmp-8b6b8eba5ecd95826cf07071f8f63a97d34796a8.tar.bz2
qmmp-8b6b8eba5ecd95826cf07071f8f63a97d34796a8.zip
improved text scroller
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@435 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/ui/textscroller.cpp')
-rw-r--r--src/ui/textscroller.cpp104
1 files changed, 81 insertions, 23 deletions
diff --git a/src/ui/textscroller.cpp b/src/ui/textscroller.cpp
index fc12ebf12..536778e62 100644
--- a/src/ui/textscroller.cpp
+++ b/src/ui/textscroller.cpp
@@ -20,11 +20,17 @@
#include <QPainter>
#include <QTimer>
#include <QSettings>
+#include <QAction>
+#include <QMenu>
+#include <QMouseEvent>
+#include <QSettings>
#include "skin.h"
#include "textscroller.h"
#include "version.h"
+#define SCROLL_SEP "*** "
+
TextScroller *TextScroller::pointer = 0;
TextScroller *TextScroller::getPointer()
@@ -34,52 +40,63 @@ TextScroller *TextScroller::getPointer()
TextScroller::TextScroller ( QWidget *parent )
- : PixmapWidget ( parent )
+ : QWidget ( parent )
{
pointer = this;
m_skin = Skin::getPointer();
m_pixmap = QPixmap ( 150,15 );
+ resize(150,15);
x = 0;
+ m_progress = -1;
m_text = "Qt-based Multimedia Player (Qmmp " + QString(QMMP_STR_VERSION) + ")";
m_update = FALSE;
readSettings();
m_timer = new QTimer ( this );
- connect ( m_timer, SIGNAL ( timeout() ),SLOT ( addOffset() ) );
+ connect (m_timer, SIGNAL (timeout()), SLOT (addOffset()));
m_timer->setInterval(50);
m_timer->start();
updateSkin();
connect(m_skin, SIGNAL(skinChanged()), this, SLOT(updateSkin()));
+ m_autoscroll = TRUE;
+ m_menu = new QMenu(this);
+ QAction *autoscrollAction = new QAction(tr("Autoscroll Songname"), m_menu);
+ autoscrollAction->setCheckable (TRUE);
+ connect(autoscrollAction, SIGNAL(toggled(bool)), SLOT(setAutoscroll(bool)));
+ m_menu->addAction(autoscrollAction);
+ QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat);
+ autoscrollAction->setChecked(settings.value("TextScroller/autoscroll", TRUE).toBool());
+ setAutoscroll(autoscrollAction->isChecked());
}
TextScroller::~TextScroller()
-{}
+{
+ QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat);
+ settings.setValue("TextScroller/autoscroll", m_autoscroll);
+}
void TextScroller::addOffset()
{
- m_pixmap.fill ( Qt::transparent );
- QPainter paint ( &m_pixmap );
x--;
- paint.setPen(m_color);
- paint.setFont(m_font);
- paint.drawText ( 154+x,12, m_text );
- paint.drawText ( 154+x+m_metrics->width ( m_text ) + 15,12, m_text );
- if ( 154 + x < - m_metrics->width ( m_text ) - 15 +1)
+ if ( 154 + x < - m_metrics->width (m_scrollText) - 15 +1)
{
x=-154;
}
- setPixmap ( m_pixmap );
+ update();
}
void TextScroller::setText(const QString& text)
{
- if(isVisible())
+ m_progress = -1;
+ if (isVisible() && m_autoscroll)
m_timer->start();
if (m_text != text)
{
m_text = text;
- x = -50;
+ m_scrollText = "*** " + text;
+ x = m_autoscroll ? -50 : -150;
}
+ update();
}
void TextScroller::updateSkin()
@@ -87,6 +104,23 @@ void TextScroller::updateSkin()
m_color.setNamedColor(m_skin->getPLValue("mbfg"));
}
+
+void TextScroller::setAutoscroll(bool enabled)
+{
+ m_autoscroll = enabled;
+ x = -150;
+ if (m_autoscroll)
+ {
+ if (isVisible())
+ m_timer->start();
+ }
+ else
+ {
+ m_timer->stop();
+ update();
+ }
+}
+
void TextScroller::readSettings()
{
QSettings settings(QDir::homePath()+"/.qmmp/qmmprc", QSettings::IniFormat);
@@ -108,21 +142,45 @@ void TextScroller::readSettings()
void TextScroller::setProgress(int progress)
{
m_timer->stop();
- x = 0;
- m_pixmap.fill ( Qt::transparent );
- QPainter paint ( &m_pixmap );
- paint.setPen(m_color);
- paint.setFont(m_font);
- paint.drawText (4,12, tr("Buffering:") + QString(" %1\%").arg(progress));
- setPixmap(m_pixmap);
+ m_progress = progress;
+ update();
}
-void TextScroller::hideEvent ( QHideEvent *)
+void TextScroller::hideEvent (QHideEvent *)
{
m_timer->stop();
}
-void TextScroller::showEvent ( QShowEvent *)
+void TextScroller::showEvent (QShowEvent *)
{
- m_timer->start();
+ if (m_autoscroll)
+ m_timer->start();
}
+
+void TextScroller::paintEvent (QPaintEvent *)
+{
+ QPainter paint (this);
+ paint.setPen(m_color);
+ paint.setFont(m_font);
+ if (m_progress < 0)
+ {
+ if (m_autoscroll)
+ {
+ paint.drawText (154 + x + m_metrics->width (m_scrollText) + 15,12, m_scrollText);
+ paint.drawText (154 + x,12, m_scrollText);
+ }
+ else
+ paint.drawText (154 + x,12, m_text);
+ }
+ else
+ paint.drawText (4,12, tr("Buffering:") + QString(" %1\%").arg(m_progress));
+}
+
+void TextScroller::mousePressEvent (QMouseEvent *e)
+{
+ if (e->button() == Qt::RightButton)
+ m_menu->exec(e->globalPos());
+ else
+ QWidget::mousePressEvent(e);
+}
+