File indexing completed on 2024-04-21 05:48:24
0001 /** 0002 * SPDX-FileCopyrightText: (C) 2003 Sébastien Laoût <slaout@linux62.org> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef NOTEEDIT_H 0008 #define NOTEEDIT_H 0009 0010 #include <QClipboard> 0011 #include <QDialog> 0012 #include <QLineEdit> 0013 0014 #include "notecontent.h" 0015 0016 class QGraphicsProxyWidget; 0017 class QWidget; 0018 class QPushButton; 0019 class QKeyEvent; 0020 class QFontComboBox; 0021 class QTextCharFormat; 0022 class QAction; 0023 0024 class KIconButton; 0025 class KUrlRequester; 0026 class KTextEdit; 0027 class KToggleAction; 0028 class KToolBar; 0029 class KActionCollection; 0030 class KComboBox; 0031 class KColorCombo; 0032 0033 class FontSizeCombo; 0034 class Note; 0035 class RunCommandRequester; 0036 class FocusWidgetFilter; 0037 class BasketListViewItem; 0038 0039 /** The base class for every note editor. 0040 * Scenario: 0041 * The Basket class calls NoteEditor::editNoteContent() with the NoteContent to edit. 0042 * This method create the good child NoteEditor depending 0043 * on the note content type and return it to the Basket. 0044 * This custom NoteEditor have two choices regarding what to do in its constructor: 0045 * - Display a dialog and then call cancel() if the user canceled the dialog; 0046 * - Create an inline editor and call setInlineEditor() with that editor as parameter. 0047 * When the user exit the edition, validate() is called by the Basket. 0048 * You should then call setEmpty() is the user cleared the content. 0049 * The custom editor SHOULD call the NoteEditor constructor. 0050 * If the user cleared the content OR if the user canceled the dialog whereas he/she 0051 * JUST ADDED the note, then the note will be deleted by the Basket. 0052 */ 0053 class NoteEditor : public QObject 0054 { 0055 Q_OBJECT 0056 public: 0057 explicit NoteEditor(NoteContent *noteContent); 0058 ~NoteEditor() override; 0059 0060 bool isEmpty() 0061 { 0062 return m_isEmpty; 0063 } 0064 bool canceled() 0065 { 0066 return m_canceled; 0067 } 0068 bool isInline() 0069 { 0070 return m_widget != nullptr; 0071 } 0072 QGraphicsProxyWidget *graphicsWidget() 0073 { 0074 return m_widget; 0075 } 0076 KTextEdit *textEdit() 0077 { 0078 return m_textEdit; 0079 } 0080 QLineEdit *lineEdit() 0081 { 0082 return m_lineEdit; 0083 } 0084 0085 void setCursorTo(const QPointF &pos); 0086 void connectActions(BasketScene *scene); 0087 void startSelection(const QPointF &pos); 0088 void updateSelection(const QPointF &pos); 0089 void endSelection(const QPointF &pos); 0090 void paste(const QPointF &pos, QClipboard::Mode mode); 0091 0092 private: 0093 bool m_isEmpty; 0094 bool m_canceled; 0095 QGraphicsProxyWidget *m_widget; 0096 KTextEdit *m_textEdit; 0097 QLineEdit *m_lineEdit; 0098 NoteContent *m_noteContent; 0099 0100 public: 0101 NoteContent *noteContent() 0102 { 0103 return m_noteContent; 0104 } 0105 Note *note(); 0106 0107 protected: 0108 void setEmpty() 0109 { 0110 m_isEmpty = true; 0111 } 0112 void cancel() 0113 { 0114 m_canceled = true; 0115 } 0116 void setInlineEditor(QWidget *inlineEditor); 0117 0118 public: 0119 virtual void validate() 0120 { 0121 } 0122 virtual void autoSave(bool /*toFileToo*/) 0123 { 0124 } // Same as validate(), but does not precede editor close and is triggered either while the editor widget changed size or after 3 seconds of inactivity. 0125 0126 Q_SIGNALS: 0127 void askValidation(); 0128 void mouseEnteredEditorWidget(); 0129 0130 public: 0131 static NoteEditor *editNoteContent(NoteContent *noteContent, QWidget *parent); 0132 }; 0133 0134 class TextEditor : public NoteEditor 0135 { 0136 Q_OBJECT 0137 public: 0138 TextEditor(TextContent *textContent, QWidget *parent); 0139 ~TextEditor() override; 0140 void validate() override; 0141 void autoSave(bool toFileToo) override; 0142 0143 protected: 0144 TextContent *m_textContent; 0145 }; 0146 0147 class HtmlEditor : public NoteEditor 0148 { 0149 Q_OBJECT 0150 public: 0151 HtmlEditor(HtmlContent *htmlContent, QWidget *parent); 0152 ~HtmlEditor() override; 0153 void validate() override; 0154 void autoSave(bool toFileToo) override; 0155 0156 protected: 0157 HtmlContent *m_htmlContent; 0158 public Q_SLOTS: 0159 void cursorPositionChanged(); 0160 void editTextChanged(); 0161 void charFormatChanged(const QTextCharFormat &format); 0162 protected Q_SLOTS: 0163 void setBold(bool isChecked); 0164 void setLeft(); 0165 void setCentered(); 0166 void setRight(); 0167 void setBlock(); 0168 void onFontSelectionChanged(const QFont &font); //!< When a font is selected from combo box 0169 void detectTags(); 0170 }; 0171 0172 class ImageEditor : public NoteEditor 0173 { 0174 Q_OBJECT 0175 public: 0176 ImageEditor(ImageContent *imageContent, QWidget *parent); 0177 }; 0178 0179 class AnimationEditor : public NoteEditor 0180 { 0181 Q_OBJECT 0182 public: 0183 AnimationEditor(AnimationContent *animationContent, QWidget *parent); 0184 }; 0185 0186 class FileEditor : public NoteEditor 0187 { 0188 Q_OBJECT 0189 public: 0190 FileEditor(FileContent *fileContent, QWidget *parent); 0191 ~FileEditor() override; 0192 void validate() override; 0193 void autoSave(bool toFileToo) override; 0194 0195 protected: 0196 FileContent *m_fileContent; 0197 }; 0198 0199 class LinkEditor : public NoteEditor 0200 { 0201 Q_OBJECT 0202 public: 0203 LinkEditor(LinkContent *linkContent, QWidget *parent); 0204 }; 0205 0206 class CrossReferenceEditor : public NoteEditor 0207 { 0208 Q_OBJECT 0209 public: 0210 CrossReferenceEditor(CrossReferenceContent *crossReferenceContent, QWidget *parent); 0211 }; 0212 0213 class LauncherEditor : public NoteEditor 0214 { 0215 Q_OBJECT 0216 public: 0217 LauncherEditor(LauncherContent *launcherContent, QWidget *parent); 0218 }; 0219 0220 class ColorEditor : public NoteEditor 0221 { 0222 Q_OBJECT 0223 public: 0224 ColorEditor(ColorContent *colorContent, QWidget *parent); 0225 }; 0226 0227 class UnknownEditor : public NoteEditor 0228 { 0229 Q_OBJECT 0230 public: 0231 UnknownEditor(UnknownContent *unknownContent, QWidget *parent); 0232 }; 0233 0234 /** The dialog to edit Link Note content. 0235 * @author Sébastien Laoût 0236 */ 0237 class LinkEditDialog : public QDialog 0238 { 0239 Q_OBJECT 0240 public: 0241 explicit LinkEditDialog(LinkContent *contentNote, QWidget *parent = nullptr); 0242 ~LinkEditDialog() override; 0243 void ensurePolished(); 0244 0245 protected Q_SLOTS: 0246 void slotOk(); 0247 void urlChanged(const QString &); 0248 void doNotAutoTitle(const QString &); 0249 void doNotAutoIcon(QString); 0250 void guessTitle(); 0251 void guessIcon(); 0252 0253 private: 0254 LinkContent *m_noteContent; 0255 bool m_isAutoModified; 0256 KUrlRequester *m_url; 0257 QLineEdit *m_title; 0258 KIconButton *m_icon; 0259 QPushButton *m_autoTitle; 0260 QPushButton *m_autoIcon; 0261 }; 0262 0263 /** The dialog to edit cross reference content. 0264 * @author Brian C. Milco 0265 */ 0266 class CrossReferenceEditDialog : public QDialog 0267 { 0268 Q_OBJECT 0269 public: 0270 explicit CrossReferenceEditDialog(CrossReferenceContent *contentNote, QWidget *parent = nullptr); 0271 ~CrossReferenceEditDialog() override; 0272 0273 protected Q_SLOTS: 0274 void slotOk(); 0275 void urlChanged(const int index); 0276 0277 protected: 0278 void generateBasketList(KComboBox *targetList, BasketListViewItem *item = nullptr, int indent = 0); 0279 0280 private: 0281 CrossReferenceContent *m_noteContent; 0282 KComboBox *m_targetBasket; 0283 }; 0284 0285 /** The dialog to edit Launcher Note content. 0286 * @author Sébastien Laoût 0287 */ 0288 class LauncherEditDialog : public QDialog 0289 { 0290 Q_OBJECT 0291 public: 0292 explicit LauncherEditDialog(LauncherContent *contentNote, QWidget *parent = nullptr); 0293 ~LauncherEditDialog() override; 0294 void ensurePolished(); 0295 protected Q_SLOTS: 0296 void slotOk(); 0297 void guessIcon(); 0298 0299 private: 0300 LauncherContent *m_noteContent; 0301 RunCommandRequester *m_command; 0302 QLineEdit *m_name; 0303 KIconButton *m_icon; 0304 }; 0305 0306 /** This class manage toolbars for the inline editors. 0307 * The toolbars should be created once at the application startup, 0308 * then KXMLGUI can manage them and save their state and position... 0309 * @author Sébastien Laoût 0310 */ 0311 class InlineEditors : public QObject 0312 { 0313 Q_OBJECT 0314 public: 0315 InlineEditors(); 0316 ~InlineEditors() override; 0317 void initToolBars(KActionCollection *ac); 0318 static InlineEditors *instance(); 0319 0320 public: 0321 // Rich Text ToolBar: 0322 KToolBar *richTextToolBar(); 0323 void enableRichTextToolBar(); 0324 void disableRichTextToolBar(); 0325 QPalette palette() const; 0326 QFontComboBox *richTextFont; 0327 FontSizeCombo *richTextFontSize; 0328 KColorCombo *richTextColor; 0329 KToggleAction *richTextBold; 0330 KToggleAction *richTextItalic; 0331 KToggleAction *richTextUnderline; 0332 // KToggleAction *richTextSuper; 0333 // KToggleAction *richTextSub; 0334 KToggleAction *richTextLeft; 0335 KToggleAction *richTextCenter; 0336 KToggleAction *richTextRight; 0337 KToggleAction *richTextJustified; 0338 QAction *richTextUndo; 0339 QAction *richTextRedo; 0340 FocusWidgetFilter *focusWidgetFilter; 0341 }; 0342 0343 #endif // NOTEEDIT_H