Default ctors for LED checkbox and LCD spinbox. Fixes for knob.

This commit is contained in:
Johannes Lorenz
2014-04-15 13:43:23 +02:00
parent f32f7689b4
commit 51ed1105df
6 changed files with 140 additions and 55 deletions

View File

@@ -40,48 +40,41 @@
//! @todo: in C++11, we can use delegating ctors
#define DEFAULT_LCDWIDGET_INITIALIZER_LIST \
QWidget( parent ), \
m_label()
LcdWidget::LcdWidget( QWidget* parent, const QString& name ) :
DEFAULT_LCDWIDGET_INITIALIZER_LIST,
m_numDigits( 1 )
{
initUi( name );
}
LcdWidget::LcdWidget( int numDigits, QWidget* parent, const QString& name ) :
QWidget( parent ),
m_label(),
DEFAULT_LCDWIDGET_INITIALIZER_LIST,
m_numDigits( numDigits )
{
setEnabled( true );
setWindowTitle( name );
m_lcdPixmap = new QPixmap( embed::getIconPixmap( "lcd_19green" ) );
m_cellWidth = m_lcdPixmap->size().width() / LcdWidget::charsPerPixmap;
m_cellHeight = m_lcdPixmap->size().height() / 2;
m_marginWidth = m_cellWidth / 2;
updateSize();
initUi( name );
}
LcdWidget::LcdWidget( int numDigits, const QString& style, QWidget* parent, const QString& name ) :
QWidget( parent ),
m_label(),
DEFAULT_LCDWIDGET_INITIALIZER_LIST,
m_numDigits( numDigits )
{
setEnabled( true );
setWindowTitle( name );
// We should make a factory for these or something.
m_lcdPixmap = new QPixmap( embed::getIconPixmap( QString( "lcd_" + style ).toUtf8().constData() ) );
m_cellWidth = m_lcdPixmap->size().width() / LcdWidget::charsPerPixmap;
m_cellHeight = m_lcdPixmap->size().height() / 2;
m_marginWidth = m_cellWidth / 2;
updateSize();
initUi( name, style );
}
#undef DEFAULT_LCDWIDGET_INITIALIZER_LIST
@@ -242,5 +235,27 @@ void LcdWidget::updateSize()
void LcdWidget::initUi(const QString& name , const QString& style)
{
setEnabled( true );
setWindowTitle( name );
// We should make a factory for these or something.
//m_lcdPixmap = new QPixmap( embed::getIconPixmap( QString( "lcd_" + style ).toUtf8().constData() ) );
//m_lcdPixmap = new QPixmap( embed::getIconPixmap( "lcd_19green" ) ); // TODO!!
m_lcdPixmap = new QPixmap( embed::getIconPixmap( QString( "lcd_" + style ).toUtf8().constData() ) );
m_cellWidth = m_lcdPixmap->size().width() / LcdWidget::charsPerPixmap;
m_cellHeight = m_lcdPixmap->size().height() / 2;
m_marginWidth = m_cellWidth / 2;
updateSize();
}
#include "moc_LcdWidget.cxx"

View File

@@ -70,14 +70,14 @@ knob::knob( knobTypes _knob_num, QWidget * _parent, const QString & _name ) :
DEFAULT_KNOB_INITIALIZER_LIST,
m_knobNum( _knob_num )
{
init( _name );
initUi( _name );
}
knob::knob( QWidget * _parent, const QString & _name ) :
DEFAULT_KNOB_INITIALIZER_LIST,
m_knobNum( knobBright_26 )
{
init( _name );
initUi( _name );
}
#undef DEFAULT_KNOB_INITIALIZER_LIST
@@ -85,7 +85,7 @@ knob::knob( QWidget * _parent, const QString & _name ) :
void knob::init( const QString & _name )
void knob::initUi( const QString & _name )
{
if( s_textFloat == NULL )
{
@@ -94,6 +94,19 @@ void knob::init( const QString & _name )
setWindowTitle( _name );
onKnobNumUpdated();
setTotalAngle( 270.0f );
setInnerRadius( 1.0f );
setOuterRadius( 10.0f );
setFocusPolicy( Qt::ClickFocus );
doConnections();
}
void knob::onKnobNumUpdated()
{
if( m_knobNum != knobStyled )
{
m_knobPixmap = new QPixmap( embed::getIconPixmap( QString( "knob0" +
@@ -101,11 +114,6 @@ void knob::init( const QString & _name )
setFixedSize( m_knobPixmap->width(), m_knobPixmap->height() );
}
setTotalAngle( 270.0f );
setInnerRadius( 1.0f );
setOuterRadius( 10.0f );
setFocusPolicy( Qt::ClickFocus );
doConnections();
}
@@ -193,7 +201,11 @@ knobTypes knob::knobNum() const
void knob::setknobNum( knobTypes _k )
{
m_knobNum = _k;
if( m_knobNum != _k )
{
m_knobNum = _k;
onKnobNumUpdated();
}
}

View File

@@ -38,28 +38,33 @@ static const QString names[ledCheckBox::NumColors] =
//! @todo: in C++11, we can use delegating ctors
#define DEFAULT_LEDCHECKBOX_INITIALIZER_LIST \
automatableButton( _parent, _name )
ledCheckBox::ledCheckBox( const QString & _text, QWidget * _parent,
const QString & _name, LedColors _color ) :
automatableButton( _parent, _name ),
DEFAULT_LEDCHECKBOX_INITIALIZER_LIST,
m_text( _text )
{
setCheckable( true );
if( _color >= NumColors || _color < Yellow )
{
_color = Yellow;
}
m_ledOnPixmap = new QPixmap( embed::getIconPixmap(
names[_color].toUtf8().constData() ) );
m_ledOffPixmap = new QPixmap( embed::getIconPixmap( "led_off" ) );
setFont( pointSize<7>( font() ) );
setFixedSize( m_ledOffPixmap->width() + 5 + QFontMetrics( font() ).width( text() ), m_ledOffPixmap->height() );
initUi( _color );
}
ledCheckBox::ledCheckBox( QWidget * _parent,
const QString & _name, LedColors _color ) :
DEFAULT_LEDCHECKBOX_INITIALIZER_LIST
{
initUi( _color );
}
#undef DEFAULT_LEDCHECKBOX_INITIALIZER_LIST
ledCheckBox::~ledCheckBox()
{
delete m_ledOnPixmap;
@@ -69,14 +74,23 @@ ledCheckBox::~ledCheckBox()
void ledCheckBox::setText( const QString &s )
{
m_text = s;
onTextUpdated();
}
void ledCheckBox::paintEvent( QPaintEvent * )
{
QPainter p( this );
p.setFont( pointSize<7>( font() ) );
if( model()->value() == true )
{
p.drawPixmap( 0, 0, *m_ledOnPixmap );
{
p.drawPixmap( 0, 0, *m_ledOnPixmap );
}
else
{
@@ -91,5 +105,32 @@ void ledCheckBox::paintEvent( QPaintEvent * )
void ledCheckBox::initUi( LedColors _color )
{
setCheckable( true );
if( _color >= NumColors || _color < Yellow )
{
_color = Yellow;
}
m_ledOnPixmap = new QPixmap( embed::getIconPixmap(
names[_color].toUtf8().constData() ) );
m_ledOffPixmap = new QPixmap( embed::getIconPixmap( "led_off" ) );
setFont( pointSize<7>( font() ) );
setText( m_text );
}
void ledCheckBox::onTextUpdated()
{
setFixedSize( m_ledOffPixmap->width() + 5 + QFontMetrics( font() ).width( text() ), m_ledOffPixmap->height() );
}
#include "moc_led_checkbox.cxx"