VR-Engage  2.3
Loading...
Searching...
No Matches
stationItemDelegate.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2026 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file stationItemDelegate.h
7//! \ingroup vreManager
8//! \brief Station item delegate for the VR-Engage Manager station list
9//!
10//! This file defines the DtStationItemDelegate class, which provides custom
11//! two-line rendering for station items. The station name is drawn in a bold,
12//! larger font so it stands out, while the assignment details (entity / role)
13//! are drawn in the same normal-sized font used by the entity/role tree.
14
15#pragma once
16
17#include "vreManager/export.h"
19
20#include <QIcon>
21#include <QStyledItemDelegate>
22
23namespace makVre
24{
25
26//! \brief Custom item delegate for station list rendering
27//!
28//! Paints each station item as a two-line card:
29//! - Line 1: status icon + station name (bold, larger font)
30//! - Line 2: assignment text such as "Entity / Role" (normal font)
31//!
32//! For stations with any assignment (pending or confirmed) a spectator mode toggle
33//! button is drawn on the right-hand side of the card, vertically centred.
34//! For pending assignments the button is fully opaque and interactive; clicking
35//! it emits spectatorToggleClicked() to toggle spectator mode. For confirmed
36//! assignments the button is dimmed and acts as a read-only state indicator.
37//!
38//! The delegate reads custom data roles from DtVreStationListModel to
39//! obtain the station name and assignment text separately so they can be
40//! rendered in different font sizes.
41class VREMANAGER_DLL DtStationItemDelegate : public QStyledItemDelegate
42{
43 Q_OBJECT
44
45public:
46 //! \brief Left padding inside each station card (pixels from item left edge)
47 static constexpr int kCardHPadding = 10;
48
49 //! \brief Width of the status icon drawn in each station card
50 static constexpr int kStatusIconSize = 16;
51
52 //! \brief Gap between status icon and station name text
53 //!
54 //! Sized to accommodate the sort-arrow indicator in the status column
55 //! header (which sits in this gap when the status column is the active
56 //! sort key) while leaving visible breathing room on either side of the
57 //! arrow. Card rows use the same gap so the station name text in cards
58 //! stays aligned with the "Station" header label.
59 static constexpr int kIconTextGap = 30;
60
61 //! \brief Builds a neutral-state status-circle pixmap that geometrically
62 //! matches the status circles painted on station cards.
63 //!
64 //! The pixmap is sized \a size x \a size with the ellipse drawn inside
65 //! the same inset (4 px) used by station cards, guaranteeing pixel-aligned
66 //! horizontal centerlines when the icon is placed left-of-text in a button.
67 //! The icon is outlined (not filled) using \a color so it reads as a
68 //! "no-status" indicator on the sort header.
69 //!
70 //! \param size Pixmap and bounding-box edge length in pixels
71 //! \param color Outline color for the circle
72 //! \return Transparent QPixmap containing the outline circle
73 static QPixmap neutralStatusPixmap(int size, const QColor& color);
74
75 //! \brief Returns the bounding rect of the assignment-indicator within a row
76 //!
77 //! This is the authoritative geometry for the status icon slot at the left
78 //! of each station card. The sort-header button uses this to achieve
79 //! pixel-perfect horizontal alignment with the card indicators underneath.
80 //!
81 //! \param rowRect The full bounding rect of the row item
82 //! \param option Style options for the item (reserved for future variant use)
83 //! \return Rect of the assignment indicator in view coordinates
85 const QRect& rowRect,
86 const QStyleOptionViewItem& option);
87
88 //! \brief Returns the x-coordinate of the left edge of the station-name text
89 //!
90 //! The station-name sort button uses this value so its label x-aligns with
91 //! the card station-name baseline.
92 //!
93 //! \param rowRect The full bounding rect of the row item
94 //! \param option Style options for the item (reserved for future variant use)
95 //! \return Left pixel x of the station name column
96 static int nameLeftEdge(
97 const QRect& rowRect,
98 const QStyleOptionViewItem& option);
99
100 //! \brief Paints the assignment-indicator icon at the given rect
101 //!
102 //! This is the authoritative painting function for the status icon slot.
103 //! For unassigned stations it draws a grey dashed circle.
104 //! For confirmed/pending stations it draws the entity icon.
105 //! For conflict stations it adds a thin red border around the entity icon.
106 //! For pending-unassignment stations it adds a thin orange border.
107 //!
108 //! \param painter The painter to draw with
109 //! \param rect Bounding rect for the indicator (see assignmentIndicatorRectInRow)
110 //! \param status Assignment status of the station
111 //! \param entityIcon Entity icon to draw (may be null for unassigned stations)
113 QPainter* painter,
114 const QRect& rect,
116 const QIcon& entityIcon);
117
118 //! \brief Constructor
119 //! \param parent The parent object
120 DtStationItemDelegate(QObject* parent = nullptr);
121
122 //! \brief Destructor
123 virtual ~DtStationItemDelegate() override;
124
125 //! \brief Sets the icon used for the spectator mode toggle button (spectator active)
126 //! \param icon The icon to display when spectator mode is on
127 void setSpectatorModeIcon(const QIcon& icon);
128
129 //! \brief Sets the icon used for the spectator mode toggle button (spectator inactive)
130 //! \param icon The icon to display when spectator mode is off
131 void setSpectatorModeDisabledIcon(const QIcon& icon);
132
133 //! \brief Paints a station list item with two-line layout
134 //! \param painter The painter to draw with
135 //! \param option Style options for the item
136 //! \param index The model index of the item
137 virtual void paint(
138 QPainter* painter,
139 const QStyleOptionViewItem& option,
140 const QModelIndex& index) const override;
141
142 //! \brief Returns the preferred size for a station list item
143 //! \param option Style options for the item
144 //! \param index The model index of the item
145 //! \return Size hint accommodating two lines of text
146 virtual QSize sizeHint(
147 const QStyleOptionViewItem& option,
148 const QModelIndex& index) const override;
149
150 //! \brief Handles mouse events for the embedded spectator mode toggle button
151 //! \param event The incoming event
152 //! \param model The item model
153 //! \param option Style options for the item
154 //! \param index The model index of the item
155 //! \return True if the event was consumed by the spectator mode button
156 virtual bool editorEvent(
157 QEvent* event,
158 QAbstractItemModel* model,
159 const QStyleOptionViewItem& option,
160 const QModelIndex& index) override;
161
162signals:
163 //! \brief Emitted when the spectator mode toggle button is clicked
164 //! \param stationId The ID of the station whose spectator mode should be toggled
165 //!
166 //! Connect this signal to a slot that calls
167 //! DtVreAssignmentTracker::setPendingSpectatorMode() to toggle spectator mode.
168 //! For confirmed (non-pending) stations the signal is still emitted but the
169 //! connected slot will take no action — the button acts as a read-only indicator.
170 void spectatorToggleClicked(QString stationId);
171
172 //! \brief Emitted when the status indicator circle is clicked
173 //! \param stationId The ID of the station to unassign or clear pending
174 void statusIndicatorClicked(QString stationId);
175
176private:
177 //! \brief Computes the bounding rect of the status indicator circle
178 //! \param option Style options for the item
179 //! \return The status indicator rect in view coordinates
180 QRect statusIndicatorRect(const QStyleOptionViewItem& option) const;
181
182 //! \brief Computes the bounding rect of the spectator mode toggle button
183 //! \param option Style options for the item
184 //! \param index The model index of the item
185 //! \return The button rect in view coordinates, or an invalid QRect when the
186 //! button is not shown (station is unassigned)
188 const QStyleOptionViewItem& option,
189 const QModelIndex& index) const;
190
191 QIcon mySpectatorModeIcon; //!< Icon shown when spectator mode is active
192 QIcon mySpectatorModeDisabledIcon; //!< Icon shown when spectator mode is inactive
193};
194
195} // namespace makVre
static QPixmap neutralStatusPixmap(int size, const QColor &color)
Builds a neutral-state status-circle pixmap that geometrically matches the status circles painted on ...
static int nameLeftEdge(const QRect &rowRect, const QStyleOptionViewItem &option)
Returns the x-coordinate of the left edge of the station-name text.
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
Returns the preferred size for a station list item.
void setSpectatorModeDisabledIcon(const QIcon &icon)
Sets the icon used for the spectator mode toggle button (spectator inactive)
QRect spectatorButtonRect(const QStyleOptionViewItem &option, const QModelIndex &index) const
Computes the bounding rect of the spectator mode toggle button.
QRect statusIndicatorRect(const QStyleOptionViewItem &option) const
Computes the bounding rect of the status indicator circle.
void statusIndicatorClicked(QString stationId)
Emitted when the status indicator circle is clicked.
static void paintAssignmentIndicator(QPainter *painter, const QRect &rect, StationAssignmentStatus status, const QIcon &entityIcon)
Paints the assignment-indicator icon at the given rect.
static constexpr int kStatusIconSize
Width of the status icon drawn in each station card.
Definition stationItemDelegate.h:50
QIcon mySpectatorModeDisabledIcon
Icon shown when spectator mode is inactive.
Definition stationItemDelegate.h:192
DtStationItemDelegate(QObject *parent=nullptr)
Constructor.
virtual bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
Handles mouse events for the embedded spectator mode toggle button.
void spectatorToggleClicked(QString stationId)
Emitted when the spectator mode toggle button is clicked.
virtual ~DtStationItemDelegate() override
Destructor.
static QRect assignmentIndicatorRectInRow(const QRect &rowRect, const QStyleOptionViewItem &option)
Returns the bounding rect of the assignment-indicator within a row.
void setSpectatorModeIcon(const QIcon &icon)
Sets the icon used for the spectator mode toggle button (spectator active)
static constexpr int kCardHPadding
Left padding inside each station card (pixels from item left edge)
Definition stationItemDelegate.h:47
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Paints a station list item with two-line layout.
static constexpr int kIconTextGap
Gap between status icon and station name text.
Definition stationItemDelegate.h:59
QIcon mySpectatorModeIcon
Icon shown when spectator mode is active.
Definition stationItemDelegate.h:191
Export macros for the VREngage Manager library.
#define VREMANAGER_DLL
Platform-specific export/import macro for VREngage Manager library.
Definition export.h:28
!
Definition glsVreMessageUtil.h:50
StationAssignmentStatus
Assignment status for a station.
Definition vreStationListModel.h:88
List model for VR-Engage station display.