Change PosBar to use the new PixmapSlider class

This commit is contained in:
Thomas Frauendorfer 2008-03-21 22:43:21 +01:00
parent 6e7e2c2184
commit 220c124447
7 changed files with 58 additions and 204 deletions

View file

@ -16,172 +16,54 @@
#include "XMMSHandler.h"
#include "xplayback.h"
#include "mainwindow.h"
#include "PosBar.h"
#include "Skin.h"
#include <QWidget>
#include <QMouseEvent>
PosButton::PosButton (QWidget *parent, uint normal, uint pressed) : Button (parent, normal, pressed)
{
m_slider = dynamic_cast<PosBar *>(parent);
setMinimumSize (29, 10);
setMaximumSize (29, 10);
}
void
PosButton::setPos (uint pos)
{
m_pos = pos;
if (!isDown ()) {
move (pos, 0);
}
}
uint
PosButton::getPos (void)
{
return m_pos;
}
void
PosButton::mousePressEvent (QMouseEvent *event)
{
QPoint p (event->pos ());
m_diffx = p.x();
m_diffy = p.y();
setDown (true);
}
void
PosButton::mouseReleaseEvent (QMouseEvent *event)
{
setDown (false);
float value = pos().x() / (float)(m_slider->width() - width());
m_slider->requestPos (value);
}
void
PosButton::mouseMoveEvent (QMouseEvent *event)
{
QPoint p (event->pos ());
/** @todo this could be cleaned up */
if (m_slider->getVertical ()) {
int npos = pos().x() + p.x() - m_diffx;
if (npos >= 0 && (npos + rect().width()) <= m_slider->rect().width()) {
move (npos, 0);
} else if (npos < 0) {
move (0, 0);
} else if (npos + rect().width() > m_slider->rect().width()) {
move (m_slider->rect().width() - rect().width(), 0);
}
} else {
int npos = pos().y() + p.y() - m_diffy;
if (npos >= 0 && (npos + rect().height()) <= m_slider->rect().height()) {
move (npos, 0);
} else if (npos < 0) {
move (0, 0);
} else if (npos + rect().height() > m_slider->rect().height()) {
move (m_slider->rect().height() - rect().height(), 0);
}
}
}
PosBar::PosBar (QWidget *parent, uint bg, uint bnormal, uint bpressed, bool vertical) : PixWidget (parent)
PosBar::PosBar (QWidget *parent, uint bg, uint bnormal, uint bpressed)
: PixmapSlider (parent)
{
Skin *skin = Skin::getInstance ();
m_slider_normal = bnormal;
m_slider_pressed = bpressed;
m_bg = bg;
m_vertical = vertical;
setMinimumSize (248, 10);
setMaximumSize (248, 10);
m_max = 0;
m_button = new PosButton (this, bnormal, bpressed);
m_button->move (0, 0);
if (m_vertical) {
m_pix = size().width()-m_button->size().width();
} else {
m_pix = size().height()-m_button->size().height();
}
hideBar (true);
connect (skin, SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps (Skin *)));
setFixedSize (248, 10);
setMinimum (0);
setMaximum (0);
connect (this, SIGNAL (sliderMoved (int)),
this, SLOT (seekMs (int)));
hide ();
}
void
PosBar::setSize (uint x, uint y)
PosBar::seekMs (int value)
{
setMinimumSize (x, y);
setMaximumSize (x, y);
if (m_vertical) {
m_pix = size().width()-m_button->size().width();
} else {
m_pix = size().height()-m_button->size().height();
}
}
uint
PosBar::getPos (void)
{
if (m_vertical) {
return (uint)((float)m_button->pos().x()) / (float)(m_pix) * float(m_max);
} else {
return (uint)((float)m_button->pos().y())/((float)(m_pix*m_max));
}
}
void
PosBar::hideBar (bool b)
{
if (b) {
m_button->hide ();
hide ();
} else {
m_button->show ();
show ();
}
update();
}
void
PosBar::setPos (uint p)
{
if (!m_max) {
return;
}
uint x = m_pix * p / m_max;
if (x < m_pix - m_button->rect().width() && x != m_button->getPos()) {
m_button->setPos (x);
update ();
}
}
void
PosBar::requestPos (float value)
{
XMMSHandler::getInstance ().xplayback ()->seekMs (m_max * value);
XMMSHandler::getInstance ().xplayback ()->seekMs (value);
}
void
PosBar::setPixmaps (Skin *skin)
{
m_pixmap = skin->getItem (m_bg);
QPixmap pixmap = skin->getItem (m_bg);
setBackground (pixmap);
setFixedSize (248, pixmap.height ());
if ( !skin->getItem(m_slider_normal).isNull() &&
!skin->getItem(m_slider_pressed).isNull()) {
setSliders (skin->getItem(m_slider_normal),
skin->getItem(m_slider_pressed));
} else {
setSliders (QPixmap (), QPixmap ());
}
update ();
}

View file

