1 | /* $Id: UISoftKeyboardDialog.cpp 78567 2019-05-17 12:27:12Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UISoftKeyboardDialog class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /* Qt includes: */
|
---|
19 | #include <QPushButton>
|
---|
20 | #include <QVBoxLayout>
|
---|
21 |
|
---|
22 | /* GUI includes: */
|
---|
23 | #include "UIDesktopWidgetWatchdog.h"
|
---|
24 | #include "UIExtraDataManager.h"
|
---|
25 | #include "UIIconPool.h"
|
---|
26 | #include "UIGuestControlConsole.h"
|
---|
27 | #include "UISoftKeyboardDialog.h"
|
---|
28 | #include "UISoftKeyboard.h"
|
---|
29 | #include "VBoxGlobal.h"
|
---|
30 | #ifdef VBOX_WS_MAC
|
---|
31 | # include "VBoxUtils-darwin.h"
|
---|
32 | #endif
|
---|
33 |
|
---|
34 |
|
---|
35 | /*********************************************************************************************************************************
|
---|
36 | * Class UISoftKeyboardDialogFactory implementation. *
|
---|
37 | *********************************************************************************************************************************/
|
---|
38 |
|
---|
39 | UISoftKeyboardDialogFactory::UISoftKeyboardDialogFactory(UIActionPool *pActionPool /* = 0 */,
|
---|
40 | const QString &strMachineName /* = QString() */)
|
---|
41 | : m_pActionPool(pActionPool)
|
---|
42 | , m_strMachineName(strMachineName)
|
---|
43 | {
|
---|
44 | }
|
---|
45 |
|
---|
46 | void UISoftKeyboardDialogFactory::create(QIManagerDialog *&pDialog, QWidget *pCenterWidget)
|
---|
47 | {
|
---|
48 | pDialog = new UISoftKeyboardDialog(pCenterWidget, m_pActionPool, m_strMachineName);
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | /*********************************************************************************************************************************
|
---|
53 | * Class UISoftKeyboardDialog implementation. *
|
---|
54 | *********************************************************************************************************************************/
|
---|
55 |
|
---|
56 | UISoftKeyboardDialog::UISoftKeyboardDialog(QWidget *pCenterWidget,
|
---|
57 | UIActionPool *pActionPool,
|
---|
58 | const QString &strMachineName /* = QString() */)
|
---|
59 | : QIWithRetranslateUI<QIManagerDialog>(pCenterWidget)
|
---|
60 | , m_pActionPool(pActionPool)
|
---|
61 | , m_strMachineName(strMachineName)
|
---|
62 | {
|
---|
63 | }
|
---|
64 |
|
---|
65 | void UISoftKeyboardDialog::retranslateUi()
|
---|
66 | {
|
---|
67 | /* Translate window title: */
|
---|
68 | setWindowTitle(tr("%1 - Guest Control").arg(m_strMachineName));
|
---|
69 | /* Translate buttons: */
|
---|
70 | button(ButtonType_Close)->setText(tr("Close"));
|
---|
71 | }
|
---|
72 |
|
---|
73 | void UISoftKeyboardDialog::configure()
|
---|
74 | {
|
---|
75 | /* Apply window icons: */
|
---|
76 | setWindowIcon(UIIconPool::iconSetFull(":/vm_show_logs_32px.png", ":/vm_show_logs_16px.png"));
|
---|
77 | }
|
---|
78 |
|
---|
79 | void UISoftKeyboardDialog::configureCentralWidget()
|
---|
80 | {
|
---|
81 | /* Create widget: */
|
---|
82 | UISoftKeyboard *pSoftKeyboard = new UISoftKeyboard(EmbedTo_Dialog, 0, "");
|
---|
83 |
|
---|
84 | if (pSoftKeyboard)
|
---|
85 | {
|
---|
86 | /* Configure widget: */
|
---|
87 | setWidget(pSoftKeyboard);
|
---|
88 | //setWidgetMenu(pWidget->menu());
|
---|
89 | #ifdef VBOX_WS_MAC
|
---|
90 | //setWidgetToolbar(pWidget->toolbar());
|
---|
91 | #endif
|
---|
92 | /* Add into layout: */
|
---|
93 | centralWidget()->layout()->addWidget(pSoftKeyboard);
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | void UISoftKeyboardDialog::finalize()
|
---|
98 | {
|
---|
99 | /* Apply language settings: */
|
---|
100 | retranslateUi();
|
---|
101 | }
|
---|
102 |
|
---|
103 | void UISoftKeyboardDialog::loadSettings()
|
---|
104 | {
|
---|
105 | const QRect desktopRect = gpDesktop->availableGeometry(this);
|
---|
106 | int iDefaultWidth = desktopRect.width() / 2;
|
---|
107 | int iDefaultHeight = desktopRect.height() * 3 / 4;
|
---|
108 |
|
---|
109 | QRect defaultGeometry(0, 0, iDefaultWidth, iDefaultHeight);
|
---|
110 | if (centerWidget())
|
---|
111 | defaultGeometry.moveCenter(centerWidget()->geometry().center());
|
---|
112 |
|
---|
113 | /* Load geometry from extradata: */
|
---|
114 | QRect geometry = gEDataManager->guestProcessControlDialogGeometry(this, defaultGeometry);
|
---|
115 |
|
---|
116 | /* Restore geometry: */
|
---|
117 | LogRel2(("GUI: UISoftKeyboardDialog: Restoring geometry to: Origin=%dx%d, Size=%dx%d\n",
|
---|
118 | geometry.x(), geometry.y(), geometry.width(), geometry.height()));
|
---|
119 | setDialogGeometry(geometry);
|
---|
120 | }
|
---|
121 |
|
---|
122 | void UISoftKeyboardDialog::saveSettings() const
|
---|
123 | {
|
---|
124 | /* Save window geometry to extradata: */
|
---|
125 | const QRect saveGeometry = geometry();
|
---|
126 | #ifdef VBOX_WS_MAC
|
---|
127 | /* darwinIsWindowMaximized expects a non-const QWidget*. thus const_cast: */
|
---|
128 | QWidget *pw = const_cast<QWidget*>(qobject_cast<const QWidget*>(this));
|
---|
129 | gEDataManager->setGuestProcessControlDialogGeometry(saveGeometry, ::darwinIsWindowMaximized(pw));
|
---|
130 | #else /* !VBOX_WS_MAC */
|
---|
131 | gEDataManager->setGuestProcessControlDialogGeometry(saveGeometry, isMaximized());
|
---|
132 | #endif /* !VBOX_WS_MAC */
|
---|
133 | LogRel2(("GUI: Guest Process Control Dialog: Geometry saved as: Origin=%dx%d, Size=%dx%d\n",
|
---|
134 | saveGeometry.x(), saveGeometry.y(), saveGeometry.width(), saveGeometry.height()));
|
---|
135 | }
|
---|
136 |
|
---|
137 | bool UISoftKeyboardDialog::shouldBeMaximized() const
|
---|
138 | {
|
---|
139 | return gEDataManager->guestProcessControlDialogShouldBeMaximized();
|
---|
140 | }
|
---|
141 |
|
---|
142 | void UISoftKeyboardDialog::sltSetCloseButtonShortCut(QKeySequence shortcut)
|
---|
143 | {
|
---|
144 | if (button(ButtonType_Close))
|
---|
145 | button(ButtonType_Close)->setShortcut(shortcut);
|
---|
146 | }
|
---|