vizkit3d
qtbuttonpropertybrowser.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 **
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 **
8 ** This file is part of a Qt Solutions component.
9 **
10 ** You may use this file under the terms of the BSD license as follows:
11 **
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
14 ** met:
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
20 ** distribution.
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 ** the names of its contributors may be used to endorse or promote
23 ** products derived from this software without specific prior written
24 ** permission.
25 **
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37 **
38 ****************************************************************************/
39 
40 
41 #ifndef QTBUTTONPROPERTYBROWSER_H
42 #define QTBUTTONPROPERTYBROWSER_H
43 
44 #include "qtpropertybrowser.h"
45 #include <QtGui/QLabel>
46 #include <QtGui/QGridLayout>
47 #include <QtGui/QToolButton>
48 #include <QtGui/QWidget>
49 
50 #if QT_VERSION >= 0x040400
51 QT_BEGIN_NAMESPACE
52 #endif
53 
55 
57 {
58  Q_OBJECT
59 public:
60 
61  QtButtonPropertyBrowser(QWidget *parent = 0);
63 
64  void setExpanded(QtBrowserItem *item, bool expanded);
65  bool isExpanded(QtBrowserItem *item) const;
66 
67 Q_SIGNALS:
68 
69  void collapsed(QtBrowserItem *item);
70  void expanded(QtBrowserItem *item);
71 
72 protected:
73  virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem);
74  virtual void itemRemoved(QtBrowserItem *item);
75  virtual void itemChanged(QtBrowserItem *item);
76 
77 private:
78 
80  Q_DECLARE_PRIVATE(QtButtonPropertyBrowser)
81  Q_DISABLE_COPY(QtButtonPropertyBrowser)
82  Q_PRIVATE_SLOT(d_func(), void slotUpdate())
83  Q_PRIVATE_SLOT(d_func(), void slotEditorDestroyed())
84  Q_PRIVATE_SLOT(d_func(), void slotToggled(bool))
85 
86 };
87 
89 {
91  Q_DECLARE_PUBLIC(QtButtonPropertyBrowser)
92 public:
93 
94  void init(QWidget *parent);
95 
96  void propertyInserted(QtBrowserItem *index, QtBrowserItem *afterIndex);
97  void propertyRemoved(QtBrowserItem *index);
98  void propertyChanged(QtBrowserItem *index);
99  QWidget *createEditor(QtProperty *property, QWidget *parent) const
100  { return q_ptr->createEditor(property, parent); }
101 
102  void slotEditorDestroyed();
103  void slotUpdate();
104  void slotToggled(bool checked);
105 
106  struct WidgetItem
107  {
108  WidgetItem() : widget(0), label(0), widgetLabel(0),
109  button(0), container(0), layout(0), /*line(0), */parent(0), expanded(false) { }
110  QWidget *widget; // can be null
111  QLabel *label; // main label with property name
112  QLabel *widgetLabel; // label substitute showing the current value if there is no widget
113  QToolButton *button; // expandable button for items with children
114  QWidget *container; // container which is expanded when the button is clicked
115  QGridLayout *layout; // layout in container
117  QList<WidgetItem *> children;
118  bool expanded;
119  };
120 private:
121  void updateLater();
122  void updateItem(WidgetItem *item);
123  void insertRow(QGridLayout *layout, int row) const;
124  void removeRow(QGridLayout *layout, int row) const;
125  int gridRow(WidgetItem *item) const;
126  int gridSpan(WidgetItem *item) const;
127  void setExpanded(WidgetItem *item, bool expanded);
128  QToolButton *createButton(QWidget *panret = 0) const;
129 
130  QMap<QtBrowserItem *, WidgetItem *> m_indexToItem;
131  QMap<WidgetItem *, QtBrowserItem *> m_itemToIndex;
132  QMap<QWidget *, WidgetItem *> m_widgetToItem;
133  QMap<QObject *, WidgetItem *> m_buttonToItem;
134  QGridLayout *m_mainLayout;
135  QList<WidgetItem *> m_children;
136  QList<WidgetItem *> m_recreateQueue;
137 };
138 
139 #if QT_VERSION >= 0x040400
140 QT_END_NAMESPACE
141 #endif
142 
143 #endif
Definition: qtbuttonpropertybrowser.h:106
QLabel * label
Definition: qtbuttonpropertybrowser.h:111
QtAbstractPropertyBrowser provides a base class for implementing property browsers.
Definition: qtpropertybrowser.h:357
QGridLayout * layout
Definition: qtbuttonpropertybrowser.h:115
The QtBrowserItem class represents a property in a property browser instance.
Definition: qtpropertybrowser.h:309
Definition: qtbuttonpropertybrowser.h:88
bool expanded
Definition: qtbuttonpropertybrowser.h:118
virtual void itemRemoved(QtBrowserItem *item)=0
QList< WidgetItem * > children
Definition: qtbuttonpropertybrowser.h:117
QWidget * widget
Definition: qtbuttonpropertybrowser.h:110
QLabel * widgetLabel
Definition: qtbuttonpropertybrowser.h:112
virtual void itemChanged(QtBrowserItem *item)=0
virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem)=0
The QtButtonPropertyBrowser class provides a drop down QToolButton based property browser...
Definition: qtbuttonpropertybrowser.h:56
QWidget * container
Definition: qtbuttonpropertybrowser.h:114
#define QT_QTPROPERTYBROWSER_EXPORT
Definition: qtpropertybrowser.h:66
WidgetItem * parent
Definition: qtbuttonpropertybrowser.h:116
The QtProperty class encapsulates an instance of a property.
Definition: qtpropertybrowser.h:74
QToolButton * button
Definition: qtbuttonpropertybrowser.h:113
virtual QWidget * createEditor(QtProperty *property, QWidget *parent)
Definition: qtpropertybrowser.cpp:1840
QWidget * createEditor(QtProperty *property, QWidget *parent) const
Definition: qtbuttonpropertybrowser.h:99
WidgetItem()
Definition: qtbuttonpropertybrowser.h:108