Freeciv-3.1
Loading...
Searching...
No Matches
chatline.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifndef FC__CHATLINE_H
15#define FC__CHATLINE_H
16
17#ifdef HAVE_CONFIG_H
18#include <fc_config.h>
19#endif
20
21extern "C" {
22#include "chatline_g.h"
23}
24
25// Qt
26#include <QEvent>
27#include <QLineEdit>
28#include <QTextBrowser>
29
30// gui-qt
31#include "fonts.h"
32#include "listener.h"
33
34class chat_listener;
35class QCheckBox;
36class QMouseEvent;
37class QPushButton;
38
39QString apply_tags(QString str, const struct text_tag_list *tags,
40 QColor bg_color);
41template<> std::set<chat_listener *> listener<chat_listener>::instances;
42/***************************************************************************
43 Listener for chat. See listener<> for information about how to use it
44***************************************************************************/
45class chat_listener : public listener<chat_listener>
46{
47 // History is shared among all instances...
48 static QStringList history;
49 // ...but each has its own position.
51
52 // Chat completion word list.
53 static QStringList word_list;
54
55public:
56 // Special value meaning "end of history".
57 static const int HISTORY_END = -1;
58
59 static void update_word_list();
60
61 explicit chat_listener();
62
63 virtual void chat_message_received(const QString &,
64 const struct text_tag_list *);
65 virtual void chat_word_list_changed(const QStringList &cmplt_word_list);
66
67 void send_chat_message(const QString &message);
68
69 int position_in_history() { return position; }
70 QString back_in_history();
71 QString forward_in_history();
73
74 QStringList current_word_list() { return word_list; }
75};
76
77/***************************************************************************
78 Chat input widget
79***************************************************************************/
80class chat_input : public QLineEdit, private chat_listener
81{
82 Q_OBJECT
83
84private slots:
85 void send();
86
87public:
88 explicit chat_input(QWidget *parent = nullptr);
89
90 virtual void chat_word_list_changed(const QStringList &cmplt_word_list);
91
92 bool event(QEvent *event);
93};
94
95/***************************************************************************
96 Text browser with mouse double click signal
97***************************************************************************/
98class text_browser_dblclck : public QTextBrowser
99{
100 Q_OBJECT
101public:
102 explicit text_browser_dblclck(QWidget *parent = NULL): QTextBrowser(parent) {}
103signals:
105protected:
106 void mouseDoubleClickEvent(QMouseEvent *event) {
107 emit dbl_clicked();
108 }
109};
110
111/***************************************************************************
112 Class for chat widget
113***************************************************************************/
114class chatwdg : public QWidget, private chat_listener
115{
116 Q_OBJECT
117public:
118 chatwdg(QWidget *parent);
119 void append(const QString &str);
121 void make_link(struct tile *ptile);
122 void update_widgets();
123 int default_size(int lines);
124 void scroll_to_bottom();
125 void update_font();
126private slots:
127 void state_changed(int state);
128 void rm_links();
129 void anchor_clicked(const QUrl &link);
130 void toggle_size();
131protected:
132 void paint(QPainter *painter, QPaintEvent *event);
133 void paintEvent(QPaintEvent *event);
134 bool eventFilter(QObject *obj, QEvent *event);
135private:
136 void chat_message_received(const QString &message,
137 const struct text_tag_list *tags);
138
140 QPushButton *remove_links;
141 QCheckBox *cb;
142
143};
144
145class version_message_event : public QEvent
146{
147 QString message;
148public:
149 explicit version_message_event(const QString &msg);
150 QString get_message() const { return message; }
151};
152
153#endif /* FC__CHATLINE_H */
#define str
Definition astring.c:76
virtual void chat_word_list_changed(const QStringList &cmplt_word_list)
Definition chatline.cpp:236
void send()
Definition chatline.cpp:227
QStringList current_word_list()
Definition chatline.h:74
static const int HISTORY_END
Definition chatline.h:57
QString forward_in_history()
Definition chatline.cpp:191
void send_chat_message(const QString &message)
Definition chatline.cpp:109
void reset_history_position()
Definition chatline.cpp:208
QString back_in_history()
Definition chatline.cpp:177
static QStringList history
Definition chatline.h:48
int position_in_history()
Definition chatline.h:69
virtual void chat_word_list_changed(const QStringList &cmplt_word_list)
Definition chatline.cpp:100
static void update_word_list()
Definition chatline.cpp:58
static QStringList word_list
Definition chatline.h:53
virtual void chat_message_received(const QString &, const struct text_tag_list *)
Definition chatline.cpp:92
bool eventFilter(QObject *obj, QEvent *event)
Definition chatline.cpp:466
chat_input * chat_line
Definition chatline.h:120
void paintEvent(QPaintEvent *event)
Definition chatline.cpp:454
void update_font()
Definition chatline.cpp:352
void anchor_clicked(const QUrl &link)
Definition chatline.cpp:370
int default_size(int lines)
Definition chatline.cpp:503
text_browser_dblclck * chat_output
Definition chatline.h:139
void make_link(struct tile *ptile)
Definition chatline.cpp:537
void chat_message_received(const QString &message, const struct text_tag_list *tags)
Definition chatline.cpp:423
void scroll_to_bottom()
Definition chatline.cpp:342
void paint(QPainter *painter, QPaintEvent *event)
Definition chatline.cpp:445
void update_widgets()
Definition chatline.cpp:488
QCheckBox * cb
Definition chatline.h:141
void rm_links()
Definition chatline.cpp:362
QPushButton * remove_links
Definition chatline.h:140
void state_changed(int state)
Definition chatline.cpp:316
void append(const QString &str)
Definition chatline.cpp:433
void toggle_size()
Definition chatline.cpp:328
text_browser_dblclck(QWidget *parent=NULL)
Definition chatline.h:102
void mouseDoubleClickEvent(QMouseEvent *event)
Definition chatline.h:106
QString get_message() const
Definition chatline.h:150
enum event_type event
Definition events.c:81
QString apply_tags(QString str, const struct text_tag_list *tags, QColor bg_color)
Definition chatline.cpp:557
char * lines
Definition packhand.c:129
struct player_slot * slots
Definition player.c:50
Definition tile.h:49