mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 03:40:05 +00:00 
			
		
		
		
	Timeline pause
This commit is contained in:
		
							parent
							
								
									41b9e25ea8
								
							
						
					
					
						commit
						ba1de683fa
					
				
					 6 changed files with 79 additions and 36 deletions
				
			
		|  | @ -682,11 +682,7 @@ void MainWindowImpl::ConnectAnimationSignals() | ||||||
|    connect(animationDockWidget_, |    connect(animationDockWidget_, | ||||||
|            &ui::AnimationDockWidget::AnimationPlaySelected, |            &ui::AnimationDockWidget::AnimationPlaySelected, | ||||||
|            timelineManager_.get(), |            timelineManager_.get(), | ||||||
|            &manager::TimelineManager::AnimationPlay); |            &manager::TimelineManager::AnimationPlayPause); | ||||||
|    connect(animationDockWidget_, |  | ||||||
|            &ui::AnimationDockWidget::AnimationPauseSelected, |  | ||||||
|            timelineManager_.get(), |  | ||||||
|            &manager::TimelineManager::AnimationPause); |  | ||||||
|    connect(animationDockWidget_, |    connect(animationDockWidget_, | ||||||
|            &ui::AnimationDockWidget::AnimationStepNextSelected, |            &ui::AnimationDockWidget::AnimationStepNextSelected, | ||||||
|            timelineManager_.get(), |            timelineManager_.get(), | ||||||
|  | @ -705,6 +701,11 @@ void MainWindowImpl::ConnectAnimationSignals() | ||||||
|                  map->SelectTime(dateTime); |                  map->SelectTime(dateTime); | ||||||
|               } |               } | ||||||
|            }); |            }); | ||||||
|  | 
 | ||||||
|  |    connect(timelineManager_.get(), | ||||||
|  |            &manager::TimelineManager::AnimationStateUpdated, | ||||||
|  |            animationDockWidget_, | ||||||
|  |            &ui::AnimationDockWidget::UpdateAnimationState); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void MainWindowImpl::ConnectOtherSignals() | void MainWindowImpl::ConnectOtherSignals() | ||||||
|  |  | ||||||
|  | @ -42,6 +42,7 @@ public: | ||||||
| 
 | 
 | ||||||
|    TimelineManager* self_; |    TimelineManager* self_; | ||||||
| 
 | 
 | ||||||
|  |    void Pause(); | ||||||
|    void Play(); |    void Play(); | ||||||
|    void SelectTime(std::chrono::system_clock::time_point selectedTime = {}); |    void SelectTime(std::chrono::system_clock::time_point selectedTime = {}); | ||||||
|    void Step(Direction direction); |    void Step(Direction direction); | ||||||
|  | @ -55,6 +56,7 @@ public: | ||||||
|    std::chrono::minutes                  loopTime_ {30}; |    std::chrono::minutes                  loopTime_ {30}; | ||||||
|    double                                loopSpeed_ {1.0}; |    double                                loopSpeed_ {1.0}; | ||||||
| 
 | 
 | ||||||
|  |    types::AnimationState     animationState_ {types::AnimationState::Pause}; | ||||||
|    boost::asio::steady_timer animationTimer_ {scwx::util::io_context()}; |    boost::asio::steady_timer animationTimer_ {scwx::util::io_context()}; | ||||||
|    std::mutex                animationTimerMutex_ {}; |    std::mutex                animationTimerMutex_ {}; | ||||||
| 
 | 
 | ||||||
