VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/manager/tools/UIToolsHandlerMouse.cpp@ 103977

Last change on this file since 103977 was 102811, checked in by vboxsync, 12 months ago

FE/Qt: A bit of cleanup for UITools; Rework the way model asks parent to close.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
1/* $Id: UIToolsHandlerMouse.cpp 102811 2024-01-10 11:08:41Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIToolsHandlerMouse class implementation.
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/* Qt includes: */
29#include <QGraphicsSceneMouseEvent>
30
31/* GUI incluedes: */
32#include "UIToolsHandlerMouse.h"
33#include "UIToolsModel.h"
34
35
36UIToolsHandlerMouse::UIToolsHandlerMouse(UIToolsModel *pParent)
37 : QObject(pParent)
38 , m_pModel(pParent)
39{
40}
41
42bool UIToolsHandlerMouse::handle(QGraphicsSceneMouseEvent *pEvent, UIMouseEventType enmType) const
43{
44 /* Process passed event: */
45 switch (enmType)
46 {
47 case UIMouseEventType_Press: return handleMousePress(pEvent);
48 case UIMouseEventType_Release: return handleMouseRelease(pEvent);
49 }
50 /* Pass event if unknown: */
51 return false;
52}
53
54UIToolsModel *UIToolsHandlerMouse::model() const
55{
56 return m_pModel;
57}
58
59bool UIToolsHandlerMouse::handleMousePress(QGraphicsSceneMouseEvent *pEvent) const
60{
61 /* Get item under mouse cursor: */
62 QPointF scenePos = pEvent->scenePos();
63 if (QGraphicsItem *pItemUnderMouse = model()->itemAt(scenePos))
64 {
65 /* Which button it was? */
66 switch (pEvent->button())
67 {
68 /* Both buttons: */
69 case Qt::LeftButton:
70 case Qt::RightButton:
71 {
72 /* Which item we just clicked? */
73 UIToolsItem *pClickedItem = qgraphicsitem_cast<UIToolsItem*>(pItemUnderMouse);
74 /* Make clicked item the current one: */
75 if (pClickedItem && pClickedItem->isEnabled())
76 {
77 model()->setCurrentItem(pClickedItem);
78 model()->close();
79 }
80 break;
81 }
82 default:
83 break;
84 }
85 }
86 /* Pass all other events: */
87 return false;
88}
89
90bool UIToolsHandlerMouse::handleMouseRelease(QGraphicsSceneMouseEvent *) const
91{
92 /* Pass all events: */
93 return false;
94}
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