~ubuntu-branches/ubuntu/warty/koffice/warty

« back to all changes in this revision

Viewing changes to kivio/kiviopart/tklib/tkfloatspinbox.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Kivio - Visual Modelling and Flowcharting
3
 
 * Copyright (C) 2000 theKompany.com
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU General Public License
7
 
 * as published by the Free Software Foundation; either version 2
8
 
 * of the License, or (at your option) any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
 
 */
19
 
#include "tkfloatspinbox.h"
20
 
#include "tktoolbarbutton.h"
21
 
#include "tkunits.h"
22
 
 
23
 
#include "qglobal.h"
24
 
#include <limits.h>
25
 
 
26
 
#include <qpushbutton.h>
27
 
#include <qpainter.h>
28
 
#include <qbitmap.h>
29
 
#include <qlineedit.h>
30
 
#include <qvalidator.h>
31
 
#include <qpixmapcache.h>
32
 
#include <qapplication.h>
33
 
#include <kdebug.h>
34
 
 
35
 
TKFloatSpinBox::TKFloatSpinBox( QWidget * parent , const char *name )
36
 
: QFrame( parent, name ), TKFloatRangeControl()
37
 
{
38
 
  flength = 0;
39
 
  m_decimal = 3;
40
 
  initSpinBox();
41
 
}
42
 
 
43
 
TKFloatSpinBox::TKFloatSpinBox( float minValue, float maxValue, float step, int decimal, QWidget* parent, const char* name )
44
 
: QFrame( parent, name ), TKFloatRangeControl( minValue, maxValue, step, step, minValue )
45
 
{
46
 
  m_decimal = decimal;
47
 
  initSpinBox();
48
 
}
49
 
 
50
 
void TKFloatSpinBox::initSpinBox()
51
 
{
52
 
  buttonSymbol = TKFloatSpinBox::UpDownArrows;
53
 
  wrap = false;
54
 
  edited = false;
55
 
  pfix = QString::null;
56
 
  sfix = QString::null;
57
 
 
58
 
  m_minimum = false;
59
 
 
60
 
  up = new TKToolBarButton(QPixmap(),QString::null,this,"up");
61
 
  up->setAutoRaised(false);
62
 
  up->setRaised(true);
63
 
  up->setFocusPolicy( QWidget::NoFocus );
64
 
  up->setAutoRepeat( true );
65
 
 
66
 
  down = new TKToolBarButton(QPixmap(),QString::null,this,"down");
67
 
  down->setAutoRaised(false);
68
 
  down->setRaised(true);
69
 
  down->setFocusPolicy( QWidget::NoFocus );
70
 
  down->setAutoRepeat( true );
71
 
 
72
 
  setButtonSymbols(UpDownArrows);
73
 
 
74
 
  validate = new QDoubleValidator( minValue(), maxValue(), m_decimal, this );
75
 
  vi = new QLineEdit(this);
76
 
  vi->setFrame(false);
77
 
  vi->setAlignment(AlignRight);
78
 
  setFocusProxy( vi );
79
 
  setFocusPolicy( StrongFocus );
80
 
  vi->setValidator( validate );
81
 
  vi->installEventFilter( this );
82
 
 
83
 
  setPalettePropagation( AllChildren );
84
 
  setFontPropagation( AllChildren );
85
 
 
86
 
  setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ) );
87
 
  setFrameStyle( Panel|Sunken );
88
 
  updateDisplay();
89
 
 
90
 
  connect( up, SIGNAL(pressed()), SLOT(stepUp()) );
91
 
  connect( down, SIGNAL(pressed()), SLOT(stepDown()) );
92
 
  connect( vi, SIGNAL(textChanged(const QString&)), SLOT(textChanged()) );
93
 
}
94
 
 
95
 
TKFloatSpinBox::~TKFloatSpinBox()
96
 
{
97
 
}
98
 
 
99
 
void TKFloatSpinBox::setDecimals( int decimal )
100
 
