- Timestamp:
- Dec 15, 2023 5:48:06 PM (10 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/UIAdvancedSettingsDialog.cpp
r102618 r102619 115 115 116 116 117 /** QILineEdit subclass used as filter line-edit. */118 class UIFilterLineEdit : public QILineEdit119 {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_OVERRIDE136 {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 else152 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 198 117 /** QWidget reimplementation 199 * wrapping UIFilterLineEdit and118 * wrapping QILineEdit and 200 119 * representing filter editor for advanced settings dialog. */ 201 120 class UIFilterEditor : public QWidget … … 239 158 /** Handles resize @a pEvent. */ 240 159 virtual void resizeEvent(QResizeEvent *pEvent) RT_OVERRIDE; 160 161 /** Handles paint @a pEvent. */ 162 virtual void paintEvent(QPaintEvent *pEvent) RT_OVERRIDE; 241 163 242 164 private slots: … … 266 188 int focusedEditorWidth() const { return m_iFocusedEditorWidth; } 267 189 190 /** Holds the decoration radius. */ 191 int m_iRadius; 192 268 193 /** Holds the filter editor instance. */ 269 UIFilterLineEdit*m_pLineEdit;194 QILineEdit *m_pLineEdit; 270 195 /** Holds the filter reset button instance. */ 271 QToolButton *m_pToolButton;196 QToolButton *m_pToolButton; 272 197 273 198 /** Holds whether filter editor focused. */ … … 444 369 UIFilterEditor::UIFilterEditor(QWidget *pParent) 445 370 : QWidget(pParent) 371 , m_iRadius(0) 446 372 , m_pLineEdit(0) 447 373 , m_pToolButton(0) … … 511 437 } 512 438 439 void 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 513 477 void UIFilterEditor::sltHandleEditorTextChanged(const QString &strText) 514 478 { … … 524 488 void UIFilterEditor::prepare() 525 489 { 490 /* Init the decoration radius: */ 491 m_iRadius = 10; 492 526 493 /* Prepare filter editor: */ 527 m_pLineEdit = new UIFilterLineEdit(this);494 m_pLineEdit = new QILineEdit(this); 528 495 if (m_pLineEdit) 529 496 { 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 }"); 530 504 m_pLineEdit->installEventFilter(this); 531 connect(m_pLineEdit, & UIFilterLineEdit::textChanged,505 connect(m_pLineEdit, &QILineEdit::textChanged, 532 506 this, &UIFilterEditor::sltHandleEditorTextChanged); 533 507 } … … 595 569 const int iY = 0; 596 570 const int iHeight = m_pLineEdit->minimumSizeHint().height(); 571 const QRect oldGeo = m_pLineEdit->geometry(); 597 572 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)); 598 578 } 599 579
Note:
See TracChangeset
for help on using the changeset viewer.

