int StyleHelper::avatarHeight(bool bNoScreenFactor) { QFont f; int nHeight = fontHead(f) + fontNormal(f) + margin() * 3 ; if (bNoScreenFactor) return nHeight; #ifdef Q_OS_LINUX return nHeight; #else float factor = qt_mac_get_scalefactor(0); return nHeight * factor; #endif }
int StyleHelper::listViewItemHeight(int nType) { QFont f; switch (nType) { case ListTypeOneLine: return fontHead(f) + margin() * 4; case ListTypeTwoLine: return fontHead(f) + fontNormal(f) + margin() * 5; case ListTypeThumb: return thumbnailHeight() + margin() * 2; default: Q_ASSERT(0); return 0; } }
void ImportCategoryDrawer::drawCategory(const QModelIndex& index, int /*sortRole*/, const QStyleOption& option, QPainter* p) const { if (option.rect.width() != d->rect.width()) { const_cast<ImportCategoryDrawer*>(this)->updateRectsAndPixmaps(option.rect.width()); } p->save(); p->translate(option.rect.topLeft()); CamItemSortSettings::CategorizationMode mode = (CamItemSortSettings::CategorizationMode)index.data(ImportFilterModel::CategorizationModeRole).toInt(); p->drawPixmap(0, 0, d->pixmap); QFont fontBold(d->font); QFont fontNormal(d->font); fontBold.setBold(true); int fnSize = fontBold.pointSize(); // bool usePointSize; if (fnSize > 0) { fontBold.setPointSize(fnSize+2); // usePointSize = true; } else { fnSize = fontBold.pixelSize(); fontBold.setPixelSize(fnSize+2); // usePointSize = false; } QString header; QString subLine; switch (mode) { case CamItemSortSettings::NoCategories: break; case CamItemSortSettings::CategoryByFolder: viewHeaderText(index, &header, &subLine); break; case CamItemSortSettings::CategoryByFormat: textForFormat(index, &header, &subLine); break; } p->setPen(kapp->palette().color(QPalette::HighlightedText)); p->setFont(fontBold); QRect tr; p->drawText(5, 5, d->rect.width(), d->rect.height(), Qt::AlignLeft | Qt::AlignTop, header, &tr); int y = tr.height() + 2; p->setFont(fontNormal); p->drawText(5, y, d->rect.width(), d->rect.height() - y, Qt::AlignLeft | Qt::AlignVCenter, subLine); p->restore(); }
int StyleHelper::thumbnailHeight() { QFont f; return fontHead(f) + fontNormal(f) * 3 + margin() * 5; }
int StyleHelper::avatarHeight() { QFont f; return fontHead(f) + fontNormal(f) + margin() * 3; }
void CBlockUnit::DrawBlock(Graphics *pGraph) { Pen pen(Color(0, 0, 0)); Font fontBold(L"Tahoma", 10, FontStyleBold); Font fontNormal(L"Tahoma", 10, FontStyleRegular); SolidBrush brush(Color(0, 0, 0)); // Check & update block size UINT nMinWidth = GetMinWidth(); UINT nMinHeight = GetMinHeight(); if ((INT)m_rRect.Width < (INT)nMinWidth) { m_rRect.Width = ROUND(nMinWidth); } if ((INT)m_rRect.Height < (INT)nMinHeight) { m_rRect.Height = ROUND(nMinHeight); } // select color according to type switch (m_nType) { case T_FUNCTION: { brush.SetColor(Color(220, 220, 255)); } break; case T_SUBSYSTEM: { brush.SetColor(Color(255, 220, 220)); } break; case T_TEXTBOX: { brush.SetColor(Color(255, 255, 230)); } break; case T_INPUT: { brush.SetColor(Color(255, 255, 220)); } break; case T_OUTPUT: { brush.SetColor(Color(255, 255, 220)); } break; default: { ASSERT(TRUE); } } // Mark selected if (m_bSelected) { pen.SetWidth(2); } // Outline error connections if (m_bError) { pen.SetColor(Color(255, 100, 100)); } else { pen.SetColor(Color(0, 0, 0)); } // Draw rectangle body pGraph->FillRectangle(&brush, m_rRect); pGraph->DrawRectangle(&pen, m_rRect); if ((m_nType != T_INPUT) && (m_nType != T_OUTPUT)) { pen.SetWidth(1); brush.SetColor(Color(0, 0, 0)); RectF rect, rectSize; StringFormat format; // Write title string if (m_nType == T_TEXTBOX) { rect = RectF(m_rRect.X, m_rRect.Y, m_rRect.Width, m_rRect.Height); wstring ws(m_sName.begin(), m_sName.end()); pGraph->DrawString(ws.c_str(), -1, &fontNormal, rect, &format, &brush); // Measure title text width rect.Width = 0; pGraph->MeasureString(ws.c_str(), -1, &fontNormal, rect, &format, &rectSize); m_lName = (INT)rectSize.Width; } else { // Draw title line pGraph->DrawLine(&pen, m_rRect.X, m_rRect.Y+20, m_rRect.GetRight(), m_rRect.Y+20); format.SetAlignment(StringAlignmentCenter); format.SetLineAlignment(StringAlignmentCenter); rect = RectF(m_rRect.X, m_rRect.Y, m_rRect.Width, 20); wstring ws(m_sName.begin(), m_sName.end()); pGraph->DrawString(ws.c_str(), -1, &fontBold, rect, &format, &brush); // Measure title text width rect.Width = 0; pGraph->MeasureString(ws.c_str(), -1, &fontBold, rect, &format, &rectSize); m_lName = (INT)rectSize.Width; } } // Draw input variables Point ptInput(m_rRect.X, m_rRect.GetTop() + 10); if ((m_nType != T_INPUT) && (m_nType != T_OUTPUT)) { ptInput.Y += 20; } for (int i=0; i<m_vInput.size(); i++) { // Skip if input port if (m_nType == T_INPUT) { break; } // Draw port m_vInput[i]->DrawIOPort(pGraph, ptInput.X, ptInput.Y); ptInput.Y += 20; // Only draw one if I/O ports if (m_nType == T_OUTPUT) { break; } } // Draw output variables Point ptOutput(m_rRect.GetRight(), m_rRect.Y + 10); if ((m_nType != T_INPUT) && (m_nType != T_OUTPUT)) { ptOutput.Y += 20; } for (int i=0; i<m_vOutput.size(); i++) { // Skip if output port if (m_nType == T_OUTPUT) { break; } // Draw port m_vOutput[i]->DrawIOPort(pGraph, ptOutput.X, ptOutput.Y); ptOutput.Y += 20; // Only draw one if I/O ports if (m_nType == T_INPUT) { break; } } }
void inputRZImpl::print() { QString fname = EGSdir + EGSfileName; QPrinter* printer = new QPrinter; printer->setPageSize( QPrinter::Letter ); const int Margin = 20; const int MarginY = 30; int pageNo = 1; QPrintDialog pdialog(printer,this); if ( pdialog.exec()) { cout << "let's print !!!" << endl; QPainter paint( printer ); //if( !paint.begin( printer ) ) // paint on printer // return; static const char *fonts[] = { "Helvetica", "Courier", "Times", 0 }; static int sizes[] = { 10, 12, 18, 24, 36, 0 }; int yPos = 0; QFont fontNormal( fonts[1], sizes[0] ); QFont fontBold( fonts[0], sizes[0] ); fontBold.setWeight( QFont::Black); paint.setFont( fontBold ); QFontMetrics fmBold = paint.fontMetrics(); paint.setFont( fontNormal ); QFontMetrics fm = paint.fontMetrics(); //qt3to4 -- BW //Q3PaintDeviceMetrics metrics( printer ); // need width/height QFile fi( fname ); //qt3to4 -- BW //Q3TextStream ts( &fi ); QTextStream ts( &fi ); QString t; int StepsPerPage = 500; int LinesPerPage = (printer->height() - 2* MarginY) / fm.lineSpacing(); if ( fi.open( QIODevice::ReadOnly ) ) { int NumOfPages = 1 + TotalTextLines( fname ) / LinesPerPage; int totalSteps = StepsPerPage * NumOfPages; QString msg( "Printing (page " ); msg += QString::number( pageNo ); msg += ")..."; //qt3to4 -- BW //Q3ProgressDialog* dialog = new Q3ProgressDialog(msg, "Cancel", // totalSteps, this, "progress", true); QProgressDialog* dialog = new QProgressDialog(msg, "Cancel",0,totalSteps); //dialog->setTotalSteps( totalSteps ); //dialog->setProgress( 0 ); dialog->setValue(0); dialog->setMinimumDuration( 0 ); int progress_count = 0; QString gui = "EGSnrc GUI for RZ Geometries: " + EGSfileName; QDate currDate = QDate::currentDate(); QString date = currDate.toString ( "dd.MM.yyyy" ); paint.setFont( fontBold ); paint.drawText( Margin, 0, printer->width() - 2*Margin, fmBold.lineSpacing(), Qt::AlignLeft | Qt::RichText, gui ); paint.drawText( Margin, 0, printer->width() - 2*Margin, fmBold.lineSpacing(), Qt::AlignRight, date ); paint.drawLine( Margin, MarginY - 10, printer->width() - Margin, MarginY - 10 ); paint.drawLine( Margin, printer->height() - MarginY + 10, printer->width() - Margin, printer->height() - MarginY + 10 ); paint.drawText( Margin, printer->height() - fmBold.lineSpacing(), printer->width(), fmBold.lineSpacing(), Qt::AlignHCenter, QString::number( pageNo ) ); paint.setFont( fontNormal ); do { progress_count++; qApp->processEvents(); if ( dialog->wasCanceled() ) dialog->close(); t = ts.readLine(); if ( MarginY + yPos + fm.lineSpacing() > printer->height() - MarginY ) { do{ //dialog->setProgress( ++progress_count ); dialog->setValue(++progress_count ); }while ( progress_count < StepsPerPage*pageNo ); msg = "Printing (page " + QString::number( ++pageNo ) + ")..."; dialog->setLabelText( msg ); printer->newPage(); // no more room on this page yPos = 0; // back to top of page paint.setFont( fontBold ); paint.drawText( Margin, 0, printer->width() - 2*Margin, fmBold.lineSpacing(), Qt::AlignLeft | Qt::RichText, gui ); paint.drawText( Margin, 0, printer->width() - 2*Margin, fmBold.lineSpacing(), Qt::AlignRight, date ); paint.drawLine( Margin, MarginY - 10, printer->width() - Margin, MarginY - 10 ); paint.drawLine( Margin, printer->height() - MarginY + 10, printer->width() - Margin, printer->height() - MarginY + 10 ); paint.drawText( Margin, printer->height() - fmBold.lineSpacing(), printer->width(), fmBold.lineSpacing(), Qt::AlignHCenter, QString::number( pageNo ) ); paint.setFont( fontNormal ); } paint.drawText( Margin, MarginY + yPos, printer->width(), fm.lineSpacing(), Qt::TextExpandTabs | Qt::TextDontClip, t ); yPos = yPos + fm.lineSpacing(); dialog->setValue( progress_count ); //qt3to4 -- BW //} while ( !ts.eof() ); } while ( !ts.atEnd() ); do{ dialog->setValue( ++progress_count ); }while ( progress_count < totalSteps ); dialog->setValue( totalSteps ); zap(dialog); } else { QMessageBox::critical( 0, tr("Error printing "), tr("Couldn't open file %1").arg(fname), tr("Quit") ); } fi.close(); } else { QMessageBox::information( this, "Printing status", "Printing aborted"); } delete printer; }