From 241ddb92a19e21cabf0a420ab52e52af8539ae04 Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Wed, 4 Dec 2013 17:14:36 +0300 Subject: [PATCH] Duplicated group button functionality on the frame --- src/adaptors/UBMetadataDcSubsetAdaptor.cpp | 2 +- src/board/UBBoardController.cpp | 3 +- src/core/UBApplication.cpp | 4 ++- src/core/UBSettings.cpp | 14 ++++++-- src/core/UBSettings.h | 1 + .../UBGraphicsGroupContainerItemDelegate.cpp | 20 +++++++++++ .../UBGraphicsGroupContainerItemDelegate.h | 5 +++ src/domain/UBSelectionFrame.cpp | 33 ++++++++++++++++++- src/domain/UBSelectionFrame.h | 4 +++ 9 files changed, 79 insertions(+), 7 deletions(-) diff --git a/src/adaptors/UBMetadataDcSubsetAdaptor.cpp b/src/adaptors/UBMetadataDcSubsetAdaptor.cpp index acd4a0ba..5e3f237b 100644 --- a/src/adaptors/UBMetadataDcSubsetAdaptor.cpp +++ b/src/adaptors/UBMetadataDcSubsetAdaptor.cpp @@ -85,7 +85,7 @@ void UBMetadataDcSubsetAdaptor::persist(UBDocumentProxy* proxy) return; } QString fileName = proxy->persistencePath() + "/" + metadataFilename; - qWarning() << fileName; + qWarning() << "Persisting document path is" << fileName; QFile file(fileName); if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 19716757..3868c791 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -1804,8 +1804,7 @@ void UBBoardController::autosaveTimeout() void UBBoardController::appMainModeChanged(UBApplicationController::MainMode md) { -// int timerInterval = autosaveTimeoutFromSettings(); - int timerInterval = 50000; + int timerInterval = autosaveTimeoutFromSettings(); if (!timerInterval) { return; } diff --git a/src/core/UBApplication.cpp b/src/core/UBApplication.cpp index 25368c7b..e02a987c 100644 --- a/src/core/UBApplication.cpp +++ b/src/core/UBApplication.cpp @@ -120,7 +120,9 @@ UBApplication::UBApplication(const QString &id, int &argc, char **argv) : QtSing staticMemoryCleaner = new QObject(0); // deleted in UBApplication destructor - setOrganizationName("Open Education Foundation"); + setOrganizationName(UBSettings::organizationName()); + qDebug() << "organization name" << organizationName(); + qDebug() << "application" << this; setOrganizationDomain("oe-f.org"); setApplicationName("OpenBoard"); diff --git a/src/core/UBSettings.cpp b/src/core/UBSettings.cpp index 19d0fcfb..d34ad285 100644 --- a/src/core/UBSettings.cpp +++ b/src/core/UBSettings.cpp @@ -148,6 +148,7 @@ QSettings* UBSettings::getAppSettings() UBSettings::sAppSettings->setIniCodec("utf-8"); } + qDebug() << "sAppSettings" << sAppSettings; return UBSettings::sAppSettings; } @@ -774,7 +775,8 @@ QString UBSettings::userDataDirectory() { static QString dataDirPath = ""; if(dataDirPath.isEmpty()){ - if (sAppSettings && getAppSettings()->contains("App/DataDirectory")) { + if (getAppSettings() && getAppSettings()->contains("App/DataDirectory")) { + qDebug() << "getAppSettings()->contains(App/DataDirectory):" << getAppSettings()->contains("App/DataDirectory"); dataDirPath = getAppSettings()->value("App/DataDirectory").toString(); dataDirPath = replaceWildcard(dataDirPath); @@ -785,7 +787,9 @@ QString UBSettings::userDataDirectory() } dataDirPath = UBFileSystemUtils::normalizeFilePath(QDesktopServices::storageLocation(QDesktopServices::DataLocation)); - dataDirPath.replace(qApp->organizationName() + "/", ""); + qDebug() << "organization name" << UBSettings::organizationName(); + qDebug() << "application" << qApp; + dataDirPath.replace(UBSettings::organizationName() + "/", ""); } return dataDirPath; } @@ -879,6 +883,11 @@ QString UBSettings::userPodcastRecordingDirectory() return dirPath; } +QString UBSettings::organizationName() +{ + return "Open Education Foundation"; +} + QString UBSettings::userDocumentDirectory() { @@ -887,6 +896,7 @@ QString UBSettings::userDocumentDirectory() documentDirectory = userDataDirectory() + "/document"; checkDirectory(documentDirectory); } + qDebug() << "userDocumentDirectory()" << documentDirectory; return documentDirectory; } diff --git a/src/core/UBSettings.h b/src/core/UBSettings.h index 9de4c801..b786219e 100644 --- a/src/core/UBSettings.h +++ b/src/core/UBSettings.h @@ -137,6 +137,7 @@ class UBSettings : public QObject static QString userInteractiveDirectory(); static QString userInteractiveFavoritesDirectory(); static QString userPodcastRecordingDirectory(); + static QString organizationName(); QString userGipLibraryDirectory(); diff --git a/src/domain/UBGraphicsGroupContainerItemDelegate.cpp b/src/domain/UBGraphicsGroupContainerItemDelegate.cpp index 65a951c1..2be700f0 100644 --- a/src/domain/UBGraphicsGroupContainerItemDelegate.cpp +++ b/src/domain/UBGraphicsGroupContainerItemDelegate.cpp @@ -70,9 +70,23 @@ void UBGraphicsGroupContainerItemDelegate::decorateMenu(QMenu *menu) void UBGraphicsGroupContainerItemDelegate::buildButtons() { + if (!mDestroyGroupButton) { + mDestroyGroupButton = new DelegateButton(":/images/minus.svg", mDelegated, mFrame, Qt::TopLeftSection); + mDestroyGroupButton->setShowProgressIndicator(false); + connect(mDestroyGroupButton, SIGNAL(clicked()), this, SLOT(destroyGroup())); + mButtons << mDestroyGroupButton; + } + UBGraphicsItemDelegate::buildButtons(); } +void UBGraphicsGroupContainerItemDelegate::freeButtons() +{ + UBGraphicsItemDelegate::freeButtons(); + mDestroyGroupButton = 0; + mButtons.clear(); +} + bool UBGraphicsGroupContainerItemDelegate::mousePressEvent(QGraphicsSceneMouseEvent *event) { Q_UNUSED(event) @@ -93,3 +107,9 @@ bool UBGraphicsGroupContainerItemDelegate::mouseReleaseEvent(QGraphicsSceneMouse return false; } + +void UBGraphicsGroupContainerItemDelegate::destroyGroup() +{ + qDebug() << "Destroying group"; + delegated()->destroy(); +} diff --git a/src/domain/UBGraphicsGroupContainerItemDelegate.h b/src/domain/UBGraphicsGroupContainerItemDelegate.h index 6bd8af49..27046481 100644 --- a/src/domain/UBGraphicsGroupContainerItemDelegate.h +++ b/src/domain/UBGraphicsGroupContainerItemDelegate.h @@ -43,11 +43,16 @@ public: protected: virtual void decorateMenu(QMenu *menu); virtual void buildButtons(); + virtual void freeButtons(); virtual bool mousePressEvent(QGraphicsSceneMouseEvent *event); virtual bool mouseMoveEvent(QGraphicsSceneMouseEvent *event); virtual bool mouseReleaseEvent(QGraphicsSceneMouseEvent *event); + +private slots: + void destroyGroup(); + private: DelegateButton *mDestroyGroupButton; }; diff --git a/src/domain/UBSelectionFrame.cpp b/src/domain/UBSelectionFrame.cpp index 993dc80b..35ee9b4f 100644 --- a/src/domain/UBSelectionFrame.cpp +++ b/src/domain/UBSelectionFrame.cpp @@ -29,12 +29,15 @@ #include "domain/UBItem.h" #include "domain/UBGraphicsItemZLevelUndoCommand.h" +#include "domain/UBGraphicsGroupContainerItem.h" #include "board/UBBoardController.h" #include "core/UBSettings.h" #include "core/UBApplication.h" #include "gui/UBResources.h" +#include "gui/UBMainWindow.h" #include "core/UBApplication.h" #include "board/UBBoardView.h" +#include "board/UBDrawingController.h" UBSelectionFrame::UBSelectionFrame() : mThickness(UBSettings::settings()->objectFrameWidth) @@ -44,6 +47,7 @@ UBSelectionFrame::UBSelectionFrame() , mDuplicateButton(0) , mZOrderUpButton(0) , mZOrderDownButton(0) + , mGroupButton(0) , mRotateButton(0) { setLocalBrush(QBrush(UBSettings::paletteColor)); @@ -314,6 +318,15 @@ void UBSelectionFrame::increaseZlevelBottom() // } } +void UBSelectionFrame::groupItems() +{ + UBGraphicsGroupContainerItem *groupItem = ubscene()->createGroup(enclosedGraphicsItems()); + + groupItem->setSelected(true); + UBDrawingController::drawingController()->setStylusTool(UBStylusTool::Selector); + qDebug() << "Grouping items"; +} + void UBSelectionFrame::addSelectionUndo(QList items, UBZLayerController::moveDestination dest){ if(!items.empty()){ qreal topItemLevel = items.at(0)->data(UBGraphicsItemData::ItemOwnZValue).toReal(); @@ -453,7 +466,6 @@ QList UBSelectionFrame::buttonsForFlags(UBGraphicsFlags fls) { if (!mDeleteButton) { mDeleteButton = new DelegateButton(":/images/close.svg", this, 0, Qt::TopLeftSection); - mButtons << mDeleteButton; connect(mDeleteButton, SIGNAL(clicked()), this, SLOT(remove())); } result << mDeleteButton; @@ -466,6 +478,15 @@ QList UBSelectionFrame::buttonsForFlags(UBGraphicsFlags fls) { result << mDuplicateButton; } + if (mEnclosedtems.count() >= 1) { + if (!mGroupButton) { + mGroupButton = new DelegateButton(":/images/plus.svg", this, 0, Qt::TopLeftSection); + mGroupButton->setShowProgressIndicator(false); + connect(mGroupButton, SIGNAL(clicked()), this, SLOT(groupItems())); + } + result << mGroupButton; + } + if (fls | GF_ZORDER_MANIPULATIONS_ALLOWED) { if (!mZOrderUpButton) { mZOrderUpButton = new DelegateButton(":/images/z_layer_up.svg", this, 0, Qt::BottomLeftSection); @@ -498,4 +519,14 @@ QList UBSelectionFrame::buttonsForFlags(UBGraphicsFlags fls) { return result; } +QList UBSelectionFrame::enclosedGraphicsItems() +{ + QList result; + foreach (UBGraphicsItemDelegate *d, mEnclosedtems) { + result << d->delegated(); + } + + return result; +} + diff --git a/src/domain/UBSelectionFrame.h b/src/domain/UBSelectionFrame.h index 1c50661c..3428f4eb 100644 --- a/src/domain/UBSelectionFrame.h +++ b/src/domain/UBSelectionFrame.h @@ -72,6 +72,7 @@ private slots: void increaseZlevelTop(); void increaseZlevelDown(); void increaseZlevelBottom(); + void groupItems(); private: void addSelectionUndo(QList items, UBZLayerController::moveDestination dest); @@ -86,6 +87,8 @@ private: QList sortedByZ(const QList &pItems); QList buttonsForFlags(UBGraphicsFlags fls); + QList enclosedGraphicsItems(); + private: int mThickness; @@ -104,6 +107,7 @@ private: DelegateButton *mDuplicateButton; DelegateButton *mZOrderUpButton; DelegateButton *mZOrderDownButton; + DelegateButton *mGroupButton; DelegateButton *mRotateButton;