annotate layout_view.cpp @ 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 98485ebbdb86
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 #include "layout_view.h"
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19 #include <QDebug>
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20
9
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
21 WidgetView::WidgetView(const QString& name)
10
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
22 {
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
23 qDebug() << "Contructeur WidgetView";
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
24 }
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
25
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
26 WidgetView::~WidgetView()
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
27 {
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
28 qDebug() << "Destructeur WidgetView";
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
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
31 WidgetViewItem::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
32 : QLabel(name), WidgetView(name)
9
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
33 {
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
34 }
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
35
10
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
36 WidgetViewBox::WidgetViewBox(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(name)
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 setWidget(new LayoutView(0, HORIZONTAL));
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
40 }
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
41
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
42 LayoutView::LayoutView(QWidget* parent, LayoutDirection direction)
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
43 : m_direction(direction)
8
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 {
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 setAcceptDrops(true);
10
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
46 if (m_direction == VERTICAL)
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
47 m_layout = new QVBoxLayout;
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
48 else
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
49 m_layout = new QHBoxLayout;
8
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 setLayout(m_layout);
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 m_layout->addStretch();
10
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
52 setStyleSheet("WidgetViewItem {border: 1px solid black; \
8
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 border-radius: 5px; \
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 text-align: center; \
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 background-color: white; \
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 min-height: 20px; \
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 max-height: 20px; \
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 margin: 2px; \
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 }");
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 }
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 LayoutView::~LayoutView()
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 {
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 }
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 void LayoutView::setLayoutWidgets(const QHash<QString, LayoutWidget*>& layout_widgets)
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 {
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 m_layout_widgets = layout_widgets;
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 }
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71 void LayoutView::dragEnterEvent (QDragEnterEvent* event )
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 {
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 if (event->mimeData()->hasFormat(LAYOUT_WIDGET_MIME))
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 event->acceptProposedAction();
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 }
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76
9
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
77 void LayoutView::dragLeaveEvent (QDragLeaveEvent* event )
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
78 {
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
79 m_loc_hint.setCoords(1,1,0,0); //We make the QRect invalid to hide it
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
80 update();
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
81 }
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
82
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
83
8
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 void LayoutView::dragMoveEvent (QDragMoveEvent* event )
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 {
10
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
86 int ref_pos = m_direction == VERTICAL ? event->pos().y() : event->pos().x();
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
87 int hint_start = 0;
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
88 int pos_start, pos_end;
9
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
89 QList<QWidget*> _children = findChildren<QWidget*>("");
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
90
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
91 QWidget* wid = 0;
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
92
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
93 for (m_insert_pos=0; m_insert_pos<layout()->count()-1; m_insert_pos++) {
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
94 wid = layout()->itemAt(m_insert_pos)->widget();
10
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
95
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
96 if (m_direction == VERTICAL) {
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
97 pos_start = wid->geometry().top();
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
98 pos_end = wid->geometry().bottom();
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
99 }
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
100 else {
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
101 pos_start = wid->geometry().left();
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
102 pos_end = wid->geometry().right();
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
103 }
9
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
104
10
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
105 if (pos_end > ref_pos && pos_start < ref_pos) {
9
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
106 //We are inside a widget, we break here
10
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
107 hint_start = pos_end;
9
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
108 m_insert_pos++;
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
109 break;
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
110 }
10
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
111 else if (pos_start > ref_pos)
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
112 //we are too far, we stop
9
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
113 break;
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
114
10
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
115 hint_start = pos_end;
9
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
116 }
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
117
10
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
118 if (m_direction == VERTICAL)
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
119 m_loc_hint.setRect(5, hint_start+1, qMax(5,width()-10), 5);
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
120 else
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
121 m_loc_hint.setRect(hint_start+1, 5, 5, qMax(5,height()-10));
9
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
122 update();
8
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
123 }
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
124
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
125 void LayoutView::dropEvent (QDropEvent* event)
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
126 {
9
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
127 m_loc_hint.setCoords(1,1,0,0); //We make the QRect invalid to hide it
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
128 update();
8
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
129 const QMimeData *data = event->mimeData();
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130 QByteArray encodedData = data->data(LAYOUT_WIDGET_MIME);
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
131 QDataStream stream(&encodedData, QIODevice::ReadOnly);
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
132 while (!stream.atEnd()) {
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
133 QString widget_name;
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
134 stream >> widget_name;
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
135 addWidget(widget_name);
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
136 }
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
137 }
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
138
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
139 void LayoutView::addWidget(const QString& name)
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
140 {
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
141 LayoutWidget* _widget = m_layout_widgets[name];
10
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
142 WidgetView* _widget_view;
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
143 if (name == "Box") {
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
144 _widget_view = new WidgetViewBox(name);
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
145 }
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
146 else {
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
147 _widget_view = new WidgetViewItem(name);
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
148 reinterpret_cast<WidgetViewItem*>(_widget_view)->setAlignment(Qt::AlignCenter);
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
149 }
877a005c2b42 Layout designer: WidgetView class, with two types: WidgetViewItem and WidgetViewBox which contains items.
Goffi <goffi@goffi.org>
parents: 9
diff changeset
150 m_layout->insertWidget(m_insert_pos, reinterpret_cast<QWidget*>(_widget_view), 0, Qt::AlignTop);
8
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
151
c63d67895cbe layout designer: first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
152 }
9
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
153
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
154 void LayoutView::paintEvent(QPaintEvent* event)
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
155 {
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
156 if (m_loc_hint.isValid()) {
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
157 QPainter newPainter(this);
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
158 newPainter.fillRect(m_loc_hint, Qt::blue);
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
159 }
0d7875c26974 layout designer: hints on widget placement during drag and drop
Goffi <goffi@goffi.org>
parents: 8
diff changeset
160 }