mirror of
https://github.com/Murmele/Gittyup.git
synced 2024-09-11 02:35:41 +03:00
HunkHeader resizes itself to not interfere with line wrapping
This commit is contained in:
parent
dac06473c0
commit
d4dc0f57b2
@ -11,6 +11,7 @@ add_library(
|
||||
ContextMenuButton.cpp
|
||||
DetailView.cpp
|
||||
DiffView/DiffView.cpp
|
||||
DiffView/HunkHeader.cpp
|
||||
DiffView/HunkWidget.cpp
|
||||
DiffView/FileWidget.cpp
|
||||
DiffView/FileLabel.cpp
|
||||
|
42
src/ui/DiffView/HunkHeader.cpp
Normal file
42
src/ui/DiffView/HunkHeader.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include "HunkHeader.h"
|
||||
#include "DiffView.h"
|
||||
#include "../RepoView.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
|
||||
HunkHeader::HunkHeader(const QString &name, bool submodule, QWidget *parent)
|
||||
: QWidget(parent), mName(name) {
|
||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
}
|
||||
|
||||
void HunkHeader::setName(const QString &name) { mName = name; }
|
||||
|
||||
void HunkHeader::setOldName(const QString &oldName) { mOldName = oldName; }
|
||||
|
||||
QSize HunkHeader::sizeHint() const {
|
||||
QFontMetrics fm = fontMetrics();
|
||||
int width = fm.boundingRect(mName).width() + 2;
|
||||
if (!mOldName.isEmpty())
|
||||
width += fm.boundingRect(mOldName).width() + DiffViewStyle::kArrowWidth;
|
||||
return QSize(width, fm.lineSpacing());
|
||||
}
|
||||
|
||||
void HunkHeader::paintEvent(QPaintEvent *event) {
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
QFontMetrics fm = fontMetrics();
|
||||
QRect rect = fm.boundingRect(0, 0, this->rect().width(), 300,
|
||||
Qt::AlignLeft | Qt::ElideRight, mName);
|
||||
painter.drawText(rect, Qt::AlignLeft | Qt::ElideRight, mName);
|
||||
}
|
||||
|
||||
void HunkHeader::mouseReleaseEvent(QMouseEvent *event) {
|
||||
if (!rect().contains(event->pos()))
|
||||
return;
|
||||
|
||||
QUrl url;
|
||||
url.setScheme("submodule");
|
||||
url.setPath(mName);
|
||||
RepoView::parentView(this)->visitLink(url.toString());
|
||||
}
|
22
src/ui/DiffView/HunkHeader.h
Normal file
22
src/ui/DiffView/HunkHeader.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef HUNKHEADER_H
|
||||
#define HUNKHEADER_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class HunkHeader : public QWidget {
|
||||
public:
|
||||
HunkHeader(const QString &name, bool submodule, QWidget *parent = nullptr);
|
||||
void setName(const QString &name);
|
||||
void setOldName(const QString &oldName);
|
||||
QSize sizeHint() const override;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
|
||||
private:
|
||||
QString mName;
|
||||
QString mOldName;
|
||||
};
|
||||
|
||||
#endif // HUNKHEADER_H
|
@ -5,6 +5,7 @@
|
||||
#include "DiffView.h"
|
||||
#include "DisclosureButton.h"
|
||||
#include "EditButton.h"
|
||||
#include "HunkHeader.h"
|
||||
#include "DiscardButton.h"
|
||||
#include "app/Application.h"
|
||||
|
||||
@ -39,15 +40,16 @@ _HunkWidget::Header::Header(const git::Diff &diff, const git::Patch &patch,
|
||||
int index, bool lfs, bool submodule,
|
||||
QWidget *parent)
|
||||
: QFrame(parent) {
|
||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
|
||||
setObjectName("HunkHeader");
|
||||
mCheck = new QCheckBox(this);
|
||||
mCheck->setTristate(true);
|
||||
mCheck->setVisible(diff.isStatusDiff() && !submodule &&
|
||||
!patch.isConflicted());
|
||||
|
||||
QString header = (index >= 0) ? patch.header(index) : QString();
|
||||
QString escaped = header.trimmed().toHtmlEscaped();
|
||||
QLabel *label = new QLabel(DiffViewStyle::kHunkFmt.arg(escaped), this);
|
||||
QString headerString = (index >= 0) ? patch.header(index) : QString();
|
||||
QString escaped = headerString.trimmed().toHtmlEscaped();
|
||||
HunkHeader *header = new HunkHeader(escaped, submodule, this);
|
||||
|
||||
if (patch.isConflicted()) {
|
||||
mSave = new QToolButton(this);
|
||||
@ -132,7 +134,7 @@ _HunkWidget::Header::Header(const git::Diff &diff, const git::Patch &patch,
|
||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||
layout->setContentsMargins(4, 4, 4, 4);
|
||||
layout->addWidget(mCheck);
|
||||
layout->addWidget(label);
|
||||
layout->addWidget(header, 1);
|
||||
layout->addStretch();
|
||||
layout->addLayout(buttons);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user