File indexing completed on 2025-04-27 03:58:23
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2008-12-23 0007 * Description : a widget to change font properties. 0008 * 0009 * SPDX-FileCopyrightText: 2008-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0010 * SPDX-FileCopyrightText: 1996 by Bernd Johannes Wuebben <wuebben at kde dot org> 0011 * SPDX-FileCopyrightText: 1999 by Preston Brown <pbrown at kde dot org> 0012 * SPDX-FileCopyrightText: 1999 by Mario Weilguni <mweilguni at kde dot org> 0013 * 0014 * SPDX-License-Identifier: GPL-2.0-or-later 0015 * 0016 * ============================================================ */ 0017 0018 #ifndef DIGIKAM_DFONT_PROPERTIES_H 0019 #define DIGIKAM_DFONT_PROPERTIES_H 0020 0021 // Qt includes 0022 0023 #include <QWidget> 0024 #include <QColor> 0025 #include <QFont> 0026 #include <QStringList> 0027 0028 // Local includes 0029 0030 #include "digikam_export.h" 0031 0032 0033 namespace Digikam 0034 { 0035 0036 class DIGIKAM_EXPORT DFontProperties : public QWidget 0037 { 0038 Q_OBJECT 0039 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontSelected USER true) 0040 Q_PROPERTY(QColor color READ color WRITE setColor) 0041 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) 0042 Q_PROPERTY(Qt::CheckState sizeIsRelative READ sizeIsRelative WRITE setSizeIsRelative) 0043 Q_PROPERTY(QString sampleText READ sampleText WRITE setSampleText) 0044 0045 public: 0046 0047 /** 0048 * @li @p FamilyList - Identifies the family (leftmost) list. 0049 * @li @p StyleList - Identifies the style (center) list. 0050 * @li @p SizeList - Identifies the size (rightmost) list. 0051 */ 0052 enum FontColumn 0053 { 0054 FamilyList = 0x01, 0055 StyleList = 0x02, 0056 SizeList = 0x04 0057 }; 0058 0059 /** 0060 * @li @p FontDiffFamily - Identifies a requested change in the font family. 0061 * @li @p FontDiffStyle - Identifies a requested change in the font style. 0062 * @li @p FontDiffSize - Identifies a requested change in the font size. 0063 */ 0064 enum FontDiff 0065 { 0066 NoFontDiffFlags = 0, 0067 FontDiffFamily = 1, 0068 FontDiffStyle = 2, 0069 FontDiffSize = 4, 0070 AllFontDiffs = FontDiffFamily | FontDiffStyle | FontDiffSize 0071 }; 0072 Q_DECLARE_FLAGS(FontDiffFlags, FontDiff) 0073 0074 /** 0075 * @li @p FixedFontsOnly only show fixed fonts, excluding proportional fonts 0076 * @li @p DisplayFrame show a visual frame around the chooser 0077 * @li @p ShowDifferences display the font differences interfaces 0078 */ 0079 enum DisplayFlag 0080 { 0081 NoDisplayFlags = 0, 0082 FixedFontsOnly = 1, 0083 DisplayFrame = 2, 0084 ShowDifferences = 4 0085 }; 0086 Q_DECLARE_FLAGS(DisplayFlags, DisplayFlag) 0087 0088 /** 0089 * The selection criteria for the font families shown in the dialog. 0090 * @li @p FixedWidthFont when included only fixed-width fonts are returned. 0091 * The fonts where the width of every character is equal. 0092 * @li @p ScalableFont when included only scalable fonts are returned; 0093 * certain configurations allow bitmap fonts to remain unscaled and 0094 * thus these fonts have limited number of sizes. 0095 * @li @p SmoothScalableFont when included only return smooth scalable fonts. 0096 * this will return only non-bitmap fonts which are scalable to any size requested. 0097 * Setting this option to true will mean the "scalable" flag is irrelevant. 0098 */ 0099 enum FontListCriteria 0100 { 0101 FixedWidthFonts = 0x01, 0102 ScalableFonts = 0x02, 0103 SmoothScalableFonts = 0x04 0104 }; 0105 0106 public: 0107 0108 /** 0109 * Constructs a font picker widget. 0110 * It normally comes up with all font families present on the system; the 0111 * getFont method below does allow some more fine-tuning of the selection of fonts 0112 * that will be displayed in the dialog. 0113 * 0114 * @param parent The parent widget. 0115 * @param flags Defines how the font chooser is displayed. @see DisplayFlags 0116 * @param fontList A list of fonts to display, in XLFD format. 0117 * @param visibleListSize The minimum number of visible entries in the 0118 * fontlists. 0119 * @param sizeIsRelativeState If not zero the widget will show a 0120 * checkbox where the user may choose whether the font size 0121 * is to be interpreted as relative size. 0122 * Initial state of this checkbox will be set according to 0123 * *sizeIsRelativeState, user choice may be retrieved by 0124 * calling sizeIsRelative(). 0125 */ 0126 explicit DFontProperties(QWidget* const parent = nullptr, 0127 const DisplayFlags& flags = DisplayFrame, 0128 const QStringList& fontList = QStringList(), 0129 int visibleListSize = 8, 0130 Qt::CheckState* const sizeIsRelativeState = nullptr); 0131 0132 /** 0133 * Destructs the font chooser. 0134 */ 0135 ~DFontProperties() override; 0136 0137 /** 0138 * Enables or disable a font column in the chooser. 0139 * 0140 * Use this 0141 * function if your application does not need or supports all font 0142 * properties. 0143 * 0144 * @param column Specify the columns. An or'ed combination of 0145 * @p FamilyList, @p StyleList and @p SizeList is possible. 0146 * @param state If @p false the columns are disabled. 0147 */ 0148 void enableColumn(int column, bool state); 0149 0150 /** 0151 * Makes a font column in the chooser visible or invisible. 0152 * 0153 * Use this 0154 * function if your application does not need to show all font 0155 * properties. 0156 * 0157 * @param column Specify the columns. An or'ed combination of 0158 * @p FamilyList, @p StyleList and @p SizeList is possible. 0159 * @param state If @p false the columns are made invisible. 0160 */ 0161 void makeColumnVisible(int column, bool state); 0162 0163 /** 0164 * Sets the currently selected font in the chooser. 0165 * 0166 * @param font The font to select. 0167 * @param onlyFixed Readjust the font list to display only fixed 0168 * width fonts if @p true, or vice-versa. 0169 */ 0170 0171 0172 void setFont(const QFont& font, bool onlyFixed = false); 0173 0174 /** 0175 * @return The bitmask corresponding to the attributes the user 0176 * wishes to change. 0177 */ 0178 FontDiffFlags fontDiffFlags() const; 0179 0180 /** 0181 * @return The currently selected font in the chooser. 0182 */ 0183 QFont font() const; 0184 0185 /** 0186 * Sets the color to use in the preview. 0187 */ 0188 void setColor(const QColor& col); 0189 0190 /** 0191 * @return The color currently used in the preview (default: the text 0192 * color of the active color group) 0193 */ 0194 QColor color() const; 0195 0196 /** 0197 * Sets the background color to use in the preview. 0198 */ 0199 void setBackgroundColor(const QColor& col); 0200 0201 /** 0202 * @return The background color currently used in the preview (default: 0203 * the base color of the active colorgroup) 0204 */ 0205 QColor backgroundColor() const; 0206 0207 /** 0208 * Sets the state of the checkbox indicating whether the font size 0209 * is to be interpreted as relative size. 0210 * NOTE: If parameter sizeIsRelative was not set in the constructor 0211 * of the widget this setting will be ignored. 0212 */ 0213 void setSizeIsRelative(Qt::CheckState relative); 0214 0215 /** 0216 * @return Whether the font size is to be interpreted as relative size 0217 * (default: QButton:Off) 0218 */ 0219 Qt::CheckState sizeIsRelative() const; 0220 0221 /** 0222 * @return The current text in the sample text input area. 0223 */ 0224 QString sampleText() const; 0225 0226 /** 0227 * Sets the sample text. 0228 * 0229 * Normally you should not change this 0230 * text, but it can be better to do this if the default text is 0231 * too large for the edit area when using the default font of your 0232 * application. 0233 * 0234 * @param text The new sample text. The current will be removed. 0235 */ 0236 void setSampleText(const QString& text); 0237 0238 /** 0239 * Shows or hides the sample text box. 0240 * 0241 * @param visible Set it to true to show the box, to false to hide it. 0242 */ 0243 void setSampleBoxVisible(bool visible); 0244 0245 /** 0246 * Creates a list of font strings. 0247 * 0248 * @param list The list is returned here. 0249 * @param fontListCriteria should contain all the restrictions for font selection as OR-ed values 0250 * @see DFontProperties::FontListCriteria for the individual values 0251 */ 0252 static void getFontList(QStringList& list, uint fontListCriteria); 0253 0254 /** 0255 * Reimplemented for internal reasons. 0256 */ 0257 QSize sizeHint(void) const override; 0258 0259 Q_SIGNALS: 0260 0261 /** 0262 * Emitted whenever the selected font changes. 0263 */ 0264 void fontSelected(const QFont& font); 0265 0266 private: 0267 0268 class Private; 0269 Private* const d; 0270 0271 Q_DISABLE_COPY(DFontProperties) 0272 0273 Q_PRIVATE_SLOT(d, void _d_toggled_checkbox()) 0274 Q_PRIVATE_SLOT(d, void _d_family_chosen_slot(const QString&)) 0275 Q_PRIVATE_SLOT(d, void _d_size_chosen_slot(const QString&)) 0276 Q_PRIVATE_SLOT(d, void _d_style_chosen_slot(const QString&)) 0277 Q_PRIVATE_SLOT(d, void _d_displaySample(const QFont& font)) 0278 Q_PRIVATE_SLOT(d, void _d_size_value_slot(double)) 0279 }; 0280 0281 Q_DECLARE_OPERATORS_FOR_FLAGS(DFontProperties::DisplayFlags) 0282 0283 } // namespace Digikam 0284 0285 #endif // DIGIKAM_DFONT_PROPERTIES_H