Freeciv-3.4
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 = event->globalPosition().toPoint() - 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 int newheight = event->globalPosition().y() - cursor.y() - geometry().y();
165
166 resize(width(), this->geometry().height()-newheight);
167 to_move = event->globalPosition().toPoint() - cursor;
168 move(this->x(), to_move.y());
169 setCursor(Qt::SizeVerCursor);
170 restore_chat();
171 } else if (ex > width() - 9 && ey > 0 && ey < 9) {
172 setCursor(Qt::SizeBDiagCursor);
173 } else if ((event->buttons() & Qt::LeftButton) && resize_mode && resx) {
174 resize(ex, height());
175 setCursor(Qt::SizeHorCursor);
176 } else if (ex > width() - 5 && ex < width()) {
177 setCursor(Qt::SizeHorCursor);
178 } else if (ey > 0 && ey < 5) {
179 setCursor(Qt::SizeVerCursor);
180 } else if (resxy && (event->buttons() & Qt::LeftButton)) {
182 int newheight = event->globalPosition().y() - cursor.y() - geometry().y();
183
184 resize(ex, this->geometry().height()- newheight);
185 to_move = event->globalPosition().toPoint() - cursor;
186 move(this->x(), to_move.y());
187 setCursor(Qt::SizeBDiagCursor);
188 restore_chat();
189 } else {
190 setCursor(Qt::ArrowCursor);
191 }
192
193 event->setAccepted(true);
194}
195
196/***********************************************************************/
200{
201}
202
203/***********************************************************************/
207{
209 layout = new QGridLayout;
210
211 mesg_table = new QTableWidget;
212 mesg_table->setColumnCount(1);
213 mesg_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
214 mesg_table->verticalHeader()->setVisible(false);
215 mesg_table->setSelectionMode(QAbstractItemView::SingleSelection);
216 mesg_table->horizontalHeader()->setStretchLastSection(true);
217 mesg_table->horizontalHeader()->setVisible(false);
218 mesg_table->setShowGrid(false);
219 layout->addWidget(mesg_table, 0, 2, 1, 1);
220 layout->setContentsMargins(0, 0, 3, 3);
222
223 // Dont highlight show current cell - set the same colors
224 palette.setColor(QPalette::Highlight, QColor(0, 0, 0, 0));
225 palette.setColor(QPalette::HighlightedText, QColor(205, 206, 173));
226 palette.setColor(QPalette::Text, QColor(205, 206, 173));
227
228 mesg_table->setPalette(palette);
229 connect(mesg_table->selectionModel(),
231 const QItemSelection &)),
233 const QItemSelection &)));
234 setMouseTracking(true);
235}
236
237/***********************************************************************/
241 const QItemSelection &ds)
242{
243 const struct message *pmsg;
244 int i, j;
245 QFont f;
246 QModelIndex index;
247 QModelIndexList indexes = sl.indexes();
249
250 if (indexes.isEmpty()) {
251 return;
252 }
253 index = indexes.at(0);
254 i = index.row();
256 if (i > -1 && pmsg != nullptr) {
257 if (QApplication::mouseButtons() == Qt::LeftButton
258 || QApplication::mouseButtons() == Qt::RightButton) {
260 item = mesg_table->item(i, 0);
261 f = item->font();
262 f.setItalic(true);
263 item->setFont(f);
264 }
265 if (QApplication::mouseButtons() == Qt::LeftButton && pmsg->location_ok) {
266 meswin_goto(i);
267 }
268 if (QApplication::mouseButtons() == Qt::RightButton && pmsg->city_ok) {
270 }
271 if (QApplication::mouseButtons() == Qt::RightButton
272 && pmsg->event == E_DIPLOMACY) {
273 j = gui()->gimme_index_of("DDI");
274 gui()->game_tab_widget->setCurrentIndex(j);
275 }
276 }
277 mesg_table->clearSelection();
278}
279
280/***********************************************************************/
284{
285 setCursor(Qt::ArrowCursor);
286}
287
288/***********************************************************************/
292{
293 setCursor(Qt::ArrowCursor);
294}
295
296/***********************************************************************/
300{
301 painter->setBrush(QColor(0, 0, 0, 35));
302 painter->drawRect(0, 0, width(), height());
303}
304
305/***********************************************************************/
309{
311
312 painter.begin(this);
314 painter.end();
315}
316
317/***********************************************************************/
321{
322 mesg_table->clearContents();
323 mesg_table->setRowCount(0);
324}
325
326/***********************************************************************/
329void messagewdg::msg(const struct message *pmsg)
330{
331 int i;
332 struct sprite *icon;
333 QFont f;
335
337 item->setText(pmsg->descr);
338 i = mesg_table->rowCount();
339 mesg_table->insertRow(i);
340 if (pmsg->visited) {
341 f = item->font();
342 f.setItalic(true);
343 item->setFont(f);
344 }
345 icon = get_event_sprite(tileset, pmsg->event);
346 if (icon != nullptr) {
347 pix = icon->pm;
348 item->setIcon(QIcon(*pix));
349 }
350 mesg_table->setItem(i, 0, item);
351 msg_update();
352 mesg_table->scrollToBottom();
353}
354
355/***********************************************************************/
359{
360 mesg_table->resizeRowsToContents();
361 update();
362}
363
364/***********************************************************************/
371
372/***********************************************************************/
376{
377 // PORTME
378}
379
380/***********************************************************************/
384{
385 // PORTME
386 return true;
387}
388
389/***********************************************************************/
393{
394 int i, num;
395 const struct message *pmsg;
396
397 if (gui()->infotab == nullptr) {
398 return;
399 }
400 gui()->infotab->msgwdg->clr();
402 for (i = 0; i < num; i++) {
404 gui()->infotab->msgwdg->msg(pmsg);
405 }
406 gui()->infotab->msgwdg->msg_update();
407
408}
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:519
void scroll_to_bottom()
Definition chatline.cpp:356
bool resize_mode
Definition messagewin.h:85
void mouseReleaseEvent(QMouseEvent *event)
messagewdg * msgwdg
Definition messagewin.h:74
info_tab(QWidget *parent)
QGridLayout * layout
Definition messagewin.h:73
void update_menu()
bool resxy
Definition messagewin.h:86
QPoint cursor
Definition messagewin.h:81
bool resx
Definition messagewin.h:87
bool chat_maximized
Definition messagewin.h:78
bool resy
Definition messagewin.h:88
move_widget * mw
Definition messagewin.h:83
void restore_chat()
void mousePressEvent(QMouseEvent *event)
chatwdg * chtwdg
Definition messagewin.h:75
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:76
enum event_type event
Definition events.c:81
static struct tile * pos
Definition finddlg.c:53
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:53
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:7148