libquentier  0.8.0
The library for rich desktop clients of Evernote service
NoteEditor.h
1 /*
2  * Copyright 2016-2025 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 #pragma once
20 
21 #include <quentier/enml/Fwd.h>
22 #include <quentier/local_storage/Fwd.h>
23 #include <quentier/types/ErrorString.h>
24 #include <quentier/utility/Linkage.h>
25 
26 #include <qevercloud/types/Note.h>
27 #include <qevercloud/types/Notebook.h>
28 
29 #include <QPrinter>
30 #include <QStringList>
31 #include <QThread>
32 #include <QWidget>
33 
34 class QUndoStack;
35 
36 namespace quentier {
37 
38 class Account;
39 class INoteEditorBackend;
40 class SpellChecker;
41 
46 class QUENTIER_EXPORT NoteEditor : public QWidget
47 {
48  Q_OBJECT
49 public:
50  explicit NoteEditor(
51  QWidget * parent = nullptr,
52 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
53  Qt::WindowFlags flags = {});
54 #else
55  Qt::WindowFlags flags = 0); // NOLINT
56 #endif
57 
58  ~NoteEditor() noexcept override;
59 
80  void initialize(
81  local_storage::ILocalStoragePtr localStorage,
82  SpellChecker & spellChecker, const Account & account,
83  QThread * backgroundJobsThread = nullptr,
84  enml::IDecryptedTextCachePtr decryptedTextCache = nullptr);
85 
89  [[nodiscard]] INoteEditorBackend * backend() noexcept;
90 
96  void setBackend(INoteEditorBackend * backend);
97 
101  void setAccount(const Account & account);
102 
106  [[nodiscard]] const QUndoStack * undoStack() const noexcept;
107 
111  void setUndoStack(QUndoStack * pUndoStack);
112 
116  void setInitialPageHtml(const QString & html);
117 
122  void setNoteNotFoundPageHtml(const QString & html);
123 
129  void setNoteDeletedPageHtml(const QString & html);
130 
135  void setNoteLoadingPageHtml(const QString & html);
136 
140  [[nodiscard]] QString currentNoteLocalId() const;
141 
149  void setCurrentNoteLocalId(const QString & noteLocalId);
150 
154  void clear();
155 
160  [[nodiscard]] bool isModified() const noexcept;
161 
166  [[nodiscard]] bool isEditorPageModified() const noexcept;
167 
172  [[nodiscard]] bool isNoteLoaded() const noexcept;
173 
179  [[nodiscard]] qint64 idleTime() const noexcept;
180 
184  void setFocus();
185 
186  [[nodiscard]] QString selectedText() const noexcept;
187  [[nodiscard]] bool hasSelection() const noexcept;
188 
189  [[nodiscard]] bool spellCheckEnabled() const noexcept;
190 
191  [[nodiscard]] bool print(
192  QPrinter & printer, ErrorString & errorDescription);
193 
194  [[nodiscard]] bool exportToPdf(
195  const QString & absoluteFilePath, ErrorString & errorDescription);
196 
197  [[nodiscard]] bool exportToEnex(
198  const QStringList & tagNames, QString & enex,
199  ErrorString & errorDescription);
200 
208  [[nodiscard]] QPalette defaultPalette() const;
209 
214  [[nodiscard]] const QFont * defaultFont() const;
215 
216 Q_SIGNALS:
221  void contentChanged();
222 
228  void noteAndNotebookFoundInLocalStorage(
229  qevercloud::Note note, qevercloud::Notebook notebook);
230 
235  void noteNotFound(QString noteLocalId);
236 
242  void noteDeleted(QString noteLocalId);
243 
249  void noteModified();
250 
255  void notifyError(ErrorString error);
256 
261  void inAppNoteLinkClicked(
262  QString userId, QString shardId, QString noteGuid);
263 
275  void inAppNoteLinkPasteRequested(
276  QString url, QString userId, QString shardId, QString noteGuid);
277 
278  void convertedToNote(qevercloud::Note note);
279  void cantConvertToNote(ErrorString error);
280 
281  void noteEditorHtmlUpdated(QString html);
282 
283  void currentNoteChanged(qevercloud::Note note);
284 
285  void spellCheckerNotReady();
286  void spellCheckerReady();
287 
288  void noteLoaded();
289 
296  void noteSavedToLocalStorage(QString noteLocalId);
297 
302  void failedToSaveNoteToLocalStorage(
303  ErrorString errorDescription, QString noteLocalId);
304 
305  // Signals to notify anyone interested of the formatting at the current
306  // cursor position
307  void textBoldState(bool state);
308  void textItalicState(bool state);
309  void textUnderlineState(bool state);
310  void textStrikethroughState(bool state);
311  void textAlignLeftState(bool state);
312  void textAlignCenterState(bool state);
313  void textAlignRightState(bool state);
314  void textAlignFullState(bool state);
315  void textInsideOrderedListState(bool state);
316  void textInsideUnorderedListState(bool state);
317  void textInsideTableState(bool state);
318 
319  void textFontFamilyChanged(QString fontFamily);
320  void textFontSizeChanged(int fontSize);
321 
322  void insertTableDialogRequested();
323 
324 public Q_SLOTS:
330  void convertToNote();
331 
340  void saveNoteToLocalStorage();
341 
351  void setNoteTitle(const QString & noteTitle);
352 
364  void setTagIds(
365  const QStringList & tagLocalIds, const QStringList & tagGuids);
366 
367  void undo();
368  void redo();
369  void cut();
370  void copy();
371  void paste();
372  void pasteUnformatted();
373  void selectAll();
374 
375  void formatSelectionAsSourceCode();
376 
377  void fontMenu();
378  void textBold();
379  void textItalic();
380  void textUnderline();
381  void textStrikethrough();
382  void textHighlight();
383 
384  void alignLeft();
385  void alignCenter();
386  void alignRight();
387  void alignFull();
388 
389  void findNext(const QString & text, bool matchCase) const;
390  void findPrevious(const QString & text, bool matchCase) const;
391 
392  void replace(
393  const QString & textToReplace, const QString & replacementText,
394  bool matchCase);
395 
396  void replaceAll(
397  const QString & textToReplace, const QString & replacementText,
398  bool matchCase);
399 
400  void insertToDoCheckbox();
401 
402  void insertInAppNoteLink(
403  const QString & userId, const QString & shardId,
404  const QString & noteGuid, const QString & linkText);
405 
406  void setSpellcheck(bool enabled);
407 
408  void setFont(const QFont & font);
409  void setFontHeight(int height);
410  void setFontColor(const QColor & color);
411  void setBackgroundColor(const QColor & color);
412 
428  void setDefaultPalette(const QPalette & pal);
429 
435  void setDefaultFont(const QFont & font);
436 
437  void insertHorizontalLine();
438 
439  void increaseFontSize();
440  void decreaseFontSize();
441 
442  void increaseIndentation();
443  void decreaseIndentation();
444 
445  void insertBulletedList();
446  void insertNumberedList();
447 
448  void insertTableDialog();
449 
450  void insertFixedWidthTable(int rows, int columns, int widthInPixels);
451 
452  void insertRelativeWidthTable(int rows, int columns, double relativeWidth);
453 
454  void insertTableRow();
455  void insertTableColumn();
456  void removeTableRow();
457  void removeTableColumn();
458 
459  void addAttachmentDialog();
460  void saveAttachmentDialog(const QByteArray & resourceHash);
461  void saveAttachmentUnderCursor();
462  void openAttachment(const QByteArray & resourceHash);
463  void openAttachmentUnderCursor();
464  void copyAttachment(const QByteArray & resourceHash);
465  void copyAttachmentUnderCursor();
466 
467  void encryptSelectedText();
468  void decryptEncryptedTextUnderCursor();
469 
470  void editHyperlinkDialog();
471  void copyHyperlink();
472  void removeHyperlink();
473 
474  void onNoteLoadCancelled();
475 
476 protected:
477  void dragMoveEvent(QDragMoveEvent * pEvent) override;
478  void dropEvent(QDropEvent * pEvent) override;
479 
480 private:
481  INoteEditorBackend * m_backend;
482 };
483 
484 } // namespace quentier
Definition: INoteEditorBackend.h:41
The ErrorString class encapsulates two (or more) strings which are meant to contain translatable (bas...
Definition: ErrorString.h:42
The Account class encapsulates some details about the account: its name, whether it is local or synch...
Definition: Account.h:37
Definition: SpellChecker.h:35
The NoteEditor class is a widget encapsulating all the functionality necessary for showing and editin...
Definition: NoteEditor.h:46