diff --git a/src/dialogs/dialogalongline.cpp b/src/dialogs/dialogalongline.cpp index 8f957c52e..f7d1f21ee 100644 --- a/src/dialogs/dialogalongline.cpp +++ b/src/dialogs/dialogalongline.cpp @@ -56,7 +56,7 @@ DialogAlongLine::DialogAlongLine(const VContainer *data, QWidget *parent) QPushButton *bCansel = ui->buttonBox->button(QDialogButtonBox::Cancel); connect(bCansel, &QPushButton::clicked, this, &DialogAlongLine::DialogRejected); FillComboBoxTypeLine(ui->comboBoxLineType); - ui->comboBoxLineType->setCurrentIndex(1); + ui->comboBoxLineType->setCurrentIndex(0); FillComboBoxPoints(ui->comboBoxFirstPoint); FillComboBoxPoints(ui->comboBoxSecondPoint); diff --git a/src/dialogs/dialogtool.cpp b/src/dialogs/dialogtool.cpp index bd0891414..b641815fa 100644 --- a/src/dialogs/dialogtool.cpp +++ b/src/dialogs/dialogtool.cpp @@ -29,6 +29,7 @@ #include "dialogtool.h" #include "../container/calculator.h" #include "../geometry/vgobject.h" +#include "../tools/vabstracttool.h" #include @@ -36,11 +37,15 @@ DialogTool::DialogTool(const VContainer *data, QWidget *parent) :QDialog(parent), data(data), isInitialized(false), flagName(true), flagFormula(true), timerFormula(0), bOk(0), spinBoxAngle(0), lineEditFormula(0), listWidget(0), labelResultCalculation(0), labelDescription(0), labelEditNamePoint(0), labelEditFormula(0), radioButtonSizeGrowth(0), radioButtonStandardTable(0), - radioButtonIncrements(0), radioButtonLengthLine(0), radioButtonLengthArc(0), radioButtonLengthCurve(0) + radioButtonIncrements(0), radioButtonLengthLine(0), radioButtonLengthArc(0), radioButtonLengthCurve(0), + lineStyles(QStringList()) { Q_ASSERT(data != 0); timerFormula = new QTimer(this); connect(timerFormula, &QTimer::timeout, this, &DialogTool::EvalFormula); + //Keep synchronize with VAbstractTool styles list!!! + lineStyles<addItems(list); + box->addItems(lineStyles); + box->setCurrentIndex(1); } QString DialogTool::GetTypeLine(const QComboBox *box) const { - if (box->currentText()==tr("Line")) + switch(lineStyles.indexOf(box->currentText())) { - return QString("hair"); - } - else - { - return QString("none"); + case 0: + return VAbstractTool::TypeLineNone; + break; + case 1: + return VAbstractTool::TypeLineLine; + break; + case 2: + return VAbstractTool::TypeLineDashLine; + break; + case 3: + return VAbstractTool::TypeLineDotLine; + break; + case 4: + return VAbstractTool::TypeLineDashDotLine; + break; + case 5: + return VAbstractTool::TypeLineDashDotDotLine; + break; + default: + return VAbstractTool::TypeLineLine; + break; } } void DialogTool::SetupTypeLine(QComboBox *box, const QString &value) { - if (value == "hair") + QStringList styles = VAbstractTool::Styles(); + qint32 index = box->findText(lineStyles.at(styles.indexOf(value))); + if (index != -1) { - qint32 index = box->findText(tr("Line")); - if (index != -1) - { - box->setCurrentIndex(index); - } - } - if (value == "none") - { - qint32 index = box->findText(tr("No line")); - if (index != -1) - { - box->setCurrentIndex(index); - } + box->setCurrentIndex(index); } } diff --git a/src/dialogs/dialogtool.h b/src/dialogs/dialogtool.h index da8512dc5..ef8346c0d 100644 --- a/src/dialogs/dialogtool.h +++ b/src/dialogs/dialogtool.h @@ -255,6 +255,10 @@ protected: * @brief radioButtonLengthCurve radio button for lengths of curves variables */ QRadioButton *radioButtonLengthCurve; + /** + * @brief lineStyles list supported line styles. + */ + QStringList lineStyles; /** * @brief closeEvent handle when dialog cloded * @param event event diff --git a/src/tools/drawTools/vtoollinepoint.cpp b/src/tools/drawTools/vtoollinepoint.cpp index 00b960e77..ff7d53dc4 100644 --- a/src/tools/drawTools/vtoollinepoint.cpp +++ b/src/tools/drawTools/vtoollinepoint.cpp @@ -31,23 +31,16 @@ VToolLinePoint::VToolLinePoint(VDomDocument *doc, VContainer *data, const qint64 &id, const QString &typeLine, const QString &formula, const qint64 &basePointId, const qreal &angle, QGraphicsItem *parent) - :VToolPoint(doc, data, id, parent), typeLine(typeLine), formula(formula), angle(angle), basePointId(basePointId), + :VToolPoint(doc, data, id, parent), formula(formula), angle(angle), basePointId(basePointId), mainLine(0) { + this->typeLine = typeLine; Q_ASSERT_X(basePointId > 0, Q_FUNC_INFO, "basePointId <= 0"); QPointF point1 = data->GeometricObject(basePointId)->toQPointF(); QPointF point2 = data->GeometricObject(id)->toQPointF(); mainLine = new QGraphicsLineItem(QLineF(point1 - point2, QPointF()), this); - mainLine->setPen(QPen(Qt::black, widthHairLine/factor)); + mainLine->setPen(QPen(Qt::black, widthHairLine/factor, LineStyle())); mainLine->setFlag(QGraphicsItem::ItemStacksBehindParent, true); - if (typeLine == TypeLineNone) - { - mainLine->setVisible(false); - } - else - { - mainLine->setVisible(true); - } } void VToolLinePoint::ChangedActivDraw(const QString &newName) @@ -60,25 +53,17 @@ void VToolLinePoint::ChangedActivDraw(const QString &newName) { currentColor = Qt::gray; } - mainLine->setPen(QPen(currentColor, widthHairLine/factor)); + mainLine->setPen(QPen(currentColor, widthHairLine/factor, LineStyle())); VToolPoint::ChangedActivDraw(newName); } void VToolLinePoint::RefreshGeometry() { - mainLine->setPen(QPen(currentColor, widthHairLine/factor)); + mainLine->setPen(QPen(currentColor, widthHairLine/factor, LineStyle())); VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); QPointF point = VDrawTool::data.GeometricObject(id)->toQPointF(); QPointF basePoint = VDrawTool::data.GeometricObject(basePointId)->toQPointF(); mainLine->setLine(QLineF(basePoint - point, QPointF())); - if (typeLine == TypeLineNone) - { - mainLine->setVisible(false); - } - else - { - mainLine->setVisible(true); - } } void VToolLinePoint::SetFactor(qreal factor) diff --git a/src/tools/drawTools/vtoollinepoint.h b/src/tools/drawTools/vtoollinepoint.h index eb329e1cb..2ba9bd9ab 100644 --- a/src/tools/drawTools/vtoollinepoint.h +++ b/src/tools/drawTools/vtoollinepoint.h @@ -64,10 +64,6 @@ public slots: */ virtual void SetFactor(qreal factor); protected: - /** - * @brief typeLine type line. - */ - QString typeLine; /** * @brief formula string with length formula. */ diff --git a/src/tools/vabstracttool.cpp b/src/tools/vabstracttool.cpp index 5e443972a..e552ccb58 100644 --- a/src/tools/vabstracttool.cpp +++ b/src/tools/vabstracttool.cpp @@ -64,9 +64,13 @@ const QString VAbstractTool::AttrAxisP1 = QStringLiteral("axisP1"); const QString VAbstractTool::AttrAxisP2 = QStringLiteral("axisP2"); const QString VAbstractTool::TypeLineNone = QStringLiteral("none"); const QString VAbstractTool::TypeLineLine = QStringLiteral("hair"); +const QString VAbstractTool::TypeLineDashLine = QStringLiteral("dashLine"); +const QString VAbstractTool::TypeLineDotLine = QStringLiteral("dotLine"); +const QString VAbstractTool::TypeLineDashDotLine = QStringLiteral("dashDotLine"); +const QString VAbstractTool::TypeLineDashDotDotLine = QStringLiteral("dashDotDotLine"); VAbstractTool::VAbstractTool(VDomDocument *doc, VContainer *data, qint64 id, QObject *parent) - :VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black) + :VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black), typeLine(TypeLineLine) { Q_ASSERT(doc != 0); connect(this, &VAbstractTool::toolhaveChange, this->doc, &VDomDocument::haveLiteChange); @@ -201,7 +205,6 @@ void VAbstractTool::RemoveAllChild(QDomElement &domElement) } } -//TODO see method deleteNode. I think no need have QGraphicsItem. QObject can delete yourself. void VAbstractTool::DeleteTool(QGraphicsItem *tool) { if (_referens <= 1) @@ -242,6 +245,35 @@ void VAbstractTool::DeleteTool(QGraphicsItem *tool) } } +Qt::PenStyle VAbstractTool::LineStyle() +{ + QStringList styles = Styles(); + switch(styles.indexOf(typeLine)) + { + case 0: + return Qt::NoPen; + break; + case 1: + return Qt::SolidLine; + break; + case 2: + return Qt::DashLine; + break; + case 3: + return Qt::DotLine; + break; + case 4: + return Qt::DashDotLine; + break; + case 5: + return Qt::DashDotDotLine; + break; + default: + return Qt::SolidLine; + break; + } +} + void VAbstractTool::LineCoefficients(const QLineF &line, qreal *a, qreal *b, qreal *c) { //coefficient for equation of segment @@ -251,6 +283,15 @@ void VAbstractTool::LineCoefficients(const QLineF &line, qreal *a, qreal *b, qre *c = - *a * p1.x() - *b * p1.y(); } +const QStringList VAbstractTool::Styles() +{ + //Keep synchronize with DialogTool lineStyles list!!! + QStringList styles; + styles << TypeLineNone << TypeLineLine << TypeLineDashLine << TypeLineDotLine << TypeLineDashDotLine + << TypeLineDashDotDotLine; + return styles; +} + void VAbstractTool::AddRecord(const qint64 id, const Tool::Tools &toolType, VDomDocument *doc) { qint64 cursor = doc->getCursor(); diff --git a/src/tools/vabstracttool.h b/src/tools/vabstracttool.h index 3d8eee4be..7141a5323 100644 --- a/src/tools/vabstracttool.h +++ b/src/tools/vabstracttool.h @@ -137,6 +137,15 @@ public: static const QString AttrAxisP2; static const QString TypeLineNone; static const QString TypeLineLine; + static const QString TypeLineDashLine; + static const QString TypeLineDotLine; + static const QString TypeLineDashDotLine; + static const QString TypeLineDashDotDotLine; + /** + * @brief Styles return list of all line styles. + * @return + */ + static const QStringList Styles(); /** * @brief AddRecord add record about tool in history. * @param id object id in container @@ -181,6 +190,10 @@ protected: * @brief currentColor current tool color. */ Qt::GlobalColor currentColor; + /** + * @brief typeLine line type. + */ + QString typeLine; /** * @brief AddToFile add tag with informations about tool into file. */ @@ -208,6 +221,11 @@ protected: * @param tool tool */ virtual void DeleteTool(QGraphicsItem *tool); + /** + * @brief LineStyle return pen style for current line style. + * @return pen style. + */ + Qt::PenStyle LineStyle(); template /** * @brief SetAttribute set attribute in pattern file. Replace "," by ".". diff --git a/src/widgets/vmaingraphicsview.cpp b/src/widgets/vmaingraphicsview.cpp index c65e2206a..7bb45251c 100644 --- a/src/widgets/vmaingraphicsview.cpp +++ b/src/widgets/vmaingraphicsview.cpp @@ -79,8 +79,8 @@ void VMainGraphicsView::scalingTime(qreal x) const QPointF p1mouse = mapFromScene(p0scene); const QPointF move = p1mouse - this->mapFromGlobal(QCursor::pos()); // The move - horizontalScrollBar()->setValue(move.x() + horizontalScrollBar()->value()); - verticalScrollBar()->setValue(move.y() + verticalScrollBar()->value()); + horizontalScrollBar()->setValue(static_cast(move.x()) + horizontalScrollBar()->value()); + verticalScrollBar()->setValue(static_cast(move.y()) + verticalScrollBar()->value()); VAbstractTool::NewSceneRect(this->scene(), this);