新增模型补全空洞
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <QDialogButtonBox>
|
||||
#include <QFrame>
|
||||
#include <QLabel>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QPushButton>
|
||||
#include <QStackedWidget>
|
||||
#include <QVBoxLayout>
|
||||
@@ -40,6 +41,10 @@ BlackholeResolveDialog::BlackholeResolveDialog(const QString& blackholeName, QWi
|
||||
m_pages->setCurrentWidget(m_pageSelect);
|
||||
}
|
||||
|
||||
QString BlackholeResolveDialog::promptText() const {
|
||||
return m_promptEdit ? m_promptEdit->toPlainText().trimmed() : QString();
|
||||
}
|
||||
|
||||
void BlackholeResolveDialog::buildSelectPage() {
|
||||
m_pageSelect = new QWidget(this);
|
||||
auto* layout = new QVBoxLayout(m_pageSelect);
|
||||
@@ -61,14 +66,14 @@ void BlackholeResolveDialog::buildSelectPage() {
|
||||
QStringLiteral("使用原始背景"),
|
||||
QStringLiteral("撤销黑洞显示,恢复抠图前背景区域。"),
|
||||
m_pageSelect);
|
||||
auto* btnModel = makeAlgoButton(
|
||||
QStringLiteral("模型补全(SDXL Inpaint)"),
|
||||
QStringLiteral("输入提示词,自动补全缺失区域;可预览后再决定是否接受。"),
|
||||
m_pageSelect);
|
||||
layout->addWidget(btnCopy);
|
||||
layout->addWidget(btnOriginal);
|
||||
layout->addWidget(btnModel);
|
||||
|
||||
auto* modelNote = new QLabel(
|
||||
QStringLiteral("模型补全:已预留接口,本版本暂不实现。"),
|
||||
m_pageSelect);
|
||||
modelNote->setStyleSheet("color: palette(mid);");
|
||||
layout->addWidget(modelNote);
|
||||
layout->addStretch(1);
|
||||
|
||||
auto* btns = new QDialogButtonBox(QDialogButtonBox::Cancel, m_pageSelect);
|
||||
@@ -81,6 +86,9 @@ void BlackholeResolveDialog::buildSelectPage() {
|
||||
connect(btnOriginal, &QPushButton::clicked, this, [this]() {
|
||||
enterAlgorithmPage(Algorithm::UseOriginalBackground);
|
||||
});
|
||||
connect(btnModel, &QPushButton::clicked, this, [this]() {
|
||||
enterAlgorithmPage(Algorithm::ModelInpaint);
|
||||
});
|
||||
|
||||
m_pages->addWidget(m_pageSelect);
|
||||
}
|
||||
@@ -141,8 +149,29 @@ void BlackholeResolveDialog::buildDetailPage() {
|
||||
oLay->addStretch(1);
|
||||
}
|
||||
|
||||
// 详情页 C:模型补全(提示词)
|
||||
m_modelDetail = new QWidget(m_algoDetails);
|
||||
{
|
||||
auto* mLay = new QVBoxLayout(m_modelDetail);
|
||||
mLay->setSpacing(8);
|
||||
|
||||
auto* panel = new QFrame(m_modelDetail);
|
||||
panel->setFrameShape(QFrame::StyledPanel);
|
||||
auto* pLay = new QVBoxLayout(panel);
|
||||
pLay->setSpacing(8);
|
||||
|
||||
m_promptEdit = new QPlainTextEdit(panel);
|
||||
m_promptEdit->setPlainText(QStringLiteral("This is part of a Chinese painting; please complete the background for me, following the style of the other parts."));
|
||||
m_promptEdit->setMinimumHeight(90);
|
||||
pLay->addWidget(m_promptEdit);
|
||||
|
||||
mLay->addWidget(panel);
|
||||
mLay->addStretch(1);
|
||||
}
|
||||
|
||||
m_algoDetails->addWidget(m_copyDetail);
|
||||
m_algoDetails->addWidget(m_originalDetail);
|
||||
m_algoDetails->addWidget(m_modelDetail);
|
||||
layout->addWidget(m_algoDetails, 1);
|
||||
|
||||
auto* btns = new QDialogButtonBox(m_pageDetail);
|
||||
@@ -165,10 +194,14 @@ void BlackholeResolveDialog::enterAlgorithmPage(Algorithm algo) {
|
||||
m_detailTitle->setText(QStringLiteral("第 2 步:复制背景其他区域"));
|
||||
m_detailHint->setText(QStringLiteral("准备进入画布拖动取样框模式。"));
|
||||
m_algoDetails->setCurrentWidget(m_copyDetail);
|
||||
} else {
|
||||
} else if (algo == Algorithm::UseOriginalBackground) {
|
||||
m_detailTitle->setText(QStringLiteral("第 2 步:使用原始背景"));
|
||||
m_detailHint->setText(QStringLiteral("确认后将切换为原始背景显示。"));
|
||||
m_algoDetails->setCurrentWidget(m_originalDetail);
|
||||
} else {
|
||||
m_detailTitle->setText(QStringLiteral("第 2 步:模型补全(SDXL Inpaint)"));
|
||||
m_detailHint->setText(QStringLiteral("输入提示词(可选),点击应用后将生成预览。"));
|
||||
m_algoDetails->setCurrentWidget(m_modelDetail);
|
||||
}
|
||||
m_pages->setCurrentWidget(m_pageDetail);
|
||||
}
|
||||
|
||||
@@ -11,11 +11,13 @@ public:
|
||||
enum class Algorithm {
|
||||
CopyBackgroundRegion,
|
||||
UseOriginalBackground,
|
||||
ModelInpaint,
|
||||
};
|
||||
|
||||
explicit BlackholeResolveDialog(const QString& blackholeName, QWidget* parent = nullptr);
|
||||
|
||||
Algorithm selectedAlgorithm() const { return m_selectedAlgorithm; }
|
||||
QString promptText() const;
|
||||
|
||||
private:
|
||||
void buildSelectPage();
|
||||
@@ -38,5 +40,8 @@ private:
|
||||
QWidget* m_copyDetail = nullptr;
|
||||
|
||||
QWidget* m_originalDetail = nullptr;
|
||||
|
||||
QWidget* m_modelDetail = nullptr;
|
||||
class QPlainTextEdit* m_promptEdit = nullptr;
|
||||
};
|
||||
|
||||
|
||||
68
client/gui/dialogs/InpaintPreviewDialog.cpp
Normal file
68
client/gui/dialogs/InpaintPreviewDialog.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "dialogs/InpaintPreviewDialog.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
#include <QScrollArea>
|
||||
#include <QSplitter>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
static QLabel* makeImageLabel(QWidget* parent) {
|
||||
auto* lab = new QLabel(parent);
|
||||
lab->setBackgroundRole(QPalette::Base);
|
||||
lab->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
|
||||
lab->setScaledContents(false);
|
||||
lab->setAlignment(Qt::AlignCenter);
|
||||
return lab;
|
||||
}
|
||||
|
||||
static QScrollArea* wrapScroll(QWidget* child, QWidget* parent) {
|
||||
auto* sc = new QScrollArea(parent);
|
||||
sc->setWidget(child);
|
||||
sc->setWidgetResizable(true);
|
||||
sc->setBackgroundRole(QPalette::Dark);
|
||||
return sc;
|
||||
}
|
||||
|
||||
InpaintPreviewDialog::InpaintPreviewDialog(const QString& title, QWidget* parent)
|
||||
: QDialog(parent) {
|
||||
setModal(true);
|
||||
setMinimumSize(860, 520);
|
||||
setWindowTitle(title);
|
||||
|
||||
auto* root = new QVBoxLayout(this);
|
||||
root->setContentsMargins(8, 8, 8, 8);
|
||||
root->setSpacing(8);
|
||||
|
||||
m_beforeLabel = makeImageLabel(this);
|
||||
m_afterLabel = makeImageLabel(this);
|
||||
m_beforeScroll = wrapScroll(m_beforeLabel, this);
|
||||
m_afterScroll = wrapScroll(m_afterLabel, this);
|
||||
|
||||
auto* splitter = new QSplitter(Qt::Horizontal, this);
|
||||
splitter->addWidget(m_beforeScroll);
|
||||
splitter->addWidget(m_afterScroll);
|
||||
splitter->setStretchFactor(0, 1);
|
||||
splitter->setStretchFactor(1, 1);
|
||||
root->addWidget(splitter, 1);
|
||||
|
||||
auto* btns = new QDialogButtonBox(this);
|
||||
btns->addButton(QStringLiteral("取消"), QDialogButtonBox::RejectRole);
|
||||
btns->addButton(QStringLiteral("接受并写回"), QDialogButtonBox::AcceptRole);
|
||||
connect(btns, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(btns, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
root->addWidget(btns);
|
||||
}
|
||||
|
||||
void InpaintPreviewDialog::setImages(const QImage& before, const QImage& after) {
|
||||
if (m_beforeLabel) {
|
||||
m_beforeLabel->setPixmap(QPixmap::fromImage(before));
|
||||
m_beforeLabel->adjustSize();
|
||||
}
|
||||
if (m_afterLabel) {
|
||||
m_afterLabel->setPixmap(QPixmap::fromImage(after));
|
||||
m_afterLabel->adjustSize();
|
||||
}
|
||||
}
|
||||
|
||||
22
client/gui/dialogs/InpaintPreviewDialog.h
Normal file
22
client/gui/dialogs/InpaintPreviewDialog.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include <QImage>
|
||||
|
||||
class QLabel;
|
||||
class QScrollArea;
|
||||
|
||||
class InpaintPreviewDialog final : public QDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit InpaintPreviewDialog(const QString& title, QWidget* parent = nullptr);
|
||||
|
||||
void setImages(const QImage& before, const QImage& after);
|
||||
|
||||
private:
|
||||
QLabel* m_beforeLabel = nullptr;
|
||||
QLabel* m_afterLabel = nullptr;
|
||||
QScrollArea* m_beforeScroll = nullptr;
|
||||
QScrollArea* m_afterScroll = nullptr;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user