VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/widgets/graphics/UIGraphicsToolBar.cpp@ 103988

Last change on this file since 103988 was 98103, checked in by vboxsync, 21 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.7 KB
Line 
1/* $Id: UIGraphicsToolBar.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIGraphicsToolBar class definition.
4 */
5
6/*
7 * Copyright (C) 2012-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* GUI includes: */
29#include "UIGraphicsToolBar.h"
30#include "UIGraphicsButton.h"
31
32
33UIGraphicsToolBar::UIGraphicsToolBar(QIGraphicsWidget *pParent, int iRows, int iColumns)
34 : QIGraphicsWidget(pParent)
35 , m_iMargin(3)
36 , m_iRows(iRows)
37 , m_iColumns(iColumns)
38{
39}
40
41int UIGraphicsToolBar::toolBarMargin() const
42{
43 return m_iMargin;
44}
45
46void UIGraphicsToolBar::setToolBarMargin(int iMargin)
47{
48 m_iMargin = iMargin;
49}
50
51void UIGraphicsToolBar::insertItem(UIGraphicsButton *pButton, int iRow, int iColumn)
52{
53 UIGraphicsToolBarIndex key = qMakePair(iRow, iColumn);
54 m_buttons.insert(key, pButton);
55}
56
57void UIGraphicsToolBar::updateLayout()
58{
59 /* For all the rows: */
60 for (int iRow = 0; iRow < m_iRows; ++iRow)
61 {
62 /* For all the columns: */
63 for (int iColumn = 0; iColumn < m_iColumns; ++iColumn)
64 {
65 /* Generate key: */
66 UIGraphicsToolBarIndex key = qMakePair(iRow, iColumn);
67 /* Check if key present: */
68 if (m_buttons.contains(key))
69 {
70 /* Get corresponding button: */
71 UIGraphicsButton *pButton = m_buttons.value(key);
72 QSize minimumSize = pButton->minimumSizeHint().toSize();
73 pButton->setPos(toolBarMargin() + iColumn * minimumSize.width(),
74 toolBarMargin() + iRow * minimumSize.height());
75 }
76 }
77 }
78}
79
80QSizeF UIGraphicsToolBar::sizeHint(Qt::SizeHint which, const QSizeF &constraint /* = QSizeF() */) const
81{
82 /* If Qt::MinimumSize hint requested: */
83 if (which == Qt::MinimumSize)
84 {
85 /* Prepare variables: */
86 int iProposedWidth = 2 * toolBarMargin();
87 int iProposedHeight = 2 * toolBarMargin();
88 /* Search for any button: */
89 UIGraphicsButton *pButton = 0;
90 for (int iRow = 0; !pButton && iRow < m_iRows; ++iRow)
91 {
92 /* For all the columns: */
93 for (int iColumn = 0; !pButton && iColumn < m_iColumns; ++iColumn)
94 {
95 /* Generate key: */
96 UIGraphicsToolBarIndex key = qMakePair(iRow, iColumn);
97 /* Check if key present: */
98 if (m_buttons.contains(key))
99 {
100 /* Get corresponding button: */
101 pButton = m_buttons.value(key);
102 }
103 }
104 }
105 /* If any button found: */
106 if (pButton)
107 {
108 /* Get button minimum-size: */
109 QSize minimumSize = pButton->minimumSizeHint().toSize();
110 iProposedWidth += m_iColumns * minimumSize.width();
111 iProposedHeight += m_iRows * minimumSize.height();
112 }
113 /* Return result: */
114 return QSizeF(iProposedWidth, iProposedHeight);
115 }
116 /* Else call to base-class: */
117 return QIGraphicsWidget::sizeHint(which, constraint);
118}
119
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette