Skip to content

Commit

Permalink
Implement the Path editor. (#82)
Browse files Browse the repository at this point in the history
Extracts a view component from the room editor and uses it to create the path editor. Also installs it in the background editor.
  • Loading branch information
fundies authored and JoshDreamland committed Jan 10, 2020
1 parent ec88031 commit 4b0c8aa
Show file tree
Hide file tree
Showing 34 changed files with 1,783 additions and 389 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,12 @@ set(RGM_SOURCES
Components/Utility.cpp
Components/RecentFiles.cpp
Components/QMenuView.cpp
Widgets/AssetScrollAreaBackground.cpp
Widgets/BackgroundView.cpp
Widgets/CodeWidget.cpp
Widgets/StackedCodeWidget.cpp
Widgets/ColorPicker.cpp
Widgets/PathView.cpp
Widgets/RoomView.cpp
Widgets/AssetView.cpp
Plugins/RGMPlugin.cpp
Expand Down Expand Up @@ -101,10 +103,13 @@ set(RGM_HEADERS
Components/Utility.h
Components/QMenuView.h
Components/Logger.h
Widgets/AssetScrollArea.h
Widgets/AssetScrollAreaBackground.h
Widgets/BackgroundView.h
Widgets/CodeWidget.h
Widgets/StackedCodeWidget.h
Widgets/ColorPicker.h
Widgets/PathView.h
Widgets/RoomView.h
Widgets/AssetView.h
Plugins/RGMPlugin.h
Expand Down
18 changes: 9 additions & 9 deletions Editors/BackgroundEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

#include "gmx.h"

#include <QDebug>
#include <QDesktopServices>
#include <QPainter>
#include <QDebug>

using buffers::resources::Background;

Expand All @@ -21,6 +21,8 @@ BackgroundEditor::BackgroundEditor(ProtoModelPtr model, QWidget* parent)

connect(ui->actionSave, &QAction::triggered, this, &BaseEditor::OnSave);

ui->imagePreviewBackground->SetAssetView(ui->backgroundView);

ui->backgroundView->SetResourceModel(resMapper->GetModel());

resMapper->addMapping(ui->smoothCheckBox, Background::kSmoothEdgesFieldNumber);
Expand All @@ -43,15 +45,11 @@ void BackgroundEditor::dataChanged(const QModelIndex& topLeft, const QModelIndex
ui->backgroundView->update();
}

void BackgroundEditor::on_actionZoomIn_triggered() {
ui->backgroundView->SetZoom(ui->backgroundView->GetZoom() * 2);
}
void BackgroundEditor::on_actionZoomIn_triggered() { ui->imagePreviewBackground->ZoomIn(); }

void BackgroundEditor::on_actionZoomOut_triggered() {
ui->backgroundView->SetZoom(ui->backgroundView->GetZoom() / 2);
}
void BackgroundEditor::on_actionZoomOut_triggered() { ui->imagePreviewBackground->ZoomOut(); }

void BackgroundEditor::on_actionZoom_triggered() { ui->backgroundView->SetZoom(1); }
void BackgroundEditor::on_actionZoom_triggered() { ui->imagePreviewBackground->ResetZoom(); }

void BackgroundEditor::on_actionNewImage_triggered() {
QDialog dialog(this);
Expand Down Expand Up @@ -80,7 +78,9 @@ void BackgroundEditor::on_actionLoadImage_triggered() {
// QString newData = GetModelData(Background::kImageFieldNumber).toString();
// TODO: Copy data into our egm and reset the path
// SetModelData(Background::kImageFieldNumber, lastData);
} else qDebug() << "Failed to load gmx Background";
} else {
qDebug() << "Failed to load gmx Background";
}
} else {
// TODO: Copy data into our egm
SetModelData(Background::kImageFieldNumber, fName);
Expand Down
20 changes: 16 additions & 4 deletions Editors/BackgroundEditor.ui
Original file line number Diff line number Diff line change
Expand Up @@ -355,20 +355,20 @@
</layout>
</item>
<item>
<widget class="QScrollArea" name="imagePreview">
<widget class="AssetScrollArea" name="imagePreview">
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<widget class="QWidget" name="scrollAreaWidget">
<widget class="AssetScrollAreaBackground" name="imagePreviewBackground">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>426</width>
<height>311</height>
<width>446</width>
<height>314</height>
</rect>
</property>
<property name="autoFillBackground">
Expand Down Expand Up @@ -498,12 +498,24 @@
</action>
</widget>
<customwidgets>
<customwidget>
<class>AssetScrollArea</class>
<extends>QScrollArea</extends>
<header>Widgets/AssetScrollArea.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>BackgroundView</class>
<extends>QWidget</extends>
<header>Widgets/BackgroundView.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>AssetScrollAreaBackground</class>
<extends>QWidget</extends>
<header>Widgets/AssetScrollAreaBackground.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../images.qrc"/>
Expand Down
5 changes: 5 additions & 0 deletions Editors/BaseEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ BaseEditor::BaseEditor(ProtoModelPtr treeNodeModel, QWidget* parent)
resMapper->GetModel()->BackupModel(this);

connect(_model, &QAbstractItemModel::modelReset, [this]() { this->RebindSubModels(); });

connect(this, &BaseEditor::FocusGained, [=]() { hasFocus = true; });
connect(this, &BaseEditor::FocusLost, [=]() { hasFocus = false; });
}

void BaseEditor::closeEvent(QCloseEvent* event) {
Expand All @@ -38,6 +41,8 @@ void BaseEditor::closeEvent(QCloseEvent* event) {
event->accept();
}

bool BaseEditor::HasFocus() { return hasFocus; }

void BaseEditor::ReplaceBuffer(google::protobuf::Message* buffer) { resMapper->ReplaceBuffer(buffer); }

void BaseEditor::SetModelData(int index, const QVariant& value) {
Expand Down
7 changes: 6 additions & 1 deletion Editors/BaseEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ class BaseEditor : public QWidget {
public:
explicit BaseEditor(ProtoModelPtr treeNodeModel, QWidget *parent);

virtual void closeEvent(QCloseEvent *event);
void ReplaceBuffer(google::protobuf::Message *buffer);
void SetModelData(int index, const QVariant &value);
QVariant GetModelData(int index);
bool HasFocus();

signals:
void ResourceRenamed(TypeCase type, const QString &oldName, const QString &newName);
void FocusGained();
void FocusLost();

public slots:
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight,
Expand All @@ -35,9 +37,12 @@ class BaseEditor : public QWidget {
void OnSave();

protected:
virtual void closeEvent(QCloseEvent *event) override;

ModelMapper *nodeMapper;
ModelMapper *resMapper;
ProtoModelPtr _model;
bool hasFocus = false;
};

#endif // BASEEDTIOR_H

0 comments on commit 4b0c8aa

Please sign in to comment.