Freeciv-3.1: /fast/freeciv/nightly/S3_1/client/gui-qt/messagewin.cpp Source File

Freeciv-3.1

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