File indexing completed on 2024-04-21 04:47:53
0001 /**************************************************************************************** 0002 * Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #include "PopupDropperFactory.h" 0018 0019 #include "MainWindow.h" 0020 #include "PaletteHandler.h" 0021 #include "SvgHandler.h" 0022 #include "core/support/Debug.h" 0023 #include "context/popupdropper/libpud/PopupDropperItem.h" 0024 0025 #include <QAction> 0026 0027 0028 namespace The 0029 { 0030 static PopupDropperFactory* s_PopupDropperFactory_instance = nullptr; 0031 0032 PopupDropperFactory* popupDropperFactory() 0033 { 0034 if( !s_PopupDropperFactory_instance ) 0035 s_PopupDropperFactory_instance = new PopupDropperFactory( The::mainWindow() ); 0036 0037 return s_PopupDropperFactory_instance; 0038 } 0039 } 0040 0041 0042 PopupDropperFactory::PopupDropperFactory( QObject* parent ) 0043 : QObject( parent ) 0044 {} 0045 0046 0047 PopupDropperFactory::~PopupDropperFactory() 0048 { 0049 DEBUG_BLOCK 0050 } 0051 0052 0053 PopupDropper * PopupDropperFactory::createPopupDropper( QWidget * parent, bool ignoreEmptyParent ) 0054 { 0055 DEBUG_BLOCK 0056 0057 // Lazy loading of widgets not currently shown in layout means that parent could be zero 0058 // if this happens, it pops up in its own window -- so detect this 0059 // ignoreEmptyParent is for creating submenus, where you set the initial parent to zero 0060 if( !parent && !ignoreEmptyParent ) 0061 return nullptr; 0062 0063 PopupDropper* pd = new PopupDropper( parent ); 0064 if( !pd ) 0065 return nullptr; 0066 0067 pd->setSvgRenderer( The::svgHandler()->getRenderer( "amarok/images/pud_items.svg" ) ); 0068 pd->setQuitOnDragLeave( false ); 0069 pd->setFadeInTime( 500 ); 0070 pd->setFadeOutTime( 300 ); 0071 //QColor origWindowColor( The::paletteHandler()->palette().color( QPalette::Window ) ); 0072 //QColor windowColor; 0073 //windowColor.setRed( 255 - origWindowColor.red() ); 0074 //windowColor.setBlue( 255 - origWindowColor.blue() ); 0075 //windowColor.setGreen( 255 - origWindowColor.green() ); 0076 QColor windowColor( The::paletteHandler()->palette().color( QPalette::Base ) ); 0077 windowColor.setAlpha( 200 ); 0078 QColor textColor( The::paletteHandler()->palette().color( QPalette::Link ) ); 0079 QColor highlightedTextColor( The::paletteHandler()->palette().color( QPalette::Text ) ); 0080 QColor borderColor( The::paletteHandler()->palette().color( QPalette::Text ) ); 0081 QColor fillColor( borderColor ); 0082 fillColor.setAlpha( 48 ); 0083 pd->setColors( windowColor, textColor, highlightedTextColor, borderColor, fillColor ); 0084 0085 return pd; 0086 } 0087 0088 PopupDropperItem * PopupDropperFactory::createItem( QAction * action ) 0089 { 0090 PopupDropperItem* pdi = new PopupDropperItem(); 0091 pdi->setAction( action ); 0092 QString text = pdi->text(); 0093 text.remove( QChar('&') ); 0094 pdi->setText( text ); 0095 adjustItem( pdi ); 0096 return pdi; 0097 } 0098 0099 void PopupDropperFactory::adjustItem( PopupDropperItem *item ) 0100 { 0101 if( !item ) 0102 return; 0103 QFont font; 0104 font.setPointSize( 16 ); 0105 font.setBold( true ); 0106 item->setFont( font ); 0107 item->setHoverMsecs( 800 ); 0108 QColor hoverIndicatorFillColor( The::paletteHandler()->palette().color( QPalette::Highlight ) ); 0109 hoverIndicatorFillColor.setAlpha( 96 ); 0110 QBrush brush = item->hoverIndicatorFillBrush(); 0111 brush.setColor( hoverIndicatorFillColor ); 0112 item->setHoverIndicatorFillBrush( brush ); 0113 0114 if( item->isSubmenuTrigger() ) 0115 item->setHoverIndicatorShowStyle( PopupDropperItem::OnHover ); 0116 } 0117 0118 void PopupDropperFactory::adjustItems( PopupDropper* pud ) 0119 { 0120 if( !pud ) 0121 return; 0122 pud->forEachItem( adjustItemCallback ); 0123 } 0124 0125 void PopupDropperFactory::adjustItemCallback( void *pdi ) 0126 { 0127 The::popupDropperFactory()->adjustItem( (PopupDropperItem*)pdi ); 0128 } 0129