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 <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);
38
39 const QColor fgColor = foregroundColor();
40
41 QStyleOption option;
42 option.initFrom(this);
43 option.rect = QRect(0, 0, width(), height());
44 option.palette = palette();
45 option.palette.setColor(QPalette::Text, fgColor);
46 option.palette.setColor(QPalette::WindowText, fgColor);
47 option.palette.setColor(QPalette::ButtonText, fgColor);
48
49 if (layoutDirection() == Qt::LeftToRight) {
50 style()->drawPrimitive(QStyle::PE_IndicatorArrowRight, &option, &painter, this);
51 } else {
52 style()->drawPrimitive(QStyle::PE_IndicatorArrowLeft, &option, &painter, 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"
Widget that allows to navigate through the paths of an URL.
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 Tue Mar 26 2024 11:18:52 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.