int toResultViewMLine::realWidth(const QFontMetrics &fm, const toTreeWidget *top, int column, const QString &txt) const { if (!MaxColDisp) { MaxColDisp = toConfigurationSingle::Instance().maxColDisp(); Gridlines = toConfigurationSingle::Instance().displayGridlines(); } QString t = text(column); if (t.isNull()) t = txt; return std::min(TextWidth(fm, t), MaxColDisp) + top->itemMargin() * 2 - fm.minLeftBearing() - fm.minRightBearing() + 1; }
void FontRowTable::setRow(int r) { row = r; QFontMetrics fm = fontMetrics(); QString str; str.sprintf("mLB=%d mRB=%d mW=%d", fm.minLeftBearing(), fm.minRightBearing(), fm.maxWidth() ); emit fontInformation(str); update(); }
int toResultViewMLCheck::realWidth(const QFontMetrics &fm, const toTreeWidget *top, int column, const QString &txt) const { if (!MaxColDisp) { MaxColDisp = toConfigurationSingle::Instance().maxColDisp(); Gridlines = toConfigurationSingle::Instance().displayGridlines(); } QString t = text(column); if (t.isNull()) t = txt; int wx = top->itemMargin() * 2 - fm.minLeftBearing() - fm.minRightBearing() + 1; if (column == 0) wx += top->style()->pixelMetric(QStyle::PM_CheckListButtonSize) + 4 + top->itemMargin(); return std::min(TextWidth(fm, t), MaxColDisp) + wx; }
QRect PrimerLineEdit::placeHolderRect() const { QStyleOptionFrame panel; initStyleOption(&panel); QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); r.setX(r.x() + textMargins().left()); r.setY(r.y() + textMargins().top()); r.setRight(r.right() - textMargins().right()); r.setBottom(r.bottom() - textMargins().bottom()); QFontMetrics fm = fontMetrics(); int minLB = qMax(0, -fm.minLeftBearing()); int minRB = qMax(0, -fm.minRightBearing()); int vscroll = r.y() + (r.height() - fm.height() + 1) / 2; static const int horizontalMargin = 2; // QLineEditPrivate::horizontalMargin QRect lineRect(r.x() + horizontalMargin, vscroll, r.width() - 2*horizontalMargin, fm.height()); return lineRect.adjusted(minLB, 0, -minRB, 0); }
// -------------------------------------------------- void ctkSearchBox::paintEvent(QPaintEvent * event) { Q_D(ctkSearchBox); // Draw the line edit with text. // Text has already been shifted to the right (in resizeEvent()) to leave // space for the search icon. this->Superclass::paintEvent(event); QPainter p(this); QRect cRect = d->clearRect(); QRect sRect = d->showSearchIcon ? d->searchRect() : QRect(); #if QT_VERSION >= 0x040700 QRect r = rect(); QPalette pal = palette(); QStyleOptionFrameV2 panel; initStyleOption(&panel); r = this->style()->subElementRect(QStyle::SE_LineEditContents, &panel, this); r.setX(r.x() + this->textMargins().left()); r.setY(r.y() + this->textMargins().top()); r.setRight(r.right() - this->textMargins().right()); r.setBottom(r.bottom() - this->textMargins().bottom()); p.setClipRect(r); QFontMetrics fm = fontMetrics(); Qt::Alignment va = QStyle::visualAlignment(this->layoutDirection(), QFlag(this->alignment())); int vscroll = 0; const int verticalMargin = 1; const int horizontalMargin = 2; switch (va & Qt::AlignVertical_Mask) { case Qt::AlignBottom: vscroll = r.y() + r.height() - fm.height() - verticalMargin; break; case Qt::AlignTop: vscroll = r.y() + verticalMargin; break; default: //center vscroll = r.y() + (r.height() - fm.height() + 1) / 2; break; } QRect lineRect(r.x() + horizontalMargin, vscroll, r.width() - 2*horizontalMargin, fm.height()); int minLB = qMax(0, -fm.minLeftBearing()); if (this->text().isEmpty()) { if (!this->hasFocus() && !this->placeholderText().isEmpty()) { QColor col = pal.text().color(); col.setAlpha(128); QPen oldpen = p.pen(); p.setPen(col); lineRect.adjust(minLB, 0, 0, 0); QString elidedText = fm.elidedText(this->placeholderText(), Qt::ElideRight, lineRect.width()); p.drawText(lineRect, va, elidedText); p.setPen(oldpen); } } p.setClipRect(this->rect()); #endif // Draw clearIcon if (!d->hideClearIcon) { QPixmap closePixmap = d->clearIcon.pixmap(cRect.size(),this->isEnabled() ? QIcon::Normal : QIcon::Disabled); this->style()->drawItemPixmap(&p, cRect, Qt::AlignCenter, closePixmap); } // Draw searchIcon if (d->showSearchIcon) { QPixmap searchPixmap = d->searchIcon.pixmap(sRect.size(), this->isEnabled() ? QIcon::Normal : QIcon::Disabled); this->style()->drawItemPixmap(&p, sRect, Qt::AlignCenter, searchPixmap); } }
void FontRowTable::paintEvent( QPaintEvent* e ) { QFrame::paintEvent(e); QPainter p(this); p.setClipRegion(e->region()); QRect r = e->rect(); QFontMetrics fm = fontMetrics(); int ml = frameWidth()+margin() + 1 + QMAX(0,-fm.minLeftBearing()); int mt = frameWidth()+margin(); QSize cell((width()-15-ml)/16,(height()-15-mt)/16); if ( !cell.width() || !cell.height() ) return; int mini = r.left() / cell.width(); int maxi = (r.right()+cell.width()-1) / cell.width(); int minj = r.top() / cell.height(); int maxj = (r.bottom()+cell.height()-1) / cell.height(); int h = fm.height(); QColor body(255,255,192); QColor negative(255,192,192); QColor positive(192,192,255); QColor rnegative(255,128,128); QColor rpositive(128,128,255); for (int j = minj; j<=maxj; j++) { for (int i = mini; i<=maxi; i++) { if ( i < 16 && j < 16 ) { int x = i*cell.width(); int y = j*cell.height(); QChar ch = QChar(j*16+i,row); if ( fm.inFont(ch) ) { int w = fm.width(ch); int l = fm.leftBearing(ch); int r = fm.rightBearing(ch); x += ml; y += mt+h; p.fillRect(x,y,w,-h,body); if ( w ) { if ( l ) { p.fillRect(x+(l>0?0:l), y-h/2, abs(l),-h/2, l < 0 ? negative : positive); } if ( r ) { p.fillRect(x+w-(r>0?r:0),y+2, abs(r),-h/2, r < 0 ? rnegative : rpositive); } } QString s; s += ch; p.setPen(QPen(Qt::black)); p.drawText(x,y,s); } } } } }