diff options
author | deva <deva> | 2008-07-04 17:49:51 +0000 |
---|---|---|
committer | deva <deva> | 2008-07-04 17:49:51 +0000 |
commit | 678aba4c1fd1c9930ecda84a126f1bc7163dc29d (patch) | |
tree | 74664cdf0dae0d77b9de382d327716726ff13306 | |
parent | fe81dbb0a0dfc9c3808df9576dfe9a8f0b7520be (diff) |
First attempt on an editor framework.
-rw-r--r-- | editor/editor.cc | 41 | ||||
-rw-r--r-- | editor/editor.pro | 13 | ||||
-rw-r--r-- | editor/macrowindow.cc | 198 | ||||
-rw-r--r-- | editor/macrowindow.h | 53 | ||||
-rw-r--r-- | editor/tool.cc | 54 | ||||
-rw-r--r-- | editor/tool.h | 47 | ||||
-rw-r--r-- | editor/toolbox.cc | 55 | ||||
-rw-r--r-- | editor/toolbox.h | 38 | ||||
-rw-r--r-- | editor/widget.cc | 59 | ||||
-rw-r--r-- | editor/widget.h | 47 |
10 files changed, 605 insertions, 0 deletions
diff --git a/editor/editor.cc b/editor/editor.cc new file mode 100644 index 0000000..780b6dc --- /dev/null +++ b/editor/editor.cc @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * editor.cc + * + * Fri Jul 4 12:29:34 CEST 2008 + * Copyright 2008 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include <QApplication> + +#include "toolbox.h" +#include "macrowindow.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + Toolbox toolbox; + MacroWindow macrowindow(Qt::Horizontal); + macrowindow.resize(400, 300); + + return app.exec(); +} diff --git a/editor/editor.pro b/editor/editor.pro new file mode 100644 index 0000000..8d27503 --- /dev/null +++ b/editor/editor.pro @@ -0,0 +1,13 @@ +# -*- Makefile -*- + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . + +# For debugging +QMAKE_CXXFLAGS += -g -Wall -Werror + +# Input +HEADERS += toolbox.h tool.h macrowindow.h widget.h +SOURCES += editor.cc toolbox.cc tool.cc macrowindow.cc widget.cc diff --git a/editor/macrowindow.cc b/editor/macrowindow.cc new file mode 100644 index 0000000..761f107 --- /dev/null +++ b/editor/macrowindow.cc @@ -0,0 +1,198 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * macrowindow.cc + * + * Fri Jul 4 12:29:41 CEST 2008 + * Copyright 2008 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "macrowindow.h" + +#include <QLabel> +#include <QBoxLayout> +#include <QVBoxLayout> +#include <QHBoxLayout> + +#include <math.h> + +#include "widget.h" + +MacroWindow::MacroWindow(Qt::Orientation orientation) + : QFrame() +{ + this->orientation = orientation; + setAcceptDrops(true); + if(orientation == Qt::Horizontal) { + setLayout(new QHBoxLayout()); + } else { + setLayout(new QVBoxLayout()); + } + // layout()->setSpacing(0); + // layout()->setContentsMargins(2,2,2,2); + show(); + dragObject = NULL; + + setFrameStyle(QFrame::Box | QFrame::Plain); + 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); + + ((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(); + + if(orientation == Qt::Horizontal) { + mimedata->setData("pracro/widget", "horizontal"); + } else { + mimedata->setData("pracro/widget", "vertical"); + } + drag->setMimeData(mimedata); + + QWidget *parent = parentWidget(); + if(parent) { + parent->layout()->removeWidget(this); + setVisible(false); + drag->exec(); + } + } +} diff --git a/editor/macrowindow.h b/editor/macrowindow.h new file mode 100644 index 0000000..5ff375f --- /dev/null +++ b/editor/macrowindow.h @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * macrowindow.h + * + * Fri Jul 4 12:29:41 CEST 2008 + * Copyright 2008 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __PRACRO_MACROWINDOW_H__ +#define __PRACRO_MACROWINDOW_H__ + +#include <QFrame> +#include <QDragEnterEvent> +#include <QDropEvent> + +class MacroWindow : public QFrame +{ +Q_OBJECT +public: + MacroWindow(Qt::Orientation orientation); + +protected: + void dragEnterEvent(QDragEnterEvent *event); + void dragLeaveEvent(QDragLeaveEvent *event); + void dragMoveEvent(QDragMoveEvent *event); + void dropEvent(QDropEvent *event); + void mousePressEvent(QMouseEvent *event); + +private: + Qt::Orientation orientation; + QWidget *dragObject; + QWidget *findWidget(QPoint pos); +}; + +#endif/*__PRACRO_MACROWINDOW_H__*/ diff --git a/editor/tool.cc b/editor/tool.cc new file mode 100644 index 0000000..4a40c47 --- /dev/null +++ b/editor/tool.cc @@ -0,0 +1,54 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * tool.cc + * + * Fri Jul 4 12:29:46 CEST 2008 + * Copyright 2008 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "tool.h" + +#include <QDrag> +//#include <QMimeType> + +Tool::Tool(QPixmap &pixmap, QString widget) + : QLabel() +{ + setPixmap(pixmap); + this->pixmap = pixmap; + this->widget = widget; + show(); +} + +void Tool::mousePressEvent(QMouseEvent *event) +{ + if(event->button() == Qt::LeftButton) { + + QDrag *drag = new QDrag(this); + drag->setPixmap(pixmap); + + QMimeData *mimedata = new QMimeData(); + mimedata->setData("pracro/widget", widget.toAscii()); + drag->setMimeData(mimedata); + + drag->exec(); + } +} diff --git a/editor/tool.h b/editor/tool.h new file mode 100644 index 0000000..a9ef1a6 --- /dev/null +++ b/editor/tool.h @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * tool.h + * + * Fri Jul 4 12:29:46 CEST 2008 + * Copyright 2008 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __PRACRO_TOOL_H__ +#define __PRACRO_TOOL_H__ + +#include <QLabel> +#include <QPixmap> +#include <QMouseEvent> + +class Tool : public QLabel { +Q_OBJECT +public: + Tool(QPixmap &pixmap, QString widget); + +protected: + void mousePressEvent(QMouseEvent *event); + +private: + QPixmap pixmap; + QString widget; +}; + +#endif/*__PRACRO_TOOL_H__*/ diff --git a/editor/toolbox.cc b/editor/toolbox.cc new file mode 100644 index 0000000..9e75e66 --- /dev/null +++ b/editor/toolbox.cc @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * toolbox.cc + * + * Fri Jul 4 12:29:49 CEST 2008 + * Copyright 2008 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "toolbox.h" + +#include <QVBoxLayout> +#include "tool.h" + +Toolbox::Toolbox() + : QDialog() +{ + setLayout(new QVBoxLayout()); + + QPixmap pixmap("drag.png"); + + Tool *tool1 = new Tool(pixmap, "Tool1"); + layout()->addWidget(tool1); + + Tool *tool2 = new Tool(pixmap, "Tool2"); + layout()->addWidget(tool2); + + Tool *tool3 = new Tool(pixmap, "Tool3"); + layout()->addWidget(tool3); + + Tool *tool4 = new Tool(pixmap, "vertical"); + layout()->addWidget(tool4); + + Tool *tool5 = new Tool(pixmap, "horizontal"); + layout()->addWidget(tool5); + + show(); +} diff --git a/editor/toolbox.h b/editor/toolbox.h new file mode 100644 index 0000000..e703c35 --- /dev/null +++ b/editor/toolbox.h @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * toolbox.h + * + * Fri Jul 4 12:29:49 CEST 2008 + * Copyright 2008 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __PRACRO_TOOLBOX_H__ +#define __PRACRO_TOOLBOX_H__ + +#include <QDialog> + +class Toolbox : public QDialog { +Q_OBJECT +public: + Toolbox(); +}; + +#endif/*__PRACRO_TOOLBOX_H__*/ diff --git a/editor/widget.cc b/editor/widget.cc new file mode 100644 index 0000000..15bcd2f --- /dev/null +++ b/editor/widget.cc @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * widget.cc + * + * Fri Jul 4 12:31:17 CEST 2008 + * Copyright 2008 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "widget.h" + +#include <QDrag> +#include <QLayout> + +Widget::Widget(QString type) + : QLabel(type) +{ + widget = type; + setAutoFillBackground(true); + QPalette pal; + pal.setColor(QPalette::Foreground, Qt::black); + // pal.setColor(QPalette::Background, Qt::yellow); + setPalette(pal); +} + +void Widget::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", widget.toAscii()); + drag->setMimeData(mimedata); + + parentWidget()->layout()->removeWidget(this); + setVisible(false); + + drag->exec(); + } +} diff --git a/editor/widget.h b/editor/widget.h new file mode 100644 index 0000000..1cb7d9e --- /dev/null +++ b/editor/widget.h @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * widget.h + * + * Fri Jul 4 12:31:17 CEST 2008 + * Copyright 2008 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __PRACRO_WIDGET_H__ +#define __PRACRO_WIDGET_H__ + +#include <QLabel> +#include <QPixmap> +#include <QMouseEvent> + +class Widget : public QLabel { +Q_OBJECT +public: + Widget(QString type); + +protected: + void mousePressEvent(QMouseEvent *event); + +private: + QPixmap pixmap; + QString widget; +}; + +#endif/*__PRACRO_WIDGET_H__*/ |