Example #1
0
void BrailleMusicEditor::highlightObject(int id) {
  QList<QTextEdit::ExtraSelection> selections;
  QSettings settings;

  if (id == -1) // remove highlighting
  {
    textEdit->setExtraSelections(selections);
    textEdit->show();
    return;
  }

  struct finder : public ::bmc::braille::ast::const_visitor<finder> {
    int target_id, beg_line, beg_column, end_line, end_column;

    finder(int target_id)
    : target_id{target_id}
    , beg_line{-1}
    , beg_column{-1}
    , end_line{-1}
    , end_column{-1} {}

    bool visit_locatable(::bmc::braille::ast::locatable const &lexeme) {
      if (lexeme.id == target_id) {
        beg_line = lexeme.begin_line;
        beg_column = lexeme.begin_column;
        end_line = lexeme.end_line;
        end_column = lexeme.end_column;

        return false;
      }
      return true;
    }
  } find{id};

  QColor highlightingColor(230, 230, 250);

  if (auto rgba = settings.value("ui/highlighting_color").toUInt()) {
    highlightingColor.setRgba(rgba);
  }

  if (score && find.traverse_score(*score) == false) {
    QTextCharFormat format;
    format.setBackground(QBrush(highlightingColor));
    QTextBlock block =
      textEdit->document()->findBlockByLineNumber(find.beg_line - 1);
    if (block.isValid()) {
      QTextCursor cursor = textEdit->textCursor();
      cursor.setPosition(block.position() + find.beg_column - 1);
      cursor.movePosition(QTextCursor::Down, QTextCursor::KeepAnchor,
                          find.beg_line - find.end_line);
      cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor,
                          find.end_column - find.beg_column);
      QTextEdit::ExtraSelection sel = {cursor, format};
      selections.append(sel);
    }
    textEdit->setExtraSelections(selections);
    textEdit->show();
  }
}
int QHexEdit::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QScrollArea::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: currentAddressChanged((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 1: currentSizeChanged((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 2: dataChanged(); break;
        case 3: overwriteModeChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 4: setAddressWidth((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 5: setAddressArea((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 6: setAsciiArea((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 7: setHighlighting((*reinterpret_cast< bool(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 8;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< QByteArray*>(_v) = data(); break;
        case 1: *reinterpret_cast< int*>(_v) = addressOffset(); break;
        case 2: *reinterpret_cast< QColor*>(_v) = addressAreaColor(); break;
        case 3: *reinterpret_cast< QColor*>(_v) = highlightingColor(); break;
        case 4: *reinterpret_cast< bool*>(_v) = overwriteMode(); break;
        }
        _id -= 5;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setData(*reinterpret_cast< QByteArray*>(_v)); break;
        case 1: setAddressOffset(*reinterpret_cast< int*>(_v)); break;
        case 2: setAddressAreaColor(*reinterpret_cast< QColor*>(_v)); break;
        case 3: setHighlightingColor(*reinterpret_cast< QColor*>(_v)); break;
        case 4: setOverwriteMode(*reinterpret_cast< bool*>(_v)); break;
        }
        _id -= 5;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 5;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 5;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 5;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 5;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 5;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 5;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}