From 4608d2cb04acb543d4d875616cf9a037bab14b82 Mon Sep 17 00:00:00 2001 From: Davide Punzo Date: Mon, 22 Apr 2024 14:16:20 +0200 Subject: [PATCH] BUG: Fix colors for the settings in dark mode --- .../Widgets/ctkDICOMPatientItemWidget.cpp | 1 - .../Widgets/ctkDICOMServerNodeWidget2.cpp | 73 ++++++++++++++----- .../Widgets/ctkDICOMVisualBrowserWidget.cpp | 49 +++++-------- 3 files changed, 71 insertions(+), 52 deletions(-) diff --git a/Libs/DICOM/Widgets/ctkDICOMPatientItemWidget.cpp b/Libs/DICOM/Widgets/ctkDICOMPatientItemWidget.cpp index f92627c52e..862189d315 100644 --- a/Libs/DICOM/Widgets/ctkDICOMPatientItemWidget.cpp +++ b/Libs/DICOM/Widgets/ctkDICOMPatientItemWidget.cpp @@ -837,7 +837,6 @@ void ctkDICOMPatientItemWidget::generateStudies(bool queryRetrieve) d->createStudies(queryRetrieve); if (queryRetrieve && d->Scheduler && d->Scheduler->queryRetrieveServersCount() > 0) { - qDebug()<< "bellaaaaaaaaaaaaaaaaa2 : "<AllowedServers; d->Scheduler->queryStudies(d->PatientID, QThread::NormalPriority, d->AllowedServers); diff --git a/Libs/DICOM/Widgets/ctkDICOMServerNodeWidget2.cpp b/Libs/DICOM/Widgets/ctkDICOMServerNodeWidget2.cpp index 59a64a738f..7a5bc3b24e 100644 --- a/Libs/DICOM/Widgets/ctkDICOMServerNodeWidget2.cpp +++ b/Libs/DICOM/Widgets/ctkDICOMServerNodeWidget2.cpp @@ -55,11 +55,12 @@ #include "ui_ctkDICOMServerNodeWidget2.h" static ctkLogger logger("org.commontk.DICOM.Widgets.DICOMServerNodeWidget2"); -Qt::GlobalColor defaultColor = Qt::white; -Qt::GlobalColor modifiedColor = Qt::darkYellow; -Qt::GlobalColor serverSuccesColor = Qt::darkGreen; -Qt::GlobalColor serverProgressColor = Qt::darkCyan; -Qt::GlobalColor serverFailedColor = Qt::darkRed; +QColor ctkDICOMServerNodeWidget2DefaultColor(Qt::white); +QColor ctkDICOMServerNodeWidget2DarkModectkDICOMServerNodeWidget2DefaultColor(50, 50, 50); +QColor ctkDICOMServerNodeWidget2ModifiedColor(Qt::darkYellow); +QColor ctkDICOMServerNodeWidget2ServerSuccesColor(Qt::darkGreen); +QColor ctkDICOMServerNodeWidget2ServerProgressColor(Qt::darkCyan); +QColor ctkDICOMServerNodeWidget2ServerFailedColor(Qt::darkRed); class QSelectionColorStyledItemDelegate : public QStyledItemDelegate { @@ -77,7 +78,7 @@ class QSelectionColorStyledItemDelegate : public QStyledItemDelegate } QTableWidgetItem* item = table->item(index.row(), index.column()); - if (!item || item->background() == defaultColor) + if (!item || item->background() == ctkDICOMServerNodeWidget2DefaultColor || item->background() == ctkDICOMServerNodeWidget2DarkModectkDICOMServerNodeWidget2DefaultColor) { return; } @@ -103,7 +104,7 @@ class QCheckStateStyledItemDelegate : public QStyledItemDelegate } QTableWidgetItem* item = table->item(index.row(), index.column()); - if (!item || item->background() == defaultColor) + if (!item || item->background() == ctkDICOMServerNodeWidget2DefaultColor || item->background() == ctkDICOMServerNodeWidget2DarkModectkDICOMServerNodeWidget2DefaultColor) { return; } @@ -293,16 +294,16 @@ ctkDICOMServerNodeWidget2Private::ctkDICOMServerNodeWidget2Private(ctkDICOMServe this->Scheduler = nullptr; this->CancelButton = nullptr; this->SaveButton = nullptr; - this->DefaultPalette.setColor(QPalette::Button, defaultColor); - this->DefaultPalette.setColor(QPalette::Base, defaultColor); - this->ModifiedPalette.setColor(QPalette::Button, modifiedColor); - this->ModifiedPalette.setColor(QPalette::Base, modifiedColor); - this->ServerSuccesPalette.setColor(QPalette::Button, serverSuccesColor); - this->ServerSuccesPalette.setColor(QPalette::Base, serverSuccesColor); - this->ServerProgresPalette.setColor(QPalette::Button, serverProgressColor); - this->ServerProgresPalette.setColor(QPalette::Base, serverProgressColor); - this->ServerFailedPalette.setColor(QPalette::Button, serverFailedColor); - this->ServerFailedPalette.setColor(QPalette::Base, serverFailedColor); + this->DefaultPalette.setColor(QPalette::Button, ctkDICOMServerNodeWidget2DefaultColor); + this->DefaultPalette.setColor(QPalette::Base, ctkDICOMServerNodeWidget2DefaultColor); + this->ModifiedPalette.setColor(QPalette::Button, ctkDICOMServerNodeWidget2ModifiedColor); + this->ModifiedPalette.setColor(QPalette::Base, ctkDICOMServerNodeWidget2ModifiedColor); + this->ServerSuccesPalette.setColor(QPalette::Button, ctkDICOMServerNodeWidget2ServerSuccesColor); + this->ServerSuccesPalette.setColor(QPalette::Base, ctkDICOMServerNodeWidget2ServerSuccesColor); + this->ServerProgresPalette.setColor(QPalette::Button, ctkDICOMServerNodeWidget2ServerProgressColor); + this->ServerProgresPalette.setColor(QPalette::Base, ctkDICOMServerNodeWidget2ServerProgressColor); + this->ServerFailedPalette.setColor(QPalette::Button, ctkDICOMServerNodeWidget2ServerFailedColor); + this->ServerFailedPalette.setColor(QPalette::Base, ctkDICOMServerNodeWidget2ServerFailedColor); } //---------------------------------------------------------------------------- @@ -927,6 +928,8 @@ void ctkDICOMServerNodeWidget2Private::restoreFocus(QModelIndexList selectedInde int verticalScrollBarValue, bool resetServerStatus) { + Q_Q(ctkDICOMServerNodeWidget2); + bool wasBlocked = this->NodeTable->blockSignals(true); int rowCount = this->NodeTable->rowCount(); int columnCount = this->NodeTable->columnCount(); @@ -950,6 +953,18 @@ void ctkDICOMServerNodeWidget2Private::restoreFocus(QModelIndexList selectedInde lineEdit->clearFocus(); } + QColor serverNodeWidgetColor = q->palette().color(QPalette::Normal, q->backgroundRole()); + if (serverNodeWidgetColor.lightnessF() < 0.5) + { + this->DefaultPalette.setColor(QPalette::Button, ctkDICOMServerNodeWidget2DarkModectkDICOMServerNodeWidget2DefaultColor); + this->DefaultPalette.setColor(QPalette::Base, ctkDICOMServerNodeWidget2DarkModectkDICOMServerNodeWidget2DefaultColor); + } + else + { + this->DefaultPalette.setColor(QPalette::Button, ctkDICOMServerNodeWidget2DefaultColor); + this->DefaultPalette.setColor(QPalette::Base, ctkDICOMServerNodeWidget2DefaultColor); + } + for (int row = 0; row < rowCount; ++row) { for (int column = 0; column < columnCount; ++column) @@ -957,7 +972,14 @@ void ctkDICOMServerNodeWidget2Private::restoreFocus(QModelIndexList selectedInde QTableWidgetItem *item = this->NodeTable->item(row, column); if (item) { - item->setBackground(defaultColor); + if (serverNodeWidgetColor.lightnessF() < 0.5) + { + item->setBackground(ctkDICOMServerNodeWidget2DarkModectkDICOMServerNodeWidget2DefaultColor); + } + else + { + item->setBackground(ctkDICOMServerNodeWidget2DefaultColor); + } } if (column == ctkDICOMServerNodeWidget2::VerificationColumn && !resetServerStatus) @@ -1261,7 +1283,7 @@ void ctkDICOMServerNodeWidget2::onCellSettingsModified(int row, int column) QTableWidgetItem *item = d->NodeTable->item(row, column); if (item) { - item->setBackground(modifiedColor); + item->setBackground(ctkDICOMServerNodeWidget2ModifiedColor); } QLineEdit* lineEdit = qobject_cast(d->NodeTable->cellWidget(row, ctkDICOMServerNodeWidget2::VerificationColumn)); @@ -1270,6 +1292,19 @@ void ctkDICOMServerNodeWidget2::onCellSettingsModified(int row, int column) lineEdit->setReadOnly(false); lineEdit->setText(ctkDICOMServerNodeWidget2::tr("unknown")); lineEdit->setReadOnly(true); + + QColor serverNodeWidgetColor = this->palette().color(QPalette::Normal, this->backgroundRole()); + if (serverNodeWidgetColor.lightnessF() < 0.5) + { + d->DefaultPalette.setColor(QPalette::Button, ctkDICOMServerNodeWidget2DarkModectkDICOMServerNodeWidget2DefaultColor); + d->DefaultPalette.setColor(QPalette::Base, ctkDICOMServerNodeWidget2DarkModectkDICOMServerNodeWidget2DefaultColor); + } + else + { + d->DefaultPalette.setColor(QPalette::Button, ctkDICOMServerNodeWidget2DefaultColor); + d->DefaultPalette.setColor(QPalette::Base, ctkDICOMServerNodeWidget2DefaultColor); + } + lineEdit->setPalette(d->DefaultPalette); } diff --git a/Libs/DICOM/Widgets/ctkDICOMVisualBrowserWidget.cpp b/Libs/DICOM/Widgets/ctkDICOMVisualBrowserWidget.cpp index f6cf91a602..7636a7a21d 100644 --- a/Libs/DICOM/Widgets/ctkDICOMVisualBrowserWidget.cpp +++ b/Libs/DICOM/Widgets/ctkDICOMVisualBrowserWidget.cpp @@ -61,8 +61,10 @@ #include "ui_ctkDICOMVisualBrowserWidget.h" static ctkLogger logger("org.commontk.DICOM.Widgets.DICOMVisualBrowserWidget"); -Qt::GlobalColor warningColor = Qt::yellow; -QColor warningColorDarkMode = QColor(60, 164, 255); + +QColor ctkDICOMVisualBrowserWidgetDefaultColor(Qt::white); +QColor ctkDICOMVisualBrowserWidgetDarkModeDefaultColor(50, 50, 50); +QColor ctkDICOMVisualBrowserWidgetWarningColor(Qt::darkYellow); class ctkDICOMMetadataDialog : public QDialog { @@ -792,12 +794,7 @@ void ctkDICOMVisualBrowserWidgetPrivate::updateFiltersWarnings() // If there are no series, highlight which are the filters that produce no results this->setBackgroundColorToFilterWidgets(); - QColor visualDICOMBrowserColor = q->palette().color(QPalette::Normal, q->backgroundRole()); - QColor color = warningColor; - if (visualDICOMBrowserColor.lightnessF() < 0.5) - { - color = warningColorDarkMode; - } + QColor color = ctkDICOMVisualBrowserWidgetWarningColor; QStringList patientList = this->DicomDatabase->patients(); if (patientList.count() == 0) @@ -859,13 +856,22 @@ void ctkDICOMVisualBrowserWidgetPrivate::updateFiltersWarnings() void ctkDICOMVisualBrowserWidgetPrivate::setBackgroundColorToFilterWidgets(bool warning) { Q_Q(ctkDICOMVisualBrowserWidget); - QColor visualDICOMBrowserColor = q->palette().color(QPalette::Normal, q->backgroundRole()); if (warning) { - QColor color = Qt::yellow; + this->setBackgroundColorToWidget(ctkDICOMVisualBrowserWidgetWarningColor, this->FilteringPatientIDSearchBox); + this->setBackgroundColorToWidget(ctkDICOMVisualBrowserWidgetWarningColor, this->FilteringPatientNameSearchBox); + this->setBackgroundColorToWidget(ctkDICOMVisualBrowserWidgetWarningColor, this->FilteringDateComboBox); + this->setBackgroundColorToWidget(ctkDICOMVisualBrowserWidgetWarningColor, this->FilteringStudyDescriptionSearchBox); + this->setBackgroundColorToWidget(ctkDICOMVisualBrowserWidgetWarningColor, this->FilteringSeriesDescriptionSearchBox); + this->setBackgroundColorToWidget(ctkDICOMVisualBrowserWidgetWarningColor, this->FilteringModalityCheckableComboBox); + } + else + { + QColor color(ctkDICOMVisualBrowserWidgetDefaultColor); + QColor visualDICOMBrowserColor = q->palette().color(QPalette::Normal, q->backgroundRole()); if (visualDICOMBrowserColor.lightnessF() < 0.5) { - color.setRgb(60, 164, 255); + color = ctkDICOMVisualBrowserWidgetDarkModeDefaultColor; } this->setBackgroundColorToWidget(color, this->FilteringPatientIDSearchBox); this->setBackgroundColorToWidget(color, this->FilteringPatientNameSearchBox); @@ -874,27 +880,6 @@ void ctkDICOMVisualBrowserWidgetPrivate::setBackgroundColorToFilterWidgets(bool this->setBackgroundColorToWidget(color, this->FilteringSeriesDescriptionSearchBox); this->setBackgroundColorToWidget(color, this->FilteringModalityCheckableComboBox); } - else - { - QColor colorSearchBox(255, 255, 255); - QColor colorButton(239, 239, 239); - if (visualDICOMBrowserColor.lightnessF() < 0.5) - { - colorSearchBox.setRgb(30, 30, 30); - colorButton.setRgb(50, 50, 50); - } - else if (visualDICOMBrowserColor.lightnessF() > 0.95) - { - colorSearchBox.setRgb(255, 255, 255); - colorButton.setRgb(255, 255, 255); - } - this->setBackgroundColorToWidget(colorSearchBox, this->FilteringPatientIDSearchBox); - this->setBackgroundColorToWidget(colorSearchBox, this->FilteringPatientNameSearchBox); - this->setBackgroundColorToWidget(colorButton, this->FilteringDateComboBox); - this->setBackgroundColorToWidget(colorSearchBox, this->FilteringStudyDescriptionSearchBox); - this->setBackgroundColorToWidget(colorSearchBox, this->FilteringSeriesDescriptionSearchBox); - this->setBackgroundColorToWidget(colorButton, this->FilteringModalityCheckableComboBox); - } } //----------------------------------------------------------------------------