修改ribbon模式下动画控制按钮无法点击的情况

master
禅元天道 2023-06-15 18:10:48 +08:00
parent 34fb3dad3f
commit 7cb034b50e
4 changed files with 155 additions and 117 deletions

View File

@ -14,17 +14,22 @@
#include <QApplication>
#include <QDebug>
namespace Post
{
namespace Post {
AnimationToolBar::AnimationToolBar(GUI::MainWindow* mainWindow, PostTreeWidget* tree)
: QToolBar(mainWindow), _mainWindow(mainWindow), _treeWidget(tree)
: QToolBar(mainWindow)
, _mainWindow(mainWindow)
, _treeWidget(tree)
{
_aniAviTool = new aviSetting;
initToolBar();
_generateAni = new GenerateAnimation(_aniAviTool);
connect(_treeWidget, SIGNAL(currentRenderDataChanged(RenderDataObject *)), this, SLOT(on_currentRenderDataChanged(RenderDataObject *)));
connect(_treeWidget, SIGNAL(currentRenderDataChanged(RenderDataObject*)), this,
SLOT(on_currentRenderDataChanged(RenderDataObject*)));
connect(_treeWidget, SIGNAL(clearAllItemSig()), this,
SLOT(clearAllRenderObjSlot()));
connect(this, SIGNAL(sig_generateAvi()), _generateAni, SLOT(on_generate()));
connect(this, SIGNAL(sig_terminateGenerateAvi()), _generateAni, SLOT(on_finishSaveAvi()));
}
@ -40,6 +45,8 @@ namespace Post
void AnimationToolBar::on_currentRenderDataChanged(RenderDataObject* vobj)
{
if(vobj == nullptr)
return;
auto rObj = vobj->getRootViewObject();
if(_unSteadyObj == rObj)
return;
@ -47,6 +54,7 @@ namespace Post
// if (_unSteadyObj == vobj) return;
// _unSteadyObj = dynamic_cast<RenderDataImportUnSteady*>(vobj);
this->setEnabled(false);
this->setEnableBtn(false);
if(_unSteadyObj == nullptr)
return;
@ -54,6 +62,7 @@ namespace Post
if(n < 2)
return;
this->setEnabled(true);
this->setEnableBtn(true);
_totalLabel->setText(QString(tr("Total: %1")).arg(n));
_spinBox->setMaximum(n - 1);
@ -63,6 +72,8 @@ namespace Post
void AnimationToolBar::on_FirstFrame()
{
if(_unSteadyObj == nullptr)
return;
int totalCount = _unSteadyObj->getTotalCount();
if(totalCount < 2)
return;
@ -77,6 +88,8 @@ namespace Post
void AnimationToolBar::on_PreviousFrame()
{
if(_unSteadyObj == nullptr)
return;
int totalCount = _unSteadyObj->getTotalCount();
if(totalCount < 2)
return;
@ -94,19 +107,18 @@ namespace Post
void AnimationToolBar::on_RunAnimation()
{
if(_unSteadyObj == nullptr)
return;
int totalCount = _unSteadyObj->getTotalCount();
if(totalCount < 2)
return;
if (_aniAction->text() == tr("run"))
{
if(_aniAction->text() == tr("run")) {
_aniThread = new AniThread;
_aniAction->setIcon(QIcon("://QUI/post/stop.png"));
_aniAction->setText(tr("stop"));
_runAnimation = true;
}
else
{
} else {
_aniAction->setIcon(QIcon("://QUI/post/run.png"));
_aniAction->setText(tr("run"));
_runAnimation = false;
@ -124,8 +136,7 @@ namespace Post
int currIndex = _unSteadyObj->getCurrentIndex();
if (currIndex == totalCount - 1)
{
if(currIndex == totalCount - 1) {
currIndex = -1; // 从索引0开始播放
}
@ -134,19 +145,16 @@ namespace Post
_aniThread->start();
QThread::msleep(20);
while ((currIndex < totalCount - 1) && _runAnimation)
{
while (true)
{
if (g_qUnSteady.size() == 1)
{
while((currIndex < totalCount - 1) && _runAnimation) {
while(true) {
if(g_qUnSteady.size() == 1) {
g_mutex.lock();
_unSteadyObj = g_qUnSteady.dequeue();
_unSteadyObj->update();
int winID = _unSteadyObj->getRenderWinID();
auto graphWindow = RenderWindowManager::getInstance()->getRenderWindowByID(winID);
if (graphWindow == nullptr)
{
auto graphWindow =
RenderWindowManager::getInstance()->getRenderWindowByID(winID);
if(graphWindow == nullptr) {
g_mutex.unlock();
return;
}
@ -160,8 +168,7 @@ namespace Post
break;
}
if (!_runAnimation)
{
if(!_runAnimation) {
_spinBox->setValue(_unSteadyObj->getCurrentIndex());
_aniThread->stop(true);
_aniThread->quit();
@ -182,11 +189,9 @@ namespace Post
}
// 播放完一轮之后恢复为可播放状态
if (currIndex == totalCount - 1)
{
if(currIndex == totalCount - 1) {
// 线程关闭
if (_aniThread != nullptr)
{
if(_aniThread != nullptr) {
_spinBox->setValue(_unSteadyObj->getCurrentIndex());
_aniThread->stop(true);
_aniThread->quit();
@ -204,8 +209,7 @@ namespace Post
void AnimationToolBar::on_RunAnimation(RenderDataObject* obj, int index)
{
if (SetCurrObj(obj))
{
if(SetCurrObj(obj)) {
this->frameTo(index);
qApp->processEvents();
}
@ -213,6 +217,8 @@ namespace Post
void AnimationToolBar::on_NextFrame()
{
if(_unSteadyObj == nullptr)
return;
int totalCount = _unSteadyObj->getTotalCount();
if(totalCount < 2)
return;
@ -230,6 +236,8 @@ namespace Post
void AnimationToolBar::on_LastFrame()
{
if(_unSteadyObj == nullptr)
return;
int totalCount = _unSteadyObj->getTotalCount();
if(totalCount < 2)
return;
@ -244,8 +252,7 @@ namespace Post
void AnimationToolBar::slot_saveAnimation(RenderDataObject* obj, QString file, int fps)
{
if (SetCurrObj(obj))
{
if(SetCurrObj(obj)) {
this->setAviSetting(file, fps);
on_RunAnimation();
}
@ -259,14 +266,13 @@ namespace Post
void AnimationToolBar::slot_runAnimation()
{
if (_aniAction->text() == tr("run"))
{
if(_unSteadyObj == nullptr)
return;
if(_aniAction->text() == tr("run")) {
_aniAction->setIcon(QIcon("://QUI/post/stop.png"));
_aniAction->setText(tr("stop"));
_runAnimation = true;
}
else
{
} else {
_aniAction->setIcon(QIcon("://QUI/post/run.png"));
_aniAction->setText(tr("run"));
_runAnimation = false;
@ -282,36 +288,44 @@ namespace Post
if(index == (totalCount - 1))
index = 0;
for (index; index < totalCount; index++)
{
for(index; index < totalCount; index++) {
if(!_runAnimation)
break;
_runFinished = false;
QString code = QString("PostProcess.runAnimation(%1,%2)").arg(_unSteadyObj->getID()).arg(index);
QString code =
QString("PostProcess.runAnimation(%1,%2)").arg(_unSteadyObj->getID()).arg(index);
Py::PythonAgent::getInstance()->submit(code);
_runFinished = true;
}
// if (_runFinished && !_runAnimation)
// {
// QString code = QString("PostProcess.stopAnimation(%1,%2)").arg(_unSteadyObj->getID()).arg(_spinBox->value());
// QString code =
// QString("PostProcess.stopAnimation(%1,%2)").arg(_unSteadyObj->getID()).arg(_spinBox->value());
// Py::PythonAgent::getInstance()->submit(code);
//
// return;
// }
if (index == totalCount)
{
if(index == totalCount) {
_aniAction->setIcon(QIcon("://QUI/post/run.png"));
_aniAction->setText("run");
_runAnimation = false;
}
}
void AnimationToolBar::clearAllRenderObjSlot() {
this->setEnabled(false);
this->setEnableBtn(false);
_totalLabel->setText(QString(tr("Total: %1")).arg(0));
_spinBox->setMaximum(0);
_spinBox->setValue(0);
}
void AnimationToolBar::initToolBar()
{
auto addAction = [=](QString icon, QString text) -> QAction *
{
auto addAction = [=](QString icon, QString text) -> QAction* {
auto act = new QAction(this);
act->setObjectName("QAction");
act->setText(text);
@ -326,27 +340,27 @@ namespace Post
_nextAction = addAction("://QUI/post/next.png", QString(tr("next")));
_lastAction = addAction("://QUI/post/end.png", QString(tr("last")));
connect(_firstAction, &QAction::triggered, [=]
{
connect(_firstAction, &QAction::triggered, [=] {
auto id = _unSteadyObj->getID();
QString code = QString("PostProcess.firstFrame(%1)").arg(id);
Py::PythonAgent::getInstance()->submit(code); });
connect(_preAction, &QAction::triggered, [=]
{
Py::PythonAgent::getInstance()->submit(code);
});
connect(_preAction, &QAction::triggered, [=] {
auto id = _unSteadyObj->getID();
QString code = QString("PostProcess.proviousFrame(%1)").arg(id);
Py::PythonAgent::getInstance()->submit(code); });
Py::PythonAgent::getInstance()->submit(code);
});
connect(_aniAction, SIGNAL(triggered()), this, SLOT(slot_runAnimation()));
connect(_nextAction, &QAction::triggered, [=]
{
connect(_nextAction, &QAction::triggered, [=] {
auto id = _unSteadyObj->getID();
QString code = QString("PostProcess.nextFrame(%1)").arg(id);
Py::PythonAgent::getInstance()->submit(code); });
connect(_lastAction, &QAction::triggered, [=]
{
Py::PythonAgent::getInstance()->submit(code);
});
connect(_lastAction, &QAction::triggered, [=] {
auto id = _unSteadyObj->getID();
QString code = QString("PostProcess.lastFrame(%1)").arg(id);
Py::PythonAgent::getInstance()->submit(code); });
Py::PythonAgent::getInstance()->submit(code);
});
// connect(actFirst, SIGNAL(triggered()), this, SLOT(on_FirstFrame()));
// connect(actPre, SIGNAL(triggered()), this, SLOT(on_PreviousFrame()));
// connect(_aniAction, SIGNAL(triggered()), this, SLOT(on_RunAnimation()));
@ -375,10 +389,25 @@ namespace Post
this->addSeparator();
this->setEnabled(false);
this->setEnableBtn(false);
}
void AnimationToolBar::setEnableBtn(bool enable)
{
_firstAction->setEnabled(enable);
_preAction->setEnabled(enable);
_aniAction->setEnabled(enable);
_nextAction->setEnabled(enable);
_lastAction->setEnabled(enable);
_stepLabel->setEnabled(enable);
_spinBox->setEnabled(enable);
_totalLabel->setEnabled(enable);
}
void AnimationToolBar::on_SpinBoxValueChanged(int i)
{
if(_unSteadyObj == nullptr)
return;
auto rootObj = _unSteadyObj->getRootViewObject();
auto rootObject = dynamic_cast<RenderDataImportUnSteady*>(rootObj);
if(rootObject == nullptr)
@ -409,6 +438,8 @@ namespace Post
void AnimationToolBar::frameTo(int index)
{
if(_unSteadyObj == nullptr)
return;
int totalCount = _unSteadyObj->getTotalCount();
if(index < 0 || index >= totalCount)
return;
@ -433,4 +464,4 @@ namespace Post
_totalLabel->setText(tr("Total: 0"));
}
}
} // namespace Post

View File

@ -98,6 +98,8 @@ namespace Post {
private:
void initToolBar();
void setEnableBtn(bool enable);
private Q_SLOTS:
/**
* @brief spinBox
@ -110,7 +112,7 @@ namespace Post {
void on_LastFrame(RenderDataObject* obj);
void on_stopAnimation(RenderDataObject* obj,int index);
void slot_runAnimation();
void clearAllRenderObjSlot();
private:
GUI::MainWindow* _mainWindow{};

View File

@ -306,6 +306,10 @@ namespace Post
{
this->clear();
const int n = _dataManager->getRenderObjectListCount();
if(n == 0)
{
emit clearAllItemSig();
}
for (int i = 0; i < n; ++i)
{
auto vObj = _dataManager->getRenderObjectListAt(i);

View File

@ -26,6 +26,7 @@ namespace Post
signals:
void showPostRenderWindowSig(int id, int type);
void currentRenderDataChanged(RenderDataObject* obj);
void clearAllItemSig();
public:
QMultiHash<int, int> getSelectedData(RenderDataObject* obj = nullptr);