File indexing completed on 2024-05-12 16:34:16

0001 /* This file is part of the KDE project
0002  * Copyright 2007 Marijn Kruisselbrink <mkruisselbrink@kde.org>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Library General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Library General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Library General Public License
0015  * along with this library; see the file COPYING.LIB.  If not, write to
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  */
0019 #include <QPainter>
0020 #include <QTabWidget>
0021 
0022 #include "MusicDebug.h"
0023 #include <klocalizedstring.h>
0024 
0025 #include <KoCanvasBase.h>
0026 #include <KoSelection.h>
0027 
0028 #include "MusicShape.h"
0029 
0030 #include "MusicTool.h"
0031 
0032 #include "dialogs/PartsWidget.h"
0033 
0034 MusicTool::MusicTool( KoCanvasBase* canvas )
0035     : KoToolBase( canvas ),
0036       m_musicshape(0)
0037 {
0038 }
0039 
0040 MusicTool::~MusicTool()
0041 {
0042 }
0043 
0044 void MusicTool::activate(ToolActivation toolActivation, const QSet<KoShape*> &shapes)
0045 {
0046     Q_UNUSED(toolActivation);
0047     //debugMusic ;
0048 
0049     foreach (KoShape *shape, shapes) {
0050         m_musicshape = dynamic_cast<MusicShape*>( shape );
0051         if ( m_musicshape )
0052             break;
0053     }
0054     if ( !m_musicshape )
0055     {
0056         emit done();
0057         return;
0058     }
0059     emit shapeChanged(m_musicshape);
0060     useCursor(Qt::ArrowCursor);
0061 }
0062 
0063 void MusicTool::deactivate()
0064 {
0065   //debugMusic<<"MusicTool::deactivate";
0066   m_musicshape = 0;
0067 }
0068 
0069 void MusicTool::paint( QPainter& painter, const KoViewConverter& viewConverter )
0070 {
0071     Q_UNUSED( painter );
0072     Q_UNUSED( viewConverter );
0073 }
0074 
0075 void MusicTool::mousePressEvent( KoPointerEvent* )
0076 {
0077 }
0078 
0079 void MusicTool::mouseMoveEvent( KoPointerEvent* )
0080 {
0081 }
0082 
0083 void MusicTool::mouseReleaseEvent( KoPointerEvent* )
0084 {
0085 }
0086 
0087 void MusicTool::addCommand(KUndo2Command* command)
0088 {
0089     canvas()->addCommand(command);
0090 }
0091 
0092 
0093 QWidget * MusicTool::createOptionWidget()
0094 {
0095     QTabWidget *widget = new QTabWidget();
0096 
0097     PartsWidget *pw = new PartsWidget(this, widget);
0098     widget->addTab(pw, i18n("Parts"));
0099 
0100     connect(this, SIGNAL(shapeChanged(MusicShape*)), pw, SLOT(setShape(MusicShape*)));
0101 
0102     if (m_musicshape) pw->setShape(m_musicshape);
0103 
0104     return widget;
0105 
0106 }
0107 
0108 MusicShape* MusicTool::shape()
0109 {
0110     return m_musicshape;
0111 }
0112