1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * UIToolBar class implementation
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2010 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 | /* Local includes */
|
---|
20 | #include "UIToolBar.h"
|
---|
21 | #ifdef Q_WS_MAC
|
---|
22 | # include "VBoxUtils.h"
|
---|
23 | #endif
|
---|
24 |
|
---|
25 | /* Global includes */
|
---|
26 | #include <QLayout>
|
---|
27 | #include <QMainWindow>
|
---|
28 | /* Note: This styles are available on _all_ platforms. */
|
---|
29 | #include <QCleanlooksStyle>
|
---|
30 | #include <QWindowsStyle>
|
---|
31 |
|
---|
32 | UIToolBar::UIToolBar(QWidget *pParent)
|
---|
33 | : QToolBar(pParent)
|
---|
34 | , m_pMainWindow(qobject_cast <QMainWindow*>(pParent))
|
---|
35 | {
|
---|
36 | setFloatable(false);
|
---|
37 | setMovable(false);
|
---|
38 |
|
---|
39 | /* Remove that ugly frame panel around the toolbar.
|
---|
40 | * Doing that currently for Cleanlooks & Windows styles. */
|
---|
41 | if (qobject_cast <QCleanlooksStyle*>(QToolBar::style()) ||
|
---|
42 | qobject_cast <QWindowsStyle*>(QToolBar::style()))
|
---|
43 | setStyleSheet("QToolBar { border: 0px none black; }");
|
---|
44 |
|
---|
45 | if (layout())
|
---|
46 | layout()->setContentsMargins(0, 0, 0, 0);;
|
---|
47 |
|
---|
48 | setContextMenuPolicy(Qt::NoContextMenu);
|
---|
49 | }
|
---|
50 |
|
---|
51 | #ifdef Q_WS_MAC
|
---|
52 | void UIToolBar::setMacToolbar()
|
---|
53 | {
|
---|
54 | if (m_pMainWindow)
|
---|
55 | m_pMainWindow->setUnifiedTitleAndToolBarOnMac(true);
|
---|
56 | }
|
---|
57 |
|
---|
58 | void UIToolBar::setShowToolBarButton(bool fShow)
|
---|
59 | {
|
---|
60 | ::darwinSetShowsToolbarButton(this, fShow);
|
---|
61 | }
|
---|
62 | #endif /* Q_WS_MAC */
|
---|
63 |
|
---|
64 | void UIToolBar::updateLayout()
|
---|
65 | {
|
---|
66 | #ifdef Q_WS_MAC
|
---|
67 | /* There is a bug in Qt Cocoa which result in showing a "more arrow" when
|
---|
68 | the necessary size of the toolbar is increased. Also for some languages
|
---|
69 | the with doesn't match if the text increase. So manually adjust the size
|
---|
70 | after changing the text. */
|
---|
71 | QSizePolicy sp = sizePolicy();
|
---|
72 | setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
---|
73 | adjustSize();
|
---|
74 | setSizePolicy(sp);
|
---|
75 | layout()->invalidate();
|
---|
76 | layout()->activate();
|
---|
77 | #endif /* Q_WS_MAC */
|
---|
78 | }
|
---|
79 |
|
---|
80 | void UIToolBar::setUsesTextLabel(bool fEnable)
|
---|
81 | {
|
---|
82 | Qt::ToolButtonStyle tbs = Qt::ToolButtonTextUnderIcon;
|
---|
83 | if (!fEnable)
|
---|
84 | tbs = Qt::ToolButtonIconOnly;
|
---|
85 |
|
---|
86 | if (m_pMainWindow)
|
---|
87 | m_pMainWindow->setToolButtonStyle(tbs);
|
---|
88 | else
|
---|
89 | setToolButtonStyle(tbs);
|
---|
90 | }
|
---|
91 |
|
---|