diff layout_view.cpp @ 8:c63d67895cbe

layout designer: first draft
author Goffi <goffi@goffi.org>
date Wed, 24 Aug 2011 20:38:55 +0200
parents
children 0d7875c26974
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/layout_view.cpp	Wed Aug 24 20:38:55 2011 +0200
@@ -0,0 +1,81 @@
+/*
+Bellaciao: a Salut à Toi frontend
+Copyright (C) 2011  Jérôme Poisson (goffi@goffi.org)
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#include "layout_view.h"
+#include <QDebug>
+
+LayoutView::LayoutView(QWidget* parent)
+{
+    setAcceptDrops(true);
+    m_layout = new QVBoxLayout;
+    setLayout(m_layout);
+    m_layout->addStretch();
+    setStyleSheet("QLabel {border: 1px solid black; \
+                           border-radius: 5px; \
+                           text-align: center; \
+                           background-color: white; \
+                           min-height: 20px; \
+                           max-height: 20px; \
+                           margin: 2px; \
+                           }");
+}
+
+LayoutView::~LayoutView()
+{
+}
+        
+void LayoutView::setLayoutWidgets(const QHash<QString, LayoutWidget*>& layout_widgets)
+{
+    m_layout_widgets = layout_widgets;
+}
+        
+void LayoutView::dragEnterEvent (QDragEnterEvent* event )
+{
+    qDebug() << "Drag enter: " << event->pos();
+    if (event->mimeData()->hasFormat(LAYOUT_WIDGET_MIME))
+        event->acceptProposedAction();
+}
+        
+void LayoutView::dragMoveEvent (QDragMoveEvent* event )
+{
+    qDebug() << "Drag move: " << event->pos();
+    QWidget* _wid = childAt(event->pos());
+    if (_wid)
+        qDebug() << "Object: " << _wid->metaObject()->className();
+}
+
+void LayoutView::dropEvent (QDropEvent* event)
+{
+    const QMimeData *data = event->mimeData();
+    QByteArray encodedData = data->data(LAYOUT_WIDGET_MIME);
+    QDataStream stream(&encodedData, QIODevice::ReadOnly);
+    while (!stream.atEnd()) {
+        QString widget_name;
+        stream >> widget_name;
+        addWidget(widget_name);
+    } 
+}
+
+void LayoutView::addWidget(const QString& name)
+{
+    LayoutWidget* _widget = m_layout_widgets[name];
+    qDebug() << "Adding: " << name;
+    QLabel* _label = new QLabel(name);
+    _label->setAlignment(Qt::AlignCenter);
+    m_layout->insertWidget(qMax(0, m_layout->count()-1), _label, 0, Qt::AlignTop);
+
+}