1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

LP-597 again 3 separate buttons + various fixes & cleanups

Suggested by Philippe Renon:
- change the combined play-pause button to separate play and pause buttons. Hide button irrelevant button.
  Code has been simplified as a result.

Fixes:
- fix situation where replay is stopped/paused and logfile is disconnected through the Disconnect button.
- remove unneeded stuff (resizing related)
- rename updateBeginAndEndTimes -> setBeginAndEndTimes
- less base height needed for the widget
- wordwrap for "Playback speed" label. Wraps when space constrains.
- set a fixed width for statusLabel to prevent jumping around when the text changes
- Update the statusLabel to "Paused" when stopped/paused.
- rename enableButtons -> enableWidgets
- clear start and end text labels when playback has finished.
This commit is contained in:
Jan NIJS 2018-05-04 21:31:20 +02:00
parent ecd6d20b13
commit 684849f33c
5 changed files with 135 additions and 156 deletions

View File

@ -305,11 +305,14 @@ bool LogFile::startReplay()
*/
bool LogFile::stopReplay()
{
if (!m_file.isOpen() || !m_timer.isActive()) {
if (!m_file.isOpen()) {
return false;
}
if (m_timer.isActive()) {
m_timer.stop();
}
qDebug() << "LogFile - stopReplay";
m_timer.stop();
m_replayState = STOPPED;
emit replayFinished();
@ -386,9 +389,6 @@ bool LogFile::pauseReplay()
qDebug() << "LogFile - pauseReplay";
m_timer.stop();
m_replayState = PAUSED;
// hack to notify UI that replay paused
emit replayStarted();
return true;
}
@ -527,7 +527,7 @@ bool LogFile::buildIndex()
}
}
emit updateBeginAndEndTimes(m_beginTimeStamp, m_endTimeStamp);
emit setBeginAndEndTimes(m_beginTimeStamp, m_endTimeStamp);
// reset the read pointer to the start of the file
m_file.seek(0);

View File

@ -99,7 +99,7 @@ signals:
void replayStarted();
void replayFinished();
void setPlaybackPosition(quint32);
void updateBeginAndEndTimes(quint32, quint32);
void setBeginAndEndTimes(quint32, quint32);
protected:
QByteArray m_dataBuffer;

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>439</width>
<height>118</height>
<height>120</height>
</rect>
</property>
<property name="sizePolicy">
@ -27,34 +27,43 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,1">
<item>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>3</number>
</property>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,2,0,0,2,0,0">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,2,0,0,2,0,0">
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
<item>
<widget class="QPushButton" name="playPauseButton">
<widget class="QPushButton" name="playButton">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>80</horstretch>
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>30</width>
<height>0</height>
<width>39</width>
<height>38</height>
</size>
</property>
<property name="maximumSize">
<property name="baseSize">
<size>
<width>80</width>
<height>16777215</height>
<width>39</width>
<height>38</height>
</size>
</property>
<property name="text">
<string> Play</string>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="res.qrc">
@ -69,27 +78,44 @@
</widget>
</item>
<item>
<widget class="QPushButton" name="stopButton">
<widget class="QPushButton" name="pauseButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>80</horstretch>
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>30</width>
<height>0</height>
<width>39</width>
<height>38</height>
</size>
</property>
<property name="maximumSize">
<property name="icon">
<iconset resource="res.qrc">
<normaloff>:/logging/images/pause.png</normaloff>:/logging/images/pause.png</iconset>
</property>
<property name="iconSize">
<size>
<width>80</width>
<height>16777215</height>
<width>16</width>
<height>16</height>
</size>
</property>
<property name="text">
<string> Stop</string>
</widget>
</item>
<item>
<widget class="QPushButton" name="stopButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>39</width>
<height>38</height>
</size>
</property>
<property name="icon">
<iconset resource="res.qrc">
@ -121,12 +147,15 @@
<property name="text">
<string>Playback speed:</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="playbackSpeed">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<sizepolicy hsizetype="Fixed" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -170,6 +199,12 @@
</item>
<item>
<widget class="QLabel" name="statusLabel">
<property name="minimumSize">
<size>
<width>65</width>
<height>0</height>
</size>
</property>
<property name="font">
<font>
<weight>75</weight>
@ -184,29 +219,20 @@
</layout>
</item>
<item>
<widget class="QSlider" name="playBackPosition">
<widget class="QSlider" name="playbackPosition">
<property name="tracking">
<bool>true</bool>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="invertedAppearance">
<bool>false</bool>
</property>
<property name="invertedControls">
<bool>false</bool>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBothSides</enum>
</property>
<property name="tickInterval">
<number>5</number>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<property name="spacing">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
@ -230,6 +256,9 @@
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item>
@ -262,6 +291,9 @@
<property name="text">
<string/>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item>
@ -295,7 +327,7 @@
<string/>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<set>Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing</set>
</property>
</widget>
</item>

