void StringConfig::draw(QPainter* p) { QFontMetrics fm = p->fontMetrics(); for (int r=0; r<nrows; r++) { p->translate(0,fm.lineSpacing()); p->setPen(rowColor(r)); int tw=0; QString s; int i=0; for (; !(s=text(r,i)).isNull(); ++i) { int w = fm.width(s); tw += w; } bool spread = spreadRow(r);// && parent->width() > tw; int xw = spread ? (width2()-tw)/(i-1) : 3; int x = spread ? (width2()-tw-xw*(i-1))/2 : 2; i=0; for (; !(s=text(r,i)).isNull(); ++i) { int w = fm.width(s)+xw; if ( highlight(r,i) ) { p->fillRect(x-xw/2,1+fm.descent()-fm.lineSpacing(),w,fm.lineSpacing(),Qt::black); p->setPen(Qt::white); }else{ p->setPen(Qt::black); } p->drawText(x,-fm.descent()-1,s); x += w; } } }
/** * 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 Entity::paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { RoundedRectObject::paint(painter, option, widget); // Couper la region déssinée painter->setClipRect(boundingRect()); // Declaration de variables QFontMetrics fontMetrics = painter->fontMetrics(); const qreal padding = 5 ; qreal descent = padding + fontMetrics.descent(); qreal fontHeight = fontMetrics.height(); // Erire le nom de l'entité QString name = m_entity->name() ; qreal x = width() / 2 - padding / 2 - fontMetrics.width(name) / 2 ; qreal y = padding + fontHeight; painter->drawText(x, y, name); // Tracer un trait qreal lineY = fontHeight + 2 * padding + descent; painter->drawLine(0, lineY, width(), lineY); // Ecrire les proprietes QFont underlined = style()->font(); underlined.setUnderline(true); QList<Logic::Property*> pts = m_entity->properties(); for(int i=0; i<pts.size(); i++) { // sourligner les identifiants painter->setFont(pts[i]->isIdentifier()? underlined : style()->font()); qreal pHeight = lineY + (padding + fontHeight)*(i + 1); painter->drawText(padding, pHeight, pts[i]->name()); } }
/* Print the current entry */ void SBookWidget::menuFilePrint() { Entry *entry = selectedEntry(); if(entry){ QPrinter printer; if(printer.setup()){ int lines = entry->lines(); QPainter p(&printer); QFont font("Helvitica",12); p.setFont(font); QFontMetrics fm = p.fontMetrics(); int y = 0; int i = 0; for(i=0;i<lines;i++){ y += fm.ascent(); p.drawText(10,y,entry->getLine(i)); y += fm.descent(); } } } }
void StringConfig::updateItem(int r, int item) { QFontMetrics fm = parent->fontMetrics(); int y = r * fm.lineSpacing(); int tw=0; QString s; int i=0; for (; !(s=text(r,i)).isNull(); ++i) { int w = fm.width(s); tw += w; } bool spread = spreadRow(r) && width2() > tw; int xw = spread ? (width2()-tw)/(i-1) : 3; int x = spread ? (width2()-tw-xw*(i-1))/2 : 2; i=0; for (; !(s=text(r,i)).isNull(); ++i) { int w = fm.width(s)+xw; if ( i == item ) { parent->update(QRect(x-xw/2,y+1+fm.descent(),w,fm.lineSpacing())); return; } x += w; } }
void setXY( float * x , float * y , int alignMode , const QFontMetrics& metrics , const QString& str ) { if ( alignMode == VGDevice::kAlignBaseLeft ) return; float w = metrics.width( str ); float descent = metrics.descent(); float ascent = metrics.ascent(); //Vertical align if ( alignMode & VGDevice::kAlignTop ) { (*y) += ascent; } else if ( alignMode & VGDevice::kAlignBottom ) { (*y) -= descent; } else { // kAlignBase : do nothing, standard QPainter's behaviour. } // Horizontal align if( alignMode & VGDevice::kAlignRight ) (*x) -= w; else if( alignMode & VGDevice::kAlignCenter ) (*x) -= (w * 0.5); else { // kAlignLeft : do nothing, standard QPainter's behaviour. } }
void Painter::fontMetrics(float *ascent, float *descent) { QFontMetrics metrics = QFontMetrics(font()); // ascent and descent are distances, so we use lines QTransform rtform = transform().inverted(); *ascent = rtform.map(QLineF(0, 0, 0, metrics.ascent())).length(); *descent = rtform.map(QLineF(0, 0, 0, metrics.descent())).length(); }
void SBookWidget::printLabel(const QString &str) { labelPrinter->setPrinterName("Dymo LabelWriter Turbo"); QStringList list = QStringList::split(QChar('\n'), str); QPainter p(labelPrinter); QFont font("Helvitica",12); p.rotate(-90); p.setFont(font); QFontMetrics fm = p.fontMetrics(); p.drawText(-330,20,"Simson Garfinkel & Beth Rosenberg"); p.drawText(-330,40,"305 Walden St., #2"); p.drawText(-330,60,"Cambridge, MA 02138"); int x = -250; int y = 100; unsigned int i = 0; for(i=0;i<list.count();i++){ QString line = (*list.at(i)); y += fm.ascent(); p.drawText(x,y,line); y += fm.descent(); } }
void MapWidget::drawMarker(const MapMarker &marker, QPainter &painter, const QPointF &markerPosition, const QPointF &rectPosition) { QRectF markerRect = getMarkerRect(marker, rectPosition); QColor bgColor = getMarkerTextBackgroundColor(); painter.setBrush(QBrush(bgColor)); // drawing the line connector painter.setPen(bgColor); painter.setClipping(true); painter.setClipRegion(QRegion(rect()).subtracted(markerRect.toRect())); painter.drawLine(markerRect.center(), markerPosition); // drawing the transparent background painter.setClipping(false); painter.setPen(Qt::NoPen); painter.drawRect(markerRect); // drawing the player marker const static qreal markerSize = 1.6; painter.setBrush(getMarkerColor()); painter.drawEllipse(markerPosition, markerSize, markerSize); qreal hOffset = rectPosition.x() + TEXT_MARGIM; // left margin // draw the player name text QString playerName = marker.getPlayerName(); painter.setFont(userFont); QFontMetrics metrics = painter.fontMetrics(); qreal playerNameWidth = metrics.width(playerName); painter.setPen(getMarkerTextColor()); qreal textY = rectPosition.y() + TEXT_MARGIM + metrics.descent()/2.0; painter.drawText(hOffset, textY, playerName); hOffset += playerNameWidth + TEXT_MARGIM * 3; // draw the player country name painter.setFont(countryFont); metrics = painter.fontMetrics(); QColor countryNameColor(getMarkerTextColor()); countryNameColor.setAlpha(180); // country name is drawed using some alpha painter.setPen(countryNameColor); QString countryName = marker.getCountryName(); painter.drawText(hOffset, textY, countryName); hOffset += metrics.width(countryName); painter.setFont(userFont); //restore the normal font metrics = painter.fontMetrics(); // draw the player country flag const QImage &image = marker.getFlag(); qreal imageX = hOffset + TEXT_MARGIM; qreal imageY = rectPosition.y() - image.height()/2.0; painter.drawImage(QPointF(imageX, imageY), image); }
void PickboardConfig::updateRows(int from, int to) { if ( from != to ) { // (all) parent->update(); } else { QFontMetrics fm = parent->fontMetrics(); parent->update(QRect(0,1+fm.descent() + from * fm.lineSpacing(), width2(), fm.lineSpacing())); } }
void QGroupBox::paintEvent( QPaintEvent *event ) { QPainter paint( this ); if ( lenvisible && !isCheckable() ) { // draw title QFontMetrics fm = paint.fontMetrics(); int h = fm.height(); int tw = fm.width( str, lenvisible ) + fm.width(QChar(' ')); int x; int marg = bFlat ? 0 : 8; if ( align & AlignHCenter ) // center alignment x = frameRect().width()/2 - tw/2; else if ( align & AlignRight ) // right alignment x = frameRect().width() - tw - marg; else if ( align & AlignLeft ) // left alignment x = marg; else { // auto align if( QApplication::reverseLayout() ) x = frameRect().width() - tw - marg; else x = marg; } QRect r( x, 0, tw, h ); int va = style().styleHint(QStyle::SH_GroupBox_TextLabelVerticalAlignment, this); if(va & AlignTop) r.moveBy(0, fm.descent()); QColor pen( (QRgb) style().styleHint(QStyle::SH_GroupBox_TextLabelColor, this ) ); if (!style().styleHint(QStyle::SH_UnderlineAccelerator, this)) va |= NoAccel; style().drawItem( &paint, r, ShowPrefix | AlignHCenter | va, colorGroup(), isEnabled(), 0, str, -1, ownPalette() ? 0 : &pen ); paint.setClipRegion( event->region().subtract( r ) ); // clip everything but title #ifndef QT_NO_CHECKBOX } else if ( d->checkbox ) { QRect cbClip = d->checkbox->geometry(); QFontMetrics fm = paint.fontMetrics(); cbClip.setX( cbClip.x() - fm.width(QChar(' ')) ); cbClip.setWidth( cbClip.width() + fm.width(QChar(' ')) ); paint.setClipRegion( event->region().subtract( cbClip ) ); #endif } if ( bFlat ) { QRect fr = frameRect(); QPoint p1( fr.x(), fr.y() + 1 ); QPoint p2( fr.x() + fr.width(), p1.y() ); // ### This should probably be a style primitive. qDrawShadeLine( &paint, p1, p2, colorGroup(), TRUE, lineWidth(), midLineWidth() ); } else { drawFrame(&paint); } drawContents( &paint ); // draw the contents }
WindowHeader(QWidget* parent = NULL): QWidget(parent), m_text("H.265 Encoder"), m_logo(":/Logo") { setFixedHeight(76); const int kLabelBaseline = 48; const int kLabelXPos = 29; setFont(CommonGui::font(CommonGui::kSentinelLight)); QFontMetrics qf = fontMetrics(); int labelWidth = qf.width(m_text) + 4; // Add a few pixels for safety int labelHeight = qf.height(); int labelYPos = kLabelBaseline + qf.descent() - labelHeight; m_textRect = QRect(kLabelXPos, labelYPos, labelWidth, labelHeight); }
RKInput::RKInput (const QDomElement &element, RKComponent *parent_component, QWidget *parent_widget) : RKComponent (parent_component, parent_widget) { RK_TRACE (PLUGIN); textedit = 0; lineedit = 0; // get xml-helper XMLHelper *xml = parent_component->xmlHelper (); // create and add property addChild ("text", text = new RKComponentPropertyBase (this, false)); connect (text, SIGNAL (valueChanged(RKComponentPropertyBase*)), this, SLOT (textChanged(RKComponentPropertyBase*))); setRequired (xml->getBoolAttribute (element, "required", false, DL_INFO)); connect (requirednessProperty (), SIGNAL (valueChanged(RKComponentPropertyBase*)), this, SLOT (requirednessChanged(RKComponentPropertyBase*))); // do all the layouting QVBoxLayout *vbox = new QVBoxLayout (this); vbox->setContentsMargins (0, 0, 0, 0); label_string = xml->i18nStringAttribute (element, "label", i18n ("Enter text"), DL_INFO); if (!label_string.isEmpty ()) { QLabel *label = new QLabel (label_string, this); vbox->addWidget (label); } int size = xml->getMultiChoiceAttribute (element, "size", "small;medium;large", 1, DL_INFO); if (size == 2) { textedit = new QTextEdit (this); QFontMetrics fm = QFontMetrics (textedit->currentFont ()); int lheight = fm.lineSpacing (); int margin = fm.descent () + 2; textedit->setMinimumSize (250, lheight * 4 + margin); vbox->addWidget (textedit); connect (textedit, SIGNAL (textChanged()), SLOT (textChanged())); } else { lineedit = new QLineEdit (this); vbox->addWidget (lineedit); connect (lineedit, SIGNAL (textChanged(QString)), SLOT (textChanged(QString))); } vbox->addStretch (1); // to keep the label attached // initialize updating = false; // DO NOT replace "" with QString (), here! it is important, that this is actually an empty string, not a null string. text->setValue (xml->getStringAttribute (element, "initial", "", DL_INFO)); }
void drawFonts( QPainter *p ) { static const char *fonts[] = { "Helvetica", "Courier", "Times", 0 }; static int sizes[] = { 10, 12, 18, 24, 36, 0 }; int f = 0; int y = 0; while ( fonts[f] ) { int s = 0; while ( sizes[s] ) { QFont font( fonts[f], sizes[s] ); p->setFont( font ); QFontMetrics fm = p->fontMetrics(); y += fm.ascent(); p->drawText( 10, y, "Quartz Glyph Job Vex'd Cwm Finks" ); y += fm.descent(); s++; } f++; } }
/** * @brief 绘制label上显示的文字 * @param [in] 描绘事件 */ void Label::paintEvent(QPaintEvent *ev) { QLabel::paintEvent(ev); if (!customText.isEmpty()) { QPainter p(this); QFontMetrics fm = p.fontMetrics(); QPoint offset; if (flags == Qt::AlignRight) { offset.setX(19); offset.setY(0); } QPoint pos((size().width() - fm.width(customText)) / 2 + offset.x(), (size().height() - (fm.ascent() + fm.descent())) / 2 + fm.ascent() + offset.y()); p.drawText(pos, customText); } }
void MiniView::paintEvent(QPaintEvent * event) { QFrame::paintEvent(event); QPainter painter(this); if (m_graphicsView && m_graphicsView->scene()) { //DebugDialog::debug(QString("w:%1 h:%2").arg(width()).arg(height())); FGraphicsScene * scene = qobject_cast<FGraphicsScene *>(m_graphicsView->scene()); painter.fillRect(0, 0, width(), height(), scene->backgroundBrush()); QRectF sr = scene->sceneRect(); //DebugDialog::debug(QString("sr:%1 %2 %3 %4").arg(sr.left()).arg(sr.top()).arg(sr.width()).arg(sr.height())); int cw = width(); int ch = qRound(sr.height() * cw / sr.width()); if (ch > height()) { ch = height(); cw = qRound(sr.width() * ch / sr.height()); } m_sceneRect.setRect((width() - cw) / 2, (height() - ch) / 2, cw, ch); //DebugDialog::debug(QString("m_sceneRect:%1 %2 %3 %4").arg(m_sceneRect.left()).arg(m_sceneRect.top()).arg(m_sceneRect.width()).arg(m_sceneRect.height())); scene->setDisplayHandles(false); scene->render(&painter, m_sceneRect, sr, Qt::KeepAspectRatio); scene->setDisplayHandles(true); } QPen pen(m_titleColor, 1); painter.setPen(pen); QFont font; font.setFamily(FontFamily); font.setWeight(m_titleWeight); font.setPixelSize(FontPixelSize); painter.setFont(font); QFontMetrics metrics = painter.fontMetrics(); m_lastHeight = metrics.descent() + metrics.ascent(); int h = 0; // metrics.descent(); int y = height() - h - 2; QRect br = metrics.boundingRect(m_title); int x = ((width() - br.width()) / 2); painter.drawText(QPointF(x, y), m_title); }
void Hello::paintEvent( QPaintEvent * ) { static int sin_tbl[16] = { 0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38}; if ( t.isEmpty() ) return; // 1: Compute some sizes, positions etc. QFontMetrics fm = fontMetrics(); int w = fm.width(t) + 20; int h = fm.height() * 2; int pmx = width()/2 - w/2; int pmy = height()/2 - h/2; // 2: Create the pixmap and fill it with the widget's background QPixmap pm( w, h ); pm.fill( this, pmx, pmy ); // 3: Paint the pixmap. Cool wave effect QPainter p; int x = 10; int y = h/2 + fm.descent(); int i = 0; p.begin( &pm ); p.setFont( font() ); while ( !t[i].isNull() ) { int i16 = (b+i) & 15; p.setPen( QColor((15-i16)*16,255,255,QColor::Hsv) ); p.drawText( x, y-sin_tbl[i16]*h/800, t.mid(i,1), 1 ); x += fm.width( t[i] ); i++; } p.end(); // 4: Copy the pixmap to the Hello widget bitBlt( this, pmx, pmy, &pm ); }
void Association::paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { RoundedRectObject::paint(painter, option, widget); // Couper la region déssinée painter->setClipRect(boundingRect()); // Declaration de variables QFontMetrics fontMetrics = painter->fontMetrics(); const qreal padding = 5 ; qreal descent = padding + fontMetrics.descent(); qreal fontHeight = fontMetrics.height(); // Erire le nom de l'entité QString name = m_association->name() ; qreal x = width() / 2 - padding / 2 - fontMetrics.width(name) / 2 ; qreal y = padding + fontHeight; painter->drawText(x, y, name); // Tracer un trait if(!m_association->properties().empty()) { qreal lineY = fontHeight + 2 * padding + descent; painter->drawLine(0, lineY, width(), lineY); // Ecrire les entité QList<Logic::Property*> properties = m_association->properties(); for(int i=0, size=properties.size(); i<size; i++) { qreal pHeight = lineY + (padding + fontHeight)*(i + 1); painter->drawText(padding, pHeight, properties[i]->name()); } } }
void MainWindow::btnExportClicked() { QList<QChar> charset; if (chkLowerAZ->isChecked()) for (char c = 'a'; c <= 'z'; c++) charset.append(c); if (chkUpperAZ->isChecked()) for (char c = 'A'; c <= 'Z'; c++) charset.append(c); if (chkNumbers->isChecked()) for (char c = '0'; c <= '9'; c++) charset.append(c); QString str = ldtCharacters->text(); for (QString::const_iterator itr(str.begin()); itr != str.end(); itr++) if (!charset.contains(*itr)) charset.append(*itr); qSort(charset); // Render characters QFont font = fontSelector->currentFont(); font.setPixelSize(font.pointSize()); QFontMetrics metrics = QFontMetrics(font); QTextCodec *codec = QTextCodec::codecForName("utf-8"); QString glyphs; QString fontName = QString("font_%1%2") .arg(font.family().toLower()) .arg(font.pixelSize()) .replace(' ', '_'); QString fontstruct = QString( "const struct glib_font %1 = {\n" " .charcount = %2,\n" " .size = %3,\n" " .glyphs = {\n ") .arg(fontName) .arg(charset.size()) .arg(font.pixelSize()); QListIterator<QChar> itr(charset); while (itr.hasNext()) { QChar c = itr.next(); if (c == ' ') { // Add space character fontstruct += QString("{.utf8 = 0x20, .x = %1, .y = 0, .bitmap = NULL}") .arg(metrics.width(' ')); } else { QRect boundingRect = metrics.boundingRect(c); QImage image = QImage(boundingRect.width(), boundingRect.height(), QImage::Format_Mono); image.fill(Qt::color1); QPainter p; p.begin(&image); p.setFont(font); p.setWindow(metrics.boundingRect(c)); p.drawText(0, 0, c); p.end(); QString utf8 = codec->fromUnicode(c).toHex(); glyphs += renderGlyph(utf8, image); fontstruct += QString("{.utf8 = 0x%1, .x = %2, .y = %3, .bitmap = &glyph_%1}") .arg(utf8) .arg(boundingRect.x() + 1) .arg(boundingRect.y() - metrics.descent() + 1); // +1 for the base line } if (itr.hasNext()) fontstruct += ",\n "; } fontstruct += "\n }\n};\n"; glyphs = "#include <liblcd/glib.h>\n\n" + glyphs + "\n" + fontstruct; QString filename = QFileDialog::getSaveFileName(this, tr("Save Font"), fontName + ".c", tr("Source Files (*.c *.cpp)")); if (!filename.isEmpty()) { if (!(filename.endsWith(".c") || filename.endsWith(".cpp"))) filename += ".c"; QFile file(filename); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) return; QTextStream out(&file); out << glyphs; file.close(); } }
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 FavoriteWidget::resizeEvent(QResizeEvent* e) { // ignore text descent when vertically centering QFontMetrics fontMetrics = QFontMetrics(this->font()); rect_ = this->rect(); rect_.setBottom(rect_.bottom() - fontMetrics.descent()); }
void QLineEdit::paintEvent( QPaintEvent *e ) { if ( !d->pm || d->pmDirty ) { if ( !d->pm ) d->pm = new QPixmap( size() ); QPainter p( d->pm, this ); QColorGroup g = colorGroup(); QColor bg = isEnabled() ? g.base() : g.background(); QFontMetrics fm = fontMetrics(); int markBegin = minMark(); int markEnd = maxMark(); int margin = frame() ? 2 : 0; if ( frame() ) { QBrush fill( bg ); qDrawWinPanel( &p, 0, 0, width(), height(), g, TRUE, &fill ); } else { p.fillRect( 0, 0, width(), height(), bg ); } QString displayText; switch( echoMode() ) { case Normal: displayText = tbuf.mid( offset, tbuf.length() ); break; case NoEcho: displayText = ""; break; case Password: displayText.fill( '*', tbuf.length() - offset ); break; } int ypos = height() - margin - fm.descent() - 1 - (height() - 2*margin - fm.height())/2; if ( !displayText.isEmpty() ) { int charsVisible = lastCharVisible() - offset; if ( displayText[ charsVisible ] != '\0' ) charsVisible++; int mark1,mark2; if ( markBegin > offset ) { if ( markBegin < offset + charsVisible ) mark1 = markBegin - offset; else mark1 = charsVisible; } else { mark1 = 0; } if ( markEnd > offset ) { if ( markEnd < offset + charsVisible ) mark2 = markEnd - offset; else mark2 = charsVisible; } else { mark2 = 0; } // display code comes here - a bit yucky but it works if ( mark1 != mark2 ) { QString marked( displayText.mid( mark1, mark2 - mark1 ) ); int xpos1 = margin + 2 + fm.width( displayText, mark1 ); int xpos2 = xpos1 + fm.width( marked ) - 1; p.fillRect( xpos1, ypos - fm.ascent(), xpos2 - xpos1, fm.height(), style() == WindowsStyle ? QApplication::winStyleHighlightColor() : g.text() ); p.setPen( style() == WindowsStyle ? white : g.base() ); p.drawText( xpos1, ypos, marked ); } p.setPen( g.text() ); if ( mark1 != 0 ) p.drawText( margin + 2, ypos, displayText, mark1 ); if ( mark2 != charsVisible ) { QString rest( displayText.mid( mark2, charsVisible - mark2 ) ); p.drawText( margin + 2 + fm.width( displayText.left( mark2) ), ypos, rest ); } } p.setPen( g.foreground() ); int curXPos = margin + 2; if ( echoMode() != NoEcho ) curXPos += offset > cursorPos ? -1 : // ?: for scrolling case fm.width( displayText, cursorPos - offset ) - 1; int curYPos = ypos - fm.ascent(); d->cursorRepaintRect.setRect( curXPos-2, curYPos, 5, fm.height() ); d->pmDirty = FALSE; } bitBlt( this, e->rect().topLeft(), d->pm, e->rect() ); if ( hasFocus() ) { if ( cursorOn && d->cursorRepaintRect.intersects( e->rect() ) ) { QPainter p( this ); int curYTop = d->cursorRepaintRect.y(); int curYBot = d->cursorRepaintRect.bottom(); int curXPos = d->cursorRepaintRect.x() + 2; p.drawLine( curXPos, curYTop, curXPos, curYBot ); if ( style() != WindowsStyle ) { p.drawLine( curXPos - 2, curYTop, curXPos + 2, curYTop ); p.drawLine( curXPos - 2, curYBot, curXPos + 2, curYBot ); } } } else { delete d->pm; d->pm = 0; } }
void kpok::paintEvent( QPaintEvent *) { /* This was shamelessy stolen from the "hello world" example coming with Qt Thanks to the Qt-Guys for doing such a cool example 8-) */ QString t; if (!waveActive) { return; } t = wonLabel->text(); static int sin_tbl[16] = { 0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38}; if ( t.isEmpty() ) return; QFont wonFont("Helvetica", 18, QFont::Bold); QFontMetrics fm = QFontMetrics(wonFont); int w = fm.width(t) + 20; int h = fm.height() * 2; int pmx = this->width() / 2 - w / 2; int pmy = wonLabelVDist - h / 4; QPixmap pm( w, h ); pm.fill( this, pmx, pmy ); if (fCount == -1) { /* clear area */ bitBlt( this, pmx, pmy, &pm ); return; } QPainter p; int x = 10; int y = h/2 + fm.descent(); int i = 0; p.begin( &pm ); p.setFont( wonFont ); p.setPen( QColor(0,0,0) ); while ( t[i] ) { int i16 = (fCount+i) & 15; p.drawText( x, y-sin_tbl[i16]*h/800, &t[i], 1 ); x += fm.width( t[i] ); i++; } p.end(); // 4: Copy the pixmap to the Hello widget bitBlt( this, pmx, pmy, &pm ); }
void kpok::paintEvent( QPaintEvent *) { /* NOTE: This was shamelessy stolen from the "hello world" example * coming with Qt Thanks to the Qt-Guys for doing such a cool * example 8-) */ if (!waveActive) { return; } QString txt = wonLabel->text(); wonLabel->hide(); static int sin_tbl[16] = { 0, 38, 71, 92, 100, 92, 71, 38, 0, -38, -71, -92, -100, -92, -71, -38}; if ( txt.isEmpty() ) { return; } QFont wonFont; wonFont.setPointSize(18); wonFont.setBold(true); QFontMetrics fm = QFontMetrics(wonFont); int w = fm.width(txt) + 20; int h = fm.height() * 2; while (w > mWonWidget->width() && wonFont.pointSize() > 6) {// > 6 for emergency abort... wonFont.setPointSize(wonFont.pointSize() - 1); fm = QFontMetrics(wonFont); w = fm.width(txt) + 20; h = fm.height() * 2; } int pmx = mWonWidget->width() / 2 - w / 2; int pmy = 0; // int pmy = (playerBox[0]->x() + playerBox[0]->height() + 10) - h / 4; QPixmap pm( w, h ); pm.fill( mWonWidget, pmx, pmy ); if (fCount == -1) { /* clear area */ bitBlt( mWonWidget, pmx, pmy, &pm ); return; } QPainter p; int x = 10; int y = h/2 + fm.descent(); unsigned int i = 0; p.begin( &pm ); p.setFont( wonFont ); p.setPen( QColor(0,0,0) ); while ( i < txt.length() ) { int i16 = (fCount+i) & 15; p.drawText( x, y-sin_tbl[i16]*h/800, QString(txt[i]), 1 ); x += fm.width( txt[i] ); i++; } p.end(); // 4: Copy the pixmap to the Hello widget bitBlt( mWonWidget, pmx, pmy, &pm ); }
void Avatar::renderDisplayName() { if (_displayName.isEmpty() || _displayNameAlpha == 0.0f) { return; } glDisable(GL_LIGHTING); glPushMatrix(); glm::vec3 textPosition = getPosition() + getBodyUpDirection() * ((getSkeletonHeight() + getHeadHeight()) / 1.5f); glTranslatef(textPosition.x, textPosition.y, textPosition.z); // we need "always facing camera": we must remove the camera rotation from the stack glm::quat rotation = Application::getInstance()->getCamera()->getRotation(); glm::vec3 axis = glm::axis(rotation); glRotatef(glm::angle(rotation), axis.x, axis.y, axis.z); // We need to compute the scale factor such as the text remains with fixed size respect to window coordinates // We project a unit vector and check the difference in screen coordinates, to check which is the // correction scale needed // save the matrices for later scale correction factor glm::dmat4 modelViewMatrix; glm::dmat4 projectionMatrix; GLint viewportMatrix[4]; Application::getInstance()->getModelViewMatrix(&modelViewMatrix); Application::getInstance()->getProjectionMatrix(&projectionMatrix); glGetIntegerv(GL_VIEWPORT, viewportMatrix); GLdouble result0[3], result1[3]; glm::dvec3 upVector(modelViewMatrix[1]); glm::dvec3 testPoint0 = glm::dvec3(textPosition); glm::dvec3 testPoint1 = glm::dvec3(textPosition) + upVector; bool success; success = gluProject(testPoint0.x, testPoint0.y, testPoint0.z, (GLdouble*)&modelViewMatrix, (GLdouble*)&projectionMatrix, viewportMatrix, &result0[0], &result0[1], &result0[2]); success = success && gluProject(testPoint1.x, testPoint1.y, testPoint1.z, (GLdouble*)&modelViewMatrix, (GLdouble*)&projectionMatrix, viewportMatrix, &result1[0], &result1[1], &result1[2]); if (success) { double textWindowHeight = abs(result1[1] - result0[1]); float scaleFactor = (textWindowHeight > EPSILON) ? 1.0f / textWindowHeight : 1.0f; glScalef(scaleFactor, scaleFactor, 1.0); // draw a gray background QFontMetrics metrics = textRenderer(DISPLAYNAME)->metrics(); int bottom = -metrics.descent(), top = bottom + metrics.height(); int left = -_displayNameWidth/2, right = _displayNameWidth/2; const int border = 5; bottom -= border; left -= border; top += border; right += border; // We are drawing coplanar textures with depth: need the polygon offset glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.0f, 1.0f); glColor4f(0.2f, 0.2f, 0.2f, _displayNameAlpha); glBegin(GL_QUADS); glVertex2f(left, bottom); glVertex2f(right, bottom); glVertex2f(right, top); glVertex2f(left, top); glEnd(); glScalef(1.0f, -1.0f, 1.0f); // TextRenderer::draw paints the text upside down in y axis glColor4f(0.93f, 0.93f, 0.93f, _displayNameAlpha); QByteArray ba = _displayName.toLocal8Bit(); const char* text = ba.data(); glDisable(GL_POLYGON_OFFSET_FILL); textRenderer(DISPLAYNAME)->draw(-_displayNameWidth / 2, 0, text); } glPopMatrix(); glEnable(GL_LIGHTING); }
void FGWCondition::paintEvent(QPaintEvent *) { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); QFontMetrics fm = painter.fontMetrics(); if (fm.ascent() + fm.descent() != m_fontHeight) { m_fontHeight = fm.ascent() + fm.descent(); updateTransforms(); } // Y-Axis label QTransform transform; transform.rotate(270); transform.translate(-(height() + fm.width(m_yAxisLabel)) / 2, fm.ascent()); painter.setTransform(transform); painter.drawText(QPointF(0, 0), m_yAxisLabel); // X-Axis label transform.reset(); painter.setTransform(transform); painter.drawText(QPointF((width() - fm.width(m_xAxisLabel)) / 2, height() - fm.descent()), m_xAxisLabel); // The actual graph if (m_forceCondition) { QPointF startPos(-1.0, 0.0); QPointF startViewPos = m_model2View.map(startPos); QPointF endPos(1.0, 0.0); QPointF endViewPos = m_model2View.map(endPos); double negativeSaturation = m_forceCondition->negativeSaturation(); if (m_forceCondition->negativeCoefficient() < 0.0) { negativeSaturation = -negativeSaturation; } double positiveSaturation = m_forceCondition->positiveSaturation(); if (m_forceCondition->positiveCoefficient() < 0.0) { positiveSaturation = -positiveSaturation; } double negativeDeadBandValue = CLIP11(m_forceCondition->offset() - m_forceCondition->deadBand()); double positiveDeadBandValue = CLIP11(m_forceCondition->offset() + m_forceCondition->deadBand()); double negCoeff = m_forceCondition->negativeCoefficient(); double negCoeffValue = 1000.0; if (0.001 < fabs(negCoeff)) { negCoeffValue = (1.0 / fabs(negCoeff)) - 1.0; } negCoeffValue *= m_forceCondition->negativeSaturation(); double negativeSaturationValue = negativeDeadBandValue - negCoeffValue; if (negativeSaturationValue < -1.0) { double negCoeffVisible = negativeDeadBandValue + 1.0; double ratio = negCoeffVisible / negCoeffValue; negativeSaturation *= ratio; negativeSaturationValue = -1.0; } double posCoeff = m_forceCondition->positiveCoefficient(); double posCoeffValue = 1000.0; if (0.001 < fabs(posCoeff)) { posCoeffValue = (1.0 / fabs(posCoeff)) - 1.0; } posCoeffValue *= m_forceCondition->positiveSaturation(); double positiveSaturationValue = positiveDeadBandValue + posCoeffValue; if (1.0 < positiveSaturationValue) { double posCoeffVisible = 1.0 - positiveDeadBandValue; double ratio = posCoeffVisible / posCoeffValue; positiveSaturation *= ratio; positiveSaturationValue = 1.0; } QPointF offsetPos(m_forceCondition->offset(), 0.0); QPointF offsetViewPos = m_model2View.map(offsetPos); QPointF negativeSaturationPos(-1.0, negativeSaturation); QPointF negativeSaturationViewPos = m_model2View.map(negativeSaturationPos); QPointF negativeCoefficientPos(negativeSaturationValue, negativeSaturation); QPointF negativeCoefficientViewPos = m_model2View.map(negativeCoefficientPos); QPointF negativeDeadBandPos(negativeDeadBandValue, 0.0); QPointF negativeDeadBandViewPos = m_model2View.map(negativeDeadBandPos); QPointF positiveDeadBandPos(positiveDeadBandValue, 0.0); QPointF positiveDeadBandViewPos = m_model2View.map(positiveDeadBandPos); QPointF positiveCoefficientPos(positiveSaturationValue, positiveSaturation); QPointF positiveCoefficientViewPos = m_model2View.map(positiveCoefficientPos); QPointF positiveSaturationPos(1.0, positiveSaturation); QPointF positiveSaturationViewPos = m_model2View.map(positiveSaturationPos); painter.setPen(Qt::black); painter.setBrush(Qt::green); QPolygon envelope; envelope << startViewPos.toPoint() << negativeSaturationViewPos.toPoint() << negativeCoefficientViewPos.toPoint() << negativeDeadBandViewPos.toPoint() << positiveDeadBandViewPos.toPoint() << positiveCoefficientViewPos.toPoint() << positiveSaturationViewPos.toPoint() << endViewPos.toPoint(); painter.drawPolygon(envelope); painter.setBrush(QBrush(Qt::red)); painter.drawEllipse(negativeCoefficientViewPos, m_handleRadius, m_handleRadius); painter.drawEllipse(negativeDeadBandViewPos, m_handleRadius, m_handleRadius); painter.drawEllipse(positiveDeadBandViewPos, m_handleRadius, m_handleRadius); painter.drawEllipse(positiveCoefficientViewPos, m_handleRadius, m_handleRadius); if (!m_dragHandler->isDragging()) { double negSatHalfWidth = (negativeCoefficientViewPos.x() - startViewPos.x()) / 2.0; m_dragHandler->setHitAreaView(NegativeSaturation, QPointF(startViewPos.x() + negSatHalfWidth, negativeSaturationViewPos.y()), negSatHalfWidth, m_handleRadius); m_dragHandler->setHitAreaView(NegativeCoefficient, negativeCoefficientViewPos); m_dragHandler->setHitAreaView(NegativeDeadBand, negativeDeadBandViewPos); double offsetHalfWidth = (positiveDeadBandViewPos.x() - negativeDeadBandViewPos.x()) / 2.0; m_dragHandler->setHitAreaView(Offset, offsetViewPos, offsetHalfWidth, m_handleRadius); m_dragHandler->setHitAreaView(PositiveDeadBand, positiveDeadBandViewPos); m_dragHandler->setHitAreaView(PositiveCoefficient, positiveCoefficientViewPos); double posSatHalfWidth = (endViewPos.x() - positiveCoefficientViewPos.x()) / 2.0; m_dragHandler->setHitAreaView(PositiveSaturation, QPointF(endViewPos.x() - posSatHalfWidth, positiveSaturationViewPos.y()), posSatHalfWidth, m_handleRadius); } } }