1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-2011 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#ifndef __SPATIUM_H__
#define __SPATIUM_H__
namespace Ms {
//---------------------------------------------------------
// Spatium
// - a unit of measure
// - the distance between two note lines
// - used for many layout items
//---------------------------------------------------------
class Spatium {
qreal _val;
public:
constexpr Spatium() : _val(0.0) {}
explicit Spatium(qreal v) { _val = v; }
constexpr qreal val() const { return _val; }
bool operator>(const Spatium& a) const { return _val > a._val; }
bool operator<(const Spatium& a) const { return _val < a._val; }
bool operator==(const Spatium& a) const { return _val == a._val; }
bool operator!=(const Spatium& a) const { return _val != a._val; }
bool isZero() const { return _val == 0.0; }
Spatium& operator+=(const Spatium& a) {
_val += a._val;
return *this;
}
Spatium& operator-=(const Spatium& a) {
_val -= a._val;
return *this;
}
Spatium& operator/=(qreal d) {
_val /= d;
return *this;
}
qreal operator/(const Spatium& b) {
return _val / b._val;
}
Spatium& operator*=(int d) {
_val *= d;
return *this;
}
Spatium& operator*=(qreal d) {
_val *= d;
return *this;
}
Spatium operator-() const { return Spatium(-_val); }
operator QVariant() const { return QVariant::fromValue(*this); }
static double toDouble(const Spatium& v) { return v._val; }
};
inline Spatium operator+(const Spatium& a, const Spatium& b)
{
Spatium r(a);
r += b;
return r;
}
inline Spatium operator-(const Spatium& a, const Spatium& b)
{
Spatium r(a);
r -= b;
return r;
}
inline Spatium operator/(const Spatium& a, qreal b)
{
Spatium r(a);
r /= b;
return r;
}
inline Spatium operator*(const Spatium& a, int b)
{
Spatium r(a);
r *= b;
return r;
}
inline Spatium operator*(int a, const Spatium& b)
{
Spatium r(b);
r *= a;
return r;
}
inline Spatium operator*(const Spatium& a, qreal b)
{
Spatium r(a);
r *= b;
return r;
}
inline Spatium operator*(qreal a, const Spatium& b)
{
Spatium r(b);
r *= a;
return r;
}
} // namespace Ms
Q_DECLARE_METATYPE(Ms::Spatium);
#endif
|