3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/28/2010 Created this file. :-)
19 #include "filterdxf.h"
25 DlgText::DlgText(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
26 QDialog(parent, flags)
34 updateUniCharComboBox(0);
35 updateUniCharButton(0);
42 settings.beginGroup("Draw");
43 settings.setValue("TextHeight", ui.leHeight->text());
44 settings.setValue("TextFont", ui.cbFont->currentText());
45 settings.setValue("TextDefault", ui.cbDefault->isChecked());
46 settings.setValue("TextAlignment", getAlignment());
47 //settings.setValue("/TextLetterSpacing", leLetterSpacing->text());
48 //settings.setValue("/TextWordSpacing", leWordSpacing->text());
49 settings.setValue("TextLineSpacingFactor", ui.leLineSpacingFactor->text());
50 // settings.setValue("TextString", ui.teText->text());
51 settings.setValue("TextString", ui.teText->toPlainText());
52 //settings.setValue("/TextShape", getShape());
53 settings.setValue("TextAngle", ui.leAngle->text());
54 //settings.setValue("/TextRadius", leRadius->text());
59 void DlgText::updateUniCharComboBox(int)
61 QString t = ui.cbUniPage->currentText();
62 // int i1 = t.find('-');
63 int i1 = t.indexOf('-');
64 // int i2 = t.find(']');
65 int i2 = t.indexOf(']');
66 int min = t.mid(1, i1 - 1).toInt(NULL, 16);
67 int max = t.mid(i1 + 1, i2 - i1 - 1).toInt(NULL, 16);
68 ui.cbUniChar->clear();
70 for(int c=min; c<=max; c++)
73 sprintf(buf, "%04X", c);
74 // ui.cbUniChar->insertItem(QString("[%1] %2").arg(buf).arg(QChar(c)));
75 ui.cbUniChar->addItem(QString("[%1] %2").arg(buf).arg(QChar(c)));
80 * Sets the text entity represented by this dialog.
82 void DlgText::setText(Text & t, bool isNew)
91 //QString letterSpacing;
92 //QString wordSpacing;
93 QString lineSpacingFactor;
100 settings.beginGroup("Draw");
101 //default font depending on locale
102 // Q3CString iso = System::localeToISO( QTextCodec::locale() );
103 // QString iso = System::localeToISO(QTextCodec::locale());
104 QString iso = System::localeToISO(QLocale::system().name());
106 if (iso == "ISO8859-1")
107 fon = settings.value("TextFont", "normallatin1").toString();
108 else if (iso == "ISO8859-2")
109 fon = settings.value("TextFont", "normallatin2").toString();
110 else if (iso == "ISO8859-7")
111 fon = settings.value("TextFont", "greekc").toString();
112 else if (iso == "KOI8-U" || iso == "KOI8-R")
113 fon = settings.value("TextFont", "cyrillic_ii").toString();
115 fon = settings.value("TextFont", "standard").toString();
117 height = settings.value("TextHeight", "1.0").toString();
118 def = settings.value("TextDefault", true).toBool();
119 alignment = settings.value("TextAlignment", 1).toInt();
120 //letterSpacing = settings.value("/TextLetterSpacing", "0");
121 //wordSpacing = settings.value("/TextWordSpacing", "0");
122 lineSpacingFactor = settings.value("TextLineSpacingFactor", "1").toString();
123 str = settings.value("TextString", "").toString();
124 //shape = settings.value("/TextShape", "0");
125 angle = settings.value("TextAngle", "0").toString();
126 //radius = settings.value("/TextRadius", "10");
131 fon = text->getStyle();
133 height = QString("%1").arg(text->getHeight());
137 if (font->getLineSpacingFactor() == text->getLineSpacingFactor())
143 alignment = QString("%1").arg(text->getAlignment());
144 //QString letterSpacing = settings.value("/TextLetterSpacing", "0");
145 //QString wordSpacing = settings.value("/TextWordSpacing", "0");
146 lineSpacingFactor = QString("%1").arg(text->getLineSpacingFactor());
148 str = text->getText();
149 //QString shape = settings.value("/TextShape", "0");
150 angle = QString("%1").arg(Math::rad2deg(text->getAngle()));
153 ui.cbDefault->setChecked(def == "1");
155 ui.leHeight->setText(height);
156 setAlignment(alignment.toInt());
158 if (def != "1" || font == NULL)
160 //leLetterSpacing->setText(letterSpacing);
161 //leWordSpacing->setText(wordSpacing);
162 ui.leLineSpacingFactor->setText(lineSpacingFactor);
166 //leLetterSpacing->setText(font->getLetterSpacing());
167 //leWordSpacing->setText(font->getWordSpacing());
168 ui.leLineSpacingFactor->setText(QString("%1").arg(font->getLineSpacingFactor()));
171 // ui.teText->setText(str);
172 ui.teText->setPlainText(str);
173 //setShape(shape.toInt());
174 ui.leAngle->setText(angle);
175 //leRadius->setText(radius);
176 ui.teText->setFocus();
177 ui.teText->selectAll();
181 * Updates the text entity represented by the dialog to fit the choices of the user.
183 void DlgText::updateText()
187 text->setStyle(ui.cbFont->currentText());
188 text->setHeight(ui.leHeight->text().toDouble());
189 // text->setText(FilterDXF::toNativeString(ui.teText->text()));
190 text->setText(FilterDXF::toNativeString(ui.teText->toPlainText()));
191 //text->setLetterSpacing(leLetterSpacing.toDouble());
192 text->setLineSpacingFactor(ui.leLineSpacingFactor->text().toDouble());
193 text->setAlignment(getAlignment());
194 text->setAngle(Math::deg2rad(ui.leAngle->text().toDouble()));
198 void DlgText::setAlignmentTL()
203 void DlgText::setAlignmentTC()
208 void DlgText::setAlignmentTR()
213 void DlgText::setAlignmentML()
218 void DlgText::setAlignmentMC()
223 void DlgText::setAlignmentMR()
228 void DlgText::setAlignmentBL()
233 void DlgText::setAlignmentBC()
238 void DlgText::setAlignmentBR()
243 void DlgText::setAlignment(int a)
245 ui.bTL->setChecked(false);
246 ui.bTC->setChecked(false);
247 ui.bTR->setChecked(false);
248 ui.bML->setChecked(false);
249 ui.bMC->setChecked(false);
250 ui.bMR->setChecked(false);
251 ui.bBL->setChecked(false);
252 ui.bBC->setChecked(false);
253 ui.bBR->setChecked(false);
258 ui.bTL->setChecked(true);
261 ui.bTC->setChecked(true);
264 ui.bTR->setChecked(true);
267 ui.bML->setChecked(true);
270 ui.bMC->setChecked(true);
273 ui.bMR->setChecked(true);
276 ui.bBL->setChecked(true);
279 ui.bBC->setChecked(true);
282 ui.bBR->setChecked(true);
289 int DlgText::getAlignment()
291 if (ui.bTL->isChecked())
293 else if (ui.bTC->isChecked())
295 else if (ui.bTR->isChecked())
297 else if (ui.bML->isChecked())
299 else if (ui.bMC->isChecked())
301 else if (ui.bMR->isChecked())
303 else if (ui.bBL->isChecked())
305 else if (ui.bBC->isChecked())
307 else if (ui.bBR->isChecked())
313 void DlgText::setFont(const QString & f)
315 // ui.cbFont->setCurrentText(f);
316 ui.cbFont->setItemText(ui.cbFont->currentIndex(), f);
317 font = ui.cbFont->getFont();
318 defaultChanged(false);
322 void DlgText::setShape(int s) {
325 rbStraight->setChecked(true);
328 rbRound1->setChecked(true);
331 rbRound2->setChecked(true);
338 int DlgText::getShape() {
339 if (rbStraight->isOn()) {
341 } else if (rbRound1->isOn()) {
343 } else if (rbRound2->isOn()) {
350 void DlgText::defaultChanged(bool)
352 if (ui.cbDefault->isChecked() && font != NULL)
353 ui.leLineSpacingFactor->setText(QString("%1").arg(font->getLineSpacingFactor()));
356 void DlgText::loadText()
358 // QString fn = Q3FileDialog::getOpenFileName(QString::null, QString::null, this);
359 QString fn = QFileDialog::getOpenFileName(this);
365 void DlgText::load(const QString & fn)
369 if (!f.open(QIODevice::ReadOnly))
372 // Q3TextStream ts(&f);
374 // ui.teText->setText(ts.readAll());
375 ui.teText->setPlainText(ts.readAll());
378 void DlgText::saveText()
380 // QString fn = Q3FileDialog::getSaveFileName(QString::null, QString::null, this);
381 QString fn = QFileDialog::getSaveFileName(this);
387 void DlgText::save(const QString & fn)
389 // QString text = ui.teText->text();
390 QString text = ui.teText->toPlainText();
393 if (f.open(QIODevice::WriteOnly))
395 // Q3TextStream t(&f);
402 void DlgText::insertSymbol(int)
404 QString str = ui.cbSymbol->currentText();
405 // int i = str.find('(');
406 int i = str.indexOf('(');
409 // ui.teText->insert(QString("%1").arg(str.at(i + 1)));
410 ui.teText->insertPlainText(QString("%1").arg(str.at(i + 1)));
413 void DlgText::updateUniCharButton(int)
415 QString t = ui.cbUniChar->currentText();
416 // int i1 = t.find(']');
417 int i1 = t.indexOf(']');
418 int c = t.mid(1, i1 - 1).toInt(NULL, 16);
419 ui.bUnicode->setText(QString("%1").arg(QChar(c)));
422 void DlgText::insertChar()
424 QString t = ui.cbUniChar->currentText();
425 // int i1 = t.find(']');
426 int i1 = t.indexOf(']');
427 int c = t.mid(1, i1 - 1).toInt(NULL, 16);
428 // ui.teText->insert(QString("%1").arg(QChar(c)));
429 ui.teText->insertPlainText(QString("%1").arg(QChar(c)));