Commit 7488776e authored by Mathieu Tillet's avatar Mathieu Tillet
Browse files

Fix various small problems

- Add a proper shortcut
- Fix the bounding box not following the sector when moved, but updating
it
- Set new endAngle at creation
- Fix a bug where the topLeft corner drag was mismanaged due to a bad
variable
- Better check for angles and radii values
parent b4b139b5
......@@ -327,10 +327,11 @@ InstrumentWidgetDecoder::decodeSector(const QMap<QString, QVariant> &map) {
const double innerRadius = map[QString("innerRadius")].toDouble();
const double startAngle = map[QString("startAngle")].toDouble();
const double endAngle = map[QString("endAngle")].toDouble();
const QPointF center = map[QString("center")].toPointF();
const double centerX = map[QString("centerX")].toDouble();
const double centerY = map[QString("centerY")].toDouble();
return new Shape2DSector(innerRadius, outerRadius, startAngle, endAngle,
center);
QPointF(centerX, centerY));
}
Shape2D *
......
......@@ -408,14 +408,16 @@ InstrumentWidgetEncoder::encodeSector(const Shape2DSector *obj) {
const auto innerRadius = obj->getDouble("innerRadius");
const auto startAngle = obj->getDouble("startAngle");
const auto endAngle = obj->getDouble("endAngle");
const auto center = obj->getPoint("center");
const auto centerX = obj->getPoint("center").x();
const auto centerY = obj->getPoint("center").y();
QMap<QString, QVariant> map;
map.insert(QString("outerRadius"), QVariant(outerRadius));
map.insert(QString("innerRadius"), QVariant(innerRadius));
map.insert(QString("startAngle"), QVariant(startAngle));
map.insert(QString("endAngle"), QVariant(endAngle));
map.insert(QString("center"), QVariant(center));
map.insert(QString("centerX"), QVariant(centerX));
map.insert(QString("centerY"), QVariant(centerY));
return map;
}
......
......@@ -134,7 +134,8 @@ InstrumentWidgetMaskTab::InstrumentWidgetMaskTab(InstrumentWidget *instrWidget)
m_sector->setCheckable(true);
m_sector->setAutoExclusive(true);
m_sector->setIcon(QIcon(":/MaskTools/selection-sector.png"));
m_sector->setToolTip("Draw a circle sector (Shift+Alt+R)");
m_sector->setToolTip("Draw a circle sector (Shift+Alt+S)");
m_sector->setShortcut(QKeySequence("Shift+Alt+S"));
m_free_draw = new QPushButton();
m_free_draw->setCheckable(true);
......
......@@ -773,7 +773,7 @@ void Shape2DSector::refit() {
BBox.bottomRight().y() == bRectBottomRight.y()) {
// top left corner is moving
computeScaling(BBox.topLeft(), BBox.bottomRight(), bRectBottomRight, 0);
computeScaling(BBox.topLeft(), BBox.bottomRight(), bRectTopLeft, 0);
} else if (BBox.topLeft().x() != bRectTopLeft.x() &&
BBox.bottomRight().y() != bRectBottomRight.y() &&
......@@ -818,6 +818,7 @@ void Shape2DSector::refit() {
m_center.setX(m_center.x() + xDiff);
m_center.setY(m_center.y() + yDiff);
resetBoundingRect();
}
}
......@@ -948,9 +949,15 @@ void Shape2DSector::setShapeControlPoint(size_t i, const QPointF &pos) {
switch (i) {
case 0:
m_outerRadius = sqrt(pow(to_center.x(), 2) + pow(to_center.y(), 2));
if (m_outerRadius < m_innerRadius) {
m_outerRadius = 1.01 * m_innerRadius;
}
break;
case 1:
m_innerRadius = sqrt(pow(to_center.x(), 2) + pow(to_center.y(), 2));
if (m_outerRadius < m_innerRadius) {
m_innerRadius = 0.99 * m_outerRadius;
}
break;
case 2:
newAngle = atan2(to_center.y(), to_center.x());
......@@ -1026,7 +1033,7 @@ void Shape2DSector::setShapeControlPoint(size_t i, const QPointF &pos) {
m_endAngle = newAngle;
break;
}
refit();
resetBoundingRect();
}
QStringList Shape2DSector::getDoubleNames() const {
......@@ -1064,10 +1071,10 @@ void Shape2DSector::setDouble(const QString &prop, double value) {
m_innerRadius = value;
refit();
} else if (prop == "startAngle") {
m_startAngle = value * to_radians;
m_startAngle = fmod(value, 360) * to_radians;
refit();
} else if (prop == "endAngle") {
m_endAngle = value * to_radians;
m_endAngle = fmod(value, 360) * to_radians;
refit();
}
}
......
......@@ -179,7 +179,7 @@ Shape2D *Shape2DCollection::createShape(const QString &type, int x,
} else if (type.toLower() == "rectangle") {
return new Shape2DRectangle(p, QSizeF(0, 0));
} else if (type.toLower() == "sector") {
return new Shape2DSector(0.001, 0.002, 0, 5.28, p);
return new Shape2DSector(0.001, 0.002, 0, M_PI / 2, p);
} else if (type.toLower() == "free") {
return new Shape2DFree(p);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment