Skip to content

Commit

Permalink
implemented LineWidth
Browse files Browse the repository at this point in the history
  • Loading branch information
godardma committed Sep 5, 2024
1 parent e4adb1a commit 9f580bc
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 32 deletions.
5 changes: 5 additions & 0 deletions viewer/propertyeditdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#include <QDebug>

// TO DELETE
#include <iostream>

PropertyEditDialog::PropertyEditDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::PropertyEditDialog)
Expand All @@ -21,6 +24,7 @@ QJsonObject PropertyEditDialog::showEditorForJson(QJsonObject init)
dlg->ui->comboBox_LineStyle->setCurrentText(init["LineStyle"].toString());
dlg->ui->comboBox_FaceColor->setCurrentText(init["FaceColor"].toString());
dlg->ui->comboBox_EdgeColor->setCurrentText(init["EdgeColor"].toString());
dlg->ui->lineEdit_LineWidth->setText(init["LineWidth"].toString());

QJsonObject json;

Expand All @@ -29,6 +33,7 @@ QJsonObject PropertyEditDialog::showEditorForJson(QJsonObject init)
json["LineStyle"] = QJsonValue(dlg->ui->comboBox_LineStyle->currentText());
json["FaceColor"] = QJsonValue(dlg->ui->comboBox_FaceColor->currentText());
json["EdgeColor"] = QJsonValue(dlg->ui->comboBox_EdgeColor->currentText());
json["LineWidth"] = QJsonValue(dlg->ui->lineEdit_LineWidth->text());
}

// qDebug() << "dlg json result" << json;
Expand Down
41 changes: 41 additions & 0 deletions viewer/propertyeditdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,47 @@
</item>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Line width</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="lineEdit_LineWidth">
<item>
<property name="text">
<string/>
</property>
</item>
<item>
<property name="text">
<string>-</string>
</property>
</item>
<item>
<property name="text">
<string>--</string>
</property>
</item>
<item>
<property name="text">
<string>-.</string>
</property>
</item>
<item>
<property name="text">
<string>-..</string>
</property>
</item>
<item>
<property name="text">
<string>..</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</widget>
Expand Down
66 changes: 35 additions & 31 deletions viewer/vibesgraphicsitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <cmath>
using namespace std;

//TO DELETE
#include <iostream>

// The only instance of VibesDefaults
VibesDefaults VibesDefaults::_instance;
Expand Down Expand Up @@ -346,22 +348,27 @@ bool VibesGraphicsGroup::parseJsonGraphics(const QJsonObject &json)
foreach(QGraphicsItem* child, children)
{
VibesGraphicsItem * item = qgraphicsitem_cast<VibesGraphicsItem *>(child);

// Each item gets the group properties
// Each item gets the group properties if needed
if (item)
{
if (json["EdgeColor"]!=QJsonValue())
if (json["EdgeColor"].toString()!=QString())
{
item->setJsonValue("EdgeColor",json["EdgeColor"]);
}
if (json["FaceColor"]!=QJsonValue())
if (json["FaceColor"].toString()!=QString())
{
item->setJsonValue("FaceColor",json["FaceColor"]);
}
if (json["LineStyle"]!=QJsonValue())
if (json["LineStyle"].toString()!=QString())
{
item->setJsonValue("LineStyle",json["LineStyle"]);
}
if (json["LineWidth"].toString()!=QString())
{
// storing old line width for clean erasing when needed
item->setJsonValue("OldLineWidth",item->json()["LineWidth"]);
item->setJsonValue("LineWidth",json["LineWidth"]);
}
item->updateProj();
}

Expand Down Expand Up @@ -390,7 +397,7 @@ bool VibesGraphicsBox::parseJsonGraphics(const QJsonObject &json)
this->_nbDim = bounds.size() / 2;

// Set graphical properties
this->setPen(vibesDefaults.pen(jsonValue("EdgeColor").toString()));
this->setPen(vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString()));
this->setBrush(vibesDefaults.brush(jsonValue("FaceColor").toString()));

// Update successful
Expand All @@ -408,7 +415,7 @@ bool VibesGraphicsBox::computeProjection(int dimX, int dimY)

// Get shape color (or default if not specified)
const QBrush & brush = vibesDefaults.brush(jsonValue("FaceColor").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString());

