• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KFile

kurlnavigatortogglebutton.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 as published by the Free Software Foundation; either              *
00007  * version 2 of the License, or (at your option) any later version.          *
00008  *                                                                           *
00009  * This library is distributed in the hope that it will be useful,           *
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00012  * Library General Public License for more details.                          *
00013  *                                                                           *
00014  * You should have received a copy of the GNU Library General Public License *
00015  * along with this library; see the file COPYING.LIB.  If not, write to      *
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,      *
00017  * Boston, MA 02110-1301, USA.                                               *
00018  *****************************************************************************/
00019 
00020 #include "kurlnavigatortogglebutton_p.h"
00021 
00022 #include <kcolorscheme.h>
00023 #include <kicon.h>
00024 #include <klocale.h>
00025 
00026 #include <QtGui/QPainter>
00027 #include <QtGui/QKeyEvent>
00028 #include <QtGui/QApplication>
00029 
00030 KUrlNavigatorToggleButton::KUrlNavigatorToggleButton(QWidget* parent) :
00031     KUrlNavigatorButtonBase(parent)
00032 {
00033     setCheckable(true);
00034     connect(this, SIGNAL(toggled(bool)),
00035             this, SLOT(updateToolTip()));
00036     connect(this, SIGNAL(clicked(bool)),
00037             this, SLOT(updateCursor()));
00038     m_pixmap = KIcon("dialog-ok").pixmap(16, 16);
00039     updateToolTip();
00040 }
00041 
00042 KUrlNavigatorToggleButton::~KUrlNavigatorToggleButton()
00043 {
00044 }
00045 
00046 QSize KUrlNavigatorToggleButton::sizeHint() const
00047 {
00048     QSize size = KUrlNavigatorButtonBase::sizeHint();
00049     size.setWidth(m_pixmap.width() + 4);
00050     return size;
00051 }
00052 
00053 void KUrlNavigatorToggleButton::enterEvent(QEvent* event)
00054 {
00055     KUrlNavigatorButtonBase::enterEvent(event);
00056     updateCursor();
00057 }
00058 
00059 void KUrlNavigatorToggleButton::leaveEvent(QEvent* event)
00060 {
00061     KUrlNavigatorButtonBase::leaveEvent(event);
00062     setCursor(Qt::ArrowCursor);
00063 }
00064 
00065 void KUrlNavigatorToggleButton::paintEvent(QPaintEvent* event)
00066 {
00067     QPainter painter(this);
00068     painter.setClipRect(event->rect());
00069 
00070     const int buttonWidth = width();
00071     const int buttonHeight = height();
00072     if (isChecked()) {
00073         const int x = (buttonWidth - m_pixmap.width()) / 2;
00074         const int y = (buttonHeight - m_pixmap.height()) / 2;
00075         painter.drawPixmap(QRect(x, y, m_pixmap.width(), m_pixmap.height()), m_pixmap);
00076     } else if (isDisplayHintEnabled(EnteredHint)) {
00077         painter.setPen(Qt::NoPen);
00078         painter.setBrush(palette().color(foregroundRole()));
00079 
00080         const int verticalGap = 4;
00081         const int caretWidth = 2;
00082         const int x = (layoutDirection() == Qt::LeftToRight) ? 0 : width() - caretWidth;
00083         painter.drawRect(x, verticalGap, caretWidth, buttonHeight - 2 * verticalGap);
00084     }
00085 }
00086 
00087 void KUrlNavigatorToggleButton::updateToolTip()
00088 {
00089     if (isChecked()) {
00090         setToolTip(i18n("Click for Location Navigation"));
00091     } else {
00092         setToolTip(i18n("Click to Edit Location"));
00093     }
00094 }
00095 
00096 void KUrlNavigatorToggleButton::updateCursor()
00097 {
00098     setCursor(isChecked() ? Qt::ArrowCursor : Qt::IBeamCursor);
00099 }
00100 
00101 #include "kurlnavigatortogglebutton_p.moc"

KFile

Skip menu "KFile"
  • Main Page
  • Namespace List
  • 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
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
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