File indexing completed on 2024-07-21 03:41:22

0001 /*
0002     SPDX-FileCopyrightText: 2006-2010 Peter Penz <peter.penz@gmx.at>
0003     SPDX-FileCopyrightText: 2006 Aaron J. Seigo <aseigo@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KURLNAVIGATORBUTTONBASE_P_H
0009 #define KURLNAVIGATORBUTTONBASE_P_H
0010 
0011 #include <QColor>
0012 #include <QPushButton>
0013 
0014 class QUrl;
0015 class QEvent;
0016 
0017 class KUrlNavigator;
0018 
0019 namespace KDEPrivate
0020 {
0021 /**
0022  * @brief Base class for buttons of the URL navigator.
0023  *
0024  * Buttons of the URL navigator offer an active/inactive
0025  * state and custom display hints.
0026  */
0027 class KUrlNavigatorButtonBase : public QPushButton
0028 {
0029     Q_OBJECT
0030 
0031 public:
0032     explicit KUrlNavigatorButtonBase(KUrlNavigator *parent);
0033     ~KUrlNavigatorButtonBase() override;
0034 
0035     /**
0036      * When having several URL navigator instances, it is important
0037      * to provide a visual difference to indicate which URL navigator
0038      * is active (usecase: split view in Dolphin). The activation state
0039      * is independent from the focus or hover state.
0040      * Per default the URL navigator button is marked as active.
0041      */
0042     void setActive(bool active);
0043     bool isActive() const;
0044 
0045 protected:
0046     enum DisplayHint {
0047         EnteredHint = 1,
0048         DraggedHint = 2,
0049         PopupActiveHint = 4,
0050     };
0051 
0052     enum { BorderWidth = 2 };
0053 
0054     void setDisplayHintEnabled(DisplayHint hint, bool enable);
0055     bool isDisplayHintEnabled(DisplayHint hint) const;
0056 
0057     void focusInEvent(QFocusEvent *event) override;
0058     void focusOutEvent(QFocusEvent *event) override;
0059 
0060     void enterEvent(QEnterEvent *event) override;
0061     void leaveEvent(QEvent *event) override;
0062 
0063     void drawHoverBackground(QPainter *painter);
0064 
0065     /** Returns the foreground color by respecting the current display hint. */
0066     QColor foregroundColor() const;
0067 
0068 private Q_SLOTS:
0069     /** Invokes setActive(true). */
0070     void activate();
0071 
0072 private:
0073     bool m_active;
0074     int m_displayHint;
0075 };
0076 
0077 } // namespace KDEPrivate
0078 
0079 #endif