~ubuntu-branches/ubuntu/karmic/muse/karmic-proposed

« back to all changes in this revision

Viewing changes to widgets/tempolabel.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2002-04-23 17:28:23 UTC
  • Revision ID: james.westby@ubuntu.com-20020423172823-w8yplzr81a759xa3
Tags: upstream-0.5.2
ImportĀ upstreamĀ versionĀ 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//=========================================================
 
2
//  MusE
 
3
//  Linux Music Editor
 
4
//    $Id: tempolabel.cpp,v 1.1 2002/01/30 14:54:04 muse Exp $
 
5
//  (C) Copyright 1999 Werner Schweer (ws@seh.de)
 
6
//=========================================================
 
7
 
 
8
#include <qapplication.h>
 
9
#include <qstyle.h>
 
10
#include <qvalidator.h>
 
11
#include "tempolabel.h"
 
12
 
 
13
//---------------------------------------------------------
 
14
//   TempoLabel
 
15
//---------------------------------------------------------
 
16
 
 
17
TempoLabel::TempoLabel(QWidget* parent, const char* name = 0)
 
18
   : QLabel(parent, name)
 
19
      {
 
20
      setFrameStyle(WinPanel | Sunken);
 
21
      setLineWidth(2);
 
22
      setMidLineWidth(3);
 
23
      _value = 1.0;
 
24
      setValue(0.0);
 
25
      int fw = style().pixelMetric(QStyle::PM_DefaultFrameWidth, this);
 
26
      setIndent(fw);
 
27
      }
 
28
 
 
29
//---------------------------------------------------------
 
30
//   setVal
 
31
//---------------------------------------------------------
 
32
 
 
33
void TempoLabel::setValue(int val)
 
34
      {
 
35
      setValue(double(val/1000.0));
 
36
      }
 
37
 
 
38
void TempoLabel::setValue(double val)
 
39
      {
 
40
      if (val == _value)
 
41
            return;
 
42
      _value = val;
 
43
      QString s = QString("%1").arg(val, 3, 'f', 2);
 
44
      setText(s);
 
45
      }
 
46
 
 
47
//---------------------------------------------------------
 
48
//   sizeHint
 
49
//---------------------------------------------------------
 
50
 
 
51
QSize TempoLabel::sizeHint() const
 
52
      {
 
53
      QFontMetrics fm(font());
 
54
      int fw = style().pixelMetric(QStyle::PM_DefaultFrameWidth, this);
 
55
      int h  = fm.height() + fw * 2;
 
56
      int w  = 2 + fm.width("000.00") +  fw * 4;
 
57
      return QSize(w, h).expandedTo(QApplication::globalStrut());
 
58
      }
 
59
 
 
60
//---------------------------------------------------------
 
61
//   TempoSpinBox
 
62
//---------------------------------------------------------
 
63
 
 
64
TempoSpinBox::TempoSpinBox(QWidget* parent, const char* name = 0)
 
65
   : QSpinBox(parent, name)
 
66
      {
 
67
      setLineStep(100);
 
68
      setMaxValue(60000);
 
69
      setMinValue(3000);
 
70
      setValidator(new QDoubleValidator(this));
 
71
      connect(this, SIGNAL(valueChanged(int)), SLOT(tempoChanged(int)));
 
72
      }
 
73
 
 
74
//---------------------------------------------------------
 
75
//   sizeHint
 
76
//---------------------------------------------------------
 
77
 
 
78
QSize TempoSpinBox::sizeHint() const
 
79
      {
 
80
      QFontMetrics fm(font());
 
81
      int fw = style().pixelMetric(QStyle::PM_DefaultFrameWidth, this);
 
82
      int h  = fm.height() + fw * 2;
 
83
      int w  = 2 + fm.width("000.00") +  fw * 4 + 30;
 
84
      return QSize(w, h).expandedTo(QApplication::globalStrut());
 
85
      }
 
86
 
 
87
//---------------------------------------------------------
 
88
//   mapValueToText
 
89
//---------------------------------------------------------
 
90
 
 
91
QString TempoSpinBox::mapValueToText(int val)
 
92
      {
 
93
      double v = val / 100.0;
 
94
      return QString("%1").arg(v, 3, 'f', 2);
 
95
      }
 
96
 
 
97
//---------------------------------------------------------
 
98
//   mapTextToValue
 
99
//---------------------------------------------------------
 
100
 
 
101
int TempoSpinBox::mapTextToValue(bool* ok)
 
102
      {
 
103
      double v = text().toDouble(ok);
 
104
      return int(v * 100);
 
105
      }
 
106
 
 
107
//---------------------------------------------------------
 
108
//   tempoChanged
 
109
//---------------------------------------------------------
 
110
 
 
111
void TempoSpinBox::tempoChanged(int val)
 
112
      {
 
113
      emit valueChanged(double(val)/100.0);
 
114
      }
 
115
 
 
116
//---------------------------------------------------------
 
117
//   setValue
 
118
//---------------------------------------------------------
 
119
 
 
120
void TempoSpinBox::setValue(double val)
 
121
      {
 
122
      QSpinBox::setValue(int(val*100));
 
123
      }
 
124