]> cloud.milkyroute.net Git - dolphin.git/blob - src/urlbutton.cpp
commited initial version of Dolphin
[dolphin.git] / src / urlbutton.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at) *
3 * Copyright (C) 2006 by Aaron J. Seigo (<aseigo@kde.org>) *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program 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 *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21 #include "urlnavigatorbutton.h"
22 #include <kurl.h>
23 #include <qtooltip.h>
24 #include <qcursor.h>
25 #include <qfontmetrics.h>
26 //Added by qt3to4:
27 #include <QEvent>
28 #include <kurldrag.h>
29 #include <kpopupmenu.h>
30 #include <kiconloader.h>
31 #include <klocale.h>
32
33 #include "urlnavigator.h"
34 #include "dolphin.h"
35
36
37 URLButton::URLButton(URLNavigator* parent)
38 : QPushButton(parent),
39 m_displayHint(0),
40 m_urlNavigator(parent)
41 {
42 setFocusPolicy(Qt::NoFocus);
43 setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
44 setMinimumHeight(parent->minimumHeight());
45
46 connect(this, SIGNAL(clicked()), parent, SLOT(slotRequestActivation()));
47 connect(&Dolphin::mainWin(), SIGNAL(activeViewChanged()),
48 this, SLOT(update()));
49 }
50
51 URLButton::~URLButton()
52 {
53 }
54
55 URLNavigator* URLButton::urlNavigator() const
56 {
57 return m_urlNavigator;
58 }
59
60 void URLButton::setDisplayHintEnabled(DisplayHint hint,
61 bool enable)
62 {
63 if (enable) {
64 m_displayHint = m_displayHint | hint;
65 }
66 else {
67 m_displayHint = m_displayHint & ~hint;
68 }
69 update();
70 }
71
72 bool URLButton::isDisplayHintEnabled(DisplayHint hint) const
73 {
74 return (m_displayHint & hint) > 0;
75 }
76
77 void URLButton::enterEvent(QEvent* event)
78 {
79 QPushButton::enterEvent(event);
80 setDisplayHintEnabled(EnteredHint, true);
81 update();
82 }
83
84 void URLButton::leaveEvent(QEvent* event)
85 {
86 QPushButton::leaveEvent(event);
87 setDisplayHintEnabled(EnteredHint, false);
88 update();
89 }
90
91 QColor URLButton::mixColors(const QColor& c1,
92 const QColor& c2) const
93 {
94 const int Qt::red = (c1.Qt::red() + c2.Qt::red()) / 2;
95 const int Qt::green = (c1.Qt::green() + c2.Qt::green()) / 2;
96 const int Qt::blue = (c1.Qt::blue() + c2.Qt::blue()) / 2;
97 return QColor(Qt::red, Qt::green, Qt::blue);
98 }