Skip to content

Commit

Permalink
ENH: Improve study widget layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Punzo committed Jun 4, 2024
1 parent 5255c53 commit c5b7fff
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions Libs/DICOM/Widgets/ctkDICOMStudyItemWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,34 +507,33 @@ void ctkDICOMStudyItemWidget::setDescription(const QString& description)
if (description.isEmpty())
{
d->StudyDescriptionTextBrowser->hide();
return;
}
else

QFontMetrics metrics(d->StudyDescriptionTextBrowser->font());
int textWidth = metrics.horizontalAdvance(description);
int widgetWidth = this->width();
if (textWidth > widgetWidth)
{
QFontMetrics metrics(d->StudyDescriptionTextBrowser->font());
int textWidth = metrics.horizontalAdvance(description);
int widgetWidth = this->width();
if (textWidth > widgetWidth)
int length = 0;
while (length < description.length() && metrics.horizontalAdvance(description.mid(0, length)) <= widgetWidth)
{
int length = 0;
while (length < description.length() && metrics.horizontalAdvance(description.mid(0, length)) <= widgetWidth)
{
length++;
}

QString wrappedText = description;
if (length < description.length())
{
wrappedText.insert(length, "\n");
}
d->StudyDescriptionTextBrowser->setCollapsibleText(wrappedText);
length++;
}
else

QString wrappedText = description;
if (length < description.length())
{
d->StudyDescriptionTextBrowser->setPlainText(description);
wrappedText.insert(length, "\n");
}

d->StudyDescriptionTextBrowser->show();
d->StudyDescriptionTextBrowser->setCollapsibleText(wrappedText);
}
else
{
d->StudyDescriptionTextBrowser->setPlainText(description);
}

d->StudyDescriptionTextBrowser->show();
}

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

0 comments on commit c5b7fff

Please sign in to comment.