BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
widgetboxtreewidget.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the Qt Designer of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef BORNAGAIN_GUI_COREGUI_VIEWS_WIDGETBOX_WIDGETBOXTREEWIDGET_H
43 #define BORNAGAIN_GUI_COREGUI_VIEWS_WIDGETBOX_WIDGETBOXTREEWIDGET_H
44 
46 
47 #include <QHash>
48 #include <QIcon>
49 #include <QList>
50 #include <QTreeWidget>
51 #include <QXmlStreamReader> // Cannot forward declare them on Mac
52 #include <QXmlStreamWriter>
53 
54 QT_BEGIN_NAMESPACE
55 
56 class QDesignerFormEditorInterface;
57 class QDesignerDnDItemInterface;
58 
59 class QTimer;
60 
62 
63 namespace qdesigner_internal {
64 
65 class WidgetBoxCategoryListView;
66 
67 //! WidgetBoxTreeWidget: A tree of categories
68 class WidgetBoxTreeWidget : public QTreeWidget {
69  Q_OBJECT
70 
71 public:
72  typedef QDesignerWidgetBoxInterface::Widget Widget;
73  typedef QDesignerWidgetBoxInterface::Category Category;
74  typedef QDesignerWidgetBoxInterface::CategoryList CategoryList;
75 
76  explicit WidgetBoxTreeWidget(SampleDesignerInterface* core, QWidget* parent = 0);
77  virtual ~WidgetBoxTreeWidget();
78 
79  int categoryCount() const;
80  Category category(int cat_idx) const;
81  void addCategory(const Category& cat);
82  void removeCategory(int cat_idx);
83 
84  int widgetCount(int cat_idx) const;
85  Widget widget(int cat_idx, int wgt_idx) const;
86  void addWidget(int cat_idx, const Widget& wgt);
87  void removeWidget(int cat_idx, int wgt_idx);
88 
89  void dropWidgets(const QList<QDesignerDnDItemInterface*>& item_list);
90 
91  void setFileName(const QString& file_name);
92  QString fileName() const;
93  bool load(QDesignerWidgetBox::LoadMode loadMode);
94  bool loadContents(const QString& contents);
95  bool save();
96  QIcon iconForWidget(QString iconName) const;
97 
98 signals:
99  void pressed(const QString name, const QString dom_xml, const QPoint& global_mouse_pos);
100 
101 public slots:
102  void filter(const QString&);
103 
104 protected:
105  virtual void contextMenuEvent(QContextMenuEvent* e);
106  virtual void resizeEvent(QResizeEvent* e);
107 
108 private slots:
109  void slotSave();
112 
113  void handleMousePress(QTreeWidgetItem* item);
114  void deleteScratchpad();
115  void slotListMode();
116  void slotIconMode();
117 
118 private:
119  WidgetBoxCategoryListView* addCategoryView(QTreeWidgetItem* parent, bool iconMode);
121  void adjustSubListSize(QTreeWidgetItem* cat_item);
122 
123  static bool readCategories(const QString& fileName, const QString& xml, CategoryList* cats,
124  QString* errorMessage);
125  static bool readWidget(Widget* w, const QString& xml, QXmlStreamReader& r);
126 
128  void writeCategories(QXmlStreamWriter& writer, const CategoryList& cat_list) const;
129 
130  int indexOfCategory(const QString& name) const;
131  int indexOfScratchpad() const;
132  int ensureScratchpad();
133  void addCustomCategories(bool replace);
134 
135  void saveExpandedState() const;
136  void restoreExpandedState();
137  void updateViewMode();
138 
140  QString m_file_name;
141  typedef QHash<QString, QIcon> IconCache;
145 };
146 
147 } // namespace qdesigner_internal
148 
149 QT_END_NAMESPACE
150 
151 #endif // BORNAGAIN_GUI_COREGUI_VIEWS_WIDGETBOX_WIDGETBOXTREEWIDGET_H
sample designer interface
WidgetBoxTreeWidget: A tree of categories.
void adjustSubListSize(QTreeWidgetItem *cat_item)
WidgetBoxTreeWidget(SampleDesignerInterface *core, QWidget *parent=0)
Widget widget(int cat_idx, int wgt_idx) const
static bool readWidget(Widget *w, const QString &xml, QXmlStreamReader &r)
void setFileName(const QString &file_name)
bool loadContents(const QString &contents)
WidgetBoxCategoryListView * addCategoryView(QTreeWidgetItem *parent, bool iconMode)
void pressed(const QString name, const QString dom_xml, const QPoint &global_mouse_pos)
void writeCategories(QXmlStreamWriter &writer, const CategoryList &cat_list) const
WidgetBoxCategoryListView * categoryViewAt(int idx) const
QIcon iconForWidget(QString iconName) const
virtual void resizeEvent(QResizeEvent *e)
static bool readCategories(const QString &fileName, const QString &xml, CategoryList *cats, QString *errorMessage)
void addWidget(int cat_idx, const Widget &wgt)
QDesignerWidgetBoxInterface::CategoryList CategoryList
QDesignerWidgetBoxInterface::Widget Widget
virtual void contextMenuEvent(QContextMenuEvent *e)
bool load(QDesignerWidgetBox::LoadMode loadMode)
QDesignerWidgetBoxInterface::Category Category
void handleMousePress(QTreeWidgetItem *item)
int indexOfCategory(const QString &name) const
void removeWidget(int cat_idx, int wgt_idx)
void dropWidgets(const QList< QDesignerDnDItemInterface * > &item_list)
QString const & name(EShape k)
Definition: particles.cpp:21