{
101
 
  m_decimal = decimal;
102
 
 
103
 
  if (validate->inherits("QDoubleValidator"))
104
 
    ((QDoubleValidator*)validate)->setDecimals( m_decimal );
105
 
 
106
 
  updateDisplay();
107
 
}
108
 
 
109
 
QString TKFloatSpinBox::text() const
110
 
{
111
 
  return vi->text();
112
 
}
113
 
 
114
 
QString TKFloatSpinBox::cleanText() const
115
 
{
116
 
  QString s = QString(text()).stripWhiteSpace();
117
 
  if ( !prefix().isEmpty() ) {
118
 
    QString px = QString(prefix()).stripWhiteSpace();
119
 
    int len = px.length();
120
 
    if ( len && s.left(len) == px )
121
 
      s.remove( 0, len );
122
 
  }
123
 
  if ( !suffix().isEmpty() ) {
124
 
    QString sx = QString(suffix()).stripWhiteSpace();
125
 
    int len = sx.length();
126
 
    if ( len && s.right(len) == sx )
127
 
      s.truncate( s.length() - len );
128
 
  }
129
 
  return s.stripWhiteSpace();
130
 
}
131
 
 
132
 
void TKFloatSpinBox::setPrefix( const QString &text )
133
 
{
134
 
  pfix = text;
135
 
  updateDisplay();
136
 
}
137
 
 
138
 
void TKFloatSpinBox::setSuffix( const QString &text )
139
 
{
140
 
  sfix = text;
141
 
  updateDisplay();
142
 
}
143
 
 
144
 
QString TKFloatSpinBox::prefix() const
145
 
{
146
 
  if ( pfix.isEmpty() )
147
 
    return QString::null;
148
 
 
149
 
  return pfix;
150
 
}
151
 
 
152
 
QString TKFloatSpinBox::suffix() const
153
 
{
154
 
  if ( sfix.isEmpty() )
155
 
    return QString::null;
156
 
 
157
 
  return sfix;
158
 
}
159
 
 
160
 
void TKFloatSpinBox::setWrapping( bool on )
161
 
{
162
 
  wrap = on;
163
 
  updateDisplay();
164
 
}
165
 
 
166
 
bool TKFloatSpinBox::wrapping() const
167
 
{
168
 
  return wrap;
169
 
}
170
 
 
171
 
void TKFloatSpinBox::setFixedLength(int l)
172
 
{
173
 
  flength = l;
174
 
  updateGeometry();
175
 
}
176
 
 
177
 
QSize TKFloatSpinBox::sizeHint() const
178
 
{
179
 
  constPolish();
180
 
  QFontMetrics fm = fontMetrics();
181
 
  int fw = frameWidth();
182
 
 
183
 
  int h = m_minimum ? 9 : QMAX(12,fm.height()); // ensure enough space for the button pixmaps
184
 
        
185
 
        // button width - see resizeevent()
186
 
        int bw;
187
 
        if (m_minimum)
188
 
          bw = 2*14;
189
 
        else
190
 
        bw = (height()/2 - fw)*8/5;
191
 
 
192
 
  int w = 35;   // minimum width for the value
193
 
  QString s;
194
 
  if (flength != 0) {
195
 
    int wl = fm.width('0')*QABS(flength+1);
196
 
    if (flength < 0)
197
 
      s = prefix() + suffix();
198
 
    w = QMAX( w, fm.width(s) + wl);
199
 
  } else {
200
 
    s = prefix() + ( (TKFloatSpinBox*)this )->mapValueToText( minValue() ) + suffix();
201
 
    w = QMAX(w, fm.width(s));
202
 
    s = prefix() + ( (TKFloatSpinBox*)this )->mapValueToText( maxValue() ) + suffix();
203
 
    w = QMAX(w, fm.width(s));
204
 
  }
205
 
 
206
 
  QSize r( bw + fw * 2 // buttons AND frame both sides - see resizeevent()
207
 
  + 6 // right/left margins
208
 
  + w, // widest value
209
 
  fw * 2 // top/bottom frame
210
 
  + (m_minimum ? 0:4) // top/bottom margins
211
 
  + h // font height
212
 
  );
213
 
  return r.expandedTo( QApplication::globalStrut() );
214
 
}
215
 
 
216
 
