Dark mode: Fix radio buttons having no outline. Fixes #1900022 [Radio buttons in Windows Dark mode](https://bugs.launchpad.net/calibre/+bug/1900022)

This commit is contained in:
Kovid Goyal 2020-10-16 08:40:31 +05:30
parent cb31fc219d
commit d9cc545f71
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -9,6 +9,7 @@
#include <QStyleOptionToolButton>
#include <QFormLayout>
#include <QDialogButtonBox>
#include <QPainterPath>
#include <algorithm>
#include <qdrawutil.h>
@ -253,6 +254,39 @@ class CalibreStyle: public QProxyStyle {
}
break; // }}}
case PE_IndicatorRadioButton: // {{{
// Fix color used to draw radiobutton outline in dark mode
if (is_color_dark(option->palette.color(QPalette::Window))) {
painter->save();
painter->setBrush((option->state & State_Sunken) ? option->palette.base().color().lighter(320) : option->palette.base().color());
painter->setRenderHint(QPainter::Antialiasing, true);
QPainterPath circle;
const QPointF circleCenter = option->rect.center() + QPoint(1, 1);
const qreal outlineRadius = (option->rect.width() + (option->rect.width() + 1) % 2) / 2.0 - 1;
circle.addEllipse(circleCenter, outlineRadius, outlineRadius);
painter->setPen(QPen(option->palette.window().color().lighter(320)));
if (option->state & State_HasFocus && option->state & State_KeyboardFocusChange) {
QColor highlightedOutline = option->palette.color(QPalette::Highlight).lighter(125);
painter->setPen(QPen(highlightedOutline));
}
painter->drawPath(circle);
if (option->state & (State_On )) {
circle = QPainterPath();
const qreal checkmarkRadius = outlineRadius / 2.32;
circle.addEllipse(circleCenter, checkmarkRadius, checkmarkRadius);
QColor checkMarkColor = option->palette.text().color().lighter(120);
checkMarkColor.setAlpha(200);
painter->setPen(checkMarkColor);
checkMarkColor.setAlpha(180);
painter->setBrush(checkMarkColor);
painter->drawPath(circle);
}
painter->restore();
return;
} else { baseStyle()->drawPrimitive(element, option, painter, widget); }
break; // }}}
case PE_PanelItemViewItem: // {{{
// Highlight the current, selected item with a different background in an item view if the highlight current item property is set
if (option->state & QStyle::State_HasFocus && (vopt = qstyleoption_cast<const QStyleOptionViewItem *>(option)) && widget && widget->property("highlight_current_item").toBool()) {