| 1 | /*************************************************************************** |
| 2 | * This file is part of Robocut. * |
| 3 | * Copyright (C) 2010 Tim Hutt <[email protected]> * |
| 4 | * Copyright (C) 2010 Markus Schulz <[email protected]> * |
| 5 | * * |
| 6 | * This program is free software; you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 3 of the License, or * |
| 9 | * (at your option) any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, write to the * |
| 18 | * Free Software Foundation, Inc., * |
| 19 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * |
| 20 | ***************************************************************************/ |
| 21 | |
| 22 | #include "CutDialog.h" |
| 23 | #include "ui_CutDialog.h" |
| 24 | #include "ProgramOptions.h" |
| 25 | |
| 26 | CutDialog::CutDialog(QWidget *parent) : |
| 27 | QDialog(parent), |
| 28 | ui(new Ui::CutDialog) |
| 29 | { |
| 30 | ui->setupUi(this); |
| 31 | ui->mediaCombo->setCurrentIndex(ProgramOptions::Instance().getMedia()); |
| 32 | ui->speedSlider->setValue(ProgramOptions::Instance().getSpeed()); |
| 33 | ui->pressureSlider->setValue(ProgramOptions::Instance().getPressure()); |
| 34 | ui->trackEnhancingCheckbox->setChecked(ProgramOptions::Instance().getTrackEnhancing()); |
| 35 | if(ProgramOptions::Instance().getRegMark()) |
| 36 | { |
| 37 | ui->regMarksGroup->setChecked(true); |
| 38 | ui->regSearchCheckbox->setChecked(false); |
| 39 | } |
| 40 | if(ProgramOptions::Instance().getRegMarkAuto()) |
| 41 | { |
| 42 | ui->regMarksGroup->setChecked(true); |
| 43 | ui->regSearchCheckbox->setChecked(true); |
| 44 | } |
| 45 | ui->regWidthSpinner->setValue(ProgramOptions::Instance().getRegDimensionWidthMM()); |
| 46 | ui->regHeightSpinner->setValue(ProgramOptions::Instance().getRegDimensionHeightMM()); |
| 47 | } |
| 48 | |
| 49 | CutDialog::~CutDialog() |
| 50 | { |
| 51 | delete ui; |
| 52 | } |
| 53 | |
| 54 | void CutDialog::changeEvent(QEvent *e) |
| 55 | { |
| 56 | QDialog::changeEvent(e); |
| 57 | switch (e->type()) { |
| 58 | case QEvent::LanguageChange: |
| 59 | ui->retranslateUi(this); |
| 60 | break; |
| 61 | default: |
| 62 | break; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | int CutDialog::media() const |
| 67 | { |
| 68 | int idx = ui->mediaCombo->currentIndex(); |
| 69 | |
| 70 | // Media code for each entry. |
| 71 | int medias[] = { |
| 72 | 100, 101, 102, 106, 111, 112, 113, 120, 121, 122, 123, 124, 125, |
| 73 | 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138 |
| 74 | }; |
| 75 | |
| 76 | if (idx < 0 || idx >= 26) |
| 77 | idx = 0; |
| 78 | return medias[idx]; |
| 79 | } |
| 80 | int CutDialog::speed() const |
| 81 | { |
| 82 | return ui->speedSlider->value(); |
| 83 | } |
| 84 | int CutDialog::pressure() const |
| 85 | { |
| 86 | return ui->pressureSlider->value(); |
| 87 | } |
| 88 | bool CutDialog::trackEnhancing() const |
| 89 | { |
| 90 | return ui->trackEnhancingCheckbox->isChecked(); |
| 91 | } |
| 92 | |
| 93 | bool CutDialog::regMark() const |
| 94 | { |
| 95 | return ui->regMarksGroup->isChecked(); |
| 96 | } |
| 97 | |
| 98 | bool CutDialog::regSearch() const |
| 99 | { |
| 100 | return ui->regSearchCheckbox->isChecked(); |
| 101 | } |
| 102 | |
| 103 | double CutDialog::regWidth() const |
| 104 | { |
| 105 | return ui->regWidthSpinner->value(); |
| 106 | } |
| 107 | |
| 108 | double CutDialog::regHeight() const |
| 109 | { |
| 110 | return ui->regHeightSpinner->value(); |
| 111 | } |
| 112 | |
| 113 | void CutDialog::onMediaChanged(int idx) |
| 114 | { |
| 115 | |
| 116 | if (idx < 0 || idx >= 26) |
| 117 | idx = 0; |
| 118 | |
| 119 | // Pressure for each entry. |
| 120 | int pressures[] = { |
| 121 | 27, 27, 10, 14, 27, 2, 10, 30, 30, 30, 30, 1, 1, |
| 122 | 1, 30, 20, 27, 30, 30, 5, 25, 20, 20, 30, 30, 30 |
| 123 | }; |
| 124 | |
| 125 | // Default speed is max except for magnetic sheet. |
| 126 | int newspeed = idx == 17 ? 3 : 10; |
| 127 | int newpressure = pressures[idx]; |
| 128 | |
| 129 | ui->speedSlider->setValue(newspeed); |
| 130 | ui->pressureSlider->setValue(newpressure); |
| 131 | } |