mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-09-23 14:15:42 +00:00
Fix a few widgets to properly respond to and use style changes
This commit is contained in:
@@ -108,4 +108,14 @@ void RDLabel::resizeEvent(QResizeEvent *event)
|
||||
setContentsMargins(margin, 0, margin, 0);
|
||||
}
|
||||
}
|
||||
|
||||
QLabel::resizeEvent(event);
|
||||
}
|
||||
|
||||
void RDLabel::changeEvent(QEvent *event)
|
||||
{
|
||||
if(event->type() == QEvent::PaletteChange || event->type() == QEvent::StyleChange)
|
||||
emit styleChanged(event);
|
||||
|
||||
QLabel::changeEvent(event);
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ signals:
|
||||
void doubleClicked(QMouseEvent *event);
|
||||
void mouseMoved(QMouseEvent *event);
|
||||
void leave();
|
||||
void styleChanged(QEvent *event);
|
||||
|
||||
public slots:
|
||||
|
||||
@@ -52,6 +53,7 @@ protected:
|
||||
void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
void leaveEvent(QEvent *event) override;
|
||||
void resizeEvent(QResizeEvent *event) override;
|
||||
void changeEvent(QEvent *event) override;
|
||||
|
||||
bool m_preserveRatio = false;
|
||||
};
|
||||
|
||||
@@ -42,18 +42,20 @@ ResourcePreview::ResourcePreview(ICaptureContext &c, IReplayOutput *output, QWid
|
||||
ui->thumbnail = thumb;
|
||||
ui->gridLayout->addWidget(ui->thumbnail, 0, 0, 1, 2);
|
||||
|
||||
QPalette Pal(ui->slotLabel->palette());
|
||||
setBackgroundRole(QPalette::Background);
|
||||
setForegroundRole(QPalette::Highlight);
|
||||
|
||||
QWidget tmp;
|
||||
|
||||
Pal.setColor(ui->slotLabel->foregroundRole(), tmp.palette().color(QPalette::Foreground));
|
||||
Pal.setColor(ui->slotLabel->backgroundRole(), tmp.palette().color(QPalette::Dark));
|
||||
setSelected(false);
|
||||
|
||||
ui->slotLabel->setPalette(palette());
|
||||
ui->slotLabel->setBackgroundRole(QPalette::Dark);
|
||||
ui->slotLabel->setForegroundRole(QPalette::Foreground);
|
||||
ui->slotLabel->setAutoFillBackground(true);
|
||||
ui->slotLabel->setPalette(Pal);
|
||||
ui->slotLabel->setFont(Formatter::PreferredFont());
|
||||
ui->descriptionLabel->setPalette(palette());
|
||||
ui->descriptionLabel->setAutoFillBackground(true);
|
||||
ui->descriptionLabel->setPalette(Pal);
|
||||
ui->descriptionLabel->setBackgroundRole(QPalette::Dark);
|
||||
ui->descriptionLabel->setForegroundRole(QPalette::Foreground);
|
||||
ui->descriptionLabel->setFont(Formatter::PreferredFont());
|
||||
|
||||
QObject::connect(ui->thumbnail, &CustomPaintWidget::clicked, this, &ResourcePreview::clickEvent);
|
||||
@@ -102,13 +104,21 @@ void ResourcePreview::setSize(QSize s)
|
||||
|
||||
void ResourcePreview::setSelected(bool sel)
|
||||
{
|
||||
m_Selected = sel;
|
||||
|
||||
QPalette Pal(palette());
|
||||
|
||||
Pal.setColor(QPalette::Foreground, sel ? Qt::red : Qt::black);
|
||||
Pal.setColor(QPalette::Highlight, sel ? QColor(Qt::red) : Pal.color(QPalette::Foreground));
|
||||
|
||||
setPalette(Pal);
|
||||
}
|
||||
|
||||
void ResourcePreview::changeEvent(QEvent *event)
|
||||
{
|
||||
if(event->type() == QEvent::PaletteChange || event->type() == QEvent::StyleChange)
|
||||
setSelected(m_Selected);
|
||||
}
|
||||
|
||||
WId ResourcePreview::thumbWinId()
|
||||
{
|
||||
return ui->thumbnail->winId();
|
||||
|
||||
@@ -68,8 +68,12 @@ public:
|
||||
|
||||
void setSelected(bool sel);
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent *event) override;
|
||||
|
||||
private:
|
||||
Ui::ResourcePreview *ui;
|
||||
|
||||
bool m_Active;
|
||||
bool m_Selected = false;
|
||||
};
|
||||
|
||||
@@ -68,22 +68,29 @@ void CaptureDialog::initWarning(RDLabel *warning)
|
||||
if(warning->devicePixelRatio() >= 2)
|
||||
warning->setText(warning->text().replace(lit(".png"), lit("@2x.png")));
|
||||
|
||||
QPalette pal = warning->palette();
|
||||
auto calcPaletteFromStyle = [warning](QEvent *) {
|
||||
QPalette pal = warning->palette();
|
||||
|
||||
QColor base = pal.color(QPalette::ToolTipBase);
|
||||
QColor base = pal.color(QPalette::ToolTipBase);
|
||||
|
||||
pal.setColor(QPalette::Foreground, pal.color(QPalette::ToolTipText));
|
||||
pal.setColor(QPalette::Window, base);
|
||||
pal.setColor(QPalette::Base, base.darker(120));
|
||||
pal.setColor(QPalette::Foreground, pal.color(QPalette::ToolTipText));
|
||||
pal.setColor(QPalette::Window, base);
|
||||
pal.setColor(QPalette::Base, base.darker(120));
|
||||
|
||||
warning->setPalette(pal);
|
||||
};
|
||||
|
||||
calcPaletteFromStyle(NULL);
|
||||
|
||||
warning->setBackgroundRole(QPalette::Window);
|
||||
warning->setForegroundRole(QPalette::Foreground);
|
||||
|
||||
QObject::connect(warning, &RDLabel::mouseMoved,
|
||||
[this, warning](QMouseEvent *) { warning->setBackgroundRole(QPalette::Base); });
|
||||
[warning](QMouseEvent *) { warning->setBackgroundRole(QPalette::Base); });
|
||||
QObject::connect(warning, &RDLabel::leave,
|
||||
[this, warning]() { warning->setBackgroundRole(QPalette::Window); });
|
||||
[warning]() { warning->setBackgroundRole(QPalette::Window); });
|
||||
QObject::connect(warning, &RDLabel::styleChanged, calcPaletteFromStyle);
|
||||
|
||||
warning->setPalette(pal);
|
||||
warning->setAutoFillBackground(true);
|
||||
warning->setMouseTracking(true);
|
||||
warning->setVisible(false);
|
||||
|
||||
Reference in New Issue
Block a user