File indexing completed on 2024-03-24 05:51:15
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 NOTECONTENT_H 0008 #define NOTECONTENT_H 0009 0010 #include <QMap> 0011 #include <QGraphicsItem> 0012 #include <QUrl> 0013 #include <QNetworkAccessManager> 0014 #include <QXmlStreamWriter> 0015 #include <QtCore/QObject> 0016 0017 #include <phonon/phononnamespace.h> 0018 0019 #include "basket_export.h" 0020 #include "linklabel.h" 0021 0022 class QDomElement; 0023 0024 class QBuffer; 0025 class QColor; 0026 class QMimeData; 0027 class QMovie; 0028 class QPainter; 0029 class QPixmap; 0030 class QPoint; 0031 class QRect; 0032 class QString; 0033 class QStringList; 0034 class QTextDocument; 0035 class QWidget; 0036 0037 class KFileItem; 0038 class QUrl; 0039 0040 namespace KIO 0041 { 0042 class PreviewJob; 0043 } 0044 0045 namespace Phonon 0046 { 0047 class MediaObject; 0048 } 0049 0050 class BasketScene; 0051 struct FilterData; 0052 class Note; 0053 0054 /** 0055 * LinkDisplayItem is a QGraphicsItem using a LinkDisplay 0056 */ 0057 class LinkDisplayItem : public QGraphicsItem 0058 { 0059 public: 0060 explicit LinkDisplayItem(Note *parent) 0061 : m_note(parent) 0062 { 0063 } 0064 ~LinkDisplayItem() override 0065 { 0066 } 0067 QRectF boundingRect() const override; 0068 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override; 0069 0070 LinkDisplay &linkDisplay() 0071 { 0072 return m_linkDisplay; 0073 } 0074 0075 private: 0076 LinkDisplay m_linkDisplay; 0077 Note *m_note; 0078 }; 0079 0080 /** A list of numeric identifier for each note type. 0081 * Declare a variable with the type NoteType::Id and assign a value like NoteType::Text... 0082 * @author Sébastien Laoût 0083 */ 0084 namespace NoteType 0085 { 0086 enum Id { Group = 255, Text = 1, Html, Image, Animation, Sound, File, Link, CrossReference, Launcher, Color, Unknown }; // Always positive 0087 0088 QString typeToName(const NoteType::Id noteType); 0089 QString typeToLowerName(const NoteType::Id noteType); 0090 NoteType::Id typeFromLowerName(const QString &lowerTypeName); 0091 0092 } 0093 0094 /** Abstract base class for every content type of basket note. 0095 * It's a base class to represent those types: Text, Html, Image, Animation, Sound, File, Link, Launcher, Color, Unknown. 0096 * @author Sébastien Laoût 0097 */ 0098 class BASKET_EXPORT NoteContent 0099 { 0100 public: 0101 // Constructor and destructor: 0102 explicit NoteContent(Note *parent, const NoteType::Id type, const QString &fileName = QString()); 0103 virtual ~NoteContent() {} 0104 // Note Type Information 0105 NoteType::Id type() const { return m_type; } /// << @return the internal number that identify that note type. 0106 QString typeName() const { return NoteType::typeToName(type()); } /// << @return the translated type name to display in the user interface. 0107 QString lowerTypeName() const { return NoteType::typeToLowerName(type()); } /// << @return the type name in lowercase without space, for eg. saving. 0108 // Simple Abstract Generic Methods: 0109 virtual QString toText(const QString &cuttedFullPath); /// << @return a plain text equivalent of the content. 0110 virtual QString toHtml(const QString &imageName, const QString &cuttedFullPath) = 0; /// << @return an HTML text equivalent of the content. @param imageName Save image in this Qt resource. 0111 virtual QPixmap toPixmap() 0112 { 0113 return QPixmap(); 0114 } /// << @return an image equivalent of the content. 0115 virtual void toLink(QUrl *url, QString *title, const QString &cuttedFullPath); /// << Set the link to the content. By default, it set them to fullPath() if useFile(). 0116 virtual bool useFile() const = 0; /// << @return true if it use a file to store the content. 0117 virtual bool canBeSavedAs() const = 0; /// << @return true if the content can be saved as a file by the user. 0118 virtual QString saveAsFilters() const = 0; /// << @return the filters for the user to choose a file destination to save the note as. 0119 virtual bool match(const FilterData &data) = 0; /// << @return true if the content match the filter criteria. 0120 // Complex Abstract Generic Methods: 0121 virtual void exportToHTML(HTMLExporter *exporter, int indent) = 0; /// << Export the note in an HTML file. 0122 virtual QString cssClass() const = 0; /// << @return the CSS class of the note when exported to HTML 0123 virtual qreal setWidthAndGetHeight(qreal width) = 0; /// << Relayout content with @p width (never less than minWidth()). @return its new height. 0124 virtual bool loadFromFile(bool /*lazyLoad*/) 0125 { 0126 return false; 0127 } /// << Load the content from the file. The default implementation does nothing. @see fileName(). 0128 virtual bool finishLazyLoad() 0129 { 0130 return false; 0131 } /// << Load what was not loaded by loadFromFile() if it was lazy-loaded 0132 virtual bool saveToFile() 0133 { 0134 return false; 0135 } /// << Save the content to the file. The default implementation does nothing. @see fileName(). 0136 virtual QString linkAt(const QPointF & /*pos*/) 0137 { 0138 return QString(); 0139 } /// << @return the link anchor at position @p pos or QString() if there is no link. 0140 virtual void saveToNode(QXmlStreamWriter &stream); /// << Save the note in the basket XML file. By default it store the filename if a file is used. 0141 virtual void fontChanged() = 0; /// << If your content display textual data, called when the font have changed (from tags or basket font) 0142 virtual void linkLookChanged() 0143 { 0144 } /// << If your content use LinkDisplay with preview enabled, reload the preview (can have changed size) 0145 virtual QString editToolTipText() const = 0; /// << @return "Edit this [text|image|...]" to put in the tooltip for the note's content zone. 0146 virtual QMap<QString, QString> toolTipInfos() 0147 { 0148 return {}; 0149 } /// << Return "key: value" map to put in the tooltip for the note's content zone. 0150 // Custom Zones: /// Implement this if you want to store custom data. 0151 virtual int zoneAt(const QPointF & /*pos*/) 0152 { 0153 return 0; 0154 } /// << If your note-type have custom zones, @return the zone at @p pos or 0 if it's not a custom zone! 0155 virtual QRectF zoneRect(int /*zone*/, const QPointF & /*pos*/); /// << Idem, @return the rect of the custom zone 0156 virtual QString zoneTip(int /*zone*/) 0157 { 0158 return QString(); 0159 } /// << Idem, @return the toolTip of the custom zone 0160 virtual Qt::CursorShape cursorFromZone(int /*zone*/) const 0161 { 0162 return Qt::ArrowCursor; 0163 } /// << Idem, @return the mouse cursor when it is over zone @p zone! 0164 virtual void setHoveredZone(int /*oldZone*/, int /*newZone*/) 0165 { 0166 } /// << If your note type need some feedback, you get notified of hovering changes here. 0167 virtual QString statusBarMessage(int /*zone*/) 0168 { 0169 return QString(); 0170 } /// << @return the statusBar message to show for zone @p zone, or QString() if nothing special have to be said. 0171 // Drag and Drop Content: 0172 virtual void serialize(QDataStream & /*stream*/) 0173 { 0174 } /// << Serialize the content in a QDragObject. If it consists of a file, it can be serialized for you. 0175 virtual bool shouldSerializeFile() 0176 { 0177 return useFile(); 0178 } /// << @return true if the dragging process should serialize the filename (and move the file if cutting). 0179 virtual void addAlternateDragObjects(QMimeData * /*dragObj*/) 0180 { 0181 } /// << If you offer more than toText/Html/Image/Link(), this will be called if this is the only selected. 0182 virtual QPixmap feedbackPixmap(qreal width, qreal height) = 0; /// << @return the pixmap to put under the cursor while dragging this object. 0183 virtual bool needSpaceForFeedbackPixmap() 0184 { 0185 return false; 0186 } /// << @return true if a space must be inserted before and after the DND feedback pixmap. 0187 // Content Edition: 0188 virtual int xEditorIndent() 0189 { 0190 return 0; 0191 } /// << If the editor should be indented (eg. to not cover an icon), return the number of pixels. 0192 // Open Content or File: 0193 virtual QUrl urlToOpen(bool /*with*/); /// << @return the URL to open the note, or an invalid QUrl if it's not openable. If @p with if false, it's a normal "Open". If it's true, it's for an "Open with..." action. The default 0194 /// implementation return the fullPath() if the note useFile() and nothing if not. 0195 enum OpenMessage { 0196 OpenOne, /// << Message to send to the statusbar when opening this note. 0197 OpenSeveral, /// << Message to send to the statusbar when opening several notes of this type. 0198 OpenOneWith, /// << Message to send to the statusbar when doing "Open With..." on this note. 0199 OpenSeveralWith, /// << Message to send to the statusbar when doing "Open With..." several notes of this type. 0200 OpenOneWithDialog, /// << Prompt-message of the "Open With..." dialog for this note. 0201 OpenSeveralWithDialog /// << Prompt-message of the "Open With..." dialog for several notes of this type. 0202 }; 0203 virtual QString messageWhenOpening(OpenMessage /*where*/) 0204 { 0205 return QString(); 0206 } /// << @return the message to display according to @p where or nothing if it can't be done. @see OpenMessage describing the nature of the message that should be returned... The default implementation return an empty string. NOTE: If 0207 /// urlToOpen() is invalid and messageWhenOpening() is not empty, then the user will be prompted to edit the note (with the message returned by messageWhenOpening()) for eg. being able to edit URL of a link if it's empty when opening 0208 /// it... 0209 virtual QString customOpenCommand() 0210 { 0211 return QString(); 0212 } /// << Reimplement this if your urlToOpen() should be opened with another application instead of the default KDE one. This choice should be left to the users in the setting (choice to use a custom app or not, and which app). 0213 // Common File Management: /// (and do save changes) and optionally hide the toolbar. 0214 virtual void setFileName(const QString &fileName); /// << Set the filename. Reimplement it if you eg. want to update the view when the filename is changed. 0215 bool trySetFileName(const QString &fileName); /// << Set the new filename and return true. Can fail and return false if a file with this fileName already exists. 0216 QString fullPath(); /// << Get the absolute path of the file where this content is stored on disk. 0217 QUrl fullPathUrl(); /// << Get the absolute path of the file where this content is stored on disk as QUrl 0218 QString fileName() const 0219 { 0220 return m_fileName; 0221 } /// << Get the file name where this content is stored (relative to the basket folder). @see fullPath(). 0222 qreal minWidth() const 0223 { 0224 return m_minWidth; 0225 } /// << Get the minimum width for this content. 0226 Note *note() 0227 { 0228 return m_note; 0229 } /// << Get the note managing this content. 0230 BasketScene *basket(); /// << Get the basket containing the note managing this content. 0231 virtual QGraphicsItem *graphicsItem() = 0; 0232 0233 public: 0234 void setEdited(); /// << Mark the note as edited NOW: change the "last modification time and time" AND save the basket to XML file. 0235 protected: 0236 void contentChanged(qreal newMinWidth); /// << When the content has changed, inherited classes should call this to specify its new minimum size and trigger a basket relayout. 0237 NoteType::Id m_type = NoteType::Unknown; 0238 private: 0239 Note *m_note; 0240 QString m_fileName; 0241 qreal m_minWidth; 0242 0243 public: 0244 static const int FEEDBACK_DARKING; 0245 }; 0246 0247 /** Real implementation of plain text notes: 0248 * @author Sébastien Laoût 0249 */ 0250 class BASKET_EXPORT TextContent : public NoteContent 0251 { 0252 public: 0253 // Constructor and destructor: 0254 TextContent(Note *parent, const QString &fileName, bool lazyLoad = false); 0255 ~TextContent() override; 0256 // Simple Generic Methods: 0257 QString toText(const QString & /*cuttedFullPath*/) override; 0258 QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; 0259 bool useFile() const override; 0260 bool canBeSavedAs() const override; 0261 QString saveAsFilters() const override; 0262 bool match(const FilterData &data) override; 0263 // Complex Generic Methods: 0264 void exportToHTML(HTMLExporter *exporter, int indent) override; 0265 QString cssClass() const override; 0266 qreal setWidthAndGetHeight(qreal width) override; 0267 bool loadFromFile(bool lazyLoad) override; 0268 bool finishLazyLoad() override; 0269 bool saveToFile() override; 0270 QString linkAt(const QPointF &pos) override; 0271 void fontChanged() override; 0272 QString editToolTipText() const override; 0273 // Drag and Drop Content: 0274 QPixmap feedbackPixmap(qreal width, qreal height) override; 0275 // Open Content or File: 0276 QString messageWhenOpening(OpenMessage where) override; 0277 // QString customOpenCommand(); 0278 // Content-Specific Methods: 0279 void setText(const QString &text, bool lazyLoad = false); /// << Change the text note-content and relayout the note. 0280 QString text() 0281 { 0282 return m_graphicsTextItem.text(); 0283 } /// << @return the text note-content. 0284 QGraphicsItem *graphicsItem() override 0285 { 0286 return &m_graphicsTextItem; 0287 } 0288 0289 protected: 0290 // QString m_text; 0291 // QTextDocument *m_simpleRichText; 0292 QGraphicsSimpleTextItem m_graphicsTextItem; 0293 }; 0294 0295 #include <QGraphicsTextItem> 0296 /** Real implementation of rich text (HTML) notes: 0297 * @author Sébastien Laoût 0298 */ 0299 class BASKET_EXPORT HtmlContent : public NoteContent 0300 { 0301 public: 0302 // Constructor and destructor: 0303 HtmlContent(Note *parent, const QString &fileName, bool lazyLoad = false); 0304 ~HtmlContent() override; 0305 // Simple Generic Methods: 0306 QString toText(const QString & /*cuttedFullPath*/) override; 0307 QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; 0308 bool useFile() const override; 0309 bool canBeSavedAs() const override; 0310 QString saveAsFilters() const override; 0311 bool match(const FilterData &data) override; 0312 // Complex Generic Methods: 0313 void exportToHTML(HTMLExporter *exporter, int indent) override; 0314 QString cssClass() const override; 0315 qreal setWidthAndGetHeight(qreal width) override; 0316 bool loadFromFile(bool lazyLoad) override; 0317 bool finishLazyLoad() override; 0318 bool saveToFile() override; 0319 QString linkAt(const QPointF &pos) override; 0320 void fontChanged() override; 0321 QString editToolTipText() const override; 0322 // Drag and Drop Content: 0323 QPixmap feedbackPixmap(qreal width, qreal height) override; 0324 // Open Content or File: 0325 QString messageWhenOpening(OpenMessage where) override; 0326 QString customOpenCommand() override; 0327 // Content-Specific Methods: 0328 void setHtml(const QString &html, bool lazyLoad = false); /// << Change the HTML note-content and relayout the note. 0329 QString html() 0330 { 0331 return m_html; 0332 } /// << @return the HTML note-content. 0333 QGraphicsItem *graphicsItem() override 0334 { 0335 return &m_graphicsTextItem; 0336 } 0337 0338 protected: 0339 QString m_html; 0340 QString m_textEquivalent; // OPTIM_FILTER 0341 QGraphicsTextItem m_graphicsTextItem; 0342 }; 0343 0344 /** Real implementation of image notes: 0345 * @author Sébastien Laoût 0346 */ 0347 class BASKET_EXPORT ImageContent : public NoteContent 0348 { 0349 public: 0350 // Constructor and destructor: 0351 ImageContent(Note *parent, const QString &fileName, bool lazyLoad = false); 0352 ~ImageContent() override; 0353 // Simple Generic Methods: 0354 QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; 0355 QPixmap toPixmap() override; 0356 bool useFile() const override; 0357 bool canBeSavedAs() const override; 0358 QString saveAsFilters() const override; 0359 bool match(const FilterData &data) override; 0360 // Complex Generic Methods: 0361 void exportToHTML(HTMLExporter *exporter, int indent) override; 0362 QString cssClass() const override; 0363 qreal setWidthAndGetHeight(qreal width) override; 0364 bool loadFromFile(bool lazyLoad) override; 0365 bool finishLazyLoad() override; 0366 bool saveToFile() override; 0367 void fontChanged() override; 0368 QString editToolTipText() const override; 0369 QMap<QString, QString> toolTipInfos() override; 0370 // Drag and Drop Content: 0371 QPixmap feedbackPixmap(qreal width, qreal height) override; 0372 bool needSpaceForFeedbackPixmap() override 0373 { 0374 return true; 0375 } 0376 // Open Content or File: 0377 QString messageWhenOpening(OpenMessage where) override; 0378 QString customOpenCommand() override; 0379 // Content-Specific Methods: 0380 void setPixmap(const QPixmap &pixmap); /// << Change the pixmap note-content and relayout the note. 0381 QPixmap pixmap() 0382 { 0383 return m_pixmapItem.pixmap(); 0384 } /// << @return the pixmap note-content. 0385 QByteArray data(); 0386 QGraphicsItem *graphicsItem() override 0387 { 0388 return &m_pixmapItem; 0389 } 0390 0391 protected: 0392 QGraphicsPixmapItem m_pixmapItem; 0393 QByteArray m_format; 0394 }; 0395 0396 /** Real implementation of animated image (GIF, MNG) notes: 0397 * @author Sébastien Laoût 0398 */ 0399 class BASKET_EXPORT AnimationContent : public QObject, public NoteContent // QObject to be able to receive QMovie signals 0400 { 0401 Q_OBJECT 0402 public: 0403 // Constructor and destructor: 0404 AnimationContent(Note *parent, const QString &fileName, bool lazyLoad = false); 0405 ~AnimationContent() override; 0406 // Simple Generic Methods: 0407 QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; 0408 QPixmap toPixmap() override; 0409 bool useFile() const override; 0410 bool canBeSavedAs() const override; 0411 QString saveAsFilters() const override; 0412 bool match(const FilterData &data) override; 0413 void fontChanged() override; 0414 QString editToolTipText() const override; 0415 // Drag and Drop Content: 0416 QPixmap feedbackPixmap(qreal width, qreal height) override; 0417 bool needSpaceForFeedbackPixmap() override 0418 { 0419 return true; 0420 } 0421 // Complex Generic Methods: 0422 void exportToHTML(HTMLExporter *exporter, int indent) override; 0423 QString cssClass() const override; 0424 qreal setWidthAndGetHeight(qreal width) override; 0425 bool loadFromFile(bool lazyLoad) override; 0426 bool finishLazyLoad() override; 0427 bool saveToFile() override; 0428 // Open Content or File: 0429 QString messageWhenOpening(OpenMessage where) override; 0430 QString customOpenCommand() override; 0431 QGraphicsItem *graphicsItem() override 0432 { 0433 return &m_graphicsPixmap; 0434 } 0435 0436 // Content-Specific Methods: 0437 bool startMovie(); 0438 0439 protected Q_SLOTS: 0440 void movieUpdated(); 0441 void movieResized(); 0442 void movieFrameChanged(); 0443 0444 protected: 0445 QBuffer *m_buffer; 0446 QMovie *m_movie; 0447 qreal m_currentWidth; 0448 QGraphicsPixmapItem m_graphicsPixmap; 0449 }; 0450 0451 /** Real implementation of file notes: 0452 * @author Sébastien Laoût 0453 */ 0454 class BASKET_EXPORT FileContent : public QObject, public NoteContent 0455 { 0456 Q_OBJECT 0457 public: 0458 // Constructor and destructor: 0459 FileContent(Note *parent, const QString &fileName); 0460 ~FileContent() override; 0461 // Simple Generic Methods: 0462 QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; 0463 bool useFile() const override; 0464 bool canBeSavedAs() const override; 0465 QString saveAsFilters() const override; 0466 bool match(const FilterData &data) override; 0467 // Complex Generic Methods: 0468 void exportToHTML(HTMLExporter *exporter, int indent) override; 0469 QString cssClass() const override; 0470 qreal setWidthAndGetHeight(qreal width) override; 0471 bool loadFromFile(bool /*lazyLoad*/) override; 0472 void fontChanged() override; 0473 void linkLookChanged() override; 0474 QString editToolTipText() const override; 0475 QMap<QString, QString> toolTipInfos() override; 0476 // Drag and Drop Content: 0477 QPixmap feedbackPixmap(qreal width, qreal height) override; 0478 // Custom Zones: 0479 int zoneAt(const QPointF &pos) override; 0480 QRectF zoneRect(int zone, const QPointF & /*pos*/) override; 0481 QString zoneTip(int zone) override; 0482 Qt::CursorShape cursorFromZone(int zone) const override; 0483 // Content Edition: 0484 int xEditorIndent() override; 0485 // Open Content or File: 0486 QString messageWhenOpening(OpenMessage where) override; 0487 // Content-Specific Methods: 0488 void setFileName(const QString &fileName) override; /// << Reimplemented to be able to relayout the note. 0489 virtual LinkLook *linkLook() 0490 { 0491 return LinkLook::fileLook; 0492 } 0493 QGraphicsItem *graphicsItem() override 0494 { 0495 return &m_linkDisplayItem; 0496 } 0497 0498 protected: 0499 LinkDisplayItem m_linkDisplayItem; 0500 // File Preview Management: 0501 protected Q_SLOTS: 0502 void newPreview(const KFileItem &, const QPixmap &preview); 0503 void removePreview(const KFileItem &); 0504 void startFetchingUrlPreview(); 0505 0506 protected: 0507 KIO::PreviewJob *m_previewJob; 0508 }; 0509 0510 /** Real implementation of sound notes: 0511 * @author Sébastien Laoût 0512 */ 0513 class BASKET_EXPORT SoundContent : public FileContent // A sound is a file with just a bit different user interaction 0514 { 0515 Q_OBJECT 0516 public: 0517 // Constructor and destructor: 0518 SoundContent(Note *parent, const QString &fileName); 0519 // Simple Generic Methods: 0520 QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; 0521 bool useFile() const override; 0522 bool canBeSavedAs() const override; 0523 QString saveAsFilters() const override; 0524 bool match(const FilterData &data) override; 0525 QString editToolTipText() const override; 0526 // Complex Generic Methods: 0527 QString cssClass() const override; 0528 // Custom Zones: 0529 QString zoneTip(int zone) override; 0530 void setHoveredZone(int oldZone, int newZone) override; 0531 // Open Content or File: 0532 QString messageWhenOpening(OpenMessage where) override; 0533 QString customOpenCommand() override; 0534 // Content-Specific Methods: 0535 void setFileName(const QString &fileName) override; 0536 LinkLook *linkLook() override 0537 { 0538 return LinkLook::soundLook; 0539 } 0540 Phonon::MediaObject *music; 0541 private Q_SLOTS: 0542 void stateChanged(Phonon::State, Phonon::State); 0543 }; 0544 0545 /** Real implementation of link notes: 0546 * @author Sébastien Laoût 0547 */ 0548 class BASKET_EXPORT LinkContent : public QObject, public NoteContent 0549 { 0550 Q_OBJECT 0551 public: 0552 // Constructor and destructor: 0553 LinkContent(Note *parent, const QUrl &url, const QString &title, const QString &icon, bool autoTitle, bool autoIcon); 0554 ~LinkContent() override; 0555 // Simple Generic Methods: 0556 QString toText(const QString & /*cuttedFullPath*/) override; 0557 QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; 0558 void toLink(QUrl *url, QString *title, const QString &cuttedFullPath) override; 0559 bool useFile() const override; 0560 bool canBeSavedAs() const override; 0561 QString saveAsFilters() const override; 0562 bool match(const FilterData &data) override; 0563 // Complex Generic Methods: 0564 void exportToHTML(HTMLExporter *exporter, int indent) override; 0565 QString cssClass() const override; 0566 qreal setWidthAndGetHeight(qreal width) override; 0567 void saveToNode(QXmlStreamWriter &stream) override; 0568 void fontChanged() override; 0569 void linkLookChanged() override; 0570 QString editToolTipText() const override; 0571 QMap<QString, QString> toolTipInfos() override; 0572 // Drag and Drop Content: 0573 void serialize(QDataStream &stream) override; 0574 QPixmap feedbackPixmap(qreal width, qreal height) override; 0575 // Custom Zones: 0576 int zoneAt(const QPointF &pos) override; 0577 QRectF zoneRect(int zone, const QPointF & /*pos*/) override; 0578 QString zoneTip(int zone) override; 0579 Qt::CursorShape cursorFromZone(int zone) const override; 0580 QString statusBarMessage(int zone) override; 0581 // Open Content or File: 0582 QUrl urlToOpen(bool /*with*/) override; 0583 QString messageWhenOpening(OpenMessage where) override; 0584 // Content-Specific Methods: 0585 void setLink(const QUrl &url, const QString &title, const QString &icon, bool autoTitle, bool autoIcon); /// << Change the link and relayout the note. 0586 QUrl url() 0587 { 0588 return m_url; 0589 } /// << @return the URL of the link note-content. 0590 QString title() 0591 { 0592 return m_title; 0593 } /// << @return the displayed title of the link note-content. 0594 QString icon() 0595 { 0596 return m_icon; 0597 } /// << @return the displayed icon of the link note-content. 0598 bool autoTitle() 0599 { 0600 return m_autoTitle; 0601 } /// << @return if the title is auto-computed from the URL. 0602 bool autoIcon() 0603 { 0604 return m_autoIcon; 0605 } /// << @return if the icon is auto-computed from the URL. 0606 void startFetchingLinkTitle(); 0607 QGraphicsItem *graphicsItem() override 0608 { 0609 return &m_linkDisplayItem; 0610 } 0611 0612 protected: 0613 QUrl m_url; 0614 QString m_title; 0615 QString m_icon; 0616 bool m_autoTitle; 0617 bool m_autoIcon; 0618 LinkDisplayItem m_linkDisplayItem; 0619 QNetworkAccessManager *m_access_manager; 0620 QNetworkReply *m_reply; 0621 QByteArray m_httpBuff; ///< Accumulator for downloaded HTTP data with yet unknown encoding 0622 bool m_acceptingData; ///< When false, don't accept any HTTP data 0623 // File Preview Management: 0624 protected Q_SLOTS: 0625 void httpReadyRead(); 0626 void httpDone(QNetworkReply *reply); 0627 void newPreview(const KFileItem &, const QPixmap &preview); 0628 void removePreview(const KFileItem &); 0629 void startFetchingUrlPreview(); 0630 0631 protected: 0632 KIO::PreviewJob *m_previewJob; 0633 0634 private: 0635 void decodeHtmlTitle(); ///< Detect encoding of \p m_httpBuff and extract the title from HTML 0636 void endFetchingLinkTitle(); ///< Extract title and clear http buffer 0637 }; 0638 0639 /** Real implementation of cross reference notes: 0640 * Copied and modified from LinkContent. 0641 * @author Brian C. Milco 0642 */ 0643 class BASKET_EXPORT CrossReferenceContent : public QObject, public NoteContent 0644 { 0645 Q_OBJECT 0646 public: 0647 // Constructor and destructor: 0648 CrossReferenceContent(Note *parent, const QUrl &url, const QString &title, const QString &icon); 0649 ~CrossReferenceContent() override; 0650 // Simple Generic Methods: 0651 QString toText(const QString & /*cuttedFullPath*/) override; 0652 QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; 0653 void toLink(QUrl *url, QString *title, const QString &cuttedFullPath) override; 0654 bool useFile() const override; 0655 bool canBeSavedAs() const override; 0656 QString saveAsFilters() const override; 0657 bool match(const FilterData &data) override; 0658 // Complex Generic Methods: 0659 void exportToHTML(HTMLExporter *exporter, int indent) override; 0660 QString cssClass() const override; 0661 qreal setWidthAndGetHeight(qreal) override; 0662 void saveToNode(QXmlStreamWriter &stream) override; 0663 void fontChanged() override; 0664 void linkLookChanged() override; 0665 QString editToolTipText() const override; 0666 QMap<QString, QString> toolTipInfos() override; 0667 // Drag and Drop Content: 0668 void serialize(QDataStream &stream) override; 0669 QPixmap feedbackPixmap(qreal width, qreal height) override; 0670 // Custom Zones: 0671 int zoneAt(const QPointF &pos) override; 0672 QRectF zoneRect(int zone, const QPointF & /*pos*/) override; 0673 QString zoneTip(int zone) override; 0674 Qt::CursorShape cursorFromZone(int zone) const override; 0675 QString statusBarMessage(int zone) override; 0676 // Open Content or File: 0677 QUrl urlToOpen(bool /*with*/) override; 0678 QString messageWhenOpening(OpenMessage where) override; 0679 // Content-Specific Methods: 0680 void setLink(const QUrl &url, const QString &title, const QString &icon); /// << Change the link and relayout the note. 0681 void setCrossReference(const QUrl &url, const QString &title, const QString &icon); 0682 QUrl url() 0683 { 0684 return m_url; 0685 } /// << @return the URL of the link note-content. 0686 QString title() 0687 { 0688 return m_title; 0689 } /// << @return the displayed title of the link note-content. 0690 QString icon() 0691 { 0692 return m_icon; 0693 } /// << @return the displayed icon of the link note-content. 0694 0695 QGraphicsItem *graphicsItem() override 0696 { 0697 return &m_linkDisplayItem; 0698 } 0699 0700 protected: 0701 QUrl m_url; 0702 QString m_title; 0703 QString m_icon; 0704 LinkDisplayItem m_linkDisplayItem; 0705 }; 0706 0707 /** Real implementation of launcher notes: 0708 * @author Sébastien Laoût 0709 */ 0710 class BASKET_EXPORT LauncherContent : public NoteContent 0711 { 0712 public: 0713 // Constructor and destructor: 0714 LauncherContent(Note *parent, const QString &fileName); 0715 ~LauncherContent() override; 0716 // Simple Generic Methods: 0717 QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; 0718 void toLink(QUrl *url, QString *title, const QString &cuttedFullPath) override; 0719 bool useFile() const override; 0720 bool canBeSavedAs() const override; 0721 QString saveAsFilters() const override; 0722 bool match(const FilterData &data) override; 0723 // Complex Generic Methods: 0724 void exportToHTML(HTMLExporter *exporter, int indent) override; 0725 QString cssClass() const override; 0726 qreal setWidthAndGetHeight(qreal width) override; 0727 bool loadFromFile(bool /*lazyLoad*/) override; 0728 void fontChanged() override; 0729 QString editToolTipText() const override; 0730 QMap<QString, QString> toolTipInfos() override; 0731 // Drag and Drop Content: 0732 QPixmap feedbackPixmap(qreal width, qreal height) override; 0733 // Custom Zones: 0734 int zoneAt(const QPointF &pos) override; 0735 QRectF zoneRect(int zone, const QPointF & /*pos*/) override; 0736 QString zoneTip(int zone) override; 0737 Qt::CursorShape cursorFromZone(int zone) const override; 0738 // Open Content or File: 0739 QUrl urlToOpen(bool with) override; 0740 QString messageWhenOpening(OpenMessage where) override; 0741 // Content-Specific Methods: 0742 void setLauncher(const QString &name, const QString &icon, const QString &exec); /// << Change the launcher note-content and relayout the note. Normally called by loadFromFile (no save done). 0743 QString name() 0744 { 0745 return m_name; 0746 } /// << @return the URL of the launcher note-content. 0747 QString icon() 0748 { 0749 return m_icon; 0750 } /// << @return the displayed icon of the launcher note-content. 0751 QString exec() 0752 { 0753 return m_exec; 0754 } /// << @return the execute command line of the launcher note-content. 0755 // TODO: KService *service() ??? And store everything in thta service ? 0756 0757 QGraphicsItem *graphicsItem() override 0758 { 0759 return &m_linkDisplayItem; 0760 } 0761 0762 protected: 0763 QString m_name; // TODO: Store them in linkDisplay to gain place (idem for Link notes) 0764 QString m_icon; 0765 QString m_exec; 0766 LinkDisplayItem m_linkDisplayItem; 0767 }; 0768 0769 /** 0770 * 0771 */ 0772 class BASKET_EXPORT ColorItem : public QGraphicsItem 0773 { 0774 public: 0775 ColorItem(Note *parent, const QColor &color); 0776 // virtual ~ColorItem(); 0777 virtual QColor color() 0778 { 0779 return m_color; 0780 } 0781 virtual void setColor(const QColor &color); 0782 0783 QRectF boundingRect() const override; 0784 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override; 0785 0786 private: 0787 Note *m_note; 0788 QColor m_color; 0789 QRectF m_textRect; 0790 0791 static const int RECT_MARGIN; 0792 }; 0793 0794 /** Real implementation of color notes: 0795 * @author Sébastien Laoût 0796 */ 0797 class BASKET_EXPORT ColorContent : public NoteContent 0798 { 0799 public: 0800 // Constructor and destructor: 0801 ColorContent(Note *parent, const QColor &color); 0802 ~ColorContent() override; 0803 // Simple Generic Methods: 0804 QString toText(const QString & /*cuttedFullPath*/) override; 0805 QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; 0806 bool useFile() const override; 0807 bool canBeSavedAs() const override; 0808 QString saveAsFilters() const override; 0809 bool match(const FilterData &data) override; 0810 // Complex Generic Methods: 0811 void exportToHTML(HTMLExporter *exporter, int indent) override; 0812 QString cssClass() const override; 0813 qreal setWidthAndGetHeight(qreal width) override; 0814 void saveToNode(QXmlStreamWriter &stream) override; 0815 void fontChanged() override; 0816 QString editToolTipText() const override; 0817 QMap<QString, QString> toolTipInfos() override; 0818 // Drag and Drop Content: 0819 void serialize(QDataStream &stream) override; 0820 QPixmap feedbackPixmap(qreal width, qreal height) override; 0821 bool needSpaceForFeedbackPixmap() override 0822 { 0823 return true; 0824 } 0825 void addAlternateDragObjects(QMimeData *dragObject) override; 0826 // Content-Specific Methods: 0827 void setColor(const QColor &color); /// << Change the color note-content and relayout the note. 0828 QColor color() 0829 { 0830 return m_colorItem.color(); 0831 } /// << @return the color note-content. 0832 QGraphicsItem *graphicsItem() override 0833 { 0834 return &m_colorItem; 0835 } 0836 0837 protected: 0838 ColorItem m_colorItem; 0839 }; 0840 0841 /** 0842 * 0843 */ 0844 class BASKET_EXPORT UnknownItem : public QGraphicsItem 0845 { 0846 public: 0847 UnknownItem(Note *parent); 0848 0849 QRectF boundingRect() const override; 0850 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) override; 0851 0852 virtual QString mimeTypes() 0853 { 0854 return m_mimeTypes; 0855 } 0856 virtual void setMimeTypes(QString mimeTypes); 0857 virtual void setWidth(qreal width); 0858 0859 private: 0860 Note *m_note; 0861 QString m_mimeTypes; 0862 QRectF m_textRect; 0863 0864 static const qreal DECORATION_MARGIN; 0865 }; 0866 0867 /** Real implementation of unknown MIME-types dropped notes: 0868 * @author Sébastien Laoût 0869 */ 0870 class BASKET_EXPORT UnknownContent : public NoteContent 0871 { 0872 public: 0873 // Constructor and destructor: 0874 UnknownContent(Note *parent, const QString &fileName); 0875 ~UnknownContent() override; 0876 // Simple Generic Methods: 0877 QString toText(const QString & /*cuttedFullPath*/) override; 0878 QString toHtml(const QString &imageName, const QString &cuttedFullPath) override; 0879 bool useFile() const override; 0880 bool canBeSavedAs() const override; 0881 QString saveAsFilters() const override; 0882 bool match(const FilterData &data) override; 0883 // Complex Generic Methods: 0884 void exportToHTML(HTMLExporter *exporter, int indent) override; 0885 QString cssClass() const override; 0886 qreal setWidthAndGetHeight(qreal width) override; 0887 bool loadFromFile(bool /*lazyLoad*/) override; 0888 void fontChanged() override; 0889 QString editToolTipText() const override; 0890 // Drag and Drop Content: 0891 bool shouldSerializeFile() override 0892 { 0893 return false; 0894 } 0895 void addAlternateDragObjects(QMimeData *dragObject) override; 0896 QPixmap feedbackPixmap(qreal width, qreal height) override; 0897 bool needSpaceForFeedbackPixmap() override 0898 { 0899 return true; 0900 } 0901 // Open Content or File: 0902 QUrl urlToOpen(bool /*with*/) override 0903 { 0904 return QUrl(); 0905 } 0906 0907 QGraphicsItem *graphicsItem() override 0908 { 0909 return &m_unknownItem; 0910 } 0911 0912 // Content-Specific Methods: 0913 QString mimeTypes() 0914 { 0915 return m_unknownItem.mimeTypes(); 0916 } /// << @return the list of MIME types this note-content contains. 0917 private: 0918 UnknownItem m_unknownItem; 0919 }; 0920 0921 #endif // NOTECONTENT_H