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 #include "layout_view.h" |
|
19 #include <QDebug> |
|
20 |
|
21 LayoutView::LayoutView(QWidget* parent) |
|
22 { |
|
23 setAcceptDrops(true); |
|
24 m_layout = new QVBoxLayout; |
|
25 setLayout(m_layout); |
|
26 m_layout->addStretch(); |
|
27 setStyleSheet("QLabel {border: 1px solid black; \ |
|
28 border-radius: 5px; \ |
|
29 text-align: center; \ |
|
30 background-color: white; \ |
|
31 min-height: 20px; \ |
|
32 max-height: 20px; \ |
|
33 margin: 2px; \ |
|
34 }"); |
|
35 } |
|
36 |
|
37 LayoutView::~LayoutView() |
|
38 { |
|
39 } |
|
40 |
|
41 void LayoutView::setLayoutWidgets(const QHash<QString, LayoutWidget*>& layout_widgets) |
|
42 { |
|
43 m_layout_widgets = layout_widgets; |
|
44 } |
|
45 |
|
46 void LayoutView::dragEnterEvent (QDragEnterEvent* event ) |
|
47 { |
|
48 qDebug() << "Drag enter: " << event->pos(); |
|
49 if (event->mimeData()->hasFormat(LAYOUT_WIDGET_MIME)) |
|
50 event->acceptProposedAction(); |
|
51 } |
|
52 |
|
53 void LayoutView::dragMoveEvent (QDragMoveEvent* event ) |
|
54 { |
|
55 qDebug() << "Drag move: " << event->pos(); |
|
56 QWidget* _wid = childAt(event->pos()); |
|
57 if (_wid) |
|
58 qDebug() << "Object: " << _wid->metaObject()->className(); |
|
59 } |
|
60 |
|
61 void LayoutView::dropEvent (QDropEvent* event) |
|
62 { |
|
63 const QMimeData *data = event->mimeData(); |
|
64 QByteArray encodedData = data->data(LAYOUT_WIDGET_MIME); |
|
65 QDataStream stream(&encodedData, QIODevice::ReadOnly); |
|
66 while (!stream.atEnd()) { |
|
67 QString widget_name; |
|
68 stream >> widget_name; |
|
69 addWidget(widget_name); |
|
70 } |
|
71 } |
|
72 |
|
73 void LayoutView::addWidget(const QString& name) |
|
74 { |
|
75 LayoutWidget* _widget = m_layout_widgets[name]; |
|
76 qDebug() << "Adding: " << name; |
|
77 QLabel* _label = new QLabel(name); |
|
78 _label->setAlignment(Qt::AlignCenter); |
|
79 m_layout->insertWidget(qMax(0, m_layout->count()-1), _label, 0, Qt::AlignTop); |
|
80 |
|
81 } |