Debian Codegraph @

src/gui/settingsDialog/ImageGrabberSettings.cpp

raw symbols SCIP
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 "ImageGrabberSettings.h"
21
22 ImageGrabberSettings::ImageGrabberSettings(const QSharedPointer<IConfig> &config) :
23 mCaptureCursorCheckbox(new QCheckBox(this)),
24 mHideMainWindowDuringScreenshotCheckbox(new QCheckBox(this)),
25 mShowMainWindowAfterTakingScreenshotCheckbox(new QCheckBox(this)),
26 mForceGenericWaylandCheckbox(new QCheckBox(this)),
27 mScaleGenericWaylandScreenshotsCheckbox(new QCheckBox(this)),
28 mImplicitCaptureDelayLabel(new QLabel(this)),
29 mImplicitCaptureDelaySpinBox(new CustomSpinBox(0, 2000, this)),
30 mLayout(new QGridLayout(this)),
31 mConfig(config)
32 {
33 Q_ASSERT(mConfig != nullptr);
34
35 initGui();
36 loadConfig();
37 }
38
39 void ImageGrabberSettings::saveSettings()
40 {
41 mConfig->setHideMainWindowDuringScreenshot(mHideMainWindowDuringScreenshotCheckbox->isChecked());
42 mConfig->setCaptureCursor(mCaptureCursorCheckbox->isChecked());
43 mConfig->setShowMainWindowAfterTakingScreenshotEnabled(mShowMainWindowAfterTakingScreenshotCheckbox->isChecked());
44 mConfig->setForceGenericWaylandEnabled(mForceGenericWaylandCheckbox->isChecked());
45 mConfig->setScaleGenericWaylandScreenshots(mScaleGenericWaylandScreenshotsCheckbox->isChecked());
46 mConfig->setImplicitCaptureDelay(mImplicitCaptureDelaySpinBox->value());
47 }
48
49 void ImageGrabberSettings::initGui()
50 {
51 mCaptureCursorCheckbox->setText(tr("Capture mouse cursor on screenshot"));
52 mCaptureCursorCheckbox->setToolTip(tr("Should mouse cursor be visible on\n"
53 "screenshots."));
54
55 mShowMainWindowAfterTakingScreenshotCheckbox->setText(tr("Show Main Window after capturing screenshot"));
56 mShowMainWindowAfterTakingScreenshotCheckbox->setToolTip(tr("Show Main Window after capturing a new screenshot\n"
57 "when the Main Window was hidden or minimize."));
58
59 mForceGenericWaylandCheckbox->setText(tr("Force Generic Wayland (xdg-desktop-portal) Screenshot"));
60 mForceGenericWaylandCheckbox->setToolTip(tr("GNOME and KDE Plasma support their own Wayland\n"
61 "and the Generic XDG-DESKTOP-PORTAL screenshots.\n"
62 "Enabling this option will force KDE Plasma and\n"
63 "GNOME to use the XDG-DESKTOP-PORTAL screenshots.\n"
64 "Change in this option require a ksnip restart."));
65
66 mScaleGenericWaylandScreenshotsCheckbox->setText(tr("Scale Generic Wayland (xdg-desktop-portal) Screenshots"));
67 mScaleGenericWaylandScreenshotsCheckbox->setToolTip(tr("Generic Wayland implementations that use\n"
68 "XDG-DESKTOP-PORTAL handle screen scaling\n"
69 "differently. Enabling this option will\n"
70 "determine the current screen scaling and\n"
71 "apply that to the screenshot in ksnip."));
72
73 mHideMainWindowDuringScreenshotCheckbox->setText(tr("Hide Main Window during screenshot"));
74 mHideMainWindowDuringScreenshotCheckbox->setToolTip(tr("Hide Main Window when capturing a new screenshot."));
75
76 mImplicitCaptureDelayLabel->setText(tr("Implicit capture delay") + QLatin1String(":"));
77 mImplicitCaptureDelayLabel->setToolTip(tr("This delay is used when no delay was selected in\n"
78 "the UI, it allows ksnip to hide before taking\n"
79 "a screenshot. This value is not applied when\n"
80 "ksnip was already minimized. Reducing this value\n"
81 "can have the effect that ksnip's main window is\n"
82 "visible on the screenshot."));
83
84 mImplicitCaptureDelaySpinBox->setSuffix(QLatin1String("ms"));
85 mImplicitCaptureDelaySpinBox->setToolTip(mImplicitCaptureDelayLabel->toolTip());
86 mImplicitCaptureDelaySpinBox->setSingleStep(10);
87
88 mLayout->setAlignment(Qt::AlignTop);
89 mLayout->setColumnMinimumWidth(0, 10);
90 mLayout->addWidget(mCaptureCursorCheckbox, 0, 0, 1, 3);
91 mLayout->addWidget(mShowMainWindowAfterTakingScreenshotCheckbox, 1, 0, 1, 3);
92 mLayout->addWidget(mHideMainWindowDuringScreenshotCheckbox, 2, 0, 1, 3);
93 mLayout->addWidget(mForceGenericWaylandCheckbox, 3, 0, 1, 3);
94 mLayout->addWidget(mScaleGenericWaylandScreenshotsCheckbox, 4, 0, 1, 3);
95 mLayout->setRowMinimumHeight(5, 15);
96 mLayout->addWidget(mImplicitCaptureDelayLabel, 6, 0, 1, 1);
97 mLayout->addWidget(mImplicitCaptureDelaySpinBox, 6, 1, Qt::AlignLeft);
98
99 setTitle(tr("Image Grabber"));
100 setLayout(mLayout);
101 }
102
103 void ImageGrabberSettings::loadConfig()
104 {
105 mHideMainWindowDuringScreenshotCheckbox->setChecked(mConfig->hideMainWindowDuringScreenshot());
106 mCaptureCursorCheckbox->setChecked(mConfig->captureCursor());
107 mShowMainWindowAfterTakingScreenshotCheckbox->setChecked(mConfig->showMainWindowAfterTakingScreenshotEnabled());
108 mForceGenericWaylandCheckbox->setChecked(mConfig->forceGenericWaylandEnabled());
109 mForceGenericWaylandCheckbox->setEnabled(!mConfig->isForceGenericWaylandEnabledReadOnly());
110 mScaleGenericWaylandScreenshotsCheckbox->setChecked(mConfig->scaleGenericWaylandScreenshotsEnabled());
111 mScaleGenericWaylandScreenshotsCheckbox->setEnabled(!mConfig->isScaleGenericWaylandScreenshotEnabledReadOnly());
112 mImplicitCaptureDelaySpinBox->setValue(mConfig->implicitCaptureDelay());
113 }