From eabed6e1f1d0aa9e25fc73f540250232ec9edc55 Mon Sep 17 00:00:00 2001 From: Filip Fila Date: Mon, 15 Jun 2026 11:28:43 +0000 Subject: search/chip: Draw chip with QStyle instead of hardcoding Breeze Currently the code for the Dolphin chip, that gets used for filters with file indexing, is hardcoding Breeze. We want it to support other styles too, all the while retaining the desired appearance for Breeze. The port to use the `FrameLineEdit` accomplishes that. The results are that: - Non-Breeze themes now get to style the chip properly - the code is cleaner - Breeze even looks better since there is no more of this hover glitch: ![image](/uploads/03707ad2e76cf702757c2e66ab49be34/image.png){width=173 height=72} | Breeze before | Breeze after | | ------ | ------ | | ![Dolphin-searchChip_Breeze-before_](/uploads/ef2809514e973ce5306ce78aca127cb9/Dolphin-searchChip_Breeze-before_.png){width=613 height=120} | ![Dolphin-searchChip_Breeze-after_](/uploads/ce0bcdc4ac766255e3d06627b9740085/Dolphin-searchChip_Breeze-after_.png){width=642 height=139} | | Oxygen before | Oxygen after | | ------ | ------ | | ![Dolphin-searchChip_Oxygen-before_](/uploads/0b32b7a6d7849a13f46ed0e9a8c10b38/Dolphin-searchChip_Oxygen-before_.png){width=616 height=106} | ![Dolphin-searchChip_Oxygen-after_](/uploads/9fbce947e0c65726ddc118217ac34884/Dolphin-searchChip_Oxygen-after_.png){width=621 height=103} | | MSWindows9x before | MSWindows9x after | | ------ | ------ | | ![Dolphin-searchChip_MSWindows-before_](/uploads/c8b7823f74de708e95eef8380eafb231/Dolphin-searchChip_MSWindows-before_.png){width=618 height=99} | ![Dolphin-searchChip_MSWindows-after_](/uploads/d1f1d390ffabbc21e3d734c7816b4fd0/Dolphin-searchChip_MSWindows-after_.png){width=606 height=89} | --- src/search/chip.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/search/chip.cpp b/src/search/chip.cpp index 69c166c9d..d5b47d568 100644 --- a/src/search/chip.cpp +++ b/src/search/chip.cpp @@ -31,20 +31,11 @@ ChipBase::ChipBase(std::shared_ptr dolphinQuery, QWidget *pa void ChipBase::paintEvent(QPaintEvent *event) { QStylePainter painter(this); - painter.setRenderHint(QPainter::Antialiasing); - QColor penColor = KColorUtils::mix(palette().base().color(), palette().text().color(), 0.3); - // QPainter is bad at drawing lines that are exactly 1px. - // Using QPen::setCosmetic(true) with a 1px pen width - // doesn't look quite as good as just using 1.001px. - qreal penWidth = 1.001; - qreal penMargin = penWidth / 2; - QPen pen(penColor, penWidth); - pen.setCosmetic(true); - QRectF rect = event->rect(); - rect.adjust(penMargin, penMargin, -penMargin, -penMargin); - painter.setBrush(palette().base()); - painter.setPen(pen); - painter.drawRoundedRect(rect, 5, 5); // 5 is the current default Breeze corner radius + QStyleOptionFrame option; + option.initFrom(this); + option.lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &option, this); + option.state = QStyle::State_Enabled | QStyle::State_Sunken; + painter.drawPrimitive(QStyle::PE_FrameLineEdit, option); QWidget::paintEvent(event); } -- cgit v1.3.1