1 /*********************************************************************** 2 * 3 * Copyright (C) 2009, 2010, 2012, 2013, 2014, 2015, 2016 Graeme Gott <graeme@gottcode.org> 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 ***********************************************************************/ 19 20 #ifndef THEME_H 21 #define THEME_H 22 23 #include "ranged_int.h" 24 #include "settings_file.h" 25 26 #include <QColor> 27 #include <QCoreApplication> 28 #include <QExplicitlySharedDataPointer> 29 #include <QFont> 30 #include <QFuture> 31 #include <QSharedData> 32 class QImage; 33 class QSize; 34 35 class Theme : public SettingsFile 36 { Q_DECLARE_TR_FUNCTIONS(Theme)37 Q_DECLARE_TR_FUNCTIONS(Theme) 38 39 class ThemeData : public QSharedData 40 { 41 public: 42 ThemeData(const QString& id, bool is_default, bool create); 43 44 QString id; 45 QString name; 46 bool is_default; 47 48 QColor load_color; 49 50 RangedInt background_type; 51 QColor background_color; 52 QString background_path; 53 QString background_image; 54 55 QColor foreground_color; 56 RangedInt foreground_opacity; 57 RangedInt foreground_width; 58 RangedInt foreground_margin; 59 RangedInt foreground_padding; 60 RangedInt foreground_position; 61 62 bool round_corners_enabled; 63 RangedInt corner_radius; 64 65 bool blur_enabled; 66 RangedInt blur_radius; 67 68 bool shadow_enabled; 69 RangedInt shadow_offset; 70 RangedInt shadow_radius; 71 QColor shadow_color; 72 73 QColor text_color; 74 QFont text_font; 75 QColor misspelled_color; 76 77 bool indent_first_line; 78 RangedInt line_spacing; 79 RangedInt paragraph_spacing_above; 80 RangedInt paragraph_spacing_below; 81 RangedInt tab_width; 82 }; 83 QSharedDataPointer<ThemeData> d; 84 85 public: 86 Theme(); 87 Theme(const Theme& theme); 88 Theme(const QString& id, bool is_default); 89 ~Theme(); 90 Theme& operator=(const Theme& theme); 91 92 static QString clone(const QString& id, bool is_default, const QString& name); 93 static void copyBackgrounds(); 94 static QString createId(); defaultId()95 static QString defaultId() { return "writingdesk"; } 96 static bool exists(const QString& name); 97 static QString filePath(const QString& id, bool is_default = false); 98 static QString iconPath(const QString& id, bool is_default, qreal pixelratio); path()99 static QString path() { return m_path; } 100 static void removeIcon(const QString& id, bool is_default); 101 static void setDefaultPath(const QString& path); 102 static void setPath(const QString& path); 103 104 QImage render(const QSize& background, QRect& foreground, const int margin, const qreal pixelratio) const; 105 void renderText(QImage background, const QRect& foreground, const qreal pixelratio, QImage* preview, QImage* icon) const; 106 107 // Name settings isDefault()108 bool isDefault() const { return d->is_default; } id()109 QString id() const { return d->id; } name()110 QString name() const { return d->name; } setName(const QString & name)111 void setName(const QString& name) { setValue(d->name, name); } 112 113 QFuture<QColor> calculateLoadColor() const; loadColor()114 QColor loadColor() const { return d->load_color; } setLoadColor(const QColor & color)115 void setLoadColor(const QColor& color) { setValue(d->load_color, color); } 116 117 // Background settings backgroundType()118 int backgroundType() const { return d->background_type; } backgroundColor()119 QColor backgroundColor() const { return d->background_color; } 120 QString backgroundImage() const; backgroundPath()121 QString backgroundPath() const { return d->background_path; } 122 setBackgroundType(int type)123 void setBackgroundType(int type) { setValue(d->background_type, type); } setBackgroundColor(const QColor & color)124 void setBackgroundColor(const QColor& color) { setValue(d->background_color, color); } 125 void setBackgroundImage(const QString& path); 126 127 // Foreground settings foregroundColor()128 QColor foregroundColor() const { return d->foreground_color; } foregroundOpacity()129 RangedInt foregroundOpacity() const { return d->foreground_opacity; } foregroundWidth()130 RangedInt foregroundWidth() const { return d->foreground_width; } foregroundMargin()131 RangedInt foregroundMargin() const { return d->foreground_margin; } foregroundPadding()132 RangedInt foregroundPadding() const { return d->foreground_padding; } foregroundPosition()133 RangedInt foregroundPosition() const { return d->foreground_position; } 134 QRect foregroundRect(const QSize& size, int margin, const qreal pixelratio) const; 135 setForegroundColor(const QColor & color)136 void setForegroundColor(const QColor& color) { setValue(d->foreground_color, color); } setForegroundOpacity(int opacity)137 void setForegroundOpacity(int opacity) { setValue(d->foreground_opacity, opacity); } setForegroundWidth(int width)138 void setForegroundWidth(int width) { setValue(d->foreground_width, width); } setForegroundMargin(int margin)139 void setForegroundMargin(int margin) { setValue(d->foreground_margin, margin); } setForegroundPadding(int padding)140 void setForegroundPadding(int padding) { setValue(d->foreground_padding, padding); } setForegroundPosition(int position)141 void setForegroundPosition(int position) { setValue(d->foreground_position, position); } 142 roundCornersEnabled()143 bool roundCornersEnabled() const { return d->round_corners_enabled; } cornerRadius()144 RangedInt cornerRadius() const { return d->corner_radius; } 145 setRoundCornersEnabled(bool enabled)146 void setRoundCornersEnabled(bool enabled) { setValue(d->round_corners_enabled, enabled); } setCornerRadius(int radius)147 void setCornerRadius(int radius) { setValue(d->corner_radius, radius); } 148 blurEnabled()149 bool blurEnabled() const { return d->blur_enabled; } blurRadius()150 RangedInt blurRadius() const { return d->blur_radius; } 151 setBlurEnabled(bool enabled)152 void setBlurEnabled(bool enabled) { setValue(d->blur_enabled, enabled); } setBlurRadius(int radius)153 void setBlurRadius(int radius) { setValue(d->blur_radius, radius); } 154 shadowEnabled()155 bool shadowEnabled() const { return d->shadow_enabled; } shadowColor()156 QColor shadowColor() const { return d->shadow_color; } shadowRadius()157 RangedInt shadowRadius() const { return d->shadow_radius; } shadowOffset()158 RangedInt shadowOffset() const { return d->shadow_offset; } 159 setShadowEnabled(bool enabled)160 void setShadowEnabled(bool enabled) { setValue(d->shadow_enabled, enabled); } setShadowColor(const QColor & color)161 void setShadowColor(const QColor& color) { setValue(d->shadow_color, color); } setShadowRadius(int radius)162 void setShadowRadius(int radius) { setValue(d->shadow_radius, radius); } setShadowOffset(int offset)163 void setShadowOffset(int offset) { setValue(d->shadow_offset, offset); } 164 165 // Text settings textColor()166 QColor textColor() const { return d->text_color; } textFont()167 QFont textFont() const { return d->text_font; } misspelledColor()168 QColor misspelledColor() const { return d->misspelled_color; } 169 setTextColor(const QColor & color)170 void setTextColor(const QColor& color) { setValue(d->text_color, color); } setTextFont(const QFont & font)171 void setTextFont(const QFont& font) { setValue(d->text_font, font); } setMisspelledColor(const QColor & color)172 void setMisspelledColor(const QColor& color) { setValue(d->misspelled_color, color); } 173 174 // Spacing settings indentFirstLine()175 bool indentFirstLine() const { return d->indent_first_line; } lineSpacing()176 RangedInt lineSpacing() const { return d->line_spacing; } spacingAboveParagraph()177 RangedInt spacingAboveParagraph() const { return d->paragraph_spacing_above; } spacingBelowParagraph()178 RangedInt spacingBelowParagraph() const { return d->paragraph_spacing_below; } tabWidth()179 RangedInt tabWidth() const { return d->tab_width; } 180 setIndentFirstLine(bool indent)181 void setIndentFirstLine(bool indent) { setValue(d->indent_first_line, indent); } setLineSpacing(int spacing)182 void setLineSpacing(int spacing) { setValue(d->line_spacing, spacing); } setSpacingAboveParagraph(int spacing)183 void setSpacingAboveParagraph(int spacing) { setValue(d->paragraph_spacing_above, spacing); } setSpacingBelowParagraph(int spacing)184 void setSpacingBelowParagraph(int spacing) { setValue(d->paragraph_spacing_below, spacing); } setTabWidth(int width)185 void setTabWidth(int width) { setValue(d->tab_width, width); } 186 187 bool operator==(const Theme& theme) const; 188 189 private: 190 void reload(); 191 void write(); 192 193 private: 194 static QString m_path_default; 195 static QString m_path; 196 }; 197 198 Q_DECLARE_METATYPE(Theme) 199 200 #endif 201