MCPcopy Create free account
hub / github.com/bumptop/BumpTop / syncStickyNoteWithFileContents

Method syncStickyNoteWithFileContents

trunk/win/Source/BT_StickyNoteActor.cpp:326–404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

324}
325
326void StickyNoteActor::syncStickyNoteWithFileContents()
327{
328 reauthorize(false);
329
330 // clear the old texture
331#ifdef DXRENDER
332 SAFE_RELEASE(_stickyNoteTextureId);
333#else
334 if (_stickyNoteTextureId)
335 {
336 glDeleteTextures(1, &_stickyNoteTextureId);
337 _stickyNoteTextureId = 0;
338 }
339#endif
340
341 // get the font
342 int fontSize = NxMath::max(20, themeManager->getValueAsInt("ui.stickyNote.font.size",0));
343 FontDescription desc(themeManager->getValueAsFontFamilyName("ui.stickyNote.font.family",""), fontSize);
344 QFont stickyNoteFont = fontManager->getFont(desc);
345
346 // get the sticky note text
347 QString stickyNoteStr;
348 getStickyNote(getFullPath(), &stickyNoteStr);
349
350 // layout the sticky note text
351 QTextOption option;
352 option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
353 _stickyNoteText.setDefaultTextOption(option);
354 _stickyNoteText.setDefaultFont(stickyNoteFont);
355 _stickyNoteText.setDocumentMargin(12.5f);
356 _stickyNoteText.setTextWidth(256);
357 _stickyNoteText.setPlainText(stickyNoteStr);
358
359 QSizeF textSize = _stickyNoteText.size();
360 const int minStickyNoteFontSize = 10;
361 while (textSize.height() > 256 &&
362 stickyNoteFont.pointSize() > minStickyNoteFontSize)
363 {
364 stickyNoteFont.setPointSize(stickyNoteFont.pointSize() - 1);
365 _stickyNoteText.setDefaultFont(stickyNoteFont);
366 textSize = _stickyNoteText.size();
367 }
368
369 // render the sticky note to a qimage
370 const unsigned int bufferSize = 256;
371 QImage image(bufferSize, bufferSize, QImage::Format_ARGB32);
372 image.fill(Qt::red);
373 QPainter p;
374 p.begin(&image);
375 p.setRenderHint(QPainter::Antialiasing, true);
376 p.setRenderHint(QPainter::TextAntialiasing, true);
377 p.drawImage(0, 0, _stickyNoteBackground);
378 p.setPen(QColor(50, 50, 75));
379 _stickyNoteText.drawContents(&p, QRect(0, 0, bufferSize, int(bufferSize - _stickyNoteText.documentMargin())));
380 p.end();
381#ifdef DXRENDER
382 _stickyNoteTextureId = dxr->createTextureFromData(image.width(), image.height(), image.bits(), image.bytesPerLine());
383#else

Callers 5

processGestureImplMethod · 0.80
onFileModifiedMethod · 0.80
PostIntroLoadFunction · 0.80

Calls 15

getStickyNoteFunction · 0.85
getValueAsIntMethod · 0.80
getFontMethod · 0.80
drawImageMethod · 0.80
createTextureFromDataMethod · 0.80
bitsMethod · 0.80
maxClass · 0.50
QColorClass · 0.50
QRectClass · 0.50
sizeMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected