mirror of
https://github.com/Murmele/Gittyup.git
synced 2024-09-11 02:35:41 +03:00
Move HunkLabel.cpp into HunkWidget.cpp
This commit is contained in:
parent
d4dc0f57b2
commit
cec48ca95d
@ -11,7 +11,6 @@ add_library(
|
||||
ContextMenuButton.cpp
|
||||
DetailView.cpp
|
||||
DiffView/DiffView.cpp
|
||||
DiffView/HunkHeader.cpp
|
||||
DiffView/HunkWidget.cpp
|
||||
DiffView/FileWidget.cpp
|
||||
DiffView/FileLabel.cpp
|
||||
|
@ -1,42 +0,0 @@
|
||||
#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());
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
#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,7 +5,6 @@
|
||||
#include "DiffView.h"
|
||||
#include "DisclosureButton.h"
|
||||
#include "EditButton.h"
|
||||
#include "HunkHeader.h"
|
||||
#include "DiscardButton.h"
|
||||
#include "app/Application.h"
|
||||
|
||||
@ -36,20 +35,31 @@ const QString noNewLineAtEndOfFile =
|
||||
HunkWidget::tr("No newline at end of file");
|
||||
} // namespace
|
||||
|
||||
_HunkWidget::HunkLabel::HunkLabel(const QString &name, bool submodule,
|
||||
QWidget *parent)
|
||||
: QWidget(parent), mName(name) {}
|
||||
void _HunkWidget::HunkLabel::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);
|
||||
}
|
||||
|
||||
_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 headerString = (index >= 0) ? patch.header(index) : QString();
|
||||
QString escaped = headerString.trimmed().toHtmlEscaped();
|
||||
HunkHeader *header = new HunkHeader(escaped, submodule, this);
|
||||
QString label_string = (index >= 0) ? patch.header(index) : QString();
|
||||
label_string = label_string.trimmed().toHtmlEscaped();
|
||||
HunkLabel *label = new HunkLabel(label_string, submodule, this);
|
||||
|
||||
if (patch.isConflicted()) {
|
||||
mSave = new QToolButton(this);
|
||||
@ -134,7 +144,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(header, 1);
|
||||
layout->addWidget(label, 1);
|
||||
layout->addStretch();
|
||||
layout->addLayout(buttons);
|
||||
|
||||
|
@ -19,6 +19,19 @@ class DisclosureButton;
|
||||
class Line;
|
||||
|
||||
namespace _HunkWidget {
|
||||
|
||||
class HunkLabel : public QWidget {
|
||||
public:
|
||||
HunkLabel(const QString &name, bool submodule, QWidget *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
|
||||
private:
|
||||
QString mName;
|
||||
QString mOldName;
|
||||
};
|
||||
|
||||
class Header : public QFrame {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user