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