| 380 | }; |
| 381 | |
| 382 | CommitDiffTreeView::CommitDiffTreeView(const QString &repoBase, const QString &hash, KTextEditor::MainWindow *mainWindow, QWidget *parent) |
| 383 | : QWidget(parent) |
| 384 | , m_mainWindow(mainWindow) |
| 385 | , m_gitDir(repoBase) |
| 386 | { |
| 387 | auto vLayout = new QVBoxLayout; |
| 388 | setLayout(vLayout); |
| 389 | layout()->setContentsMargins({}); |
| 390 | layout()->setSpacing(0); |
| 391 | |
| 392 | m_backBtn.setIcon(QIcon::fromTheme(QStringLiteral("tab-close"))); |
| 393 | m_backBtn.setAutoRaise(true); |
| 394 | m_backBtn.setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); |
| 395 | connect(&m_backBtn, &QAbstractButton::clicked, this, [parent, mainWindow] { |
| 396 | Q_ASSERT(parent); |
| 397 | parent->deleteLater(); |
| 398 | mainWindow->hideToolView(parent); |
| 399 | }); |
| 400 | |
| 401 | // Label |
| 402 | m_label.setText(hash.left(7)); |
| 403 | m_label.setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); |
| 404 | m_icon.setPixmap(QIcon::fromTheme(QStringLiteral("vcs-commit")).pixmap(style()->pixelMetric(QStyle::PM_SmallIconSize))); |
| 405 | |
| 406 | // Horiz layout |
| 407 | auto *hLayout = new QHBoxLayout(); |
| 408 | hLayout->setContentsMargins(style()->pixelMetric(QStyle::PM_LayoutLeftMargin), 0, 0, 0); |
| 409 | hLayout->addWidget(&m_icon); |
| 410 | hLayout->addSpacing(style()->pixelMetric(QStyle::PM_LayoutLeftMargin) / 2); |
| 411 | hLayout->addWidget(&m_label); |
| 412 | hLayout->addWidget(&m_backBtn); |
| 413 | |
| 414 | vLayout->addLayout(hLayout); |
| 415 | |
| 416 | m_tree.setModel(&m_model); |
| 417 | layout()->addWidget(&m_tree); |
| 418 | |
| 419 | m_tree.setHeaderHidden(true); |
| 420 | m_tree.setEditTriggers(QTreeView::NoEditTriggers); |
| 421 | m_tree.setItemDelegate(new DiffStyleDelegate(this)); |
| 422 | m_tree.setIndentation(10); |
| 423 | m_tree.setProperty("_breeze_borders_sides", QVariant::fromValue(QFlags{Qt::TopEdge})); |
| 424 | |
| 425 | m_tree.setContextMenuPolicy(Qt::CustomContextMenu); |
| 426 | connect(&m_tree, &QTreeView::customContextMenuRequested, this, &CommitDiffTreeView::openContextMenu); |
| 427 | |
| 428 | connect(&m_tree, &QTreeView::clicked, this, &CommitDiffTreeView::showDiff); |
| 429 | openCommit(hash); |
| 430 | } |
| 431 | |
| 432 | void CommitDiffTreeView::openContextMenu(QPoint pos) |
| 433 | { |
nothing calls this directly
no test coverage detected