Files
GUI/src/dialogs/AsyncActionDialog.cpp
2024-06-25 10:25:26 +08:00

78 lines
2.0 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "AsyncActionDialog.h"
#include <QVBoxLayout>
#include <QLabel>
#include "action/AsyncAction.h"
#include "components/LoadingWidget.h"
AsyncActionDialog::AsyncActionDialog(AsyncAction* aAsyncAction,const QString& aTitle, QWidget* aParent, Qt::WindowFlags aFlags)
: GUIFormBaseDialog(aParent,aFlags)
, mContentWidget(new QWidget(mFormWidget))
, mLoadingWidget(new QWidget(mFormWidget))
, mAction(aAsyncAction)
, mLayout(new QVBoxLayout(mFormWidget))
{
setFocusPolicy(Qt::ClickFocus);
mLoadingWidget->hide();
initializeTitle(aTitle);
initializeProgressBar();
//注意本处的connect连接的槽函数是一个虚函数会在子类中被override
connect(mAction,&AsyncAction::actionCompleted,this,&AsyncActionDialog::handleFinishedAction);
mLayout->setSpacing(10);
mLayout->addWidget(mContentWidget);
mLayout->addWidget(mLoadingWidget);
QMargins margin = mLayout->contentsMargins();
margin.setBottom(1);
mLayout->setContentsMargins(margin);
}
AsyncActionDialog::~AsyncActionDialog()
{
}
void AsyncActionDialog::initializeTitle(const QString& aTitle)
{
QLabel* title = new QLabel(this);
title->setAlignment(Qt::AlignCenter);
title->setText(tr(aTitle.toLatin1()));
title->setObjectName("title");
title->setFixedHeight(40);
mLayout->addWidget(title);
}
void AsyncActionDialog::initializeProgressBar()
{
QVBoxLayout* loadingLayout = new QVBoxLayout(mLoadingWidget);
LoadingWidget* loadingWidget = new LoadingWidget(mLoadingWidget);
loadingLayout->addWidget(loadingWidget);
}
AsyncAction* AsyncActionDialog::getAction()
{
return mAction;
}
bool AsyncActionDialog::updateReferenceData()
{
mAction->execute();
mContentWidget->hide();
mBtnWidget->hide();
mLoadingWidget->show();
return false;
}
void AsyncActionDialog::handleFinishedAction(const ActionResult& aResult)
{
mLoadingWidget->hide();
if (aResult.Code == Sucessed)
{
accept();
}
}