VirtualBox

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

Last change on this file since 103977 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
1/* $Id: UIToolsHandlerKeyboard.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIToolsHandlerKeyboard 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 <QKeyEvent>
30
31/* GUI incluedes: */
32#include "UIToolsHandlerKeyboard.h"
33#include "UIToolsModel.h"
34#include "UIToolsItem.h"
35
36
37UIToolsHandlerKeyboard::UIToolsHandlerKeyboard(UIToolsModel *pParent)
38 : QObject(pParent)
39 , m_pModel(pParent)
40{
41}
42
43bool UIToolsHandlerKeyboard::handle(QKeyEvent *pEvent, UIKeyboardEventType enmType) const
44{
45 /* Process passed event: */
46 switch (enmType)
47 {
48 case UIKeyboardEventType_Press: return handleKeyPress(pEvent);
49 case UIKeyboardEventType_Release: return handleKeyRelease(pEvent);
50 }
51 /* Pass event if unknown: */
52 return false;
53}
54
55UIToolsModel *UIToolsHandlerKeyboard::model() const
56{
57 return m_pModel;
58}
59
60bool UIToolsHandlerKeyboard::handleKeyPress(QKeyEvent *pEvent) const
61{
62 /* Which key it was? */
63 switch (pEvent->key())
64 {
65 /* Key UP? */
66 case Qt::Key_Up:
67 /* Key HOME? */
68 case Qt::Key_Home:
69 {
70 /* Determine focus item position: */
71 const int iPosition = model()->navigationList().indexOf(model()->focusItem());
72 /* Determine 'previous' item: */
73 UIToolsItem *pPreviousItem = 0;
74 if (iPosition > 0)
75 {
76 if (pEvent->key() == Qt::Key_Up)
77 for (int i = iPosition - 1; i >= 0; --i)
78 {
79 UIToolsItem *pIteratedItem = model()->navigationList().at(i);
80 if (pIteratedItem->isEnabled())
81 {
82 pPreviousItem = pIteratedItem;
83 break;
84 }
85 }
86 else if (pEvent->key() == Qt::Key_Home)
87 pPreviousItem = model()->navigationList().first();
88 }
89 if (pPreviousItem)
90 {
91 /* Make 'previous' item the current one: */
92 model()->setCurrentItem(pPreviousItem);
93 /* Filter-out this event: */
94 return true;
95 }
96 /* Pass this event: */
97 return false;
98 }
99 /* Key DOWN? */
100 case Qt::Key_Down:
101 /* Key END? */
102 case Qt::Key_End:
103 {
104 /* Determine focus item position: */
105 int iPosition = model()->navigationList().indexOf(model()->focusItem());
106 /* Determine 'next' item: */
107 UIToolsItem *pNextItem = 0;
108 if (iPosition < model()->navigationList().size() - 1)
109 {
110 if (pEvent->key() == Qt::Key_Down)
111 for (int i = iPosition + 1; i < model()->navigationList().size(); ++i)
112 {
113 UIToolsItem *pIteratedItem = model()->navigationList().at(i);
114 if (pIteratedItem->isEnabled())
115 {
116 pNextItem = pIteratedItem;
117 break;
118 }
119 }
120 else if (pEvent->key() == Qt::Key_End)
121 pNextItem = model()->navigationList().last();
122 }
123 if (pNextItem)
124 {
125 /* Make 'next' item the current one: */
126 model()->setCurrentItem(pNextItem);
127 /* Filter-out this event: */
128 return true;
129 }
130 /* Pass this event: */
131 return false;
132 }
133 default:
134 break;
135 }
136 /* Pass all other events: */
137 return false;
138}
139
140bool UIToolsHandlerKeyboard::handleKeyRelease(QKeyEvent *) const
141{
142 /* Pass all events: */
143 return false;
144}
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