| 1 | /* |
| 2 | * Copyright (C) 2019 Damir Porobic <[email protected]> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | #include "AnnotationSettings.h" |
| 21 | |
| 22 | AnnotationSettings::AnnotationSettings(const QSharedPointer<IConfig> &config, const QSharedPointer<IScaledSizeProvider> &scaledSizeProvider) : |
| 23 | mSmoothPathCheckbox(new QCheckBox(this)), |
| 24 | mRememberToolSelectionCheckBox(new QCheckBox(this)), |
| 25 | mSwitchToSelectToolAfterDrawingItemCheckBox(new QCheckBox(this)), |
| 26 | mNumberToolSeedChangeUpdatesAllItemsCheckBox(new QCheckBox(this)), |
| 27 | mSelectItemAfterDrawingCheckBox(new QCheckBox(this)), |
| 28 | mIsControlsWidgetVisibleCheckBox(new QCheckBox(this)), |
| 29 | mSmoothFactorLabel(new QLabel(this)), |
| 30 | mCanvasColorLabel(new QLabel(this)), |
| 31 | mSmoothFactorCombobox(new NumericComboBox(1, 1, 15)), |
| 32 | mCanvasColorButton(new ColorButton(this)), |
| 33 | mLayout(new QGridLayout(this)), |
| 34 | mConfig(config), |
| 35 | mScaledSizeProvider(scaledSizeProvider) |
| 36 | { |
| 37 | initGui(); |
| 38 | loadConfig(); |
| 39 | } |
| 40 | |
| 41 | AnnotationSettings::~AnnotationSettings() |
| 42 | { |
| 43 | delete mSmoothFactorCombobox; |
| 44 | } |
| 45 | |
| 46 | void AnnotationSettings::saveSettings() |
| 47 | { |
| 48 | mConfig->setSmoothPathEnabled(mSmoothPathCheckbox->isChecked()); |
| 49 | mConfig->setSmoothFactor(mSmoothFactorCombobox->value()); |
| 50 | mConfig->setRememberToolSelection(mRememberToolSelectionCheckBox->isChecked()); |
| 51 | mConfig->setSwitchToSelectToolAfterDrawingItem(mSwitchToSelectToolAfterDrawingItemCheckBox->isChecked()); |
| 52 | mConfig->setNumberToolSeedChangeUpdatesAllItems(mNumberToolSeedChangeUpdatesAllItemsCheckBox->isChecked()); |
| 53 | mConfig->setSelectItemAfterDrawing(mSelectItemAfterDrawingCheckBox->isChecked()); |
| 54 | mConfig->setIsControlsWidgetVisible(mIsControlsWidgetVisibleCheckBox->isChecked()); |
| 55 | mConfig->setCanvasColor(mCanvasColorButton->color()); |
| 56 | } |
| 57 | |
| 58 | void AnnotationSettings::initGui() |
| 59 | { |
| 60 | auto const fixedButtonWidth = mScaledSizeProvider->scaledWidth(100); |
| 61 | |
| 62 | mRememberToolSelectionCheckBox->setText(tr("Remember annotation tool selection and load on startup")); |
| 63 | |
| 64 | mSwitchToSelectToolAfterDrawingItemCheckBox->setText(tr("Switch to Select Tool after drawing Item")); |
| 65 | connect(mSwitchToSelectToolAfterDrawingItemCheckBox, &QCheckBox::clicked, this, &AnnotationSettings::switchToSelectToolAfterDrawingItemCheckBoxClicked); |
| 66 | |
| 67 | mSelectItemAfterDrawingCheckBox->setText(tr("Select Item after drawing")); |
| 68 | mSelectItemAfterDrawingCheckBox->setToolTip(tr("With this option enabled the item gets selected after\n" |
| 69 | "being created, allowing changing settings.")); |
| 70 | |
| 71 | mNumberToolSeedChangeUpdatesAllItemsCheckBox->setText(tr("Number Tool Seed change updates all Number Items")); |
| 72 | mNumberToolSeedChangeUpdatesAllItemsCheckBox->setToolTip(tr("Disabling this option causes changes of the number tool\n" |
| 73 | "seed to affect only new items but not existing items.\n" |
| 74 | "Disabling this option allows having duplicate numbers.")); |
| 75 | |
| 76 | mIsControlsWidgetVisibleCheckBox->setText(tr("Show Controls Widget")); |
| 77 | mIsControlsWidgetVisibleCheckBox->setToolTip(tr("The Controls Widget contains the Undo/Redo,\n" |
| 78 | "Crop, Scale, Rotate and Modify Canvas buttons.")); |
| 79 | |
| 80 | mSmoothPathCheckbox->setText(tr("Smooth Painter Paths")); |
| 81 | mSmoothPathCheckbox->setToolTip(tr("When enabled smooths out pen and\n" |
| 82 | "marker paths after finished drawing.")); |
| 83 | connect(mSmoothPathCheckbox, &QCheckBox::clicked, this, &AnnotationSettings::smoothPathCheckBoxClicked); |
| 84 | |
| 85 | mSmoothFactorLabel->setText(tr("Smooth Factor") + QLatin1String(":")); |
| 86 | mSmoothFactorLabel->setToolTip(tr("Increasing the smooth factor will decrease\n" |
| 87 | "precision for pen and marker but will\n" |
| 88 | "make them more smooth.")); |
| 89 | mSmoothFactorCombobox->setMinimumWidth(fixedButtonWidth); |
| 90 | mSmoothFactorCombobox->setToolTip(mSmoothFactorLabel->toolTip()); |
| 91 | |
| 92 | mCanvasColorLabel->setText(tr("Canvas Color") + QLatin1String(":")); |
| 93 | mCanvasColorLabel->setToolTip(tr("Default Canvas background color for annotation area.\n" |
| 94 | "Changing color affects only new annotation areas.")); |
| 95 | mCanvasColorButton->setMinimumWidth(fixedButtonWidth); |
| 96 | mCanvasColorButton->setShowAlphaChannel(true); |
| 97 | |
| 98 | mLayout->setAlignment(Qt::AlignTop); |
| 99 | mLayout->setColumnMinimumWidth(0, 10); |
| 100 | mLayout->addWidget(mRememberToolSelectionCheckBox, 0, 0, 1, 6); |
| 101 | mLayout->addWidget(mSwitchToSelectToolAfterDrawingItemCheckBox, 1, 0, 1, 6); |
| 102 | mLayout->addWidget(mSelectItemAfterDrawingCheckBox, 2, 1, 1, 5); |
| 103 | mLayout->addWidget(mNumberToolSeedChangeUpdatesAllItemsCheckBox, 3, 0, 1, 6); |
| 104 | mLayout->addWidget(mIsControlsWidgetVisibleCheckBox, 4, 0, 1, 6); |
| 105 | mLayout->addWidget(mSmoothPathCheckbox, 5, 0, 1, 6); |
| 106 | mLayout->addWidget(mSmoothFactorLabel, 6, 1, 1, 3); |
| 107 | mLayout->addWidget(mSmoothFactorCombobox, 7, 3, 1,3, Qt::AlignLeft); |
| 108 | mLayout->setRowMinimumHeight(7, 15); |
| 109 | mLayout->addWidget(mCanvasColorLabel, 8, 0, 1, 2); |
| 110 | mLayout->addWidget(mCanvasColorButton, 8, 3, 1,3, Qt::AlignLeft); |
| 111 | |
| 112 | setTitle(tr("Annotator Settings")); |
| 113 | setLayout(mLayout); |
| 114 | } |
| 115 | |
| 116 | void AnnotationSettings::loadConfig() |
| 117 | { |
| 118 | mSmoothPathCheckbox->setChecked(mConfig->smoothPathEnabled()); |
| 119 | mSmoothFactorCombobox->setValue(mConfig->smoothFactor()); |
| 120 | mRememberToolSelectionCheckBox->setChecked(mConfig->rememberToolSelection()); |
| 121 | mSwitchToSelectToolAfterDrawingItemCheckBox->setChecked(mConfig->switchToSelectToolAfterDrawingItem()); |
| 122 | mNumberToolSeedChangeUpdatesAllItemsCheckBox->setChecked(mConfig->numberToolSeedChangeUpdatesAllItems()); |
| 123 | mSelectItemAfterDrawingCheckBox->setChecked(mConfig->selectItemAfterDrawing()); |
| 124 | mIsControlsWidgetVisibleCheckBox->setChecked(mConfig->isControlsWidgetVisible()); |
| 125 | mCanvasColorButton->setColor(mConfig->canvasColor()); |
| 126 | smoothPathCheckBoxClicked(mConfig->smoothPathEnabled()); |
| 127 | switchToSelectToolAfterDrawingItemCheckBoxClicked(mConfig->switchToSelectToolAfterDrawingItem()); |
| 128 | } |
| 129 | |
| 130 | void AnnotationSettings::smoothPathCheckBoxClicked(bool checked) |
| 131 | { |
| 132 | mSmoothFactorLabel->setEnabled(checked); |
| 133 | mSmoothFactorCombobox->setEnabled(checked); |
| 134 | } |
| 135 | |
| 136 | void AnnotationSettings::switchToSelectToolAfterDrawingItemCheckBoxClicked(bool checked) |
| 137 | { |
| 138 | mSelectItemAfterDrawingCheckBox->setEnabled(checked); |
| 139 | } |