| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2008 Nikolaj Hald Nielsen <nhnFreespirit@gmail.com> * |
| 3 |
* * |
| 4 |
* This program is free software; you can redistribute it and/or modify * |
| 5 |
* it under the terms of the GNU General Public License as published by * |
| 6 |
* the Free Software Foundation; either version 2 of the License, or * |
| 7 |
* (at your option) any later version. * |
| 8 |
* * |
| 9 |
* This program is distributed in the hope that it will be useful, * |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 12 |
* GNU General Public License for more details. * |
| 13 |
* * |
| 14 |
* You should have received a copy of the GNU General Public License * |
| 15 |
* along with this program; if not, write to the * |
| 16 |
* Free Software Foundation, Inc., * |
| 17 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * |
| 18 |
***************************************************************************/ |
| 19 |
|
| 20 |
#include "PopupDropperFactory.h" |
| 21 |
|
| 22 |
#include "Debug.h" |
| 23 |
#include "ContextView.h" |
| 24 |
#include "PaletteHandler.h" |
| 25 |
#include "context/popupdropper/libpud/PopupDropperAction.h" |
| 26 |
#include "context/popupdropper/libpud/PopupDropperItem.h" |
| 27 |
#include "MainWindow.h" |
| 28 |
#include "SvgHandler.h" |
| 29 |
|
| 30 |
#include <kglobal.h> |
| 31 |
|
| 32 |
|
| 33 |
namespace The |
| 34 |
{ |
| 35 |
static PopupDropperFactory* s_PopupDropperFactory_instance = 0; |
| 36 |
|
| 37 |
PopupDropperFactory* popupDropperFactory() |
| 38 |
{ |
| 39 |
if( !s_PopupDropperFactory_instance ) |
| 40 |
s_PopupDropperFactory_instance = new PopupDropperFactory( The::mainWindow() ); |
| 41 |
|
| 42 |
return s_PopupDropperFactory_instance; |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
PopupDropperFactory::PopupDropperFactory( QObject* parent ) |
| 48 |
: QObject( parent ) |
| 49 |
{} |
| 50 |
|
| 51 |
|
| 52 |
PopupDropperFactory::~PopupDropperFactory() |
| 53 |
{ |
| 54 |
DEBUG_BLOCK |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
PopupDropper * PopupDropperFactory::createPopupDropper( QWidget * parent ) |
| 59 |
{ |
| 60 |
DEBUG_BLOCK |
| 61 |
|
| 62 |
PopupDropper* pd = new PopupDropper( parent ); |
| 63 |
if( !pd ) |
| 64 |
return 0; |
| 65 |
|
| 66 |
pd->setSvgRenderer( The::svgHandler()->getRenderer( "amarok/images/pud_items.svg" ) ); |
| 67 |
pd->setQuitOnDragLeave( false ); |
| 68 |
pd->setFadeInTime( 500 ); |
| 69 |
pd->setFadeOutTime( 300 ); |
| 70 |
//QColor origWindowColor( The::paletteHandler()->palette().color( QPalette::Window ) ); |
| 71 |
//QColor windowColor; |
| 72 |
//windowColor.setRed( 255 - origWindowColor.red() ); |
| 73 |
//windowColor.setBlue( 255 - origWindowColor.blue() ); |
| 74 |
//windowColor.setGreen( 255 - origWindowColor.green() ); |
| 75 |
QColor windowColor( The::paletteHandler()->palette().color( QPalette::Base ) ); |
| 76 |
windowColor.setAlpha( 176 ); |
| 77 |
QColor textColor( The::paletteHandler()->palette().color( QPalette::Link ) ); |
| 78 |
QColor highlightedTextColor( The::paletteHandler()->palette().color( QPalette::LinkVisited ) ); |
| 79 |
QColor borderColor( The::paletteHandler()->palette().color( QPalette::Text ) ); |
| 80 |
QColor fillColor( borderColor ); |
| 81 |
fillColor.setAlpha( 48 ); |
| 82 |
pd->setColors( windowColor, textColor, highlightedTextColor, borderColor, fillColor ); |
| 83 |
|
| 84 |
return pd; |
| 85 |
} |
| 86 |
|
| 87 |
PopupDropper * PopupDropperFactory::createPopupDropper() |
| 88 |
{ |
| 89 |
return createPopupDropper( Context::ContextView::self() ); |
| 90 |
} |
| 91 |
|
| 92 |
PopupDropperItem * PopupDropperFactory::createItem( PopupDropperAction * action ) |
| 93 |
{ |
| 94 |
QFont font; |
| 95 |
font.setPointSize( 16 ); |
| 96 |
font.setBold( true ); |
| 97 |
|
| 98 |
PopupDropperItem* pdi = new PopupDropperItem(); |
| 99 |
pdi->setAction( action ); |
| 100 |
QString text = pdi->text(); |
| 101 |
text.remove( QChar('&') ); |
| 102 |
pdi->setText( text ); |
| 103 |
pdi->setFont( font ); |
| 104 |
pdi->setHoverMsecs( 800 ); |
| 105 |
QColor hoverIndicatorFillColor( The::paletteHandler()->palette().color( QPalette::Highlight ) ); |
| 106 |
hoverIndicatorFillColor.setAlpha( 96 ); |
| 107 |
QBrush brush = pdi->hoverIndicatorFillBrush(); |
| 108 |
brush.setColor( hoverIndicatorFillColor ); |
| 109 |
pdi->setHoverIndicatorFillBrush( brush ); |
| 110 |
|
| 111 |
return pdi; |
| 112 |
} |
| 113 |
|
| 114 |
void PopupDropperFactory::adjustSubmenuItem( PopupDropperItem *item ) |
| 115 |
{ |
| 116 |
if( !item ) |
| 117 |
return; |
| 118 |
|
| 119 |
QFont font; |
| 120 |
font.setPointSize( 16 ); |
| 121 |
font.setBold( true ); |
| 122 |
|
| 123 |
item->setFont( font ); |
| 124 |
item->setHoverMsecs( 800 ); |
| 125 |
item->setHoverIndicatorShowStyle( PopupDropperItem::OnHover ); |
| 126 |
QColor hoverIndicatorFillColor( The::paletteHandler()->palette().color( QPalette::Highlight ) ); |
| 127 |
hoverIndicatorFillColor.setAlpha( 96 ); |
| 128 |
QBrush brush = item->hoverIndicatorFillBrush(); |
| 129 |
brush.setColor( hoverIndicatorFillColor ); |
| 130 |
item->setHoverIndicatorFillBrush( brush ); |
| 131 |
} |