File indexing completed on 2024-04-28 04:55:41
0001 /* 0002 This file is part of Choqok, the KDE micro-blogging client 0003 0004 SPDX-FileCopyrightText: 2008-2012 Mehrdad Momeny <mehrdad.momeny@gmail.com> 0005 0006 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0007 */ 0008 0009 #ifndef POSTWIDGET_H 0010 #define POSTWIDGET_H 0011 0012 #include <QDateTime> 0013 0014 #include "account.h" 0015 #include "choqoktypes.h" 0016 #include "microblog.h" 0017 0018 class QAction; 0019 class QPushButton; 0020 0021 namespace Choqok 0022 { 0023 namespace UI 0024 { 0025 0026 class TextBrowser; 0027 0028 /** 0029 Post Widget! 0030 Attribute "Qt::WA_DeleteOnClose" is enabled at construtor! So please use close() for deleting an object, instead of deleteLater() or delete 0031 0032 @author Mehrdad Momeny \<mehrdad.momeny@gmail.com\> 0033 */ 0034 class CHOQOK_EXPORT PostWidget : public QWidget 0035 { 0036 Q_OBJECT 0037 Q_PROPERTY(bool read READ isRead) 0038 public: 0039 explicit PostWidget(Choqok::Account *account, Choqok::Post *post, QWidget *parent = nullptr); 0040 virtual ~PostWidget(); 0041 Post *currentPost() const; 0042 virtual void setRead(bool read = true); 0043 0044 /** 0045 Sets post widget as read, and emits postReaded() signal 0046 */ 0047 void setReadWithSignal(); 0048 0049 virtual bool isRead() const; 0050 0051 Account *currentAccount(); 0052 /** 0053 Setup UI elements 0054 @Note Should call from outside of class, To initialize drived class items too! 0055 */ 0056 virtual void initUi(); 0057 0058 /** 0059 Set stylesheet data with new color data! to use later. 0060 0061 @see setUiStyle() 0062 */ 0063 static void setStyle(const QColor &unreadColor, const QColor &unreadBack, 0064 const QColor &readColor, const QColor &readBack, 0065 const QColor &ownColor, const QColor &ownBack, 0066 const QFont &font); 0067 0068 /** 0069 @brief Set current post 0070 0071 @note Use with care! 0072 0073 After changing current post, Don't forget to call @ref initUi() to update post UI. 0074 */ 0075 void setCurrentPost(Post *post); 0076 0077 /** 0078 @brief Sets Post sign 0079 sign is the text that showed as sign of this post under post content. 0080 */ 0081 void setSign(const QString &sign); 0082 0083 /** 0084 @return post sign 0085 sign is an html text that showed as sign of this post under post content. 0086 */ 0087 QString sign() const; 0088 0089 /** 0090 @brief Sets post content 0091 Post content is an html text that showed as post text. 0092 */ 0093 void setContent(const QString &content); 0094 0095 /** 0096 @return post content 0097 Post content is an html text that showed as post text. 0098 */ 0099 QString content() const; 0100 0101 void deleteLater(); 0102 0103 TextBrowser *mainWidget(); 0104 0105 QStringList urls(); 0106 0107 TimelineWidget *timelineWidget() const; 0108 0109 /** 0110 * Plugins can add status specific actions and process them internally 0111 * 0112 */ 0113 static void addAction(QAction *action); 0114 0115 static QString getBaseStyle(); 0116 0117 public Q_SLOTS: 0118 /** 0119 Set Style sheet of widget to corresponding data-> 0120 @see setStyle() 0121 */ 0122 void setUiStyle(); 0123 0124 Q_SIGNALS: 0125 /** 0126 Emit and contain text to resend. 0127 */ 0128 void resendPost(const QString &text); 0129 /** 0130 Emit when this post has been readed by pressing mouse on it, And to notify TimelineWidget about it. 0131 */ 0132 void postReaded(); 0133 /** 0134 Carry reply information, to reply to a post. 0135 */ 0136 void reply(const QString &txt, const QString &replyToId, const QString &replyToUsername); 0137 0138 /** 0139 Emitted when this widget is about to close! 0140 postId and this returned! 0141 */ 0142 void aboutClosing(const QString &postId, PostWidget *widget); 0143 0144 protected Q_SLOTS: 0145 0146 virtual void checkAnchor(const QUrl &url); 0147 /** 0148 Set height of widget related to text contents 0149 */ 0150 virtual void setHeight(); 0151 0152 /** 0153 Update UI after changes, such as timestamp 0154 */ 0155 virtual void updateUi(); 0156 0157 /** 0158 Call microblog() to remove this post! 0159 */ 0160 virtual void removeCurrentPost(); 0161 /** 0162 Prepare text to send for resending this post. 0163 */ 0164 virtual void slotResendPost(); 0165 /** 0166 Internal slot to remove/close/destroy this post after bing deleted 0167 */ 0168 void slotCurrentPostRemoved(Choqok::Account *theAccount, Choqok::Post *post); 0169 0170 virtual void slotPostError(Choqok::Account *theAccount, Choqok::Post *post, 0171 Choqok::MicroBlog::ErrorType error, const QString &errorMessage); 0172 0173 void avatarFetchError(const QUrl &remoteUrl, const QString &errMsg); 0174 void avatarFetched(const QUrl &remoteUrl, const QPixmap &pixmap); 0175 0176 void slotImageFetched(const QUrl &remoteUrl, const QPixmap &pixmap); 0177 virtual void mousePressEvent(QMouseEvent *ev) override; 0178 0179 protected: 0180 virtual void setupUi(); 0181 virtual void closeEvent(QCloseEvent *event) override; 0182 virtual void setupAvatar(); 0183 virtual void fetchImage(); 0184 virtual void wheelEvent(QWheelEvent *) override; 0185 virtual void resizeEvent(QResizeEvent *event) override; 0186 virtual void enterEvent(QEvent *event) override; 0187 virtual void leaveEvent(QEvent *event) override; 0188 virtual QString prepareStatus(const QString &text); 0189 QLatin1String getDirection(QString text); 0190 virtual QString generateSign(); 0191 virtual QString formatDateTime(const QDateTime &time); 0192 virtual bool isResendAvailable() ; 0193 virtual bool isRemoveAvailable() ; 0194 virtual bool isOwnPost(); 0195 virtual QString removeTags(const QString &text) const; 0196 /** 0197 @brief Create and Add a new button to widget 0198 This function will add button to UI! 0199 @return added button, for some managements such as connect to a slot 0200 */ 0201 QPushButton *addButton(const QString &objName, const QString &toolTip, const QString &icon); 0202 QPushButton *addButton(const QString &objName, const QString &toolTip, const QIcon &icon); 0203 QMap<QString, QPushButton *> &buttons(); 0204 0205 QString getUsernameHyperlink(const Choqok::User &user) const; 0206 0207 protected: 0208 TextBrowser *_mainWidget; 0209 static const QString baseStyle; 0210 static QString readStyle; 0211 static QString unreadStyle; 0212 static QString ownStyle; 0213 static const QString webIconText; 0214 static const QString hrefTemplate; 0215 static const QString baseTextTemplate; 0216 static const QRegExp dirRegExp; 0217 0218 void setAvatarText(const QString &text); 0219 QString avatarText() const; 0220 void setExtraContents(const QString &text); 0221 QString extraContents() const; 0222 virtual QString generateResendText(); 0223 void updatePostImage(int width); 0224 0225 private: 0226 class Private; 0227 Private *const d; 0228 }; 0229 0230 class CHOQOK_EXPORT PostWidgetUserData : public QObjectUserData 0231 { 0232 public: 0233 PostWidgetUserData(PostWidget *postWidget); 0234 virtual ~PostWidgetUserData(); 0235 PostWidget *postWidget(); 0236 void setPostWidget(PostWidget *widget); 0237 0238 private: 0239 class Private; 0240 Private *const d; 0241 }; 0242 0243 } 0244 } 0245 #endif // POSTWIDGET_H