void TKFloatSpinBox::setMinimumStyle(bool minimum)
217
 
{
218
 
  if (m_minimum == minimum)
219
 
    return;
220
 
 
221
 
  m_minimum = minimum;
222
 
  setFrameStyle( m_minimum ? NoFrame:Panel|Sunken );
223
 
  setSizePolicy( QSizePolicy( QSizePolicy::Minimum, m_minimum ? QSizePolicy::Minimum : QSizePolicy::Fixed ) );
224
 
 
225
 
  arrangeWidgets();
226
 
}
227
 
 
228
 
void TKFloatSpinBox::arrangeWidgets()
229
 
{
230
 
  if ( !up || !down )
231
 
  return;
232
 
 
233
 
  int fw = frameWidth();
234
 
  QSize bs;
235
 
        if (m_minimum) {
236
 
          bs.setHeight( height() - 2*fw );
237
 
    bs.setWidth(14);
238
 
        } else {
239
 
        bs.setHeight( height()/2 - fw );
240
 
    bs.setWidth( bs.height() * 8 / 5 ); // 1.6 - approximate golden mean
241
 
  }
242
 
 
243
 
  if ( up->size() != bs || down->size() != bs ) {
244
 
    up->resize( bs );
245
 
    down->resize( bs );
246
 
    updateButtonSymbols();
247
 
  }
248
 
 
249
 
  if (m_minimum) {
250
 
    int y = fw;
251
 
    int x = width() - fw - 2*bs.width();
252
 
    up->move( x, y );
253
 
    down->move( x+bs.width(), y );
254
 
        vi->setGeometry( fw, fw, x - fw, height() - 2*fw );
255
 
  } else {
256
 
    int y = fw;
257
 
    int x = width() - fw - bs.width();
258
 
    up->move( x, y );
259
 
    down->move( x, height() - y - up->height() );
260
 
        vi->setGeometry( fw, fw, x - fw, height() - 2*fw );
261
 
        }
262
 
}
263
 
 
264
 
void TKFloatSpinBox::setValue( float value )
265
 
{
266
 
  directSetValue( value );
267
 
  updateDisplay();
268
 
}
269
 
 
270
 
void TKFloatSpinBox::stepUp()
271
 
{
272
 
  if ( edited )
273
 
    interpretText();
274
 
  if ( wrapping() && ( value()+lineStep() > maxValue() ) )
275
 
    TKFloatRangeControl::setValue( minValue() );
276
 
  else
277
 
    addLine();
278
 
}
279
 
 
280
 
void TKFloatSpinBox::stepDown()
281
 
{
282
 
  if ( edited )
283
 
    interpretText();
284
 
  if ( wrapping() && ( value()-lineStep() < minValue() ) )
285
 
    TKFloatRangeControl::setValue( maxValue() );
286
 
  else
287
 
    subtractLine();
288
 
}
289
 
 
290
 
bool TKFloatSpinBox::eventFilter( QObject* obj, QEvent* ev )
291
 
{
292
 
  if ( obj != vi )
293
 
    return false;
294
 
 
295
 
  if ( ev->type() == QEvent::FocusOut || ev->type() == QEvent::Leave || ev->type() == QEvent::Hide ) {
296
 
    if ( edited )
297
 
      interpretText();
298
 
  } else if ( ev->type() == QEvent::KeyPress ) {
299
 
    QKeyEvent* k = (QKeyEvent*)ev;
300
 
    if ( k->key() == Key_Up ) {
301
 
      stepUp();
302
 
      return true;
303
 
    } else if ( k->key() == Key_Down ) {
304
 
      stepDown();
305
 
      return true;
306
 
    } else if ( k->key() == Key_Return ) {
307
 
      interpretText();
308
 
      return false;
309
 
    }
310
 
  }
311
 
  return false;
312
 
}
313
 
 
314
 
