File: plugins.h

package info (click to toggle)
musescore 2.0.3%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 202,532 kB
  • ctags: 58,769
  • sloc: cpp: 257,595; xml: 172,226; ansic: 139,931; python: 6,565; sh: 6,383; perl: 423; makefile: 290; awk: 142; pascal: 67; sed: 3
file content (155 lines) | stat: -rw-r--r-- 4,944 bytes parent folder | download | duplicates (7)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//=============================================================================
//  MuseScore
//  Music Composition & Notation
//
//  Copyright (C) 2012 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 __PLUGINS_H__
#define __PLUGINS_H__

#include "config.h"

#ifdef SCRIPT_INTERFACE
#include "libmscore/element.h"
#include "libmscore/score.h"
#include "libmscore/utils.h"

namespace Ms {

//---------------------------------------------------------
//   @@ FileIO
//   @P source string
//---------------------------------------------------------

class FileIO : public QObject {
      Q_OBJECT

   public:
      Q_PROPERTY(QString source
               READ source
               WRITE setSource
               NOTIFY sourceChanged)
      explicit FileIO(QObject *parent = 0);

      //@ reads file contents and returns a string
      Q_INVOKABLE QString read();
      //@ return true if the file exists
      Q_INVOKABLE bool exists();
      //@ write a string to the file
      Q_INVOKABLE bool write(const QString& data);
      //@ removes the file
      Q_INVOKABLE bool remove();
      //@ returns user's home directory
      Q_INVOKABLE QString homePath() {QDir dir; return dir.homePath();}
      //@ returns a path suitable for a temporary file
      Q_INVOKABLE QString tempPath() {QDir dir; return dir.tempPath();}
      //@ returns the file modification time
      Q_INVOKABLE int modifiedTime();

      QString source() { return mSource; };

   public slots:
      void setSource(const QString& source) { mSource = source; };

   signals:
      void sourceChanged(const QString& source);
      void error(const QString& msg);

   private:
      QString mSource;
      };

//---------------------------------------------------------
//   MsProcess
//   @@ QProcess
//---------------------------------------------------------

class MsProcess : public QProcess {
      Q_OBJECT

   public:
      MsProcess(QObject* parent = 0) : QProcess(parent) {}

   public slots:
      //@ --
      Q_INVOKABLE void start(const QString& program)      { QProcess::start(program); }
      //@ --
      Q_INVOKABLE bool waitForFinished(int msecs = 30000) { return QProcess::waitForFinished(msecs); }
      //@ --
      Q_INVOKABLE QByteArray readAllStandardOutput()      { return QProcess::readAllStandardOutput(); }
      };

//---------------------------------------------------------
//   @@ ScoreView
///    This is an GUI element to show a score.
//
//   @P color  color    background color
//   @P scale  float    scaling factor
//---------------------------------------------------------

class MsScoreView : public QQuickPaintedItem, public MuseScoreView {
      Q_OBJECT
      Q_PROPERTY(QColor color READ color WRITE setColor)
      Q_PROPERTY(qreal  scale READ scale WRITE setScale)

      Score* score;
      int _currentPage;
      QColor _color;
      qreal mag;
      int playPos;
      QRectF _boundingRect;

      QNetworkAccessManager* networkManager;

      virtual void dataChanged(const QRectF&)   { update(); }
      virtual void updateAll()                  { update(); }
      virtual void adjustCanvasPosition(const Element*, bool) {}
      virtual void removeScore()                {}
      virtual void changeEditElement(Element*)  {}
      virtual int gripCount() const             { return 0; }
      virtual const QRectF& getGrip(Grip) const override;
      virtual const QTransform& matrix() const;
      virtual void setDropRectangle(const QRectF&) {}
      virtual void cmdAddSlur(Note*, Note*)     {}
      virtual void cmdAddHairpin(bool)          {}
      virtual void startEdit()                  {}
      virtual void startEdit(Element*, Grip)    {}
      virtual Element* elementNear(QPointF)     { return 0; }

      virtual void paint(QPainter*);

      virtual void setCursor(const QCursor&)    {}
      virtual QCursor cursor() const            { return QCursor(); }
      virtual QRectF boundingRect() const       { return _boundingRect; }
      virtual void drawBackground(QPainter*, const QRectF&) const {}

   public slots:
      //@ --
      Q_INVOKABLE void setScore(Score*);
      //@ --
      Q_INVOKABLE void setCurrentPage(int n);
      //@ --
      Q_INVOKABLE void nextPage();
      //@ --
      Q_INVOKABLE void prevPage();

   public:
      MsScoreView(QQuickItem* parent = 0);
      virtual ~MsScoreView() {}
      QColor color() const            { return _color;        }
      void setColor(const QColor& c)  { _color = c;           }
      qreal scale() const             { return mag;        }
      void setScale(qreal v)          { mag = v;           }
      };
} // namespace Ms
#endif

#endif