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

View File

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

View File

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

View File

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