Index: trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp	(revision 78963)
+++ trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp	(revision 78964)
@@ -199,4 +199,5 @@
     void mouseReleaseEvent(QMouseEvent *pEvent) /* override */;
     void mouseMoveEvent(QMouseEvent *pEvent) /* override */;
+
     virtual void retranslateUi() /* override */;
 
@@ -204,6 +205,6 @@
 
     void sltHandleMenuBarContextMenuRequest(const QPoint &point);
-    void sltHandleLoadLayoutFile();
-    void sltHandleLoadDefaultLayout();
+    void sltHandleLoadLayout(QAction *pSenderAction);
+    void sltHandleShowKeyPositions();
 
 private:
@@ -215,6 +216,8 @@
     void               handleKeyPress(UISoftKeyboardKey *pKey);
     void               handleKeyRelease(UISoftKeyboardKey *pKey);
-    void               createKeyboard(const QString &strLayoutFileName = QString());
+    bool               createKeyboard(const QString &strLayoutFileName);
     void               reset();
+    void               configure();
+    void               prepareObjects();
 
     UISoftKeyboardKey *m_pKeyUnderMouse;
@@ -239,4 +242,10 @@
     int   m_iRightMargin;
     int   m_iBottomMargin;
+
+    QMenu   *m_pContextMenu;
+    QActionGroup *m_pLayoutActionGroup;
+    QAction *m_pShowPositionsAction;
+    QAction *m_pLoadLayoutFileAction;
+    QAction *m_pLastSelectedLayout;
 };
 
@@ -549,11 +558,12 @@
     , m_iRightMargin(10)
     , m_iBottomMargin(10)
-{
-    defaultLayouts << ":/101_ansi.xml" << ":/102_iso.xml";
-    setMouseTracking(true);
-    setContextMenuPolicy(Qt::CustomContextMenu);
-    createKeyboard();
-    connect(this, &UISoftKeyboardWidget::customContextMenuRequested,
-            this, &UISoftKeyboardWidget::sltHandleMenuBarContextMenuRequest);
+    , m_pContextMenu(0)
+    , m_pShowPositionsAction(0)
+    , m_pLoadLayoutFileAction(0)
+    , m_pLastSelectedLayout(0)
+{
+
+    configure();
+    prepareObjects();
 }
 
@@ -607,8 +617,11 @@
             painter.drawPolygon(key.polygon());
 
+
             QRect textRect(0.55 * unitSize, 1 * unitSize
                            , key.keyGeometry().width(), key.keyGeometry().height());
-            //painter.drawText(textRect, Qt::TextWordWrap, key.keyCap());
-            painter.drawText(textRect, Qt::TextWordWrap, QString::number(key.position()));
+            if (m_pShowPositionsAction && m_pShowPositionsAction->isChecked())
+                painter.drawText(textRect, Qt::TextWordWrap, QString::number(key.position()));
+            else
+                painter.drawText(textRect, Qt::TextWordWrap, key.keyCap());
 
             if (key.type() != UIKeyType_Ordinary)
@@ -657,4 +670,10 @@
 }
 
+void UISoftKeyboard::focusOutEvent(QFocusEvent *pEvent)
+{
+    QIWithRetranslateUI<QMainWindow>::focusOutEvent(pEvent);
+    printf("booo\n");
+}
+
 void UISoftKeyboardWidget::retranslateUi()
 {
@@ -663,37 +682,45 @@
 void UISoftKeyboardWidget::sltHandleMenuBarContextMenuRequest(const QPoint &point)
 {
-    QMenu menu;
-    foreach (const QString &strLayout, defaultLayouts)
-    {
-        QString strName = strLayout.left(strLayout.indexOf('.'));
-        QAction *pAction = menu.addAction(QString("%1 %2").arg(UISoftKeyboard::tr("Load Layout ")).arg(strName.remove(":/")));
-        pAction->setData(strLayout);
-        connect(pAction, &QAction::triggered, this, &UISoftKeyboardWidget::sltHandleLoadDefaultLayout);
-    }
-    QAction *pAction = menu.addAction(UISoftKeyboard::tr("Load Layout File"));
-    connect(pAction, &QAction::triggered, this, &UISoftKeyboardWidget::sltHandleLoadLayoutFile);
-    menu.exec(mapToGlobal(point));
-}
-
-void UISoftKeyboardWidget::sltHandleLoadLayoutFile()
-{
-    const QString strFileName = QIFileDialog::getOpenFileName(QString(), "XML files (*.xml)", this,
-                                                              UISoftKeyboard::tr("Choose file to load physical keyboard layout.."));
-    if (strFileName.isEmpty())
+    m_pContextMenu->exec(mapToGlobal(point));
+    update();
+}
+
+void UISoftKeyboardWidget::sltHandleLoadLayout(QAction *pSenderAction)
+{
+    if (!pSenderAction)
         return;
-    createKeyboard(strFileName);
-}
-
-void UISoftKeyboardWidget::sltHandleLoadDefaultLayout()
-{
-    QAction *pSender = qobject_cast<QAction*>(sender());
-    if (!pSender)
-        return;
-    QString strLayout = pSender->data().toString();
-    if (strLayout.isEmpty())
-        return;
-    createKeyboard(strLayout);
-}
-
+    if (pSenderAction == m_pLoadLayoutFileAction)
+    {
+        const QString strFileName = QIFileDialog::getOpenFileName(QString(), "XML files (*.xml)", this,
+                                                                  UISoftKeyboard::tr("Choose file to load physical keyboard layout.."));
+        if (!strFileName.isEmpty() && createKeyboard(strFileName))
+        {
+            m_pLastSelectedLayout = pSenderAction;
+            m_pLoadLayoutFileAction->setData(strFileName);
+            return;
+        }
+    }
+    else
+    {
+        QString strLayout = pSenderAction->data().toString();
+        if (!strLayout.isEmpty() && createKeyboard(strLayout))
+        {
+            m_pLastSelectedLayout = pSenderAction;
+            return;
+        }
+    }
+    /** In case something went wrong try to restore the previous layout: */
+    if (m_pLastSelectedLayout)
+    {
+        QString strLayout = m_pLastSelectedLayout->data().toString();
+        createKeyboard(strLayout);
+        m_pLastSelectedLayout->setChecked(true);
+    }
+}
+
+void UISoftKeyboardWidget::sltHandleShowKeyPositions()
+{
+
+}
 
 void UISoftKeyboardWidget::setNewMinimumSize(const QSize &size)
