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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 /*
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 Bellaciao: a Salut à Toi frontend
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3 Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org)
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6 it under the terms of the GNU Affero General Public License as published by
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7 the Free Software Foundation, either version 3 of the License, or
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 (at your option) any later version.
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 GNU Affero General Public License for more details.
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 You should have received a copy of the GNU Affero General Public License
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17 */
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19 #ifndef LAYOUT_VIEW_H
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20 #define LAYOUT_VIEW_H
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 #include <QWidget>
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 #include <QDragEnterEvent>
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 #include "layout_widget.h"
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 #define LAYOUT_WIDGET_MIME "application/x-bellaciao-widget"
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 class LayoutView : public QWidget
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 {
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 Q_OBJECT
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 ~LayoutView();
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 void setLayoutWidgets(const QHash<QString, LayoutWidget*>& layout_widgets);
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 void dragMoveEvent (QDragMoveEvent* event );
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 void dropEvent (QDropEvent * event);
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 protected:
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 private:
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 QHash<QString, LayoutWidget*> m_layout_widgets;
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
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
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 #endif