1/*****************************************************************************
2 * Copyright (C) 2006-2010 by Peter Penz <peter.penz@gmx.at> *
3 * Copyright (C) 2006 by Aaron J. Seigo <aseigo@kde.org> *
4 * *
5 * This library is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU Library General Public *
7 * License as published by the Free Software Foundation; either *
8 * version 2 of the License, or (at your option) any later version. *
9 * *
10 * This library is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13 * Library General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU Library General Public License *
16 * along with this library; see the file COPYING.LIB. If not, write to *
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
18 * Boston, MA 02110-1301, USA. *
19 *****************************************************************************/
20
21#ifndef KURLNAVIGATORBUTTONBASE_P_H
22#define KURLNAVIGATORBUTTONBASE_P_H
23
24#include <QtGui/QColor>
25#include <QtGui/QPushButton>
26
27class KUrl;
28class QEvent;
29
30namespace KDEPrivate
31{
32
33/**
34 * @brief Base class for buttons of the URL navigator.
35 *
36 * Buttons of the URL navigator offer an an active/inactive
37 * state and custom display hints.
38 */
39class KUrlNavigatorButtonBase : public QPushButton
40{
41 Q_OBJECT
42
43public:
44 explicit KUrlNavigatorButtonBase(QWidget* parent);
45 virtual ~KUrlNavigatorButtonBase();
46
47 /**
48 * When having several URL navigator instances, it is important
49 * to provide a visual difference to indicate which URL navigator
50 * is active (usecase: split view in Dolphin). The activation state
51 * is independent from the the focus or hover state.
52 * Per default the URL navigator button is marked as active.
53 */
54 void setActive(bool active);
55 bool isActive() const;
56
57protected:
58 enum DisplayHint {
59 EnteredHint = 1,
60 DraggedHint = 2,
61 PopupActiveHint = 4
62 };
63
64 enum { BorderWidth = 2 };
65
66 void setDisplayHintEnabled(DisplayHint hint, bool enable);
67 bool isDisplayHintEnabled(DisplayHint hint) const;
68
69 virtual void focusInEvent(QFocusEvent *event);
70 virtual void focusOutEvent(QFocusEvent *event);
71
72 virtual void enterEvent(QEvent* event);
73 virtual void leaveEvent(QEvent* event);
74
75 void drawHoverBackground(QPainter* painter);
76
77 /** Returns the foreground color by respecting the current display hint. */
78 QColor foregroundColor() const;
79
80private Q_SLOTS:
81 /** Invokes setActive(true). */
82 void activate();
83
84private:
85 bool m_active;
86 int m_displayHint;
87};
88
89} // namespace KDEPrivate
90
91#endif
92