void TextBase::endHexState(EditData& ed) { TextEditData* ted = static_cast<TextEditData*>(ed.getData(this)); TextCursor* _cursor = &ted->cursor; if (hexState >= 0) { if (hexState > 0) { int c2 = _cursor->column(); int c1 = c2 - (hexState + 1); TextBlock& t = _layout[_cursor->row()]; QString ss = t.remove(c1, hexState + 1); bool ok; int code = ss.mid(1).toInt(&ok, 16); _cursor->setColumn(c1); _cursor->clearSelection(); if (ok) editInsertText(_cursor, QString(code)); else qDebug("cannot convert hex string <%s>, state %d (%d-%d)", qPrintable(ss.mid(1)), hexState, c1, c2); } hexState = -1; } }
void Image::startDrag(EditData& data) { ImageEditData* ed = new ImageEditData(); ed->e = this; ed->size = _size; data.addData(ed); }
void TextBase::movePosition(EditData& ed, QTextCursor::MoveOperation op) { TextEditData* ted = static_cast<TextEditData*>(ed.getData(this)); TextCursor* _cursor = &ted->cursor; _cursor->movePosition(op); score()->addRefresh(canvasBoundingRect()); score()->update(); }
void TextBase::inputTransition(EditData& ed, QInputMethodEvent* ie) { TextEditData* ted = static_cast<TextEditData*>(ed.getData(this)); TextCursor* _cursor = &ted->cursor; // remove preedit string int n = preEdit.size(); while (n--) { if (_cursor->movePosition(QTextCursor::Left)) { TextBlock& l = _cursor->curLine(); l.remove(_cursor->column()); _cursor->text()->triggerLayout(); _cursor->text()->setTextInvalid(); } } qDebug("<%s><%s> len %d start %d, preEdit size %d", qPrintable(ie->commitString()), qPrintable(ie->preeditString()), ie->replacementLength(), ie->replacementStart(), preEdit.size()); if (!ie->commitString().isEmpty()) { _cursor->format()->setPreedit(false); score()->startCmd(); insertText(ed, ie->commitString()); score()->endCmd(); preEdit.clear(); } else { preEdit = ie->preeditString(); if (!preEdit.isEmpty()) { #if 0 for (auto a : ie->attributes()) { switch(a.type) { case QInputMethodEvent::TextFormat: { qDebug(" attribute TextFormat: %d-%d", a.start, a.length); QTextFormat tf = a.value.value<QTextFormat>(); } break; case QInputMethodEvent::Cursor: qDebug(" attribute Cursor at %d", a.start); break; default: qDebug(" attribute %d", a.type); } } #endif _cursor->format()->setPreedit(true); _cursor->updateCursorFormat(); editInsertText(_cursor, preEdit); setTextInvalid(); layout1(); score()->update(); } } ie->accept(); }
/* CreateFromFile * If the user decides to create your object * from the file you said you were OK with * above, this is where you take that file * and actually create your object from it. * The CreateObject function up above will * not have executed, so you need to initialize * the editdata just as you would in CreateObject. */ void MMF2Func CreateFromFile(mv *mV, LPTSTR FileName, SerializedED *SED) { #ifndef RUN_ONLY Edif::Init(mV, SED); EditData ed; //default EditData // std::ifstream in (FileName); // EditData::MyArray_t::size_type MyArray_size; // in >> ed.MyString >> ed.MyInt >> MyArray_size; // ed.MyArray.clear(); // for(EditData::MyArray_t::size_type i = 0; i < MyArray_size; ++i) // { // ed.MyArray.push_back(0); // in >> ed.MyArray.back(); // } ed.Serialize(mV, SED); #endif }
void TextBase::endEdit(EditData& ed) { TextEditData* ted = static_cast<TextEditData*>(ed.getData(this)); score()->undoStack()->remove(ted->startUndoIdx); // remove all undo/redo records // replace all undo/redo records collected during text editing with // one property change QString actualText = xmlText(); if (ted->oldXmlText.isEmpty()) { UndoStack* us = score()->undoStack(); UndoCommand* ucmd = us->last(); if (ucmd) { const QList<UndoCommand*>& cl = ucmd->commands(); const UndoCommand* cmd = cl.back(); if (strncmp(cmd->name(), "Add:", 4) == 0) { const AddElement* ae = static_cast<const AddElement*>(cmd); if (ae->getElement() == this) { if (actualText.isEmpty()) { // we just created this empty text, rollback that operation us->rollback(); score()->update(); ed.element = 0; } else { setXmlText(ted->oldXmlText); // reset text to value before editing us->reopen(); // combine undo records of text creation with text editing undoChangeProperty(Pid::TEXT, actualText); layout1(); score()->endCmd(); } return; } } } } if (actualText.isEmpty()) { qDebug("actual text is empty"); score()->startCmd(); score()->undoRemoveElement(this); ed.element = 0; score()->endCmd(); return; } setXmlText(ted->oldXmlText); // reset text to value before editing score()->startCmd(); undoChangeProperty(Pid::TEXT, actualText); // change property to set text to actual value again // this also changes text of linked elements layout1(); triggerLayout(); // force relayout even if text did not change score()->endCmd(); static const qreal w = 2.0; score()->addRefresh(canvasBoundingRect().adjusted(-w, -w, w, w)); }
void StaticEditMenu::editItem(uint8_t item, uint8_t key) { int16_t * valuePtr = getEditAddress(item); uint8_t index = getSelectedIndexOrSize(item); EditData d = pgm::read(&staticEditData[index].edit); int dir = 1; if(key == BUTTON_DEC) dir = -1; if(d.step == CE_STEP_TYPE_SMART) { change0ToInfSmart((uint16_t*)valuePtr, dir); } else if(d.step == CE_STEP_TYPE_METHOD) { d.editMethod(dir); goto callback; //TODO:: ?? rewrite } else { *valuePtr += dir*d.step; } if(*valuePtr < d.minValue) *valuePtr = d.minValue; if(*valuePtr > d.maxValue) *valuePtr = d.maxValue; callback: if(editCallback) { editCallback(this, (uint16_t*)valuePtr); } }
void TextBase::insertSym(EditData& ed, SymId id) { TextEditData* ted = static_cast<TextEditData*>(ed.getData(this)); TextCursor* _cursor = &ted->cursor; deleteSelectedText(ed); QString s = score()->scoreFont()->toString(id); CharFormat fmt = *_cursor->format(); // save format // uint code = ScoreFont::fallbackFont()->sym(id).code(); _cursor->format()->setFontFamily("ScoreText"); _cursor->format()->setBold(false); _cursor->format()->setItalic(false); score()->undo(new InsertText(_cursor, s), &ed); _cursor->setFormat(fmt); // restore format }
bool Anm2DAsm::makeFromEditData2Inc(EditData &rEditData, QString qsFname) { qsFname = QFileInfo(qsFname).baseName().toUpper(); m_pModel = rEditData.getObjectModel(); if (m_bFlat) { ObjectModel *p = new ObjectModel(); p->copy(m_pModel); p->flat(); m_pModel = p; } ObjectItem *pRoot = m_pModel->getItemFromIndex(QModelIndex()); // ObjectItem *pObj = pRoot->child(0); addString("; このファイルはAnimationCreatorにより生成されました。\n"); addString("\n"); for (int i = 0; i < pRoot->childCount(); i++) { ObjectItem *pObj = pRoot->child(i); addString("%define\t\tACO_" + qsFname + "__" + pObj->getName().replace(" ", "_").toUpper().toUtf8() + QString("\t\t%1").arg(i) + "\n"); } addString("\n"); for (int i = 0; i < pRoot->childCount(); i++) { ObjectItem *pObj = pRoot->child(i); QVector4D qv4AreaMin = QVector4D(FLT_MAX, FLT_MAX, FLT_MAX, 0); QVector4D qv4AreaMax = QVector4D(FLT_MIN, FLT_MIN, FLT_MIN, 0); QString qsLabel = "ACL_" + qsFname + "__" + pObj->getName().replace(" ", "_").toUpper().toUtf8() + "__"; addString("%define\t\t" + qsLabel + "ROOT\t\t0\n"); makeFromEditDataArea(pObj, &qv4AreaMin, &qv4AreaMax, true); addString("\t\t; Area:" + QString("(%1, %2, %3)-(%4, %5, %6) size:(%7, %8, %9)").arg(qv4AreaMin.x(), 0, 'f').arg(qv4AreaMin.y(), 0, 'f').arg(qv4AreaMin.z(), 0, 'f').arg(qv4AreaMax.x(), 0, 'f').arg(qv4AreaMax.y(), 0, 'f').arg(qv4AreaMax.z(), 0, 'f').arg(qv4AreaMax.x() - qv4AreaMin.x(), 0, 'f').arg(qv4AreaMax.y() - qv4AreaMin.y(), 0, 'f').arg(qv4AreaMax.z() - qv4AreaMin.z(), 0, 'f') + "\n"); m_nCnt = 1; for (int j = 0; j < pObj->childCount(); j++) { ObjectItem *pChild = pObj->child(j); makeFromEditData2IncTip(qsLabel, pChild); } addString("\n"); } return true; }
void TextBase::startEdit(EditData& ed) { ed.grips = 0; TextEditData* ted = new TextEditData(this); ted->e = this; ted->cursor.setRow(0); ted->cursor.setColumn(0); ted->cursor.clearSelection(); Q_ASSERT(!score()->undoStack()->active()); // make sure we are not in a Cmd ted->oldXmlText = xmlText(); ted->startUndoIdx = score()->undoStack()->getCurIdx(); if (layoutInvalid) layout(); if (!ted->cursor.set(ed.startMove)) ted->cursor.init(); qreal _spatium = spatium(); // refresh edit bounding box score()->addRefresh(canvasBoundingRect().adjusted(-_spatium, -_spatium, _spatium, _spatium)); ed.addData(ted); }
void Image::endEditDrag(EditData& ed) { ImageEditData* ied = static_cast<ImageEditData*>(ed.getData(this)); if (_size != ied->size) score()->undoPropertyChanged(this, Pid::SIZE, ied->size); }
bool TextBase::edit(EditData& ed) { TextEditData* ted = static_cast<TextEditData*>(ed.getData(this)); TextCursor* _cursor = &ted->cursor; // do nothing on Shift, it messes up IME on Windows. See #64046 if (ed.key == Qt::Key_Shift) return false; QString s = ed.s; bool ctrlPressed = ed.modifiers & Qt::ControlModifier; bool shiftPressed = ed.modifiers & Qt::ShiftModifier; QTextCursor::MoveMode mm = shiftPressed ? QTextCursor::KeepAnchor : QTextCursor::MoveAnchor; bool wasHex = false; if (hexState >= 0) { if (ed.modifiers == (Qt::ControlModifier | Qt::ShiftModifier | Qt::KeypadModifier)) { switch (ed.key) { case Qt::Key_0: case Qt::Key_1: case Qt::Key_2: case Qt::Key_3: case Qt::Key_4: case Qt::Key_5: case Qt::Key_6: case Qt::Key_7: case Qt::Key_8: case Qt::Key_9: s = QChar::fromLatin1(ed.key); ++hexState; wasHex = true; break; default: break; } } else if (ed.modifiers == (Qt::ControlModifier | Qt::ShiftModifier)) { switch (ed.key) { case Qt::Key_A: case Qt::Key_B: case Qt::Key_C: case Qt::Key_D: case Qt::Key_E: case Qt::Key_F: s = QChar::fromLatin1(ed.key); ++hexState; wasHex = true; break; default: break; } } } if (!wasHex) { // printf("======%x\n", s.isEmpty() ? -1 : s[0].unicode()); switch (ed.key) { case Qt::Key_Z: // happens when the undo stack is empty if (ed.modifiers == Qt::ControlModifier) return true; break; case Qt::Key_Enter: case Qt::Key_Return: deleteSelectedText(ed); score()->undo(new SplitText(_cursor), &ed); return true; case Qt::Key_Delete: if (!deleteSelectedText(ed)) score()->undo(new RemoveText(_cursor, QString(_cursor->currentCharacter())), &ed); return true; case Qt::Key_Backspace: if (!deleteSelectedText(ed)) { if (_cursor->column() == 0 && _cursor->row() != 0) score()->undo(new JoinText(_cursor), &ed); else { if (!_cursor->movePosition(QTextCursor::Left)) return false; score()->undo(new RemoveText(_cursor, QString(_cursor->currentCharacter())), &ed); } } return true; case Qt::Key_Left: if (!_cursor->movePosition(ctrlPressed ? QTextCursor::WordLeft : QTextCursor::Left, mm) && type() == ElementType::LYRICS) return false; s.clear(); break; case Qt::Key_Right: if (!_cursor->movePosition(ctrlPressed ? QTextCursor::NextWord : QTextCursor::Right, mm) && type() == ElementType::LYRICS) return false; s.clear(); break; case Qt::Key_Up: #if defined(Q_OS_MAC) if (!_cursor->movePosition(QTextCursor::Up, mm)) _cursor->movePosition(QTextCursor::StartOfLine, mm); #else _cursor->movePosition(QTextCursor::Up, mm); #endif s.clear(); break; case Qt::Key_Down: #if defined(Q_OS_MAC) if (!_cursor->movePosition(QTextCursor::Down, mm)) _cursor->movePosition(QTextCursor::EndOfLine, mm); #else _cursor->movePosition(QTextCursor::Down, mm); #endif s.clear(); break; case Qt::Key_Home: if (ctrlPressed) _cursor->movePosition(QTextCursor::Start, mm); else _cursor->movePosition(QTextCursor::StartOfLine, mm); s.clear(); break; case Qt::Key_End: if (ctrlPressed) _cursor->movePosition(QTextCursor::End, mm); else _cursor->movePosition(QTextCursor::EndOfLine, mm); s.clear(); break; case Qt::Key_Tab: s = " "; ed.modifiers = 0; break; case Qt::Key_Space: if (ed.modifiers & CONTROL_MODIFIER) s = QString(QChar(0xa0)); // non-breaking space else s = " "; ed.modifiers = 0; break; case Qt::Key_Minus: if (ed.modifiers == 0) s = "-"; break; case Qt::Key_Underscore: if (ed.modifiers == 0) s = "_"; break; case Qt::Key_A: if (ctrlPressed) { selectAll(_cursor); s.clear(); } break; default: break; } if (ctrlPressed && shiftPressed) { switch (ed.key) { case Qt::Key_U: if (hexState == -1) { hexState = 0; s = "u"; } break; case Qt::Key_B: insertSym(ed, SymId::accidentalFlat); return true; case Qt::Key_NumberSign: insertSym(ed, SymId::accidentalSharp); return true; case Qt::Key_H: insertSym(ed, SymId::accidentalNatural); return true; case Qt::Key_Space: insertSym(ed, SymId::space); return true; case Qt::Key_F: insertSym(ed, SymId::dynamicForte); return true; case Qt::Key_M: insertSym(ed, SymId::dynamicMezzo); return true; case Qt::Key_N: insertSym(ed, SymId::dynamicNiente); return true; case Qt::Key_P: insertSym(ed, SymId::dynamicPiano); return true; case Qt::Key_S: insertSym(ed, SymId::dynamicSforzando); return true; case Qt::Key_R: insertSym(ed, SymId::dynamicRinforzando); return true; case Qt::Key_Z: // Ctrl+Z is normally "undo" // but this code gets hit even if you are also holding Shift // so Shift+Ctrl+Z works insertSym(ed, SymId::dynamicZ); return true; } } } if (!s.isEmpty()) { deleteSelectedText(ed); score()->undo(new InsertText(_cursor, s), &ed); } return true; }
void TextBase::insertText(EditData& ed, const QString& s) { TextEditData* ted = static_cast<TextEditData*>(ed.getData(this)); TextCursor* _cursor = &ted->cursor; score()->undo(new InsertText(_cursor, s), &ed); }
bool Anm2DAsm::makeFromEditData(EditData &rEditData) { m_pModel = rEditData.getObjectModel(); if (m_bFlat) { ObjectModel *p = new ObjectModel(); p->copy(m_pModel); p->flat(); m_pModel = p; } ObjectItem *pRoot = m_pModel->getItemFromIndex(QModelIndex()); // 画像をラベル化 // 未使用画像をスキップするテーブル構築 int nVram = 0; { for (int i = 0; i < rEditData.getImageDataListSize(); i++) { if (i >= KM_VRAM_MAX) { return false; } EditData::ImageData *p = rEditData.getImageData(i); if (!p) continue; QFileInfo fi(p->fileName); QString sImageLabel = fi.fileName(); sImageLabel = QString("ID_") + sImageLabel.replace(".", "_").toUpper(); sImageLabel = sImageLabel.toUtf8(); m_aqsVramID[i] = sImageLabel; m_bUnused[i] = true; } for (int i = 0; i < pRoot->childCount(); i++) { ObjectItem *pObj = pRoot->child(i); for (int j = 0; j < pObj->childCount(); j++) { ObjectItem *pChild = pObj->child(j); subUnusedVramSkip(pChild); } } for (int i = 0; i < rEditData.getImageDataListSize(); i++) { if (m_bUnused[i] == false) nVram++; } } addString(";----------------------------------------------------------------\n"); addString("; @kamefile\t" + pRoot->getName().toUtf8() + "\n"); addString(";---------------------------------------------------------------- HEADER\n"); addString("\t\t\%include\t\"../imageid.inc\"\n"); addString("\n"); addString(";---------------------------------------------------------------- DATA\n"); addString("%define\t\tNO_READ\t\t0\n"); addString("%define\t\tF32(f32)\t\t__float32__(f32)\n"); addString("data:\n"); addString(";---------------------------------------------------------------- ANM_HEAD\n"); addString("\t\t\tdb\t\t'ANM0'\t\t; ANM0\n"); addString("\t\t\tdd\t\t00000003h\t\t; uVersion\n"); addString("\t\t\tdd\t\t" + QString("%1").arg(/*rEditData.getImageDataListSize()*/ nVram) + "\t\t; nVram\n"); addString("\t\t\tdd\t\t.vram\t\t; pauVram\n"); addString("\t\t\tdd\t\t" + QString("%1").arg(pRoot->childCount()) + "\t\t; nObject\n"); addString("\t\t\tdd\t\t.object\t\t; paObj\n"); addString("\t\n"); addString("\t.vram:\n"); for (int i = 0; i < rEditData.getImageDataListSize(); i++) { if (i >= KM_VRAM_MAX) { return false; } if (m_bUnused[i]) continue; EditData::ImageData *p = rEditData.getImageData(i); if (!p) continue; QFileInfo fi(p->fileName); QString sImageLabel = fi.fileName(); sImageLabel = QString("ID_") + sImageLabel.replace(".", "_").toUpper(); sImageLabel = sImageLabel.toUtf8(); m_aqsVramID[i] = sImageLabel; addString("\t\t\tdd\t\t" + m_aqsVramID[i] + "\n"); } addString("\t\n"); addString("\t.object:\n"); for (int i = 0; i < pRoot->childCount(); i++) { addString("\t\t\tdd\t\tanmobj" + QString("%1").arg(i) + "\n"); } addString("\n"); for (int i = 0; i < pRoot->childCount(); i++) { ObjectItem *pObj = pRoot->child(i); QVector4D qv4AreaMin = QVector4D(FLT_MAX, FLT_MAX, FLT_MAX, 0); QVector4D qv4AreaMax = QVector4D(FLT_MIN, FLT_MIN, FLT_MIN, 0); addString(";---------------------------------------------------------------- ANM_OBJ\n"); addString("; " + QString(pObj->getName().toUtf8()) + "\n"); addString("anmobj" + QString("%1").arg(i) + ":\n"); if (pObj->childCount()) { if (pObj->getLoop()) { addString("\t\t\tdd\t\t00000001h\t\t; bFlag\n"); } else { addString("\t\t\tdd\t\t00000000h\t\t; bFlag\n"); } // 最小矩形算出 for (int j = 0; j < pObj->childCount(); j++) { ObjectItem *pChild = pObj->child(j); makeFromEditDataArea(pChild, &qv4AreaMin, &qv4AreaMax, true); } addString("\t\t\tdd\t\t" + QString("F32(%1), F32(%2), F32(%3), F32(%4)").arg(qv4AreaMin.x(), 0, 'f').arg(qv4AreaMin.y(), 0, 'f').arg(qv4AreaMax.x(), 0, 'f').arg(qv4AreaMax.y(), 0, 'f') + "\t\t; fvArea\n"); addString("\t\t\tdd\t\t" + QString("%1").arg(pObj->childCount()) + "\t\t; nTip\n"); addString("\t\t\tdd\t\t.tips\t\t; papTip\n"); addString("\t\n"); addString("\t.tips:\n"); for (int j = 0; j < pObj->childCount(); j++) { addString("\t\t\tdd\t\tobj" + QString("%1").arg(i) + "tip" + QString("%1").arg(j) + "\n"); } addString("\n"); for (int j = 0; j < pObj->childCount(); j++) { QString qsLabel = "obj" + QString("%1").arg(i) + "tip" + QString("%1").arg(j); ObjectItem *pChild = pObj->child(j); if (!makeFromEditDataTip(qsLabel, pChild)) { return false; } } } else { addString("\t\t\tdd\t\t00000000h\t\t; bFlag\n"); addString("\t\t\tdd\t\t0, 0, 0, 0\t\t; fvArea\n"); addString("\t\t\tdd\t\t" + QString("%1").arg(pObj->childCount()) + "\t\t; nTip\n"); addString("\t\t\tdd\t\tNO_READ\t\t; papTip\n"); } } addString("\n"); return true; }