VirtualBox

Changeset 44520 in vbox


Ignore:
Timestamp:
Feb 1, 2013 7:21:56 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: UIHotKeyEditor: Reworking it to use QLineEdit base class, making look&feel more similar to other hot-key input-widgets used in Qt applications.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsInput.ui

    r43106 r44520  
    33 VBox frontends: Qt4 GUI ("VirtualBox"):
    44
    5  Copyright (C) 2008-2012 Oracle Corporation
     5 Copyright (C) 2008-2013 Oracle Corporation
    66
    77 This file is part of VirtualBox Open Source Edition (OSE), as
     
    107107  <customwidget>
    108108   <class>UIHotKeyEditor</class>
    109    <extends>QLabel</extends>
     109   <extends>QLineEdit</extends>
    110110   <header>UIHotKeyEditor.h</header>
    111111  </customwidget>
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHotKeyEditor.cpp

    r41689 r44520  
    77
    88/*
    9  * Copyright (C) 2006-2011 Oracle Corporation
     9 * Copyright (C) 2006-2013 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1818 */
    1919
    20 /* Local includes */
    21 #include "UIHotKeyEditor.h"
    22 #include "VBoxGlobal.h"
    23 
    24 /* Global includes */
     20/* Qt includes: */
    2521#include <QApplication>
    2622#include <QStyleOption>
     
    2824#include <QKeyEvent>
    2925#include <QTimer>
     26
     27/* GUI includes: */
     28#include "UIHotKeyEditor.h"
     29#include "VBoxGlobal.h"
    3030
    3131#ifdef Q_WS_WIN
     
    299299
    300300UIHotKeyEditor::UIHotKeyEditor(QWidget *pParent)
    301     : QLabel(pParent)
     301    : QLineEdit(pParent)
    302302    , m_pReleaseTimer(0)
    303303    , m_fStartNewSequence(true)
     
    305305    /* Configure widget: */
    306306    setAttribute(Qt::WA_NativeWindow);
    307     setFrameStyle(QFrame::StyledPanel | Sunken);
    308307    setAlignment(Qt::AlignCenter);
    309     setFocusPolicy(Qt::StrongFocus);
    310     setAutoFillBackground(true);
    311 
    312     /* Setup palette: */
    313     QPalette p = palette();
    314     p.setColor(QPalette::Active, QPalette::Foreground, p.color(QPalette::Active, QPalette::Text));
    315     p.setColor(QPalette::Active, QPalette::Background, p.color(QPalette::Active, QPalette::Base));
    316     setPalette(p);
     308    setContextMenuPolicy(Qt::NoContextMenu);
     309    connect(this, SIGNAL(selectionChanged()), this, SLOT(sltDeselect()));
    317310
    318311    /* Setup release-pending-keys timer: */
     
    365358}
    366359
    367 QSize UIHotKeyEditor::sizeHint() const
    368 {
    369     ensurePolished();
    370     QFontMetrics fm(font());
    371     int h = qMax(fm.lineSpacing(), 14) + 2;
    372     int w = fm.width('x') * 17;
    373     int m = frameWidth() * 2;
    374     QStyleOption option;
    375     option.initFrom(this);
    376     return (style()->sizeFromContents(QStyle::CT_LineEdit, &option,
    377                                       QSize(w + m, h + m).expandedTo(QApplication::globalStrut()),
    378                                       this));
    379 }
    380 
    381 QSize UIHotKeyEditor::minimumSizeHint() const
    382 {
    383     ensurePolished();
    384     QFontMetrics fm = fontMetrics();
    385     int h = fm.height() + qMax(2, fm.leading());
    386     int w = fm.maxWidth();
    387     int m = frameWidth() * 2;
    388     return QSize(w + m, h + m);
     360void UIHotKeyEditor::sltDeselect()
     361{
     362    deselect();
    389363}
    390364
     
    501475#endif /* Q_WS_MAC */
    502476
    503 void UIHotKeyEditor::focusInEvent(QFocusEvent *pEvent)
    504 {
    505     QLabel::focusInEvent(pEvent);
    506 
    507     QPalette p = palette();
    508     p.setColor(QPalette::Active, QPalette::Foreground, p.color(QPalette::Active, QPalette::HighlightedText));
    509     p.setColor(QPalette::Active, QPalette::Background, p.color(QPalette::Active, QPalette::Highlight));
    510     setPalette(p);
    511 }
    512 
    513 void UIHotKeyEditor::focusOutEvent(QFocusEvent *pEvent)
    514 {
    515     QLabel::focusOutEvent(pEvent);
    516 
    517     QPalette p = palette();
    518     p.setColor(QPalette::Active, QPalette::Foreground, p.color(QPalette::Active, QPalette::Text));
    519     p.setColor(QPalette::Active, QPalette::Background, p.color(QPalette::Active, QPalette::Base));
    520     setPalette(p);
    521 }
    522 
    523 void UIHotKeyEditor::paintEvent(QPaintEvent *pEvent)
    524 {
    525     if (hasFocus())
    526     {
    527         QStylePainter painter(this);
    528         QStyleOptionFocusRect option;
    529         option.initFrom(this);
    530         option.backgroundColor = palette().color(QPalette::Background);
    531         option.rect = contentsRect();
    532         painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);
    533     }
    534     QLabel::paintEvent(pEvent);
     477void UIHotKeyEditor::keyPressEvent(QKeyEvent *pEvent)
     478{
     479    /* Ignore most of key presses... */
     480    switch (pEvent->key())
     481    {
     482        case Qt::Key_Tab:
     483        case Qt::Key_Backtab:
     484        case Qt::Key_Escape:
     485            return QLineEdit::keyPressEvent(pEvent);
     486        default:
     487            break;
     488    }
     489}
     490
     491void UIHotKeyEditor::keyReleaseEvent(QKeyEvent *pEvent)
     492{
     493    /* Ignore most of key presses... */
     494    switch (pEvent->key())
     495    {
     496        case Qt::Key_Tab:
     497        case Qt::Key_Backtab:
     498        case Qt::Key_Escape:
     499            return QLineEdit::keyReleaseEvent(pEvent);
     500        default:
     501            break;
     502    }
     503}
     504
     505void UIHotKeyEditor::mousePressEvent(QMouseEvent *pEvent)
     506{
     507    /* Handle like for usual QWidget: */
     508    QWidget::mousePressEvent(pEvent);
     509}
     510
     511void UIHotKeyEditor::mouseReleaseEvent(QMouseEvent *pEvent)
     512{
     513    /* Handle like for usual QWidget: */
     514    QWidget::mouseReleaseEvent(pEvent);
    535515}
    536516
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHotKeyEditor.h

    r35862 r44520  
    66
    77/*
    8  * Copyright (C) 2006-2011 Oracle Corporation
     8 * Copyright (C) 2006-2013 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020#define ___UIHotKeyEditor_h___
    2121
    22 /* Global includes */
    23 #include <QLabel>
     22/* Qt includes: */
     23#include <QLineEdit>
    2424#include <QMap>
    2525#include <QSet>
     
    4848}
    4949
    50 class UIHotKeyEditor : public QLabel
     50class UIHotKeyEditor : public QLineEdit
    5151{
    5252    Q_OBJECT;
     
    5555
    5656    UIHotKeyEditor(QWidget *pParent);
    57     virtual ~UIHotKeyEditor();
     57    ~UIHotKeyEditor();
    5858
    5959    void setCombo(const QString &strKeyCombo);
    6060    QString combo() const;
    6161
    62     QSize sizeHint() const;
    63     QSize minimumSizeHint() const;
    64 
    6562public slots:
    6663
     64    void sltDeselect();
    6765    void sltClear();
    6866
     
    8078#endif /* Q_WS_MAC */
    8179
    82     void focusInEvent(QFocusEvent *pEvent);
    83     void focusOutEvent(QFocusEvent *pEvent);
    84     void paintEvent(QPaintEvent *pEvent);
     80    void keyPressEvent(QKeyEvent *pEvent);
     81    void keyReleaseEvent(QKeyEvent *pEvent);
     82    void mousePressEvent(QMouseEvent *pEvent);
     83    void mouseReleaseEvent(QMouseEvent *pEvent);
    8584
    8685private slots:
     
    10099    bool m_fStartNewSequence;
    101100
    102 #ifdef RT_OS_DARWIN
     101#ifdef Q_WS_MAC
    103102    /* The current modifier key mask. Used to figure out which modifier
    104103     * key was pressed when we get a kEventRawKeyModifiersChanged event. */
    105104    uint32_t m_uDarwinKeyModifiers;
    106 #endif /* RT_OS_DARWIN */
     105#endif /* Q_WS_MAC */
    107106};
    108107
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