1 | /** @file
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * VBoxToolBar class declaration & implementation
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2007 innotek GmbH
|
---|
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 | /* Qt includes */
|
---|
23 | #include <QToolBar>
|
---|
24 | #include <QToolButton>
|
---|
25 | #include <QMainWindow>
|
---|
26 | #include <QContextMenuEvent>
|
---|
27 | #ifdef Q_WS_MAC
|
---|
28 | //# include "VBoxAquaStyle.h"
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * The VBoxToolBar class is a simple QToolBar reimplementation to disable
|
---|
33 | * its built-in context menu and add some default behavior we need.
|
---|
34 | */
|
---|
35 | class VBoxToolBar : public QToolBar
|
---|
36 | {
|
---|
37 | public:
|
---|
38 |
|
---|
39 | VBoxToolBar (QMainWindow *aMainWindow, QWidget *aParent = NULL)
|
---|
40 | : QToolBar (aParent),
|
---|
41 | mMainWindow (aMainWindow)
|
---|
42 | {
|
---|
43 | setFloatable (false);
|
---|
44 | setMovable (false);
|
---|
45 | };
|
---|
46 |
|
---|
47 | /** Reimplements and does nothing to disable the context menu */
|
---|
48 | void contextMenuEvent (QContextMenuEvent *) {};
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Substitutes for QMainWindow::setUsesBigPixmaps() when QMainWindow is
|
---|
52 | * not used (otherwise just redirects the call to #mainWindow()).
|
---|
53 | */
|
---|
54 | void setUsesBigPixmaps (bool enable)
|
---|
55 | {
|
---|
56 | QSize size (32, 32);
|
---|
57 | if (!enable)
|
---|
58 | size = QSize (16, 16);
|
---|
59 |
|
---|
60 | if (mMainWindow)
|
---|
61 | mMainWindow->setIconSize (size);
|
---|
62 | else
|
---|
63 | setIconSize (size);
|
---|
64 | }
|
---|
65 |
|
---|
66 | void setUsesTextLabel (bool enable)
|
---|
67 | {
|
---|
68 | Qt::ToolButtonStyle tbs = Qt::ToolButtonTextUnderIcon;
|
---|
69 | if (!enable)
|
---|
70 | tbs = Qt::ToolButtonIconOnly;
|
---|
71 |
|
---|
72 | if (mMainWindow)
|
---|
73 | mMainWindow->setToolButtonStyle (tbs);
|
---|
74 | else
|
---|
75 | setToolButtonStyle (tbs);
|
---|
76 | }
|
---|
77 |
|
---|
78 | #ifdef Q_WS_MAC
|
---|
79 | /**
|
---|
80 | * This is a temporary hack, we'll set the style globally later.
|
---|
81 | */
|
---|
82 | #warning port me
|
---|
83 | void setMacStyle()
|
---|
84 | {
|
---|
85 | /* self */
|
---|
86 | // QStyle *qs = &VBoxAquaStyle::instance();
|
---|
87 | // setStyle(qs);
|
---|
88 | //
|
---|
89 | // /* the buttons */
|
---|
90 | // QObjectList *list = queryList ("QToolButton");
|
---|
91 | // QObjectListIt it (*list);
|
---|
92 | // QObject *obj;
|
---|
93 | // while ((obj = it.current()) != 0)
|
---|
94 | // {
|
---|
95 | // QToolButton *btn = ::qt_cast <QToolButton *> (obj);
|
---|
96 | // btn->setStyle (&VBoxAquaStyle::instance());
|
---|
97 | // ++ it;
|
---|
98 | // }
|
---|
99 | // delete list;
|
---|
100 |
|
---|
101 | /** @todo the separator */
|
---|
102 | }
|
---|
103 | #endif
|
---|
104 | private:
|
---|
105 | QMainWindow *mMainWindow;
|
---|
106 | };
|
---|
107 |
|
---|
108 | #endif // __VBoxToolBar_h__
|
---|