RoomEditorWidget improvements
This commit is contained in:
@ -27,6 +27,9 @@ INCLUDEPATH += \
|
|||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/closeeventfilter.h \
|
src/closeeventfilter.h \
|
||||||
src/editor/dialogs/genericcodeeditordialog.h \
|
src/editor/dialogs/genericcodeeditordialog.h \
|
||||||
|
src/editor/editorguiutils.h \
|
||||||
|
src/editor/roomscene.h \
|
||||||
|
src/editor/widgets/draggabletreeview.h \
|
||||||
src/editor/widgets/qlineeditwithmenu.h \
|
src/editor/widgets/qlineeditwithmenu.h \
|
||||||
src/editor/widgets/qscrollareawithmenu.h \
|
src/editor/widgets/qscrollareawithmenu.h \
|
||||||
src/editor/widgets/roomeditwidget.h \
|
src/editor/widgets/roomeditwidget.h \
|
||||||
@ -81,6 +84,9 @@ HEADERS += \
|
|||||||
SOURCES += \
|
SOURCES += \
|
||||||
src/closeeventfilter.cpp \
|
src/closeeventfilter.cpp \
|
||||||
src/editor/dialogs/genericcodeeditordialog.cpp \
|
src/editor/dialogs/genericcodeeditordialog.cpp \
|
||||||
|
src/editor/editorguiutils.cpp \
|
||||||
|
src/editor/roomscene.cpp \
|
||||||
|
src/editor/widgets/draggabletreeview.cpp \
|
||||||
src/editor/widgets/qlineeditwithmenu.cpp \
|
src/editor/widgets/qlineeditwithmenu.cpp \
|
||||||
src/editor/widgets/qscrollareawithmenu.cpp \
|
src/editor/widgets/qscrollareawithmenu.cpp \
|
||||||
src/editor/widgets/roomeditwidget.cpp \
|
src/editor/widgets/roomeditwidget.cpp \
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
#include "projectcontainer.h"
|
#include "projectcontainer.h"
|
||||||
#include "models/projecttreemodel.h"
|
#include "models/projecttreemodel.h"
|
||||||
|
#include "roomscene.h"
|
||||||
|
#include "editorguiutils.h"
|
||||||
#include "genericcodeeditordialog.h"
|
#include "genericcodeeditordialog.h"
|
||||||
|
|
||||||
RoomPropertiesDialog::RoomPropertiesDialog(Room &room, ProjectTreeModel &projectModel, QWidget *parent) :
|
RoomPropertiesDialog::RoomPropertiesDialog(Room &room, ProjectTreeModel &projectModel, QWidget *parent) :
|
||||||
@ -17,6 +19,7 @@ RoomPropertiesDialog::RoomPropertiesDialog(Room &room, ProjectTreeModel &project
|
|||||||
m_ui{std::make_unique<Ui::RoomPropertiesDialog>()},
|
m_ui{std::make_unique<Ui::RoomPropertiesDialog>()},
|
||||||
m_room{room},
|
m_room{room},
|
||||||
m_projectModel{projectModel},
|
m_projectModel{projectModel},
|
||||||
|
m_scene{std::make_unique<RoomScene>(this)},
|
||||||
m_creationCode{m_room.creationCode},
|
m_creationCode{m_room.creationCode},
|
||||||
m_spinBoxSnapX{new QSpinBox{this}},
|
m_spinBoxSnapX{new QSpinBox{this}},
|
||||||
m_spinBoxSnapY{new QSpinBox{this}},
|
m_spinBoxSnapY{new QSpinBox{this}},
|
||||||
@ -34,6 +37,10 @@ RoomPropertiesDialog::RoomPropertiesDialog(Room &room, ProjectTreeModel &project
|
|||||||
m_ui->roomEditWidget->setSnapY(m_room.snapY);
|
m_ui->roomEditWidget->setSnapY(m_room.snapY);
|
||||||
m_ui->roomEditWidget->setGridEnabled(m_room.gridEnabled);
|
m_ui->roomEditWidget->setGridEnabled(m_room.gridEnabled);
|
||||||
m_ui->roomEditWidget->setIsometricGrid(m_room.isometricGrid);
|
m_ui->roomEditWidget->setIsometricGrid(m_room.isometricGrid);
|
||||||
|
m_ui->roomEditWidget->setProjectTreeModel(&m_projectModel);
|
||||||
|
|
||||||
|
m_ui->graphicsView->setScene(m_scene.get());
|
||||||
|
m_ui->graphicsView->setBackgroundBrush(makeGridBrush(16, 16, QPen{Qt::black}, Qt::white));
|
||||||
|
|
||||||
{
|
{
|
||||||
int index{11};
|
int index{11};
|
||||||
@ -352,6 +359,7 @@ void RoomPropertiesDialog::objectAboutToBeRemoved(const Object &object)
|
|||||||
m_selectedObject = nullptr;
|
m_selectedObject = nullptr;
|
||||||
m_ui->lineEditObject->clear();
|
m_ui->lineEditObject->clear();
|
||||||
m_ui->labelObjectPreview->setPixmap({});
|
m_ui->labelObjectPreview->setPixmap({});
|
||||||
|
m_ui->roomEditWidget->setSelectedObject(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomPropertiesDialog::objectSpriteNameChanged(const Object &object)
|
void RoomPropertiesDialog::objectSpriteNameChanged(const Object &object)
|
||||||
@ -416,6 +424,7 @@ void RoomPropertiesDialog::setObject(const Object &object)
|
|||||||
}
|
}
|
||||||
m_ui->labelObjectPreview->setPixmap(std::move(pixmap));
|
m_ui->labelObjectPreview->setPixmap(std::move(pixmap));
|
||||||
m_ui->lineEditObject->setText(object.name);
|
m_ui->lineEditObject->setText(object.name);
|
||||||
|
m_ui->roomEditWidget->setSelectedObject(&object);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomPropertiesDialog::updateTitle()
|
void RoomPropertiesDialog::updateTitle()
|
||||||
|
@ -12,6 +12,7 @@ struct Room;
|
|||||||
struct Sprite;
|
struct Sprite;
|
||||||
struct Object;
|
struct Object;
|
||||||
class ProjectTreeModel;
|
class ProjectTreeModel;
|
||||||
|
class RoomScene;
|
||||||
|
|
||||||
class RoomPropertiesDialog : public QDialog
|
class RoomPropertiesDialog : public QDialog
|
||||||
{
|
{
|
||||||
@ -55,6 +56,8 @@ private:
|
|||||||
Room &m_room;
|
Room &m_room;
|
||||||
ProjectTreeModel &m_projectModel;
|
ProjectTreeModel &m_projectModel;
|
||||||
|
|
||||||
|
const std::unique_ptr<RoomScene> m_scene;
|
||||||
|
|
||||||
QString m_creationCode;
|
QString m_creationCode;
|
||||||
|
|
||||||
bool m_unsavedChanges{};
|
bool m_unsavedChanges{};
|
||||||
|
@ -133,7 +133,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>683</width>
|
<width>419</width>
|
||||||
<height>333</height>
|
<height>333</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
@ -383,19 +383,35 @@
|
|||||||
<widget class="QWidget" name="layoutWidget">
|
<widget class="QWidget" name="layoutWidget">
|
||||||
<layout class="QVBoxLayout">
|
<layout class="QVBoxLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QScrollArea" name="scrollAreaRoom">
|
<widget class="QTabWidget" name="tabWidget_2">
|
||||||
<property name="alignment">
|
<property name="currentIndex">
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="RoomEditWidget" name="roomEditWidget">
|
<widget class="QScrollArea" name="scrollAreaRoom">
|
||||||
<property name="geometry">
|
<property name="widgetResizable">
|
||||||
<rect>
|
<bool>true</bool>
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>0</width>
|
|
||||||
<height>0</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
|
</property>
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Custom Widget</string>
|
||||||
|
</attribute>
|
||||||
|
<widget class="RoomEditWidget" name="roomEditWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>459</width>
|
||||||
|
<height>482</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<widget class="QGraphicsView" name="graphicsView">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>QGraphicsView</string>
|
||||||
|
</attribute>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
37
src/editor/editorguiutils.cpp
Normal file
37
src/editor/editorguiutils.cpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#include "editorguiutils.h"
|
||||||
|
|
||||||
|
#include <QBrush>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QPen>
|
||||||
|
#include <QColor>
|
||||||
|
|
||||||
|
QBrush makeGridBrush(int snapX, int snapY, const QPen &gridPen, const QColor &backgroundColor)
|
||||||
|
{
|
||||||
|
QPixmap pixmap{snapX, snapY};
|
||||||
|
pixmap.fill(backgroundColor);
|
||||||
|
|
||||||
|
{
|
||||||
|
QPainter painter{&pixmap};
|
||||||
|
painter.setPen(gridPen);
|
||||||
|
painter.drawLine(0, 0, snapX, 0);
|
||||||
|
painter.drawLine(0, 0, 0, snapY);
|
||||||
|
}
|
||||||
|
|
||||||
|
return QBrush{std::move(pixmap)};
|
||||||
|
}
|
||||||
|
|
||||||
|
QBrush makeGridBrush(int snapX, int snapY, const QColor &gridColor, const QColor &backgroundColor)
|
||||||
|
{
|
||||||
|
QPixmap pixmap{snapX, snapY};
|
||||||
|
pixmap.fill(backgroundColor);
|
||||||
|
|
||||||
|
{
|
||||||
|
QPainter painter{&pixmap};
|
||||||
|
painter.setPen(gridColor);
|
||||||
|
painter.drawLine(0, 0, snapX, 0);
|
||||||
|
painter.drawLine(0, 0, 0, snapY);
|
||||||
|
}
|
||||||
|
|
||||||
|
return QBrush{std::move(pixmap)};
|
||||||
|
}
|
8
src/editor/editorguiutils.h
Normal file
8
src/editor/editorguiutils.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class QBrush;
|
||||||
|
class QPen;
|
||||||
|
class QColor;
|
||||||
|
|
||||||
|
QBrush makeGridBrush(int snapX, int snapY, const QPen &gridPen, const QColor &backgroundColor);
|
||||||
|
QBrush makeGridBrush(int snapX, int snapY, const QColor &gridColor, const QColor &backgroundColor);
|
@ -17,13 +17,19 @@
|
|||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QTreeView" name="treeView">
|
<widget class="DraggableTreeView" name="treeView">
|
||||||
<property name="contextMenuPolicy">
|
<property name="contextMenuPolicy">
|
||||||
<enum>Qt::CustomContextMenu</enum>
|
<enum>Qt::CustomContextMenu</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="editTriggers">
|
<property name="editTriggers">
|
||||||
<set>QAbstractItemView::EditKeyPressed</set>
|
<set>QAbstractItemView::EditKeyPressed</set>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="dragEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="dragDropMode">
|
||||||
|
<enum>QAbstractItemView::DragDrop</enum>
|
||||||
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
<size>
|
<size>
|
||||||
<width>16</width>
|
<width>16</width>
|
||||||
@ -264,7 +270,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<action name="actionNew">
|
<action name="actionNew">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/new.png</normaloff>:/qtgameengine/icons/new.png</iconset>
|
<normaloff>:/qtgameengine/icons/new.png</normaloff>:/qtgameengine/icons/new.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -273,7 +279,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionOpen">
|
<action name="actionOpen">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/open.png</normaloff>:/qtgameengine/icons/open.png</iconset>
|
<normaloff>:/qtgameengine/icons/open.png</normaloff>:/qtgameengine/icons/open.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -282,7 +288,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionSave">
|
<action name="actionSave">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/save.png</normaloff>:/qtgameengine/icons/save.png</iconset>
|
<normaloff>:/qtgameengine/icons/save.png</normaloff>:/qtgameengine/icons/save.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -291,7 +297,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionSaveAs">
|
<action name="actionSaveAs">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/save-as.png</normaloff>:/qtgameengine/icons/save-as.png</iconset>
|
<normaloff>:/qtgameengine/icons/save-as.png</normaloff>:/qtgameengine/icons/save-as.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -300,7 +306,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionCreateExecutable">
|
<action name="actionCreateExecutable">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/create-executable.png</normaloff>:/qtgameengine/icons/create-executable.png</iconset>
|
<normaloff>:/qtgameengine/icons/create-executable.png</normaloff>:/qtgameengine/icons/create-executable.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -309,7 +315,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionPublishGame">
|
<action name="actionPublishGame">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/publish-game.png</normaloff>:/qtgameengine/icons/publish-game.png</iconset>
|
<normaloff>:/qtgameengine/icons/publish-game.png</normaloff>:/qtgameengine/icons/publish-game.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -318,7 +324,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionImportResources">
|
<action name="actionImportResources">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/import-resources.png</normaloff>:/qtgameengine/icons/import-resources.png</iconset>
|
<normaloff>:/qtgameengine/icons/import-resources.png</normaloff>:/qtgameengine/icons/import-resources.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -327,7 +333,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionExportResources">
|
<action name="actionExportResources">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/export-resources.png</normaloff>:/qtgameengine/icons/export-resources.png</iconset>
|
<normaloff>:/qtgameengine/icons/export-resources.png</normaloff>:/qtgameengine/icons/export-resources.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -347,7 +353,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionPreferences">
|
<action name="actionPreferences">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/preferences.png</normaloff>:/qtgameengine/icons/preferences.png</iconset>
|
<normaloff>:/qtgameengine/icons/preferences.png</normaloff>:/qtgameengine/icons/preferences.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -359,7 +365,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionExit">
|
<action name="actionExit">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/exit.png</normaloff>:/qtgameengine/icons/exit.png</iconset>
|
<normaloff>:/qtgameengine/icons/exit.png</normaloff>:/qtgameengine/icons/exit.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -379,7 +385,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionCreate">
|
<action name="actionCreate">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/create.png</normaloff>:/qtgameengine/icons/create.png</iconset>
|
<normaloff>:/qtgameengine/icons/create.png</normaloff>:/qtgameengine/icons/create.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -388,7 +394,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionDuplicate">
|
<action name="actionDuplicate">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/duplicate.png</normaloff>:/qtgameengine/icons/duplicate.png</iconset>
|
<normaloff>:/qtgameengine/icons/duplicate.png</normaloff>:/qtgameengine/icons/duplicate.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -400,7 +406,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionCreateGroup">
|
<action name="actionCreateGroup">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/create-group.png</normaloff>:/qtgameengine/icons/create-group.png</iconset>
|
<normaloff>:/qtgameengine/icons/create-group.png</normaloff>:/qtgameengine/icons/create-group.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -414,7 +420,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionDelete">
|
<action name="actionDelete">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/delete.png</normaloff>:/qtgameengine/icons/delete.png</iconset>
|
<normaloff>:/qtgameengine/icons/delete.png</normaloff>:/qtgameengine/icons/delete.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -423,7 +429,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionRename">
|
<action name="actionRename">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/rename.png</normaloff>:/qtgameengine/icons/rename.png</iconset>
|
<normaloff>:/qtgameengine/icons/rename.png</normaloff>:/qtgameengine/icons/rename.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -432,7 +438,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionProperties">
|
<action name="actionProperties">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/properties.png</normaloff>:/qtgameengine/icons/properties.png</iconset>
|
<normaloff>:/qtgameengine/icons/properties.png</normaloff>:/qtgameengine/icons/properties.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -444,7 +450,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionFindResource">
|
<action name="actionFindResource">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/find.png</normaloff>:/qtgameengine/icons/find.png</iconset>
|
<normaloff>:/qtgameengine/icons/find.png</normaloff>:/qtgameengine/icons/find.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -463,7 +469,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionShowObjectInformation">
|
<action name="actionShowObjectInformation">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/object-file.png</normaloff>:/qtgameengine/icons/object-file.png</iconset>
|
<normaloff>:/qtgameengine/icons/object-file.png</normaloff>:/qtgameengine/icons/object-file.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -472,7 +478,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionCreateSprite">
|
<action name="actionCreateSprite">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/sprite.png</normaloff>:/qtgameengine/icons/sprite.png</iconset>
|
<normaloff>:/qtgameengine/icons/sprite.png</normaloff>:/qtgameengine/icons/sprite.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -484,7 +490,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionCreateSound">
|
<action name="actionCreateSound">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/sound.png</normaloff>:/qtgameengine/icons/sound.png</iconset>
|
<normaloff>:/qtgameengine/icons/sound.png</normaloff>:/qtgameengine/icons/sound.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -496,7 +502,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionCreateBackground">
|
<action name="actionCreateBackground">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/background.png</normaloff>:/qtgameengine/icons/background.png</iconset>
|
<normaloff>:/qtgameengine/icons/background.png</normaloff>:/qtgameengine/icons/background.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -508,7 +514,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionCreatePath">
|
<action name="actionCreatePath">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/path.png</normaloff>:/qtgameengine/icons/path.png</iconset>
|
<normaloff>:/qtgameengine/icons/path.png</normaloff>:/qtgameengine/icons/path.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -520,7 +526,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionCreateScript">
|
<action name="actionCreateScript">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/script.png</normaloff>:/qtgameengine/icons/script.png</iconset>
|
<normaloff>:/qtgameengine/icons/script.png</normaloff>:/qtgameengine/icons/script.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -532,7 +538,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionCreateFont">
|
<action name="actionCreateFont">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/font.png</normaloff>:/qtgameengine/icons/font.png</iconset>
|
<normaloff>:/qtgameengine/icons/font.png</normaloff>:/qtgameengine/icons/font.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -544,7 +550,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionCreateTimeLine">
|
<action name="actionCreateTimeLine">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/timeline.png</normaloff>:/qtgameengine/icons/timeline.png</iconset>
|
<normaloff>:/qtgameengine/icons/timeline.png</normaloff>:/qtgameengine/icons/timeline.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -556,7 +562,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionCreateObject">
|
<action name="actionCreateObject">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/object.png</normaloff>:/qtgameengine/icons/object.png</iconset>
|
<normaloff>:/qtgameengine/icons/object.png</normaloff>:/qtgameengine/icons/object.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -568,7 +574,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionCreateRoom">
|
<action name="actionCreateRoom">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/room.png</normaloff>:/qtgameengine/icons/room.png</iconset>
|
<normaloff>:/qtgameengine/icons/room.png</normaloff>:/qtgameengine/icons/room.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -580,7 +586,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionGameInformation">
|
<action name="actionGameInformation">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/game-information.png</normaloff>:/qtgameengine/icons/game-information.png</iconset>
|
<normaloff>:/qtgameengine/icons/game-information.png</normaloff>:/qtgameengine/icons/game-information.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -592,7 +598,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionGlobalGameSettings">
|
<action name="actionGlobalGameSettings">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/global-game-settings.png</normaloff>:/qtgameengine/icons/global-game-settings.png</iconset>
|
<normaloff>:/qtgameengine/icons/global-game-settings.png</normaloff>:/qtgameengine/icons/global-game-settings.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -604,7 +610,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionExtensionPackages">
|
<action name="actionExtensionPackages">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/extension-packages.png</normaloff>:/qtgameengine/icons/extension-packages.png</iconset>
|
<normaloff>:/qtgameengine/icons/extension-packages.png</normaloff>:/qtgameengine/icons/extension-packages.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -616,7 +622,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionDefineConstants">
|
<action name="actionDefineConstants">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/constants.png</normaloff>:/qtgameengine/icons/constants.png</iconset>
|
<normaloff>:/qtgameengine/icons/constants.png</normaloff>:/qtgameengine/icons/constants.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -644,7 +650,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionRunNormally">
|
<action name="actionRunNormally">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/run.png</normaloff>:/qtgameengine/icons/run.png</iconset>
|
<normaloff>:/qtgameengine/icons/run.png</normaloff>:/qtgameengine/icons/run.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -656,7 +662,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionRunInDebugMode">
|
<action name="actionRunInDebugMode">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/debug.png</normaloff>:/qtgameengine/icons/debug.png</iconset>
|
<normaloff>:/qtgameengine/icons/debug.png</normaloff>:/qtgameengine/icons/debug.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -673,7 +679,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionContents">
|
<action name="actionContents">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/help.png</normaloff>:/qtgameengine/icons/help.png</iconset>
|
<normaloff>:/qtgameengine/icons/help.png</normaloff>:/qtgameengine/icons/help.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -783,7 +789,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionTile">
|
<action name="actionTile">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/tile.png</normaloff>:/qtgameengine/icons/tile.png</iconset>
|
<normaloff>:/qtgameengine/icons/tile.png</normaloff>:/qtgameengine/icons/tile.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -792,7 +798,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionCascade">
|
<action name="actionCascade">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../resources_editor.qrc">
|
<iconset resource="resources_editor.qrc">
|
||||||
<normaloff>:/qtgameengine/icons/cascade.png</normaloff>:/qtgameengine/icons/cascade.png</iconset>
|
<normaloff>:/qtgameengine/icons/cascade.png</normaloff>:/qtgameengine/icons/cascade.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
@ -826,8 +832,15 @@
|
|||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>DraggableTreeView</class>
|
||||||
|
<extends>QTreeView</extends>
|
||||||
|
<header>widgets/draggabletreeview.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../../resources_editor.qrc"/>
|
<include location="resources_editor.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections>
|
<connections>
|
||||||
<connection>
|
<connection>
|
||||||
|
@ -273,12 +273,17 @@ Qt::ItemFlags ProjectTreeModel::flags(const QModelIndex &index) const
|
|||||||
case NodeType::TimeLine:
|
case NodeType::TimeLine:
|
||||||
case NodeType::Object:
|
case NodeType::Object:
|
||||||
case NodeType::Room:
|
case NodeType::Room:
|
||||||
flags |= Qt::ItemIsEditable;
|
flags |= Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Qt::DropActions ProjectTreeModel::supportedDropActions() const
|
||||||
|
{
|
||||||
|
return QAbstractItemModel::supportedDropActions() | Qt::MoveAction;
|
||||||
|
}
|
||||||
|
|
||||||
bool ProjectTreeModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
bool ProjectTreeModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
{
|
{
|
||||||
switch (const auto nodeType = this->nodeType(index))
|
switch (const auto nodeType = this->nodeType(index))
|
||||||
@ -314,6 +319,12 @@ bool ProjectTreeModel::insertRows(int row, int count, const QModelIndex &parent)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ProjectTreeModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
|
||||||
|
{
|
||||||
|
qDebug() << "called" << sourceParent << sourceRow << count << destinationParent << destinationChild;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool ProjectTreeModel::removeRows(int row, int count, const QModelIndex &parent)
|
bool ProjectTreeModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||||
{
|
{
|
||||||
if (auto result = removeRowsFor<Sprite>(row, count, parent)) return *result;
|
if (auto result = removeRowsFor<Sprite>(row, count, parent)) return *result;
|
||||||
|
@ -42,8 +42,10 @@ public:
|
|||||||
int columnCount(const QModelIndex &parent) const override;
|
int columnCount(const QModelIndex &parent) const override;
|
||||||
QVariant data(const QModelIndex &index, int role) const override;
|
QVariant data(const QModelIndex &index, int role) const override;
|
||||||
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
|
Qt::DropActions supportedDropActions() const override;
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
|
||||||
bool insertRows(int row, int count, const QModelIndex &parent) override;
|
bool insertRows(int row, int count, const QModelIndex &parent) override;
|
||||||
|
bool moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override;
|
||||||
bool removeRows(int row, int count, const QModelIndex &parent) override;
|
bool removeRows(int row, int count, const QModelIndex &parent) override;
|
||||||
|
|
||||||
ProjectContainer *project() { return m_project; }
|
ProjectContainer *project() { return m_project; }
|
||||||
|
7
src/editor/roomscene.cpp
Normal file
7
src/editor/roomscene.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "roomscene.h"
|
||||||
|
|
||||||
|
RoomScene::RoomScene(QObject *parent) :
|
||||||
|
QGraphicsScene{parent}
|
||||||
|
{
|
||||||
|
setSceneRect(QRectF{0, 0, 640, 480});
|
||||||
|
}
|
11
src/editor/roomscene.h
Normal file
11
src/editor/roomscene.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
|
||||||
|
class RoomScene : public QGraphicsScene
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit RoomScene(QObject *parent = nullptr);
|
||||||
|
};
|
51
src/editor/widgets/draggabletreeview.cpp
Normal file
51
src/editor/widgets/draggabletreeview.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include "draggabletreeview.h"
|
||||||
|
|
||||||
|
DraggableTreeView::DraggableTreeView(QWidget *parent) :
|
||||||
|
QTreeView{parent}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DraggableTreeView::dragMoveEvent(QDragMoveEvent *event)
|
||||||
|
{
|
||||||
|
setDropIndicatorShown(true);
|
||||||
|
//qDebug() << QStringList{"OnItem","AboveItem","BelowItem","OnViewport"}[dropIndicatorPosition()];
|
||||||
|
QTreeView::dragMoveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DraggableTreeView::dropEvent(QDropEvent *event)
|
||||||
|
{
|
||||||
|
bool dropOK = false;
|
||||||
|
DropIndicatorPosition dropIndicator = dropIndicatorPosition();
|
||||||
|
|
||||||
|
switch (dropIndicator)
|
||||||
|
{
|
||||||
|
case QAbstractItemView::AboveItem:
|
||||||
|
dropOK = true;
|
||||||
|
break;
|
||||||
|
case QAbstractItemView::BelowItem:
|
||||||
|
dropOK = true;
|
||||||
|
break;
|
||||||
|
case QAbstractItemView::OnItem:
|
||||||
|
dropOK = false;
|
||||||
|
break;
|
||||||
|
case QAbstractItemView::OnViewport:
|
||||||
|
dropOK = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(dropOK)
|
||||||
|
{
|
||||||
|
// Here, you need to manage yourself the case of dropping an item
|
||||||
|
}
|
||||||
|
setDropIndicatorShown(false); // hide the drop indicator once the drop is done
|
||||||
|
QTreeView::dropEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DraggableTreeView::paintEvent(QPaintEvent *event)
|
||||||
|
{
|
||||||
|
DropIndicatorPosition position = dropIndicatorPosition();
|
||||||
|
setDropIndicatorShown( position == QAbstractItemView::BelowItem || position == QAbstractItemView::AboveItem );
|
||||||
|
|
||||||
|
QTreeView::paintEvent(event);
|
||||||
|
|
||||||
|
setDropIndicatorShown( true );
|
||||||
|
}
|
15
src/editor/widgets/draggabletreeview.h
Normal file
15
src/editor/widgets/draggabletreeview.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QTreeView>
|
||||||
|
|
||||||
|
class DraggableTreeView : public QTreeView
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit DraggableTreeView(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||||
|
void dropEvent(QDropEvent *event) override;
|
||||||
|
void paintEvent(QPaintEvent *event) override;
|
||||||
|
};
|
@ -7,6 +7,8 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "editorguiutils.h"
|
||||||
|
|
||||||
PathPointsWidget::PathPointsWidget(QWidget *parent) :
|
PathPointsWidget::PathPointsWidget(QWidget *parent) :
|
||||||
QWidget{parent}
|
QWidget{parent}
|
||||||
{
|
{
|
||||||
@ -81,21 +83,10 @@ void PathPointsWidget::paintEvent(QPaintEvent *event)
|
|||||||
{
|
{
|
||||||
if (!m_gridBrush || m_gridBrush->snapX != m_snapX || m_gridBrush->snapY != m_snapY)
|
if (!m_gridBrush || m_gridBrush->snapX != m_snapX || m_gridBrush->snapY != m_snapY)
|
||||||
{
|
{
|
||||||
QPixmap pixmap{m_snapX, m_snapY};
|
|
||||||
|
|
||||||
{
|
|
||||||
QPainter painter{&pixmap};
|
|
||||||
painter.setPen(palette().color(m_gridRole));
|
|
||||||
painter.drawLine(0, 0, m_snapX, 0);
|
|
||||||
painter.drawLine(0, 0, 0, m_snapY);
|
|
||||||
|
|
||||||
painter.fillRect(1, 1, m_snapX - 1, m_snapY - 1, palette().color(backgroundRole()));
|
|
||||||
}
|
|
||||||
|
|
||||||
m_gridBrush = GridBrush {
|
m_gridBrush = GridBrush {
|
||||||
.snapX = m_snapX,
|
.snapX = m_snapX,
|
||||||
.snapY = m_snapY,
|
.snapY = m_snapY,
|
||||||
.brush = QBrush{std:: move(pixmap)}
|
.brush = makeGridBrush(m_snapX, m_snapY, palette().color(m_gridRole), palette().color(backgroundRole()))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,10 @@
|
|||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
|
||||||
|
#include "editorguiutils.h"
|
||||||
|
#include "models/projecttreemodel.h"
|
||||||
|
#include "projectcontainer.h"
|
||||||
|
|
||||||
RoomEditWidget::RoomEditWidget(QWidget *parent) :
|
RoomEditWidget::RoomEditWidget(QWidget *parent) :
|
||||||
QWidget{parent}
|
QWidget{parent}
|
||||||
{
|
{
|
||||||
@ -18,7 +22,8 @@ void RoomEditWidget::setSnapX(int snapX)
|
|||||||
if (m_snapX == snapX)
|
if (m_snapX == snapX)
|
||||||
return;
|
return;
|
||||||
emit snapXChanged(m_snapX = snapX);
|
emit snapXChanged(m_snapX = snapX);
|
||||||
update();
|
if (m_gridEnabled)
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomEditWidget::setSnapY(int snapY)
|
void RoomEditWidget::setSnapY(int snapY)
|
||||||
@ -26,7 +31,8 @@ void RoomEditWidget::setSnapY(int snapY)
|
|||||||
if (m_snapY == snapY)
|
if (m_snapY == snapY)
|
||||||
return;
|
return;
|
||||||
emit snapYChanged(m_snapY = snapY);
|
emit snapYChanged(m_snapY = snapY);
|
||||||
update();
|
if (m_gridEnabled)
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomEditWidget::setGridEnabled(bool gridEnabled)
|
void RoomEditWidget::setGridEnabled(bool gridEnabled)
|
||||||
@ -50,6 +56,17 @@ void RoomEditWidget::setGridRole(QPalette::ColorRole gridRole)
|
|||||||
if (gridRole == m_gridRole)
|
if (gridRole == m_gridRole)
|
||||||
return;
|
return;
|
||||||
m_gridRole = gridRole;
|
m_gridRole = gridRole;
|
||||||
|
if (m_gridEnabled)
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void RoomEditWidget::setSelectedObject(const Object *selectedObject)
|
||||||
|
{
|
||||||
|
if (m_selectedObject == selectedObject)
|
||||||
|
return;
|
||||||
|
if (m_draggedObject && &m_draggedObject->object.get() == m_selectedObject)
|
||||||
|
m_draggedObject = std::nullopt;
|
||||||
|
m_selectedObject = selectedObject;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,25 +74,16 @@ void RoomEditWidget::paintEvent(QPaintEvent *event)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
Q_UNUSED(event)
|
||||||
|
|
||||||
|
QWidget::paintEvent(event);
|
||||||
|
|
||||||
if (m_gridEnabled)
|
if (m_gridEnabled)
|
||||||
{
|
{
|
||||||
if (!m_gridBrush || m_gridBrush->snapX != m_snapX || m_gridBrush->snapY != m_snapY)
|
if (!m_gridBrush || m_gridBrush->snapX != m_snapX || m_gridBrush->snapY != m_snapY)
|
||||||
{
|
{
|
||||||
QPixmap pixmap{m_snapX, m_snapY};
|
|
||||||
|
|
||||||
{
|
|
||||||
QPainter painter{&pixmap};
|
|
||||||
painter.setPen(palette().color(m_gridRole));
|
|
||||||
painter.drawLine(0, 0, m_snapX, 0);
|
|
||||||
painter.drawLine(0, 0, 0, m_snapY);
|
|
||||||
|
|
||||||
painter.fillRect(1, 1, m_snapX - 1, m_snapY - 1, palette().color(backgroundRole()));
|
|
||||||
}
|
|
||||||
|
|
||||||
m_gridBrush = GridBrush {
|
m_gridBrush = GridBrush {
|
||||||
.snapX = m_snapX,
|
.snapX = m_snapX,
|
||||||
.snapY = m_snapY,
|
.snapY = m_snapY,
|
||||||
.brush = QBrush{std:: move(pixmap)}
|
.brush = makeGridBrush(m_snapX, m_snapY, palette().color(m_gridRole), Qt::transparent)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -83,17 +91,62 @@ void RoomEditWidget::paintEvent(QPaintEvent *event)
|
|||||||
m_gridBrush = std::nullopt;
|
m_gridBrush = std::nullopt;
|
||||||
|
|
||||||
QPainter painter{this};
|
QPainter painter{this};
|
||||||
painter.fillRect(rect(), m_gridBrush ? m_gridBrush->brush : palette().color(backgroundRole()));
|
|
||||||
|
if (m_draggedObject)
|
||||||
|
{
|
||||||
|
if (m_projectTreeModel)
|
||||||
|
{
|
||||||
|
QPixmap pixmap;
|
||||||
|
const auto &object = m_draggedObject->object.get();
|
||||||
|
if (!object.spriteName.isEmpty())
|
||||||
|
{
|
||||||
|
const auto iter = std::find_if(std::cbegin(m_projectTreeModel->project()->sprites), std::cend(m_projectTreeModel->project()->sprites),
|
||||||
|
[&object](const auto &sprite){ return object.spriteName == sprite.name; });
|
||||||
|
if (iter == std::cend(m_projectTreeModel->project()->sprites))
|
||||||
|
qWarning() << "invalid sprite" << object.spriteName;
|
||||||
|
else if (!iter->pixmaps.empty() && !iter->pixmaps.front().isNull())
|
||||||
|
pixmap = iter->pixmaps.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pixmap.isNull())
|
||||||
|
goto noPixmap;
|
||||||
|
|
||||||
|
painter.drawPixmap(m_draggedObject->pos, std::move(pixmap));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
noPixmap:
|
||||||
|
painter.drawRect(QRect{m_draggedObject->pos, QSize{64, 64}});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_gridBrush)
|
||||||
|
painter.fillRect(rect(), m_gridBrush->brush);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomEditWidget::mousePressEvent(QMouseEvent *event)
|
void RoomEditWidget::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
QWidget::mousePressEvent(event);
|
QWidget::mousePressEvent(event);
|
||||||
|
|
||||||
|
if (m_selectedObject)
|
||||||
|
{
|
||||||
|
m_draggedObject = DraggedObject {
|
||||||
|
.object = *m_selectedObject,
|
||||||
|
.pos = event->pos()
|
||||||
|
};
|
||||||
|
update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomEditWidget::mouseReleaseEvent(QMouseEvent *event)
|
void RoomEditWidget::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
QWidget::mouseReleaseEvent(event);
|
QWidget::mouseReleaseEvent(event);
|
||||||
|
|
||||||
|
if (m_draggedObject)
|
||||||
|
{
|
||||||
|
m_draggedObject = std::nullopt;
|
||||||
|
update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RoomEditWidget::mouseMoveEvent(QMouseEvent *event)
|
void RoomEditWidget::mouseMoveEvent(QMouseEvent *event)
|
||||||
@ -101,6 +154,16 @@ void RoomEditWidget::mouseMoveEvent(QMouseEvent *event)
|
|||||||
QWidget::mouseMoveEvent(event);
|
QWidget::mouseMoveEvent(event);
|
||||||
|
|
||||||
emit cursorMoved(snapPoint(event->pos()));
|
emit cursorMoved(snapPoint(event->pos()));
|
||||||
|
|
||||||
|
if (m_draggedObject)
|
||||||
|
{
|
||||||
|
const auto newPos = snapPoint(event->pos());
|
||||||
|
if (newPos != m_draggedObject->pos)
|
||||||
|
{
|
||||||
|
m_draggedObject->pos = newPos;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QPoint RoomEditWidget::snapPoint(const QPoint &point) const
|
QPoint RoomEditWidget::snapPoint(const QPoint &point) const
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
struct Object;
|
struct Object;
|
||||||
|
class ProjectTreeModel;
|
||||||
|
|
||||||
class RoomEditWidget : public QWidget
|
class RoomEditWidget : public QWidget
|
||||||
{
|
{
|
||||||
@ -33,8 +34,12 @@ public:
|
|||||||
QPalette::ColorRole gridRole() const { return m_gridRole; }
|
QPalette::ColorRole gridRole() const { return m_gridRole; }
|
||||||
void setGridRole(QPalette::ColorRole gridRole);
|
void setGridRole(QPalette::ColorRole gridRole);
|
||||||
|
|
||||||
|
ProjectTreeModel *projectTreeModel() { return m_projectTreeModel; }
|
||||||
|
const ProjectTreeModel *projectTreeModel() const { return m_projectTreeModel; }
|
||||||
|
void setProjectTreeModel(ProjectTreeModel *projectTreeModel) { m_projectTreeModel = projectTreeModel; update(); }
|
||||||
|
|
||||||
const Object *selectedObject() const { return m_selectedObject; }
|
const Object *selectedObject() const { return m_selectedObject; }
|
||||||
void setSelectedObject(const Object *object) { m_selectedObject = object; update(); }
|
void setSelectedObject(const Object *selectedObject);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void snapXChanged(int snapX);
|
void snapXChanged(int snapX);
|
||||||
@ -69,4 +74,12 @@ private:
|
|||||||
std::optional<GridBrush> m_gridBrush;
|
std::optional<GridBrush> m_gridBrush;
|
||||||
|
|
||||||
QPalette::ColorRole m_gridRole{QPalette::Dark};
|
QPalette::ColorRole m_gridRole{QPalette::Dark};
|
||||||
|
|
||||||
|
ProjectTreeModel *m_projectTreeModel{};
|
||||||
|
|
||||||
|
struct DraggedObject {
|
||||||
|
std::reference_wrapper<const Object> object;
|
||||||
|
QPoint pos;
|
||||||
|
};
|
||||||
|
std::optional<DraggedObject> m_draggedObject;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user