~ubuntu-branches/ubuntu/quantal/muse/quantal

« back to all changes in this revision

Viewing changes to widgets/sigscale.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Kobras
  • Date: 2005-08-23 17:19:39 UTC
  • mto: (4.1.1 breezy) (1.1.9) (10.1.6 sid)
  • mto: This revision was merged to the branch mainline in revision 5.
  • Revision ID: james.westby@ubuntu.com-20050823171939-hd8fgzokb4dbj007
Tags: upstream-0.7.1+0.7.2pre2
ImportĀ upstreamĀ versionĀ 0.7.1+0.7.2pre2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//=========================================================
2
 
//  MusE
3
 
//  Linux Music Editor
4
 
//    $Id: sigscale.cpp,v 1.1.1.1 2003/10/29 10:06:24 wschweer Exp $
5
 
//  (C) Copyright 1999 Werner Schweer (ws@seh.de)
6
 
//=========================================================
7
 
 
8
 
#include "sigscale.h"
9
 
#include "midieditor.h"
10
 
#include <qpainter.h>
11
 
#include <qtooltip.h>
12
 
#include "globals.h"
13
 
 
14
 
#include "song.h"
15
 
 
16
 
//---------------------------------------------------------
17
 
//   SigScale
18
 
//---------------------------------------------------------
19
 
 
20
 
SigScale::SigScale(int* r, QWidget* parent, int xs)
21
 
   : View(parent, xs, 1)
22
 
      {
23
 
      QToolTip::add(this, tr("signature scale"));
24
 
      raster = r;
25
 
      pos[0] = song->cpos();
26
 
      pos[1] = song->lpos();
27
 
      pos[2] = song->rpos();
28
 
      button = QMouseEvent::NoButton;
29
 
      setMouseTracking(true);
30
 
      connect(song, SIGNAL(posChanged(int, int, bool)), this, SLOT(setPos(int, int, bool)));
31
 
      setFixedHeight(18);
32
 
      }
33
 
 
34
 
//---------------------------------------------------------
35
 
//   setPos
36
 
//---------------------------------------------------------
37
 
 
38
 
void SigScale::setPos(int idx, int val, bool)
39
 
      {
40
 
      if (val == pos[idx])
41
 
            return;
42
 
      int opos = mapx(pos[idx]);
43
 
      pos[idx] = val;
44
 
      if (!isVisible())
45
 
            return;
46
 
      val = mapx(val);
47
 
      int x = -9;
48
 
      int w = 18;
49
 
      if (opos > val) {
50
 
            w += opos - val;
51
 
            x += val;
52
 
            }
53
 
      else {
54
 
            w += val - opos;
55
 
            x += opos;
56
 
            }
57
 
      redraw(QRect(x, 0, w, height()));
58
 
      }
59
 
 
60
 
void SigScale::viewMousePressEvent(QMouseEvent* event)
61
 
      {
62
 
      button = event->button();
63
 
      viewMouseMoveEvent(event);
64
 
      }
65
 
 
66
 
void SigScale::viewMouseReleaseEvent(QMouseEvent*)
67
 
      {
68
 
      button = QMouseEvent::NoButton;
69
 
      }
70
 
 
71
 
void SigScale::viewMouseMoveEvent(QMouseEvent* event)
72
 
      {
73
 
      int x = sigmap.raster(event->x(), *raster);
74
 
      emit timeChanged(x);
75
 
      int i;
76
 
      switch (button) {
77
 
            case QMouseEvent::LeftButton:
78
 
                  i = 0;
79
 
                  break;
80
 
            case QMouseEvent::MidButton:
81
 
                  i = 1;
82
 
                  break;
83
 
            case QMouseEvent::RightButton:
84
 
                  i = 2;
85
 
                  break;
86
 
            default:
87
 
                  return;
88
 
            }
89
 
      song->setPos(i, x);
90
 
      }
91
 
 
92
 
//---------------------------------------------------------
93
 
//   leaveEvent
94
 
//---------------------------------------------------------
95
 
 
96
 
void SigScale::leaveEvent(QEvent*)
97
 
      {
98
 
      emit timeChanged(-1);
99
 
      }
100
 
 
101
 
//---------------------------------------------------------
102
 
//   draw
103
 
//---------------------------------------------------------
104
 
 
105
 
void SigScale::pdraw(QPainter& p, const QRect& r)
106
 
      {
107
 
      int x = r.x();
108
 
      int w = r.width();
109
 
      int h = height();
110
 
 
111
 
      if (x < 0)
112
 
            x = 0;
113
 
      p.setFont(font3);
114
 
      for (ciSigEvent si = sigmap.begin(); si != sigmap.end(); ++si) {
115
 
            SigEvent* e = si->second;
116
 
            int xp = mapx(e->tick);
117
 
            if (xp > x+w)
118
 
                  break;
119
 
            if (xp+40 < x)
120
 
                  continue;
121
 
            p.drawLine(xp, 0, xp, h/2);
122
 
            p.drawLine(xp, h/2, xp+5, h/2);
123
 
            QString s;
124
 
            s.sprintf("%d/%d", e->z, e->n);
125
 
            p.drawText(xp+8, h-6, s);
126
 
            }
127
 
 
128
 
      //---------------------------------------------------
129
 
      //    draw location marker
130
 
      //---------------------------------------------------
131
 
 
132
 
      p.setPen(red);
133
 
      int xp = mapx(pos[0]);
134
 
      if (xp >= x && xp < x+w)
135
 
            p.drawLine(xp, 0, xp, h);
136
 
      p.setPen(blue);
137
 
      xp = mapx(pos[1]);
138
 
      if (xp >= x && xp < x+w)
139
 
            p.drawLine(xp, 0, xp, h);
140
 
      xp = mapx(pos[2]);
141
 
      if (xp >= x && xp < x+w)
142
 
            p.drawLine(xp, 0, xp, h);
143
 
      }
144
 
 
145