1 | /* $Id: QIStatusBarIndicator.h 76532 2018-12-30 06:08:06Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - Qt extensions: QIStatusBarIndicator interface declaration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2018 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ___QIStatusBarIndicators_h___
|
---|
19 | #define ___QIStatusBarIndicators_h___
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | /* Qt includes: */
|
---|
25 | #include <QIcon>
|
---|
26 | #include <QMap>
|
---|
27 | #include <QWidget>
|
---|
28 |
|
---|
29 | /* GUI includes: */
|
---|
30 | #include "UILibraryDefs.h"
|
---|
31 |
|
---|
32 | /* Forward declarations: */
|
---|
33 | class QIcon;
|
---|
34 | class QLabel;
|
---|
35 | class QSize;
|
---|
36 | class QString;
|
---|
37 | class QWidget;
|
---|
38 |
|
---|
39 |
|
---|
40 | /** QWidget extension used as status-bar indicator. */
|
---|
41 | class SHARED_LIBRARY_STUFF QIStatusBarIndicator : public QWidget
|
---|
42 | {
|
---|
43 | Q_OBJECT;
|
---|
44 |
|
---|
45 | signals:
|
---|
46 |
|
---|
47 | /** Notifies about mouse-double-click-event: */
|
---|
48 | void sigMouseDoubleClick(QIStatusBarIndicator *pIndicator, QMouseEvent *pEvent);
|
---|
49 | /** Notifies about context-menu-request-event: */
|
---|
50 | void sigContextMenuRequest(QIStatusBarIndicator *pIndicator, QContextMenuEvent *pEvent);
|
---|
51 |
|
---|
52 | public:
|
---|
53 |
|
---|
54 | /** Constructs status-bar indicator passing @a pParent to the base-class. */
|
---|
55 | QIStatusBarIndicator(QWidget *pParent = 0);
|
---|
56 |
|
---|
57 | /** Returns size-hint. */
|
---|
58 | virtual QSize sizeHint() const { return m_size.isValid() ? m_size : QWidget::sizeHint(); }
|
---|
59 |
|
---|
60 | protected:
|
---|
61 |
|
---|
62 | #ifdef VBOX_WS_MAC
|
---|
63 | /** Handles mouse-press @a pEvent. */
|
---|
64 | virtual void mousePressEvent(QMouseEvent *pEvent) /* override */;
|
---|
65 | #endif /* VBOX_WS_MAC */
|
---|
66 | /** Handles mouse-double-click @a pEvent. */
|
---|
67 | virtual void mouseDoubleClickEvent(QMouseEvent *pEvent) /* override */;
|
---|
68 |
|
---|
69 | /** Handles context-menu @a pEvent. */
|
---|
70 | virtual void contextMenuEvent(QContextMenuEvent *pEvent) /* override */;
|
---|
71 |
|
---|
72 | /** Holds currently cached size. */
|
---|
73 | QSize m_size;
|
---|
74 | };
|
---|
75 |
|
---|
76 |
|
---|
77 | /** QIStatusBarIndicator extension used as status-bar state indicator. */
|
---|
78 | class SHARED_LIBRARY_STUFF QIStateStatusBarIndicator : public QIStatusBarIndicator
|
---|
79 | {
|
---|
80 | Q_OBJECT;
|
---|
81 |
|
---|
82 | public:
|
---|
83 |
|
---|
84 | /** Constructs state status-bar indicator passing @a pParent to the base-class. */
|
---|
85 | QIStateStatusBarIndicator(QWidget *pParent = 0);
|
---|
86 |
|
---|
87 | /** Returns current state. */
|
---|
88 | int state() const { return m_iState; }
|
---|
89 |
|
---|
90 | /** Returns state-icon for passed @a iState. */
|
---|
91 | QIcon stateIcon(int iState) const;
|
---|
92 | /** Defines state-icon for passed @a iState as @a icon. */
|
---|
93 | void setStateIcon(int iState, const QIcon &icon);
|
---|
94 |
|
---|
95 | public slots:
|
---|
96 |
|
---|
97 | /** Defines int @a state. */
|
---|
98 | virtual void setState(int iState) { m_iState = iState; repaint(); }
|
---|
99 | /** Defines bool @a state. */
|
---|
100 | void setState(bool fState) { setState((int)fState); }
|
---|
101 |
|
---|
102 | protected:
|
---|
103 |
|
---|
104 | /** Handles paint @a pEvent. */
|
---|
105 | virtual void paintEvent(QPaintEvent *pEvent) /* override */;
|
---|
106 |
|
---|
107 | /** Draws contents using passed @a pPainter. */
|
---|
108 | virtual void drawContents(QPainter *pPainter);
|
---|
109 |
|
---|
110 | private:
|
---|
111 |
|
---|
112 | /** Holds current state. */
|
---|
113 | int m_iState;
|
---|
114 | /** Holds cached state icons. */
|
---|
115 | QMap<int, QIcon> m_icons;
|
---|
116 | };
|
---|
117 |
|
---|
118 |
|
---|
119 | /** QIStatusBarIndicator extension used as status-bar state indicator. */
|
---|
120 | class SHARED_LIBRARY_STUFF QITextStatusBarIndicator : public QIStatusBarIndicator
|
---|
121 | {
|
---|
122 | Q_OBJECT;
|
---|
123 |
|
---|
124 | public:
|
---|
125 |
|
---|
126 | /** Constructs text status-bar indicator passing @a pParent to the base-class. */
|
---|
127 | QITextStatusBarIndicator(QWidget *pParent = 0);
|
---|
128 |
|
---|
129 | /** Returns text. */
|
---|
130 | QString text() const;
|
---|
131 | /** Defines @a strText. */
|
---|
132 | void setText(const QString &strText);
|
---|
133 |
|
---|
134 | private:
|
---|
135 |
|
---|
136 | /** Holds the label instance. */
|
---|
137 | QLabel *m_pLabel;
|
---|
138 | };
|
---|
139 |
|
---|
140 |
|
---|
141 | #endif /* !___QIStatusBarIndicators_h___ */
|
---|