diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2015-03-08 20:13:36 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2015-03-08 20:13:36 +0000 |
| commit | 03afd18b5d80871c1fee4c6b57ba22a7a1886970 (patch) | |
| tree | 53a4e19a2407097196a06826485e898324710544 | |
| parent | 9e4946702bde29f2f8bd59b0770cd34fae2b85d6 (diff) | |
| download | qmmp-03afd18b5d80871c1fee4c6b57ba22a7a1886970.tar.gz qmmp-03afd18b5d80871c1fee4c6b57ba22a7a1886970.tar.bz2 qmmp-03afd18b5d80871c1fee4c6b57ba22a7a1886970.zip | |
added feature to move columns
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@4769 90c681e8-e032-0410-971d-27865f9a5e38
| -rw-r--r-- | src/plugins/Ui/skinned/listwidget.cpp | 3 | ||||
| -rw-r--r-- | src/plugins/Ui/skinned/playlistheader.cpp | 105 | ||||
| -rw-r--r-- | src/plugins/Ui/skinned/playlistheader.h | 18 | ||||
| -rw-r--r-- | src/qmmpui/columnmanager.cpp | 11 | ||||
| -rw-r--r-- | src/qmmpui/columnmanager.h | 1 |
5 files changed, 112 insertions, 26 deletions
diff --git a/src/plugins/Ui/skinned/listwidget.cpp b/src/plugins/Ui/skinned/listwidget.cpp index b5ec88345..74f6da5d7 100644 --- a/src/plugins/Ui/skinned/listwidget.cpp +++ b/src/plugins/Ui/skinned/listwidget.cpp @@ -73,7 +73,7 @@ ListWidget::ListWidget(QWidget *parent) connect(column_manager, SIGNAL(resized(int)), SLOT(updateColumns())); connect(column_manager, SIGNAL(inserted(int)), SLOT(updateColumns())); connect(column_manager, SIGNAL(removed(int)), SLOT(updateColumns())); - connect(column_manager, SIGNAL(moved(int)), SLOT(updateColumns())); + connect(column_manager, SIGNAL(moved(int, int)), SLOT(updateColumns())); } ListWidget::~ListWidget() @@ -399,6 +399,7 @@ void ListWidget::updateList(int flags) void ListWidget::updateColumns() { + m_header->updateColumns(); QList<PlayListItem *> items = m_model->mid(m_first, m_row_count); for(int i = 0; i < items.count(); ++i) { diff --git a/src/plugins/Ui/skinned/playlistheader.cpp b/src/plugins/Ui/skinned/playlistheader.cpp index 50196bbd2..ad8494795 100644 --- a/src/plugins/Ui/skinned/playlistheader.cpp +++ b/src/plugins/Ui/skinned/playlistheader.cpp @@ -40,14 +40,15 @@ PlayListHeader::PlayListHeader(QWidget *parent) : QWidget(parent) { m_scrollable = false; - m_resize = false; m_metrics = 0; m_model = 0; m_show_number = false; m_align_numbres = false; m_number_width = 0; + m_task = NO_TASK; m_manager = QmmpUiSettings::instance()->columnManager(); m_skin = Skin::instance(); + connect(m_skin, SIGNAL(skinChanged()), this, SLOT(updateSkin())); loadColors(); readSettings(); @@ -123,37 +124,78 @@ void PlayListHeader::updateSkin() void PlayListHeader::mousePressEvent(QMouseEvent *e) { - for(int i = 0; i < m_rects.count(); ++i) + if(e->button() == Qt::LeftButton) { - if(m_rects.at(i).contains(e->pos())) + for(int i = 0; i < m_rects.count(); ++i) { - m_pressed_pos = e->pos(); - - if(e->pos().x() > m_rects[i].right() - m_metrics->width("9")) + if(m_rects.at(i).contains(e->pos())) { - m_pressed_index = i; - m_size = m_manager->size(i); - m_resize = true; - qDebug("resize = %d", i); + m_pressed_pos = e->pos(); + m_mouse_pos = e->pos(); + m_pressed_column = i; + + if(e->pos().x() > m_rects[i].right() - m_metrics->width("9")) + { + m_old_size = m_manager->size(i); + + m_task = RESIZE; + } + else + { + m_press_offset = e->pos().x() - m_rects.at(m_pressed_column).x(); + m_task = MOVE; + } + break; } - else - qDebug("move = %d", i); } } + else + { + m_task = NO_TASK; + update(); + } } -void PlayListHeader::mouseReleaseEvent(QMouseEvent *e) +void PlayListHeader::mouseReleaseEvent(QMouseEvent *) { - m_resize = false; + m_task = NO_TASK; + update(); } void PlayListHeader::mouseMoveEvent(QMouseEvent *e) { - if(m_resize && m_pressed_index >= 0) + if(m_task == RESIZE && m_manager->count() > 1) { - //qDebug("delta = %d", e->pos().x() - m_pressed_pos.x()); - m_manager->resize(m_pressed_index, m_size + e->pos().x() - m_pressed_pos.x()); - updateColumns(); + m_manager->resize(m_pressed_column, m_old_size + e->pos().x() - m_pressed_pos.x()); + } + else if(m_task == MOVE) + { + m_mouse_pos = e->pos(); + + int dest = -1; + for(int i = 0; i < m_rects.count(); ++i) + { + int x_delta = m_mouse_pos.x() - m_rects.at(i).x(); + if(x_delta < 0 || x_delta > m_rects.at(i).width()) + continue; + + if((x_delta > m_rects.at(i).width()/2 && m_pressed_column < i) || + (x_delta < m_rects.at(i).width()/2 && m_pressed_column > i)) + { + dest = i; + break; + } + } + if(dest == -1 || dest == m_pressed_column) + { + update(); + QWidget::mouseMoveEvent(e); + return; + } + qDebug("moved: %d, %d", m_pressed_column, dest); + m_manager->move(m_pressed_column, dest); + m_pressed_column = dest; + update(); } } @@ -171,7 +213,7 @@ void PlayListHeader::paintEvent(QPaintEvent *) painter.setPen(m_normal); painter.drawRect(5,-1,width()-10,height()+1); - painter.setPen(m_selected_bg); + painter.setPen(m_normal_bg); if(m_number_width) { @@ -188,6 +230,17 @@ void PlayListHeader::paintEvent(QPaintEvent *) for(int i = 0; i < m_rects.count(); ++i) { + if(m_task == MOVE && i == m_pressed_column) + { + painter.setBrush(m_normal_bg); + painter.setPen(m_current); + painter.drawRect(m_rects[i].x() - m_metrics->width("9")/2, 0, + m_rects[i].width(), height()-1); + painter.setBrush(m_normal); + painter.setPen(m_normal_bg); + continue; + } + painter.drawText((m_rects[i].x() + m_rects[i].right())/2 - m_metrics->width(m_names[i])/2, m_metrics->ascent(), m_names[i]); @@ -195,10 +248,22 @@ void PlayListHeader::paintEvent(QPaintEvent *) m_rects[i].right() - m_metrics->width("9")/2, height()+1); } + + if(m_task == MOVE) + { + painter.setPen(m_normal); + painter.drawRect(m_mouse_pos.x() - m_press_offset - m_metrics->width("9")/2, 0, + m_rects.at(m_pressed_column).width(), height()); + + painter.setPen(m_normal_bg); + painter.drawText(m_mouse_pos.x() - m_press_offset + m_rects[m_pressed_column].width()/2 - m_metrics->width(m_names[m_pressed_column])/2, + m_metrics->ascent(), m_names.at(m_pressed_column)); + } } void PlayListHeader::loadColors() { m_normal.setNamedColor(m_skin->getPLValue("normal")); - m_selected_bg.setNamedColor(m_skin->getPLValue("selectedbg")); + m_normal_bg.setNamedColor(m_skin->getPLValue("normalbg")); + m_current.setNamedColor(m_skin->getPLValue("current")); } diff --git a/src/plugins/Ui/skinned/playlistheader.h b/src/plugins/Ui/skinned/playlistheader.h index ccb75e282..f1f145706 100644 --- a/src/plugins/Ui/skinned/playlistheader.h +++ b/src/plugins/Ui/skinned/playlistheader.h @@ -51,7 +51,7 @@ private slots: private: void mousePressEvent(QMouseEvent *e); - void mouseReleaseEvent(QMouseEvent *e); + void mouseReleaseEvent(QMouseEvent *); void mouseMoveEvent(QMouseEvent *e); void resizeEvent(QResizeEvent *); void paintEvent(QPaintEvent *); @@ -62,7 +62,7 @@ private: QFontMetrics *m_metrics; QFont m_font; bool m_scrollable; - QColor m_normal, m_selected_bg; + QColor m_normal, m_normal_bg, m_selected_bg, m_current; bool m_show_number; bool m_align_numbres; int m_number_width; @@ -70,9 +70,17 @@ private: QList <QRect> m_rects; QStringList m_names; QPoint m_pressed_pos; - int m_pressed_index; - int m_size; - bool m_resize; + int m_pressed_column; + int m_old_size; + QPoint m_mouse_pos; + int m_press_offset; + + enum + { + NO_TASK = -1, + RESIZE, + MOVE + } m_task; }; diff --git a/src/qmmpui/columnmanager.cpp b/src/qmmpui/columnmanager.cpp index f5ba0054e..2699bc3f5 100644 --- a/src/qmmpui/columnmanager.cpp +++ b/src/qmmpui/columnmanager.cpp @@ -90,6 +90,17 @@ void ColumnManager::resize(int index, int size) emit resized(index); } +void ColumnManager::move(int from, int to) +{ + if(from < 0 || from >= m_columns.size()) + qWarning("ColumnManager: index is out of range"); + + if(to < 0 || to >= m_columns.size()) + qWarning("ColumnManager: index is out of range"); + m_columns.move(from, to); + emit moved(from, to); +} + void ColumnManager::execEditor(int index, QWidget *parent) { diff --git a/src/qmmpui/columnmanager.h b/src/qmmpui/columnmanager.h index 734ad0e40..0b709dde6 100644 --- a/src/qmmpui/columnmanager.h +++ b/src/qmmpui/columnmanager.h @@ -39,6 +39,7 @@ public: void insert(int index, const QString &name, const QString &pattern); void remove(int index); void resize(int index, int size); + void move(int from, int to); void execEditor(int index, QWidget *parent = 0); int count(); |
