VirtualBox

Changeset 102619 in vbox for trunk


Ignore:
Timestamp:
Dec 15, 2023 5:48:06 PM (10 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10513: UIAdvancedSettingsDialog: Now merge UIFilterLineEdit into UIFilterEditor; This also requires a bit of rasterizer magic cause parent now draws frame for child.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UIAdvancedSettingsDialog.cpp

    r102618 r102619  
    115115
    116116
    117 /** QILineEdit subclass used as filter line-edit. */
    118 class UIFilterLineEdit : public QILineEdit
    119 {
    120     Q_OBJECT;
    121 
    122 public:
    123 
    124     /** Constructs line-edit passing @a pParent to the base-class. */
    125     UIFilterLineEdit(QWidget *pParent)
    126         : QILineEdit(pParent)
    127         , m_iRadius(0)
    128     {
    129         prepare();
    130     }
    131 
    132 protected:
    133 
    134     /** Handles paint @a pEvent. */
    135     virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE
    136     {
    137         /* Prepare painter: */
    138         QPainter painter(this);
    139         painter.setRenderHint(QPainter::Antialiasing);
    140         painter.setRenderHint(QPainter::TextAntialiasing);
    141         /* Avoid painting more than necessary: */
    142         painter.setClipRect(pEvent->rect());
    143 
    144         /* Prepare colors: */
    145         const bool fActive = window() && window()->isActiveWindow();
    146         const QPalette::ColorGroup enmColorGroup = fActive ? QPalette::Active : QPalette::Inactive;
    147         QColor colorBase = qApp->palette().color(enmColorGroup, QPalette::Base);
    148         QColor colorFrame;
    149         if (uiCommon().isInDarkMode())
    150             colorFrame = qApp->palette().color(enmColorGroup, QPalette::Window).lighter(120);
    151         else
    152             colorFrame = qApp->palette().color(enmColorGroup, QPalette::Window).darker(120);
    153 
    154         /* Prepare base/frame painter path: */
    155         const QRect widgetRect = rect();
    156         const QSizeF arcSize(2 * m_iRadius, 2 * m_iRadius);
    157         QPainterPath path;
    158         path.moveTo(widgetRect.x() + m_iRadius, widgetRect.y());
    159         path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-m_iRadius, 0), 90, 90);
    160         path.lineTo(path.currentPosition().x(), path.currentPosition().y() + widgetRect.height() - 2 * m_iRadius);
    161         path.arcTo(QRectF(path.currentPosition(), arcSize).translated(0, -m_iRadius), 180, 90);
    162         path.lineTo(path.currentPosition().x() + widgetRect.width() - 2 * m_iRadius, path.currentPosition().y());
    163         path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-m_iRadius, -2 * m_iRadius), 270, 90);
    164         path.lineTo(path.currentPosition().x(), path.currentPosition().y() - widgetRect.height() + 2 * m_iRadius);
    165         path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-2 * m_iRadius, -m_iRadius), 0, 90);
    166         path.closeSubpath();
    167 
    168         /* Draw base/frame: */
    169         painter.fillPath(path, colorBase);
    170         painter.strokePath(path, colorFrame);
    171 
    172         /* Call to base-class: */
    173         QILineEdit::paintEvent(pEvent);
    174     }
    175 
    176 private:
    177 
    178     /** Prepares everything. */
    179     void prepare()
    180     {
    181         /* A bit of magic to be able to replace the frame.
    182          * Disable border, adjust margins and make background transparent. */
    183         setStyleSheet("QLineEdit {\
    184                        background-color: rgba(255, 255, 255, 0%);\
    185                        border: 0px none black;\
    186                        margin: 3px 10px 3px 10px;\
    187                        }");
    188 
    189         /* Init the decoration radius: */
    190         m_iRadius = 10;
    191     }
    192 
    193     /** Holds the decoration radius. */
    194     int  m_iRadius;
    195 };
    196 
    197 
    198117/** QWidget reimplementation
    199   * wrapping UIFilterLineEdit and
     118  * wrapping QILineEdit and
    200119  * representing filter editor for advanced settings dialog. */
    201120class UIFilterEditor : public QWidget
     
    239158    /** Handles resize @a pEvent. */
    240159    virtual void resizeEvent(QResizeEvent *pEvent) RT_OVERRIDE;
     160
     161    /** Handles paint @a pEvent. */
     162    virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE;
    241163
    242164private slots:
     
    266188    int focusedEditorWidth() const { return m_iFocusedEditorWidth; }
    267189
     190    /** Holds the decoration radius. */
     191    int  m_iRadius;
     192
    268193    /** Holds the filter editor instance. */
    269     UIFilterLineEdit *m_pLineEdit;
     194    QILineEdit *m_pLineEdit;
    270195    /** Holds the filter reset button instance. */
    271     QToolButton      *m_pToolButton;
     196    QToolButton *m_pToolButton;
    272197
    273198    /** Holds whether filter editor focused. */
     
    444369UIFilterEditor::UIFilterEditor(QWidget *pParent)
    445370    : QWidget(pParent)
     371    , m_iRadius(0)
    446372    , m_pLineEdit(0)
    447373    , m_pToolButton(0)
     
    511437}
    512438
     439void UIFilterEditor::paintEvent(QPaintEvent *pEvent)
     440{
     441    /* Prepare painter: */
     442    QPainter painter(this);
     443    painter.setRenderHint(QPainter::Antialiasing);
     444    painter.setRenderHint(QPainter::TextAntialiasing);
     445    /* Avoid painting more than necessary: */
     446    painter.setClipRect(pEvent->rect());
     447
     448    /* Prepare colors: */
     449    const bool fActive = window() && window()->isActiveWindow();
     450    const QPalette::ColorGroup enmColorGroup = fActive ? QPalette::Active : QPalette::Inactive;
     451    QColor colorBase = qApp->palette().color(enmColorGroup, QPalette::Base);
     452    QColor colorFrame;
     453    if (uiCommon().isInDarkMode())
     454        colorFrame = qApp->palette().color(enmColorGroup, QPalette::Window).lighter(120);
     455    else
     456        colorFrame = qApp->palette().color(enmColorGroup, QPalette::Window).darker(120);
     457
     458    /* Prepare base/frame painter path: */
     459    const QRect widgetRect = m_pLineEdit->geometry();
     460    const QSizeF arcSize(2 * m_iRadius, 2 * m_iRadius);
     461    QPainterPath path;
     462    path.moveTo(widgetRect.x() + m_iRadius, widgetRect.y());
     463    path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-m_iRadius, 0), 90, 90);
     464    path.lineTo(path.currentPosition().x(), path.currentPosition().y() + widgetRect.height() - 2 * m_iRadius);
     465    path.arcTo(QRectF(path.currentPosition(), arcSize).translated(0, -m_iRadius), 180, 90);
     466    path.lineTo(path.currentPosition().x() + widgetRect.width() - 2 * m_iRadius, path.currentPosition().y());
     467    path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-m_iRadius, -2 * m_iRadius), 270, 90);
     468    path.lineTo(path.currentPosition().x(), path.currentPosition().y() - widgetRect.height() + 2 * m_iRadius);
     469    path.arcTo(QRectF(path.currentPosition(), arcSize).translated(-2 * m_iRadius, -m_iRadius), 0, 90);
     470    path.closeSubpath();
     471
     472    /* Draw base/frame: */
     473    painter.fillPath(path, colorBase);
     474    painter.strokePath(path, colorFrame);
     475}
     476
    513477void UIFilterEditor::sltHandleEditorTextChanged(const QString &strText)
    514478{
     
    524488void UIFilterEditor::prepare()
    525489{
     490    /* Init the decoration radius: */
     491    m_iRadius = 10;
     492
    526493    /* Prepare filter editor: */
    527     m_pLineEdit = new UIFilterLineEdit(this);
     494    m_pLineEdit = new QILineEdit(this);
    528495    if (m_pLineEdit)
    529496    {
     497        /* A bit of magic to be able to replace the frame.
     498         * Disable border, adjust margins and make background transparent. */
     499        m_pLineEdit->setStyleSheet("QLineEdit {\
     500                                    background-color: rgba(255, 255, 255, 0%);\
     501                                    border: 0px none black;\
     502                                    margin: 3px 10px 3px 10px;\
     503                                    }");
    530504        m_pLineEdit->installEventFilter(this);
    531         connect(m_pLineEdit, &UIFilterLineEdit::textChanged,
     505        connect(m_pLineEdit, &QILineEdit::textChanged,
    532506                this, &UIFilterEditor::sltHandleEditorTextChanged);
    533507    }
     
    595569    const int iY = 0;
    596570    const int iHeight = m_pLineEdit->minimumSizeHint().height();
     571    const QRect oldGeo = m_pLineEdit->geometry();
    597572    m_pLineEdit->setGeometry(iX, iY, iWidth, iHeight);
     573    const QRect newGeo = m_pLineEdit->geometry();
     574
     575    /* Update rasterizer: */
     576    const QRect rasterizer = oldGeo | newGeo;
     577    update(rasterizer.adjusted(-1, -1, 1, 1));
    598578}
    599579
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