1 | /* $Id: UIToolBar.cpp 62493 2016-07-22 18:44:18Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIToolBar class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2016 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 | #ifdef VBOX_WITH_PRECOMPILED_HEADERS
|
---|
19 | # include <precomp.h>
|
---|
20 | #else /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
21 |
|
---|
22 | /* Qt includes: */
|
---|
23 | # include <QLayout>
|
---|
24 | # include <QMainWindow>
|
---|
25 |
|
---|
26 | /* GUI includes: */
|
---|
27 | # include "UIToolBar.h"
|
---|
28 | # ifdef VBOX_WS_MAC
|
---|
29 | # include "VBoxUtils.h"
|
---|
30 | # endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
|
---|
31 |
|
---|
32 | #endif /* VBOX_WS_MAC */
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #if QT_VERSION < 0x050000
|
---|
36 | # include <QWindowsStyle>
|
---|
37 | # include <QCleanlooksStyle>
|
---|
38 | #endif /* QT_VERSION < 0x050000 */
|
---|
39 |
|
---|
40 |
|
---|
41 | UIToolBar::UIToolBar(QWidget *pParent /* = 0 */)
|
---|
42 | : QToolBar(pParent)
|
---|
43 | , m_pMainWindow(qobject_cast<QMainWindow*>(pParent))
|
---|
44 | {
|
---|
45 | /* Prepare: */
|
---|
46 | prepare();
|
---|
47 | }
|
---|
48 |
|
---|
49 | void UIToolBar::setUseTextLabels(bool fEnable)
|
---|
50 | {
|
---|
51 | /* Determine tool-button style on the basis of passed flag: */
|
---|
52 | Qt::ToolButtonStyle tbs = fEnable ? Qt::ToolButtonTextUnderIcon : Qt::ToolButtonIconOnly;
|
---|
53 |
|
---|
54 | /* Depending on parent, assign this style: */
|
---|
55 | if (m_pMainWindow)
|
---|
56 | m_pMainWindow->setToolButtonStyle(tbs);
|
---|
57 | else
|
---|
58 | setToolButtonStyle(tbs);
|
---|
59 | }
|
---|
60 |
|
---|
61 | #ifdef VBOX_WS_MAC
|
---|
62 | void UIToolBar::enableMacToolbar()
|
---|
63 | {
|
---|
64 | /* Depending on parent, enable unified title/tool-bar: */
|
---|
65 | if (m_pMainWindow)
|
---|
66 | m_pMainWindow->setUnifiedTitleAndToolBarOnMac(true);
|
---|
67 | }
|
---|
68 |
|
---|
69 | void UIToolBar::setShowToolBarButton(bool fShow)
|
---|
70 | {
|
---|
71 | ::darwinSetShowsToolbarButton(this, fShow);
|
---|
72 | }
|
---|
73 |
|
---|
74 | void UIToolBar::updateLayout()
|
---|
75 | {
|
---|
76 | /* There is a bug in Qt Cocoa which result in showing a "more arrow" when
|
---|
77 | the necessary size of the toolbar is increased. Also for some languages
|
---|
78 | the with doesn't match if the text increase. So manually adjust the size
|
---|
79 | after changing the text. */
|
---|
80 | QSizePolicy sp = sizePolicy();
|
---|
81 | setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
82 | adjustSize();
|
---|
83 | setSizePolicy(sp);
|
---|
84 | layout()->invalidate();
|
---|
85 | layout()->activate();
|
---|
86 | }
|
---|
87 | #endif /* VBOX_WS_MAC */
|
---|
88 |
|
---|
89 | void UIToolBar::prepare()
|
---|
90 | {
|
---|
91 | /* Configure tool-bar: */
|
---|
92 | setFloatable(false);
|
---|
93 | setMovable(false);
|
---|
94 |
|
---|
95 | #if QT_VERSION < 0x050000
|
---|
96 | /* Remove that ugly frame panel around the toolbar.
|
---|
97 | * Doing that currently for Cleanlooks & Windows styles. */
|
---|
98 | if (qobject_cast <QWindowsStyle*>(QToolBar::style()) ||
|
---|
99 | qobject_cast <QCleanlooksStyle*>(QToolBar::style()))
|
---|
100 | setStyleSheet("QToolBar { border: 0px none black; }");
|
---|
101 | #else /* QT_VERSION >= 0x050000 */
|
---|
102 | # ifdef VBOX_WS_MAC
|
---|
103 | setStyleSheet("QToolBar { border: 0px none black; }");
|
---|
104 | # endif /* VBOX_WS_MAC */
|
---|
105 | #endif /* QT_VERSION >= 0x050000 */
|
---|
106 |
|
---|
107 | /* Configure tool-bar' layout: */
|
---|
108 | if (layout())
|
---|
109 | layout()->setContentsMargins(0, 0, 0, 0);
|
---|
110 |
|
---|
111 | /* Configure tool-bar' context-menu policy: */
|
---|
112 | setContextMenuPolicy(Qt::NoContextMenu);
|
---|
113 | }
|
---|
114 |
|
---|