Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am6
-rw-r--r--src/mainwindow.cc8
-rw-r--r--src/mapwidget.cc73
-rw-r--r--src/mapwidget.h33
4 files changed, 113 insertions, 7 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 231fd8a..7486902 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,12 +4,14 @@ bin_PROGRAMS = editor
# Remember to include the name of the resource file with the .cpp extension.
editor_SOURCES = \
editor.cc \
- mainwindow.cc
+ mainwindow.cc \
+ mapwidget.cc
# You have one .h file, it's called editor.h. Therefore, here I list
# its mocced name, moc_editor.cpp.
nodist_editor_SOURCES = \
- moc_mainwindow.cc
+ moc_mainwindow.cc \
+ moc_mapwidget.cc
# This rule lets GNU make create any moc_*.cpp from the equivalent *.h
moc_%.cc: %.h
diff --git a/src/mainwindow.cc b/src/mainwindow.cc
index e5f8000..e0fe6b2 100644
--- a/src/mainwindow.cc
+++ b/src/mainwindow.cc
@@ -6,8 +6,7 @@
*/
#include <mainwindow.h>
-
-#include <QTextEdit>
+#include <mapwidget.h>
namespace editor
{
@@ -66,9 +65,8 @@ void MainWindow::init_menu()
void MainWindow::add_child()
{
// create a child widget
- // TODO replace QTextEdit qith the actual editor widget
- QTextEdit *child_widget = new QTextEdit();
-
+ MapWidget *child_widget = new MapWidget();
+
// add the widget to the MDI area,
// this will wrap an QMdiSubWindow around it
mainwindow_mdiarea->addSubWindow(child_widget);
diff --git a/src/mapwidget.cc b/src/mapwidget.cc
new file mode 100644
index 0000000..3c0d846
--- /dev/null
+++ b/src/mapwidget.cc
@@ -0,0 +1,73 @@
+/*
+ mapwidget.cc
+ This file is part of the Project::OSiRiON zone editor
+ and is distributed under the terms and conditions of
+ the GNU General Public License version 2
+*/
+
+#include <mapwidget.h>
+
+#include <QPainter>
+#include <QWheelEvent>
+
+namespace editor
+{
+
+MapWidget::MapWidget(QWidget *parent) : QWidget(parent)
+{
+ setMinimumSize(128,128);
+
+ // zoom sucks but it works
+ mapwidget_zoom = 4;
+}
+
+void MapWidget::wheelEvent(QWheelEvent *event)
+{
+ if (event->orientation() == Qt::Vertical) {
+ mapwidget_zoom += event->delta() / 120;
+ if (mapwidget_zoom < 1)
+ mapwidget_zoom = 1;
+ else if (mapwidget_zoom > 64) {
+ mapwidget_zoom = 64;
+ }
+ repaint();
+ event->accept();
+ }
+}
+
+void MapWidget::paintEvent(QPaintEvent *event)
+{
+ QPen pen(Qt::blue, 1, Qt::SolidLine);
+ QPainter painter(this);
+
+ painter.setPen(pen);
+
+ // mapwidget_zoom is used to scale from game units to screen coorinates
+ // 1 grid square is 128 game units
+ // gridsize is the size of one grid square in screen coordinates
+ int gridsize = 128 / mapwidget_zoom;
+
+ int x = width() / 2;
+ while (x > 0) {
+ painter.drawLine(x, 0, x, height());
+ x -= gridsize;
+ }
+ x = width() / 2 + gridsize;
+ while (x <= width()) {
+ painter.drawLine(x, 0, x, height());
+ x += gridsize;
+ }
+
+ int y = height() / 2;
+ while (y > 0) {
+ painter.drawLine(0, y, width(), y);
+ y -= gridsize;
+ }
+ y = height() / 2 + gridsize;
+ while (y <= height()) {
+ painter.drawLine(0, y, width(), y);
+ y += gridsize;
+ }
+}
+
+}
diff --git a/src/mapwidget.h b/src/mapwidget.h
new file mode 100644
index 0000000..fcc8b28
--- /dev/null
+++ b/src/mapwidget.h
@@ -0,0 +1,33 @@
+/*
+ mapwidget.h
+ This file is part of the Project::OSiRiON zone editor
+ and is distributed under the terms and conditions of
+ the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_EDITOR_MAPWIDGET__
+#define __INCLUDED_EDITOR_MAPWIDGET__
+
+#include <QWidget>
+
+namespace editor
+{
+
+class MapWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ MapWidget(QWidget *parent = 0);
+
+protected:
+
+ virtual void paintEvent(QPaintEvent *event);
+ virtual void wheelEvent(QWheelEvent *event);
+private:
+ int mapwidget_zoom;
+};
+
+}
+
+#endif // __INCLUDED_EDITOR_MAPWIDGET__ \ No newline at end of file