• Skip to content
  • Skip to link menu
KDE 4.7 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 namespace KDEPrivate
00031 {
00032 
00033 KUrlNavigatorToggleButton::KUrlNavigatorToggleButton(QWidget* parent) :
00034     KUrlNavigatorButtonBase(parent)
00035 {
00036     setCheckable(true);
00037     connect(this, SIGNAL(toggled(bool)),
00038             this, SLOT(updateToolTip()));
00039     connect(this, SIGNAL(clicked(bool)),
00040             this, SLOT(updateCursor()));
00041     m_pixmap = KIcon("dialog-ok").pixmap(16, 16);
00042     updateToolTip();
00043 }
00044 
00045 KUrlNavigatorToggleButton::~KUrlNavigatorToggleButton()
00046 {
00047 }
00048 
00049 QSize KUrlNavigatorToggleButton::sizeHint() const
00050 {
00051     QSize size = KUrlNavigatorButtonBase::sizeHint();
00052     size.setWidth(m_pixmap.width() + 4);
00053     return size;
00054 }
00055 
00056 void KUrlNavigatorToggleButton::enterEvent(QEvent* event)
00057 {
00058     KUrlNavigatorButtonBase::enterEvent(event);
00059     updateCursor();
00060 }
00061 
00062 void KUrlNavigatorToggleButton::leaveEvent(QEvent* event)
00063 {
00064     KUrlNavigatorButtonBase::leaveEvent(event);
00065     setCursor(Qt::ArrowCursor);
00066 }
00067 
00068 void KUrlNavigatorToggleButton::paintEvent(QPaintEvent* event)
00069 {
00070     QPainter painter(this);
00071     painter.setClipRect(event->rect());
00072 
00073     const int buttonWidth = width();
00074     const int buttonHeight = height();
00075     if (isChecked()) {
00076         const int x = (buttonWidth - m_pixmap.width()) / 2;
00077         const int y = (buttonHeight - m_pixmap.height()) / 2;
00078         painter.drawPixmap(QRect(x, y, m_pixmap.width(), m_pixmap.height()), m_pixmap);
00079     } else if (isDisplayHintEnabled(EnteredHint)) {
00080         painter.setPen(Qt::NoPen);
00081         painter.setBrush(palette().color(foregroundRole()));
00082 
00083         const int verticalGap = 4;
00084         const int caretWidth = 2;
00085         const int x = (layoutDirection() == Qt::LeftToRight) ? 0 : width() - caretWidth;
00086         painter.drawRect(x, verticalGap, caretWidth, buttonHeight - 2 * verticalGap);
00087     }
00088 }
00089 
00090 void KUrlNavigatorToggleButton::updateToolTip()
00091 {
00092     if (isChecked()) {
00093         setToolTip(i18n("Click for Location Navigation"));
00094     } else {
00095         setToolTip(i18n("Click to Edit Location"));
00096     }
00097 }
00098 
00099 void KUrlNavigatorToggleButton::updateCursor()
00100 {
00101     setCursor(isChecked() ? Qt::ArrowCursor : Qt::IBeamCursor);
00102 }
00103 
00104 } // namespace KDEPrivate
00105 
00106 #include "kurlnavigatortogglebutton_p.moc"

KFile

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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.5
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