1 /*
2  note_edit_view.cpp     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 #include "note_edit_view.h"
20 
21 namespace m8r {
22 
23 using namespace std;
24 
NoteEditView(QWidget * parent)25 NoteEditView::NoteEditView(QWidget* parent)
26     : QWidget(parent)
27 {
28     // widgets
29     topNamePanel = new EditNamePanel{MfWidgetMode::NOTE_MODE, this};
30     noteEditor = new NoteEditorView{this};
31     bottomButtonsPanel = new EditButtonsPanel{MfWidgetMode::NOTE_MODE, this};
32 
33     // assembly
34     QVBoxLayout* layout = new QVBoxLayout{this};
35     // ensure that wont be extra space around member widgets
36     layout->setContentsMargins(QMargins(0,0,0,0));
37     layout->addWidget(topNamePanel);
38     layout->addWidget(noteEditor);
39     layout->addWidget(bottomButtonsPanel);
40     setLayout(layout);
41 
42     // signals
43 #ifdef __APPLE__
44     new QShortcut(
45         QKeySequence(Qt::CTRL+Qt::Key_L),
46         this, SLOT(slotSaveAndCloseEditor()));
47 #else
48     new QShortcut(
49         QKeySequence(Qt::ALT+Qt::Key_Left),
50         this, SLOT(slotSaveAndCloseEditor()));
51 #endif
52     new QShortcut(
53         QKeySequence(Qt::CTRL+Qt::Key_G),
54         this, SLOT(slotCloseEditor()));
55     new QShortcut(
56         QKeySequence(Qt::ALT+Qt::Key_Return),
57         this, SLOT(slotOpenNotePropertiesEditor()));
58     new QShortcut(
59         QKeySequence(Qt::CTRL+Qt::Key_S),
60         this, SLOT(slotSaveNote()));
61     QObject::connect(
62         bottomButtonsPanel->getRememberButton(), SIGNAL(clicked()),
63         this, SLOT(slotSaveAndCloseEditor()));
64     QObject::connect(
65         bottomButtonsPanel->getCancelButton(), SIGNAL(clicked()),
66         this, SLOT(slotCloseEditor()));
67 }
68 
~NoteEditView()69 NoteEditView::~NoteEditView()
70 {
71 }
72 
slotOpenNotePropertiesEditor()73 void NoteEditView::slotOpenNotePropertiesEditor()
74 {
75     bottomButtonsPanel->handleShowNoteEditDialog();
76 }
77 
slotSaveAndCloseEditor()78 void NoteEditView::slotSaveAndCloseEditor()
79 {
80     emit signalSaveAndCloseEditor();
81 }
82 
slotCloseEditor()83 void NoteEditView::slotCloseEditor()
84 {
85     emit signalCloseEditor();
86 }
87 
slotSaveNote()88 void NoteEditView::slotSaveNote()
89 {
90     emit signalSaveNote();
91 }
92 
93 } // m8r namespace
94