From ab2983dcaaae0b05b9f364c34b60ded81201df39 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 19 Dec 2021 17:49:12 +0100 Subject: [PATCH 1/7] Use Google material design icons instead --- src/core/icons.cpp | 63 +++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/core/icons.cpp b/src/core/icons.cpp index 883ce46..8f72235 100644 --- a/src/core/icons.cpp +++ b/src/core/icons.cpp @@ -49,52 +49,53 @@ void CollettIcons::destroy() { /**! * @brief Construct a CollettIcons object. * - * The icon SVG data is from https://remixicon.com + * The icon SVG data is from https://fonts.google.com/icons + * Icon style: Filled */ CollettIcons::CollettIcons() { - // RemixIcon: archive-fill + // inventory_2_black_24dp.svg m_svgData["archive"] = QString( - "" - "" - "" + "" + "" + "" "" ); - // RemixIcon: book-fill + // auto_stories_black_24dp.svg m_svgData["book"] = QString( - "" - "" - "" + "" + "" + "" "" ); - // RemixIcon: more-2-fill + // more_vert_black_24dp.svg m_svgData["more"] = QString( - "" - "" + "" + "" + "" "" ); - // RemixIcon: settings-5-fill + // settings_black_24dp.svg m_svgData["settings"] = QString( - "" - "" - "" + "" + "" + "" "" ); } @@ -105,7 +106,7 @@ CollettIcons::~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"); + QString svg = m_svgData[name].arg(col.name(QColor::HexRgb)).arg("0.7"); return QIcon(new SVGIconEngine(svg)); } From 91e9b719177bdcffe29b72dcc9aa37303b59e2a7 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 19 Dec 2021 18:51:40 +0100 Subject: [PATCH 2/7] Add a bunch of text formatting icons --- src/core/icons.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++--- src/core/icons.h | 3 +- 2 files changed, 91 insertions(+), 6 deletions(-) diff --git a/src/core/icons.cpp b/src/core/icons.cpp index 8f72235..ff25e6d 100644 --- a/src/core/icons.cpp +++ b/src/core/icons.cpp @@ -28,6 +28,7 @@ #include #include #include +#include namespace Collett { @@ -48,14 +49,46 @@ void CollettIcons::destroy() { /**! * @brief Construct a CollettIcons object. - * + * * The icon SVG data is from https://fonts.google.com/icons * Icon style: Filled */ CollettIcons::CollettIcons() { + // format_align_center_black_24dp.svg + m_svgData["alignCentre"] = QLatin1String( + "" + "" + "" + "" + ); + + // format_align_justify_black_24dp.svg + m_svgData["alignJustify"] = QLatin1String( + "" + "" + "" + "" + ); + + // format_align_left_black_24dp.svg + m_svgData["alignLeft"] = QLatin1String( + "" + "" + "" + "" + ); + + // format_align_right_black_24dp.svg + m_svgData["alignRight"] = QLatin1String( + "" + "" + "" + "" + ); + // inventory_2_black_24dp.svg - m_svgData["archive"] = QString( + m_svgData["archive"] = QLatin1String( "" "" @@ -64,8 +97,18 @@ CollettIcons::CollettIcons() { "" ); + // format_bold_black_24dp.svg + m_svgData["bold"] = QLatin1String( + "" + "" + "" + "" + ); + // auto_stories_black_24dp.svg - m_svgData["book"] = QString( + m_svgData["book"] = QLatin1String( "" "" "" + "" + "" + "" + ); + + // format_indent_decrease_black_24dp.svg + m_svgData["blockOutdent"] = QLatin1String( + "" + "" + "" + "" + ); + + // format_italic_black_24dp.svg + m_svgData["italic"] = QLatin1String( + "" + "" + "" + "" + ); + // more_vert_black_24dp.svg - m_svgData["more"] = QString( + m_svgData["more"] = QLatin1String( "" "" "" "" @@ -98,6 +165,23 @@ CollettIcons::CollettIcons() { ",3.5S13.97,15.5,12.04,15.5z'/>" "" ); + + // format_strikethrough_black_24dp.svg + m_svgData["strikethrough"] = QLatin1String( + "" + "" + "" + "" + ); + + // format_underlined_black_24dp.svg + m_svgData["underline"] = QLatin1String( + "" + "" + "" + "" + ); } CollettIcons::~CollettIcons() { diff --git a/src/core/icons.h b/src/core/icons.h index c6df814..5f372c6 100644 --- a/src/core/icons.h +++ b/src/core/icons.h @@ -27,6 +27,7 @@ #include #include #include +#include namespace Collett { @@ -45,7 +46,7 @@ class CollettIcons : public QObject private: static CollettIcons *staticInstance; - QHash m_svgData; + QHash m_svgData; }; } // namespace Collett From d983e2fee4cc1d26d03240c9b50345a3abe267ed Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 19 Dec 2021 18:52:57 +0100 Subject: [PATCH 3/7] Add a toolbar to the document editor --- CMakeLists.txt | 2 ++ i18n/collett_en_US.ts | 53 ++++++++++++++++++++++++++++++++++ i18n/collett_nb_NO.ts | 53 ++++++++++++++++++++++++++++++++++ src/editor/doceditor.cpp | 56 ++++++++++++++++++++++-------------- src/editor/doceditor.h | 54 +++++++++++++++++++---------------- src/editor/edittoolbar.cpp | 58 ++++++++++++++++++++++++++++++++++++++ src/editor/edittoolbar.h | 56 ++++++++++++++++++++++++++++++++++++ src/editor/textedit.cpp | 34 ++++++++++++++++++++++ src/editor/textedit.h | 42 +++++++++++++++++++++++++++ src/guimain.cpp | 2 +- 10 files changed, 364 insertions(+), 46 deletions(-) create mode 100644 src/editor/edittoolbar.cpp create mode 100644 src/editor/edittoolbar.h create mode 100644 src/editor/textedit.cpp create mode 100644 src/editor/textedit.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c6f9b8c..6fe99a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,6 +87,8 @@ list(APPEND SRC_FILES src/core/storage src/core/svgiconengine src/editor/doceditor + src/editor/edittoolbar + src/editor/textedit src/gui/maintoolbar src/gui/statusbar src/gui/storytree diff --git a/i18n/collett_en_US.ts b/i18n/collett_en_US.ts index e7862d9..619182a 100644 --- a/i18n/collett_en_US.ts +++ b/i18n/collett_en_US.ts @@ -1,6 +1,59 @@ + + Collett::GuiEditToolBar + + + Bold + + + + + Italic + + + + + Underline + + + + + Strikethrough + + + + + Align Left + + + + + Align Right + + + + + Align Centre + + + + + Align Justify + + + + + Indent Paragraph + + + + + Outdent Paragraph + + + Collett::GuiMain diff --git a/i18n/collett_nb_NO.ts b/i18n/collett_nb_NO.ts index f9a1f5f..80d6082 100644 --- a/i18n/collett_nb_NO.ts +++ b/i18n/collett_nb_NO.ts @@ -1,6 +1,59 @@ + + Collett::GuiEditToolBar + + + Bold + + + + + Italic + + + + + Underline + + + + + Strikethrough + + + + + Align Left + + + + + Align Right + + + + + Align Centre + + + + + Align Justify + + + + + Indent Paragraph + + + + + Outdent Paragraph + + + Collett::GuiMain diff --git a/src/editor/doceditor.cpp b/src/editor/doceditor.cpp index 2fa7d38..b73e880 100644 --- a/src/editor/doceditor.cpp +++ b/src/editor/doceditor.cpp @@ -1,33 +1,47 @@ /* -Collett – GUI Document Editor Class -=================================== - -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 . +** Collett – GUI Document Editor Class +** =================================== +** +** 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 "doceditor.h" +#include "textedit.h" +#include "edittoolbar.h" #include -#include +#include +#include namespace Collett { GuiDocEditor::GuiDocEditor(QWidget *parent) - : QTextEdit(parent) -{} + : QWidget(parent) +{ + m_textArea = new GuiTextEdit(this); + m_editToolBar = new GuiEditToolBar(this); + + QVBoxLayout *outerBox = new QVBoxLayout; + outerBox->addWidget(m_editToolBar); + outerBox->addWidget(m_textArea); + outerBox->setContentsMargins(0, 0, 0, 0); + outerBox->setSpacing(0); + + this->setLayout(outerBox); +} } // namespace Collett diff --git a/src/editor/doceditor.h b/src/editor/doceditor.h index 8b12e19..c8269a8 100644 --- a/src/editor/doceditor.h +++ b/src/editor/doceditor.h @@ -1,42 +1,48 @@ /* -Collett – GUI Document Editor Class -=================================== - -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 . +** Collett – GUI Document Editor Class +** =================================== +** +** 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 GUIDOCEDITOR_H -#define GUIDOCEDITOR_H +#ifndef GUI_DOCEDITOR_H +#define GUI_DOCEDITOR_H + +#include "textedit.h" +#include "edittoolbar.h" #include -#include +#include namespace Collett { -class GuiDocEditor : public QTextEdit +class GuiDocEditor : public QWidget { Q_OBJECT public: - GuiDocEditor(QWidget *parent=nullptr); ~GuiDocEditor() {}; +private: + GuiTextEdit *m_textArea; + GuiEditToolBar *m_editToolBar; + }; } // namespace Collett -#endif // GUIDOCEDITOR_H +#endif // GUI_DOCEDITOR_H diff --git a/src/editor/edittoolbar.cpp b/src/editor/edittoolbar.cpp new file mode 100644 index 0000000..738eae7 --- /dev/null +++ b/src/editor/edittoolbar.cpp @@ -0,0 +1,58 @@ +/* +** Collett – GUI Editor Tool Bar Class +** =================================== +** +** 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 "edittoolbar.h" +#include "icons.h" + +#include +#include +#include +#include +#include + +namespace Collett { + +GuiEditToolBar::GuiEditToolBar(QWidget *parent) + : QToolBar(parent) +{ + CollettIcons *icons = CollettIcons::instance(); + + this->setIconSize(QSize(20, 20)); + + m_formatBold = this->addAction(icons->icon("bold"), tr("Bold")); + m_formatItalic = this->addAction(icons->icon("italic"), tr("Italic")); + m_formatUnderline = this->addAction(icons->icon("underline"), tr("Underline")); + m_formatStrikethrough = this->addAction(icons->icon("strikethrough"), tr("Strikethrough")); + + this->addSeparator(); + + m_alignLeft = this->addAction(icons->icon("alignLeft"), tr("Align Left")); + m_alignCentre = this->addAction(icons->icon("alignCentre"), tr("Align Right")); + m_alignRight = this->addAction(icons->icon("alignRight"), tr("Align Centre")); + m_alignJustify = this->addAction(icons->icon("alignJustify"), tr("Align Justify")); + + this->addSeparator(); + + m_blockIndent = this->addAction(icons->icon("blockIndent"), tr("Indent Paragraph")); + m_blockOutdent = this->addAction(icons->icon("blockOutdent"), tr("Outdent Paragraph")); +} + +} // namespace Collett diff --git a/src/editor/edittoolbar.h b/src/editor/edittoolbar.h new file mode 100644 index 0000000..7cf535f --- /dev/null +++ b/src/editor/edittoolbar.h @@ -0,0 +1,56 @@ +/* +** Collett – GUI Editor Tool Bar Class +** =================================== +** +** 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 GUI_EDITTOOLBAR_H +#define GUI_EDITTOOLBAR_H + +#include +#include +#include + +namespace Collett { + +class GuiEditToolBar : public QToolBar +{ + Q_OBJECT + +public: + GuiEditToolBar(QWidget *parent=nullptr); + ~GuiEditToolBar() {}; + +private: + QAction *m_formatBold; + QAction *m_formatItalic; + QAction *m_formatUnderline; + QAction *m_formatStrikethrough; + + QAction *m_alignLeft; + QAction *m_alignCentre; + QAction *m_alignRight; + QAction *m_alignJustify; + + QAction *m_blockIndent; + QAction *m_blockOutdent; + +}; +} // namespace Collett + +#endif // GUI_EDITTOOLBAR_H diff --git a/src/editor/textedit.cpp b/src/editor/textedit.cpp new file mode 100644 index 0000000..d6d901b --- /dev/null +++ b/src/editor/textedit.cpp @@ -0,0 +1,34 @@ +/* +** Collett – GUI Text Editor Class +** =============================== +** +** 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 "textedit.h" + +#include +#include +#include + +namespace Collett { + +GuiTextEdit::GuiTextEdit(QWidget *parent) + : QTextEdit(parent) +{} + +} // namespace Collett diff --git a/src/editor/textedit.h b/src/editor/textedit.h new file mode 100644 index 0000000..3202613 --- /dev/null +++ b/src/editor/textedit.h @@ -0,0 +1,42 @@ +/* +** Collett – GUI Text Editor Class +** =============================== +** +** 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 GUI_TEXTEDIT_H +#define GUI_TEXTEDIT_H + +#include +#include +#include + +namespace Collett { + +class GuiTextEdit : public QTextEdit +{ + Q_OBJECT + +public: + GuiTextEdit(QWidget *parent=nullptr); + ~GuiTextEdit() {}; + +}; +} // namespace Collett + +#endif // GUI_TEXTEDIT_H diff --git a/src/guimain.cpp b/src/guimain.cpp index 5707de7..7998abf 100644 --- a/src/guimain.cpp +++ b/src/guimain.cpp @@ -52,7 +52,7 @@ GuiMain::GuiMain(QWidget *parent) : QMainWindow(parent) { // Assemble Main Window m_splitMain = new QSplitter(Qt::Horizontal, this); - m_splitMain->setContentsMargins(4, 4, 4, 4); + m_splitMain->setContentsMargins(0, 0, 0, 0); m_splitMain->setOpaqueResize(false); m_splitMain->addWidget(m_storyTree); m_splitMain->addWidget(m_docEditor); From 0f48ae5d597b1e3125cdac9f5029f2d770161393 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 19 Dec 2021 23:23:20 +0100 Subject: [PATCH 4/7] Replace full SVG data with only path data --- src/core/icons.cpp | 152 +++++++++++++++++++-------------------------- src/core/icons.h | 2 +- 2 files changed, 66 insertions(+), 88 deletions(-) diff --git a/src/core/icons.cpp b/src/core/icons.cpp index ff25e6d..148e06f 100644 --- a/src/core/icons.cpp +++ b/src/core/icons.cpp @@ -56,131 +56,106 @@ void CollettIcons::destroy() { CollettIcons::CollettIcons() { // format_align_center_black_24dp.svg - m_svgData["alignCentre"] = QLatin1String( - "" - "" - "" - "" + m_svgPath["alignCentre"] = QLatin1String( + "M7 15v2h10v-2H7zm-4 6h18v-2H3v2zm0-8h18v-2H3v2zm4-6v2h10V7H7zM3 3v2h18V3H3z" ); // format_align_justify_black_24dp.svg - m_svgData["alignJustify"] = QLatin1String( - "" - "" - "" - "" + m_svgPath["alignJustify"] = QLatin1String( + "M3 21h18v-2H3v2zm0-4h18v-2H3v2zm0-4h18v-2H3v2zm0-4h18V7H3v2zm0-6v2h18V3H3z" ); // format_align_left_black_24dp.svg - m_svgData["alignLeft"] = QLatin1String( - "" - "" - "" - "" + m_svgPath["alignLeft"] = QLatin1String( + "M15 15H3v2h12v-2zm0-8H3v2h12V7zM3 13h18v-2H3v2zm0 8h18v-2H3v2zM3 3v2h18V3H3z" ); // format_align_right_black_24dp.svg - m_svgData["alignRight"] = QLatin1String( - "" - "" - "" - "" + m_svgPath["alignRight"] = QLatin1String( + "M3 21h18v-2H3v2zm6-4h12v-2H9v2zm-6-4h18v-2H3v2zm6-4h12V7H9v2zM3 3v2h18V3H3z" ); // inventory_2_black_24dp.svg - m_svgData["archive"] = QLatin1String( - "" - "" - "" - "" + m_svgPath["archive"] = QLatin1String( + "M20,2H4C3,2,2,2.9,2,4v3.01C2,7.73,2.43,8.35,3,8.7V20c0,1.1,1.1,2,2,2h14c0.9,0,2-0.9,2-2V8" + ".7c0.57-0.35,1-0.97,1-1.69V4 C22,2.9,21,2,20,2z M15,14H9v-2h6V14z M20,7H4V4h16V7z" ); // format_bold_black_24dp.svg - m_svgData["bold"] = QLatin1String( - "" - "" - "" - "" + m_svgPath["bold"] = QLatin1String( + "M15.6 10.79c.97-.67 1.65-1.77 1.65-2.79 0-2.26-1.75-4-4-4H7v14h7.04c2.09 0 3.71-1.7 3.71-" + "3.79 0-1.52-.86-2.82-2.15-3.42zM10 6.5h3c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5h-3v-3zm3.5" + " 9H10v-3h3.5c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5z" ); // auto_stories_black_24dp.svg - m_svgData["book"] = QLatin1String( - "" - "" - "" - "" + m_svgPath["book"] = QLatin1String( + "M19 1l-5 5v11l5-4.5V1zM1 6v14.65c0 .25.25.5.5.5.1 0 .15-.05.25-.05C3.1 20.45 5.05 20 6.5 " + "20c1.95 0 4.05.4 5.5 1.5V6c-1.45-1.1-3.55-1.5-5.5-1.5S2.45 4.9 1 6zm22 13.5V6c-.6-.45-1.2" + "5-.75-2-1v13.5c-1.1-.35-2.3-.5-3.5-.5-1.7 0-4.15.65-5.5 1.5v2c1.35-.85 3.8-1.5 5.5-1.5 1." + "65 0 3.35.3 4.75 1.05.1.05.15.05.25.05.25 0 .5-.25.5-.5v-1.1z" ); // format_indent_increase_black_24dp.svg - m_svgData["blockIndent"] = QLatin1String( - "" - "" - "" - "" + m_svgPath["blockIndent"] = QLatin1String( + "M3 21h18v-2H3v2zM3 8v8l4-4-4-4zm8 9h10v-2H11v2zM3 3v2h18V3H3zm8 6h10V7H11v2zm0 4h10v-2H11" + "v2z" ); // format_indent_decrease_black_24dp.svg - m_svgData["blockOutdent"] = QLatin1String( - "" - "" - "" - "" + m_svgPath["blockOutdent"] = QLatin1String( + "M11 17h10v-2H11v2zm-8-5l4 4V8l-4 4zm0 9h18v-2H3v2zM3 3v2h18V3H3zm8 6h10V7H11v2zm0 4h10v-2" + "H11v2z" ); // format_italic_black_24dp.svg - m_svgData["italic"] = QLatin1String( - "" - "" - "" - "" + m_svgPath["italic"] = QLatin1String( + "M10 4v3h2.21l-3.42 8H6v3h8v-3h-2.21l3.42-8H18V4z" ); // more_vert_black_24dp.svg - m_svgData["more"] = QLatin1String( - "" - "" - "" - "" + m_svgPath["more"] = QLatin1String( + "M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-." + "9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z" ); // settings_black_24dp.svg - m_svgData["settings"] = QLatin1String( - "" - "" - "" - "" + m_svgPath["settings"] = QLatin1String( + "M19.5,12c0-0.23-0.01-0.45-0.03-0.68l1.86-1.41c0.4-0.3,0.51-0.86,0.26-1.3l-1.87-3.23c-0.25" + "-0.44-0.79-0.62-1.25-0.42 l-2.15,0.91c-0.37-0.26-0.76-0.49-1.17-0.68l-0.29-2.31C14.8,2.38" + ",14.37,2,13.87,2h-3.73C9.63,2,9.2,2.38,9.14,2.88L8.85,5.19 c-0.41,0.19-0.8,0.42-1.17,0.68" + "L5.53,4.96c-0.46-0.2-1-0.02-1.25,0.42L2.41,8.62c-0.25,0.44-0.14,0.99,0.26,1.3l1.86,1.41 C" + "4.51,11.55,4.5,11.77,4.5,12s0.01,0.45,0.03,0.68l-1.86,1.41c-0.4,0.3-0.51,0.86-0.26,1.3l1." + "87,3.23c0.25,0.44,0.79,0.62,1.25,0.42 l2.15-0.91c0.37,0.26,0.76,0.49,1.17,0.68l0.29,2.31C" + "9.2,21.62,9.63,22,10.13,22h3.73c0.5,0,0.93-0.38,0.99-0.88l0.29-2.31 c0.41-0.19,0.8-0.42,1" + ".17-0.68l2.15,0.91c0.46,0.2,1,0.02,1.25-0.42l1.87-3.23c0.25-0.44,0.14-0.99-0.26-1.3l-1.86" + "-1.41 C19.49,12.45,19.5,12.23,19.5,12z M12.04,15.5c-1.93,0-3.5-1.57-3.5-3.5s1.57-3.5,3.5-" + "3.5s3.5,1.57,3.5,3.5S13.97,15.5,12.04,15.5z" ); // format_strikethrough_black_24dp.svg - m_svgData["strikethrough"] = QLatin1String( - "" - "" - "" - "" + m_svgPath["strikethrough"] = QLatin1String( + "M10 19h4v-3h-4v3zM5 4v3h5v3h4V7h5V4H5zM3 14h18v-2H3v2z" + ); + + // subscript_black_24dp.svg + m_svgPath["subscript"] = QLatin1String( + "M22,18h-2v1h3v1h-4v-2c0-0.55,0.45-1,1-1h2v-1h-3v-1h3c0.55,0,1,0.45,1,1v1C23,17.55,22.55,1" + "8,22,18z M5.88,18h2.66 l3.4-5.42h0.12l3.4,5.42h2.66l-4.65-7.27L17.81,4h-2.68l-3.07,4.99h-" + "0.12L8.85,4H6.19l4.32,6.73L5.88,18z" + ); + + // superscript_black_24dp.svg + m_svgPath["superscript"] = QLatin1String( + "M22,7h-2v1h3v1h-4V7c0-0.55,0.45-1,1-1h2V5h-3V4h3c0.55,0,1,0.45,1,1v1C23,6.55,22.55,7,22,7" + "z M5.88,20h2.66l3.4-5.42h0.12 l3.4,5.42h2.66l-4.65-7.27L17.81,6h-2.68l-3.07,4.99h-0.12L8." + "85,6H6.19l4.32,6.73L5.88,20z" ); // format_underlined_black_24dp.svg - m_svgData["underline"] = QLatin1String( - "" - "" - "" - "" + m_svgPath["underline"] = QLatin1String( + "M12 17c3.31 0 6-2.69 6-6V3h-2.5v8c0 1.93-1.57 3.5-3.5 3.5S8.5 12.93 8.5 11V3H6v8c0 3.31 2" + ".69 6 6 6zm-7 2v2h14" ); } @@ -190,7 +165,10 @@ CollettIcons::~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.7"); + QString svg = QString( + "" + ).arg(col.name(QColor::HexRgb)).arg("0.7").arg(m_svgPath[name]); return QIcon(new SVGIconEngine(svg)); } diff --git a/src/core/icons.h b/src/core/icons.h index 5f372c6..274293d 100644 --- a/src/core/icons.h +++ b/src/core/icons.h @@ -46,7 +46,7 @@ class CollettIcons : public QObject private: static CollettIcons *staticInstance; - QHash m_svgData; + QHash m_svgPath; }; } // namespace Collett From c2353b376e5fe84dac45049450706786a98b5884 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Tue, 4 Jan 2022 00:02:51 +0100 Subject: [PATCH 5/7] Add signals and slots for the editor toolbar --- src/collett.h | 17 +++++++++++++++++ src/editor/doceditor.cpp | 4 ++++ src/editor/edittoolbar.cpp | 18 ++++++++++++++++++ src/editor/edittoolbar.h | 8 ++++++++ src/editor/textedit.cpp | 5 +++++ src/editor/textedit.h | 5 +++++ 6 files changed, 57 insertions(+) diff --git a/src/collett.h b/src/collett.h index 3a031ba..a4d032c 100644 --- a/src/collett.h +++ b/src/collett.h @@ -26,4 +26,21 @@ #define COL_VERSION_NUM 0x000001a0 #define COL_VERSION_DATE "2021-11-14" +namespace Collett { + +enum DocAction { + FormatBold, + FormatItalic, + FormatUnderline, + FormatStrikethrough, + TextAlignLeft, + TextAlignCentre, + TextAlignRight, + TextAlignJustify, + TextIndent, + TextOutdent, +}; + +} // namespace Collett + #endif // COLLETT_H diff --git a/src/editor/doceditor.cpp b/src/editor/doceditor.cpp index b73e880..31d6743 100644 --- a/src/editor/doceditor.cpp +++ b/src/editor/doceditor.cpp @@ -19,6 +19,7 @@ ** along with this program. If not, see . */ +#include "collett.h" #include "doceditor.h" #include "textedit.h" #include "edittoolbar.h" @@ -34,6 +35,7 @@ GuiDocEditor::GuiDocEditor(QWidget *parent) { m_textArea = new GuiTextEdit(this); m_editToolBar = new GuiEditToolBar(this); + connect(m_editToolBar, SIGNAL(documentAction(DocAction)), m_textArea, SLOT(applyDocAction(DocAction))); QVBoxLayout *outerBox = new QVBoxLayout; outerBox->addWidget(m_editToolBar); @@ -42,6 +44,8 @@ GuiDocEditor::GuiDocEditor(QWidget *parent) outerBox->setSpacing(0); this->setLayout(outerBox); + m_textArea->setHtml("Hello World"); + qDebug() << "QTextDocument:" << sizeof(m_textArea->document()); } } // namespace Collett diff --git a/src/editor/edittoolbar.cpp b/src/editor/edittoolbar.cpp index 738eae7..2cae9d0 100644 --- a/src/editor/edittoolbar.cpp +++ b/src/editor/edittoolbar.cpp @@ -19,6 +19,7 @@ ** along with this program. If not, see . */ +#include "collett.h" #include "edittoolbar.h" #include "icons.h" @@ -42,6 +43,11 @@ GuiEditToolBar::GuiEditToolBar(QWidget *parent) m_formatUnderline = this->addAction(icons->icon("underline"), tr("Underline")); m_formatStrikethrough = this->addAction(icons->icon("strikethrough"), tr("Strikethrough")); + connect(m_formatBold, &QAction::triggered, [this]{emitDocumentAction(DocAction::FormatBold);}); + connect(m_formatItalic, &QAction::triggered, [this]{emitDocumentAction(DocAction::FormatItalic);}); + connect(m_formatUnderline, &QAction::triggered, [this]{emitDocumentAction(DocAction::FormatUnderline);}); + connect(m_formatStrikethrough, &QAction::triggered, [this]{emitDocumentAction(DocAction::FormatStrikethrough);}); + this->addSeparator(); m_alignLeft = this->addAction(icons->icon("alignLeft"), tr("Align Left")); @@ -49,10 +55,22 @@ GuiEditToolBar::GuiEditToolBar(QWidget *parent) m_alignRight = this->addAction(icons->icon("alignRight"), tr("Align Centre")); m_alignJustify = this->addAction(icons->icon("alignJustify"), tr("Align Justify")); + connect(m_alignLeft, &QAction::triggered, [this]{emitDocumentAction(DocAction::TextAlignLeft);}); + connect(m_alignCentre, &QAction::triggered, [this]{emitDocumentAction(DocAction::TextAlignCentre);}); + connect(m_alignRight, &QAction::triggered, [this]{emitDocumentAction(DocAction::TextAlignRight);}); + connect(m_alignJustify, &QAction::triggered, [this]{emitDocumentAction(DocAction::TextAlignJustify);}); + this->addSeparator(); m_blockIndent = this->addAction(icons->icon("blockIndent"), tr("Indent Paragraph")); m_blockOutdent = this->addAction(icons->icon("blockOutdent"), tr("Outdent Paragraph")); + + connect(m_blockIndent, &QAction::triggered, [this]{emitDocumentAction(DocAction::TextIndent);}); + connect(m_blockOutdent, &QAction::triggered, [this]{emitDocumentAction(DocAction::TextOutdent);}); +} + +void GuiEditToolBar::emitDocumentAction(DocAction action) { + emit documentAction(action); } } // namespace Collett diff --git a/src/editor/edittoolbar.h b/src/editor/edittoolbar.h index 7cf535f..c326ce6 100644 --- a/src/editor/edittoolbar.h +++ b/src/editor/edittoolbar.h @@ -22,6 +22,8 @@ #ifndef GUI_EDITTOOLBAR_H #define GUI_EDITTOOLBAR_H +#include "collett.h" + #include #include #include @@ -36,6 +38,9 @@ class GuiEditToolBar : public QToolBar GuiEditToolBar(QWidget *parent=nullptr); ~GuiEditToolBar() {}; +signals: + void documentAction(DocAction action); + private: QAction *m_formatBold; QAction *m_formatItalic; @@ -50,6 +55,9 @@ class GuiEditToolBar : public QToolBar QAction *m_blockIndent; QAction *m_blockOutdent; +private slots: + void emitDocumentAction(DocAction action); + }; } // namespace Collett diff --git a/src/editor/textedit.cpp b/src/editor/textedit.cpp index d6d901b..f44fee4 100644 --- a/src/editor/textedit.cpp +++ b/src/editor/textedit.cpp @@ -19,6 +19,7 @@ ** along with this program. If not, see . */ +#include "collett.h" #include "textedit.h" #include @@ -31,4 +32,8 @@ GuiTextEdit::GuiTextEdit(QWidget *parent) : QTextEdit(parent) {} +void GuiTextEdit::applyDocAction(DocAction action) { + qDebug() << "DocAction:" << action; +} + } // namespace Collett diff --git a/src/editor/textedit.h b/src/editor/textedit.h index 3202613..fd6bb31 100644 --- a/src/editor/textedit.h +++ b/src/editor/textedit.h @@ -22,6 +22,8 @@ #ifndef GUI_TEXTEDIT_H #define GUI_TEXTEDIT_H +#include "collett.h" + #include #include #include @@ -36,6 +38,9 @@ class GuiTextEdit : public QTextEdit GuiTextEdit(QWidget *parent=nullptr); ~GuiTextEdit() {}; +public slots: + void applyDocAction(DocAction action); + }; } // namespace Collett From b57e3c470a4290dda7b5ef90cbcf58a287ef8642 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 23 Jan 2022 18:42:06 +0100 Subject: [PATCH 6/7] Update the copyright year to 2022 --- src/collett.h | 2 +- src/core/data.cpp | 2 +- src/core/data.h | 2 +- src/core/icons.cpp | 2 +- src/core/icons.h | 2 +- src/core/storage.cpp | 2 +- src/core/storage.h | 2 +- src/core/svgiconengine.cpp | 2 +- src/core/svgiconengine.h | 2 +- src/editor/doceditor.cpp | 2 +- src/editor/doceditor.h | 2 +- src/editor/edittoolbar.cpp | 2 +- src/editor/edittoolbar.h | 2 +- src/editor/textedit.cpp | 2 +- src/editor/textedit.h | 2 +- src/gui/maintoolbar.cpp | 2 +- src/gui/maintoolbar.h | 2 +- src/gui/statusbar.cpp | 2 +- src/gui/statusbar.h | 2 +- src/gui/storytree.cpp | 2 +- src/gui/storytree.h | 2 +- src/gui/storytreedelegate.cpp | 2 +- src/gui/storytreedelegate.h | 2 +- src/gui/treetoolbar.cpp | 2 +- src/gui/treetoolbar.h | 2 +- src/guimain.cpp | 2 +- src/guimain.h | 2 +- src/main.cpp | 2 +- src/project/project.cpp | 2 +- src/project/project.h | 2 +- src/project/storyitem.cpp | 2 +- src/project/storyitem.h | 2 +- src/project/storymodel.cpp | 2 +- src/project/storymodel.h | 2 +- src/settings.cpp | 2 +- src/settings.h | 2 +- 36 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/collett.h b/src/collett.h index a4d032c..4a22868 100644 --- a/src/collett.h +++ b/src/collett.h @@ -3,7 +3,7 @@ ** ============================= ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/core/data.cpp b/src/core/data.cpp index d878f45..aaade48 100644 --- a/src/core/data.cpp +++ b/src/core/data.cpp @@ -3,7 +3,7 @@ ** ========================= ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/core/data.h b/src/core/data.h index 1887359..e5d52b9 100644 --- a/src/core/data.h +++ b/src/core/data.h @@ -3,7 +3,7 @@ ** ========================= ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/core/icons.cpp b/src/core/icons.cpp index 148e06f..b3ad48c 100644 --- a/src/core/icons.cpp +++ b/src/core/icons.cpp @@ -3,7 +3,7 @@ ** ============================== ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/core/icons.h b/src/core/icons.h index 274293d..f389141 100644 --- a/src/core/icons.h +++ b/src/core/icons.h @@ -3,7 +3,7 @@ ** ============================== ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/core/storage.cpp b/src/core/storage.cpp index 0fe3439..2ef1d2f 100644 --- a/src/core/storage.cpp +++ b/src/core/storage.cpp @@ -3,7 +3,7 @@ ** ============================ ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/core/storage.h b/src/core/storage.h index 1613921..57cc20e 100644 --- a/src/core/storage.h +++ b/src/core/storage.h @@ -3,7 +3,7 @@ ** ============================ ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/core/svgiconengine.cpp b/src/core/svgiconengine.cpp index cee4e6c..1dd8ff8 100644 --- a/src/core/svgiconengine.cpp +++ b/src/core/svgiconengine.cpp @@ -3,7 +3,7 @@ ** ============================== ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/core/svgiconengine.h b/src/core/svgiconengine.h index 7eb9344..e1ddf82 100644 --- a/src/core/svgiconengine.h +++ b/src/core/svgiconengine.h @@ -3,7 +3,7 @@ ** ============================== ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/editor/doceditor.cpp b/src/editor/doceditor.cpp index 31d6743..2182afd 100644 --- a/src/editor/doceditor.cpp +++ b/src/editor/doceditor.cpp @@ -3,7 +3,7 @@ ** =================================== ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/editor/doceditor.h b/src/editor/doceditor.h index c8269a8..2d90830 100644 --- a/src/editor/doceditor.h +++ b/src/editor/doceditor.h @@ -3,7 +3,7 @@ ** =================================== ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/editor/edittoolbar.cpp b/src/editor/edittoolbar.cpp index 2cae9d0..e08755b 100644 --- a/src/editor/edittoolbar.cpp +++ b/src/editor/edittoolbar.cpp @@ -3,7 +3,7 @@ ** =================================== ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/editor/edittoolbar.h b/src/editor/edittoolbar.h index c326ce6..5c7d2cc 100644 --- a/src/editor/edittoolbar.h +++ b/src/editor/edittoolbar.h @@ -3,7 +3,7 @@ ** =================================== ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/editor/textedit.cpp b/src/editor/textedit.cpp index f44fee4..b942ce1 100644 --- a/src/editor/textedit.cpp +++ b/src/editor/textedit.cpp @@ -3,7 +3,7 @@ ** =============================== ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/editor/textedit.h b/src/editor/textedit.h index fd6bb31..302ebbd 100644 --- a/src/editor/textedit.h +++ b/src/editor/textedit.h @@ -3,7 +3,7 @@ ** =============================== ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/gui/maintoolbar.cpp b/src/gui/maintoolbar.cpp index acf59b1..2989a7d 100644 --- a/src/gui/maintoolbar.cpp +++ b/src/gui/maintoolbar.cpp @@ -3,7 +3,7 @@ ** ================================= ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/gui/maintoolbar.h b/src/gui/maintoolbar.h index 9d6fd03..40bdbd8 100644 --- a/src/gui/maintoolbar.h +++ b/src/gui/maintoolbar.h @@ -3,7 +3,7 @@ ** ================================= ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/gui/statusbar.cpp b/src/gui/statusbar.cpp index 9b7e6da..4794ba7 100644 --- a/src/gui/statusbar.cpp +++ b/src/gui/statusbar.cpp @@ -3,7 +3,7 @@ ** ============================= ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/gui/statusbar.h b/src/gui/statusbar.h index 07b6974..5edea5b 100644 --- a/src/gui/statusbar.h +++ b/src/gui/statusbar.h @@ -3,7 +3,7 @@ ** ============================= ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/gui/storytree.cpp b/src/gui/storytree.cpp index 3c4becb..3cdae87 100644 --- a/src/gui/storytree.cpp +++ b/src/gui/storytree.cpp @@ -3,7 +3,7 @@ ** ============================== ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/gui/storytree.h b/src/gui/storytree.h index c32268a..adebbe0 100644 --- a/src/gui/storytree.h +++ b/src/gui/storytree.h @@ -3,7 +3,7 @@ ** ============================== ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/gui/storytreedelegate.cpp b/src/gui/storytreedelegate.cpp index 7fd26da..45fb73f 100644 --- a/src/gui/storytreedelegate.cpp +++ b/src/gui/storytreedelegate.cpp @@ -3,7 +3,7 @@ ** ======================================= ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/gui/storytreedelegate.h b/src/gui/storytreedelegate.h index d0ca4fe..a28fb8e 100644 --- a/src/gui/storytreedelegate.h +++ b/src/gui/storytreedelegate.h @@ -3,7 +3,7 @@ ** ======================================= ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/gui/treetoolbar.cpp b/src/gui/treetoolbar.cpp index 1540d49..c97da39 100644 --- a/src/gui/treetoolbar.cpp +++ b/src/gui/treetoolbar.cpp @@ -3,7 +3,7 @@ ** ================================= ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/gui/treetoolbar.h b/src/gui/treetoolbar.h index dfffaa2..4310c2e 100644 --- a/src/gui/treetoolbar.h +++ b/src/gui/treetoolbar.h @@ -3,7 +3,7 @@ ** ================================= ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/guimain.cpp b/src/guimain.cpp index 7998abf..03d472d 100644 --- a/src/guimain.cpp +++ b/src/guimain.cpp @@ -3,7 +3,7 @@ ** ======================== ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/guimain.h b/src/guimain.h index 814138f..4b95ab9 100644 --- a/src/guimain.h +++ b/src/guimain.h @@ -3,7 +3,7 @@ ** ======================== ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/main.cpp b/src/main.cpp index 9771cdb..7372233 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,7 @@ ** ======================= ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/project/project.cpp b/src/project/project.cpp index 84e0012..50ef77b 100644 --- a/src/project/project.cpp +++ b/src/project/project.cpp @@ -3,7 +3,7 @@ ** ======================= ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/project/project.h b/src/project/project.h index 9bae56d..c9578d0 100644 --- a/src/project/project.h +++ b/src/project/project.h @@ -3,7 +3,7 @@ ** ======================= ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/project/storyitem.cpp b/src/project/storyitem.cpp index 7707fba..88b2d29 100644 --- a/src/project/storyitem.cpp +++ b/src/project/storyitem.cpp @@ -3,7 +3,7 @@ ** ================================== ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/project/storyitem.h b/src/project/storyitem.h index 4fa2cb6..8621b06 100644 --- a/src/project/storyitem.h +++ b/src/project/storyitem.h @@ -3,7 +3,7 @@ ** ================================== ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/project/storymodel.cpp b/src/project/storymodel.cpp index 6711d59..aa1a985 100644 --- a/src/project/storymodel.cpp +++ b/src/project/storymodel.cpp @@ -3,7 +3,7 @@ ** ============================= ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/project/storymodel.h b/src/project/storymodel.h index e485724..c6688f9 100644 --- a/src/project/storymodel.h +++ b/src/project/storymodel.h @@ -3,7 +3,7 @@ ** =================================== ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/settings.cpp b/src/settings.cpp index 717b1eb..78ee1ea 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -3,7 +3,7 @@ ** ============================= ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 diff --git a/src/settings.h b/src/settings.h index 6f452d1..8918d24 100644 --- a/src/settings.h +++ b/src/settings.h @@ -3,7 +3,7 @@ ** ============================= ** ** This file is a part of Collett -** Copyright 2020–2021, Veronica Berglyd Olsen +** Copyright 2020–2022, 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 From 0d9f10c62e664a0568d1537d677aa47c9db26080 Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sun, 23 Jan 2022 18:47:16 +0100 Subject: [PATCH 7/7] Connect the formatting buttons to the editor --- i18n/collett_en_US.ts | 36 +++++++++++++-------------- i18n/collett_nb_NO.ts | 36 +++++++++++++-------------- sample/project/project.json | 2 +- src/editor/textedit.cpp | 49 ++++++++++++++++++++++++++++++++++++- 4 files changed, 85 insertions(+), 38 deletions(-) diff --git a/i18n/collett_en_US.ts b/i18n/collett_en_US.ts index 619182a..580f23f 100644 --- a/i18n/collett_en_US.ts +++ b/i18n/collett_en_US.ts @@ -4,52 +4,52 @@ Collett::GuiEditToolBar - + Bold - + Italic - + Underline - + Strikethrough - + Align Left - + Align Right - + Align Centre - + Align Justify - + Indent Paragraph - + Outdent Paragraph @@ -186,7 +186,7 @@ Collett::Project - + Unnamed Project @@ -223,32 +223,32 @@ Collett::StoryItem - + Unnamed - + Book - + Partition - + Chapter - + Scene - + Page @@ -256,7 +256,7 @@ Collett::StoryModel - + New %1 diff --git a/i18n/collett_nb_NO.ts b/i18n/collett_nb_NO.ts index 80d6082..0e098e6 100644 --- a/i18n/collett_nb_NO.ts +++ b/i18n/collett_nb_NO.ts @@ -4,52 +4,52 @@ Collett::GuiEditToolBar - + Bold - + Italic - + Underline - + Strikethrough - + Align Left - + Align Right - + Align Centre - + Align Justify - + Indent Paragraph - + Outdent Paragraph @@ -186,7 +186,7 @@ Collett::Project - + Unnamed Project @@ -223,32 +223,32 @@ Collett::StoryItem - + Unnamed - + Book - + Partition - + Chapter - + Scene - + Page @@ -256,7 +256,7 @@ Collett::StoryModel - + New %1 diff --git a/sample/project/project.json b/sample/project/project.json index 4710472..4b474fb 100644 --- a/sample/project/project.json +++ b/sample/project/project.json @@ -1,7 +1,7 @@ { "c:meta": { "m:created": "2021-12-14T22:24:25", - "m:updated": "2022-01-23T17:54:31" + "m:updated": "2022-01-23T18:46:08" }, "c:project": { "u:project-name": "Sample Project" diff --git a/src/editor/textedit.cpp b/src/editor/textedit.cpp index b942ce1..ebd6a03 100644 --- a/src/editor/textedit.cpp +++ b/src/editor/textedit.cpp @@ -33,7 +33,54 @@ GuiTextEdit::GuiTextEdit(QWidget *parent) {} void GuiTextEdit::applyDocAction(DocAction action) { - qDebug() << "DocAction:" << action; + + if (action == Collett::FormatBold) { + if (fontWeight() > QFont::Medium) { + setFontWeight(QFont::Normal); + } else { + setFontWeight(QFont::Bold); + } + + } else if (action == Collett::FormatItalic) { + setFontItalic(!fontItalic()); + + } else if (action == Collett::FormatUnderline) { + setFontUnderline(!fontUnderline()); + + } else if (action == Collett::FormatStrikethrough) { + QFont font = currentFont(); + font.setStrikeOut(!font.strikeOut()); + setCurrentFont(font); + + } else if (action == Collett::TextAlignLeft) { + setAlignment(Qt::AlignLeft); + + } else if (action == Collett::TextAlignCentre) { + setAlignment(Qt::AlignHCenter); + + } else if (action == Collett::TextAlignRight) { + setAlignment(Qt::AlignRight); + + } else if (action == Collett::TextAlignJustify) { + setAlignment(Qt::AlignJustify); + + } else if (action == Collett::TextIndent) { + // Indenting is only allowed on text paragraphs (no heading level) that + // are also aligned to the leading edge. + QTextCursor cursor = textCursor(); + QTextBlockFormat format = cursor.blockFormat(); + if (format.headingLevel() == 0 && format.alignment() == Qt::AlignLeading) { + format.setTextIndent(8.0); + cursor.setBlockFormat(format); + } + + } else if (action == Collett::TextOutdent) { + // Text outdent is always allowed as there is no need to restrict it. + QTextCursor cursor = textCursor(); + QTextBlockFormat format = cursor.blockFormat(); + format.setTextIndent(0.0); + cursor.setBlockFormat(format); + } } } // namespace Collett