diff --git a/src/adaptors/UBCFFSubsetAdaptor.cpp b/src/adaptors/UBCFFSubsetAdaptor.cpp index 016af489..f4993b9a 100644 --- a/src/adaptors/UBCFFSubsetAdaptor.cpp +++ b/src/adaptors/UBCFFSubsetAdaptor.cpp @@ -26,8 +26,7 @@ #include "domain/UBGraphicsTextItem.h" #include "domain/UBGraphicsSvgItem.h" #include "domain/UBGraphicsPixmapItem.h" -#include "domain/UBGraphicsVideoItem.h" -#include "domain/UBGraphicsAudioItem.h" +#include "domain/UBGraphicsMediaItem.h" #include "domain/UBGraphicsWidgetItem.h" #include "domain/UBGraphicsTextItem.h" #include "domain/UBGraphicsTextItemDelegate.h" @@ -823,7 +822,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgAudio(const QDomElement &ele ->addAudioFileToDocument(mCurrentScene->document(), concreteUrl.toLocalFile(), uuid)); #endif - UBGraphicsAudioItem *audioItem = mCurrentScene->addAudio(concreteUrl, false); + UBGraphicsMediaItem *audioItem = mCurrentScene->addAudio(concreteUrl, false); QTransform transform; QString textTransform = parentOfAudio.attribute(aTransform); @@ -866,7 +865,7 @@ bool UBCFFSubsetAdaptor::UBCFFSubsetReader::parseSvgVideo(const QDomElement &ele ->addVideoFileToDocument(mCurrentScene->document(), concreteUrl.toLocalFile(), uuid)); #endif - UBGraphicsVideoItem *videoItem = mCurrentScene->addVideo(concreteUrl, false); + UBGraphicsMediaItem *videoItem = mCurrentScene->addVideo(concreteUrl, false); QTransform transform; QString textTransform = element.attribute(aTransform); diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 286d148d..2d4be84f 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -22,8 +22,7 @@ #include "domain/UBGraphicsPixmapItem.h" #include "domain/UBGraphicsProxyWidget.h" #include "domain/UBGraphicsPolygonItem.h" -#include "domain/UBGraphicsVideoItem.h" -#include "domain/UBGraphicsAudioItem.h" +#include "domain/UBGraphicsMediaItem.h" #include "domain/UBGraphicsWidgetItem.h" #include "domain/UBGraphicsPDFItem.h" #include "domain/UBGraphicsTextItem.h" @@ -639,7 +638,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() } else if (mXmlReader.name() == "audio") { - UBGraphicsAudioItem* audioItem = audioItemFromSvg(); + UBGraphicsMediaItem* audioItem = audioItemFromSvg(); if (audioItem) { @@ -660,7 +659,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene() } else if (mXmlReader.name() == "video") { - UBGraphicsVideoItem* videoItem = videoItemFromSvg(); + UBGraphicsMediaItem* videoItem = videoItemFromSvg(); if (videoItem) { @@ -1132,17 +1131,14 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex) continue; } - UBGraphicsVideoItem *videoItem = qgraphicsitem_cast (item); + UBGraphicsMediaItem *mediaItem = qgraphicsitem_cast (item); - if (videoItem && videoItem->isVisible()) + if (mediaItem && mediaItem->isVisible()) { - videoItemToLinkedVideo(videoItem); - continue; - } - - UBGraphicsAudioItem* audioItem = qgraphicsitem_cast (item); - if (audioItem && audioItem->isVisible()) { - audioItemToLinkedAudio(audioItem); + if (UBGraphicsMediaItem::mediaType_Video == mediaItem->getMediaType()) + videoItemToLinkedVideo(mediaItem); + else + audioItemToLinkedAudio(mediaItem); continue; } @@ -1949,7 +1945,7 @@ UBGraphicsPDFItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::pdfItemFromPDF() return pdfItem; } -void UBSvgSubsetAdaptor::UBSvgSubsetWriter::audioItemToLinkedAudio(UBGraphicsAudioItem* audioItem) +void UBSvgSubsetAdaptor::UBSvgSubsetWriter::audioItemToLinkedAudio(UBGraphicsMediaItem* audioItem) { mXmlWriter.writeStartElement("audio"); @@ -1967,7 +1963,7 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::audioItemToLinkedAudio(UBGraphicsAud } -void UBSvgSubsetAdaptor::UBSvgSubsetWriter::videoItemToLinkedVideo(UBGraphicsVideoItem* videoItem) +void UBSvgSubsetAdaptor::UBSvgSubsetWriter::videoItemToLinkedVideo(UBGraphicsMediaItem* videoItem) { /* w3c sample * @@ -1991,7 +1987,7 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::videoItemToLinkedVideo(UBGraphicsVid mXmlWriter.writeEndElement(); } -UBGraphicsAudioItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::audioItemFromSvg() +UBGraphicsMediaItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::audioItemFromSvg() { QStringRef audioHref = mXmlReader.attributes().value(nsXLink, "href"); @@ -2011,7 +2007,11 @@ UBGraphicsAudioItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::audioItemFromSvg() href = mDocumentPath + "/" + href.right(href.length() - indexOfAudioDirectory); } - UBGraphicsAudioItem* audioItem = new UBGraphicsAudioItem(QUrl::fromLocalFile(href)); + UBGraphicsMediaItem* audioItem = new UBGraphicsMediaItem(QUrl::fromLocalFile(href)); + if(audioItem){ + audioItem->connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), audioItem, SLOT(activeSceneChanged())); + } + graphicsItemFromSvg(audioItem); QStringRef ubPos = mXmlReader.attributes().value(mNamespaceUri, "position"); @@ -2025,7 +2025,7 @@ UBGraphicsAudioItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::audioItemFromSvg() return audioItem; } -UBGraphicsVideoItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::videoItemFromSvg() +UBGraphicsMediaItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::videoItemFromSvg() { QStringRef videoHref = mXmlReader.attributes().value(nsXLink, "href"); @@ -2045,7 +2045,11 @@ UBGraphicsVideoItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::videoItemFromSvg() href = mDocumentPath + "/" + href.right(href.length() - indexOfAudioDirectory); } - UBGraphicsVideoItem* videoItem = new UBGraphicsVideoItem(href); + UBGraphicsMediaItem* videoItem = new UBGraphicsMediaItem(QUrl::fromLocalFile(href)); + if(videoItem){ + videoItem->connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), videoItem, SLOT(activeSceneChanged())); + } + graphicsItemFromSvg(videoItem); QStringRef ubPos = mXmlReader.attributes().value(mNamespaceUri, "position"); diff --git a/src/adaptors/UBSvgSubsetAdaptor.h b/src/adaptors/UBSvgSubsetAdaptor.h index d3b39c37..517f036a 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.h +++ b/src/adaptors/UBSvgSubsetAdaptor.h @@ -26,8 +26,7 @@ class UBGraphicsPolygonItem; class UBGraphicsPixmapItem; class UBGraphicsPDFItem; class UBGraphicsWidgetItem; -class UBGraphicsVideoItem; -class UBGraphicsAudioItem; +class UBGraphicsMediaItem; class UBGraphicsAppleWidgetItem; class UBGraphicsW3CWidgetItem; class UBGraphicsTextItem; @@ -119,9 +118,9 @@ class UBSvgSubsetAdaptor UBGraphicsPDFItem* pdfItemFromPDF(); - UBGraphicsVideoItem* videoItemFromSvg(); + UBGraphicsMediaItem* videoItemFromSvg(); - UBGraphicsAudioItem* audioItemFromSvg(); + UBGraphicsMediaItem* audioItemFromSvg(); UBGraphicsAppleWidgetItem* graphicsAppleWidgetFromSvg(); @@ -218,8 +217,8 @@ class UBSvgSubsetAdaptor void pixmapItemToLinkedImage(UBGraphicsPixmapItem *pixmapItem); void svgItemToLinkedSvg(UBGraphicsSvgItem *svgItem); void pdfItemToLinkedPDF(UBGraphicsPDFItem *pdfItem); - void videoItemToLinkedVideo(UBGraphicsVideoItem *videoItem); - void audioItemToLinkedAudio(UBGraphicsAudioItem* audioItem); + void videoItemToLinkedVideo(UBGraphicsMediaItem *videoItem); + void audioItemToLinkedAudio(UBGraphicsMediaItem *audioItem); void graphicsItemToSvg(QGraphicsItem *item); void graphicsAppleWidgetToSvg(UBGraphicsAppleWidgetItem *item); void graphicsW3CWidgetToSvg(UBGraphicsW3CWidgetItem *item); diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 53802ca6..85872574 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -44,8 +44,7 @@ #include "domain/UBGraphicsProxyWidget.h" #include "domain/UBGraphicsSvgItem.h" #include "domain/UBGraphicsWidgetItem.h" -#include "domain/UBGraphicsVideoItem.h" -#include "domain/UBGraphicsAudioItem.h" +#include "domain/UBGraphicsMediaItem.h" #include "domain/UBGraphicsPDFItem.h" #include "domain/UBW3CWidget.h" #include "domain/UBGraphicsTextItem.h" @@ -951,27 +950,27 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString { qDebug() << "accepting mime type" << mimeType << "as video"; - UBGraphicsVideoItem *videoItem = 0; + UBGraphicsMediaItem *mediaVideoItem = 0; if (pData.length() > 0) { QUuid uuid = QUuid::createUuid(); QUrl url = QUrl::fromLocalFile(UBPersistenceManager::persistenceManager() - ->addVideoFileToDocument(mActiveDocument, sourceUrl, pData, uuid)); + ->addVideoFileToDocument(mActiveDocument, sourceUrl, pData, uuid)); - videoItem = mActiveScene->addVideo(url, false, pPos); + mediaVideoItem = mActiveScene->addMedia(url, false, pPos); - videoItem->setSourceUrl(sourceUrl); - videoItem->setUuid(uuid); + mediaVideoItem->setSourceUrl(sourceUrl); + mediaVideoItem->setUuid(uuid); } else { - videoItem = addVideo(sourceUrl, false, pPos); + mediaVideoItem = addVideo(sourceUrl, false, pPos); } - if(videoItem){ - connect(this, SIGNAL(activeSceneChanged()), videoItem, SLOT(activeSceneChanged())); + if(mediaVideoItem){ + connect(this, SIGNAL(activeSceneChanged()), mediaVideoItem, SLOT(activeSceneChanged())); } UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); @@ -980,27 +979,27 @@ void UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString { qDebug() << "accepting mime type" << mimeType << "as audio"; - UBGraphicsAudioItem *audioItem = 0; + UBGraphicsMediaItem *audioMediaItem = 0; if (pData.length() > 0) { QUuid uuid = QUuid::createUuid(); QUrl url = QUrl::fromLocalFile(UBPersistenceManager::persistenceManager() - ->addAudioFileToDocument(mActiveDocument, sourceUrl, pData, uuid)); + ->addVideoFileToDocument(mActiveDocument, sourceUrl, pData, uuid)); - audioItem = mActiveScene->addAudio(url, false, pPos); + audioMediaItem = mActiveScene->addMedia(url, false, pPos); - audioItem->setSourceUrl(sourceUrl); - audioItem->setUuid(uuid); + audioMediaItem->setSourceUrl(sourceUrl); + audioMediaItem->setUuid(uuid); } else { - audioItem = addAudio(sourceUrl, false, pPos); + audioMediaItem = addAudio(sourceUrl, false, pPos); } - if(audioItem){ - connect(this, SIGNAL(activeSceneChanged()), audioItem, SLOT(activeSceneChanged())); + if(audioMediaItem){ + connect(this, SIGNAL(activeSceneChanged()), audioMediaItem, SLOT(activeSceneChanged())); } UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); @@ -1805,7 +1804,7 @@ void UBBoardController::controlViewShown() } -UBGraphicsVideoItem* UBBoardController::addVideo(const QUrl& pSourceUrl, bool startPlay, const QPointF& pos) +UBGraphicsMediaItem* UBBoardController::addVideo(const QUrl& pSourceUrl, bool startPlay, const QPointF& pos) { QUuid uuid = QUuid::createUuid(); QUrl concreteUrl = pSourceUrl; @@ -1818,7 +1817,7 @@ UBGraphicsVideoItem* UBBoardController::addVideo(const QUrl& pSourceUrl, bool st ->addVideoFileToDocument(mActiveDocument, pSourceUrl.toLocalFile(), uuid)); #endif - UBGraphicsVideoItem* vi = mActiveScene->addVideo(concreteUrl, startPlay, pos); + UBGraphicsMediaItem* vi = mActiveScene->addMedia(concreteUrl, startPlay, pos); mActiveDocument->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); if (vi) { @@ -1830,7 +1829,7 @@ UBGraphicsVideoItem* UBBoardController::addVideo(const QUrl& pSourceUrl, bool st } -UBGraphicsAudioItem* UBBoardController::addAudio(const QUrl& pSourceUrl, bool startPlay, const QPointF& pos) +UBGraphicsMediaItem* UBBoardController::addAudio(const QUrl& pSourceUrl, bool startPlay, const QPointF& pos) { QUuid uuid = QUuid::createUuid(); QUrl concreteUrl = pSourceUrl; @@ -1843,15 +1842,15 @@ UBGraphicsAudioItem* UBBoardController::addAudio(const QUrl& pSourceUrl, bool st ->addAudioFileToDocument(mActiveDocument, pSourceUrl.toLocalFile(), uuid)); #endif - UBGraphicsAudioItem* vi = mActiveScene->addAudio(concreteUrl, startPlay, pos); + UBGraphicsMediaItem* ai = mActiveScene->addMedia(concreteUrl, startPlay, pos); mActiveDocument->setMetaData(UBSettings::documentUpdatedAt, UBStringUtils::toUtcIsoDateTime(QDateTime::currentDateTime())); - if (vi){ - vi->setUuid(uuid); - vi->setSourceUrl(pSourceUrl); + if (ai){ + ai->setUuid(uuid); + ai->setSourceUrl(pSourceUrl); } - return vi; + return ai; } diff --git a/src/board/UBBoardController.h b/src/board/UBBoardController.h index c0d9aed4..aa19c5b2 100644 --- a/src/board/UBBoardController.h +++ b/src/board/UBBoardController.h @@ -33,6 +33,7 @@ class UBToolWidget; class UBVersion; class UBSoftwareUpdate; class UBSoftwareUpdateDialog; +class UBGraphicsMediaItem; class UBGraphicsVideoItem; class UBGraphicsAudioItem; class UBGraphicsWidgetItem; @@ -204,8 +205,8 @@ class UBBoardController : public QObject void grabScene(const QRectF& pSceneRect); void controlViewHidden(); void controlViewShown(); - UBGraphicsVideoItem* addVideo(const QUrl& pUrl, bool startPlay, const QPointF& pos); - UBGraphicsAudioItem* addAudio(const QUrl& pUrl, bool startPlay, const QPointF& pos); + UBGraphicsMediaItem* addVideo(const QUrl& pUrl, bool startPlay, const QPointF& pos); + UBGraphicsMediaItem* addAudio(const QUrl& pUrl, bool startPlay, const QPointF& pos); UBGraphicsWidgetItem *addW3cWidget(const QUrl& pUrl, const QPointF& pos); void cut(); diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index e3f1e8bb..4f8eddab 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -47,8 +47,7 @@ #include "domain/UBGraphicsPDFItem.h" #include "domain/UBGraphicsPolygonItem.h" #include "domain/UBItem.h" -#include "domain/UBGraphicsVideoItem.h" -#include "domain/UBGraphicsAudioItem.h" +#include "domain/UBGraphicsMediaItem.h" #include "domain/UBGraphicsSvgItem.h" #include "domain/ubgraphicsgroupcontaineritem.h" #include "domain/UBGraphicsStrokesGroup.h" @@ -560,8 +559,7 @@ UBBoardView::mouseMoveEvent (QMouseEvent *event) if (item->type() == UBGraphicsW3CWidgetItem::Type || item->type() == UBGraphicsPixmapItem::Type - || item->type() == UBGraphicsVideoItem::Type - || item->type() == UBGraphicsAudioItem::Type + || item->type() == UBGraphicsMediaItem::Type || item->type() == UBGraphicsSvgItem::Type || item->type() == UBGraphicsTextItem::Type || item->type() == UBGraphicsStrokesGroup::Type) { diff --git a/src/board/UBLibraryController.cpp b/src/board/UBLibraryController.cpp index 04034161..bbdeec01 100644 --- a/src/board/UBLibraryController.cpp +++ b/src/board/UBLibraryController.cpp @@ -28,7 +28,7 @@ #include "domain/UBGraphicsScene.h" #include "domain/UBGraphicsSvgItem.h" #include "domain/UBGraphicsPixmapItem.h" -#include "domain/UBGraphicsVideoItem.h" +#include "domain/UBGraphicsMediaItem.h" #include "domain/UBGraphicsWidgetItem.h" #include "tools/UBToolsManager.h" @@ -698,7 +698,7 @@ void UBLibraryController::addVideosToCurrentPage(const QList& videos) mLastItemOffsetIndex++; mLastItemOffsetIndex = qMin(mLastItemOffsetIndex, 5); - UBGraphicsVideoItem* itemInScene = UBApplication::boardController->addVideo(url, false, pos); + UBGraphicsMediaItem* itemInScene = UBApplication::boardController->addVideo(url, false, pos); itemInScene->setPos(QPoint(pos.x() + 50 * mLastItemOffsetIndex, pos.y() + 50 * mLastItemOffsetIndex)); } } diff --git a/src/core/UB.h b/src/core/UB.h index ab8d3e9f..46fa6e8c 100644 --- a/src/core/UB.h +++ b/src/core/UB.h @@ -111,8 +111,7 @@ struct UBGraphicsItemType PolygonItemType = QGraphicsItem::UserType + 1, PixmapItemType, SvgItemType, - VideoItemType, - AudioItemType, + MediaItemType, AppleWidgetItemType, PDFItemType, TextItemType, diff --git a/src/domain/UBGraphicsAudioItem.cpp b/src/domain/UBGraphicsAudioItem.cpp index fcee5e06..e69de29b 100644 --- a/src/domain/UBGraphicsAudioItem.cpp +++ b/src/domain/UBGraphicsAudioItem.cpp @@ -1,128 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "UBGraphicsAudioItem.h" -#include "UBGraphicsAudioItemDelegate.h" -#include "UBGraphicsDelegateFrame.h" - -#include "core/memcheck.h" - -UBGraphicsAudioItem::UBGraphicsAudioItem(const QUrl& pAudioFileUrl, QGraphicsItem *parent): - UBGraphicsMediaItem(pAudioFileUrl,parent) -{ - update(); - - mAudioOutput = new Phonon::AudioOutput ( Phonon::MusicCategory, this ); - mMediaObject = new Phonon::MediaObject ( this ); - mMediaObject->setTickInterval ( 1000 ); - Phonon::createPath ( mMediaObject, mAudioOutput ); - - mMediaObject->clearQueue(); - mSource = Phonon::MediaSource(pAudioFileUrl); - mMediaObject->setCurrentSource (mSource ); - - connect (mMediaObject,SIGNAL ( tick ( qint64 ) ), this, SLOT ( tick ( qint64 ) ) ); - connect(mMediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(onStateChanged(Phonon::State,Phonon::State))); - - mAudioWidget = new QWidget(); - - mSeekSlider = new Phonon::SeekSlider ( mAudioWidget ); - mSeekSlider->setMediaObject ( mMediaObject ); - - QPalette palette; - palette.setBrush ( QPalette::Light, Qt::darkGray ); - - mTimeLcd = new QLCDNumber; - mTimeLcd->setPalette ( palette ); - mTimeLcd->display ( "00:00" ); - - QHBoxLayout *seekerLayout = new QHBoxLayout; - seekerLayout->addWidget ( mSeekSlider ); - seekerLayout->addWidget ( mTimeLcd ); - - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addLayout ( seekerLayout ); - - mAudioWidget->setLayout ( mainLayout ); - setWidget ( mAudioWidget ); - - UBGraphicsAudioItemDelegate* delegate = new UBGraphicsAudioItemDelegate ( this, mMediaObject ); - delegate->init(); - setDelegate ( delegate ); - - mDelegate->frame()->setOperationMode ( UBGraphicsDelegateFrame::Resizing ); - - setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly - -} - -void UBGraphicsAudioItem::onStateChanged(Phonon::State newState, Phonon::State oldState) -{ - qDebug() << "STATE CHANGED!"; - qDebug() << "old state:" << oldState; - qDebug() << "new state:" << newState; - - if(oldState == Phonon::ErrorState) - { - qDebug() << "ERROR! : " << mMediaObject->errorString(); - } - else if(newState == Phonon::LoadingState) - { - int itotaltime = mMediaObject->totalTime(); - qDebug() << "[Loading State entered!] Total time : " << itotaltime; - } -} - -UBGraphicsAudioItem::~UBGraphicsAudioItem() -{ - //NOOP -} - -UBItem* UBGraphicsAudioItem::deepCopy() const -{ - QUrl audioUrl = this->mediaFileUrl(); - - UBGraphicsAudioItem *copy = new UBGraphicsAudioItem(audioUrl, parentItem()); - - connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), copy, SLOT(activeSceneChanged())); - - copy->setPos(this->pos()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); - copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); - copy->setUuid(this->uuid()); // this is OK as long as Videos are imutable - copy->setSourceUrl(this->sourceUrl()); - - copy->resize(this->size()); - - // TODO UB 4.7 complete all members - - return copy; -} - -void UBGraphicsAudioItem::tick ( qint64 time ) -{ - QTime displayTime ( 0, ( time / 60000 ) % 60, ( time / 1000 ) % 60 ); - - mTimeLcd->display ( displayTime.toString ( "mm:ss" ) ); -} - -void UBGraphicsAudioItem::setUuid(const QUuid &pUuid) -{ - UBItem::setUuid(pUuid); - setData(UBGraphicsItemData::ItemUuid, QVariant(pUuid)); -} diff --git a/src/domain/UBGraphicsAudioItem.h b/src/domain/UBGraphicsAudioItem.h index cd2ac84b..e69de29b 100644 --- a/src/domain/UBGraphicsAudioItem.h +++ b/src/domain/UBGraphicsAudioItem.h @@ -1,66 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifndef UBGRAPHICSAUDIOITEM_H -#define UBGRAPHICSAUDIOITEM_H - -#include "UBGraphicsMediaItem.h" -#include "phonon/seekslider.h" -#include "phonon/mediasource.h" -#include "core/UB.h" -#include "core/UBApplication.h" -#include "board/UBBoardController.h" - -class UBGraphicsAudioItem : public UBGraphicsMediaItem -{ - Q_OBJECT - -public: - - UBGraphicsAudioItem(const QUrl& pAudioFileUrl, QGraphicsItem *parent = 0); - ~UBGraphicsAudioItem(); - - enum { Type = UBGraphicsItemType::AudioItemType }; - - virtual int type() const - { - return Type; - } - - virtual UBItem* deepCopy () const; - virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;} - - virtual void clearSource() - { - UBGraphicsMediaItem::clearSource(); - } - void setUuid(const QUuid &pUuid); - -private slots: - - void tick ( qint64 time ); - void onStateChanged(Phonon::State newState,Phonon::State oldState); - -protected: - - QWidget* mAudioWidget; - QLCDNumber* mTimeLcd; - - Phonon::SeekSlider* mSeekSlider; -private: - Phonon::MediaSource mSource; - -}; - -#endif // UBGRAPHICSAUDIOITEM_H diff --git a/src/domain/UBGraphicsAudioItemDelegate.cpp b/src/domain/UBGraphicsAudioItemDelegate.cpp index 93c9fd60..e69de29b 100644 --- a/src/domain/UBGraphicsAudioItemDelegate.cpp +++ b/src/domain/UBGraphicsAudioItemDelegate.cpp @@ -1,123 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "UBGraphicsAudioItemDelegate.h" -#include "domain/UBGraphicsAudioItem.h" -#include "domain/UBGraphicsDelegateFrame.h" -#include "UBGraphicsScene.h" - -#include "core/memcheck.h" - -UBGraphicsAudioItemDelegate::UBGraphicsAudioItemDelegate ( UBGraphicsAudioItem* pDelegated, QObject *parent ) - : UBGraphicsItemDelegate ( pDelegated, parent ) - , mDelegated ( pDelegated ) -{ - //NOOP -} - -UBGraphicsAudioItemDelegate::~UBGraphicsAudioItemDelegate() -{ - //NNOP -} - - -void UBGraphicsAudioItemDelegate::buildButtons() -{ - mPlayPauseButton = new DelegateButton ( ":/images/play.svg", mDelegated, mFrame ); - - mStopButton = new DelegateButton ( ":/images/stop.svg", mDelegated, mFrame ); - mStopButton->hide(); - - if ( mDelegated->isMuted() ) - mMuteButton = new DelegateButton ( ":/images/soundOff.svg", mDelegated, mFrame ); - else - mMuteButton = new DelegateButton ( ":/images/soundOn.svg", mDelegated, mFrame ); - - mMuteButton->hide(); - - - connect ( mPlayPauseButton, SIGNAL ( clicked ( bool ) ), this, SLOT ( togglePlayPause() ) ); - connect ( mStopButton, SIGNAL ( clicked ( bool ) ), mDelegated->mediaObject(), SLOT ( stop() ) ); - connect ( mMuteButton, SIGNAL ( clicked ( bool ) ), mDelegated, SLOT ( toggleMute() ) ); - connect ( mMuteButton, SIGNAL ( clicked ( bool ) ), this, SLOT ( toggleMute() ) ); - - connect ( mDelegated->mediaObject(), SIGNAL ( stateChanged ( Phonon::State, Phonon::State ) ), this, SLOT ( mediaStateChanged ( Phonon::State, Phonon::State ) ) ); - connect ( mDelegated->mediaObject(), SIGNAL ( finished() ), this, SLOT ( updatePlayPauseState() ) ); - - mButtons << mPlayPauseButton << mStopButton << mMuteButton; - -} - -void UBGraphicsAudioItemDelegate::togglePlayPause() -{ - if ( mDelegated && mDelegated->mediaObject() ) - { - Phonon::MediaObject* media = mDelegated->mediaObject(); - - if ( media->state() == Phonon::StoppedState ) { - media->play(); - } else if ( media->state() == Phonon::PlayingState ) { - if ( media->remainingTime() <= 0 ) { - media->stop(); - media->play(); - } else { - media->pause(); - if ( mDelegated->scene() ) - mDelegated->scene()->setModified ( true ); - } - } else if ( media->state() == Phonon::PausedState ) { - if ( media->remainingTime() <= 0 ) { - media->stop(); - } - media->play(); - } else if ( media->state() == Phonon::LoadingState ) { - mDelegated->mediaObject()->setCurrentSource(mDelegated->mediaFileUrl()); - media->play(); - } else if (media->state() == Phonon::ErrorState){ - qDebug() << "Error appeared." << media->errorString(); - } - } -} - -void UBGraphicsAudioItemDelegate::toggleMute() -{ - if ( mDelegated->isMuted() ) - mMuteButton->setFileName ( ":/images/soundOff.svg" ); - else - mMuteButton->setFileName ( ":/images/soundOn.svg" ); -} - -void UBGraphicsAudioItemDelegate::updatePlayPauseState() -{ - Phonon::MediaObject* media = mDelegated->mediaObject(); - - if ( media->state() == Phonon::PlayingState ) - mPlayPauseButton->setFileName ( ":/images/pause.svg" ); - else - mPlayPauseButton->setFileName ( ":/images/play.svg" ); -} - -void UBGraphicsAudioItemDelegate::mediaStateChanged ( Phonon::State newstate, Phonon::State oldstate ) -{ - Q_UNUSED ( newstate ); - Q_UNUSED ( oldstate ); - updatePlayPauseState(); -} - -void UBGraphicsAudioItemDelegate::remove ( bool canUndo ) -{ - mDelegated->mediaObject()->stop(); - UBGraphicsItemDelegate::remove ( canUndo ); -} diff --git a/src/domain/UBGraphicsDelegateFrame.cpp b/src/domain/UBGraphicsDelegateFrame.cpp index 91a9d353..f5ad3016 100644 --- a/src/domain/UBGraphicsDelegateFrame.cpp +++ b/src/domain/UBGraphicsDelegateFrame.cpp @@ -585,7 +585,10 @@ void UBGraphicsDelegateFrame::positionHandles() if (mDelegate->getToolBarItem()->isVisibleOnBoard() && mDelegate->getToolBarItem()->isShifting()) - itemRect.setHeight(itemRect.height() + mDelegate->getToolBarItem()->rect().height() * mDelegate->antiScaleRatio() * 1.1); + { + QPointF graphicsItemPosition = itemRect.topLeft(); + itemRect.setTopLeft(graphicsItemPosition-QPointF(0,mDelegate->getToolBarItem()->boundingRect().height()* mDelegate->antiScaleRatio())); + } QTransform itemTransform = delegated()->sceneTransform(); QPointF topLeft = itemTransform.map(itemRect.topLeft()); diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 35fc5bf6..bbc13a99 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -18,6 +18,7 @@ #include #include "UBGraphicsItemDelegate.h" +#include "UBGraphicsMediaItemDelegate.h" #include "UBGraphicsDelegateFrame.h" #include "UBGraphicsScene.h" #include "UBGraphicsItemUndoCommand.h" @@ -38,8 +39,7 @@ #include "domain/UBAbstractWidget.h" #include "domain/UBGraphicsTextItem.h" -#include "domain/UBGraphicsAudioItem.h" -#include "domain/UBGraphicsVideoItem.h" +#include "domain/UBGraphicsMediaItem.h" #include "domain/ubgraphicsgroupcontaineritem.h" #include "web/UBWebController.h" @@ -112,13 +112,14 @@ UBGraphicsItemDelegate::UBGraphicsItemDelegate(QGraphicsItem* pDelegated, QObjec , mRespectRatio(respectRatio) , mMimeData(NULL) , mFlippable(false) + , mToolBarItem(NULL) { // NOOP } void UBGraphicsItemDelegate::init() { - mToolBarItem = new UBGraphicsToolBarItem(delegated()); + mToolBarItem = new UBGraphicsToolBarItem(mDelegated); mFrame = new UBGraphicsDelegateFrame(this, QRectF(0, 0, 0, 0), mFrameWidth, mRespectRatio); mFrame->hide(); @@ -152,11 +153,11 @@ void UBGraphicsItemDelegate::init() { if (button->getSection() != Qt::TitleBarArea) { - button->hide(); - button->setFlag(QGraphicsItem::ItemIsSelectable, true); + button->hide(); + button->setFlag(QGraphicsItem::ItemIsSelectable, true); + } } } -} UBGraphicsItemDelegate::~UBGraphicsItemDelegate() @@ -335,8 +336,9 @@ void UBGraphicsItemDelegate::positionHandles() if (mToolBarItem->isVisibleOnBoard()) { - updateToolBar(); - mToolBarItem->show(); + mToolBarItem->positionHandles(); + mToolBarItem->update(); + mToolBarItem->show(); } } else { foreach(DelegateButton* button, mButtons) @@ -518,6 +520,10 @@ void UBGraphicsItemDelegate::commitUndoStep() } +void UBGraphicsItemDelegate::buildButtons() +{ +} + void UBGraphicsItemDelegate::decorateMenu(QMenu* menu) { mLockAction = menu->addAction(tr("Locked"), this, SLOT(lock(bool))); @@ -650,36 +656,6 @@ void UBGraphicsItemDelegate::updateButtons(bool showUpdated) } } -void UBGraphicsItemDelegate::updateToolBar() -{ - QTransform transformForToolbarButtons; - transformForToolbarButtons.scale(mAntiScaleRatio, 1); - - QRectF toolBarRect = mToolBarItem->rect(); - toolBarRect.setWidth(delegated()->boundingRect().width() - 10); - mToolBarItem->setRect(toolBarRect); - - if (mToolBarItem->isShifting()) - mToolBarItem->setPos(delegated()->boundingRect().bottomLeft() + QPointF(5 * mAntiScaleRatio, 0)); - else mToolBarItem->setPos(delegated()->boundingRect().bottomLeft() - QPointF(-5 * mAntiScaleRatio, mToolBarItem->rect().height() * 1.1 * mAntiScaleRatio)); - - int offsetOnToolBar = 5 * mAntiScaleRatio; - QList itemList = mToolBarItem->itemsOnToolBar(); - foreach (QGraphicsItem* item, itemList) - { - item->setPos(offsetOnToolBar, 0); - offsetOnToolBar += (item->boundingRect().width() + 5) * mAntiScaleRatio; - item->setTransform(transformForToolbarButtons); - item->show(); - } - - mToolBarItem->setOffsetOnToolBar(offsetOnToolBar); - - QTransform tr; - tr.scale(1, mAntiScaleRatio); - mToolBarItem->setTransform(tr); -} - void UBGraphicsItemDelegate::setButtonsVisible(bool visible) { foreach(DelegateButton* pButton, mButtons){ @@ -687,19 +663,41 @@ void UBGraphicsItemDelegate::setButtonsVisible(bool visible) } } + UBGraphicsToolBarItem::UBGraphicsToolBarItem(QGraphicsItem * parent) : QGraphicsRectItem(parent), mShifting(true), mVisible(false), - mMinWidth(200) + mMinWidth(200), + mInitialHeight(26) { QRectF rect = this->rect(); - rect.setHeight(26); + rect.setHeight(mInitialHeight); + rect.setWidth(parent->boundingRect().width()); this->setRect(rect); setBrush(QColor(UBSettings::paletteColor)); setPen(Qt::NoPen); hide(); + + update(); +} + + +void UBGraphicsToolBarItem::positionHandles() +{ + int itemXOffset = 0; + foreach (QGraphicsItem* item, mItemsOnToolBar) + { + item->setPos(itemXOffset, 0); + itemXOffset += (item->boundingRect().width()); + item->show(); + } +} + +void UBGraphicsToolBarItem::update() +{ + QGraphicsRectItem::update(); } void UBGraphicsToolBarItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) @@ -712,3 +710,552 @@ void UBGraphicsToolBarItem::paint(QPainter *painter, const QStyleOptionGraphicsI painter->fillPath(path, brush()); } + +MediaTimer::MediaTimer(QGraphicsItem * parent): QGraphicsRectItem(parent) +{} + +MediaTimer::~MediaTimer() +{} + +void MediaTimer::drawString(const QString &s, QPainter &p, + QBitArray *newPoints, bool newString) +{ + QPoint pos; + + int digitSpace = smallPoint ? 2 : 1; + int xSegLen = (rect().width()/1)*5/(ndigits*(5 + digitSpace) + digitSpace); + int ySegLen = rect().height()*5/12; + int segLen = ySegLen > xSegLen ? xSegLen : ySegLen; + int xAdvance = segLen*(5 + digitSpace)/5; + int xOffset = rect().x() + (rect().width()/1 - ndigits*xAdvance + segLen/5)/2; + int yOffset = (rect().height() - segLen*2)/2; + + for (int i=0; itestBit(i) ? '.' : ' '; + if (newString) { + char oldPoint = points.testBit(i) ? '.' : ' '; + drawDigit(pos, p, segLen, newPoint, oldPoint); + } else { + drawDigit(pos, p, segLen, newPoint); + } + } + } + if (newString) { + digitStr = s; + digitStr.truncate(ndigits); + if (newPoints) + points = *newPoints; + } +} + +void MediaTimer::drawDigit(const QPoint &pos, QPainter &p, int segLen, + char newCh, char oldCh) +{ + char updates[18][2]; // can hold 2 times number of segments, only + // first 9 used if segment table is correct + int nErases; + int nUpdates; + const char *segs; + int i,j; + + const char erase = 0; + const char draw = 1; + const char leaveAlone = 2; + + segs = getSegments(oldCh); + for (nErases=0; segs[nErases] != 99; nErases++) { + updates[nErases][0] = erase; // get segments to erase to + updates[nErases][1] = segs[nErases]; // remove old char + } + nUpdates = nErases; + segs = getSegments(newCh); + for(i = 0 ; segs[i] != 99 ; i++) { + for (j=0; j= '0' && ch <= '9') + return segments[ch - '0']; + if (ch == ':') + n = 10; + if (ch == ' ') + n = 11; + + return segments[n]; +} + +void MediaTimer::drawSegment(const QPoint &pos, char segmentNo, QPainter &p, + int segLen, bool erase) +{ + Q_UNUSED(erase); + + QPoint ppt; + QPoint pt = pos; + int width = segLen/5; + +#define LINETO(X,Y) addPoint(a, QPoint(pt.x() + (X),pt.y() + (Y))) +#define LIGHT +#define DARK + + if (fill) { + QPolygon a(0); + switch (segmentNo) { + case 0 : + ppt = pt; + LIGHT; + LINETO(segLen - 1,0); + DARK; + LINETO(segLen - width - 1,width); + LINETO(width,width); + LINETO(0,0); + break; + case 1 : + pt += QPoint(0 , 1); + ppt = pt; + LIGHT; + LINETO(width,width); + DARK; + LINETO(width,segLen - width/2 - 2); + LINETO(0,segLen - 2); + LIGHT; + LINETO(0,0); + break; + case 2 : + pt += QPoint(segLen - 1 , 1); + ppt = pt; + DARK; + LINETO(0,segLen - 2); + LINETO(-width,segLen - width/2 - 2); + LIGHT; + LINETO(-width,width); + LINETO(0,0); + break; + case 3 : + pt += QPoint(0 , segLen); + ppt = pt; + LIGHT; + LINETO(width,-width/2); + LINETO(segLen - width - 1,-width/2); + LINETO(segLen - 1,0); + DARK; + if (width & 1) { // adjust for integer division error + LINETO(segLen - width - 3,width/2 + 1); + LINETO(width + 2,width/2 + 1); + } else { + LINETO(segLen - width - 1,width/2); + LINETO(width,width/2); + } + LINETO(0,0); + break; + case 4 : + pt += QPoint(0 , segLen + 1); + ppt = pt; + LIGHT; + LINETO(width,width/2); + DARK; + LINETO(width,segLen - width - 2); + LINETO(0,segLen - 2); + LIGHT; + LINETO(0,0); + break; + case 5 : + pt += QPoint(segLen - 1 , segLen + 1); + ppt = pt; + DARK; + LINETO(0,segLen - 2); + LINETO(-width,segLen - width - 2); + LIGHT; + LINETO(-width,width/2); + LINETO(0,0); + break; + case 6 : + pt += QPoint(0 , segLen*2); + ppt = pt; + LIGHT; + LINETO(width,-width); + LINETO(segLen - width - 1,-width); + LINETO(segLen - 1,0); + DARK; + LINETO(0,0); + break; + case 7 : + pt += QPoint(segLen/2 , segLen*2); + ppt = pt; + DARK; + LINETO(width,0); + LINETO(width,-width); + LIGHT; + LINETO(0,-width); + LINETO(0,0); + break; + case 8 : + pt += QPoint(segLen/2 - width/2 + 1 , segLen/2 + width); + ppt = pt; + DARK; + LINETO(width,0); + LINETO(width,-width); + LIGHT; + LINETO(0,-width); + LINETO(0,0); + break; + case 9 : + pt += QPoint(segLen/2 - width/2 + 1 , 3*segLen/2 + width); + ppt = pt; + DARK; + LINETO(width,0); + LINETO(width,-width); + LIGHT; + LINETO(0,-width); + LINETO(0,0); + break; + default : + break; + } + // End exact copy + p.setPen(Qt::white); + p.setBrush(Qt::white); + p.drawPolygon(a); + p.setBrush(Qt::NoBrush); + + pt = pos; + } +#undef LINETO +#undef LIGHT +#undef DARK +} + +void MediaTimer::addPoint(QPolygon &a, const QPoint &p) +{ + uint n = a.size(); + a.resize(n + 1); + a.setPoint(n, p); +} + +void MediaTimer::paint(QPainter *p, + const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(option); + Q_UNUSED(widget); + + QFont f = p->font(); + f.setPointSizeF(f.pointSizeF()); + p->setFont(f); + + if (smallPoint) + drawString(digitStr, *p, &points, false); + else + drawString(digitStr, *p, 0, false); +} + +void MediaTimer::internalSetString(const QString& s) +{ + QString buffer; + int i; + int len = s.length(); + QBitArray newPoints(ndigits); + + if (!smallPoint) { + if (len == ndigits) + buffer = s; + else + buffer = s.right(ndigits).rightJustified(ndigits, QLatin1Char(' ')); + } else { + int index = -1; + bool lastWasPoint = true; + newPoints.clearBit(0); + for (i=0; i=0; i--) { + buffer[ndigits - 1 - index + i] = buffer[i]; + newPoints.setBit(ndigits - 1 - index + i, + newPoints.testBit(i)); + } + for(i=0; i 99) { + qWarning("QLCDNumber::setNumDigits: (%s) Max 99 digits allowed"); + numDigits = 99; + } + if (numDigits < 0) { + qWarning("QLCDNumber::setNumDigits: (%s) Min 0 digits allowed"); + numDigits = 0; + } + if (digitStr.isNull()) { // from constructor + ndigits = numDigits; + digitStr.fill(QLatin1Char(' '), ndigits); + points.fill(0, ndigits); + digitStr[ndigits - 1] = QLatin1Char('0'); // "0" is the default number + } else { + if (numDigits == ndigits) // no change + return; + register int i; + int dif; + if (numDigits > ndigits) { // expand + dif = numDigits - ndigits; + QString buf; + buf.fill(QLatin1Char(' '), dif); + digitStr.insert(0, buf); + points.resize(numDigits); + for (i=numDigits-1; i>=dif; i--) + points.setBit(i, points.testBit(i-dif)); + for (i=0; iinit(); + + update(); +} + + +void DelegateMediaControl::paint(QPainter *painter, + const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + Q_UNUSED(option); + Q_UNUSED(widget); + + QPainterPath path; + + mLCDTimerArea.setHeight(rect().height()); + mLCDTimerArea.setWidth(rect().height()); + + mSeecArea = rect(); + mSeecArea.setWidth(rect().width()-mLCDTimerArea.width()); + + path.addRoundedRect(mSeecArea, mSeecArea.height()/2, mSeecArea.height()/2); + painter->fillPath(path, brush()); + + qreal frameWidth = rect().height() / 2; + int position = frameWidth; + + if (mTotalTimeInMs > 0) + { + position = frameWidth + ((mSeecArea.width() - (2 * frameWidth)) / mTotalTimeInMs) * mCurrentTimeInMs; + } + + int clearance = 2; + int radius = frameWidth-clearance; + QRectF r(position - radius, clearance, radius * 2, radius * 2); + + painter->setBrush(UBSettings::documentViewLightColor); + painter->drawEllipse(r); +} + + +QPainterPath DelegateMediaControl::shape() const +{ + QPainterPath path; + path.addRoundedRect(rect(), rect().height()/ 2, rect().height()/2); + return path; +} + +void DelegateMediaControl::positionHandles() +{ + mLCDTimerArea.setWidth(parentItem()->boundingRect().height()); + mLCDTimerArea.setHeight(parentItem()->boundingRect().height()); + lcdTimer->setRect(mLCDTimerArea); + lcdTimer->setPos(mSeecArea.width()-mLCDTimerArea.width(),0); + + mSeecArea.setWidth(rect().width()-mLCDTimerArea.width()); + + QRectF selfRect = rect(); + selfRect.setHeight(parentItem()->boundingRect().height()); + setRect(selfRect); + + lcdTimer->setPos(rect().width() - mLCDTimerArea.width(), 0); + +} + +void DelegateMediaControl::update() +{ + QTime t; + t = t.addMSecs(mCurrentTimeInMs < 0 ? 0 : mCurrentTimeInMs); + lcdTimer->display(t.toString("m:ss")); + + QGraphicsRectItem::update(); +} + +void DelegateMediaControl::updateTicker(qint64 time ) +{ + mCurrentTimeInMs = time; + update(); +} + + +void DelegateMediaControl::totalTimeChanged(qint64 newTotalTime) +{ + mTotalTimeInMs = newTotalTime; + update(); +} + + +void DelegateMediaControl::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ + qreal frameWidth = mSeecArea.height()/2; + if (boundingRect().contains(event->pos() - QPointF(frameWidth,0)) + && boundingRect().contains(event->pos() + QPointF(frameWidth,0))) + { + mDisplayCurrentTime = true; + seekToMousePos(event->pos()); + this->update(); + event->accept(); + } +} + +void DelegateMediaControl::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + qreal frameWidth = rect().height() / 2; + if (boundingRect().contains(event->pos() - QPointF(frameWidth,0)) + && boundingRect().contains(event->pos() + QPointF(frameWidth,0))) + { + seekToMousePos(event->pos()); + this->update(); + event->accept(); + } +} + +void DelegateMediaControl::seekToMousePos(QPointF mousePos) +{ + qreal minX, length; + qreal frameWidth = rect().height() / 2; + + minX = frameWidth; + length = mSeecArea.width() - lcdTimer->rect().width(); + + qreal mouseX = mousePos.x(); + if (mouseX >= (mSeecArea.width() - mSeecArea.height()/2)) + mouseX = mSeecArea.width() - mSeecArea.height()/2; + + if (mTotalTimeInMs > 0 && length > 0 && mDelegate + && mDelegate->mediaObject() && mDelegate->mediaObject()->isSeekable()) + { + qint64 tickPos = (mTotalTimeInMs/length)* (mouseX - minX); + mDelegate->mediaObject()->seek(tickPos); + + //OSX is a bit lazy + updateTicker(tickPos); + } +} + +void DelegateMediaControl::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) +{ + mDisplayCurrentTime = false; + this->update(); + event->accept(); +} diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index 696fcaa7..79ed8d2d 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -29,6 +29,7 @@ class UBGraphicsScene; class UBGraphicsProxyWidget; class UBGraphicsDelegateFrame; class UBGraphicsWidgetItem; +class UBGraphicsMediaItem; class DelegateButton: public QGraphicsSvgItem { @@ -70,6 +71,80 @@ class DelegateButton: public QGraphicsSvgItem }; +class MediaTimer: public QGraphicsRectItem +{ +public: + MediaTimer(QGraphicsItem * parent = 0); + ~MediaTimer(); + + char* getSegments(char); + void addPoint(QPolygon&, const QPoint&); + void init(); + void internalSetString(const QString& s); + void drawString(const QString& s, QPainter &, QBitArray * = 0, bool = true); + void drawDigit(const QPoint &, QPainter &, int, char, char = ' '); + void drawSegment(const QPoint &, char, QPainter &, int, bool = false); + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget); + void display(const QString &str); + void setNumDigits(int nDigits); + +private: + int ndigits; + QString digitStr; + QBitArray points; + double val; + + +uint fill : 1; +uint shadow : 1; +uint smallPoint : 1; + +}; + +class DelegateMediaControl: public QGraphicsRectItem +{ + public: + + DelegateMediaControl(UBGraphicsMediaItem* pDelegated, QGraphicsItem * parent = 0); + + virtual ~DelegateMediaControl() + { + // NOOP + } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, + QWidget *widget); + + QPainterPath shape() const; + + virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); + virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + virtual void update(); + + void positionHandles(); + void updateTicker(qint64 time); + void totalTimeChanged(qint64 newTotalTime); + + protected: + void seekToMousePos(QPointF mousePos); + + UBGraphicsMediaItem* mDelegate; + bool mDisplayCurrentTime; + + qint64 mCurrentTimeInMs; + qint64 mTotalTimeInMs; + + private: + int mStartWidth; + + QRectF mSeecArea; + QRectF mLCDTimerArea; + + MediaTimer *lcdTimer; +}; + class UBGraphicsToolBarItem : public QGraphicsRectItem, public QObject { public: @@ -80,19 +155,21 @@ class UBGraphicsToolBarItem : public QGraphicsRectItem, public QObject void setVisibleOnBoard(bool visible) { mVisible = visible; } bool isShifting() const { return mShifting; } void setShifting(bool shifting) { mShifting = shifting; } - int offsetOnToolBar() const { return mOffsetOnToolBar; } - void setOffsetOnToolBar(int pOffset) { mOffsetOnToolBar = pOffset; } QList itemsOnToolBar() const { return mItemsOnToolBar; } void setItemsOnToolBar(QList itemsOnToolBar) { mItemsOnToolBar = itemsOnToolBar;} int minWidth() { return mMinWidth; } + void positionHandles(); + void update(); + + private: void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); private: bool mShifting; bool mVisible; - int mOffsetOnToolBar; int mMinWidth; + int mInitialHeight; QList mItemsOnToolBar; }; @@ -168,7 +245,7 @@ class UBGraphicsItemDelegate : public QObject void increaseZlevelBottom(); protected: - virtual void buildButtons() {;} + virtual void buildButtons(); virtual void decorateMenu(QMenu *menu); virtual void updateMenuActionState(); @@ -203,9 +280,6 @@ protected slots: private: void updateFrame(); void updateButtons(bool showUpdated = false); - void updateToolBar(); - - QPointF mOffset; QTransform mPreviousTransform; diff --git a/src/domain/UBGraphicsMediaItem.cpp b/src/domain/UBGraphicsMediaItem.cpp index dd19e275..8a25a217 100644 --- a/src/domain/UBGraphicsMediaItem.cpp +++ b/src/domain/UBGraphicsMediaItem.cpp @@ -13,18 +13,15 @@ * along with this program. If not, see . */ +#include "UBGraphicsGroupContainerItem.h" #include "UBGraphicsMediaItem.h" +#include "UBGraphicsMediaItemDelegate.h" #include "UBGraphicsScene.h" #include "UBGraphicsDelegateFrame.h" - #include "document/UBDocumentProxy.h" - #include "core/UBApplication.h" - #include "board/UBBoardController.h" - #include "frameworks/UBFileSystemUtils.h" - #include "core/memcheck.h" bool UBGraphicsMediaItem::sIsMutedByDefault = false; @@ -35,8 +32,63 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte , mMutedByUserAction(sIsMutedByDefault) , mMediaFileUrl(pMediaFileUrl) , mInitialPos(0) + , mVideoWidget(NULL) + , mAudioWidget(NULL) { - //NOOP + + update(); + + QString s = pMediaFileUrl.toLocalFile(); + + mMediaObject = new Phonon::MediaObject(this); + if (pMediaFileUrl.toLocalFile().contains("videos")) + { + mMediaType = mediaType_Video; + + mAudioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this); + mMediaObject->setTickInterval(50); + mVideoWidget = new Phonon::VideoWidget(); // owned and destructed by the scene ... + Phonon::createPath(mMediaObject, mVideoWidget); + + /* + * The VideoVidget should recover the size from the original movie, but this is not always true expecially on + * windows and linux os. I don't know why? + * In this case the wiget size is equal to QSize(1,1). + */ + + if(mVideoWidget->sizeHint() == QSize(1,1)){ + mVideoWidget->resize(320,240); + } + setWidget(mVideoWidget); + } + else + if (pMediaFileUrl.toLocalFile().contains("audios")) + { + mMediaType = mediaType_Audio; + mAudioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); + + mMediaObject->setTickInterval(1000); + mAudioWidget = new QWidget(); + mAudioWidget->resize(320,26); + setWidget(mAudioWidget); + } + + Phonon::createPath(mMediaObject, mAudioOutput); + + mSource = Phonon::MediaSource(pMediaFileUrl); + mMediaObject->setCurrentSource(mSource); + + UBGraphicsMediaItemDelegate* itemDelegate = new UBGraphicsMediaItemDelegate(this, mMediaObject); + itemDelegate->init(); + setDelegate(itemDelegate); + + mDelegate->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); + + setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly + + connect(mDelegate, SIGNAL(showOnDisplayChanged(bool)), this, SLOT(showOnDisplayChanged(bool))); + connect(mMediaObject, SIGNAL(hasVideoChanged(bool)), this, SLOT(hasMediaChanged(bool))); + } @@ -106,8 +158,14 @@ void UBGraphicsMediaItem::toggleMute() void UBGraphicsMediaItem::hasMediaChanged(bool hasMedia) { + if(hasMedia && mMediaObject->isSeekable()) + { Q_UNUSED(hasMedia); mMediaObject->seek(mInitialPos); + UBGraphicsMediaItemDelegate *med = dynamic_cast(mDelegate); + if (med) + med->updateTicker(initialPos()); + } } @@ -139,3 +197,104 @@ void UBGraphicsMediaItem::showOnDisplayChanged(bool shown) mAudioOutput->setMuted(mMuted); } } + +UBItem* UBGraphicsMediaItem::deepCopy() const +{ + QUrl url = this->mediaFileUrl(); + UBGraphicsMediaItem *copy; + + copy = new UBGraphicsMediaItem(url, parentItem()); + + copy->setPos(this->pos()); + copy->setTransform(this->transform()); + copy->setFlag(QGraphicsItem::ItemIsMovable, true); + copy->setFlag(QGraphicsItem::ItemIsSelectable, true); + copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); + copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); + copy->setUuid(this->uuid()); // this is OK as long as Videos are imutable + copy->setSourceUrl(this->sourceUrl()); + copy->resize(this->size()); + + connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), copy, SLOT(activeSceneChanged())); + // TODO UB 4.7 complete all members + + return copy; +} + +void UBGraphicsMediaItem::mousePressEvent(QGraphicsSceneMouseEvent *event) +{ +// QDrag* mDrag = new QDrag(event->widget()); +// QMimeData* pMime = new QMimeData(); +// mDrag->setMimeData(pMime); +// mDrag->start(); + +// UBApplication::boardController->activeScene()->setActiveItem(this); + + + if (mDelegate) + { + mDelegate->mousePressEvent(event); + if (mDelegate && parentItem() && UBGraphicsGroupContainerItem::Type == parentItem()->type()) + { + UBGraphicsGroupContainerItem *group = qgraphicsitem_cast(parentItem()); + if (group) + { + QGraphicsItem *curItem = group->getCurrentItem(); + if (curItem && this != curItem) + { + group->deselectCurrentItem(); + } + group->setCurrentItem(this); + this->setSelected(true); + mDelegate->positionHandles(); + } + + } + else + { + mDelegate->getToolBarItem()->show(); + } + + } + + if (parentItem() && parentItem()->type() == UBGraphicsGroupContainerItem::Type) + { + mShouldMove = false; + if (!Delegate()->mousePressEvent(event)) + { + event->accept(); + } + } + else + { + mShouldMove = (event->buttons() & Qt::LeftButton); + mMousePressPos = event->scenePos(); + mMouseMovePos = mMousePressPos; + + event->accept(); + setSelected(true); + } + +} + +void UBGraphicsMediaItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) +{ + if(mShouldMove && (event->buttons() & Qt::LeftButton)) + { + QPointF offset = event->scenePos() - mMousePressPos; + + if (offset.toPoint().manhattanLength() > QApplication::startDragDistance()) + { + QPointF mouseMovePos = mapFromScene(mMouseMovePos); + QPointF eventPos = mapFromScene( event->scenePos()); + + QPointF translation = eventPos - mouseMovePos; + translate(translation.x(), translation.y()); + } + + mMouseMovePos = event->scenePos(); + } + + event->accept(); + +} diff --git a/src/domain/UBGraphicsMediaItem.h b/src/domain/UBGraphicsMediaItem.h index f31841bc..8d545944 100644 --- a/src/domain/UBGraphicsMediaItem.h +++ b/src/domain/UBGraphicsMediaItem.h @@ -18,6 +18,7 @@ #include "UBGraphicsProxyWidget.h" #include #include +#include #include "core/UBApplication.h" #include "board/UBBoardController.h" @@ -27,10 +28,21 @@ class UBGraphicsMediaItem : public UBGraphicsProxyWidget Q_OBJECT public: + typedef enum{ + mediaType_Video, + mediaType_Audio + } mediaType; UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsItem *parent = 0); ~UBGraphicsMediaItem(); + enum { Type = UBGraphicsItemType::MediaItemType }; + + virtual int type() const + { + return Type; + } + void hasMediaChanged(bool hasMedia); void showOnDisplayChanged(bool shown); @@ -56,8 +68,17 @@ public: return mMuted; } + Phonon::VideoWidget* videoWidget() const + { + return mVideoWidget; + } + + mediaType getMediaType() { return mMediaType; } + virtual UBGraphicsScene* scene(); + virtual UBItem* deepCopy() const; + public slots: void toggleMute(); @@ -66,11 +87,16 @@ public slots: protected: virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); + virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); + virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual void clearSource(); Phonon::MediaObject *mMediaObject; + Phonon::VideoWidget *mVideoWidget; Phonon::AudioOutput *mAudioOutput; + Phonon::MediaSource mSource; + QWidget *mAudioWidget; private: @@ -83,6 +109,20 @@ private: qint64 mInitialPos; + mediaType mMediaType; + + bool mShouldMove; + QPointF mMousePressPos; + QPointF mMouseMovePos; + +}; + + +class UBGraphicsUnitedMediaItem : public UBGraphicsMediaItem +{ +public: + UBGraphicsUnitedMediaItem(const QUrl& pMediaFileUrl, QGraphicsItem *parent = 0); + }; #endif // UBGRAPHICSMEDIAITEM_H diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index bbe74fc1..33716f14 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -50,8 +50,7 @@ #include "UBGraphicsPixmapItem.h" #include "UBGraphicsSvgItem.h" #include "UBGraphicsPolygonItem.h" -#include "UBGraphicsVideoItem.h" -#include "UBGraphicsAudioItem.h" +#include "UBGraphicsMediaItem.h" #include "UBGraphicsWidgetItem.h" #include "UBGraphicsPDFItem.h" #include "UBGraphicsTextItem.h" @@ -1331,67 +1330,48 @@ void UBGraphicsScene::textUndoCommandAdded(UBGraphicsTextItem *textItem) UBApplication::undoStack->push(uc); } } - -UBGraphicsVideoItem* UBGraphicsScene::addVideo(const QUrl& pVideoFileUrl, bool shouldPlayAsap, const QPointF& pPos) +UBGraphicsMediaItem* UBGraphicsScene::addMedia(const QUrl& pMediaFileUrl, bool shouldPlayAsap, const QPointF& pPos) { - UBGraphicsVideoItem* videoItem = new UBGraphicsVideoItem(pVideoFileUrl); + UBGraphicsMediaItem* mediaItem = new UBGraphicsMediaItem(pMediaFileUrl); + if(mediaItem){ + connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), mediaItem, SLOT(activeSceneChanged())); + } - videoItem->setPos(pPos); + mediaItem->setPos(pPos); - videoItem->setFlag(QGraphicsItem::ItemIsMovable, true); - videoItem->setFlag(QGraphicsItem::ItemIsSelectable, true); + mediaItem->setFlag(QGraphicsItem::ItemIsMovable, true); + mediaItem->setFlag(QGraphicsItem::ItemIsSelectable, true); - addItem(videoItem); + addItem(mediaItem); - videoItem->show(); + mediaItem->show(); if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented - UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, 0, videoItem); + UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, 0, mediaItem); UBApplication::undoStack->push(uc); } - videoItem->mediaObject()->play(); + mediaItem->mediaObject()->play(); if (!shouldPlayAsap) { - videoItem->mediaObject()->pause(); - videoItem->mediaObject()->seek(0); + mediaItem->mediaObject()->pause(); + mediaItem->mediaObject()->seek(0); } setDocumentUpdated(); - return videoItem; + return mediaItem; } -UBGraphicsAudioItem* UBGraphicsScene::addAudio(const QUrl& pAudioFileUrl, bool shouldPlayAsap, const QPointF& pPos) +UBGraphicsMediaItem* UBGraphicsScene::addVideo(const QUrl& pVideoFileUrl, bool shouldPlayAsap, const QPointF& pPos) { - UBGraphicsAudioItem* audioItem = new UBGraphicsAudioItem(pAudioFileUrl); - - audioItem->setPos(pPos); - - audioItem->setFlag(QGraphicsItem::ItemIsMovable, true); - audioItem->setFlag(QGraphicsItem::ItemIsSelectable, true); - - addItem(audioItem); - - audioItem->show(); - - if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented - UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, 0, audioItem); - UBApplication::undoStack->push(uc); - } - - audioItem->mediaObject()->play(); - - if (!shouldPlayAsap) - { - audioItem->mediaObject()->pause(); - audioItem->mediaObject()->seek(0); - } - - setDocumentUpdated(); + return addMedia(pVideoFileUrl, shouldPlayAsap, pPos); +} - return audioItem; +UBGraphicsMediaItem* UBGraphicsScene::addAudio(const QUrl& pAudioFileUrl, bool shouldPlayAsap, const QPointF& pPos) +{ + return addMedia(pAudioFileUrl, shouldPlayAsap, pPos); } UBGraphicsWidgetItem* UBGraphicsScene::addWidget(const QUrl& pWidgetUrl, const QPointF& pPos) @@ -2067,7 +2047,7 @@ QList UBGraphicsScene::relativeDependencies() const while (itItems.hasNext()) { - UBGraphicsVideoItem *videoItem = qgraphicsitem_cast (itItems.next()); + UBGraphicsMediaItem *videoItem = qgraphicsitem_cast (itItems.next()); if (videoItem && videoItem->mediaFileUrl().isRelative()) { diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 0d3e44c4..f37602c3 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -29,6 +29,7 @@ class UBGraphicsPixmapItem; class UBGraphicsProxyWidget; class UBGraphicsSvgItem; class UBGraphicsPolygonItem; +class UBGraphicsMediaItem; class UBGraphicsVideoItem; class UBGraphicsAudioItem; class UBGraphicsWidgetItem; @@ -130,8 +131,9 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem UBGraphicsW3CWidgetItem* addW3CWidget(const QUrl& pWidgetUrl, const QPointF& pPos = QPointF(0, 0),int widgetType = UBGraphicsItemType::W3CWidgetItemType); void addGraphicsWidget(UBGraphicsWidgetItem* graphicsWidget, const QPointF& pPos = QPointF(0, 0)); - UBGraphicsVideoItem* addVideo(const QUrl& pVideoFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); - UBGraphicsAudioItem* addAudio(const QUrl& pAudioFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); + UBGraphicsMediaItem* addMedia(const QUrl& pMediaFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); + UBGraphicsMediaItem* addVideo(const QUrl& pVideoFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); + UBGraphicsMediaItem* addAudio(const QUrl& pAudioFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); UBGraphicsSvgItem* addSvg(const QUrl& pSvgFileUrl, const QPointF& pPos = QPointF(0, 0)); UBGraphicsTextItem* addText(const QString& pString, const QPointF& pTopLeft = QPointF(0, 0)); UBGraphicsTextItem* textForObjectName(const QString& pString, const QString &objectName = "UBTGZeroPageSessionTitle"); diff --git a/src/domain/UBGraphicsTextItem.cpp b/src/domain/UBGraphicsTextItem.cpp index 6202a6c6..16328d3e 100644 --- a/src/domain/UBGraphicsTextItem.cpp +++ b/src/domain/UBGraphicsTextItem.cpp @@ -14,6 +14,7 @@ */ #include +#include "UBGraphicsGroupContainerItem.h" #include "UBGraphicsTextItem.h" #include "UBGraphicsTextItemDelegate.h" #include "UBGraphicsScene.h" @@ -97,8 +98,32 @@ QVariant UBGraphicsTextItem::itemChange(GraphicsItemChange change, const QVarian void UBGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { + if (mDelegate) + { mDelegate->mousePressEvent(event); + if (mDelegate && parentItem() && UBGraphicsGroupContainerItem::Type == parentItem()->type()) + { + UBGraphicsGroupContainerItem *group = qgraphicsitem_cast(parentItem()); + if (group) + { + QGraphicsItem *curItem = group->getCurrentItem(); + if (curItem && this != curItem) + { + group->deselectCurrentItem(); + } + group->setCurrentItem(this); + this->setSelected(true); + mDelegate->positionHandles(); + } + + } + else + { + mDelegate->getToolBarItem()->show(); + } + + } if (!data(UBGraphicsItemData::ItemEditable).toBool()) return; diff --git a/src/domain/UBGraphicsTextItemDelegate.cpp b/src/domain/UBGraphicsTextItemDelegate.cpp index 2a911fbf..ce47c04c 100644 --- a/src/domain/UBGraphicsTextItemDelegate.cpp +++ b/src/domain/UBGraphicsTextItemDelegate.cpp @@ -16,6 +16,8 @@ #include #include +#include "core/UBApplication.h" +#include "UBGraphicsGroupContainerItem.h" #include "UBGraphicsTextItemDelegate.h" #include "UBGraphicsScene.h" #include "gui/UBResources.h" @@ -108,7 +110,7 @@ void UBGraphicsTextItemDelegate::buildButtons() QList itemsOnToolBar; itemsOnToolBar << mFontButton << mColorButton << mDecreaseSizeButton << mIncreaseSizeButton; mToolBarItem->setItemsOnToolBar(itemsOnToolBar); - + mToolBarItem->setShifting(true); mToolBarItem->setVisibleOnBoard(true); } @@ -281,6 +283,39 @@ void UBGraphicsTextItemDelegate::updateMenuActionState() void UBGraphicsTextItemDelegate::positionHandles() { UBGraphicsItemDelegate::positionHandles(); + + if (mDelegated->isSelected() || (mDelegated->parentItem() && UBGraphicsGroupContainerItem::Type == mDelegated->parentItem()->type())) + { + if (mToolBarItem->isVisibleOnBoard()) + { + qreal AntiScaleRatio = 1 / (UBApplication::boardController->systemScaleFactor() * UBApplication::boardController->currentZoom()); + mToolBarItem->setScale(AntiScaleRatio); + QRectF toolBarRect = mToolBarItem->rect(); + toolBarRect.setWidth(delegated()->boundingRect().width()/AntiScaleRatio); + mToolBarItem->setRect(toolBarRect); + mToolBarItem->positionHandles(); + mToolBarItem->update(); + if (mToolBarItem->isShifting()) + mToolBarItem->setPos(0,-mToolBarItem->boundingRect().height()*AntiScaleRatio); + else + mToolBarItem->setPos(0, 0); + + UBGraphicsGroupContainerItem *group = qgraphicsitem_cast(mDelegated->parentItem()); + + mToolBarItem->hide(); + if (group && group->getCurrentItem() == mDelegated && group->isSelected()) + mToolBarItem->show(); + + if (!group) + mToolBarItem->show(); + + } + } + else + { + mToolBarItem->hide(); + } + setEditable(isEditable()); } diff --git a/src/domain/UBGraphicsVideoItem.cpp b/src/domain/UBGraphicsVideoItem.cpp index 0229135c..e69de29b 100644 --- a/src/domain/UBGraphicsVideoItem.cpp +++ b/src/domain/UBGraphicsVideoItem.cpp @@ -1,149 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "UBGraphicsVideoItem.h" -#include "UBGraphicsVideoItemDelegate.h" -#include "UBGraphicsDelegateFrame.h" - -#include "core/memcheck.h" - -UBGraphicsVideoItem::UBGraphicsVideoItem(const QUrl& pVideoFileUrl, QGraphicsItem *parent): - UBGraphicsMediaItem(pVideoFileUrl,parent) - , mShouldMove(false) -{ - update(); - - mMediaObject = new Phonon::MediaObject(this); - mVideoWidget = new Phonon::VideoWidget(); // owned and destructed by the scene ... - - Phonon::createPath(mMediaObject, mVideoWidget); - - mAudioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this); - Phonon::createPath(mMediaObject, mAudioOutput); - - /* - * The VideoVidget should recover the size from the original movie, but this is not always true expecially on - * windows and linux os. I don't know why? - * In this case the wiget size is equal to QSize(1,1). - */ - - if(mVideoWidget->sizeHint() == QSize(1,1)){ - mVideoWidget->resize(320,240); - } - - setWidget(mVideoWidget); - - UBGraphicsVideoItemDelegate* delegate = new UBGraphicsVideoItemDelegate(this, mMediaObject); - delegate->init(); - setDelegate(delegate); - - mDelegate->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); - - setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly - - connect(mDelegate, SIGNAL(showOnDisplayChanged(bool)), this, SLOT(showOnDisplayChanged(bool))); - connect(mMediaObject, SIGNAL(hasVideoChanged(bool)), this, SLOT(hasVideoChanged(bool))); -} - - -UBGraphicsVideoItem::~UBGraphicsVideoItem() -{ - //NOOP -} - -UBItem* UBGraphicsVideoItem::deepCopy() const -{ - QUrl videoUrl = this->mediaFileUrl(); - - UBGraphicsVideoItem *copy = new UBGraphicsVideoItem(videoUrl, parentItem()); - - connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), copy, SLOT(activeSceneChanged())); - - copy->setPos(this->pos()); - copy->setTransform(this->transform()); - copy->setFlag(QGraphicsItem::ItemIsMovable, true); - copy->setFlag(QGraphicsItem::ItemIsSelectable, true); - copy->setData(UBGraphicsItemData::ItemLayerType, this->data(UBGraphicsItemData::ItemLayerType)); - copy->setData(UBGraphicsItemData::ItemLocked, this->data(UBGraphicsItemData::ItemLocked)); - copy->setUuid(this->uuid()); // this is OK as long as Videos are imutable - copy->setSourceUrl(this->sourceUrl()); - - copy->resize(this->size()); - - // TODO UB 4.7 complete all members - - return copy; -} - - - -void UBGraphicsVideoItem::hasVideoChanged(bool hasVideo) -{ - if(hasVideo && mMediaObject->isSeekable()) - { - hasMediaChanged(hasVideo); - UBGraphicsVideoItemDelegate *vid = dynamic_cast(mDelegate); - if (vid) - vid->updateTicker(initialPos()); - } -} - -void UBGraphicsVideoItem::showOnDisplayChanged(bool shown) -{ - UBGraphicsMediaItem::showOnDisplayChanged(shown); - UBGraphicsVideoItemDelegate *vid = dynamic_cast(mDelegate); - - if (vid) - vid->toggleMute(); -} - -void UBGraphicsVideoItem::setUuid(const QUuid &pUuid) -{ - UBItem::setUuid(pUuid); - setData(UBGraphicsItemData::ItemUuid, QVariant(pUuid)); //store item uuid inside the QGraphicsItem to fast operations with Items on the scene -} - -void UBGraphicsVideoItem::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - mShouldMove = (event->buttons() & Qt::LeftButton); - mMousePressPos = event->scenePos(); - mMouseMovePos = mMousePressPos; - - event->accept(); - setSelected(true); - -} - -void UBGraphicsVideoItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - if(mShouldMove && (event->buttons() & Qt::LeftButton)) - { - QPointF offset = event->scenePos() - mMousePressPos; - - if (offset.toPoint().manhattanLength() > QApplication::startDragDistance()) - { - QPointF mouseMovePos = mapFromScene(mMouseMovePos); - QPointF eventPos = mapFromScene( event->scenePos()); - - QPointF translation = eventPos - mouseMovePos; - translate(translation.x(), translation.y()); - } - - mMouseMovePos = event->scenePos(); - } - - event->accept(); - -} diff --git a/src/domain/UBGraphicsVideoItem.h b/src/domain/UBGraphicsVideoItem.h index 27a7dee7..e69de29b 100644 --- a/src/domain/UBGraphicsVideoItem.h +++ b/src/domain/UBGraphicsVideoItem.h @@ -1,76 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#ifndef UBGRAPHICSVIDEOITEM_H -#define UBGRAPHICSVIDEOITEM_H - -#include -#include "UBGraphicsMediaItem.h" -#include "core/UB.h" -#include "core/UBApplication.h" -#include "board/UBBoardController.h" - -class UBGraphicsVideoItem : public UBGraphicsMediaItem -{ - Q_OBJECT; - -public: - UBGraphicsVideoItem(const QUrl& pMediaFileUrl, QGraphicsItem *parent = 0); - ~UBGraphicsVideoItem(); - - enum { Type = UBGraphicsItemType::VideoItemType }; - - virtual int type() const - { - return Type; - } - - virtual UBItem* deepCopy() const; - - Phonon::VideoWidget* videoWidget() const - { - return mVideoWidget; - } - virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;} - - virtual void clearSource() - { - UBGraphicsMediaItem::clearSource(); - } - virtual void setUuid(const QUuid &pUuid); - -public slots: - void hasVideoChanged(bool hasVideo); - - -protected: - - virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); - virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - - Phonon::VideoWidget *mVideoWidget; - -private slots: - void showOnDisplayChanged(bool shown); - - -private: - bool mShouldMove; - QPointF mMousePressPos; - QPointF mMouseMovePos; - - -}; - -#endif // UBGRAPHICSVIDEOITEM_H diff --git a/src/domain/UBGraphicsVideoItemDelegate.cpp b/src/domain/UBGraphicsVideoItemDelegate.cpp index e02640c5..e69de29b 100644 --- a/src/domain/UBGraphicsVideoItemDelegate.cpp +++ b/src/domain/UBGraphicsVideoItemDelegate.cpp @@ -1,351 +0,0 @@ -/* - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include - -#include "UBGraphicsVideoItemDelegate.h" - -#include "UBGraphicsScene.h" - -#include "core/UBSettings.h" -#include "core/UBApplication.h" -#include "core/UBApplicationController.h" -#include "core/UBDisplayManager.h" - -#include "domain/UBGraphicsVideoItem.h" -#include "domain/UBGraphicsDelegateFrame.h" - -#include "core/memcheck.h" - -UBGraphicsVideoItemDelegate::UBGraphicsVideoItemDelegate(UBGraphicsVideoItem* pDelegated, Phonon::MediaObject* pMedia, QObject * parent) - : UBGraphicsItemDelegate(pDelegated, parent, true, false) - , mMedia(pMedia) -{ - // NOOP -} - -void UBGraphicsVideoItemDelegate::buildButtons() -{ - mPlayPauseButton = new DelegateButton(":/images/play.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); - - mStopButton = new DelegateButton(":/images/stop.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); - - mVideoControl = new DelegateVideoControl(delegated(), mToolBarItem); - UBGraphicsItem::assignZValue(mVideoControl, delegated()->zValue()); - mVideoControl->setFlag(QGraphicsItem::ItemIsSelectable, true); - - if (delegated()->isMuted()) - mMuteButton = new DelegateButton(":/images/soundOff.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); - else - mMuteButton = new DelegateButton(":/images/soundOn.svg", mDelegated, mToolBarItem, Qt::TitleBarArea); - - connect(mPlayPauseButton, SIGNAL(clicked(bool)), this, SLOT(togglePlayPause())); - connect(mStopButton, SIGNAL(clicked(bool)), mMedia, SLOT(stop())); - connect(mMuteButton, SIGNAL(clicked(bool)), delegated(), SLOT(toggleMute())); - connect(mMuteButton, SIGNAL(clicked(bool)), this, SLOT(toggleMute())); - - mButtons << mPlayPauseButton << mStopButton << mMuteButton; - - QList itemsOnToolBar; - itemsOnToolBar << mPlayPauseButton << mStopButton << mVideoControl << mMuteButton; - mToolBarItem->setItemsOnToolBar(itemsOnToolBar); - - mMedia->setTickInterval(50); - - connect(mMedia, SIGNAL(stateChanged (Phonon::State, Phonon::State)), this, SLOT(mediaStateChanged (Phonon::State, Phonon::State))); - connect(mMedia, SIGNAL(finished()), this, SLOT(updatePlayPauseState())); - connect(mMedia, SIGNAL(tick(qint64)), this, SLOT(updateTicker(qint64))); - connect(mMedia, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64))); - - mToolBarItem->setVisibleOnBoard(true); - mToolBarItem->setShifting(false); -} - - -UBGraphicsVideoItemDelegate::~UBGraphicsVideoItemDelegate() -{ - //NOOP -} - - -void UBGraphicsVideoItemDelegate::positionHandles() -{ - UBGraphicsItemDelegate::positionHandles(); - - if (mDelegated->isSelected()) - { - qreal scaledFrameWidth = mFrameWidth * mAntiScaleRatio; - - int offset = 0; - foreach (DelegateButton* button, mButtons) - { - if (button->getSection() == Qt::TitleBarArea) - offset += button->boundingRect().width() * mAntiScaleRatio; - } - - mVideoControl->setRect(mVideoControl->rect().x() - , scaledFrameWidth/6 - 0.5 - , (mToolBarItem->rect().width() - 35 - offset) / mAntiScaleRatio - , (2 * scaledFrameWidth) / mAntiScaleRatio); - - offset += (mVideoControl->rect().width() + 5) * mAntiScaleRatio; - mMuteButton->setPos(offset, 0); - - if (!mVideoControl->scene()) - { - mVideoControl->setParentItem(mToolBarItem);//update parent for the case the item has been previously removed from scene - mDelegated->scene()->addItem(mVideoControl); - } - - mVideoControl->setAntiScale(mAntiScaleRatio); - mVideoControl->setZValue(delegated()->zValue()); - mVideoControl->show(); - } - else - { - mVideoControl->hide(); - } -} - - -void UBGraphicsVideoItemDelegate::remove(bool canUndo) -{ - if (delegated() && delegated()->mediaObject()) - delegated()->mediaObject()->stop(); - - QGraphicsScene* scene = mDelegated->scene(); - - scene->removeItem(mVideoControl); - - UBGraphicsItemDelegate::remove(canUndo); -} - - -void UBGraphicsVideoItemDelegate::toggleMute() -{ - if (delegated()->isMuted()) - mMuteButton->setFileName(":/images/soundOff.svg"); - else - mMuteButton->setFileName(":/images/soundOn.svg"); - -} - - -UBGraphicsVideoItem* UBGraphicsVideoItemDelegate::delegated() -{ - return static_cast(mDelegated); -} - - -void UBGraphicsVideoItemDelegate::togglePlayPause() -{ - if (delegated() && delegated()->mediaObject()) { - - Phonon::MediaObject* media = delegated()->mediaObject(); - if (media->state() == Phonon::StoppedState) { - media->play(); - } else if (media->state() == Phonon::PlayingState) { - if (media->remainingTime() <= 0) { - media->stop(); - media->play(); - } else { - media->pause(); - if(delegated()->scene()) - delegated()->scene()->setModified(true); - } - } else if (media->state() == Phonon::PausedState) { - if (media->remainingTime() <= 0) { - media->stop(); - } - media->play(); - } else if ( media->state() == Phonon::LoadingState ) { - delegated()->mediaObject()->setCurrentSource(delegated()->mediaFileUrl()); - media->play(); - } else if (media->state() == Phonon::ErrorState){ - qDebug() << "Error appeared." << media->errorString(); - } - } -} - -void UBGraphicsVideoItemDelegate::mediaStateChanged ( Phonon::State newstate, Phonon::State oldstate ) -{ - Q_UNUSED(newstate); - Q_UNUSED(oldstate); - updatePlayPauseState(); -} - - -void UBGraphicsVideoItemDelegate::updatePlayPauseState() -{ - Phonon::MediaObject* media = delegated()->mediaObject(); - - if (media->state() == Phonon::PlayingState) - mPlayPauseButton->setFileName(":/images/pause.svg"); - else - mPlayPauseButton->setFileName(":/images/play.svg"); -} - - -void UBGraphicsVideoItemDelegate::updateTicker(qint64 time) -{ - Phonon::MediaObject* media = delegated()->mediaObject(); - mVideoControl->totalTimeChanged(media->totalTime()); - - mVideoControl->updateTicker(time); -} - - -void UBGraphicsVideoItemDelegate::totalTimeChanged(qint64 newTotalTime) -{ - mVideoControl->totalTimeChanged(newTotalTime); -} - - -DelegateVideoControl::DelegateVideoControl(UBGraphicsVideoItem* pDelegated, QGraphicsItem * parent) - : QGraphicsRectItem(parent) - , mDelegate(pDelegated) - , mDisplayCurrentTime(false) - , mAntiScale(1.0) - , mCurrentTimeInMs(0) - , mTotalTimeInMs(0) - , mStartWidth(200) -{ - setAcceptedMouseButtons(Qt::LeftButton); - - setBrush(QBrush(Qt::white)); - setPen(Qt::NoPen); - setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Control)); - - QRectF rect = this->rect(); - rect.setWidth(mStartWidth); - this->setRect(rect); -} - - -void DelegateVideoControl::paint(QPainter *painter, - const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - Q_UNUSED(option); - Q_UNUSED(widget); - - painter->fillPath(shape(), brush()); - - qreal frameWidth = rect().height() / 2; - int position = frameWidth; - - if (mTotalTimeInMs > 0) - { - position = frameWidth + (rect().width() - (2 * frameWidth)) / mTotalTimeInMs * mCurrentTimeInMs; - } - - int radius = rect().height() / 6; - QRectF r(rect().x() + position - radius, rect().y() + (rect().height() / 4) - radius, radius * 2, radius * 2); - - painter->setBrush(UBSettings::documentViewLightColor); - painter->drawEllipse(r); - - if(mDisplayCurrentTime) - { - painter->setBrush(UBSettings::paletteColor); - painter->setPen(QPen(Qt::NoPen)); - mBalloon.setRect(rect().x() + position - frameWidth, rect().y() - (frameWidth * 1.2), 2 * frameWidth, frameWidth); - painter->drawRoundedRect(mBalloon, frameWidth/2, frameWidth/2); - - QTime t; - t = t.addMSecs(mCurrentTimeInMs < 0 ? 0 : mCurrentTimeInMs); - QFont f = painter->font(); - f.setPointSizeF(f.pointSizeF() * mAntiScale); - painter->setFont(f); - painter->setPen(Qt::white); - painter->drawText(mBalloon, Qt::AlignCenter, t.toString("m:ss")); - } -} - - -QPainterPath DelegateVideoControl::shape() const -{ - QPainterPath path; - QRectF r = rect().adjusted(0,0,0,- rect().height() / 2); - path.addRoundedRect(r, rect().height() / 4, rect().height() / 4); - return path; -} - - -void DelegateVideoControl::updateTicker(qint64 time ) -{ - mCurrentTimeInMs = time; - update(); -} - - -void DelegateVideoControl::totalTimeChanged(qint64 newTotalTime) -{ - mTotalTimeInMs = newTotalTime; - update(); -} - - -void DelegateVideoControl::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - mDisplayCurrentTime = true; - seekToMousePos(event->pos()); - update(); - event->accept(); -} - - -void DelegateVideoControl::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - if (shape().contains(event->pos() - QPointF(mBalloon.width()/2,0)) - && shape().contains(event->pos() + QPointF(mBalloon.width()/2,0))) - { - seekToMousePos(event->pos()); - update(); - event->accept(); - } -} - - -void DelegateVideoControl::seekToMousePos(QPointF mousePos) -{ - qreal minX, length; - qreal frameWidth = rect().height() / 2; - - minX = rect().x() + frameWidth; - length = rect().width() - (2 * frameWidth); - - qreal mouseX = mousePos.x(); - - if (mTotalTimeInMs > 0 && length > 0 && mDelegate - && mDelegate->mediaObject() && mDelegate->mediaObject()->isSeekable()) - { - qint64 tickPos = mTotalTimeInMs / length * (mouseX - minX); - mDelegate->mediaObject()->seek(tickPos); - - //OSX is a bit lazy - updateTicker(tickPos); - } -} - -void DelegateVideoControl::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - mDisplayCurrentTime = false; - update(); - event->accept(); -} - - - diff --git a/src/domain/domain.pri b/src/domain/domain.pri index c7ed4466..4028dfed 100644 --- a/src/domain/domain.pri +++ b/src/domain/domain.pri @@ -10,7 +10,6 @@ HEADERS += src/domain/UBGraphicsScene.h \ src/domain/UBGraphicsSvgItem.h \ src/domain/UBGraphicsPolygonItem.h \ src/domain/UBItem.h \ - src/domain/UBGraphicsVideoItem.h \ src/domain/UBGraphicsWidgetItem.h \ src/domain/UBAppleWidget.h \ src/domain/UBGraphicsPDFItem.h \ @@ -20,8 +19,6 @@ HEADERS += src/domain/UBGraphicsScene.h \ src/domain/UBResizableGraphicsItem.h \ src/domain/UBGraphicsStroke.h \ src/domain/UBGraphicsMediaItem.h \ - src/domain/UBGraphicsAudioItem.h \ - src/domain/UBGraphicsAudioItemDelegate.h \ src/domain/UBAbstractUndoCommand.h\ src/domain/UBAngleWidget.h \ src/domain/ubgraphicsgroupcontaineritem.h \ @@ -29,10 +26,10 @@ HEADERS += src/domain/UBGraphicsScene.h \ src/domain/UBGraphicsStrokesGroup.h HEADERS += src/domain/UBGraphicsItemDelegate.h \ - src/domain/UBGraphicsVideoItemDelegate.h \ src/domain/UBGraphicsTextItemDelegate.h \ src/domain/UBGraphicsDelegateFrame.h \ - src/domain/UBGraphicsWidgetItemDelegate.h + src/domain/UBGraphicsWidgetItemDelegate.h \ + src/domain/UBGraphicsMediaItemDelegate.h SOURCES += src/domain/UBGraphicsScene.cpp \ @@ -56,8 +53,6 @@ SOURCES += src/domain/UBGraphicsScene.cpp \ src/domain/UBResizableGraphicsItem.cpp \ src/domain/UBGraphicsStroke.cpp \ src/domain/UBGraphicsMediaItem.cpp \ - src/domain/UBGraphicsAudioItem.cpp \ - src/domain/UBGraphicsAudioItemDelegate.cpp \ src/domain/UBAbstractUndoCommand.cpp \ src/domain/UBAngleWidget.cpp \ src/domain/ubgraphicsgroupcontaineritem.cpp \ @@ -65,8 +60,8 @@ SOURCES += src/domain/UBGraphicsScene.cpp \ src/domain/UBGraphicsStrokesGroup.cpp SOURCES += src/domain/UBGraphicsItemDelegate.cpp \ - src/domain/UBGraphicsVideoItemDelegate.cpp \ - src/domain/UBGraphicsTextItemDelegate.cpp \ + src/domain/UBGraphicsTextItemDelegate.cpp \ + src/domain/UBGraphicsMediaItemDelegate.cpp \ src/domain/UBGraphicsDelegateFrame.cpp \ - src/domain/UBGraphicsWidgetItemDelegate.cpp + src/domain/UBGraphicsWidgetItemDelegate.cpp \ diff --git a/src/domain/ubgraphicsgroupcontaineritem.cpp b/src/domain/ubgraphicsgroupcontaineritem.cpp index 91758a3e..cea31fb9 100644 --- a/src/domain/ubgraphicsgroupcontaineritem.cpp +++ b/src/domain/ubgraphicsgroupcontaineritem.cpp @@ -2,6 +2,8 @@ #include +#include "UBGraphicsMediaItem.h" +#include "UBGraphicsTextItem.h" #include "domain/UBGraphicsItemDelegate.h" #include "domain/ubgraphicsgroupcontaineritemdelegate.h" #include "domain/UBGraphicsScene.h" @@ -10,6 +12,7 @@ UBGraphicsGroupContainerItem::UBGraphicsGroupContainerItem(QGraphicsItem *parent) : QGraphicsItem(parent) + , mCurrentItem(NULL) { setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); @@ -128,6 +131,29 @@ void UBGraphicsGroupContainerItem::removeFromGroup(QGraphicsItem *item) itemsBoundingRect = childrenBoundingRect(); } +void UBGraphicsGroupContainerItem::deselectCurrentItem() +{ + if (mCurrentItem) + { + switch(mCurrentItem->type()) + { + case UBGraphicsTextItem::Type: + { + dynamic_cast(mCurrentItem)->Delegate()->getToolBarItem()->hide(); + } + break; + case UBGraphicsMediaItem::Type: + { + dynamic_cast(mCurrentItem)->Delegate()->getToolBarItem()->hide(); + } + break; + + } + mCurrentItem->setSelected(false); + mCurrentItem = NULL; + } +} + QRectF UBGraphicsGroupContainerItem::boundingRect() const { return itemsBoundingRect; @@ -234,5 +260,20 @@ void UBGraphicsGroupContainerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e QVariant UBGraphicsGroupContainerItem::itemChange(GraphicsItemChange change, const QVariant &value) { QVariant newValue = mDelegate->itemChange(change, value); + + foreach(QGraphicsItem *child, children()) + { + UBGraphicsItem *item = dynamic_cast(child); + if (item) + { + item->Delegate()->positionHandles(); + } + } + + if (QGraphicsItem::ItemSelectedChange == change) + { + deselectCurrentItem(); + } + return QGraphicsItem::itemChange(change, newValue); } diff --git a/src/domain/ubgraphicsgroupcontaineritem.h b/src/domain/ubgraphicsgroupcontaineritem.h index 18c5ffd5..a98bf9f1 100644 --- a/src/domain/ubgraphicsgroupcontaineritem.h +++ b/src/domain/ubgraphicsgroupcontaineritem.h @@ -13,6 +13,10 @@ public: void addToGroup(QGraphicsItem *item); void removeFromGroup(QGraphicsItem *item); + void setCurrentItem(QGraphicsItem *item){mCurrentItem = item;} + QGraphicsItem *getCurrentItem() const {return mCurrentItem;} + void deselectCurrentItem(); + QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); @@ -41,6 +45,7 @@ protected: private: QRectF itemsBoundingRect; + QGraphicsItem *mCurrentItem; }; diff --git a/src/domain/ubgraphicsgroupcontaineritemdelegate.cpp b/src/domain/ubgraphicsgroupcontaineritemdelegate.cpp index db50b095..48f1270f 100644 --- a/src/domain/ubgraphicsgroupcontaineritemdelegate.cpp +++ b/src/domain/ubgraphicsgroupcontaineritemdelegate.cpp @@ -50,7 +50,7 @@ void UBGraphicsGroupContainerItemDelegate::buildButtons() bool UBGraphicsGroupContainerItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_UNUSED(event) - + delegated()->deselectCurrentItem(); return false; } diff --git a/src/frameworks/UBCoreGraphicsScene.cpp b/src/frameworks/UBCoreGraphicsScene.cpp index 9eb68db7..8b127fc9 100644 --- a/src/frameworks/UBCoreGraphicsScene.cpp +++ b/src/frameworks/UBCoreGraphicsScene.cpp @@ -15,8 +15,6 @@ #include "UBCoreGraphicsScene.h" -#include "domain/UBGraphicsAudioItem.h" -#include "domain/UBGraphicsVideoItem.h" #include "domain/UBGraphicsMediaItem.h" #include "domain/UBGraphicsWidgetItem.h" @@ -66,11 +64,8 @@ bool UBCoreGraphicsScene::deleteItem(QGraphicsItem* item) UBGraphicsItem* item_casted = 0; switch (item->type()) { - case UBGraphicsAudioItem::Type: - item_casted = dynamic_cast(item); - break; - case UBGraphicsVideoItem::Type: - item_casted = dynamic_cast(item); + case UBGraphicsMediaItem::Type: + item_casted = dynamic_cast(item); break; case UBGraphicsW3CWidgetItem::Type: item_casted = dynamic_cast(item);