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)) {
|
||||
|
||||
// advance the replay window for the next time period
|
||||
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++) {
|
||||
if (m_timeStamps.at(i) >= desiredPosition) {
|
||||
|
||||
int bytesToSkip = m_timeStampPositions.at(i);
|
||||
bool seek_ok = m_file.seek(bytesToSkip);
|
||||
if (!seek_ok) {
|
||||
|
@ -36,8 +36,8 @@
|
||||
<item>
|
||||
<widget class="QPushButton" name="playPauseButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>80</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
@ -47,11 +47,17 @@
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string> Play</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../logging/res.qrc">
|
||||
<iconset resource="res.qrc">
|
||||
<normaloff>:/logging/images/play.png</normaloff>:/logging/images/play.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
@ -65,8 +71,8 @@
|
||||
<item>
|
||||
<widget class="QPushButton" name="stopButton">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||
<horstretch>80</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
@ -76,11 +82,17 @@
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>80</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string> Stop</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../logging/res.qrc">
|
||||
<iconset resource="res.qrc">
|
||||
<normaloff>:/logging/images/stop.png</normaloff>:/logging/images/stop.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
@ -113,6 +125,12 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="playbackSpeed">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="decimals">
|
||||
<number>1</number>
|
||||
</property>
|
||||
@ -203,6 +221,12 @@
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
@ -229,6 +253,12 @@
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
@ -255,6 +285,12 @@
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
@ -283,7 +319,7 @@
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../logging/res.qrc"/>
|
||||
<include location="res.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -41,6 +41,9 @@ LoggingGadgetWidget::LoggingGadgetWidget(QWidget *parent) : QWidget(parent), log
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
scpPlugin = pm->getObject<ScopeGadgetFactory>();
|
||||
|
||||
// Store preferred button width before manipulating the button appearance
|
||||
m_preferredButtonWidth = m_logging->playPauseButton->sizeHint().width();
|
||||
|
||||
disableButtons();
|
||||
|
||||
// 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
|
||||
connect(logFile, &LogFile::replayFinished, scpPlugin, &ScopeGadgetFactory::stopPlotting);
|
||||
|
||||
|
||||
// Perform actions as if the plugin state has been changed
|
||||
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()
|
||||
@ -100,19 +122,27 @@ void LoggingGadgetWidget::setPlugin(LoggingPlugin *p)
|
||||
void LoggingGadgetWidget::setPlayPauseButtonToPlay()
|
||||
{
|
||||
m_logging->playPauseButton->setIcon(QIcon(":/logging/images/play.png"));
|
||||
if (m_iconOnlyButtons) {
|
||||
m_logging->playPauseButton->setText(QString());
|
||||
} else {
|
||||
m_logging->playPauseButton->setText(tr(" Play"));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
setPlayPauseButtonToPlay()
|
||||
setPlayPauseButtonToPause()
|
||||
|
||||
Changes the appearance of the playPause button to the PAUSE appearance.
|
||||
*/
|
||||
void LoggingGadgetWidget::setPlayPauseButtonToPause()
|
||||
{
|
||||
m_logging->playPauseButton->setIcon(QIcon(":/logging/images/pause.png"));
|
||||
if (m_iconOnlyButtons) {
|
||||
m_logging->playPauseButton->setText(QString());
|
||||
} else {
|
||||
m_logging->playPauseButton->setText(tr(" Pause"));
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
if (!m_logging->playBackPosition->isSliderDown() && !sliderActionDelay.isActive()) {
|
||||
|
||||
// Block signals during slider position update:
|
||||
m_logging->playBackPosition->blockSignals(true);
|
||||
m_logging->playBackPosition->setValue(positionTimeStamp);
|
||||
@ -217,8 +246,7 @@ void LoggingGadgetWidget::enableButtons()
|
||||
{
|
||||
ReplayState replayState = (loggingPlugin->getLogfile())->getReplayStatus();
|
||||
|
||||
switch (replayState)
|
||||
{
|
||||
switch (replayState) {
|
||||
case STOPPED:
|
||||
m_logging->stopButton->setEnabled(false);
|
||||
setPlayPauseButtonToPlay();
|
||||
@ -240,7 +268,6 @@ void LoggingGadgetWidget::enableButtons()
|
||||
|
||||
void LoggingGadgetWidget::disableButtons()
|
||||
{
|
||||
|
||||
m_logging->playPauseButton->setEnabled(false);
|
||||
setPlayPauseButtonToPlay();
|
||||
m_logging->stopButton->setEnabled(false);
|
||||
@ -248,11 +275,40 @@ void LoggingGadgetWidget::disableButtons()
|
||||
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)
|
||||
{
|
||||
// update position label -> MM:SS
|
||||
int sec = (positionTimeStamp / 1000) % 60;
|
||||
int min = positionTimeStamp / (60 * 1000);
|
||||
|
||||
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;
|
||||
ScopeGadgetFactory *scpPlugin;
|
||||
QTimer sliderActionDelay;
|
||||
bool m_iconOnlyButtons;
|
||||
int m_preferredButtonWidth;
|
||||
|
||||
void updatePositionLabel(quint32 positionTimeStamp);
|
||||
void setPlayPauseButtonToPlay();
|
||||
void setPlayPauseButtonToPause();
|
||||
void updateButtonAppearance();
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
};
|
||||
|
||||
#endif /* LoggingGADGETWIDGET_H_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user