Skip to content

Commit

Permalink
Work with tabs. Make long tab tooltip multiline
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitozz committed May 7, 2024
1 parent b7e5e39 commit 3dae580
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/widgets/psitabwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,32 @@ void PsiTabWidget::setTabText(QWidget *widget, const QString &label)
{
int index = widgets_.indexOf(widget);
if (index != -1) {
QString shortLabel = label;
if (label.length() > 40) {
auto shortLabel = label;
auto labelSize = label.size();
if (labelSize > 40) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
shortLabel = label.left(37) + "...";
tabBar_->setTabToolTip(index, label);
#else
shortLabel = label.first(37) + "...";
#endif
int maxLength = 80;
// If label text is longer than 80 symbols then make lable multiline
if (labelSize > maxLength) {
QStringList sentences;
for (int i = 0; i < labelSize;) {
if (i + maxLength < labelSize) {
auto lastSpace = QStringView { label }.mid(i, maxLength).lastIndexOf(QString(" ")) + 1;
sentences << label.mid(i, lastSpace);
i += lastSpace;
} else {
sentences << label.mid(i, labelSize - i);
break;
}
}
tabBar_->setTabToolTip(index, sentences.join("\n"));
} else {
tabBar_->setTabToolTip(index, label);
}
}
tabBar_->setTabText(index, shortLabel);
}
Expand Down

0 comments on commit 3dae580

Please sign in to comment.