|  | @ -145,6 +147,8 @@ void TimelineManager::AnimationStepBegin() | ||||||
| { | { | ||||||
|    logger_->debug("AnimationStepBegin"); |    logger_->debug("AnimationStepBegin"); | ||||||
| 
 | 
 | ||||||
|  |    p->Pause(); | ||||||
|  | 
 | ||||||
|    if (p->viewType_ == types::MapTime::Live || |    if (p->viewType_ == types::MapTime::Live || | ||||||
|        p->pinnedTime_ == std::chrono::system_clock::time_point {}) |        p->pinnedTime_ == std::chrono::system_clock::time_point {}) | ||||||
|    { |    { | ||||||
|  | @ -162,25 +166,29 @@ void TimelineManager::AnimationStepBack() | ||||||
| { | { | ||||||
|    logger_->debug("AnimationStepBack"); |    logger_->debug("AnimationStepBack"); | ||||||
| 
 | 
 | ||||||
|  |    p->Pause(); | ||||||
|    p->Step(Direction::Back); |    p->Step(Direction::Back); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void TimelineManager::AnimationPlay() | void TimelineManager::AnimationPlayPause() | ||||||
| { | { | ||||||
|    logger_->debug("AnimationPlay"); |    if (p->animationState_ == types::AnimationState::Pause) | ||||||
| 
 |    { | ||||||
|    p->Play(); |       logger_->debug("AnimationPlay"); | ||||||
| } |       p->Play(); | ||||||
| 
 |    } | ||||||
| void TimelineManager::AnimationPause() |    else | ||||||
| { |    { | ||||||
|    logger_->debug("AnimationPause"); |       logger_->debug("AnimationPause"); | ||||||
|  |       p->Pause(); | ||||||
|  |    } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void TimelineManager::AnimationStepNext() | void TimelineManager::AnimationStepNext() | ||||||
| { | { | ||||||
|    logger_->debug("AnimationStepNext"); |    logger_->debug("AnimationStepNext"); | ||||||
| 
 | 
 | ||||||
|  |    p->Pause(); | ||||||
|    p->Step(Direction::Next); |    p->Step(Direction::Next); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -188,6 +196,8 @@ void TimelineManager::AnimationStepEnd() | ||||||
| { | { | ||||||
|    logger_->debug("AnimationStepEnd"); |    logger_->debug("AnimationStepEnd"); | ||||||
| 
 | 
 | ||||||
|  |    p->Pause(); | ||||||
|  | 
 | ||||||
|    if (p->viewType_ == types::MapTime::Live) |    if (p->viewType_ == types::MapTime::Live) | ||||||
|    { |    { | ||||||
|       // If the selected view type is live, select the current products
 |       // If the selected view type is live, select the current products
 | ||||||
|  | @ -200,10 +210,29 @@ void TimelineManager::AnimationStepEnd() | ||||||
|    } |    } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void TimelineManager::Impl::Pause() | ||||||
|  | { | ||||||
|  |    // Cancel animation
 | ||||||
|  |    std::unique_lock animationTimerLock {animationTimerMutex_}; | ||||||
|  |    animationTimer_.cancel(); | ||||||
|  | 
 | ||||||
|  |    if (animationState_ != types::AnimationState::Pause) | ||||||
|  |    { | ||||||
|  |       animationState_ = types::AnimationState::Pause; | ||||||
|  |       emit self_->AnimationStateUpdated(animationState_); | ||||||
|  |    } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void TimelineManager::Impl::Play() | void TimelineManager::Impl::Play() | ||||||
| { | { | ||||||
|    using namespace std::chrono_literals; |    using namespace std::chrono_literals; | ||||||
| 
 | 
 | ||||||
|  |    if (animationState_ != types::AnimationState::Play) | ||||||
|  |    { | ||||||
|  |       animationState_ = types::AnimationState::Play; | ||||||
|  |       emit self_->AnimationStateUpdated(animationState_); | ||||||
|  |    } | ||||||
|  | 
 | ||||||
|    { |    { | ||||||
|       std::unique_lock animationTimerLock {animationTimerMutex_}; |       std::unique_lock animationTimerLock {animationTimerMutex_}; | ||||||
|       animationTimer_.cancel(); |       animationTimer_.cancel(); | ||||||
|  | @ -260,7 +289,10 @@ void TimelineManager::Impl::Play() | ||||||
|             { |             { | ||||||
|                if (e == boost::system::errc::success) |                if (e == boost::system::errc::success) | ||||||
|                { |                { | ||||||
|                   Play(); |                   if (animationState_ == types::AnimationState::Play) | ||||||
|  |                   { | ||||||
|  |                      Play(); | ||||||
|  |                   } | ||||||
|                } |                } | ||||||
|                else if (e == boost::asio::error::operation_aborted) |                else if (e == boost::asio::error::operation_aborted) | ||||||
|                { |                { | ||||||
|  |  | ||||||
|  | @ -35,8 +35,7 @@ public slots: | ||||||
| 
 | 
 | ||||||
|    void AnimationStepBegin(); |    void AnimationStepBegin(); | ||||||
|    void AnimationStepBack(); |    void AnimationStepBack(); | ||||||
|    void AnimationPlay(); |    void AnimationPlayPause(); | ||||||
|    void AnimationPause(); |  | ||||||
|    void AnimationStepNext(); |    void AnimationStepNext(); | ||||||
|    void AnimationStepEnd(); |    void AnimationStepEnd(); | ||||||
| 
 | 
 | ||||||
|  | @ -44,6 +43,7 @@ signals: | ||||||
|    void SelectedTimeUpdated(std::chrono::system_clock::time_point dateTime); |    void SelectedTimeUpdated(std::chrono::system_clock::time_point dateTime); | ||||||
|    void VolumeTimeUpdated(std::chrono::system_clock::time_point dateTime); |    void VolumeTimeUpdated(std::chrono::system_clock::time_point dateTime); | ||||||
| 
 | 
 | ||||||
|  |    void AnimationStateUpdated(types::AnimationState state); | ||||||
|    void ViewTypeUpdated(types::MapTime viewType); |    void ViewTypeUpdated(types::MapTime viewType); | ||||||
| 
 | 
 | ||||||
| private: | private: | ||||||
|  |  | ||||||
|  | @ -9,6 +9,12 @@ namespace qt | ||||||
| namespace types | namespace types | ||||||
| { | { | ||||||
| 
 | 
 | ||||||
|  | enum class AnimationState | ||||||
|  | { | ||||||
|  |    Play, | ||||||
|  |    Pause | ||||||
|  | }; | ||||||
|  | 
 | ||||||
| enum class MapTime | enum class MapTime | ||||||
| { | { | ||||||
|    Live, |    Live, | ||||||
|  |  | ||||||
|  | @ -16,21 +16,18 @@ namespace ui | ||||||
| static const std::string logPrefix_ = "scwx::qt::ui::animation_dock_widget"; | static const std::string logPrefix_ = "scwx::qt::ui::animation_dock_widget"; | ||||||
| static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | static const auto        logger_    = scwx::util::Logger::Create(logPrefix_); | ||||||
| 
 | 
 | ||||||
| enum class AnimationState |  | ||||||
| { |  | ||||||
|    Play, |  | ||||||
|    Pause |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| class AnimationDockWidgetImpl | class AnimationDockWidgetImpl | ||||||
| { | { | ||||||
| public: | public: | ||||||
|    explicit AnimationDockWidgetImpl(AnimationDockWidget* self) : self_ {self} {} |    explicit AnimationDockWidgetImpl(AnimationDockWidget* self) : self_ {self} {} | ||||||
|    ~AnimationDockWidgetImpl() = default; |    ~AnimationDockWidgetImpl() = default; | ||||||
| 
 | 
 | ||||||
|  |    const QIcon kPauseIcon_ {":/res/icons/font-awesome-6/pause-solid.svg"}; | ||||||
|  |    const QIcon kPlayIcon_ {":/res/icons/font-awesome-6/play-solid.svg"}; | ||||||
|  | 
 | ||||||
|    AnimationDockWidget* self_; |    AnimationDockWidget* self_; | ||||||
| 
 | 
 | ||||||
|    AnimationState animationState_ {AnimationState::Pause}; |    types::AnimationState animationState_ {types::AnimationState::Pause}; | ||||||
| 
 | 
 | ||||||
|    std::chrono::sys_days selectedDate_ {}; |    std::chrono::sys_days selectedDate_ {}; | ||||||
|    std::chrono::seconds  selectedTime_ {}; |    std::chrono::seconds  selectedTime_ {}; | ||||||
|  | @ -171,17 +168,7 @@ void AnimationDockWidgetImpl::ConnectSignals() | ||||||
|    QObject::connect(self_->ui->playButton, |    QObject::connect(self_->ui->playButton, | ||||||
|                     &QAbstractButton::clicked, |                     &QAbstractButton::clicked, | ||||||
|                     self_, |                     self_, | ||||||
|                     [this]() |                     [this]() { emit self_->AnimationPlaySelected(); }); | ||||||
|                     { |  | ||||||
|                        if (animationState_ == AnimationState::Pause) |  | ||||||
|                        { |  | ||||||
|                           emit self_->AnimationPlaySelected(); |  | ||||||
|                        } |  | ||||||
|                        else |  | ||||||
|                        { |  | ||||||
|                           emit self_->AnimationPauseSelected(); |  | ||||||
|                        } |  | ||||||
|                     }); |  | ||||||
|    QObject::connect(self_->ui->stepNextButton, |    QObject::connect(self_->ui->stepNextButton, | ||||||
|                     &QAbstractButton::clicked, |                     &QAbstractButton::clicked, | ||||||
|                     self_, |                     self_, | ||||||
|  | @ -192,6 +179,21 @@ void AnimationDockWidgetImpl::ConnectSignals() | ||||||
|                     [this]() { emit self_->AnimationStepEndSelected(); }); |                     [this]() { emit self_->AnimationStepEndSelected(); }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void AnimationDockWidget::UpdateAnimationState(types::AnimationState state) | ||||||
|  | { | ||||||
|  |    // Update icon to opposite of state
 | ||||||
|  |    switch (state) | ||||||
|  |    { | ||||||
|  |    case types::AnimationState::Pause: | ||||||
|  |       ui->playButton->setIcon(p->kPlayIcon_); | ||||||
|  |       break; | ||||||
|  | 
 | ||||||
|  |    case types::AnimationState::Play: | ||||||
|  |       ui->playButton->setIcon(p->kPauseIcon_); | ||||||
|  |       break; | ||||||
|  |    } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| } // namespace ui
 | } // namespace ui
 | ||||||
| } // namespace qt
 | } // namespace qt
 | ||||||
| } // namespace scwx
 | } // namespace scwx
 | ||||||
|  |  | ||||||
|  | @ -28,6 +28,9 @@ public: | ||||||
|    explicit AnimationDockWidget(QWidget* parent = nullptr); |    explicit AnimationDockWidget(QWidget* parent = nullptr); | ||||||
|    ~AnimationDockWidget(); |    ~AnimationDockWidget(); | ||||||
| 
 | 
 | ||||||
|  | public slots: | ||||||
|  |    void UpdateAnimationState(types::AnimationState state); | ||||||
|  | 
 | ||||||
| signals: | signals: | ||||||
|    void ViewTypeChanged(types::MapTime viewType); |    void ViewTypeChanged(types::MapTime viewType); | ||||||
|    void DateTimeChanged(std::chrono::system_clock::time_point dateTime); |    void DateTimeChanged(std::chrono::system_clock::time_point dateTime); | ||||||
|  | @ -37,7 +40,6 @@ signals: | ||||||
| 
 | 
 | ||||||
|    void AnimationStepBeginSelected(); |    void AnimationStepBeginSelected(); | ||||||
|    void AnimationStepBackSelected(); |    void AnimationStepBackSelected(); | ||||||
|    void AnimationPauseSelected(); |  | ||||||
|    void AnimationPlaySelected(); |    void AnimationPlaySelected(); | ||||||
|    void AnimationStepNextSelected(); |    void AnimationStepNextSelected(); | ||||||
|    void AnimationStepEndSelected(); |    void AnimationStepEndSelected(); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat