1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * VBoxToolBar class declaration & implementation
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2007 Oracle Corporation
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | #ifndef ___VBoxToolBar_h___
|
---|
20 | #define ___VBoxToolBar_h___
|
---|
21 |
|
---|
22 | #include <QGlobalStatic> /* for Q_WS_MAC */
|
---|
23 | #ifdef Q_WS_MAC
|
---|
24 | # include "VBoxUtils.h"
|
---|
25 | #endif
|
---|
26 |
|
---|
27 | /* Qt includes */
|
---|
28 | #include <QLayout>
|
---|
29 | #include <QMainWindow>
|
---|
30 | #include <QToolBar>
|
---|
31 |
|
---|
32 | /* Note: This styles are available on _all_ platforms. */
|
---|
33 | #include <QCleanlooksStyle>
|
---|
34 | #include <QWindowsStyle>
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * The VBoxToolBar class is a simple QToolBar reimplementation to disable
|
---|
38 | * its built-in context menu and add some default behavior we need.
|
---|
39 | */
|
---|
40 | class VBoxToolBar : public QToolBar
|
---|
41 | {
|
---|
42 |
|
---|
43 | public:
|
---|
44 |
|
---|
45 | VBoxToolBar (QWidget *aParent)
|
---|
46 | : QToolBar (aParent)
|
---|
47 | , mMainWindow (qobject_cast <QMainWindow*> (aParent))
|
---|
48 | {
|
---|
49 | setFloatable (false);
|
---|
50 | setMovable (false);
|
---|
51 |
|
---|
52 | /* Remove that ugly frame panel around the toolbar.
|
---|
53 | * Doing that currently for Cleanlooks & Windows styles. */
|
---|
54 | if (qobject_cast <QCleanlooksStyle*> (QToolBar::style()) ||
|
---|
55 | qobject_cast <QWindowsStyle*> (QToolBar::style()))
|
---|
56 | setStyleSheet ("QToolBar { border: 0px none black; }");
|
---|
57 |
|
---|
58 | if (layout())
|
---|
59 | layout()->setContentsMargins (0, 0, 0, 0);;
|
---|
60 |
|
---|
61 | setContextMenuPolicy (Qt::NoContextMenu);
|
---|
62 | }
|
---|
63 |
|
---|
64 | #ifdef Q_WS_MAC
|
---|
65 | void setMacToolbar()
|
---|
66 | {
|
---|
67 | if (mMainWindow)
|
---|
68 | mMainWindow->setUnifiedTitleAndToolBarOnMac (true);
|
---|
69 | }
|
---|
70 |
|
---|
71 | void setShowToolBarButton (bool aShow)
|
---|
72 | {
|
---|
73 | ::darwinSetShowsToolbarButton (this, aShow);
|
---|
74 | }
|
---|
75 | #endif /* Q_WS_MAC */
|
---|
76 |
|
---|
77 | void updateLayout()
|
---|
78 | {
|
---|
79 | #ifdef Q_WS_MAC
|
---|
80 | /* There is a bug in Qt Cocoa which result in showing a "more arrow" when
|
---|
81 | the necessary size of the toolbar is increased. Also for some languages
|
---|
82 | the with doesn't match if the text increase. So manually adjust the size
|
---|
83 | after changing the text. */
|
---|
84 | QSizePolicy sp = sizePolicy();
|
---|
85 | setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
86 | adjustSize();
|
---|
87 | setSizePolicy(sp);
|
---|
88 | layout()->invalidate();
|
---|
89 | layout()->activate();
|
---|
90 | #endif /* Q_WS_MAC */
|
---|
91 | }
|
---|
92 |
|
---|
93 | void setUsesTextLabel (bool aEnable)
|
---|
94 | {
|
---|
95 | Qt::ToolButtonStyle tbs = Qt::ToolButtonTextUnderIcon;
|
---|
96 | if (!aEnable)
|
---|
97 | tbs = Qt::ToolButtonIconOnly;
|
---|
98 |
|
---|
99 | if (mMainWindow)
|
---|
100 | mMainWindow->setToolButtonStyle (tbs);
|
---|
101 | else
|
---|
102 | setToolButtonStyle (tbs);
|
---|
103 | }
|
---|
104 |
|
---|
105 | private:
|
---|
106 |
|
---|
107 | QMainWindow *mMainWindow;
|
---|
108 | };
|
---|
109 |
|
---|
110 | #endif // !___VBoxToolBar_h___
|
---|
111 |
|
---|