void TKFloatSpinBox::leaveEvent( QEvent* )
315
 
{
316
 
  if (edited)
317
 
    interpretText();
318
 
}
319
 
 
320
 
void TKFloatSpinBox::resizeEvent( QResizeEvent* )
321
 
{
322
 
  arrangeWidgets();
323
 
}
324
 
 
325
 
void TKFloatSpinBox::wheelEvent( QWheelEvent* e )
326
 
{
327
 
   kdDebug() << "WHEEL EVENT **************************************\n";
328
 
  e->accept();
329
 
  static float offset = 0;
330
 
  static TKFloatSpinBox* offset_owner = 0;
331
 
  if (offset_owner != this) {
332
 
    offset_owner = this;
333
 
    offset = 0;
334
 
  }
335
 
  offset += -e->delta()/120;
336
 
 
337
 
  if (QABS(offset) < 1)
338
 
    return;
339
 
 
340
 
  float ioff = offset;
341
 
  for (int i=0; i<QABS(ioff); i++)
342
 
    offset > 0 ? stepDown() : stepUp();
343
 
 
344
 
  offset -= ioff;
345
 
}
346
 
 
347
 
void TKFloatSpinBox::valueChange()
348
 
{
349
 
  updateDisplay();
350
 
  emit valueChanged( value() );
351
 
}
352
 
 
353
 
void TKFloatSpinBox::rangeChange()
354
 
{
355
 
  if ( validate->inherits( "QDoubleValidator" ) )
356
 
    ((QDoubleValidator*)validate)->setRange( minValue(), maxValue() );
357
 
  updateDisplay();
358
 
}
359
 
 
360
 
void TKFloatSpinBox::setValidator( const QValidator* v )
361
 
{
362
 
  if ( vi )
363
 
    vi->setValidator( v );
364
 
}
365
 
 
366
 
const QValidator * TKFloatSpinBox::validator() const
367
 
{
368
 
  return vi ? vi->validator() : 0;
369
 
}
370
 
 
371
 
void TKFloatSpinBox::updateDisplay()
372
 
{
373
 
  vi->setText( currentValueText() );
374
 
  edited = false;
375
 
  up->setEnabled( isEnabled() && (wrapping() || value() < maxValue()) );
376
 
  down->setEnabled( isEnabled() && (wrapping() || value() > minValue()) );
377
 
}
378
 
 
379
 
void TKFloatSpinBox::interpretText()
380
 
{
381
 
  bool ok = true;
382
 
  float newVal = mapTextToValue( &ok );
383
 
  if ( ok )
384
 
    TKFloatRangeControl::setValue( newVal );
385
 
 
386
 
  updateDisplay();
387
 
}
388
 
 
389
 
TKToolBarButton* TKFloatSpinBox::upButton() const
390
 
{
391
 
  return up;
392
 
}
393
 
 
394
 
TKToolBarButton* TKFloatSpinBox::downButton() const
395
 
{
396
 
  return down;
397
 
}
398
 
 
399
 
QLineEdit* TKFloatSpinBox::editor() const
400
 
{
401
 
  return vi;
402
 
}
403
 
 
404
 
void TKFloatSpinBox::textChanged()
405
 
{
406
 
  edited = true;
407
 
}
408
 
 
409
 
QString TKFloatSpinBox::mapValueToText( float v )
410
 
{
411
 
  QString s = QString::number(v,'f',m_decimal);
412
 
  return s;
413
 
}
414
 
 
415
 
float TKFloatSpinBox::mapTextToValue( bool* ok )
416
 
{
417
 
  QString s = text();
418
 
  float newVal = s.toDouble( ok );
419
 
  if ( !(*ok) && !( !prefix() && !suffix() ) ) {
420
 
    s = cleanText();
421
 
    newVal = s.toDouble( ok );
422
 
  }
423
 
  return newVal;
424
 
}
425
 
 
426
 
QString TKFloatSpinBox::currentValueText()
427
 
{
428
 
  QString s;
429
 
  s = prefix();
430
 
  s.append( mapValueToText( value() ) );
431
 
  s.append( suffix() );
432
 
  return s;
433
 
}
434
 
 
435
 
void TKFloatSpinBox::setEnabled( bool on )
436
 
{
437
 
  bool b = isEnabled();
438
 
  QFrame::setEnabled( on );
439
 
  if ( isEnabled() != b ) {
440
 
    updateDisplay();
441
 
  }
442
 
}
443
 
 
444
 
void TKFloatSpinBox::styleChange( QStyle& old )
445
 
{
446
 
        setFrameStyle( Panel | Sunken );
447
 
  arrangeWidgets();
448
 
  QWidget::styleChange( old );
449
 
}
450
 
 
451
 
void TKFloatSpinBox::setButtonSymbols( ButtonSymbols newSymbols )
452
 
{
453
 
  if ( buttonSymbols() == newSymbols )
454
 
    return;
455
 
 
456
 
  buttonSymbol = newSymbols;
457
 
  updateButtonSymbols();
458
 
}
459
 
 
460
 
TKFloatSpinBox::ButtonSymbols TKFloatSpinBox::buttonSymbols() const
461
 
{
462
 
  return buttonSymbol;
463
 
}
464
 
 
465
 
void TKFloatSpinBox::updateButtonSymbols()
466
 
{
467
 
  QString key( QString::fromLatin1("$qt$qspinbox$"));
468
 
 
469
 
  bool pmSym = buttonSymbols() == PlusMinus;
470
 
 
471
 
  key += QString::fromLatin1( pmSym ? "+-" : "^v" );
472
 
  key += QString::number( down->height() );
473
 
 
474
 
  QString upKey = key + QString::fromLatin1( "$up" );
475
 
  QString dnKey = key + QString::fromLatin1( "$down" );
476
 
 
477
 
  QBitmap upBm;
478
 
  QBitmap dnBm;
479
 
 
480
 
  bool found = QPixmapCache::find( dnKey, dnBm ) && QPixmapCache::find( upKey, upBm );
481
 
 
482
 
  if ( !found ) {
483
 
    QPainter p;
484
 
    if ( pmSym ) {
485
 
      int h = down->height()-4;
486
 
      if ( h < 3 )
487
 
        return;
488
 
      else if ( h == 4 )
489
 
        h = 3;
490
 
      else if ( (h > 6) && (h & 1) )
491
 
        h--;
492
 
 
493
 
      h -= ( h / 8 ) * 2;     // Empty border
494
 
      dnBm.resize( h, h );
495
 
      p.begin( &dnBm );
496
 
      p.eraseRect( 0, 0, h, h );
497
 
      p.setBrush( color1 );
498
 
      int c = h/2;
499
 
      p.drawLine( 0, c, h, c );
500
 
      if ( !(h & 1) )
501
 
        p.drawLine( 0, c-1, h, c-1 );
502
 
      p.end();
503
 
 
504
 
      upBm = dnBm;
505
 
      p.begin( &upBm );
506
 
      p.drawLine( c, 0, c, h );
507
 
      if ( !(h & 1) )
508
 
        p.drawLine( c-1, 0, c-1, h );
509
 
      p.end();
510
 
    } else {
511
 
      int w = down->width()-4;
512
 
      if ( w < 3 )
513
 
        return;
514
 
      else if ( !(w & 1) )
515
 
        w--;
516
 
 
517
 
      w -= ( w / 7 ) * 2;     // Empty border
518
 
      int h = w/2 + 2;        // Must have empty row at foot of arrow
519
 
      dnBm.resize( w, h );
520
 
      p.begin( &dnBm );
521
 
      p.eraseRect( 0, 0, w, h );
522
 
      QPointArray a;
523
 
      a.setPoints( 3,  0, 1,  w-1, 1,  h-2, h-1 );
524
 
      p.setBrush( color1 );
525
 
      p.drawPolygon( a );
526
 
      p.end();
527
 
      QWMatrix wm;
528
 
      wm.scale( 1, -1 );
529
 
      upBm = dnBm.xForm( wm );
530
 
    }
531
 
 
532
 
    QPixmapCache::insert( dnKey, dnBm );
533
 
    QPixmapCache::insert( upKey, upBm );
534
 
  }
535
 
 
536
 
  down->setPixmap( dnBm );
537
 
  up->setPixmap( upBm );
538
 
}
539
 
 
540
 
