KIO

kurlnavigatordropdownbutton.cpp
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
16namespace KDEPrivate
17{
18KUrlNavigatorDropDownButton::KUrlNavigatorDropDownButton(KUrlNavigator *parent)
19 : KUrlNavigatorButtonBase(parent)
20{
21 setText(i18nc("@action:button opening a list of locations", "Go to Location on Path"));
22}
23
24KUrlNavigatorDropDownButton::~KUrlNavigatorDropDownButton()
25{
26}
27
28QSize KUrlNavigatorDropDownButton::sizeHint() const
29{
30 QSize size = KUrlNavigatorButtonBase::sizeHint();
31 size.setWidth(size.height() / 2);
32 return size;
33}
34
35void KUrlNavigatorDropDownButton::paintEvent(QPaintEvent *event)
36{
37 Q_UNUSED(event);
38
39 QPainter painter(this);
40 drawHoverBackground(&painter);
41
42 const QColor fgColor = foregroundColor();
43
44 QStyleOption option;
45 option.initFrom(this);
46 option.rect = QRect(0, 0, width(), height());
47 option.palette = palette();
48 option.palette.setColor(QPalette::Text, fgColor);
49 option.palette.setColor(QPalette::WindowText, fgColor);
50 option.palette.setColor(QPalette::ButtonText, fgColor);
51
52 if (layoutDirection() == Qt::LeftToRight) {
53 style()->drawPrimitive(QStyle::PE_IndicatorArrowRight, &option, &painter, this);
54 } else {
55 style()->drawPrimitive(QStyle::PE_IndicatorArrowLeft, &option, &painter, this);
56 }
57}
58
59void 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"
Widget that allows to navigate through the paths of an URL.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
int height() const const
void setWidth(int width)
PE_IndicatorArrowRight
void initFrom(const QWidget *widget)
Key_Enter
LeftToRight
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:04:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.