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

KFile

kurlnavigatorbuttonbase.cpp
Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Copyright (C) 2006-2010 by Peter Penz <peter.penz@gmx.at>                 *
00003  * Copyright (C) 2006 by Aaron J. Seigo <aseigo@kde.org>                     *
00004  *                                                                           *
00005  * This library is free software; you can redistribute it and/or             *
00006  * modify it under the terms of the GNU Library General Public               *
00007  * License as published by the Free Software Foundation; either              *
00008  * version 2 of the License, or (at your option) any later version.          *
00009  *                                                                           *
00010  * This library is distributed in the hope that it will be useful,           *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00013  * Library General Public License for more details.                          *
00014  *                                                                           *
00015  * You should have received a copy of the GNU Library General Public License *
00016  * along with this library; see the file COPYING.LIB.  If not, write to      *
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,      *
00018  * Boston, MA 02110-1301, USA.                                               *
00019  *****************************************************************************/
00020 
00021 #include "kurlnavigatorbuttonbase_p.h"
00022 
00023 #include <kcolorscheme.h>
00024 #include <kicon.h>
00025 #include <klocale.h>
00026 #include <kmenu.h>
00027 #include <kurl.h>
00028 
00029 #include <QApplication>
00030 #include <QClipboard>
00031 #include <QMimeData>
00032 #include <QStyle>
00033 #include <QStyleOptionFocusRect>
00034 
00035 namespace KDEPrivate
00036 {
00037 
00038 KUrlNavigatorButtonBase::KUrlNavigatorButtonBase(QWidget* parent) :
00039     QPushButton(parent),
00040     m_active(true),
00041     m_displayHint(0)
00042 {
00043     setFocusPolicy(Qt::TabFocus);
00044     setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed);
00045     setMinimumHeight(parent->minimumHeight());
00046 
00047     connect(this, SIGNAL(pressed()), parent, SLOT(requestActivation()));
00048 }
00049 
00050 KUrlNavigatorButtonBase::~KUrlNavigatorButtonBase()
00051 {
00052 }
00053 
00054 void KUrlNavigatorButtonBase::setActive(bool active)
00055 {
00056     if (m_active != active) {
00057         m_active = active;
00058         update();
00059     }
00060 }
00061 
00062 bool KUrlNavigatorButtonBase::isActive() const
00063 {
00064     return m_active;
00065 }
00066 
00067 void KUrlNavigatorButtonBase::setDisplayHintEnabled(DisplayHint hint,
00068                                        bool enable)
00069 {
00070     if (enable) {
00071         m_displayHint = m_displayHint | hint;
00072     } else {
00073         m_displayHint = m_displayHint & ~hint;
00074     }
00075     update();
00076 }
00077 
00078 bool KUrlNavigatorButtonBase::isDisplayHintEnabled(DisplayHint hint) const
00079 {
00080     return (m_displayHint & hint) > 0;
00081 }
00082 
00083 void KUrlNavigatorButtonBase::focusInEvent(QFocusEvent *event)
00084 {
00085     setDisplayHintEnabled(EnteredHint, true);
00086     QPushButton::focusInEvent(event);
00087 }
00088 
00089 void KUrlNavigatorButtonBase::focusOutEvent(QFocusEvent *event)
00090 {
00091     setDisplayHintEnabled(EnteredHint, false);
00092     QPushButton::focusOutEvent(event);
00093 }
00094 
00095 void KUrlNavigatorButtonBase::enterEvent(QEvent* event)
00096 {
00097     QPushButton::enterEvent(event);
00098     setDisplayHintEnabled(EnteredHint, true);
00099     update();
00100 }
00101 
00102 void KUrlNavigatorButtonBase::leaveEvent(QEvent* event)
00103 {
00104     QPushButton::leaveEvent(event);
00105     setDisplayHintEnabled(EnteredHint, false);
00106     update();
00107 }
00108 
00109 void KUrlNavigatorButtonBase::drawHoverBackground(QPainter* painter)
00110 {
00111     const bool isHighlighted = isDisplayHintEnabled(EnteredHint) ||
00112                                isDisplayHintEnabled(DraggedHint) ||
00113                                isDisplayHintEnabled(PopupActiveHint);
00114 
00115     QColor backgroundColor = isHighlighted ? palette().color(QPalette::Highlight) : Qt::transparent;
00116     if (!m_active && isHighlighted) {
00117         backgroundColor.setAlpha(128);
00118     }
00119 
00120     if (backgroundColor != Qt::transparent) {
00121         // TODO: the backgroundColor should be applied to the style
00122         QStyleOptionViewItemV4 option;
00123         option.initFrom(this);
00124         option.state = QStyle::State_Enabled | QStyle::State_MouseOver;
00125         option.viewItemPosition = QStyleOptionViewItemV4::OnlyOne;
00126         style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, this);
00127     }
00128 }
00129 
00130 QColor KUrlNavigatorButtonBase::foregroundColor() const
00131 {
00132     const bool isHighlighted = isDisplayHintEnabled(EnteredHint) ||
00133                                isDisplayHintEnabled(DraggedHint) ||
00134                                isDisplayHintEnabled(PopupActiveHint);
00135 
00136     QColor foregroundColor = palette().color(foregroundRole());
00137 
00138     int alpha = m_active ? 255 : 128;
00139     if (!m_active && !isHighlighted) {
00140         alpha -= alpha / 4;
00141     }
00142     foregroundColor.setAlpha(alpha);
00143 
00144     return foregroundColor;
00145 }
00146 
00147 void KUrlNavigatorButtonBase::activate()
00148 {
00149     setActive(true);
00150 }
00151 
00152 } // namespace KDEPrivate
00153 
00154 #include "kurlnavigatorbuttonbase_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