1 /*
2  outline_header_edit_view.h     MindForger thinking notebook
3 
4  Copyright (C) 2016-2020 Martin Dvorak <martin.dvorak@mindforger.com>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License
8  as published by the Free Software Foundation; either version 2
9  of the License, or (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #ifndef M8RUI_OUTLINE_HEADER_EDIT_VIEW_H
20 #define M8RUI_OUTLINE_HEADER_EDIT_VIEW_H
21 
22 #include <QtWidgets>
23 
24 #include "../../lib/src/model/outline.h"
25 
26 #include "note_editor_view.h"
27 #include "widgets/edit_name_panel.h"
28 #include "widgets/edit_buttons_panel.h"
29 
30 namespace m8r {
31 
32 class OutlineHeaderEditView : public QWidget
33 {
34     Q_OBJECT
35 
36 private:
37     Outline* currentOutline;
38 
39     EditNamePanel* topNamePanel;
40     NoteEditorView* noteEditor;
41     EditButtonsPanel* bottomButtonsPanel;
42 
43 public:
44     explicit OutlineHeaderEditView(QWidget* parent);
45     OutlineHeaderEditView(const OutlineHeaderEditView&) = delete;
46     OutlineHeaderEditView(const OutlineHeaderEditView&&) = delete;
47     OutlineHeaderEditView &operator=(const OutlineHeaderEditView&) = delete;
48     OutlineHeaderEditView &operator=(const OutlineHeaderEditView&&) = delete;
49     ~OutlineHeaderEditView();
50 
setOutlineHeaderEditDialog(OutlineHeaderEditDialog * outlineHeaderEditDialog)51     void setOutlineHeaderEditDialog(OutlineHeaderEditDialog* outlineHeaderEditDialog) {
52         bottomButtonsPanel->setOutlineHeaderEditDialog(outlineHeaderEditDialog);
53     }
setOutline(Outline * outline,std::string mdDescription)54     void setOutline(Outline* outline, std::string mdDescription) {
55         currentOutline = outline;
56         topNamePanel->setOutline(outline);
57         bottomButtonsPanel->setOutline(outline);
58         noteEditor->setPlainText(QString::fromStdString(mdDescription));
59     }
setEditorShowLineNumbers(bool show)60     void setEditorShowLineNumbers(bool show) { noteEditor->setShowLineNumbers(show); }
setStatusBar(const StatusBarView * statusBar)61     void setStatusBar(const StatusBarView* statusBar) { noteEditor->setStatusBar(statusBar); }
62 
focusName()63     void focusName() { topNamePanel->focusName(); }
getName()64     QString getName() const { return topNamePanel->getName(); }
getDescription()65     QString getDescription() const { return noteEditor->toPlainText(); }
isDescriptionEmpty()66     bool isDescriptionEmpty() const { return noteEditor->toPlainText().isEmpty(); }
getSelectedText()67     QString getSelectedText() const { return noteEditor->getSelectedText(); }
getHeaderEditor()68     NoteEditorView* getHeaderEditor() const { return noteEditor; }
getButtonsPanel()69     EditButtonsPanel* getButtonsPanel() const { return bottomButtonsPanel; }
70 
giveEditorFocus()71     void giveEditorFocus() { noteEditor->setFocus(); }
72 
73 private slots:
74     void slotOpenOutlineHeaderPropertiesEditor();
75     void slotSaveOutlineHeader();
76     void slotCloseEditor();
77     void slotSaveAndCloseEditor();
78 
79 signals:
80     void signalSaveAndCloseEditor();
81     void signalCloseEditor();
82     void signalSaveOutlineHeader();
83 };
84 
85 }
86 #endif // M8RUI_OUTLINE_HEADER_EDIT_VIEW_H
87