MuseScore  3.4
Music composition and notation
util.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2012 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __PLUGIN_API_UTIL_H__
14 #define __PLUGIN_API_UTIL_H__
15 
16 #include "config.h"
17 
18 #include "libmscore/element.h"
19 #include "libmscore/mscoreview.h"
20 #include "libmscore/score.h"
21 #include "libmscore/utils.h"
22 
23 namespace Ms {
24 namespace PluginAPI {
25 
26 class Score;
27 
28 //---------------------------------------------------------
50 //---------------------------------------------------------
51 
52 class FileIO : public QObject {
53  Q_OBJECT
54 
55  public:
57  Q_PROPERTY(QString source
58  READ source
59  WRITE setSource
60  )
62  explicit FileIO(QObject *parent = 0);
63 
69  Q_INVOKABLE QString read();
71  Q_INVOKABLE bool exists();
78  Q_INVOKABLE bool write(const QString& data);
80  Q_INVOKABLE bool remove();
82  Q_INVOKABLE QString homePath() {QDir dir; return dir.homePath();}
84  Q_INVOKABLE QString tempPath() {QDir dir; return dir.tempPath();}
86  Q_INVOKABLE int modifiedTime();
87 
89  QString source() { return mSource; }
90 
91  public slots:
92  void setSource(const QString& source) { mSource = source; }
94 
95  signals:
101  void error(const QString& msg);
102 
103  private:
104  QString mSource;
105  };
106 
107 //---------------------------------------------------------
108 // MsProcess
109 // @@ QProcess
114 //---------------------------------------------------------
115 
116 class MsProcess : public QProcess {
117  Q_OBJECT
118 
119  public:
120  MsProcess(QObject* parent = 0) : QProcess(parent) {}
121 
122  public slots:
123  //@ --
124  Q_INVOKABLE void start(const QString& program) { QProcess::start(program); }
125  //@ --
126  Q_INVOKABLE bool waitForFinished(int msecs = 30000) { return QProcess::waitForFinished(msecs); }
127  //@ --
128  Q_INVOKABLE QByteArray readAllStandardOutput() { return QProcess::readAllStandardOutput(); }
129  };
130 
131 //---------------------------------------------------------
132 // @@ ScoreView
134 //---------------------------------------------------------
135 
136 class ScoreView : public QQuickPaintedItem, public MuseScoreView {
137  Q_OBJECT
139  Q_PROPERTY(QColor color READ color WRITE setColor)
141  Q_PROPERTY(qreal scale READ scale WRITE setScale)
142 
143  Ms::Score* score;
144  int _currentPage;
145  QColor _color;
146  qreal mag;
147  int playPos;
148  QRectF _boundingRect;
149 
150  QNetworkAccessManager* networkManager;
151 
152  virtual void setScore(Ms::Score*) override;
153 
154  virtual void dataChanged(const QRectF&) override { update(); }
155  virtual void updateAll() override { update(); }
156 
157  virtual void paint(QPainter*) override;
158 
159  virtual QRectF boundingRect() const override { return _boundingRect; }
160  virtual void drawBackground(QPainter*, const QRectF&) const override {}
161 
162  public slots:
163  //@ --
164  Q_INVOKABLE void setScore(Ms::PluginAPI::Score*);
165  //@ --
166  Q_INVOKABLE void setCurrentPage(int n);
167  //@ --
168  Q_INVOKABLE void nextPage();
169  //@ --
170  Q_INVOKABLE void prevPage();
171 
172  public:
174  ScoreView(QQuickItem* parent = 0);
175  virtual ~ScoreView() {}
176  QColor color() const { return _color; }
177  void setColor(const QColor& c) { _color = c; }
178  qreal scale() const { return mag; }
179  void setScale(qreal v) { mag = v; }
180  virtual const QRect geometry() const override { return QRect(QQuickPaintedItem::x(), y(), width(), height()); }
182  };
183 } // namespace PluginAPI
184 } // namespace Ms
185 #endif
void setColor(const QColor &c)
Definition: util.h:177
This is an GUI element to show a score.
Definition: util.h:136
Q_INVOKABLE bool remove()
Removes the file.
Definition: util.cpp:102
Q_INVOKABLE bool write(const QString &data)
Writes a string to the file.
Definition: util.cpp:83
MsProcess(QObject *parent=0)
Definition: util.h:120
void error(const QString &msg)
Emitted on file operations errors.
Q_INVOKABLE void start(const QString &program)
Definition: util.h:124
Definition of Score class.
virtual const QRect geometry() const override
Definition: util.h:180
void setScale(qreal v)
Definition: util.h:179
Q_INVOKABLE QByteArray readAllStandardOutput()
Definition: util.h:128
Q_INVOKABLE int modifiedTime()
Returns the file's last modification time.
Definition: util.cpp:117
QString mSource
Definition: util.h:104
virtual QRectF boundingRect() const override
Definition: util.h:159
Q_INVOKABLE bool waitForFinished(int msecs=30000)
Definition: util.h:126
virtual ~ScoreView()
Definition: util.h:175
Provides a simple API to perform file reading and writing operations.
Definition: util.h:52
QColor color() const
Definition: util.h:176
Definition: score.h:36
virtual void drawBackground(QPainter *, const QRectF &) const override
Definition: util.h:160
Q_INVOKABLE QString read()
Reads file contents and returns a string.
Definition: util.cpp:54
Definition: aeolus.cpp:26
Q_INVOKABLE QString tempPath()
Returns a path suitable for a temporary file.
Definition: util.h:84
Start an external program. Available in QML as QProcess.
Definition: util.h:116
qreal scale() const
Definition: util.h:178
QString source()
Definition: util.h:89
Q_INVOKABLE bool exists()
Returns true if the file exists.
Definition: util.cpp:111
Q_INVOKABLE QString homePath()
Returns user's home directory.
Definition: util.h:82
void setSource(const QString &source)
Definition: util.h:92
Definition: mscoreview.h:32
virtual void updateAll() override
Definition: util.h:155