1/*
2 SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz@gmx.at>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "kurlnavigator.h"
8#include "kurlnavigatordropdownbutton_p.h"
9
10#include <QKeyEvent>
11#include <QPainter>
12#include <QStyleOption>
13
14namespace KDEPrivate
15{
16KUrlNavigatorDropDownButton::KUrlNavigatorDropDownButton(KUrlNavigator *parent)
17 : KUrlNavigatorButtonBase(parent)
18{
19}
20
21KUrlNavigatorDropDownButton::~KUrlNavigatorDropDownButton()
22{
23}
24
25QSize KUrlNavigatorDropDownButton::sizeHint() const
26{
27 QSize size = KUrlNavigatorButtonBase::sizeHint();
28 size.setWidth(size.height() / 2);
29 return size;
30}
31
32void KUrlNavigatorDropDownButton::paintEvent(QPaintEvent *event)
33{
34 Q_UNUSED(event);
35
36 QPainter painter(this);
37 drawHoverBackground(painter: &painter);
38
39 const QColor fgColor = foregroundColor();
40
41 QStyleOption option;
42 option.initFrom(w: this);
43 option.rect = QRect(0, 0, width(), height());
44 option.palette = palette();
45 option.palette.setColor(acr: QPalette::Text, acolor: fgColor);
46 option.palette.setColor(acr: QPalette::WindowText, acolor: fgColor);
47 option.palette.setColor(acr: QPalette::ButtonText, acolor: fgColor);
48
49 if (layoutDirection() == Qt::LeftToRight) {
50 style()->drawPrimitive(pe: QStyle::PE_IndicatorArrowRight, opt: &option, p: &painter, w: this);
51 } else {
52 style()->drawPrimitive(pe: QStyle::PE_IndicatorArrowLeft, opt: &option, p: &painter, w: this);
53 }
54}
55
56void KUrlNavigatorDropDownButton::keyPressEvent(QKeyEvent *event)
57{
58 switch (event->key()) {
59 case Qt::Key_Enter:
60 case Qt::Key_Return:
61 case Qt::Key_Down:
62 Q_EMIT clicked();
63 break;
64 default:
65 KUrlNavigatorButtonBase::keyPressEvent(event);
66 }
67}
68
69} // namespace KDEPrivate
70
71#include "moc_kurlnavigatordropdownbutton_p.cpp"
72

source code of kio/src/filewidgets/kurlnavigatordropdownbutton.cpp