@ -16,58 +16,26 @@
#ifndef __SLIDER_H__
#define __SLIDER_H__
#include "PixWidget.h"
#include "Button.h"
#include "pixmapslider.h"
class PosBar;
class Skin;
class PosButton : public Button
{
public:
PosButton (QWidget *, uint, uint);
void mouseMoveEvent (QMouseEvent *);
void mousePressEvent (QMouseEvent *);
void mouseReleaseEvent (QMouseEvent *);
void setPos (uint pos);
uint getPos (void);
private:
PosBar *m_slider;
uint m_pos;
uint m_diffx;
uint m_diffy;
};
class PosBar : public PixWidget
class PosBar : public PixmapSlider
{
Q_OBJECT
public:
PosBar (QWidget *parent, uint bg, uint bnormal, uint bpressed, bool vertical=true);
PosBar (QWidget *parent, uint bg, uint bnormal, uint bpressed);
~PosBar () { }
void setSize (uint, uint);
uint getPos (void);
void setPos (uint);
void requestPos (float value);
void setMax (uint max) { m_max = max; }
uint getMax () { return m_max; }
void hideBar (bool b);
bool getVertical () { return m_vertical; }
public slots:
void setPixmaps (Skin *skin);
void seekMs (int);
private:
bool m_vertical;
int m_bg;
uint m_max;
uint m_pix;
PosButton *m_button;
uint m_slider_normal;
uint m_slider_pressed;
uint m_bg;
};
#endif

View file

@ -25,6 +25,8 @@ Slider::Slider (QWidget *parent, uint name_min, uint name_max,
connect (skin, SIGNAL (skinChanged (Skin *)),
this, SLOT (setPixmaps(Skin *)));
setSliderOffset (1);
m_name_min = name_min;
m_name_max = name_max;
m_name_on = name_on;

View file

@ -128,8 +128,7 @@ MainDisplay::setPixmaps (Skin *skin)
palette.setBrush(QPalette::Background, brush);
setPalette(palette);
setMaximumSize(QSize(275, 116));
setMinimumSize(QSize(275, 116));
setFixedSize(QSize(275, 116));
}
void
@ -137,8 +136,8 @@ MainDisplay::setStatus (Xmms::Playback::Status status)
{
if (status == Xmms::Playback::STOPPED) {
m_time->setTime(0);
m_posbar->setPos (0);
m_posbar->hideBar (true);
m_posbar->setValue (0);
m_posbar->hide ();
m_stereo->setStereoMono (false, false);
}
}
@ -148,7 +147,7 @@ MainDisplay::setPlaytime (uint32_t time)
{
uint32_t showtime;
if (m_mw->isTimemodeReverse()) {
uint maxtime = m_posbar->getMax();
uint maxtime = m_posbar->maximum ();
showtime = -(maxtime - time);
} else {
showtime = time;
@ -156,7 +155,7 @@ MainDisplay::setPlaytime (uint32_t time)
m_time->setTime (showtime);
// update slider
m_posbar->setPos (time);
m_posbar->setValue (time);
}
void
@ -199,10 +198,10 @@ MainDisplay::setMediainfo (const Xmms::PropDict &info)
}
if (info.contains ("duration")) {
m_posbar->setMax (info.get<int32_t> ("duration"));
m_posbar->hideBar (false);
m_posbar->setMaximum (info.get<int32_t> ("duration"));
m_posbar->show ();
} else {
m_posbar->hideBar (true);
m_posbar->hide ();
}
}

View file

@ -125,10 +125,6 @@ PlaylistScrollBar::paintEvent (QPaintEvent *event)
return;
}
// TODO remove, in here for debuging
// qDebug("%i %i %i %i %i %i %i", event->rect ().x(), event->rect ().y(), event->rect ().width(), event->rect ().height(),
// minimum(), maximum (), sliderPosition ());
QPainter (paint);
paint.begin (this);
/* draw background */
@ -148,6 +144,7 @@ PlaylistScrollBar::setPixmaps (Skin *skin)
m_pixmap = skin->getPls (Skin::PLS_RFILL2_0);
m_slider = skin->getPls (Skin::PLS_SCROLL_0);
m_slider_down = skin->getPls (Skin::PLS_SCROLL_1);
update ();
}

View file

@ -25,6 +25,7 @@
PixmapSlider::PixmapSlider (QWidget *parent) : QAbstractSlider (parent)
{
setSliderDown (false);
m_slider_offset = 0;
}
void
@ -144,10 +145,10 @@ PixmapSlider::paintEvent (QPaintEvent *event)
QRect rect (slider->rect ());
if (orientation () == Qt::Vertical) {
rect.moveTop (sliderPositionFromValue ());
rect.moveLeft (1);
rect.moveLeft (m_slider_offset);
} else {
rect.moveLeft (sliderPositionFromValue ());
rect.moveTop (1);
rect.moveTop (m_slider_offset);
}
p.drawPixmap (rect , *slider, slider->rect ());
p.end ();

View file

@ -58,12 +58,17 @@ class PixmapSlider : public QAbstractSlider
int sliderValueFromPosition (int pos);
int backgroundIndex ();
// horizontal offset in vertical sliders or
// vertical offset in horizontal sliders
void setSliderOffset (int offset) { m_slider_offset = offset; };
private:
QPixmapList m_backgrounds;
QPixmap m_normal;
QPixmap m_pressed;
int m_background_index;
int m_slider_offset;
};
#endif