Search the web with selected text.
[quassel.git] / src / qtui / inputwidget.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2014 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 protected:
48     virtual bool eventFilter(QObject *watched, QEvent *event);
49
50 protected slots:
51     virtual void currentChanged(const QModelIndex &current, const QModelIndex &previous);
52     virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
53     virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
54
55 private slots:
56     void setCustomFont(const QVariant &font);
57     void setUseCustomFont(const QVariant &);
58     void setEnableSpellCheck(const QVariant &);
59     void setEnableEmacsMode(const QVariant &);
60     void setShowNickSelector(const QVariant &);
61     void setShowStyleButtons(const QVariant &);
62     void setEnablePerChatHistory(const QVariant &);
63     void setMaxLines(const QVariant &);
64     void setMultiLineEnabled(const QVariant &);
65     void setScrollBarsEnabled(const QVariant &);
66     void onTextEntered(const QString &text);
67     void changeNick(const QString &newNick) const;
68
69     void setNetwork(NetworkId networkId);
70     void setIdentity(IdentityId identityId);
71     void connectMyIrcUser();
72     void updateNickSelector() const;
73     void updateEnabledState();
74
75     BufferInfo currentBufferInfo() const;
76
77     void currentCharFormatChanged(const QTextCharFormat &format);
78     void on_showStyleButton_toggled(bool checked);
79     void on_boldButton_clicked(bool checked);
80     void on_italicButton_clicked(bool checked);
81     void on_underlineButton_clicked(bool checked);
82     void colorChosen(QAction *action);
83     void colorHighlightChosen(QAction *action);
84
85 private:
86     Ui::InputWidget ui;
87
88     NetworkId _networkId;
89     IdentityId _identityId;
90     QMenu *_colorMenu, *_colorFillMenu;
91
92     void mergeFormatOnSelection(const QTextCharFormat &format);
93     void fontChanged(const QFont &f);
94     QIcon createColorToolButtonIcon(const QIcon &icon, const QColor &color);
95     QTextCharFormat getFormatOfWordOrSelection();
96     void setFormatOnSelection(const QTextCharFormat &format);
97
98     bool _perChatHistory;
99     struct HistoryState {
100         QStringList history;
101         QHash<int, QString> tempHistory;
102         qint32 idx;
103         QString inputLine;
104         inline HistoryState() : idx(0) {};
105     };
106
107     QMap<BufferId, HistoryState> historyMap;
108 };
109
110
111 class MouseWheelFilter : public QObject
112 {
113     Q_OBJECT
114
115 public:
116     MouseWheelFilter(QObject *parent = 0);
117     virtual bool eventFilter(QObject *obj, QEvent *event);
118 };
119
120
121 #endif // INPUTWIDGET_H