1 /*
2  note_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 M8R_NOTE_EDIT_VIEW_H
20 #define M8R_NOTE_EDIT_VIEW_H
21 
22 #include <QtWidgets>
23 
24 #include "../../lib/src/model/note.h"
25 
26 #include "note_editor_view.h"
27 #include "widgets/edit_name_panel.h"
28 #include "widgets/edit_buttons_panel.h"
29 #include "status_bar_view.h"
30 
31 namespace m8r {
32 
33 class NoteEditView : public QWidget
34 {
35     Q_OBJECT
36 
37 private:
38     Note* currentNote;
39 
40     EditNamePanel* topNamePanel;
41     NoteEditorView* noteEditor;
42     EditButtonsPanel* bottomButtonsPanel;
43 
44 public:
45     explicit NoteEditView(QWidget* parent);
46     NoteEditView(const NoteEditView&) = delete;
47     NoteEditView(const NoteEditView&&) = delete;
48     NoteEditView &operator=(const NoteEditView&) = delete;
49     NoteEditView &operator=(const NoteEditView&&) = delete;
50     ~NoteEditView();
51 
setNoteEditDialog(NoteEditDialog * noteEditDialog)52     void setNoteEditDialog(NoteEditDialog* noteEditDialog) {
53         bottomButtonsPanel->setNoteEditDialog(noteEditDialog);
54     }
setNote(Note * note,std::string mdDescription)55     void setNote(Note* note, std::string mdDescription) {
56         currentNote = note;
57         topNamePanel->setNote(note);
58         bottomButtonsPanel->setNote(note);
59         noteEditor->setPlainText(QString::fromStdString(mdDescription));
60     }
setEditorShowLineNumbers(bool show)61     void setEditorShowLineNumbers(bool show) { noteEditor->setShowLineNumbers(show); }
setStatusBar(const StatusBarView * statusBar)62     void setStatusBar(const StatusBarView* statusBar) { noteEditor->setStatusBar(statusBar); }
63 
focusName()64     void focusName() const { topNamePanel->focusName(); }
getName()65     QString getName() const { return topNamePanel->getName(); }
getDescription()66     QString getDescription() const { return noteEditor->toPlainText(); }
isDescriptionEmpty()67     bool isDescriptionEmpty() const { return noteEditor->toPlainText().isEmpty(); }
getSelectedText()68     QString getSelectedText() const { return noteEditor->getSelectedText(); }
getNoteEditor()69     NoteEditorView* getNoteEditor() const { return noteEditor; }
getButtonsPanel()70     EditButtonsPanel* getButtonsPanel() const { return bottomButtonsPanel; }
71 
giveEditorFocus()72     void giveEditorFocus() { noteEditor->setFocus(); }
73 
74 private slots:
75     void slotOpenNotePropertiesEditor();
76     void slotSaveNote();
77     void slotCloseEditor();
78     void slotSaveAndCloseEditor();
79 
80 signals:
81     void signalSaveAndCloseEditor();
82     void signalCloseEditor();
83     void signalSaveNote();
84 };
85 
86 }
87 #endif // M8R_NOTE_EDIT_VIEW_H
88