summaryrefslogtreecommitdiff
path: root/src/VBox/Frontends/VirtualBox/src/manager/chooser/UIChooserItemGroup.h
blob: 6f751b421939bf2645c633163bfa447a850d90cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
/* $Id$ */
/** @file
 * VBox Qt GUI - UIChooserItemGroup class declaration.
 */

/*
 * Copyright (C) 2012-2022 Oracle Corporation
 *
 * This file is part of VirtualBox Open Source Edition (OSE), as
 * available from http://www.virtualbox.org. This file is free software;
 * you can redistribute it and/or modify it under the terms of the GNU
 * General Public License (GPL) as published by the Free Software
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 */

#ifndef FEQT_INCLUDED_SRC_manager_chooser_UIChooserItemGroup_h
#define FEQT_INCLUDED_SRC_manager_chooser_UIChooserItemGroup_h
#ifndef RT_WITHOUT_PRAGMA_ONCE
# pragma once
#endif

/* GUI includes: */
#include "UIChooserItem.h"

/* Forward declarations: */
class QGraphicsLinearLayout;
class QLineEdit;
class UIChooserNodeGroup;
class UIEditorGroupRename;
class UIGraphicsButton;
class UIGraphicsRotatorButton;
class UIGraphicsScrollArea;


/** UIChooserItem extension implementing group item. */
class UIChooserItemGroup : public UIChooserItem
{
    Q_OBJECT;
    Q_PROPERTY(int additionalHeight READ additionalHeight WRITE setAdditionalHeight);

signals:

    /** @name Item stuff.
      * @{ */
        /** Notifies listeners about toggle start. */
        void sigToggleStarted();
        /** Notifies listeners about toggle finish. */
        void sigToggleFinished();
    /** @} */

    /** @name Layout stuff.
      * @{ */
        /** Notifies listeners about @a iMinimumWidthHint change. */
        void sigMinimumWidthHintChanged(int iMinimumWidthHint);
    /** @} */

public:

    /** RTTI required for qgraphicsitem_cast. */
    enum { Type = UIChooserNodeType_Group };

    /** Build item for certain @a pNode, adding it directly to the @a pScene. */
    UIChooserItemGroup(QGraphicsScene *pScene, UIChooserNodeGroup *pNode);
    /** Build item for certain @a pNode, passing @a pParent to the base-class. */
    UIChooserItemGroup(UIChooserItem *pParent, UIChooserNodeGroup *pNode);
    /** Destructs group item. */
    virtual ~UIChooserItemGroup() RT_OVERRIDE;

    /** @name Item stuff.
      * @{ */
        /** Returns group node reference. */
        UIChooserNodeGroup *nodeToGroupType() const;
        /** Returns item machine id. */
        QUuid id() const;
        /** Returns group node type. */
        UIChooserNodeGroupType groupType() const;

        /** Returns whether group is closed. */
        bool isClosed() const;
        /** Closes group in @a fAnimated way if requested. */
        void close(bool fAnimated = true);

        /** Returns whether group is opened. */
        bool isOpened() const;
        /** Opens group in @a fAnimated way if requested. */
        void open(bool fAnimated = true);
    /** @} */

    /** @name Children stuff.
      * @{ */
        /** Updates positions of favorite items. */
        void updateFavorites();
    /** @} */

    /** @name Navigation stuff.
      * @{ */
        /** Returns scrolling location value in pixels. */
        int scrollingValue() const;
        /** Defines scrolling location @a iValue in pixels. */
        void setScrollingValue(int iValue);
        /** Performs scrolling by @a iDelta pixels. */
        void scrollBy(int iDelta);

        /** Makes sure passed @a pItem is visible within the current root item.
          * @note Please keep in mind that any group item can be a root, but there
          * is just one model root item at the same time, accessible via model's
          * root() getter, and this API can be called for current root item only,
          * because this is root item who performs actual scrolling, while
          * @a pItem itself can be on any level of embedding. */
        void makeSureItemIsVisible(UIChooserItem *pItem);

