16 #include <QMouseEvent>
43 ufont.setItalic(
true);
48 setMouseTracking(
true);
50 popup(mapFromGlobal(QCursor::pos()));
72 QList<QPixmap *> pix_list;
101 h_pix->fill(palette().color(QPalette::HighlightedText));
112 pix->fill(Qt::transparent);
113 for (
auto *punit : qAsConst(
unit_list)) {
116 unit_pixmap->fill(Qt::transparent);
117 put_unit(punit, unit_pixmap, QPoint());
118 img = unit_pixmap->toImage();
120 cropped_img =
img.copy(crop);
122 img = cropped_img.scaled(
124 Qt::KeepAspectRatio, Qt::SmoothTransformation);
129 Qt::SmoothTransformation);
131 pixc = QPixmap::fromImage(
img);
132 pixp =
new QPixmap(pixc);
133 pix_list.push_back(pixp);
139 ufont.setPixelSize(a);
141 pen.setColor(palette().color(QPalette::Text));
144 while (!pix_list.isEmpty()) {
145 tmp_pix = pix_list.takeFirst();
152 Q_ASSERT(punit !=
nullptr);
155 p.drawPixmap(x, y, *
h_pix);
156 p.drawPixmap(x, y, *tmp_pix);
158 p.drawPixmap(x, y, *tmp_pix);
166 str +=
" " + QString(
_(
"(%1T)")).arg(punit->
fuel - 1);
169 str = QString(
_(
"MP:")) + str;
170 p.drawText(x, y +
item_size.height() - 4, str);
177 setFixedWidth(
pix->width() + 20);
178 setFixedHeight(
pix->height() + 3 * fm.height() + 2 * 6);
179 qDeleteAll(pix_list.begin(), pix_list.end());
194 if (
event->x() > width() - 11 ||
event->y() > height() - fm.height() - 5
195 ||
event->y() < fm.height() + 3 ||
event->x() < 11) {
198 a = (
event->x() - 10) /
item_size.width();
199 b = (
event->y() - fm.height() - 3) /
item_size.height();
222 QMenu::mousePressEvent(
event);
235 QString str, str2, unit_name;
239 if (point_size < 0) {
240 f_size = &pixel_size;
242 f_size = &point_size;
248 str2 = QString(
_(
"%1 HP:%2/%3"))
252 str = QString(
PL_(
"%1 unit",
"%1 units", unit_list_size(
utile->
units)))
254 for (i = *f_size; i > 4; i--) {
255 if (point_size < 0) {
261 if (10 + qfm.horizontalAdvance(str2) < width()) {
266 if (
pix !=
nullptr) {
267 painter->drawPixmap(10, h + 3, *
pix);
268 pen.setColor(palette().color(QPalette::Text));
269 painter->setPen(pen);
271 painter->drawText(10, h, str);
273 painter->drawText(10, height() - 5 - h, unit_name);
274 painter->drawText(10, height() - 5, str2);
279 float page_height = 3.0f / maxl;
280 float page_start = (
static_cast<float>(
show_line)) / maxl;
281 pen.setColor(palette().color(QPalette::HighlightedText));
282 painter->setBrush(palette().color(QPalette::HighlightedText).darker());
283 painter->setPen(palette().color(QPalette::HighlightedText).darker());
284 painter->drawRect(
pix->width() + 10, h, 8, h +
pix->height());
285 painter->setPen(pen);
286 painter->drawRoundedRect(
pix->width() + 10,
287 h + page_start *
pix->height(), 8,
288 h + page_height *
pix->height(), 2, 2);
291 if (point_size < 0) {
303 QMenu::paintEvent(
event);
319 if (
utile ==
nullptr) {
323 if (
utile ==
nullptr) {
330 if (
utile !=
nullptr) {
332 if (punit_list !=
nullptr) {
353 QMenu::closeEvent(
event);
372 const auto delta =
event->angleDelta().y();
376 }
else if (delta > 0) {
392 if (unit_sel !=
nullptr) {
409 if (unit_sel !=
nullptr) {
422 if (unit_sel !=
nullptr) {
QRect zealous_crop_rect(QImage &p)
Return rectangle containing pure image (crops transparency)
QFont getFont(const QString &name, double zoom=1.0) const
Returns desired font.
static fcFont * instance()
Returns instance of fc_font.
units_select * unit_selector
std::vector< unit * > unit_list
size of each pixmap of unit
void mousePressEvent(QMouseEvent *event) override
Mouse pressed event for units_select.
~units_select() override
Destructor for unit select.
void paint(QPainter *painter, QPaintEvent *event)
Redirected paint event.
void closeEvent(QCloseEvent *event) override
Close event for units_select, restores focus to map.
void update_units()
Updates unit list on tile.
void wheelEvent(QWheelEvent *event) override
Mouse wheel event for units_select.
QSize item_size
pixmap for highlighting
units_select(struct tile *ptile, QWidget *parent=0)
Contructor for units_select.
void create_pixmap()
Create pixmap of whole widget except borders (pix)
void paintEvent(QPaintEvent *event) override
Paint event, redirects to paint(...)
void mouseMoveEvent(QMouseEvent *event) override
Event for mouse moving around units_select.
std::vector< unit * > sorted(const unit_list *units)
Returns a version of units sorted in the way the user would like to see them.
bool client_is_global_observer()
Returns whether client is global observer.
void unit_focus_set(struct unit *punit)
Sets the focus unit directly.
struct unit * head_of_units_in_focus()
Return head of focus units list.
#define PL_(String1, String2, n)
const char * move_points_text(int mp, bool reduce)
Simple version of move_points_text_full() – render positive movement points as text without any prefi...
const char *const notify_label
pageGame * queen()
Return game instandce.
int tileset_hex_width(const struct tileset *t)
Return the hex_width of the current tileset.
int tileset_unit_width(const struct tileset *t)
Return the unit tile width of the current tileset.
int tileset_unit_height(const struct tileset *t)
Return the unit tile height of the current tileset.
bool tileset_is_isometric(const struct tileset *t)
Return whether the current tileset is isometric.
int tileset_hex_height(const struct tileset *t)
Return the hex_height of the current tileset.
const QString unit_activity_text(const struct unit *punit)
Return text describing the unit's current activity as a static string.
void toggle_unit_sel_widget(struct tile *ptile)
Shows/closes unit selection widget.
void update_unit_sel()
Update unit selection widget if open.
void popdown_unit_sel()
Closes unit selection widget.
const struct unit_type * unit_type_get(const struct unit *punit)
Return the unit type for this unit.
const char * unit_name_translation(const struct unit *punit)
Return the (translated) name of the unit.
#define utype_fuel(ptype)
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.