File indexing completed on 2024-05-12 16:35:06
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2012 Gopalakrishna Bhat A <gopalakbhat@gmail.com> 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 0020 #include "VideoTool.h" 0021 0022 #include "ui_VideoToolWidget.h" 0023 #include "VideoShape.h" 0024 #include "VideoCollection.h" 0025 #include "SelectVideoWidget.h" 0026 #include "ChangeVideoCommand.h" 0027 #include "FullScreenPlayer.h" 0028 #include "VideoData.h" 0029 0030 #include <KoIcon.h> 0031 #include <KoCanvasBase.h> 0032 #include <KoViewConverter.h> 0033 0034 #include <KoDialog.h> 0035 0036 #include <QUrl> 0037 #include <QPointer> 0038 #include <QPainter> 0039 0040 class VideoToolUI: public QWidget, public Ui::VideoTool 0041 { 0042 public: 0043 VideoToolUI() 0044 { 0045 setupUi(this); 0046 btnPlay->setIcon(koIcon("media-playback-start")); 0047 btnPlay->setToolTip(i18n("Play")); 0048 } 0049 }; 0050 0051 0052 VideoTool::VideoTool(KoCanvasBase *canvas) 0053 : KoToolBase(canvas), 0054 m_videoToolUI(0), 0055 m_videoShape(0) 0056 { 0057 0058 } 0059 0060 VideoTool::~VideoTool() 0061 { 0062 0063 } 0064 0065 void VideoTool::activate(ToolActivation toolActivation, const QSet<KoShape *> &shapes) 0066 { 0067 Q_UNUSED(toolActivation); 0068 0069 foreach (KoShape *shape, shapes) { 0070 if ((m_videoShape = dynamic_cast<VideoShape*>(shape))) 0071 break; 0072 } 0073 0074 if (!m_videoShape) { 0075 emit done(); 0076 return; 0077 } 0078 0079 useCursor(Qt::ArrowCursor); 0080 } 0081 0082 void VideoTool::mousePressEvent(KoPointerEvent *event) 0083 { 0084 Q_UNUSED(event); 0085 } 0086 0087 void VideoTool::mouseMoveEvent(KoPointerEvent *event) 0088 { 0089 Q_UNUSED(event); 0090 } 0091 0092 void VideoTool::mouseReleaseEvent(KoPointerEvent *event) 0093 { 0094 Q_UNUSED(event); 0095 } 0096 0097 void VideoTool::paint(QPainter &painter, const KoViewConverter &converter) 0098 { 0099 Q_UNUSED(painter); 0100 Q_UNUSED(converter); 0101 } 0102 0103 QWidget *VideoTool::createOptionWidget() 0104 { 0105 m_videoToolUI = new VideoToolUI(); 0106 0107 connect(m_videoToolUI->btnVideoFile, SIGNAL(clicked(bool)), this, SLOT(changeUrlPressed())); 0108 connect(m_videoToolUI->btnPlay, SIGNAL(clicked(bool)), this, SLOT(play())); 0109 0110 return m_videoToolUI; 0111 } 0112 0113 void VideoTool::changeUrlPressed() 0114 { 0115 if (!m_videoShape) { 0116 return; 0117 } 0118 0119 QPointer<KoDialog> diag = new KoDialog(); 0120 SelectVideoWidget *fileSelectionWidget = new SelectVideoWidget(diag); 0121 diag->setMainWidget(fileSelectionWidget); 0122 0123 if (diag->exec() == KoDialog::Accepted) { 0124 fileSelectionWidget->accept(); 0125 VideoData *data = 0; 0126 data = m_videoShape->videoCollection()->createExternalVideoData(fileSelectionWidget->selectedUrl(), fileSelectionWidget->saveEmbedded()); 0127 0128 ChangeVideoCommand *command = new ChangeVideoCommand(m_videoShape, data); 0129 canvas()->addCommand(command); 0130 } else { 0131 fileSelectionWidget->cancel(); 0132 } 0133 0134 delete diag; 0135 } 0136 0137 void VideoTool::play() 0138 { 0139 VideoData *videoData = qobject_cast<VideoData*>(m_videoShape->userData()); 0140 Q_ASSERT(videoData); 0141 new FullScreenPlayer(videoData->playableUrl()); 0142 }