From 9b133fa4bc3086b617115465c35ac7410c52fc40 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Mon, 3 Sep 2012 14:55:58 +0200 Subject: [PATCH 01/15] fixed issue 1084 --- src/gui/UBTeacherGuideWidget.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gui/UBTeacherGuideWidget.cpp b/src/gui/UBTeacherGuideWidget.cpp index ca73ec76..77bebf96 100644 --- a/src/gui/UBTeacherGuideWidget.cpp +++ b/src/gui/UBTeacherGuideWidget.cpp @@ -895,9 +895,9 @@ void UBTeacherGuidePageZeroWidget::fillComboBoxes() parametersFile.close(); QStringList licences; - licences << tr("Attribution CC BY") + licences << tr("Attribution-ShareAlike CC BY-SA") + << tr("Attribution CC BY") << tr("Attribution-NoDerivs CC BY-ND") - << tr("Attribution-ShareAlike CC BY-SA") << tr("Attribution-NonCommercial CC BY-NC") << tr("Attribution-NonCommercial-NoDerivs CC BY-NC-ND") << tr("Attribution-NonCommercial-ShareAlike CC BY-NC-SA") @@ -905,9 +905,9 @@ void UBTeacherGuidePageZeroWidget::fillComboBoxes() << tr("Copyright"); mpLicenceBox->addItems(licences); QStringList licenceIconList; - licenceIconList << ":images/licenses/ccby.png" + licenceIconList << ":images/licenses/ccbysa.png" + << ":images/licenses/ccby.png" << ":images/licenses/ccbynd.png" - << ":images/licenses/ccbysa.png" << ":images/licenses/ccbync.png" << ":images/licenses/ccbyncnd.png" << ":images/licenses/ccbyncsa.png"; From 218071207cc7e719e5fc8dba64d197588538d3d7 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Mon, 3 Sep 2012 15:59:49 +0200 Subject: [PATCH 02/15] resizable title page first draft achieved --- src/gui/UBTeacherGuideWidget.cpp | 74 ++++++++++++++++++++------------ src/gui/UBTeacherGuideWidget.h | 7 ++- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/gui/UBTeacherGuideWidget.cpp b/src/gui/UBTeacherGuideWidget.cpp index 77bebf96..a18edc4e 100644 --- a/src/gui/UBTeacherGuideWidget.cpp +++ b/src/gui/UBTeacherGuideWidget.cpp @@ -20,7 +20,7 @@ #include #include #include - +#include #include "UBTeacherGuideWidget.h" @@ -632,8 +632,11 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons QWidget(parent) , mpLayout(NULL) , mpButtonTitleLayout(NULL) + , mpContainerWidgetLayout(NULL) , mpModePushButton(NULL) , mpPageNumberLabel(NULL) + , mpScrollArea(NULL) + , mpContainerWidget(NULL) , mpSessionTitle(NULL) , mpSeparatorSessionTitle(NULL) , mpAuthorsLabel(NULL) @@ -673,6 +676,18 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpPageNumberLabel->setText(tr("Title page")); mpLayout->addWidget(mpPageNumberLabel); + + mpScrollArea = new QScrollArea(); + mpContainerWidget = new QWidget(); + mpContainerWidgetLayout = new QVBoxLayout(); + + + mpLayout->addWidget(mpScrollArea); + mpScrollArea->setWidget(mpContainerWidget); + mpScrollArea->setWidgetResizable(true); + mpContainerWidget->setLayout(mpContainerWidgetLayout); + + mpButtonTitleLayout = new QHBoxLayout(0); mpModePushButton = new QPushButton(this); @@ -687,129 +702,129 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpButtonTitleLayout->addWidget(mpSessionTitle); connect(this, SIGNAL(resized()), mpSessionTitle, SLOT(onTextChanged())); - mpLayout->addLayout(mpButtonTitleLayout); + mpContainerWidgetLayout->addLayout(mpButtonTitleLayout); mpSeparatorSessionTitle = new QFrame(this); mpSeparatorSessionTitle->setFixedHeight(UBTG_SEPARATOR_FIXED_HEIGHT); mpSeparatorSessionTitle->setObjectName("UBTGSeparator"); - mpLayout->addWidget(mpSeparatorSessionTitle); + mpContainerWidgetLayout->addWidget(mpSeparatorSessionTitle); mpAuthorsLabel = new QLabel(this); mpAuthorsLabel->setObjectName("UBTGZeroPageEditionModeTitle"); mpAuthorsLabel->setText(tr("Author(s)")); mpAuthorsLabel->setStyleSheet(chapterStyle); - mpLayout->addWidget(mpAuthorsLabel); + mpContainerWidgetLayout->addWidget(mpAuthorsLabel); mpAuthors = new UBTGAdaptableText(0, this); mpAuthors->setObjectName("UBTGZeroPageInputText"); mpAuthors->setPlaceHolderText(tr("Type authors here ...")); - mpLayout->addWidget(mpAuthors); + mpContainerWidgetLayout->addWidget(mpAuthors); connect(this, SIGNAL(resized()), mpAuthors, SLOT(onTextChanged())); mpCreationLabel = new QLabel(this); mpCreationLabel->setObjectName("UBTGZeroPageDateLabel"); - mpLayout->addWidget(mpCreationLabel); + mpContainerWidgetLayout->addWidget(mpCreationLabel); mpLastModifiedLabel = new QLabel(this); mpLastModifiedLabel->setObjectName("UBTGZeroPageDateLabel"); - mpLayout->addWidget(mpLastModifiedLabel); + mpContainerWidgetLayout->addWidget(mpLastModifiedLabel); mpSeparatorAuthors = new QFrame(this); mpSeparatorAuthors->setFixedHeight(UBTG_SEPARATOR_FIXED_HEIGHT); mpSeparatorAuthors->setObjectName("UBTGSeparator"); - mpLayout->addWidget(mpSeparatorAuthors); + mpContainerWidgetLayout->addWidget(mpSeparatorAuthors); mpObjectivesLabel = new QLabel(this); mpObjectivesLabel->setObjectName("UBTGZeroPageEditionModeTitle"); mpObjectivesLabel->setText(tr("Objective(s)")); mpObjectivesLabel->setStyleSheet(chapterStyle); - mpLayout->addWidget(mpObjectivesLabel); + mpContainerWidgetLayout->addWidget(mpObjectivesLabel); mpObjectives = new UBTGAdaptableText(0, this); mpObjectives->setObjectName("UBTGZeroPageInputText"); mpObjectives->setPlaceHolderText(tr("Type objectives here...")); - mpLayout->addWidget(mpObjectives); + mpContainerWidgetLayout->addWidget(mpObjectives); connect(this, SIGNAL(resized()), mpObjectives, SLOT(onTextChanged())); mpSeparatorObjectives = new QFrame(this); mpSeparatorObjectives->setFixedHeight(UBTG_SEPARATOR_FIXED_HEIGHT); mpSeparatorObjectives->setObjectName("UBTGSeparator"); - mpLayout->addWidget(mpSeparatorObjectives); + mpContainerWidgetLayout->addWidget(mpSeparatorObjectives); mpIndexLabel = new QLabel(this); mpIndexLabel->setObjectName("UBTGZeroPageEditionModeTitle"); mpIndexLabel->setText(tr("Resource indexing")); mpIndexLabel->setStyleSheet(chapterStyle); - mpLayout->addWidget(mpIndexLabel); + mpContainerWidgetLayout->addWidget(mpIndexLabel); mpKeywordsLabel = new QLabel(this); mpKeywordsLabel->setObjectName("UBTGZeroPageItemLabel"); mpKeywordsLabel->setText(tr("Keywords:")); mpKeywordsLabel->setStyleSheet(chapterStyle); - mpLayout->addWidget(mpKeywordsLabel); + mpContainerWidgetLayout->addWidget(mpKeywordsLabel); mpKeywords = new UBTGAdaptableText(0, this); mpKeywords->setPlaceHolderText(tr("Type keywords here ...")); - mpLayout->addWidget(mpKeywords); + mpContainerWidgetLayout->addWidget(mpKeywords); connect(this, SIGNAL(resized()), mpKeywords, SLOT(onTextChanged())); mpSchoolLevelItemLabel = new QLabel(this); mpSchoolLevelItemLabel->setObjectName("UBTGZeroPageItemLabel"); mpSchoolLevelItemLabel->setText(tr("Level:")); mpSchoolLevelItemLabel->setStyleSheet(chapterStyle); - mpLayout->addWidget(mpSchoolLevelItemLabel); + mpContainerWidgetLayout->addWidget(mpSchoolLevelItemLabel); mpSchoolLevelBox = new QComboBox(this); mpSchoolLevelBox->setMinimumHeight(22); mpSchoolLevelBox->setObjectName("DockPaletteWidgetComboBox"); connect(mpSchoolLevelBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(onSchoolLevelChanged(QString))); - mpLayout->addWidget(mpSchoolLevelBox); + mpContainerWidgetLayout->addWidget(mpSchoolLevelBox); mpSchoolLevelValueLabel = new QLabel(this); - mpLayout->addWidget(mpSchoolLevelValueLabel); + mpContainerWidgetLayout->addWidget(mpSchoolLevelValueLabel); mpSchoolSubjectsItemLabel = new QLabel(this); mpSchoolSubjectsItemLabel->setObjectName("UBTGZeroPageItemLabel"); mpSchoolSubjectsItemLabel->setText(tr("Subjects:")); mpSchoolSubjectsItemLabel->setStyleSheet(chapterStyle); - mpLayout->addWidget(mpSchoolSubjectsItemLabel); + mpContainerWidgetLayout->addWidget(mpSchoolSubjectsItemLabel); mpSchoolSubjectsBox = new QComboBox(this); mpSchoolSubjectsBox->setMinimumHeight(22); mpSchoolSubjectsBox->setObjectName("DockPaletteWidgetComboBox"); - mpLayout->addWidget(mpSchoolSubjectsBox); + mpContainerWidgetLayout->addWidget(mpSchoolSubjectsBox); mpSchoolSubjectsValueLabel = new QLabel(this); - mpLayout->addWidget(mpSchoolSubjectsValueLabel); + mpContainerWidgetLayout->addWidget(mpSchoolSubjectsValueLabel); mpSchoolTypeItemLabel = new QLabel(this); mpSchoolTypeItemLabel->setObjectName("UBTGZeroPageItemLabel"); mpSchoolTypeItemLabel->setText(tr("Type:")); mpSchoolTypeItemLabel->setStyleSheet(chapterStyle); - mpLayout->addWidget(mpSchoolTypeItemLabel); + mpContainerWidgetLayout->addWidget(mpSchoolTypeItemLabel); mpSchoolTypeBox = new QComboBox(this); mpSchoolTypeBox->setMinimumHeight(22); mpSchoolTypeBox->setObjectName("DockPaletteWidgetComboBox"); - mpLayout->addWidget(mpSchoolTypeBox); + mpContainerWidgetLayout->addWidget(mpSchoolTypeBox); mpSchoolTypeValueLabel = new QLabel(this); - mpLayout->addWidget(mpSchoolTypeValueLabel); + mpContainerWidgetLayout->addWidget(mpSchoolTypeValueLabel); mpSeparatorIndex = new QFrame(this); mpSeparatorIndex->setFixedHeight(UBTG_SEPARATOR_FIXED_HEIGHT); mpSeparatorIndex->setObjectName("UBTGSeparator"); - mpLayout->addWidget(mpSeparatorIndex); + mpContainerWidgetLayout->addWidget(mpSeparatorIndex); mpLicenceLabel = new QLabel(this); mpLicenceLabel->setObjectName("UBTGZeroPageItemLabel"); mpLicenceLabel->setText(tr("Licence")); mpLicenceLabel->setStyleSheet(chapterStyle); - mpLayout->addWidget(mpLicenceLabel); + mpContainerWidgetLayout->addWidget(mpLicenceLabel); mpLicenceBox = new QComboBox(this); mpLicenceBox->setMinimumHeight(22); mpLicenceBox->setObjectName("DockPaletteWidgetComboBox"); - mpLayout->addWidget(mpLicenceBox); + mpContainerWidgetLayout->addWidget(mpLicenceBox); mpLicenceLayout = new QHBoxLayout(0); mpLicenceIcon = new QLabel(this); mpLicenceLayout->addWidget(mpLicenceIcon); mpLicenceValueLabel = new QLabel(this); mpLicenceLayout->addWidget(mpLicenceValueLabel); - mpLayout->addLayout(mpLicenceLayout); - mpLayout->addStretch(1); + mpContainerWidgetLayout->addLayout(mpLicenceLayout); + mpContainerWidgetLayout->addStretch(1); connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(onActiveSceneChanged())); fillComboBoxes(); @@ -845,6 +860,9 @@ UBTeacherGuidePageZeroWidget::~UBTeacherGuidePageZeroWidget() DELETEPTR(mpModePushButton); DELETEPTR(mpLicenceLayout); DELETEPTR(mpButtonTitleLayout); + DELETEPTR(mpContainerWidgetLayout); + DELETEPTR(mpContainerWidget); + DELETEPTR(mpScrollArea); DELETEPTR(mpLayout); } diff --git a/src/gui/UBTeacherGuideWidget.h b/src/gui/UBTeacherGuideWidget.h index a970807e..60e5ab04 100644 --- a/src/gui/UBTeacherGuideWidget.h +++ b/src/gui/UBTeacherGuideWidget.h @@ -23,7 +23,7 @@ class QVBoxLayout; class QPushButton; class UBDocumentProxy; class UBGraphicsTextItem; - +class QScrollArea; #include "UBTeacherGuideWidgetsTools.h" @@ -155,8 +155,13 @@ private: QVBoxLayout* mpLayout; QHBoxLayout* mpButtonTitleLayout; + QVBoxLayout* mpContainerWidgetLayout; QPushButton* mpModePushButton; QLabel* mpPageNumberLabel; + + QScrollArea* mpScrollArea; + QWidget* mpContainerWidget; + UBTGAdaptableText* mpSessionTitle; QFrame* mpSeparatorSessionTitle; From 5bb5444b61697b9e6161e66ba4a86a25e612a70c Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Tue, 4 Sep 2012 13:23:52 +0200 Subject: [PATCH 03/15] fixed issue for resizing on title page --- src/gui/UBTeacherGuideWidget.cpp | 21 ++++++++++++++------- src/gui/UBTeacherGuideWidget.h | 2 ++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/gui/UBTeacherGuideWidget.cpp b/src/gui/UBTeacherGuideWidget.cpp index a18edc4e..77c692a5 100644 --- a/src/gui/UBTeacherGuideWidget.cpp +++ b/src/gui/UBTeacherGuideWidget.cpp @@ -676,18 +676,16 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpPageNumberLabel->setText(tr("Title page")); mpLayout->addWidget(mpPageNumberLabel); - mpScrollArea = new QScrollArea(); mpContainerWidget = new QWidget(); mpContainerWidgetLayout = new QVBoxLayout(); - mpLayout->addWidget(mpScrollArea); mpScrollArea->setWidget(mpContainerWidget); mpScrollArea->setWidgetResizable(true); + mpScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); mpContainerWidget->setLayout(mpContainerWidgetLayout); - mpButtonTitleLayout = new QHBoxLayout(0); mpModePushButton = new QPushButton(this); @@ -774,6 +772,7 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpContainerWidgetLayout->addWidget(mpSchoolLevelItemLabel); mpSchoolLevelBox = new QComboBox(this); mpSchoolLevelBox->setMinimumHeight(22); + mpSchoolLevelBox->setMinimumWidth(LOWER_RESIZE_WIDTH); mpSchoolLevelBox->setObjectName("DockPaletteWidgetComboBox"); connect(mpSchoolLevelBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(onSchoolLevelChanged(QString))); mpContainerWidgetLayout->addWidget(mpSchoolLevelBox); @@ -787,6 +786,7 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpContainerWidgetLayout->addWidget(mpSchoolSubjectsItemLabel); mpSchoolSubjectsBox = new QComboBox(this); mpSchoolSubjectsBox->setMinimumHeight(22); + mpSchoolSubjectsBox->setMinimumWidth(LOWER_RESIZE_WIDTH); mpSchoolSubjectsBox->setObjectName("DockPaletteWidgetComboBox"); mpContainerWidgetLayout->addWidget(mpSchoolSubjectsBox); mpSchoolSubjectsValueLabel = new QLabel(this); @@ -799,6 +799,7 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpContainerWidgetLayout->addWidget(mpSchoolTypeItemLabel); mpSchoolTypeBox = new QComboBox(this); mpSchoolTypeBox->setMinimumHeight(22); + mpSchoolTypeBox->setMinimumWidth(LOWER_RESIZE_WIDTH); mpSchoolTypeBox->setObjectName("DockPaletteWidgetComboBox"); mpContainerWidgetLayout->addWidget(mpSchoolTypeBox); mpSchoolTypeValueLabel = new QLabel(this); @@ -816,12 +817,15 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpContainerWidgetLayout->addWidget(mpLicenceLabel); mpLicenceBox = new QComboBox(this); mpLicenceBox->setMinimumHeight(22); + mpLicenceBox->setMinimumWidth(LOWER_RESIZE_WIDTH); mpLicenceBox->setObjectName("DockPaletteWidgetComboBox"); mpContainerWidgetLayout->addWidget(mpLicenceBox); mpLicenceLayout = new QHBoxLayout(0); mpLicenceIcon = new QLabel(this); + mpLicenceIcon->setMinimumWidth(LOWER_RESIZE_WIDTH/2); mpLicenceLayout->addWidget(mpLicenceIcon); mpLicenceValueLabel = new QLabel(this); + mpLicenceValueLabel->setMinimumWidth(LOWER_RESIZE_WIDTH/2); mpLicenceLayout->addWidget(mpLicenceValueLabel); mpContainerWidgetLayout->addLayout(mpLicenceLayout); mpContainerWidgetLayout->addStretch(1); @@ -941,7 +945,8 @@ void UBTeacherGuidePageZeroWidget::onSchoolLevelChanged(QString schoolLevel) mpSchoolSubjectsItemLabel->setEnabled(true); mpSchoolSubjectsBox->setEnabled(true); mpSchoolSubjectsBox->addItems(subjects); - } else { + } + else { mpSchoolSubjectsItemLabel->setDisabled(true); mpSchoolSubjectsBox->setDisabled(true); } @@ -1144,10 +1149,12 @@ bool UBTeacherGuidePageZeroWidget::isModified() return result; } -void UBTeacherGuidePageZeroWidget::resizeEvent(QResizeEvent* ev){ +void UBTeacherGuidePageZeroWidget::resizeEvent(QResizeEvent* ev) +{ emit resized(); - - QWidget::resizeEvent(ev); +/* mpScrollArea->resize(width(), height()); + mpContainerWidget->resize(width(), height()); +*/ QWidget::resizeEvent(ev); } /*************************************************************************** diff --git a/src/gui/UBTeacherGuideWidget.h b/src/gui/UBTeacherGuideWidget.h index 60e5ab04..87cd081b 100644 --- a/src/gui/UBTeacherGuideWidget.h +++ b/src/gui/UBTeacherGuideWidget.h @@ -35,6 +35,8 @@ typedef enum tUBTGZeroPageMode_PRESENTATION }tUBTGZeroPageMode; +#define LOWER_RESIZE_WIDTH 50 + /*************************************************************************** * class UBTeacherGuideEditionWidget * ***************************************************************************/ From 8b0e41ea9136b8f091740ac7d9e526d47d7ba963 Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Tue, 4 Sep 2012 17:10:45 +0300 Subject: [PATCH 04/15] Sankore 1107 Crashes fixed Undo command left --- src/api/UBWidgetUniboardAPI.cpp | 2 +- src/board/UBBoardController.cpp | 8 +- src/desktop/UBDesktopAnnotationController.cpp | 2 +- src/domain/UBGraphicsGroupContainerItem.cpp | 5 +- src/domain/UBGraphicsItemDelegate.cpp | 19 ++- src/domain/UBGraphicsItemDelegate.h | 1 + src/domain/UBGraphicsScene.cpp | 132 +++++++----------- src/domain/UBGraphicsScene.h | 12 +- src/domain/UBGraphicsTextItemDelegate.cpp | 9 +- src/domain/UBGraphicsTextItemDelegate.h | 1 + src/domain/UBItem.cpp | 43 ++++++ src/domain/UBItem.h | 1 + src/gui/UBKeyboardPalette.cpp | 5 +- 13 files changed, 140 insertions(+), 100 deletions(-) diff --git a/src/api/UBWidgetUniboardAPI.cpp b/src/api/UBWidgetUniboardAPI.cpp index 0e2a54f1..b86e7aa1 100644 --- a/src/api/UBWidgetUniboardAPI.cpp +++ b/src/api/UBWidgetUniboardAPI.cpp @@ -250,7 +250,7 @@ void UBWidgetUniboardAPI::eraseLineTo(const qreal x, const qreal y, const qreal void UBWidgetUniboardAPI::clear() { if (mScene) - mScene->clearItemsAndAnnotations(); + mScene->clearContent(UBGraphicsScene::clearItemsAndAnnotations); } diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index b7a5ad6b..3fd87fe3 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -683,7 +683,7 @@ void UBBoardController::clearScene() if (mActiveScene) { freezeW3CWidgets(true); - mActiveScene->clearItemsAndAnnotations(); + mActiveScene->clearContent(UBGraphicsScene::clearItemsAndAnnotations); updateActionStates(); } } @@ -694,7 +694,7 @@ void UBBoardController::clearSceneItems() if (mActiveScene) { freezeW3CWidgets(true); - mActiveScene->clearItems(); + mActiveScene->clearContent(UBGraphicsScene::clearItems); updateActionStates(); } } @@ -704,7 +704,7 @@ void UBBoardController::clearSceneAnnotation() { if (mActiveScene) { - mActiveScene->clearAnnotations(); + mActiveScene->clearContent(UBGraphicsScene::clearAnnotations); updateActionStates(); } } @@ -713,7 +713,7 @@ void UBBoardController::clearSceneBackground() { if (mActiveScene) { - mActiveScene->clearBackground(); + mActiveScene->clearContent(UBGraphicsScene::clearBackground); updateActionStates(); } } diff --git a/src/desktop/UBDesktopAnnotationController.cpp b/src/desktop/UBDesktopAnnotationController.cpp index e86dca46..b95b433d 100644 --- a/src/desktop/UBDesktopAnnotationController.cpp +++ b/src/desktop/UBDesktopAnnotationController.cpp @@ -274,7 +274,7 @@ void UBDesktopAnnotationController::eraseDesktopAnnotations() { if (mTransparentDrawingScene) { - mTransparentDrawingScene->clearAnnotations(); + mTransparentDrawingScene->clearContent(UBGraphicsScene::clearAnnotations); } } diff --git a/src/domain/UBGraphicsGroupContainerItem.cpp b/src/domain/UBGraphicsGroupContainerItem.cpp index 95b95af3..818eb88e 100644 --- a/src/domain/UBGraphicsGroupContainerItem.cpp +++ b/src/domain/UBGraphicsGroupContainerItem.cpp @@ -78,7 +78,10 @@ void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item) QTransform newItemTransform(itemTransform); item->setPos(mapFromItem(item, 0, 0)); - item->scene()->removeItem(item); + if (item->scene()) { + item->scene()->removeItem(item); + } + if (corescene()) corescene()->removeItemFromDeletion(item); item->setParentItem(this); diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index 6c0349e4..d5620d12 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -387,12 +387,25 @@ void UBGraphicsItemDelegate::remove(bool canUndo) UBGraphicsScene* scene = dynamic_cast(mDelegated->scene()); if (scene) { - foreach(DelegateButton* button, mButtons) - scene->removeItem(button); +// bool shownOnDisplay = mDelegated->data(UBGraphicsItemData::ItemLayerType).toInt() != UBItemLayerType::Control; +// showHide(shownOnDisplay); +// updateFrame(); +// updateButtons(); + + if (mFrame && !mFrame->scene() && mDelegated->scene()) + { + mDelegated->scene()->addItem(mFrame); + } + mFrame->setAntiScale(mAntiScaleRatio); + mFrame->positionHandles(); + updateButtons(true); + foreach(DelegateButton* button, mButtons) { + scene->removeItem(button); + } scene->removeItem(mFrame); - /* this is performed because when removing delegated from scene while it contains flash content, segfault happens because of QGraphicsScene::removeItem() */ + /* this is performed because when removing delegated from scene while it contains flash content, segfault happens because of QGraphicsScene::removeItem() */ UBGraphicsWebView *mDelegated_casted = dynamic_cast(mDelegated); if (mDelegated_casted) mDelegated_casted->setHtml(QString()); diff --git a/src/domain/UBGraphicsItemDelegate.h b/src/domain/UBGraphicsItemDelegate.h index c782c94b..01ef854b 100644 --- a/src/domain/UBGraphicsItemDelegate.h +++ b/src/domain/UBGraphicsItemDelegate.h @@ -244,6 +244,7 @@ class UBGraphicsItemDelegate : public QObject UBGraphicsToolBarItem* getToolBarItem() const { return mToolBarItem; } qreal antiScaleRatio() const { return mAntiScaleRatio; } + virtual void update() {positionHandles();} signals: void showOnDisplayChanged(bool shown); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index ea3666df..0cdb2ae6 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1064,106 +1064,72 @@ UBItem* UBGraphicsScene::deepCopy() const return sceneDeepCopy(); } -void UBGraphicsScene::clearItemsAndAnnotations() +void UBGraphicsScene::clearContent(clearCase pCase) { - deselectAllItems(); - - QSet emptyList; - QSet removedItems; - - QList sceneItems = items(); - foreach(QGraphicsItem* item, sceneItems) - { - if(!mTools.contains(item) && !isBackgroundObject(item)) - { - removeItem(item); - removedItems << item; - } - } - - // force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint - update(sceneRect()); - - if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented - UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, removedItems, emptyList); - UBApplication::undoStack->push(uc); - } - - setDocumentUpdated(); -} - -void UBGraphicsScene::clearItems() -{ - deselectAllItems(); - - QSet emptyList; QSet removedItems; - QList sceneItems = items(); - foreach(QGraphicsItem* item, sceneItems) - { - bool isGroup = qgraphicsitem_cast(item) != NULL; - bool isPolygon = qgraphicsitem_cast(item) != NULL; - bool isStrokesGroup = qgraphicsitem_cast(item) != NULL; - - if(!isGroup && !isPolygon && !isStrokesGroup && !mTools.contains(item) && !isBackgroundObject(item)) - { - removeItem(item); - removedItems << item; - } - } - - // force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint - update(sceneRect()); - - - if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented - UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, removedItems, emptyList); - UBApplication::undoStack->push(uc); - } + switch (pCase) { + case clearBackground : + removeItem(mBackgroundObject); + removedItems << mBackgroundObject; + break; + + case clearItemsAndAnnotations : + case clearItems : + case clearAnnotations : + foreach(QGraphicsItem* item, items()) { + + bool isGroup = item->type() == UBGraphicsGroupContainerItem::Type; + bool isStrokesGroup = item->type() == UBGraphicsStrokesGroup::Type; + + UBGraphicsGroupContainerItem *itemGroup = item->parentItem() + ? qgraphicsitem_cast(item->parentItem()) + : 0; + UBGraphicsItemDelegate *curDelegate = UBGraphicsItem::Delegate(item); + if (!curDelegate) { + continue; + } - setDocumentUpdated(); -} + bool shouldDelete = false; + switch (static_cast(pCase)) { + case clearAnnotations : + shouldDelete = isStrokesGroup; + break; + case clearItems : + shouldDelete = !isGroup && !isBackgroundObject(item) && !isStrokesGroup; + break; + case clearItemsAndAnnotations: + shouldDelete = !isGroup && !isBackgroundObject(item); + break; + } -void UBGraphicsScene::clearAnnotations() -{ - QSet emptyList; - QSet removedItems; + if(shouldDelete) { + if (itemGroup) { + itemGroup->removeFromGroup(item); + if (itemGroup->childItems().count() == 1) { + itemGroup->destroy(); + } + itemGroup->Delegate()->update(); + } - QList sceneItems = items(); - foreach(QGraphicsItem* item, sceneItems) - { - UBGraphicsStrokesGroup* pi = qgraphicsitem_cast(item); - if (pi) - { - removeItem(item); - removedItems << item; + curDelegate->remove(false); + removedItems << item; + } } + break; } // force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint update(sceneRect()); if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented - UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, removedItems, emptyList); + UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, removedItems, QSet()); UBApplication::undoStack->push(uc); } - setDocumentUpdated(); -} - -void UBGraphicsScene::clearBackground() -{ - if(mBackgroundObject){ - removeItem(mBackgroundObject); - - if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented - UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, mBackgroundObject, NULL); - UBApplication::undoStack->push(uc); - } + if (pCase == clearBackground) { mBackgroundObject = 0; } - update(sceneRect()); setDocumentUpdated(); } @@ -1357,8 +1323,8 @@ UBGraphicsW3CWidgetItem* UBGraphicsScene::addOEmbed(const QUrl& pContentUrl, con UBGraphicsGroupContainerItem *UBGraphicsScene::createGroup(QList items) { UBGraphicsGroupContainerItem *groupItem = new UBGraphicsGroupContainerItem(); - addItem(groupItem); + addItem(groupItem); foreach (QGraphicsItem *item, items) { if (item->type() == UBGraphicsGroupContainerItem::Type) { QList childItems = item->childItems(); diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 6f8c8def..0dedb9c1 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -101,6 +101,13 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem public: + enum clearCase { + clearItemsAndAnnotations = 0 + , clearAnnotations + , clearItems + , clearBackground + }; + // tmp stub for divide addings scene objects from undo mechanism implementation void setURStackEnable(bool set = true) {enableUndoRedoStack = set;} bool isURStackIsEnabled(){ return enableUndoRedoStack;} @@ -114,10 +121,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem UBGraphicsScene* sceneDeepCopy() const; - void clearItemsAndAnnotations(); - void clearItems(); - void clearAnnotations(); - void clearBackground(); + void clearContent(clearCase pCase = clearItemsAndAnnotations); bool inputDevicePress(const QPointF& scenePos, const qreal& pressure = 1.0); bool inputDeviceMove(const QPointF& scenePos, const qreal& pressure = 1.0); diff --git a/src/domain/UBGraphicsTextItemDelegate.cpp b/src/domain/UBGraphicsTextItemDelegate.cpp index 6e7e730e..9f7b5fdb 100644 --- a/src/domain/UBGraphicsTextItemDelegate.cpp +++ b/src/domain/UBGraphicsTextItemDelegate.cpp @@ -263,6 +263,11 @@ void UBGraphicsTextItemDelegate::setEditable(bool editable) mDelegated->setData(UBGraphicsItemData::ItemEditable, QVariant(false)); } } +void UBGraphicsTextItemDelegate::remove(bool canUndo) +{ + UBGraphicsItemDelegate::remove(canUndo); +} + bool UBGraphicsTextItemDelegate::isEditable() { return mDelegated->data(UBGraphicsItemData::ItemEditable).toBool(); @@ -419,8 +424,8 @@ QVariant UBGraphicsTextItemDelegate::itemChange(QGraphicsItem::GraphicsItemChang QTextCursor c = delegated()->textCursor(); if (c.hasSelection()) { - c.clearSelection(); - delegated()->setTextCursor(c); + c.clearSelection(); + delegated()->setTextCursor(c); } } } diff --git a/src/domain/UBGraphicsTextItemDelegate.h b/src/domain/UBGraphicsTextItemDelegate.h index 26b3ba9b..2cf6f447 100644 --- a/src/domain/UBGraphicsTextItemDelegate.h +++ b/src/domain/UBGraphicsTextItemDelegate.h @@ -46,6 +46,7 @@ class UBGraphicsTextItemDelegate : public UBGraphicsItemDelegate public slots: void contentsChanged(); virtual void setEditable(bool); + virtual void remove(bool canUndo); protected: virtual void buildButtons(); diff --git a/src/domain/UBItem.cpp b/src/domain/UBItem.cpp index 9d999a94..10d3d6ce 100644 --- a/src/domain/UBItem.cpp +++ b/src/domain/UBItem.cpp @@ -17,6 +17,15 @@ #include "core/memcheck.h" +#include "domain/UBGraphicsPixmapItem.h" +#include "domain/UBGraphicsTextItem.h" +#include "domain/UBGraphicsSvgItem.h" +#include "domain/UBGraphicsMediaItem.h" +#include "domain/UBGraphicsStrokesGroup.h" +#include "domain/UBGraphicsGroupContainerItem.h" +#include "domain/UBGraphicsWidgetItem.h" +#include "tools/UBGraphicsCurtainItem.h" + UBItem::UBItem() : mUuid(QUuid()) , mRenderingQuality(UBItem::RenderingQualityNormal) @@ -44,3 +53,37 @@ bool UBGraphicsItem::isRotatable(QGraphicsItem *item) { return item->data(UBGraphicsItemData::ItemRotatable).toBool(); } + +UBGraphicsItemDelegate *UBGraphicsItem::Delegate(QGraphicsItem *pItem) +{ + UBGraphicsItemDelegate *result = 0; + + switch (static_cast(pItem->type())) { + case UBGraphicsPixmapItem::Type : + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsTextItem::Type : + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsSvgItem::Type : + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsMediaItem::Type: + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsStrokesGroup::Type : + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsGroupContainerItem::Type : + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsWidgetItem::Type : + result = (static_cast(pItem))->Delegate(); + break; + case UBGraphicsCurtainItem::Type : + result = (static_cast(pItem))->Delegate(); + break; + } + + return result; +} diff --git a/src/domain/UBItem.h b/src/domain/UBItem.h index 99c3e6a6..ca8a0f3b 100644 --- a/src/domain/UBItem.h +++ b/src/domain/UBItem.h @@ -108,6 +108,7 @@ public: static bool isRotatable(QGraphicsItem *item); static bool isFlippable(QGraphicsItem *item); + static UBGraphicsItemDelegate *Delegate(QGraphicsItem *pItem); virtual UBGraphicsItemDelegate *Delegate() const = 0; virtual void remove() = 0; diff --git a/src/gui/UBKeyboardPalette.cpp b/src/gui/UBKeyboardPalette.cpp index 3f1fe242..2a496526 100644 --- a/src/gui/UBKeyboardPalette.cpp +++ b/src/gui/UBKeyboardPalette.cpp @@ -60,7 +60,10 @@ UBKeyboardPalette::UBKeyboardPalette(QWidget *parent) createCtrlButtons(); nCurrentLocale = UBSettings::settings()->KeyboardLocale->get().toInt(); - setInput(locales[nCurrentLocale]); + if (nCurrentLocale < 0 || nCurrentLocale >= nLocalesCount) + nCurrentLocale = 0; + if (locales!=NULL) + setInput(locales[nCurrentLocale]); setContentsMargins( 22, 22, 22, 22 ); From 931e099e5d4afedfaeb128a6d7d05e596e17f302 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Wed, 5 Sep 2012 11:13:54 +0200 Subject: [PATCH 05/15] added toque on page thumbnail depending if the teacherguide is filled out or not --- resources/images/toque.png | Bin 0 -> 3423 bytes resources/sankore.qrc | 1 + src/document/UBDocumentController.cpp | 23 ++++++----------- src/gui/UBDocumentNavigator.cpp | 34 +++++++++++++++++++++----- src/gui/UBTeacherGuideWidget.cpp | 4 +-- 5 files changed, 38 insertions(+), 24 deletions(-) create mode 100644 resources/images/toque.png diff --git a/resources/images/toque.png b/resources/images/toque.png new file mode 100644 index 0000000000000000000000000000000000000000..a976e147507342f478265ea2db06db82baec4d84 GIT binary patch literal 3423 zcmV-l4WROgP)Px#24YJ`L;(K){{a7>y{D4^000SaNLh0L01FcU01FcV0GgZ_00007bV*G`2iyq- z1~woi87a5`01V$rL_t(|+U=X!avN8E#=p~jdPjpG36i2H3le3CBDGUgG?HaYlh~@* z)k9)Q5^*!2@!iejFACh`P#^2M z{u!PR_pgBSBH;2zUDE-ybi9SyG5{*Woab10_|5;aN4LI! z@7hI>b_!hn5M>pKwsT0d{ba`gZaX+*e&+XgzWVg%L%sLlx%RRXDjm4|oFFNv-+LI% zCoUe4wb(#Kf}5EbVh?Wq3H@EykvsSA11UYY<;U&=C$aDN8${NsDx&}%OZKpDzx)K_ zgS|y3UTI@8`2f!cAF^0O0{f1>j;i{-q%7ci?sl@?``0iw&|T5MzCRYGhVkI5-yznJ zU=90@p?=>{QW9`IcRShbFF!$gZu&<9YqgP{9)U44im~3CY){*H)a^Y&wjG>nXV7)y z3hTOY1)gK!Wg4!P#=zY_VdP;a+x2QY8k$cLUXZp1Ek^!82 zavM|6zGXFgTG8<8nN$NO1T!+yjQ$Dvj?k|J2Q906PvdynQxA zYhuYAXBG&qKjiVn9SY0Mw@u{*CW;bb)zwf`75#m^=;`i;=Xq$q_#S9=T@yq}f#=#_ z3}B2wQBp$yY}XqeBZUvcdwHrAKyYIJ-e&~$t4QU^I+RHY}+n6vHbIujrvlPA5jP{ zog#SW9EyPT3=v#=z~R~ht|U$V_vi9|FFg`OB0BVF6bwLbPY;F$lZEx_u{e&Ly^KRA zE)Y>xSE?h)$G6#|n^#r^7=|HC(}Zo?8-mkhf_Goz@Xk2`ZJ8w2JxK6}|0C!b;!3KH ztOrhuL=cNr!!XiF4h&#oV!Q}g`^EQg@Wci3LbB4>(}%3@{#8tkJT0=Y9KZm!ZNsuG zFvf}&R9{W-Pk+bbZ`z81b#?()ZV?PWFORJB{W+fJq3coT(I{q9DGUuIkxHcs>uub3 z80{C|Lu2AF*_0kPHTsnG-@A&@rw@zfIWG5kmSw?l9K@>_e(@%cpSCX*TNwxVwg>pH ztH8`cdG)yb9HkVhra{-En3{Ty z0OU9h|MCw84(|;Lz&`();g2^NEVnX*OiBgl(I_NI!qoFgjE;`Nah8A`I&lH*7vK9h z5{v)ijwryH^y~-y_pW}Je0&?8yY$8X`U?v!uLQXNl;S@=2{CW@6`=r2k_1hQKoA8? zjE`e{d<@xawvZu@<^ui;1KYG7r$uW%I(6y&kB**u8~4BZm<{&cFRJ%Orzv<*K`fSq zWm$zqmZJvKA{qc-WONwQQ&UB;dVgyNF1-6|BFbuM6<|S95Q}Q4t*u5XH4C;_%QD80 z&1S)I9HP-^Ar5+;TM}ThEJKUvaBK^sBO{oZnO+uFIEbPIK@btqW7sUTE$=x5S+7v8 zFqX5ry!C})h%gLu>0Z;IX&M~If#Gf6a~JY z>qyuSG{L+T3xWvKG%z|k3g7pZHRTk7Ac5!kHCs4;Sz;?GIL|gd+~_^N?_*(M9+`{@ zO^ZO5Yy>ue}0@H`JiQ6Y*V=I7@yH#dtQ$V*YVqE-+DaNOF! zL{WsMY2Y{xvlB^H)3~3M6r4FX3C2PQg0OKc3<9Ln3ouOss;WU%)kT0ld_N08pwRUw z!Z3v6*ef!zAP7)Z4TKOZEX*UFP9qG1BA29;f)H*^V3bm5ng&UdAj>jzU56|QWwAK$ zJP%b>P+eUEp0@$`>;6v|hR9@0SXKtIEJIZ_@H`LC^Wk|u1VKO~qJuF8*LA^h1d5V_ zJU2HB!$>cWaNv1n39*=!nuAV88Nh@ynNI-Q5M zmOCyF{IV<;x#YS(T6${J;5M~ynXU`rq zH8nxgv={#DY&MHbCWCZ(0YShvES3o&5JeHuXcVfdu4`p0yfq9Fcvk5w&YqtvJil=G z`O4TLggCk1z@Hz)77J7bK@h+&3^<2Vi+&!ej8NNLLv0I1)8k{s9)5ehYSZAV z(YIFn2f_h_@CdRVF1>jH$KQF44EJ}j$)P?>4EDm9p8;bGj4@D35r$!r6qLWlBj188 z--~cvx8RETu%K7h;ZVzI95`|Ydz#ybq-Z-H3N{T+CNmo-4=lGQ;XH$=zlm3mog=Rv zJD0N*$3p7)2%8w}h3i;IO$>nn7*F;TfaX6V|0v2T;*AL~#!%OofGDeIYHmYaW1=LW zwgnu81qCzfv@;yC*${*PyuH#gMOj5-qJ=ajTJU2XbaU}-gstDw9Gci~EhUb;KyHhpV3g@uFo9cu_Xb80Zl^@E=0V_`mxc{7By>o>^M{_>@~-EhnI zimages/teacherGuide/pencil.svg images/duplicateDisabled.svg images/teacherGuide/flash_24x24.svg + images/toque.png diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp index 4be9ee0f..24d76fd6 100755 --- a/src/document/UBDocumentController.cpp +++ b/src/document/UBDocumentController.cpp @@ -363,25 +363,18 @@ void UBDocumentController::setupViews() connect(mDocumentUI->thumbnailWidget, SIGNAL(sceneDropped(UBDocumentProxy*, int, int)), this, SLOT(moveSceneToIndex ( UBDocumentProxy*, int, int))); connect(mDocumentUI->thumbnailWidget, SIGNAL(resized()), this, SLOT(thumbnailViewResized())); - connect(mDocumentUI->thumbnailWidget, SIGNAL(mouseDoubleClick(QGraphicsItem*, int)), - this, SLOT(pageDoubleClicked(QGraphicsItem*, int))); - connect(mDocumentUI->thumbnailWidget, SIGNAL(mouseClick(QGraphicsItem*, int)), - this, SLOT(pageClicked(QGraphicsItem*, int))); + connect(mDocumentUI->thumbnailWidget, SIGNAL(mouseDoubleClick(QGraphicsItem*, int)), this, SLOT(pageDoubleClicked(QGraphicsItem*, int))); + connect(mDocumentUI->thumbnailWidget, SIGNAL(mouseClick(QGraphicsItem*, int)), this, SLOT(pageClicked(QGraphicsItem*, int))); - connect(mDocumentUI->thumbnailWidget->scene(), SIGNAL(selectionChanged()), - this, SLOT(pageSelectionChanged())); + connect(mDocumentUI->thumbnailWidget->scene(), SIGNAL(selectionChanged()), this, SLOT(pageSelectionChanged())); - connect(UBPersistenceManager::persistenceManager(), SIGNAL(documentCreated(UBDocumentProxy*)), - this, SLOT(addDocumentInTree(UBDocumentProxy*))); + connect(UBPersistenceManager::persistenceManager(), SIGNAL(documentCreated(UBDocumentProxy*)), this, SLOT(addDocumentInTree(UBDocumentProxy*))); - connect(UBPersistenceManager::persistenceManager(), SIGNAL(documentMetadataChanged(UBDocumentProxy*)), - this, SLOT(updateDocumentInTree(UBDocumentProxy*))); + connect(UBPersistenceManager::persistenceManager(), SIGNAL(documentMetadataChanged(UBDocumentProxy*)), this, SLOT(updateDocumentInTree(UBDocumentProxy*))); - connect(UBPersistenceManager::persistenceManager(), SIGNAL(documentSceneCreated(UBDocumentProxy*, int)), - this, SLOT(documentSceneChanged(UBDocumentProxy*, int))); + connect(UBPersistenceManager::persistenceManager(), SIGNAL(documentSceneCreated(UBDocumentProxy*, int)), this, SLOT(documentSceneChanged(UBDocumentProxy*, int))); - connect(UBPersistenceManager::persistenceManager(), SIGNAL(documentSceneWillBeDeleted(UBDocumentProxy*, int)), - this, SLOT(documentSceneChanged(UBDocumentProxy*, int))); + connect(UBPersistenceManager::persistenceManager(), SIGNAL(documentSceneWillBeDeleted(UBDocumentProxy*, int)), this, SLOT(documentSceneChanged(UBDocumentProxy*, int))); mDocumentUI->thumbnailWidget->setBackgroundBrush(UBSettings::documentViewLightColor); @@ -996,7 +989,7 @@ void UBDocumentController::addFolderOfImages() if (importedImageNumber == 0) { - showMessage(tr("Folder does not contain any image files!")); + showMessage(tr("Folder does not contain any image files")); UBApplication::applicationController->showDocument(); } else diff --git a/src/gui/UBDocumentNavigator.cpp b/src/gui/UBDocumentNavigator.cpp index e2de9970..90b45615 100644 --- a/src/gui/UBDocumentNavigator.cpp +++ b/src/gui/UBDocumentNavigator.cpp @@ -69,6 +69,9 @@ UBDocumentNavigator::~UBDocumentNavigator() } } +#include "gui/UBDockTeacherGuideWidget.h" +#include "gui/UBTeacherGuideWidget.h" + /** * \brief Generate the thumbnails */ @@ -84,10 +87,31 @@ void UBDocumentNavigator::generateThumbnails(UBDocumentContainer* source) for(int i = 0; i < source->selectedDocument()->pageCount(); i++) { + const QPixmap* pix = source->pageAt(i); - UBSceneThumbnailNavigPixmap* pixmapItem = new UBSceneThumbnailNavigPixmap(*pix, source->selectedDocument(), i); + QPixmap result(pix->width(),pix->height()); int pageIndex = UBDocumentContainer::pageFromSceneIndex(i); - QString label = pageIndex == 0 ? tr("Title page") : tr("Page %0").arg(pageIndex); + + QPainter composePainter; + composePainter.begin(&result); + composePainter.drawPixmap(QPoint(0,0),*pix); + + if(pageIndex == UBApplication::boardController->currentPage() && + ((pageIndex == 0 && UBSettings::settings()->teacherGuidePageZeroActivated->get().toBool()) || + (pageIndex && UBSettings::settings()->teacherGuideLessonPagesActivated->get().toBool())) + ) { + if(UBApplication::boardController->paletteManager()->teacherGuideDockWidget()->teacherGuideWidget()->isModified()){ + QPixmap toque(":images/toque.png"); + composePainter.setOpacity(0.6); + composePainter.drawPixmap(QPoint(pix->width() - toque.width(),0),toque); + } + } + + composePainter.end(); + + UBSceneThumbnailNavigPixmap* pixmapItem = new UBSceneThumbnailNavigPixmap(result, source->selectedDocument(), i); + + QString label = pageIndex == 0 ? tr("Title page") : tr("Page %0").arg(pageIndex); UBThumbnailTextItem *labelItem = new UBThumbnailTextItem(label); UBImgTextThumbnailElement thumbWithText(pixmapItem, labelItem); @@ -104,7 +128,7 @@ void UBDocumentNavigator::generateThumbnails(UBDocumentContainer* source) void UBDocumentNavigator::onScrollToSelectedPage(int index) { - qDebug() << "Selection in widet: " << index; + qDebug() << "Selection in widget: " << index; int c = 0; foreach(UBImgTextThumbnailElement el, mThumbsWithLabels) { @@ -118,7 +142,6 @@ void UBDocumentNavigator::onScrollToSelectedPage(int index) } c++; } -// centerOn(mThumbsWithLabels[index].getThumbnail()); } /** @@ -131,8 +154,7 @@ void UBDocumentNavigator::updateSpecificThumbnail(int iPage) //UBGraphicsScene* pScene = UBApplication::boardController->activeScene(); const QPixmap* pix = UBApplication::boardController->pageAt(iPage); - UBSceneThumbnailNavigPixmap* newItem = new UBSceneThumbnailNavigPixmap(*pix, - UBApplication::boardController->selectedDocument(), iPage); + UBSceneThumbnailNavigPixmap* newItem = new UBSceneThumbnailNavigPixmap(*pix, UBApplication::boardController->selectedDocument(), iPage); // Get the old thumbnail UBSceneThumbnailNavigPixmap* oldItem = mThumbsWithLabels.at(iPage).getThumbnail(); diff --git a/src/gui/UBTeacherGuideWidget.cpp b/src/gui/UBTeacherGuideWidget.cpp index 77c692a5..ffe11cbd 100644 --- a/src/gui/UBTeacherGuideWidget.cpp +++ b/src/gui/UBTeacherGuideWidget.cpp @@ -1152,9 +1152,7 @@ bool UBTeacherGuidePageZeroWidget::isModified() void UBTeacherGuidePageZeroWidget::resizeEvent(QResizeEvent* ev) { emit resized(); -/* mpScrollArea->resize(width(), height()); - mpContainerWidget->resize(width(), height()); -*/ QWidget::resizeEvent(ev); + QWidget::resizeEvent(ev); } /*************************************************************************** From 8f1f0d9cbb942493e2555ab9218708bae6a7693b Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Thu, 6 Sep 2012 13:07:49 +0300 Subject: [PATCH 06/15] SANKORE-1026 Navigation palette: thumbnails isn't refeshed after application added to the page --- src/api/UBWidgetMessageAPI.cpp | 2 - src/domain/UBGraphicsItemDelegate.cpp | 2 +- src/domain/UBGraphicsMediaItem.cpp | 1 + src/domain/UBGraphicsMediaItem.h | 1 - src/domain/UBGraphicsPDFItem.cpp | 2 + src/domain/UBGraphicsPDFItem.h | 1 - src/domain/UBGraphicsScene.cpp | 4 +- src/domain/UBGraphicsWebView.cpp | 152 -------------------------- src/domain/UBGraphicsWebView.h | 61 ----------- src/domain/UBGraphicsWidgetItem.cpp | 143 +++++++++++++++--------- src/domain/UBGraphicsWidgetItem.h | 20 ++-- src/domain/domain.pri | 2 - 12 files changed, 108 insertions(+), 283 deletions(-) delete mode 100644 src/domain/UBGraphicsWebView.cpp delete mode 100644 src/domain/UBGraphicsWebView.h diff --git a/src/api/UBWidgetMessageAPI.cpp b/src/api/UBWidgetMessageAPI.cpp index 306f2702..f145fba3 100644 --- a/src/api/UBWidgetMessageAPI.cpp +++ b/src/api/UBWidgetMessageAPI.cpp @@ -17,8 +17,6 @@ #include "core/UBApplication.h" -#include "domain/UBGraphicsWebView.h" - #include "core/memcheck.h" UBWidgetMessageAPI::UBWidgetMessageAPI(UBGraphicsWidgetItem *graphicsWidgetItem, QObject *parent) diff --git a/src/domain/UBGraphicsItemDelegate.cpp b/src/domain/UBGraphicsItemDelegate.cpp index d5620d12..45b626ef 100644 --- a/src/domain/UBGraphicsItemDelegate.cpp +++ b/src/domain/UBGraphicsItemDelegate.cpp @@ -406,7 +406,7 @@ void UBGraphicsItemDelegate::remove(bool canUndo) scene->removeItem(mFrame); /* this is performed because when removing delegated from scene while it contains flash content, segfault happens because of QGraphicsScene::removeItem() */ - UBGraphicsWebView *mDelegated_casted = dynamic_cast(mDelegated); + UBGraphicsWidgetItem *mDelegated_casted = dynamic_cast(mDelegated); if (mDelegated_casted) mDelegated_casted->setHtml(QString()); diff --git a/src/domain/UBGraphicsMediaItem.cpp b/src/domain/UBGraphicsMediaItem.cpp index 76bbbd53..d1e97583 100644 --- a/src/domain/UBGraphicsMediaItem.cpp +++ b/src/domain/UBGraphicsMediaItem.cpp @@ -351,3 +351,4 @@ void UBGraphicsMediaItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) event->accept(); } + diff --git a/src/domain/UBGraphicsMediaItem.h b/src/domain/UBGraphicsMediaItem.h index 308fbea9..b52c0ab6 100644 --- a/src/domain/UBGraphicsMediaItem.h +++ b/src/domain/UBGraphicsMediaItem.h @@ -112,7 +112,6 @@ protected: virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - virtual void clearSource(); Phonon::MediaObject *mMediaObject; diff --git a/src/domain/UBGraphicsPDFItem.cpp b/src/domain/UBGraphicsPDFItem.cpp index f918b3d2..425ab749 100644 --- a/src/domain/UBGraphicsPDFItem.cpp +++ b/src/domain/UBGraphicsPDFItem.cpp @@ -155,3 +155,5 @@ UBGraphicsPixmapItem* UBGraphicsPDFItem::toPixmapItem() const return pixmapItem; } + + diff --git a/src/domain/UBGraphicsPDFItem.h b/src/domain/UBGraphicsPDFItem.h index ac55190e..b41b15ec 100644 --- a/src/domain/UBGraphicsPDFItem.h +++ b/src/domain/UBGraphicsPDFItem.h @@ -63,7 +63,6 @@ class UBGraphicsPDFItem: public GraphicsPDFItem, public UBItem, public UBGraphic virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); -// UBGraphicsItemDelegate* mDelegate; }; #endif /* UBGRAPHICSPDFITEM_H_ */ diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 0cdb2ae6..f244bae8 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -2041,8 +2041,8 @@ void UBGraphicsScene::drawItems (QPainter * painter, int numItems, { if (!mTools.contains(rootItem(items[i]))) { - UBGraphicsPDFItem *pdfItem = qgraphicsitem_cast (items[i]); - if(!pdfItem || mRenderingContext == NonScreen) + bool isPdfItem = qgraphicsitem_cast (items[i]) != NULL; + if(!isPdfItem || mRenderingContext == NonScreen) { itemsFiltered[count] = items[i]; optionsFiltered[count] = options[i]; diff --git a/src/domain/UBGraphicsWebView.cpp b/src/domain/UBGraphicsWebView.cpp deleted file mode 100644 index cfc92dc3..00000000 --- a/src/domain/UBGraphicsWebView.cpp +++ /dev/null @@ -1,152 +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 "UBGraphicsWebView.h" -#include "UBGraphicsScene.h" -#include "UBGraphicsItemDelegate.h" -#include "UBGraphicsDelegateFrame.h" - -#include "core/memcheck.h" - -UBGraphicsWebView::UBGraphicsWebView(QGraphicsItem* parent) - : QGraphicsWebView(parent) -{ - setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); - - mDelegate = new UBGraphicsItemDelegate(this, 0, true); - mDelegate->init(); - - setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); - - QGraphicsWebView::setAcceptHoverEvents(true); -} - - -UBGraphicsWebView::~UBGraphicsWebView() -{ - if (mDelegate) - delete mDelegate; -} - - -QVariant UBGraphicsWebView::itemChange(GraphicsItemChange change, const QVariant &value) -{ - if ((change == QGraphicsItem::ItemSelectedHasChanged) && scene()) { - if (isSelected()) - scene()->setActiveWindow(this); - else - if(scene()->activeWindow() == this) - scene()->setActiveWindow(0); - } - - QVariant newValue = mDelegate->itemChange(change, value); - return QGraphicsWebView::itemChange(change, newValue); -} - -void UBGraphicsWebView::setUuid(const QUuid &pUuid) -{ - UBItem::setUuid(pUuid); - setData(UBGraphicsItemData::ItemUuid, QVariant(pUuid)); //store item uuid inside the QGraphicsItem to fast operations with Items on the scene -} - -void UBGraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) -{ - if (!mDelegate->mousePressEvent(event)) - setSelected(true); /* forcing selection */ - - QGraphicsWebView::mousePressEvent(event); -} - - -void UBGraphicsWebView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) -{ - if (!mDelegate->mouseMoveEvent(event)) - QGraphicsWebView::mouseMoveEvent(event); -} - - -void UBGraphicsWebView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - mDelegate->mouseReleaseEvent(event); - QGraphicsWebView::mouseReleaseEvent(event); -} - -void UBGraphicsWebView::wheelEvent(QGraphicsSceneWheelEvent *event) -{ - if (mDelegate->weelEvent(event)) - { - QGraphicsWebView::wheelEvent(event); - event->accept(); - } -} - -void UBGraphicsWebView::hoverEnterEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event) - /* NOOP */ -} -void UBGraphicsWebView::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event) - /* NOOP */ -} - -void UBGraphicsWebView::setDelegate(UBGraphicsItemDelegate* pDelegate) -{ - if (mDelegate) - delete mDelegate; - - mDelegate = pDelegate; -} - - -void UBGraphicsWebView::resize(qreal w, qreal h) -{ - UBGraphicsWebView::resize(QSizeF(w, h)); -} - - -void UBGraphicsWebView::resize(const QSizeF & pSize) -{ - if (pSize != size()) { - QGraphicsWebView::setMaximumSize(pSize.width(), pSize.height()); - QGraphicsWebView::resize(pSize.width(), pSize.height()); - if (mDelegate) - mDelegate->positionHandles(); - if (scene()) - scene()->setModified(true); - } -} - -QSizeF UBGraphicsWebView::size() const -{ - return QGraphicsWebView::size(); -} - - -UBGraphicsScene* UBGraphicsWebView::scene() -{ - return static_cast(QGraphicsItem::scene()); -} - - -void UBGraphicsWebView::remove() -{ - if (mDelegate) - mDelegate->remove(true); -} diff --git a/src/domain/UBGraphicsWebView.h b/src/domain/UBGraphicsWebView.h deleted file mode 100644 index 45a2db7a..00000000 --- a/src/domain/UBGraphicsWebView.h +++ /dev/null @@ -1,61 +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 UBGRAPHICSWEBVIEW_H_ -#define UBGRAPHICSWEBVIEW_H_ - -#include -#include - -#include "UBItem.h" -#include "UBResizableGraphicsItem.h" - -class UBGraphicsItemDelegate; - -class UBGraphicsWebView: public QGraphicsWebView, public UBItem, public UBResizableGraphicsItem, public UBGraphicsItem -{ - public: - UBGraphicsWebView(QGraphicsItem* parent = 0); - virtual ~UBGraphicsWebView(); - - virtual void resize(qreal w, qreal h); - virtual void resize(const QSizeF & size); - - virtual QSizeF size() const; - - void setDelegate(UBGraphicsItemDelegate* pDelegate); - - virtual UBGraphicsScene* scene(); - - virtual void remove(); - - virtual UBGraphicsItemDelegate* Delegate() const { return mDelegate;} - - virtual void clearSource(){;} - virtual void setUuid(const QUuid &pUuid); - - protected: - - virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); - virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); - virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event); - virtual void wheelEvent(QGraphicsSceneWheelEvent *event); - virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event); - virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); - virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); - -}; - -#endif /* UBGRAPHICSWEBVIEW_H_ */ diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index 35bb32ad..c3aed833 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -45,7 +45,7 @@ bool UBGraphicsWidgetItem::sInlineJavaScriptLoaded = false; QStringList UBGraphicsWidgetItem::sInlineJavaScripts; UBGraphicsWidgetItem::UBGraphicsWidgetItem(const QUrl &pWidgetUrl, QGraphicsItem *parent) - : UBGraphicsWebView(parent) + : QGraphicsWebView(parent) , mInitialLoadDone(false) , mIsFreezable(true) , mIsResizable(false) @@ -58,7 +58,7 @@ UBGraphicsWidgetItem::UBGraphicsWidgetItem(const QUrl &pWidgetUrl, QGraphicsItem , mShouldMoveWidget(false) , mUniboardAPI(0) { - setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly + setData(UBGraphicsItemData::ItemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly QGraphicsWebView::setPage(new UBWebPage(this)); QGraphicsWebView::settings()->setAttribute(QWebSettings::JavaEnabled, true); @@ -84,9 +84,11 @@ UBGraphicsWidgetItem::UBGraphicsWidgetItem(const QUrl &pWidgetUrl, QGraphicsItem viewPalette.setBrush(QPalette::Window, QBrush(Qt::transparent)); setPalette(viewPalette); - UBGraphicsWidgetItemDelegate* delegate = new UBGraphicsWidgetItemDelegate(this); - delegate->init(); - setDelegate(delegate); + mDelegate = new UBGraphicsWidgetItemDelegate(this); + mDelegate->init(); + + setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); + QGraphicsWebView::setAcceptHoverEvents(true); } @@ -97,7 +99,7 @@ UBGraphicsWidgetItem::~UBGraphicsWidgetItem() void UBGraphicsWidgetItem::initialize() { - UBGraphicsWebView::setMinimumSize(nominalSize()); + setMinimumSize(nominalSize()); setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); // Necessary to set if we want z value to be assigned correctly if (mDelegate && mDelegate->frame() && resizable()) @@ -260,11 +262,6 @@ void UBGraphicsWidgetItem::removeAllDatastoreEntries() mDatastore.clear(); } -UBGraphicsItemDelegate* UBGraphicsWidgetItem::Delegate() const -{ - return mDelegate; -} - void UBGraphicsWidgetItem::remove() { if (mDelegate) @@ -360,6 +357,8 @@ QPixmap UBGraphicsWidgetItem::takeSnapshot() mIsTakingSnapshot = false; + mSnapshot = pixmap; + return pixmap; } @@ -502,7 +501,7 @@ bool UBGraphicsWidgetItem::event(QEvent *event) else if (event->type() == QEvent::ShortcutOverride) event->accept(); - return UBGraphicsWebView::event(event); + return QGraphicsWebView::event(event); } void UBGraphicsWidgetItem::dropEvent(QGraphicsSceneDragDropEvent *event) @@ -513,7 +512,10 @@ void UBGraphicsWidgetItem::dropEvent(QGraphicsSceneDragDropEvent *event) void UBGraphicsWidgetItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - UBGraphicsWebView::mousePressEvent(event); + if (!mDelegate->mousePressEvent(event)) + setSelected(true); /* forcing selection */ + + QGraphicsWebView::mousePressEvent(event); // did webkit consume the mouse press ? mShouldMoveWidget = !event->isAccepted() && (event->buttons() & Qt::LeftButton); @@ -527,24 +529,19 @@ void UBGraphicsWidgetItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { mShouldMoveWidget = false; - UBGraphicsWebView::mouseReleaseEvent(event); + mDelegate->mouseReleaseEvent(event); + QGraphicsWebView::mouseReleaseEvent(event); } void UBGraphicsWidgetItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { sendJSEnterEvent(); mDelegate->hoverEnterEvent(event); - UBGraphicsWebView::hoverEnterEvent(event); } void UBGraphicsWidgetItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { sendJSLeaveEvent(); mDelegate->hoverLeaveEvent(event); - UBGraphicsWebView::hoverLeaveEvent(event); -} -void UBGraphicsWidgetItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) -{ - UBGraphicsWebView::hoverMoveEvent(event); } void UBGraphicsWidgetItem::sendJSEnterEvent() @@ -572,33 +569,40 @@ void UBGraphicsWidgetItem::injectInlineJavaScript() void UBGraphicsWidgetItem::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { - if (mIsFrozen) - painter->drawPixmap(0, 0, mSnapshot); + if (scene()->renderingContext() != UBGraphicsScene::Screen) + { + painter->drawPixmap(0, 0, snapshot()); + } else - UBGraphicsWebView::paint(painter, option, widget); - if (!mInitialLoadDone || mLoadIsErronous) { - QString message; + { + if (!mInitialLoadDone || mLoadIsErronous) + { + QString message; - if (mInitialLoadDone && mLoadIsErronous) - message = tr("Cannot load content"); - else - message = tr("Loading ..."); + if (mInitialLoadDone && mLoadIsErronous) + message = tr("Cannot load content"); + else + message = tr("Loading ..."); - painter->setFont(QFont("Arial", 12)); + painter->setFont(QFont("Arial", 12)); - QFontMetrics fm = painter->fontMetrics(); - QRect txtBoundingRect = fm.boundingRect(message); + QFontMetrics fm = painter->fontMetrics(); + QRect txtBoundingRect = fm.boundingRect(message); - txtBoundingRect.moveCenter(rect().center().toPoint()); - txtBoundingRect.adjust(-10, -5, 10, 5); + txtBoundingRect.moveCenter(rect().center().toPoint()); + txtBoundingRect.adjust(-10, -5, 10, 5); - painter->setPen(Qt::NoPen); - painter->setBrush(UBSettings::paletteColor); - painter->drawRoundedRect(txtBoundingRect, 3, 3); + painter->setPen(Qt::NoPen); + painter->setBrush(UBSettings::paletteColor); + painter->drawRoundedRect(txtBoundingRect, 3, 3); - painter->setPen(Qt::white); - painter->drawText(rect(), Qt::AlignCenter, message); + painter->setPen(Qt::white); + painter->drawText(rect(), Qt::AlignCenter, message); + } + else + QGraphicsWebView::paint(painter, option, widget); } + } void UBGraphicsWidgetItem::geometryChangeRequested(const QRect& geom) @@ -624,6 +628,52 @@ void UBGraphicsWidgetItem::mainFrameLoadFinished (bool ok) update(boundingRect()); } +void UBGraphicsWidgetItem::wheelEvent(QGraphicsSceneWheelEvent *event) +{ + if (mDelegate->weelEvent(event)) + { + QGraphicsWebView::wheelEvent(event); + event->accept(); + } +} + +QVariant UBGraphicsWidgetItem::itemChange(GraphicsItemChange change, const QVariant &value) +{ + if ((change == QGraphicsItem::ItemSelectedHasChanged) && scene()) { + if (isSelected()) + scene()->setActiveWindow(this); + else + if(scene()->activeWindow() == this) + scene()->setActiveWindow(0); + } + + QVariant newValue = mDelegate->itemChange(change, value); + return QGraphicsWebView::itemChange(change, newValue); +} + +void UBGraphicsWidgetItem::resize(qreal w, qreal h) +{ + UBGraphicsWidgetItem::resize(QSizeF(w, h)); +} + + +void UBGraphicsWidgetItem::resize(const QSizeF & pSize) +{ + if (pSize != size()) { + QGraphicsWebView::setMaximumSize(pSize.width(), pSize.height()); + QGraphicsWebView::resize(pSize.width(), pSize.height()); + if (mDelegate) + mDelegate->positionHandles(); + if (scene()) + scene()->setModified(true); + } +} + +QSizeF UBGraphicsWidgetItem::size() const +{ + return QGraphicsWebView::size(); +} + UBGraphicsAppleWidgetItem::UBGraphicsAppleWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent) @@ -881,21 +931,6 @@ UBItem* UBGraphicsW3CWidgetItem::deepCopy() const return copy; } -void UBGraphicsW3CWidgetItem::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget) -{ - UBGraphicsScene::RenderingContext rc = UBGraphicsScene::Screen; - - if (scene()) - rc = scene()->renderingContext(); - - if (rc == UBGraphicsScene::NonScreen || rc == UBGraphicsScene::PdfExport) { - if (!snapshot().isNull()) - painter->drawPixmap(0, 0, snapshot()); - } - else - UBGraphicsWidgetItem::paint(painter, option, widget); -} - QMap UBGraphicsW3CWidgetItem::preferences() { return mPreferences; diff --git a/src/domain/UBGraphicsWidgetItem.h b/src/domain/UBGraphicsWidgetItem.h index c7074e2a..ed11a3c8 100644 --- a/src/domain/UBGraphicsWidgetItem.h +++ b/src/domain/UBGraphicsWidgetItem.h @@ -19,10 +19,11 @@ #include #include -#include "UBGraphicsWebView.h" - #include "core/UB.h" +#include "UBItem.h" +#include "UBResizableGraphicsItem.h" + class UBWidgetUniboardAPI; class UBGraphicsScene; class UBW3CWidgetAPI; @@ -38,7 +39,7 @@ struct UBWidgetType }; }; -class UBGraphicsWidgetItem : public UBGraphicsWebView +class UBGraphicsWidgetItem : public QGraphicsWebView, public UBItem, public UBResizableGraphicsItem, public UBGraphicsItem { Q_OBJECT @@ -52,6 +53,12 @@ class UBGraphicsWidgetItem : public UBGraphicsWebView virtual void initialize(); + virtual void resize(qreal w, qreal h); + virtual void resize(const QSizeF & size); + virtual QSizeF size() const; + + virtual UBGraphicsItemDelegate* Delegate() const { return mDelegate;} + QUrl mainHtml(); void loadMainHtml(); QUrl widgetUrl(); @@ -75,8 +82,6 @@ class UBGraphicsWidgetItem : public UBGraphicsWebView void removeDatastoreEntry(const QString& key); void removeAllDatastoreEntries(); - virtual UBGraphicsItemDelegate* Delegate() const; - virtual void remove(); void removeScript(); @@ -140,16 +145,18 @@ 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 void sendJSEnterEvent(); virtual void sendJSLeaveEvent(); virtual void injectInlineJavaScript(); + virtual void wheelEvent(QGraphicsSceneWheelEvent *event); + virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); protected slots: @@ -230,7 +237,6 @@ class UBGraphicsW3CWidgetItem : public UBGraphicsWidgetItem virtual void setUuid(const QUuid &pUuid); virtual UBItem* deepCopy() const; virtual void copyItemParameters(UBItem *copy) const; - virtual void paint ( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget ); QMap preferences(); Metadata metadatas() const; diff --git a/src/domain/domain.pri b/src/domain/domain.pri index 1111106f..a7dbb78d 100644 --- a/src/domain/domain.pri +++ b/src/domain/domain.pri @@ -6,7 +6,6 @@ HEADERS += src/domain/UBGraphicsScene.h \ src/domain/UBDocumentUndoCommand.h \ src/domain/UBPageSizeUndoCommand.h \ src/domain/UBGraphicsProxyWidget.h \ - src/domain/UBGraphicsWebView.h \ src/domain/UBGraphicsSvgItem.h \ src/domain/UBGraphicsPolygonItem.h \ src/domain/UBItem.h \ @@ -35,7 +34,6 @@ SOURCES += src/domain/UBGraphicsScene.cpp \ src/domain/UBDocumentUndoCommand.cpp \ src/domain/UBPageSizeUndoCommand.cpp \ src/domain/UBGraphicsProxyWidget.cpp \ - src/domain/UBGraphicsWebView.cpp \ src/domain/UBGraphicsSvgItem.cpp \ src/domain/UBGraphicsPolygonItem.cpp \ src/domain/UBItem.cpp \ From a726171f1b90b7005b803acf45950ae5d0cfe8c9 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Thu, 6 Sep 2012 15:03:23 +0200 Subject: [PATCH 07/15] add the possibility to set maximum number of character --- src/gui/UBTeacherGuideWidget.cpp | 1 + src/gui/UBTeacherGuideWidgetsTools.cpp | 14 ++++++++++++++ src/gui/UBTeacherGuideWidgetsTools.h | 2 ++ 3 files changed, 17 insertions(+) diff --git a/src/gui/UBTeacherGuideWidget.cpp b/src/gui/UBTeacherGuideWidget.cpp index ffe11cbd..679da6a8 100644 --- a/src/gui/UBTeacherGuideWidget.cpp +++ b/src/gui/UBTeacherGuideWidget.cpp @@ -697,6 +697,7 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpSessionTitle = new UBTGAdaptableText(0, this, "UBTGSessionTitle"); mpSessionTitle->setPlaceHolderText(tr("Type session title here ...")); + mpSessionTitle->setMaximumLength(1000); mpButtonTitleLayout->addWidget(mpSessionTitle); connect(this, SIGNAL(resized()), mpSessionTitle, SLOT(onTextChanged())); diff --git a/src/gui/UBTeacherGuideWidgetsTools.cpp b/src/gui/UBTeacherGuideWidgetsTools.cpp index 6300c65b..4456b243 100644 --- a/src/gui/UBTeacherGuideWidgetsTools.cpp +++ b/src/gui/UBTeacherGuideWidgetsTools.cpp @@ -120,6 +120,7 @@ UBTGAdaptableText::UBTGAdaptableText(QTreeWidgetItem* widget, QWidget* parent, c , mMinimumHeight(0) , mHasPlaceHolder(false) , mIsUpdatingSize(false) + , mMaximumLength(0) { setObjectName(name); connect(this,SIGNAL(textChanged()),this,SLOT(onTextChanged())); @@ -131,6 +132,11 @@ UBTGAdaptableText::UBTGAdaptableText(QTreeWidgetItem* widget, QWidget* parent, c } +void UBTGAdaptableText::setMaximumLength(int length) +{ + mMaximumLength = length; +} + void UBTGAdaptableText::setPlaceHolderText(QString text) { mHasPlaceHolder = true; @@ -166,6 +172,12 @@ void UBTGAdaptableText::keyReleaseEvent(QKeyEvent* e) setTextColor(QColor(Qt::lightGray)); setPlainText(mPlaceHolderText); } + if(mMaximumLength && toPlainText().length()>mMaximumLength){ + setPlainText(toPlainText().left(mMaximumLength)); + QTextCursor tc(document()); + tc.setPosition(mMaximumLength); + setTextCursor(tc); + } } void UBTGAdaptableText::showEvent(QShowEvent* e) @@ -212,8 +224,10 @@ void UBTGAdaptableText::onTextChanged() setFocus(); } mIsUpdatingSize = false; + } + void UBTGAdaptableText::setInitialText(const QString& text) { setText(text); diff --git a/src/gui/UBTeacherGuideWidgetsTools.h b/src/gui/UBTeacherGuideWidgetsTools.h index e4ee8c53..2f87ccfd 100644 --- a/src/gui/UBTeacherGuideWidgetsTools.h +++ b/src/gui/UBTeacherGuideWidgetsTools.h @@ -97,6 +97,7 @@ public: void setPlaceHolderText(QString text); QString text(); void setInitialText(const QString& text); + void setMaximumLength(int length); public slots: void onTextChanged(); @@ -113,6 +114,7 @@ private: bool mHasPlaceHolder; QString mPlaceHolderText; bool mIsUpdatingSize; + int mMaximumLength; }; From db5c7ce7324033cb1fefb0ec6ea9f7cc85ff075d Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Thu, 6 Sep 2012 16:21:18 +0300 Subject: [PATCH 08/15] Correct deletion of delegate instance (error with Vido on MAC OS) --- src/domain/UBGraphicsGroupContainerItem.cpp | 30 +++++-------- src/domain/UBGraphicsGroupContainerItem.h | 3 -- src/domain/UBGraphicsMediaItem.cpp | 22 ++++----- src/domain/UBGraphicsPDFItem.cpp | 22 +++------ src/domain/UBGraphicsPDFItem.h | 3 -- src/domain/UBGraphicsPixmapItem.cpp | 29 +++++------- src/domain/UBGraphicsPixmapItem.h | 3 -- src/domain/UBGraphicsProxyWidget.cpp | 37 +++++----------- src/domain/UBGraphicsProxyWidget.h | 8 +--- src/domain/UBGraphicsStrokesGroup.cpp | 29 +++++------- src/domain/UBGraphicsStrokesGroup.h | 2 - src/domain/UBGraphicsSvgItem.cpp | 25 ++++------- src/domain/UBGraphicsSvgItem.h | 3 -- src/domain/UBGraphicsTextItem.cpp | 49 +++++++++------------ src/domain/UBGraphicsTextItem.h | 3 -- src/domain/UBGraphicsWidgetItem.cpp | 30 +++++-------- src/domain/UBGraphicsWidgetItem.h | 3 -- src/domain/UBItem.cpp | 19 ++++++++ src/domain/UBItem.h | 22 ++++----- src/tools/UBGraphicsCurtainItem.cpp | 23 ++++------ src/tools/UBGraphicsCurtainItem.h | 3 -- src/tools/UBGraphicsCurtainItemDelegate.h | 5 +-- 22 files changed, 142 insertions(+), 231 deletions(-) diff --git a/src/domain/UBGraphicsGroupContainerItem.cpp b/src/domain/UBGraphicsGroupContainerItem.cpp index 818eb88e..5f0e85c0 100644 --- a/src/domain/UBGraphicsGroupContainerItem.cpp +++ b/src/domain/UBGraphicsGroupContainerItem.cpp @@ -16,8 +16,8 @@ UBGraphicsGroupContainerItem::UBGraphicsGroupContainerItem(QGraphicsItem *parent { setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); - mDelegate = new UBGraphicsGroupContainerItemDelegate(this, 0); - mDelegate->init(); + setDelegate(new UBGraphicsGroupContainerItemDelegate(this, 0)); + Delegate()->init(); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); setFlag(QGraphicsItem::ItemIsSelectable, true); @@ -32,8 +32,6 @@ UBGraphicsGroupContainerItem::UBGraphicsGroupContainerItem(QGraphicsItem *parent UBGraphicsGroupContainerItem::~UBGraphicsGroupContainerItem() { - if (mDelegate) - delete mDelegate; } void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item) @@ -50,14 +48,14 @@ void UBGraphicsGroupContainerItem::addToGroup(QGraphicsItem *item) //Check if group is allready rotatable or flippable if (childItems().count()) { if (UBGraphicsItem::isFlippable(this) && !UBGraphicsItem::isFlippable(item)) { - mDelegate->setFlippable(false); + Delegate()->setFlippable(false); } if (UBGraphicsItem::isRotatable(this) && !UBGraphicsItem::isRotatable(item)) { - mDelegate->setRotatable(false); + Delegate()->setRotatable(false); } } else { - mDelegate->setFlippable(UBGraphicsItem::isFlippable(item)); - mDelegate->setRotatable(UBGraphicsItem::isRotatable(item)); + Delegate()->setFlippable(UBGraphicsItem::isFlippable(item)); + Delegate()->setRotatable(UBGraphicsItem::isRotatable(item)); } // COMBINE @@ -207,12 +205,6 @@ void UBGraphicsGroupContainerItem::copyItemParameters(UBItem *copy) const } } -void UBGraphicsGroupContainerItem::remove() -{ - if (mDelegate) - mDelegate->remove(); -} - void UBGraphicsGroupContainerItem::setUuid(const QUuid &pUuid) { UBItem::setUuid(pUuid); @@ -244,7 +236,7 @@ void UBGraphicsGroupContainerItem::clearSource() void UBGraphicsGroupContainerItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (mDelegate->mousePressEvent(event)) { + if (Delegate()->mousePressEvent(event)) { //NOOP } else { @@ -257,7 +249,7 @@ void UBGraphicsGroupContainerItem::mousePressEvent(QGraphicsSceneMouseEvent *eve void UBGraphicsGroupContainerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if (mDelegate->mouseMoveEvent(event)) { + if (Delegate()->mouseMoveEvent(event)) { // NOOP; } else { QGraphicsItem::mouseMoveEvent(event); @@ -273,7 +265,7 @@ void UBGraphicsGroupContainerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *e QVariant UBGraphicsGroupContainerItem::itemChange(GraphicsItemChange change, const QVariant &value) { - QVariant newValue = mDelegate->itemChange(change, value); + QVariant newValue = Delegate()->itemChange(change, value); foreach(QGraphicsItem *child, children()) { @@ -317,8 +309,8 @@ void UBGraphicsGroupContainerItem::pRemoveFromGroup(QGraphicsItem *item) break; } } - mDelegate->setFlippable(flippableNow); - mDelegate->setRotatable(rotatableNow); + Delegate()->setFlippable(flippableNow); + Delegate()->setRotatable(rotatableNow); } } diff --git a/src/domain/UBGraphicsGroupContainerItem.h b/src/domain/UBGraphicsGroupContainerItem.h index e8fa77eb..6f14204a 100644 --- a/src/domain/UBGraphicsGroupContainerItem.h +++ b/src/domain/UBGraphicsGroupContainerItem.h @@ -22,13 +22,10 @@ public: QRectF boundingRect() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - virtual UBGraphicsItemDelegate* Delegate() const { return mDelegate;} - virtual UBCoreGraphicsScene *corescene(); virtual UBGraphicsGroupContainerItem *deepCopy() const; virtual void copyItemParameters(UBItem *copy) const; - virtual void remove(); enum { Type = UBGraphicsItemType::groupContainerType }; virtual int type() const diff --git a/src/domain/UBGraphicsMediaItem.cpp b/src/domain/UBGraphicsMediaItem.cpp index d1e97583..d96ab915 100644 --- a/src/domain/UBGraphicsMediaItem.cpp +++ b/src/domain/UBGraphicsMediaItem.cpp @@ -72,6 +72,10 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte update(); mMediaObject = new Phonon::MediaObject(this); + + setDelegate(new UBGraphicsMediaItemDelegate(this, mMediaObject)); + Delegate()->init(); + if (pMediaFileUrl.toLocalFile().contains("videos")) { mMediaType = mediaType_Video; @@ -116,18 +120,14 @@ UBGraphicsMediaItem::UBGraphicsMediaItem(const QUrl& pMediaFileUrl, QGraphicsIte mSource = Phonon::MediaSource(pMediaFileUrl); mMediaObject->setCurrentSource(mSource); - UBGraphicsMediaItemDelegate* itemDelegate = new UBGraphicsMediaItemDelegate(this, mMediaObject); - itemDelegate->init(); - setDelegate(itemDelegate); - if (mediaType_Audio == mMediaType) - mDelegate->frame()->setOperationMode(UBGraphicsDelegateFrame::ResizingHorizontally); + Delegate()->frame()->setOperationMode(UBGraphicsDelegateFrame::ResizingHorizontally); else - mDelegate->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); + Delegate()->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); //Necessary to set if we want z value to be assigned correctly - connect(mDelegate, SIGNAL(showOnDisplayChanged(bool)), this, SLOT(showOnDisplayChanged(bool))); + connect(Delegate(), SIGNAL(showOnDisplayChanged(bool)), this, SLOT(showOnDisplayChanged(bool))); connect(mMediaObject, SIGNAL(hasVideoChanged(bool)), this, SLOT(hasMediaChanged(bool))); } @@ -220,7 +220,7 @@ void UBGraphicsMediaItem::hasMediaChanged(bool hasMedia) { Q_UNUSED(hasMedia); mMediaObject->seek(mInitialPos); - UBGraphicsMediaItemDelegate *med = dynamic_cast(mDelegate); + UBGraphicsMediaItemDelegate *med = dynamic_cast(Delegate()); if (med) med->updateTicker(initialPos()); } @@ -289,9 +289,9 @@ void UBGraphicsMediaItem::copyItemParameters(UBItem *copy) const void UBGraphicsMediaItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (mDelegate) + if (Delegate()) { - mDelegate->mousePressEvent(event); + Delegate()->mousePressEvent(event); if (parentItem() && UBGraphicsGroupContainerItem::Type == parentItem()->type()) { UBGraphicsGroupContainerItem *group = qgraphicsitem_cast(parentItem()); @@ -304,7 +304,7 @@ void UBGraphicsMediaItem::mousePressEvent(QGraphicsSceneMouseEvent *event) } group->setCurrentItem(this); this->setSelected(true); - mDelegate->positionHandles(); + Delegate()->positionHandles(); } } diff --git a/src/domain/UBGraphicsPDFItem.cpp b/src/domain/UBGraphicsPDFItem.cpp index 425ab749..3bcb09f6 100644 --- a/src/domain/UBGraphicsPDFItem.cpp +++ b/src/domain/UBGraphicsPDFItem.cpp @@ -28,21 +28,20 @@ UBGraphicsPDFItem::UBGraphicsPDFItem(PDFRenderer *renderer, int pageNumber, QGra { setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); //deprecated setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::BackgroundItem)); //Necessary to set if we want z value to be assigned correctly - mDelegate = new UBGraphicsItemDelegate(this,0, true, false, false); - mDelegate->init(); + + setDelegate(new UBGraphicsItemDelegate(this,0, true, false, false)); + Delegate()->init(); } UBGraphicsPDFItem::~UBGraphicsPDFItem() { - if (mDelegate) - delete mDelegate; } QVariant UBGraphicsPDFItem::itemChange(GraphicsItemChange change, const QVariant &value) { - QVariant newValue = mDelegate->itemChange(change, value); + QVariant newValue = Delegate()->itemChange(change, value); return GraphicsPDFItem::itemChange(change, newValue); } @@ -54,7 +53,7 @@ void UBGraphicsPDFItem::setUuid(const QUuid &pUuid) void UBGraphicsPDFItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (mDelegate->mousePressEvent(event)) + if (Delegate()->mousePressEvent(event)) { // NOOP } @@ -67,7 +66,7 @@ void UBGraphicsPDFItem::mousePressEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsPDFItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if (mDelegate->mouseMoveEvent(event)) + if (Delegate()->mouseMoveEvent(event)) { // NOOP } @@ -80,7 +79,7 @@ void UBGraphicsPDFItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsPDFItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - mDelegate->mouseReleaseEvent(event); + Delegate()->mouseReleaseEvent(event); GraphicsPDFItem::mouseReleaseEvent(event); } @@ -131,13 +130,6 @@ UBGraphicsScene* UBGraphicsPDFItem::scene() } -void UBGraphicsPDFItem::remove() -{ - if (mDelegate) - mDelegate->remove(true); -} - - UBGraphicsPixmapItem* UBGraphicsPDFItem::toPixmapItem() const { QPixmap pixmap(mRenderer->pageSizeF(mPageNumber).toSize()); diff --git a/src/domain/UBGraphicsPDFItem.h b/src/domain/UBGraphicsPDFItem.h index b41b15ec..9107ea85 100644 --- a/src/domain/UBGraphicsPDFItem.h +++ b/src/domain/UBGraphicsPDFItem.h @@ -47,10 +47,7 @@ class UBGraphicsPDFItem: public GraphicsPDFItem, public UBItem, public UBGraphic virtual UBGraphicsScene* scene(); - virtual void remove(); - virtual UBGraphicsPixmapItem* toPixmapItem() const; - virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;} virtual void clearSource(){;} virtual void setUuid(const QUuid &pUuid); diff --git a/src/domain/UBGraphicsPixmapItem.cpp b/src/domain/UBGraphicsPixmapItem.cpp index 4e346256..f771032d 100644 --- a/src/domain/UBGraphicsPixmapItem.cpp +++ b/src/domain/UBGraphicsPixmapItem.cpp @@ -28,10 +28,10 @@ UBGraphicsPixmapItem::UBGraphicsPixmapItem(QGraphicsItem* parent) : QGraphicsPixmapItem(parent) { - mDelegate = new UBGraphicsItemDelegate(this, 0, true); - mDelegate->init(); - mDelegate->setFlippable(true); - mDelegate->setRotatable(true); + setDelegate(new UBGraphicsItemDelegate(this, 0, true)); + Delegate()->init(); + Delegate()->setFlippable(true); + Delegate()->setRotatable(true); setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); setTransformationMode(Qt::SmoothTransformation); @@ -44,13 +44,11 @@ UBGraphicsPixmapItem::UBGraphicsPixmapItem(QGraphicsItem* parent) UBGraphicsPixmapItem::~UBGraphicsPixmapItem() { - if (mDelegate) - delete mDelegate; } QVariant UBGraphicsPixmapItem::itemChange(GraphicsItemChange change, const QVariant &value) { - QVariant newValue = mDelegate->itemChange(change, value); + QVariant newValue = Delegate()->itemChange(change, value); return QGraphicsPixmapItem::itemChange(change, newValue); } @@ -64,14 +62,14 @@ void UBGraphicsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { QMimeData* pMime = new QMimeData(); pMime->setImageData(pixmap().toImage()); - mDelegate->setMimeData(pMime); + Delegate()->setMimeData(pMime); qreal k = (qreal)pixmap().width() / 100.0; QSize newSize((int)(pixmap().width() / k), (int)(pixmap().height() / k)); - mDelegate->setDragPixmap(pixmap().scaled(newSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + Delegate()->setDragPixmap(pixmap().scaled(newSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); - if (mDelegate->mousePressEvent(event)) + if (Delegate()->mousePressEvent(event)) { //NOOP } @@ -83,7 +81,7 @@ void UBGraphicsPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if (mDelegate->mouseMoveEvent(event)) + if (Delegate()->mouseMoveEvent(event)) { // NOOP; } @@ -95,7 +93,7 @@ void UBGraphicsPixmapItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - mDelegate->mouseReleaseEvent(event); + Delegate()->mouseReleaseEvent(event); QGraphicsPixmapItem::mouseReleaseEvent(event); } @@ -145,13 +143,6 @@ UBGraphicsScene* UBGraphicsPixmapItem::scene() } -void UBGraphicsPixmapItem::remove() -{ - if (mDelegate) - mDelegate->remove(true); -} - - void UBGraphicsPixmapItem::setOpacity(qreal op) { QGraphicsPixmapItem::setOpacity(op); diff --git a/src/domain/UBGraphicsPixmapItem.h b/src/domain/UBGraphicsPixmapItem.h index 787f28eb..2a43e4eb 100644 --- a/src/domain/UBGraphicsPixmapItem.h +++ b/src/domain/UBGraphicsPixmapItem.h @@ -44,14 +44,11 @@ class UBGraphicsPixmapItem : public QObject, public QGraphicsPixmapItem, public virtual UBGraphicsScene* scene(); - virtual void remove(); - Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity) void setOpacity(qreal op); qreal opacity() const; - virtual UBGraphicsItemDelegate* Delegate() const {return mDelegate;} virtual void clearSource(){;} virtual void setUuid(const QUuid &pUuid); diff --git a/src/domain/UBGraphicsProxyWidget.cpp b/src/domain/UBGraphicsProxyWidget.cpp index 25617250..ed2f6797 100644 --- a/src/domain/UBGraphicsProxyWidget.cpp +++ b/src/domain/UBGraphicsProxyWidget.cpp @@ -29,8 +29,9 @@ UBGraphicsProxyWidget::UBGraphicsProxyWidget(QGraphicsItem* parent) { setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); - mDelegate = new UBGraphicsItemDelegate(this,0, true, false, false); - mDelegate->init(); + //UBGraphicsItemDelegate* delegate = new UBGraphicsItemDelegate(this,0, true, false, false); + //delegate->init(); + //setDelegate(delegate); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); @@ -40,8 +41,6 @@ UBGraphicsProxyWidget::UBGraphicsProxyWidget(QGraphicsItem* parent) UBGraphicsProxyWidget::~UBGraphicsProxyWidget() { - if (mDelegate) - delete mDelegate; } @@ -67,7 +66,7 @@ QVariant UBGraphicsProxyWidget::itemChange(GraphicsItemChange change, const QVar } } - QVariant newValue = mDelegate->itemChange(change, value); + QVariant newValue = Delegate()->itemChange(change, value); return QGraphicsProxyWidget::itemChange(change, newValue); } @@ -79,7 +78,7 @@ void UBGraphicsProxyWidget::setUuid(const QUuid &pUuid) void UBGraphicsProxyWidget::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (mDelegate->mousePressEvent(event)) + if (Delegate()->mousePressEvent(event)) { //NOOP } @@ -95,7 +94,7 @@ void UBGraphicsProxyWidget::mousePressEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsProxyWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if (mDelegate->mouseMoveEvent(event)) + if (Delegate()->mouseMoveEvent(event)) { // NOOP; } @@ -108,13 +107,13 @@ void UBGraphicsProxyWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsProxyWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - mDelegate->mouseReleaseEvent(event); + Delegate()->mouseReleaseEvent(event); QGraphicsProxyWidget::mouseReleaseEvent(event); } void UBGraphicsProxyWidget::wheelEvent(QGraphicsSceneWheelEvent *event) { - if( mDelegate->weelEvent(event) ) + if( Delegate()->weelEvent(event) ) { QGraphicsProxyWidget::wheelEvent(event); event->accept(); @@ -132,17 +131,6 @@ void UBGraphicsProxyWidget::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) // NOOP } -void UBGraphicsProxyWidget::setDelegate(UBGraphicsItemDelegate* pDelegate) -{ - if (mDelegate) - { - delete mDelegate; - } - - mDelegate = pDelegate; -} - - void UBGraphicsProxyWidget::resize(qreal w, qreal h) { UBGraphicsProxyWidget::resize(QSizeF(w, h)); @@ -177,8 +165,8 @@ void UBGraphicsProxyWidget::resize(const QSizeF & pSize) QGraphicsProxyWidget::resize(size.width(), size.height()); if (widget()) widget()->resize(size.width(), size.height()); - if (mDelegate) - mDelegate->positionHandles(); + if (Delegate()) + Delegate()->positionHandles(); if (scene()) scene()->setModified(true); } @@ -197,8 +185,3 @@ UBGraphicsScene* UBGraphicsProxyWidget::scene() } -void UBGraphicsProxyWidget::remove() -{ - if (mDelegate) - mDelegate->remove(true); -} diff --git a/src/domain/UBGraphicsProxyWidget.h b/src/domain/UBGraphicsProxyWidget.h index d9280fb7..d663f441 100644 --- a/src/domain/UBGraphicsProxyWidget.h +++ b/src/domain/UBGraphicsProxyWidget.h @@ -27,7 +27,6 @@ class UBGraphicsItemDelegate; class UBGraphicsProxyWidget: public QGraphicsProxyWidget, public UBItem, public UBResizableGraphicsItem, public UBGraphicsItem { public: - UBGraphicsProxyWidget(QGraphicsItem* parent = 0); virtual ~UBGraphicsProxyWidget(); virtual void resize(qreal w, qreal h); @@ -35,18 +34,13 @@ class UBGraphicsProxyWidget: public QGraphicsProxyWidget, public UBItem, public virtual QSizeF size() const; - void setDelegate(UBGraphicsItemDelegate* pDelegate); - virtual UBGraphicsScene* scene(); - virtual void remove(); - - virtual UBGraphicsItemDelegate* Delegate() const { return mDelegate;} - virtual void clearSource(){;} virtual void setUuid(const QUuid &pUuid); protected: + UBGraphicsProxyWidget(QGraphicsItem* parent = 0); virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); diff --git a/src/domain/UBGraphicsStrokesGroup.cpp b/src/domain/UBGraphicsStrokesGroup.cpp index e9993375..490f6bd4 100644 --- a/src/domain/UBGraphicsStrokesGroup.cpp +++ b/src/domain/UBGraphicsStrokesGroup.cpp @@ -4,12 +4,14 @@ #include "core/memcheck.h" -UBGraphicsStrokesGroup::UBGraphicsStrokesGroup(QGraphicsItem *parent):QGraphicsItemGroup(parent) +UBGraphicsStrokesGroup::UBGraphicsStrokesGroup(QGraphicsItem *parent) + :UBGraphicsItem(), QGraphicsItemGroup(parent) { - mDelegate = new UBGraphicsItemDelegate(this, 0, true, true, false); - mDelegate->init(); - mDelegate->setFlippable(true); - mDelegate->setRotatable(true); + setDelegate(new UBGraphicsItemDelegate(this, 0, true, true, false)); + Delegate()->init(); + Delegate()->setFlippable(true); + Delegate()->setRotatable(true); + setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); @@ -22,9 +24,6 @@ UBGraphicsStrokesGroup::UBGraphicsStrokesGroup(QGraphicsItem *parent):QGraphicsI UBGraphicsStrokesGroup::~UBGraphicsStrokesGroup() { - if(mDelegate){ - delete mDelegate; - } } void UBGraphicsStrokesGroup::setUuid(const QUuid &pUuid) @@ -83,7 +82,7 @@ QColor UBGraphicsStrokesGroup::color(colorType pColorType) const void UBGraphicsStrokesGroup::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (mDelegate->mousePressEvent(event)) + if (Delegate()->mousePressEvent(event)) { //NOOP } @@ -95,7 +94,7 @@ void UBGraphicsStrokesGroup::mousePressEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsStrokesGroup::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if (mDelegate->mouseMoveEvent(event)) + if (Delegate()->mouseMoveEvent(event)) { // NOOP; } @@ -107,7 +106,7 @@ void UBGraphicsStrokesGroup::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsStrokesGroup::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - mDelegate->mouseReleaseEvent(event); + Delegate()->mouseReleaseEvent(event); QGraphicsItemGroup::mouseReleaseEvent(event); } @@ -144,12 +143,6 @@ void UBGraphicsStrokesGroup::copyItemParameters(UBItem *copy) const } } -void UBGraphicsStrokesGroup::remove() -{ - if (mDelegate) - mDelegate->remove(true); -} - void UBGraphicsStrokesGroup::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { // Never draw the rubber band, we draw our custom selection with the DelegateFrame @@ -161,7 +154,7 @@ void UBGraphicsStrokesGroup::paint(QPainter *painter, const QStyleOptionGraphics QVariant UBGraphicsStrokesGroup::itemChange(GraphicsItemChange change, const QVariant &value) { - QVariant newValue = mDelegate->itemChange(change, value); + QVariant newValue = Delegate()->itemChange(change, value); return QGraphicsItemGroup::itemChange(change, newValue); } diff --git a/src/domain/UBGraphicsStrokesGroup.h b/src/domain/UBGraphicsStrokesGroup.h index 2c286d11..9b3aa79e 100644 --- a/src/domain/UBGraphicsStrokesGroup.h +++ b/src/domain/UBGraphicsStrokesGroup.h @@ -21,8 +21,6 @@ public: ~UBGraphicsStrokesGroup(); virtual UBItem* deepCopy() const; virtual void copyItemParameters(UBItem *copy) const; - virtual void remove(); - virtual UBGraphicsItemDelegate* Delegate() const {return mDelegate;} enum { Type = UBGraphicsItemType::StrokeItemType }; virtual int type() const { diff --git a/src/domain/UBGraphicsSvgItem.cpp b/src/domain/UBGraphicsSvgItem.cpp index e393ef23..dfa402c9 100644 --- a/src/domain/UBGraphicsSvgItem.cpp +++ b/src/domain/UBGraphicsSvgItem.cpp @@ -53,10 +53,11 @@ void UBGraphicsSvgItem::init() { setData(UBGraphicsItemData::ItemLayerType, UBItemLayerType::Object); - mDelegate = new UBGraphicsItemDelegate(this, 0, true, true, false); - mDelegate->init(); - mDelegate->setFlippable(true); - mDelegate->setRotatable(true); + setDelegate(new UBGraphicsItemDelegate(this, 0, true, true, false)); + Delegate()->init(); + Delegate()->setFlippable(true); + Delegate()->setRotatable(true); + setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); @@ -71,8 +72,6 @@ void UBGraphicsSvgItem::init() UBGraphicsSvgItem::~UBGraphicsSvgItem() { - if (mDelegate) - delete mDelegate; } @@ -84,14 +83,14 @@ QByteArray UBGraphicsSvgItem::fileData() const QVariant UBGraphicsSvgItem::itemChange(GraphicsItemChange change, const QVariant &value) { - QVariant newValue = mDelegate->itemChange(change, value); + QVariant newValue = Delegate()->itemChange(change, value); return QGraphicsSvgItem::itemChange(change, newValue); } void UBGraphicsSvgItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (mDelegate->mousePressEvent(event)) + if (Delegate()->mousePressEvent(event)) { //NOOP } @@ -104,7 +103,7 @@ void UBGraphicsSvgItem::mousePressEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsSvgItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if (mDelegate->mouseMoveEvent(event)) + if (Delegate()->mouseMoveEvent(event)) { // NOOP; } @@ -117,7 +116,7 @@ void UBGraphicsSvgItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsSvgItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - mDelegate->mouseReleaseEvent(event); + Delegate()->mouseReleaseEvent(event); QGraphicsSvgItem::mouseReleaseEvent(event); } @@ -182,12 +181,6 @@ UBGraphicsScene* UBGraphicsSvgItem::scene() } -void UBGraphicsSvgItem::remove() -{ - if (mDelegate) - mDelegate->remove(true); -} - UBGraphicsPixmapItem* UBGraphicsSvgItem::toPixmapItem() const { diff --git a/src/domain/UBGraphicsSvgItem.h b/src/domain/UBGraphicsSvgItem.h index 95b9d536..1c2351d0 100644 --- a/src/domain/UBGraphicsSvgItem.h +++ b/src/domain/UBGraphicsSvgItem.h @@ -58,10 +58,7 @@ class UBGraphicsSvgItem: public QGraphicsSvgItem, public UBItem, public UBGraphi virtual UBGraphicsScene* scene(); - virtual void remove(); - virtual UBGraphicsPixmapItem* toPixmapItem() const; - virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;} virtual void setUuid(const QUuid &pUuid); diff --git a/src/domain/UBGraphicsTextItem.cpp b/src/domain/UBGraphicsTextItem.cpp index 20adf243..f7812e29 100644 --- a/src/domain/UBGraphicsTextItem.cpp +++ b/src/domain/UBGraphicsTextItem.cpp @@ -31,16 +31,17 @@ QColor UBGraphicsTextItem::lastUsedTextColor; UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) - : QGraphicsTextItem(parent) + : UBGraphicsItem() + , QGraphicsTextItem(parent) , mMultiClickState(0) , mLastMousePressTime(QTime::currentTime()) { - mDelegate = new UBGraphicsTextItemDelegate(this, 0); - mDelegate->init(); + setDelegate(new UBGraphicsTextItemDelegate(this, 0)); + Delegate()->init(); - mDelegate->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); - mDelegate->setFlippable(false); - mDelegate->setRotatable(true); + Delegate()->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); + Delegate()->setFlippable(false); + Delegate()->setRotatable(true); mTypeTextHereLabel = tr(""); @@ -58,7 +59,7 @@ UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) setUuid(QUuid::createUuid()); - connect(document(), SIGNAL(contentsChanged()), mDelegate, SLOT(contentsChanged())); + connect(document(), SIGNAL(contentsChanged()), Delegate(), SLOT(contentsChanged())); connect(document(), SIGNAL(undoCommandAdded()), this, SLOT(undoCommandAdded())); connect(document()->documentLayout(), SIGNAL(documentSizeChanged(const QSizeF &)), @@ -68,18 +69,14 @@ UBGraphicsTextItem::UBGraphicsTextItem(QGraphicsItem * parent) UBGraphicsTextItem::~UBGraphicsTextItem() { - if (mDelegate) - { - delete mDelegate; - } } QVariant UBGraphicsTextItem::itemChange(GraphicsItemChange change, const QVariant &value) { QVariant newValue = value; - if(mDelegate) - newValue = mDelegate->itemChange(change, value); + if(Delegate()) + newValue = Delegate()->itemChange(change, value); return QGraphicsTextItem::itemChange(change, newValue); } @@ -95,10 +92,10 @@ void UBGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) return; } - if (mDelegate) + if (Delegate()) { - mDelegate->mousePressEvent(event); - if (mDelegate && parentItem() && UBGraphicsGroupContainerItem::Type == parentItem()->type()) + Delegate()->mousePressEvent(event); + if (Delegate() && parentItem() && UBGraphicsGroupContainerItem::Type == parentItem()->type()) { UBGraphicsGroupContainerItem *group = qgraphicsitem_cast(parentItem()); if (group) @@ -110,13 +107,13 @@ void UBGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) } group->setCurrentItem(this); this->setSelected(true); - mDelegate->positionHandles(); + Delegate()->positionHandles(); } } else { - mDelegate->getToolBarItem()->show(); + Delegate()->getToolBarItem()->show(); } } @@ -165,7 +162,7 @@ void UBGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if (!mDelegate || !mDelegate->mouseMoveEvent(event)) + if (!Delegate() || !Delegate()->mouseMoveEvent(event)) { QGraphicsTextItem::mouseMoveEvent(event); } @@ -184,8 +181,8 @@ void UBGraphicsTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) if (mMultiClickState == 1) { - if (mDelegate) - mDelegate->mouseReleaseEvent(event); + if (Delegate()) + Delegate()->mouseReleaseEvent(event); QGraphicsTextItem::mouseReleaseEvent(event); } @@ -324,8 +321,8 @@ void UBGraphicsTextItem::resize(qreal w, qreal h) setTextWidth(w); setTextHeight(h); - if (mDelegate) - mDelegate->positionHandles(); + if (Delegate()) + Delegate()->positionHandles(); } @@ -347,12 +344,6 @@ void UBGraphicsTextItem::undoCommandAdded() } -void UBGraphicsTextItem::remove() -{ - if (mDelegate) - mDelegate->remove(true); -} - void UBGraphicsTextItem::documentSizeChanged(const QSizeF & newSize) { resize(newSize.width(), newSize.height()); diff --git a/src/domain/UBGraphicsTextItem.h b/src/domain/UBGraphicsTextItem.h index c7dc5c95..61fdb8b1 100644 --- a/src/domain/UBGraphicsTextItem.h +++ b/src/domain/UBGraphicsTextItem.h @@ -58,8 +58,6 @@ class UBGraphicsTextItem : public QGraphicsTextItem, public UBItem, public UBRes virtual QSizeF size() const; - virtual void remove(); - static QColor lastUsedTextColor; QColor colorOnDarkBackground() const @@ -81,7 +79,6 @@ class UBGraphicsTextItem : public QGraphicsTextItem, public UBItem, public UBRes { mColorOnLightBackground = pColorOnLightBackground; } - virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;} virtual void clearSource(){;} virtual void setUuid(const QUuid &pUuid); diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index c3aed833..5bd2b725 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -84,8 +84,8 @@ UBGraphicsWidgetItem::UBGraphicsWidgetItem(const QUrl &pWidgetUrl, QGraphicsItem viewPalette.setBrush(QPalette::Window, QBrush(Qt::transparent)); setPalette(viewPalette); - mDelegate = new UBGraphicsWidgetItemDelegate(this); - mDelegate->init(); + setDelegate(new UBGraphicsWidgetItemDelegate(this)); + Delegate()->init(); setFlag(QGraphicsItem::ItemSendsGeometryChanges, true); QGraphicsWebView::setAcceptHoverEvents(true); @@ -102,8 +102,8 @@ void UBGraphicsWidgetItem::initialize() setMinimumSize(nominalSize()); setData(UBGraphicsItemData::itemLayerType, QVariant(itemLayerType::ObjectItem)); // Necessary to set if we want z value to be assigned correctly - if (mDelegate && mDelegate->frame() && resizable()) - mDelegate->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); + if (Delegate() && Delegate()->frame() && resizable()) + Delegate()->frame()->setOperationMode(UBGraphicsDelegateFrame::Resizing); QPalette palette = page()->palette(); palette.setBrush(QPalette::Base, QBrush(Qt::transparent)); @@ -262,12 +262,6 @@ void UBGraphicsWidgetItem::removeAllDatastoreEntries() mDatastore.clear(); } -void UBGraphicsWidgetItem::remove() -{ - if (mDelegate) - mDelegate->remove(); -} - void UBGraphicsWidgetItem::removeScript() { if (page() && page()->mainFrame()) @@ -512,7 +506,7 @@ void UBGraphicsWidgetItem::dropEvent(QGraphicsSceneDragDropEvent *event) void UBGraphicsWidgetItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (!mDelegate->mousePressEvent(event)) + if (!Delegate()->mousePressEvent(event)) setSelected(true); /* forcing selection */ QGraphicsWebView::mousePressEvent(event); @@ -529,19 +523,19 @@ void UBGraphicsWidgetItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { mShouldMoveWidget = false; - mDelegate->mouseReleaseEvent(event); + Delegate()->mouseReleaseEvent(event); QGraphicsWebView::mouseReleaseEvent(event); } void UBGraphicsWidgetItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) { sendJSEnterEvent(); - mDelegate->hoverEnterEvent(event); + Delegate()->hoverEnterEvent(event); } void UBGraphicsWidgetItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) { sendJSLeaveEvent(); - mDelegate->hoverLeaveEvent(event); + Delegate()->hoverLeaveEvent(event); } void UBGraphicsWidgetItem::sendJSEnterEvent() @@ -630,7 +624,7 @@ void UBGraphicsWidgetItem::mainFrameLoadFinished (bool ok) void UBGraphicsWidgetItem::wheelEvent(QGraphicsSceneWheelEvent *event) { - if (mDelegate->weelEvent(event)) + if (Delegate()->weelEvent(event)) { QGraphicsWebView::wheelEvent(event); event->accept(); @@ -647,7 +641,7 @@ QVariant UBGraphicsWidgetItem::itemChange(GraphicsItemChange change, const QVari scene()->setActiveWindow(0); } - QVariant newValue = mDelegate->itemChange(change, value); + QVariant newValue = Delegate()->itemChange(change, value); return QGraphicsWebView::itemChange(change, newValue); } @@ -662,8 +656,8 @@ void UBGraphicsWidgetItem::resize(const QSizeF & pSize) if (pSize != size()) { QGraphicsWebView::setMaximumSize(pSize.width(), pSize.height()); QGraphicsWebView::resize(pSize.width(), pSize.height()); - if (mDelegate) - mDelegate->positionHandles(); + if (Delegate()) + Delegate()->positionHandles(); if (scene()) scene()->setModified(true); } diff --git a/src/domain/UBGraphicsWidgetItem.h b/src/domain/UBGraphicsWidgetItem.h index ed11a3c8..10aeb2b7 100644 --- a/src/domain/UBGraphicsWidgetItem.h +++ b/src/domain/UBGraphicsWidgetItem.h @@ -57,8 +57,6 @@ class UBGraphicsWidgetItem : public QGraphicsWebView, public UBItem, public UBRe virtual void resize(const QSizeF & size); virtual QSizeF size() const; - virtual UBGraphicsItemDelegate* Delegate() const { return mDelegate;} - QUrl mainHtml(); void loadMainHtml(); QUrl widgetUrl(); @@ -82,7 +80,6 @@ class UBGraphicsWidgetItem : public QGraphicsWebView, public UBItem, public UBRe void removeDatastoreEntry(const QString& key); void removeAllDatastoreEntries(); - virtual void remove(); void removeScript(); void processDropEvent(QGraphicsSceneDragDropEvent *event); diff --git a/src/domain/UBItem.cpp b/src/domain/UBItem.cpp index 10d3d6ce..c9392e2f 100644 --- a/src/domain/UBItem.cpp +++ b/src/domain/UBItem.cpp @@ -38,6 +38,18 @@ UBItem::~UBItem() // NOOP } +UBGraphicsItem::~UBGraphicsItem() +{ + if (mDelegate!=NULL) + delete mDelegate; +} + +void UBGraphicsItem::setDelegate(UBGraphicsItemDelegate* delegate) +{ + Q_ASSERT(mDelegate==NULL); + mDelegate = delegate; +} + void UBGraphicsItem::assignZValue(QGraphicsItem *item, qreal value) { item->setZValue(value); @@ -54,6 +66,13 @@ bool UBGraphicsItem::isRotatable(QGraphicsItem *item) return item->data(UBGraphicsItemData::ItemRotatable).toBool(); } +void UBGraphicsItem::remove() +{ + if (Delegate()) + Delegate()->remove(this); +} + + UBGraphicsItemDelegate *UBGraphicsItem::Delegate(QGraphicsItem *pItem) { UBGraphicsItemDelegate *result = 0; diff --git a/src/domain/UBItem.h b/src/domain/UBItem.h index ca8a0f3b..99644f77 100644 --- a/src/domain/UBItem.h +++ b/src/domain/UBItem.h @@ -90,30 +90,30 @@ class UBItem class UBGraphicsItem { protected: - - UBGraphicsItem() : mDelegate(0) - { - // NOOP - } - UBGraphicsItemDelegate* mDelegate; - - virtual ~UBGraphicsItem() + UBGraphicsItem() : mDelegate(NULL) { // NOOP } + virtual ~UBGraphicsItem(); + void setDelegate(UBGraphicsItemDelegate* mDelegate); public: + inline UBGraphicsItemDelegate *Delegate() const { return mDelegate; } + static void assignZValue(QGraphicsItem*, qreal value); static bool isRotatable(QGraphicsItem *item); static bool isFlippable(QGraphicsItem *item); static UBGraphicsItemDelegate *Delegate(QGraphicsItem *pItem); - virtual UBGraphicsItemDelegate *Delegate() const = 0; + - virtual void remove() = 0; + void remove(); - virtual void clearSource(){;} + virtual void clearSource(){} + +private: + UBGraphicsItemDelegate* mDelegate; }; #endif // UBITEM_H diff --git a/src/tools/UBGraphicsCurtainItem.cpp b/src/tools/UBGraphicsCurtainItem.cpp index a84d0234..bdb06614 100644 --- a/src/tools/UBGraphicsCurtainItem.cpp +++ b/src/tools/UBGraphicsCurtainItem.cpp @@ -37,8 +37,9 @@ const QColor UBGraphicsCurtainItem::sDarkBackgroundOpaqueControlColor = QColor(6 UBGraphicsCurtainItem::UBGraphicsCurtainItem(QGraphicsItem* parent) : QGraphicsRectItem(parent) { - mDelegate = new UBGraphicsCurtainItemDelegate(this, 0); - mDelegate->init(); + UBGraphicsCurtainItemDelegate* delegate = new UBGraphicsCurtainItemDelegate(this, 0); + delegate->init(); + setDelegate(delegate); setFlag(QGraphicsItem::ItemIsMovable, true); setFlag(QGraphicsItem::ItemIsSelectable, true); @@ -56,7 +57,6 @@ UBGraphicsCurtainItem::UBGraphicsCurtainItem(QGraphicsItem* parent) UBGraphicsCurtainItem::~UBGraphicsCurtainItem() { - delete mDelegate; } QVariant UBGraphicsCurtainItem::itemChange(GraphicsItemChange change, const QVariant &value) @@ -64,9 +64,9 @@ QVariant UBGraphicsCurtainItem::itemChange(GraphicsItemChange change, const QVar QVariant newValue = value; - if (mDelegate) + if (Delegate()) { - newValue = mDelegate->itemChange(change, value); + newValue = Delegate()->itemChange(change, value); } return QGraphicsRectItem::itemChange(change, newValue); @@ -80,7 +80,7 @@ void UBGraphicsCurtainItem::setUuid(const QUuid &pUuid) void UBGraphicsCurtainItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (mDelegate->mousePressEvent(event)) + if (Delegate()->mousePressEvent(event)) { //NOOP } @@ -92,7 +92,7 @@ void UBGraphicsCurtainItem::mousePressEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsCurtainItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) { - if (mDelegate->mouseMoveEvent(event)) + if (Delegate()->mouseMoveEvent(event)) { // NOOP; } @@ -104,7 +104,7 @@ void UBGraphicsCurtainItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void UBGraphicsCurtainItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - mDelegate->mouseReleaseEvent(event); + Delegate()->mouseReleaseEvent(event); QGraphicsRectItem::mouseReleaseEvent(event); } @@ -171,13 +171,6 @@ QColor UBGraphicsCurtainItem::opaqueControlColor() const } -void UBGraphicsCurtainItem::remove() -{ - if (mDelegate) - mDelegate->remove(true); -} - - void UBGraphicsCurtainItem::triggerRemovedSignal() { emit removed(); diff --git a/src/tools/UBGraphicsCurtainItem.h b/src/tools/UBGraphicsCurtainItem.h index afef3960..9f5d36d4 100644 --- a/src/tools/UBGraphicsCurtainItem.h +++ b/src/tools/UBGraphicsCurtainItem.h @@ -44,11 +44,8 @@ class UBGraphicsCurtainItem : public QObject, public QGraphicsRectItem, public U virtual UBItem* deepCopy() const; virtual void copyItemParameters(UBItem *copy) const; - virtual void remove(); - //TODO UB 4.x not nice ... void triggerRemovedSignal(); - virtual UBGraphicsItemDelegate* Delegate() const {return mDelegate;} virtual void clearSource(){;} virtual void setUuid(const QUuid &pUuid); diff --git a/src/tools/UBGraphicsCurtainItemDelegate.h b/src/tools/UBGraphicsCurtainItemDelegate.h index e1435170..18523fd7 100644 --- a/src/tools/UBGraphicsCurtainItemDelegate.h +++ b/src/tools/UBGraphicsCurtainItemDelegate.h @@ -40,13 +40,12 @@ class UBGraphicsCurtainItemDelegate : public UBGraphicsItemDelegate virtual QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value); virtual void positionHandles(); + virtual void init(); + public slots: virtual void remove(bool checked, bool canUndo = true); - protected: - virtual void init(); - }; #endif /* UBGRAPHICSCURTAINITEMDELEGATE_H_ */ From a0ee46503f7d48e1e0bcc1fc72f3d8041118b65f Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Thu, 6 Sep 2012 19:37:44 +0300 Subject: [PATCH 09/15] Minor changes --- src/domain/domain.pri | 4 ++-- src/pdf-merger/Utils.cpp | 11 +++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/domain/domain.pri b/src/domain/domain.pri index a7dbb78d..bb3751e4 100644 --- a/src/domain/domain.pri +++ b/src/domain/domain.pri @@ -45,8 +45,8 @@ SOURCES += src/domain/UBGraphicsScene.cpp \ src/domain/UBGraphicsStroke.cpp \ src/domain/UBGraphicsMediaItem.cpp \ src/domain/UBAbstractUndoCommand.cpp \ - src/domain/ubgraphicsgroupcontaineritem.cpp \ - src/domain/ubgraphicsgroupcontaineritemdelegate.cpp \ + src/domain/UBGraphicsGroupContainerItem.cpp \ + src/domain/UBGraphicsGroupContainerItemDelegate.cpp \ src/domain/UBGraphicsStrokesGroup.cpp \ src/domain/UBGraphicsItemGroupUndoCommand.cpp \ src/domain/UBGraphicsItemDelegate.cpp \ diff --git a/src/pdf-merger/Utils.cpp b/src/pdf-merger/Utils.cpp index 44b3ec91..f1fe14c2 100644 --- a/src/pdf-merger/Utils.cpp +++ b/src/pdf-merger/Utils.cpp @@ -14,6 +14,7 @@ */ #include +#include #include "Config.h" #include "Utils.h" #include "Exception.h" @@ -65,18 +66,12 @@ double Utils::stringToDouble(const std::string & s ) std::string Utils::uIntToStr(unsigned int integer) { - char str[10]; - snprintf(str, sizeof(str), "%u", integer); - return std::string(str); - + return std::string(QString::number(integer).toAscii()); } std::string Utils::doubleToStr(double doubleValue) { - char str[16]; - snprintf(str, sizeof(str), "%f", doubleValue); - return std::string(str); - + return std::string(QString::number(doubleValue).toAscii()); } int Utils::_stringToInt(const std::string & str) //throw ConvertException From 2519df805b2fa581318558e161a6d1e068e859bf Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Fri, 7 Sep 2012 11:26:12 +0200 Subject: [PATCH 10/15] fixed issue 880 --- src/domain/UBGraphicsScene.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index f244bae8..6137033d 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1442,6 +1442,7 @@ UBGraphicsTextItem* UBGraphicsScene::textForObjectName(const QString& pString, c textItem->setObjectName(objectName); QSizeF size = textItem->size(); textItem->setPos(QPointF(-size.width()/2.0,-size.height()/2.0)); + textItem->setData(UBGraphicsItemData::ItemEditable,QVariant(false)); } textItem->setPlainText(pString); From 571109e386a5a2018274d2abe0dd9cfce9a68893 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Fri, 7 Sep 2012 13:19:48 +0200 Subject: [PATCH 11/15] fixed issue 1083 --- src/gui/UBTeacherGuideWidget.cpp | 6 ++++-- src/web/UBWebController.cpp | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gui/UBTeacherGuideWidget.cpp b/src/gui/UBTeacherGuideWidget.cpp index 679da6a8..09031a0c 100644 --- a/src/gui/UBTeacherGuideWidget.cpp +++ b/src/gui/UBTeacherGuideWidget.cpp @@ -163,7 +163,8 @@ UBTeacherGuideEditionWidget::~UBTeacherGuideEditionWidget() void UBTeacherGuideEditionWidget::onSliderMoved(int size) { Q_UNUSED(size); - mpAddAMediaItem->setExpanded(true); + if(mpAddAMediaItem) + mpAddAMediaItem->setExpanded(true); } #endif void UBTeacherGuideEditionWidget::showEvent(QShowEvent* event) @@ -491,7 +492,8 @@ UBTeacherGuidePresentationWidget::~UBTeacherGuidePresentationWidget() void UBTeacherGuidePresentationWidget::onSliderMoved(int size) { Q_UNUSED(size); - mpMediaSwitchItem->setExpanded(true); + if(mpMediaSwitchItem) + mpMediaSwitchItem->setExpanded(true); } #endif diff --git a/src/web/UBWebController.cpp b/src/web/UBWebController.cpp index 9ad0861e..e9d55be2 100644 --- a/src/web/UBWebController.cpp +++ b/src/web/UBWebController.cpp @@ -733,8 +733,8 @@ bool UBWebController::isEduMedia(const QUrl& pUrl) void UBWebController::loadUrl(const QUrl& url) { - bool webBrowserAlreadyInstanciated = dynamic_cast(mStackedWidget->widget(WebBrowser)) != NULL; - UBApplication::applicationController->showInternet(); + bool webBrowserAlreadyInstanciated = dynamic_cast(mStackedWidget->widget(WebBrowser)) != NULL; + UBApplication::applicationController->showInternet(); if (UBSettings::settings()->webUseExternalBrowser->get().toBool()) { QDesktopServices::openUrl(url); From cd010590edd98ed6c2bcab950558a6df312d6897 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Fri, 7 Sep 2012 14:40:19 +0200 Subject: [PATCH 12/15] fixed issue 1115 --- src/board/UBBoardController.cpp | 6 +++--- src/core/UBPersistenceManager.cpp | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index e83414f7..3a6a2394 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -645,7 +645,7 @@ void UBBoardController::duplicateItem(UBItem *item) { mActiveScene->addItem(gitem); gitem->setPos(itemPos); - mLastCreatedItem = gitem; + mLastCreatedItem = gitem; gitem->setSelected(true); } return; @@ -1132,7 +1132,7 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri QString destFile; bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(), - "", + sourceUrl.toString(), UBPersistenceManager::videoDirectory, uuid, destFile, @@ -1175,7 +1175,7 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri QString destFile; bool b = UBPersistenceManager::persistenceManager()->addFileToDocument(selectedDocument(), - "", + sourceUrl.toString(), UBPersistenceManager::audioDirectory, uuid, destFile, diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index 2c025a7c..62c1aca0 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -913,6 +913,7 @@ bool UBPersistenceManager::addFileToDocument(UBDocumentProxy* pDocumentProxy, QString& destinationPath, QByteArray* data) { + QAssert(path.length()); QFileInfo fi(path); if (!pDocumentProxy || objectUuid.isNull()) @@ -920,6 +921,8 @@ bool UBPersistenceManager::addFileToDocument(UBDocumentProxy* pDocumentProxy, if (data == NULL && !fi.exists()) return false; + qDebug() << fi.suffix(); + QString fileName = subdir + "/" + objectUuid.toString() + "." + fi.suffix(); destinationPath = pDocumentProxy->persistencePath() + "/" + fileName; From 9d21875c079efd09c6fb2d6608cd26eca5a0f6d5 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Fri, 7 Sep 2012 14:41:34 +0200 Subject: [PATCH 13/15] fixed issue 1115 --- src/core/UBPersistenceManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index 62c1aca0..44c534aa 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -913,7 +913,7 @@ bool UBPersistenceManager::addFileToDocument(UBDocumentProxy* pDocumentProxy, QString& destinationPath, QByteArray* data) { - QAssert(path.length()); + Q_ASSERT(path.length()); QFileInfo fi(path); if (!pDocumentProxy || objectUuid.isNull()) From f6693f4e854d52637388d1e89511afef184d9e6f Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Fri, 7 Sep 2012 19:36:50 +0300 Subject: [PATCH 14/15] Undo-redo stack for eraising operations and Sankore 834 --- src/adaptors/UBSvgSubsetAdaptor.cpp | 2 +- src/domain/UBGraphicsGroupContainerItem.cpp | 6 +- src/domain/UBGraphicsGroupContainerItem.h | 2 +- src/domain/UBGraphicsItemGroupUndoCommand.cpp | 4 +- src/domain/UBGraphicsItemUndoCommand.cpp | 66 ++++++++++++++++++- src/domain/UBGraphicsItemUndoCommand.h | 4 +- src/domain/UBGraphicsScene.cpp | 15 +++-- src/domain/UBGraphicsScene.h | 2 +- src/domain/UBItem.cpp | 6 ++ src/domain/UBItem.h | 1 + 10 files changed, 93 insertions(+), 15 deletions(-) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index f557ff8a..80f91e9d 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -1084,7 +1084,7 @@ QGraphicsItem *UBSvgSubsetAdaptor::UBSvgSubsetReader::readElementFromGroup() { QGraphicsItem *result = 0; - result = mScene->itemByUuid(QUuid(mXmlReader.attributes().value(aId).toString())); + result = mScene->itemForUuid(QUuid(mXmlReader.attributes().value(aId).toString())); mXmlReader.skipCurrentElement(); mXmlReader.readNext(); diff --git a/src/domain/UBGraphicsGroupContainerItem.cpp b/src/domain/UBGraphicsGroupContainerItem.cpp index 818eb88e..07b71ab3 100644 --- a/src/domain/UBGraphicsGroupContainerItem.cpp +++ b/src/domain/UBGraphicsGroupContainerItem.cpp @@ -125,6 +125,8 @@ void UBGraphicsGroupContainerItem::removeFromGroup(QGraphicsItem *item) pRemoveFromGroup(item); + item->setFlags(ItemIsSelectable | ItemIsFocusable); + } void UBGraphicsGroupContainerItem::deselectCurrentItem() @@ -219,7 +221,7 @@ void UBGraphicsGroupContainerItem::setUuid(const QUuid &pUuid) setData(UBGraphicsItemData::ItemUuid, QVariant(pUuid)); //store item uuid inside the QGraphicsItem to fast operations with Items on the scene } -void UBGraphicsGroupContainerItem::destroy() { +void UBGraphicsGroupContainerItem::destroy(bool canUndo) { foreach (QGraphicsItem *item, childItems()) { pRemoveFromGroup(item); @@ -227,7 +229,7 @@ void UBGraphicsGroupContainerItem::destroy() { item->setFlag(QGraphicsItem::ItemIsFocusable, true); } - remove(); + mDelegate->remove(canUndo); } void UBGraphicsGroupContainerItem::clearSource() diff --git a/src/domain/UBGraphicsGroupContainerItem.h b/src/domain/UBGraphicsGroupContainerItem.h index e8fa77eb..7207315d 100644 --- a/src/domain/UBGraphicsGroupContainerItem.h +++ b/src/domain/UBGraphicsGroupContainerItem.h @@ -37,7 +37,7 @@ public: } virtual void setUuid(const QUuid &pUuid); - void destroy(); + void destroy(bool canUndo = true); virtual void clearSource(); diff --git a/src/domain/UBGraphicsItemGroupUndoCommand.cpp b/src/domain/UBGraphicsItemGroupUndoCommand.cpp index 9b58dc1d..d087216f 100644 --- a/src/domain/UBGraphicsItemGroupUndoCommand.cpp +++ b/src/domain/UBGraphicsItemGroupUndoCommand.cpp @@ -22,7 +22,7 @@ UBGraphicsItemGroupUndoCommand::~UBGraphicsItemGroupUndoCommand() void UBGraphicsItemGroupUndoCommand::undo() { - mGroup->destroy(); + mGroup->destroy(false); foreach(QGraphicsItem *item, mItems) { item->setSelected(true); } @@ -41,7 +41,7 @@ void UBGraphicsItemGroupUndoCommand::redo() QList childItems = item->childItems(); UBGraphicsGroupContainerItem *currentGroup = dynamic_cast(item); if (currentGroup) { - currentGroup->destroy(); + currentGroup->destroy(false); } foreach (QGraphicsItem *chItem, childItems) { mGroup->addToGroup(chItem); diff --git a/src/domain/UBGraphicsItemUndoCommand.cpp b/src/domain/UBGraphicsItemUndoCommand.cpp index d9961fa0..64ea6091 100644 --- a/src/domain/UBGraphicsItemUndoCommand.cpp +++ b/src/domain/UBGraphicsItemUndoCommand.cpp @@ -27,10 +27,11 @@ #include "domain/UBGraphicsGroupContainerItem.h" UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet& pRemovedItems, - const QSet& pAddedItems) + const QSet& pAddedItems, const QMultiMap &groupsMap) : mScene(pScene) - , mRemovedItems(pRemovedItems - pAddedItems) - , mAddedItems(pAddedItems - pRemovedItems) + , mRemovedItems(pRemovedItems - pAddedItems) + , mAddedItems(pAddedItems - pRemovedItems) + , mExcludedFromGroup(groupsMap) { mFirstRedo = true; @@ -110,6 +111,36 @@ void UBGraphicsItemUndoCommand::undo() } } + QMapIterator curMapElement(mExcludedFromGroup); + UBGraphicsGroupContainerItem *nextGroup = 0; + UBGraphicsGroupContainerItem *previousGroupItem; + bool groupChanged = false; + + while (curMapElement.hasNext()) { + curMapElement.next(); + + groupChanged = previousGroupItem != curMapElement.key(); + //trying to find the group on the scene; + if (!nextGroup || groupChanged) { + UBGraphicsGroupContainerItem *groupCandidate = curMapElement.key(); + if (groupCandidate) { + nextGroup = groupCandidate; + if(!mScene->items().contains(nextGroup)) { + mScene->addItem(nextGroup); + } + nextGroup->setVisible(true); + } + } + + QGraphicsItem *groupedItem = mScene->itemForUuid(curMapElement.value()); + if (groupedItem) { + nextGroup->addToGroup(groupedItem); + } + + previousGroupItem = curMapElement.key(); + UBGraphicsItem::Delegate(nextGroup)->update(); + } + // force refresh, QT is a bit lazy and take a lot of time (nb item ^2 ?) to trigger repaint mScene->update(mScene->sceneRect()); @@ -125,6 +156,35 @@ void UBGraphicsItemUndoCommand::redo() return; } + QMapIterator curMapElement(mExcludedFromGroup); + UBGraphicsGroupContainerItem *nextGroup = 0; + UBGraphicsGroupContainerItem *previousGroupItem; + bool groupChanged = false; + + while (curMapElement.hasNext()) { + curMapElement.next(); + + groupChanged = previousGroupItem != curMapElement.key(); + //trying to find the group on the scene; + if (!nextGroup || groupChanged) { + UBGraphicsGroupContainerItem *groupCandidate = curMapElement.key(); + if (groupCandidate) { + nextGroup = groupCandidate; + } + } + QGraphicsItem *groupedItem = mScene->itemForUuid(curMapElement.value()); + if (groupedItem) { + if (nextGroup->childItems().count() == 1) { + nextGroup->destroy(false); + break; + } + nextGroup->removeFromGroup(groupedItem); + } + + previousGroupItem = curMapElement.key(); + UBGraphicsItem::Delegate(nextGroup)->update(); + } + QSetIterator itRemoved(mRemovedItems); while (itRemoved.hasNext()) { diff --git a/src/domain/UBGraphicsItemUndoCommand.h b/src/domain/UBGraphicsItemUndoCommand.h index 78e7ec9a..be8fa9d4 100644 --- a/src/domain/UBGraphicsItemUndoCommand.h +++ b/src/domain/UBGraphicsItemUndoCommand.h @@ -18,6 +18,7 @@ #include #include "UBAbstractUndoCommand.h" +#include "UBGraphicsGroupContainerItem.h" class UBGraphicsScene; @@ -27,7 +28,7 @@ class UBGraphicsItemUndoCommand : public UBAbstractUndoCommand { public: UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet& pRemovedItems, - const QSet& pAddedItems); + const QSet& pAddedItems, const QMultiMap &groupsMap = QMultiMap()); UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, QGraphicsItem* pRemovedItem, QGraphicsItem* pAddedItem); @@ -47,6 +48,7 @@ class UBGraphicsItemUndoCommand : public UBAbstractUndoCommand UBGraphicsScene* mScene; QSet mRemovedItems; QSet mAddedItems; + QMultiMap mExcludedFromGroup; bool mFirstRedo; }; diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 0cdb2ae6..ecbcc424 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1067,6 +1067,7 @@ UBItem* UBGraphicsScene::deepCopy() const void UBGraphicsScene::clearContent(clearCase pCase) { QSet removedItems; + QMultiMap groupsMap; switch (pCase) { case clearBackground : @@ -1106,8 +1107,13 @@ void UBGraphicsScene::clearContent(clearCase pCase) if(shouldDelete) { if (itemGroup) { itemGroup->removeFromGroup(item); + groupsMap.insert(itemGroup, UBGraphicsItem::getOwnUuid(item)); if (itemGroup->childItems().count() == 1) { - itemGroup->destroy(); + groupsMap.insert(itemGroup, UBGraphicsItem::getOwnUuid(itemGroup->childItems().first())); + QGraphicsItem *lastItem = itemGroup->childItems().first(); + bool isSelected = itemGroup->isSelected(); + itemGroup->destroy(false); + lastItem->setSelected(isSelected); } itemGroup->Delegate()->update(); } @@ -1123,7 +1129,7 @@ void UBGraphicsScene::clearContent(clearCase pCase) update(sceneRect()); if (enableUndoRedoStack) { //should be deleted after scene own undo stack implemented - UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, removedItems, QSet()); + UBGraphicsItemUndoCommand* uc = new UBGraphicsItemUndoCommand(this, removedItems, QSet(), groupsMap); UBApplication::undoStack->push(uc); } @@ -1571,8 +1577,9 @@ void UBGraphicsScene::removeItem(QGraphicsItem* item) void UBGraphicsScene::removeItems(const QSet& items) { - foreach(QGraphicsItem* item, items) + foreach(QGraphicsItem* item, items) { UBCoreGraphicsScene::removeItem(item); + } mItemCount -= items.size(); @@ -1665,7 +1672,7 @@ QRectF UBGraphicsScene::normalizedSceneRect(qreal ratio) return normalizedRect; } -QGraphicsItem *UBGraphicsScene::itemByUuid(QUuid uuid) +QGraphicsItem *UBGraphicsScene::itemForUuid(QUuid uuid) { QGraphicsItem *result = 0; diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 0dedb9c1..3722d8be 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -174,7 +174,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem QRectF normalizedSceneRect(qreal ratio = -1.0); - QGraphicsItem *itemByUuid(QUuid uuid); + QGraphicsItem *itemForUuid(QUuid uuid); void moveTo(const QPointF& pPoint); void drawLineTo(const QPointF& pEndPoint, const qreal& pWidth, bool bLineStyle); diff --git a/src/domain/UBItem.cpp b/src/domain/UBItem.cpp index 10d3d6ce..e7083338 100644 --- a/src/domain/UBItem.cpp +++ b/src/domain/UBItem.cpp @@ -54,6 +54,12 @@ bool UBGraphicsItem::isRotatable(QGraphicsItem *item) return item->data(UBGraphicsItemData::ItemRotatable).toBool(); } +QUuid UBGraphicsItem::getOwnUuid(QGraphicsItem *item) +{ + QString idCandidate = item->data(UBGraphicsItemData::ItemUuid).toString(); + return idCandidate == QUuid().toString() ? QUuid() : QUuid(idCandidate); +} + UBGraphicsItemDelegate *UBGraphicsItem::Delegate(QGraphicsItem *pItem) { UBGraphicsItemDelegate *result = 0; diff --git a/src/domain/UBItem.h b/src/domain/UBItem.h index ca8a0f3b..2fe22ae8 100644 --- a/src/domain/UBItem.h +++ b/src/domain/UBItem.h @@ -107,6 +107,7 @@ public: static void assignZValue(QGraphicsItem*, qreal value); static bool isRotatable(QGraphicsItem *item); static bool isFlippable(QGraphicsItem *item); + static QUuid getOwnUuid(QGraphicsItem *item); static UBGraphicsItemDelegate *Delegate(QGraphicsItem *pItem); virtual UBGraphicsItemDelegate *Delegate() const = 0; From 46b81abe15d84ed116544102998421be779e75d5 Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Mon, 10 Sep 2012 11:41:34 +0300 Subject: [PATCH 15/15] typedef for QMultiMap specified --- src/domain/UBGraphicsItemUndoCommand.cpp | 2 +- src/domain/UBGraphicsItemUndoCommand.h | 6 ++++-- src/domain/UBGraphicsScene.cpp | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/domain/UBGraphicsItemUndoCommand.cpp b/src/domain/UBGraphicsItemUndoCommand.cpp index 64ea6091..c8637242 100644 --- a/src/domain/UBGraphicsItemUndoCommand.cpp +++ b/src/domain/UBGraphicsItemUndoCommand.cpp @@ -27,7 +27,7 @@ #include "domain/UBGraphicsGroupContainerItem.h" UBGraphicsItemUndoCommand::UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet& pRemovedItems, - const QSet& pAddedItems, const QMultiMap &groupsMap) + const QSet& pAddedItems, const GroupDataTable &groupsMap) : mScene(pScene) , mRemovedItems(pRemovedItems - pAddedItems) , mAddedItems(pAddedItems - pRemovedItems) diff --git a/src/domain/UBGraphicsItemUndoCommand.h b/src/domain/UBGraphicsItemUndoCommand.h index be8fa9d4..fec45d4f 100644 --- a/src/domain/UBGraphicsItemUndoCommand.h +++ b/src/domain/UBGraphicsItemUndoCommand.h @@ -27,8 +27,10 @@ class UBGraphicsScene; class UBGraphicsItemUndoCommand : public UBAbstractUndoCommand { public: + typedef QMultiMap GroupDataTable; + UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, const QSet& pRemovedItems, - const QSet& pAddedItems, const QMultiMap &groupsMap = QMultiMap()); + const QSet& pAddedItems, const GroupDataTable &groupsMap = GroupDataTable()); UBGraphicsItemUndoCommand(UBGraphicsScene* pScene, QGraphicsItem* pRemovedItem, QGraphicsItem* pAddedItem); @@ -48,7 +50,7 @@ class UBGraphicsItemUndoCommand : public UBAbstractUndoCommand UBGraphicsScene* mScene; QSet mRemovedItems; QSet mAddedItems; - QMultiMap mExcludedFromGroup; + GroupDataTable mExcludedFromGroup; bool mFirstRedo; }; diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 0e476dea..352d0f2a 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1067,7 +1067,7 @@ UBItem* UBGraphicsScene::deepCopy() const void UBGraphicsScene::clearContent(clearCase pCase) { QSet removedItems; - QMultiMap groupsMap; + UBGraphicsItemUndoCommand::GroupDataTable groupsMap; switch (pCase) { case clearBackground :