Commit 876b9d26 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Draw a less prominent focus indicator for text labels

Draw a PE_FrameFocusRect primitive instead of a CE_FocusFrame control
for the focus frame. This is an experimental change to check how it
looks on Windows. The Breeze style draws the primitive as a line below
the widget.

GnuPG-bug-id: 6111
parent ccb6f078
Pipeline #209618 passed with stage
in 3 minutes and 4 seconds
......@@ -60,7 +60,12 @@
#include <QFile>
#include <QDir>
#include <QFocusFrame>
#if QT_CONFIG(graphicseffect)
#include <QGraphicsEffect>
#endif
#include <QPointer>
#include <QStyleOption>
#include <QStylePainter>
#include <memory>
#include <KSharedConfig>
......@@ -86,6 +91,63 @@ static QList<QByteArray> default_logging_options()
return result;
}
namespace
{
class FocusFrame : public QFocusFrame
{
Q_OBJECT
public:
using QFocusFrame::QFocusFrame;
protected:
void paintEvent(QPaintEvent *event) override;
};
static QRect effectiveWidgetRect(const QWidget *w)
{
// based on QWidgetPrivate::effectiveRectFor
#if QT_CONFIG(graphicseffect)
if (auto graphicsEffect = w->graphicsEffect(); graphicsEffect && graphicsEffect->isEnabled())
return graphicsEffect->boundingRectFor(w->rect()).toAlignedRect();
#endif // QT_CONFIG(graphicseffect)
return w->rect();
}
static QRect clipRect(const QWidget *w)
{
// based on QWidgetPrivate::clipRect
if (!w->isVisible()) {
return QRect();
}
QRect r = effectiveWidgetRect(w);
int ox = 0;
int oy = 0;
while (w && w->isVisible() && !w->isWindow() && w->parentWidget()) {
ox -= w->x();
oy -= w->y();
w = w->parentWidget();
r &= QRect(ox, oy, w->width(), w->height());
}
return r;
}
void FocusFrame::paintEvent(QPaintEvent *)
{
if (!widget()) {
return;
}
QStylePainter p(this);
QStyleOptionFocusRect option;
initStyleOption(&option);
const int vmargin = style()->pixelMetric(QStyle::PM_FocusFrameVMargin, &option);
const int hmargin = style()->pixelMetric(QStyle::PM_FocusFrameHMargin, &option);
const QRect rect = clipRect(widget()).adjusted(0, 0, hmargin*2, vmargin*2);
p.setClipRect(rect);
p.drawPrimitive(QStyle::PE_FrameFocusRect, option);
}
}
class KleopatraApplication::Private
{
friend class ::KleopatraApplication;
......@@ -146,7 +208,7 @@ private:
public:
bool ignoreNewInstance;
bool firstNewInstance;
QPointer<QFocusFrame> focusFrame;
QPointer<FocusFrame> focusFrame;
QPointer<ConfigureDialog> configureDialog;
QPointer<MainWindow> mainWindow;
SmartCard::ReaderStatus readerStatus;
......@@ -218,7 +280,7 @@ public:
{
if (focusWidget && focusWidget->inherits("QLabel")) {
if (!focusFrame) {
focusFrame = new QFocusFrame{focusWidget};
focusFrame = new FocusFrame{focusWidget};
}
focusFrame->setWidget(focusWidget);
} else if (focusFrame) {
......@@ -734,3 +796,5 @@ void KleopatraApplication::startGpgAgent()
{
Kleo::launchGpgAgent();
}
#include "kleopatraapplication.moc"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment