Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Redesign time display #5118

Closed
18 changes: 11 additions & 7 deletions include/TimeDisplayWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
#ifndef _TIME_DISPLAY_WIDGET
#define _TIME_DISPLAY_WIDGET

#include <QWidget>
#include <QHBoxLayout>
#include <QFrame>
#include <QGridLayout>
#include <QLabel>

#include "LcdWidget.h"


class TimeDisplayWidget : public QWidget
class TimeDisplayWidget : public QFrame
{
Q_OBJECT
public:
Expand Down Expand Up @@ -60,10 +61,13 @@ private slots:
void setDisplayMode( DisplayMode displayMode );

DisplayMode m_displayMode;
QHBoxLayout m_spinBoxesLayout;
LcdWidget m_majorLCD;
LcdWidget m_minorLCD;
LcdWidget m_milliSecondsLCD;
QGridLayout m_spinBoxesLayout;
QLabel m_majorLabel;
QLabel m_majorValue;
QLabel m_minorLabel;
QLabel m_minorValue;
QLabel m_milliSecondsLabel;
QLabel m_milliSecondsValue;

} ;

Expand Down
7 changes: 4 additions & 3 deletions src/gui/editors/SongEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,15 @@ SongEditor::SongEditor( Song * song ) :

gui->mainWindow()->addSpacingToToolBar( 40 );

gui->mainWindow()->addWidgetToToolBar( new TimeDisplayWidget );
gui->mainWindow()->addSpacingToToolBar( 40 );

m_tempoSpinBox = new LcdSpinBox( 3, tb, tr( "Tempo" ) );
m_tempoSpinBox->setModel( &m_song->m_tempoModel );
m_tempoSpinBox->setLabel( tr( "TEMPO" ) );
ToolTip::add( m_tempoSpinBox, tr( "Tempo in BPM" ) );

int tempoSpinBoxCol = gui->mainWindow()->addWidgetToToolBar( m_tempoSpinBox, 0 );
gui->mainWindow()->addWidgetToToolBar( m_tempoSpinBox);

#if 0
toolButton * hq_btn = new toolButton( embed::getIconPixmap( "hq_mode" ),
Expand All @@ -131,8 +134,6 @@ SongEditor::SongEditor( Song * song ) :
gui->mainWindow()->addWidgetToToolBar( hq_btn, 1, col );
#endif

gui->mainWindow()->addWidgetToToolBar( new TimeDisplayWidget, 1, tempoSpinBoxCol );

gui->mainWindow()->addSpacingToToolBar( 10 );

m_timeSigDisplay = new MeterDialog( this, true );
Expand Down
76 changes: 53 additions & 23 deletions src/gui/widgets/TimeDisplayWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,42 @@


TimeDisplayWidget::TimeDisplayWidget() :
QWidget(),
QFrame(),
m_displayMode( MinutesSeconds ),
m_spinBoxesLayout( this ),
m_majorLCD( 4, this ),
m_minorLCD( 2, this ),
m_milliSecondsLCD( 3, this )
m_majorLabel( this ),
m_majorValue( this ),
m_minorLabel( this ),
m_minorValue( this ),
m_milliSecondsLabel( this ),
m_milliSecondsValue( this )
{
m_spinBoxesLayout.setSpacing( 0 );
m_spinBoxesLayout.setMargin( 0 );
m_spinBoxesLayout.addWidget( &m_majorLCD );
m_spinBoxesLayout.addWidget( &m_minorLCD );
m_spinBoxesLayout.addWidget( &m_milliSecondsLCD );

setMaximumHeight( 32 );
m_spinBoxesLayout.addWidget( &m_majorLabel, 0, 0 );
m_spinBoxesLayout.addWidget( &m_majorValue, 1, 0 );
m_spinBoxesLayout.addWidget( &m_minorLabel, 0, 1 );
m_spinBoxesLayout.addWidget( &m_minorValue, 1, 1 );
m_spinBoxesLayout.addWidget( &m_milliSecondsLabel, 0, 2 );
m_spinBoxesLayout.addWidget( &m_milliSecondsValue, 1, 2 );

this->setStyleSheet( "TimeDisplayWidget { border-radius: 4px; background-color: rgba(0,0,0,70); margin: 8px; padding: 4px; }" );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go in the stylesheet.


QString labelStyle = "font-size: 10px;";
QString valueStyle = "color: #0bd556; font-size: 24px;";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go in the stylesheet.


m_majorLabel.setAlignment(Qt::AlignRight);
m_majorLabel.setStyleSheet(labelStyle);
m_majorValue.setAlignment(Qt::AlignRight);
m_majorValue.setStyleSheet(valueStyle);
m_minorLabel.setAlignment(Qt::AlignRight);
m_minorLabel.setStyleSheet(labelStyle);
m_minorValue.setAlignment(Qt::AlignRight);
m_minorValue.setStyleSheet(valueStyle);
m_milliSecondsLabel.setAlignment(Qt::AlignRight);
m_milliSecondsLabel.setStyleSheet(labelStyle);
m_milliSecondsValue.setAlignment(Qt::AlignRight);
m_milliSecondsValue.setStyleSheet(valueStyle);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repetition deserves its own widget.


ToolTip::add( this, tr( "Time units" ) );

Expand All @@ -65,15 +87,15 @@ void TimeDisplayWidget::setDisplayMode( DisplayMode displayMode )
switch( m_displayMode )
{
case MinutesSeconds:
m_majorLCD.setLabel( tr( "MIN" ) );
m_minorLCD.setLabel( tr( "SEC" ) );
m_milliSecondsLCD.setLabel( tr( "MSEC" ) );
m_majorLabel.setText( tr( "MIN" ) );
m_minorLabel.setText( tr( "SEC" ) );
m_milliSecondsLabel.setText( tr( "MSEC" ) );
break;

case BarsTicks:
m_majorLCD.setLabel( tr( "BAR" ) );
m_minorLCD.setLabel( tr( "BEAT" ) );
m_milliSecondsLCD.setLabel( tr( "TICK" ) );
m_majorLabel.setText( tr( "BAR" ) );
m_minorLabel.setText( tr( "BEAT" ) );
m_milliSecondsLabel.setText( tr( "TICK" ) );
break;

default: break;
Expand All @@ -87,28 +109,36 @@ void TimeDisplayWidget::updateTime()
{
Song* s = Engine::getSong();

int major = 0;
int minor = 0;
int milliSeconds = 0;

switch( m_displayMode )
{
case MinutesSeconds:
int msec;
msec = s->getMilliseconds();
m_majorLCD.setValue(msec / 60000);
m_minorLCD.setValue((msec / 1000) % 60);
m_milliSecondsLCD.setValue(msec % 1000);
major = msec / 60000;
minor = (msec / 1000) % 60;
milliSeconds = msec % 1000;
break;

case BarsTicks:
int tick;
tick = s->getPlayPos().getTicks();
m_majorLCD.setValue((int)(tick / s->ticksPerTact()) + 1);
m_minorLCD.setValue((tick % s->ticksPerTact()) /
(s->ticksPerTact() / s->getTimeSigModel().getNumerator() ) +1);
m_milliSecondsLCD.setValue((tick % s->ticksPerTact()) %
(s->ticksPerTact() / s->getTimeSigModel().getNumerator()));
major = (int)(tick / s->ticksPerTact()) + 1;
minor = (tick % s->ticksPerTact()) /
(s->ticksPerTact() / s->getTimeSigModel().getNumerator()) +1;
milliSeconds = (tick % s->ticksPerTact()) %
(s->ticksPerTact() / s->getTimeSigModel().getNumerator());
break;

default: break;
}

m_majorValue.setText( QString::number( major ).rightJustified( 4, '0' ) );
m_minorValue.setText( QString::number( minor ).rightJustified( 2, '0' ).prepend( ':' ) );
m_milliSecondsValue.setText( QString::number( milliSeconds ).rightJustified( 3, '0' ).prepend( '.' ) );
}


Expand Down