1 /***************************************************************************
2 * Copyright (C) 2005-2018 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
26 #include <QTextCharFormat>
28 #include "abstractitemview.h"
30 #include "buffermodel.h"
31 #include "bufferinfo.h"
35 #include "ui_inputwidget.h"
39 class InputWidget : public AbstractItemView
44 InputWidget(QWidget *parent = 0);
45 virtual ~InputWidget();
47 const Network *currentNetwork() const;
49 inline MultiLineEdit *inputLine() const { return ui.inputEdit; }
53 * Apply the active color to the selected or typed text
55 * Active color is chosen using the UI menu.
57 void applyFormatActiveColor();
60 * Apply the active fill color to the selected or typed text background
62 * Fill color is chosen using the UI menu.
64 void applyFormatActiveColorFill();
67 * Toggle the boldness of the selected or typed text
69 * Bold becomes normal, and normal becomes bold.
71 void toggleFormatBold();
74 * Toggle the italicness of the selected or typed text
76 * Italicized becomes normal, and normal becomes italicized.
78 void toggleFormatItalic();
81 * Toggle the underlining of the selected or typed text
83 * Underlined becomes normal, and normal becomes underlined.
85 void toggleFormatUnderline();
88 * Clear the formatting of the selected or typed text
90 * Clears the font weight (bold, italic, underline) and foreground/background coloring.
95 virtual bool eventFilter(QObject *watched, QEvent *event);
98 virtual void currentChanged(const QModelIndex ¤t, const QModelIndex &previous);
99 virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
100 virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
103 void setCustomFont(const QVariant &font);
104 void setUseCustomFont(const QVariant &);
105 void setEnableSpellCheck(const QVariant &);
106 void setEnableEmacsMode(const QVariant &);
107 void setShowNickSelector(const QVariant &);
108 void setShowStyleButtons(const QVariant &);
109 void setEnablePerChatHistory(const QVariant &);
110 void setMaxLines(const QVariant &);
111 void setLineWrapEnabled(const QVariant &);
112 void setMultiLineEnabled(const QVariant &);
113 void setScrollBarsEnabled(const QVariant &);
114 void onTextEntered(const QString &text);
115 void changeNick(const QString &newNick) const;
117 void setNetwork(NetworkId networkId);
118 void setIdentity(IdentityId identityId);
119 void connectMyIrcUser();
120 void updateNickSelector() const;
121 void updateEnabledState();
123 BufferInfo currentBufferInfo() const;
126 * Set whether or not the style options frame is expanded
128 * @param visible If true, expand the style options frame, otherwise collapse it
130 void setStyleOptionsExpanded(const bool visible);
132 void currentCharFormatChanged(const QTextCharFormat &format);
133 void on_showStyleButton_toggled(bool checked);
134 void on_boldButton_clicked(bool checked);
135 void on_italicButton_clicked(bool checked);
136 void on_underlineButton_clicked(bool checked);
137 void colorChosen(QAction *action);
138 void colorHighlightChosen(QAction *action);
142 * Clear the formatting of the text, globally or selected text only
144 * Clears the font weight (bold, italic, underline) and foreground/background coloring.
146 * @param global If true, clear all text formatting, otherwise only clear selected text
148 void setFormatClear(const bool global = false);
151 * Sets the boldness of the selected or typed text
153 * @param bold If true, set text bold, otherwise set text normal
155 void setFormatBold(const bool bold);
158 * Sets the italicness of the selected or typed text
160 * @param bold If true, set text italic, otherwise set text normal
162 void setFormatItalic(const bool italic);
165 * Sets the underline of the selected or typed text
167 * @param bold If true, set text underlined, otherwise set text normal
169 void setFormatUnderline(const bool underline);
173 NetworkId _networkId;
174 IdentityId _identityId;
175 QMenu *_colorMenu, *_colorFillMenu;
177 void mergeFormatOnSelection(const QTextCharFormat &format);
178 void fontChanged(const QFont &f);
179 QIcon createColorToolButtonIcon(const QIcon &icon, const QColor &color);
180 QTextCharFormat getFormatOfWordOrSelection();
181 void setFormatOnSelection(const QTextCharFormat &format);
183 bool _perChatHistory;
184 struct HistoryState {
186 QHash<int, QString> tempHistory;
189 inline HistoryState() : idx(0) {};
192 QMap<BufferId, HistoryState> historyMap;
196 class MouseWheelFilter : public QObject
201 MouseWheelFilter(QObject *parent = 0);
202 virtual bool eventFilter(QObject *obj, QEvent *event);