1 /************************************************************************ 2 ** 3 ** Copyright (C) 2015-2020 Kevin B. Hendricks, Stratford Ontario Canada 4 ** Copyright (C) 2020 Doug Massay 5 ** Copyright (C) 2011-2013 John Schember <john@nachtimwald.com> 6 ** Copyright (C) 2012-2013 Dave Heiland 7 ** 8 ** This file is part of Sigil. 9 ** 10 ** Sigil is free software: you can redistribute it and/or modify 11 ** it under the terms of the GNU General Public License as published by 12 ** the Free Software Foundation, either version 3 of the License, or 13 ** (at your option) any later version. 14 ** 15 ** Sigil is distributed in the hope that it will be useful, 16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 ** GNU General Public License for more details. 19 ** 20 ** You should have received a copy of the GNU General Public License 21 ** along with Sigil. If not, see <http://www.gnu.org/licenses/>. 22 ** 23 *************************************************************************/ 24 25 #pragma once 26 #ifndef SETTINGSSTORE_H 27 #define SETTINGSSTORE_H 28 29 #include <QColor> 30 #include <QtCore/QSettings> 31 #include <QtCore/QString> 32 #include <utility> 33 34 #define CLEANON_OPEN (1 << 0) 35 #define CLEANON_SAVE (1 << 1) 36 37 class QColor; 38 39 /** 40 * Provides access for reading and writing user configurable 41 * settings. This should be used instead of QSettings because it 42 * sets up the settings to use INI format on all platforms except 43 * OS X. Also, it implements a variety of settings that are used in 44 * a large number of places throughout the application. 45 */ 46 class SettingsStore : public QSettings 47 { 48 Q_OBJECT 49 50 public: 51 SettingsStore(); 52 SettingsStore(QString filename); 53 54 /** 55 * The langauge to use for the user interface 56 * 57 * @return The language as a string. 58 */ 59 QString uiLanguage(); 60 61 QString uiFont(); 62 QString originalUIFont(); 63 QString uiIconTheme(); 64 65 int uiDragDistanceTweak(); 66 67 /** 68 * The default langauge to use when creating new books. 69 * 70 * @return The language as a string. 71 */ 72 QString defaultMetadataLang(); 73 74 QString externalXEditorPath(); 75 76 /** 77 * The zoom factor used by the component. 78 * 79 * @return The zoom factor. 80 */ 81 float zoomImage(); 82 float zoomText(); 83 float zoomWeb(); 84 float zoomPreview(); 85 float zoomInspector(); 86 87 /** 88 * The name of the dictionary to use for spell check. 89 * 90 * @return The dictionary name. 91 */ 92 QString dictionary(); 93 94 QStringList enabledUserDictionaries(); 95 96 QString secondary_dictionary(); 97 98 99 /** 100 * Get the list of entities/code pairs to preserve 101 */ 102 103 QList<std::pair <ushort, QString>> preserveEntityCodeNames(); 104 105 /** 106 * Support for Plugins 107 */ 108 QHash <QString, QString> pluginEnginePaths(); 109 QString pluginLastFolder(); 110 bool useBundledInterp(); 111 112 /** 113 * Get version specification for W3C validation 114 */ 115 QString cssEpub2ValidationSpec(); 116 QString cssEpub3ValidationSpec(); 117 118 119 /** 120 * Get path to temp folder home 121 */ 122 QString tempFolderHome(); 123 124 /** 125 * Whether automatic Spellcheck is enabled or not 126 * 127 * @return if spell check is enabled 128 */ 129 bool spellCheck(); 130 131 bool spellCheckNumbers(); 132 133 /** 134 * The name of the file containing user words 135 * 136 * @return The dictionary name. 137 */ 138 QString defaultUserDictionary(); 139 140 /** 141 * The template name for renaming selections in book browser 142 * 143 * @return The template name. 144 */ 145 QString renameTemplate(); 146 147 int remoteOn(); 148 149 int javascriptOn(); 150 151 int showFullPathOn(); 152 153 int highDPI(); 154 155 int previewDark(); 156 157 int cleanOn(); 158 159 QStringList pluginMap(); 160 161 QString defaultVersion(); 162 163 /** 164 * All appearance settings related to BookView. 165 */ 166 struct PreviewAppearance { 167 QString font_family_standard; 168 QString font_family_serif; 169 QString font_family_sans_serif; 170 int font_size; 171 }; 172 173 /** 174 * All appearance settings related to CodeView. 175 */ 176 struct CodeViewAppearance { 177 QString font_family; 178 int font_size; 179 180 QColor css_comment_color; 181 QColor css_property_color; 182 QColor css_quote_color; 183 QColor css_selector_color; 184 QColor css_value_color; 185 186 QColor line_highlight_color; 187 QColor line_number_background_color; 188 QColor line_number_foreground_color; 189 190 QColor spelling_underline_color; 191 192 QColor xhtml_attribute_name_color; 193 QColor xhtml_attribute_value_color; 194 QColor xhtml_css_color; 195 QColor xhtml_css_comment_color; 196 QColor xhtml_doctype_color; 197 QColor xhtml_entity_color; 198 QColor xhtml_html_color; 199 QColor xhtml_html_comment_color; 200 }; 201 202 /** 203 * Highlight the matching open/close tag when the cursor is in a tag 204 */ 205 bool highlightOpenCloseTags(); 206 207 /** 208 * All appearance settings related to Special Characters. 209 */ 210 struct SpecialCharacterAppearance { 211 QString font_family; 212 int font_size; 213 }; 214 215 216 /** 217 * The preferred tab for the appearance prefs widget. 218 */ 219 int appearancePrefsTabIndex(); 220 221 /** 222 * The default font to use for rendering Preview. 223 */ 224 PreviewAppearance previewAppearance(); 225 226 /** 227 * The appearance settings to use for editing in Code View. 228 */ 229 CodeViewAppearance codeViewAppearance(); 230 231 CodeViewAppearance codeViewDarkAppearance(); 232 233 234 /** 235 * The appearance settings to use for editing in Code View. 236 */ 237 SpecialCharacterAppearance specialCharacterAppearance(); 238 239 /** 240 * The icon size to use for the main menu. 241 */ 242 double mainMenuIconSize(); 243 244 /** 245 * How many clipboard history items to save. 246 * -1 default 247 * 0 disable clipboard history saving 248 * 1+ limit saved entries to this number 249 */ 250 int clipboardHistoryLimit(); 251 252 /** 253 * Clear all Preview, Code View and Special Characters settings back to their defaults. 254 */ 255 void clearAppearanceSettings(); 256 257 bool enableAltGr(); 258 259 public slots: 260 261 /** 262 * Set the language to use for the user interface 263 * 264 * @param lang The language to set. 265 */ 266 void setUILanguage(const QString &language_code); 267 268 void setUIFont(const QString &font_data); 269 270 void setOriginalUIFont(const QString &font_data); 271 272 void setUIIconTheme(const QString &iconthemename); 273 274 void setUiDragDistanceTweak(int tweak); 275 276 /** 277 * Set the default language to use when creating new books. 278 * 279 * @param lang The language to set. 280 */ 281 void setDefaultMetadataLang(const QString &lang); 282 283 void setExternalXEditorPath(const QString &path); 284 285 /** 286 * Set the zoom factor used by the component. 287 * 288 * @param zoom The zoom factor. 289 */ 290 void setZoomImage(float zoom); 291 void setZoomText(float zoom); 292 void setZoomWeb(float zoom); 293 void setZoomPreview(float zoom); 294 void setZoomInspector(float zoom); 295 296 /** 297 * Set the name of the dictionary the user has selected. 298 * 299 * @param name The name of the dictionary. 300 */ 301 void setDictionary(const QString &name); 302 303 void setEnabledUserDictionaries(const QStringList name); 304 305 void setSecondaryDictionary(const QString &name); 306 307 /** 308 * Set the list of paired code, entity strings to preserve. 309 */ 310 311 void setPreserveEntityCodeNames(const QList<std::pair <ushort, QString>> codenames); 312 313 314 /** 315 * Support for Plugins 316 */ 317 318 void setPluginEnginePaths(const QHash <QString, QString> &enginepaths); 319 void setPluginLastFolder(const QString &lastfolder); 320 void setUseBundledInterp(bool use); 321 322 /** 323 * Set which css version to specify to the W3C Validator 324 */ 325 void setCssEpub2ValidationSpec(const QString &spec); 326 void setCssEpub3ValidationSpec(const QString &spec); 327 328 /** 329 * Set path to temp folder home 330 */ 331 void setTempFolderHome(const QString &path); 332 333 /** 334 * Set whether automatic Spellcheck is enabled 335 * 336 * @param name The name of the dictionary. 337 */ 338 void setSpellCheck(bool enabled); 339 340 void setSpellCheckNumbers(bool enabled); 341 342 /** 343 * Set the name of the dictionary file to store user words. 344 * 345 * @param name The name of the dictionary file. 346 */ 347 void setDefaultUserDictionary(const QString &name); 348 349 /** 350 * Set the name of the dictionary the user has selected. 351 * 352 * @param name The name of the dictionary. 353 */ 354 void setRenameTemplate(const QString &name); 355 356 void setRemoteOn(int on); 357 358 void setJavascriptOn(int on); 359 360 void setShowFullPathOn(int on); 361 362 void setHighDPI(int value); 363 364 void setPreviewDark(int enabled); 365 366 void setCleanOn(int on); 367 368 void setPluginMap(const QStringList & map); 369 370 void setDefaultVersion(const QString &version); 371 372 /** 373 * Set the preferred tab for the appearance prefs widget. 374 */ 375 void setAppearancePrefsTabIndex(int index); 376 377 /** 378 * Set the default font settings to use for rendering Book View/Preview 379 */ 380 void setPreviewAppearance(const PreviewAppearance &preview_appearance); 381 /** 382 * Set the appearance settings to use for editing in Code View 383 */ 384 void setCodeViewAppearance(const CodeViewAppearance &code_view_appearance); 385 386 /** 387 * Set whether to highlight the matching open/close tag when the cursor is in a tag 388 */ 389 void setHighlightOpenCloseTags(bool enabled); 390 391 void setCodeViewDarkAppearance(const CodeViewAppearance &code_view_appearance); 392 /** 393 * Set the default font settings to use for Special Characters popup window 394 */ 395 void setSpecialCharacterAppearance(const SpecialCharacterAppearance &special_character_appearance); 396 397 /** 398 * Set the icon size to use for the main menu. 399 */ 400 void setMainMenuIconSize(double icon_size); 401 402 /** 403 * Set the number of clipboard history items to retain 404 */ 405 void setClipboardHistoryLimit(int limit); 406 407 void setEnableAltGr(bool enabled); 408 409 private: 410 /** 411 * Ensures there is not an open settings group which will cause the settings 412 * this class implements to be set in the wrong place. 413 */ 414 void clearSettingsGroup(); 415 }; 416 417 #endif // SETTINGSSTORE_H 418