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

Freeciv-3.1

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/**********************************************************************/
38message_dlg::message_dlg()
39{
40 int index;
41 QStringList slist;
42 QLabel *empty1, *empty2;
43 QPushButton *but1;
44 QPushButton *but2;
45 QMargins margins;
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::
59 ResizeToContents);
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);
78 setLayout(layout);
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/**********************************************************************/
97message_dlg::~message_dlg()
98{
99 gui()->remove_repo_dlg("MSD");
100}
101
102/**********************************************************************/
105 void message_dlg::fill_data()
106{
107 int i, j;
108 QTableWidgetItem *item;
109 i = 0;
110 msgtab->setRowCount(0);
111
112 sorted_event_iterate(ev) {
113 item = new QTableWidgetItem;
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;
119 item = new QTableWidgetItem;
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++;
129 } sorted_event_iterate_end;
130 msgtab->resizeColumnsToContents();
131
132}
133
134/**********************************************************************/
137 void message_dlg::apply_changes()
138{
139 int i, j;
140 QTableWidgetItem *item;
141 Qt::CheckState state;
142 for (i = 0; i <= event_type_max(); i++) {
143 /* Include possible undefined messages. */
144 messages_where[i] = 0;
145 }
146 i = 0;
147 sorted_event_iterate(ev) {
148 for (j = 0; j < NUM_MW; j++) {
149 bool checked;
150 item = msgtab->item(i, j + 1);
151 checked = messages_where[ev] & (1 << j);
152 state = item->checkState();
153 if ((state == Qt::Checked && !checked)
154 || (state == Qt::Unchecked && checked)) {
155 messages_where[ev] |= (1 << j);
156 }
157 }
158 i++;
159 } sorted_event_iterate_end;
160 close();
161}
162
163/**********************************************************************/
166 void message_dlg::cancel_changes()
167{
168 close();
169}
170
171/**********************************************************************/
174 void popup_messageopt_dialog(void)
175{
176 int i;
177 QWidget *w;
178
179 if (!gui()->is_repo_dlg_open("MSD")) {
180 new message_dlg;
181 } else {
182 i = gui()->gimme_index_of("MSD");
183
184 fc_assert(i != -1);
185
186 if (gui()->game_tab_widget->currentIndex() == i) {
187 return;
188 }
189
190 w = gui()->game_tab_widget->widget(i);
191 gui()->game_tab_widget->setCurrentWidget(w);
192 }
193}
message_dlg
Definition messagedlg.h:30
message_dlg::message_dlg
message_dlg()
Definition messagedlg.cpp:38
message_dlg::cancel_changes
void cancel_changes()
Definition messagedlg.cpp:166
message_dlg::apply_changes
void apply_changes()
Definition messagedlg.cpp:137
message_dlg::msgtab
QTableWidget * msgtab
Definition messagedlg.h:32
message_dlg::layout
QGridLayout * layout
Definition messagedlg.h:33
message_dlg::fill_data
void fill_data()
Definition messagedlg.cpp:105
message_dlg::~message_dlg
~message_dlg()
Definition messagedlg.cpp:97
get_event_message_text
const char * get_event_message_text(enum event_type event)
Definition events.c:245
sorted_event_iterate_end
#define sorted_event_iterate_end
Definition events.h:211
sorted_event_iterate
#define sorted_event_iterate(event)
Definition events.h:201
fc_client.h
_
#define _(String)
Definition fcintl.h:67
gui_main.h
messagedlg.h
current_app
QApplication * current_app()
Definition gui_main.cpp:220
fc_assert
#define fc_assert(condition)
Definition log.h:176
popup_messageopt_dialog
void popup_messageopt_dialog(void)
Definition messagedlg.cpp:174
gui
static mpgui * gui
Definition mpgui_qt.cpp:52
messages_where
int messages_where[E_COUNT]
Definition options.c:5028
options.h
NUM_MW
#define NUM_MW
Definition options.h:553
len
int len
Definition packhand.c:125
item
Definition climisc.h:80
item::item
struct universal item
Definition climisc.h:81