~ubuntu-branches/ubuntu/hardy/lmms/hardy

« back to all changes in this revision

Viewing changes to src/widgets/lcd_spinbox.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Florian Ragwitz
  • Date: 2005-12-22 16:22:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20051222162250-key3p7x0212jy6dn
Tags: 0.1.2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * lcd_spinbox.cpp - class lcdSpinBox, an improved QLCDNumber
3
3
 *
4
 
 * Linux MultiMedia Studio
5
 
 * Copyright (c) 2004-2005 Tobias Doerffel <tobydox@users.sourceforge.net>
 
4
 * Copyright (c) 2005 Tobias Doerffel <tobydox/at/users.sourceforge.net>
 
5
 * 
 
6
 * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
6
7
 *
7
8
 * This program is free software; you can redistribute it and/or
8
9
 * modify it under the terms of the GNU General Public
41
42
 
42
43
 
43
44
#include "lcd_spinbox.h"
 
45
#include "gui_templates.h"
44
46
#include "templates.h"
45
47
 
46
48
 
47
 
 
48
49
lcdSpinBox::lcdSpinBox( int _min, int _max, int _num_digits,
49
50
                                                        QWidget * _parent ) :
50
51
        QWidget( _parent ),
58
59
        m_number->setFrameShape( QFrame::Panel );
59
60
        m_number->setFrameShadow( QFrame::Sunken );
60
61
        m_number->setSegmentStyle( QLCDNumber::Flat );
61
 
#ifdef QT4
62
 
        QPalette pal = m_number->palette();
63
 
        pal.setColor( QPalette::Background, QColor( 32, 32, 32 ) );
64
 
        pal.setColor( QPalette::Foreground, QColor( 255, 180, 0 ) );
65
 
        m_number->setPalette( pal );
66
 
#else
67
 
        m_number->setPaletteBackgroundColor( QColor( 32, 32, 32 ) );
68
 
        m_number->setPaletteForegroundColor( QColor( 255, 180, 0 ) );
69
 
#endif
 
62
        setEnabled( TRUE );
 
63
 
70
64
        // value is automatically limited to given range
71
65
        setValue( 0 );
72
66
 
95
89
{
96
90
        _value = ( ( tLimit( _value, m_minValue, m_maxValue ) - m_minValue ) /
97
91
                                                m_step ) * m_step + m_minValue;
98
 
        QString s = QString::number( _value );
99
 
        while( (int) s.length() < m_number->numDigits() )
 
92
        QString s = m_textForValue[_value];
 
93
        if( s == "" )
100
94
        {
101
 
                s = "0" + s;
 
95
                s = QString::number( _value );
 
96
                while( (int) s.length() < m_number->numDigits() )
 
97
                {
 
98
                        s = "0" + s;
 
99
                }
102
100
        }
103
 
 
104
101
        m_number->display( s );
105
102
}
106
103
 
127
124
 
128
125
 
129
126
 
 
127
void lcdSpinBox::setEnabled( bool _on )
 
128
{
 
129
        QColor fg( 255, 180, 0 );
 
130
        if( _on == FALSE )
 
131
        {
 
132
                fg = QColor( 160, 160, 160 );
 
133
        }
 
134
#ifdef QT4
 
135
        QPalette pal = m_number->palette();
 
136
        pal.setColor( QPalette::Background, QColor( 32, 32, 32 ) );
 
137
        pal.setColor( QPalette::Foreground, fg );
 
138
        m_number->setPalette( pal );
 
139
#else
 
140
        m_number->setPaletteBackgroundColor( QColor( 32, 32, 32 ) );
 
141
        m_number->setPaletteForegroundColor( fg );
 
142
#endif
 
143
        QWidget::setEnabled( _on );
 
144
}
 
145
 
 
146
 
 
147
 
 
148
 
130
149
void lcdSpinBox::mousePressEvent( QMouseEvent * _me )
131
150
{
132
151
        if( _me->button() == Qt::LeftButton && _me->y() < m_number->height()  )
138
157
 
139
158
 
140
159
 
 
160
 
141
161
void lcdSpinBox::mouseMoveEvent( QMouseEvent * _me )
142
162
{
 
163
#ifdef QT4
 
164
        if( _me->buttons() & Qt::LeftButton )
 
165
#else
143
166
        if( _me->modifiers() == Qt::LeftButton )
 
167
#endif
144
168
        {
145
169
                int dy = _me->globalY() - m_origMousePos.y();
146
170
                if( dy > 1 || dy < -1 )
166
190
 
167
191
void lcdSpinBox::wheelEvent( QWheelEvent * _we )
168
192
{
169
 
        setValue( value() + _we->delta() / 120 * m_step );
 
193
        _we->accept();
 
194
        setValue( value() + ( ( _we->delta() > 0 ) ? 1 : -1 ) * m_step );
 
195
        emit valueChanged( value() );
170
196
}
171
197
 
172
198