MCPcopy Create free account
hub / github.com/MiniZinc/MiniZincIDE / copyHighlightedToClipboard

Method copyHighlightedToClipboard

MiniZincIDE/highlighter.cpp:315–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

313#include <QMimeData>
314
315void Highlighter::copyHighlightedToClipboard(QTextCursor cursor)
316{
317 QTextDocument* tempDocument(new QTextDocument);
318 Q_ASSERT(tempDocument);
319 QTextCursor tempCursor(tempDocument);
320
321 tempCursor.insertFragment(cursor.selection());
322 tempCursor.select(QTextCursor::Document);
323
324 QTextCharFormat textfmt = cursor.charFormat();
325 textfmt.setFont(commentFormat.font());
326 tempCursor.setCharFormat(textfmt);
327
328 QTextBlock start = document()->findBlock(cursor.selectionStart());
329 QTextBlock end = document()->findBlock(cursor.selectionEnd());
330 end = end.next();
331 const int selectionStart = cursor.selectionStart();
332 const int endOfDocument = tempDocument->characterCount() - 1;
333 for(QTextBlock current = start; current.isValid() && current != end; current = current.next()) {
334 const QTextLayout* layout(current.layout());
335
336 foreach(const QTextLayout::FormatRange &range, layout->formats()) {
337 const int start = current.position() + range.start - selectionStart;
338 const int end = start + range.length;
339 if(end <= 0 || start >= endOfDocument)
340 continue;
341 tempCursor.setPosition(qMax(start, 0));
342 tempCursor.setPosition(qMin(end, endOfDocument), QTextCursor::KeepAnchor);
343 tempCursor.setCharFormat(range.format);
344 }
345 }
346
347 for(QTextBlock block = tempDocument->begin(); block.isValid(); block = block.next())
348 block.setUserState(-1);
349
350 tempCursor.select(QTextCursor::Document);
351 QTextBlockFormat blockFormat = cursor.blockFormat();
352 blockFormat.setNonBreakableLines(true);
353 tempCursor.setBlockFormat(blockFormat);
354
355 IDEUtils::MimeDataExporter te;
356 te.setDocument(tempDocument);
357 te.selectAll();
358 QMimeData* mimeData = te.md();
359 QApplication::clipboard()->setMimeData(mimeData);
360 delete tempDocument;
361}
362
363void Highlighter::setTheme(const Theme& theme, bool darkMode)
364{

Callers 2

copyMethod · 0.80
cutMethod · 0.80

Calls 5

nextMethod · 0.80
isValidMethod · 0.80
setDocumentMethod · 0.80
mdMethod · 0.80
beginMethod · 0.45

Tested by

no test coverage detected