File indexing completed on 2024-05-05 04:49:24

0001 /****************************************************************************************
0002  * Copyright (c) 2004 Mark Kretschmann <kretschmann@kde.org>                            *
0003  * Copyright (c) 2007 Dan Meltzer <parallelgrapefruit@gmail.com>                        *
0004  *                                                                                      *
0005  * This program is free software; you can redistribute it and/or modify it under        *
0006  * the terms of the GNU General Public License as published by the Free Software        *
0007  * Foundation; either version 2 of the License, or (at your option) any later           *
0008  * version.                                                                             *
0009  *                                                                                      *
0010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0012  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0013  *                                                                                      *
0014  * You should have received a copy of the GNU General Public License along with         *
0015  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0016  ****************************************************************************************/
0017 
0018 #include "AnalyzerWidget.h"
0019 
0020 #include "core/support/Amarok.h"
0021 #include "amarokconfig.h"
0022 #include "core/support/Debug.h"
0023 #include "analyzerbase.h"
0024 #include "socketserver.h"
0025 
0026 #include <QIcon>
0027 #include <KLocale>
0028 #include <QMenu>
0029 
0030 AnalyzerWidget::AnalyzerWidget( QWidget *parent )
0031     : QWidget( parent )
0032     , m_child( 0 )
0033 {
0034     setObjectName(  "AnalyzerWidget" );
0035     setToolTip( i18n( "Click for more analyzers" ) );
0036     setContentsMargins(0,0,0,0);
0037     changeAnalyzer();
0038 }
0039 
0040 void
0041 AnalyzerWidget::resizeEvent( QResizeEvent *)
0042 {
0043     m_child->resize( size() );
0044 }
0045 
0046 void AnalyzerWidget::changeAnalyzer()
0047 {
0048     delete m_child;
0049     m_child = Analyzer::Factory::createPlaylistAnalyzer( this );
0050     m_child->setObjectName( "ToolBarAnalyzer" );
0051     m_child->resize( size() );
0052     m_child->show();
0053 }
0054 
0055 void
0056 AnalyzerWidget::mousePressEvent( QMouseEvent *e)
0057 {
0058     if( e->button() == Qt::LeftButton ) {
0059         AmarokConfig::setCurrentAnalyzer( AmarokConfig::currentAnalyzer() + 1 );
0060         changeAnalyzer();
0061     }
0062 }
0063 
0064 void
0065 AnalyzerWidget::contextMenuEvent( QContextMenuEvent *e)
0066 {
0067 #if defined HAVE_LIBVISUAL
0068     QMenu menu;
0069     menu.addAction( QIcon::fromTheme( "view-media-visualization-amarok" ), i18n("&Visualizations"),
0070                            Vis::Selector::instance(), SLOT(show()) );
0071 
0072     menu.exec( mapToGlobal( e->pos() ) );
0073 #else
0074     Q_UNUSED(e);
0075 #endif
0076 }
0077