From def5f7f7193e74ded5c6fb5741397a6d10c0f488 Mon Sep 17 00:00:00 2001 From: Craig Watson Date: Fri, 2 Sep 2016 22:44:46 -0400 Subject: [PATCH] Added ruled background --- resources/OpenBoard.qrc | 4 + resources/forms/mainWindow.ui | 38 +++++ .../images/backgroundPalette/background5.svg | 146 +++++++++++++++++ .../backgroundPalette/background5On.svg | 149 +++++++++++++++++ .../images/backgroundPalette/background6.svg | 146 +++++++++++++++++ .../backgroundPalette/background6On.svg | 150 ++++++++++++++++++ src/adaptors/UBExportFullPDF.cpp | 6 +- src/adaptors/UBExportPDF.cpp | 6 +- src/adaptors/UBSvgSubsetAdaptor.cpp | 37 ++++- src/api/UBWidgetUniboardAPI.cpp | 8 +- src/board/UBBoardController.cpp | 47 ++++-- src/board/UBBoardController.h | 4 +- src/board/UBBoardPaletteManager.cpp | 21 ++- src/board/UBBoardView.cpp | 12 +- src/core/UB.h | 7 + src/core/UBApplicationController.cpp | 2 +- src/core/UBPersistenceManager.cpp | 2 +- src/core/UBSettings.cpp | 28 +++- src/core/UBSettings.h | 4 +- src/desktop/UBDesktopAnnotationController.cpp | 4 +- src/domain/UBGraphicsScene.cpp | 22 ++- src/domain/UBGraphicsScene.h | 8 +- 22 files changed, 797 insertions(+), 54 deletions(-) create mode 100644 resources/images/backgroundPalette/background5.svg create mode 100644 resources/images/backgroundPalette/background5On.svg create mode 100644 resources/images/backgroundPalette/background6.svg create mode 100644 resources/images/backgroundPalette/background6On.svg diff --git a/resources/OpenBoard.qrc b/resources/OpenBoard.qrc index 07f0d10a..1a2f3d1e 100644 --- a/resources/OpenBoard.qrc +++ b/resources/OpenBoard.qrc @@ -159,6 +159,10 @@ images/backgroundPalette/background3On.svg images/backgroundPalette/background4.svg images/backgroundPalette/background4On.svg + images/backgroundPalette/background5.svg + images/backgroundPalette/background5On.svg + images/backgroundPalette/background6.svg + images/backgroundPalette/background6On.svg images/toolPalette/podcast.svg images/toolPalette/podcastOn.svg images/toolPalette/rulerTool.png diff --git a/resources/forms/mainWindow.ui b/resources/forms/mainWindow.ui index 287d4e0a..d1c27a4b 100644 --- a/resources/forms/mainWindow.ui +++ b/resources/forms/mainWindow.ui @@ -1004,6 +1004,25 @@ Grid Light Background + + + true + + + + :/images/backgroundPalette/background5.svg + :/images/backgroundPalette/background5On.svg:/images/backgroundPalette/background5.svg + + + Ruled Light Background + + + Light + + + Ruled Light Background + + true @@ -1042,6 +1061,25 @@ Grid Dark Background + + + true + + + + :/images/backgroundPalette/background6.svg + :/images/backgroundPalette/background6On.svg:/images/backgroundPalette/background6.svg + + + Ruled Dark Background + + + Dark + + + Ruled Dark Background + + true diff --git a/resources/images/backgroundPalette/background5.svg b/resources/images/backgroundPalette/background5.svg new file mode 100644 index 00000000..ac6e870e --- /dev/null +++ b/resources/images/backgroundPalette/background5.svg @@ -0,0 +1,146 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/resources/images/backgroundPalette/background5On.svg b/resources/images/backgroundPalette/background5On.svg new file mode 100644 index 00000000..25d0a1c3 --- /dev/null +++ b/resources/images/backgroundPalette/background5On.svg @@ -0,0 +1,149 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/resources/images/backgroundPalette/background6.svg b/resources/images/backgroundPalette/background6.svg new file mode 100644 index 00000000..1c38545b --- /dev/null +++ b/resources/images/backgroundPalette/background6.svg @@ -0,0 +1,146 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/resources/images/backgroundPalette/background6On.svg b/resources/images/backgroundPalette/background6On.svg new file mode 100644 index 00000000..1210a251 --- /dev/null +++ b/resources/images/backgroundPalette/background6On.svg @@ -0,0 +1,150 @@ + + + +image/svg+xml \ No newline at end of file diff --git a/src/adaptors/UBExportFullPDF.cpp b/src/adaptors/UBExportFullPDF.cpp index 64b989a0..9b6684f0 100644 --- a/src/adaptors/UBExportFullPDF.cpp +++ b/src/adaptors/UBExportFullPDF.cpp @@ -97,8 +97,8 @@ void UBExportFullPDF::saveOverlayPdf(UBDocumentProxy* pDocumentProxy, const QStr UBGraphicsScene* scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocumentProxy, pageIndex); // set background to white, no grid for PDF output bool isDark = scene->isDarkBackground(); - bool isCrossed = scene->isCrossedBackground(); - scene->setBackground(false, false); + UBPageBackground pageBackground = scene->pageBackground(); + scene->setBackground(false, UBPageBackground::plain); // set high res rendering scene->setRenderingQuality(UBItem::RenderingQualityHigh); @@ -126,7 +126,7 @@ void UBExportFullPDF::saveOverlayPdf(UBDocumentProxy* pDocumentProxy, const QStr //restore background state scene->setDrawingMode(false); - scene->setBackground(isDark, isCrossed); + scene->setBackground(isDark, pageBackground); } if (pdfPainter) delete pdfPainter; diff --git a/src/adaptors/UBExportPDF.cpp b/src/adaptors/UBExportPDF.cpp index ad9aaa5a..9f70c57b 100644 --- a/src/adaptors/UBExportPDF.cpp +++ b/src/adaptors/UBExportPDF.cpp @@ -91,8 +91,8 @@ bool UBExportPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QStrin UBApplication::showMessage(tr("Exporting page %1 of %2").arg(pageIndex + 1).arg(existingPageCount)); // set background to white, no crossing for PDF output bool isDark = scene->isDarkBackground(); - bool isCrossed = scene->isCrossedBackground(); - scene->setBackground(false, false); + UBPageBackground pageBackground = scene->pageBackground(); + scene->setBackground(false, UBPageBackground::plain); QSize pageSize = scene->nominalSize(); @@ -113,7 +113,7 @@ bool UBExportPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QStrin scene->setRenderingQuality(UBItem::RenderingQualityNormal); //restore background state - scene->setBackground(isDark, isCrossed); + scene->setBackground(isDark, pageBackground); } if(!painterNeedsBegin) pdfPainter.end(); diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 82da8160..bf04c400 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -445,6 +445,7 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene(UBDocumentProx bool darkBackground = false; bool crossedBackground = false; + bool ruledBackground = false; QStringRef ubDarkBackground = mXmlReader.attributes().value(mNamespaceUri, "dark-background"); @@ -456,7 +457,6 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene(UBDocumentProx if (!ubCrossedBackground.isNull()) crossedBackground = (ubCrossedBackground.toString() == xmlTrue); - mScene->setBackground(darkBackground, crossedBackground); if (crossedBackground) { QStringRef ubGridSize = mXmlReader.attributes().value(mNamespaceUri, "grid-size"); @@ -469,6 +469,32 @@ UBGraphicsScene* UBSvgSubsetAdaptor::UBSvgSubsetReader::loadScene(UBDocumentProx } } + QStringRef ubRuledBackground = mXmlReader.attributes().value(mNamespaceUri, "ruled-background"); + + if (!ubRuledBackground.isNull()) + ruledBackground = (ubRuledBackground.toString() == xmlTrue); + + if (ruledBackground && !crossedBackground) { // if for some reason both are true, the background will be a grid + QStringRef ubGridSize = mXmlReader.attributes().value(mNamespaceUri, "grid-size"); + + if (!ubGridSize.isNull()) { + int gridSize = ubGridSize.toInt(); + + UBSettings::settings()->crossSize = gridSize; + mScene->setBackgroundGridSize(gridSize); + } + } + + UBPageBackground bg; + if (crossedBackground) + bg = UBPageBackground::crossed; + else if (ruledBackground) + bg = UBPageBackground::ruled; + else + bg = UBPageBackground::plain; + + mScene->setBackground(darkBackground, bg); + QStringRef pageNominalSize = mXmlReader.attributes().value(mNamespaceUri, "nominal-size"); if (!pageNominalSize.isNull()) { @@ -1077,9 +1103,14 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::writeSvgElement(UBDocumentProxy* pro } mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "dark-background", mScene->isDarkBackground() ? xmlTrue : xmlFalse); - mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "crossed-background", mScene->isCrossedBackground() ? xmlTrue : xmlFalse); - if (mScene->isCrossedBackground()) { + bool crossedBackground = mScene->pageBackground() == UBPageBackground::crossed; + bool ruledBackground = mScene->pageBackground() == UBPageBackground::ruled; + + mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "crossed-background", crossedBackground ? xmlTrue : xmlFalse); + mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "ruled-background", ruledBackground ? xmlTrue : xmlFalse); + + if (crossedBackground || ruledBackground) { int gridSize = mScene->backgroundGridSize(); mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "grid-size", QString::number(gridSize)); diff --git a/src/api/UBWidgetUniboardAPI.cpp b/src/api/UBWidgetUniboardAPI.cpp index c84bb546..5645519c 100644 --- a/src/api/UBWidgetUniboardAPI.cpp +++ b/src/api/UBWidgetUniboardAPI.cpp @@ -223,8 +223,12 @@ void UBWidgetUniboardAPI::addObject(QString pUrl, int width, int height, int x, void UBWidgetUniboardAPI::setBackground(bool pIsDark, bool pIsCrossed) { - if (mScene) - mScene->setBackground(pIsDark, pIsCrossed); + if (mScene) { + if (pIsCrossed) + mScene->setBackground(pIsDark, UBPageBackground::crossed); + else + mScene->setBackground(pIsDark, UBPageBackground::plain); + } } diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index a87524d2..b1dac51f 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -1527,14 +1527,14 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, adjustDisplayViews(); UBSettings::settings()->setDarkBackground(mActiveScene->isDarkBackground()); - UBSettings::settings()->setCrossedBackground(mActiveScene->isCrossedBackground()); + UBSettings::settings()->setPageBackground(mActiveScene->pageBackground()); freezeW3CWidgets(false); } selectionChanged(); - updateBackgroundActionsState(mActiveScene->isDarkBackground(), mActiveScene->isCrossedBackground()); + updateBackgroundActionsState(mActiveScene->isDarkBackground(), mActiveScene->pageBackground()); if(documentChange) UBGraphicsTextItem::lastUsedTextColor = QColor(); @@ -1650,17 +1650,17 @@ int UBBoardController::autosaveTimeoutFromSettings() return value * minute; } -void UBBoardController::changeBackground(bool isDark, bool isCrossed) +void UBBoardController::changeBackground(bool isDark, UBPageBackground pageBackground) { bool currentIsDark = mActiveScene->isDarkBackground(); - bool currentIsCrossed = mActiveScene->isCrossedBackground(); + UBPageBackground currentBackgroundType = mActiveScene->pageBackground(); - if ((isDark != currentIsDark) || (currentIsCrossed != isCrossed)) + if ((isDark != currentIsDark) || (currentBackgroundType != pageBackground)) { UBSettings::settings()->setDarkBackground(isDark); - UBSettings::settings()->setCrossedBackground(isCrossed); + UBSettings::settings()->setPageBackground(pageBackground); - mActiveScene->setBackground(isDark, isCrossed); + mActiveScene->setBackground(isDark, pageBackground); emit backgroundChanged(); } @@ -2449,16 +2449,31 @@ void UBBoardController::moveToolWidgetToScene(UBToolWidget* toolWidget) } -void UBBoardController::updateBackgroundActionsState(bool isDark, bool isCrossed) +void UBBoardController::updateBackgroundActionsState(bool isDark, UBPageBackground pageBackground) { - if (isDark && !isCrossed) - mMainWindow->actionPlainDarkBackground->setChecked(true); - else if (isDark && isCrossed) - mMainWindow->actionCrossedDarkBackground->setChecked(true); - else if (!isDark && isCrossed) - mMainWindow->actionCrossedLightBackground->setChecked(true); - else - mMainWindow->actionPlainLightBackground->setChecked(true); + switch (pageBackground) { + + case UBPageBackground::crossed: + if (isDark) + mMainWindow->actionCrossedDarkBackground->setChecked(true); + else + mMainWindow->actionCrossedLightBackground->setChecked(true); + break; + + case UBPageBackground::ruled : + if (isDark) + mMainWindow->actionRuledDarkBackground->setChecked(true); + else + mMainWindow->actionRuledLightBackground->setChecked(true); + break; + + default: + if (isDark) + mMainWindow->actionPlainDarkBackground->setChecked(true); + else + mMainWindow->actionPlainLightBackground->setChecked(true); + break; + } } diff --git a/src/board/UBBoardController.h b/src/board/UBBoardController.h index f57b21ef..5631299a 100644 --- a/src/board/UBBoardController.h +++ b/src/board/UBBoardController.h @@ -220,7 +220,7 @@ class UBBoardController : public UBDocumentContainer UBItem *downloadFinished(bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground = false, bool internalData = false); - void changeBackground(bool isDark, bool isCrossed); + void changeBackground(bool isDark, UBPageBackground pageBackground); void setToolCursor(int tool); void showMessage(const QString& message, bool showSpinningWheel = false); void hideMessage(); @@ -321,7 +321,7 @@ class UBBoardController : public UBDocumentContainer void stylusToolDoubleClicked(int tool); void boardViewResized(QResizeEvent* event); void documentWillBeDeleted(UBDocumentProxy* pProxy); - void updateBackgroundActionsState(bool isDark, bool isCrossed); + void updateBackgroundActionsState(bool isDark, UBPageBackground pageBackground); void colorPaletteChanged(); void libraryDialogClosed(int ret); void lastWindowClosed(); diff --git a/src/board/UBBoardPaletteManager.cpp b/src/board/UBBoardPaletteManager.cpp index cbff6491..449d0831 100644 --- a/src/board/UBBoardPaletteManager.cpp +++ b/src/board/UBBoardPaletteManager.cpp @@ -251,8 +251,10 @@ void UBBoardPaletteManager::setupPalettes() backgroundsActions << UBApplication::mainWindow->actionPlainLightBackground; backgroundsActions << UBApplication::mainWindow->actionCrossedLightBackground; + backgroundsActions << UBApplication::mainWindow->actionRuledLightBackground; backgroundsActions << UBApplication::mainWindow->actionPlainDarkBackground; backgroundsActions << UBApplication::mainWindow->actionCrossedDarkBackground; + backgroundsActions << UBApplication::mainWindow->actionRuledDarkBackground; mBackgroundsPalette = new UBBackgroundPalette(backgroundsActions, mContainer); mBackgroundsPalette->setButtonIconSize(QSize(128, 128)); @@ -434,8 +436,10 @@ void UBBoardPaletteManager::connectPalettes() connect(UBApplication::mainWindow->actionPlainLightBackground, SIGNAL(triggered()), this, SLOT(changeBackground())); connect(UBApplication::mainWindow->actionCrossedLightBackground, SIGNAL(triggered()), this, SLOT(changeBackground())); + connect(UBApplication::mainWindow->actionRuledLightBackground, SIGNAL(triggered()), this, SLOT(changeBackground())); connect(UBApplication::mainWindow->actionPlainDarkBackground, SIGNAL(triggered()), this, SLOT(changeBackground())); connect(UBApplication::mainWindow->actionCrossedDarkBackground, SIGNAL(triggered()), this, SLOT(changeBackground())); + connect(UBApplication::mainWindow->actionRuledDarkBackground, SIGNAL(triggered()), this, SLOT(changeBackground())); connect(UBApplication::mainWindow->actionPodcast, SIGNAL(triggered(bool)), this, SLOT(tooglePodcastPalette(bool))); connect(UBApplication::mainWindow->actionAddItemToCurrentPage, SIGNAL(triggered()), this, SLOT(addItemToCurrentPage())); @@ -525,13 +529,22 @@ void UBBoardPaletteManager::containerResized() void UBBoardPaletteManager::changeBackground() { if (UBApplication::mainWindow->actionCrossedLightBackground->isChecked()) - UBApplication::boardController->changeBackground(false, true); + UBApplication::boardController->changeBackground(false, UBPageBackground::crossed); + + else if (UBApplication::mainWindow->actionRuledLightBackground->isChecked()) + UBApplication::boardController->changeBackground(false, UBPageBackground::ruled); + else if (UBApplication::mainWindow->actionPlainDarkBackground->isChecked()) - UBApplication::boardController->changeBackground(true, false); + UBApplication::boardController->changeBackground(true, UBPageBackground::plain); + else if (UBApplication::mainWindow->actionCrossedDarkBackground->isChecked()) - UBApplication::boardController->changeBackground(true, true); + UBApplication::boardController->changeBackground(true, UBPageBackground::crossed); + + else if (UBApplication::mainWindow->actionRuledDarkBackground->isChecked()) + UBApplication::boardController->changeBackground(true, UBPageBackground::ruled); + else - UBApplication::boardController->changeBackground(false, false); + UBApplication::boardController->changeBackground(false, UBPageBackground::plain); mBackgroundsPalette->backgroundChanged(); } diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index b50d0115..490e3955 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -1607,7 +1607,7 @@ void UBBoardView::drawBackground (QPainter *painter, const QRectF &rect) painter->setPen (bgCrossColor); - if (scene () && scene ()->isCrossedBackground ()) + if (scene () && scene ()->pageBackground() == UBPageBackground::crossed) { qreal firstY = ((int) (rect.y () / scene()->backgroundGridSize())) * scene()->backgroundGridSize(); @@ -1623,6 +1623,16 @@ void UBBoardView::drawBackground (QPainter *painter, const QRectF &rect) painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ()); } } + + if (scene() && scene()->pageBackground() == UBPageBackground::ruled) + { + qreal firstY = ((int) (rect.y () / scene()->backgroundGridSize())) * scene()->backgroundGridSize(); + + for (qreal yPos = firstY; yPos < rect.y () + rect.height (); yPos += scene()->backgroundGridSize()) + { + painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos); + } + } } if (!mFilterZIndex && scene ()) diff --git a/src/core/UB.h b/src/core/UB.h index 651ac139..4c791615 100644 --- a/src/core/UB.h +++ b/src/core/UB.h @@ -212,4 +212,11 @@ struct UBUndoType }; }; +enum UBPageBackground +{ + plain = 0, + crossed, + ruled +}; + #endif /* UB_H_ */ diff --git a/src/core/UBApplicationController.cpp b/src/core/UBApplicationController.cpp index 48d670ad..7e45d365 100644 --- a/src/core/UBApplicationController.cpp +++ b/src/core/UBApplicationController.cpp @@ -111,7 +111,7 @@ UBApplicationController::UBApplicationController(UBBoardView *pControlView, } mBlackScene = new UBGraphicsScene(0); // deleted by UBApplicationController::destructor - mBlackScene->setBackground(true, false); + mBlackScene->setBackground(true, UBPageBackground::plain); if (mDisplayManager->numScreens() >= 2) { diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index bcef40aa..9b951b1e 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -653,7 +653,7 @@ UBGraphicsScene* UBPersistenceManager::createDocumentSceneAt(UBDocumentProxy* pr UBGraphicsScene *newScene = mSceneCache.createScene(proxy, index, useUndoRedoStack); newScene->setBackground(UBSettings::settings()->isDarkBackground(), - UBSettings::settings()->UBSettings::isCrossedBackground()); + UBSettings::settings()->UBSettings::pageBackground()); persistDocumentScene(proxy, newScene, index); diff --git a/src/core/UBSettings.cpp b/src/core/UBSettings.cpp index ad9bc861..3b1bc4f5 100644 --- a/src/core/UBSettings.cpp +++ b/src/core/UBSettings.cpp @@ -735,9 +735,16 @@ bool UBSettings::isDarkBackground() } -bool UBSettings::isCrossedBackground() +UBPageBackground UBSettings::pageBackground() { - return value("Board/CrossedBackground", 0).toBool(); + QString val = value("Board/PageBackground", 0).toString(); + + if (val == "crossed") + return UBPageBackground::crossed; + else if (val == "ruled") + return UBPageBackground::ruled; + else + return UBPageBackground::plain; } @@ -748,9 +755,18 @@ void UBSettings::setDarkBackground(bool isDarkBackground) } -void UBSettings::setCrossedBackground(bool isCrossedBackground) +void UBSettings::setPageBackground(UBPageBackground background) { - setValue("Board/CrossedBackground", isCrossedBackground); + QString val; + + if (background == UBPageBackground::crossed) + val = "crossed"; + else if (background == UBPageBackground::ruled) + val = "ruled"; + else + val = "plain"; + + setValue("Board/PageBackground", val); } @@ -1413,4 +1429,8 @@ void UBSettings::checkNewSettings() // A typo was corrected in version 1.3 removeSetting("Board/useSystemOnScreenKeybard"); + + // CrossedBackground changed in 1.4 (no longer a bool but an enum; can be crossed or ruled) + removeSetting("Board/CrossedBackground"); + } diff --git a/src/core/UBSettings.h b/src/core/UBSettings.h index b0bf73ca..6be12962 100644 --- a/src/core/UBSettings.h +++ b/src/core/UBSettings.h @@ -87,9 +87,9 @@ class UBSettings : public QObject // Background related bool isDarkBackground(); - bool isCrossedBackground(); + UBPageBackground pageBackground(); void setDarkBackground(bool isDarkBackground); - void setCrossedBackground(bool isCrossedBackground); + void setPageBackground(UBPageBackground background); // Stylus palette related bool isStylusPaletteVisible(); diff --git a/src/desktop/UBDesktopAnnotationController.cpp b/src/desktop/UBDesktopAnnotationController.cpp index 894b33bc..40188703 100644 --- a/src/desktop/UBDesktopAnnotationController.cpp +++ b/src/desktop/UBDesktopAnnotationController.cpp @@ -185,9 +185,9 @@ UBDesktopAnnotationController::~UBDesktopAnnotationController() void UBDesktopAnnotationController::updateColors(){ if(UBApplication::boardController->activeScene()->isDarkBackground()){ - mTransparentDrawingScene->setBackground(true, false); + mTransparentDrawingScene->setBackground(true, UBPageBackground::plain); }else{ - mTransparentDrawingScene->setBackground(false, false); + mTransparentDrawingScene->setBackground(false, UBPageBackground::plain); } } diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index acd54ee7..6a451a28 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -321,7 +321,7 @@ UBGraphicsScene::UBGraphicsScene(UBDocumentProxy* parent, bool enableUndoRedoSta , mMarkerCircle(0) , mDocument(parent) , mDarkBackground(false) - , mCrossedBackground(false) + , mPageBackground(UBPageBackground::plain) , mIsDesktopMode(false) , mZoomFactor(1) , mBackgroundObject(0) @@ -1010,7 +1010,7 @@ void UBGraphicsScene::drawArcTo(const QPointF& pCenterPoint, qreal pSpanAngle) setDocumentUpdated(); } -void UBGraphicsScene::setBackground(bool pIsDark, bool pIsCrossed) +void UBGraphicsScene::setBackground(bool pIsDark, UBPageBackground pBackground) { bool needRepaint = false; @@ -1026,9 +1026,9 @@ void UBGraphicsScene::setBackground(bool pIsDark, bool pIsCrossed) setModified(true); } - if (mCrossedBackground != pIsCrossed) + if (mPageBackground != pBackground) { - mCrossedBackground = pIsCrossed; + mPageBackground = pBackground; needRepaint = true; setModified(true); } @@ -1243,7 +1243,7 @@ UBGraphicsScene* UBGraphicsScene::sceneDeepCopy() const { UBGraphicsScene* copy = new UBGraphicsScene(this->document(), this->mUndoRedoStackEnabled); - copy->setBackground(this->isDarkBackground(), this->isCrossedBackground()); + copy->setBackground(this->isDarkBackground(), mPageBackground); copy->setBackgroundGridSize(mBackgroundGridSize); copy->setSceneRect(this->sceneRect()); @@ -2489,7 +2489,7 @@ void UBGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect) painter->setPen (bgCrossColor); - if (isCrossedBackground()) + if (mPageBackground == UBPageBackground::crossed) { qreal firstY = ((int) (rect.y () / backgroundGridSize())) * backgroundGridSize(); @@ -2505,6 +2505,16 @@ void UBGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect) painter->drawLine (xPos, rect.y (), xPos, rect.y () + rect.height ()); } } + + else if (mPageBackground == UBPageBackground::ruled) + { + qreal firstY = ((int) (rect.y () / backgroundGridSize())) * backgroundGridSize(); + + for (qreal yPos = firstY; yPos < rect.y () + rect.height (); yPos += backgroundGridSize()) + { + painter->drawLine (rect.x (), yPos, rect.x () + rect.width (), yPos); + } + } } } diff --git a/src/domain/UBGraphicsScene.h b/src/domain/UBGraphicsScene.h index 05674873..37f1a470 100644 --- a/src/domain/UBGraphicsScene.h +++ b/src/domain/UBGraphicsScene.h @@ -217,9 +217,9 @@ class UBGraphicsScene: public UBCoreGraphicsScene, public UBItem return !mDarkBackground; } - bool isCrossedBackground() const + UBPageBackground pageBackground() const { - return mCrossedBackground; + return mPageBackground; } int backgroundGridSize() const @@ -336,7 +336,7 @@ public slots: void initStroke(); void hideTool(); - void setBackground(bool pIsDark, bool pIsCrossed); + void setBackground(bool pIsDark, UBPageBackground pBackground); void setBackgroundZoomFactor(qreal zoom); void setBackgroundGridSize(int pSize); void setDrawingMode(bool bModeDesktop); @@ -413,7 +413,7 @@ public slots: UBDocumentProxy* mDocument; bool mDarkBackground; - bool mCrossedBackground; + UBPageBackground mPageBackground; int mBackgroundGridSize; bool mIsDesktopMode;