Q_ASSERT(json.contains("type"));
Q_ASSERT(json["type"].toString() == "box");
Expand Down Expand Up @@ -503,7 +510,7 @@ bool VibesGraphicsBoxes::computeProjection(int dimX, int dimY)

// Get shape color (or default if not specified)
const QBrush & brush = vibesDefaults.brush(jsonValue("FaceColor").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString());

// Now process shape-specific properties
// (we can only update properties of a shape, but mutation into another type is not supported)
Expand Down Expand Up @@ -627,7 +634,7 @@ bool VibesGraphicsBoxesUnion::computeProjection(int dimX, int dimY)

// Get shape color (or default if not specified)
const QBrush & brush = vibesDefaults.brush(jsonValue("FaceColor").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString());

// Now process shape-specific properties
// (we can only update properties of a shape, but mutation into another type is not supported)
Expand Down Expand Up @@ -730,7 +737,7 @@ bool VibesGraphicsEllipse::computeProjection(int dimX, int dimY)

// Get shape color (or default if not specified)
const QBrush & brush = vibesDefaults.brush(jsonValue("FaceColor").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString());

Q_ASSERT(json.contains("type"));
Q_ASSERT(json["type"].toString() == "ellipse");
Expand Down Expand Up @@ -886,10 +893,7 @@ bool VibesGraphicsLine::computeProjection(int dimX, int dimY)
const QJsonObject & json = this->_json;

// Get shape color (or default if not specified)
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString());

// To erase last draw
const QPen & pen_eraser = vibesDefaults.pen("white","-");
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString());

// Now process shape-specific properties
// (we can only update properties of a shape, but mutation into another type is not supported)
Expand Down Expand Up @@ -944,7 +948,7 @@ bool VibesGraphicsPolygon::parseJsonGraphics(const QJsonObject &json)
this->_nbDim = nbCols;

// Set pen
this->setPen(vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString()));
this->setPen(vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString()));
this->setBrush(vibesDefaults.brush(jsonValue("FaceColor").toString()));

// Update successful
Expand All @@ -962,7 +966,7 @@ bool VibesGraphicsPolygon::computeProjection(int dimX, int dimY)

// Get shape color (or default if not specified)
const QBrush & brush = vibesDefaults.brush(jsonValue("FaceColor").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString());

Q_ASSERT(json.contains("type"));
Q_ASSERT(json["type"].toString() == "polygon");
Expand Down Expand Up @@ -1028,11 +1032,11 @@ bool VibesGraphicsVehicle::computeProjection(int dimX, int dimY)

// Get shape color (or default if not specified)
const QBrush & brush = vibesDefaults.brush(jsonValue("FaceColor").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString());

// To erase last draw
const QBrush & brush_eraser = vibesDefaults.brush("white");
const QPen & pen_eraser = vibesDefaults.pen("white","-");
const QPen & pen_eraser = vibesDefaults.pen("white","-",jsonValue("OldLineWidth").toString());

Q_ASSERT(json.contains("type"));
Q_ASSERT(json["type"].toString() == "vehicle");
Expand Down Expand Up @@ -1116,10 +1120,10 @@ bool VibesGraphicsVehicleAUV::computeProjection(int dimX, int dimY)

// Get shape color (or default if not specified)
const QBrush & brush = vibesDefaults.brush(jsonValue("FaceColor").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString());

// To erase last draw
const QPen & pen_eraser = vibesDefaults.pen("white","-");
const QPen & pen_eraser = vibesDefaults.pen("white","-",jsonValue("OldLineWidth").toString());
const QBrush & brush_eraser = vibesDefaults.brush("white");


Expand Down Expand Up @@ -1242,11 +1246,11 @@ bool VibesGraphicsVehicleTank::computeProjection(int dimX, int dimY)

// Get shape color (or default if not specified)
const QBrush & brush = vibesDefaults.brush(jsonValue("FaceColor").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString());

// To erase last draw
const QBrush & brush_eraser = vibesDefaults.brush("white");
const QPen & pen_eraser = vibesDefaults.pen("white","-");
const QPen & pen_eraser = vibesDefaults.pen("white","-",jsonValue("OldLineWidth").toString());

Q_ASSERT(json.contains("type"));
Q_ASSERT(json["type"].toString() == "vehicle_tank");
Expand Down Expand Up @@ -1352,7 +1356,7 @@ bool VibesGraphicsArrow::computeProjection(int dimX, int dimY)

// Get shape color (or default if not specified)
const QBrush & brush = vibesDefaults.brush(jsonValue("FaceColor").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString());

// Now process shape-specific properties
// (we can only update properties of a shape, but mutation into another type is not supported)
Expand Down Expand Up @@ -1469,11 +1473,11 @@ bool VibesGraphicsPie::computeProjection(int dimX, int dimY)

// Get shape color (or default if not specified)
const QBrush & brush = vibesDefaults.brush(jsonValue("FaceColor").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString());

// To erase last draw
const QBrush & brush_eraser = vibesDefaults.brush("white");
const QPen & pen_eraser = vibesDefaults.pen("white","-");
const QPen & pen_eraser = vibesDefaults.pen("white","-",jsonValue("OldLineWidth").toString());

// Now process shape-specific properties
// (we can only update properties of a shape, but mutation into another type is not supported)
Expand Down Expand Up @@ -1592,7 +1596,7 @@ bool VibesGraphicsPoint::computeProjection(int dimX, int dimY)
double cy = point[1].toDouble();

const QBrush & brush = vibesDefaults.brush(jsonValue("FaceColor").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString());

// Now process shape-specific properties
// (we can only update properties of a shape, but mutation into another type is not supported)
Expand Down Expand Up @@ -1669,11 +1673,11 @@ bool VibesGraphicsPoints::computeProjection(int dimX, int dimY)

// Get shape color (or default if not specified)
const QBrush & brush = vibesDefaults.brush(jsonValue("FaceColor").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString());

// To erase last draw
const QBrush & brush_eraser = vibesDefaults.brush("white");
const QPen & pen_eraser = vibesDefaults.pen("white","-");
const QPen & pen_eraser = vibesDefaults.pen("white","-",jsonValue("OldLineWidth").toString());

// Now process shape-specific properties
// (we can only update properties of a shape, but mutation into another type is not supported)
Expand Down Expand Up @@ -1785,11 +1789,11 @@ bool VibesGraphicsRing::computeProjection(int dimX, int dimY)

// Get shape color (or default if not specified)
const QBrush & brush = vibesDefaults.brush(jsonValue("FaceColor").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString());

// To erase last draw
const QBrush & brush_eraser = vibesDefaults.brush("white");
const QPen & pen_eraser = vibesDefaults.pen("white","-");
const QPen & pen_eraser = vibesDefaults.pen("white","-",jsonValue("OldLineWidth").toString());

// Now process shape-specific properties
// (we can only update properties of a shape, but mutation into another type is not supported)
Expand Down Expand Up @@ -1886,7 +1890,7 @@ bool VibesGraphicsRaster::computeProjection(int dimX, int dimY)
QImage image(filename);
QPixmap pixmap = QPixmap::fromImage(image);
if (json.contains("EdgeColor")) {
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString());
const QPen & pen = vibesDefaults.pen(jsonValue("EdgeColor").toString(),jsonValue("LineStyle").toString(),jsonValue("LineWidth").toString());
pixmap.setMask(pixmap.createMaskFromColor(pen.color().rgb()));

}
Expand Down
9 changes: 8 additions & 1 deletion viewer/vibesgraphicsitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include <QHash>
#include <QPen>

// TO DELETE
#include <iostream>

// Singleton class to hold Vibes defaults and constants
class VibesDefaults {
QHash<QString, QBrush> _brushes;
Expand All @@ -38,18 +41,22 @@ class VibesDefaults {
if(style == QString("..")) return Qt::DotLine;
return Qt::SolidLine;
}
const qreal parsePenWidth(const QString& width){
return std::max(0.,width.toDouble());
}
const QBrush brush(const QString & name = QString()) {
if( !_brushes.contains(name)){
_brushes[name] = QBrush(parseColorName(name));
}
return _brushes[name];
}

const QPen pen(const QString & name = QString(),const QString & style = QString()) {
const QPen pen(const QString & name = QString(),const QString & style = QString(),const QString & width = QString()) {
if( !_pens.contains(name)){
_pens[name] = QPen(parseColorName(name),0);
}
_pens[name].setStyle(parsePenStyle(style));
_pens[name].setWidthF(parsePenWidth(width));
return _pens[name];
}

Expand Down

0 comments on commit 9f580bc

Please sign in to comment.