diff options
Diffstat (limited to 'src/plugins/Ui/skinned/playlistheader.cpp')
| -rw-r--r-- | src/plugins/Ui/skinned/playlistheader.cpp | 240 |
1 files changed, 180 insertions, 60 deletions
diff --git a/src/plugins/Ui/skinned/playlistheader.cpp b/src/plugins/Ui/skinned/playlistheader.cpp index ff4fa5c8d..6698f557d 100644 --- a/src/plugins/Ui/skinned/playlistheader.cpp +++ b/src/plugins/Ui/skinned/playlistheader.cpp @@ -127,6 +127,7 @@ void PlayListHeader::updateColumns() { m_rects.clear(); m_names.clear(); + bool rtl = (layoutDirection() == Qt::RightToLeft); int sx = 5; if(m_number_width) @@ -134,7 +135,7 @@ void PlayListHeader::updateColumns() if(m_model->count() == 1) { - m_rects << QRect(sx, 0, width() - sx - 5, height()); + m_rects << (rtl ? QRect(5, 0, width() - sx - 5, height()) : QRect(sx, 0, width() - sx - 5, height())); if(m_sorting_column == 0) { m_names << m_metrics->elidedText(m_model->name(0), Qt::ElideRight, @@ -150,7 +151,10 @@ void PlayListHeader::updateColumns() for(int i = 0; i < m_model->count(); ++i) { - m_rects << QRect(sx, 0, m_model->size(i), height()); + if(rtl) + m_rects << QRect(width() - sx - m_model->size(i), 0, m_model->size(i), height()); + else + m_rects << QRect(sx, 0, m_model->size(i), height()); if(i == m_sorting_column) { m_names << m_metrics->elidedText(m_model->name(i), Qt::ElideRight, @@ -240,6 +244,8 @@ void PlayListHeader::restoreSize() void PlayListHeader::mousePressEvent(QMouseEvent *e) { + bool rtl = layoutDirection() == Qt::RightToLeft; + if(e->button() == Qt::LeftButton) { m_pressed_column = findColumn(e->pos()); @@ -248,22 +254,38 @@ void PlayListHeader::mousePressEvent(QMouseEvent *e) m_pressed_pos = e->pos(); m_mouse_pos = e->pos(); - if(e->pos().x() > m_rects[m_pressed_column].right() - m_metrics->width("9")) + if(rtl) { - m_old_size = m_model->size(m_pressed_column); - m_task = RESIZE; + if(e->pos().x() < m_rects[m_pressed_column].x() + m_metrics->width("9")) + { + m_old_size = m_model->size(m_pressed_column); + m_task = RESIZE; + } + else + { + m_press_offset = e->pos().x() - m_rects.at(m_pressed_column).x(); + m_task = SORT; + } } else { - m_press_offset = e->pos().x() - m_rects.at(m_pressed_column).x(); - m_task = SORT; + if(e->pos().x() > m_rects[m_pressed_column].right() - m_metrics->width("9")) + { + m_old_size = m_model->size(m_pressed_column); + m_task = RESIZE; + } + else + { + m_press_offset = e->pos().x() - m_rects.at(m_pressed_column).x(); + m_task = SORT; + } } } - } - else - { - m_task = NO_TASK; - update(); + else + { + m_task = NO_TASK; + update(); + } } } @@ -280,6 +302,8 @@ void PlayListHeader::mouseReleaseEvent(QMouseEvent *) void PlayListHeader::mouseMoveEvent(QMouseEvent *e) { + bool rtl = layoutDirection() == Qt::RightToLeft; + if(m_task == SORT) { m_task = MOVE; @@ -287,7 +311,10 @@ void PlayListHeader::mouseMoveEvent(QMouseEvent *e) if(m_task == RESIZE && m_model->count() > 1) { - m_model->resize(m_pressed_column, m_old_size + e->pos().x() - m_pressed_pos.x()); + if(rtl) + m_model->resize(m_pressed_column, m_old_size - e->pos().x() + m_pressed_pos.x()); + else + m_model->resize(m_pressed_column, m_old_size + e->pos().x() - m_pressed_pos.x()); } else if(m_task == MOVE) { @@ -300,11 +327,23 @@ void PlayListHeader::mouseMoveEvent(QMouseEvent *e) 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)) + if(rtl) + { + 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; + } + } + else { - dest = i; - break; + 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) @@ -320,10 +359,20 @@ void PlayListHeader::mouseMoveEvent(QMouseEvent *e) else if(e->button() == Qt::NoButton) { int column = findColumn(e->pos()); - if(column >= 0 && e->pos().x() > m_rects[column].right() - m_metrics->width("9")) - setCursor(Qt::SplitHCursor); + if(rtl) + { + if(column >= 0 && e->pos().x() < m_rects[column].x() + m_metrics->width("9")) + setCursor(Qt::SplitHCursor); + else + setCursor(Qt::ArrowCursor); + } else - setCursor(Qt::ArrowCursor); + { + if(column >= 0 && e->pos().x() > m_rects[column].right() - m_metrics->width("9")) + setCursor(Qt::SplitHCursor); + else + setCursor(Qt::ArrowCursor); + } } } @@ -335,15 +384,20 @@ void PlayListHeader::resizeEvent(QResizeEvent *e) return; } + int delta = e->size().width() - e->oldSize().width(); + int index = m_model->autoResizeColumn(); + + if(layoutDirection() == Qt::RightToLeft) + updateColumns(); + if(e->oldSize().width() <= 10) return; - int delta = e->size().width() - e->oldSize().width(); - int index = m_model->autoResizeColumn(); if(index >= 0) { m_model->resize(index, m_model->size(index) + delta); updateColumns(); + return; } } @@ -381,59 +435,125 @@ void PlayListHeader::paintEvent(QPaintEvent *) painter.setPen(m_normal_bg); - if(m_number_width) - { - painter.drawLine(m_rects.at(0).x(), 0, - m_rects.at(0).x(), height()); - } + bool rtl = (layoutDirection() == Qt::RightToLeft); - if(m_names.count() == 1) + if(rtl) { - painter.drawText(m_rects[0].x() + m_padding, m_metrics->ascent(), m_names[0]); - if(m_sorting_column == 0) + if(m_number_width) { - painter.drawPixmap(m_rects[0].right() - m_arrow_up.width() - 4, - (height() - m_arrow_up.height()) / 2, - m_reverted ? m_arrow_up : m_arrow_down); + painter.drawLine(m_rects.at(0).right(), 0, + m_rects.at(0).right(), height()); } - return; - } - for(int i = 0; i < m_rects.count(); ++i) - { - if(m_task == MOVE && i == m_pressed_column) + if(m_names.count() == 1) { - painter.setBrush(m_normal_bg); - painter.setPen(m_current); - painter.drawRect(m_rects[i].x(), 0, - m_rects[i].width(), height()-1); - painter.setBrush(m_normal); - painter.setPen(m_normal_bg); - continue; + painter.drawText(m_rects[0].right() - m_padding - m_metrics->width(m_names[0]), + m_metrics->ascent(), m_names[0]); + if(m_sorting_column == 0) + { + painter.drawPixmap(m_rects[0].x() + 4, + (height() - m_arrow_up.height()) / 2, + m_reverted ? m_arrow_up : m_arrow_down); + } + return; } - painter.drawText(m_rects[i].x() + m_padding, m_metrics->ascent(), m_names[i]); + 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(), 0, + m_rects[i].width(), height()-1); + painter.setBrush(m_normal); + painter.setPen(m_normal_bg); + continue; + } - painter.drawLine(m_rects[i].right()+1, 0, - m_rects[i].right()+1, height()+1); + painter.drawText(m_rects[i].right() - m_padding - m_metrics->width(m_names[i]), + m_metrics->ascent(), m_names[i]); - if(i == m_sorting_column) + painter.drawLine(m_rects[i].x()-1, 0, + m_rects[i].x()-1, height()+1); + + if(i == m_sorting_column) + { + painter.drawPixmap(m_rects[i].x() + 4, + (height() - m_arrow_up.height()) / 2, + m_reverted ? m_arrow_up : m_arrow_down); + } + } + + if(m_task == MOVE) { - painter.drawPixmap(m_rects[i].right() - m_arrow_up.width() - 4, - (height() - m_arrow_up.height()) / 2, - m_reverted ? m_arrow_up : m_arrow_down); + painter.setPen(m_normal); + painter.drawRect(m_mouse_pos.x() - m_press_offset, 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.at(m_pressed_column).width() - m_padding - + m_metrics->width(m_names.at(m_pressed_column)), + m_metrics->ascent(), m_names.at(m_pressed_column)); } } - - if(m_task == MOVE) + else { - painter.setPen(m_normal); - painter.drawRect(m_mouse_pos.x() - m_press_offset, 0, - m_rects.at(m_pressed_column).width(), height()); + if(m_number_width) + { + painter.drawLine(m_rects.at(0).x(), 0, + m_rects.at(0).x(), height()); + } - painter.setPen(m_normal_bg); - painter.drawText(m_mouse_pos.x() - m_press_offset + m_padding, - m_metrics->ascent(), m_names.at(m_pressed_column)); + if(m_names.count() == 1) + { + painter.drawText(m_rects[0].x() + m_padding, m_metrics->ascent(), m_names[0]); + if(m_sorting_column == 0) + { + painter.drawPixmap(m_rects[0].right() - m_arrow_up.width() - 4, + (height() - m_arrow_up.height()) / 2, + m_reverted ? m_arrow_up : m_arrow_down); + } + return; + } + + 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(), 0, + m_rects[i].width(), height()-1); + painter.setBrush(m_normal); + painter.setPen(m_normal_bg); + continue; + } + + painter.drawText(m_rects[i].x() + m_padding, m_metrics->ascent(), m_names[i]); + + painter.drawLine(m_rects[i].right()+1, 0, + m_rects[i].right()+1, height()+1); + + if(i == m_sorting_column) + { + painter.drawPixmap(m_rects[i].right() - m_arrow_up.width() - 4, + (height() - m_arrow_up.height()) / 2, + m_reverted ? m_arrow_up : m_arrow_down); + } + } + + if(m_task == MOVE) + { + painter.setPen(m_normal); + painter.drawRect(m_mouse_pos.x() - m_press_offset, 0, + m_rects.at(m_pressed_column).width(), height()); + + painter.setPen(m_normal_bg); + painter.drawText(m_mouse_pos.x() - m_press_offset + m_padding, + m_metrics->ascent(), m_names.at(m_pressed_column)); + } } } |
