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 #include <quentier/utility/Macros.h>
27 
28 #include <QPrinter>
29 #include <QStringList>
30 #include <QThread>
31 #include <QWidget>
32 
33 QT_FORWARD_DECLARE_CLASS(QUndoStack)
34 
35 namespace quentier {
36 
37 QT_FORWARD_DECLARE_CLASS(Account)
38 QT_FORWARD_DECLARE_CLASS(INoteEditorBackend)
39 QT_FORWARD_DECLARE_CLASS(LocalStorageManagerAsync)
40 QT_FORWARD_DECLARE_CLASS(SpellChecker)
41 
42 
46 class QUENTIER_EXPORT NoteEditor: public QWidget
47 {
48  Q_OBJECT
49 public:
50  explicit NoteEditor(QWidget * parent = nullptr, Qt::WindowFlags flags = 0);
51  virtual ~NoteEditor() override;
52 
71  void initialize(
72  LocalStorageManagerAsync & localStorageManager,
73  SpellChecker & spellChecker, const Account & account,
74  QThread * pBackgroundJobsThread = nullptr);
75 
79  INoteEditorBackend * backend();
80 
86  void setBackend(INoteEditorBackend * backend);
87 
91  void setAccount(const Account & account);
92 
96  const QUndoStack * undoStack() const;
97 
101  void setUndoStack(QUndoStack * pUndoStack);
102 
106  void setInitialPageHtml(const QString & html);
107 
112  void setNoteNotFoundPageHtml(const QString & html);
113 
119  void setNoteDeletedPageHtml(const QString & html);
120 
125  void setNoteLoadingPageHtml(const QString & html);
126 
130  QString currentNoteLocalUid() const;
131 
139  void setCurrentNoteLocalUid(const QString & noteLocalUid);
140 
144  void clear();
145 
150  bool isModified() const;
151 
156  bool isEditorPageModified() const;
157 
162  bool isNoteLoaded() const;
163 
169  qint64 idleTime() const;
170 
174  void setFocus();
175 
176  QString selectedText() const;
177  bool hasSelection() const;
178 
179  bool spellCheckEnabled() const;
180 
181  bool print(QPrinter & printer, ErrorString & errorDescription);
182 
183  bool exportToPdf(
184  const QString & absoluteFilePath, ErrorString & errorDescription);
185 
186  bool exportToEnex(
187  const QStringList & tagNames, QString & enex,
188  ErrorString & errorDescription);
189 
197  QPalette defaultPalette() const;
198 
203  const QFont * defaultFont() const;
204 
205 Q_SIGNALS:
210  void contentChanged();
211 
217  void noteAndNotebookFoundInLocalStorage(Note note, Notebook notebook);
218 
223  void noteNotFound(QString noteLocalUid);
224 
230  void noteDeleted(QString noteLocalUid);
231 
237  void noteModified();
238 
243  void notifyError(ErrorString error);
244 
249  void inAppNoteLinkClicked(QString userId, QString shardId, QString noteGuid);
250 
262  void inAppNoteLinkPasteRequested(
263  QString url, QString userId, QString shardId, QString noteGuid);
264 
265  void convertedToNote(Note note);
266  void cantConvertToNote(ErrorString error);
267 
268  void noteEditorHtmlUpdated(QString html);
269 
270  void currentNoteChanged(Note note);
271 
272  void spellCheckerNotReady();
273  void spellCheckerReady();
274 
275  void noteLoaded();
276 
283  void noteSavedToLocalStorage(QString noteLocalUid);
284 
289  void failedToSaveNoteToLocalStorage(
290  ErrorString errorDescription, QString noteLocalUid);
291 
292  // Signals to notify anyone interested of the formatting at the current
293  // cursor position
294  void textBoldState(bool state);
295  void textItalicState(bool state);
296  void textUnderlineState(bool state);
297  void textStrikethroughState(bool state);
298  void textAlignLeftState(bool state);
299  void textAlignCenterState(bool state);
300  void textAlignRightState(bool state);
301  void textAlignFullState(bool state);
302  void textInsideOrderedListState(bool state);
303  void textInsideUnorderedListState(bool state);
304  void textInsideTableState(bool state);
305 
306  void textFontFamilyChanged(QString fontFamily);
307  void textFontSizeChanged(int fontSize);
308 
309  void insertTableDialogRequested();
310 
311 public Q_SLOTS:
317  void convertToNote();
318 
327  void saveNoteToLocalStorage();
328 
338  void setNoteTitle(const QString & noteTitle);
339 
351  void setTagIds(
352  const QStringList & tagLocalUids, const QStringList & tagGuids);
353 
354  void undo();
355  void redo();
356  void cut();
357  void copy();
358  void paste();
359  void pasteUnformatted();
360  void selectAll();
361 
362  void formatSelectionAsSourceCode();
363 
364  void fontMenu();
365  void textBold();
366  void textItalic();
367  void textUnderline();
368  void textStrikethrough();
369  void textHighlight();
370 
371  void alignLeft();
372  void alignCenter();
373  void alignRight();
374  void alignFull();
375 
376  void findNext(const QString & text, const bool matchCase) const;
377  void findPrevious(const QString & text, const bool matchCase) const;
378 
379  void replace(
380  const QString & textToReplace, const QString & replacementText,
381  const bool matchCase);
382 
383  void replaceAll(
384  const QString & textToReplace, const QString & replacementText,
385  const bool matchCase);
386 
387  void insertToDoCheckbox();
388 
389  void insertInAppNoteLink(
390  const QString & userId, const QString & shardId,
391  const QString & noteGuid, const QString & linkText);
392 
393  void setSpellcheck(const bool enabled);
394 
395  void setFont(const QFont & font);
396  void setFontHeight(const int height);
397  void setFontColor(const QColor & color);
398  void setBackgroundColor(const QColor & color);
399 
415  void setDefaultPalette(const QPalette & pal);
416 
422  void setDefaultFont(const QFont & font);
423 
424  void insertHorizontalLine();
425 
426  void increaseFontSize();
427  void decreaseFontSize();
428 
429  void increaseIndentation();
430  void decreaseIndentation();
431 
432  void insertBulletedList();
433  void insertNumberedList();
434 
435  void insertTableDialog();
436 
437  void insertFixedWidthTable(
438  const int rows, const int columns, const int widthInPixels);
439 
440  void insertRelativeWidthTable(
441  const int rows, const int columns, const double relativeWidth);
442 
443  void insertTableRow();
444  void insertTableColumn();
445  void removeTableRow();
446  void removeTableColumn();
447 
448  void addAttachmentDialog();
449  void saveAttachmentDialog(const QByteArray & resourceHash);
450  void saveAttachmentUnderCursor();
451  void openAttachment(const QByteArray & resourceHash);
452  void openAttachmentUnderCursor();
453  void copyAttachment(const QByteArray & resourceHash);
454  void copyAttachmentUnderCursor();
455 
456  void encryptSelectedText();
457  void decryptEncryptedTextUnderCursor();
458 
459  void editHyperlinkDialog();
460  void copyHyperlink();
461  void removeHyperlink();
462 
463  void onNoteLoadCancelled();
464 
465 protected:
466  virtual void dragMoveEvent(QDragMoveEvent * pEvent) override;
467  virtual void dropEvent(QDropEvent * pEvent) override;
468 
469 private:
470  INoteEditorBackend * m_backend;
471 };
472 
473 } // namespace quentier
474 
475 #endif // LIB_QUENTIER_NOTE_EDITOR_NOTE_EDITOR_H
Definition: INoteEditorBackend.h:42
The ErrorString class encapsulates two (or more) strings which are meant to contain translatable (bas...
Definition: ErrorString.h:43
Definition: LocalStorageManagerAsync.h:44
Definition: DecryptedTextManager.h:26
The Account class encapsulates some details about the account: its name, whether it is local or synch...
Definition: Account.h:39
Definition: Notebook.h:34
Definition: SpellChecker.h:36
Definition: Note.h:34
The NoteEditor class is a widget encapsulating all the functionality necessary for showing and editin...
Definition: NoteEditor.h:46