File size: 8,785 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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | /*******************************************************************************
*
This file is part of the LibreCAD project, a 2D CAD program
Copyright (C) 2024 LibreCAD.org
Copyright (C) 2024 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 "lc_rotate2options.h"
#include "ui_lc_rotate2options.h"
#include "rs_actionmodifyrotate2.h"
// todo - potentially, instead of specifying secondary angle it is possible to let the user enter the sum of angles
// todo - and calculate secondary angle based on angle1 and that sum.
// todo - Such approach will simplify ui (as sum defines resulting angle of entity) - yet will break compatibility with
// todo - previous versions. I'm not sure that this is popular command, yet still...
// fixme - think and decide which way of setting secondary angle is more convenient...
LC_Rotate2Options::LC_Rotate2Options()
: LC_ActionOptionsWidgetBase(RS2::ActionModifyRotate2, "Modify", "Rotate2")
, ui(new Ui::LC_Rotate2Options){
ui->setupUi(this);
connect(ui->cbKeepOriginals, &QCheckBox::clicked, this, &LC_Rotate2Options::cbKeepOriginalsClicked);
connect(ui->cbMultipleCopies, &QCheckBox::clicked, this, &LC_Rotate2Options::cbMultipleCopiesClicked);
connect(ui->cbCurrentAttr, &QCheckBox::clicked, this, &LC_Rotate2Options::cbUseCurrentAttributesClicked);
connect(ui->cbCurrentLayer, &QCheckBox::clicked, this, &LC_Rotate2Options::cbUseCurrentLayerClicked);
connect(ui->cbSameAngleForCopies, &QCheckBox::clicked, this, &LC_Rotate2Options::cbSameAngleForCopiesClicked);
connect(ui->cbAnglesMirrored, &QCheckBox::clicked, this, &LC_Rotate2Options::cbAnglesMirroredClicked);
connect(ui->leAngle1, &QLineEdit::editingFinished, this, &LC_Rotate2Options::onAngle1EditingFinished);
connect(ui->leAngle2, &QLineEdit::editingFinished, this, &LC_Rotate2Options::onAngle2EditingFinished);
// fixme - remove later if the control will not be reused for some other flag
ui->cbSameAngleForCopies->hide();
pickAngleSetup("angle", ui->tbPickAngle, ui->leAngle1);
pickAngleSetup("angle2", ui->tbPickAngle2, ui->leAngle2);
}
LC_Rotate2Options::~LC_Rotate2Options(){
delete ui;
}
void LC_Rotate2Options::doSaveSettings() {
save("KeepOriginals", ui->cbKeepOriginals->isChecked());
save("MultipleCopies", ui->cbMultipleCopies->isChecked());
save("UseCurrentLayer",ui->cbCurrentLayer->isChecked());
save("UseCurrentAttributes",ui->cbCurrentAttr->isChecked());
save("Angle1", ui->leAngle1->text());
save("Angle2", ui->leAngle2->text());
save("MirrorAngles", ui->cbAnglesMirrored->isChecked());
save("Copies", ui->sbNumberOfCopies->value());
save("Angle1", ui->leAngle1->text());
save("Angle2", ui->leAngle2->text());
save("SameAngleForCopies", ui->cbSameAngleForCopies->isChecked());
}
void LC_Rotate2Options::doSetAction(RS_ActionInterface *a, bool update){
m_action = dynamic_cast<RS_ActionModifyRotate2 *>(a);
QString angle1;
QString angle2;
bool useMultipleCopies;
bool keepOriginals;
bool useCurrentLayer;
bool useCurrentAttributes;
int copiesNumber;
bool sameAngle;
bool mirrorAngles;
if (update){
useCurrentLayer = m_action->isUseCurrentLayer();
useCurrentAttributes = m_action->isUseCurrentAttributes();
keepOriginals = m_action->isKeepOriginals();
useMultipleCopies = m_action->isUseMultipleCopies();
copiesNumber = m_action->getCopiesNumber();
sameAngle = m_action->isUseSameAngle2ForCopies();
mirrorAngles = m_action->isMirrorAngles();
angle1 = fromDouble(RS_Math::rad2deg(m_action->getAngle1()));
angle2 = fromDouble(RS_Math::rad2deg(m_action->getAngle2()));
}
else{
useCurrentLayer = loadBool("UseCurrentLayer", false);
useCurrentAttributes = loadBool("UseCurrentAttributes", false);
keepOriginals = loadBool("KeepOriginals", false);
useMultipleCopies = loadBool("MultipleCopies", false);
copiesNumber = loadInt("Copies", 1);
sameAngle = loadBool("SameAngleForCopies", false);
mirrorAngles = loadBool("MirrorAngles", true);
angle1 = load("Angle1", "30");
angle2 = load("Angle2", "30");
}
setUseMultipleCopiesToActionAndView(useMultipleCopies);
setCopiesNumberToActionAndView(copiesNumber);
setUseCurrentLayerToActionAndView(useCurrentLayer);
setUseCurrentAttributesToActionAndView(useCurrentAttributes);
setKeepOriginalsToActionAndView(keepOriginals);
setSameAngleForCopiesToActionAndView(sameAngle);
setAnglesMirroredToModelAndView(mirrorAngles);
setAngle1ToActionAndView(angle1);
setAngle2ToActionAndView(angle2);
}
void LC_Rotate2Options::setUseMultipleCopiesToActionAndView(bool copies) {
m_action->setUseMultipleCopies(copies);
ui->cbMultipleCopies->setChecked(copies);
ui->sbNumberOfCopies->setEnabled(copies);
ui->cbSameAngleForCopies->setEnabled(copies);
}
void LC_Rotate2Options::setUseCurrentLayerToActionAndView(bool val) {
m_action->setUseCurrentLayer(val);
ui->cbCurrentLayer->setChecked(val);
}
void LC_Rotate2Options::setUseCurrentAttributesToActionAndView(bool val) {
m_action->setUseCurrentAttributes(val);
ui->cbCurrentAttr->setChecked(val);
}
void LC_Rotate2Options::setKeepOriginalsToActionAndView(bool val) {
m_action->setKeepOriginals(val);
ui->cbKeepOriginals->setChecked(val);
}
void LC_Rotate2Options::setCopiesNumberToActionAndView(int number) {
if (number < 1){
number = 1;
}
m_action->setCopiesNumber(number);
ui->sbNumberOfCopies->setValue(number);
}
void LC_Rotate2Options::setAnglesMirroredToModelAndView(bool checked) {
ui->cbAnglesMirrored->setChecked(checked);
ui->leAngle2->setEnabled(!checked);
ui->tbPickAngle2->setEnabled(!checked);
m_action->setMirrorAngles(checked);
setAngle1ToActionAndView(ui->leAngle1->text()); // just force update both edits
}
void LC_Rotate2Options::setSameAngleForCopiesToActionAndView(bool val) {
m_action->setUseSameAngle2ForCopies(val);
ui->cbSameAngleForCopies->setChecked(val);
}
void LC_Rotate2Options::setAngle1ToActionAndView(QString val) {
double angle;
if (toDoubleAngleDegrees(val, angle, 0.0, false)){
ui->leAngle1->setText(fromDouble(angle));
m_action->setAngle1(RS_Math::deg2rad(angle));
bool anglesMirrored = ui->cbAnglesMirrored->isChecked();
if (anglesMirrored){
ui->leAngle2->setText(fromDouble(-angle));
m_action->setAngle2(RS_Math::deg2rad(-angle));
}
}
}
void LC_Rotate2Options::setAngle2ToActionAndView(QString val) {
double angle;
if (toDoubleAngleDegrees(val, angle, 0.0, false)) {
const QString &angleStr = fromDouble(angle);
ui->leAngle2->setText(angleStr);
m_action->setAngle2(RS_Math::deg2rad(angle));
}
}
void LC_Rotate2Options::languageChange() {
ui->retranslateUi(this);
}
void LC_Rotate2Options::onAngle1EditingFinished(){
const QString &expr = ui->leAngle1->text();
setAngle1ToActionAndView(expr);
}
void LC_Rotate2Options::onAngle2EditingFinished(){
const QString &expr = ui->leAngle2->text();
setAngle2ToActionAndView(expr);
}
void LC_Rotate2Options::cbKeepOriginalsClicked(bool val) {
setKeepOriginalsToActionAndView(val);
}
void LC_Rotate2Options::cbMultipleCopiesClicked(bool val) {
setUseMultipleCopiesToActionAndView(val);
}
void LC_Rotate2Options::cbUseCurrentAttributesClicked(bool val) {
setUseCurrentAttributesToActionAndView(val);
}
void LC_Rotate2Options::cbUseCurrentLayerClicked(bool val) {
setUseCurrentLayerToActionAndView(val);
}
void LC_Rotate2Options::cbSameAngleForCopiesClicked(bool val) {
setSameAngleForCopiesToActionAndView(val);
}
void LC_Rotate2Options::cbAnglesMirroredClicked(bool checked) {
setAnglesMirroredToModelAndView(checked);
}
void LC_Rotate2Options::on_sbNumberOfCopies_valueChanged(int number) {
setCopiesNumberToActionAndView(number);
}
|