Changeset View
Changeset View
Standalone View
Standalone View
kcms/fonts/menupreview.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2018 Max Harmathy | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or modify it under | ||||
5 | * the terms of the GNU General Public License as published by the Free Software | ||||
6 | * Foundation; either version 3 of the License, or (at your option) any later | ||||
7 | * version. | ||||
8 | * | ||||
9 | * This program is distributed in the hope that it will be useful, but WITHOUT | ||||
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||||
11 | * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||||
12 | * details. | ||||
13 | * | ||||
14 | * You should have received a copy of the GNU General Public License along with | ||||
15 | * this program; if not, see <http://www.gnu.org/licenses/>. | ||||
16 | */ | ||||
17 | | ||||
18 | #ifndef MENUPREVIEW_H | ||||
19 | #define MENUPREVIEW_H | ||||
20 | | ||||
21 | #include "freetype-renderer.h" | ||||
22 | #include "kxftconfig.h" | ||||
23 | | ||||
24 | #if defined(HAVE_FONTCONFIG) | ||||
25 | | ||||
26 | #include <QButtonGroup> | ||||
27 | #include <QImage> | ||||
28 | #include <QList> | ||||
29 | #include <QPushButton> | ||||
30 | #include <QString> | ||||
31 | | ||||
32 | /** | ||||
33 | * @brief The PreviewParameters is a helper class for communication between qml and | ||||
34 | * QQuickImageProvider. | ||||
35 | */ | ||||
36 | class PreviewParameters | ||||
37 | { | ||||
38 | public: | ||||
39 | QString fontFamily; | ||||
40 | double pointSize; | ||||
41 | KXftConfig* options; | ||||
42 | | ||||
43 | PreviewParameters(const QString& fontFamily, double pointSize, KXftConfig* options); | ||||
44 | PreviewParameters(const PreviewParameters& value); | ||||
45 | virtual ~PreviewParameters(); | ||||
46 | static PreviewParameters fromString(const QString& id); | ||||
47 | QString toFormatetString(); | ||||
48 | }; | ||||
49 | | ||||
50 | class EntryMockup | ||||
51 | { | ||||
52 | QString label; | ||||
53 | QString iconName; | ||||
54 | | ||||
55 | public: | ||||
56 | EntryMockup(const QString& label, const QString& iconName); | ||||
57 | | ||||
58 | const QString& getIconName() const; | ||||
59 | const QString& getLabel() const; | ||||
60 | }; | ||||
61 | | ||||
62 | class MenuMockup | ||||
63 | { | ||||
64 | QList<EntryMockup> entries; | ||||
65 | | ||||
66 | public: | ||||
67 | void add(const EntryMockup& item); | ||||
68 | QString getLabel(int index) const; | ||||
69 | QString getIconName(int index) const; | ||||
70 | static MenuMockup basicExample(); | ||||
71 | int length() const; | ||||
72 | }; | ||||
73 | | ||||
74 | class MenuPreviewArea; | ||||
75 | | ||||
76 | class MenuPreviewRenderer | ||||
77 | { | ||||
78 | private: | ||||
79 | FreeTypeFontPreviewRenderer renderer; | ||||
80 | const int iconSize; | ||||
81 | const int padding; | ||||
82 | const QColor background; | ||||
83 | | ||||
84 | public: | ||||
85 | MenuPreviewRenderer(const QColor& background, int iconSize = 16, int padding = 2); | ||||
86 | QImage getImage(const PreviewParameters& parameters); | ||||
87 | }; | ||||
88 | | ||||
89 | class MenuPreviewButton : public QPushButton | ||||
90 | { | ||||
91 | Q_OBJECT | ||||
92 | private: | ||||
93 | PreviewParameters parameters; | ||||
94 | void _update(); | ||||
95 | | ||||
96 | public: | ||||
97 | MenuPreviewButton(const PreviewParameters& parameters, MenuPreviewArea* parent); | ||||
98 | KXftConfig::AntiAliasing::State getAntialiasing(); | ||||
99 | KXftConfig::Hint::Style getHint(); | ||||
100 | KXftConfig::SubPixel::Type getSubPixel(); | ||||
101 | public slots: | ||||
102 | void setFont(const QString& fontFamily, double pointSize); | ||||
103 | }; | ||||
104 | | ||||
105 | class MenuPreviewArea : public QWidget | ||||
106 | { | ||||
107 | Q_OBJECT | ||||
108 | private: | ||||
109 | friend class MenuPreviewButton; | ||||
110 | | ||||
111 | QString fontFamily; | ||||
112 | double pointSize; | ||||
113 | | ||||
114 | MenuPreviewRenderer renderer; | ||||
115 | QButtonGroup group; | ||||
116 | | ||||
117 | public: | ||||
118 | MenuPreviewArea(const QString& fontFamily, double pointSize, QWidget* parent = nullptr); | ||||
119 | virtual ~MenuPreviewArea(); | ||||
120 | | ||||
121 | public slots: | ||||
122 | void setFont(const QFont& font); | ||||
123 | void setFontFamily(const QFont& font); | ||||
124 | void setFontFamily(const QString& fontFamily); | ||||
125 | void setPointSize(double pointSize); | ||||
126 | void onSelectionChanged(QAbstractButton* button); | ||||
127 | void reset(); | ||||
128 | | ||||
129 | signals: | ||||
130 | void fontChanged(const QString& fontFamily, double pointSize); | ||||
131 | void selectionChanged(KXftConfig::AntiAliasing::State antiAliasing, | ||||
132 | KXftConfig::Hint::Style hint, | ||||
133 | KXftConfig::SubPixel::Type subPixel); | ||||
134 | }; | ||||
135 | | ||||
136 | #endif // defined(HAVE_FONTCONFIG) | ||||
137 | | ||||
138 | #endif // MENUPREVIEW_H |