Skip to content

Commit

Permalink
Improving Diff view when large descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
francescmm committed Feb 1, 2021
1 parent 47fea9e commit 43acb84
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
12 changes: 12 additions & 0 deletions src/aux_widgets/CommitInfoPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CommitInfoPanel::CommitInfoPanel(QWidget *parent)
mScrollArea = new QScrollArea();
mScrollArea->setWidget(mLabelDescription);
mScrollArea->setWidgetResizable(true);
mScrollArea->setFixedHeight(50);

mLabelAuthor->setObjectName("labelAuthor");

Expand Down Expand Up @@ -64,6 +65,17 @@ void CommitInfoPanel::configure(const CommitInfo &commit)
const auto description = commit.longLog();
mLabelDescription->setText(description.isEmpty() ? "<No description provided>" : description);

QFontMetrics fm(mLabelDescription->font());
const auto neededsize = fm.boundingRect(QRect(0, 0, 300, 250), Qt::TextWordWrap, mLabelDescription->text());
auto height = neededsize.height();

if (height > 250)
height = 250;
else if (height < 50)
height = 50;

mScrollArea->setFixedHeight(height);

auto f = mLabelDescription->font();
f.setItalic(description.isEmpty());
mLabelDescription->setFont(f);
Expand Down
1 change: 1 addition & 0 deletions src/big_widgets/DiffWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ DiffWidget::DiffWidget(const QSharedPointer<GitBase> git, QSharedPointer<GitCach
setAttribute(Qt::WA_DeleteOnClose);

mInfoPanelParent->setObjectName("InfoPanel");
mInfoPanelParent->setFixedWidth(350);

mCenterStackedWidget->setCurrentIndex(0);
mCenterStackedWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
Expand Down
6 changes: 3 additions & 3 deletions src/big_widgets/HistoryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ HistoryWidget::HistoryWidget(const QSharedPointer<GitCache> &cache, const QShare
, mGit(git)
, mCache(cache)
, mGitServerCache(gitServerCache)
, mWipWidget(new WipWidget(mCache, mGit))
, mAmendWidget(new AmendWidget(mCache, mGit))
, mCommitInfoWidget(new CommitInfoWidget(mCache, mGit))
, mReturnFromFull(new QPushButton())
, mUserName(new QLabel())
, mUserEmail(new QLabel())
{
mCommitInfoWidget = new CommitInfoWidget(mCache, mGit);
mWipWidget = new WipWidget(mCache, mGit);
mAmendWidget = new AmendWidget(mCache, mGit);
setAttribute(Qt::WA_DeleteOnClose);

QScopedPointer<GitConfig> gitConfig(new GitConfig(mGit));
Expand Down
31 changes: 17 additions & 14 deletions src/commits/CommitInfoWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,29 @@ CommitInfoWidget::CommitInfoWidget(const QSharedPointer<GitCache> &cache, const
, mCache(cache)
, mGit(git)
, mInfoPanel(new CommitInfoPanel())
, fileListWidget(new FileListWidget(mGit, mCache))
, mFileListWidget(new FileListWidget(mGit, mCache))
{
setAttribute(Qt::WA_DeleteOnClose);

fileListWidget->setObjectName("fileListWidget");
mFileListWidget->setObjectName("fileListWidget");

const auto wipSeparator = new QFrame();
wipSeparator->setObjectName("separator");

const auto verticalLayout = new QVBoxLayout(this);
verticalLayout->setSpacing(0);
verticalLayout->setContentsMargins(0, 0, 0, 0);
verticalLayout->addWidget(mInfoPanel);
verticalLayout->addWidget(wipSeparator);
verticalLayout->addWidget(fileListWidget);

connect(fileListWidget, &FileListWidget::itemDoubleClicked, this,
const auto mainLayout = new QGridLayout(this);
mainLayout->setSpacing(0);
mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->addWidget(mInfoPanel, 0, 0);
mainLayout->addWidget(wipSeparator, 1, 0);
mainLayout->addWidget(mFileListWidget, 2, 0);
mainLayout->setRowStretch(1, 0);
mainLayout->setRowStretch(2, 0);
mainLayout->setRowStretch(2, 1);

connect(mFileListWidget, &FileListWidget::itemDoubleClicked, this,
[this](QListWidgetItem *item) { emit signalOpenFileCommit(mCurrentSha, mParentSha, item->text(), false); });
connect(fileListWidget, &FileListWidget::signalShowFileHistory, this, &CommitInfoWidget::signalShowFileHistory);
connect(fileListWidget, &FileListWidget::signalEditFile, this, &CommitInfoWidget::signalEditFile);
connect(mFileListWidget, &FileListWidget::signalShowFileHistory, this, &CommitInfoWidget::signalShowFileHistory);
connect(mFileListWidget, &FileListWidget::signalEditFile, this, &CommitInfoWidget::signalEditFile);
}

void CommitInfoWidget::configure(const QString &sha)
Expand All @@ -62,7 +65,7 @@ void CommitInfoWidget::configure(const QString &sha)

mInfoPanel->configure(commit);

fileListWidget->insertFiles(mCurrentSha, mParentSha);
mFileListWidget->insertFiles(mCurrentSha, mParentSha);
}
}
}
Expand All @@ -77,5 +80,5 @@ void CommitInfoWidget::clear()
mCurrentSha = QString();
mParentSha = QString();

fileListWidget->clear();
mFileListWidget->clear();
}
2 changes: 1 addition & 1 deletion src/commits/CommitInfoWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ class CommitInfoWidget : public QFrame
QString mCurrentSha;
QString mParentSha;
CommitInfoPanel *mInfoPanel = nullptr;
FileListWidget *fileListWidget = nullptr;
FileListWidget *mFileListWidget = nullptr;
};

0 comments on commit 43acb84

Please sign in to comment.