Change PosBar to use the new PixmapSlider class
This commit is contained in:
parent
6e7e2c2184
commit
220c124447
7 changed files with 58 additions and 204 deletions
172
src/PosBar.cpp
172
src/PosBar.cpp
|
@ -16,172 +16,54 @@
|
||||||
#include "XMMSHandler.h"
|
#include "XMMSHandler.h"
|
||||||
#include "xplayback.h"
|
#include "xplayback.h"
|
||||||
|
|
||||||
#include "mainwindow.h"
|
|
||||||
|
|
||||||
#include "PosBar.h"
|
#include "PosBar.h"
|
||||||
#include "Skin.h"
|
#include "Skin.h"
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QMouseEvent>
|
|
||||||
|
|
||||||
PosButton::PosButton (QWidget *parent, uint normal, uint pressed) : Button (parent, normal, pressed)
|
PosBar::PosBar (QWidget *parent, uint bg, uint bnormal, uint bpressed)
|
||||||
{
|
: PixmapSlider (parent)
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
|
Skin *skin = Skin::getInstance ();
|
||||||
|
m_slider_normal = bnormal;
|
||||||
|
m_slider_pressed = bpressed;
|
||||||
m_bg = bg;
|
m_bg = bg;
|
||||||
m_vertical = vertical;
|
|
||||||
|
|
||||||
setMinimumSize (248, 10);
|
connect (skin, SIGNAL (skinChanged (Skin *)),
|
||||||
setMaximumSize (248, 10);
|
this, SLOT (setPixmaps (Skin *)));
|
||||||
|
|
||||||
m_max = 0;
|
setFixedSize (248, 10);
|
||||||
|
|
||||||
m_button = new PosButton (this, bnormal, bpressed);
|
setMinimum (0);
|
||||||
m_button->move (0, 0);
|
setMaximum (0);
|
||||||
|
|
||||||
if (m_vertical) {
|
connect (this, SIGNAL (sliderMoved (int)),
|
||||||
m_pix = size().width()-m_button->size().width();
|
this, SLOT (seekMs (int)));
|
||||||
} else {
|
|
||||||
m_pix = size().height()-m_button->size().height();
|
|
||||||
}
|
|
||||||
|
|
||||||
hideBar (true);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
PosBar::setSize (uint x, uint y)
|
|
||||||
{
|
|
||||||
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 ();
|
hide ();
|
||||||
} else {
|
|
||||||
m_button->show ();
|
|
||||||
show ();
|
|
||||||
}
|
|
||||||
update();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PosBar::setPos (uint p)
|
PosBar::seekMs (int value)
|
||||||
{
|
{
|
||||||
if (!m_max) {
|
XMMSHandler::getInstance ().xplayback ()->seekMs (value);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PosBar::setPixmaps (Skin *skin)
|
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 ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
48
src/PosBar.h
48
src/PosBar.h
|
@ -16,58 +16,26 @@
|
||||||
#ifndef __SLIDER_H__
|
#ifndef __SLIDER_H__
|
||||||
#define __SLIDER_H__
|
#define __SLIDER_H__
|
||||||
|
|
||||||
#include "PixWidget.h"
|
#include "pixmapslider.h"
|
||||||
#include "Button.h"
|
|
||||||
|
|
||||||
class PosBar;
|
class Skin;
|
||||||
|
|
||||||
class PosButton : public Button
|
class PosBar : public PixmapSlider
|
||||||
{
|
|
||||||
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
|
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PosBar (QWidget *parent, uint bg, uint bnormal, uint bpressed, bool vertical=true);
|
PosBar (QWidget *parent, uint bg, uint bnormal, uint bpressed);
|
||||||
~PosBar () { }
|
~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:
|
public slots:
|
||||||
void setPixmaps (Skin *skin);
|
void setPixmaps (Skin *skin);
|
||||||
|
void seekMs (int);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_vertical;
|
uint m_slider_normal;
|
||||||
int m_bg;
|
uint m_slider_pressed;
|
||||||
uint m_max;
|
uint m_bg;
|
||||||
uint m_pix;
|
|
||||||
PosButton *m_button;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -25,6 +25,8 @@ Slider::Slider (QWidget *parent, uint name_min, uint name_max,
|
||||||
connect (skin, SIGNAL (skinChanged (Skin *)),
|
connect (skin, SIGNAL (skinChanged (Skin *)),
|
||||||
this, SLOT (setPixmaps(Skin *)));
|
this, SLOT (setPixmaps(Skin *)));
|
||||||
|
|
||||||
|
setSliderOffset (1);
|
||||||
|
|
||||||
m_name_min = name_min;
|
m_name_min = name_min;
|
||||||
m_name_max = name_max;
|
m_name_max = name_max;
|
||||||
m_name_on = name_on;
|
m_name_on = name_on;
|
||||||
|
|
|
@ -128,8 +128,7 @@ MainDisplay::setPixmaps (Skin *skin)
|
||||||
palette.setBrush(QPalette::Background, brush);
|
palette.setBrush(QPalette::Background, brush);
|
||||||
setPalette(palette);
|
setPalette(palette);
|
||||||
|
|
||||||
setMaximumSize(QSize(275, 116));
|
setFixedSize(QSize(275, 116));
|
||||||
setMinimumSize(QSize(275, 116));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -137,8 +136,8 @@ MainDisplay::setStatus (Xmms::Playback::Status status)
|
||||||
{
|
{
|
||||||
if (status == Xmms::Playback::STOPPED) {
|
if (status == Xmms::Playback::STOPPED) {
|
||||||
m_time->setTime(0);
|
m_time->setTime(0);
|
||||||
m_posbar->setPos (0);
|
m_posbar->setValue (0);
|
||||||
m_posbar->hideBar (true);
|
m_posbar->hide ();
|
||||||
m_stereo->setStereoMono (false, false);
|
m_stereo->setStereoMono (false, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +147,7 @@ MainDisplay::setPlaytime (uint32_t time)
|
||||||
{
|
{
|
||||||
uint32_t showtime;
|
uint32_t showtime;
|
||||||
if (m_mw->isTimemodeReverse()) {
|
if (m_mw->isTimemodeReverse()) {
|
||||||
uint maxtime = m_posbar->getMax();
|
uint maxtime = m_posbar->maximum ();
|
||||||
showtime = -(maxtime - time);
|
showtime = -(maxtime - time);
|
||||||
} else {
|
} else {
|
||||||
showtime = time;
|
showtime = time;
|
||||||
|
@ -156,7 +155,7 @@ MainDisplay::setPlaytime (uint32_t time)
|
||||||
m_time->setTime (showtime);
|
m_time->setTime (showtime);
|
||||||
|
|
||||||
// update slider
|
// update slider
|
||||||
m_posbar->setPos (time);
|
m_posbar->setValue (time);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -199,10 +198,10 @@ MainDisplay::setMediainfo (const Xmms::PropDict &info)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info.contains ("duration")) {
|
if (info.contains ("duration")) {
|
||||||
m_posbar->setMax (info.get<int32_t> ("duration"));
|
m_posbar->setMaximum (info.get<int32_t> ("duration"));
|
||||||
m_posbar->hideBar (false);
|
m_posbar->show ();
|
||||||
} else {
|
} else {
|
||||||
m_posbar->hideBar (true);
|
m_posbar->hide ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -125,10 +125,6 @@ PlaylistScrollBar::paintEvent (QPaintEvent *event)
|
||||||
return;
|
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);
|
QPainter (paint);
|
||||||
paint.begin (this);
|
paint.begin (this);
|
||||||
/* draw background */
|
/* draw background */
|
||||||
|
@ -148,6 +144,7 @@ PlaylistScrollBar::setPixmaps (Skin *skin)
|
||||||
m_pixmap = skin->getPls (Skin::PLS_RFILL2_0);
|
m_pixmap = skin->getPls (Skin::PLS_RFILL2_0);
|
||||||
m_slider = skin->getPls (Skin::PLS_SCROLL_0);
|
m_slider = skin->getPls (Skin::PLS_SCROLL_0);
|
||||||
m_slider_down = skin->getPls (Skin::PLS_SCROLL_1);
|
m_slider_down = skin->getPls (Skin::PLS_SCROLL_1);
|
||||||
|
update ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
PixmapSlider::PixmapSlider (QWidget *parent) : QAbstractSlider (parent)
|
PixmapSlider::PixmapSlider (QWidget *parent) : QAbstractSlider (parent)
|
||||||
{
|
{
|
||||||
setSliderDown (false);
|
setSliderDown (false);
|
||||||
|
m_slider_offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -144,10 +145,10 @@ PixmapSlider::paintEvent (QPaintEvent *event)
|
||||||
QRect rect (slider->rect ());
|
QRect rect (slider->rect ());
|
||||||
if (orientation () == Qt::Vertical) {
|
if (orientation () == Qt::Vertical) {
|
||||||
rect.moveTop (sliderPositionFromValue ());
|
rect.moveTop (sliderPositionFromValue ());
|
||||||
rect.moveLeft (1);
|
rect.moveLeft (m_slider_offset);
|
||||||
} else {
|
} else {
|
||||||
rect.moveLeft (sliderPositionFromValue ());
|
rect.moveLeft (sliderPositionFromValue ());
|
||||||
rect.moveTop (1);
|
rect.moveTop (m_slider_offset);
|
||||||
}
|
}
|
||||||
p.drawPixmap (rect , *slider, slider->rect ());
|
p.drawPixmap (rect , *slider, slider->rect ());
|
||||||
p.end ();
|
p.end ();
|
||||||
|
|
|
@ -58,12 +58,17 @@ class PixmapSlider : public QAbstractSlider
|
||||||
int sliderValueFromPosition (int pos);
|
int sliderValueFromPosition (int pos);
|
||||||
int backgroundIndex ();
|
int backgroundIndex ();
|
||||||
|
|
||||||
|
// horizontal offset in vertical sliders or
|
||||||
|
// vertical offset in horizontal sliders
|
||||||
|
void setSliderOffset (int offset) { m_slider_offset = offset; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPixmapList m_backgrounds;
|
QPixmapList m_backgrounds;
|
||||||
QPixmap m_normal;
|
QPixmap m_normal;
|
||||||
QPixmap m_pressed;
|
QPixmap m_pressed;
|
||||||
|
|
||||||
int m_background_index;
|
int m_background_index;
|
||||||
|
int m_slider_offset;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue