void CalPrintJournal::print( QPainter &p, int width, int height ) { int x=0, y=0; Journal::List journals( mCalendar->journals() ); if ( mUseDateRange ) { Journal::List allJournals = journals; journals.clear(); Journal::List::Iterator it = allJournals.begin(); for ( ; it != allJournals.end(); ++it ) { QDate dt = (*it)->dtStart().date(); if ( mFromDate <= dt && dt <= mToDate ) { journals.append( *it ); } } } drawHeader( p, i18n( "Journal entries" ), QDate(), QDate(), QRect( 0, 0, width, headerHeight() ) ); y = headerHeight() + 15; Journal::List::Iterator it = journals.begin(); for ( ; it != journals.end(); ++it ) { drawJournal( *it, p, x, y, width, height ); } }
QSize RegSexyDisplay::minimumSizeHint() const { /* cache computation because it's expensive */ if(m_size.isValid()) return m_size; /* width: display 32 columns + 33 vertical separators */ m_size.setWidth(32 * columnWidth() + 33 * separatorSize()); /* height: one separator + two digits + one separator + margin + separator * + names + separator */ m_size.setHeight(4 * separatorSize() + headerHeight() + gapHeight() + maxContentHeight()); return m_size; }
void ZLTextView::paint() { context().clear(backgroundColor()); myTextAreaController.area().setOffsets( textArea().isRtl() ? rightMargin() : leftMargin(), topMargin() + headerHeight() ); preparePaintInfo(); if (textArea().isEmpty()) { return; } myTextAreaController.area().paint(); shared_ptr<ZLTextPositionIndicatorInfo> indicatorInfo = this->indicatorInfo(); if (!indicatorInfo.isNull()) { switch (indicatorInfo->type()) { default: break; case ZLTextPositionIndicatorInfo::PAGE_FOOTER: positionIndicator()->draw(); break; case ZLTextPositionIndicatorInfo::PAGE_HEADER: paintHeader(); break; } } if (myDoUpdateScrollbar && !indicatorInfo.isNull()) { myDoUpdateScrollbar = false; const std::size_t full = sizeOfTextBeforeParagraph(endTextIndex()); const std::size_t from = sizeOfTextBeforeCursor(textArea().startCursor()); const std::size_t to = sizeOfTextBeforeCursor(textArea().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(); }
bool KatePrinter::print (KateDocument *doc) { QPrinter printer; readSettings(printer); // docname is now always there, including the right Untitled name printer.setDocName(doc->documentName()); KatePrintTextSettings *kpts = new KatePrintTextSettings; KatePrintHeaderFooter *kphf = new KatePrintHeaderFooter; KatePrintLayout *kpl = new KatePrintLayout; QList<QWidget*> tabs; tabs << kpts; tabs << kphf; tabs << kpl; QWidget *parentWidget=doc->widget(); if ( !parentWidget ) parentWidget=QApplication::activeWindow(); QScopedPointer<QPrintDialog> printDialog(KdePrint::createPrintDialog(&printer, KdePrint::SystemSelectsPages, tabs, parentWidget)); if ( doc->activeView()->selection() ) { printer.setPrintRange(QPrinter::Selection); printDialog->setOption(QAbstractPrintDialog::PrintSelection, true); } if ( printDialog->exec() ) { writeSettings(printer); KateRenderer renderer(doc, doc->activeKateView()); renderer.config()->setSchema (kpl->colorScheme()); renderer.setPrinterFriendly(true); QPainter paint( &printer ); /* * We work in tree cycles: * 1) initialize variables and retrieve print settings * 2) prepare data according to those settings * 3) draw to the printer */ uint pdmWidth = printer.width(); uint pdmHeight = printer.height(); int y = 0; uint xstart = 0; // beginning point for painting lines uint lineCount = 0; uint maxWidth = pdmWidth; int headerWidth = pdmWidth; int startCol = 0; int endCol = 0; bool pageStarted = true; int remainder = 0; // remaining sublines from a wrapped line (for the top of a new page) // Text Settings Page bool selectionOnly = (printDialog->printRange() == QAbstractPrintDialog::Selection); bool useGuide = kpts->printGuide(); bool printLineNumbers = kpts->printLineNumbers(); uint lineNumberWidth( 0 ); // Header/Footer Page QFont headerFont(kphf->font()); // used for header/footer bool useHeader = kphf->useHeader(); QColor headerBgColor(kphf->headerBackground()); QColor headerFgColor(kphf->headerForeground()); uint headerHeight( 0 ); // further init only if needed QStringList headerTagList; // do bool headerDrawBg = false; // do bool useFooter = kphf->useFooter(); QColor footerBgColor(kphf->footerBackground()); QColor footerFgColor(kphf->footerForeground()); uint footerHeight( 0 ); // further init only if needed QStringList footerTagList; // do bool footerDrawBg = false; // do // Layout Page renderer.config()->setSchema( kpl->colorScheme() ); bool useBackground = kpl->useBackground(); bool useBox = kpl->useBox(); int boxWidth(kpl->boxWidth()); QColor boxColor(kpl->boxColor()); int innerMargin = useBox ? kpl->boxMargin() : 6; // Post initialization int maxHeight = (useBox ? pdmHeight-innerMargin : pdmHeight); uint currentPage( 1 ); uint lastline = doc->lastLine(); // necessary to print selection only uint firstline( 0 ); const int fontHeight = renderer.fontHeight(); KTextEditor::Range selectionRange; /* * Now on for preparations... * during preparations, variable names starting with a "_" means * those variables are local to the enclosing block. */ { if ( selectionOnly ) { // set a line range from the first selected line to the last selectionRange = doc->activeView()->selectionRange(); firstline = selectionRange.start().line(); lastline = selectionRange.end().line(); lineCount = firstline; } if ( printLineNumbers ) { // figure out the horiizontal space required QString s( QString("%1 ").arg( doc->lines() ) ); s.fill('5', -1); // some non-fixed fonts haven't equally wide numbers // FIXME calculate which is actually the widest... lineNumberWidth = renderer.currentFontMetrics().width( s ); // a small space between the line numbers and the text int _adj = renderer.currentFontMetrics().width( "5" ); // adjust available width and set horizontal start point for data maxWidth -= (lineNumberWidth + _adj); xstart += lineNumberWidth + _adj; } if ( useHeader || useFooter ) { // Set up a tag map // This retrieves all tags, ued or not, but // none of theese operations should be expensive, // and searcing each tag in the format strings is avoided. QDateTime dt = QDateTime::currentDateTime(); QMap<QString,QString> tags; KUser u (KUser::UseRealUserID); tags["u"] = u.loginName(); tags["d"] = KGlobal::locale()->formatDateTime(dt, KLocale::ShortDate); tags["D"] = KGlobal::locale()->formatDateTime(dt, KLocale::LongDate); tags["h"] = KGlobal::locale()->formatTime(dt.time(), false); tags["y"] = KGlobal::locale()->formatDate(dt.date(), KLocale::ShortDate); tags["Y"] = KGlobal::locale()->formatDate(dt.date(), KLocale::LongDate); tags["f"] = doc->url().fileName(); tags["U"] = doc->url().prettyUrl(); if ( selectionOnly ) { QString s( i18n("(Selection of) ") ); tags["f"].prepend( s ); tags["U"].prepend( s ); } QRegExp reTags( "%([dDfUhuyY])" ); // TODO tjeck for "%%<TAG>" if (useHeader) { headerDrawBg = kphf->useHeaderBackground(); headerHeight = QFontMetrics( headerFont ).height(); if ( useBox || headerDrawBg ) headerHeight += innerMargin * 2; else headerHeight += 1 + QFontMetrics( headerFont ).leading(); headerTagList = kphf->headerFormat(); QMutableStringListIterator it(headerTagList); while ( it.hasNext() ) { QString tag = it.next(); int pos = reTags.indexIn( tag ); QString rep; while ( pos > -1 ) { rep = tags[reTags.cap( 1 )]; tag.replace( (uint)pos, 2, rep ); pos += rep.length(); pos = reTags.indexIn( tag, pos ); } it.setValue( tag ); } if (!headerBgColor.isValid()) headerBgColor = Qt::lightGray; if (!headerFgColor.isValid()) headerFgColor = Qt::black; } if (useFooter) { footerDrawBg = kphf->useFooterBackground(); footerHeight = QFontMetrics( headerFont ).height(); if ( useBox || footerDrawBg ) footerHeight += 2*innerMargin; else footerHeight += 1; // line only footerTagList = kphf->footerFormat(); QMutableStringListIterator it(footerTagList); while ( it.hasNext() ) { QString tag = it.next(); int pos = reTags.indexIn( tag ); QString rep; while ( pos > -1 ) { rep = tags[reTags.cap( 1 )]; tag.replace( (uint)pos, 2, rep ); pos += rep.length(); pos = reTags.indexIn( tag, pos ); } it.setValue( tag ); } if (!footerBgColor.isValid()) footerBgColor = Qt::lightGray; if (!footerFgColor.isValid()) footerFgColor = Qt::black; // adjust maxheight, so we can know when/where to print footer maxHeight -= footerHeight; } } // if ( useHeader || useFooter ) if ( useBackground ) { if ( ! useBox ) { xstart += innerMargin; maxWidth -= innerMargin * 2; } } if ( useBox ) { if (!boxColor.isValid()) boxColor = Qt::black; if (boxWidth < 1) // shouldn't be pssible no more! boxWidth = 1; // set maxwidth to something sensible maxWidth -= ( ( boxWidth + innerMargin ) * 2 ); xstart += boxWidth + innerMargin; // maxheight too.. maxHeight -= boxWidth; } else boxWidth = 0; // now that we know the vertical amount of space needed, // it is possible to calculate the total number of pages // if needed, that is if any header/footer tag contains "%P". if ( !headerTagList.filter("%P").isEmpty() || !footerTagList.filter("%P").isEmpty() ) { kDebug(13020)<<"'%P' found! calculating number of pages..."; int pageHeight = maxHeight; if ( useHeader ) pageHeight -= ( headerHeight + innerMargin ); if ( useFooter ) pageHeight -= innerMargin; const int linesPerPage = pageHeight / fontHeight; // kDebug() << "Lines per page:" << linesPerPage; // calculate total layouted lines in the document int totalLines = 0; // TODO: right now ignores selection printing for (int i = firstline; i <= lastline; ++i) { KateLineLayoutPtr rangeptr(new KateLineLayout(doc)); rangeptr->setLine(i); renderer.layoutLine(rangeptr, (int)maxWidth, false); totalLines += rangeptr->viewLineCount(); } int totalPages = (totalLines / linesPerPage) + ((totalLines % linesPerPage) > 0 ? 1 : 0); // kDebug() << "_______ pages:" << (totalLines / linesPerPage); // kDebug() << "________ rest:" << (totalLines % linesPerPage); // TODO: add space for guide if required // if ( useGuide ) // _lt += (guideHeight + (fontHeight /2)) / fontHeight; // substitute both tag lists QString re("%P"); QStringList::Iterator it; for ( it=headerTagList.begin(); it!=headerTagList.end(); ++it ) (*it).replace( re, QString( "%1" ).arg( totalPages ) ); for ( it=footerTagList.begin(); it!=footerTagList.end(); ++it ) (*it).replace( re, QString( "%1" ).arg( totalPages ) ); } } // end prepare block /* On to draw something :-) */ while ( lineCount <= lastline ) { startCol = 0; endCol = 0; if ( y + fontHeight > maxHeight ) { kDebug(13020)<<"Starting new page,"<<lineCount<<"lines up to now."; printer.newPage(); paint.resetTransform(); currentPage++; pageStarted = true; y=0; } if ( pageStarted ) { if ( useHeader ) { paint.setPen(headerFgColor); paint.setFont(headerFont); if ( headerDrawBg ) paint.fillRect(0, 0, headerWidth, headerHeight, headerBgColor); if (headerTagList.count() == 3) { int valign = ( (useBox||headerDrawBg||useBackground) ? Qt::AlignVCenter : Qt::AlignTop ); int align = valign|Qt::AlignLeft; int marg = ( useBox || headerDrawBg ) ? innerMargin : 0; if ( useBox ) marg += boxWidth; QString s; for (int i=0; i<3; i++) { s = headerTagList[i]; if (s.indexOf("%p") != -1) s.replace("%p", QString::number(currentPage)); paint.drawText(marg, 0, headerWidth-(marg*2), headerHeight, align, s); align = valign|(i == 0 ? Qt::AlignHCenter : Qt::AlignRight); } } if ( ! ( headerDrawBg || useBox || useBackground ) ) // draw a 1 px (!?) line to separate header from contents { paint.drawLine( 0, headerHeight-1, headerWidth, headerHeight-1 ); //y += 1; now included in headerHeight } y += headerHeight + innerMargin; } if ( useFooter ) { paint.setPen(footerFgColor); if ( ! ( footerDrawBg || useBox || useBackground ) ) // draw a 1 px (!?) line to separate footer from contents paint.drawLine( 0, maxHeight + innerMargin - 1, headerWidth, maxHeight + innerMargin - 1 ); if ( footerDrawBg ) paint.fillRect(0, maxHeight+innerMargin+boxWidth, headerWidth, footerHeight, footerBgColor); if (footerTagList.count() == 3) { int align = Qt::AlignVCenter|Qt::AlignLeft; int marg = ( useBox || footerDrawBg ) ? innerMargin : 0; if ( useBox ) marg += boxWidth; QString s; for (int i=0; i<3; i++) { s = footerTagList[i]; if (s.indexOf("%p") != -1) s.replace("%p", QString::number(currentPage)); paint.drawText(marg, maxHeight+innerMargin, headerWidth-(marg*2), footerHeight, align, s); align = Qt::AlignVCenter|(i == 0 ? Qt::AlignHCenter : Qt::AlignRight); } } } // done footer if ( useBackground ) { // If we have a box, or the header/footer has backgrounds, we want to paint // to the border of those. Otherwise just the contents area. int _y = y, _h = maxHeight - y; if ( useBox ) { _y -= innerMargin; _h += 2 * innerMargin; } else { if ( headerDrawBg ) { _y -= innerMargin; _h += innerMargin; } if ( footerDrawBg ) { _h += innerMargin; } } paint.fillRect( 0, _y, pdmWidth, _h, renderer.config()->backgroundColor()); } if ( useBox ) { paint.setPen(QPen(boxColor, boxWidth)); paint.drawRect(0, 0, pdmWidth, pdmHeight); if (useHeader) paint.drawLine(0, headerHeight, headerWidth, headerHeight); else y += innerMargin; if ( useFooter ) // drawline is not trustable, grr. paint.fillRect( 0, maxHeight+innerMargin, headerWidth, boxWidth, boxColor ); } if ( useGuide && currentPage == 1 ) { // FIXME - this may span more pages... // draw a box unless we have boxes, in which case we end with a box line int _ystart = y; QString _hlName = doc->highlight()->name(); QList<KateExtendedAttribute::Ptr> _attributes; // list of highlight attributes for the legend doc->highlight()->getKateExtendedAttributeList(kpl->colorScheme(), _attributes); KateAttributeList _defaultAttributes; KateHlManager::self()->getDefaults ( renderer.config()->schema(), _defaultAttributes ); QColor _defaultPen = _defaultAttributes.at(0)->foreground().color(); paint.setPen(_defaultPen); int _marg = 0; if ( useBox ) _marg += (2*boxWidth) + (2*innerMargin); else { if ( useBackground ) _marg += 2*innerMargin; _marg += 1; y += 1 + innerMargin; } // draw a title string QFont _titleFont = renderer.config()->font(); _titleFont.setBold(true); paint.setFont( _titleFont ); QRect _r; paint.drawText( QRect(_marg, y, pdmWidth-(2*_marg), maxHeight - y), Qt::AlignTop|Qt::AlignHCenter, i18n("Typographical Conventions for %1", _hlName ), &_r ); int _w = pdmWidth - (_marg*2) - (innerMargin*2); int _x = _marg + innerMargin; y += _r.height() + innerMargin; paint.drawLine( _x, y, _x + _w, y ); y += 1 + innerMargin; int _widest( 0 ); foreach (const KateExtendedAttribute::Ptr &attribute, _attributes) _widest = qMax(QFontMetrics(attribute->font()).width(attribute->name().section(':',1,1)), _widest); int _guideCols = _w/( _widest + innerMargin ); // draw attrib names using their styles int _cw = _w/_guideCols; int _i(0); _titleFont.setUnderline(true); QString _currentHlName; foreach (const KateExtendedAttribute::Ptr &attribute, _attributes) { QString _hl = attribute->name().section(':',0,0); QString _name = attribute->name().section(':',1,1); if ( _hl != _hlName && _hl != _currentHlName ) { _currentHlName = _hl; if ( _i%_guideCols ) y += fontHeight; y += innerMargin; paint.setFont(_titleFont); paint.setPen(_defaultPen); paint.drawText( _x, y, _w, fontHeight, Qt::AlignTop, _hl + ' ' + i18n("text") ); y += fontHeight; _i = 0; } KTextEditor::Attribute _attr = *_defaultAttributes[attribute->defaultStyleIndex()]; _attr += *attribute; paint.setPen( _attr.foreground().color() ); paint.setFont( _attr.font() ); if (_attr.hasProperty(QTextFormat::BackgroundBrush) ) { QRect _rect = QFontMetrics(_attr.font()).boundingRect(_name); _rect.moveTo(_x + ((_i%_guideCols)*_cw), y); paint.fillRect(_rect, _attr.background() ); } paint.drawText(( _x + ((_i%_guideCols)*_cw)), y, _cw, fontHeight, Qt::AlignTop, _name ); _i++; if ( _i && ! ( _i%_guideCols ) ) y += fontHeight; } if ( _i%_guideCols ) y += fontHeight;// last row not full // draw a box around the legend paint.setPen ( _defaultPen ); if ( useBox ) paint.fillRect( 0, y+innerMargin, headerWidth, boxWidth, boxColor ); else { _marg -=1; paint.drawRect( _marg, _ystart, pdmWidth-(2*_marg), y-_ystart+innerMargin ); } y += ( useBox ? boxWidth : 1 ) + (innerMargin*2); } // useGuide paint.translate(xstart,y); pageStarted = false; } // pageStarted; move on to contents:)
void QReportBand::setBandHeight(qreal value) { setSize(size().width(), value + headerHeight()); }
qreal QReportBand::bandHeight() const { return size().height() - headerHeight(); }
/*! * \see void setSize ( QSizeF size ) */ void QReportBand::setSize(int width, int height) { QSize newSize(width, height + headerHeight()); QReportWidgetBase::setSize(newSize); }
/*! *Set height for report widget * \see void setSize ( QSizeF size ) */ void QReportBand::setHeight(int height) { setSize(size().width(), height + headerHeight()); }
FloatSize ScrollingTreeFrameScrollingNode::viewToContentsOffset(const FloatPoint& scrollOffset) const { return toFloatSize(scrollOffset) - toFloatSize(scrollOrigin()) - FloatSize(0, headerHeight() + topContentInset()); }
QSize VRFSystemMiniView::cellSize() { return QSize(cellWidth(),cellHeight() + headerHeight()); }
VRFSystemMiniView::VRFSystemMiniView() { m_length = 75; m_zones = 0; m_terminals = 0; m_vrfOutdoorPix = QPixmap(":images/vrf_outdoor.png").scaled(m_length,m_length); m_vrfTransferPix = QPixmap(":images/vrf_transfer.png").scaled(m_length,m_length); m_vrfTerminalPix = QPixmap(":images/vrf_unit.png").scaled(m_length,m_length); m_vrfZonePix = QPixmap(":images/zone.png").scaled(m_length,m_length); removeButtonItem = new RemoveButtonItem(); removeButtonItem->setParentItem(this); removeButtonItem->setPos(cellWidth() - removeButtonItem->boundingRect().width() - 10,headerHeight() / 2.0 - removeButtonItem->boundingRect().height() / 2.0); zoomInButtonItem = new ZoomInButtonItem(); zoomInButtonItem->setParentItem(this); zoomInButtonItem->setPos(removeButtonItem->pos().x() - 10 - zoomInButtonItem->boundingRect().width(),headerHeight() / 2.0 - zoomInButtonItem->boundingRect().height() / 2.0); }
void CalPrintYear::print( QPainter &p, int width, int height ) { QRect headerBox( 0, 0, width, headerHeight() ); const KCalendarSystem *calsys = calendarSystem(); KLocale *locale = KGlobal::locale(); if ( !calsys || !locale ) { return; } QDate start; calsys->setYMD( start, mYear, 1, 1 ); // Determine the nr of months and the max nr of days per month (dependent on // calendar system!!!!) QDate temp( start ); int months = calsys->monthsInYear( start ); int maxdays = 1; for ( int i = 1; i< months; ++i ) { maxdays = qMax( maxdays, temp.daysInMonth() ); temp = calsys->addMonths( temp, 1 ); } // Now determine the months per page so that the printout fits on // exactly mPages pages int monthsPerPage = ( months - 1 ) / mPages + 1; int pages = ( months - 1 ) / monthsPerPage + 1; int thismonth = 0; temp = start; for ( int page = 0; page < pages; ++page ) { if ( page > 0 ) { mPrinter->newPage(); } QDate end( calsys->addMonths( start, monthsPerPage ) ); end = calsys->addDays( end, -1 ); QString stdate = locale->formatDate( start ); QString endate = locale->formatDate( end ); QString title; if ( orientation() == QPrinter::Landscape ) { title = i18nc( "date from - to", "%1 - %2", stdate, endate ); } else { title = i18nc( "date from -\nto", "%1 -\n%2", stdate, endate ); } drawHeader( p, title, calsys->addMonths( start, -1 ), calsys->addMonths( start, monthsPerPage ), headerBox ); QRect monthesBox( headerBox ); monthesBox.setTop( monthesBox.bottom() + padding() ); monthesBox.setBottom( height ); drawBox( p, BOX_BORDER_WIDTH, monthesBox ); float monthwidth = float( monthesBox.width() ) / float( monthsPerPage ); for ( int j=0; j<monthsPerPage; ++j ) { if ( ++thismonth > months ) { break; } int xstart = int( j * monthwidth + 0.5 ); int xend = int( ( j + 1 ) * monthwidth + 0.5 ); QRect monthBox( xstart, monthesBox.top(), xend - xstart, monthesBox.height() ); drawMonth( p, temp, monthBox, maxdays, mSubDaysEvents, mHolidaysEvents ); temp = calsys->addMonths( temp, 1 ); } start = calsys->addMonths( start, monthsPerPage ); } }
NodeView::NodeView( const QPointF& position, kiwi::core::Node * n) : kiwi::view::NodeView( n ) { assert( n ); n->setView( this ); setFlags(QGraphicsItem::ItemIsMovable); setPos( position ); float nodeHeight = (nodeType()->inputs().size() + nodeType()->outputs().size()) * portsSpacing() + headerHeight(); _rect = QRectF( 0, 0, 150.0, nodeHeight ); int i = 0; for( auto it = nodeType()->inputs().begin(); it != nodeType()->inputs().end(); ++it ) { _inputs.push_back( new PortView(PortView::INPUT, this, i) ); _inputs[i]->setPos( QPointF( leftX(), inputsY() + i * portsSpacing() ) ); ++i; } i = 0; for( auto it = nodeType()->outputs().begin(); it != nodeType()->outputs().end(); ++it ) { _outputs.push_back( new PortView(PortView::OUTPUT, this, i) ); _outputs[i]->setPos( QPointF( rightX(), outputsY() + i * portsSpacing() ) ); ++i; } _dropShadow.setBlurRadius( 16 ); _dropShadow.setXOffset( 0.0 ); _dropShadow.setYOffset( 5.0 ); setGraphicsEffect( &_dropShadow ); }
QPointF NodeView::relativeOutputPos(int i) const { return QPointF( _rect.width(), headerHeight() + _inputs.size() * portsSpacing() + i * portsSpacing() ); }
QPointF NodeView::relativeInputPos(int i) const { return QPointF( 0.0, headerHeight() + i * portsSpacing() ); }
IntSize ScrollableArea::totalContentsSize() const { IntSize totalContentsSize = contentsSize(); totalContentsSize.setHeight(totalContentsSize.height() + headerHeight() + footerHeight()); return totalContentsSize; }
IntPoint ScrollableArea::constrainScrollPositionForOverhang(const IntPoint& scrollPosition) { return constrainScrollPositionForOverhang(visibleContentRect(), totalContentsSize(), scrollPosition, scrollOrigin(), headerHeight(), footerHeight()); }
QRectF VRFSystemMiniView::contentRect() const { return QRectF(0,headerHeight(),cellWidth(),cellHeight()); }
void RegSexyDisplay::paintEvent(QPaintEvent *event) { // FIXME could be optimised with QStaticText Q_UNUSED(event); int txt_h = fontMetrics().height(); int sep_sz = separatorSize(); int w = width(); int h = height() - 1; int col_w = (w - 33 * sep_sz) / 32; int hdr_h = headerHeight(); int gap_h = gapHeight(); int tot_w = 33 * sep_sz + 32 * col_w; int margin = marginSize(); int txt_sep = textSep(); int tot_hdr_sz = 2 * sep_sz + hdr_h; // computer xshift int x_shift = (w - tot_w) / 2; #define ith_col_x(i) (x_shift + (i) * (sep_sz + col_w)) QPainter painter(this); QBrush back_brush = palette().base(); QBrush line_brush = palette().dark(); // fill interesting zone with base painter.fillRect(x_shift, 0, tot_w, h, back_brush); // draw top and bottom lines painter.setPen(QPen(palette().dark(), sep_sz)); painter.fillRect(x_shift, 0, tot_w, sep_sz, line_brush); painter.fillRect(x_shift, h - sep_sz, tot_w, sep_sz, line_brush); // draw intemediate lines for(int i = 0; i <= 32; i++) painter.fillRect(ith_col_x(i), 0, sep_sz, 2 * sep_sz + hdr_h, line_brush); // draw bottom header lines painter.fillRect(ith_col_x(0), sep_sz + hdr_h, tot_w, sep_sz, line_brush); painter.fillRect(ith_col_x(0), tot_hdr_sz + gap_h, tot_w, sep_sz, line_brush); // redraw some lines but wider for(int i = 4; i < 32; i += 4) painter.fillRect(ith_col_x(i) - sep_sz, 0, 3 * sep_sz, tot_hdr_sz, line_brush); // draw numbers in the header painter.setPen(palette().brush(QPalette::ButtonText).color()); for(int i = 0; i < 32; i++) { QRect r(ith_col_x(i), sep_sz + margin, col_w, txt_h); painter.drawText(r, Qt::AlignCenter, QString("%1").arg((31 - i) / 10)); r.translate(0, txt_h + txt_sep); painter.drawText(r, Qt::AlignCenter, QString("%1").arg((31 - i) % 10)); } // display content for(size_t i = 0; i < m_reg.GetReg().field.size(); i++) { const soc_reg_field_t& field = m_reg.GetReg().field[i]; QRect r(QPoint(ith_col_x(31 - field.last_bit) + sep_sz, tot_hdr_sz), QPoint(ith_col_x(32 - field.first_bit), h - sep_sz)); painter.fillRect(r.x() - sep_sz, r.y(), sep_sz, r.height(), line_brush); painter.fillRect(r.right(), r.y(), sep_sz, r.height(), line_brush); r.setY(r.y() + gap_h + sep_sz); // draw rotated text painter.save(); painter.translate(r.bottomLeft()); painter.rotate(-90); //painter.fillRect(QRect(0, 0, r.height(), r.width()), QBrush(Qt::red)); QRect r2(0, 0, r.height(), r.width()); painter.drawText(r2, Qt::AlignCenter, QString::fromStdString(field.name)); painter.restore(); } #undef ith_col_x }
QRectF VRFSystemMiniView::headerRect() const { return QRectF(0,0,cellWidth(),headerHeight()); }