1 #ifndef _KVI_IRCVIEW_H_ 2 #define _KVI_IRCVIEW_H_ 3 //============================================================================= 4 // 5 // File : KviIrcView.h 6 // Creation date : Fri Mar 19 1999 05:39:01 by Szymon Stefanek 7 // 8 // This file is part of the KVIrc IRC client distribution 9 // Copyright (C) 1999-2010 Szymon Stefanek (pragma at kvirc dot net) 10 // 11 // This program is FREE software. You can redistribute it and/or 12 // modify it under the terms of the GNU General Public License 13 // as published by the Free Software Foundation; either version 2 14 // of the License, or (at your option) any later version. 15 // 16 // This program is distributed in the HOPE that it will be USEFUL, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 // See the GNU General Public License for more details. 20 // 21 // You should have received a copy of the GNU General Public License 22 // along with this program. If not, write to the Free Software Foundation, 23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 24 // 25 //============================================================================= 26 27 #include "kvi_settings.h" 28 #include "KviCString.h" 29 30 #include <QToolButton> 31 #include <QWidget> 32 #include <QPixmap> // needed 33 #include <QMultiHash> 34 #include <QDateTime> 35 36 #include <vector> 37 38 class QScrollBar; 39 class QLineEdit; 40 class QFile; 41 class QFontMetrics; 42 class QMenu; 43 class QScreen; 44 45 class KviWindow; 46 class KviMainWindow; 47 class KviConsoleWindow; 48 class KviIrcViewToolWidget; 49 class KviIrcViewToolTip; 50 class KviAnimatedPixmap; 51 52 struct KviIrcViewLineChunk; 53 struct KviIrcViewWrappedBlock; 54 struct KviIrcViewLine; 55 struct KviIrcViewWrappedBlockSelectionInfo; 56 57 #define KVI_IRCVIEW_INVALID_LINE_MARK_INDEX 0xffffffff 58 59 class KVIRC_API KviIrcView : public QWidget 60 { 61 Q_OBJECT 62 Q_PROPERTY(int TransparencyCapable READ dummyRead) 63 // we cannot #ifdef due to a bug in moc 64 Q_PROPERTY(bool usePaintOnScreen READ getPaintOnScreen WRITE setPaintOnScreen) 65 public: 66 friend class KviIrcViewToolTip; 67 friend class KviIrcViewToolWidget; 68 69 public: 70 KviIrcView(QWidget * parent, KviWindow * pWnd); 71 ~KviIrcView(); 72 73 public: dummyRead()74 int dummyRead() const { return 0; }; getPaintOnScreen()75 bool getPaintOnScreen() const { return testAttribute(Qt::WA_PaintOnScreen); }; setPaintOnScreen(bool bFlag)76 void setPaintOnScreen(bool bFlag) { setAttribute(Qt::WA_PaintOnScreen, bFlag); }; 77 private: 78 // QDate m_lastLogDay; 79 int m_iFlushTimer; 80 KviIrcViewLine * m_pFirstLine; 81 KviIrcViewLine * m_pCurLine; // Bottom line in the view 82 KviIrcViewLine * m_pLastLine; 83 KviIrcViewLine * m_pCursorLine; 84 unsigned int m_uLineMarkLineIndex; 85 QRect m_lineMarkArea; 86 87 // Highliting of links 88 KviIrcViewWrappedBlock * m_pLastLinkUnderMouse; 89 int m_iLastLinkRectTop; 90 int m_iLastLinkRectHeight; 91 92 int m_iNumLines; 93 int m_iMaxLines; 94 95 unsigned int m_uNextLineIndex; 96 97 QPixmap * m_pPrivateBackgroundPixmap; 98 QScrollBar * m_pScrollBar; 99 QToolButton * m_pToolsButton; 100 QMenu * m_pToolsPopup; 101 102 KviIrcViewToolWidget * m_pToolWidget; 103 104 int m_iLastScrollBarValue; 105 106 // Font related stuff (needs precalculation!) 107 int m_iFontLineSpacing; 108 int m_iFontLineWidth; 109 int m_iFontDescent; 110 int m_iFontCharacterWidth[256]; //1024 bytes fixed 111 bool m_bUseRealBold; 112 113 int m_iWrapMargin; 114 int m_iMinimumPaintWidth; 115 int m_iRelativePixmapY; 116 int m_iIconWidth; 117 int m_iIconSideSpacing; 118 119 // Selection 120 KviIrcViewLine * m_pSelectionInitLine; 121 KviIrcViewLine * m_pSelectionEndLine; 122 int m_iSelectionInitCharIndex; 123 int m_iSelectionEndCharIndex; 124 int m_iSelectTimer; 125 126 bool m_bMouseIsDown; 127 bool m_bShiftPressed; 128 bool m_bCtrlPressed; 129 130 bool m_bSkipScrollBarRepaint; 131 int m_iMouseTimer; 132 KviWindow * m_pKviWindow; 133 KviIrcViewWrappedBlockSelectionInfo * m_pWrappedBlockSelectionInfo; 134 QFile * m_pLogFile; 135 KviMainWindow * m_pFrm; 136 bool m_bAcceptDrops; 137 int m_iUnprocessedPaintEventRequests; 138 bool m_bPostedPaintEventPending; 139 std::vector<KviIrcViewLine *> m_pMessagesStoppedWhileSelecting; 140 KviIrcView * m_pMasterView; 141 QFontMetrics * m_pFm; // assume this valid only inside a paint event (may be 0 in other circumstances) 142 143 QMouseEvent * m_pLastEvent; 144 qint64 m_iLastMouseClickTime; 145 146 KviIrcViewToolTip * m_pToolTip; 147 bool m_bHaveUnreadedHighlightedMessages; 148 bool m_bHaveUnreadedMessages; 149 150 QMultiHash<KviIrcViewLine *, KviAnimatedPixmap *> m_hAnimatedSmiles; 151 152 public: 153 void clearUnreaded(); 154 void applyOptions(); 155 void enableDnd(bool bEnable); haveUnreadedMessages()156 bool haveUnreadedMessages() { return m_bHaveUnreadedMessages; }; haveUnreadedHighlightedMessages()157 bool haveUnreadedHighlightedMessages() { return m_bHaveUnreadedHighlightedMessages; }; 158 enum AppendTextFlags 159 { 160 NoRepaint = 1, 161 NoTimestamp = 2, 162 SetLineMark = 4, 163 TriggersNotification = 8 164 }; 165 void appendText(int msg_type, const kvi_wchar_t * data_ptr, int iFlags = 0, const QDateTime & datetime = QDateTime()); 166 void clearLineMark(bool bRepaint = false); hasLineMark()167 bool hasLineMark() { return m_uLineMarkLineIndex != KVI_IRCVIEW_INVALID_LINE_MARK_INDEX; }; 168 void removeHeadLine(bool bRepaint = false); 169 void emptyBuffer(bool bRepaint = true); 170 void getTextBuffer(QString & buffer); 171 void setMaxBufferSize(int maxBufSize, bool bRepaint = true); maxBufferSize()172 int maxBufferSize() { return m_iMaxLines; }; //Never used ? 173 bool saveBuffer(const char * filename); 174 void findNext(const QString & szText, bool bCaseS = false, bool bRegExp = false, bool bExtended = false); 175 void findPrev(const QString & szText, bool bCaseS = false, bool bRegExp = false, bool bExtended = false); parentKviWindow()176 KviWindow * parentKviWindow() { return m_pKviWindow; }; 177 KviConsoleWindow * console(); 178 // A null pixmap passed here unsets the private backgrdound. 179 void setPrivateBackgroundPixmap(const QPixmap & pixmap, bool bRepaint = true); getPrivateBackgroundPixmap()180 QPixmap * getPrivateBackgroundPixmap() const { return m_pPrivateBackgroundPixmap; }; hasPrivateBackgroundPixmap()181 bool hasPrivateBackgroundPixmap() { return (m_pPrivateBackgroundPixmap != nullptr); }; 182 183 // Logging 184 // Stops previous logging session too... 185 bool startLogging(const QString & fname = QString(), bool bPrependCurBuffer = false); 186 void stopLogging(); isLogging()187 bool isLogging() { return (m_pLogFile != nullptr); }; 188 void getLogFileName(QString & buffer); 189 void add2Log(const QString & szBuffer, const QDateTime & date, int iMsgType, bool bPrependDate); 190 191 // Channel view splitting 192 void setMasterView(KviIrcView * v); 193 void splitMessagesTo(KviIrcView * v); 194 void joinMessagesFrom(KviIrcView * v); 195 void appendMessagesFrom(KviIrcView * v); 196 lastMouseClickTime()197 qint64 lastMouseClickTime() const { return m_iLastMouseClickTime; } 198 199 // Return true if the specified message type should be "split" to the user message specific view. 200 bool messageShouldGoToMessageView(int iMsgType); 201 202 void prevLine(); 203 void nextLine(); 204 void nextPage(); 205 void prevPage(); 206 void scrollTop(); 207 void scrollBottom(); 208 QSize sizeHint() const override; 209 const QString & lastLineOfText(); 210 const QString & lastMessageText(); 211 void setFont(const QFont & f); 212 void scrollToMarker(); 213 214 protected: 215 void paintEvent(QPaintEvent *) override; 216 void resizeEvent(QResizeEvent *) override; 217 void mousePressEvent(QMouseEvent * e) override; 218 void mouseReleaseEvent(QMouseEvent *) override; 219 void mouseDoubleClickEvent(QMouseEvent * e) override; 220 void mouseMoveEvent(QMouseEvent * e) override; 221 void timerEvent(QTimerEvent * e) override; 222 void dragEnterEvent(QDragEnterEvent * e) override; 223 void dropEvent(QDropEvent * e) override; 224 void showEvent(QShowEvent * e) override; 225 bool event(QEvent * e) override; 226 void wheelEvent(QWheelEvent * e) override; 227 void keyPressEvent(QKeyEvent * e) override; 228 void maybeTip(const QPoint & pnt); 229 void leaveEvent(QEvent *) override; 230 231 private: 232 void triggerMouseRelatedKvsEvents(QMouseEvent * e); 233 void setCursorLine(KviIrcViewLine * l); 234 void ensureLineVisible(KviIrcViewLine * pLineToShow); 235 KviIrcViewLine * getVisibleLineAt(int yPos); 236 int getVisibleCharIndexAt(KviIrcViewLine * line, int xPos, int yPos); 237 void getLinkEscapeCommand(QString & buffer, const QString & escape_cmd, const QString & escape_label); 238 void appendLine(KviIrcViewLine * ptr, const QDateTime & date, bool bRepaint); 239 void postUpdateEvent(); 240 void fastScroll(int lines = 1); 241 const kvi_wchar_t * getTextLine(int msg_type, const kvi_wchar_t * data_ptr, KviIrcViewLine * line_ptr, bool bEnableTimeStamp = true, const QDateTime & datetime = QDateTime()); 242 void calculateLineWraps(KviIrcViewLine * ptr, int maxWidth); 243 void recalcFontVariables(const QFont & font, const QFontInfo & fi); 244 bool checkSelectionBlock(KviIrcViewLine * line, int bufIndex); 245 KviIrcViewWrappedBlock * getLinkUnderMouse(int xPos, int yPos, QRect * pRect = nullptr, QString * linkCmd = nullptr, QString * linkText = nullptr); 246 void doLinkToolTip(const QRect & rct, QString & linkCmd, QString & linkText); 247 void doMarkerToolTip(); 248 bool checkMarkerArea(const QPoint & mousePos); 249 void addControlCharacter(KviIrcViewLineChunk * pC, QString & szSelectionText); 250 void reapplyMessageColors(); 251 public slots: 252 void flushLog(); 253 void showToolsPopup(); 254 void clearBuffer(); 255 void toggleToolWidget(); 256 void increaseFontSize(); 257 void decreaseFontSize(); 258 void resetDefaultFont(); 259 void chooseFont(); 260 void chooseBackground(); 261 void resetBackground(); 262 protected slots: 263 virtual void scrollBarPositionChanged(int newValue); 264 void screenChanged(QScreen *); 265 void masterDead(); 266 void animatedIconChange(); 267 signals: 268 void rightClicked(); 269 void dndEntered(); 270 void fileDropped(const QString &); 271 }; 272 273 #endif //_KVI_IRCVIEW_H_ 274