libquentier  0.5.0
The library for rich desktop clients of Evernote service
NoteEditor.h
1 /*
2  * Copyright 2016-2020 Dmitry Ivanov
3  *
4  * This file is part of libquentier
5  *
6  * libquentier is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, version 3 of the License.
9  *
10  * libquentier is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libquentier. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef LIB_QUENTIER_NOTE_EDITOR_NOTE_EDITOR_H
20 #define LIB_QUENTIER_NOTE_EDITOR_NOTE_EDITOR_H
21 
22 #include <quentier/types/ErrorString.h>
23 #include <quentier/types/Note.h>
24 #include <quentier/types/Notebook.h>
25 #include <quentier/utility/Linkage.h>
26 
27 #include <QPrinter>
28 #include <QStringList>
29 #include <QThread>
30 #include <QWidget>
31 
32 QT_FORWARD_DECLARE_CLASS(QUndoStack)
33 
34 namespace quentier {
35 
36 QT_FORWARD_DECLARE_CLASS(Account)
37 QT_FORWARD_DECLARE_CLASS(INoteEditorBackend)
38 QT_FORWARD_DECLARE_CLASS(LocalStorageManagerAsync)
39 QT_FORWARD_DECLARE_CLASS(SpellChecker)
40 
41 
45 class QUENTIER_EXPORT NoteEditor : public QWidget
46 {
47  Q_OBJECT
48 public:
49  explicit NoteEditor(
50  QWidget * parent = nullptr,
51 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
52  Qt::WindowFlags flags = {});
53 #else
54  Qt::WindowFlags flags = 0);
55 #endif
56 
57  virtual ~NoteEditor() override;
58 
77  void initialize(
78  LocalStorageManagerAsync & localStorageManager,
79  SpellChecker & spellChecker, const Account & account,
80  QThread * pBackgroundJobsThread = nullptr);
81 
86 
92  void setBackend(INoteEditorBackend * backend);
93 
97  void setAccount(const Account & account);
98 
102  const QUndoStack * undoStack() const;
103 
107  void setUndoStack(QUndoStack * pUndoStack);
108 
112  void setInitialPageHtml(const QString & html);
113 
118  void setNoteNotFoundPageHtml(const QString & html);
119 
125  void setNoteDeletedPageHtml(const QString & html);
126 
131  void setNoteLoadingPageHtml(const QString & html);
132 
136  QString currentNoteLocalUid() const;
137 
145  void setCurrentNoteLocalUid(const QString & noteLocalUid);
146 
150  void clear();
151 
156  bool isModified() const;
157 
162  bool isEditorPageModified() const;
163 
168  bool isNoteLoaded() const;
169 
175  qint64 idleTime() const;
176 
180  void setFocus();
181 
182  QString selectedText() const;
183  bool hasSelection() const;
184 
185  bool spellCheckEnabled() const;
186 
187  bool print(QPrinter & printer, ErrorString & errorDescription);
188 
189  bool exportToPdf(
190  const QString & absoluteFilePath, ErrorString & errorDescription);
191 
192  bool exportToEnex(
193  const QStringList & tagNames, QString & enex,
194  ErrorString & errorDescription);
195 
203  QPalette defaultPalette() const;
204 
209  const QFont * defaultFont() const;
210 
211 Q_SIGNALS:
217 
224 
229  void noteNotFound(QString noteLocalUid);
230 
236  void noteDeleted(QString noteLocalUid);
237 
243  void noteModified();
244 
250 
256  QString userId, QString shardId, QString noteGuid);
257 
270  QString url, QString userId, QString shardId, QString noteGuid);
271 
272  void convertedToNote(Note note);
273  void cantConvertToNote(ErrorString error);
274 
275  void noteEditorHtmlUpdated(QString html);
276 
277  void currentNoteChanged(Note note);
278 
279  void spellCheckerNotReady();
280  void spellCheckerReady();
281 
282  void noteLoaded();
283 
290  void noteSavedToLocalStorage(QString noteLocalUid);
291 
297  ErrorString errorDescription, QString noteLocalUid);
298 
299  // Signals to notify anyone interested of the formatting at the current
300  // cursor position
301  void textBoldState(bool state);
302  void textItalicState(bool state);
303  void textUnderlineState(bool state);
304  void textStrikethroughState(bool state);
305  void textAlignLeftState(bool state);
306  void textAlignCenterState(bool state);
307  void textAlignRightState(bool state);
308  void textAlignFullState(bool state);
309  void textInsideOrderedListState(bool state);
310  void textInsideUnorderedListState(bool state);
311  void textInsideTableState(bool state);
312 
313  void textFontFamilyChanged(QString fontFamily);
314  void textFontSizeChanged(int fontSize);
315 
316  void insertTableDialogRequested();
317 
318 public Q_SLOTS:
325 
335 
345  void setNoteTitle(const QString & noteTitle);
346 
358  void setTagIds(
359  const QStringList & tagLocalUids, const QStringList & tagGuids);
360 
361  void undo();
362  void redo();
363  void cut();
364  void copy();
365  void paste();
366  void pasteUnformatted();
367  void selectAll();
368 
369  void formatSelectionAsSourceCode();
370 
371  void fontMenu();
372  void textBold();
373  void textItalic();
374  void textUnderline();
375  void textStrikethrough();
376  void textHighlight();
377 
378  void alignLeft();
379  void alignCenter();
380  void alignRight();
381  void alignFull();
382 
383  void findNext(const QString & text, const bool matchCase) const;
384  void findPrevious(const QString & text, const bool matchCase) const;
385 
386  void replace(
387  const QString & textToReplace, const QString & replacementText,
388  const bool matchCase);
389 
390  void replaceAll(
391  const QString & textToReplace, const QString & replacementText,
392  const bool matchCase);
393 
394  void insertToDoCheckbox();
395 
396  void insertInAppNoteLink(
397  const QString & userId, const QString & shardId,
398  const QString & noteGuid, const QString & linkText);
399 
400  void setSpellcheck(const bool enabled);
401 
402  void setFont(const QFont & font);
403  void setFontHeight(const int height);
404  void setFontColor(const QColor & color);
405  void setBackgroundColor(const QColor & color);
406 
422  void setDefaultPalette(const QPalette & pal);
423 
429  void setDefaultFont(const QFont & font);
430 
431  void insertHorizontalLine();
432 
433  void increaseFontSize();
434  void decreaseFontSize();
435 
436  void increaseIndentation();
437  void decreaseIndentation();
438 
439  void insertBulletedList();
440  void insertNumberedList();
441 
442  void insertTableDialog();
443 
444  void insertFixedWidthTable(
445  const int rows, const int columns, const int widthInPixels);
446 
447  void insertRelativeWidthTable(
448  const int rows, const int columns, const double relativeWidth);
449 
450  void insertTableRow();
451  void insertTableColumn();
452  void removeTableRow();
453  void removeTableColumn();
454 
455  void addAttachmentDialog();
456  void saveAttachmentDialog(const QByteArray & resourceHash);
457  void saveAttachmentUnderCursor();
458  void openAttachment(const QByteArray & resourceHash);
459  void openAttachmentUnderCursor();
460  void copyAttachment(const QByteArray & resourceHash);
461  void copyAttachmentUnderCursor();
462 
463  void encryptSelectedText();
464  void decryptEncryptedTextUnderCursor();
465 
466  void editHyperlinkDialog();
467  void copyHyperlink();
468  void removeHyperlink();
469 
470  void onNoteLoadCancelled();
471 
472 protected:
473  virtual void dragMoveEvent(QDragMoveEvent * pEvent) override;
474  virtual void dropEvent(QDropEvent * pEvent) override;
475 
476 private:
477  INoteEditorBackend * m_backend;
478 };
479 
480 } // namespace quentier
481 
482 #endif // LIB_QUENTIER_NOTE_EDITOR_NOTE_EDITOR_H
quentier::Account
The Account class encapsulates some details about the account: its name, whether it is local or synch...
Definition: Account.h:39
quentier::NoteEditor::defaultFont
const QFont * defaultFont() const
quentier::NoteEditor::initialize
void initialize(LocalStorageManagerAsync &localStorageManager, SpellChecker &spellChecker, const Account &account, QThread *pBackgroundJobsThread=nullptr)
quentier::NoteEditor::noteModified
void noteModified()
noteModified signal is emitted when the note's content within the editor gets modified via some way -...
quentier::INoteEditorBackend
Definition: INoteEditorBackend.h:42
quentier::NoteEditor::inAppNoteLinkPasteRequested
void inAppNoteLinkPasteRequested(QString url, QString userId, QString shardId, QString noteGuid)
quentier::NoteEditor::backend
INoteEditorBackend * backend()
quentier::NoteEditor::setBackend
void setBackend(INoteEditorBackend *backend)
quentier::NoteEditor::setInitialPageHtml
void setInitialPageHtml(const QString &html)
quentier::NoteEditor::contentChanged
void contentChanged()
contentChanged signal is emitted when the note's content (text) gets modified via manual editing (i....
quentier::ErrorString
The ErrorString class encapsulates two (or more) strings which are meant to contain translatable (bas...
Definition: ErrorString.h:44
quentier::NoteEditor::setNoteLoadingPageHtml
void setNoteLoadingPageHtml(const QString &html)
quentier::NoteEditor::defaultPalette
QPalette defaultPalette() const
quentier::NoteEditor::noteAndNotebookFoundInLocalStorage
void noteAndNotebookFoundInLocalStorage(Note note, Notebook notebook)
noteAndNotebookFoundInLocalStorage signal is emitted when note and its corresponding notebook were fo...
quentier::SpellChecker
Definition: SpellChecker.h:36
quentier::NoteEditor::setCurrentNoteLocalUid
void setCurrentNoteLocalUid(const QString &noteLocalUid)
quentier::Notebook
Definition: Notebook.h:35
quentier::NoteEditor::setFocus
void setFocus()
quentier::NoteEditor::isModified
bool isModified() const
quentier::NoteEditor::setNoteTitle
void setNoteTitle(const QString &noteTitle)
quentier::NoteEditor::failedToSaveNoteToLocalStorage
void failedToSaveNoteToLocalStorage(ErrorString errorDescription, QString noteLocalUid)
failedToSaveNoteToLocalStorage signal is emitted in case of failure to save the note to local storage
quentier::NoteEditor::notifyError
void notifyError(ErrorString error)
notifyError signal is emitted when NoteEditor encounters some problem worth letting the user to know ...
quentier::NoteEditor::setDefaultFont
void setDefaultFont(const QFont &font)
quentier::NoteEditor::noteDeleted
void noteDeleted(QString noteLocalUid)
noteDeleted signal is emitted when the note displayed within the note editor is deleted....
quentier::NoteEditor::setNoteNotFoundPageHtml
void setNoteNotFoundPageHtml(const QString &html)
quentier::NoteEditor::noteNotFound
void noteNotFound(QString noteLocalUid)
noteNotFound signal is emitted when the note could not be found within the local storage by the provi...
quentier::NoteEditor
The NoteEditor class is a widget encapsulating all the functionality necessary for showing and editin...
Definition: NoteEditor.h:46
quentier::NoteEditor::isNoteLoaded
bool isNoteLoaded() const
quentier::NoteEditor::setDefaultPalette
void setDefaultPalette(const QPalette &pal)
quentier::NoteEditor::isEditorPageModified
bool isEditorPageModified() const
quentier::NoteEditor::idleTime
qint64 idleTime() const
quentier::Note
Definition: Note.h:35
quentier::NoteEditor::setAccount
void setAccount(const Account &account)
quentier::NoteEditor::clear
void clear()
quentier::NoteEditor::setNoteDeletedPageHtml
void setNoteDeletedPageHtml(const QString &html)
quentier::NoteEditor::currentNoteLocalUid
QString currentNoteLocalUid() const
quentier::NoteEditor::setUndoStack
void setUndoStack(QUndoStack *pUndoStack)
quentier::NoteEditor::undoStack
const QUndoStack * undoStack() const
quentier::NoteEditor::setTagIds
void setTagIds(const QStringList &tagLocalUids, const QStringList &tagGuids)
quentier::NoteEditor::saveNoteToLocalStorage
void saveNoteToLocalStorage()
quentier::NoteEditor::noteSavedToLocalStorage
void noteSavedToLocalStorage(QString noteLocalUid)
noteSavedToLocalStorage signal is emitted when the note has been saved within the local storage....
quentier::LocalStorageManagerAsync
Definition: LocalStorageManagerAsync.h:44
quentier::NoteEditor::inAppNoteLinkClicked
void inAppNoteLinkClicked(QString userId, QString shardId, QString noteGuid)
inAppNoteLinkClicked signal is emitted when the in-app note link is clicked within the note editor
quentier::NoteEditor::convertToNote
void convertToNote()