VirtualBox

Changeset 50553 in vbox


Ignore:
Timestamp:
Feb 24, 2014 10:33:21 AM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: 7262: Global settings / Input page: Implement *clear* tool-button for host-combo inline editor.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/widgets
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.cpp

    r45889 r50553  
    2828#include "UIHostComboEditor.h"
    2929#include "VBoxGlobal.h"
     30#include "QIToolButton.h"
     31#include "UIIconPool.h"
    3032
    3133#ifdef Q_WS_WIN
     
    314316
    315317UIHostComboEditor::UIHostComboEditor(QWidget *pParent)
    316     : QLineEdit(pParent)
    317     , m_pReleaseTimer(0)
     318    : QIWithRetranslateUI<QWidget>(pParent)
     319{
     320    /* Prepare: */
     321    prepare();
     322}
     323
     324void UIHostComboEditor::prepare()
     325{
     326    /* Configure self: */
     327    setAutoFillBackground(true);
     328    /* Create layout: */
     329    QHBoxLayout *pLayout = new QHBoxLayout(this);
     330    {
     331        /* Configure layout: */
     332        pLayout->setSpacing(4);
     333        pLayout->setContentsMargins(0, 0, 0, 0);
     334        /* Create UIHostComboEditorPrivate instance: */
     335        m_pEditor = new UIHostComboEditorPrivate;
     336        {
     337            /* Configure UIHostComboEditorPrivate instance: */
     338            setFocusProxy(m_pEditor);
     339        }
     340        /* Create 'clear' tool-button: */
     341        m_pButtonClear = new QIToolButton;
     342        {
     343            /* Configure 'clear' tool-button: */
     344            m_pButtonClear->removeBorder();
     345            m_pButtonClear->setIcon(UIIconPool::iconSet(":/eraser_16px.png"));
     346            connect(m_pButtonClear, SIGNAL(clicked(bool)), m_pEditor, SLOT(sltClear()));
     347        }
     348        /* Add widgets to layout: */
     349        pLayout->addWidget(m_pEditor);
     350        pLayout->addWidget(m_pButtonClear);
     351    }
     352    /* Translate finally: */
     353    retranslateUi();
     354}
     355
     356void UIHostComboEditor::retranslateUi()
     357{
     358    /* Translate 'clear' tool-button: */
     359    m_pButtonClear->setToolTip(QApplication::translate("UIHotKeyEditor", "Unset shortcut"));
     360}
     361
     362void UIHostComboEditor::setCombo(const UIHostComboWrapper &strCombo)
     363{
     364    /* Pass combo to child: */
     365    m_pEditor->setCombo(strCombo);
     366}
     367
     368UIHostComboWrapper UIHostComboEditor::combo() const
     369{
     370    /* Acquire combo from child: */
     371    return m_pEditor->combo();
     372}
     373
     374
     375UIHostComboEditorPrivate::UIHostComboEditorPrivate()
     376    : m_pReleaseTimer(0)
    318377    , m_fStartNewSequence(true)
    319378{
     
    321380    setAttribute(Qt::WA_NativeWindow);
    322381    setContextMenuPolicy(Qt::NoContextMenu);
     382    setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
    323383    connect(this, SIGNAL(selectionChanged()), this, SLOT(sltDeselect()));
    324384
     
    335395#ifdef Q_WS_MAC
    336396    m_uDarwinKeyModifiers = 0;
    337     UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */, UIHostComboEditor::darwinEventHandlerProc, this);
     397    UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */, UIHostComboEditorPrivate::darwinEventHandlerProc, this);
    338398    ::DarwinGrabKeyboard(false /* just modifiers */);
    339399#endif /* Q_WS_MAC */
    340400}
    341401
    342 UIHostComboEditor::~UIHostComboEditor()
     402UIHostComboEditorPrivate::~UIHostComboEditorPrivate()
    343403{
    344404#ifdef Q_WS_MAC
    345405    ::DarwinReleaseKeyboard();
    346     UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */, UIHostComboEditor::darwinEventHandlerProc, this);
     406    UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown  | NSKeyUp | | NSFlagsChanged */, UIHostComboEditorPrivate::darwinEventHandlerProc, this);
    347407#endif /* Q_WS_MAC */
    348408}
    349409
    350 void UIHostComboEditor::setCombo(const UIHostComboWrapper &strCombo)
     410void UIHostComboEditorPrivate::setCombo(const UIHostComboWrapper &strCombo)
    351411{
    352412    /* Cleanup old combo: */
     
    361421}
    362422
    363 UIHostComboWrapper UIHostComboEditor::combo() const
     423UIHostComboWrapper UIHostComboEditorPrivate::combo() const
    364424{
    365425    /* Compose current combination: */
     
    372432}
    373433
    374 void UIHostComboEditor::sltDeselect()
     434void UIHostComboEditorPrivate::sltDeselect()
    375435{
    376436    deselect();
    377437}
    378438
    379 void UIHostComboEditor::sltClear()
    380 {
     439void UIHostComboEditorPrivate::sltClear()
     440{
     441    /* Cleanup combo: */
    381442    m_shownKeys.clear();
     443    /* Update text: */
    382444    updateText();
     445    /* Move the focus to text-field: */
     446    setFocus();
    383447}
    384448
     
    453517}
    454518
    455 bool UIHostComboEditor::winEvent(MSG *pMsg, long* /* pResult */)
     519bool UIHostComboEditorPrivate::winEvent(MSG *pMsg, long* /* pResult */)
    456520{
    457521    switch (pMsg->message)
     
    484548#pragma GCC diagnostic push
    485549#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
    486 bool UIHostComboEditor::x11Event(XEvent *pEvent)
     550bool UIHostComboEditorPrivate::x11Event(XEvent *pEvent)
    487551{
    488552    switch (pEvent->type)
     
    511575#ifdef Q_WS_MAC
    512576/* static */
    513 bool UIHostComboEditor::darwinEventHandlerProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser)
    514 {
    515     UIHostComboEditor *pEditor = static_cast<UIHostComboEditor*>(pvUser);
     577bool UIHostComboEditorPrivate::darwinEventHandlerProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser)
     578{
     579    UIHostComboEditorPrivate *pEditor = static_cast<UIHostComboEditorPrivate*>(pvUser);
    516580    EventRef inEvent = (EventRef)pvCarbonEvent;
    517581    UInt32 EventClass = ::GetEventClass(inEvent);
     
    521585}
    522586
    523 bool UIHostComboEditor::darwinKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent)
     587bool UIHostComboEditorPrivate::darwinKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent)
    524588{
    525589    /* Ignore key changes unless we're the focus widget: */
     
    567631#endif /* Q_WS_MAC */
    568632
    569 void UIHostComboEditor::keyPressEvent(QKeyEvent *pEvent)
     633void UIHostComboEditorPrivate::keyPressEvent(QKeyEvent *pEvent)
    570634{
    571635    /* Ignore most of key presses... */
    572636    switch (pEvent->key())
    573637    {
     638        case Qt::Key_Enter:
     639        case Qt::Key_Return:
    574640        case Qt::Key_Tab:
    575641        case Qt::Key_Backtab:
     
    587653}
    588654
    589 void UIHostComboEditor::keyReleaseEvent(QKeyEvent *pEvent)
     655void UIHostComboEditorPrivate::keyReleaseEvent(QKeyEvent *pEvent)
    590656{
    591657    /* Ignore most of key presses... */
     
    607673}
    608674
    609 void UIHostComboEditor::mousePressEvent(QMouseEvent *pEvent)
     675void UIHostComboEditorPrivate::mousePressEvent(QMouseEvent *pEvent)
    610676{
    611677    /* Handle like for usual QWidget: */
     
    613679}
    614680
    615 void UIHostComboEditor::mouseReleaseEvent(QMouseEvent *pEvent)
     681void UIHostComboEditorPrivate::mouseReleaseEvent(QMouseEvent *pEvent)
    616682{
    617683    /* Handle like for usual QWidget: */
     
    619685}
    620686
    621 void UIHostComboEditor::sltReleasePendingKeys()
     687void UIHostComboEditorPrivate::sltReleasePendingKeys()
    622688{
    623689    /* Stop the timer, we process all pending keys at once: */
     
    642708}
    643709
    644 bool UIHostComboEditor::processKeyEvent(int iKeyCode, bool fKeyPress)
     710bool UIHostComboEditorPrivate::processKeyEvent(int iKeyCode, bool fKeyPress)
    645711{
    646712    /* Check if symbol is valid else pass it to Qt: */
     
    695761}
    696762
    697 void UIHostComboEditor::updateText()
     763void UIHostComboEditorPrivate::updateText()
    698764{
    699765    QStringList shownKeyNames(m_shownKeys.values());
    700     setText(shownKeyNames.isEmpty() ? tr("None") : shownKeyNames.join(" + "));
    701 }
    702 
     766    setText(shownKeyNames.isEmpty() ? UIHostComboEditor::tr("None") : shownKeyNames.join(" + "));
     767}
     768
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHostComboEditor.h

    r44753 r50553  
    2525#include <QMap>
    2626#include <QSet>
     27
     28/* GUI includes: */
     29#include "QIWithRetranslateUI.h"
     30
     31/* Forward declarations: */
     32class UIHostComboEditorPrivate;
     33class QIToolButton;
    2734
    2835/* Native hot-key namespace to unify
     
    6976Q_DECLARE_METATYPE(UIHostComboWrapper);
    7077
    71 /* Host-combo editor widget: */
    72 class UIHostComboEditor : public QLineEdit
     78/** Host-combo editor widget. */
     79class UIHostComboEditor : public QIWithRetranslateUI<QWidget>
    7380{
    7481    Q_OBJECT;
     
    7784public:
    7885
     86    /** Constructs host-combo editor for passed @a pParent. */
    7987    UIHostComboEditor(QWidget *pParent);
    80     ~UIHostComboEditor();
     88
     89private:
     90
     91    /** Prepares widget content. */
     92    void prepare();
     93
     94    /** Translates widget content. */
     95    void retranslateUi();
     96
     97    /** Defines host-combo sequence. */
     98    void setCombo(const UIHostComboWrapper &strCombo);
     99    /** Returns host-combo sequence. */
     100    UIHostComboWrapper combo() const;
     101
     102    /** UIHostComboEditorPrivate instance. */
     103    UIHostComboEditorPrivate *m_pEditor;
     104    /** <b>Clear</b> QIToolButton instance. */
     105    QIToolButton *m_pButtonClear;
     106};
     107
     108/* Host-combo editor widget private stuff: */
     109class UIHostComboEditorPrivate : public QLineEdit
     110{
     111    Q_OBJECT;
     112
     113public:
     114
     115    UIHostComboEditorPrivate();
     116    ~UIHostComboEditorPrivate();
    81117
    82118    void setCombo(const UIHostComboWrapper &strCombo);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette