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 
85  INoteEditorBackend * backend();
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:
216  void contentChanged();
217 
223  void noteAndNotebookFoundInLocalStorage(Note note, Notebook notebook);
224 
229  void noteNotFound(QString noteLocalUid);
230 
236  void noteDeleted(QString noteLocalUid);
237 
243  void noteModified();
244 
249  void notifyError(ErrorString error);
250 
255  void inAppNoteLinkClicked(
256  QString userId, QString shardId, QString noteGuid);
257 
269  void inAppNoteLinkPasteRequested(
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 
296  void failedToSaveNoteToLocalStorage(
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:
324  void convertToNote();
325 
334  void saveNoteToLocalStorage();
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
Definition: INoteEditorBackend.h:41
The ErrorString class encapsulates two (or more) strings which are meant to contain translatable (bas...
Definition: ErrorString.h:43
Definition: LocalStorageManagerAsync.h:43
Definition: DecryptedTextManager.h:26
The Account class encapsulates some details about the account: its name, whether it is local or synch...
Definition: Account.h:38
Definition: Notebook.h:34
Definition: SpellChecker.h:35
Definition: Note.h:34
The NoteEditor class is a widget encapsulating all the functionality necessary for showing and editin...
Definition: NoteEditor.h:45