| 1 |
/* |
| 2 |
* SPDX-FileCopyrightText: 2021~2021 CSSlayer <[email protected]> |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: BSD-3-Clause |
| 5 |
* |
| 6 |
*/ |
| 7 |
#ifndef _PLATFORMINPUTCONTEXT_FCITXTHEME_H_ |
| 8 |
#define _PLATFORMINPUTCONTEXT_FCITXTHEME_H_ |
| 9 |
|
| 10 |
#include <QColor> |
| 11 |
#include <QFileSystemWatcher> |
| 12 |
#include <QFont> |
| 13 |
#include <QFontMetrics> |
| 14 |
#include <QMargins> |
| 15 |
#include <QObject> |
| 16 |
#include <QPainter> |
| 17 |
#include <QPixmap> |
| 18 |
#include <QSettings> |
| 19 |
|
| 20 |
namespace fcitx { |
| 21 |
|
| 22 |
class BackgroundImage { |
| 23 |
friend class FcitxTheme; |
| 24 |
|
| 25 |
public: |
| 26 |
void load(const QString &name, QSettings &settings); |
| 27 |
void loadFromValue(const QColor &border, const QColor &background, |
| 28 |
QMargins margin, int borderWidth); |
| 29 |
|
| 30 |
private: |
| 31 |
void fillBackground(const QColor &border, const QColor &background, |
| 32 |
int borderWidth); |
| 33 |
|
| 34 |
QPixmap image_, overlay_; |
| 35 |
QMargins margin_, overlayClipMargin_; |
| 36 |
bool hideOverlayIfOversize_ = false; |
| 37 |
QString gravity_; |
| 38 |
int overlayOffsetX_ = 0; |
| 39 |
int overlayOffsetY_ = 0; |
| 40 |
}; |
| 41 |
|
| 42 |
class ActionImage { |
| 43 |
friend class FcitxTheme; |
| 44 |
|
| 45 |
public: |
| 46 |
void load(const QString &name, QSettings &settings); |
| 47 |
void reset(); |
| 48 |
bool valid() const { return valid_; } |
| 49 |
int width() const { return image_.width(); } |
| 50 |
int height() const { return image_.height(); } |
| 51 |
QSize size() const { return image_.size(); } |
| 52 |
const QMargins &margin() const { return margin_; } |
| 53 |
|
| 54 |
private: |
| 55 |
bool valid_ = false; |
| 56 |
QPixmap image_; |
| 57 |
QMargins margin_; |
| 58 |
}; |
| 59 |
|
| 60 |
class FcitxTheme : public QObject { |
| 61 |
Q_OBJECT |
| 62 |
public: |
| 63 |
FcitxTheme(QObject *parent = nullptr); |
| 64 |
~FcitxTheme(); |
| 65 |
|
| 66 |
void paint(QPainter *painter, const BackgroundImage &image, QRect region); |
| 67 |
void paint(QPainter *painter, const ActionImage &image, QPoint position, |
| 68 |
float alpha); |
| 69 |
|
| 70 |
const auto &background() const { return background_; } |
| 71 |
const auto &highlight() const { return highlight_; } |
| 72 |
const auto &prev() const { return prev_; } |
| 73 |
const auto &next() const { return next_; } |
| 74 |
const auto &font() const { return font_; } |
| 75 |
const auto &fontMetrics() const { return fontMetrics_; } |
| 76 |
const auto &highlightBackgroundColor() const { |
| 77 |
return highlightBackgroundColor_; |
| 78 |
} |
| 79 |
const auto &highlightColor() const { return highlightColor_; } |
| 80 |
const auto &buttonAlignment() const { return buttonAlignment_; } |
| 81 |
auto contentMargin() const { return contentMargin_; } |
| 82 |
auto textMargin() const { return textMargin_; } |
| 83 |
auto highlightClickMargin() const { return highlightClickMargin_; } |
| 84 |
QMargins highlightMargin() const; |
| 85 |
auto shadowMargin() const { return shadowMargin_; } |
| 86 |
auto normalColor() const { return normalColor_; } |
| 87 |
auto highlightCandidateColor() const { return highlightCandidateColor_; } |
| 88 |
auto vertical() const { return vertical_; } |
| 89 |
auto wheelForPaging() const { return wheelForPaging_; } |
| 90 |
|
| 91 |
private Q_SLOTS: |
| 92 |
void configChanged(); |
| 93 |
void themeChanged(); |
| 94 |
|
| 95 |
private: |
| 96 |
QString configPath_; |
| 97 |
QString themeConfigPath_; |
| 98 |
QFileSystemWatcher *watcher_; |
| 99 |
|
| 100 |
QFont font_; |
| 101 |
QFontMetrics fontMetrics_{font_}; |
| 102 |
bool vertical_ = false; |
| 103 |
bool wheelForPaging_ = true; |
| 104 |
QString theme_ = "default"; |
| 105 |
BackgroundImage background_; |
| 106 |
BackgroundImage highlight_; |
| 107 |
ActionImage prev_; |
| 108 |
ActionImage next_; |
| 109 |
|
| 110 |
QColor normalColor_{Qt::black}; |
| 111 |
QColor highlightCandidateColor_{Qt::white}; |
| 112 |
bool fullWidthHighlight_ = true; |
| 113 |
QColor highlightColor_{Qt::white}; |
| 114 |
QColor highlightBackgroundColor_{0xa5, 0xa5, 0xa5}; |
| 115 |
QString buttonAlignment_; |
| 116 |
QMargins highlightClickMargin_; |
| 117 |
QMargins contentMargin_; |
| 118 |
QMargins textMargin_; |
| 119 |
QMargins shadowMargin_; |
| 120 |
}; |
| 121 |
|
| 122 |
} // namespace fcitx |
| 123 |
|
| 124 |
#endif // _PLATFORMINPUTCONTEXT_FCITXTHEME_H_ |