File indexing completed on 2024-05-19 05:19:22

0001 /*
0002     This file is part of KJots.
0003 
0004     SPDX-FileCopyrightText: 1997 Christoph Neerfeld <Christoph.Neerfeld@home.ivm.de>
0005                   2002, 2003 Aaron J. Seigo <aseigo@kde.org>
0006                   2003 Stanislav Kljuhhin <crz@hot.ee>
0007                   2005-2006 Jaison Lee <lee.jaison@gmail.com>
0008                   2007-2009 Stephen Kelly <steveire@gmail.com>
0009                   2020 Igor Poboiko <igor.poboiko@gmail.com>
0010 
0011     SPDX-License-Identifier: LGPL-2.0-or-later
0012 */
0013 
0014 #ifndef KJOTSWIDGET_H
0015 #define KJOTSWIDGET_H
0016 
0017 #include <QWidget>
0018 #include <QAbstractItemDelegate>
0019 #include <QPrinter>
0020 
0021 #include <KBookmarkManager>
0022 
0023 #include <akonadi_version.h>
0024 #include <Akonadi/Collection>
0025 
0026 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0027 #include <grantlee/templateloader.h>
0028 #else
0029 #include <KTextTemplate/TemplateLoader>
0030 #endif
0031 
0032 
0033 class QActionGroup;
0034 class QCheckBox;
0035 class QTextEdit;
0036 class QTextCharFormat;
0037 class QSplitter;
0038 class QStackedWidget;
0039 class QModelIndex;
0040 class QTreeView;
0041 
0042 class KActionMenu;
0043 class KFindDialog;
0044 class KJob;
0045 class KReplaceDialog;
0046 class KSelectionProxyModel;
0047 class KJotsBrowser;
0048 class KJotsBrowserWidget;
0049 class KXMLGUIClient;
0050 
0051 namespace Akonadi
0052 {
0053 class EntityMimeTypeFilterModel;
0054 class EntityOrderProxyModel;
0055 class EntityTreeView;
0056 class StandardNoteActionManager;
0057 }
0058 
0059 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0060 namespace Grantlee
0061 #else
0062 namespace KTextTemplate
0063 #endif
0064 {
0065 class Engine;
0066 }
0067 
0068 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0069 namespace KPIMTextEdit
0070 #else
0071 namespace TextCustomEditor
0072 #endif
0073 {
0074 class RichTextEditorWidget;
0075 }
0076 
0077 class KJotsEdit;
0078 class KJotsModel;
0079 class KJotsTreeView;
0080 class NoteSortProxyModel;
0081 
0082 class KJotsWidget : public QWidget
0083 {
0084     Q_OBJECT
0085     Q_CLASSINFO("D-Bus Interface", "org.kde.KJotsWidget")
0086 
0087 public:
0088     explicit KJotsWidget(QWidget *parent, KXMLGUIClient *xmlGuiclient, Qt::WindowFlags f = Qt::WindowFlags());
0089     ~KJotsWidget();
0090 
0091     QTextEdit *activeEditor();
0092 public Q_SLOTS:
0093     void configure();
0094     void updateCaption();
0095     void updateMenu();
0096 
0097     Q_SCRIPTABLE bool queryClose();
0098 
0099     void setViewMode(int mode);
0100 
0101 Q_SIGNALS:
0102     void canGoNextPageChanged(bool);
0103     void canGoPreviousPageChanged(bool);
0104     void canGoNextBookChanged(bool);
0105     void canGoPreviousBookChanged(bool);
0106 
0107     void captionChanged(const QString &newCaption);
0108 
0109 protected:
0110     static QModelIndex previousNextEntity(QTreeView *view, int step);
0111 
0112     void setupGui();
0113     void setupActions();
0114 
0115     QString renderSelectionTo(const QString &theme, const QString &templ);
0116     QString renderSelectionToHtml();
0117 
0118     std::unique_ptr<QPrinter> setupPrinter(QPrinter::PrinterMode mode = QPrinter::ScreenResolution);
0119 
0120     void saveUIStates() const;
0121     void restoreUIStates();
0122 protected Q_SLOTS:
0123     /**
0124      * Renders contents on either KJotsEdit or KJotsBrowser based on KJotsTreeView selection
0125      */
0126     void renderSelection();
0127     void exportSelection(const QString &theme, const QString &templ);
0128     void printSelection();
0129     void printPreviewSelection();
0130 
0131     void openLink(const QUrl &url);
0132 private Q_SLOTS:
0133     void delayedInitialization();
0134 
0135     void saveState();
0136     void restoreState();
0137     void updateConfiguration();
0138 
0139     void print(QPrinter *printer);
0140 private:
0141     // Grantlee
0142 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0143     Grantlee::Engine *m_templateEngine = nullptr;
0144     QSharedPointer<Grantlee::FileSystemTemplateLoader> m_loader;
0145 #else
0146     KTextTemplate::Engine *m_templateEngine = nullptr;
0147     QSharedPointer<KTextTemplate::FileSystemTemplateLoader> m_loader;
0148 #endif
0149 
0150     // XMLGui && Actions
0151     KXMLGUIClient  *m_xmlGuiClient = nullptr;
0152     Akonadi::StandardNoteActionManager *m_actionManager = nullptr;
0153     QSet<QAction *> anySelectionActions;
0154     QActionGroup *m_viewModeGroup = nullptr;
0155 
0156     // UI
0157     QSplitter *m_splitter1 = nullptr;
0158     QSplitter *m_splitter2 = nullptr;
0159     QStackedWidget *m_stackedWidget = nullptr;
0160     Akonadi::EntityTreeView *m_collectionView = nullptr;
0161     Akonadi::EntityTreeView *m_itemView = nullptr;
0162     KJotsEdit      *m_editor = nullptr;
0163 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0164     KPIMTextEdit::RichTextEditorWidget *m_editorWidget = nullptr;
0165 #else
0166     TextCustomEditor::RichTextEditorWidget *m_editorWidget = nullptr;
0167 #endif
0168     KJotsBrowserWidget *m_browserWidget = nullptr;
0169 
0170     // Models
0171     KJotsModel *m_kjotsModel = nullptr;
0172     Akonadi::EntityMimeTypeFilterModel *m_collectionModel = nullptr;
0173     Akonadi::EntityMimeTypeFilterModel *m_itemModel = nullptr;
0174     NoteSortProxyModel *m_itemSortModel = nullptr;
0175     KSelectionProxyModel *m_collectionSelectionProxyModel = nullptr;
0176     Akonadi::EntityOrderProxyModel *m_orderProxy = nullptr;
0177 
0178     QTimer *m_autosaveTimer = nullptr;
0179     KBookmarkManager *m_bookmarkManager;
0180 };
0181 
0182 #endif