Mercurial > bellaciao
annotate layout_view.h @ 10:877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 26 Aug 2011 15:58:46 +0200 |
parents | 0d7875c26974 |
children |
rev | line source |
---|---|
8 | 1 /* |
2 Bellaciao: a Salut à Toi frontend | |
3 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) | |
4 | |
5 This program is free software: you can redistribute it and/or modify | |
6 it under the terms of the GNU Affero General Public License as published by | |
7 the Free Software Foundation, either version 3 of the License, or | |
8 (at your option) any later version. | |
9 | |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU Affero General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Affero General Public License | |
16 along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 */ | |
18 | |
19 #ifndef LAYOUT_VIEW_H | |
20 #define LAYOUT_VIEW_H | |
21 | |
22 #include <QWidget> | |
23 #include <QDragEnterEvent> | |
24 #include "layout_widget.h" | |
25 | |
26 #define LAYOUT_WIDGET_MIME "application/x-bellaciao-widget" | |
27 | |
10
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
28 typedef enum |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
29 { |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
30 HORIZONTAL, VERTICAL |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
31 } LayoutDirection; |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
32 |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
33 class WidgetView |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
34 { |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
35 public: |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
36 WidgetView(const QString& name); |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
37 ~WidgetView(); |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
38 }; |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
39 |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
40 class WidgetViewItem : public QLabel, public WidgetView |
9
0d7875c26974
layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
41 { |
0d7875c26974
layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
42 Q_OBJECT |
0d7875c26974
layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
43 public: |
10
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
44 WidgetViewItem(const QString& name); |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
45 }; |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
46 |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
47 class WidgetViewBox : public QScrollArea, public WidgetView |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
48 { |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
49 Q_OBJECT |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
50 public: |
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
51 WidgetViewBox(const QString& name); |
9
0d7875c26974
layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
52 }; |
8 | 53 |
54 class LayoutView : public QWidget | |
55 { | |
56 Q_OBJECT | |
57 | |
58 public: | |
10
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
59 LayoutView(QWidget* parent = 0, LayoutDirection direction = VERTICAL); |
8 | 60 ~LayoutView(); |
61 void setLayoutWidgets(const QHash<QString, LayoutWidget*>& layout_widgets); | |
62 void dragEnterEvent (QDragEnterEvent* event ); | |
9
0d7875c26974
layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
63 void dragLeaveEvent (QDragLeaveEvent* event ); |
8 | 64 void dragMoveEvent (QDragMoveEvent* event ); |
65 void dropEvent (QDropEvent * event); | |
66 protected: | |
67 void addWidget(const QString& name); | |
9
0d7875c26974
layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
68 void paintEvent(QPaintEvent* event); |
8 | 69 private: |
70 QHash<QString, LayoutWidget*> m_layout_widgets; | |
71 QList<LayoutWidget> m_widgets_list; | |
10
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
72 QBoxLayout* m_layout; |
9
0d7875c26974
layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
73 QRect m_loc_hint; |
0d7875c26974
layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents:
8
diff
changeset
|
74 int m_insert_pos; //position in the layout when a widget must be inserted |
10
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
75 LayoutDirection m_direction; |
8 | 76 }; |
10
877a005c2b42
Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents:
9
diff
changeset
|
77 |
8 | 78 #endif |