更新功能
This commit is contained in:
parent
a5e63fc779
commit
cab775e05b
|
@ -72,7 +72,12 @@ include_directories(${AIBASE_INCLUDE_DIRS})
|
|||
pkg_check_modules(Gsetting REQUIRED gsettings-qt)
|
||||
include_directories(${Gsetting_INCLUDE_DIRS})
|
||||
|
||||
|
||||
pkg_check_modules(Jsoncpp REQUIRED jsoncpp)
|
||||
include_directories(${Jsoncpp_INCLUDE_DIRS})
|
||||
|
||||
pkg_check_modules(JsonGlib REQUIRED json-glib-1.0)
|
||||
include_directories(${JsonGlib_INCLUDE_DIRS})
|
||||
|
||||
## Generate header with version number
|
||||
ecm_setup_version(${RELEASE_SERVICE_VERSION}
|
||||
VARIABLE_PREFIX KOLOURPAINT
|
||||
|
@ -357,6 +362,8 @@ target_link_libraries(kolourpaint
|
|||
${KSANE_LIBRARIES}
|
||||
${AIBASE_LIBRARIES}
|
||||
${Gsetting_LIBRARIES}
|
||||
${Jsoncpp_LIBRARIES}
|
||||
${JsonGlib_LIBRARIES}
|
||||
# ${LIBUKUI_LOG4QT_PATH}
|
||||
kolourpaint_lgpl
|
||||
)
|
||||
|
|
|
@ -20,6 +20,8 @@ Build-Depends: cmake (>= 3.16.0~),
|
|||
qtbase5-dev (>= 5.15.2~),
|
||||
libkylin-ai-base-dev,
|
||||
libgsettings-qt-dev,
|
||||
libjsoncpp-dev,
|
||||
libjson-glib-dev,
|
||||
Standards-Version: 4.6.1
|
||||
Rules-Requires-Root: no
|
||||
Homepage: https://apps.kde.org/en/kolourpaint
|
||||
|
@ -29,7 +31,7 @@ Vcs-Git: https://gitee.com/openkylin/kolourpaint.git
|
|||
Package: kolourpaint
|
||||
Section: graphics
|
||||
Architecture: any
|
||||
Depends: ${misc:Depends}, ${shlibs:Depends}, libkylin-ai-base0
|
||||
Depends: ${misc:Depends}, ${shlibs:Depends}, kylin-aiassistant
|
||||
Breaks: kolourpaint4 (<< 4:17.04)
|
||||
Replaces: kolourpaint4 (<< 4:17.04)
|
||||
Description: simple image editor and drawing application
|
||||
|
|
|
@ -44,9 +44,13 @@ kpAIDrawingBar::kpAIDrawingBar(QWidget *parent)
|
|||
setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
|
||||
setAcceptDrops (false);
|
||||
|
||||
AiSettings = nullptr;
|
||||
//取消登录界面绘画
|
||||
/*
|
||||
if(!getConfigStatus())
|
||||
loginConfigurationPage();
|
||||
else
|
||||
*/
|
||||
initUI();
|
||||
|
||||
setFixedWidth(250);
|
||||
|
@ -311,7 +315,6 @@ void kpAIDrawingBar::initUI()
|
|||
buildButton->setFixedSize(224,36);
|
||||
buildButton->setStyleSheet(colorGrayButtonStyle);
|
||||
buildButton->setEnabled(false);
|
||||
buildButtonFlag = false;
|
||||
|
||||
/* 分页功能 */
|
||||
stackedWidget = new QStackedWidget(centralWidget);
|
||||
|
@ -322,21 +325,30 @@ void kpAIDrawingBar::initUI()
|
|||
QPushButton *previousButton = new QPushButton(this);
|
||||
pageLabel = new QLabel(tr("1"));
|
||||
QPushButton *nextButton = new QPushButton(this);
|
||||
deleteButton = new QPushButton(this);
|
||||
resultLabel->setFixedSize(80,30);
|
||||
previousButton->setIcon(QIcon::fromTheme("go-previous-symbolic"));
|
||||
previousButton->setFixedSize(30,30);
|
||||
|
||||
previousButton->setIcon(QIcon::fromTheme("ukui-start-symbolic"));
|
||||
previousButton->setFixedSize(20,20);
|
||||
previousButton->setStyleSheet("QPushButton { background-color: transparent; }");
|
||||
|
||||
pageLabel->setFixedSize(50,30);
|
||||
pageLabel->setAlignment(Qt::AlignCenter);
|
||||
nextButton->setFixedSize(30,30);
|
||||
nextButton->setIcon(QIcon::fromTheme("go-previous-symbolic-rtl"));
|
||||
|
||||
nextButton->setFixedSize(20,20);
|
||||
nextButton->setIcon(QIcon::fromTheme("ukui-end-symbolic"));
|
||||
nextButton->setStyleSheet("QPushButton { background-color: transparent; }");
|
||||
|
||||
deleteButton->setIcon(QIcon::fromTheme("edit-delete-symbolic"));
|
||||
deleteButton->setFixedSize(24,24);
|
||||
deleteButton->setStyleSheet("QPushButton { background-color: transparent; }");
|
||||
|
||||
resultGrid->addWidget(resultLabel);
|
||||
resultGrid->addStretch();
|
||||
resultGrid->addWidget(previousButton);
|
||||
resultGrid->addWidget(pageLabel);
|
||||
resultGrid->addWidget(nextButton);
|
||||
resultGrid->addWidget(deleteButton);
|
||||
resultGrid->setAlignment(pageLabel, Qt::AlignRight);
|
||||
|
||||
/* 设置整体布局 */
|
||||
|
@ -380,8 +392,11 @@ void kpAIDrawingBar::initUI()
|
|||
connect(inputBox,&QTextEdit::textChanged, this, &kpAIDrawingBar::handleInputTextChanged);
|
||||
connect(previousButton, &QPushButton::clicked, this, &kpAIDrawingBar::showPreviousPage);
|
||||
connect(nextButton, &QPushButton::clicked, this, &kpAIDrawingBar::showNextPage);
|
||||
connect(deleteButton, &QPushButton::clicked, this, &kpAIDrawingBar::deleteCurrentPage);
|
||||
connect(&aiThread, &AIModeDataThread::finishedSignal, this, &kpAIDrawingBar::onThreadFinished);
|
||||
|
||||
centralWidget->setFixedWidth(240);
|
||||
|
||||
scrollArea->setWidget(centralWidget);
|
||||
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
|
@ -411,7 +426,7 @@ void kpAIDrawingBar::addStyleWidget()
|
|||
"style-realistic","style-ukiyoe"};
|
||||
|
||||
QStringList styleMoreList ={ "style-futurism", "style-pixel", "style-conceptual", "style-cyberpunk",
|
||||
"style-lolita", "style-baroque", "style-surrealism", "style-watercolour",
|
||||
"style-baroque", "style-surrealism", "style-watercolour", //头部删除"style-lolita"
|
||||
"style-vaporwave", "style-oil-painting","style-cartoon"};
|
||||
|
||||
|
||||
|
@ -470,7 +485,7 @@ void kpAIDrawingBar::onStyleMoreButtonClick()
|
|||
styleGrid->removeWidget(moreButton);
|
||||
|
||||
addStyleGrid(widget_low_poly, 5);
|
||||
styleGrid->addWidget(moreButton, 5, 2,Qt::AlignTop);
|
||||
styleGrid->addWidget(moreButton, 5, 1,Qt::AlignTop);
|
||||
} else {
|
||||
for (int i = 5; i < styleGrid->count()-1; ++i)
|
||||
{
|
||||
|
@ -482,7 +497,7 @@ void kpAIDrawingBar::onStyleMoreButtonClick()
|
|||
styleGrid->removeWidget(moreButton);
|
||||
styleGrid->removeWidget(widget_low_poly);
|
||||
|
||||
addStyleGrid(widget_low_poly, 17);
|
||||
addStyleGrid(widget_low_poly, 16);
|
||||
styleGrid->addWidget(moreButton, 1, 2, Qt::AlignTop);
|
||||
}
|
||||
|
||||
|
@ -626,6 +641,9 @@ void kpAIDrawingBar::handleLabelClicked(QObject *clickedObject)
|
|||
selectedIconLabel = iconLabel;
|
||||
selectedTextLabel = textLabel;
|
||||
int identifier = textLabel->property("labelStyle").toInt();
|
||||
if (identifier > 9){
|
||||
identifier += 1;
|
||||
}
|
||||
ImageStyle = (VisionImageStyle)identifier;
|
||||
}
|
||||
|
||||
|
@ -767,15 +785,12 @@ void kpAIDrawingBar::onGenerateButtonClicked()
|
|||
buildButton->setEnabled(false);
|
||||
buildButton->setText(i18n("In formation..."));
|
||||
buildButton->setStyleSheet(colorGrayButtonStyle);
|
||||
buildButtonFlag = true;
|
||||
if(!deleteButton->isEnabled())
|
||||
deleteButton->setEnabled(true);
|
||||
|
||||
// 更新结果显示
|
||||
updateResultGrid();
|
||||
|
||||
// 显示resultGrid中的所有子控件
|
||||
for (int i = 0; i < resultGrid->count(); ++i)
|
||||
{
|
||||
QLayoutItem *item = resultGrid->itemAt(i);
|
||||
if (item && item->widget())
|
||||
item->widget()->setVisible(true);
|
||||
}
|
||||
// 更新图像
|
||||
updateImageGrid();
|
||||
}
|
||||
|
@ -789,7 +804,7 @@ void kpAIDrawingBar::handleInputTextChanged()
|
|||
//考虑添加生成中判断
|
||||
QString userText = static_cast<QTextEdit *>(findChild<QTextEdit *>())->toPlainText().trimmed();
|
||||
bool enableButton = !userText.isEmpty();
|
||||
if (enableButton && !buildButton->isEnabled() && !buildButtonFlag) {
|
||||
if (enableButton && !buildButton->isEnabled()) {
|
||||
qDebug()<<"buildButton set true";
|
||||
buildButton->setEnabled(enableButton);
|
||||
buildButton->setStyleSheet(colorfulButtonStyle);
|
||||
|
@ -871,11 +886,15 @@ QPixmap kpAIDrawingBar::createPixmapWithText(const QString &text)
|
|||
QColor color("#B8B8B8");
|
||||
QPainter painter(&pixmap);
|
||||
|
||||
QFontMetrics metrics(painter.font());
|
||||
QString wrappedText = metrics.elidedText(i18n(text.toLocal8Bit().data()), Qt::ElideRight, pixmap.rect().width());
|
||||
// 设置字体和字体大小,这里假设使用默认字体,根据实际需求可自定义
|
||||
QFont font = painter.font();
|
||||
// 若需要调整字体大小以适应换行,请在此处设置,例如:font.setPointSize(10);
|
||||
|
||||
// 计算文本在给定宽度下的自动换行字符串
|
||||
QString wrappedText = fontMetrics().elidedText(text, Qt::ElideNone, pixmap.rect().width(), Qt::TextWordWrap);
|
||||
|
||||
painter.setPen(color);
|
||||
painter.drawText(pixmap.rect(), Qt::AlignCenter, wrappedText);
|
||||
painter.drawText(pixmap.rect(), Qt::AlignCenter | Qt::TextWordWrap, wrappedText);
|
||||
painter.end();
|
||||
|
||||
qDebug()<<"Error message:"<<i18n(text.toLocal8Bit().data());
|
||||
|
@ -908,7 +927,7 @@ QPixmap kpAIDrawingBar::AIGeneratesErrorHandling(int errorCode)
|
|||
map = createPixmapWithText("Service error");
|
||||
break;
|
||||
case VISION_UNAUTHORIZED:
|
||||
map = createPixmapWithText("Authentication failure");
|
||||
map = createPixmapWithText("Unconfigured model");
|
||||
break;
|
||||
case VISION_REQUEST_FAILED:
|
||||
map = createPixmapWithText("Request failed");
|
||||
|
@ -947,6 +966,8 @@ void kpAIDrawingBar::onThreadFinished(bool flag, QPixmap pixmap, int imageIndex,
|
|||
if(!flag){
|
||||
deleteImageGridWidget();
|
||||
aiThread.exit();
|
||||
deleteButtonFlag = true;
|
||||
deleteButton->setEnabled(true);
|
||||
return;
|
||||
}
|
||||
if (imageIndex == 0){
|
||||
|
@ -964,7 +985,6 @@ void kpAIDrawingBar::onThreadFinished(bool flag, QPixmap pixmap, int imageIndex,
|
|||
buildButton->setEnabled(true);
|
||||
buildButton->setText(i18n("Generate now"));
|
||||
buildButton->setStyleSheet(colorfulButtonStyle);//设置立即生成按钮为立即生成
|
||||
buildButtonFlag = false;
|
||||
addPageAndStoreImages();
|
||||
}
|
||||
aiThread.exit();
|
||||
|
@ -980,11 +1000,22 @@ bool AIModeDataThread::someFunctionInThread()
|
|||
VisionSession session = nullptr;
|
||||
VisionResult ret = vision_create_session(&session);
|
||||
|
||||
|
||||
if (ret != VISION_SUCCESS) {
|
||||
qDebug()<<"VisionResult 创建失败 VisionResult = "<<ret;
|
||||
qDebug()<<"创建失败VisionResult="<<ret
|
||||
<<"ErrorMessage:"<<vision_get_last_error_message();
|
||||
sendErrorSignal(ret);
|
||||
return false;
|
||||
}
|
||||
|
||||
VisionResult initRet = vision_init_session(session);
|
||||
if (initRet != VISION_SUCCESS) {
|
||||
qDebug()<<"初始化失败 VisionResult="<<initRet
|
||||
<<"ErrorMessage:"<<vision_get_last_error_message();
|
||||
sendErrorSignal(initRet);
|
||||
return false;
|
||||
}
|
||||
|
||||
int width = AIImageSize.width() * multipleNum;
|
||||
int height = AIImageSize.height() * multipleNum;
|
||||
|
||||
|
@ -997,7 +1028,8 @@ bool AIModeDataThread::someFunctionInThread()
|
|||
|
||||
qDebug()<<"ImageStyle == "<<ImageStyle;
|
||||
if (imageRet != VISION_SUCCESS) {
|
||||
qDebug()<<"文字输入失败, VisionResult = "<<imageRet;
|
||||
qDebug()<<"文字输入失败,VisionResult="<<imageRet
|
||||
<<"ErrorMessage:"<<vision_get_last_error_message();
|
||||
sendErrorSignal(imageRet);
|
||||
return false;
|
||||
}
|
||||
|
@ -1015,45 +1047,46 @@ QSize kpAIDrawingBar::getImageLabelSize()
|
|||
{
|
||||
QSize labelSize = QSize(90,90);
|
||||
imageColumn = 2;
|
||||
if (quantityNum == 1){
|
||||
if (show_quantityNum == 1){
|
||||
if(configVersion == 2){
|
||||
if(ratioNum == 0)
|
||||
if(show_ratioNum == 0)
|
||||
labelSize = QSize(224, 126);
|
||||
else if (ratioNum == 1)
|
||||
else if (show_ratioNum == 1)
|
||||
labelSize = QSize(224, 224);
|
||||
else if (ratioNum == 2)
|
||||
else if (show_ratioNum == 2)
|
||||
labelSize = QSize(108, 192);
|
||||
else
|
||||
labelSize = QSize(224, 126);
|
||||
}
|
||||
else if (configVersion == 1){
|
||||
if(ratioNum == 0)
|
||||
if(show_ratioNum == 0)
|
||||
labelSize = QSize(224, 150);
|
||||
else if (ratioNum == 1)
|
||||
else if (show_ratioNum == 1)
|
||||
labelSize = QSize(224, 224);
|
||||
else if (ratioNum == 2)
|
||||
else if (show_ratioNum == 2)
|
||||
labelSize = QSize(108, 162);
|
||||
else
|
||||
labelSize = QSize(224, 150);
|
||||
}
|
||||
imageColumn = 1;
|
||||
}
|
||||
else if (quantityNum >= 2) {
|
||||
else if (show_quantityNum >= 2) {
|
||||
if(configVersion == 2){
|
||||
if(ratioNum == 0)
|
||||
if(show_ratioNum == 0)
|
||||
labelSize = QSize(108, 60);
|
||||
else if (ratioNum == 1)
|
||||
else if (show_ratioNum == 1)
|
||||
labelSize = QSize(108, 108);
|
||||
else if (ratioNum == 2)
|
||||
else if (show_ratioNum == 2)
|
||||
labelSize = QSize(108, 192);
|
||||
else
|
||||
labelSize = QSize(108, 60);
|
||||
}
|
||||
else if(configVersion == 1){
|
||||
if(ratioNum == 0)
|
||||
if(show_ratioNum == 0)
|
||||
labelSize = QSize(108, 72);
|
||||
else if (ratioNum == 1)
|
||||
else if (show_ratioNum == 1)
|
||||
labelSize = QSize(108, 108);
|
||||
else if (ratioNum == 2)
|
||||
else if (show_ratioNum == 2)
|
||||
labelSize = QSize(108, 162);
|
||||
else
|
||||
labelSize = QSize(108, 72);
|
||||
|
@ -1095,7 +1128,7 @@ void kpAIDrawingBar::deleteImageGridWidget()
|
|||
{
|
||||
// 清空之前的图像
|
||||
if(stackedWidget->count() > 0 ){
|
||||
QWidget *w = stackedWidget->currentWidget();
|
||||
QWidget *w = stackedWidget->widget(stackedWidget->count() - 1);
|
||||
stackedWidget->removeWidget(w);
|
||||
w->deleteLater();
|
||||
}
|
||||
|
@ -1128,6 +1161,7 @@ void kpAIDrawingBar::showPreviousPage()
|
|||
stackedWidget->setCurrentIndex(currentPageIndx);
|
||||
updatePageLabel();
|
||||
}
|
||||
setEnabledDeleteButton();
|
||||
qDebug()<<"stackedWidget->count() = "<<stackedWidget->count()<<"currentPageIndx="<<currentPageIndx;
|
||||
}
|
||||
|
||||
|
@ -1147,15 +1181,62 @@ void kpAIDrawingBar::showNextPage()
|
|||
stackedWidget->setCurrentIndex(currentPageIndx);
|
||||
updatePageLabel();
|
||||
}
|
||||
setEnabledDeleteButton();
|
||||
qDebug()<<"stackedWidget->count() = "<<stackedWidget->count()<<"currentPageIndx="<<currentPageIndx;
|
||||
}
|
||||
|
||||
void kpAIDrawingBar::deleteCurrentPage()
|
||||
{
|
||||
stackedWidget->removeWidget(stackedWidget->currentWidget());
|
||||
updatePageLabel();
|
||||
if(stackedWidget->count() <= 1){
|
||||
updateResultGrid();
|
||||
if (currentPageIndx == -1)
|
||||
deleteButton->setEnabled(false);
|
||||
else
|
||||
setEnabledDeleteButton();
|
||||
}
|
||||
else
|
||||
setEnabledDeleteButton();
|
||||
}
|
||||
|
||||
void kpAIDrawingBar::setEnabledDeleteButton()
|
||||
{
|
||||
if(!deleteButtonFlag && currentPageIndx == stackedWidget->count() - 1){
|
||||
deleteButton->setEnabled(false);
|
||||
}
|
||||
else {
|
||||
deleteButton->setEnabled(true);
|
||||
}
|
||||
}
|
||||
void kpAIDrawingBar::updateResultGrid()
|
||||
{
|
||||
qDebug()<<"updateResultGrid: stackedWidget->count() === "<<stackedWidget->count();
|
||||
// 显示resultGrid中的所有子控件
|
||||
for (int i = 0; i < resultGrid->count(); ++i)
|
||||
{
|
||||
QLayoutItem *item = resultGrid->itemAt(i);;
|
||||
if (stackedWidget->count() < 1 && (i == 2 || i == 3 || i ==4)){
|
||||
if (item && item->widget()){
|
||||
item->widget()->setVisible(false);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (item && item->widget()){
|
||||
item->widget()->setVisible(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief kpAIDrawingBar::updateImageGrid
|
||||
* 更新、等待QLabel相关界面,并开启线程运行
|
||||
*/
|
||||
void kpAIDrawingBar::updateImageGrid()
|
||||
{
|
||||
show_quantityNum = quantityNum;
|
||||
show_ratioNum = ratioNum;
|
||||
|
||||
QSize labelSize = getImageLabelSize();
|
||||
|
||||
QWidget *newWidget = new QWidget();
|
||||
|
@ -1189,6 +1270,9 @@ void kpAIDrawingBar::updateImageGrid()
|
|||
qDebug()<<"updateImageGrid : currentPageIndx = "<<currentPageIndx + 1<<stackedWidget->count();
|
||||
updatePageLabel();
|
||||
|
||||
deleteButtonFlag = false;
|
||||
deleteButton->setEnabled(false);
|
||||
|
||||
qDebug()<<textBox<<AIImageSize * multipleNum<<quantityNum<<ImageStyle;
|
||||
|
||||
startThread();
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
#include <QJsonArray>
|
||||
#include <QDir>
|
||||
#include <QGSettings>
|
||||
|
||||
#include <ai-base/modelconfig.h>
|
||||
#include <ai-base/vision.h>
|
||||
|
||||
|
@ -166,6 +165,8 @@ private slots:
|
|||
|
||||
void showPreviousPage(); //显示上一页
|
||||
void showNextPage(); //显示下一页
|
||||
void deleteCurrentPage();
|
||||
void setEnabledDeleteButton();
|
||||
void handleLabelClick(const QPixmap &pixmap);
|
||||
|
||||
void addPageAndStoreImages();
|
||||
|
@ -180,6 +181,7 @@ private slots:
|
|||
|
||||
private:
|
||||
void updateImageGrid();
|
||||
void updateResultGrid();
|
||||
void deleteImageGridWidget();
|
||||
|
||||
void addRatioButtons(QGridLayout *layout, QString name, int line);
|
||||
|
@ -193,14 +195,16 @@ private:
|
|||
void addStyleGrid(QWidget *widget, int line);
|
||||
|
||||
private:
|
||||
int quantityNum = 4; //数量按钮
|
||||
int ratioNum = 0; //比例按钮
|
||||
int multipleNum = 1; //倍数按钮
|
||||
int imageColumn = 2;//显示列表列数
|
||||
int currentPageIndx = 0;//切换页第几页
|
||||
int quantityNum = 4; //数量按钮
|
||||
int ratioNum = 0; //比例按钮
|
||||
int show_quantityNum = 4; //数量按钮
|
||||
int show_ratioNum = 0; //比例按钮
|
||||
int currentPageIndx = -1;//切换页第几页
|
||||
|
||||
bool styleFlag; //风格标志位,用于判断按下哪一个风格
|
||||
bool buildButtonFlag; //生成按钮是否打开
|
||||
bool deleteButtonFlag = true;
|
||||
|
||||
QGSettings *AiSettings; //监听配置信息
|
||||
QSize AIImageSize; //图片大小
|
||||
|
@ -225,6 +229,7 @@ private:
|
|||
|
||||
QScrollArea *scrollArea; //滚动窗口
|
||||
QPushButton *buildButton; //立即生成按钮
|
||||
QPushButton *deleteButton; //删除按钮
|
||||
|
||||
QButtonGroup *ratioButtonGroup; //比例按钮
|
||||
QButtonGroup *quantityButtonGroup; //数量按钮
|
||||
|
|
Loading…
Reference in New Issue