diff options
| -rw-r--r-- | src/resources/save.svg | 1 | ||||
| -rw-r--r-- | src/resources/word-wrap.svg | 1 | ||||
| -rw-r--r-- | src/texteditor.cpp | 17 | ||||
| -rw-r--r-- | src/texteditor.h | 7 |
4 files changed, 10 insertions, 16 deletions
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 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M0 0h24v24H0z" fill="none"/><path d="M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7l-4-4zm-5 16c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm3-10H5V5h10v4z"/></svg>
\ 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 @@ +<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M4 19h6v-2H4v2zM20 5H4v2h16V5zm-3 6H4v2h13.25c1.1 0 2 .9 2 2s-.9 2-2 2H15v-2l-3 3 3 3v-2h2c2.21 0 4-1.79 4-4s-1.79-4-4-4z"/><path d="M0 0h24v24H0z" fill="none"/></svg>
\ 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; |
