• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.9.5 API Reference
  • 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(QSize(22, 22).expandedTo(iconSize()));
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         drawHoverBackground(&painter);
00077         const int x = (buttonWidth - m_pixmap.width()) / 2;
00078         const int y = (buttonHeight - m_pixmap.height()) / 2;
00079         painter.drawPixmap(QRect(x, y, m_pixmap.width(), m_pixmap.height()), m_pixmap);
00080     } else if (isDisplayHintEnabled(EnteredHint)) {
00081         painter.setPen(Qt::NoPen);
00082         painter.setBrush(palette().color(foregroundRole()));
00083 
00084         const int verticalGap = 4;
00085         const int caretWidth = 2;
00086         const int x = (layoutDirection() == Qt::LeftToRight) ? 0 : width() - caretWidth;
00087         painter.drawRect(x, verticalGap, caretWidth, buttonHeight - 2 * verticalGap);
00088     }
00089 }
00090 
00091 void KUrlNavigatorToggleButton::updateToolTip()
00092 {
00093     if (isChecked()) {
00094         setToolTip(i18n("Click for Location Navigation"));
00095     } else {
00096         setToolTip(i18n("Click to Edit Location"));
00097     }
00098 }
00099 
00100 void KUrlNavigatorToggleButton::updateCursor()
00101 {
00102     setCursor(isChecked() ? Qt::ArrowCursor : Qt::IBeamCursor);
00103 }
00104 
00105 } // namespace KDEPrivate
00106 
00107 #include "kurlnavigatortogglebutton_p.moc"
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Mon Jan 21 2019 12:40:58 by doxygen 1.7.5.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KFile

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

kdelibs-4.9.5 API Reference

Skip menu "kdelibs-4.9.5 API Reference"
  • 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
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal