mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-30 15:52:12 +01:00
LP-597 Progress bar for GCS log replay - Resize playPause and stop buttons according to the available space for the widget.
- also make pretty
This commit is contained in:
parent
d540c2a043
commit
fa70cb751c
@ -177,7 +177,6 @@ void LogFile::timerFired()
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
while (m_nextTimeStamp < (m_lastPlayed + (double)(time - m_timeOffset) * m_playbackSpeed)) {
|
while (m_nextTimeStamp < (m_lastPlayed + (double)(time - m_timeOffset) * m_playbackSpeed)) {
|
||||||
|
|
||||||
// advance the replay window for the next time period
|
// advance the replay window for the next time period
|
||||||
m_lastPlayed += ((double)(time - m_timeOffset) * m_playbackSpeed);
|
m_lastPlayed += ((double)(time - m_timeOffset) * m_playbackSpeed);
|
||||||
|
|
||||||
@ -347,7 +346,6 @@ bool LogFile::resumeReplay(quint32 desiredPosition)
|
|||||||
*/
|
*/
|
||||||
for (int i = 0; i < m_timeStamps.size(); i++) {
|
for (int i = 0; i < m_timeStamps.size(); i++) {
|
||||||
if (m_timeStamps.at(i) >= desiredPosition) {
|
if (m_timeStamps.at(i) >= desiredPosition) {
|
||||||
|
|
||||||
int bytesToSkip = m_timeStampPositions.at(i);
|
int bytesToSkip = m_timeStampPositions.at(i);
|
||||||
bool seek_ok = m_file.seek(bytesToSkip);
|
bool seek_ok = m_file.seek(bytesToSkip);
|
||||||
if (!seek_ok) {
|
if (!seek_ok) {
|
||||||
|
@ -36,8 +36,8 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="playPauseButton">
|
<widget class="QPushButton" name="playPauseButton">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>80</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
@ -47,11 +47,17 @@
|
|||||||
<height>0</height>
|
<height>0</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>80</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string> Play</string>
|
<string> Play</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../logging/res.qrc">
|
<iconset resource="res.qrc">
|
||||||
<normaloff>:/logging/images/play.png</normaloff>:/logging/images/play.png</iconset>
|
<normaloff>:/logging/images/play.png</normaloff>:/logging/images/play.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
@ -65,8 +71,8 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="stopButton">
|
<widget class="QPushButton" name="stopButton">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>80</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
@ -76,11 +82,17 @@
|
|||||||
<height>0</height>
|
<height>0</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>80</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string> Stop</string>
|
<string> Stop</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../logging/res.qrc">
|
<iconset resource="res.qrc">
|
||||||
<normaloff>:/logging/images/stop.png</normaloff>:/logging/images/stop.png</iconset>
|
<normaloff>:/logging/images/stop.png</normaloff>:/logging/images/stop.png</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="iconSize">
|
<property name="iconSize">
|
||||||
@ -113,6 +125,12 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QDoubleSpinBox" name="playbackSpeed">
|
<widget class="QDoubleSpinBox" name="playbackSpeed">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
<property name="decimals">
|
<property name="decimals">
|
||||||
<number>1</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
@ -203,6 +221,12 @@
|
|||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
@ -229,6 +253,12 @@
|
|||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
@ -255,6 +285,12 @@
|
|||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
@ -283,7 +319,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="../logging/res.qrc"/>
|
<include location="res.qrc"/>
|
||||||
</resources>
|
</resources>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
@ -41,6 +41,9 @@ LoggingGadgetWidget::LoggingGadgetWidget(QWidget *parent) : QWidget(parent), log
|
|||||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||||
scpPlugin = pm->getObject<ScopeGadgetFactory>();
|
scpPlugin = pm->getObject<ScopeGadgetFactory>();
|
||||||
|
|
||||||
|
// Store preferred button width before manipulating the button appearance
|
||||||
|
m_preferredButtonWidth = m_logging->playPauseButton->sizeHint().width();
|
||||||
|
|
||||||
disableButtons();
|
disableButtons();
|
||||||
|
|
||||||
// Configure timer to delay application of slider position action for 200ms
|
// Configure timer to delay application of slider position action for 200ms
|
||||||
@ -87,10 +90,29 @@ void LoggingGadgetWidget::setPlugin(LoggingPlugin *p)
|
|||||||
// Feedback from logfile to scope
|
// Feedback from logfile to scope
|
||||||
connect(logFile, &LogFile::replayFinished, scpPlugin, &ScopeGadgetFactory::stopPlotting);
|
connect(logFile, &LogFile::replayFinished, scpPlugin, &ScopeGadgetFactory::stopPlotting);
|
||||||
|
|
||||||
|
// Perform actions as if the plugin state has been changed
|
||||||
stateChanged(loggingPlugin->getState());
|
stateChanged(loggingPlugin->getState());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
resizeEvent()
|
||||||
|
|
||||||
|
Determine button content policy based on button size.
|
||||||
|
|
||||||
|
*/
|
||||||
|
void LoggingGadgetWidget::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
int width = m_logging->playPauseButton->size().width();
|
||||||
|
|
||||||
|
if (width < m_preferredButtonWidth) {
|
||||||
|
m_iconOnlyButtons = true;
|
||||||
|
} else {
|
||||||
|
m_iconOnlyButtons = false;
|
||||||
|
}
|
||||||
|
updateButtonAppearance();
|
||||||
|
|
||||||
|
QWidget::resizeEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
setPlayPauseButtonToPlay()
|
setPlayPauseButtonToPlay()
|
||||||
@ -100,19 +122,27 @@ void LoggingGadgetWidget::setPlugin(LoggingPlugin *p)
|
|||||||
void LoggingGadgetWidget::setPlayPauseButtonToPlay()
|
void LoggingGadgetWidget::setPlayPauseButtonToPlay()
|
||||||
{
|
{
|
||||||
m_logging->playPauseButton->setIcon(QIcon(":/logging/images/play.png"));
|
m_logging->playPauseButton->setIcon(QIcon(":/logging/images/play.png"));
|
||||||
|
if (m_iconOnlyButtons) {
|
||||||
|
m_logging->playPauseButton->setText(QString());
|
||||||
|
} else {
|
||||||
m_logging->playPauseButton->setText(tr(" Play"));
|
m_logging->playPauseButton->setText(tr(" Play"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
setPlayPauseButtonToPlay()
|
setPlayPauseButtonToPause()
|
||||||
|
|
||||||
Changes the appearance of the playPause button to the PAUSE appearance.
|
Changes the appearance of the playPause button to the PAUSE appearance.
|
||||||
*/
|
*/
|
||||||
void LoggingGadgetWidget::setPlayPauseButtonToPause()
|
void LoggingGadgetWidget::setPlayPauseButtonToPause()
|
||||||
{
|
{
|
||||||
m_logging->playPauseButton->setIcon(QIcon(":/logging/images/pause.png"));
|
m_logging->playPauseButton->setIcon(QIcon(":/logging/images/pause.png"));
|
||||||
|
if (m_iconOnlyButtons) {
|
||||||
|
m_logging->playPauseButton->setText(QString());
|
||||||
|
} else {
|
||||||
m_logging->playPauseButton->setText(tr(" Pause"));
|
m_logging->playPauseButton->setText(tr(" Pause"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LoggingGadgetWidget::playPauseButtonAction()
|
void LoggingGadgetWidget::playPauseButtonAction()
|
||||||
{
|
{
|
||||||
@ -202,7 +232,6 @@ void LoggingGadgetWidget::playbackPosition(quint32 positionTimeStamp)
|
|||||||
{
|
{
|
||||||
// Update position bar, but only if the user is not updating the slider position
|
// Update position bar, but only if the user is not updating the slider position
|
||||||
if (!m_logging->playBackPosition->isSliderDown() && !sliderActionDelay.isActive()) {
|
if (!m_logging->playBackPosition->isSliderDown() && !sliderActionDelay.isActive()) {
|
||||||
|
|
||||||
// Block signals during slider position update:
|
// Block signals during slider position update:
|
||||||
m_logging->playBackPosition->blockSignals(true);
|
m_logging->playBackPosition->blockSignals(true);
|
||||||
m_logging->playBackPosition->setValue(positionTimeStamp);
|
m_logging->playBackPosition->setValue(positionTimeStamp);
|
||||||
@ -217,8 +246,7 @@ void LoggingGadgetWidget::enableButtons()
|
|||||||
{
|
{
|
||||||
ReplayState replayState = (loggingPlugin->getLogfile())->getReplayStatus();
|
ReplayState replayState = (loggingPlugin->getLogfile())->getReplayStatus();
|
||||||
|
|
||||||
switch (replayState)
|
switch (replayState) {
|
||||||
{
|
|
||||||
case STOPPED:
|
case STOPPED:
|
||||||
m_logging->stopButton->setEnabled(false);
|
m_logging->stopButton->setEnabled(false);
|
||||||
setPlayPauseButtonToPlay();
|
setPlayPauseButtonToPlay();
|
||||||
@ -240,7 +268,6 @@ void LoggingGadgetWidget::enableButtons()
|
|||||||
|
|
||||||
void LoggingGadgetWidget::disableButtons()
|
void LoggingGadgetWidget::disableButtons()
|
||||||
{
|
{
|
||||||
|
|
||||||
m_logging->playPauseButton->setEnabled(false);
|
m_logging->playPauseButton->setEnabled(false);
|
||||||
setPlayPauseButtonToPlay();
|
setPlayPauseButtonToPlay();
|
||||||
m_logging->stopButton->setEnabled(false);
|
m_logging->stopButton->setEnabled(false);
|
||||||
@ -248,11 +275,40 @@ void LoggingGadgetWidget::disableButtons()
|
|||||||
m_logging->playBackPosition->setEnabled(false);
|
m_logging->playBackPosition->setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LoggingGadgetWidget::updateButtonAppearance()
|
||||||
|
{
|
||||||
|
ReplayState replayState;
|
||||||
|
|
||||||
|
if (!loggingPlugin || !loggingPlugin->getLogfile()) {
|
||||||
|
// loggingPlugin has not been completely initialized: set to STOPPED state
|
||||||
|
replayState = STOPPED;
|
||||||
|
} else {
|
||||||
|
replayState = (loggingPlugin->getLogfile())->getReplayStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update playPause button appearance
|
||||||
|
if (replayState == PLAYING) {
|
||||||
|
// Playing: playPause button must appear as a pause button
|
||||||
|
setPlayPauseButtonToPause();
|
||||||
|
} else {
|
||||||
|
// Stopped or Paused: playPause button must appear as a play button
|
||||||
|
setPlayPauseButtonToPlay();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update stop button appearance
|
||||||
|
if (m_iconOnlyButtons) {
|
||||||
|
m_logging->stopButton->setText(QString());
|
||||||
|
} else {
|
||||||
|
m_logging->stopButton->setText(tr(" Stop"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void LoggingGadgetWidget::updatePositionLabel(quint32 positionTimeStamp)
|
void LoggingGadgetWidget::updatePositionLabel(quint32 positionTimeStamp)
|
||||||
{
|
{
|
||||||
// update position label -> MM:SS
|
// update position label -> MM:SS
|
||||||
int sec = (positionTimeStamp / 1000) % 60;
|
int sec = (positionTimeStamp / 1000) % 60;
|
||||||
int min = positionTimeStamp / (60 * 1000);
|
int min = positionTimeStamp / (60 * 1000);
|
||||||
|
|
||||||
m_logging->positionTimestampLabel->setText(QString("%1:%2").arg(min, 2, 10, QChar('0')).arg(sec, 2, 10, QChar('0')));
|
m_logging->positionTimestampLabel->setText(QString("%1:%2").arg(min, 2, 10, QChar('0')).arg(sec, 2, 10, QChar('0')));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +329,6 @@ void LoggingGadgetWidget::sliderAction()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
* @}
|
* @}
|
||||||
|
@ -68,10 +68,14 @@ private:
|
|||||||
LoggingPlugin *loggingPlugin;
|
LoggingPlugin *loggingPlugin;
|
||||||
ScopeGadgetFactory *scpPlugin;
|
ScopeGadgetFactory *scpPlugin;
|
||||||
QTimer sliderActionDelay;
|
QTimer sliderActionDelay;
|
||||||
|
bool m_iconOnlyButtons;
|
||||||
|
int m_preferredButtonWidth;
|
||||||
|
|
||||||
void updatePositionLabel(quint32 positionTimeStamp);
|
void updatePositionLabel(quint32 positionTimeStamp);
|
||||||
void setPlayPauseButtonToPlay();
|
void setPlayPauseButtonToPlay();
|
||||||
void setPlayPauseButtonToPause();
|
void setPlayPauseButtonToPause();
|
||||||
|
void updateButtonAppearance();
|
||||||
|
void resizeEvent(QResizeEvent *event);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* LoggingGADGETWIDGET_H_ */
|
#endif /* LoggingGADGETWIDGET_H_ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user