        /** Class-name used for drag&drop mime-data format. */
        static QString className();
    /** @} */

protected:

    /** @name Event-handling stuff.
      * @{ */
        /** Handles translation event. */
        virtual void retranslateUi() RT_OVERRIDE;

        /** Handles show @a pEvent. */
        virtual void showEvent(QShowEvent *pEvent) RT_OVERRIDE;

        /** Handles resize @a pEvent. */
        virtual void resizeEvent(QGraphicsSceneResizeEvent *pEvent) RT_OVERRIDE;

        /** Handles hover enter @a event. */
        virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *pEvent) RT_OVERRIDE;
        /** Handles hover leave @a event. */
        virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *pEvent) RT_OVERRIDE;

        /** Performs painting using passed @a pPainter, @a pOptions and optionally specified @a pWidget. */
        virtual void paint(QPainter *pPainter, const QStyleOptionGraphicsItem *pOptions, QWidget *pWidget = 0) RT_OVERRIDE;
    /** @} */

    /** @name Item stuff.
      * @{ */
        /** Returns RTTI item type. */
        virtual int type() const RT_OVERRIDE { return Type; }

        /** Starts item editing. */
        virtual void startEditing() RT_OVERRIDE;

        /** Updates item. */
        virtual void updateItem() RT_OVERRIDE;
        /** Updates item tool-tip. */
        virtual void updateToolTip() RT_OVERRIDE;

        /** Installs event-filter for @a pSource object. */
        virtual void installEventFilterHelper(QObject *pSource) RT_OVERRIDE;
    /** @} */

    /** @name Children stuff.
      * @{ */
        /** Returns children items of certain @a enmType. */
        virtual QList<UIChooserItem*> items(UIChooserNodeType enmType = UIChooserNodeType_Any) const RT_OVERRIDE;

        /** Adds possible @a fFavorite child @a pItem to certain @a iPosition. */
        virtual void addItem(UIChooserItem *pItem, bool fFavorite, int iPosition) RT_OVERRIDE;
        /** Removes child @a pItem. */
        virtual void removeItem(UIChooserItem *pItem) RT_OVERRIDE;

        /** Searches for a first child item answering to specified @a strSearchTag and @a iSearchFlags. */
        virtual UIChooserItem *searchForItem(const QString &strSearchTag, int iSearchFlags) RT_OVERRIDE;

        /** Searches for a first machine child item. */
        virtual UIChooserItem *firstMachineItem() RT_OVERRIDE;
    /** @} */

    /** @name Layout stuff.
      * @{ */
        /** Updates geometry. */
        virtual void updateGeometry() RT_OVERRIDE;

        /** Updates layout. */
        virtual void updateLayout() RT_OVERRIDE;

        /** Returns minimum width-hint. */
        virtual int minimumWidthHint() const RT_OVERRIDE;
        /** Returns minimum height-hint. */
        virtual int minimumHeightHint() const RT_OVERRIDE;

        /** Returns size-hint.
          * @param  enmWhich    Brings size-hint type.
          * @param  constraint  Brings size constraint. */
        virtual QSizeF sizeHint(Qt::SizeHint enmWhich, const QSizeF &constraint = QSizeF()) const RT_OVERRIDE;
    /** @} */

    /** @name Navigation stuff.
      * @{ */
        /** Returns pixmap item representation. */
        virtual QPixmap toPixmap() RT_OVERRIDE;

        /** Returns whether item drop is allowed.
          * @param  pEvent    Brings information about drop event.
          * @param  enmPlace  Brings the place of drag token to the drop moment. */
        virtual bool isDropAllowed(QGraphicsSceneDragDropEvent *pEvent, UIChooserItemDragToken where) const RT_OVERRIDE;
        /** Processes item drop.
          * @param  pEvent    Brings information about drop event.
          * @param  pFromWho  Brings the item according to which we choose drop position.
          * @param  enmPlace  Brings the place of drag token to the drop moment (according to item mentioned above). */
        virtual void processDrop(QGraphicsSceneDragDropEvent *pEvent, UIChooserItem *pFromWho, UIChooserItemDragToken where) RT_OVERRIDE;
        /** Reset drag token. */
        virtual void resetDragToken() RT_OVERRIDE;

        /** Returns D&D mime data. */
        virtual QMimeData *createMimeData() RT_OVERRIDE;
    /** @} */

