diff --git a/develop/managers/assetmanager/animationbuilder.h b/develop/managers/assetmanager/animationbuilder.h deleted file mode 100644 index 2915252f3..000000000 --- a/develop/managers/assetmanager/animationbuilder.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef ANIMATIONBUILDER_H -#define ANIMATIONBUILDER_H - -#include - -#include - -#include - -class EntryState : public GraphNode { - Q_OBJECT -public: - Vector2 defaultSize() const override; - Vector4 color() const override; - - bool isState() const override; - -}; - -class BaseState : public EntryState { - Q_OBJECT - Q_CLASSINFO("Group", "States") - - Q_PROPERTY(QString Name READ objectName WRITE setObjectName NOTIFY updated DESIGNABLE true USER true) - Q_PROPERTY(Template Clip READ clip WRITE setClip NOTIFY updated DESIGNABLE true USER true) - Q_PROPERTY(bool Loop READ loop WRITE setLoop NOTIFY updated DESIGNABLE true USER true) - -public: - Q_INVOKABLE BaseState(); - - Template clip() const; - void setClip(const Template &path); - - bool loop() const; - void setLoop(bool loop); - -signals: - void updated(); - -public: - Template m_path; - bool m_loop; - -}; - -class AnimationBuilderSettings : public AssetConverterSettings { -public: - AnimationBuilderSettings(); -private: - QString defaultIcon(QString) const Q_DECL_OVERRIDE; - -}; - -class AnimationNodeGraph : public AbstractNodeGraph { - Q_OBJECT - -public: - AnimationNodeGraph(); - - void load(const QString &path) Q_DECL_OVERRIDE; - void save(const QString &path) Q_DECL_OVERRIDE; - - void loadGraph(const QVariantMap &data) Q_DECL_OVERRIDE; - - Variant object() const; - - QStringList nodeList() const Q_DECL_OVERRIDE; - -private: - GraphNode *createRoot() Q_DECL_OVERRIDE; - GraphNode *nodeCreate(const QString &path, int &index) Q_DECL_OVERRIDE; - Link *linkCreate(GraphNode *sender, NodePort *oport, GraphNode *receiver, NodePort *iport) Q_DECL_OVERRIDE; - - void loadUserValues(GraphNode *node, const QVariantMap &values) Q_DECL_OVERRIDE; - void saveUserValues(GraphNode *node, QVariantMap &values) Q_DECL_OVERRIDE; - -protected: - Variant data() const; - - GraphNode *m_entry; - QString m_path; - - QStringList m_functions; - -}; - -class AnimationBuilder : public AssetConverter { -private: - QStringList suffixes() const Q_DECL_OVERRIDE { return {"actl"}; } - - ReturnCode convertFile(AssetConverterSettings *s) Q_DECL_OVERRIDE; - AssetConverterSettings *createSettings() const Q_DECL_OVERRIDE; - - QString templatePath() const Q_DECL_OVERRIDE { return ":/Templates/Animation_Controller.actl"; } - -private: - AnimationNodeGraph m_model; -}; - -#endif // ANIMATIONBUILDER_H diff --git a/modules/editor/codeeditor/editor/codeedit.cpp b/modules/editor/codeeditor/editor/codeedit.cpp deleted file mode 100644 index d89a32541..000000000 --- a/modules/editor/codeeditor/editor/codeedit.cpp +++ /dev/null @@ -1,1422 +0,0 @@ -#include "codeedit.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -namespace { - const char *gFont("Editors/Text_Editor/Font/Font_Name"); - const char *gZoom("Editors/Text_Editor/Font/Zoom"); - - const char *gLineNumbers("Editors/Text_Editor/Display/Line_Numbers"); - const char *gFoldingMarkers("Editors/Text_Editor/Display/Folding_Markers"); - const char *gWhitespaces("Editors/Text_Editor/Display/Whitespaces"); - - const char *gSpaces("Editors/Text_Editor/Indents/Use_Spaces"); - const char *gTabSize("Editors/Text_Editor/Indents/Tab_Size"); -}; - -CodeEdit::CodeEdit(QWidget *parent) : - QPlainTextEdit(parent), - m_highlighter(new KSyntaxHighlighting::SyntaxHighlighter(document())), - m_classModel(nullptr), - m_sideBar(new CodeEditSidebar(this)), - m_spaceTabs(true), - m_spaceIndent(4), - m_blockSelection(false), - m_blockPosition(0), - m_columnPosition(0), - m_blockAnchor(0), - m_columnAnchor(0), - m_displayLineNumbers(true), - m_displayFoldingMarkers(true), - m_cursorVisible(false) { - - setLineWrapMode(QPlainTextEdit::NoWrap); - - m_repository.addCustomSearchPath(":/Themes"); - setTheme(m_repository.theme("Thunder Dark")); - - connect(this, &QPlainTextEdit::blockCountChanged, this, &CodeEdit::updateSidebarGeometry); - connect(this, &QPlainTextEdit::updateRequest, this, &CodeEdit::updateSidebarArea); - connect(this, &QPlainTextEdit::cursorPositionChanged, this, &CodeEdit::highlightCurrentLine); - - QTextOption option = document()->defaultTextOption(); - option.setFlags(option.flags() | QTextOption::AddSpaceForLineAndParagraphSeparators); - document()->setDefaultTextOption(option); - - SettingsManager *settings = SettingsManager::instance(); - settings->registerProperty(qPrintable(gFont), "Source Code Pro"); - settings->registerProperty(qPrintable(gZoom), QVariant::fromValue(100)); - - settings->registerProperty(qPrintable(gLineNumbers), QVariant::fromValue(true)); - settings->registerProperty(qPrintable(gFoldingMarkers), QVariant::fromValue(true)); - settings->registerProperty(qPrintable(gWhitespaces), QVariant::fromValue(false)); - - settings->registerProperty(qPrintable(gSpaces), QVariant::fromValue(true)); - settings->registerProperty(qPrintable(gTabSize), QVariant::fromValue(4)); - - connect(settings, &SettingsManager::updated, this, &CodeEdit::onApplySettings); - - onApplySettings(); - - startTimer(500); -} - -CodeEdit::~CodeEdit() { - delete m_highlighter; - delete m_sideBar; -} - -void CodeEdit::openFile(const QString &fileName) { - m_fileName = fileName; - QFile fp(m_fileName); - if(!fp.open(QFile::ReadOnly)) { - qWarning() << "Failed to open" << m_fileName << ":" << fp.errorString(); - return; - } - clear(); - - loadDefinition(m_fileName); - - checkClassMap(); - - if(m_classModel) { - connect(m_classModel, &QAbstractItemModel::layoutChanged, this, &CodeEdit::onClassModelChanged); - onClassModelChanged(); - } - - setPlainText(QString::fromUtf8(fp.readAll())); -} - -void CodeEdit::saveFile(const QString &path) { - if(!path.isEmpty()) { - m_fileName = path; - } - QFile fp(m_fileName); - if(!fp.open(QFile::WriteOnly)) { - qWarning() << "Failed to open" << m_fileName << ":" << fp.errorString(); - return; - } - - fp.write(toPlainText().toUtf8()); - fp.close(); - - document()->setModified(false); -} - -void CodeEdit::checkClassMap() { - for(auto &it : PluginManager::instance()->extensions("converter")) { - AssetConverter *converter = reinterpret_cast(PluginManager::instance()->getPluginObject(it)); - - for(QString &format : converter->suffixes()) { - if(format.toLower() == QFileInfo(m_fileName).suffix()) { - CodeBuilder *builder = dynamic_cast(converter); - if(builder) { - m_classModel = builder->classMap(); - return; - } - } - } - } -} - -void CodeEdit::loadDefinition(const QString &name) { - m_definition = m_repository.definitionForFileName(name); - m_highlighter->setDefinition(m_definition); -} - -void CodeEdit::setSpaceTabs(bool enable, uint32_t indent) { - m_spaceTabs = enable; - m_spaceIndent = (indent == 0) ? 4 : indent; -} - -void CodeEdit::displayLineNumbers(bool visible) { - m_displayLineNumbers = visible; - updateSidebarGeometry(); -} - -void CodeEdit::displayFoldingMarkers(bool visible) { - m_displayFoldingMarkers = visible; - updateSidebarGeometry(); -} - -void CodeEdit::decorateWhitespaces(bool value) { - QTextOption option = document()->defaultTextOption(); - if(value) { - option.setFlags(option.flags() | QTextOption::ShowTabsAndSpaces); - } else { - option.setFlags(option.flags() & ~QTextOption::ShowTabsAndSpaces); - } - document()->setDefaultTextOption(option); -} - -void CodeEdit::highlightBlock(const QString &text) { - QList extraSelections; - - QTextCursor cursor(document()); - cursor = document()->find(text, cursor); - - while(!cursor.isNull()) { - QTextEdit::ExtraSelection extra; - extra.format.setBackground(QColor(m_highlighter->theme().editorColor(KSyntaxHighlighting::Theme::SearchHighlight))); - extra.cursor = cursor; - extraSelections.append(extra); - - cursor = document()->find(text, cursor); - } - setExtraSelections(extraSelections); -} - -bool CodeEdit::findString(const QString &string, bool reverse, bool casesens, bool words) { - QTextDocument::FindFlags flag; - if(reverse) { - flag |= QTextDocument::FindBackward; - } - if(casesens) { - flag |= QTextDocument::FindCaseSensitively; - } - if(words) { - flag |= QTextDocument::FindWholeWords; - } - - QTextCursor cursor = textCursor(); - QTextCursor cursorSaved = cursor; - - if(!find(string, flag)) { - cursor.movePosition(reverse ? QTextCursor::End : QTextCursor::Start); - - setTextCursor(cursor); - - if(!find(string, flag)) { - setTextCursor(cursorSaved); - } - return false; - } - return true; -} - -void CodeEdit::replaceSelected(const QString &string) { - QTextCursor cursor = textCursor(); - - int start = cursor.selectionStart(); - int end = cursor.selectionEnd(); - - if(!cursor.hasSelection()) { - return; - } - - cursor.setPosition(end, QTextCursor::KeepAnchor); - QTextBlock endBlock = cursor.block(); - - cursor.setPosition(start, QTextCursor::KeepAnchor); - QTextBlock block = cursor.block(); - - for(; block.isValid() && !(endBlock < block); block = block.next()) { - if (!block.isValid()) { - continue; - } - - cursor.movePosition(QTextCursor::StartOfLine); - cursor.clearSelection(); - cursor.insertText(string); - cursor.movePosition(QTextCursor::NextBlock); - } -} - -void CodeEdit::reportIssue(int level, int line, int col, const QString &text) { - -} - -void CodeEdit::contextMenuEvent(QContextMenuEvent *event) { - QMenu *menu = createStandardContextMenu(event->pos()); - menu->exec(event->globalPos()); - delete menu; -} - -void CodeEdit::resizeEvent(QResizeEvent *event) { - QPlainTextEdit::resizeEvent(event); - updateSidebarGeometry(); -} - -void CodeEdit::keyPressEvent(QKeyEvent *event) { - if(isReadOnly()) { - event->accept(); - return; - } - - if(event == QKeySequence::InsertParagraphSeparator) { - QTextCursor cursor = textCursor(); - cursor.beginEditBlock(); - - int32_t indentRemain = firstNonIndent(cursor.block().text()); - if(m_highlighter->startsFoldingRegion(cursor.block())) { - indentRemain += (m_spaceTabs) ? m_spaceIndent : 1; - } - - cursor.insertBlock(); - - QString text; - text.fill((m_spaceTabs) ? ' ' : '\t', indentRemain); - cursor.insertText(text); - - cursor.endEditBlock(); - - event->accept(); - return; - } - - if(m_blockSelection) { - if(event == QKeySequence::Copy) { - QApplication::clipboard()->setText(copyBlockSelection()); - - event->accept(); - return; - } else if(event == QKeySequence::Cut) { - QApplication::clipboard()->setText(copyBlockSelection()); - removeBlockSelection(); - - event->accept(); - return; - } else if(event == QKeySequence::Delete || event->key() == Qt::Key_Backspace) { - if(m_columnPosition == m_columnAnchor) { - if(event == QKeySequence::Delete) { - ++m_columnPosition; - } else if(m_columnPosition > 0) { - --m_columnPosition; - } - } - removeBlockSelection(); - - event->accept(); - return; - } else if(event == QKeySequence::Paste) { - removeBlockSelection(); - //paste(); - } - } - - switch(event->key()) { - case Qt::Key_Slash: { - if(event->modifiers() == Qt::ControlModifier) { - commentSelection(); - - event->accept(); - return; - } - } break; - case Qt::Key_Tab: { - if(m_blockSelection && qMin(m_columnPosition, m_columnAnchor) != qMax(m_columnPosition, m_columnAnchor)) { - removeBlockSelection(); - } else { - indentSelection(); - } - event->accept(); - return; - } break; - case Qt::Key_Insert: { - if(event->modifiers() == Qt::NoModifier) { - setOverwriteMode(!overwriteMode()); - event->accept(); - return; - } - } break; - default: break; - } - - if(m_blockSelection) { - const QString text = event->text(); - if(!text.isEmpty() && - (text.at(0).isPrint() || text.at(0) == QLatin1Char('\t'))) { - insertIntoBlockSelection(text); - - return; - } - } - - QPlainTextEdit::keyPressEvent(event); -} - -void CodeEdit::mousePressEvent(QMouseEvent *event) { - if(event->buttons() & Qt::LeftButton) { - if(event->modifiers() & Qt::AltModifier) { - QTextCursor cur = cursorForPosition(event->pos()); - int col = column(cur.block().text(), cur.positionInBlock()); - if (cur.positionInBlock() == cur.block().length() - 1) { - col += (event->pos().x() - cursorRect(cur).center().x()) / QFontMetricsF(font()).width(QLatin1Char(' ')); - } - - int block = cur.blockNumber(); - if(block == blockCount() - 1) { - block += (event->pos().y() - cursorRect(cur).center().y()) / QFontMetricsF(font()).lineSpacing(); - } - if(m_blockSelection) { - m_blockPosition = block; - m_columnPosition = col; - - doSetTextCursor(cursor(), true); - viewport()->update(); - } else { - enableBlockSelection(block, col, block, col); - } - } else { - if(m_blockSelection) { - disableBlockSelection(); - } - } - } - QPlainTextEdit::mousePressEvent(event); -} - -void CodeEdit::mouseReleaseEvent(QMouseEvent *event) { - QPlainTextEdit::mouseReleaseEvent(event); -} - -void CodeEdit::mouseMoveEvent(QMouseEvent *event) { - QPlainTextEdit::mouseMoveEvent(event); - - if(event->buttons() & Qt::LeftButton) { - if(event->modifiers() & Qt::AltModifier) { - if(m_blockSelection) { - QTextCursor cur = textCursor(); - int32_t col = column(cur.block().text(), cur.positionInBlock()); - if(cur.positionInBlock() == cur.block().length() - 1) { - col += (event->pos().x() - cursorRect().center().x()) / QFontMetricsF(font()).width(QLatin1Char(' ')); - } - - m_blockPosition = cur.blockNumber(); - m_columnPosition = col; - - doSetTextCursor(cursor(), true); - viewport()->update(); - } else { - if(textCursor().hasSelection()) { - QTextCursor cursor = textCursor(); - - QTextBlock positionTextBlock = cursor.block(); - int32_t positionBlock = positionTextBlock.blockNumber(); - int32_t positionColumn = column(positionTextBlock.text(), cursor.position() - positionTextBlock.position()); - - const QTextDocument *document = cursor.document(); - QTextBlock anchorTextBlock = document->findBlock(cursor.anchor()); - int32_t anchorBlock = anchorTextBlock.blockNumber(); - int32_t anchorColumn = column(anchorTextBlock.text(), cursor.anchor() - anchorTextBlock.position()); - - enableBlockSelection(positionBlock, anchorColumn, anchorBlock, positionColumn); - } else { - const QTextCursor &cursor = cursorForPosition(event->pos()); - int32_t col = column(cursor.block().text(), cursor.positionInBlock()); - if(cursor.positionInBlock() == cursor.block().length() - 1) { - col += (event->pos().x() - cursorRect().center().x()) / QFontMetricsF(font()).width(QLatin1Char(' ')); - } - - int32_t block = cursor.blockNumber(); - if(block == blockCount() - 1) { - block += (event->pos().y() - cursorRect().center().y()) / QFontMetricsF(font()).lineSpacing(); - } - enableBlockSelection(block, col, block, col); - } - } - } - } -} - -void CodeEdit::paintEvent(QPaintEvent *event) { - QPainter painter(viewport()); - - QPointF offset(contentOffset()); - QRect er = event->rect(); - QRect viewportRect = viewport()->rect(); - bool editable = !isReadOnly(); - QTextBlock block = firstVisibleBlock(); - qreal maximumWidth = document()->documentLayout()->documentSize().width(); - - painter.setBrushOrigin(offset); - - int maxX = offset.x() + qMax((qreal)viewportRect.width(), maximumWidth) - document()->documentMargin(); - er.setRight(qMin(er.right(), maxX)); - painter.setClipRect(er); - - QAbstractTextDocumentLayout::PaintContext context = getPaintContext(); - painter.setPen(context.palette.text().color()); - while(block.isValid()) { - QRectF r = blockBoundingRect(block).translated(offset); - QTextLayout *layout = block.layout(); - if(!block.isVisible()) { - offset.ry() += r.height(); - block = block.next(); - continue; - } - if(r.bottom() >= er.top() && r.top() <= er.bottom()) { - QTextBlockFormat blockFormat = block.blockFormat(); - - QVector selections; - - int blpos = block.position(); - int bllen = block.length(); - - setupSelections(block, blpos, bllen, selections); - - QRectF rect; - paintBlockSelection(block, painter, offset, rect); - - bool drawCursor = ((editable || (textInteractionFlags() & Qt::TextSelectableByKeyboard)) && - context.cursorPosition >= blpos && - context.cursorPosition < blpos + bllen); - bool drawCursorAsBlock = drawCursor && overwriteMode(); - if(drawCursorAsBlock) { - if(context.cursorPosition == blpos + bllen - 1) { - drawCursorAsBlock = false; - } else { - QTextLayout::FormatRange o; - o.start = context.cursorPosition - blpos; - o.length = 1; - o.format.setForeground(palette().base()); - o.format.setBackground(palette().text()); - selections.append(o); - } - } - - layout->draw(&painter, offset, selections, er); - - if(!m_blockSelection) { - if((drawCursor && !drawCursorAsBlock) || - (editable && context.cursorPosition < -1 && !layout->preeditAreaText().isEmpty())) { - int cpos = context.cursorPosition; - if(cpos < -1) { - cpos = layout->preeditAreaPosition() - (cpos + 2); - } else { - cpos -= blpos; - } - layout->drawCursor(&painter, offset, cpos, cursorWidth()); - } - } else if(rect.isValid() && m_cursorVisible) { - painter.fillRect(rect, palette().text()); - } - } - offset.ry() += r.height(); - if(offset.y() > viewportRect.height()) { - break; - } - block = block.next(); - } -} - -void CodeEdit::timerEvent(QTimerEvent *event) { - m_cursorVisible = !m_cursorVisible; - update(); -} - -void CodeEdit::commentSelection() { - QTextCursor cursor = textCursor(); - - int pos = cursor.position(); - int anchor = cursor.anchor(); - int start = qMin(anchor, pos); - int end = qMax(anchor, pos); - - bool hasSelection = cursor.hasSelection(); - - QTextDocument *doc = document(); - QTextBlock startBlock = doc->findBlock(start); - QTextBlock endBlock = doc->findBlock(end); - - static const QString singleLine("//"); - static const QString multiLineBegin("/*"); - static const QString multiLineEnd("*/"); - - static const bool hasMultiLineStyle = true; - static const bool hasSingleLineStyle = true; - - bool doMultiLineStyleComment = false; - bool doMultiLineStyleUncomment = false; - bool anchorIsStart = (anchor == start); - - cursor.beginEditBlock(); - - if(hasSelection && hasMultiLineStyle) { - QString startText = startBlock.text(); - int startPos = start - startBlock.position(); - const int multiLineStartLength = multiLineBegin.length(); - bool hasLeadingCharacters = !startText.left(startPos).trimmed().isEmpty(); - - int pos = startPos - multiLineStartLength; - if(startPos >= multiLineStartLength && - startText.indexOf(multiLineBegin, pos) == pos) { - startPos -= multiLineStartLength; - start -= multiLineStartLength; - } - - bool hasSelStart = (startPos <= startText.length() - multiLineStartLength) && - (startText.indexOf(multiLineBegin, startPos) == startPos); - - QString endText = endBlock.text(); - int endPos = end - endBlock.position(); - const int multiLineEndLength = multiLineEnd.length(); - bool hasTrailingCharacters = - !endText.left(endPos).remove(singleLine).trimmed().isEmpty() - && !endText.mid(endPos).trimmed().isEmpty(); - - if(endPos <= endText.length() - multiLineEndLength && endText.indexOf(multiLineEnd, endPos) == endPos) { - endPos += multiLineEndLength; - end += multiLineEndLength; - } - - pos = endPos - multiLineEndLength; - bool hasSelEnd = endPos >= multiLineEndLength && endText.indexOf(multiLineEnd, pos) == pos; - - doMultiLineStyleUncomment = hasSelStart && hasSelEnd; - doMultiLineStyleComment = !doMultiLineStyleUncomment && (hasLeadingCharacters || hasTrailingCharacters || !hasSingleLineStyle); - - } else if(!hasSelection && !hasSingleLineStyle) { - QString text = startBlock.text().trimmed(); - doMultiLineStyleUncomment = text.startsWith(multiLineBegin) && text.endsWith(multiLineEnd); - doMultiLineStyleComment = !doMultiLineStyleUncomment && !text.isEmpty(); - - start = startBlock.position(); - end = endBlock.position() + endBlock.length() - 1; - - if(doMultiLineStyleUncomment) { - int offset = 0; - text = startBlock.text(); - const int length = text.length(); - while(offset < length && text.at(offset).isSpace()) { - ++offset; - } - start += offset; - } - } - - if(doMultiLineStyleUncomment) { - cursor.setPosition(end); - cursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor, multiLineEnd.length()); - cursor.removeSelectedText(); - cursor.setPosition(start); - cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, multiLineBegin.length()); - cursor.removeSelectedText(); - } else if(doMultiLineStyleComment) { - cursor.setPosition(end); - cursor.insertText(multiLineEnd); - cursor.setPosition(start); - cursor.insertText(multiLineBegin); - } else { - endBlock = endBlock.next(); - - bool doSingleLineStyleUncomment = true; - for(QTextBlock block = startBlock; block != endBlock; block = block.next()) { - QString text = block.text().trimmed(); - if(!text.isEmpty() && !text.startsWith(singleLine)) { - doSingleLineStyleUncomment = false; - break; - } - } - - const int singleLineLength = singleLine.length(); - for(QTextBlock block = startBlock; block != endBlock; block = block.next()) { - if(doSingleLineStyleUncomment) { - QString text = block.text(); - - int i = 0; - while(i <= text.size() - singleLineLength) { - if(text.indexOf(singleLine, i) == i) { - cursor.setPosition(block.position() + i); - cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, singleLineLength); - cursor.removeSelectedText(); - break; - } - if(!text.at(i).isSpace()) { - break; - } - ++i; - } - } else { - cursor.setPosition(block.position()); - cursor.insertText(singleLine); - } - } - } - - cursor.endEditBlock(); - - if(hasSelection && !doMultiLineStyleUncomment) { - cursor = textCursor(); - if(!doMultiLineStyleComment) - start = startBlock.position(); - int lastSelPos = anchorIsStart ? cursor.position() : cursor.anchor(); - if(anchorIsStart) { - cursor.setPosition(start); - cursor.setPosition(lastSelPos, QTextCursor::KeepAnchor); - } else { - cursor.setPosition(lastSelPos); - cursor.setPosition(start, QTextCursor::KeepAnchor); - } - setTextCursor(cursor); - } -} - -void CodeEdit::indentSelection() { - QTextCursor cur = textCursor(); - - cur.beginEditBlock(); - - int pos = cur.position(); - int col = m_blockSelection ? m_columnPosition : column(cur.block().text(), cur.positionInBlock()); - - int anchor = cur.anchor(); - int start = qMin(anchor, pos); - int end = qMax(anchor, pos); - - QTextBlock startBlock = document()->findBlock(start); - QTextBlock endBlock = document()->findBlock(qMax(end - 1, 0)).next(); - - const bool cursorAtBlockStart = (textCursor().position() == startBlock.position()); - const bool anchorAtBlockStart = (textCursor().anchor() == startBlock.position()); - const bool oneLinePartial = (startBlock.next() == endBlock) && - (start > startBlock.position() || end < endBlock.position() - 1); - - if(startBlock == endBlock) { - endBlock = endBlock.next(); - } - if(cur.hasSelection() && !m_blockSelection && !oneLinePartial) { - for(QTextBlock block = startBlock; block != endBlock; block = block.next()) { - const QString text = block.text(); - int indentPosition = lineIndentPosition(text); - - int targetColumn = indentedColumn(column(text, indentPosition), true); - cur.setPosition(block.position() + indentPosition); - cur.insertText(indentationString(0, targetColumn, 0, block)); - cur.setPosition(block.position()); - cur.setPosition(block.position() + indentPosition, QTextCursor::KeepAnchor); - cur.removeSelectedText(); - } - if (cursorAtBlockStart) { - cur = textCursor(); - cur.setPosition(startBlock.position(), QTextCursor::KeepAnchor); - } else if(anchorAtBlockStart) { - cur = textCursor(); - cur.setPosition(startBlock.position(), QTextCursor::MoveAnchor); - cur.setPosition(textCursor().position(), QTextCursor::KeepAnchor); - } - } else if(cur.hasSelection() && !m_blockSelection && oneLinePartial) { - cur.removeSelectedText(); - } else { - for(QTextBlock block = startBlock; block != endBlock; block = block.next()) { - QString text = block.text(); - - int blockColumn = column(text, text.size()); - if(blockColumn < col) { - cur.setPosition(block.position() + text.size()); - cur.insertText(indentationString(blockColumn, col, 0, block)); - text = block.text(); - } - - int indentPosition = columnPosition(text, col, 0); - int spaces = spacesLeftFromPosition(text, indentPosition); - int startColumn = column(text, indentPosition - spaces); - int targetColumn = indentedColumn(column(text, indentPosition), true); - cur.setPosition(block.position() + indentPosition); - cur.setPosition(block.position() + indentPosition - spaces, QTextCursor::KeepAnchor); - cur.removeSelectedText(); - cur.insertText(indentationString(startColumn, targetColumn, 0, block)); - } - - if(m_blockSelection) { - end = cur.position(); - int offset = column(cur.block().text(), cur.positionInBlock()) - col; - - m_columnAnchor += offset; - m_columnPosition += offset; - - cur.setPosition(start); - cur.setPosition(end, QTextCursor::KeepAnchor); - } - } - - cur.endEditBlock(); - - doSetTextCursor(cur, true); -/* - if(cur.hasSelection()) { // Insert indents for a selected text - for(QTextBlock block = startBlock; block != endBlock; block = block.next()) { - cur.setPosition(block.position()); - - QString text; - text.fill((m_spaceTabs) ? ' ' : '\t', (m_spaceTabs) ? m_spaceIndent : 1); - cur.insertText(text); - } - } else { // Indent at cursor position - if(m_spaceTabs) { - int32_t indentRemain = m_spaceIndent - (cur.positionInBlock() % m_spaceIndent); - - QString text; - text.fill(' ', indentRemain); - cur.insertText(text); - } - } -*/ -} - -void CodeEdit::setTheme(const KSyntaxHighlighting::Theme &theme) { - auto pal = qApp->palette(); - if(theme.isValid()) { - pal.setColor(QPalette::Base, theme.editorColor(KSyntaxHighlighting::Theme::BackgroundColor)); - pal.setColor(QPalette::Text, theme.textColor(KSyntaxHighlighting::Theme::Normal)); - pal.setColor(QPalette::Highlight, theme.editorColor(KSyntaxHighlighting::Theme::TextSelection)); - } - setPalette(pal); - - m_highlighter->setTheme(theme); - m_highlighter->rehighlight(); - highlightCurrentLine(); -} - -int CodeEdit::sidebarWidth() const { - int digits = 1; - auto count = blockCount(); - while(count >= 10) { - ++digits; - count /= 10; - } - - return 4 + fontMetrics().width(QLatin1Char('9')) * digits + 2 * fontMetrics().lineSpacing(); -} - -void CodeEdit::sidebarPaintEvent(QPaintEvent *event) { - QPainter painter(m_sideBar); - painter.fillRect(event->rect(), m_highlighter->theme().editorColor(KSyntaxHighlighting::Theme::IconBorder)); - - auto block = firstVisibleBlock(); - auto blockNumber = block.blockNumber(); - int top = blockBoundingGeometry(block).translated(contentOffset()).top(); - int bottom = top + blockBoundingRect(block).height(); - const int currentBlockNumber = textCursor().blockNumber(); - - const auto foldingMarkerSize = fontMetrics().lineSpacing(); - - QFont f = font(); - while(block.isValid() && top <= event->rect().bottom()) { - if(m_displayLineNumbers && block.isVisible() && bottom >= event->rect().top()) { - const auto number = QString::number(blockNumber + 1); - bool current = (blockNumber == currentBlockNumber); - painter.setPen(m_highlighter->theme().editorColor( - current ? KSyntaxHighlighting::Theme::CurrentLineNumber - : KSyntaxHighlighting::Theme::LineNumbers)); - - f.setBold(current); - painter.setFont(f); - painter.drawText(0, top, m_sideBar->width() - 2 - foldingMarkerSize, fontMetrics().height(), Qt::AlignRight, number); - } - - // folding marker - if(m_displayFoldingMarkers && block.isVisible() && isFoldable(block)) { - QPolygonF polygon; - if(isFolded(block)) { - polygon << QPointF(foldingMarkerSize * 0.4, foldingMarkerSize * 0.25); - polygon << QPointF(foldingMarkerSize * 0.4, foldingMarkerSize * 0.75); - polygon << QPointF(foldingMarkerSize * 0.8, foldingMarkerSize * 0.5); - } else { - polygon << QPointF(foldingMarkerSize * 0.25, foldingMarkerSize * 0.4); - polygon << QPointF(foldingMarkerSize * 0.75, foldingMarkerSize * 0.4); - polygon << QPointF(foldingMarkerSize * 0.5, foldingMarkerSize * 0.8); - } - painter.save(); - painter.setRenderHint(QPainter::Antialiasing); - painter.setPen(Qt::NoPen); - painter.setBrush(QColor(m_highlighter->theme().editorColor(KSyntaxHighlighting::Theme::CodeFolding))); - painter.translate(m_sideBar->width() - foldingMarkerSize, top); - painter.drawPolygon(polygon); - painter.restore(); - } - - block = block.next(); - top = bottom; - bottom = top + blockBoundingRect(block).height(); - ++blockNumber; - } -} - -void CodeEdit::updateSidebarGeometry() { - setViewportMargins(sidebarWidth(), 0, 0, 0); - const auto r = contentsRect(); - m_sideBar->setGeometry(QRect(r.left(), r.top(), sidebarWidth(), r.height())); - m_sideBar->repaint(); -} - -void CodeEdit::updateSidebarArea(const QRect& rect, int dy) { - if(dy) { - m_sideBar->scroll(0, dy); - } else { - m_sideBar->update(0, rect.y(), m_sideBar->width(), rect.height()); - } -} - -void CodeEdit::highlightCurrentLine() { - QTextEdit::ExtraSelection selection; - selection.format.setBackground(QColor(m_highlighter->theme().editorColor(KSyntaxHighlighting::Theme::CurrentLine))); - selection.format.setProperty(QTextFormat::FullWidthSelection, true); - selection.cursor = textCursor(); - selection.cursor.clearSelection(); - - QList extraSelections; - extraSelections.append(selection); - setExtraSelections(extraSelections); -} - -QTextBlock CodeEdit::blockAtPosition(int y) const { - auto block = firstVisibleBlock(); - if(!block.isValid()) { - return QTextBlock(); - } - - int top = blockBoundingGeometry(block).translated(contentOffset()).top(); - int bottom = top + blockBoundingRect(block).height(); - do { - if(top <= y && y <= bottom) { - return block; - } - block = block.next(); - top = bottom; - bottom = top + blockBoundingRect(block).height(); - } while(block.isValid()); - return QTextBlock(); -} - -bool CodeEdit::isFoldable(const QTextBlock &block) const { - return m_highlighter->startsFoldingRegion(block); -} - -bool CodeEdit::isFolded(const QTextBlock &block) const { - if(!block.isValid()) { - return false; - } - const auto nextBlock = block.next(); - if(!nextBlock.isValid()) { - return false; - } - return !nextBlock.isVisible(); -} - -void CodeEdit::toggleFold(const QTextBlock &startBlock) { - if(m_displayFoldingMarkers) { - auto endBlock = m_highlighter->findFoldingRegionEnd(startBlock).next(); - - endBlock = endBlock.previous(); - - if(isFolded(startBlock)) { // unfold - auto block = startBlock.next(); - while(block.isValid() && !block.isVisible()) { - block.setVisible(true); - block.setLineCount(block.layout()->lineCount()); - block = block.next(); - } - } else { // fold - auto block = startBlock.next(); - while(block.isValid() && block != endBlock) { - block.setVisible(false); - block.setLineCount(0); - block = block.next(); - } - } - document()->markContentsDirty(startBlock.position(), endBlock.position() - startBlock.position() + 1); - - emit document()->documentLayout()->documentSizeChanged(document()->documentLayout()->documentSize()); - } -} - -int32_t CodeEdit::column(const QString &text, int32_t pos) const { - int result = 0; - for(int i = 0; i < pos; i++) { - if(text.at(i) == QLatin1Char('\t')) { - result -= (result % m_spaceIndent) + m_spaceIndent; - } else { - result++; - } - } - return result; -} - -int32_t CodeEdit::columnPosition(const QString &text, int column, int *offset) const { - int32_t current = 0; - int32_t result = 0; - int32_t textSize = text.size(); - while((result < textSize) && current < column) { - if(result < textSize && text.at(result) == QLatin1Char('\t')) { - current -= (current % m_spaceIndent) + m_spaceIndent; - } else { - ++current; - } - ++result; - } - - if(offset) { - *offset = column - current; - } - return result; -} - -QString CodeEdit::indentationString(int startColumn, int targetColumn, int padding, const QTextBlock &block) const { - targetColumn = qMax(startColumn, targetColumn); - return QString(targetColumn - startColumn, QLatin1Char(' ')); -} - -int CodeEdit::lineIndentPosition(const QString &text) const { - int i = 0; - while(i < text.size()) { - if(!text.at(i).isSpace()) { - break; - } - ++i; - } - int col = column(text, i); - return i - (col % m_spaceIndent); -} - -int CodeEdit::spacesLeftFromPosition(const QString &text, int position) const { - if(position > text.size()) { - return 0; - } - int i = position; - while(i > 0) { - if(!text.at(i-1).isSpace()) { - break; - } - --i; - } - return position - i; -} - -int CodeEdit::indentedColumn(int column, bool doIndent) const { - int aligned = (column / m_spaceIndent) * m_spaceIndent; - if(doIndent) { - return aligned + m_spaceIndent; - } - if(aligned < column) { - return aligned; - } - return qMax(0, aligned - m_spaceIndent); -} - -QTextCursor CodeEdit::cursor() const { - int32_t selectionAnchorColumn; - int32_t selectionPositionColumn; - - if(m_blockAnchor == m_blockPosition) { - selectionAnchorColumn = m_columnAnchor; - selectionPositionColumn = m_columnPosition; - } - - QTextDocument *doc = document(); - QTextCursor cursor(doc); - - QTextBlock anchorTextBlock = doc->findBlockByNumber(m_blockAnchor); - int32_t anchorPosition = anchorTextBlock.position() + columnPosition(anchorTextBlock.text(), selectionAnchorColumn); - - QTextBlock positionTextBlock = doc->findBlockByNumber(m_blockPosition); - int32_t cursorPosition = positionTextBlock.position() + columnPosition(positionTextBlock.text(), selectionPositionColumn); - - cursor.setPosition(anchorPosition); - cursor.setPosition(cursorPosition, QTextCursor::KeepAnchor); - - return cursor; -} - -void CodeEdit::enableBlockSelection(int32_t positionBlock, int32_t positionColumn, int32_t anchorBlock, int32_t anchorColumn) { - m_blockPosition = positionBlock; - m_columnPosition = positionColumn; - - m_blockAnchor = anchorBlock; - m_columnAnchor = anchorColumn; - - m_blockSelection = true; - doSetTextCursor(cursor(), true); - viewport()->update(); -} - -void CodeEdit::disableBlockSelection() { - m_blockSelection = false; - - m_blockPosition = 0; - m_columnPosition = 0; - - m_blockAnchor = 0; - m_columnAnchor = 0; - - viewport()->update(); -} - -void CodeEdit::doSetTextCursor(const QTextCursor &cursor, bool keepBlockSelection) { - if(!keepBlockSelection && m_blockSelection) { - m_blockSelection = false; - } - QTextCursor c = cursor; - c.setVisualNavigation(true); - QPlainTextEdit::doSetTextCursor(c); -} - -void CodeEdit::doSetTextCursor(const QTextCursor &cursor) { - doSetTextCursor(cursor, false); -} - -void CodeEdit::setupSelections(const QTextBlock &block, int position, int length, QVector &selections) const { - auto context = getPaintContext(); - - int blockSelectionIndex = context.selections.size() - 1; - - for(int i = 0; i < context.selections.size(); ++i) { - const QAbstractTextDocumentLayout::Selection &range = context.selections.at(i); - const int selStart = range.cursor.selectionStart() - position; - const int selEnd = range.cursor.selectionEnd() - position; - if(selStart < length && selEnd > 0 && selEnd > selStart) { - QTextLayout::FormatRange o; - o.start = selStart; - o.length = selEnd - selStart; - o.format = range.format; - if(m_blockSelection && i == blockSelectionIndex) { - QString text = block.text(); - - o.start = columnPosition(text, qMin(m_columnPosition, m_columnAnchor)); - o.length = columnPosition(text, qMax(m_columnPosition, m_columnAnchor)) - o.start; - } - selections.append(o); - } else if(!range.cursor.hasSelection() && range.format.hasProperty(QTextFormat::FullWidthSelection) - && block.contains(range.cursor.position()) && !m_blockSelection) { - QTextLayout::FormatRange o; - QTextLine l = block.layout()->lineForTextPosition(range.cursor.position() - position); - o.start = l.textStart(); - o.length = l.textLength(); - if(o.start + o.length == length - 1) { - ++o.length; // include newline - } - o.format = range.format; - selections.append(o); - } - } -} - -void CodeEdit::paintBlockSelection(const QTextBlock &block, QPainter &painter, const QPointF &offset, QRectF &blockRect) const { - if (!m_blockSelection || - block.blockNumber() < qMin(m_blockPosition, m_blockAnchor) || - block.blockNumber() > qMax(m_blockPosition, m_blockAnchor)) { - return; - } - - QTextLayout *layout = block.layout(); - QRectF blockBounding = blockBoundingRect(block).translated(offset); - QString text = block.text(); - - const qreal spacew = QFontMetricsF(font()).width(QLatin1Char(' ')); - const int cursorw = overwriteMode() ? QFontMetrics(font()).width(QLatin1Char(' ')) : cursorWidth(); - - int startOffset = 0; - int relativePos = columnPosition(text, qMin(m_columnPosition, m_columnAnchor), &startOffset); - const QTextLine line = layout->lineForTextPosition(relativePos); - const qreal startX = line.cursorToX(relativePos) + startOffset * spacew; - - int endOffset = 0; - int endRelativePos = columnPosition(text, qMax(m_columnPosition, m_columnAnchor), &endOffset); - const QTextLine eline = layout->lineForTextPosition(endRelativePos); - const qreal endX = eline.cursorToX(endRelativePos) + endOffset * spacew; - - QRectF rect = line.naturalTextRect(); - rect.moveTop(rect.top() + blockBounding.top()); - rect.setLeft(blockBounding.left() + startX); - if(line.lineNumber() == eline.lineNumber()) { - rect.setRight(blockBounding.left() + endX); - } - painter.fillRect(rect, palette().highlight()); - - blockRect = rect; - - for(int i = line.lineNumber() + 1; i < eline.lineNumber(); ++i) { - rect = layout->lineAt(i).naturalTextRect(); - rect.moveTop(rect.top() + blockBounding.top()); - painter.fillRect(rect, palette().highlight()); - } - - rect = eline.naturalTextRect(); - rect.moveTop(rect.top() + blockBounding.top()); - rect.setRight(blockBounding.left() + endX); - if(line.lineNumber() != eline.lineNumber()) { - painter.fillRect(rect, palette().highlight()); - } - - if(m_columnAnchor < m_columnPosition) { - blockRect.setLeft(rect.right()); - } - blockRect.setWidth(cursorw); -} - -QString CodeEdit::copyBlockSelection() { - if(!m_blockSelection) { - return QString(); - } - QString selection; - QTextBlock block = document()->findBlockByNumber(qMin(m_blockPosition, m_blockAnchor)); - const QTextBlock &lastBlock = document()->findBlockByNumber(qMax(m_blockPosition, m_blockAnchor)); - bool textInserted = false; - while(true) { - if(textInserted) { - selection += QLatin1Char('\n'); - } - textInserted = true; - - QString text = block.text(); - int startOffset = 0; - int startPos = columnPosition(text, qMin(m_columnPosition, m_columnAnchor), &startOffset); - int endOffset = 0; - int endPos = columnPosition(text, qMax(m_columnPosition, m_columnAnchor), &endOffset); - - if(startPos == endPos) { - selection += QString(endOffset - startOffset, QLatin1Char(' ')); - } else { - if(startOffset < 0) { - selection += QString(-startOffset, QLatin1Char(' ')); - } - if(endOffset < 0) { - --endPos; - } - selection += text.midRef(startPos, endPos - startPos); - if(endOffset < 0) { - selection += QString((m_spaceTabs) ? m_spaceIndent : 1 + endOffset, QLatin1Char(' ')); - } else if (endOffset > 0) { - selection += QString(endOffset, QLatin1Char(' ')); - } - } - - if(block == lastBlock) { - break; - } - - block = block.next(); - } - return selection; -} - -void CodeEdit::removeBlockSelection() { - QTextCursor cur = textCursor(); - - const int firstColumn = qMin(m_columnPosition, m_columnAnchor); - const int lastColumn = qMax(m_columnPosition, m_columnAnchor); - if(firstColumn == lastColumn) { - return; - } - const int positionBlock = m_blockPosition; - const int anchorBlock = m_blockAnchor; - - int cursorPosition = cur.selectionStart(); - cur.clearSelection(); - cur.beginEditBlock(); - - QTextBlock block = document()->findBlockByNumber(qMin(m_blockPosition, m_blockAnchor)); - const QTextBlock &lastBlock = document()->findBlockByNumber(qMax(m_blockPosition, m_blockAnchor)); - while(true) { - int startOffset = 0; - const int startPos = columnPosition(block.text(), firstColumn, &startOffset); - // removing stuff doesn't make sense if the cursor is behind the code - if(startPos < block.length() - 1 || startOffset < 0) { - cur.setPosition(block.position()); - setCursorToColumn(cur, firstColumn); - setCursorToColumn(cur, lastColumn, QTextCursor::KeepAnchor); - cur.removeSelectedText(); - } - if(block == lastBlock) { - break; - } - block = block.next(); - } - - cur.setPosition(cursorPosition); - cur.endEditBlock(); - - m_blockPosition = positionBlock; - m_columnPosition = firstColumn; - - m_blockAnchor = anchorBlock; - m_columnAnchor = firstColumn; - - bool hasSelection = !(m_blockPosition == m_blockAnchor && - m_columnPosition == m_columnAnchor); - doSetTextCursor(cursor(), hasSelection); -} - -void CodeEdit::insertIntoBlockSelection(const QString &text) { - QTextCursor cur = textCursor(); - cur.beginEditBlock(); - - if(overwriteMode() && - qMax(m_columnPosition, m_columnAnchor) == m_columnPosition) { - ++m_columnPosition; - } - - if(m_columnPosition != m_columnAnchor) { - removeBlockSelection(); - if(!m_blockSelection) { - insertPlainText(text); - cur.endEditBlock(); - return; - } - } - - if(text.isEmpty()) { - cur.endEditBlock(); - return; - } - - int positionBlock = m_blockPosition; - int anchorBlock = m_blockAnchor; - int column = m_columnPosition; - - const QTextBlock &firstBlock = document()->findBlockByNumber(qMin(m_blockPosition, m_blockAnchor)); - QTextBlock block = document()->findBlockByNumber(qMax(m_blockPosition, m_blockAnchor)); - - const int selectionLineCount = qMax(m_blockPosition, m_blockAnchor) - qMin(m_blockPosition, m_blockAnchor); - const int textNewLineCount = text.count(QLatin1Char('\n')); - QStringList textLines = text.split(QLatin1Char('\n')); - - int textLength = 0; - const QStringList::const_iterator endLine = textLines.constEnd(); - for(QStringList::const_iterator textLine = textLines.constBegin(); textLine != endLine; ++textLine) { - textLength += qMax(0, columnPosition(*textLine, column) - textLength); - } - for(QStringList::iterator textLine = textLines.begin(); textLine != textLines.end(); ++textLine) { - textLine->append(QString(qMax(0, textLength - columnPosition(*textLine, column)), QLatin1Char(' '))); - } - - while(true) { - cur.setPosition(block.position()); - if(selectionLineCount == textNewLineCount) { - setCursorToColumn(cur, column); - cur.insertText(textLines.at(block.blockNumber() - qMin(m_blockPosition, m_blockAnchor))); - } else { - QStringList::const_iterator textLine = textLines.constBegin(); - while(true) { - setCursorToColumn(cur, column); - cur.insertText(*textLine); - ++textLine; - if(textLine == endLine) { - break; - } - cur.movePosition(QTextCursor::EndOfBlock); - cur.insertText(QLatin1String("\n")); - if(qMax(anchorBlock, positionBlock) == anchorBlock) { - ++anchorBlock; - } else { - ++positionBlock; - } - } - } - if(block == firstBlock) { - break; - } - block = block.previous(); - } - cur.endEditBlock(); - - column += textLength; - - m_blockPosition = positionBlock; - m_columnPosition = column; - - m_blockAnchor = anchorBlock; - m_columnAnchor = column; - - doSetTextCursor(cursor(), true); -} - -int32_t CodeEdit::firstNonIndent(const QString &text) const { - int32_t i = 0; - while(i < text.size()) { - if(text.at(i) != ' ' && text.at(i) != '\t') { - return i; - } - ++i; - } - return i; -} - -void CodeEdit::setCursorToColumn(QTextCursor &cursor, int column, QTextCursor::MoveMode moveMode) { - int offset = 0; - const int cursorPosition = cursor.position(); - const int pos = columnPosition(cursor.block().text(), column, &offset); - cursor.setPosition(cursor.block().position() + pos, offset == 0 ? moveMode : QTextCursor::MoveAnchor); - if(offset == 0) { - return; - } - if(offset < 0) { - cursor.setPosition(cursor.block().position() + pos - 1, QTextCursor::KeepAnchor); - cursor.insertText(indentationString( - CodeEdit::column(cursor.block().text(), pos - 1), - CodeEdit::column(cursor.block().text(), pos), 0, cursor.block())); - } else { - cursor.insertText(indentationString(CodeEdit::column(cursor.block().text(), pos), column, 0, cursor.block())); - } - if(moveMode == QTextCursor::KeepAnchor) { - cursor.setPosition(cursorPosition); - } - cursor.setPosition(cursor.block().position() + columnPosition(cursor.block().text(), column), moveMode); -} - -void CodeEdit::insertFromMimeData(const QMimeData *source) { - if(!isReadOnly() && m_blockSelection) { - insertIntoBlockSelection(source->text()); - return; - } - QPlainTextEdit::insertFromMimeData(source); -} - -void CodeEdit::onApplySettings() { - SettingsManager *s = SettingsManager::instance(); - QString name = s->property(qPrintable(gFont)).toString(); - if(name.isEmpty()) { - name = "Source Code Pro"; - } - QFont font(name, 10); - font.setFixedPitch(true); - setFont(font); - - int32_t range = 0.01f * font.pointSize() * s->property(qPrintable(gZoom)).toFloat() - font.pointSize(); - zoomIn(range); - - displayLineNumbers(s->property(qPrintable(gLineNumbers)).toBool()); - displayFoldingMarkers(s->property(qPrintable(gFoldingMarkers)).toBool()); - - decorateWhitespaces(s->property(qPrintable(gWhitespaces)).toBool()); - - setSpaceTabs(s->property(qPrintable(gSpaces)).toBool(), s->property(qPrintable(gTabSize)).toInt()); -} - -void CodeEdit::onClassModelChanged() { - if(m_classModel) { - QStringList classes; - QStringList enums; - for(int row = 0; row < m_classModel->rowCount(); row++) { - auto index = m_classModel->index(row, 0); - switch(m_classModel->data(index, Qt::UserRole).toInt()) { - case 4: enums << m_classModel->data(index).toString(); break; - default: classes << m_classModel->data(index).toString(); break; - } - } - m_definition.setKeywordList("classes", classes); - m_definition.setKeywordList("enums", enums); - m_highlighter->rehighlight(); - } -} diff --git a/modules/editor/codeeditor/editor/codeedit.h b/modules/editor/codeeditor/editor/codeedit.h deleted file mode 100644 index 099c04a0a..000000000 --- a/modules/editor/codeeditor/editor/codeedit.h +++ /dev/null @@ -1,157 +0,0 @@ -#ifndef CODEEDIT_H -#define CODEEDIT_H - -#include -#include - -#include -#include - -namespace KSyntaxHighlighting { - class SyntaxHighlighter; - class Theme; -} - -class CodeEditSidebar; -class QAbstractItemModel; - -class CodeEdit : public QPlainTextEdit { - Q_OBJECT -public: - explicit CodeEdit(QWidget *parent = nullptr); - ~CodeEdit() override; - - void openFile(const QString &fileName); - void saveFile(const QString &path = QString()); - - void loadDefinition(const QString &name); - - void setSpaceTabs(bool enable, uint32_t indent); - void displayLineNumbers(bool visible); - void displayFoldingMarkers(bool visible); - - void decorateWhitespaces(bool value); - - void highlightBlock(const QString &text); - bool findString(const QString &string, bool reverse, bool casesens = true, bool words = false); - void replaceSelected(const QString &string); - - void reportIssue(int level, int line, int col, const QString &text); - -protected: - void contextMenuEvent(QContextMenuEvent *event) Q_DECL_OVERRIDE; - void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE; - void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; - void timerEvent(QTimerEvent *event) Q_DECL_OVERRIDE; - -private slots: - void onApplySettings(); - void onClassModelChanged(); - -private: - friend class CodeEditSidebar; - - void checkClassMap(); - - void setTheme(const KSyntaxHighlighting::Theme &theme); - int sidebarWidth() const; - void sidebarPaintEvent(QPaintEvent *event); - void updateSidebarGeometry(); - void updateSidebarArea(const QRect &rect, int dy); - void highlightCurrentLine(); - - QTextBlock blockAtPosition(int y) const; - bool isFoldable(const QTextBlock &block) const; - bool isFolded(const QTextBlock &block) const; - void toggleFold(const QTextBlock &block); - - int32_t column(const QString &text, int32_t pos) const; - int32_t columnPosition(const QString &text, int column, int *offset = nullptr) const; - QString indentationString(int startColumn, int targetColumn, int padding, const QTextBlock &block) const; - int lineIndentPosition(const QString &text) const; - int spacesLeftFromPosition(const QString &text, int position) const; - int indentedColumn(int column, bool doIndent) const; - - QTextCursor cursor() const; - void enableBlockSelection(int32_t positionBlock, int32_t positionColumn, int32_t anchorBlock, int32_t anchorColumn); - void disableBlockSelection(); - - void setupSelections(const QTextBlock &block, int position, int length, QVector &selections) const; - void paintBlockSelection(const QTextBlock &block, QPainter &painter, const QPointF &offset, QRectF &blockRect) const; - - void commentSelection(); - void indentSelection(); - - QString copyBlockSelection(); - void removeBlockSelection(); - void insertIntoBlockSelection(const QString &text); - - void doSetTextCursor(const QTextCursor &cursor, bool keepBlockSelection); - void doSetTextCursor(const QTextCursor &cursor) Q_DECL_OVERRIDE; - int32_t firstNonIndent(const QString &text) const; - - void setCursorToColumn(QTextCursor &cursor, int column, QTextCursor::MoveMode moveMode = QTextCursor::MoveAnchor); - - void insertFromMimeData(const QMimeData *source) Q_DECL_OVERRIDE; - - QString m_fileName; - - KSyntaxHighlighting::Definition m_definition; - KSyntaxHighlighting::Repository m_repository; - KSyntaxHighlighting::SyntaxHighlighter *m_highlighter; - - QAbstractItemModel *m_classModel; - - CodeEditSidebar *m_sideBar; - - bool m_spaceTabs; - int32_t m_spaceIndent; - - bool m_blockSelection; - int32_t m_blockPosition; - int32_t m_columnPosition; - - int32_t m_blockAnchor; - int32_t m_columnAnchor; - - bool m_displayLineNumbers; - bool m_displayFoldingMarkers; - - bool m_cursorVisible; -}; - -class CodeEditSidebar : public QWidget { - Q_OBJECT -public: - explicit CodeEditSidebar(CodeEdit *editor) : - QWidget(editor), - m_codeEdit(editor) { - } - QSize sizeHint() const Q_DECL_OVERRIDE { - return QSize(m_codeEdit->sidebarWidth(), 0); - } - -protected: - void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE { - m_codeEdit->sidebarPaintEvent(event); - } - void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE { - if(event->x() >= width() - m_codeEdit->fontMetrics().lineSpacing()) { - auto block = m_codeEdit->blockAtPosition(event->y()); - if(!block.isValid() || !m_codeEdit->isFoldable(block)) { - return; - } - m_codeEdit->toggleFold(block); - } - QWidget::mouseReleaseEvent(event); - } - -private: - CodeEdit *m_codeEdit; -}; - -#endif // CODEEDIT_H diff --git a/modules/editor/codeeditor/editor/textedit.cpp b/modules/editor/codeeditor/editor/textedit.cpp deleted file mode 100644 index fd45d56d2..000000000 --- a/modules/editor/codeeditor/editor/textedit.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include "textedit.h" -#include "ui_textedit.h" - -#include -#include -#include -#include -#include - -#include - -#include "codeedit.h" - -TextEdit::TextEdit() : - ui(new Ui::TextEdit) { - - ui->setupUi(this); - - ui->findWidget->setProperty("pannel", true); - - connect(ui->editor, &CodeEdit::cursorPositionChanged, this, &TextEdit::onCursorPositionChanged); - connect(ui->editor, &CodeEdit::textChanged, this, &TextEdit::onTextChanged); - - ui->editor->addAction(ui->actionFind); - - on_pushClose_clicked(); -} - -TextEdit::~TextEdit() { - disconnect(ui->editor, &CodeEdit::textChanged, this, &TextEdit::onTextChanged); - disconnect(ui->editor, &CodeEdit::cursorPositionChanged, this, &TextEdit::onCursorPositionChanged); - delete ui; -} - -bool TextEdit::isModified() const { - return ui->editor->document()->isModified(); -} - -void TextEdit::setModified(bool flag) { - ui->editor->document()->setModified(flag); -} - -void TextEdit::loadAsset(AssetConverterSettings *settings) { - AssetEditor::loadAsset(settings); - - ui->editor->openFile(settings->source()); - setWindowTitle(QFileInfo(settings->source()).fileName()); -} - -void TextEdit::saveAsset(const QString &path) { - ui->editor->saveFile(path); - onTextChanged(); -} - -void TextEdit::loadData(const Variant &data, const QString &suffix) { - ui->editor->loadDefinition(QString("data.%1").arg(suffix)); - ui->editor->setPlainText(data.toString().c_str()); - ui->editor->setReadOnly(true); -} - -void TextEdit::onCursorPositionChanged() { - QTextCursor cursor = ui->editor->textCursor(); - ui->lineLabel->setText(QString("Line: %1, Col: %2").arg(cursor.blockNumber() + 1).arg(cursor.positionInBlock() + 1)); -} - -void TextEdit::onTextChanged() { - QString title; - if(!m_settings.empty()) { - title = QFileInfo(m_settings.first()->source()).fileName(); - } - if(ui->editor->document() && ui->editor->document()->isModified()) { - title.append('*'); - } - setWindowTitle(title); -} - -QStringList TextEdit::suffixes() const { - return {"cpp", "h", "as", "txt", "json", "html", "htm", "xml"}; -} - -void TextEdit::on_actionFind_triggered() { - ui->findWidget->show(); - ui->lineFind->setFocus(); - ui->lineFind->selectAll(); -} - -void TextEdit::on_pushClose_clicked() { - ui->findWidget->hide(); -} - -void TextEdit::on_lineFind_textChanged(const QString &arg1) { - ui->editor->highlightBlock(arg1); -} - -void TextEdit::on_pushPrevious_clicked() { - ui->editor->findString(ui->lineFind->text(), true); -} - -void TextEdit::on_pushNext_clicked() { - ui->editor->findString(ui->lineFind->text(), false); -} - -void TextEdit::on_pushReplace_clicked() { - ui->editor->replaceSelected(ui->lineReplace->text()); -} - -void TextEdit::on_pushReplaceFind_clicked() { - on_pushReplace_clicked(); - on_pushNext_clicked(); -} - -void TextEdit::changeEvent(QEvent *event) { - if(event->type() == QEvent::LanguageChange) { - ui->retranslateUi(this); - } -} diff --git a/modules/editor/codeeditor/editor/textedit.h b/modules/editor/codeeditor/editor/textedit.h deleted file mode 100644 index 9a7972eeb..000000000 --- a/modules/editor/codeeditor/editor/textedit.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef TEXTEDIT_H -#define TEXTEDIT_H - -#include - -#include - -namespace Ui { - class TextEdit; -} - -class TextEdit : public AssetEditor { - Q_OBJECT - -public: - TextEdit(); - ~TextEdit(); - -private slots: - void onCursorPositionChanged(); - void onTextChanged(); - - void on_actionFind_triggered(); - - void on_pushClose_clicked(); - - void on_lineFind_textChanged(const QString &arg1); - - void on_pushPrevious_clicked(); - - void on_pushNext_clicked(); - - void on_pushReplace_clicked(); - - void on_pushReplaceFind_clicked(); - -private: - void loadAsset(AssetConverterSettings *settings) override; - void saveAsset(const QString &path = QString()) override; - - void loadData(const Variant &data, const QString &suffix) override; - - bool isSingleInstance() const override { return false; } - - AssetEditor *createInstance() override { return new TextEdit; } - - void changeEvent(QEvent *event) override; - - bool isModified() const override; - void setModified(bool flag) override; - - QStringList suffixes() const override; - - Ui::TextEdit *ui; -}; - -#endif // TEXTEDIT_H diff --git a/modules/editor/editor.qbs b/modules/editor/editor.qbs index 01aa2892d..c526690d1 100644 --- a/modules/editor/editor.qbs +++ b/modules/editor/editor.qbs @@ -2,14 +2,15 @@ Project { id: editor references: [ + "grapheditor", "iostools", + "motiontools", "particletools", "pipelinetools", "qbstools", "shadertools", "texturetools", "texteditor", - "grapheditor", "tiledimporter", "timeline" ] diff --git a/modules/editor/motiontools/converter/animationbuilder.cpp b/modules/editor/motiontools/converter/animationbuilder.cpp new file mode 100644 index 000000000..7703a9143 --- /dev/null +++ b/modules/editor/motiontools/converter/animationbuilder.cpp @@ -0,0 +1,34 @@ +#include "animationbuilder.h" + +#include + +#include + +#include + +#define FORMAT_VERSION 1 + +AnimationBuilderSettings::AnimationBuilderSettings() { + setType(MetaType::type()); + setVersion(FORMAT_VERSION); +} + +QString AnimationBuilderSettings::defaultIcon(QString) const { + return ":/Style/styles/dark/images/machine.svg"; +} + +AssetConverter::ReturnCode AnimationControllerBuilder::convertFile(AssetConverterSettings *settings) { + m_model.load(settings->source()); + QFile file(settings->absoluteDestination()); + if(file.open(QIODevice::WriteOnly)) { + ByteArray data = Bson::save( m_model.object() ); + file.write(reinterpret_cast(&data[0]), data.size()); + file.close(); + return Success; + } + return InternalError; +} + +AssetConverterSettings *AnimationControllerBuilder::createSettings() const { + return new AnimationBuilderSettings(); +} diff --git a/modules/editor/motiontools/converter/animationbuilder.h b/modules/editor/motiontools/converter/animationbuilder.h new file mode 100644 index 000000000..aa4692c49 --- /dev/null +++ b/modules/editor/motiontools/converter/animationbuilder.h @@ -0,0 +1,29 @@ +#ifndef ANIMATIONCONTROLLERBUILDER_H +#define ANIMATIONCONTROLLERBUILDER_H + +#include + +#include "animationcontrollergraph.h" + +class AnimationBuilderSettings : public AssetConverterSettings { +public: + AnimationBuilderSettings(); +private: + QString defaultIcon(QString) const Q_DECL_OVERRIDE; + +}; + +class AnimationControllerBuilder : public AssetConverter { +private: + QStringList suffixes() const Q_DECL_OVERRIDE { return {"actl"}; } + + ReturnCode convertFile(AssetConverterSettings *s) Q_DECL_OVERRIDE; + AssetConverterSettings *createSettings() const Q_DECL_OVERRIDE; + + QString templatePath() const Q_DECL_OVERRIDE { return ":/Templates/Animation_Controller.actl"; } + +private: + AnimationControllerGraph m_model; +}; + +#endif // ANIMATIONCONTROLLERBUILDER_H diff --git a/develop/managers/assetmanager/animationbuilder.cpp b/modules/editor/motiontools/converter/animationcontrollergraph.cpp similarity index 62% rename from develop/managers/assetmanager/animationbuilder.cpp rename to modules/editor/motiontools/converter/animationcontrollergraph.cpp index 340c50cdf..ed85d9b77 100644 --- a/develop/managers/assetmanager/animationbuilder.cpp +++ b/modules/editor/motiontools/converter/animationcontrollergraph.cpp @@ -1,14 +1,9 @@ -#include "animationbuilder.h" +#include "animationcontrollergraph.h" -#include #include -#include - -#include - +#include "basestate.h" #include -#include #define ENTRY "Entry" #define NAME "Name" @@ -17,46 +12,7 @@ #define MACHINE "Machine" -#define FORMAT_VERSION 1 - -Vector2 EntryState::defaultSize() const { - return Vector2(170.0f, 40.0f); -} - -Vector4 EntryState::color() const { - return Vector4(0.1f, 0.1f, 0.1f, 1.0f); -} - -bool EntryState::isState() const { - return true; -} - - -BaseState::BaseState() { - m_path = Template("", MetaType::type()); - m_loop = false; -} - -Template BaseState::clip() const { - return m_path; -} - -void BaseState::setClip(const Template &path) { - m_path.path = path.path; - emit updated(); -} - -bool BaseState::loop() const { - return m_loop; -} - -void BaseState::setLoop(bool loop) { - m_loop = loop; - emit updated(); -} - - -AnimationNodeGraph::AnimationNodeGraph() { +AnimationControllerGraph::AnimationControllerGraph() { m_entry = nullptr; qRegisterMetaType("BaseState"); @@ -64,7 +20,7 @@ AnimationNodeGraph::AnimationNodeGraph() { m_functions << "BaseState"; } -void AnimationNodeGraph::load(const QString &path) { +void AnimationControllerGraph::load(const QString &path) { AbstractNodeGraph::load(path); if(m_entry) { @@ -72,7 +28,7 @@ void AnimationNodeGraph::load(const QString &path) { } } -void AnimationNodeGraph::loadGraph(const QVariantMap &data) { +void AnimationControllerGraph::loadGraph(const QVariantMap &data) { AbstractNodeGraph::loadGraph(data); int32_t entry = m_data[ENTRY].toInt(); @@ -81,23 +37,24 @@ void AnimationNodeGraph::loadGraph(const QVariantMap &data) { } } -void AnimationNodeGraph::save(const QString &path) { +void AnimationControllerGraph::save(const QString &path) { m_data[ENTRY] = m_nodes.indexOf(m_entry); AbstractNodeGraph::save(path); } -GraphNode *AnimationNodeGraph::createRoot() { +GraphNode *AnimationControllerGraph::createRoot() { EntryState *result = new EntryState; result->setObjectName(ENTRY); + result->setGraph(this); return result; } -GraphNode *AnimationNodeGraph::nodeCreate(const QString &path, int &index) { +GraphNode *AnimationControllerGraph::nodeCreate(const QString &path, int &index) { BaseState *node = new BaseState(); - connect(node, &BaseState::updated, this, &AnimationNodeGraph::graphUpdated); + connect(node, &BaseState::updated, this, &AnimationControllerGraph::graphUpdated); node->setObjectName(path); node->setGraph(this); node->setType(qPrintable(path)); @@ -111,7 +68,7 @@ GraphNode *AnimationNodeGraph::nodeCreate(const QString &path, int &index) { return node; } -AnimationNodeGraph::Link *AnimationNodeGraph::linkCreate(GraphNode *sender, NodePort *oport, GraphNode *receiver, NodePort *iport) { +AnimationControllerGraph::Link *AnimationControllerGraph::linkCreate(GraphNode *sender, NodePort *oport, GraphNode *receiver, NodePort *iport) { if(receiver == m_rootNode) { return nullptr; } @@ -130,7 +87,7 @@ AnimationNodeGraph::Link *AnimationNodeGraph::linkCreate(GraphNode *sender, Node return AbstractNodeGraph::linkCreate(sender, oport, receiver, iport); } -void AnimationNodeGraph::loadUserValues(GraphNode *node, const QVariantMap &values) { +void AnimationControllerGraph::loadUserValues(GraphNode *node, const QVariantMap &values) { BaseState *ptr = reinterpret_cast(node); node->setObjectName(values[NAME].toString()); @@ -141,14 +98,14 @@ void AnimationNodeGraph::loadUserValues(GraphNode *node, const QVariantMap &valu ptr->setLoop(values[LOOP].toBool()); } -void AnimationNodeGraph::saveUserValues(GraphNode *node, QVariantMap &values) { +void AnimationControllerGraph::saveUserValues(GraphNode *node, QVariantMap &values) { BaseState *ptr = reinterpret_cast(node); values[NAME] = node->objectName(); values[CLIP] = ptr->clip().path; values[LOOP] = ptr->loop(); } -Variant AnimationNodeGraph::object() const { +Variant AnimationControllerGraph::object() const { VariantList result; VariantList object; @@ -168,7 +125,7 @@ Variant AnimationNodeGraph::object() const { return result; } -QStringList AnimationNodeGraph::nodeList() const { +QStringList AnimationControllerGraph::nodeList() const { QStringList result; for(auto &it : m_functions) { const int type = QMetaType::type( qPrintable(it) ); @@ -184,7 +141,7 @@ QStringList AnimationNodeGraph::nodeList() const { return result; } -Variant AnimationNodeGraph::data() const { +Variant AnimationControllerGraph::data() const { VariantMap result; VariantList machine; @@ -231,28 +188,3 @@ Variant AnimationNodeGraph::data() const { result[MACHINE] = machine; return result; } - -AnimationBuilderSettings::AnimationBuilderSettings() { - setType(MetaType::type()); - setVersion(FORMAT_VERSION); -} - -QString AnimationBuilderSettings::defaultIcon(QString) const { - return ":/Style/styles/dark/images/machine.svg"; -} - -AssetConverter::ReturnCode AnimationBuilder::convertFile(AssetConverterSettings *settings) { - m_model.load(settings->source()); - QFile file(settings->absoluteDestination()); - if(file.open(QIODevice::WriteOnly)) { - ByteArray data = Bson::save( m_model.object() ); - file.write((const char *)&data[0], data.size()); - file.close(); - return Success; - } - return InternalError; -} - -AssetConverterSettings *AnimationBuilder::createSettings() const { - return new AnimationBuilderSettings(); -} diff --git a/modules/editor/motiontools/converter/animationcontrollergraph.h b/modules/editor/motiontools/converter/animationcontrollergraph.h new file mode 100644 index 000000000..5eaacf1d9 --- /dev/null +++ b/modules/editor/motiontools/converter/animationcontrollergraph.h @@ -0,0 +1,39 @@ +#ifndef ANIMATIONCONTROLLERGRAPH_H +#define ANIMATIONCONTROLLERGRAPH_H + +#include + +class AnimationControllerGraph : public AbstractNodeGraph { + Q_OBJECT + +public: + AnimationControllerGraph(); + + void load(const QString &path) Q_DECL_OVERRIDE; + void save(const QString &path) Q_DECL_OVERRIDE; + + void loadGraph(const QVariantMap &data) Q_DECL_OVERRIDE; + + Variant object() const; + + QStringList nodeList() const Q_DECL_OVERRIDE; + +private: + GraphNode *createRoot() Q_DECL_OVERRIDE; + GraphNode *nodeCreate(const QString &path, int &index) Q_DECL_OVERRIDE; + Link *linkCreate(GraphNode *sender, NodePort *oport, GraphNode *receiver, NodePort *iport) Q_DECL_OVERRIDE; + + void loadUserValues(GraphNode *node, const QVariantMap &values) Q_DECL_OVERRIDE; + void saveUserValues(GraphNode *node, QVariantMap &values) Q_DECL_OVERRIDE; + +protected: + Variant data() const; + + GraphNode *m_entry; + QString m_path; + + QStringList m_functions; + +}; + +#endif // ANIMATIONCONTROLLERGRAPH_H diff --git a/modules/editor/motiontools/converter/basestate.cpp b/modules/editor/motiontools/converter/basestate.cpp new file mode 100644 index 000000000..78047370f --- /dev/null +++ b/modules/editor/motiontools/converter/basestate.cpp @@ -0,0 +1,26 @@ +#include "basestate.h" + +#include + +BaseState::BaseState() { + m_path = Template("", MetaType::type()); + m_loop = false; +} + +Template BaseState::clip() const { + return m_path; +} + +void BaseState::setClip(const Template &path) { + m_path.path = path.path; + emit updated(); +} + +bool BaseState::loop() const { + return m_loop; +} + +void BaseState::setLoop(bool loop) { + m_loop = loop; + emit updated(); +} diff --git a/modules/editor/motiontools/converter/basestate.h b/modules/editor/motiontools/converter/basestate.h new file mode 100644 index 000000000..0a78ca060 --- /dev/null +++ b/modules/editor/motiontools/converter/basestate.h @@ -0,0 +1,35 @@ +#ifndef BASESTATE_H +#define BASESTATE_H + +#include "entrystate.h" + +#include + +class BaseState : public EntryState { + Q_OBJECT + Q_CLASSINFO("Group", "States") + + Q_PROPERTY(QString Name READ objectName WRITE setObjectName NOTIFY updated DESIGNABLE true USER true) + Q_PROPERTY(Template Clip READ clip WRITE setClip NOTIFY updated DESIGNABLE true USER true) + Q_PROPERTY(bool Loop READ loop WRITE setLoop NOTIFY updated DESIGNABLE true USER true) + +public: + Q_INVOKABLE BaseState(); + + Template clip() const; + void setClip(const Template &path); + + bool loop() const; + void setLoop(bool loop); + +signals: + void updated(); + +public: + Template m_path; + + bool m_loop; + +}; + +#endif // BASESTATE_H diff --git a/modules/editor/motiontools/converter/entrystate.cpp b/modules/editor/motiontools/converter/entrystate.cpp new file mode 100644 index 000000000..9cbc3de44 --- /dev/null +++ b/modules/editor/motiontools/converter/entrystate.cpp @@ -0,0 +1,13 @@ +#include "entrystate.h" + +Vector2 EntryState::defaultSize() const { + return Vector2(170.0f, 40.0f); +} + +Vector4 EntryState::color() const { + return Vector4(0.1f, 0.1f, 0.1f, 1.0f); +} + +bool EntryState::isState() const { + return true; +} diff --git a/modules/editor/motiontools/converter/entrystate.h b/modules/editor/motiontools/converter/entrystate.h new file mode 100644 index 000000000..5edfdda54 --- /dev/null +++ b/modules/editor/motiontools/converter/entrystate.h @@ -0,0 +1,17 @@ +#ifndef ENTRYSTATE_H +#define ENTRYSTATE_H + +#include + +class EntryState : public GraphNode { + Q_OBJECT + +public: + Vector2 defaultSize() const override; + Vector4 color() const override; + + bool isState() const override; + +}; + +#endif // ENTRYSTATE_H diff --git a/worldeditor/src/editors/animationedit/animationedit.cpp b/modules/editor/motiontools/editor/animationedit.cpp similarity index 92% rename from worldeditor/src/editors/animationedit/animationedit.cpp rename to modules/editor/motiontools/editor/animationedit.cpp index 9289a48c6..a7a1639f7 100644 --- a/worldeditor/src/editors/animationedit/animationedit.cpp +++ b/modules/editor/motiontools/editor/animationedit.cpp @@ -4,16 +4,16 @@ #include #include -#include "animationbuilder.h" - #include #include #include +#include "../converter/animationbuilder.h" + AnimationEdit::AnimationEdit() : ui(new Ui::AnimationEdit), - m_graph(new AnimationNodeGraph), - m_assetConverter(new AnimationBuilder), + m_graph(new AnimationControllerGraph), + m_assetConverter(new AnimationControllerBuilder), m_stateMachine(nullptr), m_lastCommand(nullptr) { diff --git a/worldeditor/src/editors/animationedit/animationedit.h b/modules/editor/motiontools/editor/animationedit.h similarity index 100% rename from worldeditor/src/editors/animationedit/animationedit.h rename to modules/editor/motiontools/editor/animationedit.h diff --git a/worldeditor/src/editors/animationedit/animationedit.ui b/modules/editor/motiontools/editor/animationedit.ui similarity index 100% rename from worldeditor/src/editors/animationedit/animationedit.ui rename to modules/editor/motiontools/editor/animationedit.ui diff --git a/modules/editor/motiontools/motiontools.cpp b/modules/editor/motiontools/motiontools.cpp new file mode 100644 index 000000000..3c23c4ff6 --- /dev/null +++ b/modules/editor/motiontools/motiontools.cpp @@ -0,0 +1,41 @@ +#include "motiontools.h" + +#include + +#include + +#include "converter/animationbuilder.h" +#include "editor/animationedit.h" + +static const char *meta = \ +"{" +" \"module\": \"MotionTools\"," +" \"version\": \"1.0\"," +" \"description\": \"Tiled Importer plugin\"," +" \"author\": \"Evgeniy Prikazchikov\"," +" \"objects\": {" +" \"AnimationBuilderSettings\": \"converter\"," +" \"AnimationEdit\": \"editor\"" +" }" +"}"; + +Module *moduleCreate(Engine *engine) { + return new MotionTools(engine); +} + +MotionTools::MotionTools(Engine *engine) : + Module(engine) { +} + +const char *MotionTools::metaInfo() const { + return meta; +} + +void *MotionTools::getObject(const char *name) { + if(strcmp(name, "AnimationBuilderSettings") == 0) { + return new AnimationControllerBuilder; + } else if(strcmp(name, "AnimationEdit") == 0) { + return new AnimationEdit; + } + return nullptr; +} diff --git a/modules/editor/motiontools/motiontools.h b/modules/editor/motiontools/motiontools.h new file mode 100644 index 000000000..2bb870f6a --- /dev/null +++ b/modules/editor/motiontools/motiontools.h @@ -0,0 +1,20 @@ +#ifndef MOTIONTOOLS_H +#define MOTIONTOOLS_H + +#include + +class MotionTools : public Module { +public: + MotionTools(Engine *engine); + + const char *metaInfo() const override; + + void *getObject(const char *name) override; + +}; + +extern "C" { + MODULE_EXPORT Module *moduleCreate(Engine *engine); +} + +#endif // MOTIONTOOLS_H diff --git a/modules/editor/motiontools/motiontools.qbs b/modules/editor/motiontools/motiontools.qbs new file mode 100644 index 000000000..08e1898f4 --- /dev/null +++ b/modules/editor/motiontools/motiontools.qbs @@ -0,0 +1,64 @@ +import qbs + +Project { + id: motiontools + property stringList srcFiles: [ + "*.cpp", + "converter/*.cpp", + "editor/*.cpp", + "editor/*.ui", + "*.qrc", + "*.h", + "converter/**/*.h", + "editor/**/*.h" + ] + + property stringList incPaths: [ + "editor", + "../../../engine/includes", + "../../../engine/includes/resources", + "../../../engine/includes/editor", + "../../../thirdparty/next/inc", + "../../../thirdparty/next/inc/math", + "../../../thirdparty/next/inc/core", + "../../../thirdparty/next/inc/anim", + "../../../modules/editor/grapheditor" + ] + + DynamicLibrary { + name: "motiontools" + condition: motiontools.desktop + files: motiontools.srcFiles + Depends { name: "cpp" } + Depends { name: "bundle" } + Depends { name: "next-editor" } + Depends { name: "engine-editor" } + Depends { name: "graph-editor" } + Depends { name: "Qt"; submodules: ["core", "gui","widgets", "xml"]; } + bundle.isBundle: false + + cpp.defines: ["SHARED_DEFINE"] + cpp.includePaths: motiontools.incPaths + cpp.cxxLanguageVersion: motiontools.languageVersion + cpp.cxxStandardLibrary: motiontools.standardLibrary + cpp.minimumMacosVersion: motiontools.osxVersion + + Properties { + condition: qbs.targetOS.contains("linux") + cpp.rpaths: "$ORIGIN/../../lib" + } + + Properties { + condition: qbs.targetOS.contains("darwin") + cpp.sonamePrefix: "@executable_path" + } + + Group { + name: "Install Plugin" + fileTagsFilter: ["dynamiclibrary", "dynamiclibrary_import"] + qbs.install: true + qbs.installDir: motiontools.PLUGINS_PATH + qbs.installPrefix: motiontools.PREFIX + } + } +} diff --git a/worldeditor/src/main.cpp b/worldeditor/src/main.cpp index 1d9bb5c03..0b4a870e5 100644 --- a/worldeditor/src/main.cpp +++ b/worldeditor/src/main.cpp @@ -20,7 +20,6 @@ #include "config.h" #include "editors/componentbrowser/componentmodel.h" -#include "develop/managers/assetmanager/animationbuilder.h" int main(int argc, char *argv[]) { QSurfaceFormat format; @@ -58,7 +57,6 @@ int main(int argc, char *argv[]) { PluginManager::instance()->init(&engine); AssetManager::instance()->init(); - AssetManager::instance()->registerConverter(new AnimationBuilder); SettingsManager::instance()->loadSettings(); diff --git a/worldeditor/src/main/documentmodel.cpp b/worldeditor/src/main/documentmodel.cpp index 27f81d040..314b19a33 100644 --- a/worldeditor/src/main/documentmodel.cpp +++ b/worldeditor/src/main/documentmodel.cpp @@ -5,14 +5,11 @@ #include #include +#include #include #include -#include "editors/animationedit/animationedit.h" - DocumentModel::DocumentModel() { - addEditor(new AnimationEdit); - for(auto &it : PluginManager::instance()->extensions("editor")) { addEditor(reinterpret_cast(PluginManager::instance()->getPluginObject(it))); }