summaryrefslogtreecommitdiff
path: root/src/VBox/Frontends/VirtualBox/src/manager/tools/UIToolsHandlerMouse.cpp
blob: 466e719d6a524f978ced390349e3290706fb8366 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* $Id$ */
/** @file
 * VBox Qt GUI - UIToolsHandlerMouse class implementation.
 */

/*
 * Copyright (C) 2012-2022 Oracle Corporation
 *
 * This file is part of VirtualBox Open Source Edition (OSE), as
 * available from http://www.virtualbox.org. This file is free software;
 * you can redistribute it and/or modify it under the terms of the GNU
 * General Public License (GPL) as published by the Free Software
 * Foundation, in version 2 as it comes in the "COPYING" file of the
 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
 */

/* Qt includes: */
#include <QGraphicsSceneMouseEvent>

/* GUI incluedes: */
#include "UIToolsHandlerMouse.h"
#include "UIToolsModel.h"


UIToolsHandlerMouse::UIToolsHandlerMouse(UIToolsModel *pParent)
    : QObject(pParent)
    , m_pModel(pParent)
{
}

bool UIToolsHandlerMouse::handle(QGraphicsSceneMouseEvent *pEvent, UIMouseEventType enmType) const
{
    /* Process passed event: */
    switch (enmType)
    {
        case UIMouseEventType_Press:   return handleMousePress(pEvent);
        case UIMouseEventType_Release: return handleMouseRelease(pEvent);
    }
    /* Pass event if unknown: */
    return false;
}

UIToolsModel *UIToolsHandlerMouse::model() const
{
    return m_pModel;
}

bool UIToolsHandlerMouse::handleMousePress(QGraphicsSceneMouseEvent *pEvent) const
{
    /* Get item under mouse cursor: */
    QPointF scenePos = pEvent->scenePos();
    if (QGraphicsItem *pItemUnderMouse = model()->itemAt(scenePos))
    {
        /* Which button it was? */
        switch (pEvent->button())
        {
            /* Both buttons: */
            case Qt::LeftButton:
            case Qt::RightButton:
            {
                /* Which item we just clicked? */
                UIToolsItem *pClickedItem = qgraphicsitem_cast<UIToolsItem*>(pItemUnderMouse);
                /* Make clicked item the current one: */
                if (pClickedItem && pClickedItem->isEnabled())
                {
                    model()->setCurrentItem(pClickedItem);
                    model()->closeParent();
                }
                break;
            }
            default:
                break;
        }
    }
    /* Pass all other events: */
    return false;
}

bool UIToolsHandlerMouse::handleMouseRelease(QGraphicsSceneMouseEvent *) const
{
    /* Pass all events: */
    return false;
}