29 #include <QContextMenuEvent>
42 constexpr
auto BuildingRole =
44 constexpr
auto UnitRole = Qt::UserRole + 2;
51 : QListView(parent), m_model(new QStandardItemModel(this))
55 setEditTriggers(NoEditTriggers);
56 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
57 setSelectionMode(NoSelection);
58 setSizeAdjustPolicy(AdjustToContents);
59 setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
60 setVerticalScrollMode(ScrollPerPixel);
62 connect(
this, &QAbstractItemView::doubleClicked,
this,
89 for (
int i = 0; i < targets_used; i++) {
94 auto rect = QRect(QPoint(), sprite.size());
95 rect.moveCenter(QPoint(icon_width / 2, sprite.height() / 2));
97 QPixmap pixmap(icon_width, sprite.height());
98 pixmap.fill(Qt::transparent);
100 p.drawPixmap(rect, sprite);
103 auto item =
new QStandardItem;
104 item->setData(pixmap, Qt::DecorationRole);
106 item->setEditable(
false);
122 auto pixmap = QPixmap(icon_width,
124 pixmap.fill(Qt::transparent);
133 auto *
item =
new QStandardItem();
134 item->setData(pixmap, Qt::DecorationRole);
136 item->setEditable(
false);
161 for (
int i = 0; i <
m_model->rowCount(); ++i) {
162 height += sizeHintForRow(i);
165 return QSize(6 + sizeHintForColumn(0), height);
178 const auto index = indexAt(
event->pos());
189 if (
const auto data =
item->data(BuildingRole); data.isValid()) {
193 auto menu =
new QMenu;
194 menu->setAttribute(Qt::WA_DeleteOnClose);
196 menu->addSeparator();
197 menu->addAction(
_(
"Show in Help"), [=] {
202 menu->popup(
event->globalPos());
203 }
else if (
const auto data =
item->data(UnitRole); data.isValid()) {
209 auto menu =
new QMenu;
210 menu->setAttribute(Qt::WA_DeleteOnClose);
212 menu->addSeparator();
213 menu->addAction(
_(
"Show in Help"), [=] {
216 menu->popup(
event->globalPos());
243 if (
const auto data =
item->data(BuildingRole); data.isValid()) {
246 }
else if (
const auto data =
item->data(UnitRole); data.isValid()) {
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
int city_unit_unhappiness(const unit *punit, int *free_unhappy)
Query unhappiness caused by a given unit.
void popdown_city_dialog()
Closes the city overlay.
Helper class to safely sell a city improvement.
static QAction * add_to_menu(QWidget *parent, QMenu *menu, const city *city, int improvement_id)
Adds a menu item to sell an improvement in a city.
city_dialog * city_overlay
bool can_client_issue_orders()
Returns TRUE iff the client can issue orders (such as giving unit commands).
void name_and_sort_items(struct universal *targets, int num_targets, struct item *items, bool show_cost, struct city *pcity)
Takes an array of compound ids (cids).
int collect_already_built_targets(struct universal *targets, struct city *pcity)
Collect the cids of all improvements which are built in the given city.
#define MAX_NUM_PRODUCTION_TARGETS
void unit_focus_add(struct unit *punit)
Adds this unit to the list of units in focus.
void unit_focus_set(struct unit *punit)
Sets the focus unit directly.
int get_city_bonus(const struct city *pcity, enum effect_type effect_type, enum vision_layer vlayer)
Returns the effect bonus at a city.
struct unit * game_unit_by_number(int id)
Find unit out of all units in game: now uses fast idex method, instead of looking through all units o...
struct city * game_city_by_number(int id)
Often used function to get a city pointer from a city ID.
void popup_help_dialog_typed(const char *item, enum help_page_type htype)
Popup the help dialog to display help on the given string topic from the given section.
struct impr_type * improvement_by_number(const Impr_type_id id)
Returns the improvement type for the given index/ID.
Impr_type_id improvement_number(const struct impr_type *pimprove)
Return the improvement index.
bool is_great_wonder(const struct impr_type *pimprove)
Is this building a great wonder?
const char * improvement_name_translation(const struct impr_type *pimprove)
Return the (translated) name of the given improvement.
#define fc_assert_ret(condition)
void add_quick_unit_actions(QMenu *menu, const std::vector< unit * > &units)
Adds a small set of common unit actions to a menu.
pageGame * queen()
Return game instandce.
struct city::@15::@18 client
struct unit_list * units_supported
const QString unit_description(const unit *punit)
Returns the unit description.
int tileset_unit_width(const struct tileset *t)
Return the unit tile width of the current tileset.
int tileset_unit_layout_offset_y(const struct tileset *t)
Offset to layout extra unit sprites, such as upkeep.
QEvent::Type TilesetChanged
An event type sent to all widgets when the current tileset changes.
struct tileset * get_tileset()
Returns the tileset.
int tileset_unit_with_upkeep_height(const struct tileset *t)
Suitable canvas height for a unit icon that includes upkeep sprites.
const QPixmap * get_building_sprite(const struct tileset *t, const struct impr_type *pimprove)
Return the sprite for the building/improvement.
const struct impr_type * building
#define unit_list_iterate(unitlist, punit)
#define unit_list_iterate_end
const char * unit_name_translation(const struct unit *punit)
Return the (translated) name of the unit.
void put_unit_city_overlays(const unit *punit, QPixmap *pcanvas, int canvas_x, int canvas_y, const int *upkeep_cost, int happy_cost)
Draw food, gold, and shield upkeep values on the unit.
void put_unit(const struct unit *punit, QPixmap *pcanvas, const QPoint &canvas_loc)
Draw the given unit onto the canvas store at the given location.