Changeset View
Changeset View
Standalone View
Standalone View
src/Gui/SettingsDialog/SaveOptionsPage.cpp
Show All 30 Lines | |||||
31 | #include <QHBoxLayout> | 31 | #include <QHBoxLayout> | ||
32 | #include <QComboBox> | 32 | #include <QComboBox> | ||
33 | #include <QImageWriter> | 33 | #include <QImageWriter> | ||
34 | #include <QCheckBox> | 34 | #include <QCheckBox> | ||
35 | 35 | | |||
36 | SaveOptionsPage::SaveOptionsPage(QWidget *parent) : | 36 | SaveOptionsPage::SaveOptionsPage(QWidget *parent) : | ||
37 | SettingsPage(parent) | 37 | SettingsPage(parent) | ||
38 | { | 38 | { | ||
39 | | ||||
davidre: You have added an empty line here. | |||||
39 | QFormLayout *mainLayout = new QFormLayout; | 40 | QFormLayout *mainLayout = new QFormLayout; | ||
40 | setLayout(mainLayout); | 41 | setLayout(mainLayout); | ||
41 | 42 | | |||
42 | // Save location | 43 | // Save location | ||
43 | mUrlRequester = new KUrlRequester; | 44 | mUrlRequester = new KUrlRequester; | ||
44 | mUrlRequester->setMode(KFile::Directory); | 45 | mUrlRequester->setMode(KFile::Directory); | ||
45 | connect(mUrlRequester, &KUrlRequester::textChanged, this, &SaveOptionsPage::markDirty); | 46 | connect(mUrlRequester, &KUrlRequester::textChanged, this, &SaveOptionsPage::markDirty); | ||
46 | mainLayout->addRow(i18n("Save Location:"), mUrlRequester); | 47 | mainLayout->addRow(i18n("Save Location:"), mUrlRequester); | ||
Show All 18 Lines | 65 | connect(mSaveNameFormat, &QLineEdit::textEdited, [&](const QString &newText) { | |||
65 | QString fmt; | 66 | QString fmt; | ||
66 | Q_FOREACH(auto item, QImageWriter::supportedImageFormats()) { | 67 | Q_FOREACH(auto item, QImageWriter::supportedImageFormats()) { | ||
67 | fmt = QString::fromLocal8Bit(item); | 68 | fmt = QString::fromLocal8Bit(item); | ||
68 | if (newText.endsWith(QLatin1Char('.') + fmt, Qt::CaseInsensitive)) { | 69 | if (newText.endsWith(QLatin1Char('.') + fmt, Qt::CaseInsensitive)) { | ||
69 | QString txtCopy = newText; | 70 | QString txtCopy = newText; | ||
70 | txtCopy.chop(fmt.length() + 1); | 71 | txtCopy.chop(fmt.length() + 1); | ||
71 | mSaveNameFormat->setText(txtCopy); | 72 | mSaveNameFormat->setText(txtCopy); | ||
72 | mSaveImageFormat->setCurrentIndex(mSaveImageFormat->findText(fmt.toUpper())); | 73 | mSaveImageFormat->setCurrentIndex(mSaveImageFormat->findText(fmt.toUpper())); | ||
73 | } | 74 | } | ||
Put the Brace on the same line as the parameter list - this style is already used in this file davidre: Put the Brace on the same line as the parameter list - this style is already used in this file | |||||
74 | } | 75 | } | ||
75 | }); | 76 | }); | ||
76 | mSaveNameFormat->setPlaceholderText(QStringLiteral("%d")); | 77 | mSaveNameFormat->setPlaceholderText(QStringLiteral("%d")); | ||
77 | saveFieldLayout->addWidget(mSaveNameFormat); | 78 | saveFieldLayout->addWidget(mSaveNameFormat); | ||
78 | 79 | | |||
79 | mSaveImageFormat = new QComboBox; | 80 | mSaveImageFormat = new QComboBox; | ||
80 | mSaveImageFormat->addItems([&](){ | 81 | mSaveImageFormat->addItems([&](){ | ||
81 | QStringList items; | 82 | QStringList items; | ||
Show All 34 Lines | |||||
116 | 117 | | |||
117 | QLabel *fmtHelpText = new QLabel(helpText, this); | 118 | QLabel *fmtHelpText = new QLabel(helpText, this); | ||
118 | fmtHelpText->setWordWrap(true); | 119 | fmtHelpText->setWordWrap(true); | ||
119 | fmtHelpText->setTextFormat(Qt::RichText); | 120 | fmtHelpText->setTextFormat(Qt::RichText); | ||
120 | fmtHelpText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); | 121 | fmtHelpText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); | ||
121 | saveNameLayout->addWidget(fmtHelpText); | 122 | saveNameLayout->addWidget(fmtHelpText); | ||
122 | mainLayout->addRow(i18n("Filename:"), saveNameLayout); | 123 | mainLayout->addRow(i18n("Filename:"), saveNameLayout); | ||
123 | 124 | | |||
125 | | ||||
126 | // Compression quality slider and current value display | ||||
127 | QHBoxLayout *qualitySliderLayout = new QHBoxLayout(); | ||||
128 | | ||||
129 | // Current value | ||||
130 | mQualityValue = new QLabel(); | ||||
131 | mQualityValue->setNum(SpectacleConfig::instance()->compressionQuality()); | ||||
132 | mQualityValue->setMinimumWidth(mQualityValue->fontInfo().pointSize()*3); | ||||
133 | | ||||
134 | // Slider | ||||
135 | mQualitySlider = new QSlider(Qt::Horizontal); | ||||
136 | mQualitySlider->setRange(0, 100); | ||||
137 | mQualitySlider->setTickInterval(5); | ||||
138 | mQualitySlider->setSliderPosition(SpectacleConfig::instance()->compressionQuality()); | ||||
139 | mQualitySlider->setTickPosition(QSlider::TicksBelow); | ||||
140 | mQualitySlider->setTracking(true); | ||||
141 | connect(mQualitySlider, &QSlider::valueChanged, this, &SaveOptionsPage::updateQualityValue); | ||||
142 | | ||||
143 | qualitySliderLayout->addWidget(mQualitySlider); | ||||
144 | qualitySliderLayout->addWidget(mQualityValue); | ||||
145 | mainLayout->addRow(i18n("Compression Quality:"), qualitySliderLayout); | ||||
146 | | ||||
124 | // read in the data | 147 | // read in the data | ||
125 | resetChanges(); | 148 | resetChanges(); | ||
126 | } | 149 | } | ||
127 | 150 | | |||
128 | void SaveOptionsPage::markDirty() | 151 | void SaveOptionsPage::markDirty() | ||
129 | { | 152 | { | ||
130 | mChangesMade = true; | 153 | mChangesMade = true; | ||
131 | } | 154 | } | ||
132 | 155 | | |||
156 | void SaveOptionsPage::updateQualityValue() | ||||
157 | { | ||||
158 | mQualityValue->setNum(mQualitySlider->value()); | ||||
159 | this->markDirty(); | ||||
160 | } | ||||
161 | | ||||
133 | void SaveOptionsPage::saveChanges() | 162 | void SaveOptionsPage::saveChanges() | ||
134 | { | 163 | { | ||
135 | // bring up the configuration reader | 164 | // bring up the configuration reader | ||
136 | 165 | | |||
137 | SpectacleConfig *cfgManager = SpectacleConfig::instance(); | 166 | SpectacleConfig *cfgManager = SpectacleConfig::instance(); | ||
138 | 167 | | |||
139 | // save the data | 168 | // save the data | ||
140 | 169 | | |||
141 | cfgManager->setDefaultSaveLocation(mUrlRequester->url().toDisplayString(QUrl::PreferLocalFile)); | 170 | cfgManager->setDefaultSaveLocation(mUrlRequester->url().toDisplayString(QUrl::PreferLocalFile)); | ||
142 | cfgManager->setAutoSaveFilenameFormat(mSaveNameFormat->text()); | 171 | cfgManager->setAutoSaveFilenameFormat(mSaveNameFormat->text()); | ||
143 | cfgManager->setSaveImageFormat(mSaveImageFormat->currentText().toLower()); | 172 | cfgManager->setSaveImageFormat(mSaveImageFormat->currentText().toLower()); | ||
144 | cfgManager->setCopySaveLocationToClipboard(mCopyPathToClipboard->checkState() == Qt::Checked); | 173 | cfgManager->setCopySaveLocationToClipboard(mCopyPathToClipboard->checkState() == Qt::Checked); | ||
174 | cfgManager->setCompressionQuality(mQualitySlider->value()); | ||||
145 | 175 | | |||
146 | // done | 176 | // done | ||
147 | 177 | | |||
148 | mChangesMade = false; | 178 | mChangesMade = false; | ||
149 | } | 179 | } | ||
150 | 180 | | |||
151 | void SaveOptionsPage::resetChanges() | 181 | void SaveOptionsPage::resetChanges() | ||
152 | { | 182 | { | ||
153 | // bring up the configuration reader | 183 | // bring up the configuration reader | ||
154 | 184 | | |||
155 | SpectacleConfig *cfgManager = SpectacleConfig::instance(); | 185 | SpectacleConfig *cfgManager = SpectacleConfig::instance(); | ||
156 | 186 | | |||
157 | // read in the data | 187 | // read in the data | ||
158 | 188 | | |||
159 | mSaveNameFormat->setText(cfgManager->autoSaveFilenameFormat()); | 189 | mSaveNameFormat->setText(cfgManager->autoSaveFilenameFormat()); | ||
160 | mUrlRequester->setUrl(QUrl::fromUserInput(cfgManager->defaultSaveLocation())); | 190 | mUrlRequester->setUrl(QUrl::fromUserInput(cfgManager->defaultSaveLocation())); | ||
161 | mCopyPathToClipboard->setChecked(cfgManager->copySaveLocationToClipboard()); | 191 | mCopyPathToClipboard->setChecked(cfgManager->copySaveLocationToClipboard()); | ||
192 | mQualitySlider->setSliderPosition(cfgManager->compressionQuality()); | ||||
162 | 193 | | |||
163 | // read in the save image format and calculate its index | 194 | // read in the save image format and calculate its index | ||
164 | 195 | | |||
165 | { | 196 | { | ||
166 | int index = mSaveImageFormat->findText(cfgManager->saveImageFormat().toUpper()); | 197 | int index = mSaveImageFormat->findText(cfgManager->saveImageFormat().toUpper()); | ||
167 | if (index >= 0) { | 198 | if (index >= 0) { | ||
168 | mSaveImageFormat->setCurrentIndex(index); | 199 | mSaveImageFormat->setCurrentIndex(index); | ||
169 | } | 200 | } | ||
170 | } | 201 | } | ||
171 | 202 | | |||
172 | // done | 203 | // done | ||
173 | 204 | | |||
174 | mChangesMade = false; | 205 | mChangesMade = false; | ||
175 | } | 206 | } |
You have added an empty line here.