Qt: Don't sort history playlist. Declare variables at top.
This commit is contained in:
parent
b6f36fcf40
commit
f5840ae6f2
|
@ -13,22 +13,20 @@ ThumbnailDelegate::ThumbnailDelegate(QObject* parent) :
|
||||||
|
|
||||||
void ThumbnailDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex& index) const
|
void ThumbnailDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex& index) const
|
||||||
{
|
{
|
||||||
painter->save();
|
|
||||||
|
|
||||||
QStyleOptionViewItem opt = option;
|
QStyleOptionViewItem opt = option;
|
||||||
initStyleOption(&opt, index);
|
|
||||||
|
|
||||||
const QWidget *widget = opt.widget;
|
const QWidget *widget = opt.widget;
|
||||||
|
|
||||||
QStyle *style = widget->style();
|
QStyle *style = widget->style();
|
||||||
|
|
||||||
int margin = 11;
|
int margin = 11;
|
||||||
int textMargin = 4;
|
int textMargin = 4;
|
||||||
QRect rect = opt.rect;
|
|
||||||
int textHeight = painter->fontMetrics().height() + margin + margin;
|
int textHeight = painter->fontMetrics().height() + margin + margin;
|
||||||
|
QRect rect = opt.rect;
|
||||||
QRect adjusted = rect.adjusted(margin, margin, -margin, -textHeight + textMargin);
|
QRect adjusted = rect.adjusted(margin, margin, -margin, -textHeight + textMargin);
|
||||||
QPixmap pixmap = index.data(PlaylistModel::THUMBNAIL).value<QPixmap>();
|
QPixmap pixmap = index.data(PlaylistModel::THUMBNAIL).value<QPixmap>();
|
||||||
|
|
||||||
|
painter->save();
|
||||||
|
|
||||||
|
initStyleOption(&opt, index);
|
||||||
|
|
||||||
// draw the background
|
// draw the background
|
||||||
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, widget);
|
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, widget);
|
||||||
|
|
||||||
|
@ -43,6 +41,8 @@ void ThumbnailDelegate::paint(QPainter* painter, const QStyleOptionViewItem &opt
|
||||||
if (!opt.text.isEmpty())
|
if (!opt.text.isEmpty())
|
||||||
{
|
{
|
||||||
QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
|
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))
|
if (cg == QPalette::Normal && !(opt.state & QStyle::State_Active))
|
||||||
cg = QPalette::Inactive;
|
cg = QPalette::Inactive;
|
||||||
|
@ -52,9 +52,6 @@ void ThumbnailDelegate::paint(QPainter* painter, const QStyleOptionViewItem &opt
|
||||||
else
|
else
|
||||||
painter->setPen(opt.palette.color(cg, QPalette::Text));
|
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->setFont(opt.font);
|
||||||
painter->drawText(textRect, Qt::AlignCenter, elidedText);
|
painter->drawText(textRect, Qt::AlignCenter, elidedText);
|
||||||
}
|
}
|
||||||
|
@ -174,8 +171,9 @@ QRect GridView::visualRect(const QModelIndex &index) const
|
||||||
|
|
||||||
QRectF GridView::viewportRectForRow(int row) const
|
QRectF GridView::viewportRectForRow(int row) const
|
||||||
{
|
{
|
||||||
|
QRectF rect;
|
||||||
calculateRectsIfNecessary();
|
calculateRectsIfNecessary();
|
||||||
QRectF rect = m_rectForRow.value(row).toRect();
|
rect = m_rectForRow.value(row).toRect();
|
||||||
if (!rect.isValid())
|
if (!rect.isValid())
|
||||||
return rect;
|
return rect;
|
||||||
return QRectF(rect.x() - horizontalScrollBar()->value(), rect.y() - verticalScrollBar()->value(), rect.width(), rect.height());
|
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
|
QModelIndex GridView::indexAt(const QPoint &point_) const
|
||||||
{
|
{
|
||||||
QPoint point(point_);
|
QPoint point(point_);
|
||||||
|
QHash<int, QRectF>::const_iterator i;
|
||||||
point.rx() += horizontalScrollBar()->value();
|
point.rx() += horizontalScrollBar()->value();
|
||||||
point.ry() += verticalScrollBar()->value();
|
point.ry() += verticalScrollBar()->value();
|
||||||
|
|
||||||
calculateRectsIfNecessary();
|
calculateRectsIfNecessary();
|
||||||
QHashIterator<int, QRectF> i(m_rectForRow);
|
|
||||||
while (i.hasNext())
|
i = m_rectForRow.constBegin();
|
||||||
|
|
||||||
|
while (i != m_rectForRow.constEnd())
|
||||||
{
|
{
|
||||||
i.next();
|
|
||||||
if (i.value().contains(point))
|
if (i.value().contains(point))
|
||||||
return model()->index(i.key(), 0, rootIndex());
|
return model()->index(i.key(), 0, rootIndex());
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
@ -302,23 +304,28 @@ QVector<QModelIndex> GridView::visibleIndexes() const {
|
||||||
|
|
||||||
void GridView::setSelection(const QRect &rect, QFlags<QItemSelectionModel::SelectionFlag> flags)
|
void GridView::setSelection(const QRect &rect, QFlags<QItemSelectionModel::SelectionFlag> flags)
|
||||||
{
|
{
|
||||||
QRect rectangle = rect.translated(horizontalScrollBar()->value(), verticalScrollBar()->value()).normalized();
|
QRect rectangle;
|
||||||
calculateRectsIfNecessary();
|
QHash<int, QRectF>::const_iterator i;
|
||||||
QHashIterator<int, QRectF> i(m_rectForRow);
|
|
||||||
int firstRow = model()->rowCount();
|
int firstRow = model()->rowCount();
|
||||||
int lastRow = -1;
|
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))
|
if (i.value().intersects(rectangle))
|
||||||
{
|
{
|
||||||
firstRow = firstRow < i.key() ? firstRow : i.key();
|
firstRow = firstRow < i.key() ? firstRow : i.key();
|
||||||
lastRow = lastRow > i.key() ? lastRow : i.key();
|
lastRow = lastRow > i.key() ? lastRow : i.key();
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
if (firstRow != model()->rowCount() && lastRow != -1)
|
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);
|
selectionModel()->select(selection, flags);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -332,7 +339,9 @@ void GridView::setSelection(const QRect &rect, QFlags<QItemSelectionModel::Selec
|
||||||
QRegion GridView::visualRegionForSelection(const QItemSelection &selection) const
|
QRegion GridView::visualRegionForSelection(const QItemSelection &selection) const
|
||||||
{
|
{
|
||||||
QRegion region;
|
QRegion region;
|
||||||
foreach(const QItemSelectionRange &range, selection)
|
QItemSelectionRange range;
|
||||||
|
|
||||||
|
foreach(range, selection)
|
||||||
{
|
{
|
||||||
for (int row = range.top(); row <= range.bottom(); ++row)
|
for (int row = range.top(); row <= range.bottom(); ++row)
|
||||||
{
|
{
|
||||||
|
@ -343,6 +352,7 @@ QRegion GridView::visualRegionForSelection(const QItemSelection &selection) cons
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return region;
|
return region;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,12 +368,12 @@ void GridView::paintEvent(QPaintEvent*)
|
||||||
{
|
{
|
||||||
QModelIndex index = model()->index(row, 0, rootIndex());
|
QModelIndex index = model()->index(row, 0, rootIndex());
|
||||||
QRectF rect = viewportRectForRow(row);
|
QRectF rect = viewportRectForRow(row);
|
||||||
|
QStyleOptionViewItem option = viewOptions();
|
||||||
|
|
||||||
if (!rect.isValid() || rect.bottom() < 0 || rect.y() > viewport()->height())
|
if (!rect.isValid() || rect.bottom() < 0 || rect.y() > viewport()->height())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
m_visibleIndexes.append(index);
|
m_visibleIndexes.append(index);
|
||||||
QStyleOptionViewItem option = viewOptions();
|
|
||||||
option.rect = rect.toRect();
|
option.rect = rect.toRect();
|
||||||
|
|
||||||
if (selectionModel()->isSelected(index))
|
if (selectionModel()->isSelected(index))
|
||||||
|
|
|
@ -2127,13 +2127,15 @@ void MainWindow::onSearchEnterPressed()
|
||||||
|
|
||||||
void MainWindow::onCurrentTableItemDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
|
void MainWindow::onCurrentTableItemDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
|
||||||
{
|
{
|
||||||
|
QHash<QString, QString> hash;
|
||||||
|
|
||||||
if (!roles.contains(Qt::EditRole))
|
if (!roles.contains(Qt::EditRole))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (topLeft != bottomRight)
|
if (topLeft != bottomRight)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QHash<QString, QString> hash = topLeft.data(PlaylistModel::HASH).value<QHash<QString, QString>>();
|
hash = topLeft.data(PlaylistModel::HASH).value<QHash<QString, QString>>();
|
||||||
|
|
||||||
updateCurrentPlaylistEntry(hash);
|
updateCurrentPlaylistEntry(hash);
|
||||||
|
|
||||||
|
@ -2617,6 +2619,7 @@ void MainWindow::initContentTableWidget()
|
||||||
QListWidgetItem *item = m_listWidget->currentItem();
|
QListWidgetItem *item = m_listWidget->currentItem();
|
||||||
QStringList horizontal_header_labels;
|
QStringList horizontal_header_labels;
|
||||||
QString path;
|
QString path;
|
||||||
|
QModelIndex index;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (!item)
|
if (!item)
|
||||||
|
@ -2633,7 +2636,6 @@ void MainWindow::initContentTableWidget()
|
||||||
|
|
||||||
m_currentGridWidget = NULL;
|
m_currentGridWidget = NULL;
|
||||||
|
|
||||||
|
|
||||||
m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
m_tableView->setSelectionMode(QAbstractItemView::SingleSelection);
|
m_tableView->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
m_tableView->setEditTriggers(QAbstractItemView::SelectedClicked | QAbstractItemView::EditKeyPressed);
|
m_tableView->setEditTriggers(QAbstractItemView::SelectedClicked | QAbstractItemView::EditKeyPressed);
|
||||||
|
@ -2660,15 +2662,14 @@ void MainWindow::initContentTableWidget()
|
||||||
else
|
else
|
||||||
m_playlistModel->addPlaylistItems(QStringList() << path);
|
m_playlistModel->addPlaylistItems(QStringList() << path);
|
||||||
|
|
||||||
//TODO delete?
|
|
||||||
//m_tableView->setSortingEnabled(true);
|
|
||||||
|
|
||||||
if (item != m_historyPlaylistsItem)
|
if (item != m_historyPlaylistsItem)
|
||||||
m_tableView->sortByColumn(0, Qt::AscendingOrder);
|
m_tableView->sortByColumn(0, Qt::AscendingOrder);
|
||||||
|
else
|
||||||
|
m_proxyModel->sort(-1);
|
||||||
|
|
||||||
m_tableView->resizeColumnsToContents();
|
m_tableView->resizeColumnsToContents();
|
||||||
|
|
||||||
QModelIndex index = m_proxyModel->index(0, 0);
|
index = m_proxyModel->index(0, 0);
|
||||||
m_gridView->scrollToTop();
|
m_gridView->scrollToTop();
|
||||||
m_gridView->setCurrentIndex(index);
|
m_gridView->setCurrentIndex(index);
|
||||||
m_tableView->setCurrentIndex(index);
|
m_tableView->setCurrentIndex(index);
|
||||||
|
|
Loading…
Reference in New Issue