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); | ||
47 | 48 | | |||
48 | // copy file location to clipboard after saving | 49 | // copy file location to clipboard after saving | ||
49 | mCopyPathToClipboard = new QCheckBox(i18n("Copy file location to clipboard after saving"), this); | 50 | mCopyPathToClipboard = new QCheckBox(i18n("Copy file location to clipboard after saving"), this); | ||
50 | connect(mCopyPathToClipboard, &QCheckBox::toggled, this, &SaveOptionsPage::markDirty); | 51 | connect(mCopyPathToClipboard, &QCheckBox::toggled, this, &SaveOptionsPage::markDirty); | ||
51 | mainLayout->addRow(QString(), mCopyPathToClipboard); | 52 | mainLayout->addRow(QString(), mCopyPathToClipboard); | ||
52 | 53 | | |||
53 | 54 | | |||
54 | mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); | 55 | mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); | ||
55 | 56 | | |||
57 | // Compression quality slider and current value display | ||||
58 | QHBoxLayout *qualitySliderLayout = new QHBoxLayout(); | ||||
59 | | ||||
60 | // Current value | ||||
61 | mQualityValue = new QLabel(); | ||||
62 | mQualityValue->setNum(SpectacleConfig::instance()->compressionQuality()); | ||||
63 | mQualityValue->setMinimumWidth(mQualityValue->fontInfo().pointSize()*3); | ||||
64 | | ||||
65 | // Slider | ||||
66 | mQualitySlider = new QSlider(Qt::Horizontal); | ||||
67 | mQualitySlider->setRange(0, 100); | ||||
68 | mQualitySlider->setTickInterval(5); | ||||
69 | mQualitySlider->setSliderPosition(SpectacleConfig::instance()->compressionQuality()); | ||||
70 | mQualitySlider->setTickPosition(QSlider::TicksBelow); | ||||
71 | mQualitySlider->setTracking(true); | ||||
72 | connect(mQualitySlider, &QSlider::valueChanged, this, &SaveOptionsPage::updateQualityValue); | ||||
73 | | ||||
74 | qualitySliderLayout->addWidget(mQualitySlider); | ||||
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 | |||||
75 | qualitySliderLayout->addWidget(mQualityValue); | ||||
76 | mainLayout->addRow(i18n("Compression Quality:"), qualitySliderLayout); | ||||
77 | | ||||
78 | mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); | ||||
56 | 79 | | |||
57 | // filename chooser and instructional text | 80 | // filename chooser and instructional text | ||
58 | QVBoxLayout *saveNameLayout = new QVBoxLayout; | 81 | QVBoxLayout *saveNameLayout = new QVBoxLayout; | ||
59 | 82 | | |||
60 | // filename chooser text field | 83 | // filename chooser text field | ||
61 | QHBoxLayout *saveFieldLayout = new QHBoxLayout; | 84 | QHBoxLayout *saveFieldLayout = new QHBoxLayout; | ||
62 | mSaveNameFormat = new QLineEdit; | 85 | mSaveNameFormat = new QLineEdit; | ||
63 | connect(mSaveNameFormat, &QLineEdit::textEdited, this, &SaveOptionsPage::markDirty); | 86 | connect(mSaveNameFormat, &QLineEdit::textEdited, this, &SaveOptionsPage::markDirty); | ||
Show All 19 Lines | 105 | Q_FOREACH(auto fmt, QImageWriter::supportedImageFormats()) { | |||
83 | items.append(QString::fromLocal8Bit(fmt).toUpper()); | 106 | items.append(QString::fromLocal8Bit(fmt).toUpper()); | ||
84 | } | 107 | } | ||
85 | return items; | 108 | return items; | ||
86 | }()); | 109 | }()); | ||
87 | connect(mSaveImageFormat, &QComboBox::currentTextChanged, this, &SaveOptionsPage::markDirty); | 110 | connect(mSaveImageFormat, &QComboBox::currentTextChanged, this, &SaveOptionsPage::markDirty); | ||
88 | saveFieldLayout->addWidget(mSaveImageFormat); | 111 | saveFieldLayout->addWidget(mSaveImageFormat); | ||
89 | saveNameLayout->addLayout(saveFieldLayout); | 112 | saveNameLayout->addLayout(saveFieldLayout); | ||
90 | 113 | | |||
114 | | ||||
91 | // now the save filename format layout | 115 | // now the save filename format layout | ||
92 | const QString helpText = i18nc("%1 is the default filename of a screenshot", | 116 | const QString helpText = i18nc("%1 is the default filename of a screenshot", | ||
93 | "<p>You can use the following placeholders in the filename, which will be replaced " | 117 | "<p>You can use the following placeholders in the filename, which will be replaced " | ||
94 | "with actual text when the file is saved:</p>" | 118 | "with actual text when the file is saved:</p>" | ||
95 | 119 | | |||
96 | "<blockquote>" | 120 | "<blockquote>" | ||
97 | "<b>%Y</b>: Year (4 digit)<br />" | 121 | "<b>%Y</b>: Year (4 digit)<br />" | ||
98 | "<b>%y</b>: Year (2 digit)<br />" | 122 | "<b>%y</b>: Year (2 digit)<br />" | ||
Show All 17 Lines | |||||
116 | 140 | | |||
117 | QLabel *fmtHelpText = new QLabel(helpText, this); | 141 | QLabel *fmtHelpText = new QLabel(helpText, this); | ||
118 | fmtHelpText->setWordWrap(true); | 142 | fmtHelpText->setWordWrap(true); | ||
119 | fmtHelpText->setTextFormat(Qt::RichText); | 143 | fmtHelpText->setTextFormat(Qt::RichText); | ||
120 | fmtHelpText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); | 144 | fmtHelpText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); | ||
121 | saveNameLayout->addWidget(fmtHelpText); | 145 | saveNameLayout->addWidget(fmtHelpText); | ||
122 | mainLayout->addRow(i18n("Filename:"), saveNameLayout); | 146 | mainLayout->addRow(i18n("Filename:"), saveNameLayout); | ||
123 | 147 | | |||
148 | | ||||
124 | // read in the data | 149 | // read in the data | ||
125 | resetChanges(); | 150 | resetChanges(); | ||
126 | } | 151 | } | ||
127 | 152 | | |||
128 | void SaveOptionsPage::markDirty() | 153 | void SaveOptionsPage::markDirty() | ||
129 | { | 154 | { | ||
130 | mChangesMade = true; | 155 | mChangesMade = true; | ||
131 | } | 156 | } | ||
132 | 157 | | |||
158 | void SaveOptionsPage::updateQualityValue() | ||||
159 | { | ||||
160 | mQualityValue->setNum(mQualitySlider->value()); | ||||
161 | this->markDirty(); | ||||
162 | } | ||||
163 | | ||||
133 | void SaveOptionsPage::saveChanges() | 164 | void SaveOptionsPage::saveChanges() | ||
134 | { | 165 | { | ||
135 | // bring up the configuration reader | 166 | // bring up the configuration reader | ||
136 | 167 | | |||
137 | SpectacleConfig *cfgManager = SpectacleConfig::instance(); | 168 | SpectacleConfig *cfgManager = SpectacleConfig::instance(); | ||
138 | 169 | | |||
139 | // save the data | 170 | // save the data | ||
140 | 171 | | |||
141 | cfgManager->setDefaultSaveLocation(mUrlRequester->url().toDisplayString(QUrl::PreferLocalFile)); | 172 | cfgManager->setDefaultSaveLocation(mUrlRequester->url().toDisplayString(QUrl::PreferLocalFile)); | ||
142 | cfgManager->setAutoSaveFilenameFormat(mSaveNameFormat->text()); | 173 | cfgManager->setAutoSaveFilenameFormat(mSaveNameFormat->text()); | ||
143 | cfgManager->setSaveImageFormat(mSaveImageFormat->currentText().toLower()); | 174 | cfgManager->setSaveImageFormat(mSaveImageFormat->currentText().toLower()); | ||
144 | cfgManager->setCopySaveLocationToClipboard(mCopyPathToClipboard->checkState() == Qt::Checked); | 175 | cfgManager->setCopySaveLocationToClipboard(mCopyPathToClipboard->checkState() == Qt::Checked); | ||
176 | cfgManager->setCompressionQuality(mQualitySlider->value()); | ||||
145 | 177 | | |||
146 | // done | 178 | // done | ||
147 | 179 | | |||
148 | mChangesMade = false; | 180 | mChangesMade = false; | ||
149 | } | 181 | } | ||
150 | 182 | | |||
151 | void SaveOptionsPage::resetChanges() | 183 | void SaveOptionsPage::resetChanges() | ||
152 | { | 184 | { | ||
153 | // bring up the configuration reader | 185 | // bring up the configuration reader | ||
154 | 186 | | |||
155 | SpectacleConfig *cfgManager = SpectacleConfig::instance(); | 187 | SpectacleConfig *cfgManager = SpectacleConfig::instance(); | ||
156 | 188 | | |||
157 | // read in the data | 189 | // read in the data | ||
158 | 190 | | |||
159 | mSaveNameFormat->setText(cfgManager->autoSaveFilenameFormat()); | 191 | mSaveNameFormat->setText(cfgManager->autoSaveFilenameFormat()); | ||
160 | mUrlRequester->setUrl(QUrl::fromUserInput(cfgManager->defaultSaveLocation())); | 192 | mUrlRequester->setUrl(QUrl::fromUserInput(cfgManager->defaultSaveLocation())); | ||
161 | mCopyPathToClipboard->setChecked(cfgManager->copySaveLocationToClipboard()); | 193 | mCopyPathToClipboard->setChecked(cfgManager->copySaveLocationToClipboard()); | ||
194 | mQualitySlider->setSliderPosition(cfgManager->compressionQuality()); | ||||
162 | 195 | | |||
163 | // read in the save image format and calculate its index | 196 | // read in the save image format and calculate its index | ||
164 | 197 | | |||
165 | { | 198 | { | ||
166 | int index = mSaveImageFormat->findText(cfgManager->saveImageFormat().toUpper()); | 199 | int index = mSaveImageFormat->findText(cfgManager->saveImageFormat().toUpper()); | ||
167 | if (index >= 0) { | 200 | if (index >= 0) { | ||
168 | mSaveImageFormat->setCurrentIndex(index); | 201 | mSaveImageFormat->setCurrentIndex(index); | ||
169 | } | 202 | } | ||
170 | } | 203 | } | ||
171 | 204 | | |||
172 | // done | 205 | // done | ||
173 | 206 | | |||
174 | mChangesMade = false; | 207 | mChangesMade = false; | ||
175 | } | 208 | } |
You have added an empty line here.