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();
|
||||
}
|
||||
|
||||
m_slider->doScroll (npos);
|
||||
m_slider->doScroll ();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -52,19 +52,41 @@ PlaylistScroller::PlaylistScroller (PlaylistWidget *parent) : QWidget (parent)
|
|||
m_button = new PlaylistScrollButton (this, Skin::PLS_SCROLL_0, Skin::PLS_SCROLL_1);
|
||||
m_button->move (0, 0);
|
||||
}
|
||||
|
||||
void
|
||||
PlaylistScroller::setMax (uint max)
|
||||
{
|
||||
m_max = max;
|
||||
repositionButton ();
|
||||
}
|
||||
|
||||
int
|
||||
uint
|
||||
PlaylistScroller::getMax (void)
|
||||
{
|
||||
return rect().height()-m_button->rect().height();
|
||||
}
|
||||
|
||||
uint
|
||||
PlaylistScroller::getPos (void)
|
||||
{
|
||||
return (int)((float)(m_button->pos ().y ()) / (float)getMax() * (float)m_max);
|
||||
}
|
||||
|
||||
void
|
||||
PlaylistScroller::setPixmaps (Skin *skin)
|
||||
{
|
||||
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
|
||||
PlaylistScroller::paintEvent (QPaintEvent *event)
|
||||
{
|
||||
|
@ -205,6 +227,7 @@ PlaylistWidget::PlaylistWidget (QWidget *parent) : QWidget (parent)
|
|||
|
||||
m_scroller = new PlaylistScroller (this);
|
||||
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);
|
||||
|
||||
|
@ -212,16 +235,20 @@ PlaylistWidget::PlaylistWidget (QWidget *parent) : QWidget (parent)
|
|||
resize (275, 300);
|
||||
}
|
||||
|
||||
void
|
||||
PlaylistWidget::sizeChangedList (QSize s)
|
||||
{
|
||||
m_scroller->setMax (s.height() - m_view->height());
|
||||
}
|
||||
|
||||
void
|
||||
PlaylistWidget::doScroll (int pos)
|
||||
{
|
||||
int npos = ((float)pos) / (float)(m_scroller->getMax()) * float(m_list->height() - m_view->height());
|
||||
|
||||
m_list->setOffset (npos);
|
||||
if (npos == 0) {
|
||||
m_list->setOffset (pos);
|
||||
if (pos == 0) {
|
||||
m_list->update ();
|
||||
} else {
|
||||
m_list->scroll (0, npos);
|
||||
m_list->scroll (0, pos);
|
||||
}
|
||||
QApplication::sendPostedEvents (m_list, 0);
|
||||
}
|
||||
|
@ -231,6 +258,7 @@ PlaylistWidget::resizeEvent (QResizeEvent *event)
|
|||
{
|
||||
m_view->resize (size().width()-30, size().height()-20-38);
|
||||
m_list->setSize (m_view->size().width(), m_view->size().height());
|
||||
m_scroller->setMax (m_list->height() - m_view->height());
|
||||
}
|
||||
|
||||
void
|
||||
|
|
14
Playlist.h
14
Playlist.h
|
@ -34,9 +34,13 @@ class PlaylistScroller : public QWidget{
|
|||
public:
|
||||
PlaylistScroller (PlaylistWidget *arent);
|
||||
~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:
|
||||
void setPixmaps (Skin *skin);
|
||||
|
@ -48,6 +52,8 @@ class PlaylistScroller : public QWidget{
|
|||
void paintEvent (QPaintEvent *event);
|
||||
QPixmap m_pixmap;
|
||||
PlaylistScrollButton *m_button;
|
||||
|
||||
uint m_max;
|
||||
};
|
||||
|
||||
class PlaylistView : public QWidget {
|
||||
|
@ -65,10 +71,12 @@ class PlaylistWidget : public QWidget {
|
|||
|
||||
void setActive (bool);
|
||||
void switchDisplay (void);
|
||||
uint getOffset (void) const { return m_list->getOffset (); };
|
||||
|
||||
public slots:
|
||||
void setPixmaps (Skin *skin);
|
||||
void doScroll (int);
|
||||
void sizeChangedList (QSize);
|
||||
|
||||
private:
|
||||
void resizeEvent (QResizeEvent *event);
|
||||
|
@ -89,7 +97,6 @@ class PlaylistWidget : public QWidget {
|
|||
QPixmap m_rfill3;
|
||||
|
||||
bool m_active;
|
||||
|
||||
|
||||
PlaylistView *m_view;
|
||||
PlaylistList *m_list;
|
||||
|
@ -115,6 +122,7 @@ class PlaylistWindow : public QMainWindow {
|
|||
void moveEvent (QMoveEvent *event);
|
||||
void resizeEvent (QResizeEvent *event);
|
||||
|
||||
|
||||
private:
|
||||
PlaylistWidget *m_playlist;
|
||||
PlaylistShade *m_shaded;
|
||||
|
|
|
@ -606,6 +606,7 @@ PlaylistList::addItem (PlaylistItem *i)
|
|||
}
|
||||
if (m_items->count()*getFontH () > size().height()) {
|
||||
resize (size().width(), m_items->count ()*getFontH ());
|
||||
emit sizeChanged (size());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ class PlaylistList : public QWidget {
|
|||
void setSize (int, int);
|
||||
void addItem (PlaylistItem *i);
|
||||
void setOffset (int i) { m_offset = i; }
|
||||
uint getOffset (void) const { return m_offset; }
|
||||
|
||||
public slots:
|
||||
void setPixmaps (Skin *skin);
|
||||
|
@ -29,6 +30,9 @@ class PlaylistList : public QWidget {
|
|||
void setStatus (uint);
|
||||
void settingsSaved ();
|
||||
|
||||
signals:
|
||||
void sizeChanged (QSize);
|
||||
|
||||
private:
|
||||
void paintEvent (QPaintEvent *event);
|
||||
void mousePressEvent (QMouseEvent *event);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue