vector styles

new_vector_item
thomas_lucky13 2 years ago
parent 4a22964363
commit ed46bc6121
  1. 48
      resources/forms/mainWindow.ui
  2. 25
      src/adaptors/UBSvgSubsetAdaptor.cpp
  3. 27
      src/board/UBBoardController.cpp
  4. 3
      src/board/UBBoardController.h
  5. 5
      src/board/UBDrawingController.cpp
  6. 1
      src/board/UBDrawingController.h
  7. 10
      src/core/UB.h
  8. 30
      src/core/UBSettings.cpp
  9. 5
      src/core/UBSettings.h
  10. 1
      src/domain/UBGraphicsScene.cpp
  11. 36
      src/domain/UBGraphicsVectorItem.cpp
  12. 8
      src/domain/UBGraphicsVectorItem.h

@ -1769,6 +1769,54 @@
<string>Ctrl+J</string>
</property>
</action>
<action name="actionVectorTo">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../OpenBoard.qrc">
<normaloff>:/images/toolbar/solidLine.svg</normaloff>:/images/toolbar/solidLine.svg</iconset>
</property>
<property name="text">
<string>Vector Style</string>
</property>
<property name="toolTip">
<string>To Style</string>
</property>
</action>
<action name="actionVectorFrom">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../OpenBoard.qrc">
<normaloff>:/images/toolbar/dashedLine.svg</normaloff>:/images/toolbar/dashedLine.svg</iconset>
</property>
<property name="text">
<string>Vector Style</string>
</property>
<property name="toolTip">
<string>From Style</string>
</property>
</action>
<action name="actionVectorFromTo">
<property name="checkable">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../OpenBoard.qrc">
<normaloff>:/images/toolbar/dottedLine.svg</normaloff>:/images/toolbar/dottedLine.svg</iconset>
</property>
<property name="text">
<string>Vector Style</string>
</property>
<property name="toolTip">
<string>FromTo Style</string>
</property>
</action>
</widget>
<resources>
<include location="../OpenBoard.qrc"/>

@ -1794,18 +1794,17 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::vectorItemToSvgVector(UBGraphicsVect
mXmlWriter.writeAttribute("stroke-opacity", QString::number(alpha, 'f', 2));
mXmlWriter.writeAttribute("stroke-linecap", "round");
/* VectorStyle
switch (vectorItem->style())
switch (vectorItem->getStyle())
{
case Qt::PenStyle::DotLine:
mXmlWriter.writeAttribute("line-style", "2");
case UBVectorStyle::From:
mXmlWriter.writeAttribute("vector-style", "1");
break;
case Qt::PenStyle::DashLine:
mXmlWriter.writeAttribute("line-style", "1");
case UBVectorStyle::FromTo:
mXmlWriter.writeAttribute("vector-style", "2");
break;
default:
mXmlWriter.writeAttribute("line-style", "0");
}*/
mXmlWriter.writeAttribute("vector-style", "0");
}
if (!groupHoldsInfo)
{
@ -2329,17 +2328,17 @@ UBGraphicsVectorItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::vectorItemFromVecto
}
vectorItem->setColor(penColor);
/* VectorStyle
if (style == 2)
{
vectorItem->setStyle(Qt::PenStyle::DotLine);
vectorItem->setStyle(UBVectorStyle::FromTo);
} else if (style == 1)
{
lineItem->setStyle(Qt::PenStyle::DashLine);
vectorItem->setStyle(UBVectorStyle::From);
} else
{
lineItem->setStyle(Qt::PenStyle::SolidLine);
}*/
vectorItem->setStyle(UBVectorStyle::To);
}
QStringRef ubFillOnDarkBackground = mXmlReader.attributes().value(mNamespaceUri, "fill-on-dark-background");

@ -399,6 +399,28 @@ void UBBoardController::setupToolbar()
//-----------------------------------------------------------//
// Setup vector style choice widget
QList<QAction *> vectorStyleActions;
vectorStyleActions.append(mMainWindow->actionVectorTo);
vectorStyleActions.append(mMainWindow->actionVectorFrom);
vectorStyleActions.append(mMainWindow->actionVectorFromTo);
UBToolbarButtonGroup *vectorStyleChoice =
new UBToolbarButtonGroup(mMainWindow->boardToolBar, vectorStyleActions);
connect(settings->appToolBarDisplayText, SIGNAL(changed(QVariant)), vectorStyleChoice, SLOT(displayText(QVariant)));
connect(vectorStyleChoice, SIGNAL(activated(int)),
UBDrawingController::drawingController(), SLOT(setVectorStyleIndex(int)));
vectorStyleChoice->displayText(QVariant(settings->appToolBarDisplayText->get().toBool()));
newPropertyPaletteWidget = mMainWindow->boardToolBar->insertWidget(mMainWindow->actionBackgrounds, vectorStyleChoice);
vectorStyleChoice->setCurrentIndex(settings->vectorStyleIndex());
vectorStyleActions.at(settings->vectorStyleIndex())->setChecked(true);
mPropertyPaletteWidgets.insert(vectorStyle, newPropertyPaletteWidget);
//-----------------------------------------------------------//
UBApplication::app()->insertSpaceToToolbarBeforeAction(mMainWindow->boardToolBar, mMainWindow->actionBackgrounds);
UBApplication::app()->insertSpaceToToolbarBeforeAction(mMainWindow->boardToolBar, mMainWindow->actionBoard, 40);
UBApplication::app()->decorateActionMenu(mMainWindow->actionMenu);
@ -2233,6 +2255,7 @@ void UBBoardController::stylusToolChanged(int tool)
mPropertyPaletteWidgets[lineWidth]->setVisible(true);
mPropertyPaletteWidgets[eraserWidth]->setVisible(false);
mPropertyPaletteWidgets[lineStyle]->setVisible(false);
mPropertyPaletteWidgets[vectorStyle]->setVisible(false);
} else
if (eTool == UBStylusTool::Eraser)
{
@ -2240,6 +2263,7 @@ void UBBoardController::stylusToolChanged(int tool)
mPropertyPaletteWidgets[lineWidth]->setVisible(false);
mPropertyPaletteWidgets[eraserWidth]->setVisible(true);
mPropertyPaletteWidgets[lineStyle]->setVisible(false);
mPropertyPaletteWidgets[vectorStyle]->setVisible(false);
} else
if (eTool == UBStylusTool::Line)
{
@ -2247,6 +2271,7 @@ void UBBoardController::stylusToolChanged(int tool)
mPropertyPaletteWidgets[lineWidth]->setVisible(true);
mPropertyPaletteWidgets[eraserWidth]->setVisible(false);
mPropertyPaletteWidgets[lineStyle]->setVisible(true);
mPropertyPaletteWidgets[vectorStyle]->setVisible(false);
} else
if (eTool == UBStylusTool::Vector)
{
@ -2254,12 +2279,14 @@ void UBBoardController::stylusToolChanged(int tool)
mPropertyPaletteWidgets[lineWidth]->setVisible(true);
mPropertyPaletteWidgets[eraserWidth]->setVisible(false);
mPropertyPaletteWidgets[lineStyle]->setVisible(false);
mPropertyPaletteWidgets[vectorStyle]->setVisible(true);
} else
{
mPropertyPaletteWidgets[color]->setVisible(false);
mPropertyPaletteWidgets[lineWidth]->setVisible(false);
mPropertyPaletteWidgets[eraserWidth]->setVisible(false);
mPropertyPaletteWidgets[lineStyle]->setVisible(false);
mPropertyPaletteWidgets[vectorStyle]->setVisible(false);
}

@ -327,7 +327,8 @@ class UBBoardController : public UBDocumentContainer
color,
lineWidth,
eraserWidth,
lineStyle
lineStyle,
vectorStyle
};
QMap<PropertyPalette, QAction*> mPropertyPaletteWidgets;

@ -289,6 +289,11 @@ void UBDrawingController::setLineStyleIndex(int index)
UBSettings::settings()->setLineStyleIndex(index);
}
void UBDrawingController::setVectorStyleIndex(int index)
{
UBSettings::settings()->setVectorStyleIndex(index);
}
void UBDrawingController::setPenColor(bool onDarkBackground, const QColor& color, int pIndex)
{
if (onDarkBackground)

@ -82,6 +82,7 @@ class UBDrawingController : public QObject
void setColorIndex(int index);
void setEraserWidthIndex(int index);
void setLineStyleIndex(int index);
void setVectorStyleIndex(int index);
signals:
void stylusToolChanged(int tool, int previousTool = -1);

@ -95,6 +95,16 @@ struct UBLineStyle
};
};
struct UBVectorStyle
{
enum Enum
{
To = 0,
From = 1,
FromTo = 2
};
};
struct UBZoom
{
enum Enum

@ -820,6 +820,36 @@ Qt::PenStyle UBSettings::currentLineStyle()
return style;
}
int UBSettings::vectorStyleIndex()
{
return value("Board/VectorStyleIndex", 0).toInt();
}
void UBSettings::setVectorStyleIndex(int index)
{
setValue("Board/VectorStyleIndex", index);
}
UBVectorStyle::Enum UBSettings::currentVectorStyle()
{
switch (vectorStyleIndex())
{
case UBVectorStyle::To:
return UBVectorStyle::To;
break;
case UBVectorStyle::From:
return UBVectorStyle::From;
break;
case UBVectorStyle::FromTo:
return UBVectorStyle::FromTo;
break;
default:
Q_ASSERT(false);
return UBVectorStyle::To;
break;
}
return UBVectorStyle::To;
}
bool UBSettings::isDarkBackground()
{
return value("Board/DarkBackground", 0).toBool();

@ -89,6 +89,10 @@ class UBSettings : public QObject
int lineStyleIndex();
Qt::PenStyle currentLineStyle();
// Line related
int vectorStyleIndex();
UBVectorStyle::Enum currentVectorStyle();
// Background related
bool isDarkBackground();
UBPageBackground pageBackground();
@ -448,6 +452,7 @@ class UBSettings : public QObject
void setEraserStrongWidth(qreal width);
void setLineStyleIndex(int index);
void setVectorStyleIndex(int index);
void setStylusPaletteVisible(bool visible);

@ -1439,6 +1439,7 @@ void UBGraphicsScene::initVectorItem(UBGraphicsVectorItem* vectorItem)
}
vectorItem->setColorOnDarkBackground(colorOnDarkBG);
vectorItem->setColorOnLightBackground(colorOnLightBG);
vectorItem->setStyle(UBSettings::settings()->currentVectorStyle());
vectorItem->setData(UBGraphicsItemData::ItemLayerType, QVariant(UBItemLayerType::Graphic));
}

@ -63,6 +63,12 @@ void UBGraphicsVectorItem::initialize()
void UBGraphicsVectorItem::setSublines()
{
for(int i = 0; i < sublines.length(); ++i)
{
delete sublines[i];
}
if ((style == UBVectorStyle::To) || (style == UBVectorStyle::FromTo))
{
QLineF thisLine = QLineF(this->line().p2().x(), this->line().p2().y(),this->line().p2().x()+this->line().length()/10, this->line().p2().y());
thisLine.setAngle(this->line().angle() - 135);
sublines.push_back(new QGraphicsLineItem(thisLine));
@ -70,6 +76,19 @@ void UBGraphicsVectorItem::setSublines()
thisLine = QLineF(this->line().p2().x(), this->line().p2().y(),this->line().p2().x()+this->line().length()/10, this->line().p2().y());
thisLine.setAngle(this->line().angle() + 135);
sublines.push_back(new QGraphicsLineItem(thisLine));
}
if ((style == UBVectorStyle::From) || (style == UBVectorStyle::FromTo))
{
QLineF thisLine = QLineF(this->line().p1().x(), this->line().p1().y(),this->line().p1().x()+this->line().length()/10, this->line().p1().y());
thisLine.setAngle(this->line().angle() - 45);
sublines.push_back(new QGraphicsLineItem(thisLine));
thisLine = QLineF(this->line().p1().x(), this->line().p1().y(),this->line().p1().x()+this->line().length()/10, this->line().p1().y());
thisLine.setAngle(this->line().angle() + 45);
sublines.push_back(new QGraphicsLineItem(thisLine));
}
}
void UBGraphicsVectorItem::setUuid(const QUuid &pUuid)
@ -88,7 +107,6 @@ UBGraphicsVectorItem::~UBGraphicsVectorItem()
void UBGraphicsVectorItem::setColor(const QColor& pColor)
{
QPen pen = QPen(pColor);
pen.setStyle(style());
pen.setCapStyle(Qt::PenCapStyle::RoundCap);
pen.setWidth(mOriginalWidth);
QGraphicsLineItem::setPen(pen);
@ -103,20 +121,12 @@ QColor UBGraphicsVectorItem::color() const
return QGraphicsLineItem::pen().color();
}
void UBGraphicsVectorItem::setStyle(const Qt::PenStyle& style)
void UBGraphicsVectorItem::setStyle(const UBVectorStyle::Enum& _style)
{
QPen pen = QPen(color());
pen.setStyle(style);
pen.setCapStyle(Qt::PenCapStyle::RoundCap);
pen.setWidth(mOriginalWidth);
QGraphicsLineItem::setPen(pen);
style = _style;
setSublines();
for (int i = 0; i < sublines.size(); ++i)
sublines[i]->setPen(pen);
}
Qt::PenStyle UBGraphicsVectorItem::style() const
{
return QGraphicsLineItem::pen().style();
sublines[i]->setPen(this->pen());
}
QList<QPointF> UBGraphicsVectorItem::linePoints()

@ -27,10 +27,13 @@ public:
void setUuid(const QUuid &pUuid);
void setColor(const QColor& color);
void setStyle(const Qt::PenStyle& style);
void setStyle(const UBVectorStyle::Enum& _style);
UBVectorStyle::Enum getStyle()
{
return style;
}
QColor color() const;
Qt::PenStyle style() const;
virtual UBGraphicsScene* scene();
@ -102,6 +105,7 @@ public:
QColor mColorOnDarkBackground;
QColor mColorOnLightBackground;
QList<QGraphicsLineItem *> sublines;
UBVectorStyle::Enum style;
};
#endif // UBGRAPHICSVECTORITEM_H

Loading…
Cancel
Save