VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIDialogButtonBox.cpp@ 35740

Last change on this file since 35740 was 30356, checked in by vboxsync, 14 years ago

FE/Qt4: added a new segmented button type; code cleanup

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/* $Id: QIDialogButtonBox.cpp 30356 2010-06-22 08:42:22Z vboxsync $ */
2/** @file
3 *
4 * VBox frontends: Qt GUI ("VirtualBox"):
5 * VirtualBox Qt extensions: QIDialogButtonBox class implementation
6 */
7
8/*
9 * Copyright (C) 2008 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#include "QIDialogButtonBox.h"
21#include "UISpecialControls.h"
22
23#include <iprt/assert.h>
24
25/* Qt includes */
26#include <QPushButton>
27#include <QEvent>
28#include <QBoxLayout>
29
30QIDialogButtonBox::QIDialogButtonBox (StandardButtons aButtons, Qt::Orientation aOrientation, QWidget *aParent)
31 : QIWithRetranslateUI<QDialogButtonBox> (aParent)
32{
33 setOrientation (aOrientation);
34 setStandardButtons (aButtons);
35
36 retranslateUi();
37}
38
39QPushButton *QIDialogButtonBox::button (StandardButton aWhich) const
40{
41 QPushButton *button = QDialogButtonBox::button (aWhich);
42 if (!button &&
43 aWhich == QDialogButtonBox::Help)
44 button = mHelpButton;
45 return button;
46}
47
48QPushButton *QIDialogButtonBox::addButton (const QString &aText, ButtonRole aRole)
49{
50 QPushButton *btn = QDialogButtonBox::addButton (aText, aRole);
51 retranslateUi();
52 return btn;
53}
54
55QPushButton *QIDialogButtonBox::addButton (StandardButton aButton)
56{
57 QPushButton *btn = QDialogButtonBox::addButton (aButton);
58 retranslateUi();
59 return btn;
60}
61
62void QIDialogButtonBox::setStandardButtons (StandardButtons aButtons)
63{
64 QDialogButtonBox::setStandardButtons (aButtons);
65 retranslateUi();
66}
67
68void QIDialogButtonBox::addExtraWidget (QWidget* aWidget)
69{
70 QBoxLayout *layout = boxLayout();
71 int index = findEmptySpace (layout);
72 layout->insertWidget (index + 1, aWidget);
73 layout->insertStretch(index + 2);
74}
75
76
77void QIDialogButtonBox::addExtraLayout (QLayout* aLayout)
78{
79 QBoxLayout *layout = boxLayout();
80 int index = findEmptySpace (layout);
81 layout->insertLayout (index + 1, aLayout);
82 layout->insertStretch(index + 2);
83}
84
85QBoxLayout *QIDialogButtonBox::boxLayout() const
86{
87 QBoxLayout *boxlayout = qobject_cast<QBoxLayout*> (layout());
88 AssertMsg (VALID_PTR (boxlayout), ("Layout of the QDialogButtonBox isn't a box layout."));
89 return boxlayout;
90}
91
92int QIDialogButtonBox::findEmptySpace (QBoxLayout *aLayout) const
93{
94 /* Search for the first occurrence of QSpacerItem and return the index.
95 * Please note that this is Qt internal, so it may change at any time. */
96 int i=0;
97 for (; i < aLayout->count(); ++i)
98 {
99 QLayoutItem *item = aLayout->itemAt(i);
100 if (item->spacerItem())
101 break;
102 }
103 return i;
104}
105
106void QIDialogButtonBox::retranslateUi()
107{
108 QPushButton *btn = QDialogButtonBox::button (QDialogButtonBox::Help);
109 if (btn)
110 {
111 /* Use our very own help button if the user requested for one. */
112 if (!mHelpButton)
113 mHelpButton = new UIHelpButton;
114 mHelpButton->initFrom (btn);
115 removeButton (btn);
116 QDialogButtonBox::addButton (mHelpButton, QDialogButtonBox::HelpRole);
117 }
118}
119
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use