18 #include <QMouseEvent>
20 #include <QSortFilterProxyModel>
21 #include <qnamespace.h>
52 QStyleOptionButton cbso;
54 QStyle::SE_CheckBoxIndicator, &cbso);
55 QPoint check_box_point(view_item_style_options.rect.x()
56 + view_item_style_options.rect.width() / 2
58 view_item_style_options.rect.y()
59 + view_item_style_options.rect.height() / 2
68 const QModelIndex &index)
const
70 return QItemDelegate::sizeHint(
option, index);
77 const QStyleOptionViewItem &
option,
78 const QModelIndex &index)
const
80 QStyleOptionButton but;
81 QStyleOptionButton cbso;
87 QStyleOptionViewItem opt = QItemDelegate::setOptions(index,
option);
91 QItemDelegate::drawBackground(painter, opt, index);
92 QItemDelegate::drawDecoration(painter, opt,
option.rect,
93 index.data().value<QPixmap>());
96 pix.fill(index.data().value<QColor>());
97 QItemDelegate::drawBackground(painter, opt, index);
98 QItemDelegate::drawDecoration(painter, opt,
option.rect, pix);
101 b = index.data().toBool();
102 QItemDelegate::drawBackground(painter, opt, index);
103 cbso.state |= QStyle::State_Enabled;
105 cbso.state |= QStyle::State_On;
107 cbso.state |= QStyle::State_Off;
111 QApplication::style()->drawControl(QStyle::CE_CheckBox, &cbso, painter);
115 QItemDelegate::paint(painter,
option, index);
118 QItemDelegate::drawBackground(painter, opt, index);
119 opt.displayAlignment = Qt::AlignRight;
121 rct.setTop((rct.top() + rct.bottom()) / 2
122 - opt.fontMetrics.height() / 2);
123 rct.setBottom((rct.top() + rct.bottom()) / 2
124 + opt.fontMetrics.height() / 2);
125 if (index.data().toInt() == -1) {
126 str = QStringLiteral(
"?");
128 str = index.data().toString();
130 QItemDelegate::drawDisplay(painter, opt, rct, str);
133 QItemDelegate::paint(painter,
option, index);
162 if (role == Qt::UserRole) {
163 return QVariant::fromValue((
void *)
ipplayer);
174 auto fm = std::make_unique<QFontMetrics>(f);
176 ->scaledToHeight(fm->height());
185 if (role == Qt::DisplayRole) {
187 }
else if (role == Qt::DecorationRole
199 if (str.toInt() != 0) {
201 }
else if (str == QLatin1String(
"?")) {
232 if (!index.isValid()) {
235 if (index.row() >= 0 && index.row() <
rowCount() && index.column() >= 0
237 return plr_list[index.row()]->data(index.column(), role);
250 if (role == Qt::DisplayRole) {
264 if (!index.isValid() || role != Qt::DisplayRole) {
267 if (index.row() >= 0 && index.row() <
rowCount() && index.column() >= 0
270 plr_list[index.row()]->setData(index.column(), value, role);
284 emit dataChanged(index(row, 0), index(row,
columnCount() - 1));
317 setItemDelegate(
pid);
325 coll.setCaseSensitivity(Qt::CaseInsensitive);
326 coll.setLocale(locale());
327 coll.setNumericMode(
true);
330 sortByColumn(0, Qt::AscendingOrder);
332 setSortingEnabled(
true);
333 setSelectionMode(QAbstractItemView::SingleSelection);
335 setAlternatingRowColors(
true);
337 auto header = horizontalHeader();
338 header->setContextMenuPolicy(Qt::CustomContextMenu);
339 header->setStretchLastSection(
true);
341 connect(header, &QWidget::customContextMenuRequested,
this,
344 connect(selectionModel(), &QItemSelectionModel::selectionChanged,
this,
354 QItemSelection selection;
364 qvar = i.data(Qt::UserRole);
368 pplayer =
reinterpret_cast<struct
player *
>(qvar.value<
void *>());
370 selection.append(QItemSelectionRange(i));
373 selectionModel()->select(selection,
374 QItemSelectionModel::Rows
375 | QItemSelectionModel::SelectCurrent);
383 QMenu *hideshow_column =
new QMenu(
this);
384 hideshow_column->setTitle(
_(
"Column visibility"));
387 QAction *myAct = hideshow_column->addAction(
390 myAct->setCheckable(
true);
391 myAct->setChecked(!isColumnHidden(i));
395 hideshow_column->setAttribute(Qt::WA_DeleteOnClose);
396 connect(hideshow_column, &QMenu::triggered,
this, [=](QAction *act) {
408 setColumnHidden(col, !isColumnHidden(col));
409 if (!isColumnHidden(col) && columnWidth(col) <= 5) {
410 setColumnWidth(col, 100);
414 hideshow_column->popup(QCursor::pos());
436 setColumnHidden(col, !isColumnHidden(col));
445 const QItemSelection &ds)
450 QModelIndexList indexes = sl.indexes();
456 QString sp = QStringLiteral(
" ");
457 QString etax, esci, elux, egold, egov;
459 QString nl = QStringLiteral(
"<br>");
460 QStringList sorted_list_a;
461 QStringList sorted_list_b;
465 bool entry_exist =
false;
474 if (indexes.isEmpty()) {
479 index = indexes.at(0);
480 qvar = index.data(Qt::UserRole);
481 pplayer =
reinterpret_cast<player *
>(qvar.value<
void *>());
494 res =
_(
"(Unknown)");
500 res =
_(
"(Unknown)");
511 etax = QString::number(pplayer->
economic.
tax) +
"%";
515 etax =
_(
"(Unknown)");
516 esci =
_(
"(Unknown)");
517 elux =
_(
"(Unknown)");
520 cult = QString::number(pplayer->
client.culture);
522 cult =
_(
"(Unknown)");
527 egold =
_(
"(Unknown)");
532 egov =
_(
"(Unknown)");
536 QString line = QStringLiteral(
"<tr><td><b>%1</b></td><td>%2</td></tr>");
539 line.arg(
_(
"Nation:"))
543 line.arg(
_(
"Ruler:"))
546 intel_str += line.arg(
_(
"Government:")).arg(egov.toHtmlEscaped());
548 line.arg(
_(
"Capital:"))
551 intel_str += line.arg(
_(
"Gold:")).arg(egold.toHtmlEscaped());
552 intel_str += line.arg(
_(
"Tax:")).arg(etax.toHtmlEscaped());
553 intel_str += line.arg(
_(
"Science:")).arg(esci.toHtmlEscaped());
554 intel_str += line.arg(
_(
"Luxury:")).arg(elux.toHtmlEscaped());
555 intel_str += line.arg(
_(
"Researching:")).arg(res.toHtmlEscaped());
556 intel_str += line.arg(
_(
"Culture:")).arg(cult.toHtmlEscaped());
559 for (
int i = 0; i < static_cast<int>(DS_LAST); i++) {
571 && !
BV_ISSET(other->client.visible, NI_DIPLOMACY)) {
578 if (
static_cast<int>(state->
type) == i) {
581 + QString(diplstate_type_translated_name(
582 static_cast<diplstate_type
>(i)))
584 +
": " + QStringLiteral(
"</b>") + nl;
599 QStringLiteral(
"."));
603 if (!global_observer &&
BV_ISSET(pplayer->
client.visible, NI_TECHS)) {
607 QString(
_(
"<b>Techs unknown by %1:</b> "))
628 sorted_list_a.sort(Qt::CaseInsensitive);
629 sorted_list_b.sort(Qt::CaseInsensitive);
630 for (
auto const &res : qAsConst(sorted_list_a)) {
632 +
"," + QStringLiteral(
"</i>") + sp;
634 for (
auto const &res : qAsConst(sorted_list_b)) {
636 + res.toHtmlEscaped() +
"," + QStringLiteral(
"</i>")
641 + QString(
Q_(
"?tech:None")) + QStringLiteral(
"</i>");
644 QStringLiteral(
"."));
648 + QString(
Q_(
"?tech:None")) + QStringLiteral(
"</i>");
651 QStringLiteral(
"."));
654 }
else if (global_observer) {
656 QString(
_(
"<b>Techs known by %1:</b> "))
667 sorted_list_a.sort(Qt::CaseInsensitive);
668 for (
auto const &res : qAsConst(sorted_list_a)) {
670 + QStringLiteral(
"</i>") + sp;
687 }
else if (
const auto city =
702 tech_str += QString(
_(
"<b>Known Wonders: </b>"));
727 horizontalHeader()->sortIndicatorSection();
729 horizontalHeader()->sortIndicatorOrder();
739 ui.meet_but->setText(
_(
"Meet"));
740 ui.cancel_but->setText(
_(
"Cancel Treaty"));
741 ui.withdraw_but->setText(
_(
"Withdraw Vision"));
742 ui.toggle_ai_but->setText(
_(
"Toggle AI Mode"));
743 ui.diplo_but->setText(
_(
"Active Diplomacy"));
744 ui.diplo_but->setEnabled(
false);
745 connect(
ui.meet_but, &QAbstractButton::pressed,
this,
747 connect(
ui.cancel_but, &QAbstractButton::pressed,
this,
749 connect(
ui.withdraw_but, &QAbstractButton::pressed,
this,
751 connect(
ui.toggle_ai_but, &QAbstractButton::pressed,
this,
753 connect(
ui.diplo_but, &QAbstractButton::pressed,
this,
755 setLayout(
ui.layout);
758 if (
king()->qt_settings.player_repo_sort_col != -1) {
759 ui.plr_wdg->sortByColumn(
king()->qt_settings.player_repo_sort_col,
760 king()->qt_settings.player_report_sort);
762 const bool has_meeting =
764 ui.diplo_but->setEnabled(has_meeting);
767 ui.plr_wdg->set_pr_rep(
this);
790 if (
ui.meet_but->isEnabled()) {
800 dsend_packet_diplomacy_cancel_pact(
822 dsend_packet_diplomacy_init_meeting_req(&
client.
conn,
831 dsend_packet_diplomacy_cancel_pact(
840 QAction *toggle_ai_act;
841 QAction *ai_level_act;
842 QMenu *ai_menu =
new QMenu(
this);
845 toggle_ai_act =
new QAction(
_(
"Toggle AI Mode"),
nullptr);
846 ai_menu->addAction(toggle_ai_act);
847 ai_menu->addSeparator();
850 QString ln = ai_level_translated_name(
static_cast<ai_level
>(
level));
851 ai_level_act =
new QAction(ln,
nullptr);
852 ai_level_act->setData(QVariant::fromValue(
level));
853 ai_menu->addAction(ai_level_act);
856 ai_menu->setAttribute(Qt::WA_DeleteOnClose);
857 connect(ai_menu, &QMenu::triggered, [=](QAction *act) {
859 if (act == toggle_ai_act) {
864 if (act && act->isVisible()) {
865 level = act->data().toInt();
875 ai_menu->popup(QCursor::pos());
883 QModelIndex index = this->indexAt(
event->pos());
884 if (index.isValid() &&
event->button() == Qt::RightButton
888 QTableView::mousePressEvent(
event);
900 if (update_selection) {
901 qmi =
ui.plr_wdg->currentIndex();
903 ui.plr_wdg->clearSelection();
904 ui.plr_wdg->setCurrentIndex(qmi);
918 ui.plr_wdg->get_model()->populate();
921 auto header =
ui.plr_wdg->horizontalHeader();
922 header->resizeSections(QHeaderView::ResizeToContents);
923 header->resizeSection(header->count() - 1, QHeaderView::Stretch);
925 ui.meet_but->setDisabled(
true);
926 ui.cancel_but->setDisabled(
true);
927 ui.withdraw_but->setDisabled(
true);
928 ui.toggle_ai_but->setDisabled(
true);
929 ui.plr_label->setText(
ui.plr_wdg->intel_str);
930 ui.ally_label->setText(
ui.plr_wdg->ally_str);
931 ui.tech_label->setText(
ui.plr_wdg->tech_str);
943 ui.cancel_but->setEnabled(
true);
945 ui.toggle_ai_but->setEnabled(
true);
949 ui.withdraw_but->setEnabled(
true);
952 ui.meet_but->setEnabled(
true);
954 const bool has_meeting =
956 ui.diplo_but->setEnabled(has_meeting);
958 ui.plr_wdg->restore_selection();
969 if (!
queen()->isRepoDlgOpen(QStringLiteral(
"PLR"))) {
979 if (w->isVisible()) {
1000 if (
queen()->isRepoDlgOpen(QStringLiteral(
"PLR"))) {
1002 if (
queen()->game_tab_widget->currentIndex() == i) {
1019 if (
queen()->isRepoDlgOpen(QStringLiteral(
"PLR"))) {
static struct action * actions[MAX_NUM_ACTIONS]
QString strvec_to_and_list(const QVector< QString > &psv)
bool BV_ISSET(const BV &bv, int bit)
int send_chat_printf(const char *format,...)
Send the message as a chat to the server.
const char * city_name_get(const struct city *pcity)
Return the name of the city.
QFont getFont(const QString &name, double zoom=1.0) const
Returns desired font.
static fcFont * instance()
Returns instance of fc_font.
A sort and filter proxy model supporting string collation.
void set_collator(const QCollator &coll)
Changes the collator currently in use.
int gimmeIndexOf(const QString &str)
Returns index on game tab page of given report dialog.
int addGameTab(QWidget *widget)
Inserts tab widget to game view page.
void removeRepoDlg(const QString &str)
Removes report dialog string from the list marking it as closed.
void updateSidebarTooltips()
Updates top bar tooltips.
void gimmePlace(QWidget *widget, const QString &str)
Finds not used index on game_view_tab and returns it.
fc_game_tab_widget * game_tab_widget
void reloadSidebarIcons()
Reloads top bar icons (useful on theme change)
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
Slighty increase deafult cell height.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Paint evenet for custom player item delegation.
bool setData(int column, const QVariant &value, int role=Qt::DisplayRole)
Sets data for plr_item (not used)
QVariant data(int column, int role=Qt::DisplayRole) const
Returns data from item.
plr_item(struct player *pplayer)
Constructor for plr_item.
plr_model(QObject *parent=0)
Constructor for player model.
int columnCount(const QModelIndex &parent=QModelIndex()) const override
void populate()
Fills model with data.
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole) override
Sets data in model.
QVariant hide_data(int section) const
Returns information about column if hidden.
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Returns header data from model.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Returns data from model.
QList< plr_item * > plr_list
void notify_plr_changed(int row)
Notifies that row has been changed.
int rowCount(const QModelIndex &index=QModelIndex()) const override
~plr_model() override
Destructor for player model.
void plr_withdraw_vision()
Slot for withdrawing vision.
void call_meeting()
Public function to call meeting.
void plr_diplomacy()
Slot for diplomacy.
void update_report(bool update_selection=true)
Updates widget.
void plr_cancel_threaty()
Slot for canceling treaty.
struct player * other_player
void toggle_ai_mode()
Slot for changing AI mode.
void req_meeeting()
Slot for meeting request.
plr_report()
Constructor for plr_report.
void init()
Adds plr_report to tab widget.
~plr_report() override
Destructor for plr_report.
bool can_meet_with_player(const struct player *pplayer)
Returns TRUE iff the client can do diplomatic meetings with another given player.
bool client_is_global_observer()
Returns whether client is global observer.
struct player * client_player()
Either controlling or observing.
bool can_client_issue_orders()
Returns TRUE iff the client can issue orders (such as giving unit commands).
QColor get_player_color(const struct tileset *t, const struct player *pplayer)
Return the color of the player.
class fc_client * king()
Return fc_client instance.
struct city * game_city_by_number(int id)
Often used function to get a city pointer from a city ID.
const char * government_name_for_player(const struct player *pplayer)
Return the (translated) name of the given government of a player.
const char * ruler_title_for_player(const struct player *pplayer, char *buf, size_t buf_len)
Return the ruler title of the player (translated).
Impr_type_id improvement_count()
Return the number of improvements.
struct impr_type * improvement_by_number(const Impr_type_id id)
Returns the improvement type for the given index/ID.
const char * improvement_name_translation(const struct impr_type *pimprove)
Return the (translated) name of the given improvement.
#define fc_assert_ret(condition)
#define fc_assert(condition)
const char *const default_font
const char * nation_plural_for_player(const struct player *pplayer)
Return the (translated) plural noun of the given nation of a player.
const char * nation_adjective_for_player(const struct player *pplayer)
Return the (translated) adjective for the given nation of a player.
struct nation_type * nation_of_player(const struct player *pplayer)
Return the nation of a player.
pageGame * queen()
Return game instandce.
bool is_settable_ai_level(enum ai_level level)
Return is AI can be set to given level.
bool players_on_same_team(const struct player *pplayer1, const struct player *pplayer2)
Return TRUE if players are in the same team.
int player_number(const struct player *pplayer)
Return the player index/number/id.
int player_count()
Return the number of players.
struct city * player_primary_capital(const struct player *pplayer)
Locate the player's primary capital city, (nullptr Otherwise)
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
enum dipl_reason pplayer_can_cancel_treaty(const struct player *p1, const struct player *p2)
The senate may not allow you to break the treaty.
bool gives_shared_vision(const struct player *me, const struct player *them)
Return TRUE iff the player me gives shared vision to player them.
struct player_diplstate * player_diplstate_get(const struct player *plr1, const struct player *plr2)
Returns diplomatic state type between two players.
#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)
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
QString research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Store the translated name of the given tech (including A_FUTURE) in 'buf'.
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Returns state of the tech for current research.
struct setting_list * level[OLEVELS_NUM]
Qt::SortOrder player_report_sort
The base class for options.
enum player_dlg_column_type type
struct player::@65::@68 client
struct government * government
struct player_economic economic
struct research::@71::@73 client
Tech_type_id advance_number(const struct advance *padvance)
Return the advance index.
#define advance_iterate(_start, _p)
#define advance_iterate_end
const QPixmap * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)
Return the sprite for the nation.
const QPixmap * get_government_sprite(const struct tileset *t, const struct government *gov)
Return the sprite for the government.
void top_bar_show_map()
Callback to show map.
void update_top_bar_diplomacy_status(bool notify)
Function to update the top bar button.
void popdown_players_report()
Closes players report.
void close_intel_dialog(struct player *p)
Close an intelligence dialog for the given player.
void real_players_dialog_update(void *unused)
Update all information in the player list dialog.
static QRect check_box_rect(const QStyleOptionViewItem &view_item_style_options)
Help function to draw checkbox inside delegate.
void popup_players_dialog()
Display the player list dialog.
void update_intel_dialog(struct player *p)
Update the intelligence dialog for the given player.
struct player_dlg_column player_dlg_columns[]
...
const int num_player_dlg_columns
static void improve(struct reqtree *tree)
Try to reduce the number of crossings by swapping two nodes and checking if it improves the situation...