add line numbers to plugin editor
This commit is contained in:
parent
870beae8de
commit
1daa6078d4
5 changed files with 206 additions and 3 deletions
|
@ -83,6 +83,7 @@ QT4_WRAP_CPP (mocs
|
|||
editstringdata.h editraster.h mediadialog.h chordeditor.h chordview.h album.h layer.h
|
||||
webpage.h inspector.h inspectorBase.h inspectorBeam.h masterpalette.h
|
||||
inspectorGroupElement.h inspectorImage.h waveview.h plugins.h pluginCreator.h
|
||||
qmledit.h
|
||||
${OMR_MOCS}
|
||||
)
|
||||
|
||||
|
@ -176,7 +177,7 @@ add_executable ( ${ExecutableName}
|
|||
inspector.cpp dragelement.cpp svggenerator.cpp
|
||||
inspectorBase.cpp inspectorBeam.cpp masterpalette.cpp
|
||||
inspectorGroupElement.cpp dragdrop.cpp inspectorImage.cpp
|
||||
waveview.cpp musicxmlsupport.cpp pluginCreator.cpp
|
||||
waveview.cpp musicxmlsupport.cpp pluginCreator.cpp qmledit.cpp
|
||||
${OMR_FILES}
|
||||
${AUDIO}
|
||||
)
|
||||
|
|
|
@ -71,7 +71,7 @@
|
|||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<widget class="QPlainTextEdit" name="textEdit"/>
|
||||
<widget class="QmlEdit" name="textEdit"/>
|
||||
<widget class="QTextBrowser" name="log"/>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -113,6 +113,13 @@
|
|||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QmlEdit</class>
|
||||
<extends>QPlainTextEdit</extends>
|
||||
<header>qmledit.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
136
mscore/qmledit.cpp
Normal file
136
mscore/qmledit.cpp
Normal file
|
@ -0,0 +1,136 @@
|
|||
//=============================================================================
|
||||
// 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
|
||||
//=============================================================================
|
||||
|
||||
#include "qmledit.h"
|
||||
|
||||
|
||||
//---------------------------------------------------------
|
||||
// QmlEdit
|
||||
//---------------------------------------------------------
|
||||
|
||||
QmlEdit::QmlEdit(QWidget* parent)
|
||||
: QPlainTextEdit(parent)
|
||||
{
|
||||
lineNumberArea = new LineNumberArea(this);
|
||||
|
||||
connect(this, SIGNAL(blockCountChanged(int)), SLOT(updateLineNumberAreaWidth(int)));
|
||||
connect(this, SIGNAL(updateRequest(QRect,int)), SLOT(updateLineNumberArea(QRect,int)));
|
||||
connect(this, SIGNAL(cursorPositionChanged()), SLOT(highlightCurrentLine()));
|
||||
|
||||
updateLineNumberAreaWidth(0);
|
||||
highlightCurrentLine();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// lineNumberAreaWidth
|
||||
//---------------------------------------------------------
|
||||
|
||||
int QmlEdit::lineNumberAreaWidth()
|
||||
{
|
||||
int digits = 1;
|
||||
int max = qMax(1, blockCount());
|
||||
while (max >= 10) {
|
||||
max /= 10;
|
||||
++digits;
|
||||
}
|
||||
int space = 6 + fontMetrics().width(QLatin1Char('9')) * digits;
|
||||
return space;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// updateLineNumberAreaWidth
|
||||
//---------------------------------------------------------
|
||||
|
||||
void QmlEdit::updateLineNumberAreaWidth(int /* newBlockCount */)
|
||||
{
|
||||
setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// updateLineNumberArea
|
||||
//---------------------------------------------------------
|
||||
|
||||
void QmlEdit::updateLineNumberArea(const QRect& rect, int dy)
|
||||
{
|
||||
if (dy)
|
||||
lineNumberArea->scroll(0, dy);
|
||||
else
|
||||
lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height());
|
||||
|
||||
if (rect.contains(viewport()->rect()))
|
||||
updateLineNumberAreaWidth(0);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// resizeEvent
|
||||
//---------------------------------------------------------
|
||||
|
||||
void QmlEdit::resizeEvent(QResizeEvent *e)
|
||||
{
|
||||
QPlainTextEdit::resizeEvent(e);
|
||||
|
||||
QRect cr = contentsRect();
|
||||
lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// highlightCurrentLine
|
||||
//---------------------------------------------------------
|
||||
|
||||
void QmlEdit::highlightCurrentLine()
|
||||
{
|
||||
QList<QTextEdit::ExtraSelection> extraSelections;
|
||||
|
||||
if (!isReadOnly()) {
|
||||
QTextEdit::ExtraSelection selection;
|
||||
|
||||
QColor lineColor = QColor(Qt::darkGray);
|
||||
|
||||
selection.format.setBackground(lineColor);
|
||||
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
|
||||
selection.cursor = textCursor();
|
||||
selection.cursor.clearSelection();
|
||||
extraSelections.append(selection);
|
||||
}
|
||||
|
||||
setExtraSelections(extraSelections);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// lineNumberAreaPaintEvent
|
||||
//---------------------------------------------------------
|
||||
|
||||
void QmlEdit::lineNumberAreaPaintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPainter painter(lineNumberArea);
|
||||
painter.fillRect(event->rect(), Qt::lightGray);
|
||||
|
||||
QTextBlock block = firstVisibleBlock();
|
||||
int blockNumber = block.blockNumber();
|
||||
int top = (int) blockBoundingGeometry(block).translated(contentOffset()).top();
|
||||
int bottom = top + (int) blockBoundingRect(block).height();
|
||||
|
||||
int w = lineNumberArea->width();
|
||||
int h = fontMetrics().height();
|
||||
while (block.isValid() && top <= event->rect().bottom()) {
|
||||
if (block.isVisible() && bottom >= event->rect().top()) {
|
||||
QString number = QString::number(blockNumber + 1);
|
||||
painter.setPen(Qt::black);
|
||||
painter.drawText(0, top, w-3, h, Qt::AlignRight, number);
|
||||
}
|
||||
|
||||
block = block.next();
|
||||
top = bottom;
|
||||
bottom = top + (int) blockBoundingRect(block).height();
|
||||
++blockNumber;
|
||||
}
|
||||
}
|
59
mscore/qmledit.h
Normal file
59
mscore/qmledit.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
//=============================================================================
|
||||
// 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 __QML_EDIT_H__
|
||||
#define __QML_EDIT_H__
|
||||
|
||||
//---------------------------------------------------------
|
||||
// QmlEdit
|
||||
//---------------------------------------------------------
|
||||
|
||||
class QmlEdit : public QPlainTextEdit {
|
||||
Q_OBJECT
|
||||
|
||||
QWidget* lineNumberArea;
|
||||
|
||||
private slots:
|
||||
void updateLineNumberAreaWidth(int);
|
||||
void highlightCurrentLine();
|
||||
void updateLineNumberArea(const QRect&, int);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent*);
|
||||
|
||||
public:
|
||||
QmlEdit(QWidget* parent = 0);
|
||||
void lineNumberAreaPaintEvent(QPaintEvent*);
|
||||
int lineNumberAreaWidth();
|
||||
};
|
||||
|
||||
//---------------------------------------------------------
|
||||
// LineNumberArea
|
||||
//---------------------------------------------------------
|
||||
|
||||
class LineNumberArea : public QWidget {
|
||||
Q_OBJECT
|
||||
QmlEdit* editor;
|
||||
|
||||
QSize sizeHint() const {
|
||||
return QSize(editor->lineNumberAreaWidth(), 0);
|
||||
}
|
||||
void paintEvent(QPaintEvent* event) {
|
||||
editor->lineNumberAreaPaintEvent(event);
|
||||
}
|
||||
|
||||
public:
|
||||
LineNumberArea(QmlEdit* parent) : QWidget(parent) { editor = parent; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -40,7 +40,7 @@ MuseScore {
|
|||
|
||||
if (typeof curScore === 'undefined')
|
||||
return;
|
||||
var cursor = newCursor();
|
||||
var cursor = curScore.newCursor();
|
||||
for (var track = 0; track < curScore.ntracks; ++track) {
|
||||
cursor.track = track;
|
||||
cursor.rewind(0); // set cursor to first chord/rest
|
||||
|
|
Loading…
Reference in a new issue