]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kstandarditemlistgroupheader.cpp
GIT_SILENT Sync po/docbooks with svn
[dolphin.git] / src / kitemviews / kstandarditemlistgroupheader.cpp
index 2afaa168c5b6721aca3333c37019df1caa9dfa0f..0960084a37984a1a02132ffe64b28dfe877525da 100644 (file)
@@ -1,45 +1,29 @@
-/***************************************************************************
- *   Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com>             *
- *                                                                         *
- *   Based on the Itemviews NG project from Trolltech Labs:                *
- *   http://qt.gitorious.org/qt-labs/itemviews-ng                          *
- *                                                                         *
- *   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 <peter.penz19@gmail.com>
+ *
+ * Based on the Itemviews NG project from Trolltech Labs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
 
 #include "kstandarditemlistgroupheader.h"
 
 #include <KRatingPainter>
 #include <QPainter>
 
-KStandardItemListGroupHeader::KStandardItemListGroupHeader(QGraphicsWidget* parent) :
-    KItemListGroupHeader(parent),
-    m_dirtyCache(true),
-    m_text(),
-    m_pixmap()
+KStandardItemListGroupHeader::KStandardItemListGroupHeader(QGraphicsWidget *parent)
+    : KItemListGroupHeader(parent)
+    , m_dirtyCache(true)
+    , m_text()
+    m_pixmap()
 {
-    m_text.setTextFormat(Qt::PlainText);
-    m_text.setPerformanceHint(QStaticText::AggressiveCaching);
 }
 
 KStandardItemListGroupHeader::~KStandardItemListGroupHeader()
 {
 }
 
-void KStandardItemListGroupHeader::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
+void KStandardItemListGroupHeader::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
 {
     if (m_dirtyCache) {
         updateCache();
@@ -47,17 +31,17 @@ void KStandardItemListGroupHeader::paint(QPainter* painter, const QStyleOptionGr
     KItemListGroupHeader::paint(painter, option, widget);
 }
 
-void KStandardItemListGroupHeader::paintRole(QPainter* painter, const QRectF& roleBounds, const QColor& color)
+void KStandardItemListGroupHeader::paintRole(QPainter *painter, const QRectF &roleBounds, const QColor &color)
 {
     if (m_pixmap.isNull()) {
         painter->setPen(color);
-        painter->drawStaticText(roleBounds.topLeft(), m_text);
+        painter->drawText(roleBounds, 0, m_text);
     } else {
         painter->drawPixmap(roleBounds.topLeft(), m_pixmap);
     }
 }
 
-void KStandardItemListGroupHeader::paintSeparator(QPainter* painter, const QColor& color)
+void KStandardItemListGroupHeader::paintSeparator(QPainter *painter, const QColor &color)
 {
     if (itemIndex() == 0) {
         // No top- or left-line should be drawn for the first group-header
@@ -67,29 +51,34 @@ void KStandardItemListGroupHeader::paintSeparator(QPainter* painter, const QColo
     painter->setPen(color);
 
     if (scrollOrientation() == Qt::Horizontal) {
-        painter->drawLine(0, 0, 0, size().height() - 1);
+        const qreal x = layoutDirection() == Qt::RightToLeft ? size().width() - 1 : 0;
+        painter->drawLine(x, 0, x, size().height() - 1);
     } else {
-        painter->drawLine(0, 0, size().width() - 1, 0);
+        if (layoutDirection() == Qt::LeftToRight) {
+            painter->drawLine(0, 0, size().width() - 1, 0);
+        } else {
+            painter->drawLine(1, 0, size().width(), 0);
+        }
     }
 }
 
 void KStandardItemListGroupHeader::roleChanged(const QByteArray &current, const QByteArray &previous)
 {
-    Q_UNUSED(current);
-    Q_UNUSED(previous);
+    Q_UNUSED(current)
+    Q_UNUSED(previous)
     m_dirtyCache = true;
 }
 
-void KStandardItemListGroupHeader::dataChanged(const QVariant& current, const QVariant& previous)
+void KStandardItemListGroupHeader::dataChanged(const QVariant &current, const QVariant &previous)
 {
-    Q_UNUSED(current);
-    Q_UNUSED(previous);
+    Q_UNUSED(current)
+    Q_UNUSED(previous)
     m_dirtyCache = true;
 }
 
-void KStandardItemListGroupHeader::resizeEvent(QGraphicsSceneResizeEventevent)
+void KStandardItemListGroupHeader::resizeEvent(QGraphicsSceneResizeEvent *event)
 {
-    QGraphicsWidget::resizeEvent(event);
+    KItemListGroupHeader::resizeEvent(event);
     m_dirtyCache = true;
 }
 
@@ -101,7 +90,7 @@ void KStandardItemListGroupHeader::updateCache()
     const qreal maxWidth = size().width() - 4 * styleOption().padding;
 
     if (role() == "rating") {
-        m_text = QString(); // krazy:exlude=nullstrassign
+        m_text = QString();
 
         const qreal height = styleOption().fontMetrics.ascent();
         const QSizeF pixmapSize(qMin(height * 5, maxWidth), height);
@@ -118,7 +107,8 @@ void KStandardItemListGroupHeader::updateCache()
 
         QFontMetricsF fontMetrics(font());
         const QString text = fontMetrics.elidedText(data().toString(), Qt::ElideRight, maxWidth);
-        m_text.setText(text);
+        m_text = text;
     }
 }
 
+#include "moc_kstandarditemlistgroupheader.cpp"