From d9cc7b6ecd34d762e2aefd367ebba312535ccd25 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 20 Aug 2012 15:08:05 +0300 Subject: [PATCH 1/9] Only selector tool can create and remove groups. --- src/domain/UBGraphicsScene.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 4c53593c..19a7e851 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -317,6 +317,11 @@ void UBGraphicsScene::selectionChangedProcessing() void UBGraphicsScene::updateGroupButtonState() { + + UBStylusTool::Enum currentTool = (UBStylusTool::Enum)UBDrawingController::drawingController()->stylusTool(); + if (UBStylusTool::Selector != currentTool) + return; + QAction *groupAction = UBApplication::mainWindow->actionGroupItems; QList selItems = selectedItems(); int selCount = selItems.count(); From 7c14893b3032a127a7579f33d5eb5000821c14af Mon Sep 17 00:00:00 2001 From: Yimgo Date: Mon, 20 Aug 2012 15:02:48 +0200 Subject: [PATCH 2/9] Fixed drag and drop in widget items. --- src/api/UBWidgetUniboardAPI.cpp | 22 ++++++------ src/api/UBWidgetUniboardAPI.h | 4 +-- src/board/UBBoardView.cpp | 50 +++++--------------------- src/domain/UBGraphicsWebView.cpp | 4 +-- src/domain/UBGraphicsWebView.h | 2 +- src/domain/UBGraphicsWidgetItem.cpp | 54 ++++++++++++++--------------- src/domain/UBGraphicsWidgetItem.h | 5 +-- 7 files changed, 53 insertions(+), 88 deletions(-) diff --git a/src/api/UBWidgetUniboardAPI.cpp b/src/api/UBWidgetUniboardAPI.cpp index 73ecbfae..0e2a54f1 100644 --- a/src/api/UBWidgetUniboardAPI.cpp +++ b/src/api/UBWidgetUniboardAPI.cpp @@ -476,7 +476,7 @@ void UBWidgetUniboardAPI::enableDropOnWidget(bool enable) } } -void UBWidgetUniboardAPI::ProcessDropEvent(QDropEvent *event) +void UBWidgetUniboardAPI::ProcessDropEvent(QGraphicsSceneDragDropEvent *event) { const QMimeData *pMimeData = event->mimeData(); @@ -485,11 +485,12 @@ void UBWidgetUniboardAPI::ProcessDropEvent(QDropEvent *event) bool downloaded = false; QGraphicsView *tmpView = mGraphicsWidget->scene()->views().at(0); - QPoint dropPoint(mGraphicsWidget->mapFromScene(tmpView->mapToScene(event->pos())).toPoint()); - Qt::DropActions dropActions = event->dropAction(); - Qt::MouseButtons dropMouseButtons = event->mouseButtons(); - Qt::KeyboardModifiers dropModifiers = event->keyboardModifiers(); - QMimeData dropMimeData; + QPoint dropPoint(mGraphicsWidget->mapFromScene(tmpView->mapToScene(event->pos().toPoint())).toPoint()); + Qt::DropActions dropActions = event->possibleActions(); + Qt::MouseButtons dropMouseButtons = event->buttons(); + Qt::KeyboardModifiers dropModifiers = event->modifiers(); + QMimeData *dropMimeData = new QMimeData; + qDebug() << event->possibleActions(); if (pMimeData->hasHtml()) { //Dropping element from web browser @@ -510,7 +511,7 @@ void UBWidgetUniboardAPI::ProcessDropEvent(QDropEvent *event) desc.name = QFileInfo(url).fileName(); desc.totalSize = 0; // The total size will be retrieved during the download - desc.dropPoint = event->pos(); //Passing pure event point. No modifications + desc.dropPoint = event->pos().toPoint(); //Passing pure event point. No modifications desc.dropActions = dropActions; desc.dropMouseButtons = dropMouseButtons; desc.dropModifiers = dropModifiers; @@ -542,12 +543,9 @@ void UBWidgetUniboardAPI::ProcessDropEvent(QDropEvent *event) } qDebug() << destFileName; QString mimeText = createMimeText(downloaded, contentType, destFileName); - dropMimeData.setData(tMimeText, mimeText.toAscii()); + dropMimeData->setData(tMimeText, mimeText.toAscii()); - QDropEvent readyEvent(dropPoint, dropActions, &dropMimeData, dropMouseButtons, dropModifiers); - //sending event to destination either it had been downloaded or not - QApplication::sendEvent(mGraphicsWidget,&readyEvent); - readyEvent.acceptProposedAction(); + event->setMimeData(dropMimeData); } void UBWidgetUniboardAPI::onDownloadFinished(bool pSuccess, sDownloadFileDesc desc, QByteArray pData) diff --git a/src/api/UBWidgetUniboardAPI.h b/src/api/UBWidgetUniboardAPI.h index 385f9417..a1bef6ce 100644 --- a/src/api/UBWidgetUniboardAPI.h +++ b/src/api/UBWidgetUniboardAPI.h @@ -16,7 +16,7 @@ #define UBWIDGETAPI_H #include -#include +#include #include "UBW3CWidgetAPI.h" #include "core/UBDownloadManager.h" @@ -246,7 +246,7 @@ class UBWidgetUniboardAPI : public QObject * When an object is dropped on a widget, this one send us the informations to download it locally. * this method download the object on the widget directory and return the path of the downloaded object */ - void ProcessDropEvent(QDropEvent *); + void ProcessDropEvent(QGraphicsSceneDragDropEvent *); bool isDropableData(const QMimeData *pMimeData) const; private slots: diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 7597d81e..7bbbd219 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -1202,56 +1202,22 @@ UBBoardView::drawItems (QPainter *painter, int numItems, } -void UBBoardView::dragMoveEvent (QDragMoveEvent *event) +void UBBoardView::dragMoveEvent(QDragMoveEvent *event) { - QGraphicsItem* graphicsItemAtPos = itemAt(event->pos().x(),event->pos().y()); - UBGraphicsWidgetItem* graphicsWidget = dynamic_cast(graphicsItemAtPos); - - if (graphicsWidget) { - if (graphicsWidget->acceptDrops()) { - if (!mOkOnWidget) { - if (!graphicsWidget->isDropableData(event->mimeData())) { - mOkOnWidget = false; - event->ignore(); - return; - } else { - mOkOnWidget = true; - } - } - QPoint newPoint(graphicsWidget->mapFromScene(mapToScene(event->pos())).toPoint()); - QDragMoveEvent newEvent(newPoint, event->dropAction(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers()); - QApplication::sendEvent(graphicsWidget,&newEvent); - } else { - mOkOnWidget = false; - event->ignore(); - } - } else { - event->acceptProposedAction(); - mOkOnWidget = false; - } + QGraphicsView::dragMoveEvent(event); + event->acceptProposedAction(); } void UBBoardView::dropEvent (QDropEvent *event) { - mOkOnWidget = false; - QGraphicsItem* graphicsItemAtPos = itemAt(event->pos().x(),event->pos().y()); - UBGraphicsWidgetItem* graphicsWidget = dynamic_cast(graphicsItemAtPos); - - if (graphicsWidget && graphicsWidget->acceptDrops()) { - - graphicsWidget->processDropEvent(event); - event->acceptProposedAction(); - - } else if (!event->source() - || dynamic_cast(event->source()) - || dynamic_cast(event->source()) - || dynamic_cast(event->source()) - || dynamic_cast(event->source()) - || dynamic_cast(event->source())) { - + if (!itemAt(event->pos().x(),event->pos().y())) { + if (!event->source() || dynamic_cast(event->source()) || dynamic_cast(event->source()) || dynamic_cast(event->source()) || dynamic_cast(event->source()) || dynamic_cast(event->source())) { mController->processMimeData (event->mimeData (), mapToScene (event->pos ())); event->acceptProposedAction(); } + } + else + QGraphicsView::dropEvent(event); } void diff --git a/src/domain/UBGraphicsWebView.cpp b/src/domain/UBGraphicsWebView.cpp index ea6a66ad..79b0d3f7 100644 --- a/src/domain/UBGraphicsWebView.cpp +++ b/src/domain/UBGraphicsWebView.cpp @@ -151,10 +151,10 @@ void UBGraphicsWebView::remove() mDelegate->remove(true); } -bool UBGraphicsWebView::event(QEvent *event) +/*bool UBGraphicsWebView::event(QEvent *event) { if (event->type() == QEvent::ShortcutOverride) event->accept(); return QGraphicsWebView::event(event); -} +}*/ diff --git a/src/domain/UBGraphicsWebView.h b/src/domain/UBGraphicsWebView.h index 988c4cbd..767a99c2 100644 --- a/src/domain/UBGraphicsWebView.h +++ b/src/domain/UBGraphicsWebView.h @@ -54,7 +54,7 @@ class UBGraphicsWebView: public QGraphicsWebView, public UBItem, public UBResiza virtual void wheelEvent(QGraphicsSceneWheelEvent *event); virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); - virtual bool event(QEvent *event); + //virtual bool event(QEvent *event); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); }; diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index 662cc947..0f056860 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -97,7 +97,6 @@ UBGraphicsWidgetItem::~UBGraphicsWidgetItem() void UBGraphicsWidgetItem::initialize() { - installEventFilter(this); UBGraphicsWebView::setMinimumSize(nominalSize()); setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); // Necessary to set if we want z value to be assigned correctly @@ -277,9 +276,9 @@ void UBGraphicsWidgetItem::removeScript() page()->mainFrame()->evaluateJavaScript("if(widget && widget.onremove) { widget.onremove();}"); } -void UBGraphicsWidgetItem::processDropEvent(QDropEvent *event) +void UBGraphicsWidgetItem::processDropEvent(QGraphicsSceneDragDropEvent *event) { - return mUniboardAPI->ProcessDropEvent(event); + mUniboardAPI->ProcessDropEvent(event); } bool UBGraphicsWidgetItem::isDropableData(const QMimeData *data) const { @@ -486,6 +485,31 @@ void UBGraphicsWidgetItem::unFreeze() mIsFrozen = false; } +bool UBGraphicsWidgetItem::event(QEvent *event) +{ + if (mShouldMoveWidget && event->type() == QEvent::MouseMove) { + QMouseEvent *mouseMoveEvent = static_cast(event); + if (mouseMoveEvent->buttons() & Qt::LeftButton) { + QPointF scenePos = mapToScene(mouseMoveEvent->pos()); + QPointF newPos = pos() + scenePos - mLastMousePos; + setPos(newPos); + mLastMousePos = scenePos; + event->accept(); + return true; + } + } + else if (event->type() == QEvent::ShortcutOverride) + event->accept(); + + return UBGraphicsWebView::event(event); +} + +void UBGraphicsWidgetItem::dropEvent(QGraphicsSceneDragDropEvent *event) +{ + processDropEvent(event); + QGraphicsWebView::dropEvent(event); +} + void UBGraphicsWidgetItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { UBGraphicsWebView::mousePressEvent(event); @@ -522,30 +546,6 @@ void UBGraphicsWidgetItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) UBGraphicsWebView::hoverMoveEvent(event); } -bool UBGraphicsWidgetItem::eventFilter(QObject *obj, QEvent *event) -{ - if (mShouldMoveWidget && obj == this && event->type() == QEvent::MouseMove) { - QMouseEvent *mouseMoveEvent = static_cast(event); - - if (mouseMoveEvent->buttons() & Qt::LeftButton) { - QPointF scenePos = mapToScene(mouseMoveEvent->pos()); - - QPointF newPos = pos() + scenePos - mLastMousePos; - - setPos(newPos); - - mLastMousePos = scenePos; - - event->accept(); - - return true; - } - } - - /* standard event processing */ - return QObject::eventFilter(obj, event); -} - void UBGraphicsWidgetItem::sendJSEnterEvent() { if (page() && page()->mainFrame()) diff --git a/src/domain/UBGraphicsWidgetItem.h b/src/domain/UBGraphicsWidgetItem.h index 08399603..18fbe1cc 100644 --- a/src/domain/UBGraphicsWidgetItem.h +++ b/src/domain/UBGraphicsWidgetItem.h @@ -76,7 +76,7 @@ class UBGraphicsWidgetItem : public UBGraphicsWebView virtual void remove(); void removeScript(); - void processDropEvent(QDropEvent *event); + void processDropEvent(QGraphicsSceneDragDropEvent *event); bool isDropableData(const QMimeData *data) const; virtual QUrl getOwnFolder() const; @@ -136,12 +136,13 @@ class UBGraphicsWidgetItem : public UBGraphicsWebView QMap mDatastore; QMap mPreferences; + virtual bool event(QEvent *event); + virtual void dropEvent(QGraphicsSceneDragDropEvent *event); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); - virtual bool eventFilter(QObject *obj, QEvent *event); virtual void sendJSEnterEvent(); virtual void sendJSLeaveEvent(); virtual void injectInlineJavaScript(); From 9d18db6d37e8abec1d918e1fdfcbe0e256e5092c Mon Sep 17 00:00:00 2001 From: Yimgo Date: Mon, 20 Aug 2012 15:07:41 +0200 Subject: [PATCH 3/9] Removed unnecessary comments. --- src/domain/UBGraphicsWebView.cpp | 8 -------- src/domain/UBGraphicsWebView.h | 1 - 2 files changed, 9 deletions(-) diff --git a/src/domain/UBGraphicsWebView.cpp b/src/domain/UBGraphicsWebView.cpp index 79b0d3f7..cfc92dc3 100644 --- a/src/domain/UBGraphicsWebView.cpp +++ b/src/domain/UBGraphicsWebView.cpp @@ -150,11 +150,3 @@ void UBGraphicsWebView::remove() if (mDelegate) mDelegate->remove(true); } - -/*bool UBGraphicsWebView::event(QEvent *event) -{ - if (event->type() == QEvent::ShortcutOverride) - event->accept(); - - return QGraphicsWebView::event(event); -}*/ diff --git a/src/domain/UBGraphicsWebView.h b/src/domain/UBGraphicsWebView.h index 767a99c2..45a2db7a 100644 --- a/src/domain/UBGraphicsWebView.h +++ b/src/domain/UBGraphicsWebView.h @@ -54,7 +54,6 @@ class UBGraphicsWebView: public QGraphicsWebView, public UBItem, public UBResiza virtual void wheelEvent(QGraphicsSceneWheelEvent *event); virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); - //virtual bool event(QEvent *event); virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); }; From c60d4992bc8a2b5597c8ed8b587e293d6113893e Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 20 Aug 2012 16:14:34 +0300 Subject: [PATCH 4/9] Grouped strokes reads from UBZ fine. it is grouped after reading now. --- src/adaptors/UBSvgSubsetAdaptor.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 370b3240..f557ff8a 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -1194,6 +1194,7 @@ bool UBSvgSubsetAdaptor::UBSvgSubsetWriter::persistScene(int pageIndex) UBGraphicsStrokesGroup* strokesGroupItem = qgraphicsitem_cast(item); if(strokesGroupItem && strokesGroupItem->isVisible()){ mXmlWriter.writeStartElement("g"); + mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "uuid", UBStringUtils::toCanonicalUuid(strokesGroupItem->uuid())); QMatrix matrix = item->sceneMatrix(); if (!matrix.isIdentity()){ mXmlWriter.writeAttribute("transform", toSvgTransform(matrix)); From 034503ddf822e73cc94fe07e01527c622e77075b Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Mon, 20 Aug 2012 16:31:30 +0300 Subject: [PATCH 5/9] Deprecated lib widget cleaned --- src/board/UBBoardPaletteManager.cpp | 15 - src/board/UBBoardPaletteManager.h | 11 - src/board/UBLibraryController.cpp | 850 ---------------------------- src/board/UBLibraryController.h | 185 ------ src/board/board.pri | 2 - src/gui/UBFeaturesActionBar.cpp | 25 + src/gui/UBFeaturesActionBar.h | 18 +- src/gui/UBFeaturesWidget.cpp | 21 +- src/gui/UBFeaturesWidget.h | 10 +- src/gui/UBLibActionBar.cpp | 534 ----------------- src/gui/UBLibActionBar.h | 120 ---- src/gui/UBLibItemProperties.cpp | 321 ----------- src/gui/UBLibItemProperties.h | 82 --- src/gui/UBLibNavigatorWidget.cpp | 189 ------- src/gui/UBLibNavigatorWidget.h | 57 -- src/gui/UBLibPathViewer.cpp | 582 ------------------- src/gui/UBLibPathViewer.h | 148 ----- src/gui/UBLibWebView.cpp | 89 --- src/gui/UBLibWebView.h | 32 -- src/gui/UBLibWidget.cpp | 230 -------- src/gui/UBLibWidget.h | 97 ---- src/gui/UBLibraryWidget.cpp | 704 ----------------------- src/gui/UBLibraryWidget.h | 124 ---- src/gui/gui.pri | 12 - 24 files changed, 47 insertions(+), 4411 deletions(-) delete mode 100644 src/board/UBLibraryController.cpp delete mode 100644 src/board/UBLibraryController.h delete mode 100644 src/gui/UBLibActionBar.cpp delete mode 100644 src/gui/UBLibActionBar.h delete mode 100644 src/gui/UBLibItemProperties.cpp delete mode 100644 src/gui/UBLibItemProperties.h delete mode 100644 src/gui/UBLibNavigatorWidget.cpp delete mode 100644 src/gui/UBLibNavigatorWidget.h delete mode 100644 src/gui/UBLibPathViewer.cpp delete mode 100644 src/gui/UBLibPathViewer.h delete mode 100644 src/gui/UBLibWebView.cpp delete mode 100644 src/gui/UBLibWebView.h delete mode 100644 src/gui/UBLibWidget.cpp delete mode 100644 src/gui/UBLibWidget.h delete mode 100644 src/gui/UBLibraryWidget.cpp delete mode 100644 src/gui/UBLibraryWidget.h diff --git a/src/board/UBBoardPaletteManager.cpp b/src/board/UBBoardPaletteManager.cpp index f6501393..83b2f3a4 100644 --- a/src/board/UBBoardPaletteManager.cpp +++ b/src/board/UBBoardPaletteManager.cpp @@ -82,12 +82,8 @@ UBBoardPaletteManager::UBBoardPaletteManager(QWidget* container, UBBoardControll , mPendingPanButtonPressed(false) , mPendingEraseButtonPressed(false) , mpPageNavigWidget(NULL) -//#ifdef USE_WEB_WIDGET - , mpLibWidget(NULL) -//#endif , mpCachePropWidget(NULL) , mpDownloadWidget(NULL) - , mpDesktopLibWidget(NULL) , mpTeacherGuideWidget(NULL) , mDownloadInProgress(false) { @@ -100,18 +96,11 @@ UBBoardPaletteManager::~UBBoardPaletteManager() { delete mAddItemPalette; - if(NULL != mStylusPalette) { delete mStylusPalette; mStylusPalette = NULL; } - - if(NULL != mpDesktopLibWidget) - { - delete mpDesktopLibWidget; - mpDesktopLibWidget = NULL; - } } void UBBoardPaletteManager::initPalettesPosAtStartup() @@ -135,10 +124,6 @@ void UBBoardPaletteManager::setupDockPaletteWidgets() mpPageNavigWidget = new UBPageNavigationWidget(); -#ifdef USE_WEB_WIDGET - mpLibWidget = new UBLibWidget(); -#endif - mpCachePropWidget = new UBCachePropertiesWidget(); mpDownloadWidget = new UBDockDownloadWidget(); diff --git a/src/board/UBBoardPaletteManager.h b/src/board/UBBoardPaletteManager.h index 335b4bcd..73493caf 100644 --- a/src/board/UBBoardPaletteManager.h +++ b/src/board/UBBoardPaletteManager.h @@ -22,7 +22,6 @@ #include "gui/UBLeftPalette.h" #include "gui/UBRightPalette.h" #include "gui/UBPageNavigationWidget.h" -#include "gui/UBLibWidget.h" #include "gui/UBCachePropertiesWidget.h" #include "gui/UBDockDownloadWidget.h" #include "core/UBApplicationController.h" @@ -136,11 +135,6 @@ class UBBoardPaletteManager : public QObject /** The page navigator widget */ UBPageNavigationWidget* mpPageNavigWidget; -//#ifdef USE_WEB_WIDGET - /** The library widget */ - UBLibWidget* mpLibWidget; -//#endif - /** The cache properties widget */ UBCachePropertiesWidget* mpCachePropWidget; @@ -148,11 +142,6 @@ class UBBoardPaletteManager : public QObject /** The download widget */ UBDockDownloadWidget* mpDownloadWidget; - // HACK: here we duplicate the lib widget for the desktop mode - // we MUST refactor the architecture in order to use only one - // lib widget! - UBLibWidget* mpDesktopLibWidget; - UBDockTeacherGuideWidget* mpTeacherGuideWidget; bool mDownloadInProgress; diff --git a/src/board/UBLibraryController.cpp b/src/board/UBLibraryController.cpp deleted file mode 100644 index d9204ef0..00000000 --- a/src/board/UBLibraryController.cpp +++ /dev/null @@ -1,850 +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 2 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 "UBLibraryController.h" - -#include "frameworks/UBFileSystemUtils.h" -#include "frameworks/UBPlatformUtils.h" - -#include "core/UBApplication.h" -#include "core/UBPersistenceManager.h" -#include "core/UBSettings.h" -#include "core/UBSetting.h" -#include "core/UBApplicationController.h" -#include "core/UBDownloadManager.h" - -#include "domain/UBGraphicsScene.h" -#include "domain/UBGraphicsSvgItem.h" -#include "domain/UBGraphicsPixmapItem.h" -#include "domain/UBGraphicsMediaItem.h" -#include "domain/UBGraphicsWidgetItem.h" - -#include "tools/UBToolsManager.h" - -#include "board/UBBoardView.h" - -#include "UBBoardController.h" - -#include "gui/UBThumbnailWidget.h" -#include "../core/UBSettings.h" - -#include "core/memcheck.h" - -static quint32 magicNumber = 0xACDCAFE0; -static QString favoriteVirtualPath = "$favorite$"; - -UBLibraryController::UBLibraryController(QWidget *pParentWidget) : - QObject(pParentWidget), - mParentWidget(pParentWidget), - mBoardController(UBApplication::boardController), - mLastItemOffsetIndex(0) -{ - readFavoriteList(); - - mAudioStandardDirectoryPath = QUrl::fromLocalFile(UBSettings::settings()->userAudioDirectory()); - - mVideoStandardDirectoryPath = QUrl::fromLocalFile(UBSettings::settings()->userVideoDirectory()); - - mPicturesStandardDirectoryPath = QUrl::fromLocalFile(UBSettings::settings()->userImageDirectory()); - - mInteractiveUserDirectoryPath = QUrl::fromLocalFile(UBSettings::settings()->userInteractiveDirectory()); - - mAnimationUserDirectoryPath = QUrl::fromLocalFile(UBSettings::settings()->userAnimationDirectory()); - - createInternalWidgetItems(); - -} - -bool UBLibraryController::canItemsOnElementBeDeleted(UBLibElement *pElement) -{ - return !pElement->path().toLocalFile().startsWith(UBSettings::settings()->applicationShapeLibraryDirectory()) && - !pElement->path().toLocalFile().startsWith(UBSettings::settings()->applicationInteractivesDirectory()) && - pElement->isDeletable(); -} - -void UBLibraryController::createInternalWidgetItems() -{ - QStringList toolUris = UBToolsManager::manager()->allToolIDs(); - - foreach(QString toolUri, toolUris) - { - UBToolsManager::UBToolDescriptor tool = UBToolsManager::manager()->toolByID(toolUri); - UBLibElement *newTool = new UBLibElement(eUBLibElementType_InteractiveItem, QUrl(tool.id), tool.label); - QImage toolImage = tool.icon.toImage(); - newTool->setThumbnail(toolImage); - newTool->setInformation(tool.label + " " + tool.version); - - mInternalLibElements << newTool; - } -} - -void UBLibraryController::createNewFolder(QString name, UBLibElement *parentElem) -{ - Q_ASSERT(parentElem); - Q_ASSERT(parentElem->type() == eUBLibElementType_Folder); - - QUrl qsPath = QUrl::fromLocalFile(parentElem->path().toLocalFile() + "/" + name); - createDirectory(qsPath); -} - -void UBLibraryController::createDirectory(QUrl& pDirPath) -{ - if(!QFileInfo(pDirPath.toLocalFile()).exists()) - QDir().mkpath(pDirPath.toLocalFile()); -} - - -QString UBLibraryController::getBaseDestinationForItem(QString& pItem) -{ - QString destination(""); - QString mimetype = UBFileSystemUtils::mimeTypeFromFileName(pItem); - - if(mimetype.contains("audio")) - destination = mAudioStandardDirectoryPath.toLocalFile(); - else if (mimetype.contains("video")) - destination = mVideoStandardDirectoryPath.toLocalFile(); - else if (mimetype.contains("image")) - destination = mPicturesStandardDirectoryPath.toLocalFile(); - else if (mimetype.contains("application")){ - if (mimetype.contains("x-shockwave-flash")) - destination = mAnimationUserDirectoryPath.toLocalFile(); - else - destination = mInteractiveUserDirectoryPath.toLocalFile(); - } - return destination; -} - -void UBLibraryController::routeDataItem(QString& pItem, QByteArray pData) -{ - QString fileName = QFileInfo(pItem).fileName(); - QString destination = getBaseDestinationForItem(pItem); - if(!destination.isEmpty()){ - QString destinationPath = UBFileSystemUtils::normalizeFilePath(QString("%0/%1").arg(destination).arg(fileName)); - QFile file(destinationPath); - if(file.open(QIODevice::WriteOnly)) { - file.write(pData); - file.close(); - } - } - else - qWarning() << "no destination found for pItem " << pItem; -} - -void UBLibraryController::routeItem(QString& pItem, QString pMiddleDirectory) -{ - QFileInfo itemToRoute(pItem); - QString destination = getBaseDestinationForItem(pItem); - - if(!destination.isEmpty()){ - if(!pMiddleDirectory.isEmpty()){ - destination = destination + "/" + pMiddleDirectory; - QUrl url = QUrl::fromLocalFile(destination); - createDirectory(url); - } - destination = UBFileSystemUtils::normalizeFilePath(destination + "/" + itemToRoute.fileName()); - - UBFileSystemUtils::copyFile(QUrl(pItem).toLocalFile(), destination, false); - } -} - -void UBLibraryController::importImageOnLibrary(QImage& pImage) -{ - if(!pImage.isNull()){ - QDateTime now = QDateTime::currentDateTime(); - QString filePath = mPicturesStandardDirectoryPath.toLocalFile() + "/" + tr("ImportedImage") + "-" + now.toString("dd-MM-yyyy hh-mm-ss") + ".png"; - filePath = UBFileSystemUtils::normalizeFilePath(filePath); - pImage.save(filePath); - UBApplication::showMessage(tr("Added 1 Image to Library")); - emit updateItemsList(); - } -} - -void UBLibraryController::importItemOnLibrary(QString& pItemString) -{ - pItemString.replace("\r",""); - pItemString.replace("\n",""); - - QFileInfo itemToImport(pItemString); - - bool isZip = false; - if(itemToImport.isDir() || (isZip = UBFileSystemUtils::isAZipFile(pItemString))){ - if(pItemString.contains(".wgt",Qt::CaseInsensitive) || pItemString.contains(".wdgt",Qt::CaseInsensitive)){ - QString destination = UBSettings::settings()->userInteractiveDirectory() + "/" + itemToImport.fileName(); - if(isZip) - UBFileSystemUtils::expandZipToDir(pItemString,destination); - else{ - if(pItemString.endsWith("/")) pItemString.chop(1); - UBFileSystemUtils::copyDir(pItemString, destination + QFileInfo(pItemString).fileName() + "/"); - } - return; - } - - QStringList allFiles = UBFileSystemUtils::allFiles(pItemString); - QString pathBeforeCurrentDir = pItemString; - pathBeforeCurrentDir.replace(UBFileSystemUtils::lastPathComponent(pathBeforeCurrentDir), ""); - if(pathBeforeCurrentDir.endsWith("//")) - pathBeforeCurrentDir.chop(1); - - foreach(QString eachFile, allFiles){ - QString intermediateDirectory = eachFile; - intermediateDirectory = intermediateDirectory.remove(pathBeforeCurrentDir); - intermediateDirectory = intermediateDirectory.remove(QFileInfo(eachFile).fileName()); - routeItem(eachFile,intermediateDirectory); - } - } - else{ - if(pItemString.startsWith("uniboardTool://") || pItemString.startsWith("file://") || pItemString.startsWith("/")) - { - // The user dropped a local file - routeItem(pItemString); - } - else - { - // The user dropped a file from the web. We must download it. - sDownloadFileDesc desc; - desc.currentSize = 0; - desc.id = 0; - desc.isBackground = false; - desc.modal = false; - desc.name = QFileInfo(pItemString).fileName(); - desc.totalSize = 0; - desc.url = pItemString; - UBDownloadManager::downloadManager()->addFileToDownload(desc); - } - } - -} - -QList UBLibraryController::rootCategoriesList() -{ - QList categories; - - UBLibElement* element = new UBLibElement(eUBLibElementType_Folder, mAudioStandardDirectoryPath, tr("Audios", "Audio category element")); - element->setThumbnail(QImage(":images/libpalette/AudiosCategory.svg")); - element->setMoveable(false); - categories << element; - - element = new UBLibElement(eUBLibElementType_Folder, mVideoStandardDirectoryPath, tr("Movies", "Movies category element")); - element->setThumbnail(QImage(":images/libpalette/MoviesCategory.svg")); - element->setMoveable(false); - categories << element; - - element = new UBLibElement(eUBLibElementType_Folder, mPicturesStandardDirectoryPath, tr("Pictures", "Pictures category element")); - element->setThumbnail(QImage(":images/libpalette/PicturesCategory.svg")); - element->setMoveable(false); - categories << element; - - QString path = UBSettings::settings()->applicationShapeLibraryDirectory(); - element = new UBLibElement(eUBLibElementType_Folder, QUrl::fromLocalFile(path), tr("Shapes", "Shapes category element")); - element->setThumbnail(QImage(":images/libpalette/ShapesCategory.svg")); - element->setMoveable(false); - categories << element; - - element = new UBLibElement(eUBLibElementType_Folder, mInteractiveUserDirectoryPath, tr("Applications", "Applications category element")); - element->setThumbnail(QImage(":images/libpalette/ApplicationsCategory.svg")); - element->setMoveable(false); - categories << element; - - element = new UBLibElement(eUBLibElementType_VirtualFolder, favoriteVirtualPath, tr("Favorite", "Favorite category element")); - element->setThumbnail(QImage(":images/libpalette/FavoritesCategory.svg")); - element->setMoveable(false); - categories << element; - - mInteractiveCategoryPath = QUrl::fromLocalFile(UBSettings::settings()->userGipLibraryDirectory()); - element = new UBLibElement(eUBLibElementType_Folder, mInteractiveCategoryPath, tr("Interactivities", "Interactives category element")); - element->setThumbnail(QImage(":images/libpalette/InteractivesCategory.svg")); - element->setMoveable(false); - categories << element; - - mSearchCategoryPath = QUrl::fromLocalFile(UBSettings::userSearchDirectory()); - element = new UBLibElement(eUBLibElementType_Folder, mSearchCategoryPath, tr("Web Search", "Web search category element")); - element->setThumbnail(QImage(":images/libpalette/WebSearchCategory.svg")); - element->setMoveable(false); - categories << element; - - element = new UBLibElement(eUBLibElementType_Folder, mAnimationUserDirectoryPath, tr("Animations", "Animations category element")); - element->setThumbnail(QImage(":images/libpalette/FlashCategory.svg")); - element->setMoveable(false); - categories << element; - - - - categories << UBLibElement::trashElement(); - - return categories; -} - -QImage UBLibraryController::createThumbnail(UBLibElement* pElement) -{ - QString thumbnailPath = UBFileSystemUtils::thumbnailPath(pElement->path().toLocalFile()); - QString mimetype = UBFileSystemUtils::mimeTypeFromFileName(pElement->path().toLocalFile()); - - if (mimetype.contains("audio")) - thumbnailPath = ":images/libpalette/soundIcon.svg"; - else if (mimetype.contains("video")) - thumbnailPath = ":images/libpalette/movieIcon.svg"; - else { - if (pElement->extension().startsWith("svg", Qt::CaseInsensitive) || pElement->extension().startsWith("svgz", Qt::CaseInsensitive)) { - thumbnailPath = pElement->path().toLocalFile(); - UBThumbnailSvg(pElement->path().toLocalFile()); - } - else { - QPixmap pix(pElement->path().toLocalFile()); - if (!pix.isNull()) { - pix = pix.scaledToWidth(qMin(UBSettings::maxThumbnailWidth, pix.width()), Qt::SmoothTransformation); - pix.save(thumbnailPath); - UBThumbnailPixmap pixmap(pix); - UBPlatformUtils::hideFile(thumbnailPath); - UBApplication::showMessage(tr("Creating image thumbnail for %1.").arg(pElement->name())); - } - else{ - thumbnailPath = ":images/libpalette/notFound.png"; - } - } - } - - return QImage(thumbnailPath); -} - -QImage UBLibraryController::thumbnailForFile(UBLibElement* pElement) -{ - if (pElement->path().toString().contains("uniboardTool://")){ - QImage image = QImage(UBToolsManager::manager()->iconFromToolId(pElement->path().toString())); - return image; - } - if (pElement->type() == eUBLibElementType_InteractiveItem){ - QImage image = QImage(UBGraphicsWidgetItem::iconFilePath(pElement->path())); - return image; - } - - QString thumbnailPath = UBFileSystemUtils::thumbnailPath(pElement->path().toLocalFile()); - - if (!thumbnailPath.length()) - qWarning() << "thumbnailForFile impossible to create thumbnail path for the element " + pElement->path().toLocalFile(); - - if (QFileInfo(thumbnailPath).exists()) - return QImage(thumbnailPath); - else - return createThumbnail(pElement); -} - -QList UBLibraryController::addVirtualElementsForItemPath(const QString& pPath) -{ - QList content; - if (pPath == mInteractiveUserDirectoryPath.toLocalFile()){ - content << listElementsInPath(UBSettings::settings()->applicationApplicationsLibraryDirectory()); - content << listElementsInPath(UBSettings::settings()->userInteractiveFavoritesDirectory()); - foreach(UBLibElement* eachElement, mInternalLibElements) - content << new UBLibElement(eachElement); - } - else if (pPath == mPicturesStandardDirectoryPath.toLocalFile()){ - QUrl path = QUrl::fromLocalFile(UBSettings::settings()->applicationImageLibraryDirectory()); - content << listElementsInPath(path.toLocalFile()); - } - else if (pPath == mInteractiveCategoryPath.toLocalFile()){ - content << listElementsInPath(UBSettings::settings()->applicationInteractivesDirectory()); - } - else if (pPath == mAudioStandardDirectoryPath.toLocalFile()){ - content << listElementsInPath(UBSettings::settings()->applicationAudiosLibraryDirectory()); - } - else if (pPath == mVideoStandardDirectoryPath.toLocalFile()){ - content << listElementsInPath(UBSettings::settings()->applicationVideosLibraryDirectory()); - } - else if (pPath == mAnimationUserDirectoryPath.toLocalFile()){ - content << listElementsInPath(UBSettings::settings()->applicationAnimationsLibraryDirectory()); - } - - return content; - -} - -QList UBLibraryController::listElementsInPath(const QString& pPath) -{ - QList content; - QFileInfoList fileInfoList = UBFileSystemUtils::allElementsInDirectory(pPath); - - QFileInfoList::iterator fileInfo; - for (fileInfo = fileInfoList.begin(); fileInfo != fileInfoList.end(); fileInfo += 1) { - eUBLibElementType fileType = fileInfo->isDir() ? eUBLibElementType_Folder : eUBLibElementType_Item; - - QString itemName = fileInfo->fileName(); - QString extension=""; - if (UBFileSystemUtils::mimeTypeFromFileName(itemName).contains("application")) { - fileType = eUBLibElementType_InteractiveItem; - itemName = fileInfo->baseName(); - extension = fileInfo->completeSuffix(); - } - - - UBLibElement *element = new UBLibElement(fileType, QUrl::fromLocalFile(fileInfo->absoluteFilePath()), itemName); - - if(!extension.isEmpty()) - element->setExtension(extension); - - if (fileType == eUBLibElementType_Folder) { - element->setThumbnail(QImage(":images/libpalette/folder.svg")); - } - else if (fileType == eUBLibElementType_Item) { - if (element->path().toLocalFile().contains(".thumbnail.")) - continue; - element->setThumbnail(thumbnailForFile(element)); - } - content << element; - } - content << addVirtualElementsForItemPath(pPath); - - return content; -} - - - -QList UBLibraryController::listElementsInVirtualForlder(UBLibElement* pElement) -{ - Q_UNUSED(pElement); - QList copyOfTheFavoriteList; - foreach(UBLibElement* eachElement, mFavoriteList) - copyOfTheFavoriteList << new UBLibElement(eachElement); - return copyOfTheFavoriteList; -} - -void UBLibraryController::moveContent(QList sourceList, UBLibElement *pDestination) -{ - if (pDestination->type() != eUBLibElementType_Folder) - qWarning() << "moveContent the destination element isn't a directory"; - - foreach (UBLibElement* eachSource, sourceList) { - if (!eachSource || pDestination->path().toLocalFile() == eachSource->path().toLocalFile() || eachSource->type() == eUBLibElementType_VirtualFolder) - continue; - - if (QFileInfo(eachSource->path().toLocalFile()).isDir()) - UBFileSystemUtils::moveDir(eachSource->path().toLocalFile(), pDestination->path().toLocalFile() + "/" + eachSource->name()); - else { - QFile(eachSource->path().toLocalFile()).copy(pDestination->path().toLocalFile() + "/" + eachSource->name() + "." + eachSource->extension()); - QFile::remove(eachSource->path().toLocalFile()); - QString thumbnailPath = UBFileSystemUtils::thumbnailPath(eachSource->path().toLocalFile()); - if (thumbnailPath.length() && QFileInfo(thumbnailPath).exists()) { - QString thumbnailFileName = UBFileSystemUtils::lastPathComponent(thumbnailPath); - QFile(thumbnailPath).copy(pDestination->path().toLocalFile() + "/" + thumbnailFileName); - QFile::remove(thumbnailPath); - } - } - } -} - -void UBLibraryController::trashElements(QList trashList) -{ - moveContent(trashList, UBLibElement::trashElement()); - removeFromFavorite(trashList); -} - -void UBLibraryController::emptyElementsOnTrash( QList elementsList) -{ - foreach(UBLibElement* eachElement, elementsList) { - if (QFileInfo(eachElement->path().toLocalFile()).isDir()) - UBFileSystemUtils::deleteDir(eachElement->path().toLocalFile()); - else - QFile::remove(eachElement->path().toLocalFile()); - } -} - -void UBLibraryController::cleanElementsList() -{ - qDeleteAll(mElementsList); - mElementsList.clear(); -} - -QList UBLibraryController::getContent(UBLibElement *element) -{ - cleanElementsList(); - - switch (element->type()) { - case eUBLibElementType_Category: { - mElementsList = rootCategoriesList(); - break; - } - case eUBLibElementType_VirtualFolder: { - mElementsList = listElementsInVirtualForlder(element); - break; - } - case eUBLibElementType_Folder: { - mElementsList = listElementsInPath(element->path().toLocalFile()); - break; - } - case eUBLibElementType_Item: { - qWarning() << "You are browsing a file"; - break; - } - default: - // We should never come here... - Q_ASSERT(false); - break; - } - - return mElementsList; -} - -UBLibraryController::~UBLibraryController() -{ - cleanElementsList(); - - qDeleteAll(mInternalLibElements); - mInternalLibElements.clear(); -} - -void UBLibraryController::setItemAsBackground(UBLibElement* image) -{ - if (!activeScene()){ - qDebug() << "No active scene"; - return; - } - QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(image->path().toLocalFile()); - - if(mimeType == "image/svg+xml"){ - QUrl url(QUrl::fromLocalFile(image->path().toLocalFile())); - QGraphicsSvgItem* boardItem = activeScene()->addSvg(url, QPointF(0, 0)); - activeScene()->setAsBackgroundObject(boardItem, true, true); - } - else{ - QPixmap pix(image->path().toLocalFile()); - UBGraphicsPixmapItem* boardItem = activeScene()->addPixmap(pix, activeScene()->backgroundObject(), QPointF(0, 0)); - activeScene()->setAsBackgroundObject(boardItem, true); - } -} - -void UBLibraryController::addItemToPage(UBLibElement* item) -{ - QList list; - list << QUrl::fromLocalFile(item->path().toLocalFile()); - QString mimeType = UBFileSystemUtils::mimeTypeFromFileName(item->path().toLocalFile()); - - if (mimeType.contains("image")){ - addImagesToCurrentPage(list); - } - else if (mimeType.contains("audio")){ - addAudiosToCurrentPage(list); - } - else if (mimeType.contains("video")){ - addVideosToCurrentPage(list); - } - else if (mimeType.contains("application")){ - addInteractivesToCurrentPage(list); - } - else if (mimeType.isEmpty() && item->type() == eUBLibElementType_InteractiveItem){ - // Those conditions allow us to detect internal app like - // mask, ruler, compass and protractor - list.clear(); - list << item->path().toString().replace("file:",""); - addInteractivesToCurrentPage(list); - } - else{ - UBApplication::showMessage(tr("Adding to page failed for item %1.").arg(item->name())); - } -} - -void UBLibraryController::removeBackground() -{ - if (activeScene()) - activeScene()->setAsBackgroundObject(0); - -} - -UBGraphicsScene* UBLibraryController::activeScene() -{ - if (mBoardController->selectedDocument()) - return mBoardController->activeScene(); - - return 0; -} - - -void UBLibraryController::persistFavoriteList() -{ - QFile file(UBSettings::userFavoriteListFilePath()); - file.open(QIODevice::WriteOnly); - QDataStream out(&file); - //magic number - out << magicNumber; - out << (quint32)mFavoriteList.count(); - foreach(UBLibElement* eachElement, mFavoriteList) - { - out << (quint32)eachElement->type(); - out << eachElement->path().toString(); - out << eachElement->information(); - out << eachElement->name(); - out << eachElement->extension(); - } - file.close(); -} - -void UBLibraryController::readFavoriteList() -{ - QFile file(UBSettings::userFavoriteListFilePath()); - file.open(QIODevice::ReadOnly); - QDataStream in(&file); // read the data serialized from the file - quint32 magicNumber; - quint32 numberOfElements; - - in >> magicNumber >> numberOfElements; - - for(quint32 i = 0; i < numberOfElements; i += 1){ - quint32 type; - QString path; - QString info; - QString name; - QString extension; - - in >> type >> path >> info >> name >> extension; - - UBLibElement* eachElement = new UBLibElement((eUBLibElementType)type, QUrl(path), name); - eachElement->setInformation(info); - eachElement->setExtension(extension); - eachElement->setThumbnail(thumbnailForFile(eachElement)); - if(!isOnFavoriteList(eachElement)) - mFavoriteList << eachElement; - } - - file.close(); - persistFavoriteList(); -} - -UBLibElement* UBLibraryController::isOnFavoriteList(UBLibElement * element) -{ - foreach(UBLibElement* eachElement, mFavoriteList) - if(eachElement->path() == element->path()) - return eachElement; - - return 0; -} -void UBLibraryController::addToFavorite(QList elementList) -{ - - foreach(UBLibElement* eachElement, elementList) - if(!isOnFavoriteList(eachElement)) - mFavoriteList << new UBLibElement(eachElement); - - persistFavoriteList(); -} - - -void UBLibraryController::removeFromFavorite(QList elementList) -{ - foreach(UBLibElement* eachElement, elementList){ - UBLibElement* elementToRemove = isOnFavoriteList(eachElement); - if(elementToRemove) - mFavoriteList.removeOne(elementToRemove); - } - - persistFavoriteList(); -} - -QRectF UBLibraryController::visibleSceneRect() -{ - QRectF visibleSceneRect(0, 0, 0, 0); - - if (activeScene() && mBoardController && mBoardController->controlView()) { - QPointF topLeftCorner = mBoardController->controlGeometry().topLeft(); - QPointF bottomRightCorner = - mBoardController->controlGeometry().bottomRight(); - - QPointF sceneTopLeft = mBoardController->controlView()->mapToScene( - topLeftCorner.toPoint()); - QPointF sceneBottomRight = mBoardController->controlView()->mapToScene( - bottomRightCorner.toPoint()); - - visibleSceneRect.setTopLeft(sceneTopLeft); - visibleSceneRect.setBottomRight(sceneBottomRight); - } - - return visibleSceneRect; -} - -void UBLibraryController::addImagesToCurrentPage(const QList& images) -{ - QPointF pos = UBApplication::boardController->activeScene()->normalizedSceneRect().center(); - - - foreach(const QUrl url, images) - { - mLastItemOffsetIndex = qMin(mLastItemOffsetIndex, 5); - - QGraphicsItem* itemInScene = 0; - - if (activeScene()) { - QString mimeType = UBFileSystemUtils::mimeTypeFromFileName( - url.toString()); - - pos = QPointF(pos.x() + 50 * mLastItemOffsetIndex, pos.y() + 50 * mLastItemOffsetIndex); - mLastItemOffsetIndex++; - //TODO UB 4.x move this logic to the scene .. - if (mimeType == "image/svg+xml") { - itemInScene = activeScene()->addSvg(url, pos); - } else { - itemInScene = activeScene()->addPixmap(QPixmap( - url.toLocalFile()), NULL, pos); - } - } - - if (itemInScene) { - itemInScene = activeScene()->scaleToFitDocumentSize(itemInScene, false, UBSettings::objectInControlViewMargin); - } - } -} - -void UBLibraryController::addVideosToCurrentPage(const QList& videos) -{ - QPointF pos = visibleSceneRect().topLeft(); - - foreach(const QUrl url, videos) - { - mLastItemOffsetIndex++; - mLastItemOffsetIndex = qMin(mLastItemOffsetIndex, 5); - - UBGraphicsMediaItem* itemInScene = UBApplication::boardController->addVideo(url, false, pos); - itemInScene->setPos(QPoint(pos.x() + 50 * mLastItemOffsetIndex, pos.y() + 50 * mLastItemOffsetIndex)); - } -} - -void UBLibraryController::addAudiosToCurrentPage(const QList& sounds) -{ - QPointF centerPos = visibleSceneRect().center(); - - QPointF pos = centerPos; - - //move it a little higher for convenience - centerPos.setX(pos.x() - 200); - centerPos.setY(pos.y() - 100); - - foreach(const QUrl url, sounds) - { - mLastItemOffsetIndex++; - mLastItemOffsetIndex = qMin(mLastItemOffsetIndex, 5); - pos = QPointF(centerPos.x() + 50 * mLastItemOffsetIndex, - centerPos.y() + 50 * mLastItemOffsetIndex); - UBApplication::boardController->addAudio(url, false, pos); - } -} - -void UBLibraryController::addInteractivesToCurrentPage( const QList& widgets) -{ - foreach(const QUrl url, widgets) - mBoardController->downloadURL(url, QPointF(0, 0)); -} - -QString UBLibraryController::favoritePath() -{ - return favoriteVirtualPath; -} - -UBLibElement::UBLibElement() { - mType = eUBLibElementType_Category; - mName = QObject::tr("/Home", "Category list label on navigation tool bar"); - mbMoveable = false; - mbDeletable = true; -} - -UBLibElement::UBLibElement(UBLibElement* element) -{ - mType = element->type(); - mPath = element->path(); - mThumbnail = *element->thumbnail(); - mInfo = element->information(); - mName = element->name(); - mExtension = element->extension(); - mbMoveable = element->isMoveable(); - mbDeletable = element->isDeletable(); -} - - -UBLibElement::UBLibElement(eUBLibElementType type, const QUrl &path, const QString &name) -{ - mType = type; - mPath = path; - mName = name; - mInfo = ""; - mbMoveable = true; - mbDeletable = true; - - if (type == eUBLibElementType_Folder) - mThumbnail = QImage(":images/libpalette/folder.svg"); - - if (type == eUBLibElementType_InteractiveItem) - mThumbnail = QImage(UBGraphicsWidgetItem::iconFilePath(path)); - - if (type == eUBLibElementType_Item) - mExtension = QFileInfo(path.toLocalFile()).completeSuffix(); - - if(type == eUBLibElementType_VirtualFolder || type == eUBLibElementType_Category) - mbMoveable = false; -} - -UBLibElement::~UBLibElement() -{ - //NOOP -} - -UBChainedLibElement::UBChainedLibElement(UBLibElement *pElem, UBChainedLibElement *pNextElem) -{ - mpElem = new UBLibElement(pElem); - mpNextElem = pNextElem; -} - -UBChainedLibElement::~UBChainedLibElement() -{ - if (NULL != mpNextElem) { - delete mpNextElem; - mpNextElem = NULL; - } - delete mpElem; -} - -void UBChainedLibElement::setNextElement(UBChainedLibElement *nextElem) -{ - mpNextElem = nextElem; -} - -UBChainedLibElement* UBChainedLibElement::lastElement() -{ - UBChainedLibElement* pElem = NULL; - - if(NULL != mpNextElem) - { - UBChainedLibElement* pLast = mpNextElem->lastElement(); - if(NULL != pLast) - { - pElem = pLast; - } - else - { - pElem = mpNextElem; - } - } - - return pElem; -} - -QUrl UBChainedLibElement::lastItemPath() -{ - return lastElement()->element()->path(); -} - -UBLibElement* UBLibElement::trashElement() -{ - UBLibElement *trashElement; - trashElement = new UBLibElement(eUBLibElementType_Folder, QUrl::fromLocalFile(UBSettings::userTrashDirPath()), QObject::tr("Trash", "Pictures category element")); - trashElement->setThumbnail(QImage(":images/libpalette/TrashCategory.svg")); - trashElement->setMoveable(false); - - return trashElement; -} - diff --git a/src/board/UBLibraryController.h b/src/board/UBLibraryController.h deleted file mode 100644 index 25e397c2..00000000 --- a/src/board/UBLibraryController.h +++ /dev/null @@ -1,185 +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 2 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 UBLIBRARYCONTROLLER_H_ -#define UBLIBRARYCONTROLLER_H_ - -#include -#include - -#include "web/UBWebPage.h" - -class UBGraphicsScene; -class UBBoardController; -class QGraphicsSvgItem; -class UBLibraryWebView; -class UBWebView; - -typedef enum -{ - eUBLibElementType_Category = 0, - eUBLibElementType_VirtualFolder, - eUBLibElementType_Folder, - eUBLibElementType_InteractiveItem, - eUBLibElementType_Item -}eUBLibElementType; - - -class UBLibElement -{ - -public: - UBLibElement(); - UBLibElement(eUBLibElementType type, const QUrl& path, const QString& name); - UBLibElement(UBLibElement* element); - virtual ~UBLibElement(); - - static UBLibElement* trashElement(); - - eUBLibElementType type(){return mType;} - void setType(eUBLibElementType type) {mType = type;} - QUrl path(){return mPath;} - void setPath(QUrl path){mPath = path;} - QImage* thumbnail(){return &mThumbnail;} - void setThumbnail(QImage pThumb){mThumbnail = pThumb;} - QString information(){return mInfo;} - void setInformation(QString info){mInfo = info;} - QString name(){return mName;} - void setName(QString name){mName = name;} - QString extension(){return mExtension;} - void setExtension(QString &extension){ mExtension = extension;} - bool isMoveable(){return mbMoveable;} - void setMoveable(bool bState){mbMoveable = bState;} - bool isDeletable() const {return mbDeletable;} - void setDeletable(bool mState) {mbDeletable = mState;} - void setMetadata(QMap metadatas){mMetadata = metadatas;} - QMap metadatas(){return mMetadata;} - -private: - eUBLibElementType mType; - QUrl mPath; - QImage mThumbnail; - QString mInfo; - QString mName; - QString mExtension; - bool mbMoveable; - bool mbDeletable; - QMap mMetadata; -}; - -class UBChainedLibElement -{ -public: - UBChainedLibElement(UBLibElement* pElem, UBChainedLibElement* pNextElem=NULL); - virtual ~UBChainedLibElement(); - - UBChainedLibElement* nextElement(){return mpNextElem;} - UBChainedLibElement* lastElement(); - void setNextElement(UBChainedLibElement* nextElem); - UBLibElement* element(){return mpElem;} - QUrl lastItemPath(); - -private: - UBLibElement* mpElem; - UBChainedLibElement* mpNextElem; -}; - -class UBLibraryController : public QObject -{ - Q_OBJECT; - - public: - UBLibraryController(QWidget *parentWidget); - virtual ~UBLibraryController(); - - QList getContent(UBLibElement* pElement); - void moveContent(QList sourceList, UBLibElement *pDestination); - void trashElements(QList trashList); - void emptyElementsOnTrash(QList elementsList); - - void addNativeToolToFavorites(const QUrl& url); - - void setItemAsBackground(UBLibElement* image); - void addItemToPage(UBLibElement* item); - - void addToFavorite(QList elementList); - void removeFromFavorite(QList elementList); - - void importItemOnLibrary(QString& pItemString); - void importImageOnLibrary(QImage &pImage); - - QString favoritePath(); - - void createNewFolder(QString name, UBLibElement* parentElem); - bool canItemsOnElementBeDeleted(UBLibElement *pElement); - - void routeItem(QString& pItem, QString pMiddleDirectory = QString()); - void routeDataItem(QString& pItem, QByteArray pData); - - signals: - void dialogClosed(int state); - void setResource(QString &pathResource,QString &mimetype); - void updateItemsList(); - - public slots: - void removeBackground(); - void addImagesToCurrentPage(const QList& images); - void addVideosToCurrentPage(const QList& videos); - void addAudiosToCurrentPage(const QList& sounds); - void addInteractivesToCurrentPage(const QList& interactiveWidgets); - - protected: - - UBGraphicsScene* activeScene(); - QRectF visibleSceneRect(); - QList mFavoriteList; - void persistFavoriteList(); - void readFavoriteList(); - QList mInternalLibElements; - QList mElementsList; - void cleanElementsList(); - - private: - QList rootCategoriesList(); - QList listElementsInPath(const QString& pPath); - QList listElementsInVirtualForlder(UBLibElement* pElement); - void userPath(QUrl &pPath); - QImage thumbnailForFile(UBLibElement* pPath); - QImage createThumbnail(UBLibElement* pPath); - QList addVirtualElementsForItemPath(const QString& pPath); - - void createInternalWidgetItems(); - void createDirectory(QUrl& pDirPath); - - QUrl mAudioStandardDirectoryPath; - QUrl mVideoStandardDirectoryPath; - QUrl mPicturesStandardDirectoryPath; - QUrl mInteractiveUserDirectoryPath; - QUrl mInteractiveCategoryPath; - QUrl mAnimationUserDirectoryPath; - QUrl mSearchCategoryPath; - - QStringList addItemsToCurrentLibrary(const QDir& pSelectedFolder, const QStringList& pExtensions); - - UBLibElement* isOnFavoriteList(UBLibElement * element); - - QWidget *mParentWidget; - UBBoardController *mBoardController; - - int mLastItemOffsetIndex; - QString getBaseDestinationForItem(QString& pItem); - -}; - -#endif /* UBLIBRARYCONTROLLER_H_ */ diff --git a/src/board/board.pri b/src/board/board.pri index 1208db87..c8d421e4 100644 --- a/src/board/board.pri +++ b/src/board/board.pri @@ -2,14 +2,12 @@ HEADERS += src/board/UBBoardController.h \ src/board/UBBoardPaletteManager.h \ src/board/UBBoardView.h \ - src/board/UBLibraryController.h \ src/board/UBDrawingController.h \ src/board/UBFeaturesController.h SOURCES += src/board/UBBoardController.cpp \ src/board/UBBoardPaletteManager.cpp \ src/board/UBBoardView.cpp \ - src/board/UBLibraryController.cpp \ src/board/UBDrawingController.cpp \ src/board/UBFeaturesController.cpp diff --git a/src/gui/UBFeaturesActionBar.cpp b/src/gui/UBFeaturesActionBar.cpp index 65ee920f..57e90ddf 100644 --- a/src/gui/UBFeaturesActionBar.cpp +++ b/src/gui/UBFeaturesActionBar.cpp @@ -271,3 +271,28 @@ void UBFeaturesActionBar::dropEvent(QDropEvent *event) UBFeaturesActionBar::~UBFeaturesActionBar() { } + +/** + * \brief Construtor + * @param parent as the parent widget + * @param action as the related action + * @param name as the related object name + */ +UBActionButton::UBActionButton(QWidget *parent, QAction* action, const char *name):QToolButton(parent) +{ + setObjectName(name); + addAction(action); + setDefaultAction(action); + setIconSize(QSize(BUTTON_SIZE, BUTTON_SIZE)); + setToolButtonStyle(Qt::ToolButtonIconOnly); + setStyleSheet(QString("QToolButton {color: white; font-weight: bold; font-family: Arial; background-color: transparent; border: none}")); + setFocusPolicy(Qt::NoFocus); +} + +/** + * \brief Destructor + */ +UBActionButton::~UBActionButton() +{ + +} diff --git a/src/gui/UBFeaturesActionBar.h b/src/gui/UBFeaturesActionBar.h index b3a406e6..60db2c37 100644 --- a/src/gui/UBFeaturesActionBar.h +++ b/src/gui/UBFeaturesActionBar.h @@ -4,11 +4,27 @@ #include #include #include -#include "UBLibActionBar.h" #include "board/UBFeaturesController.h" +#define BUTTON_SIZE 24 +#define ACTIONBAR_HEIGHT 42 + class UBFeaturesMimeData; +typedef enum +{ + eButtonSet_Default, + eButtonSet_Properties, + eButtonSet_Favorite +} eButtonSet; + +class UBActionButton : public QToolButton +{ +public: + UBActionButton(QWidget* parent=0, QAction* action=0, const char* name="UBActionButton"); + ~UBActionButton(); +}; + enum UBFeaturesActionBarState { IN_ROOT, diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index 74b0600e..1ed79316 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -1,4 +1,6 @@ #include +#include + #include "UBFeaturesWidget.h" #include "gui/UBThumbnailWidget.h" #include "frameworks/UBFileSystemUtils.h" @@ -6,7 +8,6 @@ #include "core/UBDownloadManager.h" #include "globals/UBGlobals.h" #include "board/UBBoardController.h" -#include "globals/UBGlobals.h" const char *UBFeaturesWidget::objNamePathList = "PathList"; const char *UBFeaturesWidget::objNameFeatureList = "FeatureList"; @@ -23,8 +24,6 @@ static const QString mimeSankoreFeatureTypes = "Sankore/featureTypes"; UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name) : UBDockPaletteWidget(parent) , imageGatherer(NULL) - , mkFolderDlg(NULL) - { setObjectName(name); mName = "FeaturesWidget"; @@ -151,12 +150,6 @@ void UBFeaturesWidget::createNewFolder() emit sendFileNameList(controller->getFileNamesInFolders()); } -void UBFeaturesWidget::addFolder() -{ - if (mkFolderDlg) - controller->addNewFolder(mkFolderDlg->folderName()); -} - void UBFeaturesWidget::deleteElements( const UBFeaturesMimeData * mimeData ) { if (!mimeData->features().count() ) @@ -335,16 +328,6 @@ void UBFeaturesWidget::removeElementsFromFavorite() controller->refreshModels(); } -void UBFeaturesWidget::resizeEvent(QResizeEvent *event) -{ - UBDockPaletteWidget::resizeEvent(event); - if (mkFolderDlg) - { - mkFolderDlg->resize(this->size().width()-20 ,80); - mkFolderDlg->move(5,this->size().height()-200); - } -} - void UBFeaturesWidget::switchToListView() { // stackedWidget->setCurrentIndex(ID_LISTVIEW); diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index fda210cc..a86f6697 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -21,7 +21,9 @@ #include "api/UBWidgetUniboardAPI.h" #include "UBFeaturesActionBar.h" #include "UBRubberBand.h" -#include "gui/UBLibraryWidget.h" +#include +#include +#include #define THUMBNAIL_WIDTH 400 #define ID_LISTVIEW 0 @@ -81,7 +83,6 @@ private slots: void currentSelected( const QModelIndex & ); void searchStarted( const QString & ); void createNewFolder(); - void addFolder(); void deleteElements( const UBFeaturesMimeData * ); void addToFavorite( const UBFeaturesMimeData *); void removeFromFavorite( const UBFeaturesMimeData * ); @@ -94,7 +95,6 @@ private slots: void lockIt(bool pLock); private: - void resizeEvent(QResizeEvent *event); void switchToListView(); void switchToProperties(); void switchToWebView(); @@ -105,7 +105,6 @@ private: QVBoxLayout *layout; UBFeaturesActionBar *mActionBar; UBDownloadHttpFile* imageGatherer; - UBNewFolderDlg *mkFolderDlg; UBFeaturesCentralWidget *centralWidget; }; @@ -220,9 +219,6 @@ private slots: void scanStarted(); void scanFinished(); - -private: - }; class UBFeaturesNewFolderDialog : public QWidget diff --git a/src/gui/UBLibActionBar.cpp b/src/gui/UBLibActionBar.cpp deleted file mode 100644 index f17ed45c..00000000 --- a/src/gui/UBLibActionBar.cpp +++ /dev/null @@ -1,534 +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 2 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 - -#include "UBLibWidget.h" -#include "UBLibActionBar.h" -#include "core/UBApplication.h" - -#include "core/memcheck.h" - -/** - * \brief Constructor - * @param parent as the parent widget - * @param name as the object name - */ -UBLibActionBar::UBLibActionBar(QWidget *parent, const char *name):QWidget(parent) - , mCrntButtonSet(eButtonSet_Default) - , mPreviousButtonSet(eButtonSet_Default) - , mButtonGroup(NULL) - , mSearchBar(NULL) - , mLayout(NULL) - , mpFavoriteAction(NULL) - , mpSocialAction(NULL) - , mpDeleteAction(NULL) - , mpSearchAction(NULL) - , mpCloseAction(NULL) - , mpRemoveFavorite(NULL) - , mpNewFolderAction(NULL) - , mpFavoriteBtn(NULL) - , mpSocialBtn(NULL) - , mpDeleteBtn(NULL) - , mpSearchBtn(NULL) - , mpCloseBtn(NULL) - , mpRemoveFavoriteBtn(NULL) - , mpNewFolderBtn(NULL) - , bFavorite(false) - , bIsInTrash(false) -{ - setObjectName(name); - setStyleSheet(QString("background: #EEEEEE; border-radius : 10px; border : 2px solid #999999;")); - - setAcceptDrops(true); - - mButtonGroup = new QButtonGroup(this); - mSearchBar = new QLineEdit(this); - mSearchBar->setStyleSheet(QString("background-color:white; border-radius : 10px; padding : 2px;")); - connect(mSearchBar, SIGNAL(returnPressed()), this, SLOT(onActionSearch())); - - mLayout = new QHBoxLayout(); - setLayout(mLayout); - - setMaximumHeight(ACTIONBAR_HEIGHT); - - // Create the actions - mpFavoriteAction = new QAction(QIcon(":/images/libpalette/miniFavorite.png"), tr("Add to favorites"), this); - mpSocialAction = new QAction(QIcon(":/images/libpalette/social.png"), tr("Share"), this); - mpSearchAction = new QAction(QIcon(":/images/libpalette/miniSearch.png"), tr("Search"), this); - mpDeleteAction = new QAction(QIcon(":/images/libpalette/miniTrash.png"), tr("Delete"), this); - mpCloseAction = new QAction(QIcon(":/images/close.svg"), tr("Back to folder"), this); - mpRemoveFavorite = new QAction(QIcon(":/images/libpalette/trash_favorite.svg"), tr("Remove from favorites"), this); - mpNewFolderAction = new QAction(QIcon(":/images/libpalette/miniNewFolder.png"), tr("Create new folder"), this); - - // Create the buttons - mpFavoriteBtn = new UBActionButton(this, mpFavoriteAction); - mpSocialBtn = new UBActionButton(this, mpSocialAction); - mpSearchBtn = new UBActionButton(this, mpSearchAction); - mpDeleteBtn = new UBActionButton(this, mpDeleteAction); - mpCloseBtn = new UBActionButton(this, mpCloseAction); - mpRemoveFavoriteBtn = new UBActionButton(this, mpRemoveFavorite); - mpNewFolderBtn = new UBActionButton(this, mpNewFolderAction); - - // Initialize the buttons - mpSearchBtn->setEnabled(false); - mpNewFolderBtn->setEnabled(false); - - // Add the buttons to the button group - mButtonGroup->addButton(mpFavoriteBtn); - mButtonGroup->addButton(mpSocialBtn); - mButtonGroup->addButton(mpSearchBtn); - mButtonGroup->addButton(mpDeleteBtn); - mButtonGroup->addButton(mpCloseBtn); - mButtonGroup->addButton(mpRemoveFavoriteBtn); - mButtonGroup->addButton(mpNewFolderBtn); - // Connect signals & slots - connect(mpFavoriteAction,SIGNAL(triggered()), this, SLOT(onActionFavorite())); - connect(mpSocialAction,SIGNAL(triggered()), this, SLOT(onActionSocial())); - connect(mpSearchAction,SIGNAL(triggered()), this, SLOT(onActionSearch())); - connect(mpDeleteAction,SIGNAL(triggered()), this, SLOT(onActionTrash())); - connect(mpCloseAction, SIGNAL(triggered()), this, SLOT(onActionClose())); - connect(mpRemoveFavorite, SIGNAL(triggered()), this, SLOT(onActionRemoveFavorite())); - connect(mSearchBar, SIGNAL(textChanged(QString)), this, SLOT(onSearchTextChanged(QString))); - connect(mpNewFolderAction, SIGNAL(triggered()), this, SLOT(onActionNewFolder())); - - // Build the default toolbar - mLayout->addWidget(mpFavoriteBtn); - mLayout->addWidget(mpSocialBtn); - mLayout->addWidget(mpNewFolderBtn); - mLayout->addWidget(mSearchBar); - mLayout->addWidget(mpSearchBtn); - mLayout->addWidget(mpDeleteBtn); - mLayout->addWidget(mpCloseBtn); - mLayout->addWidget(mpRemoveFavoriteBtn); - - setButtons(eButtonSet_Default); -} - -/** - * \brief Destructor - */ -UBLibActionBar::~UBLibActionBar() -{ - if(NULL != mpNewFolderAction) - { - delete mpNewFolderAction; - mpNewFolderAction = NULL; - } - if(NULL != mpNewFolderBtn) - { - delete mpNewFolderBtn; - mpNewFolderBtn = NULL; - } - if(NULL != mpRemoveFavorite) - { - delete mpRemoveFavorite; - mpRemoveFavorite = NULL; - } - if(NULL != mpRemoveFavoriteBtn) - { - delete mpRemoveFavoriteBtn; - mpRemoveFavoriteBtn = NULL; - } - if(NULL != mpCloseAction) - { - delete mpCloseAction; - mpCloseAction = NULL; - } - if(NULL != mpDeleteAction) - { - delete mpDeleteAction; - mpDeleteAction = NULL; - } - if(NULL != mpFavoriteAction) - { - delete mpFavoriteAction; - mpFavoriteAction = NULL; - } - if(NULL != mpSearchAction) - { - delete mpSearchAction; - mpSearchAction = NULL; - } - if(NULL != mpSocialAction) - { - delete mpSocialAction; - mpSocialAction = NULL; - } - if(NULL != mpCloseBtn) - { - delete mpCloseBtn; - mpCloseBtn = NULL; - } - if(NULL != mpDeleteBtn) - { - delete mpDeleteBtn; - mpDeleteBtn = NULL; - } - if(NULL != mpFavoriteBtn) - { - delete mpFavoriteBtn; - mpFavoriteBtn = NULL; - } - if(NULL != mpSearchBtn) - { - delete mpSearchBtn; - mpSearchBtn = NULL; - } - if(NULL != mpSocialBtn) - { - delete mpSocialBtn; - mpSocialBtn = NULL; - } - if(NULL != mButtonGroup) - { - delete mButtonGroup; - mButtonGroup = NULL; - } - if(NULL != mSearchBar) - { - delete mSearchBar; - mSearchBar = NULL; - } - if(NULL != mLayout) - { - delete mLayout; - mLayout = NULL; - } -} - -/** - * \brief Set the buttons of the action bar - * @param setID as the button set - */ -void UBLibActionBar::setButtons(eButtonSet setID) -{ - mPreviousButtonSet = mCrntButtonSet; - mCrntButtonSet = setID; - switch(setID) - { - case eButtonSet_Default: - mpFavoriteBtn->show(); - mpSocialBtn->hide(); - mSearchBar->show(); - mpSearchBtn->show(); - mpDeleteBtn->show(); - mpCloseBtn->hide(); - mpRemoveFavoriteBtn->hide(); - mpNewFolderBtn->show(); - break; - case eButtonSet_Properties: - mpFavoriteBtn->show(); - mpSocialBtn->hide(); - mSearchBar->show(); - mpSearchBtn->show(); - mpDeleteBtn->hide(); - mpCloseBtn->hide(); - mpRemoveFavoriteBtn->hide(); - mpNewFolderBtn->hide(); - break; - case eButtonSet_Favorite: - mpFavoriteBtn->hide(); - mpSocialBtn->hide(); - mSearchBar->show(); - mpSearchBtn->show(); - mpDeleteBtn->hide(); - mpCloseBtn->hide(); - mpRemoveFavoriteBtn->show(); - mpNewFolderBtn->hide(); - break; - default: - break; - } -} - -/** - * \brief (un)set the selected element to favorite - */ -void UBLibActionBar::onActionFavorite() -{ - mpFavoriteBtn->setIcon(QIcon(":/images/libpalette/miniFavorite.png")); - libraryController()->addToFavorite(mSelectedElements); -} - -/** - * \brief Handle the mouse enter event - * @param event as the event - */ -void UBLibActionBar::enterEvent(QEvent *event) -{ - Q_UNUSED(event); - setCursor(Qt::ArrowCursor); -} - -/** - * \brief Handle the mouse leave event - * @param event as the event - */ -void UBLibActionBar::leaveEvent(QEvent *event) -{ - Q_UNUSED(event); - unsetCursor(); -} - -/** - * \brief Perform the search - */ -void UBLibActionBar::onActionSearch() -{ - emit searchElement(mSearchBar->text()); -} - -/** - * \brief Trigger the social action - */ -void UBLibActionBar::onActionSocial() -{ - // To be implemented -} - -/** - * \brief Handles the close action - */ -void UBLibActionBar::onActionClose() -{ - emit showFolderContent(); -} - -/** - * \brief Delete the selected element - */ -void UBLibActionBar::onActionTrash() -{ - if(!bIsInTrash) - { - libraryController()->trashElements(mSelectedElements); - } - else - { - libraryController()->emptyElementsOnTrash(mSelectedElements); - } - emit deleteDone(); -} - -/** - * \brief Remove the selected favorite(s) - */ -void UBLibActionBar::onActionRemoveFavorite() -{ - libraryController()->removeFromFavorite(mSelectedElements); - emit deleteDone(); -} - -/** - * \brief Handles the selection change event - * @param itemList as the list of selected items - * @param isInTrash indicates if the current folder is the trash - */ -void UBLibActionBar::onSelectionChanged(QList itemList, bool isInTrash) -{ - bIsInTrash = isInTrash; - mSelectedElements = itemList; - bool bEnable = (itemList.count() != 0) ? true : false; - - if(mCrntButtonSet == eButtonSet_Favorite) - { - mpRemoveFavoriteBtn->setEnabled(bEnable); - return; - } - - mpFavoriteAction->setEnabled(bEnable); - mpSocialAction->setEnabled(bEnable); - mpDeleteAction->setEnabled(bEnable && libraryController()->canItemsOnElementBeDeleted(itemList.at(0))); -} - -/** - * \brief Get the library controller - * @return a pointer on the library controller - */ -UBLibraryController* UBLibActionBar::libraryController() -{ - UBLibWidget* libWidget = dynamic_cast(parentWidget()); - return libWidget->libNavigator()->libraryWidget()->libraryController(); -} - -/** - * \brief Show the actions related to the Favorites folder - */ -void UBLibActionBar::onFavoritesEntered(bool bFav) -{ - setButtons(bFav ? eButtonSet_Favorite : eButtonSet_Default); -} - -/** - * \brief Handles the drag enter event - * @param event as the drag enter event - */ -void UBLibActionBar::dragEnterEvent(QDragEnterEvent *event) -{ - event->acceptProposedAction(); -} - -/** - * \brief Handles the drag move event - * @param event as the drag move event - */ -void UBLibActionBar::dragMoveEvent(QDragMoveEvent *event) -{ - event->acceptProposedAction(); -} - -/** - * \brief Handles the drop event - * @param event as the given drop event - */ -void UBLibActionBar::dropEvent(QDropEvent *event) -{ - const QPoint droppedPoint = event->pos(); - - - QWidget* pTargetW = widgetAtPos(droppedPoint); - if(NULL != pTargetW) - { - if(mpFavoriteBtn == pTargetW) - { - onActionFavorite(); - } - else if(mpRemoveFavoriteBtn == pTargetW) - { - onActionRemoveFavorite(); - } - else if(mpDeleteBtn == pTargetW) - { - if(mpDeleteBtn->isEnabled()) - { - onActionTrash(); - } - } - else if(mpSocialBtn == pTargetW) - { - onActionSocial(); - } - } - event->acceptProposedAction(); -} - -/** - * \brief Get the widget at the given position - * @param p as the given position - * @return a pointer on the related QWidget - */ -QWidget* UBLibActionBar::widgetAtPos(const QPoint p) -{ - Q_ASSERT(mpDeleteBtn != NULL); - Q_ASSERT(mpFavoriteBtn != NULL); - Q_ASSERT(mpRemoveFavoriteBtn != NULL); - Q_ASSERT(mpSocialBtn != NULL); - - QList qlBttns; - qlBttns << mpFavoriteBtn; - qlBttns << mpDeleteBtn; - qlBttns << mpRemoveFavoriteBtn; - qlBttns << mpSocialBtn; - - foreach(UBActionButton* bt, qlBttns) - { - if(bt->pos().x() <= p.x() && - bt->pos().x() + bt->rect().width() >= p.x() && - bt->pos().y() <= p.y() && - bt->pos().y() + bt->rect().height() >= p.y()) - { - if(bt->isVisible()) - { - return bt; - } - } - } - - // No interesting button has been found - return NULL; -} - -/** - * \brief Handles the text changed event of the search bar - */ -void UBLibActionBar::onSearchTextChanged(QString txt) -{ - Q_UNUSED(txt); - onActionSearch(); -} - -/** - * \brief Add a new folder - */ -void UBLibActionBar::onActionNewFolder() -{ - emit newFolderToCreate(); -} - -/** - * \brief Update the action bar elements - * @param crntElem as the current element - */ -void UBLibActionBar::onNavigbarUpdate(UBLibElement *crntElem) -{ - if(NULL != crntElem) - { - if(crntElem->type() == eUBLibElementType_Folder) - { - if(libraryController()->canItemsOnElementBeDeleted(crntElem) && !bIsInTrash) - mpNewFolderBtn->setEnabled(true); - else - mpNewFolderBtn->setEnabled(false); - } - else - { - mpNewFolderBtn->setEnabled(false); - } - } -} - - -void UBLibActionBar::onItemChanged() -{ - mSearchBar->setText(""); - mpSearchBtn->setEnabled(false); -} - -/** - * \brief Construtor - * @param parent as the parent widget - * @param action as the related action - * @param name as the related object name - */ -UBActionButton::UBActionButton(QWidget *parent, QAction* action, const char *name):QToolButton(parent) -{ - setObjectName(name); - addAction(action); - setDefaultAction(action); - setIconSize(QSize(BUTTON_SIZE, BUTTON_SIZE)); - setToolButtonStyle(Qt::ToolButtonIconOnly); - setStyleSheet(QString("QToolButton {color: white; font-weight: bold; font-family: Arial; background-color: transparent; border: none}")); - setFocusPolicy(Qt::NoFocus); -} - -/** - * \brief Destructor - */ -UBActionButton::~UBActionButton() -{ - -} diff --git a/src/gui/UBLibActionBar.h b/src/gui/UBLibActionBar.h deleted file mode 100644 index 52b7576f..00000000 --- a/src/gui/UBLibActionBar.h +++ /dev/null @@ -1,120 +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 2 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 UBLIBACTIONBAR_H -#define UBLIBACTIONBAR_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "board/UBLibraryController.h" - -#define BUTTON_SIZE 24 -#define ACTIONBAR_HEIGHT 42 - -typedef enum -{ - eButtonSet_Default, - eButtonSet_Properties, - eButtonSet_Favorite -} eButtonSet; - -class UBActionButton : public QToolButton -{ -public: - UBActionButton(QWidget* parent=0, QAction* action=0, const char* name="UBActionButton"); - ~UBActionButton(); -}; - -class UBLibActionBar : public QWidget -{ - Q_OBJECT -public: - UBLibActionBar(QWidget* parent=0, const char* name="UBLibActionBar"); - ~UBLibActionBar(); - - void setButtons(eButtonSet setID); - eButtonSet previousButtonSet(){return mPreviousButtonSet;} - -signals: - void deleteDone(); - void showFolderContent(); - void searchElement(QString text); - void newFolderToCreate(); - -public slots: - void onSelectionChanged(QList itemList, bool isInTrash); - void onFavoritesEntered(bool bFav); - void onNavigbarUpdate(UBLibElement* crntElem); - void onItemChanged(); - -protected: - void enterEvent(QEvent *event); - void leaveEvent(QEvent *event); - void dragEnterEvent(QDragEnterEvent *event); - void dragMoveEvent(QDragMoveEvent *event); - void dropEvent(QDropEvent *event); - -private slots: - void onActionFavorite(); - void onActionSocial(); - void onActionSearch(); - void onActionTrash(); - void onActionClose(); - void onActionRemoveFavorite(); - void onSearchTextChanged(QString txt); - void onActionNewFolder(); - -private: - QWidget* widgetAtPos(const QPoint p); - UBLibraryController* libraryController(); - - eButtonSet mCrntButtonSet; - eButtonSet mPreviousButtonSet; - QButtonGroup* mButtonGroup; - QList mSelectedElements; - QLineEdit* mSearchBar; - QHBoxLayout* mLayout; - QAction* mpFavoriteAction; - QAction* mpSocialAction; - QAction* mpDeleteAction; - QAction* mpSearchAction; - QAction* mpCloseAction; - QAction* mpRemoveFavorite; - QAction* mpNewFolderAction; - UBActionButton* mpFavoriteBtn; - UBActionButton* mpSocialBtn; - UBActionButton* mpDeleteBtn; - UBActionButton* mpSearchBtn; - UBActionButton* mpCloseBtn; - UBActionButton* mpRemoveFavoriteBtn; - UBActionButton* mpNewFolderBtn; - - // This flag will be removed after the test, normally we should ask - // the selected item if it is in favorite or not - bool bFavorite; - bool bIsInTrash; - -}; - -#endif // UBLIBACTIONBAR_H diff --git a/src/gui/UBLibItemProperties.cpp b/src/gui/UBLibItemProperties.cpp deleted file mode 100644 index 4d506611..00000000 --- a/src/gui/UBLibItemProperties.cpp +++ /dev/null @@ -1,321 +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 2 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 "UBLibWidget.h" -#include "UBLibItemProperties.h" - -#include "core/UBApplication.h" -#include "core/UBDownloadManager.h" - -#include "frameworks/UBFileSystemUtils.h" - -#include "globals/UBGlobals.h" - -#include "core/memcheck.h" - - -/** - * \brief Constructor - * @param parent as the parent widget - * @param name as the object name - */ -UBLibItemProperties::UBLibItemProperties(QWidget *parent, const char *name):QWidget(parent) - , mpLayout(NULL) - , mpButtonLayout(NULL) - , mpAddPageButton(NULL) - , mpAddToLibButton(NULL) - , mpSetAsBackgroundButton(NULL) - , mpObjInfoLabel(NULL) - , mpObjInfos(NULL) - , mpThumbnail(NULL) - , mpOrigPixmap(NULL) - , mpElement(NULL) - , mpItem(NULL) -{ - setObjectName(name); - - SET_STYLE_SHEET(); - - // Create the GUI - mpLayout = new QVBoxLayout(this); - setLayout(mpLayout); - - maxThumbHeight = height() / 4; - - mpThumbnail = new QLabel(); - QPixmap icon(":images/libpalette/notFound.png"); - icon.scaledToWidth(THUMBNAIL_WIDTH); - - mpThumbnail->setPixmap(icon); - mpThumbnail->setObjectName("DockPaletteWidgetBox"); - mpThumbnail->setStyleSheet("background:white;"); - mpThumbnail->setAlignment(Qt::AlignHCenter); - mpLayout->addWidget(mpThumbnail, 0); - - mpButtonLayout = new QHBoxLayout(); - mpLayout->addLayout(mpButtonLayout, 0); - - mpAddPageButton = new UBLibItemButton(); - mpAddPageButton->setText(tr("Add to page")); - mpButtonLayout->addWidget(mpAddPageButton); - - mpSetAsBackgroundButton = new UBLibItemButton(); - mpSetAsBackgroundButton->setText(tr("Set as background")); - mpButtonLayout->addWidget(mpSetAsBackgroundButton); - - mpAddToLibButton = new UBLibItemButton(); - mpAddToLibButton->setText(tr("Add to library")); - mpButtonLayout->addWidget(mpAddToLibButton); - - mpButtonLayout->addStretch(1); - - mpObjInfoLabel = new QLabel(tr("Object informations")); - mpObjInfoLabel->setStyleSheet(QString("color: #888888; font-size : 18px; font-weight:bold;")); - mpLayout->addWidget(mpObjInfoLabel, 0); - - mpObjInfos = new QTreeWidget(this); - mpObjInfos->setColumnCount(2); - mpObjInfos->header()->hide(); - mpObjInfos->setAlternatingRowColors(true); - mpObjInfos->setRootIsDecorated(false); - mpObjInfos->setObjectName("DockPaletteWidgetBox"); - mpObjInfos->setStyleSheet("background:white;"); - mpLayout->addWidget(mpObjInfos, 1); - - connect(mpAddPageButton, SIGNAL(clicked()), this, SLOT(onAddToPage())); - connect(mpSetAsBackgroundButton, SIGNAL(clicked()), this, SLOT(onSetAsBackground())); - connect(mpAddToLibButton, SIGNAL(clicked()), this, SLOT(onAddToLib())); - -} - -/** - * \brief Destructor - */ -UBLibItemProperties::~UBLibItemProperties() -{ - if(NULL != mpOrigPixmap) - { - delete mpOrigPixmap; - mpOrigPixmap = NULL; - } - if(NULL != mpLayout) - { - delete mpLayout; - mpLayout = NULL; - } - if(NULL != mpSetAsBackgroundButton) - { - delete mpSetAsBackgroundButton; - mpSetAsBackgroundButton = NULL; - } - if(NULL != mpAddPageButton) - { - delete mpAddPageButton; - mpAddPageButton = NULL; - } - if(NULL != mpAddToLibButton) - { - delete mpAddToLibButton; - mpAddToLibButton = NULL; - } - if(NULL != mpObjInfoLabel) - { - delete mpObjInfoLabel; - mpObjInfoLabel = NULL; - } - if(NULL != mpObjInfos) - { - delete mpObjInfos; - mpObjInfos = NULL; - } - if(NULL != mpThumbnail) - { - delete mpThumbnail; - mpThumbnail = NULL; - } -} - -/** - * \brief Handle the resize event - * @param event as the resize event - */ -void UBLibItemProperties::resizeEvent(QResizeEvent *event) -{ - Q_UNUSED(event); - adaptSize(); -} - -/** - * \brief Adapt the thumbnail size - */ -void UBLibItemProperties::adaptSize() -{ - if(NULL != mpOrigPixmap) - { - if(width() < THUMBNAIL_WIDTH + 40) - { - mpThumbnail->setPixmap(mpOrigPixmap->scaledToWidth(width() - 40)); - } - else - { - mpThumbnail->setPixmap(mpOrigPixmap->scaledToWidth(THUMBNAIL_WIDTH)); - } - } -} - -/** - * \brief Add the element to the page - */ -void UBLibItemProperties::onAddToPage() -{ - if(UBApplication::isFromWeb(mpElement->path().toString())){ - sDownloadFileDesc desc; - desc.isBackground = false; - desc.modal = true; - desc.name = QFileInfo(mpElement->path().toString()).fileName(); - desc.url = mpElement->path().toString(); - UBDownloadManager::downloadManager()->addFileToDownload(desc); - - }else{ - UBLibWidget* libWidget = dynamic_cast(parentWidget()->parentWidget()); - libWidget->libNavigator()->libraryWidget()->libraryController()->addItemToPage(mpElement); - } -} - -/** - * \brief Add the item to the library - */ -void UBLibItemProperties::onAddToLib() -{ - if(UBApplication::isFromWeb(mpElement->path().toString())){ - sDownloadFileDesc desc; - desc.isBackground = false; - desc.modal = false; - desc.name = QFileInfo(mpElement->path().toString()).fileName(); - desc.url = mpElement->path().toString(); - UBDownloadManager::downloadManager()->addFileToDownload(desc); - } -} - -/** - * \brief Set the item as background - */ -void UBLibItemProperties::onSetAsBackground() -{ - if(UBApplication::isFromWeb(mpElement->path().toString())){ - sDownloadFileDesc desc; - desc.isBackground = true; - desc.modal = true; - desc.name = QFileInfo(mpElement->path().toString()).fileName(); - desc.url = mpElement->path().toString(); - UBDownloadManager::downloadManager()->addFileToDownload(desc); - - }else{ - UBLibWidget* libWidget = dynamic_cast(parentWidget()->parentWidget()); - libWidget->libNavigator()->libraryWidget()->libraryController()->setItemAsBackground(mpElement); - } -} - -/** - * \brief Show the given element properties - * @param elem as the given element - */ -void UBLibItemProperties::showElement(UBLibElement *elem) -{ - if(NULL != mpOrigPixmap) - { - delete mpOrigPixmap; - mpOrigPixmap = NULL; - } - if(NULL != elem) - { - mpElement = elem; - mpOrigPixmap = new QPixmap(QPixmap::fromImage(*elem->thumbnail())); - mpThumbnail->setPixmap(QPixmap::fromImage(*elem->thumbnail()).scaledToWidth(THUMBNAIL_WIDTH)); - populateMetadata(); - } - - if(UBApplication::isFromWeb(elem->path().toString())){ - mpAddToLibButton->show(); - if(elem->metadatas()["Type"].toLower().contains("image")){ - mpSetAsBackgroundButton->show(); - }else{ - mpSetAsBackgroundButton->hide(); - } - }else{ - mpAddToLibButton->hide(); - if(UBFileSystemUtils::mimeTypeFromFileName(elem->path().toLocalFile()).contains("image")){ - mpSetAsBackgroundButton->show(); - }else{ - mpSetAsBackgroundButton->hide(); - } - } -} - -/** - * \brief Navigate backward - */ -void UBLibItemProperties::onBack() -{ - emit showFolderContent(); -} - -/** - * \brief Handle the show event - * @param event as the show event - */ -void UBLibItemProperties::showEvent(QShowEvent *event) -{ - Q_UNUSED(event); - adaptSize(); -} - -void UBLibItemProperties::populateMetadata() -{ - if(NULL != mpObjInfos){ - mpObjInfos->clear(); - QMap metas = mpElement->metadatas(); - QList lKeys = metas.keys(); - QList lValues = metas.values(); - - for(int i=0; i< metas.size(); i++){ - QStringList values; - values << lKeys.at(i); - values << lValues.at(i); - mpItem = new QTreeWidgetItem(values); - mpObjInfos->addTopLevelItem(mpItem); - } - mpObjInfos->resizeColumnToContents(0); - } -} - -/** - * \brief Constructor - * @param parent as the parent widget - * @param name as the object name - */ -UBLibItemButton::UBLibItemButton(QWidget *parent, const char *name):QPushButton(parent) -{ - setObjectName(name); - setStyleSheet(QString("background-color : #DDDDDD; color : #555555; border-radius : 6px; padding : 5px; font-weight : bold; font-size : 12px;")); -} - -/** - * \brief Destructor - */ -UBLibItemButton::~UBLibItemButton() -{ - -} diff --git a/src/gui/UBLibItemProperties.h b/src/gui/UBLibItemProperties.h deleted file mode 100644 index 8fbfdf2c..00000000 --- a/src/gui/UBLibItemProperties.h +++ /dev/null @@ -1,82 +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 2 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 UBLIBITEMPROPERTIES_H -#define UBLIBITEMPROPERTIES_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "board/UBLibraryController.h" - -#define THUMBNAIL_WIDTH 400 - -class UBLibItemButton : public QPushButton -{ -public: - UBLibItemButton(QWidget* parent=0, const char* name="UBLibItemButton"); - ~UBLibItemButton(); -}; - -class UBLibItemProperties : public QWidget -{ - Q_OBJECT -public: - UBLibItemProperties(QWidget* parent=0, const char* name="UBLibItemProperties"); - ~UBLibItemProperties(); - - void showElement(UBLibElement* elem); - -signals: - void showFolderContent(); - -protected: - void resizeEvent(QResizeEvent *event); - void showEvent(QShowEvent *event); - -private slots: - void onAddToPage(); - void onAddToLib(); - void onSetAsBackground(); - void onBack(); - -private: - void adaptSize(); - void populateMetadata(); - - QVBoxLayout* mpLayout; - QHBoxLayout* mpButtonLayout; - UBLibItemButton* mpAddPageButton; - UBLibItemButton* mpAddToLibButton; - UBLibItemButton* mpSetAsBackgroundButton; - QLabel* mpObjInfoLabel; - QTreeWidget* mpObjInfos; - QLabel* mpThumbnail; - QPixmap* mpOrigPixmap; - int maxThumbHeight; - UBLibElement* mpElement; - QTreeWidgetItem* mpItem; -}; - - -#endif // UBLIBITEMPROPERTIES_H diff --git a/src/gui/UBLibNavigatorWidget.cpp b/src/gui/UBLibNavigatorWidget.cpp deleted file mode 100644 index 5e7d5c89..00000000 --- a/src/gui/UBLibNavigatorWidget.cpp +++ /dev/null @@ -1,189 +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 2 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 "UBLibNavigatorWidget.h" -#include "UBLibWidget.h" - -#include "core/UBApplication.h" - -#include "globals/UBGlobals.h" - -#include "core/memcheck.h" - -static int lowBoundForSlider = 40; -static int topBoundForSlider = 120; -static int tickIntervalForSlider = 10; - -/** - * \brief Constructor - * @param parent as the parent widget - * @param name as the object name - */ -UBLibNavigatorWidget::UBLibNavigatorWidget(QWidget *parent, const char *name):QWidget(parent) - , mLayout(NULL) - , mLibWidget(NULL) - , mSlider(NULL) - , mSliderWidthSetting(NULL) -{ - setObjectName(name); - - SET_STYLE_SHEET(); - - setAcceptDrops(true); - - UBLibWidget* libWidget = dynamic_cast(parentWidget()); - mLayout = new QVBoxLayout(this); - setLayout(mLayout); - - mLibWidget = new UBLibraryWidget(this); - mLayout->addWidget(mLibWidget, 1); - - mSlider = new QSlider(Qt::Horizontal, this); - mSlider->setMinimumHeight(20); - mSlider->setRange(lowBoundForSlider, topBoundForSlider); - //mSliderWidthSetting = new UBSetting(UBSettings::settings(), "Library", "LibWidgetWidth", topBoundForSlider); - //int defaultWidth = mSliderWidthSetting->get().toInt(); - int defaultWidth = UBSettings::settings()->libraryIconSize(); - qDebug() << defaultWidth; - mSlider->setValue(defaultWidth); - mSlider->setTickInterval(tickIntervalForSlider); - mLayout->addWidget(mSlider, 0); - - connect(mLibWidget, SIGNAL(navigBarUpdate(UBLibElement*)), this, SLOT(onNavigbarUpate(UBLibElement*))); - connect(this, SIGNAL(updateNavigBar(UBChainedLibElement*)), libWidget, SLOT(onUpdateNavigBar(UBChainedLibElement*))); - mLibWidget->updateThumbnailsSize(defaultWidth); - - - connect(mLibWidget, SIGNAL(propertiesRequested(UBLibElement*)), this, SLOT(onPropertiesRequested(UBLibElement*))); - connect(mLibWidget, SIGNAL(displaySearchEngine(UBLibElement*)), this, SLOT(onDisplaySearchEngine(UBLibElement*))); - connect(mSlider,SIGNAL(valueChanged(int)),this,SLOT(updateThumbnailsSize(int))); - connect(libWidget->pathViewer(), SIGNAL(mouseClick(UBChainedLibElement*)), this, SLOT(onPathItemClicked(UBChainedLibElement*))); - connect(libWidget->pathViewer(), SIGNAL(elementsDropped(QList,UBLibElement*)), mLibWidget, SLOT(onElementsDropped(QList,UBLibElement*))); - connect(mLibWidget, SIGNAL(navigBarUpdate(UBLibElement*)), libWidget->actionBar(), SLOT(onNavigbarUpdate(UBLibElement*))); - connect(mLibWidget, SIGNAL(itemsSelected(QList, bool)), libWidget->actionBar(), SLOT(onSelectionChanged(QList, bool))); - connect(libWidget->actionBar(), SIGNAL(deleteDone()), mLibWidget, SLOT(onRefreshCurrentFolder())); - connect(mLibWidget, SIGNAL(favoritesEntered(bool)), libWidget->actionBar(), SLOT(onFavoritesEntered(bool))); - connect(libWidget->actionBar(), SIGNAL(searchElement(QString)), mLibWidget, SLOT(onSearchElement(QString))); - connect(libWidget->actionBar(), SIGNAL(newFolderToCreate()), mLibWidget, SLOT(onNewFolderToCreate())); - connect(mLibWidget, SIGNAL(itemClicked()),libWidget->actionBar(), SLOT(onItemChanged())); - connect(libWidget->pathViewer(), SIGNAL(mouseClick(UBChainedLibElement*)),libWidget->actionBar(), SLOT(onItemChanged())); - mLibWidget->init(); -} - -/** - * \brief Destructor - */ -UBLibNavigatorWidget::~UBLibNavigatorWidget() -{ - if(NULL != mLibWidget) - { - delete mLibWidget; - mLibWidget = NULL; - } - if(NULL != mSlider) - { - delete mSlider; - mSlider = NULL; - } - if(NULL != mSliderWidthSetting) - { - delete mSliderWidthSetting; - mSliderWidthSetting = NULL; - } - if(NULL != mLayout) - { - delete mLayout; - mLayout = NULL; - } -} - -void UBLibNavigatorWidget::dropMe(const QMimeData *_data) -{ - // Forward the mime data to the library widget - Q_UNUSED(_data); -} - -/** - * \brief Update the navigation bar - * @param pElem as the current element - */ -void UBLibNavigatorWidget::onNavigbarUpate(UBLibElement *pElem) -{ - Q_UNUSED(pElem); - emit updateNavigBar(mLibWidget->chainedElements); -} - -/** - * \brief Handle the click event on an item - * @param elem as the clicked element - */ -void UBLibNavigatorWidget::onPathItemClicked(UBChainedLibElement *elem) -{ - if (!this->libraryWidget()->isLoadingLibraryItems()) - { - // If this element has some subelement, remove them - removeNextChainedElements(elem); - - // The refresh the view - mLibWidget->setCurrentElemsAndRefresh(elem); - } -} - -/** - * \brief Remove the next chained elements - * @param fromElem as the current elem - */ -void UBLibNavigatorWidget::removeNextChainedElements(UBChainedLibElement *fromElem) -{ - if(NULL != fromElem) - { - if(NULL != fromElem->nextElement()) - { - //removeNextChainedElements(fromElem->nextElement()); - //delete fromElem->nextElement()->element(); - //delete fromElem->nextElement(); - delete fromElem->nextElement(); - fromElem->setNextElement(NULL); - } - } -} - -/** - * \brief Handles the properties requested event - * @param elem as the related element - */ -void UBLibNavigatorWidget::onPropertiesRequested(UBLibElement *elem) -{ - emit propertiesRequested(elem); -} - -/** - * \brief Handles the display search engine requested event - * @param elem as the related element - */ -void UBLibNavigatorWidget::onDisplaySearchEngine(UBLibElement *elem) -{ - emit displaySearchEngine(elem); -} - -/** - * \brief Update the thumbnails size - * @param newSize as the given thumbnails size - */ -void UBLibNavigatorWidget::updateThumbnailsSize(int newSize) -{ - //mSliderWidthSetting->set(newSize); - UBSettings::settings()->setLibraryIconsize(newSize); - mLibWidget->updateThumbnailsSize(newSize); -} diff --git a/src/gui/UBLibNavigatorWidget.h b/src/gui/UBLibNavigatorWidget.h deleted file mode 100644 index 98a10c3d..00000000 --- a/src/gui/UBLibNavigatorWidget.h +++ /dev/null @@ -1,57 +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 2 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 UBLIBNAVIGATORWIDGET_H -#define UBLIBNAVIGATORWIDGET_H - -#include -#include -#include -#include - -#include "UBLibraryWidget.h" -#include "core/UBSetting.h" - -class UBLibNavigatorWidget : public QWidget -{ - Q_OBJECT -public: - UBLibNavigatorWidget(QWidget* parent=0, const char* name="UBLibNavigatorWidget"); - ~UBLibNavigatorWidget(); - void dropMe(const QMimeData* _data); - - UBLibraryWidget* libraryWidget(){return mLibWidget;} - -signals: - void propertiesRequested(UBLibElement* elem); - void displaySearchEngine(UBLibElement* elem); - void updateNavigBar(UBChainedLibElement* elem); - -private slots: - void onNavigbarUpate(UBLibElement* pElem); - void onPathItemClicked(UBChainedLibElement *elem); - void onPropertiesRequested(UBLibElement* elem); - void updateThumbnailsSize(int newSize); - void onDisplaySearchEngine(UBLibElement* elem); - -private: - void removeNextChainedElements(UBChainedLibElement* fromElem); - - QVBoxLayout* mLayout; - UBLibraryWidget* mLibWidget; - QSlider* mSlider; - UBSetting* mSliderWidthSetting; -}; - -#endif // UBLIBNAVIGATORWIDGET_H diff --git a/src/gui/UBLibPathViewer.cpp b/src/gui/UBLibPathViewer.cpp deleted file mode 100644 index e281a17b..00000000 --- a/src/gui/UBLibPathViewer.cpp +++ /dev/null @@ -1,582 +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 2 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 - -#include "UBLibPathViewer.h" -#include "core/UBApplication.h" -#include "board/UBBoardController.h" - -#include "core/UBDownloadManager.h" -#include "board/UBBoardPaletteManager.h" - -#include "core/memcheck.h" - -/** - * \brief Constructor - * @param parent as the parent widget - * @param name as the object name - */ -UBLibPathViewer::UBLibPathViewer(QWidget *parent, const char *name):QGraphicsView(parent) - , mpElems(NULL) - , mpElemsBackup(NULL) - , mpScene(NULL) - , mpLayout(NULL) - , mpContainer(NULL) - , mpBackElem(NULL) -{ - setObjectName(name); - setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - setAcceptDrops(true); - - mpBackElem = new UBLibElement(); - mpBackElem->setThumbnail(QPixmap(":images/libpalette/back.png").toImage()); - mpBackElem->setDeletable(false); - - mpScene = new UBPathScene(this); - setScene(mpScene); - - mpContainer = new QGraphicsWidget(); - mpContainer->setMinimumWidth(width() - 20); - mpScene->addItem(mpContainer); - mpLayout = new QGraphicsLinearLayout(); - mpContainer->setLayout(mpLayout); - - connect(mpScene, SIGNAL(mouseClick(UBChainedLibElement*)), this, SLOT(onMouseClicked(UBChainedLibElement*))); - connect(mpScene, SIGNAL(elementsDropped(QList,UBLibElement*)), this, SLOT(onElementsDropped(QList,UBLibElement*))); - connect(horizontalScrollBar(), SIGNAL(sliderMoved(int)), this, SLOT(onSliderMoved(int))); -} - -/** - * \brief Destructor - */ -UBLibPathViewer::~UBLibPathViewer() -{ - if(NULL != mpContainer) - { - delete mpContainer; - mpContainer = NULL; - } - if(NULL != mpBackElem) - { - delete mpBackElem; - mpBackElem = NULL; - } - if(NULL != mpElems) - { - delete mpElems; - mpElems = NULL; - } - //if(NULL != mpElemsBackup) - //{ - // delete mpElemsBackup; - // mpElemsBackup = NULL; - //} - //if(NULL != mpLayout) - //{ - // delete mpLayout; - // mpLayout = NULL; - //} - if(NULL != mpScene) - { - delete mpScene; - mpScene = NULL; - } -} - -/** - * \brief Display the current path - * @param elementsChain as the path to display - */ -void UBLibPathViewer::displayPath(UBChainedLibElement *elementsChain) -{ - if(NULL != elementsChain) - { - mpElems = elementsChain; - refreshPath(); - } -} - -/** - * \brief Refresh the current path - */ -void UBLibPathViewer::refreshPath() -{ - if (mpScene && mpContainer) - mpScene->removeItem(mpContainer); - if(mpContainer) - delete mpContainer; - mVItems.clear(); - mpScene->mapWidgetToChainedElem()->clear(); - mpContainer = new QGraphicsWidget(); - - mpScene->addItem(mpContainer); - mpLayout = new QGraphicsLinearLayout(); - mpContainer->setLayout(mpLayout); - mSceneWidth = 0; - addItem(mpElems); - mpLayout->addStretch(); - - updateScrolls(); - -} - -/** - * \brief Handle the slider moved event - * @param value as the current slider position - */ -void UBLibPathViewer::onSliderMoved(int value) -{ - Q_UNUSED(value); -} - -/** - * \brief Update the scroll bar status - */ -void UBLibPathViewer::updateScrolls() -{ - int iLimit = mSceneWidth + 40; // 2x 20 pixels margin - int iVp = viewport()->width(); - - if(iLimit >= iVp) - { - int iDiff = iLimit - iVp; - horizontalScrollBar()->setRange(0, iDiff); - } - else - { - horizontalScrollBar()->setRange(0, 0); - } -} - -/** - * \brief Append an item to the path - * @param elem as the element to add to the path - */ -void UBLibPathViewer::addItem(UBChainedLibElement *elem) -{ - if(NULL != elem) - { - // Add the icon - QLabel* pIconLabel = new QLabel(); - pIconLabel->setStyleSheet(QString("background-color: transparent;")); - pIconLabel->setPixmap((QPixmap::fromImage(*elem->element()->thumbnail())).scaledToWidth(PATHITEMWIDTH)); - UBFolderPath* iconWidget = reinterpret_cast(mpScene->addWidget(pIconLabel)); - //iconWidget->setToolTip(elem->element()->name()); - iconWidget->setWindowFlags(Qt::BypassGraphicsProxyWidget); - mpLayout->addItem(iconWidget); - mVItems << iconWidget; - mpScene->mapWidgetToChainedElem()->insert(iconWidget,elem); - mSceneWidth += pIconLabel->pixmap()->width() + 4; // 2px border - - if(NULL != elem->nextElement()) - { - // Add the arrow - QLabel* pArrowLabel = new QLabel(); - pArrowLabel->setStyleSheet(QString("background-color: transparent;")); - pArrowLabel->setPixmap(QPixmap(":images/navig_arrow.png")); - QGraphicsWidget* arrowWidget = mpScene->addWidget(pArrowLabel); - mpLayout->addItem(arrowWidget); - mVItems << arrowWidget; - mSceneWidth += pArrowLabel->pixmap()->width() + 4; // 2px border - - // Recursively call this method while a next item exists - addItem(elem->nextElement()); - } - } -} - -/** - * \brief Handles the resize event - * @param event as the resize event - */ -void UBLibPathViewer::resizeEvent(QResizeEvent *event) -{ - - if(event->oldSize() == event->size()) - event->ignore(); - else{ - if(NULL != mpContainer) - mpContainer->setMinimumWidth(width() - 20); - - viewport()->resize(width() - 10, viewport()->height()); - - updateScrolls(); - event->accept(); - } -} - -void UBLibPathViewer::showEvent(QShowEvent *event) -{ - Q_UNUSED(event); - updateScrolls(); -} - -/** - * \brief Handles the mouse move event - * @param event as the mouse move event - */ -void UBLibPathViewer::mouseMoveEvent(QMouseEvent *event) -{ - event->ignore(); -} - -void UBLibPathViewer::onMouseClicked(UBChainedLibElement *elem) -{ - emit mouseClick(elem); -} - -int UBLibPathViewer::widgetAt(QPointF p) -{ - int position = -1; - - for(int i = 0; i < mVItems.size(); i++) - { - QGraphicsWidget* pCrntWidget = mVItems.at(i); - if(NULL != pCrntWidget) - { - QRectF r = pCrntWidget->rect(); - QPointF wPos = pCrntWidget->scenePos(); - int xMin = wPos.x() + r.x(); - int xMax = wPos.x() + r.x() + r.width(); - int yMin = wPos.y() + r.y(); - int yMax = wPos.y() + r.y() + r.height(); - - if(p.x() >= xMin && - p.x() <= xMax && - p.y() >= yMin && - p.y() <= yMax) - { - return i; - } - } - } - - return position; -} - -void UBLibPathViewer::onElementsDropped(QList elements, UBLibElement *target) -{ - emit elementsDropped(elements, target); -} - -void UBLibPathViewer::showBack() -{ - // Backup the current path so we can go back by clicking on the back button - mpElemsBackup = mpElems; - - // Set the correct path to the backElem - UBChainedLibElement* pLastElem = mpElemsBackup->lastElement(); - - if(NULL != pLastElem) - { - mpBackElem->setPath(pLastElem->element()->path()); - mpBackElem->setType(pLastElem->element()->type()); - mpBackElem->setName(pLastElem->element()->name()); - } - - // Display the 'back' element - displayPath(new UBChainedLibElement(mpBackElem)); -} - -UBFolderPath::UBFolderPath():QGraphicsProxyWidget() -{ - -} - -UBFolderPath::~UBFolderPath() -{ - -} - -/** - * \brief Handles the drag enter event - * @param pEvent as the drag enter event - */ -void UBFolderPath::dragEnterEvent(QGraphicsSceneDragDropEvent *event) -{ - event->acceptProposedAction(); -} - -/** - * \brief Handles the drop event - * @param pEvent as the drop event - */ -void UBFolderPath::dropEvent(QDropEvent *pEvent) -{ - processMimeData(pEvent->mimeData()); - pEvent->acceptProposedAction(); -} - -/** - * \brief Handles the drag move event - * @param pEvent as the drag move event - */ -void UBFolderPath::dragMoveEvent(QDragMoveEvent* pEvent) -{ - pEvent->acceptProposedAction(); -} - -/** - * \brief Process the given MIME data - * @param pData as the MIME data to process - */ -void UBFolderPath::processMimeData(const QMimeData *pData) -{ - Q_UNUSED(pData); -} - -/** - * \brief Handles the mouse press event - * @param event as the mouse press event - */ -void UBFolderPath::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - Q_UNUSED(event); -} - -/** - * \brief Handles the mouse move event - * @param event as the mouse move event - */ -void UBFolderPath::mouseMoveEvent(QMouseEvent *event) -{ - Q_UNUSED(event); -} - -/** - * \brief Handles the mouse release event - * @param event as the mouse release event - */ -void UBFolderPath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - Q_UNUSED(event); -} - - -UBPathScene::UBPathScene(QWidget* parent):QGraphicsScene(parent) -{ - connect(UBDownloadManager::downloadManager(), SIGNAL(allDownloadsFinished()), this, SLOT(onAllDownloadsFinished())); -} - -UBPathScene::~UBPathScene() -{ - -} - - -void UBPathScene::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - if(event->button() == Qt::LeftButton) - { - mDragStartPos = event->scenePos(); - mClickTime = QTime::currentTime(); - } -} - -/** - * \brief Handles the mouse release event - * @param event as the mouse release event - */ -void UBPathScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - int elapsedTimeSincePress = mClickTime.elapsed(); - - if(elapsedTimeSincePress < STARTDRAGTIME) - { - QGraphicsWidget* pGWidget = dynamic_cast(itemAt(event->pos())); - if(NULL != pGWidget) - { - // We have only one view at a time - UBLibPathViewer* pView = dynamic_cast(this->views().at(0)); - if(NULL != pView) - { - int iClickedItem = pView->widgetAt(event->scenePos()); - QGraphicsLayout* wgtLayout = pGWidget->layout(); - if(iClickedItem != -1 && wgtLayout != NULL) - { - QGraphicsWidget* pFolderW = dynamic_cast(wgtLayout->itemAt(iClickedItem)); - if(NULL != pFolderW) - { - UBChainedLibElement* chElem = mMapWidgetToChainedElem[pFolderW]; - if(NULL != chElem) - { - emit mouseClick(chElem); - } - } - } - } - } - } -} - -/** - * \brief Handles the mouse move event - * @param event as the mouse move event - */ -void UBPathScene::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - if(event->button() == Qt::LeftButton) - { - if((event->pos() - mDragStartPos).manhattanLength() < QApplication::startDragDistance()) - { - // The user is not doing a drag - return; - } - - // The user is performing a drag operation - QDrag* drag = new QDrag(event->widget()); - QMimeData* mimeData = new QMimeData(); - drag->setMimeData(mimeData); - drag->start(); - } -} - - -void UBPathScene::dragEnterEvent(QGraphicsSceneDragDropEvent *event) -{ - event->accept(); -} - -void UBPathScene::dragMoveEvent(QGraphicsSceneDragDropEvent *event) -{ - event->accept(); -} - -void UBPathScene::dropEvent(QGraphicsSceneDragDropEvent *event) -{ - bool bAccept = false; - const QMimeData* pMimeData = event->mimeData(); - - if(NULL != event->source() && 0 == QString::compare(event->source()->metaObject()->className(), "UBLibraryWidget")){ - UBLibElement* pTargetElement = elementFromPos(event->scenePos()); - if(NULL != pTargetElement){ - if(eUBLibElementType_Folder == pTargetElement->type()){ - // The drag comes from this application, we have now to get the list of UBLibElements* - QList qlDroppedElems; - - foreach(QUrl url, pMimeData->urls()) - qlDroppedElems << url.toString(); - - if(!qlDroppedElems.empty()){ - // Send a signal with the target dir and the list of ublibelement* - emit elementsDropped(qlDroppedElems, pTargetElement); - } - } - } - - bAccept = true; - }else if(NULL != pMimeData && pMimeData->hasUrls()){ - QList urls = pMimeData->urls(); - foreach(QUrl eachUrl, urls){ - QString sUrl = eachUrl.toString(); - if(!sUrl.startsWith("uniboardTool://") && !sUrl.startsWith("file://") && !sUrl.startsWith("/")){ - // The dropped URL comes from the web - // Show the download palette if it is hidden - UBApplication::boardController->paletteManager()->startDownloads(); - - // Add the dropped url to the download list - sDownloadFileDesc desc; - desc.currentSize = 0; - desc.id = 0; - desc.isBackground = false; - desc.modal = false; - desc.name = QFileInfo(sUrl).fileName(); - desc.totalSize = 0; - desc.url = sUrl; - UBDownloadManager::downloadManager()->addFileToDownload(desc); - bAccept = true; - } - } - } - if(!bAccept && NULL != pMimeData && pMimeData->hasText()){ - // The user can only drop an Url in this location so if the text is not an Url, - // we discard it. - QString qsTxt = pMimeData->text().remove(QRegExp("[\\0]")); - if(qsTxt.startsWith("http")){ - // Show the download palette if it is hidden - UBApplication::boardController->paletteManager()->startDownloads(); - - // Add the dropped url to the download list - sDownloadFileDesc desc; - desc.currentSize = 0; - desc.id = 0; - desc.isBackground = false; - desc.modal = false; - desc.name = QFileInfo(qsTxt).fileName(); - desc.totalSize = 0; - desc.url = qsTxt; - UBDownloadManager::downloadManager()->addFileToDownload(desc); - bAccept = true; - } - } - if(!bAccept && NULL != pMimeData && pMimeData->hasHtml()){ - QString html = pMimeData->html(); - QString url = UBApplication::urlFromHtml(html); - if("" != url) - { - // Show the download palette if it is hidden - UBApplication::boardController->paletteManager()->startDownloads(); - - // Add the dropped url to the download list - sDownloadFileDesc desc; - desc.currentSize = 0; - desc.id = 0; - desc.isBackground = false; - desc.modal = false; - desc.name = QFileInfo(url).fileName(); - desc.totalSize = 0; - desc.url = url; - UBDownloadManager::downloadManager()->addFileToDownload(desc); - bAccept = true; - } - } - if(bAccept){ - event->accept(); - } - else{ - event->ignore(); - } -} - -/** - * \brief Return the element related to the given position - * @param p as the given position - * - */ -UBLibElement* UBPathScene::elementFromPos(QPointF p) -{ - UBLibElement* pElem = NULL; - - QGraphicsWidget* pGWidget = dynamic_cast(itemAt(p)); - if(NULL != pGWidget) - { - UBChainedLibElement* chElem = mMapWidgetToChainedElem[pGWidget]; - if(NULL != chElem) - { - return chElem->element(); - } - } - - return pElem; -} - -void UBPathScene::onAllDownloadsFinished() -{ - // Hide the download tab - UBApplication::boardController->paletteManager()->stopDownloads(); -} diff --git a/src/gui/UBLibPathViewer.h b/src/gui/UBLibPathViewer.h deleted file mode 100644 index 1f3764ef..00000000 --- a/src/gui/UBLibPathViewer.h +++ /dev/null @@ -1,148 +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 2 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 UBLIBPATHVIEWER_H -#define UBLIBPATHVIEWER_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "board/UBLibraryController.h" - -#define PATHITEMWIDTH 32 -#define STARTDRAGTIME 1000000 - -class UBPathScene : public QGraphicsScene -{ - Q_OBJECT -public: - UBPathScene(QWidget* parent=0); - ~UBPathScene(); - QMap* mapWidgetToChainedElem(){return &mMapWidgetToChainedElem;} - -signals: - void mouseClick(UBChainedLibElement* elem); - void elementsDropped(QList elements, UBLibElement* target); - -protected: - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - void dragEnterEvent(QGraphicsSceneDragDropEvent *event); - void dragMoveEvent(QGraphicsSceneDragDropEvent *event); - void dropEvent(QGraphicsSceneDragDropEvent *event); - -private slots: - void onAllDownloadsFinished(); - -private: - UBLibElement* elementFromPos(QPointF p); - /** The drag start position */ - QPointF mDragStartPos; - /** A timer used to detect a click or a drag */ - QTime mClickTime; - /** A map between a widget and a chained element */ - QMap mMapWidgetToChainedElem; - -}; - -class UBLibPathViewer : public QGraphicsView -{ - Q_OBJECT -public: - UBLibPathViewer(QWidget* parent=0, const char* name="UBLibPathViewer"); - ~UBLibPathViewer(); - - void displayPath(UBChainedLibElement* elementsChain); - int widgetAt(QPointF p); - void updateScrolls(); - -public slots: - void showBack(); - -signals: - void mouseClick(UBChainedLibElement* elem); - void elementsDropped(QList elements, UBLibElement* target); - -protected: - void resizeEvent(QResizeEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void showEvent(QShowEvent *event); - -private slots: - void onMouseClicked(UBChainedLibElement* elem); - void onElementsDropped(QList elements, UBLibElement* target); - void onSliderMoved(int value); - -private: - void refreshPath(); - void addItem(UBChainedLibElement* elem); - - /** The chained path elements */ - UBChainedLibElement* mpElems; - /** The backup chained path elements */ - UBChainedLibElement* mpElemsBackup; - /** The scene */ - UBPathScene* mpScene; - //QGraphicsScene* mpScene; - /** The layout */ - QGraphicsLinearLayout* mpLayout; - /** The container that will display the path properly */ - QGraphicsWidget* mpContainer; - /** The list of path items (icons + arrows) */ - QVector mVItems; - /** The total width of the element in the scene */ - int mSceneWidth; - /** The back element */ - UBLibElement* mpBackElem; -}; - - -class UBFolderPath : public QGraphicsProxyWidget -{ -public: - UBFolderPath(); - ~UBFolderPath(); - -protected: - void mousePressEvent(QGraphicsSceneMouseEvent *event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); - void dragEnterEvent(QGraphicsSceneDragDropEvent *event); - void dropEvent(QDropEvent *pEvent); - void dragMoveEvent(QDragMoveEvent *pEvent); - -private: - void processMimeData(const QMimeData* pData); - - -}; - -#endif // UBLIBPATHVIEWER_H diff --git a/src/gui/UBLibWebView.cpp b/src/gui/UBLibWebView.cpp deleted file mode 100644 index 0a4bb6cc..00000000 --- a/src/gui/UBLibWebView.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include - -#include "core/UBApplication.h" - -#include "board/UBBoardController.h" - -#include "globals/UBGlobals.h" - -#include "UBLibWebView.h" - -#include "core/memcheck.h" - -UBLibWebView::UBLibWebView(QWidget* parent, const char* name):QWidget(parent) - , mpView(NULL) - , mpWebSettings(NULL) - , mpLayout(NULL) - , mpSankoreAPI(NULL) -{ - setObjectName(name); - - SET_STYLE_SHEET(); - - mpLayout = new QVBoxLayout(); - setLayout(mpLayout); - - mpView = new QWebView(this); - mpView->setObjectName("SearchEngineView"); - mpSankoreAPI = new UBWidgetUniboardAPI(UBApplication::boardController->activeScene()); - connect(mpView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(javaScriptWindowObjectCleared())); - - mpLayout->addWidget(mpView); -} - -UBLibWebView::~UBLibWebView() -{ - if(NULL != mpSankoreAPI){ - delete mpSankoreAPI; - mpSankoreAPI = NULL; - } - if(NULL != mpView){ - delete mpView; - mpView = NULL; - } - if(NULL != mpLayout){ - delete mpLayout; - mpLayout = NULL; - } -} - -void UBLibWebView::setElement(UBLibElement *elem) -{ - if(NULL != elem) - { - QString qsWidgetName; - QString path = elem->path().toLocalFile(); - - QString qsConfigPath = QString("%0/config.xml").arg(path); - - if(QFile::exists(qsConfigPath)) - { - QFile f(qsConfigPath); - if(f.open(QIODevice::ReadOnly)) - { - QDomDocument domDoc; - domDoc.setContent(QString(f.readAll())); - QDomElement root = domDoc.documentElement(); - - QDomNode node = root.firstChild(); - while(!node.isNull()) - { - if(node.toElement().tagName() == "content") - { - QDomAttr srcAttr = node.toElement().attributeNode("src"); - qsWidgetName = srcAttr.value(); - break; - } - node = node.nextSibling(); - } - f.close(); - } - } - mpView->load(QUrl::fromLocalFile(QString("%0/%1").arg(path).arg(qsWidgetName))); - } -} - -void UBLibWebView::javaScriptWindowObjectCleared() -{ - mpView->page()->mainFrame()->addToJavaScriptWindowObject("sankore", mpSankoreAPI); -} diff --git a/src/gui/UBLibWebView.h b/src/gui/UBLibWebView.h deleted file mode 100644 index d9ccc245..00000000 --- a/src/gui/UBLibWebView.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef UBLIBWEBVIEW_H -#define UBLIBWEBVIEW_H - -#include -#include -#include -#include - -#include "board/UBLibraryController.h" -#include "api/UBWidgetUniboardAPI.h" - -class UBLibWebView : public QWidget -{ - Q_OBJECT - -public: - UBLibWebView(QWidget* parent = 0, const char* name = "UBLibWebView"); - ~UBLibWebView(); - - void setElement(UBLibElement* elem); - -protected slots: - virtual void javaScriptWindowObjectCleared(); - -private: - QWebView* mpView; - QWebSettings* mpWebSettings; - QVBoxLayout* mpLayout; - UBWidgetUniboardAPI* mpSankoreAPI; -}; - -#endif // UBLIBWEBVIEW_H diff --git a/src/gui/UBLibWidget.cpp b/src/gui/UBLibWidget.cpp deleted file mode 100644 index 60224328..00000000 --- a/src/gui/UBLibWidget.cpp +++ /dev/null @@ -1,230 +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 2 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 "UBLibWidget.h" - -#include "core/UBApplication.h" - -#include "globals/UBGlobals.h" - -#include "core/memcheck.h" - -/** - * \brief Constructor - * @param parent as the parent widget - * @param name as the object name - */ -UBLibWidget::UBLibWidget(QWidget *parent, const char *name):UBDockPaletteWidget(parent) - , mLayout(NULL) - , mStackedWidget(NULL) - , mNavigator(NULL) - , mProperties(NULL) - , mActionBar(NULL) - , mpWebView(NULL) - , mpPathViewer(NULL) -{ - setObjectName(name); - mName = "LibWidget"; - mVisibleState = true; - - SET_STYLE_SHEET(); - - mIconToLeft = QPixmap(":images/library_open.png"); - mIconToRight = QPixmap(":images/library_close.png"); - setAcceptDrops(true); - - mLayout = new QVBoxLayout(this); - setLayout(mLayout); - - // ------------- - // Build the GUI - // ------------- - // The 'global' widgets - mStackedWidget = new QStackedWidget(this); - mActionBar = new UBLibActionBar(this); - mpPathViewer = new UBLibPathViewer(this); - mpPathViewer->setMaximumHeight(62); - - // The internal widgets - mNavigator = new UBLibNavigatorWidget(this); - mProperties = new UBLibItemProperties(this); - mpWebView = new UBLibWebView(this); - - mLayout->addWidget(mpPathViewer, 0); - mLayout->addWidget(mStackedWidget, 1); - mLayout->addWidget(mActionBar, 0); - - mStackedWidget->addWidget(mNavigator); - mStackedWidget->addWidget(mProperties); - mStackedWidget->addWidget(mpWebView); - - mStackedWidget->setCurrentIndex(ID_NAVIGATOR); - miCrntStackWidget = ID_NAVIGATOR; - - connect(mNavigator, SIGNAL(updateNavigBar(UBChainedLibElement*)), this, SLOT(onUpdateNavigBar(UBChainedLibElement*))); - connect(mNavigator, SIGNAL(propertiesRequested(UBLibElement*)), this, SLOT(showProperties(UBLibElement*))); - connect(mNavigator, SIGNAL(displaySearchEngine(UBLibElement*)), this, SLOT(showSearchEngine(UBLibElement*))); - connect(mProperties, SIGNAL(showFolderContent()), this, SLOT(showFolder())); - connect(this, SIGNAL(showLibElemProperties()), mpPathViewer, SLOT(showBack())); - connect(this, SIGNAL(showLibSearchEngine()), mpPathViewer, SLOT(showBack())); -} - -/** - * \brief Destructor - */ -UBLibWidget::~UBLibWidget() -{ - if(NULL != mpPathViewer) - { - delete mpPathViewer; - mpPathViewer = NULL; - } - if(NULL != mNavigator) - { - delete mNavigator; - mNavigator = NULL; - } - if(NULL != mpWebView) - { - delete mpWebView; - mpWebView = NULL; - } - if(NULL != mProperties) - { - delete mProperties; - mProperties = NULL; - } - if(NULL != mStackedWidget) - { - delete mStackedWidget; - mStackedWidget = NULL; - } - if(NULL != mActionBar) - { - delete mActionBar; - mActionBar = NULL; - } - if(NULL != mLayout) - { - delete mLayout; - mLayout = NULL; - } -} - -/** - * \brief Handles the drag enter event - * @param pEvent as the drag enter event - */ -void UBLibWidget::dragEnterEvent(QDragEnterEvent *pEvent) -{ - setBackgroundRole(QPalette::Highlight); - pEvent->acceptProposedAction(); -} - -void UBLibWidget::dragLeaveEvent(QDragLeaveEvent *pEvent) -{ - pEvent->accept(); -} - -/** - * \brief Handles the drop event - * @param pEvent as the drop event - */ -void UBLibWidget::dropEvent(QDropEvent *pEvent) -{ - processMimeData(pEvent->mimeData()); - setBackgroundRole(QPalette::Dark); - mStackedWidget->setCurrentIndex(miCrntStackWidget); - pEvent->acceptProposedAction(); -} - -/** - * \brief Handles the drag move event - * @param pEvent as the drag move event - */ -void UBLibWidget::dragMoveEvent(QDragMoveEvent *pEvent) -{ - pEvent->acceptProposedAction(); -} - -/** - * \brief Process the dropped MIME data - * @param pData as the mime dropped data - */ -void UBLibWidget::processMimeData(const QMimeData *pData) -{ - // Display the different mime types contained in the mime data - QStringList qslFormats = pData->formats(); - for(int i = 0; i < qslFormats.size(); i++) - { - qDebug() << "Dropped element format " << i << " = "<< qslFormats.at(i); - } -} - -void UBLibWidget::showProperties(UBLibElement *elem) -{ - if(NULL != elem) - { - emit showLibElemProperties(); - mActionBar->setButtons(eButtonSet_Properties); - mProperties->showElement(elem); - mStackedWidget->setCurrentIndex(ID_PROPERTIES); - miCrntStackWidget = ID_PROPERTIES; - } -} - -void UBLibWidget::showSearchEngine(UBLibElement *elem) -{ - if(NULL != elem) - { - emit showLibSearchEngine(); - mActionBar->hide(); - mpWebView->setElement(elem); - mStackedWidget->setCurrentIndex(ID_WEBVIEW); - miCrntStackWidget = ID_WEBVIEW; - } -} - -void UBLibWidget::showFolder() -{ - if(!mActionBar->isVisible()){ - mActionBar->setVisible(true); - } - mActionBar->setButtons(mActionBar->previousButtonSet()); - mStackedWidget->setCurrentIndex(ID_NAVIGATOR); - miCrntStackWidget = ID_NAVIGATOR; -} - -int UBLibWidget::customMargin() -{ - return 5; -} - -int UBLibWidget::border() -{ - return 15; -} - -void UBLibWidget::onUpdateNavigBar(UBChainedLibElement *elem) -{ - mpPathViewer->displayPath(elem); - mpPathViewer->show(); - - if(ID_NAVIGATOR != miCrntStackWidget) - { - showFolder(); - } -} diff --git a/src/gui/UBLibWidget.h b/src/gui/UBLibWidget.h deleted file mode 100644 index eba4ca85..00000000 --- a/src/gui/UBLibWidget.h +++ /dev/null @@ -1,97 +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 2 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 UBLIBWIDGET_H -#define UBLIBWIDGET_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "UBDockPaletteWidget.h" -#include "UBLibNavigatorWidget.h" -#include "UBLibItemProperties.h" -#include "UBLibActionBar.h" -#include "UBLibWebView.h" -#include "UBLibPathViewer.h" - -#define ID_NAVIGATOR 0 -#define ID_PROPERTIES 1 -#define ID_WEBVIEW 2 - -class UBLibWidget : public UBDockPaletteWidget -{ - Q_OBJECT -public: - UBLibWidget(QWidget* parent=0, const char* name="UBLibWidget"); - ~UBLibWidget(); - - UBLibActionBar* actionBar(){return mActionBar;} - UBLibNavigatorWidget* libNavigator() {return mNavigator;} - UBLibPathViewer* pathViewer() {return mpPathViewer;} - - bool visibleInMode(eUBDockPaletteWidgetMode mode) - { - return mode == eUBDockPaletteWidget_BOARD - || mode == eUBDockPaletteWidget_DESKTOP; - } - -signals: - void resized(); - void showLibElemProperties(); - void showLibSearchEngine(); - -protected: - void dragEnterEvent(QDragEnterEvent* pEvent); - void dropEvent(QDropEvent *pEvent); - void dragMoveEvent(QDragMoveEvent* pEvent); - void dragLeaveEvent(QDragLeaveEvent* pEvent); - -private slots: - void showProperties(UBLibElement* elem); - void showSearchEngine(UBLibElement* elem); - void showFolder(); - void onUpdateNavigBar(UBChainedLibElement* elem); - -private: - void processMimeData(const QMimeData* pData); - int customMargin(); - int border(); - - /** The layout */ - QVBoxLayout* mLayout; - /** The stacked layout */ - QStackedWidget* mStackedWidget; - /** The Navigator widget */ - UBLibNavigatorWidget* mNavigator; - /** The Properties widget */ - UBLibItemProperties* mProperties; - /** UBLibActionBar */ - UBLibActionBar* mActionBar; - /** The current stack widget index*/ - int miCrntStackWidget; - /** The webview used to display the search engines */ - UBLibWebView* mpWebView; - /** The path navigation widget */ - UBLibPathViewer* mpPathViewer; -}; - -#endif // UBLIBWIDGET_H diff --git a/src/gui/UBLibraryWidget.cpp b/src/gui/UBLibraryWidget.cpp deleted file mode 100644 index 6501a488..00000000 --- a/src/gui/UBLibraryWidget.cpp +++ /dev/null @@ -1,704 +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 2 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 - -#include "UBLibraryWidget.h" -#include "core/UBSettings.h" -#include "core/UBSetting.h" -#include "core/UBApplication.h" - -#include "board/UBBoardController.h" -#include "board/UBLibraryController.h" -#include "board/UBBoardPaletteManager.h" - -#include "core/UBDownloadManager.h" - -#include "frameworks/UBFileSystemUtils.h" -#include "frameworks/UBPlatformUtils.h" - -#include "core/memcheck.h" - -/** - * \brief Constructor - * @param parent as the parent widget - * @param name as the widget object name - */ -UBLibraryWidget::UBLibraryWidget(QWidget *parent, const char *name):UBThumbnailWidget(parent) - , chainedElements(NULL) - , mLibraryController(NULL) - , mpCrntDir(NULL) - , mpCrntElem(NULL) - , mpTmpElem(NULL) - , mLoadingLibraryItems(false) -{ - setObjectName(name); - setSpacing(5); - mLibraryController = new UBLibraryController(parentWidget()); -} - -/** - * \brief Destructor - */ -UBLibraryWidget::~UBLibraryWidget() -{ - if(NULL != mLibraryController){ - delete mLibraryController; - mLibraryController = NULL; - } - if(NULL != mpCrntDir){ - delete mpCrntDir; - mpCrntDir = NULL; - } - if(NULL != mpCrntElem){ - delete mpCrntElem; - mpCrntElem = NULL; - } - if(NULL != mpTmpElem){ - delete mpTmpElem; - mpTmpElem = NULL; - } -} - -/** - * \brief Initialize the widget content - */ -void UBLibraryWidget::init() -{ - setAcceptDrops(true); - mpCrntElem = new UBLibElement(); - mpCrntElem->setThumbnail(QImage(":images/libpalette/home.png")); - chainedElements = new UBChainedLibElement(mpCrntElem); - QList qlElems = mLibraryController->getContent(mpCrntElem); - mCurrentElems = qlElems; - - setCurrentElemsAndRefresh(chainedElements); - - connect(this, SIGNAL(mouseClick(QGraphicsItem*,int)), this, SLOT(onItemClicked(QGraphicsItem*,int))); - connect(this, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); - connect(UBDownloadManager::downloadManager(), SIGNAL(addDownloadedFileToLibrary(bool,QUrl,QString,QByteArray)), this, SLOT(onAddDownloadedFileToLibrary(bool,QUrl,QString,QByteArray))); - connect(UBApplication::boardController, SIGNAL(displayMetadata(QMap)), this, SLOT(onDisplayMetadata(QMap))); - connect(mLibraryController,SIGNAL(updateItemsList()),this,SLOT(onRefreshCurrentFolder())); -} - -/** - * \brief Refresh the view - */ -void UBLibraryWidget::refreshView() -{ - // Clear the view - mItems.clear(); - mLabels.clear(); - mItemsPaths.clear(); - mGraphicItems.clear(); - - // Generate the graphics items - generateItems(); - - // Set the new items - setGraphicsItems(mGraphicItems, mItemsPaths, mLabels); - - // Refresh the view - refreshScene(); - - emit navigBarUpdate(mpCrntElem); - - bool bFavorite = false; - if(NULL != mpCrntDir && mLibraryController->favoritePath() == mpCrntDir->path().toLocalFile()) - { - bFavorite = true; - } - emit favoritesEntered(bFavorite); -} - -/** - * \brief Generate the graphic items related to the current directory - */ -void UBLibraryWidget::generateItems() -{ - for(int i = 0; i < mCurrentElems.size(); i++) - { - UBLibElement* pElem = mCurrentElems.at(i); - mLabels << pElem->name(); - mItemsPaths << pElem->path(); - QGraphicsPixmapItem *pixmapItem = new UBThumbnailPixmap(QPixmap::fromImage(*pElem->thumbnail())); - mGraphicItems << pixmapItem; - } -} - -/** - * \brief Handles the click on an item - * @param item as the clicked item - * @param index as the given index - */ -void UBLibraryWidget::onItemClicked(QGraphicsItem *item, int index) -{ - Q_UNUSED(index); - if(NULL != item) - { - mLoadingLibraryItems = true; - int iItem = mGraphicItems.indexOf(item); - if(0 <= iItem) - { - UBLibElement* pElem = mCurrentElems.at(iItem); - if(NULL != pElem) - { - delete mpCrntElem; - mpCrntElem = new UBLibElement(pElem); - if(eUBLibElementType_Folder == pElem->type() || eUBLibElementType_VirtualFolder == pElem->type()) - { - // Add the clicked element to the end of the elements list - // (at this level, the user can only go down in the path) - UBChainedLibElement* pNextElem = new UBChainedLibElement(pElem); - appendChainedElement(pNextElem, chainedElements); - delete mpCrntDir; - mpCrntDir = new UBLibElement(pElem); - // Display the content of the folder - QList qlElems = mLibraryController->getContent(mpCrntDir); - mCurrentElems = qlElems; - refreshView(); - } - else - { - if ("application/search" == UBFileSystemUtils::mimeTypeFromFileName(pElem->path().toLocalFile())) - { - emit displaySearchEngine(pElem); - } - else - { - // Display the properties view - emit propertiesRequested(pElem); - } - } - } - emit itemClicked(); - } - mLoadingLibraryItems = false; - } -} - -/** - * \brief Append the given element to the given chain - * @param element as the element to append - * @param toElem as the given chain - */ -void UBLibraryWidget::appendChainedElement(UBChainedLibElement *element, UBChainedLibElement *toElem) -{ - if(NULL != toElem) - { - if(NULL != toElem->nextElement()) - { - appendChainedElement(element, toElem->nextElement()); - } - else - { - toElem->setNextElement(element); - } - } -} - -/** - * \brief Set the current element and refresh the scene - * @param elem as the current element - */ -void UBLibraryWidget::setCurrentElemsAndRefresh(UBChainedLibElement *elem) -{ - if(NULL != elem) - { - UBLibElement* pLibElem = elem->element(); - if(NULL != pLibElem) - { - if(eUBLibElementType_Item != pLibElem->type()) - { - QList qlElements = mLibraryController->getContent(pLibElem); - mCurrentElems = qlElements; - delete mpCrntElem; - mpCrntElem = new UBLibElement(pLibElem); - refreshView(); - delete mpCrntDir; - mpCrntDir = new UBLibElement(pLibElem); - bool bFavorite = false; - if(NULL != mpCrntDir && mLibraryController->favoritePath() == mpCrntDir->path().toLocalFile()) - { - bFavorite = true; - } - emit favoritesEntered(bFavorite); - } - } - } -} - -/** - * \brief Handles the selection changed event - */ -void UBLibraryWidget::onSelectionChanged() -{ - // Get the selected items - QList qlSelectedItems; - QList qlGI = selectedItems(); - - bCanDrag = true; - foreach(QGraphicsItem* it, qlGI) - { - int itIndex = mGraphicItems.indexOf(it); - if(0 <= itIndex) - { - UBLibElement* pElem = mCurrentElems.at(itIndex); - if(NULL != pElem) - { - if(eUBLibElementType_Category != pElem->type() && eUBLibElementType_VirtualFolder != pElem->type()) { - qlSelectedItems << pElem; - } - - if(!pElem->isMoveable()) - { - bCanDrag = false; - } - } - } - } - - // Check if we are in the trash folder - bool bInTrash = false; - if(NULL != mpCrntDir) - { - if("Trash" == mpCrntDir->name()) - { - bInTrash = true; - } - } - - // Send the signal with these items - emit itemsSelected(qlSelectedItems, bInTrash); -} - -/** - * \brief Handle the delete done event - */ -void UBLibraryWidget::onRefreshCurrentFolder() -{ - // Refresh the current view - mCurrentElems = mLibraryController->getContent(mpCrntDir); - refreshView(); -} - -/** - * \brief Handles the drag enter event - * @param event as the drag enter event - */ -void UBLibraryWidget::dragEnterEvent(QDragEnterEvent *event) -{ - event->acceptProposedAction(); -} - -/** - * \brief Handles the drag move event - * @param event as the drag move event - */ -void UBLibraryWidget::dragMoveEvent(QDragMoveEvent *event) -{ - UBLibElement* pElem = elementAt(event->pos()); - if(NULL != pElem) - { - // We can only drop an item into a folder - if(eUBLibElementType_Folder == pElem->type() || - eUBLibElementType_VirtualFolder == pElem->type()) - { - event->acceptProposedAction(); - } - } -} - -void UBLibraryWidget::onDropMe(const QMimeData *_data) -{ - Q_UNUSED(_data); -} - -/** - * \brief Handles the drop event - * @param event as the drop event - */ -void UBLibraryWidget::dropEvent(QDropEvent *event) -{ - const QMimeData* pMimeData = event->mimeData(); - if(event->source() == this){ - event->accept(); - - // Get the destination item - UBLibElement* pElem = elementAt(event->pos()); - if(NULL != pElem){ - if(eUBLibElementType_Folder == pElem->type()){ - // The drag comes from this application, we have now to get the list of UBLibElements* - QList qlDroppedElems; - - foreach(QUrl url, pMimeData->urls()){ - qlDroppedElems << url.toString(); - } - - if(!qlDroppedElems.empty()) - onElementsDropped(qlDroppedElems, pElem); - } - } - } - else{ - bool bDropAccepted = false; - - // We must check the URLs first because an image dropped from the web can contains the image datas, as well as the URLs - // and if we want to display the download widget in order to make the user wait for the end of the download, we need - // to check the URLs first! - if (pMimeData->hasUrls()){ - QList urlList = pMimeData->urls(); - for (int i = 0; i < urlList.size() && i < 32; ++i){ - QString crntPath = urlList.at(i).toString(); - mLibraryController->importItemOnLibrary(crntPath); - bDropAccepted = true; - } - } - // When an HTML is present, it means that we dropped something from the web. Normally, the HTML contains the element - // of the webpage and has a 'src' attribute containing the URL of the web ressource. Here we are looking for this - // 'src' attribute, get its value and download the ressource from this URL. - if (!bDropAccepted && pMimeData->hasHtml()){ - QString html = pMimeData->html(); - QString url = UBApplication::urlFromHtml(html); - if("" != url){ - mLibraryController->importItemOnLibrary(url); - bDropAccepted = true; - } - } - if (!bDropAccepted && pMimeData->hasText()){ - // On linux external dragged element are considered as text; - QString filePath = QUrl(pMimeData->text()).toLocalFile(); - if("" != filePath){ - mLibraryController->importItemOnLibrary(filePath); - bDropAccepted = true; - } - else{ -#ifdef Q_WS_MACX - // With Safari, in 95% of the drops, the mime datas are hidden in Apple Web Archive pasteboard type. - // This is due to the way Safari is working so we have to dig into the pasteboard in order to retrieve - // the data. - QString qsUrl = UBPlatformUtils::urlFromClipboard(); - if("" != qsUrl){ - // We finally got the url of the dropped ressource! Let's import it! - mLibraryController->importItemOnLibrary(qsUrl); - bDropAccepted = true; - } -#endif - } - } - if (!bDropAccepted && pMimeData->hasImage()){ - QImage image = qvariant_cast(pMimeData->imageData()); - mLibraryController->importImageOnLibrary(image); - bDropAccepted = true; - } - - if(bDropAccepted){ - onRefreshCurrentFolder(); -#ifdef Q_WS_MACX - event->acceptProposedAction(); -#else - event->accept(); -#endif - } - else{ - event->ignore(); - } - } -} - -/** - * \brief Get the element at the given position - * @param p as the given position - * @return a pointer on the related element - */ -UBLibElement* UBLibraryWidget::elementAt(QPoint p) -{ - QGraphicsItem* pItem = itemAt(p); - if(NULL != pItem) - { - int iItem = mGraphicItems.indexOf(pItem); - if(-1 != iItem) - { - return mCurrentElems.at(iItem); - } - } - - // If no element is found, return NULL - return NULL; -} - - -/** - * \brief Get the element from the given name - * @param name as the given element name - * @return the UBLibElement related to the given name - */ -UBLibElement* UBLibraryWidget::elementFromFilePath(const QString &filePath) -{ - UBLibElement* pElem = NULL; - - foreach(UBLibElement* elem, mCurrentElems) - { - if(elem->path().toLocalFile() == QUrl(filePath).toLocalFile()) - { - return elem; - } - - } - - return pElem; -} - - -/** - * \brief Update the thumbnails size - * @param newSize as the thumbnail size - */ -void UBLibraryWidget::updateThumbnailsSize(int newSize) -{ - setThumbnailWidth(newSize); - refreshView(); -} - -/** - * \brief Handles the element dropped event - * @param elements as the list of dropped elements - * @param target as the drop target - */ -void UBLibraryWidget::onElementsDropped(QList elements, UBLibElement *target) -{ - if(target != mpCrntDir) - { - QList qlElements; - - foreach(QString qsElem, elements) - qlElements << elementFromFilePath(qsElem); - - mLibraryController->moveContent(qlElements, target); - mCurrentElems = mLibraryController->getContent(mpCrntDir); - refreshView(); - } -} - -/** - * \brief Search the element related to the given text - * @param elem as the searched element name - */ -void UBLibraryWidget::onSearchElement(QString elem) -{ - // Store the original list of items - mOrigCurrentElems = mLibraryController->getContent(mpCrntDir); - - // Build the filtered list - mCurrentElems.clear(); - if(elem.isEmpty()) - { - mCurrentElems = mOrigCurrentElems; - } - else - { - foreach(UBLibElement* ubLibElem, mOrigCurrentElems) - { - if(ubLibElem->name().toLower().contains(elem.toLower())) - { - mCurrentElems << ubLibElem; - } - } - } - refreshView(); -} - -/** - * \brief Create a new folder - */ -void UBLibraryWidget::onNewFolderToCreate() -{ - // Create here a dialog asking the name of the new folder - UBNewFolderDlg dlg; - if(QDialog::Accepted == dlg.exec()) - { - mLibraryController->createNewFolder(dlg.folderName(), mpCrntElem); - onRefreshCurrentFolder(); - } -} - -/** - * \brief Constructor - * @param parent as the parent widget - * @param name as the object name - */ -UBNewFolderDlg::UBNewFolderDlg(QWidget *parent, const char *name):QDialog(parent) - , mpLabel(NULL) - , mpLineEdit(NULL) - , mpButtons(NULL) - , mpAddButton(NULL) - , mpCancelButton(NULL) - , mpLayout(NULL) -{ - setObjectName(name); - setWindowTitle(tr("Add new folder")); - setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowTitleHint); - mpLabel = new QLabel(tr("New Folder name:"),this); - mpLineEdit = new QLineEdit(this); - mpAddButton = new QPushButton(tr("Add")); - mpAddButton->setDefault(true); - - mpCancelButton = new QPushButton(tr("Cancel")); - mpCancelButton->setAutoDefault(false); - - mpButtons = new QDialogButtonBox(Qt::Horizontal, this); - mpLayout = new QVBoxLayout(this); - setLayout(mpLayout); - - mpLayout->addWidget(mpLabel, 1); - mpLayout->addWidget(mpLineEdit); - - mpButtons->addButton(mpAddButton,QDialogButtonBox::ActionRole); - mpButtons->addButton(mpCancelButton,QDialogButtonBox::ActionRole); - mpLayout->addWidget(mpButtons, 1,Qt::AlignJustify); - - connect(mpAddButton, SIGNAL(clicked()), this, SLOT(accept())); - connect(mpCancelButton, SIGNAL(clicked()), this, SLOT(reject())); - connect(mpLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(text_Changed(const QString &))); - connect(mpLineEdit, SIGNAL(textEdited(const QString &)), this, SLOT(text_Edited(const QString &))); - - setMaximumHeight(100); - setMinimumHeight(100); -} - -/** - * \brief Destructor - */ -UBNewFolderDlg::~UBNewFolderDlg() -{ - if(NULL != mpAddButton) - { - delete mpAddButton; - mpAddButton = NULL; - } - - if(NULL != mpCancelButton) - { - delete mpCancelButton; - mpCancelButton = NULL; - } - if(NULL != mpButtons) - { - delete mpButtons; - mpButtons = NULL; - } - if(NULL != mpLineEdit) - { - delete mpLineEdit; - mpLineEdit = NULL; - } - if(NULL != mpLabel) - { - delete mpLabel; - mpLabel = NULL; - } - - if(NULL != mpLayout) - { - delete mpLayout; - mpLayout = NULL; - } -} - -/** - * \brief Get the folder name - * @return the entered folder name - */ -QString UBNewFolderDlg::folderName() -{ - return mpLineEdit->text(); -} - -void UBNewFolderDlg::text_Changed(const QString &newText) -{ - Q_UNUSED(newText); -} - -/* -http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx - -< (less than) -> (greater than) -: (colon) -" (double quote) -/ (forward slash) -\ (backslash) // Note: The C++ compiler transforms backslashes in strings. To include a \ in a regexp, enter it twice, i.e. \\. To match the backslash character itself, enter it four times, i.e. \\\\. -| (vertical bar or pipe) -? (question mark) -* (asterisk) - -*/ - -void UBNewFolderDlg::text_Edited(const QString &newText) -{ - - QString new_text = newText; - -#ifdef Q_WS_WIN // Defined on Windows. - QString illegalCharList(" < > : \" / \\ | ? * "); - QRegExp regExp("[<>:\"/\\\\|?*]"); -#endif - -#ifdef Q_WS_QWS // Defined on Qt for Embedded Linux. - QString illegalCharList(" < > : \" / \\ | ? * "); - QRegExp regExp("[<>:\"/\\\\|?*]"); -#endif - -#ifdef Q_WS_MAC // Defined on Mac OS X. - QString illegalCharList(" < > : \" / \\ | ? * "); - QRegExp regExp("[<>:\"/\\\\|?*]"); -#endif - -#ifdef Q_WS_X11 // Defined on X11. - QString illegalCharList(" < > : \" / \\ | ? * "); - QRegExp regExp("[<>:\"/\\\\|?*]"); -#endif - - if(new_text.indexOf(regExp) > -1) - { - new_text.remove(regExp); - mpLineEdit->setText(new_text); - QToolTip::showText(mpLineEdit->mapToGlobal(QPoint()), "A file name can`t contain any of the following characters:\r\n"+illegalCharList); - } -} - -void UBLibraryWidget::onAddDownloadedFileToLibrary(bool pSuccess, QUrl sourceUrl, QString pContentHeader, QByteArray pData) -{ - Q_UNUSED(pContentHeader); - if(pSuccess) - { - QString urlString = sourceUrl.toString(); - mLibraryController->routeDataItem(urlString, pData); - } -} - -void UBLibraryWidget::onDisplayMetadata(QMap metadatas) -{ - mpTmpElem = new UBLibElement(); - mpTmpElem->setMetadata(metadatas); - mpTmpElem->setPath(QUrl(metadatas["Url"])); - - // As the content comes from the web (and need a download), we will not display its thumbnail. - mpTmpElem->setThumbnail(QImage(":images/libpalette/notFound.png")); - - // Display the properties view - emit propertiesRequested(mpTmpElem); -} diff --git a/src/gui/UBLibraryWidget.h b/src/gui/UBLibraryWidget.h deleted file mode 100644 index bb655317..00000000 --- a/src/gui/UBLibraryWidget.h +++ /dev/null @@ -1,124 +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 2 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 UBLIBRARYWIDGET_H -#define UBLIBRARYWIDGET_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "UBThumbnailWidget.h" -#include "board/UBLibraryController.h" - -class UBLibraryController; -class UBChainedLibElement; -class UBLibElement; - -class UBLibraryWidget : public UBThumbnailWidget -{ - Q_OBJECT -public: - UBLibraryWidget(QWidget* parent=0, const char* name="UBLibraryWidget"); - ~UBLibraryWidget(); - - UBChainedLibElement* chainedElements; - void setCurrentElemsAndRefresh(UBChainedLibElement* elem); - - void updateThumbnailsSize(int newSize); - void init(); - - UBLibraryController* libraryController() {return mLibraryController;} - bool isLoadingLibraryItems() const { return mLoadingLibraryItems; } - -public slots: - void onRefreshCurrentFolder(); - void onElementsDropped(QList elements, UBLibElement* target); - void onSearchElement(QString elem); - void onNewFolderToCreate(); - void onDropMe(const QMimeData* _data); - void onAddDownloadedFileToLibrary(bool pSuccess, QUrl sourceUrl, QString pContentHeader, QByteArray pData); - -signals: - void navigBarUpdate(UBLibElement* pElem); - void itemsSelected(QList elemList, bool inTrash); - void propertiesRequested(UBLibElement* pElem); - void displaySearchEngine(UBLibElement* pElem); - void favoritesEntered(bool bFav); - void itemClicked(); - -protected: - void dragEnterEvent(QDragEnterEvent *event); - void dragMoveEvent(QDragMoveEvent *event); - void dropEvent(QDropEvent *event); - -private slots: - void onItemClicked(QGraphicsItem* pItem, int index); - void onSelectionChanged(); - void onDisplayMetadata(QMap metadatas); - - -private: - - void refreshView(); - void generateItems(); - void appendChainedElement(UBChainedLibElement* element, UBChainedLibElement* toElem); - - UBLibElement* elementAt(QPoint p); - UBLibElement* elementFromFilePath(const QString& filePath); - UBLibraryController* mLibraryController; - - UBLibElement* mpCrntDir; - UBLibElement* mpCrntElem; - UBLibElement* mpTmpElem; - QList mCurrentElems; - QList mOrigCurrentElems; - QList mItems; - bool mLoadingLibraryItems; -}; - -class UBNewFolderDlg : public QDialog -{ - Q_OBJECT - -public: - UBNewFolderDlg(QWidget* parent=0, const char* name="NewFolderDlg"); - ~UBNewFolderDlg(); - - QString folderName(); - -public slots: - void text_Changed(const QString &); - void text_Edited(const QString &); - - -private: - QLabel* mpLabel; - QLineEdit* mpLineEdit; - QDialogButtonBox* mpButtons; - QPushButton* mpAddButton; - QPushButton* mpCancelButton; - QVBoxLayout* mpLayout; -}; - -#endif // UBLIBRARYWIDGET_H diff --git a/src/gui/gui.pri b/src/gui/gui.pri index 61583d04..9fa8c3dc 100644 --- a/src/gui/gui.pri +++ b/src/gui/gui.pri @@ -30,11 +30,6 @@ HEADERS += src/gui/UBThumbnailView.h \ src/gui/UBDocumentNavigator.h \ src/gui/UBDockPalette.h \ src/gui/UBPropertyPalette.h \ - src/gui/UBLibNavigatorWidget.h \ - src/gui/UBLibItemProperties.h \ - src/gui/UBLibActionBar.h \ - src/gui/UBLibraryWidget.h \ - src/gui/UBLibPathViewer.h \ src/gui/UBUpdateDlg.h \ src/gui/UBDockPaletteWidget.h \ src/gui/UBLeftPalette.h \ @@ -84,20 +79,13 @@ SOURCES += src/gui/UBThumbnailView.cpp \ src/gui/UBDocumentNavigator.cpp \ src/gui/UBDockPalette.cpp \ src/gui/UBPropertyPalette.cpp \ - src/gui/UBLibNavigatorWidget.cpp \ - src/gui/UBLibItemProperties.cpp \ - src/gui/UBLibActionBar.cpp \ - src/gui/UBLibraryWidget.cpp \ - src/gui/UBLibPathViewer.cpp \ src/gui/UBUpdateDlg.cpp \ src/gui/UBDockPaletteWidget.cpp \ src/gui/UBLeftPalette.cpp \ src/gui/UBRightPalette.cpp \ src/gui/UBPageNavigationWidget.cpp \ - src/gui/UBLibWidget.cpp \ src/gui/UBMagnifer.cpp \ src/gui/UBCachePropertiesWidget.cpp \ - src/gui/UBLibWebView.cpp \ src/gui/UBDownloadWidget.cpp \ src/gui/UBDockDownloadWidget.cpp \ src/gui/UBFeaturesWidget.cpp \ From 3d56b92cff5188aaf23685e07422655ecd4e2626 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 20 Aug 2012 16:39:47 +0300 Subject: [PATCH 6/9] Group button text sets right when application mode changes. --- src/core/UBApplicationController.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/UBApplicationController.cpp b/src/core/UBApplicationController.cpp index fbb20af6..c0f9918a 100644 --- a/src/core/UBApplicationController.cpp +++ b/src/core/UBApplicationController.cpp @@ -365,6 +365,7 @@ void UBApplicationController::showBoard() emit mainModeChanged(Board); UBApplication::boardController->freezeW3CWidgets(false); + UBApplication::boardController->activeScene()->updateGroupButtonState(); } From 333adf4afb5f790b1abdf7282e4d1289aa56a693 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 20 Aug 2012 17:13:15 +0200 Subject: [PATCH 7/9] fixed Sankore-704 bug --- .../Contraste.wgt/css/basic.css | 20 +++-- .../Contraste.wgt/images/trgDown.png | Bin 0 -> 475 bytes .../Contraste.wgt/images/trgRight.png | Bin 0 -> 447 bytes .../locales/fr/scripts/blackYellow.js | 70 ++++++++++------ .../locales/ru/scripts/blackYellow.js | 70 ++++++++++------ .../Contraste.wgt/scripts/blackYellow.js | 75 ++++++++++++------ 6 files changed, 157 insertions(+), 78 deletions(-) create mode 100644 resources/library/interactivities/Contraste.wgt/images/trgDown.png create mode 100644 resources/library/interactivities/Contraste.wgt/images/trgRight.png diff --git a/resources/library/interactivities/Contraste.wgt/css/basic.css b/resources/library/interactivities/Contraste.wgt/css/basic.css index 6ca92f51..451e6ce0 100644 --- a/resources/library/interactivities/Contraste.wgt/css/basic.css +++ b/resources/library/interactivities/Contraste.wgt/css/basic.css @@ -60,6 +60,7 @@ body{ .shadowDiv{ width: 100%; + height: 100%; display: none; opacity: 0.7; background-color: black; @@ -67,7 +68,10 @@ body{ -webkit-border-radius: 3px; border-radius: 3px; border-radius: 3px; - z-index: 100; + z-index: 400; + position: absolute; + top: 0; + left: 0; } .popupBack{ @@ -126,8 +130,6 @@ body{ } .readyTask{ - margin: 2px; - padding: 2px; width: 100%; height: 100%; overflow: hidden; @@ -167,9 +169,11 @@ body{ height: 65%; cursor: e-resize; position: absolute; - background: none; + background-image: url(../images/trgRight.png); + background-position: center; + background-repeat: no-repeat; right: -10px; - top: 20%; + top: 18%; } .bottomResize{ @@ -177,9 +181,11 @@ body{ height: 10px; cursor: n-resize; position: absolute; - background: none; + background-image: url(../images/trgDown.png); + background-position: center; + background-repeat: no-repeat; bottom: -10px; - left: 20%; + left: 18%; } /*new design*/ diff --git a/resources/library/interactivities/Contraste.wgt/images/trgDown.png b/resources/library/interactivities/Contraste.wgt/images/trgDown.png new file mode 100644 index 0000000000000000000000000000000000000000..632be5fb5560dde4c9a5c76430e7878d817381b7 GIT binary patch literal 475 zcmV<10VMv3P)g(&fl=1oV=d#Yu&ZkvXRmDX`MZpSKSy>s_*w|1o z4-XH++qZ8ScJAEybnDiwrc4qN5|7*3+S1OPIm5ur%*?>T!UD%217L=L+LB44j;tU>bx41qB&)?AXEJ>gw9(?d`o2 zq=)hU|NkJG;memV+)hqT$F;Pybk)_>!D1jk@$&LA+`4s(;lzm(XMxVN;o{=@0g?mT z2m(MqeC_Y=Pd#?**iTSkaC37r02ML({ri_;`}XbMdwYA+V46@gf`GNP^~w17_y(Xt zu#@@t_!w5NUd;d$t1>e)JBO?m?o=26+Q8)H<+aDaz`zj{J=d>a-?4e~W>1hSPyk3H zI=*q^hO&l+#usgE?e}-@-j&CuhJ^tO00z$8l9G~qU{w58Qc`+|O$|VR0RRFkn+8)O RIpF{R002ovPDHLkV1k0cgTH8uZrbaeg|78dq={rZ&yn?k0aKYua^3kx%(rKK_6 zym_%3P7sHYk&yvp11l>l zgQcY_jrs=B)RU9cNLx?v^&eaz_Ur+PU7kOGeyX*#^+}ZQk(QQz>+kRXA4vbt&d#3l`SWLPtT6+0_$Q#RUjW_W phc^m?f`aBefBsySP@(_`FaZ5oAyt9V@9zKr002ovPDHLkV1jvi#&`e# literal 0 HcmV?d00001 diff --git a/resources/library/interactivities/Contraste.wgt/locales/fr/scripts/blackYellow.js b/resources/library/interactivities/Contraste.wgt/locales/fr/scripts/blackYellow.js index 7f0cfb19..7cfdea27 100644 --- a/resources/library/interactivities/Contraste.wgt/locales/fr/scripts/blackYellow.js +++ b/resources/library/interactivities/Contraste.wgt/locales/fr/scripts/blackYellow.js @@ -81,9 +81,9 @@ function init(){ .css("top",importArray[i].top) .css("left",importArray[i].left); tmpReadyTask.appendTo("#data"); - } - } - $(document).disableTextSelect(); + } + $(document).disableTextSelect(); + } } /* ------------- BUTTONS -------------*/ @@ -182,10 +182,16 @@ function init(){ }); $("#wgt_add").click(function(){ - shadowDiv.show("fast", function(){ - shadowOver = true; - popupBack.show("slow"); - }); + if($("#wgt_help").hasClass("open")){ + $("#help").slideUp("100", function(){ + $("#wgt_help").removeClass("open"); + $("#data").show(); + }); + } + shadowDiv.show() + shadowOver = true; + popupBack.show("slow"); + $(document).disableTextSelect(); }); @@ -203,7 +209,7 @@ function init(){ var rightDiv = $("
").appendTo("#data"); //divs for adding a new item - var shadowDiv = $("
").appendTo("#data"); + var shadowDiv = $("
").appendTo("html"); var popupBack = $("
").appendTo("#data"); //input fields and buttons for a popup window @@ -228,37 +234,39 @@ function init(){ }); cancelButton.click(function(){ - $(document).enableTextSelect(); popupBack.hide("slow", function(){ $("#resultText, #expresionText").val("") .css("background-color", "#ffc"); - shadowDiv.hide("fast"); + shadowDiv.hide(); shadowOver = false; + $(document).enableTextSelect(); }); + }); okButton.click(function(){ - $(document).enableTextSelect(); if(checkEmptyFields(expresionText) && checkEmptyFields(resultText)){ popupBack.hide("slow", function(){ - shadowDiv.hide("fast"); + shadowDiv.hide(); shadowOver = false; addTask(expresionText.val(), resultText.val()); exportToSankore(); $("#resultText, #expresionText").val("") .css("background-color", "#ffc"); + $(document).enableTextSelect(); }) } + }); /* -------------- THE END OF WORK WITH POPUP BUTTONS AND FIELDS ---------------*/ // a work with dragging possibility - $("input:text, .style_select").mouseover(function(){ + $("input:text").mouseover(function(){ $(document).enableTextSelect(); }); - $("input:text, .style_select").mouseout(function(){ + $("input:text").mouseout(function(){ $(document).disableTextSelect(); }); @@ -270,6 +278,8 @@ function init(){ resizeObj.width = $(this).width(); resizeObj.height = $(this).height(); } + if($("#wgt_display").hasClass("selected")) + $(document).disableTextSelect(); }); $(".rightResize").live("mousedown",function(event){ @@ -296,13 +306,25 @@ function init(){ }); $("body").mousemove(function(event){ - if(dragElement && !shadowOver){ - if(resizeObj.x) - dragElement.width(event.pageX - dragElement.position().left); - else if(resizeObj.y) - dragElement.height(event.pageY - dragElement.position().top); - else - dragElement.css("top",event.pageY - coords.top).css("left", event.pageX - coords.left); + if(dragElement && !shadowOver){ + var top = event.pageY - coords.top; + var left = event.pageX - coords.left; + var bottom = top + dragElement.height(); + var right = left + dragElement.width(); + if(resizeObj.x){ + if(right < ($(window).width() - 54)) + dragElement.width(event.pageX - dragElement.position().left); + } + else if(resizeObj.y){ + if(bottom < ($(window).height() - 54)) + dragElement.height(event.pageY - dragElement.position().top); + } + else { + if((top > 54) && (bottom < ($(window).height() - 54))) + dragElement.css("top",event.pageY - coords.top); + if((left >= 54) && (right < ($(window).width() - 54))) + dragElement.css("left", event.pageX - coords.left); + } } }); @@ -393,8 +415,8 @@ function checkEmptyFields(field){ //adding a new task to the page function addTask(expression, result){ var lastItem = $(".editContainer:last"), - lastItemPos = lastItem.length ? lastItem.position().top : 45, - lastItemHeight = lastItem.length ? lastItem.height() : 0; + lastItemPos = lastItem.length ? lastItem.position().top : 45, + lastItemHeight = lastItem.length ? lastItem.height() : 0; var editContent = $("
").width(240).height(70).css("top", lastItemPos + lastItemHeight + 15 + "px").appendTo("#data"); var closeItem = $("
").appendTo(editContent); var rightResize = $("
").appendTo(editContent); @@ -463,4 +485,6 @@ function changeStyle(val){ $("body, html").addClass("without_radius"); break; } + if($("#wgt_edit").hasClass("selected")) + $(document).enableTextSelect(); } \ No newline at end of file diff --git a/resources/library/interactivities/Contraste.wgt/locales/ru/scripts/blackYellow.js b/resources/library/interactivities/Contraste.wgt/locales/ru/scripts/blackYellow.js index d77e7108..ab7ad61a 100644 --- a/resources/library/interactivities/Contraste.wgt/locales/ru/scripts/blackYellow.js +++ b/resources/library/interactivities/Contraste.wgt/locales/ru/scripts/blackYellow.js @@ -23,9 +23,9 @@ var sankoreLang = { cancel: "Отмена", wgt_name: "Черный/желтый", reload: "Обновить", - slate: "Узор", - pad: "Планшет", - none: "Нет", + slate: "узор", + pad: "планшет", + none: "нет", help: "Помощь", help_content: "Пример текста помощи ..." }; @@ -182,10 +182,16 @@ function init(){ }); $("#wgt_add").click(function(){ - shadowDiv.show("fast", function(){ - shadowOver = true; - popupBack.show("slow"); - }); + if($("#wgt_help").hasClass("open")){ + $("#help").slideUp("100", function(){ + $("#wgt_help").removeClass("open"); + $("#data").show(); + }); + } + shadowDiv.show() + shadowOver = true; + popupBack.show("slow"); + $(document).disableTextSelect(); }); @@ -203,7 +209,7 @@ function init(){ var rightDiv = $("
").appendTo("#data"); //divs for adding a new item - var shadowDiv = $("
").appendTo("#data"); + var shadowDiv = $("
").appendTo("html"); var popupBack = $("
").appendTo("#data"); //input fields and buttons for a popup window @@ -228,37 +234,39 @@ function init(){ }); cancelButton.click(function(){ - $(document).enableTextSelect(); popupBack.hide("slow", function(){ $("#resultText, #expresionText").val("") .css("background-color", "#ffc"); - shadowDiv.hide("fast"); + shadowDiv.hide(); shadowOver = false; + $(document).enableTextSelect(); }); + }); okButton.click(function(){ - $(document).enableTextSelect(); if(checkEmptyFields(expresionText) && checkEmptyFields(resultText)){ popupBack.hide("slow", function(){ - shadowDiv.hide("fast"); + shadowDiv.hide(); shadowOver = false; addTask(expresionText.val(), resultText.val()); exportToSankore(); $("#resultText, #expresionText").val("") .css("background-color", "#ffc"); + $(document).enableTextSelect(); }) } + }); /* -------------- THE END OF WORK WITH POPUP BUTTONS AND FIELDS ---------------*/ // a work with dragging possibility - $("input:text, .style_select").mouseover(function(){ + $("input:text").mouseover(function(){ $(document).enableTextSelect(); }); - $("input:text, .style_select").mouseout(function(){ + $("input:text").mouseout(function(){ $(document).disableTextSelect(); }); @@ -270,6 +278,8 @@ function init(){ resizeObj.width = $(this).width(); resizeObj.height = $(this).height(); } + if($("#wgt_display").hasClass("selected")) + $(document).disableTextSelect(); }); $(".rightResize").live("mousedown",function(event){ @@ -296,13 +306,25 @@ function init(){ }); $("body").mousemove(function(event){ - if(dragElement && !shadowOver){ - if(resizeObj.x) - dragElement.width(event.pageX - dragElement.position().left); - else if(resizeObj.y) - dragElement.height(event.pageY - dragElement.position().top); - else - dragElement.css("top",event.pageY - coords.top).css("left", event.pageX - coords.left); + if(dragElement && !shadowOver){ + var top = event.pageY - coords.top; + var left = event.pageX - coords.left; + var bottom = top + dragElement.height(); + var right = left + dragElement.width(); + if(resizeObj.x){ + if(right < ($(window).width() - 54)) + dragElement.width(event.pageX - dragElement.position().left); + } + else if(resizeObj.y){ + if(bottom < ($(window).height() - 54)) + dragElement.height(event.pageY - dragElement.position().top); + } + else { + if((top > 54) && (bottom < ($(window).height() - 54))) + dragElement.css("top",event.pageY - coords.top); + if((left >= 54) && (right < ($(window).width() - 54))) + dragElement.css("left", event.pageX - coords.left); + } } }); @@ -393,8 +415,8 @@ function checkEmptyFields(field){ //adding a new task to the page function addTask(expression, result){ var lastItem = $(".editContainer:last"), - lastItemPos = lastItem.length ? lastItem.position().top : 45, - lastItemHeight = lastItem.length ? lastItem.height() : 0; + lastItemPos = lastItem.length ? lastItem.position().top : 45, + lastItemHeight = lastItem.length ? lastItem.height() : 0; var editContent = $("
").width(240).height(70).css("top", lastItemPos + lastItemHeight + 15 + "px").appendTo("#data"); var closeItem = $("
").appendTo(editContent); var rightResize = $("
").appendTo(editContent); @@ -463,4 +485,6 @@ function changeStyle(val){ $("body, html").addClass("without_radius"); break; } + if($("#wgt_edit").hasClass("selected")) + $(document).enableTextSelect(); } \ No newline at end of file diff --git a/resources/library/interactivities/Contraste.wgt/scripts/blackYellow.js b/resources/library/interactivities/Contraste.wgt/scripts/blackYellow.js index 85cdaab2..33687d4d 100644 --- a/resources/library/interactivities/Contraste.wgt/scripts/blackYellow.js +++ b/resources/library/interactivities/Contraste.wgt/scripts/blackYellow.js @@ -23,9 +23,9 @@ var sankoreLang = { cancel: "Cancel", wgt_name: "Contrast", reload: "Reload", - slate: "Wood", - pad: "Pad", - none: "None", + slate: "wood", + pad: "pad", + none: "none", help: "Help", help_content: "This is an example of help content ..." }; @@ -88,9 +88,12 @@ function init(){ /* ------------- BUTTONS -------------*/ - if(sankore.preference("by_style","")){ - changeStyle(sankore.preference("by_style","")); - $(".style_select").val(sankore.preference("by_style","")); + if(window.sankore){ + if(sankore.preference("by_style","")){ + changeStyle(sankore.preference("by_style","")); + $(".style_select").val(sankore.preference("by_style","")); + } else + changeStyle("3") } else changeStyle("3") @@ -182,10 +185,15 @@ function init(){ }); $("#wgt_add").click(function(){ - shadowDiv.show("fast", function(){ - shadowOver = true; - popupBack.show("slow"); - }); + if($("#wgt_help").hasClass("open")){ + $("#help").slideUp("100", function(){ + $("#wgt_help").removeClass("open"); + $("#data").show(); + }); + } + shadowDiv.show(); + shadowOver = true; + popupBack.show("slow"); $(document).disableTextSelect(); }); @@ -203,7 +211,7 @@ function init(){ var rightDiv = $("
").appendTo("#data"); //divs for adding a new item - var shadowDiv = $("
").appendTo("#data"); + var shadowDiv = $("
").appendTo("html"); var popupBack = $("
").appendTo("#data"); //input fields and buttons for a popup window @@ -228,25 +236,25 @@ function init(){ }); cancelButton.click(function(){ - $(document).enableTextSelect(); popupBack.hide("slow", function(){ $("#resultText, #expresionText").val("") .css("background-color", "#ffc"); - shadowDiv.hide("fast"); + shadowDiv.hide(); shadowOver = false; + $(document).enableTextSelect(); }); }); okButton.click(function(){ - $(document).enableTextSelect(); if(checkEmptyFields(expresionText) && checkEmptyFields(resultText)){ popupBack.hide("slow", function(){ - shadowDiv.hide("fast"); + shadowDiv.hide(); shadowOver = false; addTask(expresionText.val(), resultText.val()); exportToSankore(); $("#resultText, #expresionText").val("") .css("background-color", "#ffc"); + $(document).enableTextSelect(); }) } }); @@ -254,11 +262,11 @@ function init(){ /* -------------- THE END OF WORK WITH POPUP BUTTONS AND FIELDS ---------------*/ // a work with dragging possibility - $("input:text, .style_select").mouseover(function(){ + $("input:text").mouseover(function(){ $(document).enableTextSelect(); }); - $("input:text, .style_select").mouseout(function(){ + $("input:text").mouseout(function(){ $(document).disableTextSelect(); }); @@ -270,6 +278,8 @@ function init(){ resizeObj.width = $(this).width(); resizeObj.height = $(this).height(); } + if($("#wgt_display").hasClass("selected")) + $(document).disableTextSelect(); }); $(".rightResize").live("mousedown",function(event){ @@ -296,13 +306,25 @@ function init(){ }); $("body").mousemove(function(event){ - if(dragElement && !shadowOver){ - if(resizeObj.x) - dragElement.width(event.pageX - dragElement.position().left); - else if(resizeObj.y) - dragElement.height(event.pageY - dragElement.position().top); - else - dragElement.css("top",event.pageY - coords.top).css("left", event.pageX - coords.left); + if(dragElement && !shadowOver){ + var top = event.pageY - coords.top; + var left = event.pageX - coords.left; + var bottom = top + dragElement.height(); + var right = left + dragElement.width(); + if(resizeObj.x){ + if(right < ($(window).width() - 54)) + dragElement.width(event.pageX - dragElement.position().left); + } + else if(resizeObj.y){ + if(bottom < ($(window).height() - 54)) + dragElement.height(event.pageY - dragElement.position().top); + } + else { + if((top > 54) && (bottom < ($(window).height() - 54))) + dragElement.css("top",event.pageY - coords.top); + if((left >= 54) && (right < ($(window).width() - 54))) + dragElement.css("left", event.pageX - coords.left); + } } }); @@ -375,7 +397,8 @@ function init(){ }); } } - sankore.setPreference("blackYellowData", JSON.stringify(arrayToExport)); + if(window.sankore) + sankore.setPreference("blackYellowData", JSON.stringify(arrayToExport)); } } @@ -463,4 +486,6 @@ function changeStyle(val){ $("body, html").addClass("without_radius"); break; } + if($("#wgt_edit").hasClass("selected")) + $(document).enableTextSelect(); } From 67fbd3a135f318bc41426aad34c0a9a7474845e5 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Mon, 20 Aug 2012 17:15:36 +0300 Subject: [PATCH 8/9] Cleaning search text field for library at selection of folder from path viewer. --- src/gui/UBFeaturesActionBar.h | 1 + src/gui/UBFeaturesWidget.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/gui/UBFeaturesActionBar.h b/src/gui/UBFeaturesActionBar.h index 60db2c37..da2ca99b 100644 --- a/src/gui/UBFeaturesActionBar.h +++ b/src/gui/UBFeaturesActionBar.h @@ -42,6 +42,7 @@ public: ~UBFeaturesActionBar(); void setCurrentState( UBFeaturesActionBarState state ); + void cleanText(){ mSearchBar->clear(); } signals: void searchElement(const QString &text); diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index 1ed79316..2e7798cd 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -142,6 +142,7 @@ void UBFeaturesWidget::currentSelected(const QModelIndex ¤t) centralWidget->showElement(feature, UBFeaturesCentralWidget::FeaturePropertiesList); mActionBar->setCurrentState( IN_PROPERTIES ); } + mActionBar->cleanText(); } void UBFeaturesWidget::createNewFolder() From 2fdc027a8d49fde71da19708e07ebf0adf769b53 Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Mon, 20 Aug 2012 17:24:15 +0300 Subject: [PATCH 9/9] Sankore-969 Desktop mode bug --- src/board/UBBoardPaletteManager.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/board/UBBoardPaletteManager.cpp b/src/board/UBBoardPaletteManager.cpp index 83b2f3a4..2407ad37 100644 --- a/src/board/UBBoardPaletteManager.cpp +++ b/src/board/UBBoardPaletteManager.cpp @@ -704,8 +704,9 @@ void UBBoardPaletteManager::changeMode(eUBDockPaletteWidgetMode newMode, bool is mAddItemPalette->setParent((QWidget*)UBApplication::applicationController->uninotesController()->drawingView()); mLeftPalette->assignParent((QWidget*)UBApplication::applicationController->uninotesController()->drawingView()); mRightPalette->assignParent((QWidget*)UBApplication::applicationController->uninotesController()->drawingView()); - mRightPalette->lower(); - mLeftPalette->lower(); + // Maybe threre is a reason to keep that functions but with them right palette in desktop mode is not interactable + // mRightPalette->lower(); + // mLeftPalette->lower(); if (UBPlatformUtils::hasVirtualKeyboard() && mKeyboardPalette != NULL) {