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