| 1 | /* |
| 2 | * Copyright (C) 2020 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 "SnippingAreaSettings.h" |
| 21 | |
| 22 | SnippingAreaSettings::SnippingAreaSettings(const QSharedPointer<IConfig> &config, const QSharedPointer<IScaledSizeProvider> &scaledSizeProvider) : |
| 23 | mConfig(config), |
| 24 | mScaledSizeProvider(scaledSizeProvider), |
| 25 | mFreezeImageWhileSnippingCheckbox(new QCheckBox(this)), |
| 26 | mSnippingAreaRulersCheckbox(new QCheckBox(this)), |
| 27 | mSnippingAreaPositionAndSizeInfoCheckbox(new QCheckBox(this)), |
| 28 | mSnippingAreaMagnifyingGlassCheckbox(new QCheckBox(this)), |
| 29 | mAllowResizingRectSelectionCheckbox(new QCheckBox(this)), |
| 30 | mShowSnippingAreaInfoTextCheckbox(new QCheckBox(this)), |
| 31 | mSnippingAreaOffsetEnabledCheckbox(new QCheckBox(this)), |
| 32 | mSnippingCursorSizeLabel(new QLabel(this)), |
| 33 | mSnippingCursorColorLabel(new QLabel(this)), |
| 34 | mSnippingAdornerColorLabel(new QLabel(this)), |
| 35 | mSnippingAreaTransparencyLabel(new QLabel(this)), |
| 36 | mSnippingAreaOffsetXLabel(new QLabel(this)), |
| 37 | mSnippingAreaOffsetYLabel(new QLabel(this)), |
| 38 | mSnippingCursorSizeCombobox(new NumericComboBox(1, 2, 3)), |
| 39 | mSnippingCursorColorButton(new ColorButton(this)), |
| 40 | mSnippingAdornerColorButton(new ColorButton(this)), |
| 41 | mSnippingAreaTransparencySpinBox(new QSpinBox(this)), |
| 42 | mSnippingAreaOffsetXSpinBox(new QDoubleSpinBox(this)), |
| 43 | mSnippingAreaOffsetYSpinBox(new QDoubleSpinBox(this)), |
| 44 | mLayout(new QGridLayout(this)) |
| 45 | { |
| 46 | initGui(); |
| 47 | loadConfig(); |
| 48 | } |
| 49 | |
| 50 | SnippingAreaSettings::~SnippingAreaSettings() |
| 51 | { |
| 52 | delete mSnippingCursorSizeCombobox; |
| 53 | } |
| 54 | |
| 55 | void SnippingAreaSettings::saveSettings() |
| 56 | { |
| 57 | mConfig->setFreezeImageWhileSnippingEnabled(mFreezeImageWhileSnippingCheckbox->isChecked()); |
| 58 | mConfig->setSnippingAreaMagnifyingGlassEnabled(mSnippingAreaMagnifyingGlassCheckbox->isChecked()); |
| 59 | mConfig->setSnippingAreaRulersEnabled(mSnippingAreaRulersCheckbox->isChecked()); |
| 60 | mConfig->setSnippingAreaPositionAndSizeInfoEnabled(mSnippingAreaPositionAndSizeInfoCheckbox->isChecked()); |
| 61 | mConfig->setAllowResizingRectSelection(mAllowResizingRectSelectionCheckbox->isChecked()); |
| 62 | mConfig->setShowSnippingAreaInfoText(mShowSnippingAreaInfoTextCheckbox->isChecked()); |
| 63 | mConfig->setSnippingCursorColor(mSnippingCursorColorButton->color()); |
| 64 | mConfig->setSnippingAdornerColor(mSnippingAdornerColorButton->color()); |
| 65 | mConfig->setSnippingCursorSize(mSnippingCursorSizeCombobox->value()); |
| 66 | mConfig->setSnippingAreaTransparency(mSnippingAreaTransparencySpinBox->value()); |
| 67 | mConfig->setSnippingAreaOffsetEnable(mSnippingAreaOffsetEnabledCheckbox->isChecked()); |
| 68 | mConfig->setSnippingAreaOffset({mSnippingAreaOffsetXSpinBox->value(), mSnippingAreaOffsetYSpinBox->value()}); |
| 69 | } |
| 70 | |
| 71 | void SnippingAreaSettings::initGui() |
| 72 | { |
| 73 | auto const fixedButtonWidth = mScaledSizeProvider->scaledWidth(70); |
| 74 | |
| 75 | mFreezeImageWhileSnippingCheckbox->setText(tr("Freeze Image while snipping")); |
| 76 | mFreezeImageWhileSnippingCheckbox->setToolTip(tr("When enabled will freeze the background while\n" |
| 77 | "selecting a rectangular region. It also changes\n" |
| 78 | "the behavior of delayed screenshots, with this\n" |
| 79 | "option enabled the delay happens before the\n" |
| 80 | "snipping area is shown and with the option disabled\n" |
| 81 | "the delay happens after the snipping area is shown.\n" |
| 82 | "This feature is always disabled for Wayland and always\n" |
| 83 | "enabled for MacOs.")); |
| 84 | connect(mFreezeImageWhileSnippingCheckbox, &QCheckBox::stateChanged, this, &SnippingAreaSettings::freezeImageWhileSnippingStateChanged); |
| 85 | |
| 86 | mSnippingAreaMagnifyingGlassCheckbox->setText(tr("Show magnifying glass on snipping area")); |
| 87 | mSnippingAreaMagnifyingGlassCheckbox->setToolTip(tr("Show a magnifying glass which zooms into\n" |
| 88 | "the background image. This option only works\n" |
| 89 | "with 'Freeze Image while snipping' enabled.")); |
| 90 | |
| 91 | mSnippingAreaRulersCheckbox->setText(tr("Show Snipping Area rulers")); |
| 92 | mSnippingAreaRulersCheckbox->setToolTip(tr("Horizontal and vertical lines going from\n" |
| 93 | "desktop edges to cursor on snipping area.")); |
| 94 | |
| 95 | mSnippingAreaPositionAndSizeInfoCheckbox->setText(tr("Show Snipping Area position and size info")); |
| 96 | mSnippingAreaPositionAndSizeInfoCheckbox->setToolTip(tr("When left mouse button is not pressed the position\n" |
| 97 | "is shown, when the mouse button is pressed,\n" |
| 98 | "the size of the select area is shown left\n" |
| 99 | "and above from the captured area.")); |
| 100 | |
| 101 | mAllowResizingRectSelectionCheckbox->setText(tr("Allow resizing rect area selection by default")); |
| 102 | mAllowResizingRectSelectionCheckbox->setToolTip(tr("When enabled will, after selecting a rect\n" |
| 103 | "area, allow resizing the selection. When\n" |
| 104 | "done resizing the selection can be confirmed\n" |
| 105 | "by pressing return.")); |
| 106 | |
| 107 | mShowSnippingAreaInfoTextCheckbox->setText(tr("Show Snipping Area info text")); |
| 108 | |
| 109 | mSnippingCursorColorLabel->setText(tr("Snipping Area cursor color") + QLatin1String(":")); |
| 110 | mSnippingCursorColorLabel->setToolTip(tr("Sets the color of the snipping area cursor.")); |
| 111 | mSnippingCursorColorButton->setMinimumWidth(fixedButtonWidth); |
| 112 | mSnippingCursorColorButton->setToolTip(mSnippingCursorColorLabel->toolTip()); |
| 113 | |
| 114 | mSnippingAdornerColorLabel->setText(tr("Snipping Area adorner color") + QLatin1String(":")); |
| 115 | mSnippingAdornerColorLabel->setToolTip(tr("Sets the color of all adorner elements\n" |
| 116 | "on the snipping area.")); |
| 117 | mSnippingAdornerColorButton->setMinimumWidth(fixedButtonWidth); |
| 118 | mSnippingAdornerColorButton->setToolTip(mSnippingAdornerColorLabel->toolTip()); |
| 119 | |
| 120 | mSnippingCursorSizeLabel->setText(tr("Snipping Area cursor thickness") + QLatin1String(":")); |
| 121 | mSnippingCursorSizeLabel->setToolTip(tr("Sets the thickness of the snipping area cursor.")); |
| 122 | mSnippingCursorSizeCombobox->setMinimumWidth(fixedButtonWidth); |
| 123 | mSnippingCursorSizeCombobox->setToolTip(mSnippingCursorSizeLabel->toolTip()); |
| 124 | |
| 125 | mSnippingAreaTransparencyLabel->setText(tr("Snipping Area Transparency")); |
| 126 | mSnippingAreaTransparencyLabel->setToolTip(tr("Alpha for not selected region on snipping area.\n" |
| 127 | "Smaller number is more transparent.")); |
| 128 | mSnippingAreaTransparencySpinBox->setMinimum(0); |
| 129 | mSnippingAreaTransparencySpinBox->setMaximum(200); |
| 130 | mSnippingAreaTransparencySpinBox->setToolTip(mSnippingAreaTransparencyLabel->toolTip()); |
| 131 | mSnippingAreaTransparencySpinBox->setMinimumWidth(fixedButtonWidth); |
| 132 | |
| 133 | mSnippingAreaOffsetEnabledCheckbox->setText(tr("Enable Snipping Area offset")); |
| 134 | mSnippingAreaOffsetEnabledCheckbox->setToolTip(tr("When enabled will apply the configured\n" |
| 135 | "offset to the Snipping Area position which\n" |
| 136 | "is required when the position is not\n" |
| 137 | "correctly calculated. This is sometimes\n" |
| 138 | "required with screen scaling enabled.")); |
| 139 | connect(mSnippingAreaOffsetEnabledCheckbox, &QCheckBox::stateChanged, this, &SnippingAreaSettings::snippingAreaOffsetEnableStateChanged); |
| 140 | |
| 141 | mSnippingAreaOffsetXLabel->setText(tr("X") + QLatin1String(":")); |
| 142 | mSnippingAreaOffsetYLabel->setText(tr("Y") + QLatin1String(":")); |
| 143 | |
| 144 | mSnippingAreaOffsetXSpinBox->setMinimum(-9999); |
| 145 | mSnippingAreaOffsetXSpinBox->setMaximum(9999); |
| 146 | mSnippingAreaOffsetXSpinBox->setDecimals(2); |
| 147 | |
| 148 | mSnippingAreaOffsetYSpinBox->setMinimum(-9999); |
| 149 | mSnippingAreaOffsetYSpinBox->setMaximum(9999); |
| 150 | mSnippingAreaOffsetYSpinBox->setDecimals(2); |
| 151 | |
| 152 | mLayout->setAlignment(Qt::AlignTop); |
| 153 | mLayout->setColumnMinimumWidth(0, mScaledSizeProvider->scaledWidth(10)); |
| 154 | mLayout->setColumnMinimumWidth(1, mScaledSizeProvider->scaledWidth(30)); |
| 155 | mLayout->addWidget(mFreezeImageWhileSnippingCheckbox, 0, 0, 1, 5); |
| 156 | mLayout->addWidget(mSnippingAreaMagnifyingGlassCheckbox, 1, 1, 1, 4); |
| 157 | mLayout->addWidget(mSnippingAreaRulersCheckbox, 2, 0, 1, 5); |
| 158 | mLayout->addWidget(mSnippingAreaPositionAndSizeInfoCheckbox, 3, 0, 1, 5); |
| 159 | mLayout->addWidget(mAllowResizingRectSelectionCheckbox, 4, 0, 1, 5); |
| 160 | mLayout->addWidget(mShowSnippingAreaInfoTextCheckbox, 5, 0, 1, 5); |
| 161 | mLayout->setRowMinimumHeight(6, 15); |
| 162 | mLayout->addWidget(mSnippingAdornerColorLabel, 7, 0, 1, 3); |
| 163 | mLayout->addWidget(mSnippingAdornerColorButton, 7, 3, Qt::AlignLeft); |
| 164 | mLayout->addWidget(mSnippingCursorColorLabel, 8, 0, 1, 3); |
| 165 | mLayout->addWidget(mSnippingCursorColorButton, 8, 3, Qt::AlignLeft); |
| 166 | mLayout->addWidget(mSnippingCursorSizeLabel, 9, 0, 1, 3); |
| 167 | mLayout->addWidget(mSnippingCursorSizeCombobox, 9, 3, Qt::AlignLeft); |
| 168 | mLayout->addWidget(mSnippingAreaTransparencyLabel, 10, 0, 1, 3); |
| 169 | mLayout->addWidget(mSnippingAreaTransparencySpinBox, 10, 3, Qt::AlignLeft); |
| 170 | mLayout->setRowMinimumHeight(11, 15); |
| 171 | mLayout->addWidget(mSnippingAreaOffsetEnabledCheckbox, 12, 0, 1, 5); |
| 172 | mLayout->addWidget(mSnippingAreaOffsetXLabel, 13, 1, 1, 1); |
| 173 | mLayout->addWidget(mSnippingAreaOffsetXSpinBox, 13, 2, Qt::AlignLeft); |
| 174 | mLayout->addWidget(mSnippingAreaOffsetYLabel, 14, 1, 1, 1); |
| 175 | mLayout->addWidget(mSnippingAreaOffsetYSpinBox, 14, 2, Qt::AlignLeft); |
| 176 | |
| 177 | setTitle(tr("Snipping Area")); |
| 178 | setLayout(mLayout); |
| 179 | } |
| 180 | |
| 181 | void SnippingAreaSettings::loadConfig() |
| 182 | { |
| 183 | mFreezeImageWhileSnippingCheckbox->setChecked(mConfig->freezeImageWhileSnippingEnabled()); |
| 184 | mFreezeImageWhileSnippingCheckbox->setEnabled(!mConfig->isFreezeImageWhileSnippingEnabledReadOnly()); |
| 185 | mSnippingAreaMagnifyingGlassCheckbox->setChecked(mConfig->snippingAreaMagnifyingGlassEnabled()); |
| 186 | mSnippingAreaMagnifyingGlassCheckbox->setEnabled(!mConfig->isSnippingAreaMagnifyingGlassEnabledReadOnly()); |
| 187 | mSnippingAreaRulersCheckbox->setChecked(mConfig->snippingAreaRulersEnabled()); |
| 188 | mSnippingAreaPositionAndSizeInfoCheckbox->setChecked(mConfig->snippingAreaPositionAndSizeInfoEnabled()); |
| 189 | mAllowResizingRectSelectionCheckbox->setChecked(mConfig->allowResizingRectSelection()); |
| 190 | mShowSnippingAreaInfoTextCheckbox->setChecked(mConfig->showSnippingAreaInfoText()); |
| 191 | mSnippingCursorColorButton->setColor(mConfig->snippingCursorColor()); |
| 192 | mSnippingAdornerColorButton->setColor(mConfig->snippingAdornerColor()); |
| 193 | mSnippingCursorSizeCombobox->setValue(mConfig->snippingCursorSize()); |
| 194 | mSnippingAreaTransparencySpinBox->setValue(mConfig->snippingAreaTransparency()); |
| 195 | mSnippingAreaOffsetEnabledCheckbox->setChecked(mConfig->snippingAreaOffsetEnable()); |
| 196 | mSnippingAreaOffsetXSpinBox->setValue(mConfig->snippingAreaOffset().x()); |
| 197 | mSnippingAreaOffsetYSpinBox->setValue(mConfig->snippingAreaOffset().y()); |
| 198 | |
| 199 | freezeImageWhileSnippingStateChanged(); |
| 200 | snippingAreaOffsetEnableStateChanged(); |
| 201 | } |
| 202 | |
| 203 | void SnippingAreaSettings::freezeImageWhileSnippingStateChanged() |
| 204 | { |
| 205 | mSnippingAreaMagnifyingGlassCheckbox->setEnabled(mFreezeImageWhileSnippingCheckbox->isChecked()); |
| 206 | } |
| 207 | |
| 208 | void SnippingAreaSettings::snippingAreaOffsetEnableStateChanged() |
| 209 | { |
| 210 | auto isEnabled = mSnippingAreaOffsetEnabledCheckbox->isChecked(); |
| 211 | mSnippingAreaOffsetXLabel->setEnabled(isEnabled); |
| 212 | mSnippingAreaOffsetYLabel->setEnabled(isEnabled); |
| 213 | mSnippingAreaOffsetXSpinBox->setEnabled(isEnabled); |
| 214 | mSnippingAreaOffsetYSpinBox->setEnabled(isEnabled); |
| 215 | } |