diff --git a/CMakeLists.txt b/CMakeLists.txt index d5ef4c9..c6f9b8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,7 +51,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -O0 ${CMAKE_CXX_FLAGS_DEBUG}") set(CMAKE_PREFIX_PATH "lib/qt6") set(QT_DEFAULT_MAJOR_VERSION 6) -find_package(Qt6 COMPONENTS Core Widgets LinguistTools REQUIRED) +find_package(Qt6 COMPONENTS Core Widgets LinguistTools Svg REQUIRED) if(Qt6Core_FOUND) message(STATUS "Found Qt6Core Version: ${Qt6Core_VERSION}") endif() @@ -83,7 +83,9 @@ include_directories( # Source Files list(APPEND SRC_FILES src/core/data + src/core/icons src/core/storage + src/core/svgiconengine src/editor/doceditor src/gui/maintoolbar src/gui/statusbar @@ -107,5 +109,5 @@ set(QRC_FILES qt_add_executable(Collett ${SRC_FILES} ${QRC_FILES} ${TS_FILES}) set_target_properties(Collett PROPERTIES OUTPUT_NAME "collett") -target_link_libraries(Collett PRIVATE Qt::Widgets) +target_link_libraries(Collett PRIVATE Qt::Widgets Qt::Svg) target_compile_definitions(Collett PUBLIC "$<$:DEBUG>") diff --git a/i18n/collett_en_US.ts b/i18n/collett_en_US.ts index 0b1999e..e7862d9 100644 --- a/i18n/collett_en_US.ts +++ b/i18n/collett_en_US.ts @@ -4,7 +4,7 @@ Collett::GuiMain - + %1 %2 Version %3 @@ -12,32 +12,32 @@ Collett::GuiMainToolBar - + No Project - + New Project - + Open Project - + Save Project - + Project - + Menu @@ -120,12 +120,12 @@ Collett::GuiTreeToolBar - + Story - + Settings diff --git a/i18n/collett_nb_NO.ts b/i18n/collett_nb_NO.ts index 7d71856..f9a1f5f 100644 --- a/i18n/collett_nb_NO.ts +++ b/i18n/collett_nb_NO.ts @@ -4,7 +4,7 @@ Collett::GuiMain - + %1 %2 Version %3 @@ -12,32 +12,32 @@ Collett::GuiMainToolBar - + No Project - + New Project - + Open Project - + Save Project - + Project - + Menu @@ -120,12 +120,12 @@ Collett::GuiTreeToolBar - + Story - + Settings diff --git a/src/collett.h b/src/collett.h index 7d63f7c..3a031ba 100644 --- a/src/collett.h +++ b/src/collett.h @@ -26,9 +26,4 @@ #define COL_VERSION_NUM 0x000001a0 #define COL_VERSION_DATE "2021-11-14" -#define COL_PROJECT_FILE_NAME "project.collett" -#define COL_SETTINGS_FILE_NAME "project.json" -#define COL_STORY_FILE_NAME "story.json" -#define COL_NOTES_FILE_NAME "notes.json" - #endif // COLLETT_H diff --git a/src/core/icons.cpp b/src/core/icons.cpp new file mode 100644 index 0000000..883ce46 --- /dev/null +++ b/src/core/icons.cpp @@ -0,0 +1,112 @@ +/* +** Collett – Core Icon Repository +** ============================== +** +** This file is a part of Collett +** Copyright 2020–2021, Veronica Berglyd Olsen +** +** 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 . +*/ + +#include "icons.h" +#include "svgiconengine.h" + +#include +#include +#include +#include +#include +#include + +namespace Collett { + +CollettIcons *CollettIcons::staticInstance = nullptr; +CollettIcons *CollettIcons::instance() { + if (staticInstance == nullptr) { + staticInstance = new CollettIcons(); + qDebug() << "Constructor: CollettIcons"; + } + return staticInstance; +} + +void CollettIcons::destroy() { + if (staticInstance != nullptr) { + delete CollettIcons::staticInstance; + } +} + +/**! + * @brief Construct a CollettIcons object. + * + * The icon SVG data is from https://remixicon.com + */ +CollettIcons::CollettIcons() { + + // RemixIcon: archive-fill + m_svgData["archive"] = QString( + "" + "" + "" + "" + ); + + // RemixIcon: book-fill + m_svgData["book"] = QString( + "" + "" + "" + "" + ); + + // RemixIcon: more-2-fill + m_svgData["more"] = QString( + "" + "" + "" + ); + + // RemixIcon: settings-5-fill + m_svgData["settings"] = QString( + "" + "" + "" + "" + ); +} + +CollettIcons::~CollettIcons() { + qDebug() << "Destructor: CollettIcons"; +} + +QIcon CollettIcons::icon(const QString &name) { + QColor col = qApp->palette().buttonText().color(); + QString svg = m_svgData[name].arg(col.name(QColor::HexRgb)).arg("0.8"); + return QIcon(new SVGIconEngine(svg)); +} + +} // namespace Collett diff --git a/src/core/icons.h b/src/core/icons.h new file mode 100644 index 0000000..c6df814 --- /dev/null +++ b/src/core/icons.h @@ -0,0 +1,53 @@ +/* +** Collett – Core Icon Repository +** ============================== +** +** This file is a part of Collett +** Copyright 2020–2021, Veronica Berglyd Olsen +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, but +** WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +*/ + +#ifndef COLLETT_ICONS_H +#define COLLETT_ICONS_H + +#include +#include +#include +#include +#include + +namespace Collett { + +class CollettIcons : public QObject +{ + Q_OBJECT + +public: + static CollettIcons *instance(); + static void destroy(); + + explicit CollettIcons(); + ~CollettIcons(); + + QIcon icon(const QString &name); + +private: + static CollettIcons *staticInstance; + QHash m_svgData; + +}; +} // namespace Collett + +#endif // COLLETT_ICONS_H diff --git a/src/core/svgiconengine.cpp b/src/core/svgiconengine.cpp new file mode 100644 index 0000000..cee4e6c --- /dev/null +++ b/src/core/svgiconengine.cpp @@ -0,0 +1,67 @@ +/* +** Collett – Core SVG Icon Engine +** ============================== +** +** This file is a part of Collett +** Copyright 2020–2021, Veronica Berglyd Olsen +** +** 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 . +*/ + +#include "svgiconengine.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +namespace Collett { + +/** + * Custom Icon Engine + * ================== + * Based on: https://stackoverflow.com/a/44757951 + */ + +SVGIconEngine::SVGIconEngine(const QString &iconBuffer) { + m_iconData = iconBuffer.toLatin1(); +} + +void SVGIconEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) { + QSvgRenderer renderer(m_iconData); + renderer.render(painter, rect); +} + +QIconEngine *SVGIconEngine::clone() const { + return new SVGIconEngine(*this); +} + +QPixmap SVGIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) { + + QImage img(size, QImage::Format_ARGB32); + img.fill(qRgba(0, 0, 0, 0)); + QPixmap pix = QPixmap::fromImage(img, Qt::NoFormatConversion); + { + QPainter painter(&pix); + QRect rect(QPoint(0.0, 0.0), size); + this->paint(&painter, rect, mode, state); + } + return pix; +} + +} // namespace Collett diff --git a/src/core/svgiconengine.h b/src/core/svgiconengine.h new file mode 100644 index 0000000..7eb9344 --- /dev/null +++ b/src/core/svgiconengine.h @@ -0,0 +1,51 @@ +/* +** Collett – Core SVG Icon Engine +** ============================== +** +** This file is a part of Collett +** Copyright 2020–2021, Veronica Berglyd Olsen +** +** This program is free software: you can redistribute it and/or modify +** it under the terms of the GNU General Public License as published by +** the Free Software Foundation, either version 3 of the License, or +** (at your option) any later version. +** +** This program is distributed in the hope that it will be useful, but +** WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +** General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program. If not, see . +*/ + +#ifndef SVGICONENGINE_H +#define SVGICONENGINE_H + +#include +#include +#include +#include +#include +#include +#include + +namespace Collett { + +class SVGIconEngine : public QIconEngine +{ + +public: + explicit SVGIconEngine(const QString &iconBuffer); + + void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override; + QIconEngine *clone() const override; + QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override; + +private: + QByteArray m_iconData; + +}; +} // namespace Collett + +#endif // SVGICONENGINE_H diff --git a/src/gui/maintoolbar.cpp b/src/gui/maintoolbar.cpp index decb6a6..acf59b1 100644 --- a/src/gui/maintoolbar.cpp +++ b/src/gui/maintoolbar.cpp @@ -20,6 +20,7 @@ */ #include "maintoolbar.h" +#include "icons.h" #include #include @@ -45,7 +46,7 @@ GuiMainToolBar::GuiMainToolBar(QWidget *parent) this->addWidget(stretch1); this->addWidget(m_projectName); this->addWidget(stretch2); - this->addAction(tr("Menu")); + this->buildMoreMenu(); } void GuiMainToolBar::setProjectName(const QString &name) { @@ -59,6 +60,8 @@ void GuiMainToolBar::setProjectName(const QString &name) { void GuiMainToolBar::buildProjectMenu() { + CollettIcons *icons = CollettIcons::instance(); + // Menu m_projectMenu = new QMenu(this); @@ -74,10 +77,28 @@ void GuiMainToolBar::buildProjectMenu() { // Assemble m_projectButton = new QToolButton(this); m_projectButton->setText(tr("Project")); + m_projectButton->setIcon(icons->icon("archive")); m_projectButton->setMenu(m_projectMenu); m_projectButton->setPopupMode(QToolButton::InstantPopup); this->addWidget(m_projectButton); } +void GuiMainToolBar::buildMoreMenu() { + + CollettIcons *icons = CollettIcons::instance(); + + // Menu + m_moreMenu = new QMenu(this); + + // Assemble + m_moreButton = new QToolButton(this); + m_moreButton->setText(tr("Menu")); + m_moreButton->setIcon(icons->icon("more")); + m_moreButton->setMenu(m_moreMenu); + m_moreButton->setPopupMode(QToolButton::InstantPopup); + this->addWidget(m_moreButton); + +} + } // namespace Collett diff --git a/src/gui/maintoolbar.h b/src/gui/maintoolbar.h index 2bda05d..9d6fd03 100644 --- a/src/gui/maintoolbar.h +++ b/src/gui/maintoolbar.h @@ -45,14 +45,19 @@ class GuiMainToolBar : public QToolBar private: QLabel *m_projectName; - // Main Actions + // Project Menu QToolButton *m_projectButton; QMenu *m_projectMenu; QAction *m_newProject; QAction *m_openProject; QAction *m_saveProject; + // DropDown Menu + QToolButton *m_moreButton; + QMenu *m_moreMenu; + void buildProjectMenu(); + void buildMoreMenu(); }; } // namespace Collett diff --git a/src/gui/treetoolbar.cpp b/src/gui/treetoolbar.cpp index 370b565..1540d49 100644 --- a/src/gui/treetoolbar.cpp +++ b/src/gui/treetoolbar.cpp @@ -20,10 +20,11 @@ */ #include "treetoolbar.h" +#include "icons.h" #include -#include #include +#include #include namespace Collett { @@ -34,10 +35,12 @@ GuiTreeToolBar::GuiTreeToolBar(QWidget *parent) QWidget *stretch = new QWidget(this); stretch->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + CollettIcons *icons = CollettIcons::instance(); + this->setOrientation(Qt::Vertical); - this->addAction(tr("Story")); + this->addAction(icons->icon("book"), tr("Story")); this->addWidget(stretch); - this->addAction(tr("Settings")); + this->addAction(icons->icon("settings"), tr("Settings")); } } // namespace Collett diff --git a/src/guimain.cpp b/src/guimain.cpp index 8ff5ce7..5707de7 100644 --- a/src/guimain.cpp +++ b/src/guimain.cpp @@ -19,14 +19,15 @@ ** along with this program. If not, see . */ -#include "guimain.h" #include "data.h" -#include "settings.h" +#include "doceditor.h" +#include "guimain.h" +#include "icons.h" #include "maintoolbar.h" -#include "treetoolbar.h" +#include "settings.h" #include "statusbar.h" #include "storytree.h" -#include "doceditor.h" +#include "treetoolbar.h" #include #include @@ -124,6 +125,9 @@ bool GuiMain::closeMain() { } mainConf->flushSettings(); + CollettIcons::destroy(); + CollettSettings::destroy(); + return true; } diff --git a/src/project/project.cpp b/src/project/project.cpp index 2881544..418fffe 100644 --- a/src/project/project.cpp +++ b/src/project/project.cpp @@ -131,9 +131,9 @@ StoryModel *Project::storyModel() { } /** - * Settings FIle + * Settings File * ============= - * Load and save functions for the data/project.json file. + * Load and save functions for the project/project.json file. * * This file contains all the meta data and options for the Collett project, * except for the project content itself (the documents). @@ -180,7 +180,7 @@ bool Project::saveSettingsFile() { /** * Story File * ========== - * Load and save functions for the data/story.json file. + * Load and save functions for the project/story.json file. * * This file contains the structure of StoryItems contained in the StoryModel. * The structure is contained as child items under a single root item, and is diff --git a/src/settings.cpp b/src/settings.cpp index 0a79317..717b1eb 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -82,11 +82,17 @@ CollettSettings *CollettSettingsPrivate::instance = nullptr; CollettSettings *CollettSettings::instance() { if (CollettSettingsPrivate::instance == nullptr) { CollettSettingsPrivate::instance = new CollettSettings(); - qDebug() << "CollettSettings instance created"; + qDebug() << "Constructor: CollettSettings"; } return CollettSettingsPrivate::instance; } +void CollettSettings::destroy() { + if (CollettSettingsPrivate::instance != nullptr) { + delete CollettSettingsPrivate::instance; + } +} + CollettSettings::CollettSettings() : d_ptr(new CollettSettingsPrivate()) { @@ -109,7 +115,6 @@ CollettSettings::CollettSettings() CollettSettings::~CollettSettings() { qDebug() << "Destructor: CollettSettings"; - flushSettings(); } /** diff --git a/src/settings.h b/src/settings.h index 69f5a73..6f452d1 100644 --- a/src/settings.h +++ b/src/settings.h @@ -39,6 +39,7 @@ class CollettSettings : public QObject public: static CollettSettings *instance(); + static void destroy(); ~CollettSettings(); private: