MCPcopy Create free account
hub / github.com/MayaPosch/NymphCast / update

Method update

player/NymphCastPlayer/container_qpainter.cpp:375–435  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

373}
374
375void Selection::update()
376{
377 const auto addElement = [this](const Selection::Element &element,
378 const Selection::Element &end = {}) {
379 litehtml::tstring elemText;
380 element.element->get_text(elemText);
381 const QString textStr = QString::fromStdString(elemText);
382 if (!textStr.isEmpty()) {
383 QRect rect = toQRect(element.element->get_placement()).adjusted(-1, -1, 1, 1);
384 if (element.index < 0) { // fully selected
385 text += textStr;
386 } else if (end.element) { // select from element "to end"
387 if (element.element == end.element) {
388 // end.index is guaranteed to be >= element.index by caller, same for x
389 text += textStr.mid(element.index, end.index - element.index);
390 const int left = rect.left();
391 rect.setLeft(left + element.x);
392 rect.setRight(left + end.x);
393 } else {
394 text += textStr.mid(element.index);
395 rect.setLeft(rect.left() + element.x);
396 }
397 } else { // select from start of element
398 text += textStr.left(element.index);
399 rect.setRight(rect.left() + element.x);
400 }
401 selection.append(rect);
402 }
403 };
404
405 if (startElem.element && endElem.element) {
406 // Edge cases:
407 // start and end elements could be reversed or children of each other
408 Selection::Element start;
409 Selection::Element end;
410 std::tie(start, end) = getStartAndEnd(startElem, endElem);
411
412 selection.clear();
413 text.clear();
414
415 // Treats start element as a leaf even if it isn't, because it already contains all its
416 // children
417 addElement(start, end);
418 if (start.element != end.element) {
419 litehtml::element::ptr current = start.element;
420 do {
421 current = nextLeaf(current, end.element);
422 if (current == end.element)
423 addElement(end);
424 else
425 addElement({current, -1, -1});
426 } while (current != end.element);
427 }
428 } else {
429 selection = {};
430 text.clear();
431 }
432 QClipboard *cb = QGuiApplication::clipboard();

Callers 11

findTextMethod · 0.45
mouseMoveEventMethod · 0.45
mousePressEventMethod · 0.45
mouseReleaseEventMethod · 0.45
mouseDoubleClickEventMethod · 0.45
leaveEventMethod · 0.45
renderMethod · 0.45
renderMethod · 0.45
mouseMoveEventMethod · 0.45
mouseDoubleClickEventMethod · 0.45
findTextMethod · 0.45

Calls 9

toQRectFunction · 0.85
getStartAndEndFunction · 0.85
nextLeafFunction · 0.85
get_placementMethod · 0.80
appendMethod · 0.80
get_textMethod · 0.45
leftMethod · 0.45
clearMethod · 0.45
setTextMethod · 0.45

Tested by

no test coverage detected