Initial commit with sources

This commit is contained in:
2022-01-09 06:42:13 +01:00
parent 3e58fa693d
commit b7784d3ad7
120 changed files with 8793 additions and 41 deletions

103
.gitignore vendored
View File

@ -1,52 +1,73 @@
# C++ objects and libs # This file is used to ignore files which are generated
*.slo # ----------------------------------------------------------------------------
*.lo
*.o *~
*.autosave
*.a *.a
*.la *.core
*.lai *.moc
*.o
*.obj
*.orig
*.rej
*.so *.so
*.so.* *.so.*
*.dll *_pch.h.cpp
*.dylib *_resource.rc
*.qm
# Qt-es .#*
object_script.*.Release *.*#
object_script.*.Debug core
*_plugin_import.cpp !core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache /.qmake.cache
/.qmake.stash /.qmake.stash
*.pro.user
*.pro.user.*
*.qbs.user
*.qbs.user.*
*.moc
moc_*.cpp
moc_*.h
qrc_*.cpp
ui_*.h
*.qmlc
*.jsc
Makefile*
*build-*
*.qm
*.prl
# Qt unit tests # qtcreator generated files
target_wrapper.* *.pro.user*
# QtCreator # xemacs temporary files
*.autosave *.flc
# QtCreator Qml # Vim temporary files
*.qmlproject.user .*.swp
*.qmlproject.user.*
# QtCreator CMake # Visual Studio generated files
CMakeLists.txt.user* *.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# QtCreator 4.8< compilation database # MinGW generated files
compile_commands.json *.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe
# QtCreator local machine specific files for imported projects
*creator.user*

60
QtGameMaker.pro Normal file
View File

@ -0,0 +1,60 @@
QT = core gui widgets multimedia
CONFIG += c++latest
QMAKE_CXXFLAGS += -std=c++23
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000
HEADERS += \
codeeditorwidget.h \
dialogs/fontpropertiesdialog.h \
dialogs/pathpropertiesdialog.h \
dialogs/scriptpropertiesdialog.h \
futurecpp.h \
jshighlighter.h \
mainwindow.h \
projectcontainer.h \
projecttreemodel.h \
dialogs/backgroundpropertiesdialog.h \
dialogs/editspritedialog.h \
dialogs/extensionpackagesdialog.h \
dialogs/gameinformationdialog.h \
dialogs/globalgamesettingsdialog.h \
dialogs/preferencesdialog.h \
dialogs/soundpropertiesdialog.h \
dialogs/spritepropertiesdialog.h
SOURCES += main.cpp \
codeeditorwidget.cpp \
dialogs/fontpropertiesdialog.cpp \
dialogs/pathpropertiesdialog.cpp \
dialogs/scriptpropertiesdialog.cpp \
jshighlighter.cpp \
mainwindow.cpp \
projectcontainer.cpp \
projecttreemodel.cpp \
dialogs/backgroundpropertiesdialog.cpp \
dialogs/editspritedialog.cpp \
dialogs/extensionpackagesdialog.cpp \
dialogs/gameinformationdialog.cpp \
dialogs/globalgamesettingsdialog.cpp \
dialogs/preferencesdialog.cpp \
dialogs/soundpropertiesdialog.cpp \
dialogs/spritepropertiesdialog.cpp
FORMS += \
dialogs/fontpropertiesdialog.ui \
dialogs/pathpropertiesdialog.ui \
dialogs/scriptpropertiesdialog.ui \
mainwindow.ui \
dialogs/backgroundpropertiesdialog.ui \
dialogs/editspritedialog.ui \
dialogs/extensionpackagesdialog.ui \
dialogs/gameinformationdialog.ui \
dialogs/globalgamesettingsdialog.ui \
dialogs/preferencesdialog.ui \
dialogs/soundpropertiesdialog.ui \
dialogs/spritepropertiesdialog.ui
RESOURCES += \
resources.qrc

120
codeeditorwidget.cpp Normal file
View File

@ -0,0 +1,120 @@
#include "codeeditorwidget.h"
#include <QPainter>
#include <QTextBlock>
CodeEditorWidget::CodeEditorWidget(QWidget *parent)
: QPlainTextEdit{parent}
{
lineNumberArea = new LineNumberArea(this);
connect(this, &CodeEditorWidget::blockCountChanged,
this, &CodeEditorWidget::updateLineNumberAreaWidth);
connect(this, &CodeEditorWidget::updateRequest,
this, &CodeEditorWidget::updateLineNumberArea);
connect(this, &CodeEditorWidget::cursorPositionChanged,
this, &CodeEditorWidget::highlightCurrentLine);
updateLineNumberAreaWidth(0);
highlightCurrentLine();
}
void CodeEditorWidget::updateLineNumberAreaWidth(int newBlockCount)
{
setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
}
int CodeEditorWidget::lineNumberAreaWidth()
{
int digits = 1;
int max = qMax(1, blockCount());
while (max >= 10)
{
max /= 10;
++digits;
}
int space = 3 + fontMetrics().horizontalAdvance(QLatin1Char('9')) * digits;
return std::max(space, 40);
}
void CodeEditorWidget::resizeEvent(QResizeEvent *e)
{
QPlainTextEdit::resizeEvent(e);
QRect cr = contentsRect();
lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
}
void CodeEditorWidget::updateLineNumberArea(const QRect &rect, int dy)
{
if (dy)
lineNumberArea->scroll(0, dy);
else
lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height());
if (rect.contains(viewport()->rect()))
updateLineNumberAreaWidth(0);
}
void CodeEditorWidget::highlightCurrentLine()
{
QList<QTextEdit::ExtraSelection> extraSelections;
if (!isReadOnly())
{
QTextEdit::ExtraSelection selection;
QColor lineColor = QColor(Qt::yellow).lighter(160);
selection.format.setBackground(lineColor);
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = textCursor();
selection.cursor.clearSelection();
extraSelections.append(selection);
}
setExtraSelections(extraSelections);
}
void CodeEditorWidget::lineNumberAreaPaintEvent(QPaintEvent *event)
{
QPainter painter(lineNumberArea);
painter.fillRect(event->rect(), Qt::lightGray);
QTextBlock block = firstVisibleBlock();
int blockNumber = block.blockNumber();
int top = qRound(blockBoundingGeometry(block).translated(contentOffset()).top());
int bottom = top + qRound(blockBoundingRect(block).height());
while (block.isValid() && top <= event->rect().bottom())
{
if (block.isVisible() && bottom >= event->rect().top())
{
QString number = QString::number(blockNumber + 1);
painter.setPen(Qt::black);
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
Qt::AlignRight, number);
}
block = block.next();
top = bottom;
bottom = top + qRound(blockBoundingRect(block).height());
++blockNumber;
}
}
LineNumberArea::LineNumberArea(CodeEditorWidget *editor) : QWidget(editor), codeEditor(editor)
{
}
QSize LineNumberArea::sizeHint() const
{
return QSize(codeEditor->lineNumberAreaWidth(), 0);
}
void LineNumberArea::paintEvent(QPaintEvent *event)
{
codeEditor->lineNumberAreaPaintEvent(event);
}

41
codeeditorwidget.h Normal file
View File

@ -0,0 +1,41 @@
#pragma once
#include <QPlainTextEdit>
class CodeEditorWidget : public QPlainTextEdit
{
Q_OBJECT
public:
explicit CodeEditorWidget(QWidget *parent = nullptr);
void lineNumberAreaPaintEvent(QPaintEvent *event);
int lineNumberAreaWidth();
protected:
void resizeEvent(QResizeEvent *event) override;
private slots:
void updateLineNumberAreaWidth(int newBlockCount);
void highlightCurrentLine();
void updateLineNumberArea(const QRect &rect, int dy);
private:
QWidget *lineNumberArea;
};
class LineNumberArea : public QWidget
{
Q_OBJECT
public:
LineNumberArea(CodeEditorWidget *editor);
QSize sizeHint() const override;
protected:
void paintEvent(QPaintEvent *event) override;
private:
CodeEditorWidget *codeEditor;
};

View File

