~ubuntu-branches/ubuntu/oneiric/muse/oneiric

« back to all changes in this revision

Viewing changes to widgets/hitscale.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: hitscale.cpp,v 1.1 2002/01/30 14:54:03 muse Exp $
 
5
//  (C) Copyright 1999 Werner Schweer (ws@seh.de)
 
6
//=========================================================
 
7
 
 
8
#include "hitscale.h"
 
9
#include "midieditor.h"
 
10
#include <qpainter.h>
 
11
 
 
12
#include "song.h"
 
13
 
 
14
//---------------------------------------------------------
 
15
//   HitScale
 
16
//---------------------------------------------------------
 
17
 
 
18
HitScale::HitScale(int* r, QWidget* parent, int xs)
 
19
   : View(parent, xs, 1)
 
20
      {
 
21
      raster = r;
 
22
      pos[0] = song->cpos();
 
23
      pos[1] = song->lpos();
 
24
      pos[2] = song->rpos();
 
25
      button = QMouseEvent::NoButton;
 
26
      setMouseTracking(true);
 
27
      connect(song, SIGNAL(posChanged(int, int, bool)), this, SLOT(setPos(int, int, bool)));
 
28
      setFixedHeight(18);
 
29
      }
 
30
 
 
31
//---------------------------------------------------------
 
32
//   setPos
 
33
//---------------------------------------------------------
 
34
 
 
35
void HitScale::setPos(int idx, int val, bool)
 
36
      {
 
37
      if (val == pos[idx])
 
38
            return;
 
39
      int opos = mapx(pos[idx]);
 
40
      pos[idx] = val;
 
41
      if (!isVisible())
 
42
            return;
 
43
      val = mapx(val);
 
44
      int x = -9;
 
45
      int w = 18;
 
46
      if (opos > val) {
 
47
            w += opos - val;
 
48
            x += val;
 
49
            }
 
50
      else {
 
51
            w += val - opos;
 
52
            x += opos;
 
53
            }
 
54
      paint(QRect(x, 0, w, height()));
 
55
      }
 
56
 
 
57
void HitScale::viewMousePressEvent(QMouseEvent* event)
 
58
      {
 
59
      button = event->button();
 
60
      viewMouseMoveEvent(event);
 
61
      }
 
62
 
 
63
void HitScale::viewMouseReleaseEvent(QMouseEvent*)
 
64
      {
 
65
      button = QMouseEvent::NoButton;
 
66
      }
 
67
 
 
68
void HitScale::viewMouseMoveEvent(QMouseEvent* event)
 
69
      {
 
70
      int x = sigmap.raster(event->x(), *raster);
 
71
      emit timeChanged(x);
 
72
      int i;
 
73
      switch (button) {
 
74
            case QMouseEvent::LeftButton:
 
75
                  i = 0;
 
76
                  break;
 
77
            case QMouseEvent::MidButton:
 
78
                  i = 1;
 
79
                  break;
 
80
            case QMouseEvent::RightButton:
 
81
                  i = 2;
 
82
                  break;
 
83
            default:
 
84
                  return;
 
85
            }
 
86
      song->setPos(i, x);
 
87
      }
 
88
 
 
89
//---------------------------------------------------------
 
90
//   leaveEvent
 
91
//---------------------------------------------------------
 
92
 
 
93
void HitScale::leaveEvent(QEvent*)
 
94
      {
 
95
      emit timeChanged(-1);
 
96
      }
 
97
 
 
98
//---------------------------------------------------------
 
99
//   draw
 
100
//---------------------------------------------------------
 
101
 
 
102
void HitScale::pdraw(QPainter& p, const QRect& r)
 
103
      {
 
104
      int x = r.x();
 
105
      int w = r.width();
 
106
 
 
107
//      x -= 10;
 
108
//      w += 20;
 
109
 
 
110
      if (x < 0)
 
111
            x = 0;
 
112
 
 
113
      //---------------------------------------------------
 
114
      //    draw location marker
 
115
      //---------------------------------------------------
 
116
 
 
117
      p.setPen(red);
 
118
      int xp = mapx(pos[0]);
 
119
      if (xp >= x && xp < x+w)
 
120
            p.drawLine(xp, 0, xp, height());
 
121
      p.setPen(blue);
 
122
      xp = mapx(pos[1]);
 
123
      if (xp >= x && xp < x+w)
 
124
            p.drawLine(xp, 0, xp, height());
 
125
      xp = mapx(pos[2]);
 
126
      if (xp >= x && xp < x+w)
 
127
            p.drawLine(xp, 0, xp, height());
 
128
      }
 
129
 
 
130