| 324 | } |
| 325 | |
| 326 | void 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 |
no test coverage detected