File size: 7,142 Bytes
a5ffdcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
 * ********************************************************************************
 * This file is part of the LibreCAD project, a 2D CAD program
 *
 * Copyright (C) 2025 LibreCAD.org
 * Copyright (C) 2025 sand1024
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 * ********************************************************************************
 */

#include <QLineEdit>
#include "lc_entitypropertieseditorwidget.h"

#include <QToolButton>

#include "lc_pointpickbutton.h"

LC_EntityPropertiesEditorWidget::LC_EntityPropertiesEditorWidget(QWidget* parent):
   QWidget(parent), LC_EntityPropertiesEditorSupport(nullptr) {
}

void LC_EntityPropertiesEditorWidget::interactiveInputUpdate(
    LC_ActionContext::InteractiveInputInfo::InputType inputType,
    const QString &tag, double valueOne, double valueTwo) {
    QList<QLineEdit*> list = findChildren<QLineEdit*>();
    QPair<QString, QString> vectorCoordinatesUI;
    if (inputType == LC_ActionContext::InteractiveInputInfo::POINT) {
        RS_Vector point = RS_Vector(valueOne, valueTwo);
        vectorCoordinatesUI = toUIStr(point);
    }

    bool pointComponentSet = false;
    bool lineEditFound = false;
    for (auto lineEdit : list) {
        auto propertyInputType = lineEdit->property("_interactiveInputEdit");
        auto propertyTag = lineEdit->property("_interactiveInputTag");
        if (propertyInputType.isValid() && !propertyInputType.isNull()) {
            QString tagValue = propertyTag.toString();
            if (tag == tagValue) {
                switch (inputType) {
                    case LC_ActionContext::InteractiveInputInfo::DISTANCE: {
                        toUIValue(valueOne, lineEdit);
                        emit lineEdit->editingFinished();
                        lineEditFound = true;
                        break;
                    }
                    case LC_ActionContext::InteractiveInputInfo::ANGLE: {
                        // toUIAngleDeg(valueOne, lineEdit);
                        toUIAngleDegRaw(valueOne, lineEdit);
                        emit lineEdit->editingFinished();
                        lineEditFound = true;
                        break;
                    }
                    case LC_ActionContext::InteractiveInputInfo::POINT: {
                        int component = lineEdit->property("_interactiveInputComponent").toInt();
                        if (component == 1) {
                            lineEdit->setText(vectorCoordinatesUI.first);
                            if (pointComponentSet) {
                                lineEditFound = true;
                            }
                            else {
                                pointComponentSet = true;
                            }
                            emit lineEdit->editingFinished();
                        }
                        else if (component == 2) {
                            lineEdit->setText(vectorCoordinatesUI.second);
                            if (pointComponentSet) {
                                lineEditFound = true;
                            }
                            else {
                                pointComponentSet = true;
                            }
                            emit lineEdit->editingFinished();
                        }
                        break;
                    }
                    default: {
                        break;
                    }
                }
            }
        }
        if (lineEditFound) {
            lineEdit->setFocus();
            break;
        }
    }
}

void LC_EntityPropertiesEditorWidget::onInteractiveInputButtonClicked([[maybe_unused]]bool checked) {
    auto senderButton = dynamic_cast<QToolButton*>(sender());
    if (senderButton != nullptr) {
        auto property = senderButton->property ("_interactiveInputButton");
        if (property.isValid()) {
            auto inputType = static_cast<LC_ActionContext::InteractiveInputInfo::InputType>(property.toInt());
            auto tagProperty = senderButton->property ("_interactiveInputTag");
            QString tag = tagProperty.toString();
            emit interactiveInputRequested(inputType, tag);
        }
    }
}

void LC_EntityPropertiesEditorWidget::pickDistanceSetup(QToolButton* button,
                                                                 const QString &tag, QLineEdit* lineEditOne,
                                                                 QLineEdit* lineEditTwo) {
    setupInteractiveInputControls(button, LC_ActionContext::InteractiveInputInfo::DISTANCE, tag, lineEditOne, lineEditTwo);
}

void LC_EntityPropertiesEditorWidget::pickAngleSetup(QToolButton* button,
                                                                 const QString &tag, QLineEdit* lineEditOne,
                                                                 QLineEdit* lineEditTwo) {
    setupInteractiveInputControls(button, LC_ActionContext::InteractiveInputInfo::ANGLE, tag, lineEditOne, lineEditTwo);
}

void LC_EntityPropertiesEditorWidget::pickPointSetup(LC_PointPickButton* button,
                                                                 const QString &tag, QLineEdit* lineEditOne,
                                                                 QLineEdit* lineEditTwo) {
    setupInteractiveInputControls(button->getButton(), LC_ActionContext::InteractiveInputInfo::POINT, tag, lineEditOne, lineEditTwo);
}



void LC_EntityPropertiesEditorWidget::setupInteractiveInputControls(QToolButton* button,
                                                                 LC_ActionContext::InteractiveInputInfo::InputType inputType, const QString &tag, QLineEdit* lineEditOne,
                                                                 QLineEdit* lineEditTwo) {

    button->setProperty ("_interactiveInputButton", inputType);
    button->setProperty ("_interactiveInputTag", tag);
    button->connect(button, &QToolButton::clicked, this, &LC_EntityPropertiesEditorWidget::onInteractiveInputButtonClicked);

    lineEditOne->setProperty ("_interactiveInputEdit", inputType);
    lineEditOne->setProperty("_interactiveInputTag", tag);
    lineEditOne->setProperty("_interactiveInputComponent",1);
    if (lineEditTwo != nullptr) {
        lineEditTwo->setProperty("_interactiveInputTag", tag);
        lineEditTwo->setProperty ("_interactiveInputEdit", inputType);
        lineEditTwo->setProperty("_interactiveInputComponent",2);
    }
};