View File

@ -42,10 +42,7 @@ 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();
disableWidgets();
// Configure timer to delay application of slider position action for 200ms
sliderActionDelay.setSingleShot(true);
@ -65,7 +62,8 @@ void LoggingGadgetWidget::setPlugin(LoggingPlugin *p)
LogFile *logFile = loggingPlugin->getLogfile();
// GUI elements to gadgetwidget functions
connect(m_logging->playPauseButton, &QPushButton::clicked, this, &LoggingGadgetWidget::playPauseButtonAction);
connect(m_logging->playButton, &QPushButton::clicked, this, &LoggingGadgetWidget::playButtonAction);
connect(m_logging->pauseButton, &QPushButton::clicked, this, &LoggingGadgetWidget::pauseButtonAction);
connect(m_logging->stopButton, &QPushButton::clicked, this, &LoggingGadgetWidget::stopButtonAction);
connect(m_logging->playbackPosition, &QSlider::valueChanged, this, &LoggingGadgetWidget::sliderMoved);
@ -83,10 +81,10 @@ void LoggingGadgetWidget::setPlugin(LoggingPlugin *p)
// Feedback from logfile to GUI
connect(loggingPlugin, &LoggingPlugin::stateChanged, this, &LoggingGadgetWidget::stateChanged);
connect(logFile, &LogFile::updateBeginAndEndTimes, this, &LoggingGadgetWidget::updateBeginAndEndTimes);
connect(logFile, &LogFile::setBeginAndEndTimes, this, &LoggingGadgetWidget::setBeginAndEndTimes);
connect(logFile, &LogFile::setPlaybackPosition, this, &LoggingGadgetWidget::setPlaybackPosition);
connect(logFile, &LogFile::replayStarted, this, &LoggingGadgetWidget::enableButtons);
connect(logFile, &LogFile::replayFinished, this, &LoggingGadgetWidget::disableButtons);
connect(logFile, &LogFile::replayStarted, this, &LoggingGadgetWidget::enableWidgets);
connect(logFile, &LogFile::replayFinished, this, &LoggingGadgetWidget::disableWidgets);
// Feedback from logfile to scope
connect(logFile, &LogFile::replayFinished, scpPlugin, &ScopeGadgetFactory::stopPlotting);
@ -95,84 +93,52 @@ void LoggingGadgetWidget::setPlugin(LoggingPlugin *p)
stateChanged(loggingPlugin->getState());
}
/*
resizeEvent()
Determine button content policy based on button size.
*/
void LoggingGadgetWidget::resizeEvent(QResizeEvent *event)
void LoggingGadgetWidget::playButtonAction()
{
int width = m_logging->playPauseButton->size().width();
ReplayState replayState = (loggingPlugin->getLogfile())->getReplayState();
if (width < m_preferredButtonWidth) {
m_iconOnlyButtons = true;
} else {
m_iconOnlyButtons = false;
if (replayState != PLAYING) {
emit resumeReplay(m_logging->playbackPosition->value());
}
updateButtonAppearance();
QWidget::resizeEvent(event);
m_logging->playButton->setVisible(false);
m_logging->pauseButton->setVisible(true);
m_logging->stopButton->setEnabled(true);
}
/*
setPlayPauseButtonToPlay()
Changes the appearance of the playPause button to the PLAY appearance.
*/
void LoggingGadgetWidget::setPlayPauseButtonToPlay()
void LoggingGadgetWidget::pauseButtonAction()
{
m_logging->playPauseButton->setIcon(QIcon(":/logging/images/play.png"));
if (m_iconOnlyButtons) {
m_logging->playPauseButton->setText(QString());
} else {
m_logging->playPauseButton->setText(tr(" Play"));
}
}
/*
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()
{
ReplayState replayState = loggingPlugin->getLogfile()->getReplayState();
ReplayState replayState = (loggingPlugin->getLogfile())->getReplayState();
if (replayState == PLAYING) {
emit pauseReplay();
setPlayPauseButtonToPlay();
} else {
emit resumeReplay(m_logging->playbackPosition->value());
setPlayPauseButtonToPause();
}
m_logging->playButton->setVisible(true);
m_logging->pauseButton->setVisible(false);
m_logging->stopButton->setEnabled(true);
m_logging->statusLabel->setText(tr("Paused"));
}
void LoggingGadgetWidget::stopButtonAction()
{
ReplayState replayState = loggingPlugin->getLogfile()->getReplayState();
ReplayState replayState = (loggingPlugin->getLogfile())->getReplayState();
if (replayState != STOPPED) {
emit pauseReplayAndResetPosition();
}
m_logging->playButton->setVisible(true);
m_logging->pauseButton->setVisible(false);
m_logging->stopButton->setEnabled(false);
setPlayPauseButtonToPlay();
// Block signals while setting the slider to the start position
m_logging->playbackPosition->blockSignals(true);
m_logging->playbackPosition->setValue(m_logging->playbackPosition->minimum());
m_logging->playbackPosition->blockSignals(false);
m_logging->statusLabel->setText(tr("Paused"));
}
void LoggingGadgetWidget::stateChanged(LoggingPlugin::State state)
@ -196,16 +162,20 @@ void LoggingGadgetWidget::stateChanged(LoggingPlugin::State state)
m_logging->statusLabel->setText(status);
bool playing = loggingPlugin->getLogfile()->isPlaying();
m_logging->playButton->setEnabled(enabled);
m_logging->pauseButton->setEnabled(enabled);
m_logging->stopButton->setEnabled(enabled && playing);
m_logging->playPauseButton->setEnabled(enabled);
if (playing) {
setPlayPauseButtonToPause();
m_logging->playButton->setVisible(false);
m_logging->pauseButton->setVisible(true);
} else {
setPlayPauseButtonToPlay();
m_logging->playButton->setVisible(true);
m_logging->pauseButton->setVisible(false);
}
}
void LoggingGadgetWidget::updateBeginAndEndTimes(quint32 startTimeStamp, quint32 endTimeStamp)
void LoggingGadgetWidget::setBeginAndEndTimes(quint32 startTimeStamp, quint32 endTimeStamp)
{
int startSec, startMin, endSec, endMin;
@ -225,8 +195,6 @@ void LoggingGadgetWidget::updateBeginAndEndTimes(quint32 startTimeStamp, quint32
m_logging->playbackPosition->setSingleStep((endTimeStamp - startTimeStamp) / 100);
m_logging->playbackPosition->setPageStep((endTimeStamp - startTimeStamp) / 10);
m_logging->playbackPosition->setTickInterval((endTimeStamp - startTimeStamp) / 10);
m_logging->playbackPosition->setTickPosition(QSlider::TicksBothSides);
}
void LoggingGadgetWidget::setPlaybackPosition(quint32 positionTimeStamp)
@ -243,65 +211,49 @@ void LoggingGadgetWidget::setPlaybackPosition(quint32 positionTimeStamp)
}
}
void LoggingGadgetWidget::enableButtons()
void LoggingGadgetWidget::enableWidgets()
{
ReplayState replayState = loggingPlugin->getLogfile()->getReplayState();
m_logging->playButton->setEnabled(true);
m_logging->pauseButton->setEnabled(true);
switch (replayState) {
case STOPPED:
m_logging->stopButton->setEnabled(false);
setPlayPauseButtonToPlay();
m_logging->playButton->setVisible(true);
m_logging->pauseButton->setVisible(false);
break;
case PLAYING:
m_logging->stopButton->setEnabled(true);
setPlayPauseButtonToPause();
m_logging->playButton->setVisible(false);
m_logging->pauseButton->setVisible(true);
break;
case PAUSED:
m_logging->stopButton->setEnabled(true);
setPlayPauseButtonToPlay();
m_logging->playButton->setVisible(true);
m_logging->pauseButton->setVisible(false);
break;
}
m_logging->playPauseButton->setEnabled(true);
m_logging->playbackPosition->setEnabled(true);
}
void LoggingGadgetWidget::disableButtons()
void LoggingGadgetWidget::disableWidgets()
{
m_logging->playPauseButton->setEnabled(false);
setPlayPauseButtonToPlay();
m_logging->playButton->setVisible(true);
m_logging->pauseButton->setVisible(false);
m_logging->playButton->setEnabled(false);
m_logging->pauseButton->setEnabled(false);
m_logging->stopButton->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()->getReplayState();
}
// 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"));
}
// reset start and end labels
m_logging->startTimeLabel->setText("");
m_logging->endTimeLabel->setText("");
}
void LoggingGadgetWidget::updatePositionLabel(quint32 positionTimeStamp)

View File

@ -50,12 +50,13 @@ public:
protected slots:
void stateChanged(LoggingPlugin::State state);
void updateBeginAndEndTimes(quint32 startTimeStamp, quint32 endTimeStamp);
void setBeginAndEndTimes(quint32 startTimeStamp, quint32 endTimeStamp);
void setPlaybackPosition(quint32 positionTimeStamp);
void playPauseButtonAction();
void playButtonAction();
void pauseButtonAction();
void stopButtonAction();
void enableButtons();
void disableButtons();
void enableWidgets();
void disableWidgets();
void sliderMoved(int);
void sliderAction();
@ -69,14 +70,8 @@ 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_ */