summaryrefslogtreecommitdiff
path: root/editor/macrowindow.cc
diff options
context:
space:
mode:
authordeva <deva>2008-07-11 12:54:42 +0000
committerdeva <deva>2008-07-11 12:54:42 +0000
commit5a19d9218a5f3ed7d02b7fabd8f025922e9f7a13 (patch)
tree49ee6645bf55e620db824d0c95508a65d4d596e7 /editor/macrowindow.cc
parent12bd3e7ff088b097bf4e280161aee646fbbb50dc (diff)
Now we have a nice little editor.
Diffstat (limited to 'editor/macrowindow.cc')
-rw-r--r--editor/macrowindow.cc158
1 files changed, 5 insertions, 153 deletions
diff --git a/editor/macrowindow.cc b/editor/macrowindow.cc
index c3f8185..13a4a3b 100644
--- a/editor/macrowindow.cc
+++ b/editor/macrowindow.cc
@@ -26,19 +26,11 @@
*/
#include "macrowindow.h"
-#include <QLabel>
-#include <QBoxLayout>
-#include <QVBoxLayout>
-#include <QHBoxLayout>
-
-#include <math.h>
-
-#include "widget.h"
-#include "widgetwrapper.h"
-
-MacroWindow::MacroWindow(Qt::Orientation orientation)
- : QFrame()
+MacroWindow::MacroWindow(QDomNode &node)
+ : Widget(node)
{
+
+ /*
this->orientation = orientation;
setAcceptDrops(true);
if(orientation == Qt::Horizontal) {
@@ -55,146 +47,6 @@ MacroWindow::MacroWindow(Qt::Orientation orientation)
QPalette pal;
pal.setColor(QPalette::Foreground, Qt::blue);
setPalette(pal);
+ */
}
-void MacroWindow::dragEnterEvent(QDragEnterEvent *event)
-{
- if(event->mimeData()->hasFormat("pracro/widget")) {
- event->acceptProposedAction();
-
- if(dragObject) delete dragObject;
- QFrame *frame = new QFrame();
-
- QPalette pal;
- pal.setColor(QPalette::Foreground, Qt::red);
- frame->setPalette(pal);
-
- if(orientation == Qt::Horizontal) {
- frame->setFixedWidth(1);
- } else {
- frame->setFixedHeight(1);
- }
-
- frame->setFrameStyle(QFrame::Box | QFrame::Plain);
- frame->setContentsMargins(1,1,0,0);
-
- dragObject = frame;
-
- QWidget *w = findWidget(event->pos());
- if(w) {
- int idx = ((QBoxLayout*)layout())->indexOf(w);
- ((QBoxLayout*)layout())->insertWidget(idx, dragObject);
- } else {
- layout()->addWidget(dragObject);
- }
- }
-}
-
-void MacroWindow::dragLeaveEvent(QDragLeaveEvent *)
-{
- if(dragObject) delete dragObject;
- dragObject = NULL;
-}
-
-void MacroWindow::dragMoveEvent(QDragMoveEvent *event)
-{
- if(event->mimeData()->hasFormat("pracro/widget")) {
- event->acceptProposedAction();
-
- layout()->removeWidget(dragObject);
-
- QWidget *w = findWidget(event->pos());
- if(w == dragObject) return;
-
- if(w) {
- int idx = ((QBoxLayout*)layout())->indexOf(w);
- ((QBoxLayout*)layout())->insertWidget(idx, dragObject);
- } else {
- layout()->addWidget(dragObject);
- }
- }
-}
-
-void MacroWindow::dropEvent(QDropEvent *event)
-{
- if(event->mimeData()->hasFormat("pracro/widget")) {
- int idx = layout()->indexOf(dragObject);
-
- /*
- QString type = event->mimeData()->data("pracro/widget").data();
- QWidget *widget;
- if(type == "horizontal") widget = new MacroWindow(Qt::Horizontal);
- else if(type == "vertical") widget = new MacroWindow(Qt::Vertical);
- else widget = new Widget(type);
- */
- QWidget *widget = unwrapWidget(event->mimeData()->data("pracro/widget"));
- widget->setVisible(true);
-
- ((QBoxLayout*)layout())->insertWidget(idx, widget);
- delete dragObject;
- dragObject = NULL;
- event->acceptProposedAction();
- }
-}
-
-QWidget *MacroWindow::findWidget(QPoint pos)
-{
- QPoint newpos = pos;
- QWidget *w = childAt(newpos);
-
- float angle = 0.0;
- float dist = 0.0;
- while((!w || QString(w->metaObject()->className()) == "QFrame") && layout()->count()) {
-
- angle += M_PI / 4;
- dist += 1;
-
- newpos = pos + QPoint(sin(angle) * dist, cos(angle) * dist);
-
- if(newpos.x() > height() && newpos.y() > width() && newpos.y() < 0 && newpos.x() < 0) {
- break;
- }
-
- // printf("%d, %d\n", newpos.x(), newpos.y());
- w = childAt(newpos);
- }
- // printf("Done {%p %s}\n", w, w!=NULL?w->metaObject()->className():"(null)");
-
- if(w) {
- int idx = layout()->indexOf(w);
- // printf("\r%d > %d", pos.y() - w->pos().y(), w->height() / 2); fflush(stdout);
- if(orientation == Qt::Horizontal) {
- if(pos.x() - w->pos().x() > w->width() / 2) idx++;
- } else {
- if(pos.y() - w->pos().y() > w->height() / 2) idx++;
- }
-
- // if(idx < layout()->count()) idx = layout()->count() - 1;
- if(idx >= 0 && idx < layout()->count()) w = layout()->itemAt(idx)->widget();
- else w = NULL;
- }
-
- return w;
-}
-
-void MacroWindow::mousePressEvent(QMouseEvent *event)
-{
- if(event->button() == Qt::LeftButton) {
-
- QDrag *drag = new QDrag(this);
- drag->setPixmap(QPixmap("drag.png"));
-
- QMimeData *mimedata = new QMimeData();
-
- mimedata->setData("pracro/widget", wrapWidget(this));
-
- drag->setMimeData(mimedata);
-
- QWidget *parent = parentWidget();
- if(parent) {
- parent->layout()->removeWidget(this);
- setVisible(false);
- drag->exec();
- }
- }
-}