File indexing completed on 2024-11-24 04:48:12

0001 /*******************************************************************
0002  KNotes -- Notes for the KDE project
0003 
0004  SPDX-FileCopyrightText: 1997-2013 The KNotes Developers
0005 
0006  SPDX-License-Identifier: GPL-2.0-or-later
0007 *******************************************************************/
0008 
0009 #pragma once
0010 
0011 #include "knoteinterface.h"
0012 #include <config-knotes.h>
0013 
0014 #include <Akonadi/Item>
0015 
0016 #include <KSharedConfig>
0017 #include <KXMLGUIClient>
0018 
0019 #include <QDomDocument>
0020 #include <QFrame>
0021 
0022 class KNoteButton;
0023 class KNoteDisplaySettings;
0024 class KNoteEdit;
0025 
0026 class KSelectAction;
0027 class KToggleAction;
0028 class KToolBar;
0029 
0030 class QLabel;
0031 class QMenu;
0032 class QSizeGrip;
0033 class QVBoxLayout;
0034 class QEvent;
0035 class KNote : public QFrame, virtual public KXMLGUIClient, public KNoteInterface
0036 {
0037     Q_OBJECT
0038 public:
0039     explicit KNote(const QDomDocument &buildDoc, const Akonadi::Item &item, bool allowAkonadiSearchDebug = false, QWidget *parent = nullptr);
0040     ~KNote() override;
0041 
0042     void setChangeItem(const Akonadi::Item &item, const QSet<QByteArray> &set = QSet<QByteArray>());
0043     void saveNote(bool force = false, bool sync = false);
0044 
0045     [[nodiscard]] QString name() const;
0046     [[nodiscard]] QString text() const;
0047     [[nodiscard]] Akonadi::Item::Id noteId() const;
0048 
0049     [[nodiscard]] Akonadi::Item item() const;
0050 
0051     void setName(const QString &name);
0052     void setText(const QString &text);
0053 
0054     [[nodiscard]] bool isModified() const;
0055     [[nodiscard]] bool isDesktopAssigned() const;
0056 
0057     void toDesktop(int desktop);
0058 
0059 public Q_SLOTS:
0060     void slotRename();
0061     void slotKill(bool force = false);
0062     void slotClose();
0063 
0064 Q_SIGNALS:
0065     void sigRequestNewNote();
0066     void sigShowNextNote();
0067     void sigNameChanged(const QString &);
0068     void sigColorChanged();
0069     void sigKillNote(Akonadi::Item::Id);
0070 
0071 protected:
0072     void contextMenuEvent(QContextMenuEvent *) override;
0073     void showEvent(QShowEvent *) override;
0074     void resizeEvent(QResizeEvent *) override;
0075     void closeEvent(QCloseEvent *) override;
0076     void dropEvent(QDropEvent *) override;
0077     void dragEnterEvent(QDragEnterEvent *) override;
0078 
0079     bool event(QEvent *) override;
0080     bool eventFilter(QObject *, QEvent *) override;
0081 
0082 private Q_SLOTS:
0083     void slotUpdateReadOnly();
0084 
0085     void slotSend();
0086     void slotMail();
0087     void slotPrint();
0088     void slotPrintPreview();
0089     void slotSaveAs();
0090 
0091     void slotSetAlarm();
0092 
0093     void slotPreferences();
0094     void slotPopupActionToDesktop(QAction *act);
0095 
0096     void slotApplyConfig();
0097 
0098     void slotUpdateShowInTaskbar();
0099     void slotUpdateDesktopActions();
0100 
0101     void slotKeepAbove();
0102     void slotKeepBelow();
0103 
0104     void slotRequestNewNote();
0105     void slotNoteSaved(KJob *job);
0106     void slotDebugAkonadiSearch();
0107 
0108 private:
0109     void updateKeepAboveBelow(bool save = true);
0110     void buildGui();
0111     void createActions();
0112     void createNoteEditor(const QString &configFile);
0113     void createNoteFooter();
0114     void createNoteHeader();
0115     void prepare();
0116 
0117     void updateFocus();
0118     void updateLayout();
0119     void updateLabelAlignment();
0120 
0121     void setColor(const QColor &, const QColor &);
0122     void print(bool preview);
0123     void setDisplayDefaultValue();
0124 
0125 private:
0126     void loadNoteContent(const Akonadi::Item &item);
0127     void updateAllAttributes();
0128     void saveNoteContent();
0129     Akonadi::Item mItem;
0130     QVBoxLayout *m_noteLayout = nullptr;
0131     QLabel *m_label = nullptr;
0132     QSizeGrip *m_grip = nullptr;
0133     KNoteButton *m_button = nullptr;
0134     KToolBar *m_tool = nullptr;
0135     KNoteEdit *m_editor = nullptr;
0136 
0137     QMenu *m_menu = nullptr;
0138 
0139     KToggleAction *m_readOnly = nullptr;
0140 
0141 #if KDEPIM_HAVE_X11
0142     KSelectAction *m_toDesktop = nullptr;
0143 #endif
0144     KToggleAction *m_keepAbove = nullptr;
0145     KToggleAction *m_keepBelow = nullptr;
0146 
0147     KSharedConfig::Ptr m_kwinConf;
0148 
0149     KNoteDisplaySettings *mDisplayAttribute = nullptr;
0150     bool mAllowDebugAkonadiSearch;
0151     QPoint mOrigPos;
0152 };