@@ -802,5 +829,5 @@
 }
 
-void UISoftKeyboardWidget::createKeyboard(const QString &strLayoutFileName /* = QString() */)
+bool UISoftKeyboardWidget::createKeyboard(const QString &strLayoutFileName)
 {
     UIKeyboardLayoutReader reader;
@@ -808,11 +835,9 @@
     reset();
     bool fParseSuccess = false;
-    if (strLayoutFileName.isEmpty())
-        fParseSuccess = reader.parseXMLFile(":/101_ansi.xml", rows);
-    else
+    if (!strLayoutFileName.isEmpty())
         fParseSuccess = reader.parseXMLFile(strLayoutFileName, rows);
 
     if (!fParseSuccess)
-        return;
+        return false;
 
     int iY = m_iTopMargin;
@@ -849,4 +874,5 @@
     setInitialSize(fScale * iInitialWidth, fScale * iInitialHeight);
     update();
+    return true;
 }
 
@@ -855,4 +881,58 @@
     m_pressedModifiers.clear();
     m_rows.clear();
+}
+
+void UISoftKeyboardWidget::configure()
+{
+    defaultLayouts << ":/101_ansi.xml" << ":/102_iso.xml";
+    setMouseTracking(true);
+    setContextMenuPolicy(Qt::CustomContextMenu);
+    connect(this, &UISoftKeyboardWidget::customContextMenuRequested,
+            this, &UISoftKeyboardWidget::sltHandleMenuBarContextMenuRequest);
+}
+
+void UISoftKeyboardWidget::prepareObjects()
+{
+    m_pContextMenu = new QMenu(this);
+    //m_pShowPositionsAction = m_pContextMenu->addAction("
+    m_pLayoutActionGroup = new QActionGroup(this);
+    m_pLayoutActionGroup->setExclusive(true);
+    connect(m_pLayoutActionGroup, &QActionGroup::triggered, this, &UISoftKeyboardWidget::sltHandleLoadLayout);
+
+    foreach (const QString &strLayout, defaultLayouts)
+    {
+        QString strName = strLayout.left(strLayout.indexOf('.'));
+        QAction *pAction = m_pLayoutActionGroup->addAction(QString("%1 %2").arg(UISoftKeyboard::tr("Load Layout ")).arg(strName.remove(":/")));
+        pAction->setData(strLayout);
+        pAction->setCheckable(true);
+    }
+    m_pLoadLayoutFileAction = m_pLayoutActionGroup->addAction(UISoftKeyboard::tr("Load Layout File"));
+    m_pLoadLayoutFileAction->setCheckable(true);
+
+    m_pContextMenu->addActions(m_pLayoutActionGroup->actions());
+    m_pContextMenu->addSeparator();
+
+    m_pShowPositionsAction = m_pContextMenu->addAction(UISoftKeyboard::tr("Show key positions instead of key caps"));
+    connect(m_pLayoutActionGroup, &QActionGroup::triggered, this, &UISoftKeyboardWidget::sltHandleShowKeyPositions);
+    m_pShowPositionsAction->setCheckable(true);
+    m_pShowPositionsAction->setChecked(false);
+
+    /* Choose the first layput action's data as the defaults one: */
+    if (!m_pLayoutActionGroup->actions().empty())
+    {
+        QAction *pAction = m_pLayoutActionGroup->actions().at(0);
+        if (pAction)
+        {
+            QString strLayout = pAction->data().toString();
+            if (!strLayout.isEmpty())
+            {
+                if (createKeyboard(strLayout))
+                {
+                    m_pLastSelectedLayout = pAction;
+                    pAction->setChecked(true);
+                }
+            }
+        }
+    }
 }
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h	(revision 78963)
+++ trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.h	(revision 78964)
@@ -56,4 +56,5 @@
 
     virtual void retranslateUi() /* override */;
+    void focusOutEvent(QFocusEvent *pEvent) /* override */;
 
 private slots:
