client: Add input tooltips, clear format, cleanup
[quassel.git] / src / qtui / inputwidget.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2018 by the Quassel Project                        *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                           *
9  *                                                                         *
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.                          *
14  *                                                                         *
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  ***************************************************************************/
20
21 #ifndef INPUTWIDGET_H
22 #define INPUTWIDGET_H
23
24 #include "ui_inputwidget.h"
25
26 #include "abstractitemview.h"
27 #include "buffermodel.h"
28 #include "bufferinfo.h"
29 #include "identity.h"
30 #include "network.h"
31 #include <action.h>
32
33 class MultiLineEdit;
34
35 class InputWidget : public AbstractItemView
36 {
37     Q_OBJECT
38
39 public:
40     InputWidget(QWidget *parent = 0);
41     virtual ~InputWidget();
42
43     const Network *currentNetwork() const;
44
45     inline MultiLineEdit *inputLine() const { return ui.inputEdit; }
46
47 public slots:
48     /**
49      * Apply the active color to the selected or typed text
50      *
51      * Active color is chosen using the UI menu.
52      */
53     void applyFormatActiveColor();
54
55     /**
56      * Apply the active fill color to the selected or typed text background
57      *
58      * Fill color is chosen using the UI menu.
59      */
60     void applyFormatActiveColorFill();
61
62     /**
63      * Toggle the boldness of the selected or typed text
64      *
65      * Bold becomes normal, and normal becomes bold.
66      */
67     void toggleFormatBold();
68
69     /**
70      * Toggle the italicness of the selected or typed text
71      *
72      * Italicized becomes normal, and normal becomes italicized.
73      */
74     void toggleFormatItalic();
75
76     /**
77      * Toggle the underlining of the selected or typed text
78      *
79      * Underlined becomes normal, and normal becomes underlined.
80      */
81     void toggleFormatUnderline();
82
83     /**
84      * Clear the formatting of the selected or typed text
85      *
86      * Clears the font weight (bold, italic, underline) and foreground/background coloring.
87      */
88     void clearFormat();
89
90 protected:
91     virtual bool eventFilter(QObject *watched, QEvent *event);
92
93 protected slots:
94     virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous);
95     virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
96     virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
97
98 private slots:
99     void setCustomFont(const QVariant &font);
100     void setUseCustomFont(const QVariant &);
101     void setEnableSpellCheck(const QVariant &);
102     void setEnableEmacsMode(const QVariant &);
103     void setShowNickSelector(const QVariant &);
104     void setShowStyleButtons(const QVariant &);
105     void setEnablePerChatHistory(const QVariant &);
106     void setMaxLines(const QVariant &);
107     void setLineWrapEnabled(const QVariant &);
108     void setMultiLineEnabled(const QVariant &);
109     void setScrollBarsEnabled(const QVariant &);
110     void onTextEntered(const QString &text);
111     void changeNick(const QString &newNick) const;
112
113     void setNetwork(NetworkId networkId);
114     void setIdentity(IdentityId identityId);
115     void connectMyIrcUser();
116     void updateNickSelector() const;
117     void updateEnabledState();
118
119     BufferInfo currentBufferInfo() const;
120
121     /**
122      * Set whether or not the style options frame is expanded
123      *
124      * @param visible If true, expand the style options frame, otherwise collapse it
125      */
126     void setStyleOptionsExpanded(const bool visible);
127
128     void currentCharFormatChanged(const QTextCharFormat &format);
129     void on_showStyleButton_toggled(bool checked);
130     void on_boldButton_clicked(bool checked);
131     void on_italicButton_clicked(bool checked);
132     void on_underlineButton_clicked(bool checked);
133     void colorChosen(QAction *action);
134     void colorHighlightChosen(QAction *action);
135
136 private:
137     /**
138      * Clear the formatting of the text, globally or selected text only
139      *
140      * Clears the font weight (bold, italic, underline) and foreground/background coloring.
141      *
142      * @param global If true, clear all text formatting, otherwise only clear selected text
143      */
144     void setFormatClear(const bool global = false);
145
146     /**
147      * Sets the boldness of the selected or typed text
148      *
149      * @param bold If true, set text bold, otherwise set text normal
150      */
151     void setFormatBold(const bool bold);
152
153     /**
154      * Sets the italicness of the selected or typed text
155      *
156      * @param bold If true, set text italic, otherwise set text normal
157      */
158     void setFormatItalic(const bool italic);
159
160     /**
161      * Sets the underline of the selected or typed text
162      *
163      * @param bold If true, set text underlined, otherwise set text normal
164      */
165     void setFormatUnderline(const bool underline);
166
167     Ui::InputWidget ui;
168
169     NetworkId _networkId;
170     IdentityId _identityId;
171     QMenu *_colorMenu, *_colorFillMenu;
172
173     void mergeFormatOnSelection(const QTextCharFormat &format);
174     void fontChanged(const QFont &f);
175     QIcon createColorToolButtonIcon(const QIcon &icon, const QColor &color);
176     QTextCharFormat getFormatOfWordOrSelection();
177     void setFormatOnSelection(const QTextCharFormat &format);
178
179     bool _perChatHistory;
180     struct HistoryState {
181         QStringList history;
182         QHash<int, QString> tempHistory;
183         qint32 idx;
184         QString inputLine;
185         inline HistoryState() : idx(0) {};
186     };
187
188     QMap<BufferId, HistoryState> historyMap;
189 };
190
191
192 class MouseWheelFilter : public QObject
193 {
194     Q_OBJECT
195
196 public:
197     MouseWheelFilter(QObject *parent = 0);
198     virtual bool eventFilter(QObject *obj, QEvent *event);
199 };
200
201
202 #endif // INPUTWIDGET_H