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 <KLocalizedString> |
11 | |
12 | #include <QKeyEvent> |
13 | #include <QPainter> |
14 | #include <QStyleOption> |
15 | |
16 | namespace KDEPrivate |
17 | { |
18 | KUrlNavigatorDropDownButton::KUrlNavigatorDropDownButton(KUrlNavigator *parent) |
19 | : KUrlNavigatorButtonBase(parent) |
20 | { |
21 | setText(i18nc("@action:button opening a list of locations" , "Go to Location on Path" )); |
22 | } |
23 | |
24 | KUrlNavigatorDropDownButton::~KUrlNavigatorDropDownButton() |
25 | { |
26 | } |
27 | |
28 | QSize KUrlNavigatorDropDownButton::sizeHint() const |
29 | { |
30 | QSize size = KUrlNavigatorButtonBase::sizeHint(); |
31 | size.setWidth(size.height() / 2); |
32 | return size; |
33 | } |
34 | |
35 | void KUrlNavigatorDropDownButton::paintEvent(QPaintEvent *event) |
36 | { |
37 | Q_UNUSED(event); |
38 | |
39 | QPainter painter(this); |
40 | drawHoverBackground(painter: &painter); |
41 | |
42 | const QColor fgColor = foregroundColor(); |
43 | |
44 | QStyleOption option; |
45 | option.initFrom(w: this); |
46 | option.rect = QRect(0, 0, width(), height()); |
47 | option.palette = palette(); |
48 | option.palette.setColor(acr: QPalette::Text, acolor: fgColor); |
49 | option.palette.setColor(acr: QPalette::WindowText, acolor: fgColor); |
50 | option.palette.setColor(acr: QPalette::ButtonText, acolor: fgColor); |
51 | |
52 | if (layoutDirection() == Qt::LeftToRight) { |
53 | style()->drawPrimitive(pe: QStyle::PE_IndicatorArrowRight, opt: &option, p: &painter, w: this); |
54 | } else { |
55 | style()->drawPrimitive(pe: QStyle::PE_IndicatorArrowLeft, opt: &option, p: &painter, w: this); |
56 | } |
57 | } |
58 | |
59 | void KUrlNavigatorDropDownButton::keyPressEvent(QKeyEvent *event) |
60 | { |
61 | switch (event->key()) { |
62 | case Qt::Key_Enter: |
63 | case Qt::Key_Return: |
64 | case Qt::Key_Down: |
65 | Q_EMIT clicked(); |
66 | break; |
67 | default: |
68 | KUrlNavigatorButtonBase::keyPressEvent(event); |
69 | } |
70 | } |
71 | |
72 | } // namespace KDEPrivate |
73 | |
74 | #include "moc_kurlnavigatordropdownbutton_p.cpp" |
75 | |