From 9194120bc827115935d1285baca477864601c735 Mon Sep 17 00:00:00 2001 From: thomas_lucky13 Date: Sun, 17 Jul 2022 17:49:35 +0400 Subject: [PATCH] LineStyle toolBar --- resources/forms/mainWindow.ui | 50 ++++++++++++++++++++++++++++++- src/board/UBBoardController.cpp | 25 ++++++++++++++++ src/board/UBBoardController.h | 3 +- src/board/UBDrawingController.cpp | 5 ++++ src/board/UBDrawingController.h | 1 + src/core/UB.h | 10 +++++++ src/core/UBSettings.cpp | 35 ++++++++++++++++++++++ src/core/UBSettings.h | 6 ++++ src/domain/UBGraphicsScene.cpp | 2 +- 9 files changed, 134 insertions(+), 3 deletions(-) diff --git a/resources/forms/mainWindow.ui b/resources/forms/mainWindow.ui index a24810b4..0b0ef33b 100644 --- a/resources/forms/mainWindow.ui +++ b/resources/forms/mainWindow.ui @@ -7,7 +7,7 @@ 0 0 1342 - 223 + 268 @@ -1702,6 +1702,54 @@ Draw intermediate grid lines + + + true + + + + :/images/toolbar/smallEraser.png:/images/toolbar/smallEraser.png + + + Line Style + + + Solid Style + + + + + true + + + true + + + + :/images/toolbar/mediumEraser.png:/images/toolbar/mediumEraser.png + + + Line Style + + + Dashed Style + + + + + true + + + + :/images/toolbar/largeEraser.png:/images/toolbar/largeEraser.png + + + Line Style + + + Dotted Style + + diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 75e64925..21b2b861 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -376,6 +376,27 @@ void UBBoardController::setupToolbar() mMainWindow->boardToolBar->insertSeparator(mMainWindow->actionBackgrounds); mPropertyPaletteWidgets.insert(eraserWidth, newPropertyPaletteWidget); + //-----------------------------------------------------------// + // Setup line style choice widget + QList lineStyleActions; + lineStyleActions.append(mMainWindow->actionLineSolid); + lineStyleActions.append(mMainWindow->actionLineDashed); + lineStyleActions.append(mMainWindow->actionLineDotted); + + UBToolbarButtonGroup *lineStyleChoice = + new UBToolbarButtonGroup(mMainWindow->boardToolBar, lineStyleActions); + + connect(settings->appToolBarDisplayText, SIGNAL(changed(QVariant)), lineStyleChoice, SLOT(displayText(QVariant))); + + connect(lineStyleChoice, SIGNAL(activated(int)), + UBDrawingController::drawingController(), SLOT(setLineStyleIndex(int))); + + lineStyleChoice->displayText(QVariant(settings->appToolBarDisplayText->get().toBool())); + newPropertyPaletteWidget = mMainWindow->boardToolBar->insertWidget(mMainWindow->actionBackgrounds, lineStyleChoice); + lineStyleChoice->setCurrentIndex(settings->lineStyleIndex()); + lineStyleActions.at(settings->lineStyleIndex())->setChecked(true); + mPropertyPaletteWidgets.insert(lineStyle, newPropertyPaletteWidget); + //-----------------------------------------------------------// UBApplication::app()->insertSpaceToToolbarBeforeAction(mMainWindow->boardToolBar, mMainWindow->actionBackgrounds); @@ -2209,23 +2230,27 @@ void UBBoardController::stylusToolChanged(int tool) mPropertyPaletteWidgets[color]->setVisible(true); mPropertyPaletteWidgets[lineWidth]->setVisible(true); mPropertyPaletteWidgets[eraserWidth]->setVisible(false); + mPropertyPaletteWidgets[lineStyle]->setVisible(false); } else if (eTool == UBStylusTool::Eraser) { mPropertyPaletteWidgets[color]->setVisible(false); mPropertyPaletteWidgets[lineWidth]->setVisible(false); mPropertyPaletteWidgets[eraserWidth]->setVisible(true); + mPropertyPaletteWidgets[lineStyle]->setVisible(false); } else if (eTool == UBStylusTool::Line) { mPropertyPaletteWidgets[color]->setVisible(true); mPropertyPaletteWidgets[lineWidth]->setVisible(true); mPropertyPaletteWidgets[eraserWidth]->setVisible(false); + mPropertyPaletteWidgets[lineStyle]->setVisible(true); } else { mPropertyPaletteWidgets[color]->setVisible(false); mPropertyPaletteWidgets[lineWidth]->setVisible(false); mPropertyPaletteWidgets[eraserWidth]->setVisible(false); + mPropertyPaletteWidgets[lineStyle]->setVisible(false); } diff --git a/src/board/UBBoardController.h b/src/board/UBBoardController.h index 0ad946aa..f582d3a2 100644 --- a/src/board/UBBoardController.h +++ b/src/board/UBBoardController.h @@ -326,7 +326,8 @@ class UBBoardController : public UBDocumentContainer { color, lineWidth, - eraserWidth + eraserWidth, + lineStyle }; QMap mPropertyPaletteWidgets; diff --git a/src/board/UBDrawingController.cpp b/src/board/UBDrawingController.cpp index 705e1d18..ab6b39d4 100644 --- a/src/board/UBDrawingController.cpp +++ b/src/board/UBDrawingController.cpp @@ -279,6 +279,11 @@ void UBDrawingController::setEraserWidthIndex(int index) UBSettings::settings()->setEraserWidthIndex(index); } +void UBDrawingController::setLineStyleIndex(int index) +{ + UBSettings::settings()->setLineStyleIndex(index); +} + void UBDrawingController::setPenColor(bool onDarkBackground, const QColor& color, int pIndex) { if (onDarkBackground) diff --git a/src/board/UBDrawingController.h b/src/board/UBDrawingController.h index 01c11187..617bc824 100644 --- a/src/board/UBDrawingController.h +++ b/src/board/UBDrawingController.h @@ -80,6 +80,7 @@ class UBDrawingController : public QObject void setLineWidthIndex(int index); void setColorIndex(int index); void setEraserWidthIndex(int index); + void setLineStyleIndex(int index); signals: void stylusToolChanged(int tool, int previousTool = -1); diff --git a/src/core/UB.h b/src/core/UB.h index 388d265f..c9bfa5cb 100644 --- a/src/core/UB.h +++ b/src/core/UB.h @@ -84,6 +84,16 @@ struct UBWidth }; }; +struct UBLineStyle +{ + enum Enum + { + Solid = 0, + Dashed = 1, + Dotted = 2 + }; +}; + struct UBZoom { enum Enum diff --git a/src/core/UBSettings.cpp b/src/core/UBSettings.cpp index 663c5582..09135e60 100644 --- a/src/core/UBSettings.cpp +++ b/src/core/UBSettings.cpp @@ -785,6 +785,41 @@ qreal UBSettings::currentEraserWidth() return width; } +//----------------------------------------// +// line +int UBSettings::lineStyleIndex() +{ + return value("Board/LineStyleIndex", 0).toInt(); +} + +void UBSettings::setLineStyleIndex(int index) +{ + setValue("Board/LineStyleIndex", index); +} +Qt::PenStyle UBSettings::currentLineStyle() +{ + Qt::PenStyle style = Qt::SolidLine; + + switch (lineStyleIndex()) + { + case UBLineStyle::Solid: + style = Qt::SolidLine; + break; + case UBLineStyle::Dotted: + style = Qt::DotLine; + break; + case UBLineStyle::Dashed: + style = Qt::DashLine; + break; + default: + Q_ASSERT(false); + style = Qt::SolidLine; + break; + } + + return style; +} + bool UBSettings::isDarkBackground() { return value("Board/DarkBackground", 0).toBool(); diff --git a/src/core/UBSettings.h b/src/core/UBSettings.h index 8d5909a3..77cefead 100644 --- a/src/core/UBSettings.h +++ b/src/core/UBSettings.h @@ -85,6 +85,10 @@ class UBSettings : public QObject qreal eraserStrongWidth(); qreal currentEraserWidth(); + // Line related + int lineStyleIndex(); + Qt::PenStyle currentLineStyle(); + // Background related bool isDarkBackground(); UBPageBackground pageBackground(); @@ -443,6 +447,8 @@ class UBSettings : public QObject void setEraserMediumWidth(qreal width); void setEraserStrongWidth(qreal width); + void setLineStyleIndex(int index); + void setStylusPaletteVisible(bool visible); void setPenPressureSensitive(bool sensitive); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 5b7193bb..bc32cf1a 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1362,7 +1362,7 @@ void UBGraphicsScene::initLineItem(UBGraphicsLineItem* lineItem) lineItem->setColorOnLightBackground(colorOnLightBG); lineItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic)); - //lineItem->setStyle(UBSettings::settings()->currentLineStyle()); + lineItem->setStyle(UBSettings::settings()->currentLineStyle()); QPen linePen = lineItem->pen(); linePen.setWidth(lineItem->originalWidth());