• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KFile

kurltogglebutton.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at>                      *
00003  *                                                                           *
00004  * This library is free software; you can redistribute it and/or             *
00005  * modify it under the terms of the GNU Library General Public               *
00006  * License version 2 as published by the Free Software Foundation.           *
00007  *                                                                           *
00008  * This library is distributed in the hope that it will be useful,           *
00009  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00011  * Library General Public License for more details.                          *
00012  *                                                                           *
00013  * You should have received a copy of the GNU Library General Public License *
00014  * along with this library; see the file COPYING.LIB.  If not, write to      *
00015  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,      *
00016  * Boston, MA 02110-1301, USA.                                               *
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"

KFile

Skip menu "KFile"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal