diff --git a/ui/drivers/qt/gridview.cpp b/ui/drivers/qt/gridview.cpp index de6948a8e9..e9e74c8128 100644 --- a/ui/drivers/qt/gridview.cpp +++ b/ui/drivers/qt/gridview.cpp @@ -13,22 +13,20 @@ ThumbnailDelegate::ThumbnailDelegate(QObject* parent) : void ThumbnailDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex& index) const { - painter->save(); - QStyleOptionViewItem opt = option; - initStyleOption(&opt, index); - const QWidget *widget = opt.widget; - QStyle *style = widget->style(); - int margin = 11; int textMargin = 4; - QRect rect = opt.rect; int textHeight = painter->fontMetrics().height() + margin + margin; + QRect rect = opt.rect; QRect adjusted = rect.adjusted(margin, margin, -margin, -textHeight + textMargin); QPixmap pixmap = index.data(PlaylistModel::THUMBNAIL).value(); + painter->save(); + + initStyleOption(&opt, index); + // draw the background style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, widget); @@ -43,6 +41,8 @@ void ThumbnailDelegate::paint(QPainter* painter, const QStyleOptionViewItem &opt if (!opt.text.isEmpty()) { QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; + QRect textRect = QRect(rect.x() + margin, rect.y() + adjusted.height() - textMargin + margin, rect.width() - 2 * margin, textHeight); + QString elidedText = painter->fontMetrics().elidedText(opt.text, opt.textElideMode, textRect.width(), Qt::TextShowMnemonic); if (cg == QPalette::Normal && !(opt.state & QStyle::State_Active)) cg = QPalette::Inactive; @@ -52,9 +52,6 @@ void ThumbnailDelegate::paint(QPainter* painter, const QStyleOptionViewItem &opt else painter->setPen(opt.palette.color(cg, QPalette::Text)); - QRect textRect = QRect(rect.x() + margin, rect.y() + adjusted.height() - textMargin + margin, rect.width() - 2 * margin, textHeight); - QString elidedText = painter->fontMetrics().elidedText(opt.text, opt.textElideMode, textRect.width(), Qt::TextShowMnemonic); - painter->setFont(opt.font); painter->drawText(textRect, Qt::AlignCenter, elidedText); } @@ -174,8 +171,9 @@ QRect GridView::visualRect(const QModelIndex &index) const QRectF GridView::viewportRectForRow(int row) const { + QRectF rect; calculateRectsIfNecessary(); - QRectF rect = m_rectForRow.value(row).toRect(); + rect = m_rectForRow.value(row).toRect(); if (!rect.isValid()) return rect; return QRectF(rect.x() - horizontalScrollBar()->value(), rect.y() - verticalScrollBar()->value(), rect.width(), rect.height()); @@ -200,15 +198,19 @@ void GridView::scrollTo(const QModelIndex &index, QAbstractItemView::ScrollHint) QModelIndex GridView::indexAt(const QPoint &point_) const { QPoint point(point_); + QHash::const_iterator i; point.rx() += horizontalScrollBar()->value(); point.ry() += verticalScrollBar()->value(); + calculateRectsIfNecessary(); - QHashIterator i(m_rectForRow); - while (i.hasNext()) + + i = m_rectForRow.constBegin(); + + while (i != m_rectForRow.constEnd()) { - i.next(); if (i.value().contains(point)) return model()->index(i.key(), 0, rootIndex()); + i++; } return QModelIndex(); } @@ -302,23 +304,28 @@ QVector GridView::visibleIndexes() const { void GridView::setSelection(const QRect &rect, QFlags flags) { - QRect rectangle = rect.translated(horizontalScrollBar()->value(), verticalScrollBar()->value()).normalized(); - calculateRectsIfNecessary(); - QHashIterator i(m_rectForRow); + QRect rectangle; + QHash::const_iterator i; int firstRow = model()->rowCount(); int lastRow = -1; - while (i.hasNext()) + + calculateRectsIfNecessary(); + + rectangle = rect.translated(horizontalScrollBar()->value(), verticalScrollBar()->value()).normalized(); + + i = m_rectForRow.constBegin(); + while (i != m_rectForRow.constEnd()) { - i.next(); if (i.value().intersects(rectangle)) { firstRow = firstRow < i.key() ? firstRow : i.key(); lastRow = lastRow > i.key() ? lastRow : i.key(); } + i++; } if (firstRow != model()->rowCount() && lastRow != -1) { - QItemSelection selection( model()->index(firstRow, 0, rootIndex()), model()->index(lastRow, 0, rootIndex())); + QItemSelection selection(model()->index(firstRow, 0, rootIndex()), model()->index(lastRow, 0, rootIndex())); selectionModel()->select(selection, flags); } else @@ -332,7 +339,9 @@ void GridView::setSelection(const QRect &rect, QFlagsindex(row, 0, rootIndex()); QRectF rect = viewportRectForRow(row); + QStyleOptionViewItem option = viewOptions(); if (!rect.isValid() || rect.bottom() < 0 || rect.y() > viewport()->height()) continue; m_visibleIndexes.append(index); - QStyleOptionViewItem option = viewOptions(); option.rect = rect.toRect(); if (selectionModel()->isSelected(index)) diff --git a/ui/drivers/qt/ui_qt_window.cpp b/ui/drivers/qt/ui_qt_window.cpp index ccec679b9d..c767a414d6 100644 --- a/ui/drivers/qt/ui_qt_window.cpp +++ b/ui/drivers/qt/ui_qt_window.cpp @@ -2127,13 +2127,15 @@ void MainWindow::onSearchEnterPressed() void MainWindow::onCurrentTableItemDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) { + QHash hash; + if (!roles.contains(Qt::EditRole)) return; if (topLeft != bottomRight) return; - QHash hash = topLeft.data(PlaylistModel::HASH).value>(); + hash = topLeft.data(PlaylistModel::HASH).value>(); updateCurrentPlaylistEntry(hash); @@ -2617,6 +2619,7 @@ void MainWindow::initContentTableWidget() QListWidgetItem *item = m_listWidget->currentItem(); QStringList horizontal_header_labels; QString path; + QModelIndex index; int i = 0; if (!item) @@ -2633,7 +2636,6 @@ void MainWindow::initContentTableWidget() m_currentGridWidget = NULL; - m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows); m_tableView->setSelectionMode(QAbstractItemView::SingleSelection); m_tableView->setEditTriggers(QAbstractItemView::SelectedClicked | QAbstractItemView::EditKeyPressed); @@ -2660,15 +2662,14 @@ void MainWindow::initContentTableWidget() else m_playlistModel->addPlaylistItems(QStringList() << path); - //TODO delete? - //m_tableView->setSortingEnabled(true); - if (item != m_historyPlaylistsItem) m_tableView->sortByColumn(0, Qt::AscendingOrder); + else + m_proxyModel->sort(-1); m_tableView->resizeColumnsToContents(); - QModelIndex index = m_proxyModel->index(0, 0); + index = m_proxyModel->index(0, 0); m_gridView->scrollToTop(); m_gridView->setCurrentIndex(index); m_tableView->setCurrentIndex(index);