X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/32b51b7b92e16cfaf1121cbe80ca267fc8bb0718..97415729c34851df75c77a67f27d6299c00bfbc4:/src/kitemviews/private/kitemlistheaderwidget.cpp diff --git a/src/kitemviews/private/kitemlistheaderwidget.cpp b/src/kitemviews/private/kitemlistheaderwidget.cpp index 319d9dae3..e5cbc602f 100644 --- a/src/kitemviews/private/kitemlistheaderwidget.cpp +++ b/src/kitemviews/private/kitemlistheaderwidget.cpp @@ -1,38 +1,22 @@ -/*************************************************************************** - * Copyright (C) 2011 by Peter Penz * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ +/* + * SPDX-FileCopyrightText: 2011 Peter Penz + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ #include "kitemlistheaderwidget.h" - -#include -#include +#include "kitemviews/kitemmodelbase.h" #include #include #include #include -#include KItemListHeaderWidget::KItemListHeaderWidget(QGraphicsWidget* parent) : QGraphicsWidget(parent), m_automaticColumnResizing(true), - m_model(0), + m_model(nullptr), m_offset(0), m_columns(), m_columnWidths(), @@ -94,9 +78,8 @@ bool KItemListHeaderWidget::automaticColumnResizing() const void KItemListHeaderWidget::setColumns(const QList& roles) { - foreach (const QByteArray& role, roles) { + for (const QByteArray& role : roles) { if (!m_columnWidths.contains(role)) { - m_columnWidths.remove(role); m_preferredColumnWidths.remove(role); } } @@ -159,8 +142,8 @@ qreal KItemListHeaderWidget::minimumColumnWidth() const void KItemListHeaderWidget::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { - Q_UNUSED(option); - Q_UNUSED(widget); + Q_UNUSED(option) + Q_UNUSED(widget) if (!m_model) { return; @@ -172,7 +155,7 @@ void KItemListHeaderWidget::paint(QPainter* painter, const QStyleOptionGraphicsI qreal x = -m_offset; int orderIndex = 0; - foreach (const QByteArray& role, m_columns) { + for (const QByteArray& role : qAsConst(m_columns)) { const qreal roleWidth = m_columnWidths.value(role); const QRectF rect(x, 0, roleWidth, size().height()); paintRole(painter, role, rect, orderIndex, widget); @@ -218,22 +201,30 @@ void KItemListHeaderWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) const Qt::SortOrder current = (m_model->sortOrder() == Qt::AscendingOrder) ? Qt::DescendingOrder : Qt::AscendingOrder; m_model->setSortOrder(current); - emit sortOrderChanged(current, previous); + Q_EMIT sortOrderChanged(current, previous); } else { // Change the sort role and reset to the ascending order const QByteArray previous = m_model->sortRole(); const QByteArray current = m_columns[m_pressedRoleIndex]; - m_model->setSortRole(current); - emit sortRoleChanged(current, previous); + const bool resetSortOrder = m_model->sortOrder() == Qt::DescendingOrder; + m_model->setSortRole(current, !resetSortOrder); + Q_EMIT sortRoleChanged(current, previous); - if (m_model->sortOrder() == Qt::DescendingOrder) { + if (resetSortOrder) { m_model->setSortOrder(Qt::AscendingOrder); - emit sortOrderChanged(Qt::AscendingOrder, Qt::DescendingOrder); + Q_EMIT sortOrderChanged(Qt::AscendingOrder, Qt::DescendingOrder); } } break; } + case ResizeRoleOperation: { + const QByteArray pressedRole = m_columns[m_pressedRoleIndex]; + const qreal currentWidth = m_columnWidths.value(pressedRole); + Q_EMIT columnWidthChangeFinished(pressedRole, currentWidth); + break; + } + case MoveRoleOperation: m_movingRole.pixmap = QPixmap(); m_movingRole.x = 0; @@ -296,7 +287,7 @@ void KItemListHeaderWidget::mouseMoveEvent(QGraphicsSceneMouseEvent* event) m_columnWidths.insert(pressedRole, currentWidth); update(); - emit columnWidthChanged(pressedRole, currentWidth, previousWidth); + Q_EMIT columnWidthChanged(pressedRole, currentWidth, previousWidth); break; } @@ -313,7 +304,7 @@ void KItemListHeaderWidget::mouseMoveEvent(QGraphicsSceneMouseEvent* event) const QByteArray role = m_columns[m_movingRole.index]; const int previousIndex = m_movingRole.index; m_movingRole.index = targetIndex; - emit columnMoved(role, targetIndex, previousIndex); + Q_EMIT columnMoved(role, targetIndex, previousIndex); m_movingRole.xDec = event->pos().x() - roleXPosition(role); } @@ -338,7 +329,8 @@ void KItemListHeaderWidget::mouseDoubleClickEvent(QGraphicsSceneMouseEvent* even setColumnWidth(role, preferredColumnWidth(role)); qreal currentWidth = columnWidth(role); - emit columnWidthChanged(role, currentWidth, previousWidth); + Q_EMIT columnWidthChanged(role, currentWidth, previousWidth); + Q_EMIT columnWidthChangeFinished(role, currentWidth); } } @@ -372,15 +364,15 @@ void KItemListHeaderWidget::hoverMoveEvent(QGraphicsSceneHoverEvent* event) void KItemListHeaderWidget::slotSortRoleChanged(const QByteArray& current, const QByteArray& previous) { - Q_UNUSED(current); - Q_UNUSED(previous); + Q_UNUSED(current) + Q_UNUSED(previous) update(); } void KItemListHeaderWidget::slotSortOrderChanged(Qt::SortOrder current, Qt::SortOrder previous) { - Q_UNUSED(current); - Q_UNUSED(previous); + Q_UNUSED(current) + Q_UNUSED(previous) update(); } @@ -391,7 +383,7 @@ void KItemListHeaderWidget::paintRole(QPainter* painter, QWidget* widget) const { // The following code is based on the code from QHeaderView::paintSection(). - // Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). + // SPDX-FileCopyrightText: 2011 Nokia Corporation and/or its subsidiary(-ies). QStyleOptionHeader option; option.section = orderIndex; option.state = QStyle::State_None | QStyle::State_Raised | QStyle::State_Horizontal; @@ -476,7 +468,7 @@ int KItemListHeaderWidget::roleIndexAt(const QPointF& pos) const int index = -1; qreal x = -m_offset; - foreach (const QByteArray& role, m_columns) { + for (const QByteArray& role : qAsConst(m_columns)) { ++index; x += m_columnWidths.value(role); if (pos.x() <= x) { @@ -557,7 +549,7 @@ int KItemListHeaderWidget::targetOfMovingRole() const qreal KItemListHeaderWidget::roleXPosition(const QByteArray& role) const { qreal x = -m_offset; - foreach (const QByteArray& visibleRole, m_columns) { + for (const QByteArray& visibleRole : qAsConst(m_columns)) { if (visibleRole == role) { return x; }