UIHotKeyEditor.cpp revision aee625e805c79f14fbefcf212d05e4c41c266f01
/* $Id$ */
/** @file
*
* VBox frontends: Qt GUI ("VirtualBox"):
* VirtualBox Qt extensions: UIHotKeyEditor class implementation
*/
/*
* Copyright (C) 2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* 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 <QApplication>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QKeyEvent>
/* GUI includes; */
#include "UIHotKeyEditor.h"
#include "UIIconPool.h"
#include "UIHostComboEditor.h"
#include "QIToolButton.h"
/* A line-edit representing hot-key editor: */
class UIHotKeyLineEdit : public QLineEdit
{
public:
/* Constructor: */
private slots:
/* Handler: Selection preserver stuff: */
void sltDeselect() { deselect(); }
private:
/* Handlers: Key event processing stuff: */
};
{
/* Configure self: */
/* Connect selection preserver: */
}
{
/* Is this event ignored? */
if (isKeyEventIgnored(pEvent))
return;
/* Call to base-class: */
}
{
/* Is this event ignored? */
if (isKeyEventIgnored(pEvent))
return;
/* Call to base-class: */
}
{
/* Ignore some keys: */
{
/* Ignore cursor keys: */
return true;
/* Default handling for others: */
default: break;
}
/* Do not ignore key by default: */
return false;
}
, m_fIsModifiersAllowed(false)
, m_pMainLayout(new QHBoxLayout(this))
, m_pButtonLayout(new QHBoxLayout)
, m_pLineEdit(new UIHotKeyLineEdit(this))
, m_pResetButton(new QIToolButton(this))
, m_pClearButton(new QIToolButton(this))
, m_iTakenKey(-1)
, m_fSequenceTaken(false)
{
/* Configure self: */
setAutoFillBackground(true);
/* Configure layout: */
m_pMainLayout->setContentsMargins(0, 0, 0, 0);
/* Configure button layout: */
m_pButtonLayout->setContentsMargins(0, 0, 0, 0);
/* Configure line-edit: */
m_pLineEdit->installEventFilter(this);
/* Configure tool-buttons: */
/* Translate finally: */
}
void UIHotKeyEditor::sltReset()
{
/* Reset the seuence of the hot-key: */
/* Redraw sequence: */
drawSequence();
/* Move the focut to text-field: */
m_pLineEdit->setFocus();
}
void UIHotKeyEditor::sltClear()
{
/* Clear the seuence of the hot-key: */
/* Redraw sequence: */
drawSequence();
/* Move the focut to text-field: */
m_pLineEdit->setFocus();
}
void UIHotKeyEditor::retranslateUi()
{
}
{
/* Special handling for our line-edit only: */
if (pWatched != m_pLineEdit)
/* Special handling for key events only: */
/* Cast passed event to required type: */
/* Should we skip that event to our line-edit? */
return false;
/* Fetch modifiers state: */
/* Handle key event: */
{
default: break;
}
/* Fetch host-combo modifier state: */
/* Reflect sequence: */
/* Prevent further key event handling: */
return true;
}
{
/* Special handling for some keys: */
{
/* Skip Escape to our line-edit: */
case Qt::Key_Escape: return true;
case Qt::Key_Return:
/* Skip cursor keys to our line-edit: */
/* Default handling for others: */
default: break;
}
/* Do not skip by default: */
return false;
}
{
/* Is this event ignored? */
if (isKeyEventIgnored(pEvent))
return;
/* Call to base-class: */
}
{
/* Is this event ignored? */
if (isKeyEventIgnored(pEvent))
return;
/* Call to base-class: */
}
{
/* Ignore some keys: */
{
/* Ignore cursor keys: */
return true;
/* Default handling for others: */
default: break;
}
/* Do not ignore key by default: */
return false;
}
void UIHotKeyEditor::fetchModifiersState()
{
/* Make sure modifiers are allowed: */
if (!m_fIsModifiersAllowed)
return;
/* If full sequence was not yet taken: */
if (!m_fSequenceTaken)
{
/* Recreate the set of taken modifiers: */
{
}
}
}
{
/* Make sure other modifiers are NOT allowed: */
return;
/* Clear the set of taken modifiers: */
/* If taken key was set: */
if (m_iTakenKey != -1)
/* We have to add Host+ modifier: */
}
{
/* Qt by some reason generates text for complex cases like
* Backspace or Del but skip other similar things like
* F1 - F35, Home, End, Page UP, Page DOWN and so on.
* We should declare all the approved keys. */
/* Compose the set of the approved keys: */
/* Add Fn keys: */
approvedKeys << i;
/* Add digit keys: */
approvedKeys << i;
/* We allow to use only English letters in shortcuts.
* The reason is by some reason Qt distinguish native language
* letters only with no modifiers pressed.
* With modifiers pressed Qt thinks the letter is always English. */
approvedKeys << i;
/* Add few more special cases: */
/* Is this one of the approved keys? */
return true;
/* False by default: */
return false;
}
{
/* If full sequence was not yet taken: */
if (!m_fSequenceTaken)
{
/* If finalizing key is pressed: */
if (approvedKeyPressed(pKeyEvent))
{
/* Remember taken key: */
/* Mark full sequence taken: */
m_fSequenceTaken = true;
}
/* If something other is pressed: */
else
{
/* Clear taken key: */
m_iTakenKey = -1;
}
}
}
{
/* If full sequence was taken already and no modifiers are currently held: */
{
/* Reset taken sequence: */
m_fSequenceTaken = false;
}
}
void UIHotKeyEditor::reflectSequence()
{
/* Acquire modifier names: */
{
else
}
if (!modifierNames.isEmpty())
/* Acquire main key name: */
if (m_iTakenKey != -1)
/* Compose the text to reflect: */
/* If modifiers were set: */
if (!strModifierNames.isEmpty())
/* Append the text with modifier names: */
/* If main key was set: */
if (!strMainKeyName.isEmpty())
/* Append the sequence with the main key name: */
/* Reflect what we've got: */
/* Compose the sequence to save: */
/* If main key was set: */
if (!strMainKeyName.isEmpty())
{
/* Append the sequence with the main key name: */
/* If modifiers are allowed: */
/* Prepend the sequence with modifier names: */
}
/* Save what we've got: */
}
void UIHotKeyEditor::drawSequence()
{
/* Compose the text to reflect: */
/* If modifiers are not allowed and the text is not empty: */
/* Prepend the text with Host+ modifier name: */
/* Reflect what we've got: */
}
{
/* Return hot-key: */
return m_hotKey;
}
{
/* Remember passed hot-key: */
/* Remember if modifiers are allowed: */
/* Redraw sequence: */
drawSequence();
}
#include "UIHotKeyEditor.moc"