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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
|
//=============================================================================
// MusE Score
// Linux Music Score Editor
// $Id: scoreview.h 5599 2012-04-30 08:25:44Z lasconic $
//
// Copyright (C) 2002-2009 Werner Schweer and others
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================
#ifndef __SCANVAS_H__
#define __SCANVAS_H__
#include "globals.h"
#include "libmscore/element.h"
#include "libmscore/durationtype.h"
#include "libmscore/mscore.h"
#include "libmscore/mscoreview.h"
#include "libmscore/pos.h"
namespace Ms {
class ChordRest;
class Rest;
class Element;
class Page;
class Xml;
class Note;
class Lasso;
class ShadowNote;
class Segment;
class Measure;
class System;
class Score;
class ScoreView;
class Text;
class MeasureBase;
class Staff;
class OmrView;
class PositionCursor;
class ContinuousPanel;
class Tuplet;
class FretDiagram;
class Bend;
class TremoloBar;
enum class Grip : signed char;
enum class POS : char;
enum class MagIdx : char;
enum class TEXT : char {
TITLE,
SUBTITLE,
COMPOSER,
POET,
PART,
SYSTEM,
STAFF,
REHEARSAL_MARK
};
//---------------------------------------------------------
// CommandTransition
//---------------------------------------------------------
class CommandTransition : public QAbstractTransition
{
QString val;
protected:
virtual bool eventTest(QEvent* e);
virtual void onTransition(QEvent*) {}
public:
CommandTransition(const QString& cmd, QState* target) : val(cmd) {
setTargetState(target);
}
};
//---------------------------------------------------------
// ScoreViewDragTransition
//---------------------------------------------------------
class ScoreViewDragTransition : public QMouseEventTransition
{
ScoreView* canvas;
protected:
virtual bool eventTest(QEvent* event);
public:
ScoreViewDragTransition(ScoreView* c, QState* target);
};
//---------------------------------------------------------
// CommandEvent
//---------------------------------------------------------
struct CommandEvent : public QEvent
{
QString value;
CommandEvent(const QString& c)
: QEvent(QEvent::Type(QEvent::User+1)), value(c) {}
};
//---------------------------------------------------------
// ScoreView
//---------------------------------------------------------
class ScoreView : public QWidget, public MuseScoreView {
Q_OBJECT
enum States { NORMAL, DRAG, DRAG_OBJECT, EDIT, DRAG_EDIT, LASSO,
NOTE_ENTRY, MAG, PLAY, ENTRY_PLAY, FOTOMODE,
STATES
};
OmrView* _omrView;
// the next elements are used during dragMove to give some visual
// feedback:
// dropTarget: if valid, the element is drawn in a different color
// to mark it as a valid drop target
// dropRectangle: if valid, the rectangle is filled with a
// color to visualize a valid drop area
// dropAnchor: if valid the line is drawn from the current
// cursor position to the current anchor point
// Note:
// only one of the elements is active during drag
const Element* dropTarget; ///< current drop target during dragMove
QRectF dropRectangle; ///< current drop rectangle during dragMove
QLineF dropAnchor; ///< line to current anchor point during dragMove
QTransform _matrix, imatrix;
MagIdx _magIdx;
QStateMachine* sm;
QState* states[STATES];
bool addSelect;
QFocusFrame* focusFrame;
Element* dragElement; // valid in state DRAG_OBJECT
Staff* dragStaff;
qreal staffUserDist; // valid while dragging a staff
EditData data;
Element* curElement; // current item at mouse press
QPoint startMoveI;
QPointF dragOffset;
bool scoreViewDragging; // decide if dragging or clearing selection
// editing mode
QVector<QRectF> grip; // edit "grips"
Grip curGrip;
int grips; // number of used grips
Grip defaultGrip; // grip to start editing
Element* editObject; ///< Valid in edit mode
//--input state:
PositionCursor* _cursor;
ShadowNote* shadowNote;
// Loop In/Out marks in the score
PositionCursor* _curLoopIn;
PositionCursor* _curLoopOut;
// Continuous panel
ContinuousPanel* _continuousPanel;
Lasso* lasso; ///< temporarily drawn lasso selection
Lasso* _foto;
QColor _bgColor;
QColor _fgColor;
QPixmap* _bgPixmap;
QPixmap* _fgPixmap;
virtual void paintEvent(QPaintEvent*);
void paint(const QRect&, QPainter&);
void objectPopup(const QPoint&, Element*);
void measurePopup(const QPoint&, Measure*);
void saveChord(Xml&);
virtual bool event(QEvent* event);
virtual bool gestureEvent(QGestureEvent*);
virtual void resizeEvent(QResizeEvent*);
virtual void wheelEvent(QWheelEvent*);
virtual void dragEnterEvent(QDragEnterEvent*);
virtual void dragLeaveEvent(QDragLeaveEvent*);
virtual void dragMoveEvent(QDragMoveEvent*);
virtual void dropEvent(QDropEvent*);
virtual void focusInEvent(QFocusEvent*);
virtual void focusOutEvent(QFocusEvent*);
virtual void mouseReleaseEvent(QMouseEvent*);
void constraintCanvas(int *dxx, int *dyy);
void contextItem(Element*);
void lassoSelect();
void setShadowNote(const QPointF&);
void drawElements(QPainter& p,const QList<Element*>& el);
void dragTimeAnchorElement(const QPointF& pos);
void dragSymbol(const QPointF& pos);
bool dragMeasureAnchorElement(const QPointF& pos);
void updateGrips();
virtual void lyricsTab(bool back, bool end, bool moveOnly) override;
virtual void lyricsReturn() override;
virtual void lyricsEndEdit() override;
virtual void lyricsUpDown(bool up, bool end) override;
virtual void lyricsMinus() override;
virtual void lyricsUnderscore() override;
void harmonyEndEdit();
void harmonyTab(bool back);
void harmonyBeatsTab(bool noterest, bool back);
void harmonyTicksTab(int ticks);
void figuredBassTab(bool meas, bool back);
void figuredBassTicksTab(int ticks);
void figuredBassEndEdit();
void cmdInsertNote(int note);
void cmdAddPitch(int note, bool addFlag);
void cmdAddFret(int fret);
void cmdAddChordName();
void cmdAddText(TEXT style);
void cmdEnterRest(const TDuration&);
void cmdEnterRest();
void cmdTuplet(int n, ChordRest*);
void cmdTuplet(int);
void cmdCreateTuplet(ChordRest* cr, Tuplet* tuplet);
void cmdRepeatSelection();
void cmdChangeEnharmonic(bool);
void setupFotoMode();
MeasureBase* insertMeasure(Element::Type, MeasureBase*);
MeasureBase* checkSelectionStateForInsertMeasure();
void appendMeasures(int, Element::Type);
MeasureBase* appendMeasure(Element::Type);
void cmdInsertMeasure(Element::Type);
void createElementPropertyMenu(Element* e, QMenu*);
void genPropertyMenu1(Element* e, QMenu* popup);
void genPropertyMenuText(Element* e, QMenu* popup);
void elementPropertyAction(const QString&, Element* e);
void paintPageBorder(QPainter& p, Page* page);
bool dropCanvas(Element*);
void editCmd(const QString&);
void setLoopCursor(PositionCursor* curLoop, int tick, bool isInPos);
void cmdMoveCR(bool left);
void cmdGotoElement(Element*);
bool checkCopyOrCut();
private slots:
void enterState();
void exitState();
void startFotomode();
void stopFotomode();
void startFotoDrag();
void endFotoDrag();
void endFotoDragEdit();
void startScoreViewDrag();
void endScoreViewDrag();
void posChanged(POS pos, unsigned tick);
void loopToggled(bool);
public slots:
void setViewRect(const QRectF&);
virtual void startEdit();
void endEdit();
void endStartEdit() { endEdit(); startEdit(); }
void startDrag();
void endDrag();
void endDragEdit();
void startNoteEntry();
void endNoteEntry();
void endLasso();
void deselectAll();
void editCopy();
void editCut();
void editPaste();
void normalCut();
void normalCopy();
void fotoModeCopy();
void normalPaste();
void cloneElement(Element* e);
void doFotoDragEdit(QMouseEvent* ev);
void updateContinuousPanel();
signals:
void viewRectChanged();
void scaleChanged(double);
void offsetChanged(double, double);
public:
ScoreView(QWidget* parent = 0);
~ScoreView();
QPixmap* fgPixmap() { return _fgPixmap; }
virtual void startEdit(Element*, Grip);
void startEdit(Element*);
void moveCursor(int tick);
int cursorTick() const;
void setCursorOn(bool);
void setBackground(QPixmap*);
void setBackground(const QColor&);
void setForeground(QPixmap*);
void setForeground(const QColor&);
Page* addPage();
void modifyElement(Element* obj);
virtual void setScore(Score* s);
virtual void removeScore() { _score = 0; }
void setMag(qreal m);
bool navigatorVisible() const;
void cmd(const QAction* a);
void startUndoRedo();
void zoomStep(qreal step, const QPoint& pos);
void zoom(qreal _mag, const QPointF& pos);
void contextPopup(QContextMenuEvent* ev);
void editKey(QKeyEvent*);
bool editKeyLyrics(QKeyEvent*);
void dragScoreView(QMouseEvent* ev);
void dragNoteEntry(QMouseEvent* ev);
void noteEntryButton(QMouseEvent* ev);
void doDragElement(QMouseEvent* ev);
void doDragLasso(QMouseEvent* ev);
void doDragFoto(QMouseEvent* ev);
void doDragEdit(QMouseEvent* ev);
void select(QMouseEvent*);
bool mousePress(QMouseEvent* ev);
bool testElementDragTransition(QMouseEvent* ev);
bool editElementDragTransition(QMouseEvent* ev);
bool fotoEditElementDragTransition(QMouseEvent* ev);
bool editScoreViewDragTransition(QMouseEvent* e);
bool editSelectTransition(QMouseEvent* me);
void cmdAddSlur();
void cmdAddHairpin(bool);
void cmdAddNoteLine();
virtual void cmdAddSlur(Note* firstNote, Note* lastNote);
bool noteEntryMode() const;
bool editMode() const;
bool fotoMode() const;
void editInputTransition(QInputMethodEvent* ie);
void onEditPasteTransition(QMouseEvent* ev);
virtual void setDropRectangle(const QRectF&);
virtual void setDropTarget(const Element*) override;
void setDropAnchor(const QLineF&);
const QTransform& matrix() const { return _matrix; }
qreal mag() const;
qreal lmag() const;
MagIdx magIdx() const { return _magIdx; }
void setMag(MagIdx idx, double mag);
qreal xoffset() const;
qreal yoffset() const;
void setOffset(qreal x, qreal y);
QSizeF fsize() const;
void pageNext();
void pagePrev();
void pageTop();
void pageEnd();
QPointF toLogical(const QPoint& p) const { return imatrix.map(QPointF(p)); }
QRectF toLogical(const QRectF& r) const { return imatrix.mapRect(r); }
QRect toPhysical(const QRectF& r) const { return _matrix.mapRect(r).toRect(); }
bool searchMeasure(int i);
bool searchPage(int i);
bool searchRehearsalMark(const QString& s);
void gotoMeasure(Measure*);
void selectMeasure(int m);
void postCmd(const char* cmd) { sm->postEvent(new CommandEvent(cmd)); }
void setFocusRect();
Element* getDragElement() const { return dragElement; }
void changeVoice(int voice);
virtual void drawBackground(QPainter* p, const QRectF& r) const;
bool fotoScoreViewDragTest(QMouseEvent*);
bool fotoScoreViewDragRectTest(QMouseEvent*);
void doDragFotoRect(QMouseEvent*);
void fotoContextPopup(QContextMenuEvent*);
bool fotoRectHit(const QPoint& p);
void paintRect(bool printMode, QPainter& p, const QRectF& r, double mag);
bool saveFotoAs(bool printMode, const QRectF&);
void fotoDragDrop(QMouseEvent*);
const QRectF& getGrip(Grip n) const { return grip[int(n)]; }
int gripCount() const { return grips; } // number of used grips
void changeEditElement(Element*);
void cmdAppendMeasures(int, Element::Type);
void cmdInsertMeasures(int, Element::Type);
void cmdAddRemoveBreaks();
void cmdCopyLyricsToClipboard();
ScoreState mscoreState() const;
void setCursorVisible(bool v);
void showOmr(bool flag);
Element* getCurElement() const { return curElement; } // current item at mouse press
void midiNoteReceived(int pitch, bool chord, int velocity);
void setEditPos(const QPointF&);
virtual void moveCursor() override;
virtual void layoutChanged();
virtual void dataChanged(const QRectF&);
virtual void updateAll() { update(); }
virtual void adjustCanvasPosition(const Element* el, bool playBack);
virtual void setCursor(const QCursor& c) { QWidget::setCursor(c); }
virtual QCursor cursor() const { return QWidget::cursor(); }
void loopUpdate(bool val) { loopToggled(val); }
OmrView* omrView() const { return _omrView; }
void setOmrView(OmrView* v) { _omrView = v; }
Lasso* fotoLasso() const { return _foto; }
Element* getEditObject() { return editObject; }
void setEditObject(Element* e) { editObject = e; }
virtual Element* elementNear(QPointF);
void editFretDiagram(FretDiagram*);
void editBendProperties(Bend*);
void editTremoloBarProperties(TremoloBar*);
};
//---------------------------------------------------------
// DragTransition
//---------------------------------------------------------
class DragTransition : public QEventTransition
{
ScoreView* canvas;
protected:
virtual void onTransition(QEvent* e);
public:
DragTransition(ScoreView* c)
: QEventTransition(c, QEvent::MouseMove), canvas(c) {}
};
extern int searchStaff(const Element* element);
} // namespace Ms
#endif
|