1 | /* $Id: QIListWidget.h 104514 2024-05-03 18:10:47Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Qt extensions: QIListWidget class declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2008-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
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
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef FEQT_INCLUDED_SRC_extensions_QIListWidget_h
|
---|
29 | #define FEQT_INCLUDED_SRC_extensions_QIListWidget_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QListWidget>
|
---|
36 | #include <QListWidgetItem>
|
---|
37 |
|
---|
38 | /* GUI includes: */
|
---|
39 | #include "UILibraryDefs.h"
|
---|
40 |
|
---|
41 | /* Forward declarations: */
|
---|
42 | class QIListWidget;
|
---|
43 |
|
---|
44 | /** QListWidgetItem subclass extending standard functionality. */
|
---|
45 | class SHARED_LIBRARY_STUFF QIListWidgetItem : public QObject, public QListWidgetItem
|
---|
46 | {
|
---|
47 | Q_OBJECT;
|
---|
48 |
|
---|
49 | public:
|
---|
50 |
|
---|
51 | /** Item type for QIListWidgetItem. */
|
---|
52 | enum { ItemType = QListWidgetItem::UserType + 1 };
|
---|
53 |
|
---|
54 | /** Casts QListWidgetItem* to QIListWidgetItem* if possible. */
|
---|
55 | static QIListWidgetItem *toItem(QListWidgetItem *pItem);
|
---|
56 | /** Casts const QListWidgetItem* to const QIListWidgetItem* if possible. */
|
---|
57 | static const QIListWidgetItem *toItem(const QListWidgetItem *pItem);
|
---|
58 |
|
---|
59 | /** Casts QList<QListWidgetItem*> to QList<QIListWidgetItem*> if possible. */
|
---|
60 | static QList<QIListWidgetItem*> toList(const QList<QListWidgetItem*> &initialList);
|
---|
61 | /** Casts QList<QListWidgetItem*> to QList<QIListWidgetItem*> if possible. */
|
---|
62 | static QList<const QIListWidgetItem*> toList(const QList<const QListWidgetItem*> &initialList);
|
---|
63 |
|
---|
64 | /** Constructs item passing @a pListWidget into the base-class. */
|
---|
65 | QIListWidgetItem(QIListWidget *pListWidget);
|
---|
66 | /** Constructs item passing @a strText and @a pListWidget into the base-class. */
|
---|
67 | QIListWidgetItem(const QString &strText, QIListWidget *pListWidget);
|
---|
68 | /** Constructs item passing @a icon, @a strText and @a pListWidget into the base-class. */
|
---|
69 | QIListWidgetItem(const QIcon &icon, const QString &strText, QIListWidget *pListWidget);
|
---|
70 |
|
---|
71 | /** Returns the parent list-widget. */
|
---|
72 | QIListWidget *parentList() const;
|
---|
73 |
|
---|
74 | /** Returns default text. */
|
---|
75 | virtual QString defaultText() const;
|
---|
76 | };
|
---|
77 |
|
---|
78 | /** QListWidget subclass extending standard functionality. */
|
---|
79 | class SHARED_LIBRARY_STUFF QIListWidget : public QListWidget
|
---|
80 | {
|
---|
81 | Q_OBJECT;
|
---|
82 |
|
---|
83 | signals:
|
---|
84 |
|
---|
85 | /** Notifies about particular list-widget @a pItem is painted with @a pPainter. */
|
---|
86 | void painted(QListWidgetItem *pItem, QPainter *pPainter);
|
---|
87 | /** Notifies about list-widget being resized from @a oldSize to @a size. */
|
---|
88 | void resized(const QSize &size, const QSize &oldSize);
|
---|
89 |
|
---|
90 | public:
|
---|
91 |
|
---|
92 | /** Constructs list-widget passing @a pParent to the base-class.
|
---|
93 | * @param fDelegatePaintingToSubclass Brings whether painting should be fully delegated to sub-class. */
|
---|
94 | QIListWidget(QWidget *pParent = 0, bool fDelegatePaintingToSubclass = false);
|
---|
95 |
|
---|
96 | /** Defines @a sizeHint for list-widget items. */
|
---|
97 | void setSizeHintForItems(const QSize &sizeHint);
|
---|
98 |
|
---|
99 | /** Returns the number of children. */
|
---|
100 | int childCount() const;
|
---|
101 | /** Returns the child item with @a iIndex. */
|
---|
102 | QIListWidgetItem *childItem(int iIndex) const;
|
---|
103 | /** Returns a model-index of @a pItem specified. */
|
---|
104 | QModelIndex itemIndex(QListWidgetItem *pItem);
|
---|
105 |
|
---|
106 | /** Returns a list of all selected items in the list widget. */
|
---|
107 | QList<QIListWidgetItem*> selectedItems() const;
|
---|
108 | /** Finds items with the text that matches the string text using the given flags. */
|
---|
109 | QList<QIListWidgetItem*> findItems(const QString &text, Qt::MatchFlags flags) const;
|
---|
110 |
|
---|
111 | protected:
|
---|
112 |
|
---|
113 | /** Handles paint @a pEvent. */
|
---|
114 | virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE RT_FINAL;
|
---|
115 | /** Handles resize @a pEvent. */
|
---|
116 | virtual void resizeEvent(QResizeEvent *pEvent) RT_OVERRIDE RT_FINAL;
|
---|
117 |
|
---|
118 | private:
|
---|
119 |
|
---|
120 | /** Holds whether painting should be fully delegated to sub-class. */
|
---|
121 | bool m_fDelegatePaintingToSubclass;
|
---|
122 | };
|
---|
123 |
|
---|
124 | #endif /* !FEQT_INCLUDED_SRC_extensions_QIListWidget_h */
|
---|