Skip to content

Commit

Permalink
BUG: Fix colors for the settings in dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Punzo committed Apr 22, 2024
1 parent 9d8ad8e commit fd00c93
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 54 deletions.
1 change: 0 additions & 1 deletion Libs/DICOM/Widgets/ctkDICOMPatientItemWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,6 @@ void ctkDICOMPatientItemWidget::generateStudies(bool queryRetrieve)
d->createStudies(queryRetrieve);
if (queryRetrieve && d->Scheduler && d->Scheduler->queryRetrieveServersCount() > 0)
{
qDebug()<< "bellaaaaaaaaaaaaaaaaa2 : "<<d->AllowedServers;
d->Scheduler->queryStudies(d->PatientID,
QThread::NormalPriority,
d->AllowedServers);
Expand Down
73 changes: 54 additions & 19 deletions Libs/DICOM/Widgets/ctkDICOMServerNodeWidget2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -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();
Expand All @@ -950,14 +953,33 @@ 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)
{
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)
Expand Down Expand Up @@ -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<QLineEdit*>(d->NodeTable->cellWidget(row, ctkDICOMServerNodeWidget2::VerificationColumn));
Expand All @@ -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);
}

Expand Down
51 changes: 17 additions & 34 deletions Libs/DICOM/Widgets/ctkDICOMVisualBrowserWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -781,7 +783,6 @@ void ctkDICOMVisualBrowserWidgetPrivate::resetFilters()
//----------------------------------------------------------------------------
void ctkDICOMVisualBrowserWidgetPrivate::updateFiltersWarnings()
{
Q_Q(ctkDICOMVisualBrowserWidget);
if (!this->DicomDatabase)
{
logger.error("updateFiltersWarnings failed, no DICOM database has been set. \n");
Expand All @@ -792,13 +793,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)
{
Expand Down Expand Up @@ -859,13 +854,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);
Expand All @@ -874,27 +878,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);
}
}

//----------------------------------------------------------------------------
Expand Down

0 comments on commit fd00c93

Please sign in to comment.