float TKFloatSpinBox::minValue() const
541
 
{
542
 
  return TKFloatRangeControl::minValue();
543
 
}
544
 
 
545
 
float TKFloatSpinBox::maxValue() const
546
 
{
547
 
  return TKFloatRangeControl::maxValue();
548
 
}
549
 
 
550
 
void TKFloatSpinBox::setMinValue( float i )
551
 
{
552
 
  setRange( i, maxValue() );
553
 
}
554
 
 
555
 
void TKFloatSpinBox::setMaxValue( float i )
556
 
{
557
 
  setRange( minValue(), i );
558
 
}
559
 
 
560
 
float TKFloatSpinBox::lineStep() const
561
 
{
562
 
  return TKFloatRangeControl::lineStep();
563
 
}
564
 
 
565
 
void TKFloatSpinBox::setLineStep( float i )
566
 
{
567
 
  setSteps( i, pageStep() );
568
 
}
569
 
 
570
 
float TKFloatSpinBox::value()
571
 
{
572
 
  if (edited) {
573
 
    edited = false;
574
 
    interpretText();
575
 
  }
576
 
  return TKFloatRangeControl::value();
577
 
}
578
 
 
579
 
/*******************************************************************************************/
580
 
 
581
 
TKFloatRangeControl::TKFloatRangeControl()
582
 
{
583
 
  minVal = 0.0;
584
 
  maxVal = 1000000.0;
585
 
  line   = 0.1;
586
 
  page   = 1.0;
587
 
  val    = prevVal = 0.0;
588
 
}
589
 
 
590
 
TKFloatRangeControl::TKFloatRangeControl( float minValue, float maxValue, float lineStep, float pageStep, float value )
591
 
{
592
 
  minVal = minValue;
593
 
  maxVal = maxValue;
594
 
  line   = QABS( lineStep );
595
 
  page   = QABS( pageStep );
596
 
  val    = prevVal = bound( value );
597
 
}
598
 
 
599
 
void TKFloatRangeControl::setValue(float value)
600
 
{
601
 
  directSetValue( value );
602
 
  if ( prevVal != val )
603
 
    valueChange();
604
 
}
605
 
 
606
 
void TKFloatRangeControl::directSetValue(float value)
607
 
{
608
 
  prevVal = val;
609
 
  val = bound( value );
610
 
}
611
 
 
612
 
void TKFloatRangeControl::addPage()
613
 
{
614
 
  if ( value() + pageStep() > value() )
615
 
    setValue( value() + pageStep() );
616
 
  else
617
 
    setValue( maxValue() );
618
 
}
619
 
 
620
 
void TKFloatRangeControl::subtractPage()
621
 
{
622
 
  if ( value() - pageStep() < value() )
623
 
    setValue( value() - pageStep() );
624
 
  else
625
 
    setValue( minValue() );
626
 
}
627
 
 
628
 
void TKFloatRangeControl::addLine()
629
 
{
630
 
  setValue( value() + lineStep() );
631
 
}
632
 
 
633
 
void TKFloatRangeControl::subtractLine()
634
 
{
635
 
  setValue( value() - lineStep() );
636
 
}
637
 
 
638
 
