KFile
kurlnavigatordropdownbutton.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 "kurlnavigatordropdownbutton_p.h" 00021 #include "kurlnavigator.h" 00022 00023 #include <kglobalsettings.h> 00024 00025 #include <QtGui/QKeyEvent> 00026 #include <QtGui/QPainter> 00027 #include <QtGui/QStyleOption> 00028 00029 namespace KDEPrivate 00030 { 00031 00032 KUrlNavigatorDropDownButton::KUrlNavigatorDropDownButton(QWidget* parent) : 00033 KUrlNavigatorButtonBase(parent) 00034 { 00035 } 00036 00037 KUrlNavigatorDropDownButton::~KUrlNavigatorDropDownButton() 00038 { 00039 } 00040 00041 QSize KUrlNavigatorDropDownButton::sizeHint() const 00042 { 00043 QSize size = KUrlNavigatorButtonBase::sizeHint(); 00044 size.setWidth(size.height() / 2); 00045 return size; 00046 } 00047 00048 void KUrlNavigatorDropDownButton::paintEvent(QPaintEvent* event) 00049 { 00050 Q_UNUSED(event); 00051 00052 QPainter painter(this); 00053 drawHoverBackground(&painter); 00054 00055 const QColor fgColor = foregroundColor(); 00056 00057 QStyleOption option; 00058 option.initFrom(this); 00059 option.rect = QRect(0, 0, width(), height()); 00060 option.palette = palette(); 00061 option.palette.setColor(QPalette::Text, fgColor); 00062 option.palette.setColor(QPalette::WindowText, fgColor); 00063 option.palette.setColor(QPalette::ButtonText, fgColor); 00064 00065 if (layoutDirection() == Qt::LeftToRight) { 00066 style()->drawPrimitive(QStyle::PE_IndicatorArrowRight, &option, &painter, this); 00067 } else { 00068 style()->drawPrimitive(QStyle::PE_IndicatorArrowLeft, &option, &painter, this); 00069 } 00070 } 00071 00072 void KUrlNavigatorDropDownButton::keyPressEvent(QKeyEvent* event) 00073 { 00074 switch (event->key()) { 00075 case Qt::Key_Enter: 00076 case Qt::Key_Return: 00077 case Qt::Key_Down: 00078 emit clicked(); 00079 break; 00080 default: 00081 KUrlNavigatorButtonBase::keyPressEvent(event); 00082 } 00083 } 00084 00085 } // namespace KDEPrivate 00086 00087 #include "kurlnavigatordropdownbutton_p.moc"
KDE 4.7 API Reference