Boolean ProcessText(ATEXT text) { /* unused: text.v, text.npt, text.stf, text.code, text.style */ /* think part=-2 and voice=-2 means above top of system, not attached to staff/part (?) for now, we'll make sure these are positive, otherwise we'd end up core dumping from trying to use negative pointers */ short thisStaffNL = (short) text.stf; short thisPart = text.npt > 0? (gStaffPartMap[thisStaffNL] > 0? gStaffPartMap[thisStaffNL] : text.npt) : 1; short thisVoice = text.v > 0? text.v : 1; short thisStaffXML = text.stf > 0? gStaffToStaffMap[thisStaffNL] : 1; char syllabic[8] = "single"; char directionPlacement[8] = "above"; char tempStr[256]; /* strip out/replace all special chars */ replaceSpecialChars(text.textStr); /* It's a lyric */ if (text.code == 'L') { sprintf(tempStr, " <lyric number=\"%d\">\n", thisVoice); strcat2d(gLyrics, thisPart, thisVoice, tempStr); sprintf(tempStr, " <syllabic>%s</syllabic>\n", syllabic); strcat2d(gLyrics, thisPart, thisVoice, tempStr); sprintf(tempStr, " <text>%s</text>\n", text.textStr); strcat2d(gLyrics, thisPart, thisVoice, tempStr); strcat2d(gLyrics, thisPart, thisVoice, " </lyric>\n"); } else { /* score marking, default to position above the staff should make a point of putting these on the correct staff of a multi-staff part */ sprintf(tempStr, " <direction placement=\"%s\">\n", directionPlacement); strcat1d(gDirections, thisPart, tempStr); strcat1d(gDirections, thisPart, " <direction-type>\n"); sprintf(tempStr, " <words>%s</words>\n", text.textStr); strcat1d(gDirections, thisPart, tempStr); strcat1d(gDirections, thisPart, " </direction-type>\n"); sprintf(tempStr, " <staff>%d</staff>\n", thisStaffXML); strcat1d(gDirections, thisPart, tempStr); strcat1d(gDirections, thisPart, " </direction>\n"); } return TRUE; }
bool Text::edit(MuseScoreView*, int /*grip*/, int key, Qt::KeyboardModifiers modifiers, const QString& s) { if (MScore::debugMode) qDebug("Text::edit(%p) key 0x%x mod 0x%x\n", this, key, int(modifiers)); if (!_editMode || !_cursor) { qDebug("Text::edit(%p): not in edit mode: %d %p\n", this, _editMode, _cursor); return false; } bool lo = type() == INSTRUMENT_NAME; score()->setLayoutAll(lo); static const qreal w = 2.0; // 8.0 / view->matrix().m11(); score()->addRefresh(canvasBoundingRect().adjusted(-w, -w, w, w)); if (modifiers == Qt::ControlModifier) { switch (key) { case Qt::Key_A: // select all _cursor->select(QTextCursor::Document); break; case Qt::Key_B: // toggle bold face { QTextCharFormat f = _cursor->charFormat(); f.setFontWeight(f.fontWeight() == QFont::Bold ? QFont::Normal : QFont::Bold); _cursor->setCharFormat(f); } break; case Qt::Key_I: // toggle italic { QTextCharFormat f = _cursor->charFormat(); f.setFontItalic(!f.fontItalic()); _cursor->setCharFormat(f); } break; case Qt::Key_U: // toggle underline { QTextCharFormat f = _cursor->charFormat(); f.setFontUnderline(!f.fontUnderline()); _cursor->setCharFormat(f); } break; case Qt::Key_Up: { QTextCharFormat f = _cursor->charFormat(); if (f.verticalAlignment() == QTextCharFormat::AlignNormal) f.setVerticalAlignment(QTextCharFormat::AlignSuperScript); else if (f.verticalAlignment() == QTextCharFormat::AlignSubScript) f.setVerticalAlignment(QTextCharFormat::AlignNormal); _cursor->setCharFormat(f); } break; case Qt::Key_Down: { QTextCharFormat f = _cursor->charFormat(); if (f.verticalAlignment() == QTextCharFormat::AlignNormal) f.setVerticalAlignment(QTextCharFormat::AlignSubScript); else if (f.verticalAlignment() == QTextCharFormat::AlignSuperScript) f.setVerticalAlignment(QTextCharFormat::AlignNormal); _cursor->setCharFormat(f); } break; } #ifndef Q_WS_MAC if (key != Qt::Key_Space && key != Qt::Key_Minus) return true; #endif } #ifdef Q_WS_MAC else if (modifiers == Qt::AltModifier) { if (key != Qt::Key_Space && key != Qt::Key_Minus) return true; } #endif QTextCursor::MoveMode mm = (modifiers & Qt::ShiftModifier) ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor; switch (key) { case Qt::Key_Return: _cursor->insertText(QString("\r")); break; case Qt::Key_Backspace: _cursor->deletePreviousChar(); break; case Qt::Key_Delete: _cursor->deleteChar(); break; case Qt::Key_Left: if (!_cursor->movePosition(QTextCursor::Left, mm) && (type() == LYRICS || type() == FIGURED_BASS)) return false; break; case Qt::Key_Right: if (!_cursor->movePosition(QTextCursor::Right, mm) && (type() == LYRICS || type() == FIGURED_BASS)) return false; break; case Qt::Key_Up: _cursor->movePosition(QTextCursor::Up, mm); break; case Qt::Key_Down: _cursor->movePosition(QTextCursor::Down, mm); break; case Qt::Key_Home: _cursor->movePosition(QTextCursor::Start, mm); break; case Qt::Key_End: _cursor->movePosition(QTextCursor::End, mm); break; case Qt::Key_Space: _cursor->insertText(" "); break; case Qt::Key_Minus: _cursor->insertText("-"); break; default: if (!s.isEmpty()) _cursor->insertText(s); break; } if (key == Qt::Key_Return || key == Qt::Key_Space || key == Qt::Key_Tab) { replaceSpecialChars(); } layoutEdit(); return true; }