[Gui] Make styles update on paint (#17376)
* [Gui] Make styles update on paint Fixes #15756. Similar implementation to that already in FileCardDelegate.cpp * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
1cf5b23927
commit
954bae725e
@@ -80,7 +80,6 @@
|
||||
</FCParamGroup>
|
||||
<FCParamGroup Name="Mod">
|
||||
<FCParamGroup Name="Start">
|
||||
<FCBool Name="FileCardUseStyleSheet" Value="0"/>
|
||||
<FCInt Name="FileThumbnailIconsSize" Value="128"/>
|
||||
<FCUInt Name="FileThumbnailBorderColor" Value="1654713087"/>
|
||||
<FCUInt Name="FileThumbnailBackgroundColor" Value="3554532863"/>
|
||||
|
||||
@@ -92,7 +92,6 @@
|
||||
</FCParamGroup>
|
||||
<FCParamGroup Name="Mod">
|
||||
<FCParamGroup Name="Start">
|
||||
<FCBool Name="FileCardUseStyleSheet" Value="0"/>
|
||||
</FCParamGroup>
|
||||
<FCParamGroup Name="Arch">
|
||||
<FCUInt Name="WallColor" Value="3604403967"/>
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
</FCParamGroup>
|
||||
<FCParamGroup Name="Mod">
|
||||
<FCParamGroup Name="Start">
|
||||
<FCBool Name="FileCardUseStyleSheet" Value="0"/>
|
||||
</FCParamGroup>
|
||||
<FCParamGroup Name="Arch">
|
||||
<FCUInt Name="WallColor" Value="2914369023"/>
|
||||
|
||||
@@ -112,46 +112,50 @@ void FileCardDelegate::paint(QPainter* painter,
|
||||
thumbnail->setFixedSize(thumbnailSize, thumbnailSize);
|
||||
thumbnail->setSizePolicy(QSizePolicy::Policy::Fixed, QSizePolicy::Policy::Fixed);
|
||||
|
||||
QString style = QStringLiteral("");
|
||||
|
||||
_widget->setProperty("state", QStringLiteral(""));
|
||||
if (option.state & QStyle::State_Selected) {
|
||||
_widget->setProperty("state", QStringLiteral("pressed"));
|
||||
if (qApp->styleSheet().isEmpty()) {
|
||||
QColor color = getSelectionColor();
|
||||
_widget->setStyleSheet(QString::fromLatin1("QWidget#thumbnailWidget {"
|
||||
" border: 2px solid rgb(%1, %2, %3);"
|
||||
" border-radius: 4px;"
|
||||
" padding: 2px;"
|
||||
"}")
|
||||
.arg(color.red())
|
||||
.arg(color.green())
|
||||
.arg(color.blue()));
|
||||
style = QString::fromLatin1("QWidget#thumbnailWidget {"
|
||||
" border: 2px solid rgb(%1, %2, %3);"
|
||||
" border-radius: 4px;"
|
||||
" padding: 2px;"
|
||||
"}")
|
||||
.arg(color.red())
|
||||
.arg(color.green())
|
||||
.arg(color.blue());
|
||||
}
|
||||
}
|
||||
else if (option.state & QStyle::State_MouseOver) {
|
||||
_widget->setProperty("state", QStringLiteral("hovered"));
|
||||
if (qApp->styleSheet().isEmpty()) {
|
||||
QColor color = getBorderColor();
|
||||
_widget->setStyleSheet(QString::fromLatin1("QWidget#thumbnailWidget {"
|
||||
" border: 2px solid rgb(%1, %2, %3);"
|
||||
" border-radius: 4px;"
|
||||
" padding: 2px;"
|
||||
"}")
|
||||
.arg(color.red())
|
||||
.arg(color.green())
|
||||
.arg(color.blue()));
|
||||
style = QString::fromLatin1("QWidget#thumbnailWidget {"
|
||||
" border: 2px solid rgb(%1, %2, %3);"
|
||||
" border-radius: 4px;"
|
||||
" padding: 2px;"
|
||||
"}")
|
||||
.arg(color.red())
|
||||
.arg(color.green())
|
||||
.arg(color.blue());
|
||||
}
|
||||
}
|
||||
else if (qApp->styleSheet().isEmpty()) {
|
||||
QColor color = getBackgroundColor();
|
||||
_widget->setStyleSheet(QString::fromLatin1("QWidget#thumbnailWidget {"
|
||||
" background-color: rgb(%1, %2, %3);"
|
||||
" border-radius: 8px;"
|
||||
"}")
|
||||
.arg(color.red())
|
||||
.arg(color.green())
|
||||
.arg(color.blue()));
|
||||
style = QString::fromLatin1("QWidget#thumbnailWidget {"
|
||||
" background-color: rgb(%1, %2, %3);"
|
||||
" border-radius: 8px;"
|
||||
"}")
|
||||
.arg(color.red())
|
||||
.arg(color.green())
|
||||
.arg(color.blue());
|
||||
}
|
||||
|
||||
_widget->setStyleSheet(style);
|
||||
|
||||
auto elided =
|
||||
painter->fontMetrics().elidedText(baseName, Qt::TextElideMode::ElideRight, cardWidth);
|
||||
auto name = std::make_unique<QLabel>(elided);
|
||||
|
||||
@@ -230,18 +230,6 @@ void StartView::configureNewFileButtons(QLayout* layout) const
|
||||
tr("Create an architectural project"),
|
||||
QLatin1String(":/icons/BIMWorkbench.svg")});
|
||||
|
||||
auto hGrp = App::GetApplication().GetParameterGroupByPath(
|
||||
"User parameter:BaseApp/Preferences/Mod/Start");
|
||||
if (hGrp->GetBool("FileCardUseStyleSheet", true)) {
|
||||
QString style = fileCardStyle();
|
||||
newEmptyFile->setStyleSheet(style);
|
||||
openFile->setStyleSheet(style);
|
||||
partDesign->setStyleSheet(style);
|
||||
assembly->setStyleSheet(style);
|
||||
draft->setStyleSheet(style);
|
||||
arch->setStyleSheet(style);
|
||||
}
|
||||
|
||||
// TODO: Ensure all of the required WBs are actually available
|
||||
layout->addWidget(partDesign);
|
||||
layout->addWidget(assembly);
|
||||
@@ -258,6 +246,17 @@ void StartView::configureNewFileButtons(QLayout* layout) const
|
||||
connect(arch, &QPushButton::clicked, this, &StartView::newArchFile);
|
||||
}
|
||||
|
||||
void StartView::paintEvent(QPaintEvent* event)
|
||||
{
|
||||
QString style = QStringLiteral("");
|
||||
if (qApp->styleSheet().isEmpty()) {
|
||||
style = fileCardStyle();
|
||||
}
|
||||
setStyleSheet(style);
|
||||
|
||||
Gui::MDIView::paintEvent(event);
|
||||
}
|
||||
|
||||
QString StartView::fileCardStyle() const
|
||||
{
|
||||
if (!qApp->styleSheet().isEmpty()) {
|
||||
|
||||
@@ -96,6 +96,8 @@ protected:
|
||||
|
||||
QString fileCardStyle() const;
|
||||
|
||||
void paintEvent(QPaintEvent* event) override;
|
||||
|
||||
private:
|
||||
void retranslateUi();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user