From 6d1422a0908042219ae03377b54585e27d3ff7a5 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 18 Mar 2009 12:37:08 -0400 Subject: Move the old MapEditor code into the widgets folder --- sigmodr/EffectItem.cpp | 116 ----------------------------------- sigmodr/EffectItem.h | 56 ----------------- sigmodr/MapEditor.cpp | 67 -------------------- sigmodr/MapEditor.h | 66 -------------------- sigmodr/MapScene.cpp | 132 ---------------------------------------- sigmodr/MapScene.h | 64 ------------------- sigmodr/TileItem.cpp | 130 --------------------------------------- sigmodr/TileItem.h | 64 ------------------- sigmodr/TrainerItem.cpp | 118 ----------------------------------- sigmodr/TrainerItem.h | 56 ----------------- sigmodr/WarpItem.cpp | 123 ------------------------------------- sigmodr/WarpItem.h | 53 ---------------- sigmodr/widgets/EffectItem.cpp | 116 +++++++++++++++++++++++++++++++++++ sigmodr/widgets/EffectItem.h | 56 +++++++++++++++++ sigmodr/widgets/MapEditor.cpp | 67 ++++++++++++++++++++ sigmodr/widgets/MapEditor.h | 66 ++++++++++++++++++++ sigmodr/widgets/MapScene.cpp | 132 ++++++++++++++++++++++++++++++++++++++++ sigmodr/widgets/MapScene.h | 64 +++++++++++++++++++ sigmodr/widgets/TileItem.cpp | 130 +++++++++++++++++++++++++++++++++++++++ sigmodr/widgets/TileItem.h | 64 +++++++++++++++++++ sigmodr/widgets/TrainerItem.cpp | 118 +++++++++++++++++++++++++++++++++++ sigmodr/widgets/TrainerItem.h | 56 +++++++++++++++++ sigmodr/widgets/WarpItem.cpp | 123 +++++++++++++++++++++++++++++++++++++ sigmodr/widgets/WarpItem.h | 53 ++++++++++++++++ 24 files changed, 1045 insertions(+), 1045 deletions(-) delete mode 100644 sigmodr/EffectItem.cpp delete mode 100644 sigmodr/EffectItem.h delete mode 100644 sigmodr/MapEditor.cpp delete mode 100644 sigmodr/MapEditor.h delete mode 100644 sigmodr/MapScene.cpp delete mode 100644 sigmodr/MapScene.h delete mode 100644 sigmodr/TileItem.cpp delete mode 100644 sigmodr/TileItem.h delete mode 100644 sigmodr/TrainerItem.cpp delete mode 100644 sigmodr/TrainerItem.h delete mode 100644 sigmodr/WarpItem.cpp delete mode 100644 sigmodr/WarpItem.h create mode 100644 sigmodr/widgets/EffectItem.cpp create mode 100644 sigmodr/widgets/EffectItem.h create mode 100644 sigmodr/widgets/MapEditor.cpp create mode 100644 sigmodr/widgets/MapEditor.h create mode 100644 sigmodr/widgets/MapScene.cpp create mode 100644 sigmodr/widgets/MapScene.h create mode 100644 sigmodr/widgets/TileItem.cpp create mode 100644 sigmodr/widgets/TileItem.h create mode 100644 sigmodr/widgets/TrainerItem.cpp create mode 100644 sigmodr/widgets/TrainerItem.h create mode 100644 sigmodr/widgets/WarpItem.cpp create mode 100644 sigmodr/widgets/WarpItem.h diff --git a/sigmodr/EffectItem.cpp b/sigmodr/EffectItem.cpp deleted file mode 100644 index e297ebb0..00000000 --- a/sigmodr/EffectItem.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright 2008-2009 Ben Boeckel - * - * This program 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 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -// Header include -#include "EffectItem.h" - -// Sigmod includes -#include "../sigmod/MapEffect.h" -#include "../sigmod/Sigmod.h" -#include "../sigmod/Sprite.h" - -// KDE includes -#include - -// Qt includes -#include -#include -#include - -Sigmodr::EffectItem::EffectItem(Sigmod::MapEffect* effect, QObject* parent) : - QObject(parent), - m_effect(effect) -{ - connect(m_effect, SIGNAL(changed()), this, SLOT(effectChanged())); - effectChanged(); - setZValue(INT_MAX); - setAcceptHoverEvents(true); -} - -QRectF Sigmodr::EffectItem::boundingRect() const -{ - return m_pixmap.rect(); -} - -void Sigmodr::EffectItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) -{ - Q_UNUSED(widget) - if (!(flags() & QGraphicsItem::ItemIsSelectable)) - { - QPixmap temp(m_pixmap.size()); - temp.fill(Qt::transparent); - QPainter p; - p.begin(&temp); - p.setCompositionMode(QPainter::CompositionMode_DestinationIn); - p.fillRect(temp.rect(), QColor(0, 0, 0, 127)); - p.end(); - painter->drawPixmap(0, 0, temp); - } - painter->drawPixmap(0, 0, m_pixmap); - if (option->state & QStyle::State_MouseOver) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::View, (flags() & QGraphicsItem::ItemIsSelectable) ? KColorScheme::ActiveText : KColorScheme::InactiveText).brush((flags() & QGraphicsItem::ItemIsSelectable) ? QPalette::Active : QPalette::Inactive), 1)); - painter->drawText(m_pixmap.rect(), Qt::AlignHCenter | Qt::AlignVCenter, m_effect->name()); - } - if (option->state & QStyle::State_HasFocus) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::FocusColor).brush(QPalette::Active), 6)); - painter->drawRect(m_pixmap.rect()); - } - else if (option->state & QStyle::State_Selected) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::ActiveBackground).brush(QPalette::Active), 6)); - painter->drawRect(m_pixmap.rect()); - } - else if ((option->state & QStyle::State_MouseOver) && (flags() & QGraphicsItem::ItemIsSelectable)) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::HoverColor).brush(QPalette::Active), 6)); - painter->drawRect(m_pixmap.rect()); - } -} - -void Sigmodr::EffectItem::changeSprite(const int spriteId) -{ - const Sigmod::Sprite* sprite = m_effect->sigmod()->spriteById(spriteId); - if (sprite) - m_pixmap.loadFromData(sprite->sprite()); - update(); -} - -void Sigmodr::EffectItem::mousePressEvent(QGraphicsSceneMouseEvent* event) -{ - QGraphicsItem::mousePressEvent(event); - update(); -} - -void Sigmodr::EffectItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) -{ - QGraphicsItem::mouseMoveEvent(event); - m_effect->setPosition(scenePos().toPoint()); -} - -void Sigmodr::EffectItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) -{ - QGraphicsItem::mouseReleaseEvent(event); - update(); -} - -void Sigmodr::EffectItem::effectChanged() -{ - setPos(m_effect->position()); - update(); -} diff --git a/sigmodr/EffectItem.h b/sigmodr/EffectItem.h deleted file mode 100644 index b13ffda1..00000000 --- a/sigmodr/EffectItem.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2008 Ben Boeckel - * - * This program 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 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef SIGMODR_EFFECTITEM -#define SIGMODR_EFFECTITEM - -// Qt includes -#include - -// Forward declarations -namespace Sigmod -{ -class MapEffect; -} - -namespace Sigmodr -{ -class EffectItem : public QObject, public QGraphicsItem -{ - Q_OBJECT - - public: - EffectItem(Sigmod::MapEffect* effect, QObject* parent); - - QRectF boundingRect() const; - - void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); - public slots: - void changeSprite(const int spriteId); - protected: - void mousePressEvent(QGraphicsSceneMouseEvent* event); - void mouseMoveEvent(QGraphicsSceneMouseEvent* event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); - protected slots: - void effectChanged(); - private: - QPixmap m_pixmap; - Sigmod::MapEffect* m_effect; -}; -} - -#endif diff --git a/sigmodr/MapEditor.cpp b/sigmodr/MapEditor.cpp deleted file mode 100644 index aeff1312..00000000 --- a/sigmodr/MapEditor.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2008 Ben Boeckel - * - * This program 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 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -// Header include -#include "MapEditor.h" - -// Sigmodr includes -#include "MapScene.h" - -// KDE includes -#include -#include - -// Qt includes -#include -#include - -Sigmodr::MapEditor::MapEditor(QWidget* parent) : - QWidget(parent) -{ - setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); - QGridLayout* layout = new QGridLayout; - m_view = new QGraphicsView; - m_view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - layout->addWidget(m_view, 0, 0, 6, 1); - m_addTile = new KPushButton(KIcon("list-add"), "Add Tile"); - layout->addWidget(m_addTile, 0, 1, 1, 1); - m_removeTiles = new KPushButton(KIcon("list-remove"), "Remove Tiles"); - layout->addWidget(m_removeTiles, 1, 1, 1, 1); - m_moveToTop = new KPushButton(KIcon("arrow-up-double"), "Move to Top"); - layout->addWidget(m_moveToTop, 2, 1, 1, 1); - m_moveUp = new KPushButton(KIcon("arrow-up"), "Move Up"); - layout->addWidget(m_moveUp, 3, 1, 1, 1); - m_moveDown = new KPushButton(KIcon("arrow-down"), "Move Down"); - layout->addWidget(m_moveDown, 4, 1, 1, 1); - m_moveToBottom = new KPushButton(KIcon("arrow-down-double"), "Move to Bottom"); - layout->addWidget(m_moveToBottom, 5, 1, 1, 1); - setLayout(layout); -} - -void Sigmodr::MapEditor::setMap(Sigmod::Map* map) -{ - m_map = map; - m_scene = new MapScene(map, this); - connect(m_scene, SIGNAL(changed()), this, SIGNAL(changed())); - connect(m_addTile, SIGNAL(pressed()), m_scene, SLOT(addTile())); - connect(m_removeTiles, SIGNAL(pressed()), m_scene, SLOT(removeTiles())); - m_view->setScene(m_scene); -} - -void Sigmodr::MapEditor::reset() -{ -} diff --git a/sigmodr/MapEditor.h b/sigmodr/MapEditor.h deleted file mode 100644 index 4b6ba427..00000000 --- a/sigmodr/MapEditor.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2008-2009 Ben Boeckel - * - * This program 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 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef SIGMODR_MAPEDITOR -#define SIGMODR_MAPEDITOR - -// Qt includes -#include - -// Forward declarations -class QGraphicsView; -class KComboBox; -class KPushButton; -namespace Sigmod -{ -class Map; -} - -namespace Sigmodr -{ -class MapScene; - -class MapEditor : public QWidget -{ - Q_OBJECT - - public: - MapEditor(QWidget* parent); - - void setMap(Sigmod::Map* map); - - void reset(); - signals: - void changed(); - private: - Sigmod::Map* m_map; - MapScene* m_scene; - - QGraphicsView* m_view; - - KPushButton* m_addTile; - KPushButton* m_removeTiles; - KPushButton* m_moveToTop; - KPushButton* m_moveUp; - KPushButton* m_moveDown; - KPushButton* m_moveToBottom; - - KComboBox* m_types; -}; -} - -#endif diff --git a/sigmodr/MapScene.cpp b/sigmodr/MapScene.cpp deleted file mode 100644 index c250deae..00000000 --- a/sigmodr/MapScene.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright 2008 Ben Boeckel - * - * This program 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 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -// Header include -#include "MapScene.h" - -// Sigmodr includes -#include "EffectItem.h" -#include "TileItem.h" -#include "TrainerItem.h" -#include "WarpItem.h" - -// Sigmod includes -#include "../sigmod/Map.h" -#include "../sigmod/MapEffect.h" -#include "../sigmod/MapTile.h" -#include "../sigmod/MapTrainer.h" -#include "../sigmod/MapWarp.h" -#include "../sigmod/Tile.h" - -// KDE includes -#include -#include - -Sigmodr::MapScene::MapScene(Sigmod::Map* map, QObject* parent) : - QGraphicsScene(parent), - m_map(map) -{ - connect(this, SIGNAL(changed(QList)), this, SIGNAL(changed())); - for (int i = 0; i < m_map->effectCount(); ++i) - addItem(new EffectItem(m_map->effect(i), this)); - for (int i = 0; i < m_map->tileCount(); ++i) - addItem(new TileItem(m_map->tile(i), this)); - for (int i = 0; i < m_map->trainerCount(); ++i) - addItem(new TrainerItem(m_map->trainer(i), this)); - for (int i = 0; i < m_map->warpCount(); ++i) - addItem(new WarpItem(m_map->warp(i), this)); - typeChanged("Warps"); -} - -void Sigmodr::MapScene::addTile() -{ - KDialog* dialog = new KDialog; - dialog->setCaption("New Tile"); - KComboBox* combo = new KComboBox; - for (int i = 0; i < m_map->sigmod()->tileCount(); ++i) - combo->addItem(m_map->sigmod()->tile(i)->name()); - dialog->setMainWidget(combo); - if (dialog->exec() == KDialog::Ok) - { - Sigmod::MapTile* tile = m_map->newTile(); - tile->setTile(m_map->sigmod()->tile(combo->currentIndex())->id()); - TileItem* item = new TileItem(tile, this); - addItem(item); - m_tiles[tile] = item; - } - delete dialog; -} - -void Sigmodr::MapScene::removeTiles() -{ - QList items = selectedItems(); - foreach (QGraphicsItem* item, items) - { - if (m_effects.key(static_cast(item))) - { - Sigmod::MapEffect* effect = m_effects.key(static_cast(item)); - m_map->deleteEffectById(effect->id()); - delete m_effects[effect]; - m_effects.remove(effect); - } - else if (m_tiles.key(static_cast(item))) - { - Sigmod::MapTile* tile = m_tiles.key(static_cast(item)); - m_map->deleteTileById(tile->id()); - delete m_tiles[tile]; - m_tiles.remove(tile); - } - else if (m_trainers.key(static_cast(item))) - { - Sigmod::MapTrainer* trainer = m_trainers.key(static_cast(item)); - m_map->deleteTrainerById(trainer->id()); - delete m_trainers[trainer]; - m_trainers.remove(trainer); - } - else if (m_warps.key(static_cast(item))) - { - Sigmod::MapWarp* warp = m_warps.key(static_cast(item)); - m_map->deleteWarpById(warp->id()); - delete m_warps[warp]; - m_warps.remove(warp); - } - } -} - -void Sigmodr::MapScene::typeChanged(const QString& type) -{ - QGraphicsItem::GraphicsItemFlags effectFlags = 0; - QGraphicsItem::GraphicsItemFlags tileFlags = 0; - QGraphicsItem::GraphicsItemFlags trainerFlags = 0; - QGraphicsItem::GraphicsItemFlags warpFlags = 0; - if (type == "Effects") - effectFlags = QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable; - else if (type == "Tiles") - tileFlags = QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable; - else if (type == "Trainers") - trainerFlags = QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable; - else if (type == "Warps") - warpFlags = QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable; - foreach (EffectItem* effect, m_effects) - effect->setFlags(effectFlags); - foreach (TileItem* tile, m_tiles) - tile->setFlags(tileFlags); - foreach (TrainerItem* trainer, m_trainers) - trainer->setFlags(trainerFlags); - foreach (WarpItem* warp, m_warps) - warp->setFlags(warpFlags); -} diff --git a/sigmodr/MapScene.h b/sigmodr/MapScene.h deleted file mode 100644 index e517183f..00000000 --- a/sigmodr/MapScene.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2008 Ben Boeckel - * - * This program 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 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef SIGMODR_MAPSCENE -#define SIGMODR_MAPSCENE - -// Qt includes -#include -#include - -// Forward declarations -namespace Sigmod -{ -class Map; -class MapEffect; -class MapTile; -class MapTrainer; -class MapWarp; -} - -namespace Sigmodr -{ -class EffectItem; -class TileItem; -class TrainerItem; -class WarpItem; - -class MapScene : public QGraphicsScene -{ - Q_OBJECT - - public: - MapScene(Sigmod::Map* map, QObject* parent); - public slots: - void addTile(); - void removeTiles(); - - void typeChanged(const QString& type); - signals: - void changed(); - private: - Sigmod::Map* m_map; - QMap m_effects; - QMap m_tiles; - QMap m_trainers; - QMap m_warps; -}; -} - -#endif diff --git a/sigmodr/TileItem.cpp b/sigmodr/TileItem.cpp deleted file mode 100644 index 7ddaf885..00000000 --- a/sigmodr/TileItem.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright 2008 Ben Boeckel - * - * This program 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 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -// Header include -#include "TileItem.h" - -// Sigmod includes -#include "../sigmod/MapTile.h" -#include "../sigmod/Sigmod.h" -#include "../sigmod/Sprite.h" -#include "../sigmod/Tile.h" - -// Sigcore includes -#include "../sigcore/Script.h" - -// KDE includes -#include -#include - -// Qt includes -#include -#include -#include - -Sigmodr::TileItem::TileItem(Sigmod::MapTile* tile, QObject* parent) : - QObject(parent), - m_tile(tile) -{ - connect(m_tile, SIGNAL(changed()), this, SLOT(tileChanged())); - tileChanged(); - setAcceptHoverEvents(true); - Sigcore::Script script = m_tile->sigmod()->tileById(m_tile->tile())->script(); - m_action = new Kross::Action(this, QString("tile-%1").arg(m_tile->id())); - m_action->addObject(this, "object"); - m_action->setInterpreter(script.interpreter()); - m_action->setCode(script.script().toUtf8()); - m_action->trigger(); -} - -QRectF Sigmodr::TileItem::boundingRect() const -{ - return m_pixmap.rect(); -} - -void Sigmodr::TileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) -{ - Q_UNUSED(widget) - if (m_pixmap.isNull()) - return; - if (!(flags() & QGraphicsItem::ItemIsSelectable)) - { - QPixmap temp(m_pixmap.size()); - temp.fill(Qt::transparent); - QPainter p; - p.begin(&temp); - p.setCompositionMode(QPainter::CompositionMode_DestinationIn); - p.fillRect(temp.rect(), QColor(0, 0, 0, 127)); - p.end(); - painter->drawPixmap(0, 0, temp); - } - painter->drawPixmap(0, 0, m_pixmap); - if (option->state & QStyle::State_HasFocus) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::FocusColor).brush(QPalette::Active), 6)); - painter->drawRect(m_pixmap.rect()); - } - else if (option->state & QStyle::State_Selected) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::ActiveBackground).brush(QPalette::Active), 6)); - painter->drawRect(m_pixmap.rect()); - } - else if ((option->state & QStyle::State_MouseOver) && (flags() & QGraphicsItem::ItemIsSelectable)) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::HoverColor).brush(QPalette::Active), 6)); - painter->drawRect(m_pixmap.rect()); - } -} - -void Sigmodr::TileItem::setZIndex(const int zIndex) -{ - if (zIndex < INT_MAX) - m_tile->setZIndex(zIndex); -} - -void Sigmodr::TileItem::changeSprite(const int spriteId) -{ - const Sigmod::Sprite* sprite = m_tile->sigmod()->spriteById(spriteId); - if (sprite) - m_pixmap.loadFromData(sprite->sprite()); - update(); -} - -void Sigmodr::TileItem::mousePressEvent(QGraphicsSceneMouseEvent* event) -{ - QGraphicsItem::mousePressEvent(event); - update(); -} - -void Sigmodr::TileItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) -{ - QGraphicsItem::mouseMoveEvent(event); - m_tile->setPosition(scenePos().toPoint()); -} - -void Sigmodr::TileItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) -{ - QGraphicsItem::mouseReleaseEvent(event); - update(); -} - -void Sigmodr::TileItem::tileChanged() -{ - setPos(m_tile->position()); - setZValue(m_tile->zIndex()); - update(); -} diff --git a/sigmodr/TileItem.h b/sigmodr/TileItem.h deleted file mode 100644 index f1e312b4..00000000 --- a/sigmodr/TileItem.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2008 Ben Boeckel - * - * This program 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 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef SIGMODR_TILEITEM -#define SIGMODR_TILEITEM - -// Qt includes -#include - -// Forward declarations -namespace Sigmod -{ -class MapTile; -class Tile; -} -namespace Kross -{ -class Action; -} - -namespace Sigmodr -{ -class TileItem : public QObject, public QGraphicsItem -{ - Q_OBJECT - - public: - TileItem(Sigmod::MapTile* tile, QObject* parent); - - QRectF boundingRect() const; - - void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); - - void setZIndex(const int zIndex); - public slots: - void changeSprite(const int spriteId); - protected: - void mousePressEvent(QGraphicsSceneMouseEvent* event); - void mouseMoveEvent(QGraphicsSceneMouseEvent* event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); - protected slots: - void tileChanged(); - private: - QPixmap m_pixmap; - Kross::Action* m_action; - Sigmod::MapTile* m_tile; -}; -} - -#endif diff --git a/sigmodr/TrainerItem.cpp b/sigmodr/TrainerItem.cpp deleted file mode 100644 index 55da4d10..00000000 --- a/sigmodr/TrainerItem.cpp +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2008-2009 Ben Boeckel - * - * This program 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 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -// Header include -#include "TrainerItem.h" - -// Sigmod includes -#include "../sigmod/MapTrainer.h" -#include "../sigmod/Sigmod.h" -#include "../sigmod/Sprite.h" - -// KDE includes -#include - -// Qt includes -#include -#include -#include - -Sigmodr::TrainerItem::TrainerItem(Sigmod::MapTrainer* trainer, QObject* parent) : - QObject(parent), - m_trainer(trainer) -{ - connect(m_trainer, SIGNAL(changed()), this, SLOT(trainerChanged())); - trainerChanged(); - setZValue(INT_MAX); - setAcceptHoverEvents(true); -} - -QRectF Sigmodr::TrainerItem::boundingRect() const -{ - return m_pixmap.rect(); -} - -void Sigmodr::TrainerItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) -{ - Q_UNUSED(widget) - if (m_pixmap.isNull()) - return; - if (!(flags() & QGraphicsItem::ItemIsSelectable)) - { - QPixmap temp(m_pixmap.size()); - temp.fill(Qt::transparent); - QPainter p; - p.begin(&temp); - p.setCompositionMode(QPainter::CompositionMode_DestinationIn); - p.fillRect(temp.rect(), QColor(0, 0, 0, 127)); - p.end(); - painter->drawPixmap(0, 0, temp); - } - painter->drawPixmap(0, 0, m_pixmap); - if (option->state & QStyle::State_MouseOver) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::View, (flags() & QGraphicsItem::ItemIsSelectable) ? KColorScheme::ActiveText : KColorScheme::InactiveText).brush((flags() & QGraphicsItem::ItemIsSelectable) ? QPalette::Active : QPalette::Inactive), 1)); - painter->drawText(m_pixmap.rect(), Qt::AlignHCenter | Qt::AlignVCenter, m_trainer->name()); - } - if (option->state & QStyle::State_HasFocus) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::FocusColor).brush(QPalette::Active), 6)); - painter->drawRect(m_pixmap.rect()); - } - else if (option->state & QStyle::State_Selected) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::ActiveBackground).brush(QPalette::Active), 6)); - painter->drawRect(m_pixmap.rect()); - } - else if ((option->state & QStyle::State_MouseOver) && (flags() & QGraphicsItem::ItemIsSelectable)) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::HoverColor).brush(QPalette::Active), 6)); - painter->drawRect(m_pixmap.rect()); - } -} - -void Sigmodr::TrainerItem::changeSprite(const int spriteId) -{ - const Sigmod::Sprite* sprite = m_trainer->sigmod()->spriteById(spriteId); - if (sprite) - m_pixmap.loadFromData(sprite->sprite()); - update(); -} - -void Sigmodr::TrainerItem::mousePressEvent(QGraphicsSceneMouseEvent* event) -{ - QGraphicsItem::mousePressEvent(event); - update(); -} - -void Sigmodr::TrainerItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) -{ - QGraphicsItem::mouseMoveEvent(event); - m_trainer->setPosition(scenePos().toPoint()); -} - -void Sigmodr::TrainerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) -{ - QGraphicsItem::mouseReleaseEvent(event); - update(); -} - -void Sigmodr::TrainerItem::trainerChanged() -{ - setPos(m_trainer->position()); - update(); -} diff --git a/sigmodr/TrainerItem.h b/sigmodr/TrainerItem.h deleted file mode 100644 index 5733194b..00000000 --- a/sigmodr/TrainerItem.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2008 Ben Boeckel - * - * This program 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 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef SIGMODR_TRAINERITEM -#define SIGMODR_TRAINERITEM - -// Qt includes -#include - -// Forward declarations -namespace Sigmod -{ -class MapTrainer; -} - -namespace Sigmodr -{ -class TrainerItem : public QObject, public QGraphicsItem -{ - Q_OBJECT - - public: - TrainerItem(Sigmod::MapTrainer* trainer, QObject* parent); - - QRectF boundingRect() const; - - void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); - public slots: - void changeSprite(const int spriteId); - protected: - void mousePressEvent(QGraphicsSceneMouseEvent* event); - void mouseMoveEvent(QGraphicsSceneMouseEvent* event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); - protected slots: - void trainerChanged(); - private: - QPixmap m_pixmap; - Sigmod::MapTrainer* m_trainer; -}; -} - -#endif diff --git a/sigmodr/WarpItem.cpp b/sigmodr/WarpItem.cpp deleted file mode 100644 index bf1f2385..00000000 --- a/sigmodr/WarpItem.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2008 Ben Boeckel - * - * This program 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 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -// Header include -#include "WarpItem.h" - -// Sigmod includes -#include "../sigmod/MapWarp.h" -#include "../sigmod/Sigmod.h" - -// KDE includes -#include - -// Qt includes -#include -#include -#include -#include - -Sigmodr::WarpItem::WarpItem(Sigmod::MapWarp* warp, QObject* parent) : - QObject(parent), - m_warp(warp) -{ - connect(m_warp, SIGNAL(changed()), this, SLOT(warpChanged())); - warpChanged(); - setZValue(INT_MAX); - setAcceptHoverEvents(true); -} - -QRectF Sigmodr::WarpItem::boundingRect() const -{ - return m_warp->area(); -} - -void Sigmodr::WarpItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) -{ - Q_UNUSED(widget) - if (m_warp->area().size().isValid()) - return; - if (!(flags() & QGraphicsItem::ItemIsSelectable)) - { - QPixmap temp(m_warp->area().size()); - temp.fill(Qt::transparent); - QPainter p; - p.begin(&temp); - p.setCompositionMode(QPainter::CompositionMode_DestinationIn); - p.fillRect(temp.rect(), QColor(0, 0, 0, 127)); - p.end(); - painter->drawPixmap(0, 0, temp); - } - painter->setBrush(KStatefulBrush(KColorScheme::View, KColorScheme::ActiveBackground).brush(QPalette::Active)); - painter->drawRect(m_warp->area()); - if (option->state & QStyle::State_MouseOver) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::View, (flags() & QGraphicsItem::ItemIsSelectable) ? KColorScheme::ActiveText : KColorScheme::InactiveText).brush((flags() & QGraphicsItem::ItemIsSelectable) ? QPalette::Active : QPalette::Inactive), 1)); - painter->drawText(m_warp->area(), Qt::AlignHCenter | Qt::AlignVCenter, m_warp->name()); - } - if (option->state & QStyle::State_HasFocus) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::FocusColor).brush(QPalette::Active), 6)); - painter->drawRect(m_warp->area()); - } - else if (option->state & QStyle::State_Selected) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::ActiveBackground).brush(QPalette::Active), 6)); - painter->drawRect(m_warp->area()); - } - else if ((option->state & QStyle::State_MouseOver) && (flags() & QGraphicsItem::ItemIsSelectable)) - { - painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::HoverColor).brush(QPalette::Active), 6)); - painter->drawRect(m_warp->area()); - } -} - -void Sigmodr::WarpItem::mousePressEvent(QGraphicsSceneMouseEvent* event) -{ - QGraphicsItem::mousePressEvent(event); - update(); -} - -void Sigmodr::WarpItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) -{ - if (event->modifiers() & Qt::ShiftModifier) - { - QRect rect = m_warp->area(); - QPointF diff = event->scenePos() - event->lastScenePos(); - rect.setSize(rect.size() + QSize(diff.x(), diff.y())); - m_warp->setArea(rect); - } - else - { - QGraphicsItem::mouseMoveEvent(event); - QRect rect = m_warp->area(); - rect.setTopLeft(scenePos().toPoint()); - m_warp->setArea(rect); - } -} - -void Sigmodr::WarpItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) -{ - QGraphicsItem::mouseReleaseEvent(event); - update(); -} - -void Sigmodr::WarpItem::warpChanged() -{ - setPos(m_warp->area().topLeft()); - update(); -} diff --git a/sigmodr/WarpItem.h b/sigmodr/WarpItem.h deleted file mode 100644 index c9bf9eb2..00000000 --- a/sigmodr/WarpItem.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2008 Ben Boeckel - * - * This program 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 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see . - */ - -#ifndef SIGMODR_WARPITEM -#define SIGMODR_WARPITEM - -// Qt includes -#include - -// Forward declarations -namespace Sigmod -{ -class MapWarp; -} - -namespace Sigmodr -{ -class WarpItem : public QObject, public QGraphicsItem -{ - Q_OBJECT - - public: - WarpItem(Sigmod::MapWarp* warp, QObject* parent); - - QRectF boundingRect() const; - - void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); - protected: - void mousePressEvent(QGraphicsSceneMouseEvent* event); - void mouseMoveEvent(QGraphicsSceneMouseEvent* event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); - protected slots: - void warpChanged(); - private: - Sigmod::MapWarp* m_warp; -}; -} - -#endif diff --git a/sigmodr/widgets/EffectItem.cpp b/sigmodr/widgets/EffectItem.cpp new file mode 100644 index 00000000..e297ebb0 --- /dev/null +++ b/sigmodr/widgets/EffectItem.cpp @@ -0,0 +1,116 @@ +/* + * Copyright 2008-2009 Ben Boeckel + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +// Header include +#include "EffectItem.h" + +// Sigmod includes +#include "../sigmod/MapEffect.h" +#include "../sigmod/Sigmod.h" +#include "../sigmod/Sprite.h" + +// KDE includes +#include + +// Qt includes +#include +#include +#include + +Sigmodr::EffectItem::EffectItem(Sigmod::MapEffect* effect, QObject* parent) : + QObject(parent), + m_effect(effect) +{ + connect(m_effect, SIGNAL(changed()), this, SLOT(effectChanged())); + effectChanged(); + setZValue(INT_MAX); + setAcceptHoverEvents(true); +} + +QRectF Sigmodr::EffectItem::boundingRect() const +{ + return m_pixmap.rect(); +} + +void Sigmodr::EffectItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +{ + Q_UNUSED(widget) + if (!(flags() & QGraphicsItem::ItemIsSelectable)) + { + QPixmap temp(m_pixmap.size()); + temp.fill(Qt::transparent); + QPainter p; + p.begin(&temp); + p.setCompositionMode(QPainter::CompositionMode_DestinationIn); + p.fillRect(temp.rect(), QColor(0, 0, 0, 127)); + p.end(); + painter->drawPixmap(0, 0, temp); + } + painter->drawPixmap(0, 0, m_pixmap); + if (option->state & QStyle::State_MouseOver) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::View, (flags() & QGraphicsItem::ItemIsSelectable) ? KColorScheme::ActiveText : KColorScheme::InactiveText).brush((flags() & QGraphicsItem::ItemIsSelectable) ? QPalette::Active : QPalette::Inactive), 1)); + painter->drawText(m_pixmap.rect(), Qt::AlignHCenter | Qt::AlignVCenter, m_effect->name()); + } + if (option->state & QStyle::State_HasFocus) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::FocusColor).brush(QPalette::Active), 6)); + painter->drawRect(m_pixmap.rect()); + } + else if (option->state & QStyle::State_Selected) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::ActiveBackground).brush(QPalette::Active), 6)); + painter->drawRect(m_pixmap.rect()); + } + else if ((option->state & QStyle::State_MouseOver) && (flags() & QGraphicsItem::ItemIsSelectable)) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::HoverColor).brush(QPalette::Active), 6)); + painter->drawRect(m_pixmap.rect()); + } +} + +void Sigmodr::EffectItem::changeSprite(const int spriteId) +{ + const Sigmod::Sprite* sprite = m_effect->sigmod()->spriteById(spriteId); + if (sprite) + m_pixmap.loadFromData(sprite->sprite()); + update(); +} + +void Sigmodr::EffectItem::mousePressEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mousePressEvent(event); + update(); +} + +void Sigmodr::EffectItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mouseMoveEvent(event); + m_effect->setPosition(scenePos().toPoint()); +} + +void Sigmodr::EffectItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mouseReleaseEvent(event); + update(); +} + +void Sigmodr::EffectItem::effectChanged() +{ + setPos(m_effect->position()); + update(); +} diff --git a/sigmodr/widgets/EffectItem.h b/sigmodr/widgets/EffectItem.h new file mode 100644 index 00000000..b13ffda1 --- /dev/null +++ b/sigmodr/widgets/EffectItem.h @@ -0,0 +1,56 @@ +/* + * Copyright 2008 Ben Boeckel + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef SIGMODR_EFFECTITEM +#define SIGMODR_EFFECTITEM + +// Qt includes +#include + +// Forward declarations +namespace Sigmod +{ +class MapEffect; +} + +namespace Sigmodr +{ +class EffectItem : public QObject, public QGraphicsItem +{ + Q_OBJECT + + public: + EffectItem(Sigmod::MapEffect* effect, QObject* parent); + + QRectF boundingRect() const; + + void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); + public slots: + void changeSprite(const int spriteId); + protected: + void mousePressEvent(QGraphicsSceneMouseEvent* event); + void mouseMoveEvent(QGraphicsSceneMouseEvent* event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); + protected slots: + void effectChanged(); + private: + QPixmap m_pixmap; + Sigmod::MapEffect* m_effect; +}; +} + +#endif diff --git a/sigmodr/widgets/MapEditor.cpp b/sigmodr/widgets/MapEditor.cpp new file mode 100644 index 00000000..aeff1312 --- /dev/null +++ b/sigmodr/widgets/MapEditor.cpp @@ -0,0 +1,67 @@ +/* + * Copyright 2008 Ben Boeckel + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +// Header include +#include "MapEditor.h" + +// Sigmodr includes +#include "MapScene.h" + +// KDE includes +#include +#include + +// Qt includes +#include +#include + +Sigmodr::MapEditor::MapEditor(QWidget* parent) : + QWidget(parent) +{ + setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); + QGridLayout* layout = new QGridLayout; + m_view = new QGraphicsView; + m_view->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + layout->addWidget(m_view, 0, 0, 6, 1); + m_addTile = new KPushButton(KIcon("list-add"), "Add Tile"); + layout->addWidget(m_addTile, 0, 1, 1, 1); + m_removeTiles = new KPushButton(KIcon("list-remove"), "Remove Tiles"); + layout->addWidget(m_removeTiles, 1, 1, 1, 1); + m_moveToTop = new KPushButton(KIcon("arrow-up-double"), "Move to Top"); + layout->addWidget(m_moveToTop, 2, 1, 1, 1); + m_moveUp = new KPushButton(KIcon("arrow-up"), "Move Up"); + layout->addWidget(m_moveUp, 3, 1, 1, 1); + m_moveDown = new KPushButton(KIcon("arrow-down"), "Move Down"); + layout->addWidget(m_moveDown, 4, 1, 1, 1); + m_moveToBottom = new KPushButton(KIcon("arrow-down-double"), "Move to Bottom"); + layout->addWidget(m_moveToBottom, 5, 1, 1, 1); + setLayout(layout); +} + +void Sigmodr::MapEditor::setMap(Sigmod::Map* map) +{ + m_map = map; + m_scene = new MapScene(map, this); + connect(m_scene, SIGNAL(changed()), this, SIGNAL(changed())); + connect(m_addTile, SIGNAL(pressed()), m_scene, SLOT(addTile())); + connect(m_removeTiles, SIGNAL(pressed()), m_scene, SLOT(removeTiles())); + m_view->setScene(m_scene); +} + +void Sigmodr::MapEditor::reset() +{ +} diff --git a/sigmodr/widgets/MapEditor.h b/sigmodr/widgets/MapEditor.h new file mode 100644 index 00000000..4b6ba427 --- /dev/null +++ b/sigmodr/widgets/MapEditor.h @@ -0,0 +1,66 @@ +/* + * Copyright 2008-2009 Ben Boeckel + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef SIGMODR_MAPEDITOR +#define SIGMODR_MAPEDITOR + +// Qt includes +#include + +// Forward declarations +class QGraphicsView; +class KComboBox; +class KPushButton; +namespace Sigmod +{ +class Map; +} + +namespace Sigmodr +{ +class MapScene; + +class MapEditor : public QWidget +{ + Q_OBJECT + + public: + MapEditor(QWidget* parent); + + void setMap(Sigmod::Map* map); + + void reset(); + signals: + void changed(); + private: + Sigmod::Map* m_map; + MapScene* m_scene; + + QGraphicsView* m_view; + + KPushButton* m_addTile; + KPushButton* m_removeTiles; + KPushButton* m_moveToTop; + KPushButton* m_moveUp; + KPushButton* m_moveDown; + KPushButton* m_moveToBottom; + + KComboBox* m_types; +}; +} + +#endif diff --git a/sigmodr/widgets/MapScene.cpp b/sigmodr/widgets/MapScene.cpp new file mode 100644 index 00000000..c250deae --- /dev/null +++ b/sigmodr/widgets/MapScene.cpp @@ -0,0 +1,132 @@ +/* + * Copyright 2008 Ben Boeckel + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +// Header include +#include "MapScene.h" + +// Sigmodr includes +#include "EffectItem.h" +#include "TileItem.h" +#include "TrainerItem.h" +#include "WarpItem.h" + +// Sigmod includes +#include "../sigmod/Map.h" +#include "../sigmod/MapEffect.h" +#include "../sigmod/MapTile.h" +#include "../sigmod/MapTrainer.h" +#include "../sigmod/MapWarp.h" +#include "../sigmod/Tile.h" + +// KDE includes +#include +#include + +Sigmodr::MapScene::MapScene(Sigmod::Map* map, QObject* parent) : + QGraphicsScene(parent), + m_map(map) +{ + connect(this, SIGNAL(changed(QList)), this, SIGNAL(changed())); + for (int i = 0; i < m_map->effectCount(); ++i) + addItem(new EffectItem(m_map->effect(i), this)); + for (int i = 0; i < m_map->tileCount(); ++i) + addItem(new TileItem(m_map->tile(i), this)); + for (int i = 0; i < m_map->trainerCount(); ++i) + addItem(new TrainerItem(m_map->trainer(i), this)); + for (int i = 0; i < m_map->warpCount(); ++i) + addItem(new WarpItem(m_map->warp(i), this)); + typeChanged("Warps"); +} + +void Sigmodr::MapScene::addTile() +{ + KDialog* dialog = new KDialog; + dialog->setCaption("New Tile"); + KComboBox* combo = new KComboBox; + for (int i = 0; i < m_map->sigmod()->tileCount(); ++i) + combo->addItem(m_map->sigmod()->tile(i)->name()); + dialog->setMainWidget(combo); + if (dialog->exec() == KDialog::Ok) + { + Sigmod::MapTile* tile = m_map->newTile(); + tile->setTile(m_map->sigmod()->tile(combo->currentIndex())->id()); + TileItem* item = new TileItem(tile, this); + addItem(item); + m_tiles[tile] = item; + } + delete dialog; +} + +void Sigmodr::MapScene::removeTiles() +{ + QList items = selectedItems(); + foreach (QGraphicsItem* item, items) + { + if (m_effects.key(static_cast(item))) + { + Sigmod::MapEffect* effect = m_effects.key(static_cast(item)); + m_map->deleteEffectById(effect->id()); + delete m_effects[effect]; + m_effects.remove(effect); + } + else if (m_tiles.key(static_cast(item))) + { + Sigmod::MapTile* tile = m_tiles.key(static_cast(item)); + m_map->deleteTileById(tile->id()); + delete m_tiles[tile]; + m_tiles.remove(tile); + } + else if (m_trainers.key(static_cast(item))) + { + Sigmod::MapTrainer* trainer = m_trainers.key(static_cast(item)); + m_map->deleteTrainerById(trainer->id()); + delete m_trainers[trainer]; + m_trainers.remove(trainer); + } + else if (m_warps.key(static_cast(item))) + { + Sigmod::MapWarp* warp = m_warps.key(static_cast(item)); + m_map->deleteWarpById(warp->id()); + delete m_warps[warp]; + m_warps.remove(warp); + } + } +} + +void Sigmodr::MapScene::typeChanged(const QString& type) +{ + QGraphicsItem::GraphicsItemFlags effectFlags = 0; + QGraphicsItem::GraphicsItemFlags tileFlags = 0; + QGraphicsItem::GraphicsItemFlags trainerFlags = 0; + QGraphicsItem::GraphicsItemFlags warpFlags = 0; + if (type == "Effects") + effectFlags = QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable; + else if (type == "Tiles") + tileFlags = QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable; + else if (type == "Trainers") + trainerFlags = QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable; + else if (type == "Warps") + warpFlags = QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable; + foreach (EffectItem* effect, m_effects) + effect->setFlags(effectFlags); + foreach (TileItem* tile, m_tiles) + tile->setFlags(tileFlags); + foreach (TrainerItem* trainer, m_trainers) + trainer->setFlags(trainerFlags); + foreach (WarpItem* warp, m_warps) + warp->setFlags(warpFlags); +} diff --git a/sigmodr/widgets/MapScene.h b/sigmodr/widgets/MapScene.h new file mode 100644 index 00000000..e517183f --- /dev/null +++ b/sigmodr/widgets/MapScene.h @@ -0,0 +1,64 @@ +/* + * Copyright 2008 Ben Boeckel + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef SIGMODR_MAPSCENE +#define SIGMODR_MAPSCENE + +// Qt includes +#include +#include + +// Forward declarations +namespace Sigmod +{ +class Map; +class MapEffect; +class MapTile; +class MapTrainer; +class MapWarp; +} + +namespace Sigmodr +{ +class EffectItem; +class TileItem; +class TrainerItem; +class WarpItem; + +class MapScene : public QGraphicsScene +{ + Q_OBJECT + + public: + MapScene(Sigmod::Map* map, QObject* parent); + public slots: + void addTile(); + void removeTiles(); + + void typeChanged(const QString& type); + signals: + void changed(); + private: + Sigmod::Map* m_map; + QMap m_effects; + QMap m_tiles; + QMap m_trainers; + QMap m_warps; +}; +} + +#endif diff --git a/sigmodr/widgets/TileItem.cpp b/sigmodr/widgets/TileItem.cpp new file mode 100644 index 00000000..7ddaf885 --- /dev/null +++ b/sigmodr/widgets/TileItem.cpp @@ -0,0 +1,130 @@ +/* + * Copyright 2008 Ben Boeckel + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +// Header include +#include "TileItem.h" + +// Sigmod includes +#include "../sigmod/MapTile.h" +#include "../sigmod/Sigmod.h" +#include "../sigmod/Sprite.h" +#include "../sigmod/Tile.h" + +// Sigcore includes +#include "../sigcore/Script.h" + +// KDE includes +#include +#include + +// Qt includes +#include +#include +#include + +Sigmodr::TileItem::TileItem(Sigmod::MapTile* tile, QObject* parent) : + QObject(parent), + m_tile(tile) +{ + connect(m_tile, SIGNAL(changed()), this, SLOT(tileChanged())); + tileChanged(); + setAcceptHoverEvents(true); + Sigcore::Script script = m_tile->sigmod()->tileById(m_tile->tile())->script(); + m_action = new Kross::Action(this, QString("tile-%1").arg(m_tile->id())); + m_action->addObject(this, "object"); + m_action->setInterpreter(script.interpreter()); + m_action->setCode(script.script().toUtf8()); + m_action->trigger(); +} + +QRectF Sigmodr::TileItem::boundingRect() const +{ + return m_pixmap.rect(); +} + +void Sigmodr::TileItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +{ + Q_UNUSED(widget) + if (m_pixmap.isNull()) + return; + if (!(flags() & QGraphicsItem::ItemIsSelectable)) + { + QPixmap temp(m_pixmap.size()); + temp.fill(Qt::transparent); + QPainter p; + p.begin(&temp); + p.setCompositionMode(QPainter::CompositionMode_DestinationIn); + p.fillRect(temp.rect(), QColor(0, 0, 0, 127)); + p.end(); + painter->drawPixmap(0, 0, temp); + } + painter->drawPixmap(0, 0, m_pixmap); + if (option->state & QStyle::State_HasFocus) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::FocusColor).brush(QPalette::Active), 6)); + painter->drawRect(m_pixmap.rect()); + } + else if (option->state & QStyle::State_Selected) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::ActiveBackground).brush(QPalette::Active), 6)); + painter->drawRect(m_pixmap.rect()); + } + else if ((option->state & QStyle::State_MouseOver) && (flags() & QGraphicsItem::ItemIsSelectable)) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::HoverColor).brush(QPalette::Active), 6)); + painter->drawRect(m_pixmap.rect()); + } +} + +void Sigmodr::TileItem::setZIndex(const int zIndex) +{ + if (zIndex < INT_MAX) + m_tile->setZIndex(zIndex); +} + +void Sigmodr::TileItem::changeSprite(const int spriteId) +{ + const Sigmod::Sprite* sprite = m_tile->sigmod()->spriteById(spriteId); + if (sprite) + m_pixmap.loadFromData(sprite->sprite()); + update(); +} + +void Sigmodr::TileItem::mousePressEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mousePressEvent(event); + update(); +} + +void Sigmodr::TileItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mouseMoveEvent(event); + m_tile->setPosition(scenePos().toPoint()); +} + +void Sigmodr::TileItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mouseReleaseEvent(event); + update(); +} + +void Sigmodr::TileItem::tileChanged() +{ + setPos(m_tile->position()); + setZValue(m_tile->zIndex()); + update(); +} diff --git a/sigmodr/widgets/TileItem.h b/sigmodr/widgets/TileItem.h new file mode 100644 index 00000000..f1e312b4 --- /dev/null +++ b/sigmodr/widgets/TileItem.h @@ -0,0 +1,64 @@ +/* + * Copyright 2008 Ben Boeckel + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef SIGMODR_TILEITEM +#define SIGMODR_TILEITEM + +// Qt includes +#include + +// Forward declarations +namespace Sigmod +{ +class MapTile; +class Tile; +} +namespace Kross +{ +class Action; +} + +namespace Sigmodr +{ +class TileItem : public QObject, public QGraphicsItem +{ + Q_OBJECT + + public: + TileItem(Sigmod::MapTile* tile, QObject* parent); + + QRectF boundingRect() const; + + void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); + + void setZIndex(const int zIndex); + public slots: + void changeSprite(const int spriteId); + protected: + void mousePressEvent(QGraphicsSceneMouseEvent* event); + void mouseMoveEvent(QGraphicsSceneMouseEvent* event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); + protected slots: + void tileChanged(); + private: + QPixmap m_pixmap; + Kross::Action* m_action; + Sigmod::MapTile* m_tile; +}; +} + +#endif diff --git a/sigmodr/widgets/TrainerItem.cpp b/sigmodr/widgets/TrainerItem.cpp new file mode 100644 index 00000000..55da4d10 --- /dev/null +++ b/sigmodr/widgets/TrainerItem.cpp @@ -0,0 +1,118 @@ +/* + * Copyright 2008-2009 Ben Boeckel + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +// Header include +#include "TrainerItem.h" + +// Sigmod includes +#include "../sigmod/MapTrainer.h" +#include "../sigmod/Sigmod.h" +#include "../sigmod/Sprite.h" + +// KDE includes +#include + +// Qt includes +#include +#include +#include + +Sigmodr::TrainerItem::TrainerItem(Sigmod::MapTrainer* trainer, QObject* parent) : + QObject(parent), + m_trainer(trainer) +{ + connect(m_trainer, SIGNAL(changed()), this, SLOT(trainerChanged())); + trainerChanged(); + setZValue(INT_MAX); + setAcceptHoverEvents(true); +} + +QRectF Sigmodr::TrainerItem::boundingRect() const +{ + return m_pixmap.rect(); +} + +void Sigmodr::TrainerItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +{ + Q_UNUSED(widget) + if (m_pixmap.isNull()) + return; + if (!(flags() & QGraphicsItem::ItemIsSelectable)) + { + QPixmap temp(m_pixmap.size()); + temp.fill(Qt::transparent); + QPainter p; + p.begin(&temp); + p.setCompositionMode(QPainter::CompositionMode_DestinationIn); + p.fillRect(temp.rect(), QColor(0, 0, 0, 127)); + p.end(); + painter->drawPixmap(0, 0, temp); + } + painter->drawPixmap(0, 0, m_pixmap); + if (option->state & QStyle::State_MouseOver) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::View, (flags() & QGraphicsItem::ItemIsSelectable) ? KColorScheme::ActiveText : KColorScheme::InactiveText).brush((flags() & QGraphicsItem::ItemIsSelectable) ? QPalette::Active : QPalette::Inactive), 1)); + painter->drawText(m_pixmap.rect(), Qt::AlignHCenter | Qt::AlignVCenter, m_trainer->name()); + } + if (option->state & QStyle::State_HasFocus) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::FocusColor).brush(QPalette::Active), 6)); + painter->drawRect(m_pixmap.rect()); + } + else if (option->state & QStyle::State_Selected) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::ActiveBackground).brush(QPalette::Active), 6)); + painter->drawRect(m_pixmap.rect()); + } + else if ((option->state & QStyle::State_MouseOver) && (flags() & QGraphicsItem::ItemIsSelectable)) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::HoverColor).brush(QPalette::Active), 6)); + painter->drawRect(m_pixmap.rect()); + } +} + +void Sigmodr::TrainerItem::changeSprite(const int spriteId) +{ + const Sigmod::Sprite* sprite = m_trainer->sigmod()->spriteById(spriteId); + if (sprite) + m_pixmap.loadFromData(sprite->sprite()); + update(); +} + +void Sigmodr::TrainerItem::mousePressEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mousePressEvent(event); + update(); +} + +void Sigmodr::TrainerItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mouseMoveEvent(event); + m_trainer->setPosition(scenePos().toPoint()); +} + +void Sigmodr::TrainerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mouseReleaseEvent(event); + update(); +} + +void Sigmodr::TrainerItem::trainerChanged() +{ + setPos(m_trainer->position()); + update(); +} diff --git a/sigmodr/widgets/TrainerItem.h b/sigmodr/widgets/TrainerItem.h new file mode 100644 index 00000000..5733194b --- /dev/null +++ b/sigmodr/widgets/TrainerItem.h @@ -0,0 +1,56 @@ +/* + * Copyright 2008 Ben Boeckel + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef SIGMODR_TRAINERITEM +#define SIGMODR_TRAINERITEM + +// Qt includes +#include + +// Forward declarations +namespace Sigmod +{ +class MapTrainer; +} + +namespace Sigmodr +{ +class TrainerItem : public QObject, public QGraphicsItem +{ + Q_OBJECT + + public: + TrainerItem(Sigmod::MapTrainer* trainer, QObject* parent); + + QRectF boundingRect() const; + + void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); + public slots: + void changeSprite(const int spriteId); + protected: + void mousePressEvent(QGraphicsSceneMouseEvent* event); + void mouseMoveEvent(QGraphicsSceneMouseEvent* event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); + protected slots: + void trainerChanged(); + private: + QPixmap m_pixmap; + Sigmod::MapTrainer* m_trainer; +}; +} + +#endif diff --git a/sigmodr/widgets/WarpItem.cpp b/sigmodr/widgets/WarpItem.cpp new file mode 100644 index 00000000..bf1f2385 --- /dev/null +++ b/sigmodr/widgets/WarpItem.cpp @@ -0,0 +1,123 @@ +/* + * Copyright 2008 Ben Boeckel + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +// Header include +#include "WarpItem.h" + +// Sigmod includes +#include "../sigmod/MapWarp.h" +#include "../sigmod/Sigmod.h" + +// KDE includes +#include + +// Qt includes +#include +#include +#include +#include + +Sigmodr::WarpItem::WarpItem(Sigmod::MapWarp* warp, QObject* parent) : + QObject(parent), + m_warp(warp) +{ + connect(m_warp, SIGNAL(changed()), this, SLOT(warpChanged())); + warpChanged(); + setZValue(INT_MAX); + setAcceptHoverEvents(true); +} + +QRectF Sigmodr::WarpItem::boundingRect() const +{ + return m_warp->area(); +} + +void Sigmodr::WarpItem::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) +{ + Q_UNUSED(widget) + if (m_warp->area().size().isValid()) + return; + if (!(flags() & QGraphicsItem::ItemIsSelectable)) + { + QPixmap temp(m_warp->area().size()); + temp.fill(Qt::transparent); + QPainter p; + p.begin(&temp); + p.setCompositionMode(QPainter::CompositionMode_DestinationIn); + p.fillRect(temp.rect(), QColor(0, 0, 0, 127)); + p.end(); + painter->drawPixmap(0, 0, temp); + } + painter->setBrush(KStatefulBrush(KColorScheme::View, KColorScheme::ActiveBackground).brush(QPalette::Active)); + painter->drawRect(m_warp->area()); + if (option->state & QStyle::State_MouseOver) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::View, (flags() & QGraphicsItem::ItemIsSelectable) ? KColorScheme::ActiveText : KColorScheme::InactiveText).brush((flags() & QGraphicsItem::ItemIsSelectable) ? QPalette::Active : QPalette::Inactive), 1)); + painter->drawText(m_warp->area(), Qt::AlignHCenter | Qt::AlignVCenter, m_warp->name()); + } + if (option->state & QStyle::State_HasFocus) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::FocusColor).brush(QPalette::Active), 6)); + painter->drawRect(m_warp->area()); + } + else if (option->state & QStyle::State_Selected) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::ActiveBackground).brush(QPalette::Active), 6)); + painter->drawRect(m_warp->area()); + } + else if ((option->state & QStyle::State_MouseOver) && (flags() & QGraphicsItem::ItemIsSelectable)) + { + painter->setPen(QPen(KStatefulBrush(KColorScheme::Selection, KColorScheme::HoverColor).brush(QPalette::Active), 6)); + painter->drawRect(m_warp->area()); + } +} + +void Sigmodr::WarpItem::mousePressEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mousePressEvent(event); + update(); +} + +void Sigmodr::WarpItem::mouseMoveEvent(QGraphicsSceneMouseEvent* event) +{ + if (event->modifiers() & Qt::ShiftModifier) + { + QRect rect = m_warp->area(); + QPointF diff = event->scenePos() - event->lastScenePos(); + rect.setSize(rect.size() + QSize(diff.x(), diff.y())); + m_warp->setArea(rect); + } + else + { + QGraphicsItem::mouseMoveEvent(event); + QRect rect = m_warp->area(); + rect.setTopLeft(scenePos().toPoint()); + m_warp->setArea(rect); + } +} + +void Sigmodr::WarpItem::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) +{ + QGraphicsItem::mouseReleaseEvent(event); + update(); +} + +void Sigmodr::WarpItem::warpChanged() +{ + setPos(m_warp->area().topLeft()); + update(); +} diff --git a/sigmodr/widgets/WarpItem.h b/sigmodr/widgets/WarpItem.h new file mode 100644 index 00000000..c9bf9eb2 --- /dev/null +++ b/sigmodr/widgets/WarpItem.h @@ -0,0 +1,53 @@ +/* + * Copyright 2008 Ben Boeckel + * + * This program 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 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef SIGMODR_WARPITEM +#define SIGMODR_WARPITEM + +// Qt includes +#include + +// Forward declarations +namespace Sigmod +{ +class MapWarp; +} + +namespace Sigmodr +{ +class WarpItem : public QObject, public QGraphicsItem +{ + Q_OBJECT + + public: + WarpItem(Sigmod::MapWarp* warp, QObject* parent); + + QRectF boundingRect() const; + + void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0); + protected: + void mousePressEvent(QGraphicsSceneMouseEvent* event); + void mouseMoveEvent(QGraphicsSceneMouseEvent* event); + void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); + protected slots: + void warpChanged(); + private: + Sigmod::MapWarp* m_warp; +}; +} + +#endif -- cgit