Freeciv-3.3: /fast/freeciv/nightly/main/client/gui-qt/messagewin.cpp Source File

Freeciv-3.3

Loading...
Searching...
No Matches
messagewin.cpp
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#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18// Qt
19#include <QApplication>
20#include <QGridLayout>
21#include <QHeaderView>
22#include <QMouseEvent>
23#include <QPainter>
24#include <QStyleFactory>
25
26// gui-qt
27#include "fc_client.h"
28#include "gui_main.h"
29#include "messagewin.h"
30#include "qtg_cxxside.h"
31#include "sprite.h"
32
33
34/***********************************************************************/
37info_tab::info_tab(QWidget *parent)
38{
39 setParent(parent);
40
41 layout = new QGridLayout;
42 msgwdg = new messagewdg(this);
43 layout->addWidget(msgwdg, 0, 0);
44 chtwdg = new chatwdg(this);
45 layout->addWidget(chtwdg, 1, 0);
46 layout->setHorizontalSpacing(0);
47 layout->setVerticalSpacing(0);
48 layout->setContentsMargins(0, 3, 3, 0);
49 layout->setSpacing(0);
50 layout->setVerticalSpacing(0);
51 setLayout(layout);
52 resize_mode = false;
53 resx = false;
54 resy = false;
55 resxy = false;
56 mw = new move_widget(this);
57 mw->put_to_corner();
58 mw->setFixedSize(13, 13);
59 setMouseTracking(true);
60}
61
62/***********************************************************************/
65 void info_tab::restore_chat()
66{
67 msgwdg->setFixedHeight(qMax(0,(height() - chtwdg->default_size(3))));
68 chtwdg->setFixedHeight(chtwdg->default_size(3));
69 chat_maximized = false;
70 chtwdg->scroll_to_bottom();
71}
72
73/***********************************************************************/
76 void info_tab::maximize_chat()
77{
78 msgwdg->setFixedHeight(0);
79 chtwdg->setFixedHeight(height());
80 chat_maximized = true;
81 chtwdg->scroll_to_bottom();
82}
83
84/***********************************************************************/
87 void info_tab::mousePressEvent(QMouseEvent *event)
88{
89 if (gui()->interface_locked) {
90 return;
91 }
92
93 if (event->button() == Qt::LeftButton) {
94 QPoint pos = event->pos();
95 int x = pos.x();
96 int y = pos.y();
97
98 cursor = mevent_gpos(event) - geometry().topLeft();
99 if (y > 0 && y < 25 && x > width() - 25 && x < width()) {
100 resize_mode = true;
101 resxy = true;
102 return;
103 }
104 if (y > 0 && y < 5) {
105 resize_mode = true;
106 resy = true;
107 } else if (x > width() - 5 && x < width()) {
108 resize_mode = true;
109 resx = true;
110 }
111 }
112
113 event->setAccepted(true);
114}
115
116/***********************************************************************/
119 void info_tab::mouseReleaseEvent(QMouseEvent *event)
120{
121 QPoint p;
122
123 if (gui()->interface_locked) {
124 return;
125 }
126
127 if (resize_mode) {
128 resize_mode = false;
129 resx = false;
130 resy = false;
131 resxy = false;
132 setCursor(Qt::ArrowCursor);
133 }
134 p = pos();
135 gui()->qt_settings.chat_fwidth = static_cast<float>(width())
136 / gui()->mapview_wdg->width();
137 gui()->qt_settings.chat_fheight = static_cast<float>(height())
138 / gui()->mapview_wdg->height();
139 gui()->qt_settings.chat_fx_pos = static_cast<float>(p.x())
140 / gui()->mapview_wdg->width();
141 gui()->qt_settings.chat_fy_pos = static_cast<float>(p.y())
142 / gui()->mapview_wdg->height();
143}
144
145/***********************************************************************/
149 void info_tab::mouseMoveEvent(QMouseEvent *event)
150{
151 QPoint pos;
152 int ex, ey;
153
154 if (gui()->interface_locked) {
155 return;
156 }
157
158 pos = event->pos();
159 ex = pos.x();
160 ey = pos.y();
161
162 if ((event->buttons() & Qt::LeftButton) && resize_mode && resy) {
163 QPoint to_move;
164#ifndef FC_QT5_MODE
165 int newheight = event->globalPosition().y() - cursor.y() - geometry().y();
166#else // FC_QT5_MODE
167 int newheight = event->globalY() - cursor.y() - geometry().y();
168#endif // FC_QT5_MODE
169
170 resize(width(), this->geometry().height()-newheight);
171 to_move = mevent_gpos(event) - cursor;
172 move(this->x(), to_move.y());
173 setCursor(Qt::SizeVerCursor);
174 restore_chat();
175 } else if (ex > width() - 9 && ey > 0 && ey < 9) {
176 setCursor(Qt::SizeBDiagCursor);
177 } else if ((event->buttons() & Qt::LeftButton) && resize_mode && resx) {
178 resize(ex, height());
179 setCursor(Qt::SizeHorCursor);
180 } else if (ex > width() - 5 && ex < width()) {
181 setCursor(Qt::SizeHorCursor);
182 } else if (ey > 0 && ey < 5) {
183 setCursor(Qt::SizeVerCursor);
184 } else if (resxy && (event->buttons() & Qt::LeftButton)) {
185 QPoint to_move;
186#ifndef FC_QT5_MODE
187 int newheight = event->globalPosition().y() - cursor.y() - geometry().y();
188#else // FC_QT5_MODE
189 int newheight = event->globalY() - cursor.y() - geometry().y();
190#endif // FC_QT5_MODE
191
192 resize(ex, this->geometry().height()- newheight);
193 to_move = mevent_gpos(event) - cursor;
194 move(this->x(), to_move.y());
195 setCursor(Qt::SizeBDiagCursor);
196 restore_chat();
197 } else {
198 setCursor(Qt::ArrowCursor);
199 }
200
201 event->setAccepted(true);
202}
203
204/***********************************************************************/
207 void info_tab::update_menu()
208{
209}
210
211/***********************************************************************/
214messagewdg::messagewdg(QWidget *parent): QWidget(parent)
215{
216 QPalette palette;
217 layout = new QGridLayout;
218
219 mesg_table = new QTableWidget;
220 mesg_table->setColumnCount(1);
221 mesg_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
222 mesg_table->verticalHeader()->setVisible(false);
223 mesg_table->setSelectionMode(QAbstractItemView::SingleSelection);
224 mesg_table->horizontalHeader()->setStretchLastSection(true);
225 mesg_table->horizontalHeader()->setVisible(false);
226 mesg_table->setShowGrid(false);
227 layout->addWidget(mesg_table, 0, 2, 1, 1);
228 layout->setContentsMargins(0, 0, 3, 3);
229 setLayout(layout);
230
231 // Dont highlight show current cell - set the same colors
232 palette.setColor(QPalette::Highlight, QColor(0, 0, 0, 0));
233 palette.setColor(QPalette::HighlightedText, QColor(205, 206, 173));
234 palette.setColor(QPalette::Text, QColor(205, 206, 173));
235
236 mesg_table->setPalette(palette);
237 connect(mesg_table->selectionModel(),
238 SIGNAL(selectionChanged(const QItemSelection &,
239 const QItemSelection &)),
240 SLOT(item_selected(const QItemSelection &,
241 const QItemSelection &)));
242 setMouseTracking(true);
243}
244
245/***********************************************************************/
248 void messagewdg::item_selected(const QItemSelection &sl,
249 const QItemSelection &ds)
250{
251 const struct message *pmsg;
252 int i, j;
253 QFont f;
254 QModelIndex index;
255 QModelIndexList indexes = sl.indexes();
256 QTableWidgetItem *item;
257
258 if (indexes.isEmpty()) {
259 return;
260 }
261 index = indexes.at(0);
262 i = index.row();
263 pmsg = meswin_get_message(i);
264 if (i > -1 && pmsg != nullptr) {
265 if (QApplication::mouseButtons() == Qt::LeftButton
266 || QApplication::mouseButtons() == Qt::RightButton) {
267 meswin_set_visited_state(i, true);
268 item = mesg_table->item(i, 0);
269 f = item->font();
270 f.setItalic(true);
271 item->setFont(f);
272 }
273 if (QApplication::mouseButtons() == Qt::LeftButton && pmsg->location_ok) {
274 meswin_goto(i);
275 }
276 if (QApplication::mouseButtons() == Qt::RightButton && pmsg->city_ok) {
277 meswin_popup_city(i);
278 }
279 if (QApplication::mouseButtons() == Qt::RightButton
280 && pmsg->event == E_DIPLOMACY) {
281 j = gui()->gimme_index_of("DDI");
282 gui()->game_tab_widget->setCurrentIndex(j);
283 }
284 }
285 mesg_table->clearSelection();
286}
287
288/***********************************************************************/
291#ifndef FC_QT5_MODE
292 void messagewdg::enterEvent(QEnterEvent *event)
293#else // FC_QT5_MODE
294void messagewdg::enterEvent(QEvent *event)
295#endif // FC_QT5_MODE
296{
297 setCursor(Qt::ArrowCursor);
298}
299
300/***********************************************************************/
303 void messagewdg::leaveEvent(QEvent *event)
304{
305 setCursor(Qt::ArrowCursor);
306}
307
308/***********************************************************************/
311 void messagewdg::paint(QPainter *painter, QPaintEvent *event)
312{
313 painter->setBrush(QColor(0, 0, 0, 35));
314 painter->drawRect(0, 0, width(), height());
315}
316
317/***********************************************************************/
320 void messagewdg::paintEvent(QPaintEvent *event)
321{
322 QPainter painter;
323
324 painter.begin(this);
325 paint(&painter, event);
326 painter.end();
327}
328
329/***********************************************************************/
332 void messagewdg::clr()
333{
334 mesg_table->clearContents();
335 mesg_table->setRowCount(0);
336}
337
338/***********************************************************************/
341 void messagewdg::msg(const struct message *pmsg)
342{
343 int i;
344 struct sprite *icon;
345 QFont f;
346 QTableWidgetItem *item;
347
348 item = new QTableWidgetItem;
349 item->setText(pmsg->descr);
350 i = mesg_table->rowCount();
351 mesg_table->insertRow(i);
352 if (pmsg->visited) {
353 f = item->font();
354 f.setItalic(true);
355 item->setFont(f);
356 }
357 icon = get_event_sprite(tileset, pmsg->event);
358 if (icon != nullptr) {
359 pix = icon->pm;
360 item->setIcon(QIcon(*pix));
361 }
362 mesg_table->setItem(i, 0, item);
363 msg_update();
364 mesg_table->scrollToBottom();
365}
366
367/***********************************************************************/
370 void messagewdg::msg_update()
371{
372 mesg_table->resizeRowsToContents();
373 update();
374}
375
376/***********************************************************************/
379 void messagewdg::resizeEvent(QResizeEvent* event)
380{
381 msg_update();
382}
383
384/***********************************************************************/
387 void meswin_dialog_popup(bool raise)
388{
389 // PORTME
390}
391
392/***********************************************************************/
395 bool meswin_dialog_is_open(void)
396{
397 // PORTME
398 return true;
399}
400
401/***********************************************************************/
404 void real_meswin_dialog_update(void *unused)
405{
406 int i, num;
407 const struct message *pmsg;
408
409 if (gui()->infotab == nullptr) {
410 return;
411 }
412 gui()->infotab->msgwdg->clr();
413 num = meswin_get_num_messages();
414 for (i = 0; i < num; i++) {
415 pmsg = meswin_get_message(i);
416 gui()->infotab->msgwdg->msg(pmsg);
417 }
418 gui()->infotab->msgwdg->msg_update();
419
420}
height
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
width
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
chatwdg
Definition chatline.h:116
chatwdg::default_size
int default_size(int lines)
Definition chatline.cpp:501
chatwdg::scroll_to_bottom
void scroll_to_bottom()
Definition chatline.cpp:338
info_tab::resize_mode
bool resize_mode
Definition messagewin.h:89
info_tab::mouseReleaseEvent
void mouseReleaseEvent(QMouseEvent *event)
Definition messagewin.cpp:119
info_tab::msgwdg
messagewdg * msgwdg
Definition messagewin.h:78
info_tab::info_tab
info_tab(QWidget *parent)
Definition messagewin.cpp:37
info_tab::layout
QGridLayout * layout
Definition messagewin.h:77
info_tab::update_menu
void update_menu()
Definition messagewin.cpp:207
info_tab::resxy
bool resxy
Definition messagewin.h:90
info_tab::cursor
QPoint cursor
Definition messagewin.h:85
info_tab::resx
bool resx
Definition messagewin.h:91
info_tab::chat_maximized
bool chat_maximized
Definition messagewin.h:82
info_tab::resy
bool resy
Definition messagewin.h:92
info_tab::mw
move_widget * mw
Definition messagewin.h:87
info_tab::restore_chat
void restore_chat()
Definition messagewin.cpp:65
info_tab::mousePressEvent
void mousePressEvent(QMouseEvent *event)
Definition messagewin.cpp:87
info_tab::chtwdg
chatwdg * chtwdg
Definition messagewin.h:79
info_tab::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *event)
Definition messagewin.cpp:149
info_tab::maximize_chat
void maximize_chat()
Definition messagewin.cpp:76
messagewdg
Definition messagewin.h:43
messagewdg::paintEvent
void paintEvent(QPaintEvent *event)
Definition messagewin.cpp:320
messagewdg::msg_update
void msg_update()
Definition messagewin.cpp:370
messagewdg::leaveEvent
void leaveEvent(QEvent *event)
Definition messagewin.cpp:303
messagewdg::layout
QGridLayout * layout
Definition messagewin.h:52
messagewdg::resizeEvent
void resizeEvent(QResizeEvent *event)
Definition messagewin.cpp:379
messagewdg::mesg_table
QTableWidget * mesg_table
Definition messagewin.h:51
messagewdg::item_selected
void item_selected(const QItemSelection &sl, const QItemSelection &ds)
Definition messagewin.cpp:248
messagewdg::enterEvent
void enterEvent(QEnterEvent *event)
Definition messagewin.cpp:292
messagewdg::paint
void paint(QPainter *painter, QPaintEvent *event)
Definition messagewin.cpp:311
messagewdg::clr
void clr()
Definition messagewin.cpp:332
messagewdg::messagewdg
messagewdg(QWidget *parent)
Definition messagewin.cpp:214
messagewdg::msg
void msg(const struct message *pmsg)
Definition messagewin.cpp:341
messagewdg::pix
QPixmap * pix
Definition messagewin.h:53
move_widget
Definition mapview.h:154
move_widget::put_to_corner
void put_to_corner()
Definition mapview.cpp:399
incite_cost
char * incite_cost
Definition comments.c:74
event
enum event_type event
Definition events.c:81
fc_client.h
pos
static struct tile * pos
Definition finddlg.c:53
mevent_gpos
#define mevent_gpos(__ev__)
Definition gui_main.h:23
gui_main.h
messagewin.h
sprite.h
meswin_dialog_popup
void meswin_dialog_popup(bool raise)
Definition messagewin.cpp:387
real_meswin_dialog_update
void real_meswin_dialog_update(void *unused)
Definition messagewin.cpp:404
meswin_dialog_is_open
bool meswin_dialog_is_open(void)
Definition messagewin.cpp:395
meswin_popup_city
void meswin_popup_city(int message_index)
Definition messagewin_common.c:185
meswin_goto
void meswin_goto(int message_index)
Definition messagewin_common.c:213
meswin_get_num_messages
int meswin_get_num_messages(void)
Definition messagewin_common.c:167
meswin_get_message
const struct message * meswin_get_message(int message_index)
Definition messagewin_common.c:154
meswin_set_visited_state
void meswin_set_visited_state(int message_index, bool state)
Definition messagewin_common.c:175
gui
static mpgui * gui
Definition mpgui_qt.cpp:52
qtg_cxxside.h
y
struct sprite int int y
Definition sprite_g.h:31
x
struct sprite int x
Definition sprite_g.h:31
item
Definition climisc.h:80
item::item
struct universal item
Definition climisc.h:81
message
Definition messagewin_common.h:29
move
Definition widget_window.c:39
sprite
Definition sprite.h:22
sprite::pm
QPixmap * pm
Definition sprite.h:25
tileset
Definition tilespec.c:481
get_event_sprite
struct sprite * get_event_sprite(const struct tileset *t, enum event_type event)
Definition tilespec.c:6918