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