Freeciv-3.2: /fast/freeciv/nightly/S3_2/client/gui-qt/chatline.h Source File

Freeciv-3.2

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
39 QString 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/***************************************************************************
44 Listener for chat. See listener<> for information about how to use it
45***************************************************************************/
46 class chat_listener : public listener<chat_listener>
47{
48 // History is shared among all instances...
49 static QStringList history;
50 // ...but each has its own position.
51 int position;
52
53 // Chat completion word list.
54 static QStringList word_list;
55
56public:
57 // Special value meaning "end of history".
58 static const int HISTORY_END = -1;
59
60 static void update_word_list();
61
62 explicit chat_listener();
63
64 virtual void chat_message_received(const QString &,
65 const struct text_tag_list *);
66 virtual void chat_word_list_changed(const QStringList &cmplt_word_list);
67
68 void send_chat_message(const QString &message);
69
70 int position_in_history() { return position; }
71 QString back_in_history();
72 QString forward_in_history();
73 void reset_history_position();
74
75 QStringList current_word_list() { return word_list; }
76};
77
78/***************************************************************************
79 Chat input widget
80***************************************************************************/
81 class chat_input : public QLineEdit, private chat_listener
82{
83 Q_OBJECT
84
85private slots:
86 void send();
87
88public:
89 explicit chat_input(QWidget *parent = nullptr);
90
91 virtual void chat_word_list_changed(const QStringList &cmplt_word_list);
92
93 bool event(QEvent *event);
94};
95
96/***************************************************************************
97 Text browser with mouse double click signal
98***************************************************************************/
99 class text_browser_dblclck : public QTextBrowser
100{
101 Q_OBJECT
102public:
103 explicit text_browser_dblclck(QWidget *parent = NULL): QTextBrowser(parent) {}
104signals:
105 void dbl_clicked();
106protected:
107 void mouseDoubleClickEvent(QMouseEvent *event) {
108 emit dbl_clicked();
109 }
110};
111
112/***************************************************************************
113 Class for chat widget
114***************************************************************************/
115 class chatwdg : public QWidget, private chat_listener
116{
117 Q_OBJECT
118public:
119 chatwdg(QWidget *parent);
120 void append(const QString &str);
121 chat_input *chat_line;
122 void make_link(struct tile *ptile);
123 void update_widgets();
124 int default_size(int lines);
125 void scroll_to_bottom();
126 void update_font();
127private slots:
128 void state_changed(int state);
129 void rm_links();
130 void anchor_clicked(const QUrl &link);
131 void toggle_size();
132protected:
133 void paint(QPainter *painter, QPaintEvent *event);
134 void paintEvent(QPaintEvent *event);
135 bool eventFilter(QObject *obj, QEvent *event);
136private:
137 void chat_message_received(const QString &message,
138 const struct text_tag_list *tags);
139
140 text_browser_dblclck *chat_output;
141 QPushButton *remove_links;
142 QCheckBox *cb;
143
144};
145
146 class version_message_event : public QEvent
147{
148 QString message;
149public:
150 explicit version_message_event(const QString &msg);
151 QString get_message() const { return message; }
152};
153
154#endif // FC__CHATLINE_H
str
#define str
Definition astring.c:76
chatline_g.h
chat_input
Definition chatline.h:82
chat_input::chat_word_list_changed
virtual void chat_word_list_changed(const QStringList &cmplt_word_list)
Definition chatline.cpp:232
chat_input::send
void send()
Definition chatline.cpp:223
chat_listener
Definition chatline.h:47
chat_listener::current_word_list
QStringList current_word_list()
Definition chatline.h:75
chat_listener::HISTORY_END
static const int HISTORY_END
Definition chatline.h:58
chat_listener::forward_in_history
QString forward_in_history()
Definition chatline.cpp:187
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:204
chat_listener::back_in_history
QString back_in_history()
Definition chatline.cpp:173
chat_listener::history
static QStringList history
Definition chatline.h:49
chat_listener::position_in_history
int position_in_history()
Definition chatline.h:70
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:54
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:51
chatwdg
Definition chatline.h:116
chatwdg::eventFilter
bool eventFilter(QObject *obj, QEvent *event)
Definition chatline.cpp:463
chatwdg::chat_line
chat_input * chat_line
Definition chatline.h:121
chatwdg::paintEvent
void paintEvent(QPaintEvent *event)
Definition chatline.cpp:451
chatwdg::update_font
void update_font()
Definition chatline.cpp:348
chatwdg::anchor_clicked
void anchor_clicked(const QUrl &link)
Definition chatline.cpp:366
chatwdg::default_size
int default_size(int lines)
Definition chatline.cpp:501
chatwdg::chat_output
text_browser_dblclck * chat_output
Definition chatline.h:140
chatwdg::make_link
void make_link(struct tile *ptile)
Definition chatline.cpp:535
chatwdg::chat_message_received
void chat_message_received(const QString &message, const struct text_tag_list *tags)
Definition chatline.cpp:419
chatwdg::scroll_to_bottom
void scroll_to_bottom()
Definition chatline.cpp:338
chatwdg::paint
void paint(QPainter *painter, QPaintEvent *event)
Definition chatline.cpp:442
chatwdg::update_widgets
void update_widgets()
Definition chatline.cpp:486
chatwdg::cb
QCheckBox * cb
Definition chatline.h:142
chatwdg::rm_links
void rm_links()
Definition chatline.cpp:358
chatwdg::remove_links
QPushButton * remove_links
Definition chatline.h:141
chatwdg::state_changed
void state_changed(int state)
Definition chatline.cpp:312
chatwdg::append
void append(const QString &str)
Definition chatline.cpp:430
chatwdg::toggle_size
void toggle_size()
Definition chatline.cpp:324
listener
Definition listener.h:105
text_browser_dblclck
Definition chatline.h:100
text_browser_dblclck::text_browser_dblclck
text_browser_dblclck(QWidget *parent=NULL)
Definition chatline.h:103
text_browser_dblclck::dbl_clicked
void dbl_clicked()
text_browser_dblclck::mouseDoubleClickEvent
void mouseDoubleClickEvent(QMouseEvent *event)
Definition chatline.h:107
version_message_event
Definition chatline.h:147
version_message_event::message
QString message
Definition chatline.h:148
version_message_event::get_message
QString get_message() const
Definition chatline.h:151
incite_cost
char * incite_cost
Definition comments.c:74
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:555
listener.h
lines
char * lines
Definition packhand.c:131
slots
struct player_slot * slots
Definition player.c:51
message
Definition messagewin_common.h:29
tile
Definition tile.h:50