void TKFloatRangeControl::setRange(float minValue, float maxValue)
639
 
{
640
 
  if ( minValue == minVal && maxValue == maxVal )
641
 
    return;
642
 
  if ( minValue > maxValue ) {
643
 
        minVal = maxVal = minValue;
644
 
  } else {
645
 
    minVal = minValue;
646
 
    maxVal = maxValue;
647
 
  }
648
 
  float tmp = bound( val );
649
 
  rangeChange();
650
 
  if ( tmp != val ) {
651
 
    prevVal = tmp;
652
 
    val = tmp;
653
 
    valueChange();
654
 
  }
655
 
}
656
 
 
657
 
void TKFloatRangeControl::setSteps(float lineStep,float pageStep)
658
 
{
659
 
  if (lineStep != line || pageStep != page) {
660
 
    line = QABS(lineStep);
661
 
    page = QABS(pageStep);
662
 
    stepChange();
663
 
  }
664
 
}
665
 
 
666
 
void TKFloatRangeControl::valueChange()
667
 
{
668
 
}
669
 
 
670
 
void TKFloatRangeControl::rangeChange()
671
 
{
672
 
}
673
 
 
674
 
void TKFloatRangeControl::stepChange()
675
 
{
676
 
}
677
 
 
678
 
float TKFloatRangeControl::bound(float v) const
679
 
{
680
 
  if ( v - minVal < 1.0e-05 )
681
 
    return minVal;
682
 
  if ( v > maxVal )
683
 
    return maxVal;
684
 
  return v;
685
 
}
686
 
/***************************************************************************************/
687
 
TKUFloatSpinBox::TKUFloatSpinBox( QWidget* parent, const char* name)
688
 
: TKFloatSpinBox(parent,name)
689
 
{
690
 
  hideSuffix = false;
691
 
  setUnit((int)UnitPoint);
692
 
}
693
 
 
694
 
TKUFloatSpinBox::TKUFloatSpinBox( float minValue, float maxValue, float step, int decimal, QWidget* parent, const char* name)
695
 
: TKFloatSpinBox(minValue,maxValue,step,decimal,parent,name)
696
 
{
697
 
  setUnit((int)UnitPoint);
698
 
}
699
 
 
700
 
TKUFloatSpinBox::~TKUFloatSpinBox()
701
 
{
702
 
}
703
 
 
704
 
void TKUFloatSpinBox::setUnit(int unit)
705
 
{
706
 
  blockSignals(true);
707
 
  setSuffix(hideSuffix ? QString::null : unitToString(unit));
708
 
  float v = cvtPtToUnit(unit,cvtUnitToPt(m_unit,TKFloatSpinBox::value()));
709
 
  setMinValue( cvtPtToUnit(unit,cvtUnitToPt(m_unit,minValue())) );
710
 
  setMaxValue( cvtPtToUnit(unit,cvtUnitToPt(m_unit,maxValue())) );
711
 
  TKFloatSpinBox::setValue( v );
712
 
 
713
 
  m_unit = unit;
714
 
  blockSignals(false);
715
 
}
716
 
 
717
 
float TKUFloatSpinBox::value(int unit)
718
 
{
719
 
  return cvtPtToUnit(unit,cvtUnitToPt(m_unit,TKFloatSpinBox::value()));
720
 
}
721
 
 
722
 
void TKUFloatSpinBox::setValue(float value,int unit)
723
 
{
724
 
  TKFloatSpinBox::setValue( cvtPtToUnit(m_unit,cvtUnitToPt(unit,value)) );
725
 
}
726
 
 
727
 
void TKUFloatSpinBox::setHideSuffix(bool f)
728
 
{
729
 
  if (f== hideSuffix)
730
 
    return;
731
 
 
732
 
  hideSuffix = f;
733
 
  setSuffix(hideSuffix ? QString::null : unitToString(m_unit));
734
 
  updateGeometry();
735
 
}
736
 
 
737
 
#include "tkfloatspinbox.moc"