2
This program is free software; you can redistribute it and/or modify
3
it under the terms of the GNU General Public License as published by
4
the Free Software Foundation; either version 2 of the License, or
5
(at your option) any later version.
9
Copyright (C) 2002 Dario Abatianni <eisfuchs@tigress.com>
10
Copyright (C) 2005-2006 Peter Simonsson <psn@linux.se>
11
Copyright (C) 2006-2008 Eike Hein <hein@kde.org>
19
#include <QFontDatabase>
22
#include <KTextBrowser>
32
#include <QAbstractTextDocumentLayout>
34
class IrcViewMarkerLine: public QObject, public QTextObjectInterface
37
Q_INTERFACES(QTextObjectInterface)
40
IrcViewMarkerLine(QObject *p) : QObject(p), QTextObjectInterface() {}
41
~IrcViewMarkerLine() {}
42
virtual void drawObject(QPainter *painter, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format);
43
virtual QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format);
47
class IRCView : public KTextBrowser
52
IRCView(QWidget* parent,Server* newServer);
56
//! Some people apparently want the text in the view to be doublespaced :/
57
void enableParagraphSpacing();
59
//! this function is proper given it is not nessary for the ircview to have a server for DCC.
60
void setServer(Server* server);
61
//! FIXME assumes the IRCView looks at a chatwin
62
void setChatWin(ChatWindow* chatWin);
64
// Returns the current nick under context menu.
65
const QString& getContextNick() const;
67
//!Obtain the context menu popup in order to add things to it
68
KMenu* getPopup() const;
71
bool search(const QString& pattern, bool caseSensitive, bool wholeWords, bool forward, bool fromCursor);
72
bool searchNext(bool reversed = false);
74
//! FIXME maybe we should create some sort of palette of our own?
75
QColor highlightColor() { return m_highlightColor; }
77
void updateAppearance();
79
QString currentChannel() { return m_currentChannel; }
81
void setNickAndChannelContextMenusEnabled(bool enable);
85
void gotFocus(); // So we can set focus to input line
86
void textToLog(const QString& text); ///< send the to the log file
87
void sendFile(); ///< a command for a target to which we can DCC send
88
void extendedPopup(int id); ///< this is for the query/nickname popup
89
void autoText(const QString& text); ///< helper for autotext-on-highlight
90
void textPasted(bool useSelection); ///< middle button with no m_copyUrlMenu
91
void popupCommand(int); ///< wired to all of the popup menus
92
void urlsDropped(const KUrl::List urls);
93
void doSearch(); /// Emitted when a search should be started
94
void doSearchNext(); /// Emitted when there's a request to go to the next search result.
95
void doSearchPrevious(); /// Emitted when there's a request to go to the previous search result.
97
void setStatusBarTempText(const QString&); //! these two look like mixins to me
98
void clearStatusBarTempText();//! these two look like mixins to me
103
/// Are there any markers or a remember lines in the view?
104
///Is used internally now.
107
/// QTextBlockFormat states for setUserState.
108
enum BlockStates { None = -1, BlockIsMarker = 1, BlockIsRemember = 2 };
110
/// QTextCharFormat object types.
111
enum ObjectFormats { MarkerLine = QTextFormat::UserObject, RememberLine};
114
/// Inserts a marker line.
115
/// Does not disturb m_rememberLineDirtyBit.
116
void insertMarkerLine();
118
/// Insert a remember line now, or when text is appended. Sets the m_rememberLineDirtyBit
119
/// unless configured to add a remember line at any time.
120
void insertRememberLine();
122
/// Prevents the next append from inserting a remember line.
123
///Simply clears m_rememberLineDirtyBit.
124
void cancelRememberLine();
126
/// Remove all of the marker lines, and the remember line.
127
/// Does not effect m_rememberLineDirtyBit.
131
virtual QMimeData* createMimeDataFromSelection() const;
132
virtual void dragEnterEvent(QDragEnterEvent* e);
133
virtual void dragMoveEvent(QDragMoveEvent* e);
134
virtual void dropEvent(QDropEvent* e);
137
/// The internal mechanics of inserting a line.
138
/// Clears m_rememberLineDirtyBit.
139
void appendRememberLine();
141
/// Create a remember line and insert it.
142
void appendLine(ObjectFormats=MarkerLine);
144
/// Forget the position of the remember line and markers.
145
void wipeLineParagraphs();
147
/// Convenience method - is the last block any sort of line, or a specific line?
148
/// @param select - default value is -1, meaning "is any kind of line"
149
bool lastBlockIsLine(int select=-1);
151
/// Causes a block to stop being a marker.
152
void voidLineBlock(QTextBlock rem);
154
/// Shortcut to get an object format of the desired type
155
QTextCharFormat getFormat(ObjectFormats);
158
/** Called to see if a marker is queued up for deletion. Only triggers if
159
"where" is the beginning and there was nothing added.
161
void cullMarkedLine(int, int, int);
163
private: //marker/remember line data
164
bool m_nextCullIsMarker; ///< the next time a cull occurs, it'll be a marker
165
QList<QTextBlock> m_markers; ///< what blocks are markers?
166
int m_rememberLinePosition; ///< position of remember line in m_markers
167
bool m_rememberLineDirtyBit; ///< the next append needs a remember line
168
IrcViewMarkerLine markerFormatObject; ///< a QTextObjectInterface
172
//! FIXME enum { Raw, Query, Query+Action, Channel+Action, Server Message, Command Message, Backlog message } this looks more like a tuple
173
void append(const QString& nick, const QString& message);
174
void appendRaw(const QString& message, bool suppressTimestamps=false, bool self = false);
175
void appendLog(const QString& message);
177
void appendQuery(const QString& nick, const QString& message, bool inChannel = false);
178
void appendQueryAction(const QString& nick, const QString& message);
180
//! FIXME why is this protected, and all alone down there?
181
void appendAction(const QString& nick, const QString& message);
183
/// Appends a new line without any scrollback or notification checks
184
void doRawAppend(const QString& newLine, bool rtl);
187
void appendChannelAction(const QString& nick, const QString& message);
189
void appendServerMessage(const QString& type, const QString& message, bool parseURL = true);
190
void appendCommandMessage(const QString& command, const QString& message, bool important, bool parseURL=true, bool self=false);
191
void appendBacklogMessage(const QString& firstColumn, const QString& message);
194
void doAppend(const QString& line, bool rtl, bool self=false);
196
void updateNickMenuEntries(const QString& nickname);
199
/// Emits the doSeach signal.
201
/// Emits the doSeachNext signal.
203
/// Emits the doSeachPrevious signal.
204
void findPreviousText();
206
//! FIXME eh? what is this?
207
void setCurrentChannel(const QString& channel) { m_currentChannel = channel; }
209
/// Overwritten so the scrollview remains not freaked out
210
//virtual void removeSelectedText(int selNum=0);
211
//! TODO FIXME meta, derived
212
//virtual void scrollToBottom(); // Overwritten for internal reasons
214
// Clears context nick
215
//! The name of this method is unclear enough that it needs documentation, but clear enough that the documentation just needs to be a repeat of the name. Thanks for playing, but get some kills next time.
216
void clearContextNick();
218
// Updates the scrollbar position
219
//! Again. Really? Two in a row? Couldn't be more inventive, whoever you are? Come on, show some personality. Let your vocabulary loose! Because right now its looking like you don't know what you're taking about.
220
//void updateScrollBarPos();
223
void highlightedSlot(const QString& link);
225
void anchorClicked(const QUrl& url);
228
void handleContextActions();
231
void openLink(const QUrl &url);
233
QString filter(const QString& line, const QString& defaultColor, const QString& who=NULL, bool doHighlight=true, bool parseURL=true, bool self=false);
235
void replaceDecoration(QString& line,char decoration,char replacement);
237
virtual void resizeEvent(QResizeEvent *event);
238
virtual void mouseReleaseEvent(QMouseEvent* ev);
239
virtual void mousePressEvent(QMouseEvent* ev);
240
virtual void mouseMoveEvent(QMouseEvent* ev);
241
virtual void keyPressEvent(QKeyEvent* ev);
242
virtual void contextMenuEvent(QContextMenuEvent* ev);
244
bool contextMenu(QContextMenuEvent* ce);
246
void setupNickPopupMenu(bool isQuery);
247
void updateNickMenuEntries(KMenu* popup, const QString& nickname);
248
void setupChannelPopupMenu();
250
QChar::Direction basicDirection(const QString &string);
252
/// Returns a formated timestamp if timestamps are enabled else it returns QString::null
255
/// Returns a formated nick string
256
//! FIXME formatted in what way?
257
QString createNickLine(const QString& nick, const QString& defaultColor,
258
bool encapsulateNick = true, bool privMsg = false);
263
QTextDocument::FindFlags m_searchFlags;
268
QColor m_highlightColor;
271
QString m_lastStatusText; //last sent status text to the statusbar. Is empty after clearStatusBarTempText()
273
bool m_resetScrollbar; ///< decide if we should place the scrollbar at the bottom on show()
276
QString m_autoTextToSend;
278
//TODO FIXME light this on fire and send it sailing down an uncharted river riddled with arrows
279
Konversation::TabNotifyType m_tabNotification;
282
//QString m_buffer; ///< our text
283
Server* m_server; //! FIXME assumes we have a server
286
KMenu* m_popup; ///< text area context menu
287
QAction* copyUrlMenuSeparator;
288
QAction* m_copyUrlClipBoard;
291
KToggleAction* m_ignoreAction;
292
QAction* m_addNotifyAction;
293
bool m_copyUrlMenu; ///<the menu we're popping up, is it for copying URI?
294
KMenu* m_nickPopup; ///<menu to show when context-click on a nickname
295
KMenu* m_channelPopup; ///<menu to show when context-click on a channel
298
QString m_urlToCopy; ///< the URL we might be about to copy
309
//// Nickname colorization
311
QStringList m_colorList;
313
QString m_currentNick;
314
QString m_currentChannel;
315
bool m_isOnNick; ///< context menu click hit a nickname
316
bool m_isOnChannel; ///< context menu click hit a channel
317
bool m_mousePressed; ///< currently processing a mouse press
318
QString m_urlToDrag; ///< we took a stab at whatever was clicked on, may or may not actually be a URL
319
QPoint m_pressPosition; ///< x,y of the click, relative to the GPS location of tip of Phantom's left ear
321
//! TODO FIXME i'll bite. why do we have this in here?
322
QFontDatabase m_fontDataBase;
324
ChatWindow* m_chatWin;
325
friend class IRCStyleSheet;