private slots:

    /** @name Item stuff.
      * @{ */
        /** Handles top-level window remaps. */
        void sltHandleWindowRemapped();

        /** Handles name editing trigger. */
        void sltNameEditingFinished();

        /** Handles group toggle start. */
        void sltGroupToggleStart();
        /** Handles group toggle finish for group finally @a fToggled. */
        void sltGroupToggleFinish(bool fToggled);
    /** @} */

private:

    /** Data field types. */
    enum GroupItemData
    {
        /* Layout hints: */
        GroupItemData_MarginHL,
        GroupItemData_MarginHR,
        GroupItemData_MarginV,
        GroupItemData_HeaderSpacing,
        GroupItemData_ChildrenSpacing,
        GroupItemData_ParentIndent,
    };

    /** @name Prepare/cleanup cascade.
      * @{ */
        /** Prepares all. */
        void prepare();
        /** Cleanups all. */
        void cleanup();
    /** @} */

    /** @name Item stuff.
      * @{ */
        /** Returns abstractly stored data value for certain @a iKey. */
        QVariant data(int iKey) const;

        /** Returns additional height. */
        int additionalHeight() const;
        /** Defines @a iAdditionalHeight. */
        void setAdditionalHeight(int iAdditionalHeight);

        /** Updates animation parameters. */
        void updateAnimationParameters();
        /** Updates toggle-button tool-tip. */
        void updateToggleButtonToolTip();
    /** @} */

    /** @name Children stuff.
      * @{ */
        /** Copies group contents from @a pCopyFrom node recursively. */
        void copyContents(UIChooserNodeGroup *pCopyFrom);

        /** Returns whether group contains machine with @a uId. */
        bool isContainsMachine(const QUuid &uId) const;
        /** Returns whether group contains locked machine. */
        bool isContainsLockedMachine();

        /** Updates user count info. */
        void updateItemCountInfo();
    /** @} */

    /** @name Layout stuff.
      * @{ */
        /** Returns minimum width-hint depending on whether @a fGroupOpened. */
        int minimumWidthHintForGroup(bool fGroupOpened) const;
        /** Returns minimum height-hint depending on whether @a fGroupOpened. */
        int minimumHeightHintForGroup(bool fGroupOpened) const;
        /** Returns minimum size-hint depending on whether @a fGroupOpened. */
        QSizeF minimumSizeHintForGroup(bool fGroupOpened) const;

        /** Updates visible name. */
        void updateVisibleName();
        /** Updates pixmaps. */
        void updatePixmaps();
        /** Updates minimum header size. */
        void updateMinimumHeaderSize();
        /** Updates layout spacings. */
        void updateLayoutSpacings();
    /** @} */

    /** @name Painting stuff.
      * @{ */
        /** Paints background using specified @a pPainter and certain @a rect. */
        void paintBackground(QPainter *pPainter, const QRect &rect);
        /** Paints frame rectangle using specified @a pPainter and certain @a rect. */
        void paintFrame(QPainter *pPainter, const QRect &rect);
        /** Paints header using specified @a pPainter and certain @a rect. */
        void paintHeader(QPainter *pPainter, const QRect &rect);
    /** @} */

    /** @name Item stuff.
      * @{ */
        /** Holds the graphics scene reference. */
        QGraphicsScene *m_pScene;

        /** Holds the cached visible name. */
        QString  m_strVisibleName;
        /** Holds the cached group children info. */
        QString  m_strInfoGroups;
        /** Holds the cached machine children info. */
        QString  m_strInfoMachines;

        /** Holds root start background darkness. */
        int  m_iRootBackgroundDarknessStart;
        /** Holds root final background darkness. */
        int  m_iRootBackgroundDarknessFinal;
        /** Holds item start background darkness. */
        int  m_iItemBackgroundDarknessStart;
        /** Holds item final background darkness. */
        int  m_iItemBackgroundDarknessFinal;
        /** Holds item header highlight lightness. */
        int  m_iHighlightLightness;

        /** Holds aditional height. */
        int  m_iAdditionalHeight;

        /** Holds group children pixmap. */
        QPixmap  m_groupsPixmap;
        /** Holds machine children pixmap. */
        QPixmap  m_machinesPixmap;

        /** Holds the name font. */
        QFont  m_nameFont;
        /** Holds the info font. */
        QFont  m_infoFont;

        /** Holds the group toggle button instance. */
        UIGraphicsRotatorButton *m_pToggleButton;

        /** Holds the group name editor instance. */
        UIEditorGroupRename *m_pNameEditorWidget;
    /** @} */

    /** @name Children stuff.
      * @{ */
        /** Holds the favorite children container instance. */
        QIGraphicsWidget      *m_pContainerFavorite;
        /** Holds the favorite children layout instance. */
        QGraphicsLinearLayout *m_pLayoutFavorite;

        /** Holds the children scroll-area instance. */
        UIGraphicsScrollArea  *m_pScrollArea;
        /** Holds the children container instance. */
        QIGraphicsWidget      *m_pContainer;

        /** Holds the main layout instance. */
        QGraphicsLinearLayout *m_pLayout;
        /** Holds the global layout instance. */
        QGraphicsLinearLayout *m_pLayoutGlobal;
        /** Holds the group layout instance. */
        QGraphicsLinearLayout *m_pLayoutGroup;
        /** Holds the machine layout instance. */
        QGraphicsLinearLayout *m_pLayoutMachine;

        /** Holds the global children list. */
        QList<UIChooserItem*>  m_globalItems;
        /** Holds the group children list. */
        QList<UIChooserItem*>  m_groupItems;
        /** Holds the machine children list. */
        QList<UIChooserItem*>  m_machineItems;
    /** @} */

    /** @name Layout stuff.
      * @{ */
        /** Holds previous minimum width hint. */
        int  m_iPreviousMinimumWidthHint;

        /** Holds cached visible name size. */
        QSize  m_visibleNameSize;
        /** Holds cached group children pixmap size. */
        QSize  m_pixmapSizeGroups;
        /** Holds cached machine children pixmap size. */
        QSize  m_pixmapSizeMachines;
        /** Holds cached group children info size. */
        QSize  m_infoSizeGroups;
        /** Holds cached machine children info size. */
        QSize  m_infoSizeMachines;
        /** Holds cached minimum header size. */
        QSize  m_minimumHeaderSize;
        /** Holds cached toggle button size. */
        QSize  m_toggleButtonSize;
    /** @} */
};


/** QWidget extension to use as group name editor. */
class UIEditorGroupRename : public QWidget
{
    Q_OBJECT;

signals:

    /** Notifies about group editing finished. */
    void sigEditingFinished();

public:

    /** Constructs group editor with initial @a strName. */
    UIEditorGroupRename(const QString &strName);

    /** Returns editor text. */
    QString text() const;
    /** Defines editor @a strText. */
    void setText(const QString &strText);

    /** Defines editor @a font. */
    void setFont(const QFont &font);

private:

    /** Holds the line-edit instance. */
    QLineEdit *m_pLineEdit;
};


#endif /* !FEQT_INCLUDED_SRC_manager_chooser_UIChooserItemGroup_h */