File indexing completed on 2024-04-28 15:26:49

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 #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
0061     void enterEvent(QEnterEvent *event) override;
0062 #else
0063     void enterEvent(QEvent *event) override;
0064 #endif
0065 
0066     void leaveEvent(QEvent *event) override;
0067 
0068     void drawHoverBackground(QPainter *painter);
0069 
0070     /** Returns the foreground color by respecting the current display hint. */
0071     QColor foregroundColor() const;
0072 
0073 private Q_SLOTS:
0074     /** Invokes setActive(true). */
0075     void activate();
0076 
0077 private:
0078     bool m_active;
0079     int m_displayHint;
0080 };
0081 
0082 } // namespace KDEPrivate
0083 
0084 #endif