[55401] | 1 | /* $Id: UIChooserItemMachine.h 104251 2024-04-09 12:36:47Z vboxsync $ */
|
---|
[42529] | 2 | /** @file
|
---|
[73424] | 3 | * VBox Qt GUI - UIChooserItemMachine class declaration.
|
---|
[42529] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2012-2023 Oracle and/or its affiliates.
|
---|
[42529] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[42529] | 26 | */
|
---|
| 27 |
|
---|
[76581] | 28 | #ifndef FEQT_INCLUDED_SRC_manager_chooser_UIChooserItemMachine_h
|
---|
| 29 | #define FEQT_INCLUDED_SRC_manager_chooser_UIChooserItemMachine_h
|
---|
[76532] | 30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 31 | # pragma once
|
---|
| 32 | #endif
|
---|
[42529] | 33 |
|
---|
| 34 | /* GUI includes: */
|
---|
[73424] | 35 | #include "UIChooserItem.h"
|
---|
[83929] | 36 | #include "UIManagerDefs.h"
|
---|
[42529] | 37 |
|
---|
[77638] | 38 | /* Forward declarations: */
|
---|
| 39 | class UIChooserNodeMachine;
|
---|
[83929] | 40 | class UIVirtualMachineItem;
|
---|
[77636] | 41 |
|
---|
| 42 |
|
---|
[73962] | 43 | /** UIChooserItem extension implementing machine item. */
|
---|
[77636] | 44 | class UIChooserItemMachine : public UIChooserItem
|
---|
[42529] | 45 | {
|
---|
| 46 | Q_OBJECT;
|
---|
| 47 |
|
---|
| 48 | public:
|
---|
| 49 |
|
---|
[77596] | 50 | /** RTTI required for qgraphicsitem_cast. */
|
---|
[83672] | 51 | enum { Type = UIChooserNodeType_Machine };
|
---|
[42529] | 52 |
|
---|
[77638] | 53 | /** Build item for certain @a pNode, passing @a pParent to the base-class. */
|
---|
| 54 | UIChooserItemMachine(UIChooserItem *pParent, UIChooserNodeMachine *pNode);
|
---|
[73962] | 55 | /** Destructs machine item. */
|
---|
[93990] | 56 | virtual ~UIChooserItemMachine() RT_OVERRIDE;
|
---|
[42529] | 57 |
|
---|
[73962] | 58 | /** @name Item stuff.
|
---|
| 59 | * @{ */
|
---|
[83924] | 60 | /** Returns machine node reference. */
|
---|
| 61 | UIChooserNodeMachine *nodeToMachineType() const;
|
---|
[83946] | 62 | /** Returns item machine id. */
|
---|
| 63 | QUuid id() const;
|
---|
| 64 | /** Returns whether item accessible. */
|
---|
| 65 | bool accessible() const;
|
---|
[83924] | 66 |
|
---|
[83929] | 67 | /** Returns virtual machine cache instance. */
|
---|
| 68 | UIVirtualMachineItem *cache() const;
|
---|
| 69 | /** Returns virtual machine cache type. */
|
---|
| 70 | UIVirtualMachineItemType cacheType() const;
|
---|
| 71 |
|
---|
[77636] | 72 | /** Recaches item contents. */
|
---|
| 73 | void recache();
|
---|
| 74 |
|
---|
[73962] | 75 | /** Returns whether VM is locked. */
|
---|
| 76 | bool isLockedMachine() const;
|
---|
[74482] | 77 |
|
---|
[77364] | 78 | /** Returns whether passed @a position belongs to tool button area. */
|
---|
| 79 | bool isToolButtonArea(const QPoint &position, int iMarginMultiplier = 1) const;
|
---|
[73962] | 80 | /** @} */
|
---|
[43594] | 81 |
|
---|
[73962] | 82 | /** @name Navigation stuff.
|
---|
| 83 | * @{ */
|
---|
| 84 | /** Class-name used for drag&drop mime-data format. */
|
---|
| 85 | static QString className();
|
---|
| 86 |
|
---|
| 87 | /** Enumerates machine items from @a il to @a ol using @a iEnumerationFlags. */
|
---|
| 88 | static void enumerateMachineItems(const QList<UIChooserItem*> &il,
|
---|
| 89 | QList<UIChooserItemMachine*> &ol,
|
---|
| 90 | int iEnumerationFlags = 0);
|
---|
| 91 | /** @} */
|
---|
| 92 |
|
---|
| 93 | protected:
|
---|
| 94 |
|
---|
| 95 | /** @name Event-handling stuff.
|
---|
| 96 | * @{ */
|
---|
| 97 | /** Handles show @a pEvent. */
|
---|
[93990] | 98 | virtual void showEvent(QShowEvent *pEvent) RT_OVERRIDE;
|
---|
[73962] | 99 |
|
---|
| 100 | /** Handles resize @a pEvent. */
|
---|
[93990] | 101 | virtual void resizeEvent(QGraphicsSceneResizeEvent *pEvent) RT_OVERRIDE;
|
---|
[73962] | 102 |
|
---|
| 103 | /** Handles mouse press @a pEvent. */
|
---|
[93990] | 104 | virtual void mousePressEvent(QGraphicsSceneMouseEvent *pEvent) RT_OVERRIDE;
|
---|
[73962] | 105 |
|
---|
| 106 | /** Performs painting using passed @a pPainter, @a pOptions and optionally specified @a pWidget. */
|
---|
[93990] | 107 | virtual void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions, QWidget *pWidget = 0) RT_OVERRIDE;
|
---|
[73962] | 108 | /** @} */
|
---|
| 109 |
|
---|
| 110 | /** @name Item stuff.
|
---|
| 111 | * @{ */
|
---|
| 112 | /** Returns RTTI item type. */
|
---|
[93990] | 113 | virtual int type() const RT_OVERRIDE { return Type; }
|
---|
[73962] | 114 |
|
---|
[86769] | 115 | /** Defines item as @a fSelected. */
|
---|
[93990] | 116 | virtual void setSelected(bool fSelected) RT_OVERRIDE;
|
---|
[86769] | 117 |
|
---|
[73962] | 118 | /** Starts item editing. */
|
---|
[93990] | 119 | virtual void startEditing() RT_OVERRIDE;
|
---|
[73962] | 120 |
|
---|
[77636] | 121 | /** Updates item. */
|
---|
[93990] | 122 | virtual void updateItem() RT_OVERRIDE;
|
---|
[73962] | 123 | /** Updates item tool-tip. */
|
---|
[93990] | 124 | virtual void updateToolTip() RT_OVERRIDE;
|
---|
[73962] | 125 | /** @} */
|
---|
| 126 |
|
---|
| 127 | /** @name Children stuff.
|
---|
| 128 | * @{ */
|
---|
[77596] | 129 | /** Returns children items of certain @a enmType. */
|
---|
[93990] | 130 | virtual QList<UIChooserItem*> items(UIChooserNodeType enmType = UIChooserNodeType_Any) const RT_OVERRIDE;
|
---|
[73962] | 131 |
|
---|
[77596] | 132 | /** Adds possible @a fFavorite child @a pItem to certain @a iPosition. */
|
---|
[93990] | 133 | virtual void addItem(UIChooserItem *pItem, bool fFavorite, int iPosition) RT_OVERRIDE;
|
---|
[77596] | 134 | /** Removes child @a pItem. */
|
---|
[93990] | 135 | virtual void removeItem(UIChooserItem *pItem) RT_OVERRIDE;
|
---|
[77596] | 136 |
|
---|
[84625] | 137 | /** Searches for a first child item answering to specified @a strSearchTag and @a iSearchFlags. */
|
---|
[93990] | 138 | virtual UIChooserItem *searchForItem(const QString &strSearchTag, int iSearchFlags) RT_OVERRIDE;
|
---|
[73962] | 139 |
|
---|
| 140 | /** Searches for a first machine child item. */
|
---|
[93990] | 141 | virtual UIChooserItem *firstMachineItem() RT_OVERRIDE;
|
---|
[73962] | 142 | /** @} */
|
---|
| 143 |
|
---|
| 144 | /** @name Layout stuff.
|
---|
| 145 | * @{ */
|
---|
| 146 | /** Updates layout. */
|
---|
[93990] | 147 | virtual void updateLayout() RT_OVERRIDE;
|
---|
[73962] | 148 |
|
---|
| 149 | /** Returns minimum width-hint. */
|
---|
[93990] | 150 | virtual int minimumWidthHint() const RT_OVERRIDE;
|
---|
[73962] | 151 | /** Returns minimum height-hint. */
|
---|
[93990] | 152 | virtual int minimumHeightHint() const RT_OVERRIDE;
|
---|
[73962] | 153 |
|
---|
| 154 | /** Returns size-hint.
|
---|
| 155 | * @param enmWhich Brings size-hint type.
|
---|
| 156 | * @param constraint Brings size constraint. */
|
---|
[93990] | 157 | virtual QSizeF sizeHint(Qt::SizeHint enmWhich, const QSizeF &constraint = QSizeF()) const RT_OVERRIDE;
|
---|
[73962] | 158 | /** @} */
|
---|
| 159 |
|
---|
| 160 | /** @name Navigation stuff.
|
---|
| 161 | * @{ */
|
---|
| 162 | /** Returns pixmap item representation. */
|
---|
[93990] | 163 | virtual QPixmap toPixmap() RT_OVERRIDE;
|
---|
[73962] | 164 |
|
---|
| 165 | /** Returns whether item drop is allowed.
|
---|
| 166 | * @param pEvent Brings information about drop event.
|
---|
| 167 | * @param enmPlace Brings the place of drag token to the drop moment. */
|
---|
[93990] | 168 | virtual bool isDropAllowed(QGraphicsSceneDragDropEvent *pEvent, UIChooserItemDragToken where) const RT_OVERRIDE;
|
---|
[73962] | 169 | /** Processes item drop.
|
---|
| 170 | * @param pEvent Brings information about drop event.
|
---|
| 171 | * @param pFromWho Brings the item according to which we choose drop position.
|
---|
| 172 | * @param enmPlace Brings the place of drag token to the drop moment (according to item mentioned above). */
|
---|
[93990] | 173 | virtual void processDrop(QGraphicsSceneDragDropEvent *pEvent, UIChooserItem *pFromWho, UIChooserItemDragToken where) RT_OVERRIDE;
|
---|
[73962] | 174 | /** Reset drag token. */
|
---|
[93990] | 175 | virtual void resetDragToken() RT_OVERRIDE;
|
---|
[73962] | 176 |
|
---|
| 177 | /** Returns D&D mime data. */
|
---|
[93990] | 178 | virtual QMimeData *createMimeData() RT_OVERRIDE;
|
---|
[73962] | 179 | /** @} */
|
---|
| 180 |
|
---|
[72708] | 181 | private slots:
|
---|
[72707] | 182 |
|
---|
[73962] | 183 | /** @name Item stuff.
|
---|
| 184 | * @{ */
|
---|
| 185 | /** Handles top-level window remaps. */
|
---|
| 186 | void sltHandleWindowRemapped();
|
---|
[76935] | 187 |
|
---|
| 188 | /** Updates first row maximum width. */
|
---|
| 189 | void sltUpdateFirstRowMaximumWidth() { updateFirstRowMaximumWidth(); }
|
---|
[73962] | 190 | /** @} */
|
---|
[72707] | 191 |
|
---|
[104251] | 192 | /** @name Event handling stuff.
|
---|
| 193 | * @{ */
|
---|
| 194 | /** Handles translation event. */
|
---|
| 195 | void sltRetranslateUI();
|
---|
| 196 | /** @} */
|
---|
| 197 |
|
---|
[42529] | 198 | private:
|
---|
| 199 |
|
---|
[73962] | 200 | /** Data field types. */
|
---|
[42529] | 201 | enum MachineItemData
|
---|
| 202 | {
|
---|
| 203 | /* Layout hints: */
|
---|
[77805] | 204 | MachineItemData_MarginHL,
|
---|
| 205 | MachineItemData_MarginHR,
|
---|
| 206 | MachineItemData_MarginV,
|
---|
[42529] | 207 | MachineItemData_MajorSpacing,
|
---|
| 208 | MachineItemData_MinorSpacing,
|
---|
| 209 | MachineItemData_TextSpacing,
|
---|
[74482] | 210 | MachineItemData_ButtonMargin,
|
---|
[42529] | 211 | };
|
---|
| 212 |
|
---|
[73962] | 213 | /** @name Prepare/cleanup cascade.
|
---|
| 214 | * @{ */
|
---|
| 215 | /** Prepares all. */
|
---|
| 216 | void prepare();
|
---|
[77041] | 217 | /** Cleanups all. */
|
---|
| 218 | void cleanup();
|
---|
[73962] | 219 | /** @} */
|
---|
[42529] | 220 |
|
---|
[73962] | 221 | /** @name Item stuff.
|
---|
| 222 | * @{ */
|
---|
| 223 | /** Returns abstractly stored data value for certain @a iKey. */
|
---|
| 224 | QVariant data(int iKey) const;
|
---|
| 225 | /** @} */
|
---|
[43830] | 226 |
|
---|
[73962] | 227 | /** @name Layout stuff.
|
---|
| 228 | * @{ */
|
---|
| 229 | /** Updates pixmaps. */
|
---|
| 230 | void updatePixmaps();
|
---|
| 231 | /** Updates pixmap. */
|
---|
| 232 | void updatePixmap();
|
---|
| 233 | /** Updates state pixmap. */
|
---|
| 234 | void updateStatePixmap();
|
---|
[77364] | 235 | /** Updates tool pixmap. */
|
---|
| 236 | void updateToolPixmap();
|
---|
[73962] | 237 | /** Updates first row maximum width. */
|
---|
| 238 | void updateFirstRowMaximumWidth();
|
---|
| 239 | /** Updates minimum name width. */
|
---|
| 240 | void updateMinimumNameWidth();
|
---|
| 241 | /** Updates minimum snapshot name width. */
|
---|
| 242 | void updateMinimumSnapshotNameWidth();
|
---|
| 243 | /** Updates maximum name width. */
|
---|
| 244 | void updateMaximumNameWidth();
|
---|
| 245 | /** Updates maximum snapshot name width. */
|
---|
| 246 | void updateMaximumSnapshotNameWidth();
|
---|
| 247 | /** Updates visible name. */
|
---|
| 248 | void updateVisibleName();
|
---|
| 249 | /** Updates visible snapshot name. */
|
---|
| 250 | void updateVisibleSnapshotName();
|
---|
[77620] | 251 | /** Updates state text size. */
|
---|
| 252 | void updateStateTextSize();
|
---|
[73962] | 253 | /** @} */
|
---|
[43447] | 254 |
|
---|
[73962] | 255 | /** @name Painting stuff.
|
---|
| 256 | * @{ */
|
---|
[74467] | 257 | /** Paints background using specified @a pPainter and certain @a rectangle. */
|
---|
[89137] | 258 | void paintBackground(QPainter *pPainter, const QRect &rectangle);
|
---|
[74467] | 259 | /** Paints frame using specified @a pPainter and certain @a rectangle. */
|
---|
[89137] | 260 | void paintFrame(QPainter *pPainter, const QRect &rectangle);
|
---|
[74467] | 261 | /** Paints machine info using specified @a pPainter and certain @a rectangle. */
|
---|
[89137] | 262 | void paintMachineInfo(QPainter *pPainter, const QRect &rectangle);
|
---|
[73962] | 263 | /** @} */
|
---|
[42529] | 264 |
|
---|
[73962] | 265 | /** @name Navigation stuff.
|
---|
| 266 | * @{ */
|
---|
| 267 | /** Returns whether machine items @a list contains passed @a pItem. */
|
---|
| 268 | static bool checkIfContains(const QList<UIChooserItemMachine*> &list,
|
---|
| 269 | UIChooserItemMachine *pItem);
|
---|
| 270 | /** @} */
|
---|
[42529] | 271 |
|
---|
[73962] | 272 | /** @name Item stuff.
|
---|
| 273 | * @{ */
|
---|
[89237] | 274 | /** Holds item start default lightness. */
|
---|
| 275 | int m_iDefaultLightnessStart;
|
---|
| 276 | /** Holds item final default lightness. */
|
---|
| 277 | int m_iDefaultLightnessFinal;
|
---|
| 278 | /** Holds item start hover lightness. */
|
---|
| 279 | int m_iHoverLightnessStart;
|
---|
| 280 | /** Holds item final hover lightness. */
|
---|
| 281 | int m_iHoverLightnessFinal;
|
---|
| 282 | /** Holds item start highlight lightness. */
|
---|
| 283 | int m_iHighlightLightnessStart;
|
---|
| 284 | /** Holds item final highlight lightness. */
|
---|
| 285 | int m_iHighlightLightnessFinal;
|
---|
[42529] | 286 |
|
---|
[73962] | 287 | /** Holds item pixmap. */
|
---|
| 288 | QPixmap m_pixmap;
|
---|
| 289 | /** Holds item state pixmap. */
|
---|
| 290 | QPixmap m_statePixmap;
|
---|
[77364] | 291 | /** Holds item tool pixmap. */
|
---|
| 292 | QPixmap m_toolPixmap;
|
---|
[42529] | 293 |
|
---|
[73962] | 294 | /** Holds item visible name. */
|
---|
| 295 | QString m_strVisibleName;
|
---|
| 296 | /** Holds item visible snapshot name. */
|
---|
| 297 | QString m_strVisibleSnapshotName;
|
---|
[72704] | 298 |
|
---|
[73962] | 299 | /** Holds item name font. */
|
---|
| 300 | QFont m_nameFont;
|
---|
| 301 | /** Holds item snapshot name font. */
|
---|
| 302 | QFont m_snapshotNameFont;
|
---|
| 303 | /** Holds item state text font. */
|
---|
| 304 | QFont m_stateTextFont;
|
---|
| 305 | /** @} */
|
---|
[43853] | 306 |
|
---|
[73962] | 307 | /** @name Layout stuff.
|
---|
| 308 | * @{ */
|
---|
| 309 | /** Holds pixmap size. */
|
---|
| 310 | QSize m_pixmapSize;
|
---|
| 311 | /** Holds state pixmap size. */
|
---|
| 312 | QSize m_statePixmapSize;
|
---|
[77364] | 313 | /** Holds tool pixmap size. */
|
---|
| 314 | QSize m_toolPixmapSize;
|
---|
[73962] | 315 | /** Holds visible name size. */
|
---|
| 316 | QSize m_visibleNameSize;
|
---|
| 317 | /** Holds visible snapshot name size. */
|
---|
| 318 | QSize m_visibleSnapshotNameSize;
|
---|
| 319 | /** Holds state text size. */
|
---|
| 320 | QSize m_stateTextSize;
|
---|
[42627] | 321 |
|
---|
[73962] | 322 | /** Holds first row maximum width. */
|
---|
| 323 | int m_iFirstRowMaximumWidth;
|
---|
| 324 | /** Holds minimum name width. */
|
---|
| 325 | int m_iMinimumNameWidth;
|
---|
| 326 | /** Holds maximum name width. */
|
---|
| 327 | int m_iMaximumNameWidth;
|
---|
| 328 | /** Holds minimum snapshot name width. */
|
---|
| 329 | int m_iMinimumSnapshotNameWidth;
|
---|
| 330 | /** Holds maximum snapshot name width. */
|
---|
| 331 | int m_iMaximumSnapshotNameWidth;
|
---|
| 332 | /** @} */
|
---|
[42529] | 333 | };
|
---|
| 334 |
|
---|
[77596] | 335 |
|
---|
[76581] | 336 | #endif /* !FEQT_INCLUDED_SRC_manager_chooser_UIChooserItemMachine_h */
|
---|