File indexing completed on 2024-05-12 16:39:51
0001 /* This file is part of the KDE project 0002 Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at> 0003 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr> 0004 Copyright (C) 2004-2017 Jarosław Staniek <staniek@kde.org> 0005 0006 This library is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU Library General Public 0008 License as published by the Free Software Foundation; either 0009 version 2 of the License, or (at your option) any later version. 0010 0011 This library is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 Library General Public License for more details. 0015 0016 You should have received a copy of the GNU Library General Public License 0017 along with this library; see the file COPYING.LIB. If not, write to 0018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 */ 0021 0022 #ifndef KFORMDESIGNERWIDGETINFO_H 0023 #define KFORMDESIGNERWIDGETINFO_H 0024 0025 #include "kformdesigner_export.h" 0026 0027 #include <KDbTristate> 0028 0029 #include <QHash> 0030 0031 namespace KFormDesigner 0032 { 0033 0034 class WidgetFactory; 0035 class WidgetLibrary; 0036 0037 //! A class providing properties of a single widget class offered by a factory 0038 class KFORMDESIGNER_EXPORT WidgetInfo 0039 { 0040 public: 0041 explicit WidgetInfo(WidgetFactory *f); 0042 0043 virtual ~WidgetInfo(); 0044 0045 //! \return the name of the icon associated with the widget 0046 QString iconName() const; 0047 0048 void setIconName(const QString &iconName); 0049 0050 //! @return the class name of a widget e.g. "LineEdit" 0051 QByteArray className() const; 0052 0053 void setClassName(const QByteArray& className); 0054 0055 QByteArray inheritedClassName() const; 0056 0057 void setInheritedClassName(const QByteArray& inheritedClassName); 0058 0059 /** 0060 * @return Untranslated name prefix used to generate unique names for widget instances 0061 * 0062 * Widget names appear in the property editor or in scripts and can be references there. 0063 * Names and prefixes must be valid identifiers, as defined by KDb::isIdentifier(). 0064 * 0065 * @see translatedNamePrefix() 0066 */ 0067 QString namePrefix() const; 0068 0069 /** 0070 * Sets untranslated name prefix used to generate unique names for widget instances 0071 * 0072 * @a prefix must be a valid identifier, as defined by KDb::isIdentifier(). If it is not then 0073 * real name prefix will be reset to "widget". 0074 * Parameters of setNamePrefix() should be enclosed with I18N_NOOP2() to enable translation 0075 * text extraction without actual translation of the argument. @a context parameter is unused; 0076 * it's provided only to make I18N_NOOP2() work. 0077 * 0078 * Example use for a label class: 0079 * @code 0080 * setNamePrefix( 0081 * I18N_NOOP2("A prefix for identifiers of label widgets. Based on that, identifiers such as " 0082 * "label1, label2 are generated. " 0083 * "This string can be used to refer the widget object as variables in programming " 0084 * "languages or macros so it must _not_ contain white spaces and non latin1 characters, " 0085 * "should start with lower case letter and if there are subsequent words, these should " 0086 * "start with upper case letter. Example: smallCamelCase. " 0087 * "Moreover, try to make this prefix as short as possible.", 0088 * "label")); 0089 * @endcode 0090 * 0091 * If translation of @a prefix for given locale is not a valid identifier, as defined by 0092 * KDb::isIdentifier() then a warning is issued to the error channel and untranslated prefix is 0093 * used, e.g. "label". 0094 */ 0095 void setNamePrefix(const char *context, const char *prefix); 0096 0097 /** 0098 * @return Translated name prefix used to generate unique names for widget instances 0099 * 0100 * This string is created using i18n(namePrefix()). See setNamePrefix() for exceptional cases 0101 * of invalid translations. 0102 */ 0103 QString translatedNamePrefix() const; 0104 0105 //! \return the real name e.g. 'Line Edit', showed eg in ObjectTreeView 0106 QString name() const; 0107 0108 void setName(const QString &n); 0109 0110 QString description() const; 0111 0112 void setDescription(const QString &desc); 0113 0114 QString includeFileName() const; 0115 0116 /*! Sets the C++ include file corresponding to this class, 0117 that uic will need to add when creating the file. You don't have to set this for Qt std widgets.*/ 0118 void setIncludeFileName(const QString &name); 0119 0120 QList<QByteArray> alternateClassNames() const; 0121 0122 QByteArray savingName() const; 0123 0124 WidgetFactory *factory() const; 0125 0126 /*! Sets alternate names for this class. 0127 If this name is found when loading a .ui file, the className() will be used instead. 0128 It allows to support both KDE and Qt versions of widget, without duplicating code. 0129 As a rule, className() should always return a class name which is inherited from 0130 alternate class. For exampleQPushButton class has alternate KexiPushButton class. 0131 0132 \a override parameter overrides class name of a widget, 0133 even if it was implemented in other factory. 0134 By default it's set to false, what means that no other class is overridden 0135 by this widget class if there is already a class implementing it 0136 (no matter in which factory). 0137 By forced overriding existing class with other - custom, user 0138 will be able to see more or less properties and experience different behaviour. 0139 For example, in Kexi application, KexiDBPushButton class contains additional 0140 properties. 0141 */ 0142 void addAlternateClassName(const QByteArray& alternateName, bool override = false); 0143 0144 /*! \return true if a class \a alternateName is defined as alternate name with 0145 'override' flag set to true, using addAlternateClassName(). 0146 If this flag is set to false (the default) or there's no such alternate class 0147 name defined. */ 0148 bool isOverriddenClassName(const QByteArray& alternateName) const; 0149 0150 /*! Sets the name that will be written in the .ui file when saving. 0151 This name must be one of alternate names (or loading will be impossible). 0152 0153 On form data saving to XML .ui format, saveName is used instead, 0154 so .ui format is not broken and still usable with other software as Qt Designer. 0155 Custom properties are saved as well with 'stdset' attribute set to 0. */ 0156 void setSavingName(const QByteArray &saveName); 0157 0158 /*! Sets autoSync flag for property \a propertyName. 0159 This allows to override autoSync flag for certain widget's property, because 0160 e.g. KPropertyEditorView can have autoSync flag set to false or true, but 0161 not all properties have to comply with that. 0162 \a flag equal to cancelled value means there is no overriding (the default). */ 0163 void setAutoSyncForProperty(const QByteArray& propertyName, tristate flag); 0164 0165 /*! \return autoSync override value (true or false) for \a propertyName. 0166 If cancelled value is returned, there is no overriding (the default). */ 0167 tristate autoSyncForProperty(const QByteArray& propertyName) const; 0168 0169 QByteArray parentFactoryName() const; 0170 0171 void setParentFactoryName(const QByteArray& factoryName); 0172 0173 WidgetInfo* inheritedClass() const; 0174 0175 /*! Sets custom type \a type for property \a propertyName. 0176 This allows to override default type, especially when custom property 0177 and custom property editor item has to be used. */ 0178 void setCustomTypeForProperty(const QByteArray& propertyName, int type); 0179 0180 /*! \return custom type for property \a propertyName. If no specific custom type has been assigned, 0181 KProperty::Auto is returned. 0182 @see setCustomTypeForProperty() */ 0183 int customTypeForProperty(const QByteArray& propertyName) const; 0184 0185 /*! @return list of the properties that should automatically be saved 0186 for a widget of @a classname class. 0187 Examples are: custom properties "text" for label or button, "contents" for combobox... 0188 If there is inherited class (see @ref inheritedClass()), autosave properties 0189 from that class are prepended to the list. */ 0190 QList<QByteArray> autoSaveProperties() const; 0191 0192 /*! Sets list of the properties that should automatically be saved for a widget of @a classname class. */ 0193 void setAutoSaveProperties(const QList<QByteArray>& properties); 0194 0195 /*! @return internal property @a property. 0196 Internal properties are not stored within objects, but can be just provided 0197 to describe class' details. */ 0198 QVariant internalProperty(const QByteArray& property) const; 0199 0200 /*! Assigns @a value for internal property @a property. 0201 Internal properties are not stored within objects, but can be provided 0202 to describe class' details. */ 0203 void setInternalProperty(const QByteArray& property, const QVariant& value); 0204 0205 /** 0206 * @brief Returns @c alignment flags supports by the widget 0207 * 0208 * By default returns all possible flags minus Qt::AlignAbsolute. 0209 * @see setSupportedAlignmentFlags 0210 */ 0211 Qt::Alignment supportedAlignmentFlags() const; 0212 0213 /** 0214 * @brief Sets alignment flags supported by the widget 0215 * 0216 * Used for example by an image box that does not support justified, absolute and baseline 0217 * alignment. 0218 * @see supportedAlignmentFlags 0219 */ 0220 void setSupportedAlignmentFlags(Qt::Alignment flags); 0221 0222 protected: 0223 void setInheritedClass(WidgetInfo *inheritedClass); 0224 0225 private: 0226 class Private; 0227 Private * const d; 0228 0229 friend class WidgetLibrary; 0230 }; 0231 0232 } // namespace KFormDesigner 0233 0234 #endif