Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/gui-qt/chatline.h Source File

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***************************************************************************/
45 class 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.
50 int 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();
72 void reset_history_position();
73
74 QStringList current_word_list() { return word_list; }
75};
76
77/***************************************************************************
78 Chat input widget
79***************************************************************************/
80 class 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***************************************************************************/
98 class text_browser_dblclck : public QTextBrowser
99{
100 Q_OBJECT
101public:
102 explicit text_browser_dblclck(QWidget *parent = NULL): QTextBrowser(parent) {}
103signals:
104 void dbl_clicked();
105protected:
106 void mouseDoubleClickEvent(QMouseEvent *event) {
107 emit dbl_clicked();
108 }
109};
110
111/***************************************************************************
112 Class for chat widget
113***************************************************************************/
114 class chatwdg : public QWidget, private chat_listener
115{
116 Q_OBJECT
117public:
118 chatwdg(QWidget *parent);
119 void append(const QString &str);
120 chat_input *chat_line;
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
139 text_browser_dblclck *chat_output;
140 QPushButton *remove_links;
141 QCheckBox *cb;
142
143};
144
145 class 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 */
str
#define str
Definition astring.c:76
chatline_g.h
chat_input
Definition chatline.h:81
chat_input::chat_word_list_changed
virtual void chat_word_list_changed(const QStringList &cmplt_word_list)
Definition chatline.cpp:236
chat_input::send
void send()
Definition chatline.cpp:227
chat_listener
Definition chatline.h:46
chat_listener::current_word_list
QStringList current_word_list()
Definition chatline.h:74
chat_listener::HISTORY_END
static const int HISTORY_END
Definition chatline.h:57
chat_listener::forward_in_history
QString forward_in_history()
Definition chatline.cpp:191
chat_listener::send_chat_message
void send_chat_message(const QString &message)
Definition chatline.cpp:109
chat_listener::reset_history_position
void reset_history_position()
Definition chatline.cpp:208
chat_listener::back_in_history
QString back_in_history()
Definition chatline.cpp:177
chat_listener::history
static QStringList history
Definition chatline.h:48
chat_listener::position_in_history
int position_in_history()
Definition chatline.h:69
chat_listener::chat_word_list_changed
virtual void chat_word_list_changed(const QStringList &cmplt_word_list)
Definition chatline.cpp:100
chat_listener::update_word_list
static void update_word_list()
Definition chatline.cpp:58
chat_listener::word_list
static QStringList word_list
Definition chatline.h:53
chat_listener::chat_listener
chat_listener()
Definition chatline.cpp:84
chat_listener::chat_message_received
virtual void chat_message_received(const QString &, const struct text_tag_list *)
Definition chatline.cpp:92
chat_listener::position
int position
Definition chatline.h:50
chatwdg
Definition chatline.h:115
chatwdg::eventFilter
bool eventFilter(QObject *obj, QEvent *event)
Definition chatline.cpp:466
chatwdg::chat_line
chat_input * chat_line
Definition chatline.h:120
chatwdg::paintEvent
void paintEvent(QPaintEvent *event)
Definition chatline.cpp:454
chatwdg::update_font
void update_font()
Definition chatline.cpp:352
chatwdg::anchor_clicked
void anchor_clicked(const QUrl &link)
Definition chatline.cpp:370
chatwdg::default_size
int default_size(int lines)
Definition chatline.cpp:503
chatwdg::chat_output
text_browser_dblclck * chat_output
Definition chatline.h:139
chatwdg::make_link
void make_link(struct tile *ptile)
Definition chatline.cpp:537
chatwdg::chat_message_received
void chat_message_received(const QString &message, const struct text_tag_list *tags)
Definition chatline.cpp:423
chatwdg::scroll_to_bottom
void scroll_to_bottom()
Definition chatline.cpp:342
chatwdg::paint
void paint(QPainter *painter, QPaintEvent *event)
Definition chatline.cpp:445
chatwdg::update_widgets
void update_widgets()
Definition chatline.cpp:488
chatwdg::cb
QCheckBox * cb
Definition chatline.h:141
chatwdg::rm_links
void rm_links()
Definition chatline.cpp:362
chatwdg::remove_links
QPushButton * remove_links
Definition chatline.h:140
chatwdg::state_changed
void state_changed(int state)
Definition chatline.cpp:316
chatwdg::append
void append(const QString &str)
Definition chatline.cpp:433
chatwdg::toggle_size
void toggle_size()
Definition chatline.cpp:328
listener
Definition listener.h:105
text_browser_dblclck
Definition chatline.h:99
text_browser_dblclck::text_browser_dblclck
text_browser_dblclck(QWidget *parent=NULL)
Definition chatline.h:102
text_browser_dblclck::dbl_clicked
void dbl_clicked()
text_browser_dblclck::mouseDoubleClickEvent
void mouseDoubleClickEvent(QMouseEvent *event)
Definition chatline.h:106
version_message_event
Definition chatline.h:146
version_message_event::message
QString message
Definition chatline.h:147
version_message_event::get_message
QString get_message() const
Definition chatline.h:150
event
enum event_type event
Definition events.c:81
fonts.h
apply_tags
QString apply_tags(QString str, const struct text_tag_list *tags, QColor bg_color)
Definition chatline.cpp:557
listener.h
lines
char * lines
Definition packhand.c:129
slots
struct player_slot * slots
Definition player.c:50
message
Definition messagewin_common.h:29
tile
Definition tile.h:49