Skip to content

Commit

Permalink
ENH: Apply Andras' feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Punzo committed Jan 11, 2024
1 parent 1479596 commit 1de3f3f
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 70 deletions.
129 changes: 92 additions & 37 deletions Libs/DICOM/Widgets/ctkDICOMSeriesItemWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
//Qt includes
#include <QDebug>
#include <QIcon>
#include <QGraphicsDropShadowEffect>
#include <QLabel>
#include <QPainter>
#include <QProgressBar>
Expand All @@ -32,6 +33,7 @@

// CTK includes
#include <ctkLogger.h>
#include <ctkPushButton.h>

// ctkDICOMCore includes
#include "ctkDICOMDatabase.h"
Expand Down Expand Up @@ -63,8 +65,10 @@ class ctkDICOMSeriesItemWidgetPrivate: public Ui_ctkDICOMSeriesItemWidget
void drawModalityThumbnail();
void drawThumbnail(const QString& file, int numberOfFrames);
void drawTextWithShadow(QPainter *painter,
const QRect &r,
int flags,
const QFont &font,
const int &x,
const int &y,
const Qt::Alignment &alignment,
const QString &text);
void updateThumbnailProgressBar();

Expand Down Expand Up @@ -131,6 +135,7 @@ void ctkDICOMSeriesItemWidgetPrivate::init()
this->setupUi(q);

