From 491b96c0528159f0830e439f5c5a55e3ff09ad1a Mon Sep 17 00:00:00 2001
From: isanae <14251494+isanae@users.noreply.github.com>
Date: Mon, 17 Jun 2019 03:06:31 -0400
Subject: made TextEditorToolbar a widget added save and word wrap icons
---
src/resources/save.svg | 1 +
src/resources/word-wrap.svg | 1 +
src/texteditor.cpp | 17 ++++++-----------
src/texteditor.h | 7 ++-----
4 files changed, 10 insertions(+), 16 deletions(-)
create mode 100644 src/resources/save.svg
create mode 100644 src/resources/word-wrap.svg
(limited to 'src')
diff --git a/src/resources/save.svg b/src/resources/save.svg
new file mode 100644
index 00000000..3fb2a8df
--- /dev/null
+++ b/src/resources/save.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/src/resources/word-wrap.svg b/src/resources/word-wrap.svg
new file mode 100644
index 00000000..63b1f1f0
--- /dev/null
+++ b/src/resources/word-wrap.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/src/texteditor.cpp b/src/texteditor.cpp
index ccafb37a..78ce1610 100644
--- a/src/texteditor.cpp
+++ b/src/texteditor.cpp
@@ -4,9 +4,10 @@
TextEditor::TextEditor(QWidget* parent) :
QPlainTextEdit(parent),
- m_toolbar(*this), m_lineNumbers(nullptr), m_highlighter(nullptr),
+ m_toolbar(nullptr), m_lineNumbers(nullptr), m_highlighter(nullptr),
m_dirty(false)
{
+ m_toolbar = new TextEditorToolbar(*this);
m_lineNumbers = new TextEditorLineNumbers(*this);
m_highlighter = new TextEditorHighlighter(document());
@@ -177,7 +178,7 @@ void TextEditor::setupToolbar()
auto* layout = new QVBoxLayout(widget);
// adding toolbar and edit
- layout->addWidget(m_toolbar.widget());
+ layout->addWidget(m_toolbar);
layout->addWidget(this);
// make the edit stretch
@@ -414,16 +415,15 @@ void TextEditorLineNumbers::updateArea(const QRect &rect, int dy)
TextEditorToolbar::TextEditorToolbar(TextEditor& editor) :
m_editor(editor),
- m_widget(new QWidget),
- m_save(new QAction(QObject::tr("&Save"))),
- m_wordWrap(new QAction(QObject::tr("&Word wrap")))
+ m_save(new QAction(QIcon(":/MO/gui/save"), QObject::tr("&Save"))),
+ m_wordWrap(new QAction(QIcon(":/MO/gui/word-wrap"), QObject::tr("&Word wrap")))
{
QObject::connect(m_save, &QAction::triggered, [&]{ m_editor.save(); });
m_wordWrap->setCheckable(true);
QObject::connect(m_wordWrap, &QAction::triggered, [&]{ m_editor.toggleWordWrap(); });
- auto* layout = new QHBoxLayout(m_widget);
+ auto* layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setAlignment(Qt::AlignLeft);
@@ -439,11 +439,6 @@ TextEditorToolbar::TextEditorToolbar(TextEditor& editor) :
QObject::connect(&m_editor, &TextEditor::wordWrapChanged, [&](bool b){ onWordWrap(b); });
}
-QWidget* TextEditorToolbar::widget()
-{
- return m_widget;
-}
-
void TextEditorToolbar::onTextModified(bool b)
{
m_save->setEnabled(b);
diff --git a/src/texteditor.h b/src/texteditor.h
index 0f7447ff..eef5ca52 100644
--- a/src/texteditor.h
+++ b/src/texteditor.h
@@ -5,18 +5,15 @@
class TextEditor;
-class TextEditorToolbar : public QObject
+class TextEditorToolbar : public QFrame
{
Q_OBJECT;
public:
TextEditorToolbar(TextEditor& editor);
- QWidget* widget();
-
private:
TextEditor& m_editor;
- QWidget* m_widget;
QAction* m_save;
QAction* m_wordWrap;
@@ -122,7 +119,7 @@ protected:
void resizeEvent(QResizeEvent* e) override;
private:
- TextEditorToolbar m_toolbar;
+ TextEditorToolbar* m_toolbar;
TextEditorLineNumbers* m_lineNumbers;
TextEditorHighlighter* m_highlighter;
QColor m_highlightBackground;
--
cgit v1.3.1