Skip to content
This repository has been archived by the owner on Sep 16, 2021. It is now read-only.

Commit

Permalink
only select the number portion when editing the value of a NumControl,
Browse files Browse the repository at this point in the history
…fixes #127
  • Loading branch information
cpdt committed Oct 30, 2018
1 parent e1ce4db commit dfce901
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
17 changes: 12 additions & 5 deletions editor/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ QString AxiomUtil::formatChannelFull(float val, AxiomModel::FormType form) {
return static_cast<QString>(formatFloatForm(val, form) % " " % getFormUnit(val, form)).trimmed();
}

QString AxiomUtil::formatNumForm(AxiomModel::NumValue value, bool includeForm) {
QString AxiomUtil::formatNumForm(AxiomModel::NumValue value, bool includeForm, int *outNumLength) {
if (fabsf(value.left - value.right) < 0.01f) {
auto formattedNum = formatFloatForm(value.left, value.form);
if (outNumLength) *outNumLength = formattedNum.size();
return includeForm ? static_cast<QString>(formattedNum % " " % getFormUnit(value.left, value.form))
: formattedNum;
} else {
Expand All @@ -111,10 +112,16 @@ QString AxiomUtil::formatNumForm(AxiomModel::NumValue value, bool includeForm) {
auto leftUnit = getFormUnit(value.left, value.form);
auto rightUnit = getFormUnit(value.right, value.form);

if (leftUnit == rightUnit)
return formattedLeft % " / " % formattedRight % " " % leftUnit;
else
return formattedLeft % " " % leftUnit % " / " % formattedRight % " " % rightUnit;
if (leftUnit == rightUnit) {
auto leftSide = static_cast<QString>(formattedLeft % " / " % formattedRight);
if (outNumLength) *outNumLength = leftSide.size();
return leftSide % " " % leftUnit;
} else {
auto resultStr =
static_cast<QString>(formattedLeft % " " % leftUnit % " / " % formattedRight % " " % rightUnit);
if (outNumLength) *outNumLength = resultStr.size();
return resultStr;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion editor/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace AxiomUtil {

QString formatChannelFull(float val, AxiomModel::FormType form);

QString formatNumForm(AxiomModel::NumValue value, bool includeForm);
QString formatNumForm(AxiomModel::NumValue value, bool includeForm, int *outNumLength = nullptr);

QRect makeRect(QPoint p1, QPoint p2);

Expand Down
4 changes: 3 additions & 1 deletion editor/widgets/controls/NumControlItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ void NumControlItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) {
auto selectedAction = menu.exec(event->screenPos());

if (selectedAction == setValAction) {
auto editor = new FloatingValueEditor(AxiomUtil::formatNumForm(control->value(), true), event->scenePos());
int formatNumLength;
auto formatNumString = AxiomUtil::formatNumForm(control->value(), true, &formatNumLength);
auto editor = new FloatingValueEditor(std::move(formatNumString), event->scenePos(), 0, formatNumLength);
scene()->addItem(editor);
connect(editor, &FloatingValueEditor::valueSubmitted, this, &NumControlItem::setStringValue);
} else if (selectedAction == copyValAction) {
Expand Down

0 comments on commit dfce901

Please sign in to comment.