Debian Codegraph @

src/gui/settingsDialog/ApplicationSettings.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 "ApplicationSettings.h"
21
22 ApplicationSettings::ApplicationSettings(const QSharedPointer<IConfig> &config, const QSharedPointer<IFileDialogService> &fileDialogService) :
23 mConfig(config),
24 mFileDialogService(fileDialogService),
25 mAutoCopyToClipboardNewCapturesCheckbox(new QCheckBox(this)),
26 mRememberPositionCheckbox(new QCheckBox(this)),
27 mCaptureOnStartupCheckbox(new QCheckBox(this)),
28 mUseTabsCheckbox(new QCheckBox(this)),
29 mAutoHideTabsCheckbox(new QCheckBox(this)),
30 mUseSingleInstanceCheckBox(new QCheckBox(this)),
31 mAutoHideDocksCheckBox(new QCheckBox(this)),
32 mAutoResizeToContentCheckBox(new QCheckBox(this)),
33 mEnableDebugging(new QCheckBox(this)),
34 mApplicationStyleLabel(new QLabel(this)),
35 mResizeToContentDelayLabel(new QLabel(this)),
36 mTempDirectoryLabel(new QLabel(this)),
37 mTempDirectoryLineEdit(new QLineEdit(this)),
38 mBrowseButton(new QPushButton(this)),
39 mApplicationStyleCombobox(new QComboBox(this)),
40 mResizeToContentDelaySpinBox(new CustomSpinBox(0, 1000, this)),
41 mLayout(new QGridLayout)
42 {
43 Q_ASSERT(mConfig != nullptr);
44
45 initGui();
46
47 loadConfig();
48 }
49
50 void ApplicationSettings::initGui()
51 {
52 mAutoCopyToClipboardNewCapturesCheckbox->setText(tr("Automatically copy new captures to clipboard"));
53 mRememberPositionCheckbox->setText(tr("Remember Main Window position on move and load on startup"));
54 mCaptureOnStartupCheckbox->setText(tr("Capture screenshot at startup with default mode"));
55
56 mUseTabsCheckbox->setText(tr("Use Tabs"));
57 mUseTabsCheckbox->setToolTip(tr("Change requires restart."));
58
59 mAutoHideTabsCheckbox->setText(tr("Auto hide Tabs"));
60 mAutoHideTabsCheckbox->setToolTip(tr("Hide Tabbar when only one Tab is used."));
61
62 mUseSingleInstanceCheckBox->setText(tr("Run ksnip as single instance"));
63 mUseSingleInstanceCheckBox->setToolTip(tr("Enabling this option will allow only one ksnip instance to run,\n"
64 "all other instances started after the first will pass its\n"
65 "arguments to the first and close. Changing this option requires\n"
66 "a new start of all instances."));
67
68 mAutoHideDocksCheckBox->setText(tr("Auto hide Docks"));
69 mAutoHideDocksCheckBox->setToolTip(tr("On startup hide Toolbar and Annotation Settings.\n"
70 "Docks visibility can be toggled with the Tab Key."));
71
72 mAutoResizeToContentCheckBox->setText(tr("Auto resize to content"));
73 mAutoResizeToContentCheckBox->setToolTip(tr("Automatically resize Main Window to fit content image."));
74
75 mEnableDebugging->setText(tr("Enable Debugging"));
76 mEnableDebugging->setToolTip(tr("Enables debug output written to the console.\n"
77 "Change requires ksnip restart to take effect."));
78
79 mResizeToContentDelayLabel->setText(tr("Resize delay") + QLatin1String(":"));
80 mResizeToContentDelayLabel->setToolTip(tr("Resizing to content is delay to allow the Window Manager to receive\n"
81 "the new content. In case that the Main Windows is not adjusted correctly\n"
82 "to the new content, increasing this delay might improve the behavior."));
83
84 mResizeToContentDelaySpinBox->setSuffix(QLatin1String("ms"));
85 mResizeToContentDelaySpinBox->setToolTip(mResizeToContentDelayLabel->toolTip());
86 mResizeToContentDelaySpinBox->setSingleStep(10);
87
88 connect(mUseTabsCheckbox, &QCheckBox::stateChanged, this, &ApplicationSettings::useTabsChanged);
89
90 mApplicationStyleLabel->setText(tr("Application Style") + QLatin1String(":"));
91 mApplicationStyleLabel->setToolTip(tr("Sets the application style which defines the look and feel of the GUI.\n"
92 "Change requires ksnip restart to take effect."));
93
94 mTempDirectoryLabel->setText(tr("Temp Directory") + QLatin1String(":"));
95
96 mTempDirectoryLineEdit->setToolTip(tr("Temp directory used for storing temporary images that are\n"
97 "going to be deleted after ksnip closes."));
98
99 mBrowseButton->setText(tr("Browse"));
100 connect(mBrowseButton, &QPushButton::clicked, this, &ApplicationSettings::chooseTempDirectory);
101
102 mApplicationStyleCombobox->addItems(QStyleFactory::keys());
103 mApplicationStyleCombobox->setToolTip(mApplicationStyleLabel->toolTip());
104 mApplicationStyleCombobox->setFixedWidth(100);
105
106 mLayout->setAlignment(Qt::AlignTop);
107 mLayout->setColumnMinimumWidth(0, 10);
108 mLayout->addWidget(mAutoCopyToClipboardNewCapturesCheckbox, 0, 0, 1, 4);
109 mLayout->addWidget(mRememberPositionCheckbox, 1, 0, 1, 4);
110 mLayout->addWidget(mCaptureOnStartupCheckbox, 2, 0, 1, 4);
111 mLayout->addWidget(mUseTabsCheckbox, 3, 0, 1, 4);
112 mLayout->addWidget(mAutoHideTabsCheckbox, 4, 1, 1, 3);
113 mLayout->addWidget(mUseSingleInstanceCheckBox, 5, 0, 1, 4);
114 mLayout->addWidget(mAutoHideDocksCheckBox, 6, 0, 1, 4);
115 mLayout->addWidget(mAutoResizeToContentCheckBox, 7, 0, 1, 4);
116 mLayout->addWidget(mEnableDebugging, 8, 0, 1, 4);
117 mLayout->setRowMinimumHeight(9, 15);
118 mLayout->addWidget(mResizeToContentDelayLabel, 10, 0, 1, 2);
119 mLayout->addWidget(mResizeToContentDelaySpinBox, 10, 2, Qt::AlignLeft);
120 mLayout->setRowMinimumHeight(11, 15);
121 mLayout->addWidget(mApplicationStyleLabel, 12, 0, 1, 2);
122 mLayout->addWidget(mApplicationStyleCombobox, 12, 2, Qt::AlignLeft);
123 mLayout->setRowMinimumHeight(13, 15);
124 mLayout->addWidget(mTempDirectoryLabel, 14, 0, 1, 2);
125 mLayout->addWidget(mTempDirectoryLineEdit, 14, 2, 1, 2);
126 mLayout->addWidget(mBrowseButton, 14, 4);
127
128 setTitle(tr("Application Settings"));
129 setLayout(mLayout);
130 }
131
132 void ApplicationSettings::loadConfig()
133 {
134 mAutoCopyToClipboardNewCapturesCheckbox->setChecked(mConfig->autoCopyToClipboardNewCaptures());
135 mRememberPositionCheckbox->setChecked(mConfig->rememberPosition());
136 mCaptureOnStartupCheckbox->setChecked(mConfig->captureOnStartup());
137 mUseTabsCheckbox->setChecked(mConfig->useTabs());
138 mAutoHideTabsCheckbox->setChecked(mConfig->autoHideTabs());
139 mUseSingleInstanceCheckBox->setChecked(mConfig->useSingleInstance());
140 mAutoHideDocksCheckBox->setChecked(mConfig->autoHideDocks());
141 mAutoResizeToContentCheckBox->setChecked(mConfig->autoResizeToContent());
142 mEnableDebugging->setChecked(mConfig->isDebugEnabled());
143 mResizeToContentDelaySpinBox->setValue(mConfig->resizeToContentDelay());
144 mApplicationStyleCombobox->setCurrentText(mConfig->applicationStyle());
145 mTempDirectoryLineEdit->setText(mConfig->tempDirectory());
146
147 useTabsChanged();
148 }
149
150 void ApplicationSettings::saveSettings()
151 {
152 mConfig->setAutoCopyToClipboardNewCaptures(mAutoCopyToClipboardNewCapturesCheckbox->isChecked());
153 mConfig->setRememberPosition(mRememberPositionCheckbox->isChecked());
154 mConfig->setCaptureOnStartup(mCaptureOnStartupCheckbox->isChecked());
155 mConfig->setUseSingleInstance(mUseSingleInstanceCheckBox->isChecked());
156 mConfig->setUseTabs(mUseTabsCheckbox->isChecked());
157 mConfig->setAutoHideTabs(mAutoHideTabsCheckbox->isChecked());
158 mConfig->setAutoHideDocks(mAutoHideDocksCheckBox->isChecked());
159 mConfig->setAutoResizeToContent(mAutoResizeToContentCheckBox->isChecked());
160 mConfig->setIsDebugEnabled(mEnableDebugging->isChecked());
161 mConfig->setResizeToContentDelay(mResizeToContentDelaySpinBox->value());
162 mConfig->setApplicationStyle(mApplicationStyleCombobox->currentText());
163 mConfig->setTempDirectory(mTempDirectoryLineEdit->displayText());
164 }
165
166 void ApplicationSettings::useTabsChanged()
167 {
168 mAutoHideTabsCheckbox->setEnabled(mUseTabsCheckbox->isChecked());
169 }
170
171 void ApplicationSettings::chooseTempDirectory()
172 {
173 auto path = mFileDialogService->getExistingDirectory(this, tr("Temp Directory"), mTempDirectoryLineEdit->displayText());
174 mTempDirectoryLineEdit->setText(path);
175 }
176