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 KUrlNavigatorButtonBase::KUrlNavigatorButtonBase(QWidget* parent) : 00036 QPushButton(parent), 00037 m_active(true), 00038 m_displayHint(0) 00039 { 00040 setFocusPolicy(Qt::NoFocus); 00041 setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed); 00042 setMinimumHeight(parent->minimumHeight()); 00043 00044 connect(this, SIGNAL(pressed()), parent, SLOT(requestActivation())); 00045 } 00046 00047 KUrlNavigatorButtonBase::~KUrlNavigatorButtonBase() 00048 { 00049 } 00050 00051 void KUrlNavigatorButtonBase::setActive(bool active) 00052 { 00053 if (m_active != active) { 00054 m_active = active; 00055 update(); 00056 } 00057 } 00058 00059 bool KUrlNavigatorButtonBase::isActive() const 00060 { 00061 return m_active; 00062 } 00063 00064 void KUrlNavigatorButtonBase::setDisplayHintEnabled(DisplayHint hint, 00065 bool enable) 00066 { 00067 if (enable) { 00068 m_displayHint = m_displayHint | hint; 00069 } else { 00070 m_displayHint = m_displayHint & ~hint; 00071 } 00072 update(); 00073 } 00074 00075 bool KUrlNavigatorButtonBase::isDisplayHintEnabled(DisplayHint hint) const 00076 { 00077 return (m_displayHint & hint) > 0; 00078 } 00079 00080 void KUrlNavigatorButtonBase::enterEvent(QEvent* event) 00081 { 00082 QPushButton::enterEvent(event); 00083 setDisplayHintEnabled(EnteredHint, true); 00084 update(); 00085 } 00086 00087 void KUrlNavigatorButtonBase::leaveEvent(QEvent* event) 00088 { 00089 QPushButton::leaveEvent(event); 00090 setDisplayHintEnabled(EnteredHint, false); 00091 update(); 00092 } 00093 00094 void KUrlNavigatorButtonBase::drawHoverBackground(QPainter* painter) 00095 { 00096 const bool isHighlighted = isDisplayHintEnabled(EnteredHint) || 00097 isDisplayHintEnabled(DraggedHint) || 00098 isDisplayHintEnabled(PopupActiveHint); 00099 00100 QColor backgroundColor = isHighlighted ? palette().color(QPalette::Highlight) : Qt::transparent; 00101 if (!m_active && isHighlighted) { 00102 backgroundColor.setAlpha(128); 00103 } 00104 00105 if (backgroundColor != Qt::transparent) { 00106 // TODO: the backgroundColor should be applied to the style 00107 QStyleOptionViewItemV4 option; 00108 option.initFrom(this); 00109 option.state = QStyle::State_Enabled | QStyle::State_MouseOver; 00110 option.viewItemPosition = QStyleOptionViewItemV4::OnlyOne; 00111 style()->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter, this); 00112 } 00113 } 00114 00115 QColor KUrlNavigatorButtonBase::foregroundColor() const 00116 { 00117 const bool isHighlighted = isDisplayHintEnabled(EnteredHint) || 00118 isDisplayHintEnabled(DraggedHint) || 00119 isDisplayHintEnabled(PopupActiveHint); 00120 00121 QColor foregroundColor = palette().color(foregroundRole()); 00122 00123 int alpha = m_active ? 255 : 128; 00124 if (!m_active && !isHighlighted) { 00125 alpha -= alpha / 4; 00126 } 00127 foregroundColor.setAlpha(alpha); 00128 00129 return foregroundColor; 00130 } 00131 00132 void KUrlNavigatorButtonBase::activate() 00133 { 00134 setActive(true); 00135 } 00136 00137 #include "kurlnavigatorbuttonbase_p.moc"
KDE 4.6 API Reference