QPixmap QzTools::createPixmapForSite(const QIcon &icon, const QString &title, const QString &url) { const QFontMetrics fontMetrics = QApplication::fontMetrics(); const int padding = 4; const int maxWidth = fontMetrics.width(title.length() > url.length() ? title : url) + 3 * padding + 16; const int width = qMin(maxWidth, 150); const int height = fontMetrics.height() * 2 + fontMetrics.leading() + 2 * padding; QPixmap pixmap(width, height); QPainter painter(&pixmap); // Draw background QPen pen(Qt::black); pen.setWidth(1); painter.setPen(pen); painter.fillRect(QRect(0, 0, width, height), Qt::white); painter.drawRect(0, 0, width - 1, height - 1); // Draw icon QRect iconRect(0, 0, 16 + 2 * padding, height); icon.paint(&painter, iconRect); // Draw title QRect titleRect(iconRect.width(), padding, width - padding - iconRect.width(), fontMetrics.height()); painter.drawText(titleRect, fontMetrics.elidedText(title, Qt::ElideRight, titleRect.width())); // Draw url QRect urlRect(titleRect.x(), titleRect.bottom() + fontMetrics.leading(), titleRect.width(), titleRect.height()); painter.setPen(QApplication::palette().color(QPalette::Link)); painter.drawText(urlRect, fontMetrics.elidedText(url, Qt::ElideRight, urlRect.width())); return pixmap; }
void FluidWidget::paintEvent(QPaintEvent * /* event */) { QPainter painter(this); //painter.fillRect(rect(), Qt::black); if (pixmap.isNull()) { painter.setPen(Qt::white); painter.drawText(rect(), Qt::AlignCenter, tr("Rendering initial image, please wait...")); return; } painter.drawPixmap(0, 0, pixmap); QString text = tr("Use mouse wheel or the '+' and '-' keys to zoom. " "Press and hold left mouse button to scroll."); QFontMetrics metrics = painter.fontMetrics(); int textWidth = metrics.width(text); painter.setPen(Qt::NoPen); painter.setBrush(QColor(0, 0, 0, 127)); painter.drawRect((width() - textWidth) / 2 - 5, 0, textWidth + 10, metrics.lineSpacing() + 5); painter.setPen(Qt::white); painter.drawText((width() - textWidth) / 2, metrics.leading() + metrics.ascent(), text); }
void AlbumWidget::paintEvent(QPaintEvent *) { QPainter painter(this); painter.fillRect(rect(), Qt::black); if (m_pixmap.isNull()) { painter.setPen(Qt::white); painter.drawText(rect(), Qt::AlignCenter, tr("Downloading cover, please wait...")); return; } painter.drawPixmap(0, 0, m_pixmap); Song* actualSong = MediaApp::getInstance()->getPlaylistInstance()->getActual(); if (actualSong != NULL) { m_nowPlaying = QString::fromStdString(actualSong->getTitle()); } else { m_nowPlaying = tr("ThePlayer"); } QFontMetrics metrics = painter.fontMetrics(); int textWidth = metrics.width(m_nowPlaying); painter.setPen(Qt::NoPen); painter.setBrush(QColor(0, 0, 0, 127)); painter.drawRect((width() - textWidth) / 2 - 5, 0, textWidth + 10, metrics.lineSpacing() + 5); painter.setPen(Qt::white); painter.drawText((width() - textWidth) / 2, metrics.leading() + metrics.ascent() + 2, m_nowPlaying); }
void KSplitListItem::paint( QPainter *p ) { QFontMetrics fm = p->fontMetrics(); int yPos; // vertical text position yPos = fm.ascent() + fm.leading()/2; p->drawText( 5, yPos, actionName ); p->drawText( 5 + halfWidth, yPos, keyName ); }
void OptionsDialog::ColorListItem::paint( QPainter *p ) { QFontMetrics fm = p->fontMetrics(); int h = fm.height(); p->drawText( 30+3*2, fm.ascent() + fm.leading()/2, text() ); p->setPen( Qt::black ); p->drawRect( 3, 1, 30, h-1 ); p->fillRect( 4, 2, 28, h-3, mColor ); }
void KIconListBoxItem::paint( QPainter *p ) { p->drawPixmap( 3, 0, pm ); QFontMetrics fm = p->fontMetrics(); int yPos; // vertical text position if ( pm.height() < fm.height() ) yPos = fm.ascent() + fm.leading()/2; else yPos = pm.height()/2 - fm.height()/2 + fm.ascent(); p->drawText( pm.width() + 5, yPos, text() ); }
void GrepListBoxItem::paint(QPainter *p) { QColor base, dim, result, bkground; if (listBox()) { const QColorGroup& group = listBox()->palette().active(); if (isSelected()) { bkground = group.button(); base = group.buttonText(); } else { bkground = group.base(); base = group.text(); } dim = blend(base, bkground); result = group.link(); } else { base = Qt::black; dim = Qt::darkGreen; result = Qt::blue; if (isSelected()) bkground = Qt::lightGray; else bkground = Qt::white; } QFontMetrics fm = p->fontMetrics(); QString stx = lineNumber + ": "; int y = fm.ascent()+fm.leading()/2; int x = 3; p->fillRect(p->window(), QBrush(bkground)); if (show) { p->setPen(dim); p->drawText(x, y, fileName); x += fm.width(fileName); } else { p->setPen(base); QFont font1(p->font()); QFont font2(font1); font2.setBold(true); p->setFont(font2); p->drawText(x, y, stx); p->setFont(font1); x += fm.width(stx); p->setPen(result); p->drawText(x, y, text); } }
//! [2] void MandelbrotWidget::paintEvent(QPaintEvent * /* event */) { QPainter painter(this); painter.fillRect(rect(), Qt::black); if (pixmap.isNull()) { painter.setPen(Qt::white); painter.drawText(rect(), Qt::AlignCenter, tr("Rendering initial image, please wait...")); //! [2] //! [3] return; //! [3] //! [4] } //! [4] //! [5] if (curScale == pixmapScale) { //! [5] //! [6] painter.drawPixmap(pixmapOffset, pixmap); //! [6] //! [7] } else { //! [7] //! [8] double scaleFactor = pixmapScale / curScale; int newWidth = int(pixmap.width() * scaleFactor); int newHeight = int(pixmap.height() * scaleFactor); int newX = pixmapOffset.x() + (pixmap.width() - newWidth) / 2; int newY = pixmapOffset.y() + (pixmap.height() - newHeight) / 2; painter.save(); painter.translate(newX, newY); painter.scale(scaleFactor, scaleFactor); QRectF exposed = painter.matrix().inverted().mapRect(rect()).adjusted(-1, -1, 1, 1); painter.drawPixmap(exposed, pixmap, exposed); painter.restore(); } //! [8] //! [9] #if !defined(Q_WS_S60) && !defined(Q_WS_MAEMO_5) && !defined(Q_WS_SIMULATOR) QString text = tr("Use mouse wheel or the '+' and '-' keys to zoom. " "Press and hold left mouse button to scroll."); QFontMetrics metrics = painter.fontMetrics(); int textWidth = metrics.width(text); painter.setPen(Qt::NoPen); painter.setBrush(QColor(0, 0, 0, 127)); painter.drawRect((width() - textWidth) / 2 - 5, 0, textWidth + 10, metrics.lineSpacing() + 5); painter.setPen(Qt::white); painter.drawText((width() - textWidth) / 2, metrics.leading() + metrics.ascent(), text); #endif }
/** * Update Vim metrics */ static void update_char_metrics(const QFontMetrics& metric) { gui.char_width = metric.width("M"); // The actual linespace plus Vim's fake linespace gui.char_height = metric.lineSpacing() + p_linespace; if ( metric.underlinePos() >= metric.descent() ) { gui.char_height += metric.underlinePos() - metric.descent() + metric.lineWidth(); } gui.char_ascent = metric.ascent() + p_linespace/2 + metric.leading(); gui.char_ul_pos = metric.underlinePos(); }
void GLWidget::drawInstructions(QPainter *painter) { QString text = tr(""); QFontMetrics metrics = QFontMetrics(font()); int border = qMax(4, metrics.leading()); QRect rect = metrics.boundingRect(0, 0, width() - 2*border, int(height()*0.125), Qt::AlignCenter | Qt::TextWordWrap, text); painter->setRenderHint(QPainter::TextAntialiasing); painter->fillRect(QRect(0, 0, width(), rect.height() + 2*border), QColor(0, 0, 0, 127)); painter->setPen(Qt::white); painter->fillRect(QRect(0, 0, width(), rect.height() + 2*border), QColor(0, 0, 0, 127)); painter->drawText((width() - rect.width())/2, border, rect.width(), rect.height(), Qt::AlignCenter | Qt::TextWordWrap, text); }
void BaseRender::resetOverlay(int width, int height) { QString text = tr("Plexy Desk 1.0, Revolution Begins"); QFontMetrics metrics = QFontMetrics(font()); int border = qMax(4, metrics.leading()); QRect rect = metrics.boundingRect(0, 0, width - 2 * border, int (height * 0.125), Qt::AlignCenter | Qt::TextWordWrap, text); d->image = QImage(width, rect.height() + 2 * border, QImage::Format_ARGB32_Premultiplied); d->image.fill(qRgba(0, 0, 0, 127)); QPainter painter; painter.begin(&d->image); painter.setRenderHint(QPainter::TextAntialiasing); painter.setPen(Qt::white); painter.drawText((width - rect.width()) / 2, border, rect.width(), rect.height(), Qt::AlignCenter | Qt::TextWordWrap, text); painter.end(); }
void KDirListBoxItem::paint( QPainter *p ) { if(italic) { p->save(); QFont f = p->font(); f.setItalic(true); p->setFont(f); } p->drawPixmap( 3, 2, *pm ); QFontMetrics fm = p->fontMetrics(); int yPos; // vertical text position if ( (pm->height()) < fm.height() ) yPos = fm.ascent() + fm.leading()/2; else yPos = pm->height()/2 - fm.height()/2 + fm.ascent(); yPos= yPos+2; p->drawText( pm->width() + 5, yPos, text() ); if(italic) p->restore(); }
void VCWidget::paintEvent(QPaintEvent* e) { int caption_x = 0; int caption_y = 0; // First paint whatever QFrame wants to QFrame::paintEvent(e); // Draw the widget's caption QPainter painter(this); QFontMetrics metrics = painter.fontMetrics(); QSize textSize = metrics.size(SingleLine, caption()); caption_x = static_cast<int> (floor((width() / 2.0) - (textSize.width() / 2.0))); caption_y = static_cast<int> (floor((height() / 2.0) + ((textSize.height() - metrics.leading()) / 2.0))); painter.drawText(caption_x, caption_y, caption()); /* Draw selection frame */ if (_app->mode() == App::Design && _app->virtualConsole()->selectedWidget() == this) { // Draw a dotted line around the widget QPen pen(DotLine); pen.setWidth(2); painter.setPen(pen); painter.drawRect(1, 1, rect().width() - 1, rect().height() - 1); // Draw a resize handle QBrush b(SolidPattern); painter.fillRect(rect().width() - 10, rect().height() - 10, 10, 10, b); } }
QSize StatusEventItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { int iconHeight, iconWidth; int textWidth, textHeight; QFontMetrics fontMetrics = option.fontMetrics; QPixmap icon = index.data(StatusEventItem::IconRole).value<QPixmap>(); QString text = index.data(StatusEventItem::DescriptionRole).toString(); QTime tstamp = index.data(StatusEventItem::TimestampRole).toTime(); iconHeight = icon.height() + fontMetrics.lineSpacing() + 16; iconWidth = qMax(fontMetrics.width(tstamp.toString()), icon.width()) + 16; textWidth = option.rect.width() - iconWidth; if (option.state & QStyle::State_Selected) layoutText(text, option.font, textWidth, 6, &textHeight); else layoutText(text, option.font, textWidth, 3, &textHeight); textHeight += 8 + fontMetrics.leading() + fontMetrics.lineSpacing(); return QSize(option.rect.width(), qMax(iconHeight, textHeight)); }
QSize TopicEdit::minimumSizeHint() const { QFontMetrics fm = fontMetrics(); int m = frameWidth() * 2; return QSize( fm.maxWidth() + m, fm.height() + QMAX( 2*1, fm.leading()) + m ); }
void StatusEventItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QItemDelegate::paint(painter, option, index); painter->save(); if (option.state & QStyle::State_Selected) painter->setPen(option.palette.highlightedText().color()); QPixmap icon = index.data(StatusEventItem::IconRole).value<QPixmap>(); QTime tstamp = index.data(StatusEventItem::TimestampRole).toTime(); QString title = index.data(StatusEventItem::TitleRole).toString(); QString text = index.data(StatusEventItem::DescriptionRole).toString(); QFont font = option.font; QFontMetrics fm = option.fontMetrics; /* XXX: Handle right-to-left layouts here. */ QRect iconRect(option.rect.x(), option.rect.y(), qMax(fm.width(tstamp.toString()), icon.width()) + 16, option.rect.height()); QRect textRect(iconRect.topRight(), option.rect.bottomRight()); // Draw the status icon QPoint center = iconRect.center(); int x = center.x() - qRound(icon.width() / 2.0); int y = center.y() - qRound((icon.height() + fm.lineSpacing()) / 2.0); painter->drawPixmap(x, y, icon); // Draw the timestamp text underneath the status icon x = iconRect.x(); y = y + icon.height(); painter->drawText(x, y, iconRect.width(), fm.lineSpacing(), Qt::AlignCenter, tstamp.toString()); // Draw the event's title in a bold font. If the current item has an // associated help URL, draw the little "?" icon to the right of the // title text font.setBold(true); painter->setFont(font); if (! index.data(StatusEventItem::HelpUrlRole).isNull()) { // Draw the little "?" icon in the corner of the list item and // account for it when eliding the title title = fm.elidedText(title, Qt::ElideRight, textRect.width() - _helpIcon.width() - 24); x = textRect.topRight().x() - _helpIcon.width() - 8; y = textRect.y() + 8; painter->drawPixmap(x, y, _helpIcon); } else { title = fm.elidedText(title, Qt::ElideRight, textRect.width() - 16); } painter->drawText(textRect.x(), textRect.y() + 8, textRect.width(), fm.lineSpacing(), Qt::AlignVCenter | Qt::AlignLeft, title); // Draw the rest of the event text, up to a maximum of 2 lines for // unselected items or 5 lines for selected items. Any extra text will // be elided. font.setBold(false); painter->setFont(font); if (option.state & QStyle::State_Selected) text = layoutText(text, font, textRect.width(), 6).join("\n"); else text = layoutText(text, font, textRect.width(), 3).join("\n"); x = textRect.x(); y = textRect.y() + 8 + fm.leading() + fm.lineSpacing(); painter->drawText(x, y, textRect.width(), textRect.height() - (y - textRect.y()), Qt::AlignTop | Qt::AlignLeft, text); painter->restore(); }
void KURLBarItem::paint(QPainter *p) { QListBox *box = listBox(); int w = width(box); static const int margin = KDialog::spacingHint(); // draw sunken selection if(isCurrent() || isSelected()) { int h = height(box); QBrush brush = box->colorGroup().brush(QColorGroup::Highlight); p->fillRect(0, 0, w, h, brush); QPen pen = p->pen(); QPen oldPen = pen; pen.setColor(box->colorGroup().mid()); p->setPen(pen); p->drawPoint(0, 0); p->drawPoint(0, h - 1); p->drawPoint(w - 1, 0); p->drawPoint(w - 1, h - 1); p->setPen(oldPen); } if(m_parent->iconSize() < KIcon::SizeMedium) { // small icon -> draw icon next to text // ### mostly cut & paste of QListBoxPixmap::paint() until Qt 3.1 // (where it will properly use pixmap() instead of the internal pixmap) const QPixmap *pm = pixmap(); int yPos = QMAX(0, (height(box) - pm->height()) / 2); p->drawPixmap(margin, yPos, *pm); if(!text().isEmpty()) { QFontMetrics fm = p->fontMetrics(); if(pm->height() < fm.height()) yPos = fm.ascent() + fm.leading() / 2; else yPos = pm->height() / 2 - fm.height() / 2 + fm.ascent(); yPos += margin; int stringWidth = box->width() - pm->width() - 2 - (margin * 2); QString visibleText = KStringHandler::rPixelSqueeze(text(), fm, stringWidth); int xPos = pm->width() + margin + 2; if(isCurrent() || isSelected()) { p->setPen(box->colorGroup().highlight().dark(115)); p->drawText(xPos + (QApplication::reverseLayout() ? -1 : 1), yPos + 1, visibleText); p->setPen(box->colorGroup().highlightedText()); } p->drawText(xPos, yPos, visibleText); } // end cut & paste (modulo pixmap centering) } else { // big icons -> draw text below icon int y = margin; const QPixmap *pm = pixmap(); if(!pm->isNull()) { int x = (w - pm->width()) / 2; x = QMAX(x, margin); p->drawPixmap(x, y, *pm); } if(!text().isEmpty()) { QFontMetrics fm = p->fontMetrics(); y += pm->height() + fm.height() - fm.descent(); int stringWidth = box->width() - (margin * 2); QString visibleText = KStringHandler::rPixelSqueeze(text(), fm, stringWidth); int x = (w - fm.width(visibleText)) / 2; x = QMAX(x, margin); if(isCurrent() || isSelected()) { p->setPen(box->colorGroup().highlight().dark(115)); p->drawText(x + (QApplication::reverseLayout() ? -1 : 1), y + 1, visibleText); p->setPen(box->colorGroup().highlightedText()); } p->drawText(x, y, visibleText); } } }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- void PerformanceInfoHud::draw(QPainter *painter, int widgetWidth, int widgetHeight) { /* //!!!! strArray.push_back(QString("Last pick time used: %1 ms").arg(m_lastPickTimeUsed*1000.0, 0, 'f', 3)); //!!!! m_useDisplayLists ? strArray.push_back("Display lists: ON") : strArray.push_back("Display lists: OFF"); */ // Draw the strings QFontMetrics metrics = painter->fontMetrics(); int border = qMax(4, metrics.leading()); painter->setRenderHint(QPainter::TextAntialiasing); int x = 10; int y = 10; int spacing = 5; std::vector<QRect> rects; int maxWidth = 0; int totalHeight = 0; int i; for (i = 0; i < m_drawStrings.size(); i++) { QString text = m_drawStrings[i]; QRect rect = metrics.boundingRect(0, 0, widgetWidth - 2*border, int(widgetHeight*0.125), Qt::AlignCenter | Qt::TextWordWrap, text); if (rect.width() > maxWidth) maxWidth = rect.width(); if (text.isEmpty()) { totalHeight += spacing; } else { totalHeight += rect.height(); } rects.push_back(rect); } QRect r1(x - border, y - border, maxWidth + 2*border, totalHeight + spacing*m_drawStrings.size()); painter->fillRect(r1, QColor(0, 0, 0, 127)); painter->setPen(Qt::white); painter->fillRect(r1, QColor(0, 0, 0, 127)); for (i = 0; i < m_drawStrings.size(); i++) { QString text = m_drawStrings[i]; QRect rect = rects[i]; if (text.isEmpty()) { y += spacing; } else { painter->drawText(x, y, rect.width(), rect.height(), Qt::AlignCenter | Qt::TextWordWrap, text); y += rect.height() + spacing; } } // Clear all contents m_drawStrings.clear(); }
void MandelbrotWidget::paintEvent(QPaintEvent * /* event */) { QPainter painter(this); painter.fillRect(rect(), Qt::black); if (instances[0].pixmap.isNull()) { painter.setPen(Qt::white); painter.drawText(rect(), Qt::AlignCenter, tr("Rendering initial image, please wait...")); return; } int textWidth, pointCur; QRectF screen; QString textStat; QRectF wholescreen = QRectF(0, 0, this->width(), this->height()); //Amir QFontMetrics metrics = painter.fontMetrics(); for (int rowCur=0; rowCur< rowMax; rowCur++) //Amir for (int colCur=0; colCur< colMax; colCur++) //Amir { pointCur = rowCur * colMax + colCur; screen = QRectF(colCur * this->width() / colMax, rowCur * this->height() / rowMax, this->width() / colMax - borderThreshold , this->height() / rowMax - borderThreshold); //Amir if (instances[pointCur].curScale == instances[pointCur].pixmapScale) { // painter.drawPixmap(pixmapOffset, pixmap); painter.drawPixmap(screen, instances[pointCur].pixmap, wholescreen); //Amir } else { // double scaleFactor = pixmapScale / curScale; // int newWidth = int(pixmap[pointCur].width() * scaleFactor); // int newHeight = int(pixmap[pointCur].height() * scaleFactor); // int newX = pixmapOffset.x() + (pixmap[pointCur].width() - newWidth) / 2; // int newY = pixmapOffset.y() + (pixmap[pointCur].height() - newHeight) / 2; painter.save(); // painter.translate(newX, newY); // painter.scale(scaleFactor, scaleFactor); // QRectF exposed = painter.matrix().inverted().mapRect(rect()).adjusted(-1, -1, 1, 1); painter.drawPixmap(screen, instances[pointCur].pixmap, wholescreen); //Amir //painter.drawPixmap(exposed, pixmap, exposed); painter.restore(); } if (instances[pointCur].renderingDone) { textStat = tr("Process Done"); textWidth = metrics.width(textStat); } else { textStat = tr("Process Pass ") + QString(instances[pointCur].renderingDoneLevel+0x30); textWidth = metrics.width(textStat); } painter.setPen(Qt::NoPen); painter.setBrush(QColor(0, 0, 0, 127)); painter.drawRect(screen.x(), screen.y() + screen.height() -20, 100, 20); painter.setPen(Qt::white); painter.drawText(screen.x() + 3, screen.y() + screen.height() - 5, textStat); } QString text = tr("Use mouse wheel or the '+' and '-' keys to zoom. " "Press and hold left mouse button to scroll."); // QFontMetrics metrics = painter.fontMetrics(); textWidth = metrics.width(text); painter.setPen(Qt::NoPen); painter.setBrush(QColor(0, 0, 0, 127)); painter.drawRect((width() - textWidth) / 2 - 5, 0, textWidth + 10, metrics.lineSpacing() + 5); painter.setPen(Qt::white); painter.drawText((width() - textWidth) / 2, metrics.leading() + metrics.ascent(), text); }
// public void kpMainWindow::pasteText (const QString &text, bool forceNewTextSelection, const QPoint &newTextSelectionTopLeft) { #if DEBUG_KP_MAIN_WINDOW && 1 kdDebug () << "kpMainWindow::pasteText(" << text << ",forceNewTextSelection=" << forceNewTextSelection << ",newTextSelectionTopLeft=" << newTextSelectionTopLeft << ")" << endl; #endif if (text.isEmpty ()) return; // sync: restoreOverrideCursor() in all exit paths QApplication::setOverrideCursor (Qt::waitCursor); if (toolHasBegunShape ()) tool ()->endShapeInternal (); QValueVector <QString> textLines (1, QString::null); for (int i = 0; i < (int) text.length (); i++) { if (text [i] == '\n') textLines.push_back (QString::null); else textLines [textLines.size () - 1].append (text [i]); } if (!forceNewTextSelection && m_document && m_document->selection () && m_document->selection ()->isText () && m_commandHistory && m_viewManager) { #if DEBUG_KP_MAIN_WINDOW && 1 kdDebug () << "\treusing existing Text Selection" << endl; #endif kpMacroCommand *macroCmd = new kpMacroCommand (i18n ("Text: Paste"), this); for (int i = 0; i < (int) textLines.size (); i++) { if (i > 0) { macroCmd->addCommand ( new kpToolTextEnterCommand ( QString::null/*uninteresting child of macroCmd*/, m_viewManager->textCursorRow (), m_viewManager->textCursorCol (), this)); } macroCmd->addCommand ( new kpToolTextInsertCommand ( QString::null/*uninteresting child of macroCmd*/, m_viewManager->textCursorRow (), m_viewManager->textCursorCol (), textLines [i], this)); } m_commandHistory->addCommand (macroCmd, false/*no exec*/); } else { #if DEBUG_KP_MAIN_WINDOW && 1 kdDebug () << "\tcreating Text Selection" << endl; #endif const kpTextStyle ts = textStyle (); const QFontMetrics fontMetrics = ts.fontMetrics (); int height = textLines.size () * fontMetrics.height (); if (textLines.size () >= 1) height += (textLines.size () - 1) * fontMetrics.leading (); int width = 0; for (QValueVector <QString>::const_iterator it = textLines.begin (); it != textLines.end (); it++) { const int w = fontMetrics.width (*it); if (w > width) width = w; } const int selWidth = QMAX (kpSelection::minimumWidthForTextStyle (ts), width + kpSelection::textBorderSize () * 2); const int selHeight = QMAX (kpSelection::minimumHeightForTextStyle (ts), height + kpSelection::textBorderSize () * 2); kpSelection sel (QRect (0, 0, selWidth, selHeight), textLines, ts); if (newTextSelectionTopLeft != KP_INVALID_POINT) { sel.moveTo (newTextSelectionTopLeft); paste (sel, true/*force topLeft*/); } else { paste (sel); } } QApplication::restoreOverrideCursor (); }
void MarkListTable::paintCell( QPainter *p, int row, int col) { QColorGroup cg = QApplication::palette()->normal(); if ( col == 0 ) { if ( items.at( row )->select() ) { //p->setBrush( selectColor ); //p->setPen( selectColor ); p->setBrush(cg.base()); p->setPen(cg.base()); } else { p->setBrush(cg.base()); p->setPen(cg.base()); } p->drawRect(0,0,cellWidth(0),cellHeight()); if( items.at( row )->mark() ) { int xOffset=6; int yOffset=3; if ( items.at( row )->select() ) p->setPen( cg.text() ); //p->setPen( selectTextColor ); else p->setPen( cg.text() ); p->drawLine( xOffset+4, yOffset, xOffset+4, yOffset+9 ); p->setPen( red ); p->drawLine( xOffset+3, yOffset+1, xOffset, yOffset+4 ); p->drawLine( xOffset+3, yOffset+1, xOffset+3, yOffset+4 ); p->drawLine( xOffset, yOffset+4, xOffset+3, yOffset+4 ); } else { int xOffset=4; int yOffset=5; p->setPen( cg.dark() ); p->setBrush( cg.dark() ); p->drawEllipse( xOffset+4, yOffset, 4, 4 ); //p->setPen( cg.mid() ); //p->setBrush( cg.mid() ); //p->drawEllipse( xOffset+5, yOffset+1, 2, 2 ); p->setPen( white ); p->drawPoint( xOffset+5, yOffset+1); } } /*if ( col == 1 ) { if ( items.at( row )->select() ) { p->setBrush(selectColor); p->setPen(selectColor); p->drawRect(0,0,cellWidth(1),cellHeight()); //qDrawShadePanel( p, 3, 2, cellHeight( 1 ) - 6, cellHeight(1)-4, // cg, FALSE, 1, &QBrush(colorGroup().light())); p->setBrush(white); p->setPen(black); p->drawRect(3,2,cellHeight( 1 ) - 7, cellHeight(1)-5); } else { p->setBrush(cg.base()); p->setPen(cg.base()); p->drawRect(0,0,cellWidth(1),cellHeight()); //qDrawShadePanel( p, 3, 2, cellHeight( 1 ) - 6, cellHeight(1)-4, // cg, FALSE,1 ); p->setBrush(white); p->setPen(black); p->drawRect(3,2,cellHeight( 1 ) - 7, cellHeight(1)-5); } //QFontMetrics fm = p->fontMetrics(); //int yPos; // vertical text position //if ( 10 < fm.height() ) // yPos = fm.ascent() + fm.leading()/2; //else // yPos = 5 - fm.height()/2 + fm.ascent(); //p->drawText( 4, yPos, items.at( row )->text() ); }*/ if ( col == 1 ) { if ( items.at( row )->select() ) { p->setBrush(selectColor); p->setPen(selectColor); } else { p->setBrush(cg.base()); p->setPen(cg.base()); } p->drawRect(0,0,cellWidth(2),cellHeight()); /* if ( items.at( row )->select() ) { QColorGroup cg = QApplication::palette()->normal(); qDrawShadePanel( p, 0, 0, cellWidth( 1 ) - 1, cellHeight(), cg, FALSE, 1, &QBrush(colorGroup().light())); }*/ if ( items.at( row )->select() ) p->setPen(selectTextColor); else p->setPen(cg.text()); QFontMetrics fm = p->fontMetrics(); int yPos; // vertical text position /*if ( 10 < fm.height() ) yPos = fm.ascent() + fm.leading()/2; else*/ yPos = cellHeight()-fm.leading()/2; yPos = fm.ascent() + fm.leading()/2+1; p->drawText( 4, yPos, items.at( row )->text() ); } }
void KDPluginsListBoxItem::paint( QPainter *p ) { QFontMetrics fm = p->fontMetrics(); p->drawText( 1, fm.ascent() + fm.leading()/2, text() ); }