Reposition PlaylistSlider when list contents changes or something is resized.
This commit is contained in:
parent
c4affb2619
commit
103e016cbd
4 changed files with 51 additions and 10 deletions
42
Playlist.cpp
42
Playlist.cpp
|
@ -29,7 +29,7 @@ PlaylistScrollButton::mouseMoveEvent (QMouseEvent *event)
|
||||||
npos = m_slider->rect().height()-rect().height();
|
npos = m_slider->rect().height()-rect().height();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_slider->doScroll (npos);
|
m_slider->doScroll ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -53,18 +53,40 @@ PlaylistScroller::PlaylistScroller (PlaylistWidget *parent) : QWidget (parent)
|
||||||
m_button->move (0, 0);
|
m_button->move (0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void
|
||||||
|
PlaylistScroller::setMax (uint max)
|
||||||
|
{
|
||||||
|
m_max = max;
|
||||||
|
repositionButton ();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint
|
||||||
PlaylistScroller::getMax (void)
|
PlaylistScroller::getMax (void)
|
||||||
{
|
{
|
||||||
return rect().height()-m_button->rect().height();
|
return rect().height()-m_button->rect().height();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint
|
||||||
|
PlaylistScroller::getPos (void)
|
||||||
|
{
|
||||||
|
return (int)((float)(m_button->pos ().y ()) / (float)getMax() * (float)m_max);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistScroller::setPixmaps (Skin *skin)
|
PlaylistScroller::setPixmaps (Skin *skin)
|
||||||
{
|
{
|
||||||
m_pixmap = skin->getPls (Skin::PLS_RFILL2_0);
|
m_pixmap = skin->getPls (Skin::PLS_RFILL2_0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistScroller::repositionButton (void)
|
||||||
|
{
|
||||||
|
PlaylistWidget *pw = dynamic_cast<PlaylistWidget *>(parent ());
|
||||||
|
/* x = 182.6 / (454 - 242) * 224 */
|
||||||
|
int bpos = (int)((float)(pw->getOffset ()) / (float)m_max * (float) getMax ());
|
||||||
|
m_button->move (0, bpos);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistScroller::paintEvent (QPaintEvent *event)
|
PlaylistScroller::paintEvent (QPaintEvent *event)
|
||||||
{
|
{
|
||||||
|
@ -205,6 +227,7 @@ PlaylistWidget::PlaylistWidget (QWidget *parent) : QWidget (parent)
|
||||||
|
|
||||||
m_scroller = new PlaylistScroller (this);
|
m_scroller = new PlaylistScroller (this);
|
||||||
connect (m_scroller, SIGNAL(scrolled(int)), this, SLOT(doScroll (int)));
|
connect (m_scroller, SIGNAL(scrolled(int)), this, SLOT(doScroll (int)));
|
||||||
|
connect (m_list, SIGNAL(sizeChanged(QSize)), this, SLOT(sizeChangedList (QSize)));
|
||||||
|
|
||||||
m_drag = new dragButton (this);
|
m_drag = new dragButton (this);
|
||||||
|
|
||||||
|
@ -212,16 +235,20 @@ PlaylistWidget::PlaylistWidget (QWidget *parent) : QWidget (parent)
|
||||||
resize (275, 300);
|
resize (275, 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PlaylistWidget::sizeChangedList (QSize s)
|
||||||
|
{
|
||||||
|
m_scroller->setMax (s.height() - m_view->height());
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistWidget::doScroll (int pos)
|
PlaylistWidget::doScroll (int pos)
|
||||||
{
|
{
|
||||||
int npos = ((float)pos) / (float)(m_scroller->getMax()) * float(m_list->height() - m_view->height());
|
m_list->setOffset (pos);
|
||||||
|
if (pos == 0) {
|
||||||
m_list->setOffset (npos);
|
|
||||||
if (npos == 0) {
|
|
||||||
m_list->update ();
|
m_list->update ();
|
||||||
} else {
|
} else {
|
||||||
m_list->scroll (0, npos);
|
m_list->scroll (0, pos);
|
||||||
}
|
}
|
||||||
QApplication::sendPostedEvents (m_list, 0);
|
QApplication::sendPostedEvents (m_list, 0);
|
||||||
}
|
}
|
||||||
|
@ -231,6 +258,7 @@ PlaylistWidget::resizeEvent (QResizeEvent *event)
|
||||||
{
|
{
|
||||||
m_view->resize (size().width()-30, size().height()-20-38);
|
m_view->resize (size().width()-30, size().height()-20-38);
|
||||||
m_list->setSize (m_view->size().width(), m_view->size().height());
|
m_list->setSize (m_view->size().width(), m_view->size().height());
|
||||||
|
m_scroller->setMax (m_list->height() - m_view->height());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
14
Playlist.h
14
Playlist.h
|
@ -34,9 +34,13 @@ class PlaylistScroller : public QWidget{
|
||||||
public:
|
public:
|
||||||
PlaylistScroller (PlaylistWidget *arent);
|
PlaylistScroller (PlaylistWidget *arent);
|
||||||
~PlaylistScroller () {}
|
~PlaylistScroller () {}
|
||||||
void doScroll (int p) { emit scrolled(p); }
|
void doScroll (void) { emit scrolled(getPos ()); }
|
||||||
|
|
||||||
int getMax (void);
|
uint getPos (void);
|
||||||
|
uint getMax (void);
|
||||||
|
void setMax (uint max);
|
||||||
|
|
||||||
|
void repositionButton (void);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setPixmaps (Skin *skin);
|
void setPixmaps (Skin *skin);
|
||||||
|
@ -48,6 +52,8 @@ class PlaylistScroller : public QWidget{
|
||||||
void paintEvent (QPaintEvent *event);
|
void paintEvent (QPaintEvent *event);
|
||||||
QPixmap m_pixmap;
|
QPixmap m_pixmap;
|
||||||
PlaylistScrollButton *m_button;
|
PlaylistScrollButton *m_button;
|
||||||
|
|
||||||
|
uint m_max;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PlaylistView : public QWidget {
|
class PlaylistView : public QWidget {
|
||||||
|
@ -65,10 +71,12 @@ class PlaylistWidget : public QWidget {
|
||||||
|
|
||||||
void setActive (bool);
|
void setActive (bool);
|
||||||
void switchDisplay (void);
|
void switchDisplay (void);
|
||||||
|
uint getOffset (void) const { return m_list->getOffset (); };
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setPixmaps (Skin *skin);
|
void setPixmaps (Skin *skin);
|
||||||
void doScroll (int);
|
void doScroll (int);
|
||||||
|
void sizeChangedList (QSize);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void resizeEvent (QResizeEvent *event);
|
void resizeEvent (QResizeEvent *event);
|
||||||
|
@ -90,7 +98,6 @@ class PlaylistWidget : public QWidget {
|
||||||
|
|
||||||
bool m_active;
|
bool m_active;
|
||||||
|
|
||||||
|
|
||||||
PlaylistView *m_view;
|
PlaylistView *m_view;
|
||||||
PlaylistList *m_list;
|
PlaylistList *m_list;
|
||||||
PlaylistScroller *m_scroller;
|
PlaylistScroller *m_scroller;
|
||||||
|
@ -115,6 +122,7 @@ class PlaylistWindow : public QMainWindow {
|
||||||
void moveEvent (QMoveEvent *event);
|
void moveEvent (QMoveEvent *event);
|
||||||
void resizeEvent (QResizeEvent *event);
|
void resizeEvent (QResizeEvent *event);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PlaylistWidget *m_playlist;
|
PlaylistWidget *m_playlist;
|
||||||
PlaylistShade *m_shaded;
|
PlaylistShade *m_shaded;
|
||||||
|
|
|
@ -606,6 +606,7 @@ PlaylistList::addItem (PlaylistItem *i)
|
||||||
}
|
}
|
||||||
if (m_items->count()*getFontH () > size().height()) {
|
if (m_items->count()*getFontH () > size().height()) {
|
||||||
resize (size().width(), m_items->count ()*getFontH ());
|
resize (size().width(), m_items->count ()*getFontH ());
|
||||||
|
emit sizeChanged (size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ class PlaylistList : public QWidget {
|
||||||
void setSize (int, int);
|
void setSize (int, int);
|
||||||
void addItem (PlaylistItem *i);
|
void addItem (PlaylistItem *i);
|
||||||
void setOffset (int i) { m_offset = i; }
|
void setOffset (int i) { m_offset = i; }
|
||||||
|
uint getOffset (void) const { return m_offset; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setPixmaps (Skin *skin);
|
void setPixmaps (Skin *skin);
|
||||||
|
@ -29,6 +30,9 @@ class PlaylistList : public QWidget {
|
||||||
void setStatus (uint);
|
void setStatus (uint);
|
||||||
void settingsSaved ();
|
void settingsSaved ();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void sizeChanged (QSize);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void paintEvent (QPaintEvent *event);
|
void paintEvent (QPaintEvent *event);
|
||||||
void mousePressEvent (QMouseEvent *event);
|
void mousePressEvent (QMouseEvent *event);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue