Changeset View
Changeset View
Standalone View
Standalone View
src/Gui/SettingsDialog/SaveOptionsPage.cpp
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | 39 | { | |||
---|---|---|---|---|---|
84 | qualitySliderDescription->setText(i18n("Choose the image quality when saving with lossy image formats like JPEG")); | 84 | qualitySliderDescription->setText(i18n("Choose the image quality when saving with lossy image formats like JPEG")); | ||
85 | 85 | | |||
86 | sliderVertLayout->addWidget(qualitySliderDescription); | 86 | sliderVertLayout->addWidget(qualitySliderDescription); | ||
87 | 87 | | |||
88 | mainLayout->addRow(i18n("Compression Quality:"), sliderVertLayout); | 88 | mainLayout->addRow(i18n("Compression Quality:"), sliderVertLayout); | ||
89 | 89 | | |||
90 | mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); | 90 | mainLayout->addItem(new QSpacerItem(0, 18, QSizePolicy::Fixed, QSizePolicy::Fixed)); | ||
91 | 91 | | |||
92 | // filename chooser and instructional text | | |||
93 | QVBoxLayout *saveNameLayout = new QVBoxLayout; | | |||
94 | | ||||
95 | // filename chooser text field | 92 | // filename chooser text field | ||
96 | QHBoxLayout *saveFieldLayout = new QHBoxLayout; | 93 | QHBoxLayout *saveFieldLayout = new QHBoxLayout; | ||
97 | mSaveNameFormat = new QLineEdit; | 94 | mSaveNameFormat = new QLineEdit; | ||
98 | connect(mSaveNameFormat, &QLineEdit::textEdited, this, &SaveOptionsPage::markDirty); | 95 | connect(mSaveNameFormat, &QLineEdit::textEdited, this, &SaveOptionsPage::markDirty); | ||
99 | connect(mSaveNameFormat, &QLineEdit::textEdited, [&](const QString &newText) { | 96 | connect(mSaveNameFormat, &QLineEdit::textEdited, [&](const QString &newText) { | ||
100 | QString fmt; | 97 | QString fmt; | ||
101 | Q_FOREACH(auto item, QImageWriter::supportedImageFormats()) { | 98 | Q_FOREACH(auto item, QImageWriter::supportedImageFormats()) { | ||
102 | fmt = QString::fromLocal8Bit(item); | 99 | fmt = QString::fromLocal8Bit(item); | ||
103 | if (newText.endsWith(QLatin1Char('.') + fmt, Qt::CaseInsensitive)) { | 100 | if (newText.endsWith(QLatin1Char('.') + fmt, Qt::CaseInsensitive)) { | ||
104 | QString txtCopy = newText; | 101 | QString txtCopy = newText; | ||
105 | txtCopy.chop(fmt.length() + 1); | 102 | txtCopy.chop(fmt.length() + 1); | ||
106 | mSaveNameFormat->setText(txtCopy); | 103 | mSaveNameFormat->setText(txtCopy); | ||
107 | mSaveImageFormat->setCurrentIndex(mSaveImageFormat->findText(fmt.toUpper())); | 104 | mSaveImageFormat->setCurrentIndex(mSaveImageFormat->findText(fmt.toUpper())); | ||
108 | } | 105 | } | ||
109 | } | 106 | } | ||
110 | }); | 107 | }); | ||
108 | connect(mSaveNameFormat, &QLineEdit::textChanged,this, &SaveOptionsPage::updateFilenamePreview); | ||||
111 | mSaveNameFormat->setPlaceholderText(QStringLiteral("%d")); | 109 | mSaveNameFormat->setPlaceholderText(QStringLiteral("%d")); | ||
112 | saveFieldLayout->addWidget(mSaveNameFormat); | 110 | saveFieldLayout->addWidget(mSaveNameFormat); | ||
113 | 111 | | |||
114 | mSaveImageFormat = new QComboBox; | 112 | mSaveImageFormat = new QComboBox; | ||
115 | mSaveImageFormat->addItems([&](){ | 113 | mSaveImageFormat->addItems([&](){ | ||
116 | QStringList items; | 114 | QStringList items; | ||
117 | Q_FOREACH(auto fmt, QImageWriter::supportedImageFormats()) { | 115 | Q_FOREACH(auto fmt, QImageWriter::supportedImageFormats()) { | ||
118 | items.append(QString::fromLocal8Bit(fmt).toUpper()); | 116 | items.append(QString::fromLocal8Bit(fmt).toUpper()); | ||
119 | } | 117 | } | ||
120 | return items; | 118 | return items; | ||
121 | }()); | 119 | }()); | ||
122 | connect(mSaveImageFormat, &QComboBox::currentTextChanged, this, &SaveOptionsPage::markDirty); | 120 | connect(mSaveImageFormat, &QComboBox::currentTextChanged, this, &SaveOptionsPage::markDirty); | ||
121 | connect(mSaveImageFormat, &QComboBox::currentTextChanged, this, &SaveOptionsPage::updateFilenamePreview); | ||||
123 | saveFieldLayout->addWidget(mSaveImageFormat); | 122 | saveFieldLayout->addWidget(mSaveImageFormat); | ||
124 | saveNameLayout->addLayout(saveFieldLayout); | 123 | mainLayout->addRow(i18n("Filename:"), saveFieldLayout); | ||
125 | 124 | | |||
125 | mPreviewLabel = new QLabel(this); | ||||
126 | mainLayout->addRow(i18nc("Preview of the user configured filename", "Preview:"), mPreviewLabel); | ||||
ngraham: One more thing I missed, sorry: you don't need to add a space after the colon in the string. | |||||
126 | // now the save filename format layout | 127 | // now the save filename format layout | ||
127 | QString helpText = i18n( | 128 | QString helpText = i18n( | ||
128 | "You can use the following placeholders in the filename, which will be replaced " | 129 | "You can use the following placeholders in the filename, which will be replaced " | ||
129 | "with actual text when the file is saved:<blockquote>" | 130 | "with actual text when the file is saved:<blockquote>" | ||
130 | ); | 131 | ); | ||
131 | for (auto option = ExportManager::filenamePlaceholders.cbegin(); | 132 | for (auto option = ExportManager::filenamePlaceholders.cbegin(); | ||
132 | option != ExportManager::filenamePlaceholders.cend(); ++option) { | 133 | option != ExportManager::filenamePlaceholders.cend(); ++option) { | ||
133 | helpText += QStringLiteral("<a href=%1>%1</a>: %2<br>").arg(option.key(), option.value()); | 134 | helpText += QStringLiteral("<a href=%1>%1</a>: %2<br>").arg(option.key(), option.value()); | ||
134 | } | 135 | } | ||
135 | helpText += QStringLiteral("<a href='/'>/</a>: ") + i18n("To save to a sub-folder"); | 136 | helpText += QStringLiteral("<a href='/'>/</a>: ") + i18n("To save to a sub-folder"); | ||
136 | helpText += QStringLiteral("</blockquote>"); | 137 | helpText += QStringLiteral("</blockquote>"); | ||
137 | QLabel *fmtHelpText = new QLabel(helpText, this); | 138 | QLabel *fmtHelpText = new QLabel(helpText, this); | ||
138 | fmtHelpText->setWordWrap(true); | 139 | fmtHelpText->setWordWrap(true); | ||
139 | fmtHelpText->setTextFormat(Qt::RichText); | 140 | fmtHelpText->setTextFormat(Qt::RichText); | ||
140 | fmtHelpText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); | 141 | fmtHelpText->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding); | ||
141 | connect(fmtHelpText, &QLabel::linkActivated, [this](const QString& placeholder) { | 142 | connect(fmtHelpText, &QLabel::linkActivated, [this](const QString& placeholder) { | ||
142 | mSaveNameFormat->insert(placeholder); | 143 | mSaveNameFormat->insert(placeholder); | ||
143 | }); | 144 | }); | ||
144 | saveNameLayout->addWidget(fmtHelpText); | 145 | mainLayout->addWidget(fmtHelpText); | ||
145 | mainLayout->addRow(i18n("Filename:"), saveNameLayout); | | |||
146 | 146 | | |||
147 | // read in the data | 147 | // read in the data | ||
148 | resetChanges(); | 148 | resetChanges(); | ||
149 | } | 149 | } | ||
150 | 150 | | |||
151 | void SaveOptionsPage::markDirty() | 151 | void SaveOptionsPage::markDirty() | ||
152 | { | 152 | { | ||
153 | mChangesMade = true; | 153 | mChangesMade = true; | ||
Show All 39 Lines | 192 | if (index >= 0) { | |||
193 | mSaveImageFormat->setCurrentIndex(index); | 193 | mSaveImageFormat->setCurrentIndex(index); | ||
194 | } | 194 | } | ||
195 | } | 195 | } | ||
196 | 196 | | |||
197 | // done | 197 | // done | ||
198 | 198 | | |||
199 | mChangesMade = false; | 199 | mChangesMade = false; | ||
200 | } | 200 | } | ||
201 | | ||||
202 | void SaveOptionsPage::updateFilenamePreview() | ||||
203 | { | ||||
204 | ExportManager *exportManager = ExportManager::instance(); | ||||
205 | exportManager->setWindowTitle(QStringLiteral("Spectacle")); | ||||
206 | using GrabMode = ImageGrabber::GrabMode; | ||||
207 | GrabMode oldMode = exportManager->grabMode(); | ||||
208 | /* If the grabMode is not one of those below we need to change it to have the placeholder | ||||
209 | * replaced by the window title */ | ||||
210 | bool changeAndRestoreGrabMode = !(oldMode == GrabMode::ActiveWindow | ||||
211 | || oldMode == GrabMode::TransientWithParent || oldMode == GrabMode::WindowUnderCursor); | ||||
212 | if (changeAndRestoreGrabMode) { | ||||
213 | exportManager->setGrabMode(GrabMode::ActiveWindow); | ||||
214 | } | ||||
215 | const QString filename = exportManager->formatFilename(mSaveNameFormat->text()); | ||||
216 | mPreviewLabel->setText(xi18nc("@info", "<filename>%1.%2</filename>", filename, mSaveImageFormat->currentText().toLower())); | ||||
"Filename preview" Also, let's format the filename in a monospaced font. Here's how you'd do that: xi18nc("@info", "Preview of filename: <filename>%1.%2</filename>", filename, mSaveImageFormat->currentText().toLower()) ngraham: "Filename preview"
Also, let's format the filename in a monospaced font. Here's how you'd do… | |||||
broulik: Not sure about the explicit label "Preview of filename" | |||||
217 | if (changeAndRestoreGrabMode) { | ||||
218 | exportManager->setGrabMode(oldMode); | ||||
219 | } | ||||
220 | } |
One more thing I missed, sorry: you don't need to add a space after the colon in the string. The formLayout ensures that there's adequate space automatically (and keeps all the colons aligned vertically).