|
20 | 20 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
21 | 21 | ***************************************************************************/ |
22 | 22 |
|
| 23 | +#include <algorithm> // for sort, unique |
| 24 | + |
23 | 25 | #include <QAbstractButton> // for QAbstractButton |
24 | 26 | #include <QButtonGroup> // for QButtonGroup |
25 | 27 | #include <QByteArray> // for QByteArray |
|
34 | 36 | #include <QFontDialog> // for QFontDialog |
35 | 37 | #include <QLabel> // for QLabel |
36 | 38 | #include <QLineEdit> // for QLineEdit |
| 39 | +#include <QList> // for QList |
37 | 40 | #include <QListWidget> // for QListWidget |
38 | 41 | #include <QListWidgetItem> // for QListWidgetItem |
39 | 42 | #include <QPalette> // for QPalette |
40 | 43 | #include <QPushButton> // for QPushButton |
41 | 44 | #include <QRegularExpression> // for QRegularExpression |
42 | 45 | #include <QRegularExpressionValidator> // for QRegularExpressionValidator |
| 46 | +#include <QTextCodec> |
43 | 47 | #include <QVariant> // for QVariant |
44 | 48 | #include <Qt> // for GlobalColor, WindowFlags |
45 | 49 | #include <QtAlgorithms> // for qDeleteAll |
@@ -260,6 +264,18 @@ SetupDialog::SetupDialog(QWidget* parent, const AppConfig* prop, |
260 | 264 | connect(defaultButton, SIGNAL(clicked()), SLOT(setDefaultProp())); |
261 | 265 | connect(okButton, SIGNAL(clicked()), SLOT(accept())); |
262 | 266 | connect(cancelButton, SIGNAL(clicked()), SLOT(close())); |
| 267 | + |
| 268 | + connect(ui_showAllCodecs, &QCheckBox::stateChanged, |
| 269 | + this, &SetupDialog::showAllCodecsClicked); |
| 270 | + connect(ui_showAllCodecs, &QCheckBox::stateChanged, |
| 271 | + this, &SetupDialog::fillCodecs); |
| 272 | + connect(ui_showAliases, &QCheckBox::stateChanged, |
| 273 | + this, &SetupDialog::fillCodecs); |
| 274 | + ui_dropControl->setChecked(prop->gcodeConverterOptions.dropControll); |
| 275 | + ui_dropExtra->setChecked(prop->gcodeConverterOptions.dropExtented); |
| 276 | + ui_dropEmptyLine->setChecked(prop->gcodeConverterOptions.dropEmptyLine); |
| 277 | + showAllCodecsClicked(); |
| 278 | + fillCodecs(); |
263 | 279 | } |
264 | 280 |
|
265 | 281 | SetupDialog::~SetupDialog() |
@@ -429,6 +445,21 @@ AppConfig SetupDialog::getSettings() |
429 | 445 |
|
430 | 446 | editProp.editorProperties.guessFileNameByProgNum = progNumCheckBox->isChecked(); |
431 | 447 |
|
| 448 | + editProp.gcodeConverterOptions.dropControll = ui_dropControl->isChecked(); |
| 449 | + editProp.gcodeConverterOptions.dropExtented = ui_dropExtra->isChecked(); |
| 450 | + editProp.gcodeConverterOptions.dropEmptyLine = ui_dropEmptyLine->isChecked(); |
| 451 | + editProp.gcodeConverterOptions.codecName.clear(); |
| 452 | + |
| 453 | + if (ui_encodingCombo->currentIndex() != 0) { |
| 454 | + QTextCodec* codec = QTextCodec::codecForName(ui_encodingCombo->currentText().toLatin1()); |
| 455 | + |
| 456 | + if (codec != nullptr) { |
| 457 | + editProp.gcodeConverterOptions.codecName = codec->name(); |
| 458 | + } else { |
| 459 | + editProp.gcodeConverterOptions.codecName = ui_encodingCombo->currentText().toLatin1(); |
| 460 | + } |
| 461 | + } |
| 462 | + |
432 | 463 | return (editProp); |
433 | 464 | } |
434 | 465 |
|
@@ -667,3 +698,65 @@ void SetupDialog::on_btnBrowseDirectory_clicked() |
667 | 698 | edtSaveDirectory->setText(dir); |
668 | 699 | } |
669 | 700 | } |
| 701 | + |
| 702 | +void SetupDialog::showAllCodecsClicked() |
| 703 | +{ |
| 704 | + ui_showAliases->setEnabled(ui_showAllCodecs->isChecked()); |
| 705 | +} |
| 706 | + |
| 707 | +void SetupDialog::fillCodecs() |
| 708 | +{ |
| 709 | + ui_encodingCombo->clear(); |
| 710 | + ui_encodingCombo->setEditable(!ui_showAllCodecs->isChecked()); |
| 711 | + ui_encodingCombo->addItem(tr("System charset (%1)").arg(QString(QTextCodec::codecForLocale()->name()))); |
| 712 | + ui_encodingCombo->insertSeparator(1); |
| 713 | + |
| 714 | + QList<int> mibList; |
| 715 | + |
| 716 | + if (ui_showAllCodecs->isChecked()) { |
| 717 | + mibList = QTextCodec::availableMibs(); |
| 718 | + } else { |
| 719 | + mibList = { |
| 720 | + 2250, 2251, 2252, 2253, 2254, 2255, 2256, 2257, 2258 |
| 721 | + }; |
| 722 | + } |
| 723 | + |
| 724 | + QList<QByteArray> codecList; |
| 725 | + |
| 726 | + for (int i : mibList) { |
| 727 | + QTextCodec* tc = QTextCodec::codecForMib(i); |
| 728 | + |
| 729 | + if (tc != nullptr) { |
| 730 | + codecList.append(tc->name()); |
| 731 | + |
| 732 | + if (ui_showAllCodecs->isChecked() && ui_showAliases->isChecked()) { |
| 733 | + codecList.append(tc->aliases()); |
| 734 | + } |
| 735 | + } |
| 736 | + } |
| 737 | + |
| 738 | + std::sort(codecList.begin(), codecList.end()); |
| 739 | + auto last = std::unique(codecList.begin(), codecList.end()); |
| 740 | + codecList.erase(last, codecList.end()); |
| 741 | + |
| 742 | + for (auto i = codecList.cbegin(); i < codecList.cend(); ++i) { |
| 743 | + ui_encodingCombo->addItem(*i); |
| 744 | + } |
| 745 | + |
| 746 | + QByteArray currentCodec = editProp.gcodeConverterOptions.codecName; |
| 747 | + int currentIndex = codecList.indexOf(currentCodec); |
| 748 | + |
| 749 | + if (currentIndex < 0) { |
| 750 | + if (! currentCodec.isEmpty()) { |
| 751 | + ui_encodingCombo->insertItem(2, currentCodec); |
| 752 | + ui_encodingCombo->insertSeparator(3); |
| 753 | + currentIndex = 2; |
| 754 | + } else { |
| 755 | + currentIndex = 0; |
| 756 | + } |
| 757 | + } else { |
| 758 | + currentIndex += 2; |
| 759 | + } |
| 760 | + |
| 761 | + ui_encodingCombo->setCurrentIndex(currentIndex); |
| 762 | +} |
0 commit comments