File indexing completed on 2024-04-21 03:55:25

0001 /*
0002     SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz@gmx.at>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "kurlnavigator.h"
0008 #include "kurlnavigatordropdownbutton_p.h"
0009 
0010 #include <QKeyEvent>
0011 #include <QPainter>
0012 #include <QStyleOption>
0013 
0014 namespace KDEPrivate
0015 {
0016 KUrlNavigatorDropDownButton::KUrlNavigatorDropDownButton(KUrlNavigator *parent)
0017     : KUrlNavigatorButtonBase(parent)
0018 {
0019 }
0020 
0021 KUrlNavigatorDropDownButton::~KUrlNavigatorDropDownButton()
0022 {
0023 }
0024 
0025 QSize KUrlNavigatorDropDownButton::sizeHint() const
0026 {
0027     QSize size = KUrlNavigatorButtonBase::sizeHint();
0028     size.setWidth(size.height() / 2);
0029     return size;
0030 }
0031 
0032 void KUrlNavigatorDropDownButton::paintEvent(QPaintEvent *event)
0033 {
0034     Q_UNUSED(event);
0035 
0036     QPainter painter(this);
0037     drawHoverBackground(&painter);
0038 
0039     const QColor fgColor = foregroundColor();
0040 
0041     QStyleOption option;
0042     option.initFrom(this);
0043     option.rect = QRect(0, 0, width(), height());
0044     option.palette = palette();
0045     option.palette.setColor(QPalette::Text, fgColor);
0046     option.palette.setColor(QPalette::WindowText, fgColor);
0047     option.palette.setColor(QPalette::ButtonText, fgColor);
0048 
0049     if (layoutDirection() == Qt::LeftToRight) {
0050         style()->drawPrimitive(QStyle::PE_IndicatorArrowRight, &option, &painter, this);
0051     } else {
0052         style()->drawPrimitive(QStyle::PE_IndicatorArrowLeft, &option, &painter, this);
0053     }
0054 }
0055 
0056 void KUrlNavigatorDropDownButton::keyPressEvent(QKeyEvent *event)
0057 {
0058     switch (event->key()) {
0059     case Qt::Key_Enter:
0060     case Qt::Key_Return:
0061     case Qt::Key_Down:
0062         Q_EMIT clicked();
0063         break;
0064     default:
0065         KUrlNavigatorButtonBase::keyPressEvent(event);
0066     }
0067 }
0068 
0069 } // namespace KDEPrivate
0070 
0071 #include "moc_kurlnavigatordropdownbutton_p.cpp"