mirror of
https://github.com/juzzlin/Heimer.git
synced 2025-05-09 12:53:20 +08:00
Initial commit
This commit is contained in:
commit
da44543f95
60
.gitignore
vendored
Normal file
60
.gitignore
vendored
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
*~
|
||||||
|
*.cxx
|
||||||
|
*.o
|
||||||
|
*.a
|
||||||
|
*moc_*
|
||||||
|
*_automoc*
|
||||||
|
*qrc_*
|
||||||
|
*qm
|
||||||
|
*.tar.gz
|
||||||
|
*.zip
|
||||||
|
*.exe
|
||||||
|
*.json
|
||||||
|
log.txt
|
||||||
|
manifest*
|
||||||
|
.excludes
|
||||||
|
*__*
|
||||||
|
Makefile
|
||||||
|
bin/
|
||||||
|
dementia.pro.user
|
||||||
|
dementia.pro.user.2.1pre1
|
||||||
|
engine.txt
|
||||||
|
header.txt
|
||||||
|
src/editor/Makefile
|
||||||
|
src/editor/editor
|
||||||
|
src/game/Makefile
|
||||||
|
src/game/Makefile.Debug
|
||||||
|
src/game/Makefile.Release
|
||||||
|
src/game/MiniCore/Core/genincludeheaders.sh
|
||||||
|
*.cbp
|
||||||
|
dementia-editor
|
||||||
|
dementia-game
|
||||||
|
test/
|
||||||
|
unittests/
|
||||||
|
CTestTestfile.cmake
|
||||||
|
cmake_install.cmake
|
||||||
|
src/editor/CTestTestfile.cmake
|
||||||
|
src/editor/cmake_install.cmake
|
||||||
|
src/game/CTestTestfile.cmake
|
||||||
|
src/game/MiniCore/CTestTestfile.cmake
|
||||||
|
src/game/MiniCore/UnitTests/CTestTestfile.cmake
|
||||||
|
src/game/MiniCore/UnitTests/MCForceRegistryTest/CTestTestfile.cmake
|
||||||
|
src/game/MiniCore/UnitTests/MCForceRegistryTest/cmake_install.cmake
|
||||||
|
src/game/MiniCore/UnitTests/MCObjectTest/CTestTestfile.cmake
|
||||||
|
src/game/MiniCore/UnitTests/MCObjectTest/cmake_install.cmake
|
||||||
|
src/game/MiniCore/UnitTests/cmake_install.cmake
|
||||||
|
src/game/MiniCore/cmake_install.cmake
|
||||||
|
src/game/cmake_install.cmake
|
||||||
|
src/game/renderer.cpp.autosave
|
||||||
|
CPackConfig.cmake
|
||||||
|
CPackSourceConfig.cmake
|
||||||
|
data/translations/
|
||||||
|
dementia-1.4.6.zip
|
||||||
|
release/
|
||||||
|
src/game/dementia-game_fi.qm
|
||||||
|
src/game/dementia-game_it.qm
|
||||||
|
src/game/trackobjectfactory.cpp.orig
|
||||||
|
*_plugin_import*
|
||||||
|
*.Debug
|
||||||
|
*.Release
|
||||||
|
CMakeLists.txt.user
|
12
AUTHORS
Normal file
12
AUTHORS
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
People who have contributed to Dementia
|
||||||
|
=======================================
|
||||||
|
|
||||||
|
Programming:
|
||||||
|
* Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
|
||||||
|
Graphics:
|
||||||
|
* Jussi Lind
|
||||||
|
|
||||||
|
Translations:
|
||||||
|
* Jussi Lind (fi)
|
||||||
|
|
72
CMakeLists.txt
Normal file
72
CMakeLists.txt
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
project(Dementia)
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 2.8.12)
|
||||||
|
cmake_policy(VERSION 2.8.12)
|
||||||
|
|
||||||
|
if(POLICY CMP0005)
|
||||||
|
cmake_policy(SET CMP0005 NEW)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(POLICY CMP0020)
|
||||||
|
cmake_policy(SET CMP0020 NEW)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(POLICY CMP0043)
|
||||||
|
cmake_policy(SET CMP0043 NEW)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Global game version
|
||||||
|
set(VERSION_MAJOR "0")
|
||||||
|
set(VERSION_MINOR "0")
|
||||||
|
set(VERSION_PATCH "0")
|
||||||
|
set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
||||||
|
|
||||||
|
option(ReleaseBuild "This should be used when creating DEB and RPM packages." OFF)
|
||||||
|
|
||||||
|
option(DATA_PATH "Optional DATA_PATH for Linux release build." "")
|
||||||
|
|
||||||
|
option(BIN_PATH "Optional BIN_PATH for Linux release build." "")
|
||||||
|
|
||||||
|
option(DOC_PATH "Optional DOC_PATH for Linux release build." "")
|
||||||
|
|
||||||
|
# Default to release C++ flags if CMAKE_BUILD_TYPE not set
|
||||||
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
|
set(CMAKE_BUILD_TYPE Release CACHE STRING
|
||||||
|
"Choose the type of build, options are: None Debug Release RelWithDebInfo
|
||||||
|
MinSizeRel." FORCE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(UNIX)
|
||||||
|
include("InstallLinux.cmake")
|
||||||
|
elseif(WIN32)
|
||||||
|
include("InstallWindows.cmake")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_COMPILER_IS_GNUCXX OR MINGW OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
||||||
|
add_compile_options("$<$<CONFIG:RELEASE>:-W;-Wall;-O3;-pedantic>")
|
||||||
|
add_compile_options("$<$<CONFIG:DEBUG>:-W;-Wall;-O0;-pedantic>")
|
||||||
|
elseif(MSVC)
|
||||||
|
add_definitions(-DNOMINMAX)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(BINARY_NAME "dementia")
|
||||||
|
|
||||||
|
add_definitions(-DVERSION="${VERSION}")
|
||||||
|
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
set(QT_MIN_VER 5.2.1)
|
||||||
|
find_package(Qt5Core ${QT_MIN_VER} REQUIRED)
|
||||||
|
find_package(Qt5Xml ${QT_MIN_VER} REQUIRED)
|
||||||
|
find_package(Qt5Widgets ${QT_MIN_VER} REQUIRED)
|
||||||
|
find_package(Qt5LinguistTools ${QT_MIN_VER} REQUIRED)
|
||||||
|
find_package(Qt5Test ${QT_MIN_VER} REQUIRED)
|
||||||
|
|
||||||
|
# Install paths depend on the build type and target platform
|
||||||
|
resolve_install_paths()
|
||||||
|
|
||||||
|
add_subdirectory(src/editor)
|
||||||
|
|
||||||
|
# Enable CMake's unit test framework
|
||||||
|
enable_testing()
|
||||||
|
add_subdirectory(src/UnitTests)
|
1
CONTRIBUTING
Normal file
1
CONTRIBUTING
Normal file
@ -0,0 +1 @@
|
|||||||
|
|
674
COPYING
Normal file
674
COPYING
Normal file
@ -0,0 +1,674 @@
|
|||||||
|
GNU GENERAL PUBLIC LICENSE
|
||||||
|
Version 3, 29 June 2007
|
||||||
|
|
||||||
|
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The GNU General Public License is a free, copyleft license for
|
||||||
|
software and other kinds of works.
|
||||||
|
|
||||||
|
The licenses for most software and other practical works are designed
|
||||||
|
to take away your freedom to share and change the works. By contrast,
|
||||||
|
the GNU General Public License is intended to guarantee your freedom to
|
||||||
|
share and change all versions of a program--to make sure it remains free
|
||||||
|
software for all its users. We, the Free Software Foundation, use the
|
||||||
|
GNU General Public License for most of our software; it applies also to
|
||||||
|
any other work released this way by its authors. You can apply it to
|
||||||
|
your programs, too.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom, not
|
||||||
|
price. Our General Public Licenses are designed to make sure that you
|
||||||
|
have the freedom to distribute copies of free software (and charge for
|
||||||
|
them if you wish), that you receive source code or can get it if you
|
||||||
|
want it, that you can change the software or use pieces of it in new
|
||||||
|
free programs, and that you know you can do these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to prevent others from denying you
|
||||||
|
these rights or asking you to surrender the rights. Therefore, you have
|
||||||
|
certain responsibilities if you distribute copies of the software, or if
|
||||||
|
you modify it: responsibilities to respect the freedom of others.
|
||||||
|
|
||||||
|
For example, if you distribute copies of such a program, whether
|
||||||
|
gratis or for a fee, you must pass on to the recipients the same
|
||||||
|
freedoms that you received. You must make sure that they, too, receive
|
||||||
|
or can get the source code. And you must show them these terms so they
|
||||||
|
know their rights.
|
||||||
|
|
||||||
|
Developers that use the GNU GPL protect your rights with two steps:
|
||||||
|
(1) assert copyright on the software, and (2) offer you this License
|
||||||
|
giving you legal permission to copy, distribute and/or modify it.
|
||||||
|
|
||||||
|
For the developers' and authors' protection, the GPL clearly explains
|
||||||
|
that there is no warranty for this free software. For both users' and
|
||||||
|
authors' sake, the GPL requires that modified versions be marked as
|
||||||
|
changed, so that their problems will not be attributed erroneously to
|
||||||
|
authors of previous versions.
|
||||||
|
|
||||||
|
Some devices are designed to deny users access to install or run
|
||||||
|
modified versions of the software inside them, although the manufacturer
|
||||||
|
can do so. This is fundamentally incompatible with the aim of
|
||||||
|
protecting users' freedom to change the software. The systematic
|
||||||
|
pattern of such abuse occurs in the area of products for individuals to
|
||||||
|
use, which is precisely where it is most unacceptable. Therefore, we
|
||||||
|
have designed this version of the GPL to prohibit the practice for those
|
||||||
|
products. If such problems arise substantially in other domains, we
|
||||||
|
stand ready to extend this provision to those domains in future versions
|
||||||
|
of the GPL, as needed to protect the freedom of users.
|
||||||
|
|
||||||
|
Finally, every program is threatened constantly by software patents.
|
||||||
|
States should not allow patents to restrict development and use of
|
||||||
|
software on general-purpose computers, but in those that do, we wish to
|
||||||
|
avoid the special danger that patents applied to a free program could
|
||||||
|
make it effectively proprietary. To prevent this, the GPL assures that
|
||||||
|
patents cannot be used to render the program non-free.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow.
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
0. Definitions.
|
||||||
|
|
||||||
|
"This License" refers to version 3 of the GNU General Public License.
|
||||||
|
|
||||||
|
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||||
|
works, such as semiconductor masks.
|
||||||
|
|
||||||
|
"The Program" refers to any copyrightable work licensed under this
|
||||||
|
License. Each licensee is addressed as "you". "Licensees" and
|
||||||
|
"recipients" may be individuals or organizations.
|
||||||
|
|
||||||
|
To "modify" a work means to copy from or adapt all or part of the work
|
||||||
|
in a fashion requiring copyright permission, other than the making of an
|
||||||
|
exact copy. The resulting work is called a "modified version" of the
|
||||||
|
earlier work or a work "based on" the earlier work.
|
||||||
|
|
||||||
|
A "covered work" means either the unmodified Program or a work based
|
||||||
|
on the Program.
|
||||||
|
|
||||||
|
To "propagate" a work means to do anything with it that, without
|
||||||
|
permission, would make you directly or secondarily liable for
|
||||||
|
infringement under applicable copyright law, except executing it on a
|
||||||
|
computer or modifying a private copy. Propagation includes copying,
|
||||||
|
distribution (with or without modification), making available to the
|
||||||
|
public, and in some countries other activities as well.
|
||||||
|
|
||||||
|
To "convey" a work means any kind of propagation that enables other
|
||||||
|
parties to make or receive copies. Mere interaction with a user through
|
||||||
|
a computer network, with no transfer of a copy, is not conveying.
|
||||||
|
|
||||||
|
An interactive user interface displays "Appropriate Legal Notices"
|
||||||
|
to the extent that it includes a convenient and prominently visible
|
||||||
|
feature that (1) displays an appropriate copyright notice, and (2)
|
||||||
|
tells the user that there is no warranty for the work (except to the
|
||||||
|
extent that warranties are provided), that licensees may convey the
|
||||||
|
work under this License, and how to view a copy of this License. If
|
||||||
|
the interface presents a list of user commands or options, such as a
|
||||||
|
menu, a prominent item in the list meets this criterion.
|
||||||
|
|
||||||
|
1. Source Code.
|
||||||
|
|
||||||
|
The "source code" for a work means the preferred form of the work
|
||||||
|
for making modifications to it. "Object code" means any non-source
|
||||||
|
form of a work.
|
||||||
|
|
||||||
|
A "Standard Interface" means an interface that either is an official
|
||||||
|
standard defined by a recognized standards body, or, in the case of
|
||||||
|
interfaces specified for a particular programming language, one that
|
||||||
|
is widely used among developers working in that language.
|
||||||
|
|
||||||
|
The "System Libraries" of an executable work include anything, other
|
||||||
|
than the work as a whole, that (a) is included in the normal form of
|
||||||
|
packaging a Major Component, but which is not part of that Major
|
||||||
|
Component, and (b) serves only to enable use of the work with that
|
||||||
|
Major Component, or to implement a Standard Interface for which an
|
||||||
|
implementation is available to the public in source code form. A
|
||||||
|
"Major Component", in this context, means a major essential component
|
||||||
|
(kernel, window system, and so on) of the specific operating system
|
||||||
|
(if any) on which the executable work runs, or a compiler used to
|
||||||
|
produce the work, or an object code interpreter used to run it.
|
||||||
|
|
||||||
|
The "Corresponding Source" for a work in object code form means all
|
||||||
|
the source code needed to generate, install, and (for an executable
|
||||||
|
work) run the object code and to modify the work, including scripts to
|
||||||
|
control those activities. However, it does not include the work's
|
||||||
|
System Libraries, or general-purpose tools or generally available free
|
||||||
|
programs which are used unmodified in performing those activities but
|
||||||
|
which are not part of the work. For example, Corresponding Source
|
||||||
|
includes interface definition files associated with source files for
|
||||||
|
the work, and the source code for shared libraries and dynamically
|
||||||
|
linked subprograms that the work is specifically designed to require,
|
||||||
|
such as by intimate data communication or control flow between those
|
||||||
|
subprograms and other parts of the work.
|
||||||
|
|
||||||
|
The Corresponding Source need not include anything that users
|
||||||
|
can regenerate automatically from other parts of the Corresponding
|
||||||
|
Source.
|
||||||
|
|
||||||
|
The Corresponding Source for a work in source code form is that
|
||||||
|
same work.
|
||||||
|
|
||||||
|
2. Basic Permissions.
|
||||||
|
|
||||||
|
All rights granted under this License are granted for the term of
|
||||||
|
copyright on the Program, and are irrevocable provided the stated
|
||||||
|
conditions are met. This License explicitly affirms your unlimited
|
||||||
|
permission to run the unmodified Program. The output from running a
|
||||||
|
covered work is covered by this License only if the output, given its
|
||||||
|
content, constitutes a covered work. This License acknowledges your
|
||||||
|
rights of fair use or other equivalent, as provided by copyright law.
|
||||||
|
|
||||||
|
You may make, run and propagate covered works that you do not
|
||||||
|
convey, without conditions so long as your license otherwise remains
|
||||||
|
in force. You may convey covered works to others for the sole purpose
|
||||||
|
of having them make modifications exclusively for you, or provide you
|
||||||
|
with facilities for running those works, provided that you comply with
|
||||||
|
the terms of this License in conveying all material for which you do
|
||||||
|
not control copyright. Those thus making or running the covered works
|
||||||
|
for you must do so exclusively on your behalf, under your direction
|
||||||
|
and control, on terms that prohibit them from making any copies of
|
||||||
|
your copyrighted material outside their relationship with you.
|
||||||
|
|
||||||
|
Conveying under any other circumstances is permitted solely under
|
||||||
|
the conditions stated below. Sublicensing is not allowed; section 10
|
||||||
|
makes it unnecessary.
|
||||||
|
|
||||||
|
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||||
|
|
||||||
|
No covered work shall be deemed part of an effective technological
|
||||||
|
measure under any applicable law fulfilling obligations under article
|
||||||
|
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||||
|
similar laws prohibiting or restricting circumvention of such
|
||||||
|
measures.
|
||||||
|
|
||||||
|
When you convey a covered work, you waive any legal power to forbid
|
||||||
|
circumvention of technological measures to the extent such circumvention
|
||||||
|
is effected by exercising rights under this License with respect to
|
||||||
|
the covered work, and you disclaim any intention to limit operation or
|
||||||
|
modification of the work as a means of enforcing, against the work's
|
||||||
|
users, your or third parties' legal rights to forbid circumvention of
|
||||||
|
technological measures.
|
||||||
|
|
||||||
|
4. Conveying Verbatim Copies.
|
||||||
|
|
||||||
|
You may convey verbatim copies of the Program's source code as you
|
||||||
|
receive it, in any medium, provided that you conspicuously and
|
||||||
|
appropriately publish on each copy an appropriate copyright notice;
|
||||||
|
keep intact all notices stating that this License and any
|
||||||
|
non-permissive terms added in accord with section 7 apply to the code;
|
||||||
|
keep intact all notices of the absence of any warranty; and give all
|
||||||
|
recipients a copy of this License along with the Program.
|
||||||
|
|
||||||
|
You may charge any price or no price for each copy that you convey,
|
||||||
|
and you may offer support or warranty protection for a fee.
|
||||||
|
|
||||||
|
5. Conveying Modified Source Versions.
|
||||||
|
|
||||||
|
You may convey a work based on the Program, or the modifications to
|
||||||
|
produce it from the Program, in the form of source code under the
|
||||||
|
terms of section 4, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The work must carry prominent notices stating that you modified
|
||||||
|
it, and giving a relevant date.
|
||||||
|
|
||||||
|
b) The work must carry prominent notices stating that it is
|
||||||
|
released under this License and any conditions added under section
|
||||||
|
7. This requirement modifies the requirement in section 4 to
|
||||||
|
"keep intact all notices".
|
||||||
|
|
||||||
|
c) You must license the entire work, as a whole, under this
|
||||||
|
License to anyone who comes into possession of a copy. This
|
||||||
|
License will therefore apply, along with any applicable section 7
|
||||||
|
additional terms, to the whole of the work, and all its parts,
|
||||||
|
regardless of how they are packaged. This License gives no
|
||||||
|
permission to license the work in any other way, but it does not
|
||||||
|
invalidate such permission if you have separately received it.
|
||||||
|
|
||||||
|
d) If the work has interactive user interfaces, each must display
|
||||||
|
Appropriate Legal Notices; however, if the Program has interactive
|
||||||
|
interfaces that do not display Appropriate Legal Notices, your
|
||||||
|
work need not make them do so.
|
||||||
|
|
||||||
|
A compilation of a covered work with other separate and independent
|
||||||
|
works, which are not by their nature extensions of the covered work,
|
||||||
|
and which are not combined with it such as to form a larger program,
|
||||||
|
in or on a volume of a storage or distribution medium, is called an
|
||||||
|
"aggregate" if the compilation and its resulting copyright are not
|
||||||
|
used to limit the access or legal rights of the compilation's users
|
||||||
|
beyond what the individual works permit. Inclusion of a covered work
|
||||||
|
in an aggregate does not cause this License to apply to the other
|
||||||
|
parts of the aggregate.
|
||||||
|
|
||||||
|
6. Conveying Non-Source Forms.
|
||||||
|
|
||||||
|
You may convey a covered work in object code form under the terms
|
||||||
|
of sections 4 and 5, provided that you also convey the
|
||||||
|
machine-readable Corresponding Source under the terms of this License,
|
||||||
|
in one of these ways:
|
||||||
|
|
||||||
|
a) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by the
|
||||||
|
Corresponding Source fixed on a durable physical medium
|
||||||
|
customarily used for software interchange.
|
||||||
|
|
||||||
|
b) Convey the object code in, or embodied in, a physical product
|
||||||
|
(including a physical distribution medium), accompanied by a
|
||||||
|
written offer, valid for at least three years and valid for as
|
||||||
|
long as you offer spare parts or customer support for that product
|
||||||
|
model, to give anyone who possesses the object code either (1) a
|
||||||
|
copy of the Corresponding Source for all the software in the
|
||||||
|
product that is covered by this License, on a durable physical
|
||||||
|
medium customarily used for software interchange, for a price no
|
||||||
|
more than your reasonable cost of physically performing this
|
||||||
|
conveying of source, or (2) access to copy the
|
||||||
|
Corresponding Source from a network server at no charge.
|
||||||
|
|
||||||
|
c) Convey individual copies of the object code with a copy of the
|
||||||
|
written offer to provide the Corresponding Source. This
|
||||||
|
alternative is allowed only occasionally and noncommercially, and
|
||||||
|
only if you received the object code with such an offer, in accord
|
||||||
|
with subsection 6b.
|
||||||
|
|
||||||
|
d) Convey the object code by offering access from a designated
|
||||||
|
place (gratis or for a charge), and offer equivalent access to the
|
||||||
|
Corresponding Source in the same way through the same place at no
|
||||||
|
further charge. You need not require recipients to copy the
|
||||||
|
Corresponding Source along with the object code. If the place to
|
||||||
|
copy the object code is a network server, the Corresponding Source
|
||||||
|
may be on a different server (operated by you or a third party)
|
||||||
|
that supports equivalent copying facilities, provided you maintain
|
||||||
|
clear directions next to the object code saying where to find the
|
||||||
|
Corresponding Source. Regardless of what server hosts the
|
||||||
|
Corresponding Source, you remain obligated to ensure that it is
|
||||||
|
available for as long as needed to satisfy these requirements.
|
||||||
|
|
||||||
|
e) Convey the object code using peer-to-peer transmission, provided
|
||||||
|
you inform other peers where the object code and Corresponding
|
||||||
|
Source of the work are being offered to the general public at no
|
||||||
|
charge under subsection 6d.
|
||||||
|
|
||||||
|
A separable portion of the object code, whose source code is excluded
|
||||||
|
from the Corresponding Source as a System Library, need not be
|
||||||
|
included in conveying the object code work.
|
||||||
|
|
||||||
|
A "User Product" is either (1) a "consumer product", which means any
|
||||||
|
tangible personal property which is normally used for personal, family,
|
||||||
|
or household purposes, or (2) anything designed or sold for incorporation
|
||||||
|
into a dwelling. In determining whether a product is a consumer product,
|
||||||
|
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||||
|
product received by a particular user, "normally used" refers to a
|
||||||
|
typical or common use of that class of product, regardless of the status
|
||||||
|
of the particular user or of the way in which the particular user
|
||||||
|
actually uses, or expects or is expected to use, the product. A product
|
||||||
|
is a consumer product regardless of whether the product has substantial
|
||||||
|
commercial, industrial or non-consumer uses, unless such uses represent
|
||||||
|
the only significant mode of use of the product.
|
||||||
|
|
||||||
|
"Installation Information" for a User Product means any methods,
|
||||||
|
procedures, authorization keys, or other information required to install
|
||||||
|
and execute modified versions of a covered work in that User Product from
|
||||||
|
a modified version of its Corresponding Source. The information must
|
||||||
|
suffice to ensure that the continued functioning of the modified object
|
||||||
|
code is in no case prevented or interfered with solely because
|
||||||
|
modification has been made.
|
||||||
|
|
||||||
|
If you convey an object code work under this section in, or with, or
|
||||||
|
specifically for use in, a User Product, and the conveying occurs as
|
||||||
|
part of a transaction in which the right of possession and use of the
|
||||||
|
User Product is transferred to the recipient in perpetuity or for a
|
||||||
|
fixed term (regardless of how the transaction is characterized), the
|
||||||
|
Corresponding Source conveyed under this section must be accompanied
|
||||||
|
by the Installation Information. But this requirement does not apply
|
||||||
|
if neither you nor any third party retains the ability to install
|
||||||
|
modified object code on the User Product (for example, the work has
|
||||||
|
been installed in ROM).
|
||||||
|
|
||||||
|
The requirement to provide Installation Information does not include a
|
||||||
|
requirement to continue to provide support service, warranty, or updates
|
||||||
|
for a work that has been modified or installed by the recipient, or for
|
||||||
|
the User Product in which it has been modified or installed. Access to a
|
||||||
|
network may be denied when the modification itself materially and
|
||||||
|
adversely affects the operation of the network or violates the rules and
|
||||||
|
protocols for communication across the network.
|
||||||
|
|
||||||
|
Corresponding Source conveyed, and Installation Information provided,
|
||||||
|
in accord with this section must be in a format that is publicly
|
||||||
|
documented (and with an implementation available to the public in
|
||||||
|
source code form), and must require no special password or key for
|
||||||
|
unpacking, reading or copying.
|
||||||
|
|
||||||
|
7. Additional Terms.
|
||||||
|
|
||||||
|
"Additional permissions" are terms that supplement the terms of this
|
||||||
|
License by making exceptions from one or more of its conditions.
|
||||||
|
Additional permissions that are applicable to the entire Program shall
|
||||||
|
be treated as though they were included in this License, to the extent
|
||||||
|
that they are valid under applicable law. If additional permissions
|
||||||
|
apply only to part of the Program, that part may be used separately
|
||||||
|
under those permissions, but the entire Program remains governed by
|
||||||
|
this License without regard to the additional permissions.
|
||||||
|
|
||||||
|
When you convey a copy of a covered work, you may at your option
|
||||||
|
remove any additional permissions from that copy, or from any part of
|
||||||
|
it. (Additional permissions may be written to require their own
|
||||||
|
removal in certain cases when you modify the work.) You may place
|
||||||
|
additional permissions on material, added by you to a covered work,
|
||||||
|
for which you have or can give appropriate copyright permission.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, for material you
|
||||||
|
add to a covered work, you may (if authorized by the copyright holders of
|
||||||
|
that material) supplement the terms of this License with terms:
|
||||||
|
|
||||||
|
a) Disclaiming warranty or limiting liability differently from the
|
||||||
|
terms of sections 15 and 16 of this License; or
|
||||||
|
|
||||||
|
b) Requiring preservation of specified reasonable legal notices or
|
||||||
|
author attributions in that material or in the Appropriate Legal
|
||||||
|
Notices displayed by works containing it; or
|
||||||
|
|
||||||
|
c) Prohibiting misrepresentation of the origin of that material, or
|
||||||
|
requiring that modified versions of such material be marked in
|
||||||
|
reasonable ways as different from the original version; or
|
||||||
|
|
||||||
|
d) Limiting the use for publicity purposes of names of licensors or
|
||||||
|
authors of the material; or
|
||||||
|
|
||||||
|
e) Declining to grant rights under trademark law for use of some
|
||||||
|
trade names, trademarks, or service marks; or
|
||||||
|
|
||||||
|
f) Requiring indemnification of licensors and authors of that
|
||||||
|
material by anyone who conveys the material (or modified versions of
|
||||||
|
it) with contractual assumptions of liability to the recipient, for
|
||||||
|
any liability that these contractual assumptions directly impose on
|
||||||
|
those licensors and authors.
|
||||||
|
|
||||||
|
All other non-permissive additional terms are considered "further
|
||||||
|
restrictions" within the meaning of section 10. If the Program as you
|
||||||
|
received it, or any part of it, contains a notice stating that it is
|
||||||
|
governed by this License along with a term that is a further
|
||||||
|
restriction, you may remove that term. If a license document contains
|
||||||
|
a further restriction but permits relicensing or conveying under this
|
||||||
|
License, you may add to a covered work material governed by the terms
|
||||||
|
of that license document, provided that the further restriction does
|
||||||
|
not survive such relicensing or conveying.
|
||||||
|
|
||||||
|
If you add terms to a covered work in accord with this section, you
|
||||||
|
must place, in the relevant source files, a statement of the
|
||||||
|
additional terms that apply to those files, or a notice indicating
|
||||||
|
where to find the applicable terms.
|
||||||
|
|
||||||
|
Additional terms, permissive or non-permissive, may be stated in the
|
||||||
|
form of a separately written license, or stated as exceptions;
|
||||||
|
the above requirements apply either way.
|
||||||
|
|
||||||
|
8. Termination.
|
||||||
|
|
||||||
|
You may not propagate or modify a covered work except as expressly
|
||||||
|
provided under this License. Any attempt otherwise to propagate or
|
||||||
|
modify it is void, and will automatically terminate your rights under
|
||||||
|
this License (including any patent licenses granted under the third
|
||||||
|
paragraph of section 11).
|
||||||
|
|
||||||
|
However, if you cease all violation of this License, then your
|
||||||
|
license from a particular copyright holder is reinstated (a)
|
||||||
|
provisionally, unless and until the copyright holder explicitly and
|
||||||
|
finally terminates your license, and (b) permanently, if the copyright
|
||||||
|
holder fails to notify you of the violation by some reasonable means
|
||||||
|
prior to 60 days after the cessation.
|
||||||
|
|
||||||
|
Moreover, your license from a particular copyright holder is
|
||||||
|
reinstated permanently if the copyright holder notifies you of the
|
||||||
|
violation by some reasonable means, this is the first time you have
|
||||||
|
received notice of violation of this License (for any work) from that
|
||||||
|
copyright holder, and you cure the violation prior to 30 days after
|
||||||
|
your receipt of the notice.
|
||||||
|
|
||||||
|
Termination of your rights under this section does not terminate the
|
||||||
|
licenses of parties who have received copies or rights from you under
|
||||||
|
this License. If your rights have been terminated and not permanently
|
||||||
|
reinstated, you do not qualify to receive new licenses for the same
|
||||||
|
material under section 10.
|
||||||
|
|
||||||
|
9. Acceptance Not Required for Having Copies.
|
||||||
|
|
||||||
|
You are not required to accept this License in order to receive or
|
||||||
|
run a copy of the Program. Ancillary propagation of a covered work
|
||||||
|
occurring solely as a consequence of using peer-to-peer transmission
|
||||||
|
to receive a copy likewise does not require acceptance. However,
|
||||||
|
nothing other than this License grants you permission to propagate or
|
||||||
|
modify any covered work. These actions infringe copyright if you do
|
||||||
|
not accept this License. Therefore, by modifying or propagating a
|
||||||
|
covered work, you indicate your acceptance of this License to do so.
|
||||||
|
|
||||||
|
10. Automatic Licensing of Downstream Recipients.
|
||||||
|
|
||||||
|
Each time you convey a covered work, the recipient automatically
|
||||||
|
receives a license from the original licensors, to run, modify and
|
||||||
|
propagate that work, subject to this License. You are not responsible
|
||||||
|
for enforcing compliance by third parties with this License.
|
||||||
|
|
||||||
|
An "entity transaction" is a transaction transferring control of an
|
||||||
|
organization, or substantially all assets of one, or subdividing an
|
||||||
|
organization, or merging organizations. If propagation of a covered
|
||||||
|
work results from an entity transaction, each party to that
|
||||||
|
transaction who receives a copy of the work also receives whatever
|
||||||
|
licenses to the work the party's predecessor in interest had or could
|
||||||
|
give under the previous paragraph, plus a right to possession of the
|
||||||
|
Corresponding Source of the work from the predecessor in interest, if
|
||||||
|
the predecessor has it or can get it with reasonable efforts.
|
||||||
|
|
||||||
|
You may not impose any further restrictions on the exercise of the
|
||||||
|
rights granted or affirmed under this License. For example, you may
|
||||||
|
not impose a license fee, royalty, or other charge for exercise of
|
||||||
|
rights granted under this License, and you may not initiate litigation
|
||||||
|
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||||
|
any patent claim is infringed by making, using, selling, offering for
|
||||||
|
sale, or importing the Program or any portion of it.
|
||||||
|
|
||||||
|
11. Patents.
|
||||||
|
|
||||||
|
A "contributor" is a copyright holder who authorizes use under this
|
||||||
|
License of the Program or a work on which the Program is based. The
|
||||||
|
work thus licensed is called the contributor's "contributor version".
|
||||||
|
|
||||||
|
A contributor's "essential patent claims" are all patent claims
|
||||||
|
owned or controlled by the contributor, whether already acquired or
|
||||||
|
hereafter acquired, that would be infringed by some manner, permitted
|
||||||
|
by this License, of making, using, or selling its contributor version,
|
||||||
|
but do not include claims that would be infringed only as a
|
||||||
|
consequence of further modification of the contributor version. For
|
||||||
|
purposes of this definition, "control" includes the right to grant
|
||||||
|
patent sublicenses in a manner consistent with the requirements of
|
||||||
|
this License.
|
||||||
|
|
||||||
|
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||||
|
patent license under the contributor's essential patent claims, to
|
||||||
|
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||||
|
propagate the contents of its contributor version.
|
||||||
|
|
||||||
|
In the following three paragraphs, a "patent license" is any express
|
||||||
|
agreement or commitment, however denominated, not to enforce a patent
|
||||||
|
(such as an express permission to practice a patent or covenant not to
|
||||||
|
sue for patent infringement). To "grant" such a patent license to a
|
||||||
|
party means to make such an agreement or commitment not to enforce a
|
||||||
|
patent against the party.
|
||||||
|
|
||||||
|
If you convey a covered work, knowingly relying on a patent license,
|
||||||
|
and the Corresponding Source of the work is not available for anyone
|
||||||
|
to copy, free of charge and under the terms of this License, through a
|
||||||
|
publicly available network server or other readily accessible means,
|
||||||
|
then you must either (1) cause the Corresponding Source to be so
|
||||||
|
available, or (2) arrange to deprive yourself of the benefit of the
|
||||||
|
patent license for this particular work, or (3) arrange, in a manner
|
||||||
|
consistent with the requirements of this License, to extend the patent
|
||||||
|
license to downstream recipients. "Knowingly relying" means you have
|
||||||
|
actual knowledge that, but for the patent license, your conveying the
|
||||||
|
covered work in a country, or your recipient's use of the covered work
|
||||||
|
in a country, would infringe one or more identifiable patents in that
|
||||||
|
country that you have reason to believe are valid.
|
||||||
|
|
||||||
|
If, pursuant to or in connection with a single transaction or
|
||||||
|
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||||
|
covered work, and grant a patent license to some of the parties
|
||||||
|
receiving the covered work authorizing them to use, propagate, modify
|
||||||
|
or convey a specific copy of the covered work, then the patent license
|
||||||
|
you grant is automatically extended to all recipients of the covered
|
||||||
|
work and works based on it.
|
||||||
|
|
||||||
|
A patent license is "discriminatory" if it does not include within
|
||||||
|
the scope of its coverage, prohibits the exercise of, or is
|
||||||
|
conditioned on the non-exercise of one or more of the rights that are
|
||||||
|
specifically granted under this License. You may not convey a covered
|
||||||
|
work if you are a party to an arrangement with a third party that is
|
||||||
|
in the business of distributing software, under which you make payment
|
||||||
|
to the third party based on the extent of your activity of conveying
|
||||||
|
the work, and under which the third party grants, to any of the
|
||||||
|
parties who would receive the covered work from you, a discriminatory
|
||||||
|
patent license (a) in connection with copies of the covered work
|
||||||
|
conveyed by you (or copies made from those copies), or (b) primarily
|
||||||
|
for and in connection with specific products or compilations that
|
||||||
|
contain the covered work, unless you entered into that arrangement,
|
||||||
|
or that patent license was granted, prior to 28 March 2007.
|
||||||
|
|
||||||
|
Nothing in this License shall be construed as excluding or limiting
|
||||||
|
any implied license or other defenses to infringement that may
|
||||||
|
otherwise be available to you under applicable patent law.
|
||||||
|
|
||||||
|
12. No Surrender of Others' Freedom.
|
||||||
|
|
||||||
|
If conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot convey a
|
||||||
|
covered work so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you may
|
||||||
|
not convey it at all. For example, if you agree to terms that obligate you
|
||||||
|
to collect a royalty for further conveying from those to whom you convey
|
||||||
|
the Program, the only way you could satisfy both those terms and this
|
||||||
|
License would be to refrain entirely from conveying the Program.
|
||||||
|
|
||||||
|
13. Use with the GNU Affero General Public License.
|
||||||
|
|
||||||
|
Notwithstanding any other provision of this License, you have
|
||||||
|
permission to link or combine any covered work with a work licensed
|
||||||
|
under version 3 of the GNU Affero General Public License into a single
|
||||||
|
combined work, and to convey the resulting work. The terms of this
|
||||||
|
License will continue to apply to the part which is the covered work,
|
||||||
|
but the special requirements of the GNU Affero General Public License,
|
||||||
|
section 13, concerning interaction through a network will apply to the
|
||||||
|
combination as such.
|
||||||
|
|
||||||
|
14. Revised Versions of this License.
|
||||||
|
|
||||||
|
The Free Software Foundation may publish revised and/or new versions of
|
||||||
|
the GNU General Public License from time to time. Such new versions will
|
||||||
|
be similar in spirit to the present version, but may differ in detail to
|
||||||
|
address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the
|
||||||
|
Program specifies that a certain numbered version of the GNU General
|
||||||
|
Public License "or any later version" applies to it, you have the
|
||||||
|
option of following the terms and conditions either of that numbered
|
||||||
|
version or of any later version published by the Free Software
|
||||||
|
Foundation. If the Program does not specify a version number of the
|
||||||
|
GNU General Public License, you may choose any version ever published
|
||||||
|
by the Free Software Foundation.
|
||||||
|
|
||||||
|
If the Program specifies that a proxy can decide which future
|
||||||
|
versions of the GNU General Public License can be used, that proxy's
|
||||||
|
public statement of acceptance of a version permanently authorizes you
|
||||||
|
to choose that version for the Program.
|
||||||
|
|
||||||
|
Later license versions may give you additional or different
|
||||||
|
permissions. However, no additional obligations are imposed on any
|
||||||
|
author or copyright holder as a result of your choosing to follow a
|
||||||
|
later version.
|
||||||
|
|
||||||
|
15. Disclaimer of Warranty.
|
||||||
|
|
||||||
|
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||||
|
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||||
|
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||||
|
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||||
|
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||||
|
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. Limitation of Liability.
|
||||||
|
|
||||||
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||||
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||||
|
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||||
|
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||||
|
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||||
|
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||||
|
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||||
|
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||||
|
SUCH DAMAGES.
|
||||||
|
|
||||||
|
17. Interpretation of Sections 15 and 16.
|
||||||
|
|
||||||
|
If the disclaimer of warranty and limitation of liability provided
|
||||||
|
above cannot be given local legal effect according to their terms,
|
||||||
|
reviewing courts shall apply local law that most closely approximates
|
||||||
|
an absolute waiver of all civil liability in connection with the
|
||||||
|
Program, unless a warranty or assumption of liability accompanies a
|
||||||
|
copy of the Program in return for a fee.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply These Terms to Your New Programs
|
||||||
|
|
||||||
|
If you develop a new program, and you want it to be of the greatest
|
||||||
|
possible use to the public, the best way to achieve this is to make it
|
||||||
|
free software which everyone can redistribute and change under these terms.
|
||||||
|
|
||||||
|
To do so, attach the following notices to the program. It is safest
|
||||||
|
to attach them to the start of each source file to most effectively
|
||||||
|
state the exclusion of warranty; and each file should have at least
|
||||||
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
|
Copyright (C) <year> <name of author>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Also add information on how to contact you by electronic and paper mail.
|
||||||
|
|
||||||
|
If the program does terminal interaction, make it output a short
|
||||||
|
notice like this when it starts in an interactive mode:
|
||||||
|
|
||||||
|
<program> Copyright (C) <year> <name of author>
|
||||||
|
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
|
This is free software, and you are welcome to redistribute it
|
||||||
|
under certain conditions; type `show c' for details.
|
||||||
|
|
||||||
|
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||||
|
parts of the General Public License. Of course, your program's commands
|
||||||
|
might be different; for a GUI interface, you would use an "about box".
|
||||||
|
|
||||||
|
You should also get your employer (if you work as a programmer) or school,
|
||||||
|
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||||
|
For more information on this, and how to apply and follow the GNU GPL, see
|
||||||
|
<http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
The GNU General Public License does not permit incorporating your program
|
||||||
|
into proprietary programs. If your program is a subroutine library, you
|
||||||
|
may consider it more useful to permit linking proprietary applications with
|
||||||
|
the library. If this is what you want to do, use the GNU Lesser General
|
||||||
|
Public License instead of this License. But first, please read
|
||||||
|
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
131
INSTALL
Normal file
131
INSTALL
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
Build & install instructions
|
||||||
|
============================
|
||||||
|
|
||||||
|
These are build & install instructions for Dementia.
|
||||||
|
|
||||||
|
Build systems
|
||||||
|
=============
|
||||||
|
|
||||||
|
The "official" build system for Linux is CMake.
|
||||||
|
|
||||||
|
There are also qmake project files for easier cross-compilation for Windows and Android. Qt5 is required.
|
||||||
|
|
||||||
|
I used to make Windows releases also with CMake, but in the future I'll cross-compile for Windows on Ubuntu host by using MXE and qmake. MXE is a cool cross-compilation environment
|
||||||
|
and all libraries are linked statically by default (no DLLs needed).
|
||||||
|
|
||||||
|
Toolchains
|
||||||
|
==========
|
||||||
|
|
||||||
|
GCC/MinGW and Clang are the only "officially" supported toolchains on Linux.
|
||||||
|
|
||||||
|
Windows builds are done on Ubuntu with MXE (web: mxe.cc). The build script
|
||||||
|
also generates automatically an NSIS Windows installer and a ZIP-archive.
|
||||||
|
See scripts/mxeWindowsBuild.sh.
|
||||||
|
|
||||||
|
Building the project with Microsoft Visual C++ 2013 also works, but no automatic
|
||||||
|
packaging/deployment currently exist. The runtime files (data/, Qt, OpenAL..) must be
|
||||||
|
manually copied in place. See more detailed instructions below.
|
||||||
|
|
||||||
|
Build dependencies
|
||||||
|
==================
|
||||||
|
|
||||||
|
Currently the build depends on Qt only.
|
||||||
|
|
||||||
|
Dementia also exploits some features of the C++11 standard,
|
||||||
|
so a somewhat compliant compiler is required (GCC >= 4.7).
|
||||||
|
|
||||||
|
Building in the command line on Linux (tested on Ubuntu 16.04)
|
||||||
|
==============================================================
|
||||||
|
|
||||||
|
Development build (the app can be run without installing anything):
|
||||||
|
-------------------------------------------------------------------
|
||||||
|
|
||||||
|
1) Install Qt5 development files (qt5-default on Ubuntu).
|
||||||
|
2) Install CMake (cmake on Debian/Ubuntu).
|
||||||
|
3) Go to the source directory and run:
|
||||||
|
|
||||||
|
$ mkdir build
|
||||||
|
$ cd build
|
||||||
|
$ cmake ..
|
||||||
|
|
||||||
|
This runs CMake that generates the makefiles.
|
||||||
|
|
||||||
|
You can also use Qt Creator to open the top-level CMakeLists.txt and build inside Qt Creator.
|
||||||
|
There's also a convenience configure script which is just a wrapper for cmake.
|
||||||
|
|
||||||
|
Anyway, if everything went ok with cmake, run:
|
||||||
|
|
||||||
|
$ make
|
||||||
|
|
||||||
|
This will build the application.
|
||||||
|
|
||||||
|
Run Dementia:
|
||||||
|
|
||||||
|
$ ./dementia
|
||||||
|
|
||||||
|
Run unit tests:
|
||||||
|
|
||||||
|
$ ctest
|
||||||
|
|
||||||
|
Release build (in this example Dementia installs under /usr):
|
||||||
|
--------------------------------------------------------
|
||||||
|
|
||||||
|
$ mkdir build
|
||||||
|
$ cd build
|
||||||
|
$ cmake .. -DReleaseBuild=1 -DCMAKE_INSTALL_PREFIX=/usr
|
||||||
|
|
||||||
|
This runs CMake that generates the makefiles.
|
||||||
|
If everything went ok, run:
|
||||||
|
|
||||||
|
$ make
|
||||||
|
|
||||||
|
This will build the application.
|
||||||
|
|
||||||
|
Install the binaries and data files:
|
||||||
|
|
||||||
|
$ sudo make install
|
||||||
|
|
||||||
|
This installs also the desktop files so Dementia should appear in your application menu.
|
||||||
|
|
||||||
|
Cross-compiling for Windows with MXE on Linux (tested on Ubuntu 16.04)
|
||||||
|
======================================================================
|
||||||
|
|
||||||
|
1) Install MXE (http://mxe.cc)
|
||||||
|
2) Install Qt5 with MXE
|
||||||
|
3) Run <Your MXE installation dir>/usr/i686-pc-mingw32/qt5/bin/qmake dementia.pro
|
||||||
|
4) make
|
||||||
|
|
||||||
|
There's also a script to build the application with a Windows installer:
|
||||||
|
1) export DEMENTIA_RELEASE_VERSION=x.y.z (use the latest version)
|
||||||
|
2) source ./scripts/mxeEnv.sh (assumes that MXE is installed in /opt/mxe)
|
||||||
|
3) ./scripts/mxeWindowsBuild.sh
|
||||||
|
|
||||||
|
The script checks that needed binaries are found.
|
||||||
|
|
||||||
|
CPack
|
||||||
|
=====
|
||||||
|
|
||||||
|
Dementia has a support for CPack. It's not complete, but can be used to generate
|
||||||
|
some generic binary packages.
|
||||||
|
|
||||||
|
After a successful build run CPack:
|
||||||
|
|
||||||
|
$ cpack
|
||||||
|
|
||||||
|
This will generate .tar.gz and .sh binary packages on Linux.
|
||||||
|
|
||||||
|
For packagers
|
||||||
|
=============
|
||||||
|
|
||||||
|
The release build should be used when packaging (give
|
||||||
|
-DReleaseBuild=1 to cmake).
|
||||||
|
|
||||||
|
CMAKE_INSTALL_PREFIX usually defaults to /usr/local and
|
||||||
|
can be changed by giving, for example, -DCMAKE_INSTALL_PREFIX=/usr
|
||||||
|
to cmake (or to the configure script).
|
||||||
|
|
||||||
|
There's an example Debian packaging in packaging/debian/.
|
||||||
|
|
||||||
|
|
||||||
|
-- Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
|
82
InstallLinux.cmake
Normal file
82
InstallLinux.cmake
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
# **** Resolve install and data paths ****
|
||||||
|
function(resolve_install_paths)
|
||||||
|
|
||||||
|
# Set default install paths for release builds.
|
||||||
|
set(DEFAULT_DATA_PATH_BASE share/applications/dementia)
|
||||||
|
if(NOT DATA_PATH)
|
||||||
|
set(DATA_PATH ${CMAKE_INSTALL_PREFIX}/${DEFAULT_DATA_PATH_BASE}/data)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT BIN_PATH)
|
||||||
|
set(BIN_PATH bin)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT DOC_PATH)
|
||||||
|
set(DOC_PATH ${CMAKE_INSTALL_PREFIX}/${DEFAULT_DATA_PATH_BASE}/)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(ReleaseBuild)
|
||||||
|
message(STATUS "Linux release build with system install targets.")
|
||||||
|
else()
|
||||||
|
message(STATUS "Linux development build with local install targets.")
|
||||||
|
set(BIN_PATH .)
|
||||||
|
set(DATA_PATH ./data)
|
||||||
|
set(DOC_PATH .)
|
||||||
|
|
||||||
|
# Add target to copy runtime files to the binary dir.
|
||||||
|
add_custom_target(runtime ALL
|
||||||
|
COMMAND cmake -E copy_directory ${CMAKE_SOURCE_DIR}/data ${CMAKE_BINARY_DIR}/data
|
||||||
|
COMMAND cmake -E copy ${CMAKE_SOURCE_DIR}/AUTHORS ${CMAKE_BINARY_DIR}/AUTHORS
|
||||||
|
COMMAND cmake -E copy ${CMAKE_SOURCE_DIR}/CHANGELOG ${CMAKE_BINARY_DIR}/CHANGELOG
|
||||||
|
COMMAND cmake -E copy ${CMAKE_SOURCE_DIR}/COPYING ${CMAKE_BINARY_DIR}/COPYING
|
||||||
|
COMMAND cmake -E copy ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_BINARY_DIR}/README.md
|
||||||
|
DEPENDS ${GAME_BINARY_NAME} ${QM_FILES})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
message(STATUS "BIN_PATH: " ${BIN_PATH})
|
||||||
|
message(STATUS "DATA_PATH: " ${DATA_PATH})
|
||||||
|
message(STATUS "DOC_PATH:" ${DOC_PATH})
|
||||||
|
|
||||||
|
# This is the main data path
|
||||||
|
add_definitions(-DDATA_PATH="${DATA_PATH}")
|
||||||
|
|
||||||
|
setup_install_targets(${BIN_PATH} ${DATA_PATH} ${DOC_PATH})
|
||||||
|
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# **** Install targets for Linux ****
|
||||||
|
function(setup_install_targets BIN_PATH DATA_PATH DOC_PATH)
|
||||||
|
|
||||||
|
# Install binaries and data
|
||||||
|
install(PROGRAMS ${CMAKE_BINARY_DIR}/${BINARY_NAME} DESTINATION ${BIN_PATH})
|
||||||
|
install(FILES AUTHORS CHANGELOG COPYING README.md DESTINATION ${DOC_PATH})
|
||||||
|
install(DIRECTORY ${CMAKE_BINARY_DIR}/data/translations DESTINATION ${DATA_PATH} FILES_MATCHING PATTERN "*.qm")
|
||||||
|
|
||||||
|
if(ReleaseBuild)
|
||||||
|
# Install .desktop files
|
||||||
|
install(FILES ${CMAKE_BINARY_DIR}/dementia.desktop DESTINATION share/applications)
|
||||||
|
|
||||||
|
# Install app store meta data
|
||||||
|
install(FILES src/dementia.appdata.xml DESTINATION share/metainfo)
|
||||||
|
|
||||||
|
# Install icons
|
||||||
|
install(FILES data/icons/dementia.png DESTINATION share/pixmaps)
|
||||||
|
install(FILES data/icons/dementia.png DESTINATION share/icons/hicolor/64x64/apps)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# CPack config to create e.g. self-extracting packages
|
||||||
|
set(CPACK_BINARY_STGZ ON)
|
||||||
|
set(CPACK_BINARY_TGZ ON)
|
||||||
|
set(CPACK_BINARY_TZ OFF)
|
||||||
|
|
||||||
|
set(QT_VER_STR "qt5")
|
||||||
|
|
||||||
|
set(CPACK_PACKAGE_FILE_NAME "dementia-${VERSION}-linux-${CMAKE_HOST_SYSTEM_PROCESSOR}-${QT_VER_STR}")
|
||||||
|
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/COPYING)
|
||||||
|
set(CPACK_RESOURCE_FILE_README ${CMAKE_SOURCE_DIR}/README.md)
|
||||||
|
|
||||||
|
if(NOT ReleaseBuild)
|
||||||
|
include(CPack)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
endfunction()
|
43
InstallWindows.cmake
Normal file
43
InstallWindows.cmake
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
# **** Resolve install and data paths ****
|
||||||
|
function(resolve_install_paths)
|
||||||
|
|
||||||
|
message(STATUS "Windows build.")
|
||||||
|
|
||||||
|
set(BIN_PATH .)
|
||||||
|
set(DATA_PATH ./data)
|
||||||
|
set(DOC_PATH .)
|
||||||
|
|
||||||
|
# This is the main data path given to the game and editor binaries.
|
||||||
|
add_definitions(-DDATA_PATH="${DATA_PATH}")
|
||||||
|
|
||||||
|
# Add target to copy runtime files to the binary dir.
|
||||||
|
add_custom_target(runtimeData ALL
|
||||||
|
COMMAND cmake -E copy_directory ${CMAKE_SOURCE_DIR}/data ${CMAKE_BINARY_DIR}/data
|
||||||
|
COMMAND cmake -E copy ${CMAKE_SOURCE_DIR}/AUTHORS ${CMAKE_BINARY_DIR}/AUTHORS
|
||||||
|
COMMAND cmake -E copy ${CMAKE_SOURCE_DIR}/CHANGELOG ${CMAKE_BINARY_DIR}/CHANGELOG
|
||||||
|
COMMAND cmake -E copy ${CMAKE_SOURCE_DIR}/COPYING ${CMAKE_BINARY_DIR}/COPYING
|
||||||
|
COMMAND cmake -E copy ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_BINARY_DIR}/README.md
|
||||||
|
DEPENDS ${GAME_BINARY_NAME} ${QM_FILES})
|
||||||
|
|
||||||
|
setup_install_targets(${BIN_PATH} ${DATA_PATH} ${DOC_PATH})
|
||||||
|
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
# **** Instal targets for Windows ****
|
||||||
|
function(setup_install_targets BIN_PATH DATA_PATH DOC_PATH)
|
||||||
|
|
||||||
|
# Install binaries and game data
|
||||||
|
install(PROGRAMS ${CMAKE_BINARY_DIR}/${GAME_BINARY_NAME}.exe DESTINATION ${BIN_PATH})
|
||||||
|
install(PROGRAMS ${CMAKE_BINARY_DIR}/${EDITOR_BINARY_NAME}.exe DESTINATION ${BIN_PATH})
|
||||||
|
install(FILES data/editorModels.conf DESTINATION ${DATA_PATH})
|
||||||
|
install(FILES data/meshes.conf DESTINATION ${DATA_PATH})
|
||||||
|
install(FILES data/surfaces.conf DESTINATION ${DATA_PATH})
|
||||||
|
install(FILES AUTHORS CHANGELOG COPYING README.md DESTINATION ${DOC_PATH})
|
||||||
|
install(DIRECTORY data/images DESTINATION ${DATA_PATH} FILES_MATCHING PATTERN "*.jpg")
|
||||||
|
install(DIRECTORY data/images DESTINATION ${DATA_PATH} FILES_MATCHING PATTERN "*.png")
|
||||||
|
install(DIRECTORY data/levels DESTINATION ${DATA_PATH} FILES_MATCHING PATTERN "*.trk")
|
||||||
|
install(DIRECTORY data/models DESTINATION ${DATA_PATH} FILES_MATCHING PATTERN "*.obj")
|
||||||
|
install(DIRECTORY data/translations DESTINATION ${DATA_PATH} FILES_MATCHING PATTERN "*.qm")
|
||||||
|
|
||||||
|
endfunction()
|
||||||
|
|
21
README.md
Normal file
21
README.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
## Dementia
|
||||||
|
|
||||||
|
Dementia is an application for creating mind maps.
|
||||||
|
|
||||||
|
It's currently under development and CANNOT BE USED FOR ANYTHING!
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Dementia's source code is licensed under GNU GPLv3.
|
||||||
|
See COPYING for the complete license text.
|
||||||
|
|
||||||
|
All image files, except where otherwise noted, are licensed under
|
||||||
|
CC BY-SA 3.0: http://creativecommons.org/licenses/by-sa/3.0/
|
||||||
|
|
||||||
|
## Building the project
|
||||||
|
|
||||||
|
Please refer to the INSTALL document for build/install instructions if you're
|
||||||
|
going to build Dementia from sources.
|
||||||
|
|
||||||
|
-- Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
|
3
configure
vendored
Executable file
3
configure
vendored
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
rm -f CMakeCache.txt
|
||||||
|
cmake . $@ && echo "Configuring compeleted. Now run \"make\"."
|
BIN
data/icons/Dementia.ico
Normal file
BIN
data/icons/Dementia.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
1
data/icons/WindowsDementia.rc
Normal file
1
data/icons/WindowsDementia.rc
Normal file
@ -0,0 +1 @@
|
|||||||
|
IDI_ICON1 ICON DISCARDABLE "Dementia.ico"
|
BIN
data/icons/dementia.png
Normal file
BIN
data/icons/dementia.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.1 KiB |
5
data/icons/icons.qrc
Normal file
5
data/icons/icons.qrc
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>dementia.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
BIN
data/images/about.png
Normal file
BIN
data/images/about.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.4 KiB |
BIN
data/images/add.png
Normal file
BIN
data/images/add.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
6
data/images/images.qrc
Normal file
6
data/images/images.qrc
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<RCC>
|
||||||
|
<qresource prefix="/">
|
||||||
|
<file>about.png</file>
|
||||||
|
<file>add.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
8
dementia.pro
Normal file
8
dementia.pro
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Top-level Qt project file
|
||||||
|
|
||||||
|
TEMPLATE = subdirs
|
||||||
|
SUBDIRS += src/editor
|
||||||
|
|
||||||
|
data.path = $$OUT_PWD/
|
||||||
|
data.files = AUTHORS CHANGELOG COPYING README
|
||||||
|
|
8
packaging/README
Normal file
8
packaging/README
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
README
|
||||||
|
======
|
||||||
|
|
||||||
|
debian : Example packaging for Ubuntu/Debian.
|
||||||
|
windows : Packaging script for NSIS.
|
||||||
|
|
||||||
|
-- Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
|
2
packaging/debian/changelog
Normal file
2
packaging/debian/changelog
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
|
||||||
|
|
1
packaging/debian/compat
Normal file
1
packaging/debian/compat
Normal file
@ -0,0 +1 @@
|
|||||||
|
8
|
14
packaging/debian/control
Normal file
14
packaging/debian/control
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
Source: dementia
|
||||||
|
Section: education
|
||||||
|
Priority: extra
|
||||||
|
Maintainer: Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
Build-Depends: debhelper (>= 8.0.0), cmake (>= 2.8.0), pkg-config, qt5-default (>= 5.2.0), qttools5-dev (>= 5.2.0), qttools5-dev-tools (>= 5.2.0)
|
||||||
|
Standards-Version: 3.9.2
|
||||||
|
Homepage: http://juzzlin.github.io/Dementia/index.html
|
||||||
|
Vcs-Git: git@github.com:juzzlin/Dementia.git
|
||||||
|
|
||||||
|
Package: dementia
|
||||||
|
Architecture: any
|
||||||
|
Depends: ${shlibs:Depends}, ${misc:Depends}
|
||||||
|
Description: An application for creating and managing mind maps
|
||||||
|
|
42
packaging/debian/copyright
Normal file
42
packaging/debian/copyright
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
Format: http://dep.debian.net/deps/dep5
|
||||||
|
Upstream-Name: dementia
|
||||||
|
Source: https://sourceforge.net/projects/dementia/
|
||||||
|
|
||||||
|
Files: *
|
||||||
|
Copyright: 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
License: GPL-3.0+
|
||||||
|
|
||||||
|
Files: data/images/*
|
||||||
|
Copyright: 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
License: CC BY-SA 3.0
|
||||||
|
|
||||||
|
Files: data/icons/*
|
||||||
|
Copyright: 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
License: CC BY-SA 3.0
|
||||||
|
|
||||||
|
Files: debian/*
|
||||||
|
Copyright: 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
License: GPL-3.0+
|
||||||
|
|
||||||
|
License: GPL-3.0+
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
.
|
||||||
|
This package is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
.
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
.
|
||||||
|
On Debian systems, the complete text of the GNU General
|
||||||
|
Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
|
||||||
|
|
||||||
|
License: CC BY-SA 3.0
|
||||||
|
http://creativecommons.org/licenses/by-sa/3.0/
|
||||||
|
|
||||||
|
# Please also look if there are files or directories which have a
|
||||||
|
# different copyright/license attached and list them here.
|
78
packaging/debian/rules
Executable file
78
packaging/debian/rules
Executable file
@ -0,0 +1,78 @@
|
|||||||
|
#!/usr/bin/make -f
|
||||||
|
# Sample debian/rules that uses debhelper.
|
||||||
|
# This file is public domain software, originally written by Joey Hess.
|
||||||
|
#
|
||||||
|
# This version is for packages that are architecture dependent.
|
||||||
|
|
||||||
|
# Uncomment this to turn on verbose mode.
|
||||||
|
#export DH_VERBOSE=1
|
||||||
|
|
||||||
|
build: build-stamp
|
||||||
|
build-stamp:
|
||||||
|
dh_testdir
|
||||||
|
|
||||||
|
# Add here commands to compile the package.
|
||||||
|
cmake . -DReleaseBuild=1 -DUSC=1 -DCMAKE_INSTALL_PREFIX=/usr && $(MAKE) -j$(shell cat /proc/cpuinfo | grep processor | wc -l)
|
||||||
|
touch build-stamp
|
||||||
|
|
||||||
|
clean:
|
||||||
|
dh_testdir
|
||||||
|
dh_testroot
|
||||||
|
rm -f build-stamp
|
||||||
|
|
||||||
|
# Add here commands to clean up after the build process.
|
||||||
|
dh_clean
|
||||||
|
$(test -r Makefile && $MAKE clean)
|
||||||
|
|
||||||
|
install: build
|
||||||
|
dh_testdir
|
||||||
|
dh_testroot
|
||||||
|
dh_prep
|
||||||
|
dh_installdirs
|
||||||
|
|
||||||
|
# Add here commands to install the package into debian/<packagename>
|
||||||
|
DESTDIR=`pwd`/debian/`dh_listpackages` $(MAKE) install
|
||||||
|
|
||||||
|
# Build architecture-independent files here.
|
||||||
|
binary-indep: build install
|
||||||
|
# We have nothing to do by default.
|
||||||
|
|
||||||
|
# Build architecture-dependent files here.
|
||||||
|
binary-arch: build install
|
||||||
|
dh_testdir
|
||||||
|
dh_testroot
|
||||||
|
dh_installchangelogs
|
||||||
|
dh_installdocs
|
||||||
|
dh_installexamples
|
||||||
|
# dh_install
|
||||||
|
# dh_installmenu
|
||||||
|
# dh_installdebconf
|
||||||
|
# dh_installlogrotate
|
||||||
|
# dh_installemacsen
|
||||||
|
# dh_installcatalogs
|
||||||
|
# dh_installpam
|
||||||
|
# dh_installmime
|
||||||
|
# dh_installinit
|
||||||
|
# dh_installcron
|
||||||
|
# dh_installinfo
|
||||||
|
# dh_installwm
|
||||||
|
# dh_installudev
|
||||||
|
# dh_lintian
|
||||||
|
# dh_bugfiles
|
||||||
|
# dh_undocumented
|
||||||
|
# dh_installman
|
||||||
|
dh_link
|
||||||
|
dh_strip
|
||||||
|
dh_compress
|
||||||
|
dh_fixperms
|
||||||
|
# dh_perl
|
||||||
|
# dh_makeshlibs
|
||||||
|
dh_installdeb
|
||||||
|
dh_shlibdeps
|
||||||
|
dh_gencontrol
|
||||||
|
dh_md5sums
|
||||||
|
dh_builddeb
|
||||||
|
|
||||||
|
binary: binary-indep binary-arch
|
||||||
|
.PHONY: build clean binary-indep binary-arch binary install
|
||||||
|
|
148
packaging/windows/dementia.nsi
Normal file
148
packaging/windows/dementia.nsi
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
; Script for NSIS packaging.
|
||||||
|
|
||||||
|
!define PRODUCTNAME "Dementia"
|
||||||
|
!define APPNAME "Dementia"
|
||||||
|
!define COMPANYNAME "Jussi Lind"
|
||||||
|
!define DESCRIPTION "An application for mind map creation and management."
|
||||||
|
!define VERSIONMAJOR 0
|
||||||
|
!define VERSIONMINOR 0
|
||||||
|
!define VERSIONBUILD 0
|
||||||
|
!define HELPURL "http://juzzlin.github.io/Dementia/"
|
||||||
|
!define UPDATEURL "https://github.com/juzzlin/Dementia/releases"
|
||||||
|
!define ABOUTURL "http://juzzlin.github.io/Dementia/"
|
||||||
|
|
||||||
|
!define MUI_FILE ""
|
||||||
|
!define MUI_BRANDINGTEXT ${PRODUCTNAME}
|
||||||
|
;!define MUI_HEADERIMAGE
|
||||||
|
;!define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\orange.bmp"
|
||||||
|
!define MUI_ICON "data\icons\Dementia.ico"
|
||||||
|
!define MUI_UNICON "data\icons\Dementia.ico"
|
||||||
|
!define MUI_SPECIALBITMAP "data\icons\Dementia.ico"
|
||||||
|
|
||||||
|
!define MUI_WELCOMEPAGE
|
||||||
|
!define MUI_LICENSEPAGE
|
||||||
|
!define MUI_DIRECTORYPAGE
|
||||||
|
!define MUI_ABORTWARNING
|
||||||
|
!define MUI_UNINSTALLER
|
||||||
|
!define MUI_UNCONFIRMPAGE
|
||||||
|
!define MUI_FINISHPAGE
|
||||||
|
|
||||||
|
CRCCheck On
|
||||||
|
|
||||||
|
!include MUI2.nsh
|
||||||
|
!include LogicLib.nsh
|
||||||
|
|
||||||
|
RequestExecutionLevel admin
|
||||||
|
|
||||||
|
InstallDir "$PROGRAMFILES\${PRODUCTNAME}"
|
||||||
|
|
||||||
|
Name "${PRODUCTNAME}"
|
||||||
|
Icon "data\icons\Dementia.ico"
|
||||||
|
OutFile "dementia-${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}-windows-x86-qt5_setup.exe"
|
||||||
|
|
||||||
|
!insertmacro MUI_LANGUAGE "English"
|
||||||
|
|
||||||
|
LicenseData "COPYING"
|
||||||
|
|
||||||
|
Page license
|
||||||
|
Page directory
|
||||||
|
Page instfiles
|
||||||
|
|
||||||
|
!macro VerifyUserIsAdmin
|
||||||
|
UserInfo::GetAccountType
|
||||||
|
pop $0
|
||||||
|
${If} $0 != "admin" ;Require admin rights on NT4+
|
||||||
|
messageBox mb_iconstop "Administrator rights required!"
|
||||||
|
setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
|
||||||
|
quit
|
||||||
|
${EndIf}
|
||||||
|
!macroend
|
||||||
|
|
||||||
|
Function .onInit
|
||||||
|
SetShellVarContext all
|
||||||
|
!insertmacro VerifyUserIsAdmin
|
||||||
|
FunctionEnd
|
||||||
|
|
||||||
|
Section "install"
|
||||||
|
SetOutPath $INSTDIR
|
||||||
|
|
||||||
|
File dementia.exe
|
||||||
|
File CHANGELOG
|
||||||
|
File COPYING
|
||||||
|
File AUTHORS
|
||||||
|
File README.md
|
||||||
|
|
||||||
|
WriteUninstaller "$INSTDIR\uninstall.exe"
|
||||||
|
|
||||||
|
CreateDirectory "$SMPROGRAMS\${PRODUCTNAME}"
|
||||||
|
CreateShortCut "$SMPROGRAMS\${PRODUCTNAME}\${APPNAME}.lnk" \
|
||||||
|
"$INSTDIR\dementia.exe" "" "$INSTDIR\data\icons\Dementia.ico"
|
||||||
|
CreateShortCut "$SMPROGRAMS\${PRODUCTNAME}\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" ""
|
||||||
|
|
||||||
|
CreateShortCut "$DESKTOP\${APPNAME}.lnk" "$INSTDIR\dementia.exe" "" "$INSTDIR\data\icons\Dementia.ico"
|
||||||
|
|
||||||
|
# Registry information for add/remove programs
|
||||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} \
|
||||||
|
${PRODUCTNAME}" "DisplayName" "${PRODUCTNAME} - ${DESCRIPTION}"
|
||||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} \
|
||||||
|
${PRODUCTNAME}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
|
||||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} \
|
||||||
|
${PRODUCTNAME}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
|
||||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} \
|
||||||
|
${PRODUCTNAME}" "InstallLocation" "$\"$INSTDIR$\""
|
||||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} \
|
||||||
|
${PRODUCTNAME}" "DisplayIcon" "$\"$INSTDIR\logo.ico$\""
|
||||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} \
|
||||||
|
${PRODUCTNAME}" "Publisher" "$\"${COMPANYNAME}$\""
|
||||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} \
|
||||||
|
${PRODUCTNAME}" "HelpLink" "$\"${HELPURL}$\""
|
||||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} \
|
||||||
|
${PRODUCTNAME}" "URLUpdateInfo" "$\"${UPDATEURL}$\""
|
||||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} \
|
||||||
|
${PRODUCTNAME}" "URLInfoAbout" "$\"${ABOUTURL}$\""
|
||||||
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} \
|
||||||
|
${PRODUCTNAME}" "DisplayVersion" "$\"${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}$\""
|
||||||
|
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} \
|
||||||
|
${PRODUCTNAME}" "VersionMajor" ${VERSIONMAJOR}
|
||||||
|
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} \
|
||||||
|
${PRODUCTNAME}" "VersionMinor" ${VERSIONMINOR}
|
||||||
|
|
||||||
|
# There is no option for modifying or repairing the install
|
||||||
|
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${PRODUCTNAME}" "NoModify" 1
|
||||||
|
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${PRODUCTNAME}" "NoRepair" 1
|
||||||
|
|
||||||
|
SectionEnd
|
||||||
|
|
||||||
|
# Uninstaller
|
||||||
|
|
||||||
|
Function un.onInit
|
||||||
|
|
||||||
|
SetShellVarContext all
|
||||||
|
|
||||||
|
#Verify the uninstaller - last chance to back out
|
||||||
|
MessageBox MB_OKCANCEL "Permanently remove ${PRODUCTNAME}?" IDOK next
|
||||||
|
Abort
|
||||||
|
next:
|
||||||
|
!insertmacro VerifyUserIsAdmin
|
||||||
|
|
||||||
|
FunctionEnd
|
||||||
|
|
||||||
|
Section "uninstall"
|
||||||
|
|
||||||
|
RmDir /r "$SMPROGRAMS\${PRODUCTNAME}"
|
||||||
|
|
||||||
|
Delete "$DESKTOP\${APPNAME}.lnk"
|
||||||
|
|
||||||
|
Delete $INSTDIR\dementia.exe
|
||||||
|
Delete $INSTDIR\CHANGELOG
|
||||||
|
Delete $INSTDIR\COPYING
|
||||||
|
Delete $INSTDIR\AUTHORS
|
||||||
|
Delete $INSTDIR\README.md
|
||||||
|
|
||||||
|
Delete $INSTDIR\uninstall.exe
|
||||||
|
|
||||||
|
RmDir $INSTDIR
|
||||||
|
|
||||||
|
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${PRODUCTNAME}"
|
||||||
|
|
||||||
|
SectionEnd
|
4
scripts/archive.sh
Executable file
4
scripts/archive.sh
Executable file
@ -0,0 +1,4 @@
|
|||||||
|
VERSION=$(git log | grep -m 1 "^\s*[0-9]\.[0-9]*\.[0-9]*" | awk '{print $1}')
|
||||||
|
git archive --format=tar --prefix=dementia-$VERSION/ HEAD | gzip > dementia-$VERSION.tar.gz
|
||||||
|
git archive --format=zip --prefix=dementia-$VERSION/ HEAD > dementia-$VERSION.zip
|
||||||
|
|
6
scripts/ci/jenkins-cmake-debug.sh
Executable file
6
scripts/ci/jenkins-cmake-debug.sh
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Simple build script that can be run from Jenkins
|
||||||
|
|
||||||
|
(mkdir -p build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Debug && make) || exit 1
|
||||||
|
|
6
scripts/ci/jenkins-cmake-linux-install.sh
Executable file
6
scripts/ci/jenkins-cmake-linux-install.sh
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Simple build script that can be run from Jenkins
|
||||||
|
|
||||||
|
(mkdir -p build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -DReleaseBuild=ON && make) || exit 1
|
||||||
|
|
6
scripts/ci/jenkins-cmake.sh
Executable file
6
scripts/ci/jenkins-cmake.sh
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Simple build script that can be run from Jenkins
|
||||||
|
|
||||||
|
(mkdir -p build && cd build && cmake .. && make) || exit 1
|
||||||
|
|
6
scripts/ci/jenkins-qmake.sh
Executable file
6
scripts/ci/jenkins-qmake.sh
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Simple build script that can be run from Jenkins
|
||||||
|
|
||||||
|
(mkdir -p build && cd build && qmake .. && make) || exit 1
|
||||||
|
|
6
scripts/ci/jenkins-tests.sh
Executable file
6
scripts/ci/jenkins-tests.sh
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Simple build script that can be run from Jenkins
|
||||||
|
|
||||||
|
(mkdir -p build && cd build && cmake .. && make && ctest) || exit 1
|
||||||
|
|
88
scripts/genericLinuxBuildQt5.sh
Executable file
88
scripts/genericLinuxBuildQt5.sh
Executable file
@ -0,0 +1,88 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Assumes, that you have installed (static) qt5 to ~/qt5.
|
||||||
|
|
||||||
|
QT5_QMAKE=~/qt5/bin/qmake
|
||||||
|
if ! which $QT5_QMAKE; then
|
||||||
|
echo "$QT5_QMAKE not found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
TAR=tar
|
||||||
|
if ! which $TAR; then
|
||||||
|
echo "$TAR not found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
LRELEASE=lrelease
|
||||||
|
if ! which $LRELEASE; then
|
||||||
|
echo "$LRELEASE not found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
NUM_CPUS=$(cat /proc/cpuinfo | grep processor | wc -l)
|
||||||
|
|
||||||
|
# Package naming
|
||||||
|
|
||||||
|
NAME=dementia
|
||||||
|
VERSION=${DUSTRAC_RELEASE_VERSION?"DUSTRAC_RELEASE_VERSION_NOT_SET"}
|
||||||
|
ARCH=linux-x86_64
|
||||||
|
QT=qt5
|
||||||
|
|
||||||
|
# Build
|
||||||
|
|
||||||
|
$QT5_QMAKE && make -j$NUM_CPUS || exit 1
|
||||||
|
|
||||||
|
# Update translations
|
||||||
|
|
||||||
|
$LRELEASE ./src/game/game.pro && $LRELEASE ./src/editor/editor.pro || exit 1
|
||||||
|
|
||||||
|
# Install to packaging dir
|
||||||
|
|
||||||
|
PACKAGE_PATH=$NAME-$VERSION-$ARCH-$QT
|
||||||
|
rm -rf $PACKAGE_PATH
|
||||||
|
mkdir $PACKAGE_PATH
|
||||||
|
|
||||||
|
mkdir -p data/translations
|
||||||
|
cp -v ./src/game/translations/*.qm data/translations &&
|
||||||
|
cp -v ./src/editor/translations/*.qm data/translations &&
|
||||||
|
cp -v ./src/game/dementia-game $PACKAGE_PATH &&
|
||||||
|
cp -v ./src/editor/dementia-editor $PACKAGE_PATH &&
|
||||||
|
cp -rv data $PACKAGE_PATH || exit 1
|
||||||
|
|
||||||
|
TEXT_FILES="AUTHORS CHANGELOG COPYING README.md"
|
||||||
|
cp -v $TEXT_FILES $PACKAGE_PATH || exit 1
|
||||||
|
|
||||||
|
# Copy some needed dependecies
|
||||||
|
|
||||||
|
DEPS="ogg vorbis openal"
|
||||||
|
for lib in $DEPS; do
|
||||||
|
cp -v $(ldd $PACKAGE_PATH/dementia-game | grep $lib | awk '{print $3}') $PACKAGE_PATH
|
||||||
|
done
|
||||||
|
|
||||||
|
# Create start script for the game
|
||||||
|
|
||||||
|
cp $PACKAGE_PATH/dementia-game $PACKAGE_PATH/g.bin
|
||||||
|
SCRIPT=$PACKAGE_PATH/dementia-game
|
||||||
|
echo "#!/bin/sh" > $SCRIPT
|
||||||
|
echo "LD_LIBRARY_PATH=. ./g.bin" >> $SCRIPT
|
||||||
|
chmod 755 $SCRIPT
|
||||||
|
|
||||||
|
# Create start script for the editor
|
||||||
|
|
||||||
|
cp $PACKAGE_PATH/dementia-editor $PACKAGE_PATH/e.bin
|
||||||
|
SCRIPT=$PACKAGE_PATH/dementia-editor
|
||||||
|
echo "#!/bin/sh" > $SCRIPT
|
||||||
|
echo "LD_LIBRARY_PATH=. ./e.bin" >> $SCRIPT
|
||||||
|
chmod 755 $SCRIPT
|
||||||
|
|
||||||
|
# Create tgz archive
|
||||||
|
|
||||||
|
TGZ_ARCHIVE=$PACKAGE_PATH.tar.gz
|
||||||
|
rm -f $TGZ_ARCHIVE
|
||||||
|
$TAR czvf $TGZ_ARCHIVE $PACKAGE_PATH
|
||||||
|
|
||||||
|
ls -ltr
|
||||||
|
|
||||||
|
echo "Done."
|
||||||
|
|
73
scripts/license.py
Normal file
73
scripts/license.py
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
# This file is part of Dust Racing (DustRAC).
|
||||||
|
# Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
#
|
||||||
|
# DustRAC is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
# DustRAC is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with DustRAC. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
#
|
||||||
|
# This script replaces the license plate of the given file(s) with
|
||||||
|
# the given new license plate. license lines MUST begin with "//".
|
||||||
|
#
|
||||||
|
# e.g. python license.py gpl_header.txt `find . -name "*.hh"`
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def main(argv):
|
||||||
|
|
||||||
|
if len(argv) < 3:
|
||||||
|
print("Usage: python license.py [licenseHeaderFile] [sourceFiles]")
|
||||||
|
return 1
|
||||||
|
|
||||||
|
# Read the new license
|
||||||
|
fName = argv[1]
|
||||||
|
print("Opening " + fName + " for read..")
|
||||||
|
f = open(fName, 'r')
|
||||||
|
licenseLines = f.readlines()
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
for j in xrange(2, len(argv)):
|
||||||
|
fName = argv[j]
|
||||||
|
|
||||||
|
# Read the original file
|
||||||
|
print("Opening " + fName + " for read..")
|
||||||
|
f = open(fName, 'r')
|
||||||
|
origLines = f.readlines()
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
# Skip the current license plate
|
||||||
|
headerSkip = True
|
||||||
|
newLines = []
|
||||||
|
for i in origLines:
|
||||||
|
if (i.find('//') == 0 or i.find('\n') == 0) and headerSkip:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
headerSkip = False
|
||||||
|
newLines.append(i)
|
||||||
|
|
||||||
|
# Add the new license
|
||||||
|
newLines = licenseLines + newLines
|
||||||
|
|
||||||
|
# Modify the source file
|
||||||
|
print("Opening " + fName + " for write..")
|
||||||
|
f = open(fName, 'w')
|
||||||
|
f.writelines(newLines)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
print("Done.")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main(sys.argv)
|
||||||
|
|
30
scripts/qt5StaticConfigure.sh
Executable file
30
scripts/qt5StaticConfigure.sh
Executable file
@ -0,0 +1,30 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
#
|
||||||
|
# This for configuring static build of Qt5 itself, not the game.
|
||||||
|
#
|
||||||
|
|
||||||
|
PREFIX='/home/juzzlin/qt5'
|
||||||
|
./configure \
|
||||||
|
-opensource \
|
||||||
|
-confirm-license \
|
||||||
|
-force-pkg-config \
|
||||||
|
-fontconfig \
|
||||||
|
-release \
|
||||||
|
-static \
|
||||||
|
-prefix $PREFIX \
|
||||||
|
-no-icu \
|
||||||
|
-opengl desktop \
|
||||||
|
-no-glib \
|
||||||
|
-accessibility \
|
||||||
|
-nomake examples \
|
||||||
|
-nomake tests \
|
||||||
|
-qt-zlib \
|
||||||
|
-qt-libpng \
|
||||||
|
-qt-libjpeg \
|
||||||
|
-qt-sql-sqlite \
|
||||||
|
-qt-xcb \
|
||||||
|
-qt-pcre \
|
||||||
|
-pulseaudio \
|
||||||
|
-v
|
||||||
|
|
14
scripts/updatePPA.sh
Executable file
14
scripts/updatePPA.sh
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
VERSION=${DUSTRAC_RELEASE_VERSION?"is not set."}
|
||||||
|
|
||||||
|
# $VERSION-1 for xenial
|
||||||
|
# $VERSION-2 for artful
|
||||||
|
|
||||||
|
DEBIAN_VERSION=$VERSION-1
|
||||||
|
rm -rf *${VERSION}*
|
||||||
|
cp ../DustRacing2D/dementia-$VERSION.tar.gz .
|
||||||
|
tar xzvf dementia-$VERSION.tar.gz
|
||||||
|
mv dementia-$VERSION dementia-$DEBIAN_VERSION
|
||||||
|
cd dementia-$DEBIAN_VERSION
|
||||||
|
cp -rv packaging/debian .
|
||||||
|
debuild -S -sa && cd .. && dput ppa:jussi-lind/dementia "dementia_${DEBIAN_VERSION}_source.changes"
|
||||||
|
|
15
scripts/updateTranslationFiles.sh
Executable file
15
scripts/updateTranslationFiles.sh
Executable file
@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
LUPDATE=lupdate
|
||||||
|
if ! which ${LUPDATE}; then
|
||||||
|
echo "${LUPDATE} not found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
for LANG in cs de fi fr it; do
|
||||||
|
${LUPDATE} src/game/*.cpp src/game/menu/*.cpp -ts src/game/translations/dementia-game_${LANG}.ts
|
||||||
|
${LUPDATE} src/editor/*.cpp -ts src/editor/translations/dementia-editor_${LANG}.ts
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Done."
|
||||||
|
|
2
src/UnitTests/CMakeLists.txt
Normal file
2
src/UnitTests/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
add_subdirectory(GraphTest)
|
||||||
|
|
13
src/UnitTests/GraphTest/CMakeLists.txt
Normal file
13
src/UnitTests/GraphTest/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
set(EDITOR_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../editor)
|
||||||
|
include_directories(${EDITOR_DIR})
|
||||||
|
|
||||||
|
set(NAME GraphTest)
|
||||||
|
set(SRC ${NAME}.cpp ${EDITOR_DIR}/graph.cpp ${EDITOR_DIR}/nodebase.cpp)
|
||||||
|
|
||||||
|
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/unittests)
|
||||||
|
add_executable(${NAME} ${SRC} ${MOC_SRC})
|
||||||
|
add_test(${NAME} ${CMAKE_SOURCE_DIR}/unittests/${NAME})
|
||||||
|
|
||||||
|
qt5_use_modules(${NAME} Test)
|
||||||
|
|
||||||
|
set_property(TARGET ${NAME} PROPERTY CXX_STANDARD 11)
|
78
src/UnitTests/GraphTest/GraphTest.cpp
Normal file
78
src/UnitTests/GraphTest/GraphTest.cpp
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "GraphTest.hpp"
|
||||||
|
|
||||||
|
#include "../editor/graph.hpp"
|
||||||
|
#include "../editor/nodebase.hpp"
|
||||||
|
|
||||||
|
GraphTest::GraphTest()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphTest::testAddNode()
|
||||||
|
{
|
||||||
|
Graph dut;
|
||||||
|
NodeBasePtr node(new NodeBase);
|
||||||
|
|
||||||
|
QVERIFY(node->index() == -1);
|
||||||
|
|
||||||
|
dut.addNode(node);
|
||||||
|
|
||||||
|
QVERIFY(dut.numNodes() == 1);
|
||||||
|
QVERIFY(node->index() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphTest::testAddTwoNodes()
|
||||||
|
{
|
||||||
|
Graph dut;
|
||||||
|
NodeBasePtr node0(new NodeBase);
|
||||||
|
NodeBasePtr node1(new NodeBase);
|
||||||
|
|
||||||
|
dut.addNode(node0);
|
||||||
|
|
||||||
|
QVERIFY(dut.numNodes() == 1);
|
||||||
|
|
||||||
|
dut.addNode(node1);
|
||||||
|
|
||||||
|
QVERIFY(dut.numNodes() == 2);
|
||||||
|
|
||||||
|
QVERIFY(node0->index() == 0);
|
||||||
|
QVERIFY(node1->index() == 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphTest::testGetNodeByIndex()
|
||||||
|
{
|
||||||
|
Graph dut;
|
||||||
|
NodeBasePtr node(new NodeBase);
|
||||||
|
|
||||||
|
dut.addNode(node);
|
||||||
|
|
||||||
|
auto nodeByIndex = dut.get(0);
|
||||||
|
QVERIFY(node == nodeByIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphTest::testGetNodeByIndex_NotFound()
|
||||||
|
{
|
||||||
|
Graph dut;
|
||||||
|
NodeBasePtr node(new NodeBase);
|
||||||
|
|
||||||
|
dut.addNode(node);
|
||||||
|
|
||||||
|
auto nodeByIndex = dut.get(1);
|
||||||
|
QVERIFY(nodeByIndex == nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
QTEST_GUILESS_MAIN(GraphTest)
|
35
src/UnitTests/GraphTest/GraphTest.hpp
Normal file
35
src/UnitTests/GraphTest/GraphTest.hpp
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <QTest>
|
||||||
|
|
||||||
|
class GraphTest : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
GraphTest();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void testAddNode();
|
||||||
|
|
||||||
|
void testAddTwoNodes();
|
||||||
|
|
||||||
|
void testGetNodeByIndex();
|
||||||
|
|
||||||
|
void testGetNodeByIndex_NotFound();
|
||||||
|
};
|
17
src/dementia.appdata.xml
Normal file
17
src/dementia.appdata.xml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<component type="desktop">
|
||||||
|
<id>dementia.desktop</id>
|
||||||
|
<metadata_license>CC0-1.0</metadata_license>
|
||||||
|
<project_license>GPL-3.0 and CC BY-SA-3.0</project_license>
|
||||||
|
<name>Dementia</name>
|
||||||
|
<summary>An application for mind map creation and management.</summary>
|
||||||
|
<description>
|
||||||
|
<p>
|
||||||
|
Dementia is an application for mind map creation and management written in Qt (C++).
|
||||||
|
</p>
|
||||||
|
</description>
|
||||||
|
<screenshots>
|
||||||
|
</screenshots>
|
||||||
|
<url type="homepage">https://juzzlin.github.io/Dementia/</url>
|
||||||
|
<update_contact>jussi.lind@iki.fi</update_contact>
|
||||||
|
</component>
|
10
src/dementia.desktop.in
Normal file
10
src/dementia.desktop.in
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
Name=Dementia
|
||||||
|
GenericName=Mind map application
|
||||||
|
Comment=Mind map application
|
||||||
|
Exec=dementia
|
||||||
|
Icon=dementia
|
||||||
|
Type=Application
|
||||||
|
Categories=Education;
|
||||||
|
StartupNotify=true
|
||||||
|
|
81
src/editor/CMakeLists.txt
Normal file
81
src/editor/CMakeLists.txt
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
# Translation files in src/editor/translations (without .ts)
|
||||||
|
#set(TS dementia_fi)
|
||||||
|
set(TS_FILES)
|
||||||
|
set(QM_FILES)
|
||||||
|
foreach(TS_FILE ${TS})
|
||||||
|
list(APPEND TS_FILES ${CMAKE_SOURCE_DIR}/src/editor/translations/${TS_FILE}.ts)
|
||||||
|
list(APPEND QM_FILES ${CMAKE_BINARY_DIR}/src/editor/${TS_FILE}.qm)
|
||||||
|
endforeach()
|
||||||
|
# Set sources
|
||||||
|
set(SRC
|
||||||
|
aboutdlg.cpp
|
||||||
|
application.cpp
|
||||||
|
config.cpp
|
||||||
|
draganddropstore.cpp
|
||||||
|
edge.cpp
|
||||||
|
graph.cpp
|
||||||
|
editordata.cpp
|
||||||
|
editorview.cpp
|
||||||
|
main.cpp
|
||||||
|
mainwindow.cpp
|
||||||
|
mediator.cpp
|
||||||
|
mindmapdata.cpp
|
||||||
|
mindmapdatabase.cpp
|
||||||
|
node.cpp
|
||||||
|
nodebase.cpp
|
||||||
|
nodehandle.cpp
|
||||||
|
undostack.cpp
|
||||||
|
contrib/mclogger.cc
|
||||||
|
)
|
||||||
|
|
||||||
|
set(RCS ${CMAKE_SOURCE_DIR}/data/images/images.qrc ${CMAKE_SOURCE_DIR}/data/icons/icons.qrc)
|
||||||
|
|
||||||
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/contrib)
|
||||||
|
|
||||||
|
qt5_add_resources(RC_SRC ${RCS})
|
||||||
|
qt5_add_translation(QM ${TS_FILES})
|
||||||
|
qt5_wrap_ui(UI_HDRS ${UIS})
|
||||||
|
|
||||||
|
# We need this to be able to include headers produced by uic in our code
|
||||||
|
include_directories(${CMAKE_BINARY_DIR})
|
||||||
|
|
||||||
|
# Resource compilation for MinGW
|
||||||
|
if(MINGW)
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/windowsrc.o
|
||||||
|
COMMAND
|
||||||
|
${CMAKE_RC_COMPILER}
|
||||||
|
-I${CMAKE_SOURCE_DIR} -i${CMAKE_SOURCE_DIR}/data/icons/WindowsDementia.rc
|
||||||
|
-o ${CMAKE_CURRENT_BINARY_DIR}/windowsrc.o)
|
||||||
|
set(SRC ${SRC} ${CMAKE_CURRENT_BINARY_DIR}/windowsrc.o)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Copy desktop file
|
||||||
|
if(ReleaseBuild AND UNIX)
|
||||||
|
set(DesktopFileSourcePath)
|
||||||
|
if(USC)
|
||||||
|
set(DesktopFileSourcePath ${CMAKE_SOURCE_DIR}/src/dementia.desktop.opt.in)
|
||||||
|
else()
|
||||||
|
set(DesktopFileSourcePath ${CMAKE_SOURCE_DIR}/src/dementia.desktop.in)
|
||||||
|
endif()
|
||||||
|
add_custom_target(desktop-file ALL
|
||||||
|
COMMAND cmake -E copy ${DesktopFileSourcePath}
|
||||||
|
${CMAKE_BINARY_DIR}/dementia.desktop
|
||||||
|
DEPENDS ${BINARY_NAME})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Add the executable
|
||||||
|
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
|
||||||
|
add_executable(${BINARY_NAME} WIN32 ${SRC} ${MOC_SRC} ${RC_SRC} ${UI_HDRS} ${QM})
|
||||||
|
|
||||||
|
target_link_libraries(${BINARY_NAME} Qt5::Widgets Qt5::Xml)
|
||||||
|
set_property(TARGET ${BINARY_NAME} PROPERTY CXX_STANDARD 11)
|
||||||
|
|
||||||
|
foreach(TS_FILE ${TS})
|
||||||
|
# Make targets to copy generated qm files to data dir. This is done the hard
|
||||||
|
# way, because qt5_add_translation() generates the qm files to ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
add_custom_target(copy-translation-file-${TS_FILE} ALL
|
||||||
|
COMMAND cmake -E copy ${CMAKE_BINARY_DIR}/src/editor/${TS_FILE}.qm
|
||||||
|
${CMAKE_BINARY_DIR}/data/translations/${TS_FILE}.qm
|
||||||
|
DEPENDS ${BINARY_NAME})
|
||||||
|
endforeach()
|
1
src/editor/README
Normal file
1
src/editor/README
Normal file
@ -0,0 +1 @@
|
|||||||
|
These are common files shared between the editor and the game.
|
59
src/editor/aboutdlg.cpp
Normal file
59
src/editor/aboutdlg.cpp
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "aboutdlg.hpp"
|
||||||
|
#include "config.hpp"
|
||||||
|
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
AboutDlg::AboutDlg(QWidget * parent)
|
||||||
|
: QDialog(parent)
|
||||||
|
{
|
||||||
|
setWindowTitle(tr("About ") + Config::Editor::EDITOR_NAME);
|
||||||
|
initWidgets();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AboutDlg::initWidgets()
|
||||||
|
{
|
||||||
|
QVBoxLayout * vLayout = new QVBoxLayout(this);
|
||||||
|
QLabel * pixmapLabel = new QLabel(this);
|
||||||
|
|
||||||
|
pixmapLabel->setPixmap(QPixmap(":/about.png").scaled(512, 512));
|
||||||
|
vLayout->addWidget(pixmapLabel);
|
||||||
|
|
||||||
|
QLabel * infoLabel = new QLabel(this);
|
||||||
|
infoLabel->setText(
|
||||||
|
QString("<h2>") + Config::Editor::EDITOR_NAME + " v" + Config::Editor::EDITOR_VERSION + "</h2>"
|
||||||
|
+ "<p>" + Config::Editor::EDITOR_NAME + " is licenced under GNU GPLv3.</p>"
|
||||||
|
+ "<p>" + Config::Common::COPYRIGHT + "</p>"
|
||||||
|
+ "<a href='" + Config::Common::WEB_SITE_URL + "'>"
|
||||||
|
+ Config::Common::WEB_SITE_URL + "</a>");
|
||||||
|
|
||||||
|
vLayout->addWidget(infoLabel);
|
||||||
|
|
||||||
|
QHBoxLayout * buttonLayout = new QHBoxLayout();
|
||||||
|
QPushButton * button = new QPushButton("&Ok", this);
|
||||||
|
|
||||||
|
connect(button, SIGNAL(clicked()), this, SLOT(accept()));
|
||||||
|
|
||||||
|
buttonLayout->addWidget(button);
|
||||||
|
buttonLayout->insertStretch(0);
|
||||||
|
|
||||||
|
vLayout->addLayout(buttonLayout);
|
||||||
|
}
|
36
src/editor/aboutdlg.hpp
Normal file
36
src/editor/aboutdlg.hpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef ABOUTDLG_HPP
|
||||||
|
#define ABOUTDLG_HPP
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
|
||||||
|
//! The about dialog.
|
||||||
|
class AboutDlg : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Constructor.
|
||||||
|
explicit AboutDlg(QWidget * parent = 0);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void initWidgets();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ABOUTDLG_HPP
|
98
src/editor/application.cpp
Normal file
98
src/editor/application.cpp
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "application.hpp"
|
||||||
|
#include "mainwindow.hpp"
|
||||||
|
|
||||||
|
#include "config.hpp"
|
||||||
|
#include "userexception.hpp"
|
||||||
|
|
||||||
|
#include <QLocale>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
static void printHelp()
|
||||||
|
{
|
||||||
|
std::cout << std::endl << "Dementia version " << VERSION << std::endl;
|
||||||
|
std::cout << Config::Common::COPYRIGHT.toStdString() << std::endl << std::endl;
|
||||||
|
std::cout << "Usage: dementia [options] [mindMapFile]" << std::endl << std::endl;
|
||||||
|
std::cout << "Options:" << std::endl;
|
||||||
|
std::cout << "--help Show this help." << std::endl;
|
||||||
|
std::cout << "--lang [lang] Force language: fi." << std::endl;
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void initTranslations(QTranslator & appTranslator, QGuiApplication & app, QString lang = "")
|
||||||
|
{
|
||||||
|
if (lang == "")
|
||||||
|
{
|
||||||
|
lang = QLocale::system().name();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (appTranslator.load(QString(DATA_PATH) + "/translations/dementia_" + lang))
|
||||||
|
{
|
||||||
|
app.installTranslator(&appTranslator);
|
||||||
|
std::cout << "Loaded translations for " << lang.toStdString() << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "Failed to load translations for " << lang.toStdString() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::parseArgs(int argc, char ** argv)
|
||||||
|
{
|
||||||
|
QString lang = "";
|
||||||
|
|
||||||
|
const std::vector<QString> args(argv, argv + argc);
|
||||||
|
for (unsigned int i = 1; i < args.size(); i++)
|
||||||
|
{
|
||||||
|
if (args[i] == "-h" || args[i] == "--help")
|
||||||
|
{
|
||||||
|
printHelp();
|
||||||
|
throw UserException("Exit due to help.");
|
||||||
|
}
|
||||||
|
else if (args[i] == "--lang" && (i + i) < args.size())
|
||||||
|
{
|
||||||
|
lang = args[i + 1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_mindMapFile = args[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
initTranslations(m_appTranslator, m_app, lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
Application::Application(int & argc, char ** argv)
|
||||||
|
: m_app(argc, argv)
|
||||||
|
{
|
||||||
|
parseArgs(argc, argv);
|
||||||
|
|
||||||
|
m_mainWindow = new MainWindow(m_mindMapFile);
|
||||||
|
m_mainWindow->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
int Application::run()
|
||||||
|
{
|
||||||
|
return m_app.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
Application::~Application()
|
||||||
|
{
|
||||||
|
delete m_mainWindow;
|
||||||
|
}
|
47
src/editor/application.hpp
Normal file
47
src/editor/application.hpp
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef APPLICATION_HPP
|
||||||
|
#define APPLICATION_HPP
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QTranslator>
|
||||||
|
|
||||||
|
class MainWindow;
|
||||||
|
|
||||||
|
class Application
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Application(int & argc, char ** argv);
|
||||||
|
|
||||||
|
~Application();
|
||||||
|
|
||||||
|
int run();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void parseArgs(int argc, char ** argv);
|
||||||
|
|
||||||
|
QApplication m_app;
|
||||||
|
|
||||||
|
QTranslator m_appTranslator;
|
||||||
|
|
||||||
|
QString m_mindMapFile;
|
||||||
|
|
||||||
|
MainWindow * m_mainWindow;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // APPLICATION_HPP
|
33
src/editor/config.cpp
Normal file
33
src/editor/config.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "config.hpp"
|
||||||
|
|
||||||
|
namespace Config {
|
||||||
|
|
||||||
|
const QString Common::dataPath = DATA_PATH;
|
||||||
|
|
||||||
|
const QString Common::COPYRIGHT = "Copyright (c) 2018 Jussi Lind";
|
||||||
|
const QString Common::QSETTINGS_COMPANY_NAME = "dementia";
|
||||||
|
const QString Common::WEB_SITE_URL = "http://juzzlin.github.io/Dementia";
|
||||||
|
|
||||||
|
const QString Editor::SELECT_ICON_PATH = ":/cursor.png";
|
||||||
|
const QString Editor::ERASE_ICON_PATH = ":/cross.png";
|
||||||
|
const QString Editor::CLEAR_ICON_PATH = ":/clear.png";
|
||||||
|
const QString Editor::EDITOR_NAME = "Dementia";
|
||||||
|
const QString Editor::EDITOR_VERSION = VERSION;
|
||||||
|
const QString Editor::QSETTINGS_SOFTWARE_NAME = "Dementia";
|
||||||
|
|
||||||
|
} // Config
|
53
src/editor/config.hpp
Normal file
53
src/editor/config.hpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
//! Config variables for editor and for the game.
|
||||||
|
namespace Config
|
||||||
|
{
|
||||||
|
class Common
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! The base data path given by -DDATA_PATH.
|
||||||
|
static const QString dataPath;
|
||||||
|
|
||||||
|
static const QString COPYRIGHT;
|
||||||
|
|
||||||
|
//! "Company" name used in QSettings.
|
||||||
|
static const QString QSETTINGS_COMPANY_NAME;
|
||||||
|
|
||||||
|
static const QString WEB_SITE_URL;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Editor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static const QString EDITOR_NAME;
|
||||||
|
|
||||||
|
static const QString EDITOR_VERSION;
|
||||||
|
|
||||||
|
static const QString QSETTINGS_SOFTWARE_NAME;
|
||||||
|
|
||||||
|
static const QString SELECT_ICON_PATH;
|
||||||
|
|
||||||
|
static const QString ERASE_ICON_PATH;
|
||||||
|
|
||||||
|
static const QString CLEAR_ICON_PATH;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // Config
|
||||||
|
|
||||||
|
|
136
src/editor/contrib/mclogger.cc
Normal file
136
src/editor/contrib/mclogger.cc
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
// This file belongs to the "MiniCore" game engine.
|
||||||
|
// Copyright (C) 2012 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License
|
||||||
|
// as published by the Free Software Foundation; either version 2
|
||||||
|
// of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
// MA 02110-1301, USA.
|
||||||
|
//
|
||||||
|
|
||||||
|
#define _CRT_SECURE_NO_WARNINGS
|
||||||
|
|
||||||
|
#include "mclogger.hh"
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
#ifdef Q_OS_ANDROID
|
||||||
|
#include <QDebug>
|
||||||
|
#else
|
||||||
|
#include <cstdio>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool MCLogger::m_echoMode = false;
|
||||||
|
bool MCLogger::m_dateTime = true;
|
||||||
|
FILE * MCLogger::m_file = nullptr;
|
||||||
|
|
||||||
|
MCLogger::MCLogger()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MCLogger::init(const char * fileName, bool append)
|
||||||
|
{
|
||||||
|
MCLogger::m_file = nullptr;
|
||||||
|
if (fileName)
|
||||||
|
{
|
||||||
|
if (append)
|
||||||
|
{
|
||||||
|
MCLogger::m_file = fopen(fileName, "a+");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MCLogger::m_file = fopen(fileName, "w+");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_file)
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_ANDROID
|
||||||
|
qDebug() << "ERROR!!: Couldn't open '" << fileName << "' for write.";
|
||||||
|
#else
|
||||||
|
fprintf(stderr, "ERROR!!: Couldn't open '%s' for write.\n", fileName);
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCLogger::enableEchoMode(bool enable)
|
||||||
|
{
|
||||||
|
MCLogger::m_echoMode = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCLogger::enableDateTimePrefix(bool enable)
|
||||||
|
{
|
||||||
|
MCLogger::m_dateTime = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MCLogger::prefixDateTime()
|
||||||
|
{
|
||||||
|
if (MCLogger::m_dateTime)
|
||||||
|
{
|
||||||
|
time_t rawTime;
|
||||||
|
time(&rawTime);
|
||||||
|
std::string timeStr(ctime(&rawTime));
|
||||||
|
timeStr.erase(timeStr.length() - 1);
|
||||||
|
m_oss << "[" << timeStr << "] ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostringstream & MCLogger::info()
|
||||||
|
{
|
||||||
|
MCLogger::prefixDateTime();
|
||||||
|
m_oss << "I: ";
|
||||||
|
return m_oss;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostringstream & MCLogger::warning()
|
||||||
|
{
|
||||||
|
MCLogger::prefixDateTime();
|
||||||
|
m_oss << "W: ";
|
||||||
|
return m_oss;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostringstream & MCLogger::error()
|
||||||
|
{
|
||||||
|
MCLogger::prefixDateTime();
|
||||||
|
m_oss << "E: ";
|
||||||
|
return m_oss;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostringstream & MCLogger::fatal()
|
||||||
|
{
|
||||||
|
MCLogger::prefixDateTime();
|
||||||
|
m_oss << "F: ";
|
||||||
|
return m_oss;
|
||||||
|
}
|
||||||
|
|
||||||
|
MCLogger::~MCLogger()
|
||||||
|
{
|
||||||
|
if (MCLogger::m_file)
|
||||||
|
{
|
||||||
|
fprintf(MCLogger::m_file, "%s", m_oss.str().c_str());
|
||||||
|
fprintf(MCLogger::m_file, "\n");
|
||||||
|
fflush(MCLogger::m_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MCLogger::m_echoMode)
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_ANDROID
|
||||||
|
qDebug() << m_oss.str().c_str();
|
||||||
|
#else
|
||||||
|
fprintf(stdout, "%s", m_oss.str().c_str());
|
||||||
|
fprintf(stdout, "\n");
|
||||||
|
fflush(stdout);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
90
src/editor/contrib/mclogger.hh
Normal file
90
src/editor/contrib/mclogger.hh
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
// This file belongs to the "MiniCore" game engine.
|
||||||
|
// Copyright (C) 2012 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or
|
||||||
|
// modify it under the terms of the GNU General Public License
|
||||||
|
// as published by the Free Software Foundation; either version 2
|
||||||
|
// of the License, or (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with this program; if not, write to the Free Software
|
||||||
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
// MA 02110-1301, USA.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef MCLOGGER_HH
|
||||||
|
#define MCLOGGER_HH
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
/*! A logging class. A MCLogger instance flushes on destruction.
|
||||||
|
*
|
||||||
|
* Example initialization:
|
||||||
|
*
|
||||||
|
* MCLogger::init("myLog.txt");
|
||||||
|
* MCLogger::enableEchoMode(true);
|
||||||
|
*
|
||||||
|
* Example logging:
|
||||||
|
*
|
||||||
|
* MCLogger().info() << "Initialization finished.";
|
||||||
|
* MCLogger().error() << "Foo happened!";
|
||||||
|
*/
|
||||||
|
class MCLogger
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Constructor.
|
||||||
|
MCLogger();
|
||||||
|
|
||||||
|
//! Destructor.
|
||||||
|
~MCLogger();
|
||||||
|
|
||||||
|
/*! Initialize the logger.
|
||||||
|
* \param fileName Log to fileName. Can be nullptr.
|
||||||
|
* \param append The existing log will be appended if true.
|
||||||
|
* \return false if file couldn't be opened. */
|
||||||
|
static bool init(const char * fileName, bool append = false);
|
||||||
|
|
||||||
|
//! Enable/disable echo mode.
|
||||||
|
//! \param enable Echo everything if true. Default is false.
|
||||||
|
static void enableEchoMode(bool enable);
|
||||||
|
|
||||||
|
//! Enable/disable date and time prefix.
|
||||||
|
//! \param enable Prefix with date and time if true. Default is true.
|
||||||
|
static void enableDateTimePrefix(bool enable);
|
||||||
|
|
||||||
|
//! Get stream to the info log message.
|
||||||
|
std::ostringstream & info();
|
||||||
|
|
||||||
|
//! Get stream to the warning log message.
|
||||||
|
std::ostringstream & warning();
|
||||||
|
|
||||||
|
//! Get stream to the error log message.
|
||||||
|
std::ostringstream & error();
|
||||||
|
|
||||||
|
//! Get stream to the fatal log message.
|
||||||
|
std::ostringstream & fatal();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
MCLogger(const MCLogger & r) = delete;
|
||||||
|
MCLogger & operator=(const MCLogger & r) = delete;
|
||||||
|
|
||||||
|
void prefixDateTime();
|
||||||
|
|
||||||
|
static bool m_echoMode;
|
||||||
|
|
||||||
|
static bool m_dateTime;
|
||||||
|
|
||||||
|
static FILE * m_file;
|
||||||
|
|
||||||
|
std::ostringstream m_oss;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MCLOGGER_HH
|
58
src/editor/draganddropstore.cpp
Normal file
58
src/editor/draganddropstore.cpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dust Racing 2D is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dust Racing 2D is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "draganddropstore.hpp"
|
||||||
|
|
||||||
|
#include "node.hpp"
|
||||||
|
|
||||||
|
DragAndDropStore::DragAndDropStore()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void DragAndDropStore::clear()
|
||||||
|
{
|
||||||
|
m_dragAndDropNode = nullptr;
|
||||||
|
m_dragAndDropNodeHandle = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DragAndDropStore::setDragAndDropNode(Node * tnode)
|
||||||
|
{
|
||||||
|
m_dragAndDropNode = tnode;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node * DragAndDropStore::dragAndDropNode() const
|
||||||
|
{
|
||||||
|
return m_dragAndDropNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DragAndDropStore::setDragAndDropSourcePos(QPointF pos)
|
||||||
|
{
|
||||||
|
m_dragAndDropSourcePos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeHandle *DragAndDropStore::dragAndDropNodeHandle() const
|
||||||
|
{
|
||||||
|
return m_dragAndDropNodeHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DragAndDropStore::setDragAndDropNodeHandle(NodeHandle * dragAndDropNodeHandle)
|
||||||
|
{
|
||||||
|
m_dragAndDropNodeHandle = dragAndDropNodeHandle;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointF DragAndDropStore::dragAndDropSourcePos() const
|
||||||
|
{
|
||||||
|
return m_dragAndDropSourcePos;
|
||||||
|
}
|
51
src/editor/draganddropstore.hpp
Normal file
51
src/editor/draganddropstore.hpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dust Racing 2D is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dust Racing 2D is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef DRAGANDDROPSTORE_HPP
|
||||||
|
#define DRAGANDDROPSTORE_HPP
|
||||||
|
|
||||||
|
#include <QPointF>
|
||||||
|
|
||||||
|
class Node;
|
||||||
|
class NodeHandle;
|
||||||
|
|
||||||
|
class DragAndDropStore
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
DragAndDropStore();
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
void setDragAndDropNode(Node * tnode);
|
||||||
|
|
||||||
|
Node * dragAndDropNode() const;
|
||||||
|
QPointF dragAndDropSourcePos() const;
|
||||||
|
|
||||||
|
void setDragAndDropSourcePos(QPointF pos);
|
||||||
|
|
||||||
|
NodeHandle *dragAndDropNodeHandle() const;
|
||||||
|
void setDragAndDropNodeHandle(NodeHandle * dragAndDropNodeHandle);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
Node * m_dragAndDropNode = nullptr;
|
||||||
|
|
||||||
|
NodeHandle * m_dragAndDropNodeHandle = nullptr;
|
||||||
|
|
||||||
|
QPointF m_dragAndDropSourcePos;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DRAGANDDROPSTORE_HPP
|
34
src/editor/edge.cpp
Normal file
34
src/editor/edge.cpp
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "edge.hpp"
|
||||||
|
#include "node.hpp"
|
||||||
|
|
||||||
|
#include <QGraphicsDropShadowEffect>
|
||||||
|
|
||||||
|
Edge::Edge(Node & sourceNode, Node & targetNode)
|
||||||
|
: m_sourceNode(sourceNode)
|
||||||
|
, m_targetNode(targetNode)
|
||||||
|
{
|
||||||
|
QGraphicsDropShadowEffect * shadow = new QGraphicsDropShadowEffect();
|
||||||
|
shadow->setOffset(QPointF(3, 3));
|
||||||
|
shadow->setBlurRadius(5);
|
||||||
|
setGraphicsEffect(shadow);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Edge::updateLine()
|
||||||
|
{
|
||||||
|
setLine(m_sourceNode.pos().x(), m_sourceNode.pos().y(), m_targetNode.pos().x(), m_targetNode.pos().y());
|
||||||
|
}
|
42
src/editor/edge.hpp
Normal file
42
src/editor/edge.hpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef EDGE_HPP
|
||||||
|
#define EDGE_HPP
|
||||||
|
|
||||||
|
#include <QGraphicsLineItem>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
class Node;
|
||||||
|
|
||||||
|
//! A graphic representation of a graph edge between nodes.
|
||||||
|
class Edge : public QGraphicsLineItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Edge(Node & sourceNode, Node & targetNode);
|
||||||
|
|
||||||
|
void updateLine();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
Node & m_sourceNode;
|
||||||
|
|
||||||
|
Node & m_targetNode;
|
||||||
|
};
|
||||||
|
|
||||||
|
using EdgePtr = std::shared_ptr<Edge>;
|
||||||
|
|
||||||
|
#endif // EDGE_HPP
|
67
src/editor/editor.pro
Normal file
67
src/editor/editor.pro
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# Qt project file to cross-compile the editor for Windows with MXE
|
||||||
|
|
||||||
|
TEMPLATE = app
|
||||||
|
TARGET = dementia-editor
|
||||||
|
|
||||||
|
DEFINES += DATA_PATH=\\\"./data\\\" VERSION=\\\"0.0.0\\\"
|
||||||
|
QMAKE_CXXFLAGS += -std=gnu++11
|
||||||
|
|
||||||
|
# Qt version check
|
||||||
|
contains(QT_VERSION, ^5\\..*) {
|
||||||
|
message("Building for Qt version $${QT_VERSION}.")
|
||||||
|
QT += widgets xml
|
||||||
|
} else {
|
||||||
|
error("Qt5 is required!")
|
||||||
|
}
|
||||||
|
|
||||||
|
INCLUDEPATH += . contrib
|
||||||
|
|
||||||
|
# Input
|
||||||
|
HEADERS += \
|
||||||
|
aboutdlg.hpp \
|
||||||
|
application.hpp \
|
||||||
|
config.hpp \
|
||||||
|
draganddropstore.hpp \
|
||||||
|
graph.hpp \
|
||||||
|
edge.hpp \
|
||||||
|
editordata.hpp \
|
||||||
|
editorview.hpp \
|
||||||
|
mainwindow.hpp \
|
||||||
|
mediator.hpp \
|
||||||
|
mindmapdata.hpp \
|
||||||
|
mindmapdatabase.hpp \
|
||||||
|
node.hpp \
|
||||||
|
nodebase.hpp \
|
||||||
|
nodehandle.hpp \
|
||||||
|
undostack.hpp \
|
||||||
|
contrib/mclogger.hh \
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
aboutdlg.cpp \
|
||||||
|
application.cpp \
|
||||||
|
config.cpp \
|
||||||
|
draganddropstore.cpp \
|
||||||
|
graph.cpp \
|
||||||
|
edge.cpp \
|
||||||
|
editordata.cpp \
|
||||||
|
editorview.cpp \
|
||||||
|
main.cpp \
|
||||||
|
mainwindow.cpp \
|
||||||
|
mediator.cpp \
|
||||||
|
mindmapdata.cpp \
|
||||||
|
mindmapdatabase.cpp \
|
||||||
|
node.cpp \
|
||||||
|
nodebase.cpp \
|
||||||
|
nodehandle.cpp \
|
||||||
|
undostack.cpp \
|
||||||
|
contrib/mclogger.cc \
|
||||||
|
|
||||||
|
|
||||||
|
RESOURCES += ../../data/icons/icons.qrc ../../data/images/images.qrc
|
||||||
|
RC_FILE = ../../data/icons/WindowsDementia.rc
|
||||||
|
//TRANSLATIONS += \
|
||||||
|
// translations/dementia_fi.ts
|
||||||
|
|
||||||
|
target.path = $$OUT_PWD/../..
|
||||||
|
INSTALLS += target
|
||||||
|
|
206
src/editor/editordata.cpp
Normal file
206
src/editor/editordata.cpp
Normal file
@ -0,0 +1,206 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "editordata.hpp"
|
||||||
|
#include "mediator.hpp"
|
||||||
|
#include "node.hpp"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
using std::dynamic_pointer_cast;
|
||||||
|
|
||||||
|
EditorData::EditorData(Mediator & mediator)
|
||||||
|
: m_mediator(mediator)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void EditorData::clearScene()
|
||||||
|
{
|
||||||
|
removeNodesFromScene();
|
||||||
|
}
|
||||||
|
|
||||||
|
DragAndDropStore & EditorData::dadStore()
|
||||||
|
{
|
||||||
|
return m_dadStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EditorData::loadMindMapData(QString fileName)
|
||||||
|
{
|
||||||
|
m_undoStack.clear();
|
||||||
|
|
||||||
|
clearScene();
|
||||||
|
|
||||||
|
//m_mindMapData = m_mindMapIO.open(fileName);
|
||||||
|
//return static_cast<bool>(m_mindMapData);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EditorData::isUndoable() const
|
||||||
|
{
|
||||||
|
return m_undoStack.isUndoable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorData::undo()
|
||||||
|
{
|
||||||
|
if (m_undoStack.isUndoable())
|
||||||
|
{
|
||||||
|
m_selectedNode = nullptr;
|
||||||
|
|
||||||
|
m_dragAndDropNode = nullptr;
|
||||||
|
|
||||||
|
saveRedoPoint();
|
||||||
|
|
||||||
|
clearScene();
|
||||||
|
|
||||||
|
m_mindMapData = m_undoStack.undo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EditorData::isRedoable() const
|
||||||
|
{
|
||||||
|
return m_undoStack.isRedoable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorData::redo()
|
||||||
|
{
|
||||||
|
if (m_undoStack.isRedoable())
|
||||||
|
{
|
||||||
|
m_selectedNode = nullptr;
|
||||||
|
|
||||||
|
m_dragAndDropNode = nullptr;
|
||||||
|
|
||||||
|
saveUndoPoint();
|
||||||
|
|
||||||
|
clearScene();
|
||||||
|
|
||||||
|
m_mindMapData = m_undoStack.redo();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EditorData::saveMindMapData()
|
||||||
|
{
|
||||||
|
assert(m_mindMapData);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorData::saveUndoPoint()
|
||||||
|
{
|
||||||
|
assert(m_mindMapData);
|
||||||
|
m_undoStack.pushUndoPoint(m_mindMapData);
|
||||||
|
|
||||||
|
m_mediator.enableUndo(m_undoStack.isUndoable());
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorData::saveRedoPoint()
|
||||||
|
{
|
||||||
|
assert(m_mindMapData);
|
||||||
|
m_undoStack.pushRedoPoint(m_mindMapData);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EditorData::saveMindMapDataAs(QString fileName)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorData::setMindMapData(MindMapDataPtr mindMapData)
|
||||||
|
{
|
||||||
|
clearScene();
|
||||||
|
|
||||||
|
m_mindMapData = mindMapData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorData::addExistingGraphToScene()
|
||||||
|
{
|
||||||
|
std::vector<NodeBasePtr> temp;
|
||||||
|
m_mindMapData->graph().getAll(temp);
|
||||||
|
for (auto node : temp)
|
||||||
|
{
|
||||||
|
addNodeToScene(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeBasePtr EditorData::createAndAddNodeToGraph(QPointF pos)
|
||||||
|
{
|
||||||
|
NodeBasePtr node(new Node);
|
||||||
|
node->setLocation(pos);
|
||||||
|
m_mindMapData->graph().addNode(node);
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeBasePtr EditorData::getNodeByIndex(int index)
|
||||||
|
{
|
||||||
|
return m_mindMapData->graph().get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorData::addNodeToScene(NodeBasePtr node)
|
||||||
|
{
|
||||||
|
auto ptr = std::dynamic_pointer_cast<Node>(node);
|
||||||
|
if (!ptr->scene())
|
||||||
|
{
|
||||||
|
m_mediator.addItem(*ptr); // The scene wants a raw pointer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorData::removeGraphFromScene()
|
||||||
|
{
|
||||||
|
for (auto && nodeIter : m_mindMapData->graph())
|
||||||
|
{
|
||||||
|
auto node = dynamic_pointer_cast<Node>(nodeIter.second);
|
||||||
|
assert(node);
|
||||||
|
|
||||||
|
m_mediator.removeItem(*node); // The scene wants a raw pointer
|
||||||
|
}
|
||||||
|
|
||||||
|
m_mediator.updateView();
|
||||||
|
}
|
||||||
|
|
||||||
|
MindMapDataPtr EditorData::mindMapData()
|
||||||
|
{
|
||||||
|
return m_mindMapData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorData::setSelectedNode(Node * node)
|
||||||
|
{
|
||||||
|
m_selectedNode = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
Node * EditorData::selectedNode() const
|
||||||
|
{
|
||||||
|
return m_selectedNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorData::removeNodesFromScene()
|
||||||
|
{
|
||||||
|
if (m_mindMapData)
|
||||||
|
{
|
||||||
|
for (auto nodeIter : m_mindMapData->graph())
|
||||||
|
{
|
||||||
|
auto node = dynamic_pointer_cast<Node>(nodeIter.second);
|
||||||
|
assert(node);
|
||||||
|
|
||||||
|
m_mediator.removeItem(*node); // The scene wants a raw pointer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorData::clearGraph()
|
||||||
|
{
|
||||||
|
assert(m_mindMapData);
|
||||||
|
|
||||||
|
removeGraphFromScene();
|
||||||
|
m_mindMapData->graph().clear();
|
||||||
|
}
|
111
src/editor/editordata.hpp
Normal file
111
src/editor/editordata.hpp
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef EDITORDATA_HPP
|
||||||
|
#define EDITORDATA_HPP
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QPointF>
|
||||||
|
|
||||||
|
#include "draganddropstore.hpp"
|
||||||
|
#include "undostack.hpp"
|
||||||
|
#include "mindmapdata.hpp"
|
||||||
|
|
||||||
|
class Mediator;
|
||||||
|
class Node;
|
||||||
|
class NodeBase;
|
||||||
|
class MindMapTile;
|
||||||
|
class QGraphicsLineItem;
|
||||||
|
|
||||||
|
class EditorData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
EditorData(Mediator & mediator);
|
||||||
|
|
||||||
|
void addExistingGraphToScene();
|
||||||
|
|
||||||
|
void clearGraph();
|
||||||
|
|
||||||
|
NodeBasePtr createAndAddNodeToGraph(QPointF pos);
|
||||||
|
|
||||||
|
DragAndDropStore & dadStore();
|
||||||
|
|
||||||
|
NodeBasePtr getNodeByIndex(int index);
|
||||||
|
|
||||||
|
bool isUndoable() const;
|
||||||
|
|
||||||
|
bool isRedoable() const;
|
||||||
|
|
||||||
|
bool loadMindMapData(QString fileName);
|
||||||
|
|
||||||
|
MindMapDataPtr mindMapData();
|
||||||
|
|
||||||
|
void redo();
|
||||||
|
|
||||||
|
void removeGraphFromScene();
|
||||||
|
|
||||||
|
bool saveMindMapData();
|
||||||
|
|
||||||
|
bool saveMindMapDataAs(QString fileName);
|
||||||
|
|
||||||
|
void saveUndoPoint();
|
||||||
|
|
||||||
|
void saveRedoPoint();
|
||||||
|
|
||||||
|
void setMindMapData(MindMapDataPtr newMindMapData);
|
||||||
|
|
||||||
|
void setSelectedNode(Node * node);
|
||||||
|
|
||||||
|
Node * selectedNode() const;
|
||||||
|
|
||||||
|
void undo();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
EditorData(const EditorData & e) = delete;
|
||||||
|
EditorData & operator= (const EditorData & e) = delete;
|
||||||
|
|
||||||
|
void addNodeToScene(NodeBasePtr node);
|
||||||
|
|
||||||
|
void clearScene();
|
||||||
|
|
||||||
|
void removeNodesFromScene();
|
||||||
|
|
||||||
|
DragAndDropStore m_dadStore;
|
||||||
|
|
||||||
|
MindMapDataPtr m_mindMapData;
|
||||||
|
|
||||||
|
UndoStack m_undoStack;
|
||||||
|
|
||||||
|
Node * m_selectedNode = nullptr;
|
||||||
|
|
||||||
|
Node * m_dragAndDropNode = nullptr;
|
||||||
|
|
||||||
|
QPointF m_dragAndDropSourcePos;
|
||||||
|
|
||||||
|
Mediator & m_mediator;
|
||||||
|
|
||||||
|
std::vector<QGraphicsLineItem *> m_targetNodes;
|
||||||
|
|
||||||
|
unsigned int m_activeColumn = 0;
|
||||||
|
|
||||||
|
unsigned int m_activeRow = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // EDITORDATA_HPP
|
273
src/editor/editorview.cpp
Normal file
273
src/editor/editorview.cpp
Normal file
@ -0,0 +1,273 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QGraphicsItem>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <QStatusBar>
|
||||||
|
#include <QString>
|
||||||
|
#include <QTransform>
|
||||||
|
#include <iostream>
|
||||||
|
#include "editorview.hpp"
|
||||||
|
|
||||||
|
#include "draganddropstore.hpp"
|
||||||
|
#include "mediator.hpp"
|
||||||
|
#include "mindmapdata.hpp"
|
||||||
|
#include "node.hpp"
|
||||||
|
#include "nodehandle.hpp"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
EditorView::EditorView(Mediator & mediator)
|
||||||
|
: m_mediator(mediator)
|
||||||
|
{
|
||||||
|
createNodeContextMenuActions();
|
||||||
|
|
||||||
|
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorView::createNodeContextMenuActions()
|
||||||
|
{
|
||||||
|
const QString dummy1(QString(QWidget::tr("Set size..")));
|
||||||
|
auto setSize = new QAction(dummy1, &m_targetNodeContextMenu);
|
||||||
|
QObject::connect(setSize, &QAction::triggered, [this] () {
|
||||||
|
});
|
||||||
|
|
||||||
|
// Populate the menu
|
||||||
|
m_targetNodeContextMenu.addAction(setSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorView::handleMousePressEventOnNode(QMouseEvent & event, Node & node)
|
||||||
|
{
|
||||||
|
if (event.button() == Qt::RightButton)
|
||||||
|
{
|
||||||
|
handleRightButtonClickOnNode(node);
|
||||||
|
}
|
||||||
|
else if (event.button() == Qt::LeftButton)
|
||||||
|
{
|
||||||
|
handleLeftButtonClickOnNode(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget::mousePressEvent(&event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorView::handleMousePressEventOnNodeHandle(QMouseEvent & event, NodeHandle & nodeHandle)
|
||||||
|
{
|
||||||
|
if (event.button() == Qt::LeftButton)
|
||||||
|
{
|
||||||
|
handleLeftButtonClickOnNodeHandle(nodeHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget::mousePressEvent(&event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorView::handleLeftButtonClickOnNode(Node & node)
|
||||||
|
{
|
||||||
|
// User is initiating a drag'n'drop
|
||||||
|
|
||||||
|
m_mediator.saveUndoPoint();
|
||||||
|
|
||||||
|
node.setZValue(node.zValue() + 1);
|
||||||
|
m_mediator.dadStore().setDragAndDropNode(&node);
|
||||||
|
|
||||||
|
// Change cursor to the closed hand cursor.
|
||||||
|
QApplication::setOverrideCursor(QCursor(Qt::ClosedHandCursor));
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorView::handleLeftButtonClickOnNodeHandle(NodeHandle & nodeHandle)
|
||||||
|
{
|
||||||
|
// User is initiating a drag'n'drop
|
||||||
|
|
||||||
|
m_mediator.saveUndoPoint();
|
||||||
|
|
||||||
|
m_mediator.dadStore().setDragAndDropNodeHandle(&nodeHandle);
|
||||||
|
|
||||||
|
// Change cursor to the closed hand cursor.
|
||||||
|
QApplication::setOverrideCursor(QCursor(Qt::ClosedHandCursor));
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorView::handleRightButtonClickOnNode(Node & node)
|
||||||
|
{
|
||||||
|
m_mediator.setSelectedNode(&node);
|
||||||
|
|
||||||
|
openNodeContextMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorView::handleNodeDragRelease(QMouseEvent * event)
|
||||||
|
{
|
||||||
|
if (auto node = m_mediator.dadStore().dragAndDropNode())
|
||||||
|
{
|
||||||
|
node->setLocation(mapToScene(event->pos()));
|
||||||
|
node->setZValue(node->zValue() - 1);
|
||||||
|
|
||||||
|
update();
|
||||||
|
|
||||||
|
m_mediator.dadStore().clear();
|
||||||
|
|
||||||
|
QApplication::restoreOverrideCursor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorView::handleNodeHandleDragRelease(QMouseEvent *)
|
||||||
|
{
|
||||||
|
if (auto handle = m_mediator.dadStore().dragAndDropNodeHandle())
|
||||||
|
{
|
||||||
|
auto parentItem = dynamic_cast<Node *>(handle->parentItem());
|
||||||
|
assert(parentItem);
|
||||||
|
|
||||||
|
m_mediator.createAndAddNode(parentItem->index(), m_mappedPos - handle->pos());
|
||||||
|
|
||||||
|
hideDummyDragNode();
|
||||||
|
|
||||||
|
m_mediator.dadStore().clear();
|
||||||
|
|
||||||
|
QApplication::restoreOverrideCursor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorView::hideDummyDragNode()
|
||||||
|
{
|
||||||
|
if (m_dummyDragNode)
|
||||||
|
{
|
||||||
|
m_dummyDragNode->setVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorView::keyPressEvent(QKeyEvent * event)
|
||||||
|
{
|
||||||
|
if (!event->isAutoRepeat())
|
||||||
|
{
|
||||||
|
switch (event->key())
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorView::mouseMoveEvent(QMouseEvent * event)
|
||||||
|
{
|
||||||
|
m_mappedPos = mapToScene(event->pos());
|
||||||
|
if (auto node = m_mediator.dadStore().dragAndDropNode())
|
||||||
|
{
|
||||||
|
node->setLocation(m_mappedPos);
|
||||||
|
}
|
||||||
|
else if (auto handle = m_mediator.dadStore().dragAndDropNodeHandle())
|
||||||
|
{
|
||||||
|
showDummyDragNode();
|
||||||
|
|
||||||
|
m_dummyDragNode->setPos(m_mappedPos - handle->pos());
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsView::mouseMoveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorView::mousePressEvent(QMouseEvent * event)
|
||||||
|
{
|
||||||
|
m_clickedPos = event->pos();
|
||||||
|
m_clickedScenePos = mapToScene(m_clickedPos);
|
||||||
|
|
||||||
|
// Fetch all items at the location
|
||||||
|
QList<QGraphicsItem *> items = scene()->items(
|
||||||
|
m_clickedScenePos, Qt::IntersectsItemShape, Qt::DescendingOrder);
|
||||||
|
|
||||||
|
if (items.size())
|
||||||
|
{
|
||||||
|
auto item = *items.begin();
|
||||||
|
if (auto node = dynamic_cast<Node *>(item))
|
||||||
|
{
|
||||||
|
handleMousePressEventOnNode(*event, *node);
|
||||||
|
}
|
||||||
|
else if (auto node = dynamic_cast<NodeHandle *>(item))
|
||||||
|
{
|
||||||
|
handleMousePressEventOnNodeHandle(*event, *node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorView::mouseReleaseEvent(QMouseEvent * event)
|
||||||
|
{
|
||||||
|
handleNodeDragRelease(event);
|
||||||
|
|
||||||
|
handleNodeHandleDragRelease(event);
|
||||||
|
|
||||||
|
QGraphicsView::mouseReleaseEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorView::openNodeContextMenu()
|
||||||
|
{
|
||||||
|
const QPoint globalPos = mapToGlobal(m_clickedPos);
|
||||||
|
m_targetNodeContextMenu.exec(globalPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorView::showDummyDragNode()
|
||||||
|
{
|
||||||
|
if (!m_dummyDragNode)
|
||||||
|
{
|
||||||
|
m_dummyDragNode = new Node;
|
||||||
|
scene()->addItem(m_dummyDragNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_dummyDragNode->setVisible(true);
|
||||||
|
m_dummyDragNode->setOpacity(0.5f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorView::updateSceneRect()
|
||||||
|
{
|
||||||
|
const QRectF newSceneRect(-1000, -1000, 2000, 2000);
|
||||||
|
|
||||||
|
setSceneRect(newSceneRect);
|
||||||
|
|
||||||
|
assert(scene());
|
||||||
|
scene()->setSceneRect(newSceneRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorView::updateScale(int value)
|
||||||
|
{
|
||||||
|
qreal scale = static_cast<qreal>(value) / 100;
|
||||||
|
|
||||||
|
QTransform transform;
|
||||||
|
transform.scale(scale, scale);
|
||||||
|
setTransform(transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditorView::wheelEvent(QWheelEvent * event)
|
||||||
|
{
|
||||||
|
if (event->modifiers() & Qt::ControlModifier)
|
||||||
|
{
|
||||||
|
const int sensitivity = 10;
|
||||||
|
if (event->delta() > 0)
|
||||||
|
{
|
||||||
|
m_scaleValue += sensitivity;
|
||||||
|
}
|
||||||
|
else if (m_scaleValue > sensitivity)
|
||||||
|
{
|
||||||
|
m_scaleValue -= sensitivity;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateScale(m_scaleValue);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
QGraphicsView::wheelEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorView::~EditorView()
|
||||||
|
{
|
||||||
|
delete m_dummyDragNode;
|
||||||
|
}
|
112
src/editor/editorview.hpp
Normal file
112
src/editor/editorview.hpp
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef EDITORVIEW_HPP
|
||||||
|
#define EDITORVIEW_HPP
|
||||||
|
|
||||||
|
#include <QGraphicsView>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
|
class QAction;
|
||||||
|
class QMouseEvent;
|
||||||
|
class QPaintEvent;
|
||||||
|
class QWheelEvent;
|
||||||
|
class Object;
|
||||||
|
class ObjectModelLoaderoader;
|
||||||
|
class Node;
|
||||||
|
class NodeHandle;
|
||||||
|
class Mediator;
|
||||||
|
class MindMapTile;
|
||||||
|
|
||||||
|
class EditorView : public QGraphicsView
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit EditorView(Mediator & mediator);
|
||||||
|
|
||||||
|
~EditorView();
|
||||||
|
|
||||||
|
void updateSceneRect();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
void mouseMoveEvent(QMouseEvent * event) override;
|
||||||
|
|
||||||
|
void mousePressEvent(QMouseEvent * event) override;
|
||||||
|
|
||||||
|
void mouseReleaseEvent(QMouseEvent * event) override;
|
||||||
|
|
||||||
|
void keyPressEvent(QKeyEvent * event) override;
|
||||||
|
|
||||||
|
void wheelEvent(QWheelEvent * event) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void createNodeContextMenuActions();
|
||||||
|
|
||||||
|
void handleMousePressEventOnNode(QMouseEvent & event, Node & node);
|
||||||
|
|
||||||
|
void handleMousePressEventOnNodeHandle(QMouseEvent & event, NodeHandle & nodeHandle);
|
||||||
|
|
||||||
|
void handleLeftButtonClickOnNode(Node & node);
|
||||||
|
|
||||||
|
void handleLeftButtonClickOnNodeHandle(NodeHandle & nodeHandle);
|
||||||
|
|
||||||
|
void handleRightButtonClickOnNode(Node & node);
|
||||||
|
|
||||||
|
void handleNodeDragRelease(QMouseEvent * event);
|
||||||
|
|
||||||
|
void handleNodeHandleDragRelease(QMouseEvent * event);
|
||||||
|
|
||||||
|
void hideDummyDragNode();
|
||||||
|
|
||||||
|
void openNodeContextMenu();
|
||||||
|
|
||||||
|
void showDummyDragNode();
|
||||||
|
|
||||||
|
void updateScale(int value);
|
||||||
|
|
||||||
|
QMenu m_targetNodeContextMenu;
|
||||||
|
|
||||||
|
QPoint m_clickedPos;
|
||||||
|
|
||||||
|
QPointF m_clickedScenePos;
|
||||||
|
|
||||||
|
QAction * m_clearComputerHint = nullptr;
|
||||||
|
|
||||||
|
QAction * m_setComputerHintBrakeHard = nullptr;
|
||||||
|
|
||||||
|
QAction * m_setComputerHintBrake = nullptr;
|
||||||
|
|
||||||
|
QAction * m_deleteRow = nullptr;
|
||||||
|
|
||||||
|
QAction * m_deleteCol = nullptr;
|
||||||
|
|
||||||
|
QAction * m_excludeFromMinimap = nullptr;
|
||||||
|
|
||||||
|
QAction * m_forceStationaryAction = nullptr;
|
||||||
|
|
||||||
|
QPointF m_mappedPos;
|
||||||
|
|
||||||
|
int m_scaleValue = 100;
|
||||||
|
|
||||||
|
Mediator & m_mediator;
|
||||||
|
|
||||||
|
Node * m_dummyDragNode = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // EDITORVIEW_HPP
|
93
src/editor/graph.cpp
Normal file
93
src/editor/graph.cpp
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "graph.hpp"
|
||||||
|
#include "nodebase.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cassert>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
Graph::Graph()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void Graph::clear()
|
||||||
|
{
|
||||||
|
m_nodes.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Graph::addNode(NodeBasePtr node)
|
||||||
|
{
|
||||||
|
if (node && m_nodes.count(node->index()) == 0)
|
||||||
|
{
|
||||||
|
node->setIndex(m_count);
|
||||||
|
m_nodes.insert({node->index(), node});
|
||||||
|
m_count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Graph::addEdge(NodeBasePtr node0, NodeBasePtr node1)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int Graph::numNodes() const
|
||||||
|
{
|
||||||
|
return m_nodes.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeBasePtr Graph::get(int id)
|
||||||
|
{
|
||||||
|
if (m_nodes.count(id))
|
||||||
|
{
|
||||||
|
return m_nodes[id];
|
||||||
|
}
|
||||||
|
|
||||||
|
return NodeBasePtr();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Graph::getAll(NodeVector & nodeVector) const
|
||||||
|
{
|
||||||
|
nodeVector.clear();
|
||||||
|
for (auto const & iter : m_nodes)
|
||||||
|
{
|
||||||
|
nodeVector.push_back(iter.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Graph::NodeMap::iterator Graph::begin()
|
||||||
|
{
|
||||||
|
return m_nodes.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
Graph::NodeMap::iterator Graph::end()
|
||||||
|
{
|
||||||
|
return m_nodes.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
Graph::NodeMap::const_iterator Graph::cbegin() const
|
||||||
|
{
|
||||||
|
return m_nodes.cbegin();
|
||||||
|
}
|
||||||
|
|
||||||
|
Graph::NodeMap::const_iterator Graph::cend() const
|
||||||
|
{
|
||||||
|
return m_nodes.cend();
|
||||||
|
}
|
||||||
|
|
||||||
|
Graph::~Graph()
|
||||||
|
{
|
||||||
|
}
|
71
src/editor/graph.hpp
Normal file
71
src/editor/graph.hpp
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef GRAPH_HPP
|
||||||
|
#define GRAPH_HPP
|
||||||
|
|
||||||
|
#include "nodebase.hpp"
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
class NodeBase;
|
||||||
|
|
||||||
|
class Graph
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Graph();
|
||||||
|
|
||||||
|
Graph(const Graph & other) = delete;
|
||||||
|
|
||||||
|
Graph & operator= (const Graph & other) = delete;
|
||||||
|
|
||||||
|
virtual ~Graph();
|
||||||
|
|
||||||
|
using NodeVector = std::vector<NodeBasePtr>;
|
||||||
|
|
||||||
|
using NodeMap = std::map<int, NodeBasePtr>;
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
void addNode(NodeBasePtr node);
|
||||||
|
|
||||||
|
void addEdge(NodeBasePtr node0, NodeBasePtr node1);
|
||||||
|
|
||||||
|
int numNodes() const;
|
||||||
|
|
||||||
|
NodeBasePtr get(int id);
|
||||||
|
|
||||||
|
void getAll(NodeVector & nodeVector) const;
|
||||||
|
|
||||||
|
NodeMap::iterator begin();
|
||||||
|
|
||||||
|
NodeMap::iterator end();
|
||||||
|
|
||||||
|
NodeMap::const_iterator cbegin() const;
|
||||||
|
|
||||||
|
NodeMap::const_iterator cend() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
std::map<int, NodeBasePtr> m_nodes;
|
||||||
|
|
||||||
|
std::map<int, std::set<int> > m_edges;
|
||||||
|
|
||||||
|
int m_count = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // GRAPH_HPP
|
187
src/editor/images/about.svg
Normal file
187
src/editor/images/about.svg
Normal file
@ -0,0 +1,187 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="312"
|
||||||
|
height="312"
|
||||||
|
viewBox="0 0 312 312"
|
||||||
|
id="svg2"
|
||||||
|
version="1.1"
|
||||||
|
inkscape:version="0.91 r13725"
|
||||||
|
inkscape:export-filename="/home/juzzlin/Home/Desktop-16.04/Projects/Programming/dementia/DustRacing2D/data/images/about.png"
|
||||||
|
inkscape:export-xdpi="90"
|
||||||
|
inkscape:export-ydpi="90"
|
||||||
|
sodipodi:docname="about.svg">
|
||||||
|
<defs
|
||||||
|
id="defs4">
|
||||||
|
<filter
|
||||||
|
style="color-interpolation-filters:sRGB"
|
||||||
|
inkscape:label="Drop Shadow"
|
||||||
|
id="filter4861">
|
||||||
|
<feFlood
|
||||||
|
flood-opacity="0.498039"
|
||||||
|
flood-color="rgb(0,0,0)"
|
||||||
|
result="flood"
|
||||||
|
id="feFlood4863" />
|
||||||
|
<feComposite
|
||||||
|
in="flood"
|
||||||
|
in2="SourceGraphic"
|
||||||
|
operator="in"
|
||||||
|
result="composite1"
|
||||||
|
id="feComposite4865" />
|
||||||
|
<feGaussianBlur
|
||||||
|
in="composite1"
|
||||||
|
stdDeviation="0.5"
|
||||||
|
result="blur"
|
||||||
|
id="feGaussianBlur4867" />
|
||||||
|
<feOffset
|
||||||
|
dx="1"
|
||||||
|
dy="1"
|
||||||
|
result="offset"
|
||||||
|
id="feOffset4869" />
|
||||||
|
<feComposite
|
||||||
|
in="SourceGraphic"
|
||||||
|
in2="offset"
|
||||||
|
operator="over"
|
||||||
|
result="composite2"
|
||||||
|
id="feComposite4871" />
|
||||||
|
</filter>
|
||||||
|
<filter
|
||||||
|
style="color-interpolation-filters:sRGB"
|
||||||
|
inkscape:label="Drop Shadow"
|
||||||
|
id="filter4873">
|
||||||
|
<feFlood
|
||||||
|
flood-opacity="0.498039"
|
||||||
|
flood-color="rgb(0,0,0)"
|
||||||
|
result="flood"
|
||||||
|
id="feFlood4875" />
|
||||||
|
<feComposite
|
||||||
|
in="flood"
|
||||||
|
in2="SourceGraphic"
|
||||||
|
operator="in"
|
||||||
|
result="composite1"
|
||||||
|
id="feComposite4877" />
|
||||||
|
<feGaussianBlur
|
||||||
|
in="composite1"
|
||||||
|
stdDeviation="0.5"
|
||||||
|
result="blur"
|
||||||
|
id="feGaussianBlur4879" />
|
||||||
|
<feOffset
|
||||||
|
dx="1"
|
||||||
|
dy="1"
|
||||||
|
result="offset"
|
||||||
|
id="feOffset4881" />
|
||||||
|
<feComposite
|
||||||
|
in="SourceGraphic"
|
||||||
|
in2="offset"
|
||||||
|
operator="over"
|
||||||
|
result="composite2"
|
||||||
|
id="feComposite4883" />
|
||||||
|
</filter>
|
||||||
|
</defs>
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="1"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="2.8"
|
||||||
|
inkscape:cx="147.44235"
|
||||||
|
inkscape:cy="123.18952"
|
||||||
|
inkscape:document-units="px"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
units="px"
|
||||||
|
inkscape:window-width="2489"
|
||||||
|
inkscape:window-height="1416"
|
||||||
|
inkscape:window-x="71"
|
||||||
|
inkscape:window-y="24"
|
||||||
|
inkscape:window-maximized="1" />
|
||||||
|
<metadata
|
||||||
|
id="metadata7">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title />
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(0,-740.36216)">
|
||||||
|
<g
|
||||||
|
id="g4291"
|
||||||
|
transform="translate(2.7857094,-4.6602266)">
|
||||||
|
<rect
|
||||||
|
y="884.505"
|
||||||
|
x="127.49588"
|
||||||
|
height="32.142857"
|
||||||
|
width="52.008236"
|
||||||
|
id="rect4164"
|
||||||
|
style="opacity:1;fill:#999999;fill-opacity:1;stroke:#999999;stroke-width:1.04799998;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||||
|
<rect
|
||||||
|
y="962.7193"
|
||||||
|
x="221.13875"
|
||||||
|
height="32.142857"
|
||||||
|
width="52.008236"
|
||||||
|
id="rect4164-3"
|
||||||
|
style="opacity:1;fill:#999999;fill-opacity:1;stroke:#999999;stroke-width:1.04799998;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||||
|
<rect
|
||||||
|
y="964.50494"
|
||||||
|
x="127.49588"
|
||||||
|
height="32.142857"
|
||||||
|
width="52.008236"
|
||||||
|
id="rect4164-3-8"
|
||||||
|
style="opacity:1;fill:#999999;fill-opacity:1;stroke:#999999;stroke-width:1.04799998;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||||
|
<rect
|
||||||
|
y="962.71924"
|
||||||
|
x="33.281597"
|
||||||
|
height="32.142857"
|
||||||
|
width="52.008236"
|
||||||
|
id="rect4164-3-8-2"
|
||||||
|
style="opacity:1;fill:#999999;fill-opacity:1;stroke:#999999;stroke-width:1.04799998;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path4213"
|
||||||
|
d="m 152.8127,917.08633 0.24905,47.56662 -0.12453,0.25781"
|
||||||
|
style="fill:none;fill-rule:evenodd;stroke:#999999;stroke-width:1.00338042px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" />
|
||||||
|
<path
|
||||||
|
sodipodi:nodetypes="cc"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path4213-5"
|
||||||
|
d="m 178.83354,916.21705 69.61257,46.82301"
|
||||||
|
style="fill:none;fill-rule:evenodd;stroke:#999999;stroke-width:1.04043412px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" />
|
||||||
|
<path
|
||||||
|
sodipodi:nodetypes="cc"
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path4213-5-9"
|
||||||
|
d="M 127.90666,916.57172 58.04914,962.57083"
|
||||||
|
style="fill:none;fill-rule:evenodd;stroke:#999999;stroke-width:1.0239116px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" />
|
||||||
|
<rect
|
||||||
|
y="805.39697"
|
||||||
|
x="126.89637"
|
||||||
|
height="32.142857"
|
||||||
|
width="52.008236"
|
||||||
|
id="rect4164-3-8-6"
|
||||||
|
style="opacity:1;fill:#999999;fill-opacity:1;stroke:#999999;stroke-width:1.04799998;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||||
|
<path
|
||||||
|
inkscape:connector-curvature="0"
|
||||||
|
id="path4213-2"
|
||||||
|
d="m 152.1837,827.96377 0.19318,68.10621 -0.0966,0.36913"
|
||||||
|
style="fill:none;fill-rule:evenodd;stroke:#999999;stroke-width:1.05742276px;stroke-linecap:round;stroke-linejoin:miter;stroke-opacity:1" />
|
||||||
|
</g>
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 6.3 KiB |
82
src/editor/images/add.svg
Normal file
82
src/editor/images/add.svg
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
width="256"
|
||||||
|
height="256"
|
||||||
|
viewBox="0 0 256 256"
|
||||||
|
id="svg4302"
|
||||||
|
version="1.1"
|
||||||
|
inkscape:version="0.91 r13725"
|
||||||
|
sodipodi:docname="add.svg"
|
||||||
|
inkscape:export-filename="/home/juzzlin/Home/Desktop-16.04/Projects/Programming/dementia/Dementia/data/images/add.png"
|
||||||
|
inkscape:export-xdpi="24"
|
||||||
|
inkscape:export-ydpi="24">
|
||||||
|
<defs
|
||||||
|
id="defs4304" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="base"
|
||||||
|
pagecolor="#80ffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:pageopacity="0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:zoom="2.8"
|
||||||
|
inkscape:cx="91.877846"
|
||||||
|
inkscape:cy="162.54621"
|
||||||
|
inkscape:document-units="px"
|
||||||
|
inkscape:current-layer="layer1"
|
||||||
|
showgrid="false"
|
||||||
|
units="px"
|
||||||
|
inkscape:window-width="2489"
|
||||||
|
inkscape:window-height="1416"
|
||||||
|
inkscape:window-x="71"
|
||||||
|
inkscape:window-y="24"
|
||||||
|
inkscape:window-maximized="1" />
|
||||||
|
<metadata
|
||||||
|
id="metadata4307">
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title></dc:title>
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<g
|
||||||
|
inkscape:label="Layer 1"
|
||||||
|
inkscape:groupmode="layer"
|
||||||
|
id="layer1"
|
||||||
|
transform="translate(0,-796.36219)">
|
||||||
|
<circle
|
||||||
|
style="opacity:1;fill:#999999;fill-opacity:1;stroke:#999999;stroke-width:0.30106509;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="path4852"
|
||||||
|
cx="128"
|
||||||
|
cy="924.36218"
|
||||||
|
r="119.84946" />
|
||||||
|
<rect
|
||||||
|
style="opacity:1;fill:#e6e6e6;fill-opacity:1;stroke:#e6e6e6;stroke-width:0.31811672;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect4854"
|
||||||
|
width="159.68188"
|
||||||
|
height="39.681885"
|
||||||
|
x="48.159058"
|
||||||
|
y="904.52124" />
|
||||||
|
<rect
|
||||||
|
style="opacity:1;fill:#e6e6e6;fill-opacity:1;stroke:#e6e6e6;stroke-width:0.31811675;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||||
|
id="rect4854-1"
|
||||||
|
width="159.68188"
|
||||||
|
height="39.681885"
|
||||||
|
x="844.52124"
|
||||||
|
y="-147.84094"
|
||||||
|
transform="matrix(0,1,-1,0,0,0)" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 2.7 KiB |
79
src/editor/main.cpp
Normal file
79
src/editor/main.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
#include "application.hpp"
|
||||||
|
#include "config.hpp"
|
||||||
|
#include "userexception.hpp"
|
||||||
|
#include "mclogger.hh"
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
|
#if QT_VERSION < 0x50600
|
||||||
|
extern Q_CORE_EXPORT QBasicAtomicInt qt_qhash_seed;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void initLogger()
|
||||||
|
{
|
||||||
|
QString logPath = QDir::tempPath() + QDir::separator() + "dementia.log";
|
||||||
|
MCLogger::init(logPath.toStdString().c_str());
|
||||||
|
MCLogger::enableEchoMode(true);
|
||||||
|
MCLogger::enableDateTimePrefix(true);
|
||||||
|
MCLogger().info() << Config::Editor::QSETTINGS_SOFTWARE_NAME.toStdString() << " version " << VERSION;
|
||||||
|
MCLogger().info() << "Compiled against Qt version " << QT_VERSION_STR;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char ** argv)
|
||||||
|
{
|
||||||
|
#if QT_VERSION >= 0x50600
|
||||||
|
qSetGlobalQHashSeed(0);
|
||||||
|
#else
|
||||||
|
qt_qhash_seed.store(0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
QApplication::setOrganizationName(Config::Common::QSETTINGS_COMPANY_NAME);
|
||||||
|
QApplication::setApplicationName(Config::Editor::QSETTINGS_SOFTWARE_NAME);
|
||||||
|
#ifdef Q_OS_WIN32
|
||||||
|
QSettings::setDefaultFormat(QSettings::IniFormat);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::unique_ptr<Application> app;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
initLogger();
|
||||||
|
|
||||||
|
app.reset(new Application(argc, argv));
|
||||||
|
|
||||||
|
return app->run();
|
||||||
|
}
|
||||||
|
catch (std::exception & e)
|
||||||
|
{
|
||||||
|
if (!dynamic_cast<UserException *>(&e))
|
||||||
|
{
|
||||||
|
std::cerr << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
app.reset();
|
||||||
|
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
310
src/editor/mainwindow.cpp
Normal file
310
src/editor/mainwindow.cpp
Normal file
@ -0,0 +1,310 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either Config::Editor 3 of the License, or
|
||||||
|
// (at your option) any later Config::Editor.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "mainwindow.hpp"
|
||||||
|
|
||||||
|
#include "config.hpp"
|
||||||
|
#include "aboutdlg.hpp"
|
||||||
|
#include "mediator.hpp"
|
||||||
|
#include "mindmapdata.hpp"
|
||||||
|
|
||||||
|
#include <QAction>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QDateTime>
|
||||||
|
#include <QDesktopWidget>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QGraphicsLineItem>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QMenuBar>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QToolBar>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
MainWindow * MainWindow::m_instance = nullptr;
|
||||||
|
|
||||||
|
MainWindow::MainWindow(QString mindMapFile)
|
||||||
|
: m_aboutDlg(new AboutDlg(this))
|
||||||
|
, m_argMindMapFile(mindMapFile)
|
||||||
|
, m_mediator(new Mediator(*this))
|
||||||
|
{
|
||||||
|
if (!m_instance)
|
||||||
|
{
|
||||||
|
m_instance = this;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qFatal("MainWindow already instantiated!");
|
||||||
|
}
|
||||||
|
|
||||||
|
setWindowIcon(QIcon(":/dementia-editor.png"));
|
||||||
|
|
||||||
|
init();
|
||||||
|
|
||||||
|
if (!m_argMindMapFile.isEmpty())
|
||||||
|
{
|
||||||
|
QTimer::singleShot(0, this, SLOT(openArgMindMap()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::openArgMindMap()
|
||||||
|
{
|
||||||
|
doOpenMindMap(m_argMindMapFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::init()
|
||||||
|
{
|
||||||
|
setTitle(tr("New file"));
|
||||||
|
|
||||||
|
QSettings settings;
|
||||||
|
|
||||||
|
// Read dialog size data
|
||||||
|
settings.beginGroup(m_settingsGroup);
|
||||||
|
resize(settings.value("size", QSize(640, 480)).toSize());
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
// Try to center the window.
|
||||||
|
QRect geometry(QApplication::desktop()->availableGeometry());
|
||||||
|
move(geometry.width() / 2 - width() / 2,
|
||||||
|
geometry.height() / 2 - height() / 2);
|
||||||
|
|
||||||
|
m_mediator->initScene();
|
||||||
|
|
||||||
|
populateMenuBar();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setTitle(QString openFileName)
|
||||||
|
{
|
||||||
|
setWindowTitle(
|
||||||
|
QString(Config::Editor::EDITOR_NAME) + " " + Config::Editor::EDITOR_VERSION + " - " +
|
||||||
|
openFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
MainWindow * MainWindow::instance()
|
||||||
|
{
|
||||||
|
return MainWindow::m_instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::closeEvent(QCloseEvent * event)
|
||||||
|
{
|
||||||
|
// Open settings file
|
||||||
|
QSettings settings;
|
||||||
|
|
||||||
|
// Save window size
|
||||||
|
settings.beginGroup(m_settingsGroup);
|
||||||
|
settings.setValue("size", size());
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::populateMenuBar()
|
||||||
|
{
|
||||||
|
// Create "file"-menu
|
||||||
|
QMenu * fileMenu = menuBar()->addMenu(tr("&File"));
|
||||||
|
|
||||||
|
// Add "new"-action
|
||||||
|
QAction * newAct = new QAction(tr("&New..."), this);
|
||||||
|
newAct->setShortcut(QKeySequence("Ctrl+N"));
|
||||||
|
fileMenu->addAction(newAct);
|
||||||
|
connect(newAct, SIGNAL(triggered()), this, SLOT(initializeNewMindMap()));
|
||||||
|
|
||||||
|
// Add "open"-action
|
||||||
|
QAction * openAct = new QAction(tr("&Open..."), this);
|
||||||
|
openAct->setShortcut(QKeySequence("Ctrl+O"));
|
||||||
|
fileMenu->addAction(openAct);
|
||||||
|
connect(openAct, SIGNAL(triggered()), this, SLOT(openMindMap()));
|
||||||
|
|
||||||
|
// Add "save"-action
|
||||||
|
m_saveAction = new QAction(tr("&Save"), this);
|
||||||
|
m_saveAction->setShortcut(QKeySequence("Ctrl+S"));
|
||||||
|
fileMenu->addAction(m_saveAction);
|
||||||
|
connect(m_saveAction, SIGNAL(triggered()), this, SLOT(saveMindMap()));
|
||||||
|
m_saveAction->setEnabled(false);
|
||||||
|
|
||||||
|
// Add "save as"-action
|
||||||
|
m_saveAsAction = new QAction(tr("&Save as..."), this);
|
||||||
|
m_saveAsAction->setShortcut(QKeySequence("Ctrl+Shift+S"));
|
||||||
|
fileMenu->addAction(m_saveAsAction);
|
||||||
|
connect(m_saveAsAction, SIGNAL(triggered()), this, SLOT(saveAsMindMap()));
|
||||||
|
m_saveAsAction->setEnabled(false);
|
||||||
|
|
||||||
|
// Add "quit"-action
|
||||||
|
QAction * quitAct = new QAction(tr("&Quit"), this);
|
||||||
|
quitAct->setShortcut(QKeySequence("Ctrl+W"));
|
||||||
|
fileMenu->addAction(quitAct);
|
||||||
|
connect(quitAct, SIGNAL(triggered()), this, SLOT(close()));
|
||||||
|
|
||||||
|
// Create "edit"-menu
|
||||||
|
QMenu * editMenu = menuBar()->addMenu(tr("&Edit"));
|
||||||
|
|
||||||
|
// Add "undo"-action
|
||||||
|
m_undoAction = new QAction(tr("Undo"), this);
|
||||||
|
m_undoAction->setShortcut(QKeySequence("Ctrl+Z"));
|
||||||
|
editMenu->addAction(m_undoAction);
|
||||||
|
connect(m_undoAction, &QAction::triggered, [this](){
|
||||||
|
m_mediator->undo();
|
||||||
|
|
||||||
|
setupMindMapAfterUndoOrRedo();
|
||||||
|
|
||||||
|
m_undoAction->setEnabled(m_mediator->isUndoable());
|
||||||
|
m_redoAction->setEnabled(m_mediator->isRedoable());
|
||||||
|
});
|
||||||
|
m_undoAction->setEnabled(false);
|
||||||
|
|
||||||
|
// Add "redo"-action
|
||||||
|
m_redoAction = new QAction(tr("Redo"), this);
|
||||||
|
m_redoAction->setShortcut(QKeySequence("Ctrl+Shift+Z"));
|
||||||
|
editMenu->addAction(m_redoAction);
|
||||||
|
connect(m_redoAction, &QAction::triggered, [this](){
|
||||||
|
m_mediator->redo();
|
||||||
|
|
||||||
|
setupMindMapAfterUndoOrRedo();
|
||||||
|
|
||||||
|
m_undoAction->setEnabled(m_mediator->isUndoable());
|
||||||
|
m_redoAction->setEnabled(m_mediator->isRedoable());
|
||||||
|
});
|
||||||
|
m_redoAction->setEnabled(false);
|
||||||
|
|
||||||
|
// Create "help"-menu
|
||||||
|
QMenu * helpMenu = menuBar()->addMenu(tr("&Help"));
|
||||||
|
|
||||||
|
// Add "about"-action
|
||||||
|
QAction * aboutAct = new QAction(tr("&About"), this);
|
||||||
|
helpMenu->addAction(aboutAct);
|
||||||
|
connect(aboutAct, SIGNAL(triggered()), this, SLOT(showAboutDlg()));
|
||||||
|
|
||||||
|
// Add "about Qt"-action
|
||||||
|
QAction * aboutQtAct = new QAction(tr("About &Qt"), this);
|
||||||
|
helpMenu->addAction(aboutQtAct);
|
||||||
|
connect(aboutQtAct, SIGNAL(triggered()), this, SLOT(showAboutQtDlg()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::openMindMap()
|
||||||
|
{
|
||||||
|
// Load recent path
|
||||||
|
QSettings settings;
|
||||||
|
|
||||||
|
settings.beginGroup(m_settingsGroup);
|
||||||
|
QString path = settings.value("recentPath",
|
||||||
|
QStandardPaths::writableLocation(QStandardPaths::HomeLocation)).toString();
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
const QString fileName = QFileDialog::getOpenFileName(
|
||||||
|
this, tr("Open a mindMap"), path, tr("MindMap Files (*.dm3)"));
|
||||||
|
if (!fileName.isEmpty())
|
||||||
|
{
|
||||||
|
doOpenMindMap(fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::showAboutDlg()
|
||||||
|
{
|
||||||
|
m_aboutDlg->exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::showAboutQtDlg()
|
||||||
|
{
|
||||||
|
QMessageBox::aboutQt(this, tr("About Qt"));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainWindow::doOpenMindMap(QString fileName)
|
||||||
|
{
|
||||||
|
if (!QFile::exists(fileName))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Undo stack will be cleared.
|
||||||
|
m_undoAction->setEnabled(false);
|
||||||
|
m_redoAction->setEnabled(false);
|
||||||
|
|
||||||
|
if (m_mediator->openMindMap(fileName))
|
||||||
|
{
|
||||||
|
setTitle(fileName);
|
||||||
|
|
||||||
|
// Save recent path
|
||||||
|
QSettings settings;
|
||||||
|
|
||||||
|
settings.beginGroup(m_settingsGroup);
|
||||||
|
settings.setValue("recentPath", fileName);
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
|
m_saveAction->setEnabled(true);
|
||||||
|
|
||||||
|
setActionStatesOnNewMindMap();
|
||||||
|
|
||||||
|
m_saved = true;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setupMindMapAfterUndoOrRedo()
|
||||||
|
{
|
||||||
|
m_saveAction->setEnabled(true);
|
||||||
|
|
||||||
|
setActionStatesOnNewMindMap();
|
||||||
|
|
||||||
|
m_mediator->setupMindMapAfterUndoOrRedo();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::saveMindMap()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::saveAsMindMap()
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::initializeNewMindMap()
|
||||||
|
{
|
||||||
|
m_mediator->initializeNewMindMap();
|
||||||
|
|
||||||
|
// Undo stack has been cleared.
|
||||||
|
m_undoAction->setEnabled(false);
|
||||||
|
m_redoAction->setEnabled(false);
|
||||||
|
|
||||||
|
setActionStatesOnNewMindMap();
|
||||||
|
|
||||||
|
setTitle(tr("New file"));
|
||||||
|
|
||||||
|
m_saved = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::setActionStatesOnNewMindMap()
|
||||||
|
{
|
||||||
|
m_saveAction->setEnabled(true);
|
||||||
|
m_saveAsAction->setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::enableUndo(bool enable)
|
||||||
|
{
|
||||||
|
m_undoAction->setEnabled(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
MainWindow::~MainWindow()
|
||||||
|
{
|
||||||
|
delete m_mediator;
|
||||||
|
}
|
107
src/editor/mainwindow.hpp
Normal file
107
src/editor/mainwindow.hpp
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef MAINWINDOW_HPP
|
||||||
|
#define MAINWINDOW_HPP
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QCloseEvent>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class AboutDlg;
|
||||||
|
class EditorData;
|
||||||
|
class EditorView;
|
||||||
|
class QAction;
|
||||||
|
class QCheckBox;
|
||||||
|
class QSlider;
|
||||||
|
class QTextEdit;
|
||||||
|
class Mediator;
|
||||||
|
|
||||||
|
class MainWindow : public QMainWindow
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit MainWindow(QString mindMapFile = "");
|
||||||
|
|
||||||
|
~MainWindow();
|
||||||
|
|
||||||
|
static MainWindow * instance();
|
||||||
|
|
||||||
|
void console(QString text);
|
||||||
|
|
||||||
|
void setTitle(QString openFileName);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
|
||||||
|
void enableUndo(bool enable);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
void closeEvent(QCloseEvent * event) override;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
bool doOpenMindMap(QString fileName);
|
||||||
|
|
||||||
|
void initializeNewMindMap();
|
||||||
|
|
||||||
|
void saveMindMap();
|
||||||
|
|
||||||
|
void saveAsMindMap();
|
||||||
|
|
||||||
|
void setupMindMapAfterUndoOrRedo();
|
||||||
|
|
||||||
|
void showAboutDlg();
|
||||||
|
|
||||||
|
void showAboutQtDlg();
|
||||||
|
|
||||||
|
void openArgMindMap();
|
||||||
|
|
||||||
|
void openMindMap();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
|
void populateMenuBar();
|
||||||
|
|
||||||
|
void setActionStatesOnNewMindMap();
|
||||||
|
|
||||||
|
AboutDlg * m_aboutDlg;
|
||||||
|
|
||||||
|
QAction * m_saveAction = nullptr;
|
||||||
|
|
||||||
|
QAction * m_saveAsAction = nullptr;
|
||||||
|
|
||||||
|
QAction * m_undoAction = nullptr;
|
||||||
|
|
||||||
|
QAction * m_redoAction = nullptr;
|
||||||
|
|
||||||
|
QString m_argMindMapFile;
|
||||||
|
|
||||||
|
bool m_saved = false;
|
||||||
|
|
||||||
|
const char * m_settingsGroup = "MainWindow";
|
||||||
|
|
||||||
|
Mediator * m_mediator;
|
||||||
|
|
||||||
|
static MainWindow * m_instance;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MAINWINDOW_HPP
|
||||||
|
|
188
src/editor/mediator.cpp
Normal file
188
src/editor/mediator.cpp
Normal file
@ -0,0 +1,188 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "mediator.hpp"
|
||||||
|
|
||||||
|
#include "draganddropstore.hpp"
|
||||||
|
#include "editordata.hpp"
|
||||||
|
#include "editorview.hpp"
|
||||||
|
#include "mainwindow.hpp"
|
||||||
|
|
||||||
|
#include <QGraphicsItem>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QSizePolicy>
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
Mediator::Mediator(MainWindow & mainWindow)
|
||||||
|
: m_editorData(new EditorData(*this))
|
||||||
|
, m_editorScene(new QGraphicsScene)
|
||||||
|
, m_editorView(new EditorView(*this))
|
||||||
|
, m_mainWindow(mainWindow)
|
||||||
|
{
|
||||||
|
m_editorView->setParent(&mainWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mediator::addItem(QGraphicsItem & item)
|
||||||
|
{
|
||||||
|
m_editorScene->addItem(&item);
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeBasePtr Mediator::createAndAddNode(int sourceNodeIndex, QPointF pos)
|
||||||
|
{
|
||||||
|
auto targetNode = std::dynamic_pointer_cast<Node>(m_editorData->createAndAddNodeToGraph(pos));
|
||||||
|
assert(targetNode);
|
||||||
|
|
||||||
|
auto sourceNode = std::dynamic_pointer_cast<Node>(getNodeByIndex(sourceNodeIndex));
|
||||||
|
assert(sourceNode);
|
||||||
|
|
||||||
|
auto graphicsEgde = sourceNode->createAndAddEdge(targetNode);
|
||||||
|
targetNode->addEdge(graphicsEgde);
|
||||||
|
|
||||||
|
addItem(*graphicsEgde); // QGraphicsScene needs the raw pointer
|
||||||
|
|
||||||
|
m_editorData->addExistingGraphToScene();
|
||||||
|
|
||||||
|
return targetNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
DragAndDropStore & Mediator::dadStore()
|
||||||
|
{
|
||||||
|
return m_editorData->dadStore();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mediator::enableUndo(bool enable)
|
||||||
|
{
|
||||||
|
m_mainWindow.enableUndo(enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
int Mediator::fitScale()
|
||||||
|
{
|
||||||
|
m_editorView->centerOn(m_editorView->sceneRect().center());
|
||||||
|
return m_editorView->viewport()->height() * 100 / m_editorView->sceneRect().height();
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeBasePtr Mediator::getNodeByIndex(int index)
|
||||||
|
{
|
||||||
|
return m_editorData->getNodeByIndex(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mediator::initializeNewMindMap()
|
||||||
|
{
|
||||||
|
assert(m_editorData);
|
||||||
|
|
||||||
|
m_editorData->setMindMapData(MindMapDataPtr(new MindMapData));
|
||||||
|
|
||||||
|
delete m_editorScene;
|
||||||
|
m_editorScene = new QGraphicsScene;
|
||||||
|
|
||||||
|
m_editorView->setScene(m_editorScene);
|
||||||
|
m_editorView->updateSceneRect();
|
||||||
|
|
||||||
|
m_editorData->createAndAddNodeToGraph(QPointF(0, 0));
|
||||||
|
m_editorData->addExistingGraphToScene();
|
||||||
|
|
||||||
|
fitScale();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mediator::initScene()
|
||||||
|
{
|
||||||
|
// Set scene to the view
|
||||||
|
m_editorView->setScene(m_editorScene);
|
||||||
|
m_editorView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||||
|
m_editorView->setMouseTracking(true);
|
||||||
|
m_editorView->setBackgroundBrush(QBrush(QColor(128, 200, 255, 255)));
|
||||||
|
|
||||||
|
m_mainWindow.setCentralWidget(m_editorView);
|
||||||
|
m_mainWindow.setContentsMargins(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Mediator::isRedoable() const
|
||||||
|
{
|
||||||
|
return m_editorData->isRedoable();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Mediator::isUndoable() const
|
||||||
|
{
|
||||||
|
return m_editorData->isUndoable();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Mediator::openMindMap(QString fileName)
|
||||||
|
{
|
||||||
|
assert(m_editorData);
|
||||||
|
|
||||||
|
if (m_editorData->loadMindMapData(fileName))
|
||||||
|
{
|
||||||
|
delete m_editorScene;
|
||||||
|
m_editorScene = new QGraphicsScene;
|
||||||
|
|
||||||
|
m_editorView->setScene(m_editorScene);
|
||||||
|
m_editorView->updateSceneRect();
|
||||||
|
|
||||||
|
m_editorData->addExistingGraphToScene();
|
||||||
|
|
||||||
|
fitScale();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mediator::redo()
|
||||||
|
{
|
||||||
|
m_editorData->redo();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mediator::removeItem(QGraphicsItem & item)
|
||||||
|
{
|
||||||
|
m_editorScene->removeItem(&item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mediator::saveUndoPoint()
|
||||||
|
{
|
||||||
|
m_editorData->saveUndoPoint();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mediator::setSelectedNode(Node * node)
|
||||||
|
{
|
||||||
|
m_editorData->setSelectedNode(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mediator::setupMindMapAfterUndoOrRedo()
|
||||||
|
{
|
||||||
|
delete m_editorScene;
|
||||||
|
m_editorScene = new QGraphicsScene;
|
||||||
|
|
||||||
|
m_editorView->setScene(m_editorScene);
|
||||||
|
m_editorView->updateSceneRect();
|
||||||
|
|
||||||
|
m_editorData->addExistingGraphToScene();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mediator::undo()
|
||||||
|
{
|
||||||
|
m_editorData->undo();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mediator::updateView()
|
||||||
|
{
|
||||||
|
m_editorView->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
Mediator::~Mediator()
|
||||||
|
{
|
||||||
|
delete m_editorData;
|
||||||
|
}
|
91
src/editor/mediator.hpp
Normal file
91
src/editor/mediator.hpp
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef MEDIATOR_HPP
|
||||||
|
#define MEDIATOR_HPP
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
#include <QPointF>
|
||||||
|
|
||||||
|
#include "node.hpp"
|
||||||
|
|
||||||
|
class DragAndDropStore;
|
||||||
|
class EditorData;
|
||||||
|
class EditorView;
|
||||||
|
class MainWindow;
|
||||||
|
class QGraphicsItem;
|
||||||
|
class QGraphicsScene;
|
||||||
|
|
||||||
|
/*! Acts as a communication channel between MainWindow and editor components:
|
||||||
|
*
|
||||||
|
* - MainWindow <-> Mediator <-> QGraphicsScene / EditorView / EditorData
|
||||||
|
* - EditorView <-> Mediator <-> EditorData
|
||||||
|
*/
|
||||||
|
class Mediator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit Mediator(MainWindow & mainWindow);
|
||||||
|
|
||||||
|
~Mediator();
|
||||||
|
|
||||||
|
void addItem(QGraphicsItem & item);
|
||||||
|
|
||||||
|
NodeBasePtr createAndAddNode(int sourceNodeIndex, QPointF pos);
|
||||||
|
|
||||||
|
DragAndDropStore & dadStore();
|
||||||
|
|
||||||
|
void enableUndo(bool enable);
|
||||||
|
|
||||||
|
int fitScale();
|
||||||
|
|
||||||
|
NodeBasePtr getNodeByIndex(int index);
|
||||||
|
|
||||||
|
void initializeNewMindMap();
|
||||||
|
|
||||||
|
void initScene();
|
||||||
|
|
||||||
|
bool isUndoable() const;
|
||||||
|
|
||||||
|
bool isRedoable() const;
|
||||||
|
|
||||||
|
bool openMindMap(QString fileName);
|
||||||
|
|
||||||
|
void redo();
|
||||||
|
|
||||||
|
void removeItem(QGraphicsItem & item);
|
||||||
|
|
||||||
|
void saveUndoPoint();
|
||||||
|
|
||||||
|
void setSelectedNode(Node * node);
|
||||||
|
|
||||||
|
void setupMindMapAfterUndoOrRedo();
|
||||||
|
|
||||||
|
void undo();
|
||||||
|
|
||||||
|
void updateView();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
EditorData * m_editorData;
|
||||||
|
|
||||||
|
QGraphicsScene * m_editorScene;
|
||||||
|
|
||||||
|
EditorView * m_editorView;
|
||||||
|
|
||||||
|
MainWindow & m_mainWindow;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MEDIATOR_HPP
|
69
src/editor/mindmapdata.cpp
Normal file
69
src/editor/mindmapdata.cpp
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "mindmapdata.hpp"
|
||||||
|
|
||||||
|
#include "node.hpp"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
MindMapData::MindMapData(QString name)
|
||||||
|
: MindMapDataBase(name)
|
||||||
|
{}
|
||||||
|
|
||||||
|
MindMapData::MindMapData(const MindMapData & other)
|
||||||
|
: MindMapDataBase(other)
|
||||||
|
, m_fileName(other.m_fileName)
|
||||||
|
{
|
||||||
|
copyGraph(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MindMapData::copyGraph(const MindMapData & other)
|
||||||
|
{
|
||||||
|
m_graph.clear();
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
//for (auto iter = other.m_graph.cbegin(); iter != other.m_graph.cend(); iter++)
|
||||||
|
//{
|
||||||
|
// auto node = std::dynamic_pointer_cast<Node>(*iter);
|
||||||
|
// auto newNode = new Node(*(node.get()));
|
||||||
|
//
|
||||||
|
// m_graph.add(NodeBasePtr(newNode));
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString MindMapData::fileName() const
|
||||||
|
{
|
||||||
|
return m_fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MindMapData::setFileName(QString newFileName)
|
||||||
|
{
|
||||||
|
m_fileName = newFileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
Graph & MindMapData::graph()
|
||||||
|
{
|
||||||
|
return m_graph;
|
||||||
|
}
|
||||||
|
|
||||||
|
const Graph & MindMapData::graph() const
|
||||||
|
{
|
||||||
|
return m_graph;
|
||||||
|
}
|
||||||
|
|
||||||
|
MindMapData::~MindMapData()
|
||||||
|
{
|
||||||
|
}
|
55
src/editor/mindmapdata.hpp
Normal file
55
src/editor/mindmapdata.hpp
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef MINDMAPDATA_HPP
|
||||||
|
#define MINDMAPDATA_HPP
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
#include "mindmapdatabase.hpp"
|
||||||
|
#include "graph.hpp"
|
||||||
|
|
||||||
|
class ObjectModelLoader;
|
||||||
|
|
||||||
|
class MindMapData : public MindMapDataBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
MindMapData(QString name = "");
|
||||||
|
|
||||||
|
MindMapData(const MindMapData & other);
|
||||||
|
|
||||||
|
virtual ~MindMapData();
|
||||||
|
|
||||||
|
QString fileName() const;
|
||||||
|
|
||||||
|
void setFileName(QString fileName);
|
||||||
|
|
||||||
|
Graph & graph();
|
||||||
|
|
||||||
|
const Graph & graph() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void copyGraph(const MindMapData & other);
|
||||||
|
|
||||||
|
QString m_fileName;
|
||||||
|
|
||||||
|
Graph m_graph;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::shared_ptr<MindMapData> MindMapDataPtr;
|
||||||
|
|
||||||
|
#endif // MINDMAPDATA_HPP
|
50
src/editor/mindmapdatabase.cpp
Normal file
50
src/editor/mindmapdatabase.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "mindmapdatabase.hpp"
|
||||||
|
|
||||||
|
MindMapDataBase::MindMapDataBase(QString name)
|
||||||
|
: m_name(name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
MindMapDataBase::MindMapDataBase(const MindMapDataBase & other)
|
||||||
|
: m_name(other.m_name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QString MindMapDataBase::name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int MindMapDataBase::index() const
|
||||||
|
{
|
||||||
|
return m_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MindMapDataBase::setName(QString name)
|
||||||
|
{
|
||||||
|
m_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MindMapDataBase::setIndex(unsigned int index)
|
||||||
|
{
|
||||||
|
m_index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
MindMapDataBase::~MindMapDataBase()
|
||||||
|
{
|
||||||
|
}
|
108
src/editor/mindmapdatabase.hpp
Normal file
108
src/editor/mindmapdatabase.hpp
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef MINDMAPDATABASE_HPP
|
||||||
|
#define MINDMAPDATABASE_HPP
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class Graph;
|
||||||
|
|
||||||
|
//! Common base class for track data shared by the editor and the game.
|
||||||
|
class MindMapDataBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/** Keywords used in the track data files.
|
||||||
|
* TODO: Use constexpr when MSVC supports it properly. */
|
||||||
|
struct DataKeywords
|
||||||
|
{
|
||||||
|
struct Header
|
||||||
|
{
|
||||||
|
static QString ver()
|
||||||
|
{
|
||||||
|
return "version";
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString name()
|
||||||
|
{
|
||||||
|
return "name";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Node
|
||||||
|
{
|
||||||
|
static QString index()
|
||||||
|
{
|
||||||
|
return "i";
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString x()
|
||||||
|
{
|
||||||
|
return "x";
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString y()
|
||||||
|
{
|
||||||
|
return "y";
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString width()
|
||||||
|
{
|
||||||
|
return "w";
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString height()
|
||||||
|
{
|
||||||
|
return "h";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
//! Constructor.
|
||||||
|
MindMapDataBase(QString name);
|
||||||
|
|
||||||
|
//! Copy constructor.
|
||||||
|
MindMapDataBase(const MindMapDataBase & other);
|
||||||
|
|
||||||
|
MindMapDataBase & operator= (const MindMapDataBase & other) = delete;
|
||||||
|
|
||||||
|
//! Destructor.
|
||||||
|
virtual ~MindMapDataBase();
|
||||||
|
|
||||||
|
virtual QString name() const;
|
||||||
|
|
||||||
|
virtual void setName(QString name);
|
||||||
|
|
||||||
|
virtual QString fileName() const = 0;
|
||||||
|
|
||||||
|
virtual void setFileName(QString fileName) = 0;
|
||||||
|
|
||||||
|
virtual unsigned int index() const;
|
||||||
|
|
||||||
|
virtual void setIndex(unsigned int index);
|
||||||
|
|
||||||
|
virtual Graph & graph() = 0;
|
||||||
|
|
||||||
|
virtual const Graph & graph() const = 0;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
QString m_name;
|
||||||
|
|
||||||
|
unsigned int m_index;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MINDMAPDATABASE_HPP
|
140
src/editor/node.cpp
Normal file
140
src/editor/node.cpp
Normal file
@ -0,0 +1,140 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "node.hpp"
|
||||||
|
|
||||||
|
#include "edge.hpp"
|
||||||
|
#include "nodehandle.hpp"
|
||||||
|
|
||||||
|
#include <QGraphicsDropShadowEffect>
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPen>
|
||||||
|
#include <QVector2D>
|
||||||
|
|
||||||
|
Node::Node()
|
||||||
|
{
|
||||||
|
setAcceptHoverEvents(true);
|
||||||
|
|
||||||
|
setSize(QSize(200, 150));
|
||||||
|
|
||||||
|
setZValue(10);
|
||||||
|
|
||||||
|
createHandles();
|
||||||
|
|
||||||
|
QGraphicsDropShadowEffect * shadow = new QGraphicsDropShadowEffect();
|
||||||
|
shadow->setOffset(QPointF(3, 3));
|
||||||
|
shadow->setBlurRadius(5);
|
||||||
|
setGraphicsEffect(shadow);
|
||||||
|
}
|
||||||
|
|
||||||
|
Node::Node(const Node & other)
|
||||||
|
: QGraphicsItem()
|
||||||
|
, NodeBase()
|
||||||
|
{
|
||||||
|
setAcceptHoverEvents(true);
|
||||||
|
|
||||||
|
setIndex(other.index());
|
||||||
|
|
||||||
|
setLocation(other.location());
|
||||||
|
|
||||||
|
setSize(other.size());
|
||||||
|
|
||||||
|
setZValue(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Node::addEdge(EdgePtr edge)
|
||||||
|
{
|
||||||
|
m_edges.push_back(edge);
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF Node::boundingRect() const
|
||||||
|
{
|
||||||
|
// The bounding rect has to cover also child nodes
|
||||||
|
const int margin = m_handleRadius;
|
||||||
|
return QRectF(-size().width() / 2 - margin, -size().height() / 2 - margin, size().width() + margin * 2, size().height() + margin * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
EdgePtr Node::createAndAddEdge(NodePtr targetNode)
|
||||||
|
{
|
||||||
|
auto edge = EdgePtr(new Edge(*this, *targetNode));
|
||||||
|
edge->updateLine();
|
||||||
|
m_edges.push_back(edge);
|
||||||
|
return edge;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Node::createHandles()
|
||||||
|
{
|
||||||
|
const std::vector<QPointF> positions = {
|
||||||
|
{0, size().height() * 0.5f}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (auto position : positions)
|
||||||
|
{
|
||||||
|
auto handle = new NodeHandle(m_handleRadius);
|
||||||
|
handle->setParentItem(this);
|
||||||
|
handle->setPos(position);
|
||||||
|
m_handles.push_back(handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Node::hoverEnterEvent(QGraphicsSceneHoverEvent * event)
|
||||||
|
{
|
||||||
|
setHandlesVisible(true);
|
||||||
|
|
||||||
|
QGraphicsItem::hoverEnterEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Node::hoverLeaveEvent(QGraphicsSceneHoverEvent * event)
|
||||||
|
{
|
||||||
|
setHandlesVisible(false);
|
||||||
|
|
||||||
|
QGraphicsItem::hoverLeaveEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Node::paint(QPainter * painter,
|
||||||
|
const QStyleOptionGraphicsItem * option, QWidget * widget)
|
||||||
|
{
|
||||||
|
Q_UNUSED(widget);
|
||||||
|
Q_UNUSED(option);
|
||||||
|
|
||||||
|
painter->save();
|
||||||
|
|
||||||
|
// Background
|
||||||
|
painter->fillRect(
|
||||||
|
-size().width() / 2, -size().height() / 2,
|
||||||
|
size().width(), size().height(),
|
||||||
|
QBrush(QColor(255, 255, 255, 255)));
|
||||||
|
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Node::setHandlesVisible(bool visible)
|
||||||
|
{
|
||||||
|
for (auto handle : m_handles)
|
||||||
|
{
|
||||||
|
handle->setVisible(visible);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Node::setLocation(QPointF newLocation)
|
||||||
|
{
|
||||||
|
NodeBase::setLocation(newLocation);
|
||||||
|
setPos(newLocation);
|
||||||
|
|
||||||
|
for (auto edge : m_edges)
|
||||||
|
{
|
||||||
|
edge->updateLine();
|
||||||
|
}
|
||||||
|
}
|
70
src/editor/node.hpp
Normal file
70
src/editor/node.hpp
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef NODE_HPP
|
||||||
|
#define NODE_HPP
|
||||||
|
|
||||||
|
#include <QGraphicsItem>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "nodebase.hpp"
|
||||||
|
#include "edge.hpp"
|
||||||
|
|
||||||
|
class NodeHandle;
|
||||||
|
|
||||||
|
//! Freely placeable target node.
|
||||||
|
class Node : public QGraphicsItem, public NodeBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
//! Constructor.
|
||||||
|
Node();
|
||||||
|
|
||||||
|
//! Copy constructor.
|
||||||
|
Node(const Node & other);
|
||||||
|
|
||||||
|
virtual void addEdge(EdgePtr edge);
|
||||||
|
|
||||||
|
virtual QRectF boundingRect () const override;
|
||||||
|
|
||||||
|
using NodePtr = std::shared_ptr<Node>;
|
||||||
|
virtual EdgePtr createAndAddEdge(NodePtr targetNode);
|
||||||
|
|
||||||
|
virtual void paint(QPainter * painter,
|
||||||
|
const QStyleOptionGraphicsItem * option, QWidget * widget = nullptr) override;
|
||||||
|
|
||||||
|
//! Sets the Node and QGraphicsItem locations.
|
||||||
|
virtual void setLocation(QPointF newLocation);
|
||||||
|
|
||||||
|
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent * event) override;
|
||||||
|
|
||||||
|
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent * event) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void createHandles();
|
||||||
|
|
||||||
|
void setHandlesVisible(bool visible);
|
||||||
|
|
||||||
|
std::vector<NodeHandle *> m_handles;
|
||||||
|
|
||||||
|
std::vector<EdgePtr> m_edges;
|
||||||
|
|
||||||
|
const int m_handleRadius = 32;
|
||||||
|
};
|
||||||
|
|
||||||
|
using NodePtr = std::shared_ptr<Node>;
|
||||||
|
|
||||||
|
#endif // NODE_HPP
|
54
src/editor/nodebase.cpp
Normal file
54
src/editor/nodebase.cpp
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "nodebase.hpp"
|
||||||
|
|
||||||
|
NodeBase::NodeBase()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize NodeBase::size() const
|
||||||
|
{
|
||||||
|
return m_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeBase::setSize(QSize size)
|
||||||
|
{
|
||||||
|
m_size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
QPointF NodeBase::location() const
|
||||||
|
{
|
||||||
|
return m_location;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeBase::setLocation(QPointF newLocation)
|
||||||
|
{
|
||||||
|
m_location = newLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
int NodeBase::index() const
|
||||||
|
{
|
||||||
|
return m_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeBase::setIndex(int index)
|
||||||
|
{
|
||||||
|
m_index = index;
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeBase::~NodeBase()
|
||||||
|
{
|
||||||
|
}
|
64
src/editor/nodebase.hpp
Normal file
64
src/editor/nodebase.hpp
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef NODEBASE_HPP
|
||||||
|
#define NODEBASE_HPP
|
||||||
|
|
||||||
|
#include <QSizeF>
|
||||||
|
#include <QString>
|
||||||
|
#include <QPointF>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
//! Base class for freely placeable target nodes in the editor.
|
||||||
|
class NodeBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
using NodeBasePtr = std::shared_ptr<NodeBase>;
|
||||||
|
|
||||||
|
NodeBase();
|
||||||
|
|
||||||
|
NodeBase(NodeBase & other) = delete;
|
||||||
|
|
||||||
|
NodeBase & operator= (NodeBase & other) = delete;
|
||||||
|
|
||||||
|
virtual ~NodeBase();
|
||||||
|
|
||||||
|
virtual QPointF location() const;
|
||||||
|
|
||||||
|
virtual void setLocation(QPointF newLocation);
|
||||||
|
|
||||||
|
virtual QSize size() const;
|
||||||
|
|
||||||
|
virtual void setSize(QSize size);
|
||||||
|
|
||||||
|
virtual int index() const;
|
||||||
|
|
||||||
|
virtual void setIndex(int index);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
QPointF m_location;
|
||||||
|
|
||||||
|
QSize m_size;
|
||||||
|
|
||||||
|
int m_index = -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
using NodeBasePtr = std::shared_ptr<NodeBase>;
|
||||||
|
|
||||||
|
#endif // NODEBASE_HPP
|
81
src/editor/nodehandle.cpp
Normal file
81
src/editor/nodehandle.cpp
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "nodehandle.hpp"
|
||||||
|
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPen>
|
||||||
|
|
||||||
|
NodeHandle::NodeHandle(int radius)
|
||||||
|
: m_radius(radius)
|
||||||
|
, m_sizeAnimation(this, "size")
|
||||||
|
{
|
||||||
|
m_sizeAnimation.setDuration(125);
|
||||||
|
|
||||||
|
QGraphicsItem::setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
QRectF NodeHandle::boundingRect() const
|
||||||
|
{
|
||||||
|
const int margin = 1;
|
||||||
|
return QRectF(-size().width() / 2 - margin, - size().height() / 2 - margin, size().width() + margin * 2, size().height() + margin * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeHandle::paint(QPainter * painter,
|
||||||
|
const QStyleOptionGraphicsItem * option, QWidget * widget)
|
||||||
|
{
|
||||||
|
Q_UNUSED(widget);
|
||||||
|
Q_UNUSED(option);
|
||||||
|
|
||||||
|
painter->save();
|
||||||
|
painter->drawPixmap(-size().width() / 2, -size().height() / 2, QPixmap(":/add.png").scaled(size().width(), size().height()));
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
QSize NodeHandle::size() const
|
||||||
|
{
|
||||||
|
return m_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeHandle::setSize(const QSize & size)
|
||||||
|
{
|
||||||
|
prepareGeometryChange();
|
||||||
|
|
||||||
|
m_size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodeHandle::setVisible(bool visible)
|
||||||
|
{
|
||||||
|
static const QSize away(0, 0);
|
||||||
|
static const QSize full(m_radius * 2, m_radius * 2);
|
||||||
|
|
||||||
|
if (visible)
|
||||||
|
{
|
||||||
|
QGraphicsItem::setVisible(true);
|
||||||
|
m_sizeAnimation.setStartValue(away);
|
||||||
|
m_sizeAnimation.setEndValue(full);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_sizeAnimation.setStartValue(full);
|
||||||
|
m_sizeAnimation.setEndValue(away);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_sizeAnimation.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
NodeHandle::~NodeHandle()
|
||||||
|
{
|
||||||
|
}
|
54
src/editor/nodehandle.hpp
Normal file
54
src/editor/nodehandle.hpp
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef NODEHANDLE_HPP
|
||||||
|
#define NODEHANDLE_HPP
|
||||||
|
|
||||||
|
#include <QGraphicsItem>
|
||||||
|
#include <QPropertyAnimation>
|
||||||
|
|
||||||
|
class Node;
|
||||||
|
|
||||||
|
class NodeHandle : public QObject, public QGraphicsItem
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QSize size READ size WRITE setSize)
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit NodeHandle(int radius);
|
||||||
|
|
||||||
|
virtual ~NodeHandle();
|
||||||
|
|
||||||
|
virtual QRectF boundingRect () const override;
|
||||||
|
|
||||||
|
virtual void paint(QPainter * painter,
|
||||||
|
const QStyleOptionGraphicsItem * option, QWidget * widget = nullptr) override;
|
||||||
|
|
||||||
|
QSize size() const;
|
||||||
|
void setSize(const QSize & size);
|
||||||
|
|
||||||
|
void setVisible(bool visible);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
int m_radius;
|
||||||
|
|
||||||
|
QPropertyAnimation m_sizeAnimation;
|
||||||
|
|
||||||
|
QSize m_size;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // NODEHANDLE_HPP
|
83
src/editor/undostack.cpp
Normal file
83
src/editor/undostack.cpp
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include "undostack.hpp"
|
||||||
|
|
||||||
|
UndoStack::UndoStack(unsigned int maxHistorySize)
|
||||||
|
: m_maxHistorySize(maxHistorySize)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void UndoStack::pushUndoPoint(MindMapDataPtr mindMapData)
|
||||||
|
{
|
||||||
|
auto copyData = new MindMapData(*mindMapData.get());
|
||||||
|
m_undoStack.push_back(MindMapDataPtr(copyData));
|
||||||
|
|
||||||
|
if (m_undoStack.size() > m_maxHistorySize)
|
||||||
|
{
|
||||||
|
m_undoStack.pop_front();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UndoStack::pushRedoPoint(MindMapDataPtr mindMapData)
|
||||||
|
{
|
||||||
|
auto copyData = new MindMapData(*mindMapData.get());
|
||||||
|
m_redoStack.push_back(MindMapDataPtr(copyData));
|
||||||
|
|
||||||
|
if (m_redoStack.size() > m_maxHistorySize)
|
||||||
|
{
|
||||||
|
m_redoStack.pop_front();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UndoStack::clear()
|
||||||
|
{
|
||||||
|
m_undoStack.clear();
|
||||||
|
m_redoStack.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UndoStack::isUndoable() const
|
||||||
|
{
|
||||||
|
return m_undoStack.size() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
MindMapDataPtr UndoStack::undo()
|
||||||
|
{
|
||||||
|
if (isUndoable())
|
||||||
|
{
|
||||||
|
auto head = m_undoStack.back();
|
||||||
|
m_undoStack.pop_back();
|
||||||
|
return head;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MindMapDataPtr();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UndoStack::isRedoable() const
|
||||||
|
{
|
||||||
|
return m_redoStack.size() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
MindMapDataPtr UndoStack::redo()
|
||||||
|
{
|
||||||
|
if (isRedoable())
|
||||||
|
{
|
||||||
|
auto head = m_redoStack.back();
|
||||||
|
m_redoStack.pop_back();
|
||||||
|
return head;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MindMapDataPtr();
|
||||||
|
}
|
54
src/editor/undostack.hpp
Normal file
54
src/editor/undostack.hpp
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef UNDOSTACK_HPP
|
||||||
|
#define UNDOSTACK_HPP
|
||||||
|
|
||||||
|
#include "mindmapdata.hpp"
|
||||||
|
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
class UndoStack
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
UndoStack(unsigned int maxHistorySize = 100);
|
||||||
|
|
||||||
|
void pushUndoPoint(MindMapDataPtr mindMapData);
|
||||||
|
|
||||||
|
void pushRedoPoint(MindMapDataPtr mindMapData);
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
bool isUndoable() const;
|
||||||
|
|
||||||
|
MindMapDataPtr undo();
|
||||||
|
|
||||||
|
bool isRedoable() const;
|
||||||
|
|
||||||
|
MindMapDataPtr redo();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
using MindMapDataVector = std::list<MindMapDataPtr>;
|
||||||
|
|
||||||
|
MindMapDataVector m_undoStack;
|
||||||
|
|
||||||
|
MindMapDataVector m_redoStack;
|
||||||
|
|
||||||
|
unsigned int m_maxHistorySize;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // UNDOSTACK_HPP
|
31
src/editor/userexception.hpp
Normal file
31
src/editor/userexception.hpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
// This file is part of Dementia.
|
||||||
|
// Copyright (C) 2018 Jussi Lind <jussi.lind@iki.fi>
|
||||||
|
//
|
||||||
|
// Dementia is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
// Dementia is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License
|
||||||
|
// along with Dementia. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#ifndef USEREXCEPTION_HPP
|
||||||
|
#define USEREXCEPTION_HPP
|
||||||
|
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class UserException : public std::runtime_error
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit UserException(std::string msg)
|
||||||
|
: runtime_error(msg)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // USEREXCEPTION_HPP
|
Loading…
x
Reference in New Issue
Block a user