Skip to content

Commit

Permalink
fix: [session] Optimized the display of session name
Browse files Browse the repository at this point in the history
  • Loading branch information
Kakueeen committed Jan 6, 2025
1 parent 645bb7a commit 3fae8ec
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/plugins/core/session/sessionmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ QVariant SessionModel::data(const QModelIndex &index, int role) const

const auto &sessionName = sessionList.at(index.row());
switch (role) {
case Qt::ToolTipRole:
case Qt::DisplayRole:
switch (index.column()) {
case 0:
Expand Down
26 changes: 24 additions & 2 deletions src/plugins/recent/mainframe/sessionitemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,25 @@ void ArrowHeaderLine::setExpand(bool value)

void ArrowHeaderLine::setTitle(const QString &title)
{
titleLabel->setText(title);
titleText = title;
updateTitle();
}

QString ArrowHeaderLine::title() const
{
return titleLabel->text();
return titleText;
}

void ArrowHeaderLine::setTitleTip(const QString &tooltip)
{
titleLabel->setToolTip(tooltip);
}

void ArrowHeaderLine::resizeEvent(QResizeEvent *e)
{
updateTitle();

return QWidget::resizeEvent(e);
}

void ArrowHeaderLine::changeEvent(QEvent *e)
Expand Down Expand Up @@ -110,6 +123,13 @@ void ArrowHeaderLine::reverseArrowDirection()
setExpand(!isExpanded);
}

void ArrowHeaderLine::updateTitle()
{
QFontMetrics fm = titleLabel->fontMetrics();
auto displayText = fm.elidedText(titleText, Qt::ElideRight, titleLabel->width());
titleLabel->setText(displayText);
}

class SessionItemWidgetPrivate : public QObject
{
public:
Expand Down Expand Up @@ -307,6 +327,7 @@ void SessionItemWidgetPrivate::runInputDialog(const QString &title, const QStrin
dlg.getButton(2)->setEnabled(!text.isEmpty());
});
dlg.addContent(lineEdit);
dlg.setFocusProxy(lineEdit);

dlg.addButton(SessionItemWidget::tr("Cancel", "button"));
dlg.addButton(actList[0]);
Expand Down Expand Up @@ -391,6 +412,7 @@ void SessionItemWidget::updateSession()
if (isCurrentSession && !isDefaultVirgin)
title = tr("%1 (current session)").arg(title);
d->headerLine->setTitle(title);
d->headerLine->setTitleTip(d->sessionName);

const auto &sessionCfg = d->sessionSrv->sessionFile(d->sessionName);
if (!QFile::exists(sessionCfg))
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/recent/mainframe/sessionitemwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,23 @@ class ArrowHeaderLine : public QWidget
void setExpand(bool value);
void setTitle(const QString &title);
QString title() const;
void setTitleTip(const QString &tooltip);

Q_SIGNALS:
void expandChanged();
void itemClicked();

protected:
void resizeEvent(QResizeEvent *e) override;
void changeEvent(QEvent *e) override;
bool eventFilter(QObject *obj, QEvent *e) override;

private:
void reverseArrowDirection();
void updateTitle();

bool isExpanded { false };
QString titleText;
DTK_WIDGET_NAMESPACE::DToolButton *arrowButton { nullptr };
DTK_WIDGET_NAMESPACE::DLabel *titleLabel { nullptr };
};
Expand Down

0 comments on commit 3fae8ec

Please sign in to comment.