19#include <QApplication>
37 &view_item_style_options)
39 QStyleOptionButton cbso;
41 QStyle::SE_CheckBoxIndicator, &cbso);
42 QPoint check_box_point(view_item_style_options.rect.x() +
43 view_item_style_options.rect.width() / 2 -
45 view_item_style_options.rect.y() +
46 view_item_style_options.rect.height() / 2 -
56 const QModelIndex &index)
const
60 r = QItemDelegate::sizeHint(
option, index);
61 r.setHeight(r.height() + 4);
70 &
option,
const QModelIndex &index)
const
72 QStyleOptionButton but;
73 QStyleOptionButton cbso;
78 QStyleOptionViewItem opt = QItemDelegate::setOptions(index,
option);
86 QItemDelegate::drawBackground(painter, opt, index);
87 pm = index.data().value<QPixmap>();
89 fm =
new QFontMetrics(f);
94 pm = pm.scaledToHeight(fm->height());
96 QItemDelegate::drawDecoration(painter, opt,
option.rect, pm);
99 pix.fill(index.data().value <QColor> ());
100 QItemDelegate::drawBackground(painter, opt, index);
101 QItemDelegate::drawDecoration(painter, opt,
option.rect, pix);
104 b = index.data().toBool();
105 QItemDelegate::drawBackground(painter, opt, index);
106 cbso.state |= QStyle::State_Enabled;
108 cbso.state |= QStyle::State_On;
110 cbso.state |= QStyle::State_Off;
114 QApplication::style()->drawControl(QStyle::CE_CheckBox, &cbso, painter);
117 QItemDelegate::paint(painter,
option, index);
120 QItemDelegate::drawBackground(painter, opt, index);
121 opt.displayAlignment = Qt::AlignRight;
123 rct.setTop((rct.top() + rct.bottom()) / 2
124 - opt.fontMetrics.height() / 2);
125 rct.setBottom((rct.top()+rct.bottom()) / 2
126 + opt.fontMetrics.height() / 2);
127 if (index.data().toInt() == -1) {
130 str = index.data().toString();
132 QItemDelegate::drawDisplay(painter, opt, rct,
str);
135 QItemDelegate::paint(painter,
option, index);
165 if (role == Qt::UserRole) {
166 return QVariant::fromValue((
void *)
ipplayer);
168 if (role != Qt::DisplayRole) {
187 if (
str.toInt() != 0) {
189 }
else if (
str ==
"?") {
220 if (!index.isValid()) {
224 if (index.row() >= 0 && index.row() <
rowCount() && index.column() >= 0
226 return plr_list[index.row()]->data(index.column(), role);
241 if (role == Qt::DisplayRole) {
257 if (!index.isValid() || role != Qt::DisplayRole) {
261 if (index.row() >= 0 && index.row() <
rowCount() && index.column() >= 0
263 bool change =
plr_list[index.row()]->setData(index.column(), value, role);
280 emit dataChanged(index(row, 0), index(row,
columnCount() - 1));
325 const QModelIndex &right)
const
331 int ri = right.row();
333 struct player *lplr = NULL;
334 struct player *rplr = NULL;
352 return column->
sort_func(lplr, rplr) < 0;
356 return QSortFilterProxyModel::lessThan(left, right);
368 setItemDelegate(
pid);
375 setRootIsDecorated(
false);
376 setAllColumnsShowFocus(
true);
377 setSortingEnabled(
true);
378 setSelectionMode(QAbstractItemView::SingleSelection);
379 setItemsExpandable(
false);
381 setAlternatingRowColors(
true);
382 header()->setContextMenuPolicy(Qt::CustomContextMenu);
384 connect(header(), &QWidget::customContextMenuRequested,
386 connect(selectionModel(),
387 SIGNAL(selectionChanged(
const QItemSelection &,
388 const QItemSelection &)),
390 const QItemSelection &)));
398 QItemSelection selection;
409 qvar = i.data(Qt::UserRole);
413 pplayer =
reinterpret_cast<struct
player *
>(qvar.value<
void *>());
415 selection.append(QItemSelectionRange(i));
418 selectionModel()->select(selection, QItemSelectionModel::Rows
419 | QItemSelectionModel::SelectCurrent);
427 QMenu *hideshow_column =
new QMenu(
this);
430 hideshow_column->setTitle(
_(
"Column visibility"));
433 QAction *myAct = hideshow_column->addAction(
435 Qt::DisplayRole).toString());
436 myAct->setCheckable(
true);
437 myAct->setChecked(!isColumnHidden(i));
441 hideshow_column->setAttribute(Qt::WA_DeleteOnClose);
442 connect(hideshow_column, &QMenu::triggered,
this,
455 setColumnHidden(col, !isColumnHidden(col));
456 if (!isColumnHidden(col) && columnWidth(col) <= 5)
457 setColumnWidth(col, 100);
460 hideshow_column->popup(QCursor::pos());
484 setColumnHidden(col, !isColumnHidden(col));
493 const QItemSelection &ds)
497 QModelIndexList indexes = sl.indexes();
504 QString etax, esci, elux, egold, egov;
507 QStringList sorted_list_a;
508 QStringList sorted_list_b;
512 bool entry_exist =
false;
525 if (indexes.isEmpty()) {
531 index = indexes.at(0);
532 qvar = index.data(Qt::UserRole);
533 pplayer =
reinterpret_cast<player *
>(qvar.value<
void *>());
548 res =
_(
"(Unknown)");
554 res =
_(
"(Unknown)");
565 etax = QString::number(pplayer->
economic.
tax) +
"%";
570 etax =
_(
"(Unknown)");
571 esci =
_(
"(Unknown)");
572 elux =
_(
"(Unknown)");
573 cult =
_(
"(Unknown)");
578 if (intel || pplayer == me) {
582 egold =
_(
"(Unknown)");
583 egov =
_(
"(Unknown)");
588 QString(
"<table><tr><td><b>") +
_(
"Nation") + QString(
"</b></td><td>")
590 + QString(
"</td><tr><td><b>") +
_(
"Ruler:") + QString(
"</b></td><td>")
593 + QString(
"</td></tr><tr><td><b>") +
_(
"Government:")
594 + QString(
"</b></td><td>") + egov.toHtmlEscaped()
595 + QString(
"</td></tr><tr><td><b>") +
_(
"Capital:")
596 + QString(
"</b></td><td>")
599 + QString(
"</td></tr><tr><td><b>") +
_(
"Gold:")
600 + QString(
"</b></td><td>") + egold.toHtmlEscaped()
601 + QString(
"</td></tr><tr><td><b>") +
_(
"Tax:")
602 + QString(
"</b></td><td>") + etax.toHtmlEscaped()
603 + QString(
"</td></tr><tr><td><b>") +
_(
"Science:")
604 + QString(
"</b></td><td>") + esci.toHtmlEscaped()
605 + QString(
"</td></tr><tr><td><b>") +
_(
"Luxury:")
606 + QString(
"</b></td><td>") + elux.toHtmlEscaped()
607 + QString(
"</td></tr><tr><td><b>") +
_(
"Researching:")
608 + QString(
"</b></td><td>") + res.toHtmlEscaped()
609 + QString(
"<td></tr><tr><td><b>") +
_(
"Culture:")
610 + QString(
"</b></td><td>") + cult.toHtmlEscaped()
613 + QString(
"</td>\u200B<td>")
614 + QString(
"</td></table>");
616 for (
int i = 0; i < static_cast<int>(DS_LAST); i++) {
627 if (
static_cast<int>(state->
type) == i && intel) {
630 + QString(diplstate_type_translated_name(
631 static_cast<diplstate_type
>(i)))
633 +
": " + QString(
"</b>") + nl;
651 if (!global_observer) {
655 techs_known = QString(
_(
"<b>Techs unknown by %1:</b>")).
676 sorted_list_a.sort(Qt::CaseInsensitive);
677 sorted_list_b.sort(Qt::CaseInsensitive);
678 foreach (res, sorted_list_a) {
680 + res.toHtmlEscaped() +
","
681 + QString(
"</i>") + sp;
683 foreach (res, sorted_list_b) {
685 + res.toHtmlEscaped() +
","
686 + QString(
"</i>") + sp;
690 + QString(
Q_(
"?tech:None")) + QString(
"</i>");
696 + QString(
Q_(
"?tech:None")) + QString(
"</i>");
703 tech_str = QString(
_(
"<b>Techs known by %1:</b>")).
711 sorted_list_a.sort(Qt::CaseInsensitive);
712 foreach (res, sorted_list_a) {
714 + QString(
"</i>") + sp;
720 rule =
_(
"All Wonders are known");
723 rule =
_(
"Small Wonders not known");
729 +
"</b>" + nl + QString(
_(
"Rule: ")) + rule + nl;
733 const char *cityname;
743 cityname =
_(
"(unknown city)");
746 notes =
_(
" (obsolete)");
749 cityname =
_(
"(lost)");
760 wonder_str += wonstr + QString(
" ") + cityname + notes + nl;
783 gui()->qt_settings.player_repo_sort_col = header()->sortIndicatorSection();
784 gui()->qt_settings.player_report_sort = header()->sortIndicatorOrder();
800 plr_label->setFrameStyle(QFrame::StyledPanel);
801 plr_label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
805 ally_label->setFrameStyle(QFrame::StyledPanel);
807 ally_label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
811 tech_label->setFrameStyle(QFrame::StyledPanel);
812 tech_label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
816 wonder_label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
848 line->setFrameShape(QFrame::VLine);
864 if (
gui()->qt_settings.player_repo_sort_col != -1) {
865 plr_wdg->sortByColumn(
gui()->qt_settings.player_repo_sort_col,
866 gui()->qt_settings.player_report_sort);
875 gui()->remove_repo_dlg(
"PLR");
883 gui()->gimme_place(
this,
"PLR");
885 gui()->game_tab_widget->setCurrentIndex(
index);
938 QMenu *ai_menu =
new QMenu(
this);
939 QAction *toggle_ai_act;
942 toggle_ai_act =
new QAction(
_(
"Toggle AI Mode"),
nullptr);
943 ai_menu->addAction(toggle_ai_act);
945 ai_menu->addSeparator();
948 QAction *ai_level_act;
949 QString ln = ai_level_translated_name(
static_cast<ai_level
>(
level));
951 ai_level_act =
new QAction(ln,
nullptr);
952 ai_level_act->setData(QVariant::fromValue(
level));
953 ai_menu->addAction(ai_level_act);
957 ai_menu->setAttribute(Qt::WA_DeleteOnClose);
958 connect(ai_menu, &QMenu::triggered,
962 if (act == toggle_ai_act) {
968 if (act && act->isVisible()) {
969 lvl = act->data().toInt();
979 ai_menu->popup(QCursor::pos());
1030 QModelIndex index = this->indexAt(
event->pos());
1032 if (index.isValid() &&
event->button() == Qt::RightButton
1037 QTreeView::mousePressEvent(
event);
1064 if (update_selection) {
1065 qmi =
plr_wdg->currentIndex();
1066 if (qmi.isValid()) {
1068 plr_wdg->setCurrentIndex(qmi);
1072 plr_wdg->header()->resizeSections(QHeaderView::ResizeToContents);
1117 if (!
gui()->is_repo_dlg_open(
"PLR")) {
1125 i =
gui()->gimme_index_of(
"PLR");
1126 w =
gui()->game_tab_widget->widget(i);
1127 if (w->isVisible()) {
1128 gui()->game_tab_widget->setCurrentIndex(0);
1132 gui()->game_tab_widget->setCurrentWidget(pr);
1146 if (
gui()->is_repo_dlg_open(
"PLR")) {
1147 i =
gui()->gimme_index_of(
"PLR");
1148 if (
gui()->game_tab_widget->currentIndex() == i) {
1149 w =
gui()->game_tab_widget->widget(i);
1165 if (
gui()->is_repo_dlg_open(
"PLR")) {
1166 i =
gui()->gimme_index_of(
"PLR");
1168 w =
gui()->game_tab_widget->widget(i);
static struct action * actions[MAX_NUM_ACTIONS]
int send_chat_printf(const char *format,...)
const char * city_name_get(const struct city *pcity)
static fc_font * instance()
QFont * get_font(QString name)
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
bool setData(int column, const QVariant &value, int role=Qt::DisplayRole)
QVariant data(int column, int role=Qt::DisplayRole) const
plr_item(struct player *pplayer)
plr_model(QObject *parent=0)
int rowCount(const QModelIndex &index=QModelIndex()) const
QVariant headerData(int section, Qt::Orientation orientation, int role) const
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole)
QVariant hide_data(int section) const
QList< plr_item * > plr_list
void notify_plr_changed(int row)
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
int columnCount(const QModelIndex &parent=QModelIndex()) const
void req_caancel_threaty()
void update_report(bool update_selection=true)
struct player * other_player
QPushButton * toggle_ai_but
void show_wonders_toggle()
void show_relations_toggle()
QPushButton * withdraw_but
QPushButton * show_relations
void req_wiithdrw_vision()
QPushButton * show_wonders
plr_sorter(QObject *parent)
bool lessThan(const QModelIndex &left, const QModelIndex &right) const
bool client_is_global_observer(void)
bool can_meet_with_player(const struct player *pplayer)
bool can_client_issue_orders(void)
const char * title_for_player(const struct player *pplayer, char *buf, size_t buf_len)
struct color * get_player_color(const struct tileset *t, const struct player *pplayer)
bool could_intel_with_player(const struct player *pplayer, const struct player *aplayer)
const char * government_name_for_player(const struct player *pplayer)
#define CAPTURE_DEFAULT_THIS
bool wonder_is_lost(const struct player *pplayer, const struct impr_type *pimprove)
bool wonder_is_built(const struct player *pplayer, const struct impr_type *pimprove)
struct city * city_from_wonder(const struct player *pplayer, const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
const char * improvement_name_translation(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
#define fc_assert_ret(condition)
#define fc_assert(condition)
const char *const default_font
const char * nation_adjective_for_player(const struct player *pplayer)
struct nation_type * nation_of_player(const struct player *pplayer)
const char * nation_plural_for_player(const struct player *pplayer)
int dsend_packet_diplomacy_cancel_pact(struct connection *pc, int other_player_id, enum clause_type clause)
int dsend_packet_diplomacy_init_meeting_req(struct connection *pc, int counterpart)
bool is_settable_ai_level(enum ai_level level)
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
int player_number(const struct player *pplayer)
const char * player_name(const struct player *pplayer)
bool team_has_embassy(const struct team *pteam, const struct player *tgt_player)
struct city * player_primary_capital(const struct player *pplayer)
enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1, const struct player *p2)
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
bool gives_shared_vision(const struct player *me, const struct player *them)
#define ai_level_cmd(_level_)
#define players_iterate_end
#define players_iterate(_pplayer)
static bool is_barbarian(const struct player *pplayer)
#define players_iterate_alive_end
#define players_iterate_alive(_pplayer)
void popdown_players_report()
void real_players_dialog_update(void *unused)
void popup_players_dialog(bool raise)
static QRect check_box_rect(const QStyleOptionViewItem &view_item_style_options)
struct player_dlg_column player_dlg_columns[]
const int num_player_dlg_columns
const char * research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
struct research * research_get(const struct player *pplayer)
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
struct setting_list * level[OLEVELS_NUM]
struct packet_game_info info
enum wonder_visib_type small_wonder_visibility
bool(* bool_func)(const struct player *)
plr_dlg_sort_func sort_func
const char *(* func)(const struct player *)
enum player_dlg_column_type type
struct player::@69::@72 client
struct player_economic economic
struct research::@75::@77 client
Tech_type_id advance_number(const struct advance *padvance)
#define advance_iterate(_start, _p)
#define advance_iterate_end
struct sprite * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)