@ -0,0 +1,104 @@
#include "backgroundpropertiesdialog.h"
#include "ui_backgroundpropertiesdialog.h"
#include <QFileDialog>
#include <QDebug>
#include <QMessageBox>
#include "projectcontainer.h"
BackgroundPropertiesDialog::BackgroundPropertiesDialog(Background &background, QWidget *parent) :
QDialog{parent},
m_ui{std::make_unique<Ui::BackgroundPropertiesDialog>()},
m_background{background}
{
m_ui->setupUi(this);
setWindowTitle(tr("Background Properties: %0").arg(m_background.name));
m_ui->lineEditName->setText(m_background.name);
m_ui->labelWidth->setText(tr("Width: %0").arg(m_background.pixmap.width()));
m_ui->labelHeight->setText(tr("Height: %0").arg(m_background.pixmap.height()));
m_ui->labelPreview->setPixmap(m_background.pixmap);
connect(m_ui->pushButtonLoad, &QAbstractButton::pressed,
this, &BackgroundPropertiesDialog::loadBackground);
connect(m_ui->pushButtonSave, &QAbstractButton::pressed,
this, &BackgroundPropertiesDialog::saveBackground);
connect(m_ui->pushButtonEdit, &QAbstractButton::pressed,
this, &BackgroundPropertiesDialog::editBackground);
connect(m_ui->lineEditName, &QLineEdit::textChanged,
this, &BackgroundPropertiesDialog::changed);
connect(m_ui->checkBoxTileset, &QCheckBox::stateChanged,
this, &BackgroundPropertiesDialog::changed);
}
BackgroundPropertiesDialog::~BackgroundPropertiesDialog() = default;
void BackgroundPropertiesDialog::accept()
{
if (m_background.name != m_ui->lineEditName->text())
{
QMessageBox::critical(this, tr("Not implemented"), tr("Changing the name is not yet implemented!"));
return;
}
// TODO
QDialog::accept();
}
void BackgroundPropertiesDialog::reject()
{
if (!m_unsavedChanges)
{
QDialog::reject();
return;
}
const auto result = QMessageBox::warning(
this,
tr("The Background has been modified."),
tr("Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
QMessageBox::Save
);
switch (result)
{
case QMessageBox::Save:
accept();
return;
case QMessageBox::Discard:
QDialog::reject();
return;
case QMessageBox::Cancel:
return;
default:
qWarning() << "unexpected dialog result" << result;
}
}
void BackgroundPropertiesDialog::loadBackground()
{
QFileDialog::getOpenFileName(this, tr("Open a Background Image..."));
}
void BackgroundPropertiesDialog::saveBackground()
{
QFileDialog::getSaveFileName(this, tr("Save a Background Image..."), m_background.name + ".png", tr("PNG Files (*.png)"));
}
void BackgroundPropertiesDialog::editBackground()
{
}
void BackgroundPropertiesDialog::changed()
{
if (!m_unsavedChanges)
{
setWindowTitle(tr("Background Properties: %0*").arg(m_background.name));
m_unsavedChanges = true;
}
}

View File

@ -0,0 +1,35 @@
#pragma once
#include <QDialog>
#include <QString>
#include <memory>
namespace Ui { class BackgroundPropertiesDialog; }
struct Background;
class BackgroundPropertiesDialog : public QDialog
{
Q_OBJECT
public:
explicit BackgroundPropertiesDialog(Background &background, QWidget *parent = nullptr);
~BackgroundPropertiesDialog();
void accept() override;
void reject() override;
private slots:
void loadBackground();
void saveBackground();
void editBackground();
void changed();
private:
const std::unique_ptr<Ui::BackgroundPropertiesDialog> m_ui;
Background &m_background;
bool m_unsavedChanges{};
};

View File

@ -0,0 +1,197 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BackgroundPropertiesDialog</class>
<widget class="QDialog" name="BackgroundPropertiesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>573</width>
<height>221</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="windowIcon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/dialogs/background-file.png</normaloff>:/qtgameengine/icons/dialogs/background-file.png</iconset>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelName">
<property name="text">
<string>Name:</string>
</property>
<property name="buddy">
<cstring>lineEditName</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditName">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="pushButtonLoad">
<property name="text">
<string>&amp;Load Background</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/open.png</normaloff>:/qtgameengine/icons/actions/open.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonSave">
<property name="text">
<string>&amp;Save Background</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/save.png</normaloff>:/qtgameengine/icons/actions/save.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonEdit">
<property name="text">
<string>&amp;Edit Background</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/buttons/edit.png</normaloff>:/qtgameengine/icons/buttons/edit.png</iconset>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="labelWidth">
<property name="text">
<string>Width:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelHeight">
<property name="text">
<string>Height:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBoxTileset">
<property name="text">
<string>&amp;Use as tile set</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButtonOk">
<property name="text">
<string>&amp;OK</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/buttons/ok.png</normaloff>:/qtgameengine/icons/buttons/ok.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QLabel" name="labelPreview">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>371</width>
<height>201</height>
</rect>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../resources.qrc"/>
</resources>
<connections>
<connection>
<sender>pushButtonOk</sender>
<signal>pressed()</signal>
<receiver>BackgroundPropertiesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>124</x>
<y>197</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>110</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,22 @@
#include "editspritedialog.h"
#include "ui_editspritedialog.h"
#include "projectcontainer.h"
EditSpriteDialog::EditSpriteDialog(Sprite &sprite, QWidget *parent) :
QDialog{parent},
m_ui{std::make_unique<Ui::EditSpriteDialog>()},
m_sprite{sprite}
{
m_ui->setupUi(this);
setWindowFlags(windowFlags()
& ~Qt::Dialog
| Qt::Window
| Qt::WindowMinimizeButtonHint
| Qt::WindowMaximizeButtonHint
| Qt::WindowCloseButtonHint);
setWindowTitle(tr("Sprite editor - %0").arg(m_sprite.name));
}
EditSpriteDialog::~EditSpriteDialog() = default;

View File

@ -0,0 +1,22 @@
#pragma once
#include <QDialog>
#include <memory>
namespace Ui { class EditSpriteDialog; }
struct Sprite;
class EditSpriteDialog : public QDialog
{
Q_OBJECT
public:
explicit EditSpriteDialog(Sprite &sprite, QWidget *parent = nullptr);
~EditSpriteDialog();
private:
const std::unique_ptr<Ui::EditSpriteDialog> m_ui;
Sprite &m_sprite;
};

206
dialogs/editspritedialog.ui Normal file
View File

@ -0,0 +1,206 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EditSpriteDialog</class>
<widget class="QDialog" name="EditSpriteDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>491</width>
<height>500</height>
</rect>
</property>
<property name="windowTitle">
<string>Sprite Editor</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1,0">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QMenuBar" name="menuBar">
<widget class="QMenu" name="menuFile">
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="actionNew"/>
<addaction name="actionCreateFromFile"/>
<addaction name="actionAddFromFile"/>
<addaction name="separator"/>
<addaction name="actionSaveAsPngFile"/>
<addaction name="separator"/>
<addaction name="actionCreateFromStrip"/>
<addaction name="actionAddFromStrip"/>
<addaction name="separator"/>
<addaction name="actionCloseSavingChanges"/>
</widget>
<widget class="QMenu" name="menuEdit">
<property name="title">
<string>&amp;Edit</string>
</property>
</widget>
<widget class="QMenu" name="menuTransform">
<property name="title">
<string>&amp;Transform</string>
</property>
</widget>
<widget class="QMenu" name="menuImages">
<property name="title">
<string>&amp;Images</string>
</property>
</widget>
<widget class="QMenu" name="menuAnimation">
<property name="title">
<string>&amp;Animation</string>
</property>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuTransform"/>
<addaction name="menuImages"/>
<addaction name="menuAnimation"/>
</widget>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QToolBar" name="toolBar">
<property name="movable">
<bool>false</bool>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="floatable">
<bool>false</bool>
</property>
<addaction name="actionCloseSavingChanges"/>
<addaction name="separator"/>
<addaction name="actionNew"/>
<addaction name="actionCreateFromFile"/>
<addaction name="actionAddFromFile"/>
<addaction name="actionSaveAsPngFile"/>
<addaction name="separator"/>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget" native="true"/>
</item>
<item>
<widget class="QStatusBar" name="statusBar"/>
</item>
</layout>
<action name="actionNew">
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/new.png</normaloff>:/qtgameengine/icons/actions/new.png</iconset>
</property>
<property name="text">
<string>&amp;New...</string>
</property>
</action>
<action name="actionCreateFromFile">
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/open.png</normaloff>:/qtgameengine/icons/actions/open.png</iconset>
</property>
<property name="text">
<string>&amp;Create from file...</string>
</property>
</action>
<action name="actionAddFromFile">
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/create-group.png</normaloff>:/qtgameengine/icons/actions/create-group.png</iconset>
</property>
<property name="text">
<string>&amp;Add from file...</string>
</property>
</action>
<action name="actionSaveAsPngFile">
<property name="text">
<string>&amp;Save as PNG File...</string>
</property>
</action>
<action name="actionCreateFromStrip">
<property name="text">
<string>Create from Strip...</string>
</property>
</action>
<action name="actionAddFromStrip">
<property name="text">
<string>Add from Stri&amp;p...</string>
</property>
</action>
<action name="actionCloseSavingChanges">
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/ok.png</normaloff>:/qtgameengine/icons/actions/ok.png</iconset>
</property>
<property name="text">
<string>Close Saving Changes</string>
</property>
</action>
</widget>
<resources>
<include location="../resources.qrc"/>
</resources>
<connections>
<connection>
<sender>actionCloseSavingChanges</sender>
<signal>triggered()</signal>
<receiver>EditSpriteDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>245</x>
<y>249</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,17 @@
#include "extensionpackagesdialog.h"
#include "ui_extensionpackagesdialog.h"
ExtensionPackagesDialog::ExtensionPackagesDialog(QWidget *parent) :
QDialog{parent},
m_ui{std::make_unique<Ui::ExtensionPackagesDialog>()}
{
m_ui->setupUi(this);
setWindowFlags(windowFlags()
& ~Qt::Dialog
| Qt::Window
| Qt::WindowMinimizeButtonHint
| Qt::WindowMaximizeButtonHint
| Qt::WindowCloseButtonHint);
}
ExtensionPackagesDialog::~ExtensionPackagesDialog() = default;

View File

@ -0,0 +1,19 @@
#pragma once
#include <QDialog>
#include <memory>
namespace Ui { class ExtensionPackagesDialog; }
class ExtensionPackagesDialog : public QDialog
{
Q_OBJECT
public:
explicit ExtensionPackagesDialog(QWidget *parent = nullptr);
~ExtensionPackagesDialog();
private:
const std::unique_ptr<Ui::ExtensionPackagesDialog> m_ui;
};

View File

@ -0,0 +1,212 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ExtensionPackagesDialog</class>
<widget class="QDialog" name="ExtensionPackagesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>461</height>
</rect>
</property>
<property name="windowTitle">
<string>Extension Packages</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,1,0">
<item>
<layout class="QGridLayout" name="gridLayout" columnminimumwidth="1,0,1">
<item row="1" column="0">
<widget class="QListView" name="listViewUsedPackages"/>
</item>
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="pushButtonLeft">
<property name="text">
<string>⬅️</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonRight">
<property name="text">
<string>➡️</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="0">
<widget class="QLabel" name="labelUsedPackages">
<property name="text">
<string>Used Packages:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QListView" name="listViewAvailablePackages"/>
</item>
<item row="0" column="2">
<widget class="QLabel" name="labelAvailablePackages">
<property name="text">
<string>Available Packages:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBoxInformation">
<property name="title">
<string>Information</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelAuthor">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Author:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelVersion">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Version:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelDate">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Date:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelLicense">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>License:</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="labelDescription">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Description:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_4">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_5">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ExtensionPackagesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>199</x>
<y>278</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>149</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ExtensionPackagesDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>199</x>
<y>278</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>149</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,144 @@
#include "fontpropertiesdialog.h"
#include "ui_fontpropertiesdialog.h"
#include <QDebug>
#include <QMessageBox>
#include "projectcontainer.h"
FontPropertiesDialog::FontPropertiesDialog(Font &font, QWidget *parent) :
QDialog{parent},
m_ui{std::make_unique<Ui::FontPropertiesDialog>()},
m_font{font}
{
m_ui->setupUi(this);
setWindowTitle(tr("Font Properties: %0").arg(m_font.name));
m_ui->lineEditName->setText(m_font.name);
m_ui->fontComboBox->setCurrentFont(m_font.font);
m_ui->spinBoxSize->setValue(m_font.font.pointSize());
m_ui->checkBoxBold->setChecked(m_font.font.bold());
m_ui->checkBoxItalic->setChecked(m_font.font.italic());
m_ui->spinBoxCharRangeFrom->setValue(m_font.range.from);
m_ui->spinBoxCharRangeTo->setValue(m_font.range.to);
m_ui->labelPreview->setFont(currentFont());
connect(m_ui->pushButtonNormal, &QAbstractButton::pressed,
this, &FontPropertiesDialog::normalRange);
connect(m_ui->pushButtonDigits, &QAbstractButton::pressed,
this, &FontPropertiesDialog::digitsRange);
connect(m_ui->pushButtonAll, &QAbstractButton::pressed,
this, &FontPropertiesDialog::allRange);
connect(m_ui->pushButtonLetters, &QAbstractButton::pressed,
this, &FontPropertiesDialog::lettersRange);
connect(m_ui->lineEditName, &QLineEdit::textChanged,
this, &FontPropertiesDialog::changed);
connect(m_ui->fontComboBox, &QFontComboBox::currentFontChanged,
this, &FontPropertiesDialog::changed);
connect(m_ui->spinBoxSize, &QSpinBox::valueChanged,
this, &FontPropertiesDialog::changed);
connect(m_ui->checkBoxBold, &QCheckBox::toggled,
this, &FontPropertiesDialog::changed);
connect(m_ui->checkBoxItalic, &QCheckBox::toggled,
this, &FontPropertiesDialog::changed);
connect(m_ui->spinBoxCharRangeFrom, &QSpinBox::valueChanged,
this, &FontPropertiesDialog::changed);
connect(m_ui->spinBoxCharRangeTo, &QSpinBox::valueChanged,
this, &FontPropertiesDialog::changed);
}
FontPropertiesDialog::~FontPropertiesDialog() = default;
void FontPropertiesDialog::accept()
{
if (m_font.name != m_ui->lineEditName->text())
{
QMessageBox::critical(this, tr("Not implemented"), tr("Changing the name is not yet implemented!"));
return;
}
m_font.font = currentFont();
m_font.range = {
.from = m_ui->spinBoxCharRangeFrom->value(),
.to = m_ui->spinBoxCharRangeTo->value(),
};
QDialog::accept();
}
void FontPropertiesDialog::reject()
{
if (!m_unsavedChanges)
{
QDialog::reject();
return;
}
const auto result = QMessageBox::warning(
this,
tr("The Font has been modified."),
tr("Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
QMessageBox::Save
);
switch (result)
{
case QMessageBox::Save:
accept();
return;
case QMessageBox::Discard:
QDialog::reject();
return;
case QMessageBox::Cancel:
return;
default:
qWarning() << "unexpected dialog result" << result;
}
}
void FontPropertiesDialog::normalRange()
{
m_ui->spinBoxCharRangeFrom->setValue(32);
m_ui->spinBoxCharRangeFrom->setValue(127);
}
void FontPropertiesDialog::digitsRange()
{
m_ui->spinBoxCharRangeFrom->setValue(48);
m_ui->spinBoxCharRangeFrom->setValue(57);
}
void FontPropertiesDialog::allRange()
{
m_ui->spinBoxCharRangeFrom->setValue(0);
m_ui->spinBoxCharRangeFrom->setValue(255);
}
void FontPropertiesDialog::lettersRange()
{
m_ui->spinBoxCharRangeFrom->setValue(65);
m_ui->spinBoxCharRangeFrom->setValue(122);
}
void FontPropertiesDialog::changed()
{
m_ui->labelPreview->setFont(currentFont());
if (!m_unsavedChanges)
{
setWindowTitle(tr("Font Properties: %0*").arg(m_font.name));
m_unsavedChanges = true;
}
}
QFont FontPropertiesDialog::currentFont() const
{
QFont font;
font.setFamily(m_ui->fontComboBox->currentFont().family());
font.setPointSize(m_ui->spinBoxSize->value());
font.setBold(m_ui->checkBoxBold->isChecked());
font.setItalic(m_ui->checkBoxItalic->isChecked());
return font;
}

View File

@ -0,0 +1,37 @@
#pragma once
#include <QDialog>
#include <memory>
namespace Ui { class FontPropertiesDialog; }
struct Font;
class FontPropertiesDialog : public QDialog
{
Q_OBJECT
public:
explicit FontPropertiesDialog(Font &font, QWidget *parent = nullptr);
~FontPropertiesDialog();
void accept() override;
void reject() override;
private slots:
void normalRange();
void digitsRange();
void allRange();
void lettersRange();
void changed();
private:
QFont currentFont() const;
const std::unique_ptr<Ui::FontPropertiesDialog> m_ui;
Font &m_font;
bool m_unsavedChanges{};
};

View File

@ -0,0 +1,258 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FontPropertiesDialog</class>
<widget class="QDialog" name="FontPropertiesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>338</width>
<height>451</height>
</rect>
</property>
<property name="windowTitle">
<string>Font Properties</string>
</property>
<property name="windowIcon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/dialogs/font-file.png</normaloff>:/qtgameengine/icons/dialogs/font-file.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelName">
<property name="text">
<string>Name:</string>
</property>
<property name="buddy">
<cstring>lineEditName</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditName"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelFont">
<property name="text">
<string>Font:</string>
</property>
<property name="buddy">
<cstring>fontComboBox</cstring>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="labelSize">
<property name="text">
<string>Size:</string>
</property>
<property name="buddy">
<cstring>spinBoxSize</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QFontComboBox" name="fontComboBox"/>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="spinBoxSize"/>
</item>
<item row="1" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Minimum</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="checkBoxBold">
<property name="text">
<string>Bold</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxItalic">
<property name="text">
<string>Italic</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBoxCharacterRange">
<property name="title">
<string>Character Range</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QLabel" name="labelTill">
<property name="text">
<string>till</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QSpinBox" name="spinBoxCharRangeFrom">
<property name="maximum">
<number>255</number>
</property>
<property name="value">
<number>32</number>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QSpinBox" name="spinBoxCharRangeTo">
<property name="maximum">
<number>255</number>
</property>
<property name="value">
<number>127</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="pushButtonNormal">
<property name="text">
<string>Normal</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="pushButtonDigits">
<property name="text">
<string>Digits</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="pushButtonAll">
<property name="text">
<string>All</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="pushButtonLetters">
<property name="text">
<string>Letters</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="labelPreview">
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="text">
<string>AaBbCcDd</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButtonOk">
<property name="text">
<string>&amp;OK</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/buttons/ok.png</normaloff>:/qtgameengine/icons/buttons/ok.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../resources.qrc"/>
</resources>
<connections>
<connection>
<sender>pushButtonOk</sender>
<signal>pressed()</signal>
<receiver>FontPropertiesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>168</x>
<y>428</y>
</hint>
<hint type="destinationlabel">
<x>168</x>
<y>225</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,17 @@
#include "gameinformationdialog.h"
#include "ui_gameinformationdialog.h"
GameInformationDialog::GameInformationDialog(QWidget *parent) :
QDialog{parent},
m_ui{std::make_unique<Ui::GameInformationDialog>()}
{
m_ui->setupUi(this);
setWindowFlags(windowFlags()
& ~Qt::Dialog
| Qt::Window
| Qt::WindowMinimizeButtonHint
| Qt::WindowMaximizeButtonHint
| Qt::WindowCloseButtonHint);
}
GameInformationDialog::~GameInformationDialog() = default;

View File

@ -0,0 +1,19 @@
#pragma once
#include <QDialog>
#include <memory>
namespace Ui { class GameInformationDialog; }
class GameInformationDialog : public QDialog
{
Q_OBJECT
public:
explicit GameInformationDialog(QWidget *parent = nullptr);
~GameInformationDialog();
private:
const std::unique_ptr<Ui::GameInformationDialog> m_ui;
};

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GameInformationDialog</class>
<widget class="QDialog" name="GameInformationDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Game Information</string>
</property>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,17 @@
#include "globalgamesettingsdialog.h"
#include "ui_globalgamesettingsdialog.h"
GlobalGameSettingsDialog::GlobalGameSettingsDialog(QWidget *parent) :
QDialog{parent},
m_ui{std::make_unique<Ui::GlobalGameSettingsDialog>()}
{
m_ui->setupUi(this);
setWindowFlags(windowFlags()
& ~Qt::Dialog
| Qt::Window
| Qt::WindowMinimizeButtonHint
| Qt::WindowMaximizeButtonHint
| Qt::WindowCloseButtonHint);
}
GlobalGameSettingsDialog::~GlobalGameSettingsDialog() = default;

View File

@ -0,0 +1,19 @@
#pragma once
#include <QDialog>
#include <memory>
namespace Ui { class GlobalGameSettingsDialog; }
class GlobalGameSettingsDialog : public QDialog
{
Q_OBJECT
public:
explicit GlobalGameSettingsDialog(QWidget *parent = nullptr);
~GlobalGameSettingsDialog();
private:
const std::unique_ptr<Ui::GlobalGameSettingsDialog> m_ui;
};

View File

@ -0,0 +1,268 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>GlobalGameSettingsDialog</class>
<widget class="QDialog" name="GlobalGameSettingsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>370</width>
<height>528</height>
</rect>
</property>
<property name="windowTitle">
<string>Global Game Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,0">
<item>
<widget class="QTabWidget" name="tabWidgetResolution">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tabGraphics">
<attribute name="title">
<string>Graphics</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QCheckBox" name="checkBoxFullscreen">
<property name="text">
<string>Start in full-screen mode</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="1,1">
<item>
<widget class="QGroupBox" name="groupBoxScaling">
<property name="title">
<string>Scaling</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QRadioButton" name="radioButtonFixedScale">
<property name="text">
<string>Fixed scale (in %)</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox">
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>100</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QRadioButton" name="radioButtonKeepAspectRatio">
<property name="text">
<string>Keep aspect ratio</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonFullScale">
<property name="text">
<string>Full scale</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBoxInterpolateColors">
<property name="text">
<string>Interpolate colors between pixels</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="labelColorOutsideRoom">
<property name="text">
<string>Color outside the room region:</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBoxAllowResize">
<property name="text">
<string>Allow the player to resize the game window</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxAlwaysOntop">
<property name="text">
<string>Let the game window always stay on top</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxNoBorder">
<property name="text">
<string>Don't draw a border in windowed mode</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxNoWindowButtons">
<property name="text">
<string>Don't show the buttons in the window caption</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxDisplayCursor">
<property name="text">
<string>Display the cursor</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxFreezeOnFocusLost">
<property name="text">
<string>Freeze the game when the form loses focus</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxDisableScreensavers">
<property name="text">
<string>Disable screensavers and power saving actions</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="tabResolution">
<attribute name="title">
<string>Resolution</string>
</attribute>
</widget>
<widget class="QWidget" name="tabOther">
<attribute name="title">
<string>Other</string>
</attribute>
</widget>
<widget class="QWidget" name="tabLoading">
<attribute name="title">
<string>Loading</string>
</attribute>
</widget>
<widget class="QWidget" name="tabErrors">
<attribute name="title">
<string>Errors</string>
</attribute>
</widget>
<widget class="QWidget" name="tabInfo">
<attribute name="title">
<string>Info</string>
</attribute>
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>GlobalGameSettingsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>184</x>
<y>506</y>
</hint>
<hint type="destinationlabel">
<x>184</x>
<y>263</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>GlobalGameSettingsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>184</x>
<y>506</y>
</hint>
<hint type="destinationlabel">
<x>184</x>
<y>263</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,92 @@
#include "pathpropertiesdialog.h"
#include "ui_pathpropertiesdialog.h"
#include <QDebug>
#include <QMessageBox>
#include "projectcontainer.h"
PathPropertiesDialog::PathPropertiesDialog(Path &path, QWidget *parent) :
QDialog{parent},
m_ui{std::make_unique<Ui::PathPropertiesDialog>()},
m_path{path},
m_labelX{new QLabel{tr("x: %0").arg(0)}},
m_labelY{new QLabel{tr("y: %0").arg(0)}},
m_labelArea{new QLabel{tr("Area: (%0,%1)->(%2,%3)").arg(0).arg(0).arg(0).arg(0)}}
{
m_ui->setupUi(this);
setWindowTitle(tr("Path Properties: %0").arg(m_path.name));
m_labelX->setFrameStyle(QFrame::Sunken);
m_ui->statusbar->addWidget(m_labelX, 1);
m_labelY->setFrameStyle(QFrame::Sunken);
m_ui->statusbar->addWidget(m_labelY, 1);
m_labelArea->setFrameStyle(QFrame::Sunken);
m_ui->statusbar->addWidget(m_labelArea, 4);
{
auto frame = new QFrame{this};
frame->setFrameStyle(QFrame::Sunken);
m_ui->statusbar->addPermanentWidget(frame, 2);
}
m_ui->lineEditName->setText(m_path.name);
connect(m_ui->lineEditName, &QLineEdit::textChanged,
this, &PathPropertiesDialog::changed);
}
PathPropertiesDialog::~PathPropertiesDialog() = default;
void PathPropertiesDialog::accept()
{
if (m_path.name != m_ui->lineEditName->text())
{
QMessageBox::critical(this, tr("Not implemented"), tr("Changing the name is not yet implemented!"));
return;
}
// TODO
QDialog::accept();
}
void PathPropertiesDialog::reject()
{
if (!m_unsavedChanges)
{
QDialog::reject();
return;
}
const auto result = QMessageBox::warning(
this,
tr("The Path has been modified."),
tr("Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
QMessageBox::Save
);
switch (result)
{
case QMessageBox::Save:
accept();
return;
case QMessageBox::Discard:
QDialog::reject();
return;
case QMessageBox::Cancel:
return;
default:
qWarning() << "unexpected dialog result" << result;
}
}
void PathPropertiesDialog::changed()
{
if (!m_unsavedChanges)
{
setWindowTitle(tr("Path Properties: %0*").arg(m_path.name));
m_unsavedChanges = true;
}
}

View File

@ -0,0 +1,35 @@
#pragma once
#include <QDialog>
#include <memory>
class QLabel;
namespace Ui { class PathPropertiesDialog; }
struct Path;
class PathPropertiesDialog : public QDialog
{
Q_OBJECT
public:
explicit PathPropertiesDialog(Path &path, QWidget *parent = nullptr);
~PathPropertiesDialog();
void accept() override;
void reject() override;
private slots:
void changed();
private:
const std::unique_ptr<Ui::PathPropertiesDialog> m_ui;
Path &m_path;
QLabel * const m_labelX;
QLabel * const m_labelY;
QLabel * const m_labelArea;
bool m_unsavedChanges{};
};

View File

@ -0,0 +1,333 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PathPropertiesDialog</class>
<widget class="QDialog" name="PathPropertiesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>728</width>
<height>449</height>
</rect>
</property>
<property name="windowTitle">
<string>Path Properties</string>
</property>
<property name="windowIcon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/dialogs/path-file.png</normaloff>:/qtgameengine/icons/dialogs/path-file.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,1">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::Panel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>toolBar</string>
</property>
<property name="movable">
<bool>false</bool>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<addaction name="actionOk"/>
<addaction name="separator"/>
<addaction name="actionUndo"/>
<addaction name="separator"/>
<addaction name="actionClear"/>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="labelName">
<property name="text">
<string>Name:</string>
</property>
<property name="buddy">
<cstring>lineEditName</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEditName"/>
</item>
</layout>
</item>
<item>
<widget class="QListView" name="listView">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelX">
<property name="text">
<string>X:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinBoxX"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelY">
<property name="text">
<string>Y:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBoxY"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labelSp">
<property name="text">
<string>sp:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="spinBox_3"/>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QPushButton" name="pushButtonAdd">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonInsert">
<property name="text">
<string>Insert</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonDelete">
<property name="text">
<string>Delete</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QGroupBox" name="groupBoxConnectionKind">
<property name="title">
<string>connection kind</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QRadioButton" name="radioButtonStraight">
<property name="text">
<string>Straight lines</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonSmooth">
<property name="text">
<string>Smooth curves</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="labelPrecision">
<property name="text">
<string>Precision:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinBoxPrecision"/>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QCheckBox" name="checkBoxClosed">
<property name="text">
<string>Closed</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_7" stretch="1,0">
<item>
<widget class="QWidget" name="widget" native="true"/>
</item>
<item>
<widget class="QStatusBar" name="statusbar"/>
</item>
</layout>
</item>
</layout>
</item>
</layout>
<action name="actionOk">
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/ok.png</normaloff>:/qtgameengine/icons/actions/ok.png</iconset>
</property>
<property name="text">
<string>OK</string>
</property>
<property name="toolTip">
<string>Close the form, saving the changes</string>
</property>
</action>
<action name="actionUndo">
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/undo.png</normaloff>:/qtgameengine/icons/actions/undo.png</iconset>
</property>
<property name="text">
<string>Undo</string>
</property>
<property name="toolTip">
<string>Undo the last changes in the path</string>
</property>
</action>
<action name="actionClear">
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/new.png</normaloff>:/qtgameengine/icons/actions/new.png</iconset>
</property>
<property name="text">
<string>Clear</string>
</property>
<property name="toolTip">
<string>Clear the path</string>
</property>
</action>
</widget>
<resources>
<include location="../resources.qrc"/>
</resources>
<connections>
<connection>
<sender>actionOk</sender>
<signal>triggered()</signal>
<receiver>PathPropertiesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>363</x>
<y>224</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,17 @@
#include "preferencesdialog.h"
#include "ui_preferencesdialog.h"
PreferencesDialog::PreferencesDialog(QWidget *parent) :
QDialog{parent},
m_ui{std::make_unique<Ui::PreferencesDialog>()}
{
m_ui->setupUi(this);
setWindowFlags(windowFlags()
& ~Qt::Dialog
| Qt::Window
| Qt::WindowMinimizeButtonHint
| Qt::WindowMaximizeButtonHint
| Qt::WindowCloseButtonHint);
}
PreferencesDialog::~PreferencesDialog() = default;

View File

@ -0,0 +1,19 @@
#pragma once
#include <QDialog>
#include <memory>
namespace Ui { class PreferencesDialog; }
class PreferencesDialog : public QDialog
{
Q_OBJECT
public:
explicit PreferencesDialog(QWidget *parent = nullptr);
~PreferencesDialog();
private:
const std::unique_ptr<Ui::PreferencesDialog> m_ui;
};

View File

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PreferencesDialog</class>
<widget class="QDialog" name="PreferencesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Preferences</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,0">
<item>
<widget class="QTabWidget" name="tabWidget">
<widget class="QWidget" name="tabGeneral">
<attribute name="title">
<string>General</string>
</attribute>
</widget>
<widget class="QWidget" name="tabForms">
<attribute name="title">
<string>Forms</string>
</attribute>
</widget>
<widget class="QWidget" name="tabScriptsAndCode">
<attribute name="title">
<string>Scripts and Code</string>
</attribute>
</widget>
<widget class="QWidget" name="tabEditors">
<attribute name="title">
<string>Editors</string>
</attribute>
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>PreferencesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>199</x>
<y>278</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>149</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>PreferencesDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>199</x>
<y>278</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>149</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,158 @@
#include "scriptpropertiesdialog.h"
#include "ui_scriptpropertiesdialog.h"
#include <QDebug>
#include <QFont>
#include <QLineEdit>
#include <QLabel>
#include <QTextBlock>
#include <QMessageBox>
#include "projectcontainer.h"
#include "jshighlighter.h"
ScriptPropertiesDialog::ScriptPropertiesDialog(Script &script, QWidget *parent) :
QDialog{parent},
m_ui{std::make_unique<Ui::ScriptPropertiesDialog>()},
m_script{script},
m_lineEditName{new QLineEdit{this}},
m_labelPosition{new QLabel{this}}
{
m_ui->setupUi(this);
setWindowTitle(tr("Script Properties: %0").arg(m_script.name));
{
auto label = new QLabel{tr("Name:"), this};
label->setBuddy(m_lineEditName);
m_ui->toolBar->addWidget(label);
}
m_lineEditName->setMaximumWidth(100);
m_ui->toolBar->addWidget(m_lineEditName);
m_labelPosition->setFrameStyle(QFrame::Sunken);
m_ui->statusbar->addWidget(m_labelPosition);
{
QFont font;
font.setFamily("Consolas");
font.setFixedPitch(true);
font.setPointSize(10);
m_ui->codeEdit->setFont(font);
}
new JSHighlighter{m_ui->codeEdit->document()};
m_lineEditName->setText(m_script.name);
m_ui->codeEdit->setPlainText(m_script.script);
updatePosition();
connect(m_ui->actionLoad, &QAction::triggered,
this, &ScriptPropertiesDialog::load);
connect(m_ui->actionSave, &QAction::triggered,
this, &ScriptPropertiesDialog::save);
connect(m_ui->actionPrint, &QAction::triggered,
this, &ScriptPropertiesDialog::print);
connect(m_lineEditName, &QLineEdit::textChanged,
this, &ScriptPropertiesDialog::changed);
connect(m_ui->codeEdit, &QPlainTextEdit::textChanged,
this, &ScriptPropertiesDialog::changed);
connect(m_ui->codeEdit, &QPlainTextEdit::textChanged,
this, &ScriptPropertiesDialog::updatePosition);
connect(m_ui->codeEdit, &QPlainTextEdit::cursorPositionChanged,
this, &ScriptPropertiesDialog::updatePosition);
}
ScriptPropertiesDialog::~ScriptPropertiesDialog() = default;
void ScriptPropertiesDialog::accept()
{
if (m_script.name != m_lineEditName->text())
{
QMessageBox::critical(this, tr("Not implemented"), tr("Changing the name is not yet implemented!"));
return;
}
m_script.script = m_ui->codeEdit->toPlainText();
QDialog::accept();
}
void ScriptPropertiesDialog::reject()
{
if (!m_unsavedChanges)
{
QDialog::reject();
return;
}
const auto result = QMessageBox::warning(
this,
tr("The Script has been modified."),
tr("Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
QMessageBox::Save
);
switch (result)
{
case QMessageBox::Save:
accept();
return;
case QMessageBox::Discard:
QDialog::reject();
return;
case QMessageBox::Cancel:
return;
default:
qWarning() << "unexpected dialog result" << result;
}
}
void ScriptPropertiesDialog::changed()
{
if (!m_unsavedChanges)
{
setWindowTitle(tr("Script Properties: %0*").arg(m_script.name));
m_unsavedChanges = true;
}
}
void ScriptPropertiesDialog::load()
{
}
void ScriptPropertiesDialog::save()
{
}
void ScriptPropertiesDialog::print()
{
}
void ScriptPropertiesDialog::updatePosition()
{
auto cursor = m_ui->codeEdit->textCursor();
auto position = cursor.position();
cursor.movePosition(QTextCursor::StartOfLine);
position -= cursor.position() - 1;
int lines = 1;
while (cursor.positionInBlock() > 0)
{
cursor.movePosition(QTextCursor::Up);
//lines++;
}
QTextBlock block = cursor.block().previous();
while (block.isValid())
{
lines += 1; //block.lineCount();
block = block.previous();
}
m_labelPosition->setText(tr("%0/%1: %2").arg(lines).arg(m_ui->codeEdit->blockCount()).arg(position));
}

View File

@ -0,0 +1,42 @@
#pragma once
#include <QDialog>
#include <memory>
class QLineEdit;
class QLabel;
namespace Ui { class ScriptPropertiesDialog; }
struct Script;
class ScriptPropertiesDialog : public QDialog
{
Q_OBJECT
public:
explicit ScriptPropertiesDialog(Script &script, QWidget *parent = nullptr);
~ScriptPropertiesDialog();
void accept() override;
void reject() override;
private slots:
void changed();
void load();
void save();
void print();
void updatePosition();
private:
const std::unique_ptr<Ui::ScriptPropertiesDialog> m_ui;
Script &m_script;
QLineEdit * const m_lineEditName;
QLabel * const m_labelPosition;
bool m_unsavedChanges{};
};

View File

@ -0,0 +1,568 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ScriptPropertiesDialog</class>
<widget class="QDialog" name="ScriptPropertiesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>540</width>
<height>497</height>
</rect>
</property>
<property name="windowTitle">
<string>Script Properties</string>
</property>
<property name="windowIcon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/dialogs/script-file.png</normaloff>:/qtgameengine/icons/dialogs/script-file.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,1">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QToolBar" name="toolBar">
<property name="windowTitle">
<string>toolBar</string>
</property>
<property name="movable">
<bool>false</bool>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<addaction name="actionOk"/>
<addaction name="separator"/>
<addaction name="actionLoad"/>
<addaction name="actionSave"/>
<addaction name="actionPrint"/>
<addaction name="separator"/>
<addaction name="actionUndo"/>
<addaction name="actionRedo"/>
<addaction name="separator"/>
<addaction name="actionCut"/>
<addaction name="actionCopy"/>
<addaction name="actionPaste"/>
<addaction name="separator"/>
<addaction name="actionFind"/>
<addaction name="separator"/>
<addaction name="actionCheck"/>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0">
<item>
<layout class="QVBoxLayout">
<item>
<widget class="CodeEditorWidget" name="codeEdit"/>
</item>
<item>
<widget class="QStatusBar" name="statusbar">
<property name="sizeGripEnabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widgetSearch" native="true">
<property name="visible">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0,0">
<item>
<widget class="QGroupBox" name="groupBoxFind">
<property name="title">
<string>Find</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QComboBox" name="comboBoxFind">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxCaseSensitive">
<property name="text">
<string>Case Sensitive</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxWholeWord">
<property name="text">
<string>Whole word only</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QPushButton" name="pushButtonFindFirst">
<property name="text">
<string>First</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="pushButtonFindPrev">
<property name="text">
<string>Previous</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pushButtonFindNext">
<property name="text">
<string>Next</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="pushButtonFindLast">
<property name="text">
<string>Last</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxReplace">
<property name="title">
<string>Replace</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QComboBox" name="comboBoxReplace">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QPushButton" name="pushButtonReplaceFirst">
<property name="text">
<string>First</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QPushButton" name="pushButtonReplacePrevious">
<property name="text">
<string>Previous</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="pushButtonReplaceNext">
<property name="text">
<string>Next</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="pushButtonReplaceLast">
<property name="text">
<string>Last</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="pushButtonReplaceAll">
<property name="text">
<string>Replace All</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
<action name="actionOk">
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/ok.png</normaloff>:/qtgameengine/icons/actions/ok.png</iconset>
</property>
<property name="text">
<string>OK</string>
</property>
</action>
<action name="actionLoad">
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/open.png</normaloff>:/qtgameengine/icons/actions/open.png</iconset>
</property>
<property name="text">
<string>Load</string>
</property>
<property name="toolTip">
<string>Load the code from a text file</string>
</property>
</action>
<action name="actionSave">
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/save.png</normaloff>:/qtgameengine/icons/actions/save.png</iconset>
</property>
<property name="text">
<string>Save</string>
</property>
<property name="toolTip">
<string>Save the code to a text file</string>
</property>
</action>
<action name="actionPrint">
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/print.png</normaloff>:/qtgameengine/icons/actions/print.png</iconset>
</property>
<property name="text">
<string>Print</string>
</property>
<property name="toolTip">
<string>Print the code</string>
</property>
</action>
<action name="actionUndo">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/undo.png</normaloff>:/qtgameengine/icons/actions/undo.png</iconset>
</property>
<property name="text">
<string>Undo</string>
</property>
<property name="toolTip">
<string>Undo the last change</string>
</property>
</action>
<action name="actionRedo">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/redo.png</normaloff>:/qtgameengine/icons/actions/redo.png</iconset>
</property>
<property name="text">
<string>Redo</string>
</property>
<property name="toolTip">
<string>Redo the last undo</string>
</property>
</action>
<action name="actionCut">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/cut.png</normaloff>:/qtgameengine/icons/actions/cut.png</iconset>
</property>
<property name="text">
<string>Cut</string>
</property>
<property name="toolTip">
<string>Cut the selected text into clipboard</string>
</property>
</action>
<action name="actionCopy">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/copy.png</normaloff>:/qtgameengine/icons/actions/copy.png</iconset>
</property>
<property name="text">
<string>Copy</string>
</property>
<property name="toolTip">
<string>Copy the selected text to the clipboard</string>
</property>
</action>
<action name="actionPaste">
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/paste.png</normaloff>:/qtgameengine/icons/actions/paste.png</iconset>
</property>
<property name="text">
<string>Paste</string>
</property>
<property name="toolTip">
<string>Paste the text from the clipboard</string>
</property>
</action>
<action name="actionFind">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/find.png</normaloff>:/qtgameengine/icons/actions/find.png</iconset>
</property>
<property name="text">
<string>Find</string>
</property>
<property name="toolTip">
<string>Show the find and replace panel</string>
</property>
</action>
<action name="actionCheck">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/check.png</normaloff>:/qtgameengine/icons/actions/check.png</iconset>
</property>
<property name="text">
<string>Check</string>
</property>
<property name="toolTip">
<string>Check the script for syntax errors</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
<class>CodeEditorWidget</class>
<extends>QPlainTextEdit</extends>
<header>codeeditorwidget.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../resources.qrc"/>
</resources>
<connections>
<connection>
<sender>actionOk</sender>
<signal>triggered()</signal>
<receiver>ScriptPropertiesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>269</x>
<y>248</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionUndo</sender>
<signal>triggered()</signal>
<receiver>codeEdit</receiver>
<slot>undo()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>269</x>
<y>263</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionRedo</sender>
<signal>triggered()</signal>
<receiver>codeEdit</receiver>
<slot>redo()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>269</x>
<y>263</y>
</hint>
</hints>
</connection>
<connection>
<sender>codeEdit</sender>
<signal>undoAvailable(bool)</signal>
<receiver>actionUndo</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>269</x>
<y>263</y>
</hint>
<hint type="destinationlabel">
<x>-1</x>
<y>-1</y>
</hint>
</hints>
</connection>
<connection>
<sender>codeEdit</sender>
<signal>redoAvailable(bool)</signal>
<receiver>actionRedo</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>269</x>
<y>263</y>
</hint>
<hint type="destinationlabel">
<x>-1</x>
<y>-1</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionCut</sender>
<signal>triggered()</signal>
<receiver>codeEdit</receiver>
<slot>cut()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>269</x>
<y>263</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionCopy</sender>
<signal>triggered()</signal>
<receiver>codeEdit</receiver>
<slot>copy()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>269</x>
<y>263</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionPaste</sender>
<signal>triggered()</signal>
<receiver>codeEdit</receiver>
<slot>paste()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>269</x>
<y>263</y>
</hint>
</hints>
</connection>
<connection>
<sender>codeEdit</sender>
<signal>copyAvailable(bool)</signal>
<receiver>actionCut</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>269</x>
<y>263</y>
</hint>
<hint type="destinationlabel">
<x>-1</x>
<y>-1</y>
</hint>
</hints>
</connection>
<connection>
<sender>codeEdit</sender>
<signal>copyAvailable(bool)</signal>
<receiver>actionCopy</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>269</x>
<y>263</y>
</hint>
<hint type="destinationlabel">
<x>-1</x>
<y>-1</y>
</hint>
</hints>
</connection>
<connection>
<sender>actionFind</sender>
<signal>toggled(bool)</signal>
<receiver>widgetSearch</receiver>
<slot>setVisible(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>499</x>
<y>263</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,167 @@
#include "soundpropertiesdialog.h"
#include "ui_soundpropertiesdialog.h"
#include <QFileDialog>
#include <QDebug>
#include <QMessageBox>
#include <QFileInfo>
#include "projectcontainer.h"
SoundPropertiesDialog::SoundPropertiesDialog(Sound &sound, QWidget *parent) :
QDialog{parent},
m_ui{std::make_unique<Ui::SoundPropertiesDialog>()},
m_sound{sound}
{
m_ui->setupUi(this);
setWindowTitle(tr("Sound Properties: %0").arg(m_sound.name));
m_ui->lineEditName->setText(m_sound.name);
m_ui->labelFilename->setText(tr("Filename: %0").arg(QFileInfo{m_sound.path}.fileName()));
m_ui->radioButtonNormal->setChecked(m_sound.type == Sound::Type::Sound);
m_ui->radioButtonMusic->setChecked(m_sound.type == Sound::Type::Music);
m_ui->checkBoxChorus->setChecked(m_sound.effects.chorus);
m_ui->checkBoxFlanger->setChecked(m_sound.effects.flanger);
m_ui->checkBoxGargle->setChecked(m_sound.effects.gargle);
m_ui->checkBoxEcho->setChecked(m_sound.effects.echo);
m_ui->checkBoxReverb->setChecked(m_sound.effects.reverb);
m_ui->horizontalSliderVolume->setValue(m_sound.volume);
m_ui->horizontalSliderPan->setValue(m_sound.pan);
m_ui->checkBoxPreload->setChecked(m_sound.preload);
connect(m_ui->pushButtonLoad, &QAbstractButton::pressed,
this, &SoundPropertiesDialog::loadSound);
connect(m_ui->pushButtonPlay, &QAbstractButton::pressed,
this, &SoundPropertiesDialog::playSound);
connect(m_ui->pushButtonStop, &QAbstractButton::pressed,
this, &SoundPropertiesDialog::stopSound);
connect(m_ui->pushButtonSave, &QAbstractButton::pressed,
this, &SoundPropertiesDialog::saveSound);
connect(m_ui->pushButtonEdit, &QAbstractButton::pressed,
this, &SoundPropertiesDialog::editSound);
connect(m_ui->lineEditName, &QLineEdit::textChanged,
this, &SoundPropertiesDialog::changed);
connect(m_ui->radioButtonNormal, &QRadioButton::toggled,
this, &SoundPropertiesDialog::changed);
connect(m_ui->radioButtonMusic, &QRadioButton::toggled,
this, &SoundPropertiesDialog::changed);
connect(m_ui->radioButton3D, &QRadioButton::toggled,
this, &SoundPropertiesDialog::changed);
connect(m_ui->radioButtonMultimedia, &QRadioButton::toggled,
this, &SoundPropertiesDialog::changed);
connect(m_ui->checkBoxChorus, &QCheckBox::stateChanged,
this, &SoundPropertiesDialog::changed);
connect(m_ui->checkBoxFlanger, &QCheckBox::stateChanged,
this, &SoundPropertiesDialog::changed);
connect(m_ui->checkBoxGargle, &QCheckBox::stateChanged,
this, &SoundPropertiesDialog::changed);
connect(m_ui->checkBoxEcho, &QCheckBox::stateChanged,
this, &SoundPropertiesDialog::changed);
connect(m_ui->checkBoxReverb, &QCheckBox::stateChanged,
this, &SoundPropertiesDialog::changed);
connect(m_ui->horizontalSliderVolume, &QSlider::valueChanged,
this, &SoundPropertiesDialog::changed);
connect(m_ui->horizontalSliderPan, &QSlider::valueChanged,
this, &SoundPropertiesDialog::changed);
connect(m_ui->checkBoxPreload, &QCheckBox::stateChanged,
this, &SoundPropertiesDialog::changed);
}
SoundPropertiesDialog::~SoundPropertiesDialog() = default;
void SoundPropertiesDialog::accept()
{
if (m_sound.name != m_ui->lineEditName->text())
{
QMessageBox::critical(this, tr("Not implemented"), tr("Changing the name is not yet implemented!"));
return;
}
if (m_ui->radioButtonNormal->isChecked())
m_sound.type = Sound::Type::Sound;
else if (m_ui->radioButtonMusic->isChecked())
m_sound.type = Sound::Type::Music;
else
{
QMessageBox::critical(this, tr("Not implemented"), tr("This kind of sound is not yet supported!"));
return;
}
m_sound.effects.chorus = m_ui->checkBoxChorus->isChecked();
m_sound.effects.flanger = m_ui->checkBoxFlanger->isChecked();
m_sound.effects.gargle = m_ui->checkBoxGargle->isChecked();
m_sound.effects.echo = m_ui->checkBoxEcho->isChecked();
m_sound.effects.reverb = m_ui->checkBoxReverb->isChecked();
m_sound.volume = m_ui->horizontalSliderVolume->value();
m_sound.pan = m_ui->horizontalSliderPan->value();
QDialog::accept();
}
void SoundPropertiesDialog::reject()
{
if (!m_unsavedChanges)
{
QDialog::reject();
return;
}
const auto result = QMessageBox::warning(
this,
tr("The Sound has been modified."),
tr("Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
QMessageBox::Save
);
switch (result)
{
case QMessageBox::Save:
accept();
return;
case QMessageBox::Discard:
QDialog::reject();
return;
case QMessageBox::Cancel:
return;
default:
qWarning() << "unexpected dialog result" << result;
}
}
void SoundPropertiesDialog::loadSound()
{
QFileDialog::getOpenFileName(this, tr("Open a Sound File..."));
}
void SoundPropertiesDialog::playSound()
{
m_soundEffect.setSource(QUrl::fromLocalFile(m_sound.path));
m_soundEffect.stop();
m_soundEffect.play();
}
void SoundPropertiesDialog::stopSound()
{
m_soundEffect.stop();
}
void SoundPropertiesDialog::saveSound()
{
QFileDialog::getSaveFileName(this, tr("Save a Sound File..."), m_sound.name + ".wav", tr("WAV Files (*.wav)"));
}
void SoundPropertiesDialog::editSound()
{
QMessageBox::critical(this, tr("Setup not complete"), tr("No valid external editor has been indicated for this type of sound. You can specify this editor in the Preferences."));
}
void SoundPropertiesDialog::changed()
{
if (!m_unsavedChanges)
{
setWindowTitle(tr("Sound Properties: %0*").arg(m_sound.name));
m_unsavedChanges = true;
}
}

View File

@ -0,0 +1,40 @@
#pragma once
#include <QDialog>
#include <QString>
#include <QSoundEffect>
#include <memory>
namespace Ui { class SoundPropertiesDialog; }
struct Sound;
class SoundPropertiesDialog : public QDialog
{
Q_OBJECT
public:
explicit SoundPropertiesDialog(Sound &sound, QWidget *parent = nullptr);
~SoundPropertiesDialog();
void accept() override;
void reject() override;
private slots:
void loadSound();
void playSound();
void stopSound();
void saveSound();
void editSound();
void changed();
private:
const std::unique_ptr<Ui::SoundPropertiesDialog> m_ui;
Sound &m_sound;
bool m_unsavedChanges{};
QSoundEffect m_soundEffect;
};

View File

@ -0,0 +1,354 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SoundPropertiesDialog</class>
<widget class="QDialog" name="SoundPropertiesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>239</width>
<height>534</height>
</rect>
</property>
<property name="windowTitle">
<string>Sound Properties</string>
</property>
<property name="windowIcon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/dialogs/sound-file.png</normaloff>:/qtgameengine/icons/dialogs/sound-file.png</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelName">
<property name="text">
<string>Name:</string>
</property>
<property name="buddy">
<cstring>lineEditName</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditName"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,0,0">
<item>
<widget class="QPushButton" name="pushButtonLoad">
<property name="text">
<string>&amp;Load Sound</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/open.png</normaloff>:/qtgameengine/icons/actions/open.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonPlay">
<property name="toolTip">
<string>Play the sound</string>
</property>
<property name="text">
<string notr="true"/>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/run.png</normaloff>:/qtgameengine/icons/actions/run.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonStop">
<property name="toolTip">
<string>Stop the sound</string>
</property>
<property name="text">
<string notr="true"/>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/exit.png</normaloff>:/qtgameengine/icons/actions/exit.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="pushButtonSave">
<property name="text">
<string>Sa&amp;ve Sound</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/save.png</normaloff>:/qtgameengine/icons/actions/save.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelFilename">
<property name="text">
<string>Filename:</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxKind">
<property name="title">
<string>Kind</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="radioButtonNormal">
<property name="text">
<string>Normal Sound</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonMusic">
<property name="text">
<string>Background Music</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton3D">
<property name="text">
<string>3D Sound</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButtonMultimedia">
<property name="text">
<string>Use multimedia player</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxEffects">
<property name="title">
<string>Effects</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QCheckBox" name="checkBoxFlanger">
<property name="text">
<string>Flanger</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="checkBoxChorus">
<property name="text">
<string>Chorus</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkBoxGargle">
<property name="text">
<string>Gargle</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkBoxEcho">
<property name="text">
<string>Echo</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkBoxReverb">
<property name="text">
<string>Reverb</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="labelVolume">
<property name="text">
<string>Volume:</string>
</property>
<property name="buddy">
<cstring>horizontalSliderVolume</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="horizontalSliderVolume">
<property name="maximum">
<number>100</number>
</property>
<property name="value">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labelPan">
<property name="text">
<string>Pan:</string>
</property>
<property name="buddy">
<cstring>horizontalSliderPan</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSlider" name="horizontalSliderPan">
<property name="minimum">
<number>-100</number>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="invertedAppearance">
<bool>false</bool>
</property>
<property name="invertedControls">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBoxPreload">
<property name="text">
<string>&amp;Preload</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButtonEdit">
<property name="text">
<string>&amp;Edit Sound</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/sound.png</normaloff>:/qtgameengine/icons/actions/sound.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButtonOk">
<property name="text">
<string>&amp;OK</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/buttons/ok.png</normaloff>:/qtgameengine/icons/buttons/ok.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../resources.qrc"/>
</resources>
<connections>
<connection>
<sender>pushButtonOk</sender>
<signal>pressed()</signal>
<receiver>SoundPropertiesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>119</x>
<y>534</y>
</hint>
<hint type="destinationlabel">
<x>119</x>
<y>279</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,133 @@
#include "spritepropertiesdialog.h"
#include "ui_spritepropertiesdialog.h"
#include <QFileDialog>
#include <QDebug>
#include <QMessageBox>
#include "projectcontainer.h"
#include "editspritedialog.h"
SpritePropertiesDialog::SpritePropertiesDialog(Sprite &sprite, QWidget *parent) :
QDialog{parent},
m_ui{std::make_unique<Ui::SpritePropertiesDialog>()},
m_sprite{sprite}
{
m_ui->setupUi(this);
setWindowTitle(tr("Sprite Properties: %0").arg(m_sprite.name));
m_ui->lineEditName->setText(m_sprite.name);
m_ui->labelWidth->setText(tr("Width: %0").arg(m_sprite.pixmaps.empty() ? tr("n/a") : QString::number(m_sprite.pixmaps.front().width())));
m_ui->labelHeight->setText(tr("Height: %0").arg(m_sprite.pixmaps.empty() ? tr("n/a") : QString::number(m_sprite.pixmaps.front().height())));
m_ui->labelSubimages->setText(tr("Number of subimages: %0").arg(m_sprite.pixmaps.size()));
m_ui->spinBoxOriginX->setValue(m_sprite.origin.x);
m_ui->spinBoxOriginY->setValue(m_sprite.origin.y);
m_ui->checkBoxPreciseCollisionChecking->setChecked(m_sprite.preciseCollisionChecking);
m_ui->checkBoxSeparateCollisionMasks->setChecked(m_sprite.separateCollisionMasks);
m_ui->labelPreview->setPixmap(m_sprite.pixmaps.empty() ? QPixmap{} : m_sprite.pixmaps.front());
connect(m_ui->pushButtonLoad, &QAbstractButton::pressed,
this, &SpritePropertiesDialog::loadSprite);
connect(m_ui->pushButtonSave, &QAbstractButton::pressed,
this, &SpritePropertiesDialog::saveSprite);
connect(m_ui->pushButtonEdit, &QAbstractButton::pressed,
this, &SpritePropertiesDialog::editSprite);
connect(m_ui->pushButtonCenterOrigin, &QAbstractButton::pressed,
this, &SpritePropertiesDialog::centerOrigin);
connect(m_ui->lineEditName, &QLineEdit::textChanged,
this, &SpritePropertiesDialog::changed);
connect(m_ui->spinBoxOriginX, &QSpinBox::valueChanged,
this, &SpritePropertiesDialog::changed);
connect(m_ui->spinBoxOriginY, &QSpinBox::valueChanged,
this, &SpritePropertiesDialog::changed);
connect(m_ui->checkBoxPreciseCollisionChecking, &QCheckBox::stateChanged,
this, &SpritePropertiesDialog::changed);
connect(m_ui->checkBoxSeparateCollisionMasks, &QCheckBox::stateChanged,
this, &SpritePropertiesDialog::changed);
}
SpritePropertiesDialog::~SpritePropertiesDialog() = default;
void SpritePropertiesDialog::accept()
{
if (m_sprite.name != m_ui->lineEditName->text())
{
QMessageBox::critical(this, tr("Not implemented"), tr("Changing the name is not yet implemented!"));
return;
}
m_sprite.origin.x = m_ui->spinBoxOriginX->value();
m_sprite.origin.y = m_ui->spinBoxOriginY->value();
m_sprite.preciseCollisionChecking = m_ui->checkBoxPreciseCollisionChecking->isChecked();
m_sprite.separateCollisionMasks = m_ui->checkBoxSeparateCollisionMasks->isChecked();
QDialog::accept();
}
void SpritePropertiesDialog::reject()
{
if (!m_unsavedChanges)
{
QDialog::reject();
return;
}
const auto result = QMessageBox::warning(
this,
tr("The Sprite has been modified."),
tr("Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
QMessageBox::Save
);
switch (result)
{
case QMessageBox::Save:
accept();
return;
case QMessageBox::Discard:
QDialog::reject();
return;
case QMessageBox::Cancel:
return;
default:
qWarning() << "unexpected dialog result" << result;
}
}
void SpritePropertiesDialog::loadSprite()
{
QFileDialog::getOpenFileName(this, tr("Open a Sprite Image..."));
}
void SpritePropertiesDialog::saveSprite()
{
QFileDialog::getSaveFileName(this, tr("Save a Sprite Image..."), m_sprite.name + ".png", tr("PNG Files (*.png)"));
}
void SpritePropertiesDialog::editSprite()
{
EditSpriteDialog{m_sprite}.exec();
}
void SpritePropertiesDialog::centerOrigin()
{
if (m_sprite.pixmaps.empty())
{
qDebug() << "unexpected empty pixmaps";
return;
}
m_ui->spinBoxOriginX->setValue(m_sprite.pixmaps.front().width() / 2);
m_ui->spinBoxOriginY->setValue(m_sprite.pixmaps.front().height() / 2);
}
void SpritePropertiesDialog::changed()
{
if (!m_unsavedChanges)
{
setWindowTitle(tr("Sprite Properties: %0*").arg(m_sprite.name));
m_unsavedChanges = true;
}
}

View File

@ -0,0 +1,36 @@
#pragma once
#include <QDialog>
#include <QString>
#include <memory>
namespace Ui { class SpritePropertiesDialog; }
struct Sprite;
class SpritePropertiesDialog : public QDialog
{
Q_OBJECT
public:
explicit SpritePropertiesDialog(Sprite &sprite, QWidget *parent = nullptr);
~SpritePropertiesDialog();
void accept() override;
void reject() override;
private slots:
void loadSprite();
void saveSprite();
void editSprite();
void centerOrigin();
void changed();
private:
const std::unique_ptr<Ui::SpritePropertiesDialog> m_ui;
Sprite &m_sprite;
bool m_unsavedChanges{};
};

View File

@ -0,0 +1,360 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SpritePropertiesDialog</class>
<widget class="QDialog" name="SpritePropertiesDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>560</width>
<height>344</height>
</rect>
</property>
<property name="windowTitle">
<string>Sprite Properties</string>
</property>
<property name="windowIcon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/dialogs/sprite-file.png</normaloff>:/qtgameengine/icons/dialogs/sprite-file.png</iconset>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,1">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="labelName">
<property name="text">
<string>Name:</string>
</property>
<property name="buddy">
<cstring>lineEditName</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditName"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<widget class="QPushButton" name="pushButtonLoad">
<property name="text">
<string>&amp;Load Sprite</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/open.png</normaloff>:/qtgameengine/icons/actions/open.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonSave">
<property name="text">
<string>&amp;Save Sprite</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/actions/save.png</normaloff>:/qtgameengine/icons/actions/save.png</iconset>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonEdit">
<property name="text">
<string>&amp;Edit Sprite</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/buttons/edit.png</normaloff>:/qtgameengine/icons/buttons/edit.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="labelHeight">
<property name="text">
<string>Height:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="labelWidth">
<property name="text">
<string>Width:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="labelSubimages">
<property name="text">
<string>Number of subimages:</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBoxOrigin">
<property name="title">
<string>Origin</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="labelOriginX">
<property name="text">
<string>X:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>spinBoxOriginX</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxOriginX"/>
</item>
<item>
<widget class="QLabel" name="labelOriginY">
<property name="text">
<string>Y:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>spinBoxOriginY</cstring>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxOriginY"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButtonCenterOrigin">
<property name="text">
<string>&amp;Center</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButtonOk">
<property name="text">
<string>Ok</string>
</property>
<property name="icon">
<iconset resource="../resources.qrc">
<normaloff>:/qtgameengine/icons/buttons/ok.png</normaloff>:/qtgameengine/icons/buttons/ok.png</iconset>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBoxCollisionChecking">
<property name="title">
<string>Collision Checking</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QCheckBox" name="checkBoxPreciseCollisionChecking">
<property name="text">
<string>&amp;Precise collision checking</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxSeparateCollisionMasks">
<property name="text">
<string>Separa&amp;te Collision Masks</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonModifyCollisionmask">
<property name="text">
<string>&amp;Modify Mask</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QLabel" name="labelPreview">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>124</width>
<height>324</height>
</rect>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../resources.qrc"/>
</resources>
<connections>
<connection>
<sender>pushButtonOk</sender>
<signal>pressed()</signal>
<receiver>SpritePropertiesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>106</x>
<y>320</y>
</hint>
<hint type="destinationlabel">
<x>279</x>
<y>171</y>
</hint>
</hints>
</connection>
</connections>
</ui>

30
futurecpp.h Normal file
View File

@ -0,0 +1,30 @@
#pragma once
// system includes
#include <cstring>
#include <limits>
#include <type_traits>
// C++20 backports (until espressif finally updates their aged compiler suite)
namespace std {
template <class To, class From>
typename std::enable_if_t<
sizeof(To) == sizeof(From) && std::is_trivially_copyable_v<From> && std::is_trivially_copyable_v<To>,
To>
// constexpr support needs compiler magic
bit_cast(const From& src) noexcept
{
static_assert(std::is_trivially_constructible_v<To>,
"This implementation additionally requires destination type to be trivially constructible");
To dst;
std::memcpy(&dst, &src, sizeof(To));
return dst;
}
template <typename EnumT, typename = std::enable_if_t<std::is_enum<EnumT>{}>>
constexpr std::underlying_type_t<EnumT> to_underlying(EnumT e) noexcept {
return static_cast<std::underlying_type_t<EnumT>>(e);
}
} // namespace std

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

BIN
icons/actions/cascade.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
icons/actions/check.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
icons/actions/copy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
icons/actions/create.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
icons/actions/cut.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
icons/actions/debug.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
icons/actions/delete.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
icons/actions/duplicate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
icons/actions/exit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

BIN
icons/actions/find.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

BIN
icons/actions/font.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

BIN
icons/actions/help.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
icons/actions/new.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

BIN
icons/actions/object.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

BIN
icons/actions/ok.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
icons/actions/open.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
icons/actions/paste.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
icons/actions/path.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

BIN
icons/actions/print.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

BIN
icons/actions/redo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
icons/actions/rename.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
icons/actions/room.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

BIN
icons/actions/run.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
icons/actions/save-as.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
icons/actions/save.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
icons/actions/script.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
icons/actions/sound.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

BIN
icons/actions/sprite.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
icons/actions/tile.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
icons/actions/timeline.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

BIN
icons/actions/undo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
icons/buttons/edit.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

BIN
icons/buttons/ok.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
icons/dialogs/font-file.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
icons/dialogs/path-file.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
icons/tree/folder.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
icons/tree/font-file.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
icons/tree/music-file.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
icons/tree/path-file.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
icons/tree/script-file.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
icons/tree/sound-file.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

449
jshighlighter.cpp Normal file
View File

@ -0,0 +1,449 @@
#include "jshighlighter.h"
class JSBlockData : public QTextBlockUserData
{
public:
QList<int> bracketPositions;
};
JSHighlighter::JSHighlighter(QTextDocument *parent) :
QSyntaxHighlighter{parent},
m_colors {
// default color scheme
{ Normal, QColor("#000000") },
{ Comment, QColor("#808080") },
{ Number, QColor("#008000") },
{ String, QColor("#800000") },
{ Operator, QColor("#808000") },
{ Identifier, QColor("#000020") },
{ Keyword, QColor("#000080") },
{ BuiltIn, QColor("#008080") },
{ Marker, QColor("#ffff00") },
},
m_keywords {
// https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words
"break",
"case",
"catch",
"continue",
"default",
"delete",
"do",
"else",
"finally",
"for",
"function",
"if",
"in",
"instanceof",
"new",
"return",
"switch",
"this",
"throw",
"try",
"typeof",
"var",
"void",
"while",
"with",
"true",
"false",
"null",
},
m_knownIds {
// built-in and other popular objects + properties
"Object",
"prototype",
"create",
"defineProperty",
"defineProperties",
"getOwnPropertyDescriptor",
"keys",
"getOwnPropertyNames",
"constructor",
"__parent__",
"__proto__",
"__defineGetter__",
"__defineSetter__",
"eval",
"hasOwnProperty",
"isPrototypeOf",
"__lookupGetter__",
"__lookupSetter__",
"__noSuchMethod__",
"propertyIsEnumerable",
"toSource",
"toLocaleString",
"toString",
"unwatch",
"valueOf",
"watch",
"Function",
"arguments",
"arity",
"caller",
"constructor",
"length",
"name",
"apply",
"bind",
"call",
"String",
"fromCharCode",
"length",
"charAt",
"charCodeAt",
"concat",
"indexOf",
"lastIndexOf",
"localCompare",
"match",
"quote",
"replace",
"search",
"slice",
"split",
"substr",
"substring",
"toLocaleLowerCase",
"toLocaleUpperCase",
"toLowerCase",
"toUpperCase",
"trim",
"trimLeft",
"trimRight",
"Array",
"isArray",
"index",
"input",
"pop",
"push",
"reverse",
"shift",
"sort",
"splice",
"unshift",
"concat",
"join",
"filter",
"forEach",
"every",
"map",
"some",
"reduce",
"reduceRight",
"RegExp",
"global",
"ignoreCase",
"lastIndex",
"multiline",
"source",
"exec",
"test",
"JSON",
"parse",
"stringify",
"decodeURI",
"decodeURIComponent",
"encodeURI",
"encodeURIComponent",
"eval",
"isFinite",
"isNaN",
"parseFloat",
"parseInt",
"Infinity",
"NaN",
"undefined",
"Math",
"E",
"LN2",
"LN10",
"LOG2E",
"LOG10E",
"PI",
"SQRT1_2",
"SQRT2",
"abs",
"acos",
"asin",
"atan",
"atan2",
"ceil",
"cos",
"exp",
"floor",
"log",
"max",
"min",
"pow",
"random",
"round",
"sin",
"sqrt",
"tan",
"document",
"window",
"navigator",
"userAgent",
},
m_markCaseSensitivity{Qt::CaseInsensitive}
{
}
void JSHighlighter::setColor(ColorComponent component, const QColor &color)
{
m_colors[component] = color;
rehighlight();
}
void JSHighlighter::highlightBlock(const QString &text)
{
// parsing state
enum {
Start = 0,
Number = 1,
Identifier = 2,
String = 3,
Comment = 4,
Regex = 5
};
QList<int> bracketPositions;
int blockState = previousBlockState();
int bracketLevel = blockState >> 4;
int state = blockState & 15;
if (blockState < 0)
{
bracketLevel = 0;
state = Start;
}
int start = 0;
int i = 0;
while (i <= text.length())
{
QChar ch = (i < text.length()) ? text.at(i) : QChar();
QChar next = (i < text.length() - 1) ? text.at(i + 1) : QChar();
switch (state)
{
case Start:
start = i;
if (ch.isSpace())
{
++i;
}
else if (ch.isDigit())
{
++i;
state = Number;
}
else if (ch.isLetter() || ch == '_')
{
++i;
state = Identifier;
}
else if (ch == '\'' || ch == '\"')
{
++i;
state = String;
}
else if (ch == '/' && next == '*')
{
++i;
++i;
state = Comment;
}
else if (ch == '/' && next == '/')
{
i = text.length();
setFormat(start, text.length(), m_colors[ColorComponent::Comment]);
}
else if (ch == '/' && next != '*')
{
++i;
state = Regex;
}
else
{
if (!QString("(){}[]").contains(ch))
setFormat(start, 1, m_colors[Operator]);
if (ch =='{' || ch == '}')
{
bracketPositions += i;
if (ch == '{')
bracketLevel++;
else
bracketLevel--;
}
++i;
state = Start;
}
break;
case Number:
if (ch.isSpace() || !ch.isDigit())
{
setFormat(start, i - start, m_colors[ColorComponent::Number]);
state = Start;
}
else
{
++i;
}
break;
case Identifier:
if (ch.isSpace() || !(ch.isDigit() || ch.isLetter() || ch == '_'))
{
QString token = text.mid(start, i - start).trimmed();
if (m_keywords.contains(token))
setFormat(start, i - start, m_colors[Keyword]);
else if (m_knownIds.contains(token))
setFormat(start, i - start, m_colors[BuiltIn]);
state = Start;
}
else
{
++i;
}
break;
case String:
if (ch == text.at(start)) {
QChar prev = (i > 0) ? text.at(i - 1) : QChar();
if (prev != '\\') {
++i;
setFormat(start, i - start, m_colors[ColorComponent::String]);
state = Start;
} else {
++i;
}
} else {
++i;
}
break;
case Comment:
if (ch == '*' && next == '/')
{
++i;
++i;
setFormat(start, i - start, m_colors[ColorComponent::Comment]);
state = Start;
}
else
{
++i;
}
break;
case Regex:
if (ch == '/')
{
QChar prev = (i > 0) ? text.at(i - 1) : QChar();
if (prev != '\\')
{
++i;
setFormat(start, i - start, m_colors[ColorComponent::String]);
state = Start;
}
else
{
++i;
}
}
else
{
++i;
}
break;
default:
state = Start;
break;
}
}
if (state == Comment)
setFormat(start, text.length(), m_colors[ColorComponent::Comment]);
else
state = Start;
if (!m_markString.isEmpty())
{
int pos = 0;
int len = m_markString.length();
QTextCharFormat markerFormat;
markerFormat.setBackground(m_colors[Marker]);
markerFormat.setForeground(m_colors[Normal]);
for (;;)
{
pos = text.indexOf(m_markString, pos, m_markCaseSensitivity);
if (pos < 0)
break;
setFormat(pos, len, markerFormat);
++pos;
}
}
if (!bracketPositions.isEmpty())
{
JSBlockData *blockData = reinterpret_cast<JSBlockData*>(currentBlock().userData());
if (!blockData)
{
blockData = new JSBlockData;
currentBlock().setUserData(blockData);
}
blockData->bracketPositions = bracketPositions;
}
blockState = (state & 15) | (bracketLevel << 4);
setCurrentBlockState(blockState);
}
void JSHighlighter::mark(const QString &str, Qt::CaseSensitivity caseSensitivity)
{
m_markString = str;
m_markCaseSensitivity = caseSensitivity;
rehighlight();
}
QStringList JSHighlighter::keywords() const
{
return QStringList{std::begin(m_keywords), std::end(m_keywords)};
}
void JSHighlighter::setKeywords(std::set<QString> &&keywords)
{
m_keywords = std::move(keywords);
rehighlight();
}
void JSHighlighter::setKeywords(const std::set<QString> &keywords)
{
m_keywords = keywords;
rehighlight();
}
struct BlockInfo
{
int position;
int number;
bool foldable: 1;
bool folded : 1;
};
Q_DECLARE_TYPEINFO(BlockInfo, Q_PRIMITIVE_TYPE);

48
jshighlighter.h Normal file
View File

@ -0,0 +1,48 @@
#pragma once
#include <QSyntaxHighlighter>
#include <set>
#include <unordered_map>
enum ColorComponent {
Background,
Normal,
Comment,
Number,
String,
Operator,
Identifier,
Keyword,
BuiltIn,
Sidebar,
LineNumber,
Cursor,
Marker,
BracketMatch,
BracketError,
FoldIndicator
};
class JSHighlighter : public QSyntaxHighlighter
{
public:
JSHighlighter(QTextDocument *parent = 0);
void setColor(ColorComponent component, const QColor &color);
void mark(const QString &str, Qt::CaseSensitivity caseSensitivity);
QStringList keywords() const;
void setKeywords(std::set<QString> &&keywords);
void setKeywords(const std::set<QString> &keywords);
protected:
void highlightBlock(const QString &text);
private:
std::unordered_map<ColorComponent, QColor> m_colors;
std::set<QString> m_keywords;
std::set<QString> m_knownIds;
QString m_markString;
Qt::CaseSensitivity m_markCaseSensitivity;
};

30
main.cpp Normal file
View File

@ -0,0 +1,30 @@
#include <QApplication>
#include <QStyleFactory>
#include <QDebug>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
qSetMessagePattern(QStringLiteral("%{time dd.MM.yyyy HH:mm:ss.zzz} "
"["
"%{if-debug}D%{endif}"
"%{if-info}I%{endif}"
"%{if-warning}W%{endif}"
"%{if-critical}C%{endif}"
"%{if-fatal}F%{endif}"
"] "
"%{function}(): "
"%{message}"));
Q_INIT_RESOURCE(resources);
QApplication app(argc, argv);
QApplication::setStyle(QStyleFactory::create("Windows"));
MainWindow mainWindow;
mainWindow.show();
return app.exec();
}

Some files were not shown because too many files have changed in this diff Show More