VirtualBox

Ignore:
Timestamp:
Dec 15, 2023 4:04:56 PM (16 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
160768
Message:

FE/Qt: bugref:10513: UIAdvancedSettingsDialog: Implementing own UIFilterLineEdit instead of standard (almost) QILineEdit for filter-editor needs; It's mostly required to have more aknowledgable shape of frame; Also, nit in QILineEdit includes.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QILineEdit.cpp

    r101560 r102613  
    3333#include <QLabel>
    3434#include <QMenu>
    35 #include <QPalette>
    3635#include <QStyleOptionFrame>
    3736#include <QWindow>
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UIAdvancedSettingsDialog.cpp

    r102529 r102613  
    115115
    116116
     117/** QILineEdit subclass used as filter line-edit. */
     118class UIFilterLineEdit : public QILineEdit
     119{
     120    Q_OBJECT;
     121
     122public:
     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
     132protected:
     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        QPainterPath path;
     157        QSizeF arcSize(2 * m_iRadius, 2 * m_iRadius);
     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(), widgetRect.height() - m_iRadius);
     161        path.arcTo(QRectF(path.currentPosition(), arcSize).translated(0, -m_iRadius), 180, 90);
     162        path.lineTo(widgetRect.width() - 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(), widgetRect.y() + 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
     176private:
     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
    117198/** QWidget reimplementation
    118   * wrapping custom QILineEdit and
     199  * wrapping UIFilterLineEdit and
    119200  * representing filter editor for advanced settings dialog. */
    120201class UIFilterEditor : public QWidget
     
    186267
    187268    /** Holds the filter editor instance. */
    188     QILineEdit *m_pLineEdit;
     269    UIFilterLineEdit *m_pLineEdit;
    189270    /** Holds the filter reset button instance. */
    190     QToolButton *m_pToolButton;
     271    QToolButton      *m_pToolButton;
    191272
    192273    /** Holds whether filter editor focused. */
     
    444525{
    445526    /* Prepare filter editor: */
    446     m_pLineEdit = new QILineEdit(this);
     527    m_pLineEdit = new UIFilterLineEdit(this);
    447528    if (m_pLineEdit)
    448529    {
    449530        m_pLineEdit->installEventFilter(this);
    450         connect(m_pLineEdit, &QILineEdit::textChanged,
     531        connect(m_pLineEdit, &UIFilterLineEdit::textChanged,
    451532                this, &UIFilterEditor::sltHandleEditorTextChanged);
    452533    }
Note: See TracChangeset for help on using the changeset viewer.

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