Freeciv-3.2
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/***********************************************************************/
38{
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);
52 resize_mode = false;
53 resx = false;
54 resy = false;
55 resxy = false;
56 mw = new move_widget(this);
58 mw->setFixedSize(13, 13);
59 setMouseTracking(true);
60}
61
62/***********************************************************************/
66{
67 msgwdg->setFixedHeight(qMax(0,(height() - chtwdg->default_size(3))));
68 chtwdg->setFixedHeight(chtwdg->default_size(3));
69 chat_maximized = false;
71}
72
73/***********************************************************************/
77{
78 msgwdg->setFixedHeight(0);
79 chtwdg->setFixedHeight(height());
80 chat_maximized = true;
82}
83
84/***********************************************************************/
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/***********************************************************************/
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/***********************************************************************/
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) {
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);
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)) {
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);
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/***********************************************************************/
208{
209}
210
211/***********************************************************************/
215{
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);
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(),
239 const QItemSelection &)),
241 const QItemSelection &)));
242 setMouseTracking(true);
243}
244
245/***********************************************************************/
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();
257
258 if (indexes.isEmpty()) {
259 return;
260 }
261 index = indexes.at(0);
262 i = index.row();
264 if (i > -1 && pmsg != NULL) {
265 if (QApplication::mouseButtons() == Qt::LeftButton
266 || QApplication::mouseButtons() == Qt::RightButton) {
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) {
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
293#else // FC_QT5_MODE
294void messagewdg::enterEvent(QEvent *event)
295#endif // FC_QT5_MODE
296{
297 setCursor(Qt::ArrowCursor);
298}
299
300/***********************************************************************/
304{
305 setCursor(Qt::ArrowCursor);
306}
307
308/***********************************************************************/
312{
313 painter->setBrush(QColor(0, 0, 0, 35));
314 painter->drawRect(0, 0, width(), height());
315}
316
317/***********************************************************************/
321{
323
324 painter.begin(this);
326 painter.end();
327}
328
329/***********************************************************************/
333{
334 mesg_table->clearContents();
335 mesg_table->setRowCount(0);
336}
337
338/***********************************************************************/
341void messagewdg::msg(const struct message *pmsg)
342{
343 int i;
344 struct sprite *icon;
345 QFont f;
347
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 != NULL) {
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/***********************************************************************/
371{
372 mesg_table->resizeRowsToContents();
373 update();
374}
375
376/***********************************************************************/
383
384/***********************************************************************/
388{
389 // PORTME
390}
391
392/***********************************************************************/
396{
397 // PORTME
398 return true;
399}
400
401/***********************************************************************/
405{
406 int i, num;
407 const struct message *pmsg;
408
409 if (gui()->infotab == NULL) {
410 return;
411 }
412 gui()->infotab->msgwdg->clr();
414 for (i = 0; i < num; i++) {
416 gui()->infotab->msgwdg->msg(pmsg);
417 }
418 gui()->infotab->msgwdg->msg_update();
419
420}
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
int default_size(int lines)
Definition chatline.cpp:501
void scroll_to_bottom()
Definition chatline.cpp:338
bool resize_mode
Definition messagewin.h:89
void mouseReleaseEvent(QMouseEvent *event)
messagewdg * msgwdg
Definition messagewin.h:78
info_tab(QWidget *parent)
QGridLayout * layout
Definition messagewin.h:77
void update_menu()
bool resxy
Definition messagewin.h:90
QPoint cursor
Definition messagewin.h:85
bool resx
Definition messagewin.h:91
bool chat_maximized
Definition messagewin.h:82
bool resy
Definition messagewin.h:92
move_widget * mw
Definition messagewin.h:87
void restore_chat()
void mousePressEvent(QMouseEvent *event)
chatwdg * chtwdg
Definition messagewin.h:79
void mouseMoveEvent(QMouseEvent *event)
void maximize_chat()
void paintEvent(QPaintEvent *event)
void msg_update()
void leaveEvent(QEvent *event)
QGridLayout * layout
Definition messagewin.h:52
void resizeEvent(QResizeEvent *event)
QTableWidget * mesg_table
Definition messagewin.h:51
void item_selected(const QItemSelection &sl, const QItemSelection &ds)
void enterEvent(QEnterEvent *event)
void paint(QPainter *painter, QPaintEvent *event)
messagewdg(QWidget *parent)
void msg(const struct message *pmsg)
QPixmap * pix
Definition messagewin.h:53
void put_to_corner()
Definition mapview.cpp:399
char * incite_cost
Definition comments.c:75
enum event_type event
Definition events.c:81
static struct tile * pos
Definition finddlg.c:53
#define mevent_gpos(__ev__)
Definition gui_main.h:23
void meswin_dialog_popup(bool raise)
void real_meswin_dialog_update(void *unused)
bool meswin_dialog_is_open(void)
void meswin_popup_city(int message_index)
void meswin_goto(int message_index)
int meswin_get_num_messages(void)
const struct message * meswin_get_message(int message_index)
void meswin_set_visited_state(int message_index, bool state)
static mpgui * gui
Definition mpgui_qt.cpp:52
struct sprite int int y
Definition sprite_g.h:31
struct sprite int x
Definition sprite_g.h:31
Definition climisc.h:82
struct universal item
Definition climisc.h:83
QPixmap * pm
Definition sprite.h:25
struct sprite * get_event_sprite(const struct tileset *t, enum event_type event)
Definition tilespec.c:6900