this->SeriesThumbnail->setTransformationMode(Qt::TransformationMode::SmoothTransformation);
this->SeriesThumbnail->textPushButton()->setElideMode(Qt::ElideRight);
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -320,15 +325,16 @@ void ctkDICOMSeriesItemWidgetPrivate::createThumbnail(ctkJobDetail td)
//----------------------------------------------------------------------------
void ctkDICOMSeriesItemWidgetPrivate::drawModalityThumbnail()
{
Q_Q(ctkDICOMSeriesItemWidget);
if (!this->DicomDatabase)
{
logger.error("drawThumbnail failed, no DICOM Database has been set. \n");
return;
}

int margin = 10;
int fontSize = 40;
int textSize = 40;
QFont font = this->SeriesThumbnail->font();
font.setBold(true);
font.setPixelSize(textSize);

QPixmap resultPixmap(this->ThumbnailSize, this->ThumbnailSize);
resultPixmap.fill(Qt::transparent);
Expand All @@ -339,15 +345,16 @@ void ctkDICOMSeriesItemWidgetPrivate::drawModalityThumbnail()
QImage thumbnailImage;
QPainter painter;

QColor backgroundColor = q->palette().color(QPalette::Normal, QPalette::Window);
QColor backgroundColor = this->SeriesThumbnail->palette().color(QPalette::Normal, QPalette::Window);
thumbnailGenerator.generateBlankThumbnail(thumbnailImage, backgroundColor);
resultPixmap = QPixmap::fromImage(thumbnailImage);
if (painter.begin(&resultPixmap))
{
painter.setRenderHint(QPainter::Antialiasing);
QRect rect = resultPixmap.rect();
painter.setFont(QFont("Arial", fontSize, QFont::Bold));
this->drawTextWithShadow(&painter, rect.adjusted(margin, margin, margin, margin), Qt::AlignCenter, this->Modality);
int x = int(rect.width() * 0.5);
int y = int(rect.height() * 0.5);
this->drawTextWithShadow(&painter, font, x, y, Qt::AlignCenter, this->Modality);
painter.end();
}

Expand All @@ -357,21 +364,18 @@ void ctkDICOMSeriesItemWidgetPrivate::drawModalityThumbnail()
//----------------------------------------------------------------------------
void ctkDICOMSeriesItemWidgetPrivate::drawThumbnail(const QString &file, int numberOfFrames)
{
Q_Q(ctkDICOMSeriesItemWidget);
if (!this->DicomDatabase)
{
logger.error("drawThumbnail failed, no DICOM Database has been set. \n");
return;
}

int margin = 10;
int fontSize = 12;
if (!this->SeriesThumbnail->text().isEmpty())
{
margin = 5;
fontSize = 14;
}

int margin = 5;
int iconSize = 48;
int textSize = 20;
QFont font = this->SeriesThumbnail->font();
font.setBold(true);
font.setPixelSize(textSize);
QPixmap resultPixmap(this->ThumbnailSize, this->ThumbnailSize);
resultPixmap.fill(Qt::transparent);
ctkDICOMThumbnailGenerator thumbnailGenerator;
Expand All @@ -387,7 +391,7 @@ void ctkDICOMSeriesItemWidgetPrivate::drawThumbnail(const QString &file, int num
thumbnailGenerated = false;
emptyThumbnailGenerated = true;
this->isThumbnailDocument = true;
QColor backgroundColor = q->palette().color(QPalette::Normal, QPalette::Window);
QColor backgroundColor = this->SeriesThumbnail->palette().color(QPalette::Normal, QPalette::Window);
thumbnailGenerator.generateBlankThumbnail(this->ThumbnailImage, backgroundColor);
resultPixmap = QPixmap::fromImage(this->ThumbnailImage);
if (painter.begin(&resultPixmap))
Expand All @@ -406,18 +410,18 @@ void ctkDICOMSeriesItemWidgetPrivate::drawThumbnail(const QString &file, int num
{
painter.setRenderHint(QPainter::Antialiasing);
QRect rect = resultPixmap.rect();
painter.setFont(QFont("Arial", fontSize, QFont::Bold));
int x = int((rect.width() / 2) - (this->ThumbnailImage.rect().width() / 2));
int y = int((rect.height() / 2) - (this->ThumbnailImage.rect().height() / 2));
painter.setFont(font);
int x = int((rect.width() * 0.5) - (this->ThumbnailImage.rect().width() * 0.5));
int y = int((rect.height() * 0.5) - (this->ThumbnailImage.rect().height() * 0.5));
painter.drawPixmap(x, y, QPixmap::fromImage(this->ThumbnailImage));
QString topLeft = ctkDICOMSeriesItemWidget::tr("Series: %1\n%2").arg(this->SeriesNumber).arg(this->Modality);
this->drawTextWithShadow(&painter, rect.adjusted(margin, margin, margin, margin), Qt::AlignTop | Qt::AlignLeft, topLeft);
QString bottomLeft = ctkDICOMSeriesItemWidget::tr("N.frames: %1").arg(numberOfFrames);
this->drawTextWithShadow(&painter, rect.adjusted(margin, -margin, margin, -margin), Qt::AlignBottom | Qt::AlignLeft, bottomLeft);

QString topLeftString = ctkDICOMSeriesItemWidget::tr("Series: %1\n%2").arg(this->SeriesNumber).arg(this->Modality);
this->drawTextWithShadow(&painter, font, margin, margin, Qt::AlignTop | Qt::AlignLeft, topLeftString);
QString rows = this->DicomDatabase->instanceValue(this->CentralFrameSOPInstanceUID, "0028,0010");
QString columns = this->DicomDatabase->instanceValue(this->CentralFrameSOPInstanceUID, "0028,0011");
QString bottomRight = rows + "x" + columns;
this->drawTextWithShadow(&painter, rect.adjusted(-margin, -margin, -margin, -margin), Qt::AlignBottom | Qt::AlignRight, bottomRight);
QString bottomLeftString = rows + "x" + columns + "x" + QString::number(numberOfFrames);
this->drawTextWithShadow(&painter, font, margin, rect.height() - margin,
Qt::AlignBottom | Qt::AlignLeft, bottomLeftString);
QSvgRenderer renderer;

if (this->IsCloud)
Expand All @@ -441,7 +445,7 @@ void ctkDICOMSeriesItemWidgetPrivate::drawThumbnail(const QString &file, int num
}

QPoint topRight = rect.topRight();
QRectF bounds(topRight.x() - 48 - margin, topRight.y() + margin, 48, 48);
QRectF bounds(topRight.x() - iconSize - margin, topRight.y() + margin, iconSize, iconSize);
renderer.render(&painter, bounds);
painter.end();
}
Expand All @@ -455,16 +459,66 @@ void ctkDICOMSeriesItemWidgetPrivate::drawThumbnail(const QString &file, int num

//----------------------------------------------------------------------------
void ctkDICOMSeriesItemWidgetPrivate::drawTextWithShadow(QPainter *painter,
const QRect &r,
int flags, const
QString &text)
const QFont &font,
const int &x,
const int &y,
const Qt::Alignment &alignment,
const QString &text)
{
painter->setPen(Qt::darkGray);
painter->drawText(r.adjusted(1, 1, 1, 1), flags, text);
painter->setPen(QColor(Qt::gray));
painter->drawText(r.adjusted(2, 2, 2, 2), flags, text);
painter->setPen(QPen(QColor(41, 121, 255)));
painter->drawText(r, flags, text);
QColor textColor(60, 164, 255, 225);
QGraphicsDropShadowEffect* dropShadowEffect = new QGraphicsDropShadowEffect;
dropShadowEffect->setXOffset(1);
dropShadowEffect->setYOffset(1);
dropShadowEffect->setBlurRadius(1);
dropShadowEffect->setColor(Qt::gray);
QLabel textLabel;
QPalette palette = textLabel.palette();
palette.setColor(QPalette::WindowText, textColor);
textLabel.setPalette(palette);
textLabel.setFont(font);
textLabel.setGraphicsEffect(dropShadowEffect);
textLabel.setText(text);
QPixmap textPixMap = textLabel.grab();
QRect rect = textPixMap.rect();
int textWidth = rect.width();
int textHeight = rect.height();

if (alignment == Qt::AlignCenter)
{
painter->drawPixmap(x - textWidth * 0.5, y - textHeight * 0.5, textPixMap);
}
else if (alignment == (Qt::AlignTop | Qt::AlignLeft))
{
painter->drawPixmap(x, y, textPixMap);
}
else if (alignment == Qt::AlignTop)
{
painter->drawPixmap(x - textWidth * 0.5, y, textPixMap);
}
else if (alignment == (Qt::AlignTop | Qt::AlignRight))
{
painter->drawPixmap(x - textWidth, y, textPixMap);
}
else if (alignment == (Qt::AlignHCenter | Qt::AlignLeft))
{
painter->drawPixmap(x, y - textHeight * 0.5, textPixMap);
}
else if (alignment == (Qt::AlignHCenter | Qt::AlignRight))
{
painter->drawPixmap(x - textWidth, y - textHeight * 0.5, textPixMap);
}
else if (alignment == (Qt::AlignBottom | Qt::AlignLeft))
{
painter->drawPixmap(x, y - textHeight, textPixMap);
}
else if (alignment == Qt::AlignBottom)
{
painter->drawPixmap(x - textWidth * 0.5, y - textHeight, textPixMap);
}
else if (alignment == (Qt::AlignBottom | Qt::AlignRight))
{
painter->drawPixmap(x - textWidth, y - textHeight, textPixMap);
}
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -600,6 +654,7 @@ void ctkDICOMSeriesItemWidget::setSeriesDescription(const QString& seriesDescrip
{
Q_D(ctkDICOMSeriesItemWidget);
d->SeriesThumbnail->setText(seriesDescription);
d->SeriesThumbnail->textPushButton()->setToolTip(seriesDescription);
}

//------------------------------------------------------------------------------
Expand Down
14 changes: 7 additions & 7 deletions Libs/DICOM/Widgets/ctkDICOMVisualBrowserWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ void ctkDICOMVisualBrowserWidgetPrivate::setBackgroundColorToFilterWidgets(bool
QColor color = Qt::yellow;
if (visualDICOMBrowserColor.lightnessF() < 0.5)
{
color.setRgb(60, 164, 255);;
color.setRgb(60, 164, 255);
}
this->setBackgroundColorToWidget(color, this->FilteringPatientIDSearchBox);
this->setBackgroundColorToWidget(color, this->FilteringPatientNameSearchBox);
Expand Down Expand Up @@ -2514,7 +2514,7 @@ void ctkDICOMVisualBrowserWidget::showPatientContextMenu(const QPoint &point)
QAction *metadataAction = new QAction(metadataString, patientMenu);
patientMenu->addAction(metadataAction);

QString deleteString = tr("Delete patient");
QString deleteString = tr("Delete patient from local database");
QAction *deleteAction = new QAction(deleteString, patientMenu);
patientMenu->addAction(deleteAction);
deleteAction->setVisible(this->isDeleteActionVisible());
Expand Down Expand Up @@ -2607,8 +2607,8 @@ void ctkDICOMVisualBrowserWidget::showStudyContextMenu(const QPoint &point)
QAction *metadataAction = new QAction(metadataString, studyMenu);
studyMenu->addAction(metadataAction);

QString deleteString = numberOfSelectedStudies == 1 ? tr("Delete study") :
tr("Delete %1 studies").arg(numberOfSelectedStudies);
QString deleteString = numberOfSelectedStudies == 1 ? tr("Delete study from local database") :
tr("Delete %1 studies from local database").arg(numberOfSelectedStudies);
QAction *deleteAction = new QAction(deleteString, studyMenu);
studyMenu->addAction(deleteAction);
deleteAction->setVisible(this->isDeleteActionVisible());
Expand Down Expand Up @@ -2708,8 +2708,8 @@ void ctkDICOMVisualBrowserWidget::showSeriesContextMenu(const QPoint &point)
QAction *metadataAction = new QAction(metadataString, seriesMenu);
seriesMenu->addAction(metadataAction);

QString deleteString = numberOfSelectedSeries == 1 ? tr("Delete series") :
tr("Delete %1 series").arg(numberOfSelectedSeries);
QString deleteString = numberOfSelectedSeries == 1 ? tr("Delete series from local database") :
tr("Delete %1 series from local database").arg(numberOfSelectedSeries);
QAction *deleteAction = new QAction(deleteString, seriesMenu);
seriesMenu->addAction(deleteAction);
deleteAction->setVisible(this->isDeleteActionVisible());
Expand Down Expand Up @@ -2783,7 +2783,7 @@ void ctkDICOMVisualBrowserWidget::onPatientsTabMenuToolButtonClicked()
}

patientMenu->addSeparator();
QString deleteString = tr("Delete all Patients");
QString deleteString = tr("Delete all Patients from local database");
QAction *deleteAction = new QAction(deleteString, patientMenu);
deleteAction->setIcon(QIcon(":Icons/delete.svg"));
patientMenu->addAction(deleteAction);
Expand Down
16 changes: 13 additions & 3 deletions Libs/Widgets/Resources/UI/ctkThumbnailLabel.ui
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,24 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="TextLabel">
<property name="alignment">
<set>Qt::AlignCenter</set>
<widget class="ctkPushButton" name="TextPushButton">
<property name="checkable">
<bool>false</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>ctkPushButton</class>
<extends>QPushButton</extends>
<header>ctkPushButton.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
Loading

0 comments on commit 1de3f3f

Please sign in to comment.