1 /*****************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
4 * This library is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Library General Public *
6 * License version 2 as published by the Free Software Foundation. *
8 * This library is distributed in the hope that it will be useful, *
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
11 * Library General Public License for more details. *
13 * You should have received a copy of the GNU Library General Public License *
14 * along with this library; see the file COPYING.LIB. If not, write to *
15 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
16 * Boston, MA 02110-1301, USA. *
17 *****************************************************************************/
20 #include "kurltogglebutton_p.h"
21 #include "kurlnavigator.h"
23 #include <kcolorscheme.h>
27 #include <QtGui/QPainter>
28 #include <QtGui/QKeyEvent>
29 #include <QtGui/QApplication>
31 KUrlToggleButton::KUrlToggleButton(KUrlNavigator
* parent
) :
35 connect(this, SIGNAL(toggled(bool)),
36 this, SLOT(updateToolTip()));
37 m_pixmap
= KIcon("edit-undo").pixmap(16, 16);
41 KUrlToggleButton::~KUrlToggleButton()
45 QSize
KUrlToggleButton::sizeHint() const
47 QSize size
= KUrlButton::sizeHint();
48 size
.setWidth(m_pixmap
.width() + 4);
52 void KUrlToggleButton::paintEvent(QPaintEvent
* event
)
54 QPainter
painter(this);
55 painter
.setClipRect(event
->rect());
57 const int buttonWidth
= width();
58 const int buttonHeight
= height();
60 const int x
= (buttonWidth
- m_pixmap
.width()) / 2;
61 const int y
= (buttonHeight
- m_pixmap
.height()) / 2;
62 painter
.drawPixmap(QRect(x
, y
, m_pixmap
.width(), m_pixmap
.height()), m_pixmap
);
63 } else if (isDisplayHintEnabled(EnteredHint
)) {
64 QColor fgColor
= palette().color(foregroundRole());
66 painter
.setPen(Qt::NoPen
);
67 painter
.setBrush(fgColor
);
68 painter
.drawRect((layoutDirection() == Qt::LeftToRight
) ? 0
69 : width() - 2, 2, 2, buttonHeight
- 6);
73 void KUrlToggleButton::updateToolTip()
76 setToolTip(i18n("Click for Location Navigation"));
78 setToolTip(i18n("Click to Edit Location"));
82 #include "kurltogglebutton_p.moc"