Freeciv-3.2
Loading...
Searching...
No Matches
messagedlg.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 <QLabel>
22#include <QPushButton>
23#include <QTableWidget>
24#include <QHeaderView>
25
26// client
27#include "options.h"
28
29// gui-qt
30#include "fc_client.h"
31#include "gui_main.h"
32
33#include "messagedlg.h"
34
35/**********************************************************************/
39{
40 int index;
42 QLabel *empty1, *empty2;
43 QPushButton *but1;
44 QPushButton *but2;
46 int len;
47
48 setAttribute(Qt::WA_DeleteOnClose);
49 empty1 = new QLabel;
50 empty2 = new QLabel;
51 layout = new QGridLayout;
52 msgtab = new QTableWidget;
53 slist << _("Event") << _("Out") << _("Mes") << _("Pop");
54 msgtab->setColumnCount(slist.count());
55 msgtab->setHorizontalHeaderLabels(slist);
56 msgtab->setProperty("showGrid", "false");
57 msgtab->setEditTriggers(QAbstractItemView::NoEditTriggers);
58 msgtab->horizontalHeader()->resizeSections(QHeaderView::
60 msgtab->verticalHeader()->setVisible(false);
61 msgtab->setSelectionMode(QAbstractItemView::NoSelection);
62 msgtab->setSelectionBehavior(QAbstractItemView::SelectColumns);
63
64 but1 = new QPushButton(style()->standardIcon(
65 QStyle::SP_DialogCancelButton), _("Cancel"));
66 connect(but1, &QAbstractButton::clicked, this, &message_dlg::cancel_changes);
67 layout->addWidget(but1, 1, 1, 1, 1);
68 but2 = new QPushButton(style()->standardIcon(QStyle::SP_DialogOkButton),
69 _("Ok"));
70 connect(but2, &QAbstractButton::clicked, this, &message_dlg::apply_changes);
71 layout->addWidget(but2, 1, 2, 1, 1, Qt::AlignRight);
72 layout->addWidget(empty1, 0, 0, 1, 1);
73 layout->addWidget(msgtab, 0, 1, 1, 2);
74 layout->addWidget(empty2, 0, 3, 1, 1);
75 layout->setColumnStretch(0, 1);
76 layout->setColumnStretch(1, 10);
77 layout->setColumnStretch(3, 1);
79 gui()->gimme_place(this, "MSD");
80 index = gui()->add_game_tab(this);
81 gui()->game_tab_widget->setCurrentIndex(index);
82
83 fill_data();
84 margins = msgtab->contentsMargins();
85 len = msgtab->horizontalHeader()->length() + margins.left()
86 + margins.right()
87 + current_app()->style()->pixelMetric(QStyle::PM_ScrollBarExtent);
88 msgtab->setFixedWidth(len);
89 msgtab->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
90 but1->setFixedWidth(len / 3);
91 but2->setFixedWidth(len / 3);
92}
93
94/**********************************************************************/
98{
99 gui()->remove_repo_dlg("MSD");
100}
101
102/**********************************************************************/
106{
107 int i, j;
109 i = 0;
110 msgtab->setRowCount(0);
111
114 item->setText(get_event_message_text(ev));
115 msgtab->insertRow(i);
116 msgtab->setItem(i, 0, item);
117 for (j = 0; j < NUM_MW; j++) {
118 bool checked;
120 checked = messages_where[ev] & (1 << j);
121 if (checked) {
122 item->setCheckState(Qt::Checked);
123 } else {
124 item->setCheckState(Qt::Unchecked);
125 }
126 msgtab->setItem(i, j + 1, item);
127 }
128 i++;
130 msgtab->resizeColumnsToContents();
131
132}
133
134/**********************************************************************/
138{
139 int i, j;
141 Qt::CheckState state;
142
143 for (i = 0; i <= event_type_max(); i++) {
144 // Include possible undefined messages.
145 messages_where[i] = 0;
146 }
147 i = 0;
149 for (j = 0; j < NUM_MW; j++) {
150 bool checked;
151 item = msgtab->item(i, j + 1);
152 checked = messages_where[ev] & (1 << j);
153 state = item->checkState();
154 if ((state == Qt::Checked && !checked)
155 || (state == Qt::Unchecked && checked)) {
156 messages_where[ev] |= (1 << j);
157 }
158 }
159 i++;
161 close();
162}
163
164/**********************************************************************/
168{
169 close();
170}
171
172/**********************************************************************/
176{
177 int i;
178 QWidget *w;
179
180 if (!gui()->is_repo_dlg_open("MSD")) {
181 new message_dlg;
182 } else {
183 i = gui()->gimme_index_of("MSD");
184
185 fc_assert(i != -1);
186
187 if (gui()->game_tab_widget->currentIndex() == i) {
188 return;
189 }
190
191 w = gui()->game_tab_widget->widget(i);
192 gui()->game_tab_widget->setCurrentWidget(w);
193 }
194}
void cancel_changes()
void apply_changes()
QTableWidget * msgtab
Definition messagedlg.h:32
QGridLayout * layout
Definition messagedlg.h:33
void fill_data()
char * incite_cost
Definition comments.c:75
const char * get_event_message_text(enum event_type event)
Definition events.c:247
#define sorted_event_iterate_end
Definition events.h:213
#define sorted_event_iterate(event)
Definition events.h:203
#define _(String)
Definition fcintl.h:67
QApplication * current_app()
Definition gui_main.cpp:229
#define fc_assert(condition)
Definition log.h:176
void popup_messageopt_dialog()
static mpgui * gui
Definition mpgui_qt.cpp:52
int messages_where[E_COUNT]
Definition options.c:5037
#define NUM_MW
Definition options.h:576
int len
Definition packhand.c:127
Definition climisc.h:82
struct universal item
Definition climisc.h:83