void BubbleEllipse::writeImage() const { int fontsize = static_cast<int>(font->size);//todo bgcolor->use(); imlib_image_fill_ellipse(centerx, centery, radiusx-1, radiusy-1); // Wähle die Höhe der 1. Zeile so, dass das 1. Wort gerade hineinpasst. int width, height; unsigned first_idx = text.find(' '); string first_word = (first_idx != string::npos) ? text.substr(0,first_idx) : text; font->use(); imlib_get_text_size(first_word.c_str(), &width, &height); height = -radiusy; do { height++; //printf("%s of width %d does not fit into width %d, increase h to %d\n", //first_word.c_str(), width, ellipseWidth(radiusx, radiusy, abs(height)), height); } while (ellipseWidth(radiusx, radiusy, abs(height)) < width && height <= 0); height += fontsize/3; // Schreibe den Text nacheinander in die Zeilen. string rest = text; while(rest.length() > 0) { if (height > radiusy-2) { std::cerr<< "Error: text does not fit, aborting: "<< text <<".\n"; break; } width = ellipseWidth(radiusx, radiusy, abs(height)); rest = drawTextLine(centerx-width/2, centery+height, rest, width, height/(float)radiusx); height += fontsize*1.7; } }
void ZLTextArea::paint() { myTextElementMap.clear(); myTreeNodeMap.clear(); std::vector<size_t> labels; labels.reserve(myLineInfos.size() + 1); labels.push_back(0); ZLTextArea::Style style(*this, myProperties.baseStyle()); int y = 0; for (std::vector<ZLTextLineInfoPtr>::const_iterator it = myLineInfos.begin(); it != myLineInfos.end(); ++it) { const ZLTextLineInfo &info = **it; prepareTextLine(style, info, y); y += info.Height + info.Descent + info.VSpaceAfter; labels.push_back(myTextElementMap.size()); } if (!mySelectionModel.isNull()) { if (!myProperties.isSelectionEnabled()) { mySelectionModel->clear(); } else { mySelectionModel->update(); } } y = 0; int index = 0; for (std::vector<ZLTextLineInfoPtr>::const_iterator it = myLineInfos.begin(); it != myLineInfos.end(); ++it) { const ZLTextLineInfo &info = **it; drawTextLine(style, info, y, labels[index], labels[index + 1]); y += info.Height + info.Descent + info.VSpaceAfter; ++index; } }
void ZLTextView::paint() { preparePaintInfo(); myTextElementMap.clear(); myTreeNodeMap.clear(); context().clear(ZLTextStyleCollection::instance().baseStyle().BackgroundColorOption.value()); if (empty()) { return; } std::vector<size_t> labels; labels.reserve(myLineInfos.size() + 1); labels.push_back(0); int y = topMargin(); for (std::vector<ZLTextLineInfoPtr>::const_iterator it = myLineInfos.begin(); it != myLineInfos.end(); ++it) { const ZLTextLineInfo &info = **it; prepareTextLine(info, y); y += info.Height + info.Descent + info.VSpaceAfter; labels.push_back(myTextElementMap.size()); } mySelectionModel.update(); y = topMargin(); int index = 0; for (std::vector<ZLTextLineInfoPtr>::const_iterator it = myLineInfos.begin(); it != myLineInfos.end(); ++it) { const ZLTextLineInfo &info = **it; drawTextLine(info, y, labels[index], labels[index + 1]); y += info.Height + info.Descent + info.VSpaceAfter; ++index; } fb::shared_ptr<ZLTextPositionIndicatorInfo> indicatorInfo = this->indicatorInfo(); if (!indicatorInfo.isNull() && (indicatorInfo->type() == ZLTextPositionIndicatorInfo::FB_INDICATOR)) { positionIndicator()->draw(); } if (myDoUpdateScrollbar && !indicatorInfo.isNull()) { myDoUpdateScrollbar = false; const size_t full = positionIndicator()->sizeOfTextBeforeParagraph(positionIndicator()->endTextIndex()); const size_t from = positionIndicator()->sizeOfTextBeforeCursor(startCursor()); const size_t to = positionIndicator()->sizeOfTextBeforeCursor(endCursor()); bool showScrollbar = (indicatorInfo->type() == ZLTextPositionIndicatorInfo::OS_SCROLLBAR) && (to - from < full); if (showScrollbar) { setScrollbarEnabled(VERTICAL, true); setScrollbarParameters(VERTICAL, full, from, to); } else { setScrollbarEnabled(VERTICAL, false); } } ZLTextParagraphCursorCache::cleanup(); }
void BubbleRectangle::writeImage() const { int fontsize = static_cast<int>(font->size);//todo bgcolor->use(); imlib_image_fill_rectangle(x0, y0, width, height); // Text schreiben string rest = text; int txtheight = 0.8*fontsize; font->use(); while(rest.length() > 0) { if (txtheight > height) { std::cerr<< "Error: text does not fit, aborting: "<< text <<".\n"; break; } rest = drawTextLine(x0, y0+txtheight, rest, width, txtheight/(float)width, false); txtheight += fontsize*1.7; } }
/************************************************************************* Renders text on the display. Return number of lines output. *************************************************************************/ size_t Font::drawText(const String& text, const Rect& draw_area, float z, const Rect& clip_rect, TextFormatting fmt, const ColourRect& colours, float x_scale, float y_scale) { size_t thisCount; size_t lineCount = 0; float y_base = draw_area.d_top + getBaseline(y_scale); Rect tmpDrawArea( PixelAligned(draw_area.d_left), PixelAligned(draw_area.d_top), PixelAligned(draw_area.d_right), PixelAligned(draw_area.d_bottom) ); size_t lineStart = 0, lineEnd = 0; String currLine; while (lineEnd < text.length()) { if ((lineEnd = text.find_first_of('\n', lineStart)) == String::npos) lineEnd = text.length(); currLine = text.substr(lineStart, lineEnd - lineStart); lineStart = lineEnd + 1; // +1 to skip \n char switch(fmt) { case LeftAligned: drawTextLine(currLine, Vector3(tmpDrawArea.d_left, y_base, z), clip_rect, colours, x_scale, y_scale); thisCount = 1; y_base += getLineSpacing(y_scale); break; case RightAligned: drawTextLine(currLine, Vector3(tmpDrawArea.d_right - getTextExtent(currLine, x_scale), y_base, z), clip_rect, colours, x_scale, y_scale); thisCount = 1; y_base += getLineSpacing(y_scale); break; case Centred: drawTextLine(currLine, Vector3(PixelAligned(tmpDrawArea.d_left + ((tmpDrawArea.getWidth() - getTextExtent(currLine, x_scale)) / 2.0f)), y_base, z), clip_rect, colours, x_scale, y_scale); thisCount = 1; y_base += getLineSpacing(y_scale); break; case Justified: // new function in order to keep drawTextLine's signature unchanged drawTextLineJustified(currLine, draw_area, Vector3(tmpDrawArea.d_left, y_base, z), clip_rect, colours, x_scale, y_scale); thisCount = 1; y_base += getLineSpacing(y_scale); break; case WordWrapLeftAligned: thisCount = drawWrappedText(currLine, tmpDrawArea, z, clip_rect, LeftAligned, colours, x_scale, y_scale); tmpDrawArea.d_top += thisCount * getLineSpacing(y_scale); break; case WordWrapRightAligned: thisCount = drawWrappedText(currLine, tmpDrawArea, z, clip_rect, RightAligned, colours, x_scale, y_scale); tmpDrawArea.d_top += thisCount * getLineSpacing(y_scale); break; case WordWrapCentred: thisCount = drawWrappedText(currLine, tmpDrawArea, z, clip_rect, Centred, colours, x_scale, y_scale); tmpDrawArea.d_top += thisCount * getLineSpacing(y_scale); break; case WordWrapJustified: // no change needed thisCount = drawWrappedText(currLine, tmpDrawArea, z, clip_rect, Justified, colours, x_scale, y_scale); tmpDrawArea.d_top += thisCount * getLineSpacing(y_scale); break; default: throw InvalidRequestException("Font::drawText - Unknown or unsupported TextFormatting value specified."); } lineCount += thisCount; } // should not return 0 return ceguimax(lineCount, (size_t)1); }
void LocationCompleterDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItemV4 opt = option; initStyleOption(&opt, index); const QWidget* w = opt.widget; const QStyle* style = w ? w->style() : QApplication::style(); const int height = opt.rect.height(); const int center = height / 2 + opt.rect.top(); // Prepare title font QFont titleFont = opt.font; titleFont.setPointSize(titleFont.pointSize() + 1); const QFontMetrics titleMetrics(titleFont); int leftPosition = m_padding * 2; int rightPosition = opt.rect.right() - m_padding; opt.state &= ~QStyle::State_MouseOver; if (m_view->hoveredIndex() == index) { opt.state |= QStyle::State_Selected; } else { opt.state &= ~QStyle::State_Selected; } #ifdef Q_OS_WIN const QPalette::ColorRole colorRole = QPalette::Text; const QPalette::ColorRole colorLinkRole = QPalette::Link; #else const QPalette::ColorRole colorRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text; const QPalette::ColorRole colorLinkRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Link; #endif // Draw background style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, w); // Draw icon const int iconSize = 16; const int iconYPos = center - (iconSize / 2); QRect iconRect(leftPosition, iconYPos, iconSize, iconSize); QPixmap pixmap = index.data(Qt::DecorationRole).value<QIcon>().pixmap(iconSize); painter->drawPixmap(iconRect, pixmap); leftPosition = iconRect.right() + m_padding * 2; // Draw star to bookmark items int starPixmapWidth = 0; if (index.data(LocationCompleterModel::BookmarkRole).toBool()) { const QPixmap starPixmap = qIconProvider->bookmarkIcon(); QSize starSize = starPixmap.size(); //new starPixmapWidth = starSize.width(); QPoint pos(rightPosition - starPixmapWidth, opt.rect.top() + m_padding); QRect starRect(pos, starSize); painter->drawPixmap(starRect, starPixmap); } const QString &searchText = index.data(LocationCompleterModel::SearchStringRole).toString(); // Draw title const int leftTitleEdge = leftPosition + 2; // RTL Support: remove conflicting of right-aligned text and starpixmap! const int rightTitleEdge = rightPosition - m_padding - starPixmapWidth; QRect titleRect(leftTitleEdge, opt.rect.top() + m_padding, rightTitleEdge - leftTitleEdge, titleMetrics.height()); QString title(titleMetrics.elidedText(index.data(LocationCompleterModel::TitleRole).toString(), Qt::ElideRight, titleRect.width())); painter->setFont(titleFont); drawHighlightedTextLine(titleRect, title, searchText, painter, style, opt, colorRole); // Draw link const int infoYPos = titleRect.bottom() + opt.fontMetrics.leading() + 2; QRect linkRect(titleRect.x(), infoYPos, titleRect.width(), opt.fontMetrics.height()); QString link(opt.fontMetrics.elidedText(index.data(Qt::DisplayRole).toString(), Qt::ElideRight, linkRect.width())); painter->setFont(opt.font); TabPosition pos = index.data(LocationCompleterModel::TabPositionRole).value<TabPosition>(); if (m_drawSwitchToTab && pos.windowIndex != -1) { const QIcon tabIcon = QIcon(":icons/menu/tab.png"); QRect iconRect(linkRect); iconRect.setWidth(m_padding + 16 + m_padding); tabIcon.paint(painter, iconRect); QRect textRect(linkRect); textRect.setX(textRect.x() + m_padding + 16 + m_padding); drawTextLine(textRect, LocationCompleterView::tr("Switch to tab"), painter, style, opt, colorLinkRole); } else { drawHighlightedTextLine(linkRect, link, searchText, painter, style, opt, colorLinkRole); } // Draw line at the very bottom of item if the item is not highlighted if (!(opt.state & QStyle::State_Selected)) { QRect lineRect(opt.rect.left(), opt.rect.bottom(), opt.rect.width(), 1); painter->fillRect(lineRect, opt.palette.color(QPalette::AlternateBase)); } }