KFile
kurltogglebutton.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "kurltogglebutton_p.h"
00021 #include "kurlnavigator.h"
00022
00023 #include <kcolorscheme.h>
00024 #include <kicon.h>
00025 #include <klocale.h>
00026
00027 #include <QtGui/QPainter>
00028 #include <QtGui/QKeyEvent>
00029 #include <QtGui/QApplication>
00030
00031 KUrlToggleButton::KUrlToggleButton(KUrlNavigator* parent) :
00032 KUrlButton(parent)
00033 {
00034 setCheckable(true);
00035 connect(this, SIGNAL(toggled(bool)),
00036 this, SLOT(updateToolTip()));
00037 m_pixmap = KIcon("edit-undo").pixmap(16, 16);
00038 updateToolTip();
00039 }
00040
00041 KUrlToggleButton::~KUrlToggleButton()
00042 {
00043 }
00044
00045 QSize KUrlToggleButton::sizeHint() const
00046 {
00047 QSize size = KUrlButton::sizeHint();
00048 size.setWidth(m_pixmap.width() + 4);
00049 return size;
00050 }
00051
00052 void KUrlToggleButton::paintEvent(QPaintEvent* event)
00053 {
00054 QPainter painter(this);
00055 painter.setClipRect(event->rect());
00056
00057 const int buttonWidth = width();
00058 const int buttonHeight = height();
00059 if (isChecked()) {
00060 const int x = (buttonWidth - m_pixmap.width()) / 2;
00061 const int y = (buttonHeight - m_pixmap.height()) / 2;
00062 painter.drawPixmap(QRect(x, y, m_pixmap.width(), m_pixmap.height()), m_pixmap);
00063 } else if (isDisplayHintEnabled(EnteredHint)) {
00064 QColor fgColor = palette().color(foregroundRole());
00065
00066 painter.setPen(Qt::NoPen);
00067 painter.setBrush(fgColor);
00068 painter.drawRect((layoutDirection() == Qt::LeftToRight) ? 0
00069 : width() - 2, 2, 2, buttonHeight - 6);
00070 }
00071 }
00072
00073 void KUrlToggleButton::updateToolTip()
00074 {
00075 if (isChecked()) {
00076 setToolTip(i18n("Click for Location Navigation"));
00077 } else {
00078 setToolTip(i18n("Click to Edit Location"));
00079 }
00080 }
00081
00082 #include "kurltogglebutton_p.moc"