修改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,46 +14,55 @@
#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)
: QToolBar(mainWindow), _mainWindow(mainWindow), _treeWidget(tree) , _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()));
} }
bool AnimationToolBar::SetCurrObj(RenderDataObject *obj) bool AnimationToolBar::SetCurrObj(RenderDataObject* obj)
{ {
_unSteadyObj = dynamic_cast<RenderDataImportUnSteady *>(obj->getRootViewObject()); _unSteadyObj = dynamic_cast<RenderDataImportUnSteady*>(obj->getRootViewObject());
// _unSteadyObj = dynamic_cast<RenderDataImportUnSteady*>(obj); // _unSteadyObj = dynamic_cast<RenderDataImportUnSteady*>(obj);
if (_unSteadyObj == nullptr) if(_unSteadyObj == nullptr)
return false; return false;
return true; return true;
} }
void AnimationToolBar::on_currentRenderDataChanged(RenderDataObject *vobj) void AnimationToolBar::on_currentRenderDataChanged(RenderDataObject* vobj)
{ {
auto rObj = vobj->getRootViewObject(); if(vobj == nullptr)
if (_unSteadyObj == rObj)
return; return;
_unSteadyObj = dynamic_cast<RenderDataImportUnSteady *>(rObj); auto rObj = vobj->getRootViewObject();
if(_unSteadyObj == rObj)
return;
_unSteadyObj = dynamic_cast<RenderDataImportUnSteady*>(rObj);
// if (_unSteadyObj == vobj) return; // if (_unSteadyObj == vobj) return;
// _unSteadyObj = dynamic_cast<RenderDataImportUnSteady*>(vobj); // _unSteadyObj = dynamic_cast<RenderDataImportUnSteady*>(vobj);
this->setEnabled(false); this->setEnabled(false);
if (_unSteadyObj == nullptr) this->setEnableBtn(false);
if(_unSteadyObj == nullptr)
return; return;
const int n = _unSteadyObj->getTotalCount(); const int n = _unSteadyObj->getTotalCount();
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,50 +72,53 @@ 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;
_spinBox->setValue(0); _spinBox->setValue(0);
} }
void AnimationToolBar::on_FirstFrame(RenderDataObject *obj) void AnimationToolBar::on_FirstFrame(RenderDataObject* obj)
{ {
if (SetCurrObj(obj)) if(SetCurrObj(obj))
on_FirstFrame(); on_FirstFrame();
} }
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;
int currIndex = _spinBox->value(); int currIndex = _spinBox->value();
if (currIndex <= 0) if(currIndex <= 0)
return; return;
_spinBox->setValue(currIndex - 1); _spinBox->setValue(currIndex - 1);
} }
void AnimationToolBar::on_PreviousFrame(RenderDataObject *obj) void AnimationToolBar::on_PreviousFrame(RenderDataObject* obj)
{ {
if (SetCurrObj(obj)) if(SetCurrObj(obj))
on_PreviousFrame(); on_PreviousFrame();
} }
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;
@ -119,13 +131,12 @@ namespace Post
emit sig_terminateGenerateAvi(); emit sig_terminateGenerateAvi();
return; //返回 return; // 返回
} }
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();
@ -181,12 +188,10 @@ 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();
@ -197,15 +202,14 @@ namespace Post
_aniAction->setIcon(QIcon("://QUI/post/run.png")); _aniAction->setIcon(QIcon("://QUI/post/run.png"));
_aniAction->setText(tr("run")); _aniAction->setText(tr("run"));
//发送结束信号 // 发送结束信号
emit sig_terminateGenerateAvi(); emit sig_terminateGenerateAvi();
} }
} }
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,105 +217,115 @@ 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;
int currIndex = _spinBox->value(); int currIndex = _spinBox->value();
if (currIndex >= (totalCount - 1)) if(currIndex >= (totalCount - 1))
return; return;
_spinBox->setValue(currIndex + 1); _spinBox->setValue(currIndex + 1);
} }
void AnimationToolBar::on_NextFrame(RenderDataObject *obj) void AnimationToolBar::on_NextFrame(RenderDataObject* obj)
{ {
if (SetCurrObj(obj)) if(SetCurrObj(obj))
on_NextFrame(); on_NextFrame();
} }
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;
_spinBox->setValue(totalCount - 1); _spinBox->setValue(totalCount - 1);
} }
void AnimationToolBar::on_LastFrame(RenderDataObject *obj) void AnimationToolBar::on_LastFrame(RenderDataObject* obj)
{ {
if (SetCurrObj(obj)) if(SetCurrObj(obj))
on_LastFrame(); on_LastFrame();
} }
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();
} }
} }
void AnimationToolBar::on_stopAnimation(RenderDataObject *obj, int index) void AnimationToolBar::on_stopAnimation(RenderDataObject* obj, int index)
{ {
if (SetCurrObj(obj)) if(SetCurrObj(obj))
this->frameTo(index); this->frameTo(index);
} }
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;
} }
int totalCount = _unSteadyObj->getTotalCount(); int totalCount = _unSteadyObj->getTotalCount();
if (totalCount < 2) if(totalCount < 2)
return; return;
auto index = _spinBox->value(); auto index = _spinBox->value();
if (index < 0 || index >= totalCount) if(index < 0 || index >= totalCount)
return; return;
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()));
@ -355,7 +369,7 @@ namespace Post
this->addSeparator(); this->addSeparator();
QAction *action = nullptr; QAction* action = nullptr;
_stepLabel = new QLabel(this); _stepLabel = new QLabel(this);
_stepLabel->setText(tr("Step:")); _stepLabel->setText(tr("Step:"));
action = this->addWidget(_stepLabel); action = this->addWidget(_stepLabel);
@ -375,13 +389,28 @@ 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)
return; return;
rootObject->setAnimationIndex(i); rootObject->setAnimationIndex(i);
_unSteadyObj->update(); _unSteadyObj->update();
@ -389,7 +418,7 @@ namespace Post
// refresh window // refresh window
int winID = _unSteadyObj->getRenderWinID(); int winID = _unSteadyObj->getRenderWinID();
auto graphWindow = RenderWindowManager::getInstance()->getRenderWindowByID(winID); auto graphWindow = RenderWindowManager::getInstance()->getRenderWindowByID(winID);
if (graphWindow == nullptr) if(graphWindow == nullptr)
return; return;
graphWindow->reRender(); graphWindow->reRender();
} }
@ -401,7 +430,7 @@ namespace Post
_aniAviTool->frameRate = fps; _aniAviTool->frameRate = fps;
} }
void AnimationToolBar::getAviSetting(QString &aviSavePath, int &fps) void AnimationToolBar::getAviSetting(QString& aviSavePath, int& fps)
{ {
aviSavePath = _aniAviTool->aviFilePath; aviSavePath = _aniAviTool->aviFilePath;
fps = _aniAviTool->frameRate; fps = _aniAviTool->frameRate;
@ -409,15 +438,17 @@ 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;
_spinBox->setValue(index); _spinBox->setValue(index);
} }
int AnimationToolBar::getCurrentObjectID() int AnimationToolBar::getCurrentObjectID()
{ {
if (_unSteadyObj == nullptr) if(_unSteadyObj == nullptr)
return -1; return -1;
return _unSteadyObj->getID(); return _unSteadyObj->getID();
} }
@ -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);