File indexing completed on 2024-05-12 16:39:51
0001 /* This file is part of the KDE project 0002 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr> 0003 Copyright (C) 2007-2009 Jarosław Staniek <staniek@kde.org> 0004 0005 This library is free software; you can redistribute it and/or 0006 modify it under the terms of the GNU Library General Public 0007 License as published by the Free Software Foundation; either 0008 version 2 of the License, or (at your option) any later version. 0009 0010 This library is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 Library General Public License for more details. 0014 0015 You should have received a copy of the GNU Library General Public License 0016 along with this library; see the file COPYING.LIB. If not, write to 0017 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef FORMEDITORUTILS_H 0022 #define FORMEDITORUTILS_H 0023 0024 #include "kformdesigner_export.h" 0025 0026 #include <QHash> 0027 #include <QTabBar> 0028 #include <QTabWidget> 0029 #include <QActionGroup> 0030 0031 typedef QTabWidget TabWidgetBase; 0032 //! @todo uncomment 0033 //!//#define USE_KTabWidget 0034 0035 class QMimeData; 0036 class QDomDocument; 0037 class QPainter; 0038 0039 namespace KFormDesigner 0040 { 0041 0042 class Form; 0043 0044 /*! \return parent object of \a o that inherits \a className or NULL if no such parent 0045 If the parent is found, \a prevPrev is set to a child of child of the parent, 0046 what for TabWidget means the page widget. */ 0047 template<class type> 0048 type* findParent(QObject* o, const char* className, QObject* &prevPrev) 0049 { 0050 if (!o || !className || className[0] == '\0') 0051 return 0; 0052 QObject *prev = o; 0053 while (((o = o->parent())) && !o->inherits(className)) { 0054 prevPrev = prev; 0055 prev = o; 0056 } 0057 return static_cast<type*>(o); 0058 } 0059 0060 //! A tab widget providing information about height of the tab bar. 0061 class KFORMDESIGNER_EXPORT TabWidget : public TabWidgetBase 0062 { 0063 Q_OBJECT 0064 public: 0065 explicit TabWidget(QWidget *parent) 0066 : TabWidgetBase(parent) {} 0067 virtual ~TabWidget() {} 0068 int tabBarHeight() const { 0069 return tabBar()->height(); 0070 } 0071 }; 0072 0073 //! @short A common interface for HorizontalWidgetList and VerticalWidgetList 0074 class CustomSortableWidgetList : public QWidgetList 0075 { 0076 public: 0077 CustomSortableWidgetList() : QWidgetList() {} 0078 //! Copy constructor needed required by foreach() 0079 CustomSortableWidgetList(const CustomSortableWidgetList& list) : QWidgetList(list) {} 0080 virtual ~CustomSortableWidgetList() {} 0081 virtual void sort() {} 0082 }; 0083 0084 //! @short A helper for sorting widgets horizontally 0085 class HorizontalWidgetList : public CustomSortableWidgetList 0086 { 0087 public: 0088 explicit HorizontalWidgetList(QWidget *topLevelWidget); 0089 //! Copy constructor needed required by foreach() 0090 HorizontalWidgetList(const HorizontalWidgetList& list); 0091 virtual ~HorizontalWidgetList(); 0092 virtual void sort() override; 0093 protected: 0094 class LessThan; 0095 LessThan *m_lessThan; 0096 }; 0097 0098 //! @short A helper for sorting widgets vertically 0099 class VerticalWidgetList : public CustomSortableWidgetList 0100 { 0101 public: 0102 explicit VerticalWidgetList(QWidget *topLevelWidget); 0103 //! Copy constructor needed required by foreach() 0104 VerticalWidgetList(const VerticalWidgetList& list); 0105 virtual ~VerticalWidgetList(); 0106 virtual void sort() override; 0107 protected: 0108 class LessThan; 0109 LessThan *m_lessThan; 0110 }; 0111 0112 /*! This function is used to remove all the child widgets from a list, and 0113 keep only the "toplevel" ones. */ 0114 KFORMDESIGNER_EXPORT void removeChildrenFromList(QWidgetList &list); 0115 0116 KFORMDESIGNER_EXPORT void setRecursiveCursor(QWidget *w, Form *form); 0117 0118 //! \return the size of \a w children 0119 /*! This can be used eg to get widget's sizeHint. */ 0120 KFORMDESIGNER_EXPORT QSize getSizeFromChildren(QWidget *widget, const char *inheritClass = "QWidget"); 0121 0122 //! @return mimetype for the forms XML format 0123 inline QString mimeType() { return "application/x-kexi-form"; } 0124 0125 //! @return deep copy of the mime data @a data (for all formats) 0126 KFORMDESIGNER_EXPORT QMimeData *deepCopyOfMimeData(const QMimeData *data); 0127 0128 //! Copies @a xml data to the clipboard both in the plain text format and forms XML format 0129 KFORMDESIGNER_EXPORT void copyToClipboard(const QString& xml); 0130 0131 //! Recursively saves widget list @a list and form @a form to @a doc XML document 0132 /*! @a containers hash is filled with containers found within the widget list, 0133 and @a parents is filled with the parent widgets found within the widget list. 0134 USed in DeleteWidgetCommand ctor. */ 0135 KFORMDESIGNER_EXPORT void widgetsToXML(QDomDocument& doc, 0136 QHash<QByteArray, QByteArray>& containers, 0137 QHash<QByteArray, QByteArray>& parents, 0138 const Form& form, const QWidgetList &list); 0139 0140 //! QActionGroup extended by action() method. 0141 class KFORMDESIGNER_EXPORT ActionGroup : public QActionGroup 0142 { 0143 Q_OBJECT 0144 public: 0145 explicit ActionGroup( QObject * parent ); 0146 ~ActionGroup(); 0147 //! Reimplemented. 0148 void addAction(QAction* action); 0149 QAction *action(const QString& name) const; 0150 private: 0151 Q_DISABLE_COPY(ActionGroup) 0152 class Private; 0153 Private * const d; 0154 }; 0155 0156 //! @return @a value aligned to the nearest multiple of gridSize 0157 KFORMDESIGNER_EXPORT int alignValueToGrid(int value, int gridSize); 0158 0159 //! Paint semitransparent widget frame. 0160 //! For example it is useful for design mode to show geometry of label that has no visible frames. 0161 KFORMDESIGNER_EXPORT void paintWidgetFrame(QPainter& p, const QRect& geometry); 0162 0163 } 0164 0165 #endif