diff --git a/src/kcategorizedview.cpp b/src/kcategorizedview.cpp --- a/src/kcategorizedview.cpp +++ b/src/kcategorizedview.cpp @@ -103,7 +103,7 @@ : q(q) , proxyModel(nullptr) , categoryDrawer(nullptr) - , categorySpacing(5) + , categorySpacing(0) , alternatingBlockColors(false) , collapsibleBlocks(false) , hoveredBlock(new Block()) diff --git a/src/kcategorydrawer.cpp b/src/kcategorydrawer.cpp --- a/src/kcategorydrawer.cpp +++ b/src/kcategorydrawer.cpp @@ -1,5 +1,6 @@ /** * This file is part of the KDE project + * Copyright 2019 David Redondo * Copyright (C) 2007, 2009 Rafael Fernández López * * This library is free software; you can redistribute it and/or @@ -58,90 +59,44 @@ const QStyleOption &option, QPainter *painter) const { + // Keep this in sync with Kirigami.ListSectionHeader painter->setRenderHint(QPainter::Antialiasing); const QString category = index.model()->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString(); const QRect optRect = option.rect; QFont font(QApplication::font()); - font.setBold(true); + // Match Heading with level 3 + font.setPointSizeF(font.pointSize() * 1.20); const QFontMetrics fontMetrics = QFontMetrics(font); - QColor outlineColor = option.palette.text().color(); - outlineColor.setAlphaF(0.35); + QColor backgroundColor = option.palette.window().color(); - //BEGIN: top left corner + //BEGIN: background { + QRect backgroundRect(option.rect); + backgroundRect.setHeight(categoryHeight(index, option)); painter->save(); - painter->setPen(outlineColor); - const QPointF topLeft(optRect.topLeft()); - QRectF arc(topLeft, QSizeF(4, 4)); - arc.translate(0.5, 0.5); - painter->drawArc(arc, 1440, 1440); + painter->setBrush(backgroundColor); + painter->setPen(Qt::NoPen); + painter->drawRect(backgroundRect); painter->restore(); } - //END: top left corner - - //BEGIN: left vertical line - { - QPoint start(optRect.topLeft()); - start.ry() += 3; - QPoint verticalGradBottom(optRect.topLeft()); - verticalGradBottom.ry() += fontMetrics.height() + 5; - QLinearGradient gradient(start, verticalGradBottom); - gradient.setColorAt(0, outlineColor); - gradient.setColorAt(1, Qt::transparent); - painter->fillRect(QRect(start, QSize(1, fontMetrics.height() + 5)), gradient); - } - //END: left vertical line - - //BEGIN: horizontal line - { - QPoint start(optRect.topLeft()); - start.rx() += 3; - QPoint horizontalGradTop(optRect.topLeft()); - horizontalGradTop.rx() += optRect.width() - 6; - painter->fillRect(QRect(start, QSize(optRect.width() - 6, 1)), outlineColor); - } - //END: horizontal line - - //BEGIN: top right corner - { - painter->save(); - painter->setPen(outlineColor); - QPointF topRight(optRect.topRight()); - topRight.rx() -= 4; - QRectF arc(topRight, QSizeF(4, 4)); - arc.translate(0.5, 0.5); - painter->drawArc(arc, 0, 1440); - painter->restore(); - } - //END: top right corner - - //BEGIN: right vertical line - { - QPoint start(optRect.topRight()); - start.ry() += 3; - QPoint verticalGradBottom(optRect.topRight()); - verticalGradBottom.ry() += fontMetrics.height() + 5; - QLinearGradient gradient(start, verticalGradBottom); - gradient.setColorAt(0, outlineColor); - gradient.setColorAt(1, Qt::transparent); - painter->fillRect(QRect(start, QSize(1, fontMetrics.height() + 5)), gradient); - } - //END: right vertical line + //END: background //BEGIN: text { + // Kirgami.Units.{small/large}Spacing respectively + constexpr int topPadding = 4; + constexpr int sidePadding = 8; QRect textRect(option.rect); - textRect.setTop(textRect.top() + 7); - textRect.setLeft(textRect.left() + 7); + textRect.setTop(textRect.top() + topPadding); + textRect.setLeft(textRect.left() + sidePadding); textRect.setHeight(fontMetrics.height()); - textRect.setRight(textRect.right() - 7); + textRect.setRight(textRect.right() - sidePadding); painter->save(); painter->setFont(font); QColor penColor(option.palette.text().color()); - penColor.setAlphaF(0.6); painter->setPen(penColor); painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, category); painter->restore(); @@ -155,11 +110,10 @@ Q_UNUSED(option) QFont font(QApplication::font()); - font.setBold(true); + font.setPointSizeF(font.pointSize() * 1.20); QFontMetrics fontMetrics(font); - const int height = fontMetrics.height() + 1 /* 1 pixel-width gradient */ - + 11 /* top and bottom separation */; + const int height = fontMetrics.height() + 8; return height; }