From 9ed62340ac7f30e1365f29924383087758ad9172 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Sat, 5 May 2012 09:58:05 +0200 Subject: [PATCH] first implementation of title on scene --- src/domain/UBGraphicsScene.cpp | 64 ++++++++++++++++++++++---------- src/domain/UBGraphicsScene.h | 9 +++-- src/gui/UBTeacherGuideWidget.cpp | 46 ++++++++++++++++++++--- src/gui/UBTeacherGuideWidget.h | 4 +- 4 files changed, 92 insertions(+), 31 deletions(-) diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 1494ce85..e6dbdd1b 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -396,15 +396,15 @@ bool UBGraphicsScene::inputDevicePress(const QPointF& scenePos, const qreal& pre mAddedItems.clear(); mRemovedItems.clear(); - if (UBDrawingController::drawingController()->mActiveRuler) + if (UBDrawingController::drawingController()->mActiveRuler) { UBDrawingController::drawingController()->mActiveRuler->StartLine(scenePos, width); - } - else - { - moveTo(scenePos); + } + else + { + moveTo(scenePos); drawLineTo(scenePos, width, UBDrawingController::drawingController()->stylusTool() == UBStylusTool::Line); - } + } accepted = true; } else if (currentTool == UBStylusTool::Eraser) @@ -590,8 +590,8 @@ bool UBGraphicsScene::inputDeviceRelease() mCurrentStroke = 0; } } - } - + } + if (mRemovedItems.size() > 0 || mAddedItems.size() > 0) { @@ -654,7 +654,7 @@ void UBGraphicsScene::drawPointer(const QPointF &pPoint, bool isFirstDraw) // call this function when user release mouse button in Magnifier mode void UBGraphicsScene::DisposeMagnifierQWidgets() { - if(magniferControlViewWidget) + if(magniferControlViewWidget) { magniferControlViewWidget->hide(); magniferControlViewWidget->setParent(0); @@ -662,7 +662,7 @@ void UBGraphicsScene::DisposeMagnifierQWidgets() magniferControlViewWidget = NULL; } - if(magniferDisplayViewWidget) + if(magniferDisplayViewWidget) { magniferDisplayViewWidget->hide(); magniferDisplayViewWidget->setParent(0); @@ -679,7 +679,7 @@ void UBGraphicsScene::DisposeMagnifierQWidgets() catch (...) { } - + } void UBGraphicsScene::moveTo(const QPointF &pPoint) @@ -711,7 +711,7 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth, } } - if (bLineStyle) + if (bLineStyle) { QSetIterator itItems(mAddedItems); @@ -736,7 +736,7 @@ void UBGraphicsScene::drawLineTo(const QPointF &pEndPoint, const qreal &pWidth, mPreviousPolygonItems.append(polygonItem); - if (!bLineStyle) + if (!bLineStyle) { mPreviousPoint = pEndPoint; mPreviousWidth = pWidth; @@ -1473,6 +1473,30 @@ UBGraphicsTextItem* UBGraphicsScene::addText(const QString& pString, const QPoin , UBSettings::settings()->isItalicFont()); } +UBGraphicsTextItem* UBGraphicsScene::textForObjectName(const QString& pString, const QString& objectName) +{ + UBGraphicsTextItem* textItem = 0; + bool found = false; + //looking for a previous such item text + for(int i=0; i < mFastAccessItems.count() && !found ; i += 1){ + UBGraphicsTextItem* currentItem = dynamic_cast(mFastAccessItems.at(i)); + if(currentItem && currentItem->objectName() == objectName){ + textItem = currentItem; + found=true; + } + } + if(!textItem){ + textItem = addTextWithFont(pString,QPointF(0,0) ,64,"",true,false); + textItem->setObjectName(objectName); + textItem->Delegate()->setCanDuplicate(false); + } + + textItem->setPlainText(pString); + textItem->adjustSize(); + QSizeF size = textItem->size(); + textItem->setPos(QPointF(-size.width()/2.0,-size.height()/2.0)); + return textItem; +} UBGraphicsTextItem* UBGraphicsScene::addTextWithFont(const QString& pString, const QPointF& pTopLeft , int pointSize, const QString& fontFamily, bool bold, bool italic) @@ -1926,11 +1950,11 @@ void UBGraphicsScene::addCache() } void UBGraphicsScene::addMask(const QPointF ¢er) -{ +{ UBGraphicsCurtainItem* curtain = new UBGraphicsCurtainItem(); // mem : owned and destroyed by the scene mTools << curtain; - addItem(curtain); + addItem(curtain); QRectF rect = UBApplication::boardController->activeScene()->normalizedSceneRect(); rect.setRect(center.x() - rect.width()/4, center.y() - rect.height()/4, rect.width()/2 , rect.height()/2); @@ -2010,7 +2034,7 @@ void UBGraphicsScene::setNominalSize(int pWidth, int pHeight) } void UBGraphicsScene::setSelectedZLevel(QGraphicsItem * item) -{ +{ item->setZValue(mZLayerController->generateZLevel(itemLayerType::SelectedItem)); } void UBGraphicsScene::setOwnZlevel(QGraphicsItem *item) @@ -2180,7 +2204,7 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent) UBGraphicsW3CWidgetItem *wc3_widget = dynamic_cast(item); if (0 != wc3_widget) if (!wc3_widget->hasFocus()) - wc3_widget->remove(); + wc3_widget->remove(); break; } case UBGraphicsAppleWidgetItem::Type: @@ -2188,7 +2212,7 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent) UBGraphicsAppleWidgetItem *Apple_widget = dynamic_cast(item); if (0 !=Apple_widget) if (!Apple_widget->hasFocus()) - Apple_widget->remove(); + Apple_widget->remove(); break; } case UBGraphicsTextItem::Type: @@ -2196,7 +2220,7 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent) UBGraphicsTextItem *text_item = dynamic_cast(item); if (0 != text_item) if (!text_item->hasFocus()) - text_item->remove(); + text_item->remove(); break; } @@ -2206,7 +2230,7 @@ void UBGraphicsScene::keyReleaseEvent(QKeyEvent * keyEvent) if (0 != ubgi) ubgi->remove(); else - UBCoreGraphicsScene::removeItem(item); + UBCoreGraphicsScene::removeItem(item); } } } diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 4b9d946f..b8de208b 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -133,6 +133,7 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem UBGraphicsAudioItem* addAudio(const QUrl& pAudioFileUrl, bool shouldPlayAsap, const QPointF& pPos = QPointF(0, 0)); UBGraphicsSvgItem* addSvg(const QUrl& pSvgFileUrl, const QPointF& pPos = QPointF(0, 0)); UBGraphicsTextItem* addText(const QString& pString, const QPointF& pTopLeft = QPointF(0, 0)); + UBGraphicsTextItem* textForObjectName(const QString& pString, const QString &objectName = "UBTGZeroPageSessionTitle"); UBGraphicsTextItem* addTextWithFont(const QString& pString, const QPointF& pTopLeft = QPointF(0, 0) , int pointSize = -1, const QString& fontFamily = "", bool bold = false, bool italic = false); @@ -280,10 +281,10 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem mTools << item; } - const QPointF& previousPoint() - { - return mPreviousPoint; - } + const QPointF& previousPoint() + { + return mPreviousPoint; + } void setSelectedZLevel(QGraphicsItem *item); void setOwnZlevel(QGraphicsItem *item); diff --git a/src/gui/UBTeacherGuideWidget.cpp b/src/gui/UBTeacherGuideWidget.cpp index 51c4017d..b7022a73 100644 --- a/src/gui/UBTeacherGuideWidget.cpp +++ b/src/gui/UBTeacherGuideWidget.cpp @@ -43,6 +43,8 @@ #include "document/UBDocumentProxy.h" #include "document/UBDocumentController.h" +#include "domain/UBGraphicsTextItem.h" + #define UBTG_SEPARATOR_FIXED_HEIGHT 3 typedef enum @@ -193,6 +195,8 @@ QDomElement* UBTeacherGuideEditionWidget::save(QDomElement* parentElement) void UBTeacherGuideEditionWidget::onActiveSceneChanged() { + load(UBSvgSubsetAdaptor::sTeacherGuideNode); + qDebug() << "UBSvgSubsetAdaptor::sTeacherGuideNode " << UBSvgSubsetAdaptor::sTeacherGuideNode; mpPageNumberLabel->setText(tr("Page: %0").arg(UBApplication::boardController->currentPage())); UBDocumentProxy* documentProxy = UBApplication::boardController->activeDocument(); if(mpDocumentTitle) @@ -565,8 +569,10 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons , mpLicenceBox(NULL) , mpLicenceIcon(NULL) , mpLicenceLayout(NULL) + , mpSceneItemSessionTitle(NULL) { setObjectName(name); + QString chapterStyle("QLabel {font-size:16px; font-weight:bold;}"); mpLayout = new QVBoxLayout(this); mpPageNumberLabel = new QLabel(this); @@ -586,7 +592,6 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpSessionTitle = new UBTGAdaptableText(0,this,"UBTGSessionTitle"); mpSessionTitle->setPlaceHolderText(tr("Type session title here ...")); - //mpSessionTitle->setObjectName("UBTGSessionTitle"); mpButtonTitleLayout->addWidget(mpSessionTitle); mpLayout->addLayout(mpButtonTitleLayout); @@ -599,6 +604,7 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpAuthorsLabel = new QLabel(this); mpAuthorsLabel->setObjectName("UBTGZeroPageEditionModeTitle"); mpAuthorsLabel->setText(tr("Author(s)")); + mpAuthorsLabel->setStyleSheet(chapterStyle); mpLayout->addWidget(mpAuthorsLabel); mpAuthors = new UBTGAdaptableText(0,this); @@ -622,6 +628,7 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpGoalsLabel = new QLabel(this); mpGoalsLabel->setObjectName("UBTGZeroPageEditionModeTitle"); mpGoalsLabel->setText(tr("Goal(s)")); + mpGoalsLabel->setStyleSheet(chapterStyle); mpLayout->addWidget(mpGoalsLabel); mpGoals = new UBTGAdaptableText(0,this); @@ -637,11 +644,13 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpIndexLabel = new QLabel(this); mpIndexLabel->setObjectName("UBTGZeroPageEditionModeTitle"); mpIndexLabel->setText(tr("Resource indexing")); + mpIndexLabel->setStyleSheet(chapterStyle); mpLayout->addWidget(mpIndexLabel); mpKeywordsLabel = new QLabel(this); mpKeywordsLabel->setObjectName("UBTGZeroPageItemLabel"); mpKeywordsLabel->setText(tr("Keywords:")); + mpKeywordsLabel->setStyleSheet(chapterStyle); mpLayout->addWidget(mpKeywordsLabel); mpKeywords = new UBTGAdaptableText(0,this); mpKeywords->setPlaceHolderText(tr("Type keywords here ...")); @@ -650,6 +659,7 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpSchoolLevelItemLabel = new QLabel(this); mpSchoolLevelItemLabel->setObjectName("UBTGZeroPageItemLabel"); mpSchoolLevelItemLabel->setText(tr("Level:")); + mpSchoolLevelItemLabel->setStyleSheet(chapterStyle); mpLayout->addWidget(mpSchoolLevelItemLabel); mpSchoolLevelBox = new QComboBox(this); mpSchoolLevelBox->setObjectName("DockPaletteWidgetComboBox"); @@ -661,6 +671,7 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpSchoolBranchItemLabel = new QLabel(this); mpSchoolBranchItemLabel->setObjectName("UBTGZeroPageItemLabel"); mpSchoolBranchItemLabel->setText(tr("Branch:")); + mpSchoolBranchItemLabel->setStyleSheet(chapterStyle); mpLayout->addWidget(mpSchoolBranchItemLabel); mpSchoolBranchBox = new QComboBox(this); mpSchoolBranchBox->setObjectName("DockPaletteWidgetComboBox"); @@ -671,6 +682,7 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpSchoolTypeItemLabel = new QLabel(this); mpSchoolTypeItemLabel->setObjectName("UBTGZeroPageItemLabel"); mpSchoolTypeItemLabel->setText(tr("Type:")); + mpSchoolTypeItemLabel->setStyleSheet(chapterStyle); mpLayout->addWidget(mpSchoolTypeItemLabel); mpSchoolTypeBox = new QComboBox(this); mpSchoolTypeBox->setObjectName("DockPaletteWidgetComboBox"); @@ -685,7 +697,8 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpLicenceLabel = new QLabel(this); mpLicenceLabel->setObjectName("UBTGZeroPageItemLabel"); - mpLicenceLabel->setText(tr("Licence:")); + mpLicenceLabel->setText(tr("Licence")); + mpLicenceLabel->setStyleSheet(chapterStyle); mpLayout->addWidget(mpLicenceLabel); mpLicenceBox = new QComboBox(this); mpLicenceBox->setObjectName("DockPaletteWidgetComboBox"); @@ -697,6 +710,8 @@ UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(QWidget* parent, cons mpLicenceLayout->addWidget(mpLicenceValueLabel); mpLayout->addLayout(mpLicenceLayout); mpLayout->addStretch(1); + + setLayout(mpLayout); connect(UBApplication::boardController,SIGNAL(activeSceneChanged()), this, SLOT(onActiveSceneChanged())); fillComboBoxes(); } @@ -810,10 +825,11 @@ void UBTeacherGuidePageZeroWidget::onActiveSceneChanged() UBDocumentProxy* documentProxy = UBApplication::boardController->activeDocument(); if(documentProxy && UBApplication::boardController->currentPage() == 0){ QDateTime creationDate = documentProxy->documentDate(); - mpCreationLabel->setText(tr("Created the: ") + creationDate.toString(Qt::SystemLocaleShortDate)); + mpCreationLabel->setText(tr("Created the:\n") + creationDate.toString(Qt::SystemLocaleShortDate)); QDateTime updatedDate = documentProxy->lastUpdate(); - mpLastModifiedLabel->setText(tr("Updated the: ") + updatedDate.toString(Qt::SystemLocaleShortDate)); + mpLastModifiedLabel->setText(tr("Updated the:\n") + updatedDate.toString(Qt::SystemLocaleShortDate)); loadData(); + UBApplication::boardController->activeScene()->textForObjectName(mpSessionTitle->text()); } } @@ -860,12 +876,18 @@ void UBTeacherGuidePageZeroWidget::persistData() void UBTeacherGuidePageZeroWidget::switchToMode(tUBTGZeroPageMode mode) { if(mode == tUBTGZeroPageMode_EDITION){ + QString inputStyleSheet("QTextEdit { background: white; border-radius: 10px; border: 2px;}"); mpModePushButton->hide(); mpSessionTitle->setReadOnly(false); - mpSessionTitle->setObjectName("UBTGEditionModeSessionTitle"); + mpSessionTitle->setStyleSheet(inputStyleSheet); + QFont titleFont(QApplication::font().family(),11,-1); + mpSessionTitle->document()->setDefaultFont(titleFont); mpAuthors->setReadOnly(false); + mpAuthors->setStyleSheet(inputStyleSheet); mpGoals->setReadOnly(false); + mpGoals->setStyleSheet(inputStyleSheet); mpKeywords->setReadOnly(false); + mpKeywords->setStyleSheet(inputStyleSheet); mpSchoolLevelValueLabel->hide(); mpSchoolLevelBox->show(); mpSchoolBranchValueLabel->hide(); @@ -877,12 +899,23 @@ void UBTeacherGuidePageZeroWidget::switchToMode(tUBTGZeroPageMode mode) mpLicenceBox->show(); } else{ + QString inputStyleSheet("QTextEdit { background: transparent; border: none;}"); mpModePushButton->show(); mpSessionTitle->setReadOnly(true); - mpSessionTitle->setObjectName("UBTGPresentationSessionTitle"); + UBApplication::boardController->activeScene()->textForObjectName(mpSessionTitle->text()); + mpSessionTitle->setStyleSheet(inputStyleSheet); + mpSessionTitle->setTextColor(QColor(Qt::black)); + QFont titleFont(QApplication::font().family(),14,1); + mpSessionTitle->document()->setDefaultFont(titleFont); mpAuthors->setReadOnly(true); + mpAuthors->setStyleSheet(inputStyleSheet); + mpAuthors->setTextColor(QColor(Qt::black)); mpGoals->setReadOnly(true); + mpGoals->setStyleSheet(inputStyleSheet); + mpGoals->setTextColor(QColor(Qt::black)); mpKeywords->setReadOnly(true); + mpKeywords->setStyleSheet(inputStyleSheet); + mpKeywords->setTextColor(QColor(Qt::black)); mpSchoolLevelValueLabel->setText(mpSchoolLevelBox->currentText()); mpSchoolLevelValueLabel->show(); mpSchoolLevelBox->hide(); @@ -902,6 +935,7 @@ void UBTeacherGuidePageZeroWidget::switchToMode(tUBTGZeroPageMode mode) mpLicenceBox->hide(); persistData(); } + update(); } QVector UBTeacherGuidePageZeroWidget::getData() diff --git a/src/gui/UBTeacherGuideWidget.h b/src/gui/UBTeacherGuideWidget.h index bd43b8b2..c8ed2574 100644 --- a/src/gui/UBTeacherGuideWidget.h +++ b/src/gui/UBTeacherGuideWidget.h @@ -22,6 +22,7 @@ class QLabel; class QVBoxLayout; class QPushButton; class UBDocumentProxy; +class UBGraphicsTextItem; #include "UBTeacherGuideWidgetsTools.h" @@ -175,6 +176,8 @@ private: QLabel* mpLicenceIcon; QHBoxLayout* mpLicenceLayout; + UBGraphicsTextItem* mpSceneItemSessionTitle; + QMap mGradeLevelsMap; QMap mSubjects; @@ -205,7 +208,6 @@ private: UBTeacherGuideEditionWidget* mpEditionWidget; UBTeacherGuidePresentationWidget* mpPresentationWidget; QVectormCurrentData; - }; #endif // UBTEACHERGUIDEWIDGET_H