本文整理汇总了C++中QPainter类的典型用法代码示例。如果您正苦于以下问题:C++ QPainter类的具体用法?C++ QPainter怎么用?C++ QPainter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QPainter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SIGNAL
void MainWindow::funS()
{
QLabel* l = new QLabel;
l->setWindowTitle("Fun");
l->setFixedSize(765, 500);
QObject::connect( this, SIGNAL( closeSignal() ), l, SLOT( close() ) );
QRect rect(l->contentsRect());
QPainter painter;
QImage resultImage(rect.size(), QImage::Format_ARGB32_Premultiplied);
painter.begin(&resultImage);
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.eraseRect(rect);
painter.drawImage(rect, resultImage);
painter.end();
painter.begin(&resultImage);
painter.setCompositionMode(QPainter::CompositionMode_Darken);
for(int i = 0; i < 765; i++)
{
if(i<256)
painter.setPen(QPen(QColor(255, i, 0), 1));
else if(i < 512)
painter.setPen(QPen(QColor(511-i, 255, i-256), 1));
else
painter.setPen(QPen(QColor(i-512, 765-i, 255), 1));
painter.drawLine(i, 0, i, 500);
}
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.drawImage(rect, resultImage);
painter.end();
l->setPixmap(QPixmap::fromImage(resultImage));
l->show();
QObject::connect( this, SIGNAL( closeSignal() ), l, SLOT( close() ) );
}
示例2: renderCelSprites
void AnimationViewerPanel::renderCelSprites(const QPoint& centerPoint, QPainter& painter)
{
KeyFrame::KeyFramePosition currentPosition = mpAnimationModel->getCurrentKeyFramePosition();
if (mIsAnimationPlaying)
{
mpAnimationModel->executeCommand(currentPosition.mFrameNo);
}
QList<const GLSprite*>::Iterator iter = mRenderSpriteList.begin();
while (iter != mRenderSpriteList.end())
{
GLSprite* glSprite = (GLSprite*)*iter;
if (glSprite->mLineNo == AnimationModel::LINE_target)
{
if (!mShowTarget)
{
iter++;
continue;
}
GLSprite::Point2 position;
position.mX = glSprite->mSpriteDescriptor.mPosition.mX + AnimationModel::TARGET_originX;
position.mY = glSprite->mSpriteDescriptor.mPosition.mY + AnimationModel::TARGET_originY;
glSprite->mSpriteDescriptor.mPosition = position;
}
if (!mShowCamera && glSprite->mLineNo == AnimationModel::LINE_camera)
{
iter++;
continue;
}
// render sprite
// Move rendering position depends on targeting position option
int dx = 0;
int dy = 0;
// if (glSprite->mLineNo == AnimationModel::LINE_target)
// {
// dx = glSprite->mSpriteDescriptor.mTextureSrcRect.width() / 2;
// dy = glSprite->mSpriteDescriptor.mTextureSrcRect.height() / 2;
// }
painter.translate(centerPoint.x() + dx, centerPoint.y() + dy);
if (glSprite)
{
glSprite->render(QPoint(0, 0), painter,AnimationModel::getTargetSprite(), mIsAnimationPlaying, mEmittedAnimationList);
}
painter.translate(-centerPoint.x() - dx, -centerPoint.y() - dy);
if (glSprite && !mIsAnimationPlaying && mShowAnimationUI)
{
renderCelBox(painter, glSprite, centerPoint - glSprite->mSpriteDescriptor.center());
}
iter++;
}
if (mIsAnimationPlaying)
{
// update emitted animations
for (int lineNo = 0; lineNo < AnimationModel::LINE_COUNT; lineNo++)
{
for (int i = mEmittedAnimationList[lineNo].count() - 1; i >= 0; i--)
{
mEmittedAnimationList[lineNo][i]->update();
if (mEmittedAnimationList[lineNo][i]->isDone())
{
mEmittedAnimationList[lineNo].removeAt(i);
}
}
}
}
}
示例3: deinitPainter
void Node::deinitPainter(QPainter &p) {
p.rotate(-m_dir);
p.translate(-int(x()), -int(y()));
}
示例4: definirGrade
//-----------------------------------------------------------
void CenaObjetos::definirGrade(unsigned tam)
{
if(tam >= 20 || grade.style()==Qt::NoBrush)
{
QImage img_grade;
float larg, alt, x, y;
QSizeF tam_aux;
QPrinter printer;
QPainter painter;
QPen pen;
//Caso o tamanho do papel não seja personalizado
if(tam_papel!=QPrinter::Custom)
{
//Configura um dispositivo QPrinter para obter os tamanhos de página
printer.setPageSize(tam_papel);
printer.setOrientation(orientacao_pag);
printer.setPageMargins(margens_pag.left(), margens_pag.top(),
margens_pag.right(), margens_pag.bottom(), QPrinter::Millimeter);
tam_aux=printer.pageRect(QPrinter::DevicePixel).size();
}
//Caso o tipo de papel seja personalizado, usa as margens como tamanho do papel
else
tam_aux=margens_pag.size();
larg=fabs(roundf(tam_aux.width()/static_cast<float>(tam)) * tam);
alt=fabs(roundf(tam_aux.height()/static_cast<float>(tam)) * tam);
//Cria uma instância de QImage para ser a textura do brush
tam_grade=tam;
img_grade=QImage(larg, alt, QImage::Format_ARGB32);
//Aloca um QPaointer para executar os desenhos sobre a imagem
painter.begin(&img_grade);
//Limpa a imagem
painter.fillRect(QRect(0,0,larg,alt), QColor(255,255,255));
if(exibir_grade)
{
//Cria a grade
pen.setColor(QColor(225, 225, 225));
painter.setPen(pen);
for(x=0; x < larg; x+=tam)
for(y=0; y < alt; y+=tam)
painter.drawRect(QRectF(QPointF(x,y),QPointF(x + tam,y + tam)));
}
//Cria as linhas que definem o limite do papel
if(exibir_lim_pagina)
{
pen.setColor(QColor(75,115,195));
pen.setStyle(Qt::DashLine);
pen.setWidthF(1.85f);
painter.setPen(pen);
painter.drawLine(larg-1, 0,larg-1,alt-1);
painter.drawLine(0, alt-1,larg-1,alt-1);
}
painter.end();
grade.setTextureImage(img_grade);
}
}
示例5: QImage
void HSI::createCard(void){
QImage _cardImage = QImage(QSize(600,600), QImage::Format_ARGB32);
_cardImage.fill(0x00ff0000);
//_cardImage.moveTo(10,10);
uint midx, midy, width, height;
width = _cardImage.width();
midx = width/2;
height = _cardImage.height();
midy = height/2;
QPainter p;
p.setRenderHint(QPainter::Antialiasing, true);
p.begin(&_cardImage);
p.translate(midx, midy);
p.setPen(Qt::black);
p.setBrush(Qt::black);
p.drawChord(-midx,-midy,width,height,0,360*16);
p.setPen(Qt::white);
p.setBrush(Qt::white);
if(_thickBars > 0) {
for (float i = 0 ; i <= 360; i+=_thickBars) {
p.save();
p.rotate(value2Angle(i));
p.drawRect(-2.5, -300, 5.0, 30);
p.restore();
}
}
if(_thinBars > 0) {
for (float i = 0 ; i <= 360; i+=_thinBars) {
p.save();
p.rotate(value2Angle(i));
p.drawRect(-1.0, -300, 2.0, 20);
p.restore();
}
}
p.setPen(QColor(200,200,200));
p.setFont(QFont(QString("Helvetica"), 48, QFont::Bold, false));
if(1) {
for (float i = 0 ; i < 360; i+=_numbers) {
p.save();
p.rotate(value2Angle(i));
p.save();
QString lineNumber;
switch (int(i)) {
case 0:
lineNumber = QString("N");
break;
case 90:
lineNumber = QString("E");
break;
case 180:
lineNumber = QString("S");
break;
case 270:
lineNumber = QString("W");
break;
default:
lineNumber = QString::number(i/10);
break;
}
p.translate(0,-234);
int width = p.fontMetrics().width(lineNumber);
int height = p.fontMetrics().height();
p.drawText(-width/2,-height/2,width,height, Qt::AlignCenter, lineNumber);
p.restore();
p.restore();
}
}
p.end();
_card = QPixmap::fromImage(_cardImage, Qt::AutoColor);
}
示例6: pixmap
//---------------------------------------------------------------------------
// makePixmap
//
//! Create a pixmap representation of the rack.
//
//! @return the pixmap
//---------------------------------------------------------------------------
QPixmap
CrosswordGameRackWidget::makePixmap() const
{
QPixmap pixmap (getRackSize());
QPainter painter (&pixmap);
// FIXME: most of this is duplicated between BoardWidget and here
QColor backgroundColor = BACKGROUND_COLOR;
QPalette backgroundPalette;
backgroundPalette.setColor(QPalette::Light,
backgroundColor.light(SQUARE_SHADE_VALUE));
backgroundPalette.setColor(QPalette::Mid, backgroundColor);
backgroundPalette.setColor(QPalette::Dark,
backgroundColor.dark(SQUARE_SHADE_VALUE));
for (int i = 0; i < NUM_TILES; ++i) {
QRect rect (i * COLUMN_WIDTH, 0, COLUMN_WIDTH, ROW_HEIGHT);
painter.setPen(backgroundColor);
painter.setBrush(backgroundColor);
painter.drawRect(rect);
qDrawShadePanel(&painter, rect, backgroundPalette, false,
SQUARE_SHADE_PANEL_WIDTH);
if (i >= letters.length())
continue;
QRect tileRect(i * COLUMN_WIDTH + TILE_MARGIN, TILE_MARGIN,
COLUMN_WIDTH - 2 * TILE_MARGIN -
SQUARE_SHADE_PANEL_WIDTH,
ROW_HEIGHT - 2 * TILE_MARGIN -
SQUARE_SHADE_PANEL_WIDTH);
QColor color = TILE_COLOR;
QPalette palette;
palette.setColor(QPalette::Light,
color.light(TILE_SHADE_VALUE));
palette.setColor(QPalette::Mid, color);
palette.setColor(QPalette::Dark,
color.dark(TILE_SHADE_VALUE));
painter.setPen(QColor("black"));
painter.setBrush(color);
painter.drawRect(tileRect);
qDrawShadePanel(&painter, tileRect, palette, false,
TILE_SHADE_PANEL_WIDTH);
QFont tileFont = font();
tileFont.setPixelSize(LETTER_HEIGHT);
tileFont.setWeight(QFont::Black);
painter.setFont(tileFont);
switch (playerNum) {
case 1: color = PLAYER1_LETTER_COLOR; break;
case 2: color = PLAYER2_LETTER_COLOR; break;
default: color = DEFAULT_LETTER_COLOR; break;
}
painter.setPen(QPen(color));
QChar letter = letters[i];
if (letter == '?') {
QPen pen (color);
pen.setWidth(1);
painter.setPen(pen);
painter.setBrush(Qt::NoBrush);
QRect blankRect(rect.x() + BLANK_SQUARE_MARGIN,
rect.y() + BLANK_SQUARE_MARGIN,
rect.width() - 2 * BLANK_SQUARE_MARGIN -
SQUARE_SHADE_PANEL_WIDTH - 1,
rect.height() - 2 * BLANK_SQUARE_MARGIN -
SQUARE_SHADE_PANEL_WIDTH - 1);
painter.drawRect(blankRect);
}
else {
painter.drawText(rect, Qt::AlignCenter, letter);
}
}
return pixmap;
}
示例7: defined
void LightMaps::paintEvent(QPaintEvent *event)
{
QPainter p;
p.begin(this);
m_normalMap->render(&p, event->rect());
p.setPen(Qt::black);
#if defined(Q_OS_SYMBIAN)
QFont font = p.font();
font.setPixelSize(13);
p.setFont(font);
#endif
p.drawText(rect(), Qt::AlignBottom | Qt::TextWordWrap,
"Map data CCBYSA 2009 OpenStreetMap.org contributors");
p.end();
if (zoomed) {
int dim = qMin(width(), height());
int magnifierSize = qMin(MAX_MAGNIFIER, dim * 2 / 3);
int radius = magnifierSize / 2;
int ring = radius - 15;
QSize box = QSize(magnifierSize, magnifierSize);
// reupdate our mask
if (maskPixmap.size() != box) {
maskPixmap = QPixmap(box);
maskPixmap.fill(Qt::transparent);
QRadialGradient g;
g.setCenter(radius, radius);
g.setFocalPoint(radius, radius);
g.setRadius(radius);
g.setColorAt(1.0, QColor(255, 255, 255, 0));
g.setColorAt(0.5, QColor(128, 128, 128, 255));
QPainter mask(&maskPixmap);
mask.setRenderHint(QPainter::Antialiasing);
mask.setCompositionMode(QPainter::CompositionMode_Source);
mask.setBrush(g);
mask.setPen(Qt::NoPen);
mask.drawRect(maskPixmap.rect());
mask.setBrush(QColor(Qt::transparent));
mask.drawEllipse(g.center(), ring, ring);
mask.end();
}
QPoint center = dragPos - QPoint(0, radius);
center = center + QPoint(0, radius / 2);
QPoint corner = center - QPoint(radius, radius);
QPoint xy = center * 2 - QPoint(radius, radius);
// only set the dimension to the magnified portion
if (zoomPixmap.size() != box) {
zoomPixmap = QPixmap(box);
zoomPixmap.fill(Qt::lightGray);
}
if (true) {
QPainter p(&zoomPixmap);
p.translate(-xy);
m_largeMap->render(&p, QRect(xy, box));
p.end();
}
QPainterPath clipPath;
clipPath.addEllipse(center, ring, ring);
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
p.setClipPath(clipPath);
p.drawPixmap(corner, zoomPixmap);
p.setClipping(false);
p.drawPixmap(corner, maskPixmap);
p.setPen(Qt::gray);
p.drawPath(clipPath);
}
if (invert) {
QPainter p(this);
p.setCompositionMode(QPainter::CompositionMode_Difference);
p.fillRect(event->rect(), Qt::white);
p.end();
}
}
示例8: PaintLegend
void SectionViewWidget::PaintLegend(QPainter &painter)
{
if(!m_pSailSection) return;
painter.save();
MainFrame* pMainFrame = (MainFrame*)s_pMainFrame;
QString strlength;
GetLengthUnit(strlength, pMainFrame->m_LengthUnit);
painter.setFont(pMainFrame->m_TextFont);
QFontMetrics fm(pMainFrame->m_TextFont);
int dD = fm.height();//pixels
QPoint Place(5, rect().bottom()-5*dD);
if(m_pSail->IsNURBSSail()) Place.ry() -=dD;
painter.setBackgroundMode(Qt::TransparentMode);
QPen TextPen(pMainFrame->m_TextColor);
painter.setPen(TextPen);
if(m_pSail->IsNURBSSail() && m_pSailSection->IsTipSection())
{
QString strtwist = QString("Section chord = %1").arg(m_pSailSection->Chord()*pMainFrame->m_mtoUnit, 6,'f',2) + strlength;
painter.drawText(Place.x(), Place.y() , strtwist);
}
if(m_pSail->IsSailcutSail() || m_pSailSection->IsTipSection())
{
double x, c;
m_pSailSection->GetCamber(c, x);
QString strc = QString("Camber = %1").arg(c*100.0, 6, 'f',2);
QString strx = QString("Camber pos = %1").arg(x*100.0, 6, 'f',2);
strc += QString::fromUtf8("%");
strx += QString::fromUtf8("%");
painter.drawText(Place.x(), Place.y() + dD, strx);
painter.drawText(Place.x(), Place.y() + 2*dD, strc);
}
double s0,s1;
m_pSailSection->GetSlopes(s0,s1);
QString str0 = QString("Luff Slope = %1").arg(s0,5,'f',1) + QString::fromUtf8("°");
QString str1 = QString("Leech Slope = %1").arg(s1,5,'f',1) + QString::fromUtf8("°");
painter.drawText(Place.x(), Place.y() + 3*dD, str0);
painter.drawText(Place.x(), Place.y() + 4*dD, str1);
if(m_pSail->IsNURBSSail())
{
QString strtwist = QString("Section twist = %1").arg(m_pSailSection->Twist(), 5,'f',1) + QString::fromUtf8("°");
painter.drawText(Place.x(), Place.y() + 5*dD, strtwist);
}
//right side legend
if(m_pSail->IsNURBSSail())
{
int YPos = rect().bottom()- dD;
int XPos = rect().right() -5;
NURBSSail *pNSail =(NURBSSail*)m_pSail;
CVector LE = pNSail->m_SplineSurface.LeadingEdgeAxis();
QString strLuffAngle = QString("Luff Angle = %1").arg(atan2(LE.x, LE.z) * 180./PI, 5,'f',1) + QString::fromUtf8("°");
painter.drawText(XPos-fm.width(strLuffAngle), YPos, strLuffAngle);
}
painter.restore();
}
示例9: shape
QPixmap TaintedPixmap::createTaintedPixmapNotMac(const QString &pixmap_path, const QColor &tint_color)
{
QPixmap shape(pixmap_path);
QPixmap result(shape);
QPainter painter;
painter.begin(&result);
painter.fillRect(painter.viewport(), tint_color);
// Apply the shape on top of the tint
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.drawPixmap(painter.viewport(), shape);
// Remove unused background
painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
painter.drawPixmap(painter.viewport(), shape);
painter.end();
return result;
}
示例10: drawingContext
void CanvasRenderingContext2D::stroke()
{
GraphicsContext* c = drawingContext();
if (!c)
return;
c->beginPath();
c->addPath(m_path);
if (!m_path.isEmpty()) {
// FIXME: This is insufficient, need to use CGContextReplacePathWithStrokedPath to expand to required bounds
float lineWidth = state().m_lineWidth;
float inset = lineWidth / 2;
FloatRect boundingRect = m_path.boundingRect();
boundingRect.inflate(inset);
willDraw(boundingRect);
}
// FIXME: Do this through platform-independent GraphicsContext API.
#if PLATFORM(CG)
if (state().m_strokeStyle->canvasGradient()) {
// Shading works on the entire clip region, so convert the current path to a clip.
c->save();
CGContextReplacePathWithStrokedPath(c->platformContext());
CGContextClip(c->platformContext());
CGContextDrawShading(c->platformContext(), state().m_strokeStyle->canvasGradient()->gradient().platformGradient());
c->restore();
} else {
if (state().m_strokeStyle->pattern())
applyStrokePattern();
CGContextStrokePath(c->platformContext());
}
#elif PLATFORM(QT)
QPainterPath* path = m_path.platformPath();
QPainter* p = static_cast<QPainter*>(c->platformContext());
if (state().m_strokeStyle->canvasGradient()) {
p->save();
p->setBrush(*(state().m_strokeStyle->canvasGradient()->gradient().platformGradient()));
p->strokePath(*path, p->pen());
p->restore();
} else {
if (state().m_strokeStyle->pattern())
applyStrokePattern();
p->strokePath(*path, p->pen());
}
#elif PLATFORM(CAIRO) && !PLATFORM(BAL)
cairo_t* cr = c->platformContext();
cairo_save(cr);
if (state().m_strokeStyle->canvasGradient()) {
cairo_set_source(cr, state().m_strokeStyle->canvasGradient()->gradient().platformGradient());
c->addPath(m_path);
cairo_stroke(cr);
} else {
if (state().m_strokeStyle->pattern())
applyStrokePattern();
c->addPath(m_path);
cairo_stroke(cr);
}
cairo_restore(cr);
#elif PLATFORM(BAL)
//FIXME
notImplemented();
#endif
#if ENABLE(DASHBOARD_SUPPORT)
clearPathForDashboardBackwardCompatibilityMode();
#endif
}
示例11: Q_UNUSED
void Q3PlotAxis::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPainter painter;
painter.begin(this);
painter.setPen(Qt::white);
QFontMetrics fm(font());
QVector<int> tp = tickPositions();
int margin = Q3PlotFrameContainer::Margin;
switch (position_) {
case Q3PlotFrame::PositionLeft:
if (labelsVisible_) {
for (int i = 0; i < ticks_.count(); ++i) {
if (tp[i] + margin - fm.height() / 3. < 0
|| tp[i] + margin + fm.height() / 3. > height()) {
continue;
}
painter.drawText(QPointF(width() - margin - fm.width(labels_[i]) - 1,
tp[i] + margin + fm.height() / 3),
labels_[i]);
}
}
break;
case Q3PlotFrame::PositionTop:
if (labelsVisible_) {
for (int i = 0; i < ticks_.count(); ++i) {
if (tp[i] + margin - fm.width(labels_[i]) / 2 < 0
|| tp[i] + margin + fm.width(labels_[i]) / 2 > width()) {
continue;
}
painter.drawText(QPointF(tp[i] + margin - fm.width(labels_[i]) / 2,
height() - margin - 1), labels_[i]);
}
}
break;
case Q3PlotFrame::PositionRight:
if (labelsVisible_) {
for (int i = 0; i < ticks_.count(); ++i) {
if (tp[i] + margin - fm.height() / 3. < 0
|| tp[i] + margin + fm.height() / 3. > height()) {
continue;
}
painter.drawText(QPointF(margin, tp[i] + margin + fm.height() / 3),
labels_[i]);
}
}
break;
case Q3PlotFrame::PositionBottom:
if (labelsVisible_) {
for (int i = 0; i < ticks_.count(); ++i) {
if (tp[i] + margin - fm.width(labels_[i]) / 2 < 0
|| tp[i] + margin + fm.width(labels_[i]) / 2 > width()) {
continue;
}
painter.drawText(QPointF(tp[i] + margin - fm.width(labels_[i]) / 2,
margin + 2. / 3. * fm.height()), labels_[i]);
}
}
break;
}
painter.end();
}
示例12: paintPoints
void HoverPoints::paintPoints()
{
QPainter p;
#ifdef QT_OPENGL_SUPPORT
ArthurFrame *af = qobject_cast<ArthurFrame *>(m_widget);
if (af && af->usesOpenGL())
p.begin(af->glWidget());
else
p.begin(m_widget);
#else
p.begin(m_widget);
#endif
p.setRenderHint(QPainter::Antialiasing);
if (m_connectionPen.style() != Qt::NoPen && m_connectionType != NoConnection) {
p.setPen(m_connectionPen);
if (m_connectionType == CurveConnection) {
QPainterPath path;
path.moveTo(m_points.at(0));
for (int i=1; i<m_points.size(); ++i) {
QPointF p1 = m_points.at(i-1);
QPointF p2 = m_points.at(i);
qreal distance = p2.x() - p1.x();
path.cubicTo(p1.x() + distance / 2, p1.y(),
p1.x() + distance / 2, p2.y(),
p2.x(), p2.y());
}
p.drawPath(path);
} else {
p.drawPolyline(m_points);
}
}
p.setPen(m_pointPen);
p.setBrush(m_pointBrush);
for (int i=0; i<m_points.size(); ++i) {
QRectF bounds = pointBoundingRect(i);
if (m_shape == CircleShape)
p.drawEllipse(bounds);
else
p.drawRect(bounds);
}
}
示例13: setCursor
//---------------------------------------------------------------
void SkewTWindow::actionsCommonSlot ()
{
setCursor (Qt::WaitCursor);
QObject *send = sender ();
if (send == acExit) {
this->hide ();
this->destroy ();
if (skewt) {
delete skewt;
skewt = nullptr;
}
}
else if (send == cbTempMax) {
int v = cbTempMax->itemData (cbTempMax->currentIndex()).toInt();
Util::setSetting ("skewt_tempCMax", v);
skewt->setTempPressLimits (v, skewt->getHpaMin());
}
else if (send == cbHpaMin) {
int v = cbHpaMin->itemData (cbHpaMin->currentIndex()).toInt();
Util::setSetting ("skewt_hpaMin", v);
skewt->setTempPressLimits (skewt->getTempCMax(), v-10);
}
else if (send == cbSizeW) {
double sz = cbSizeW->itemData (cbSizeW->currentIndex()).toDouble();
Util::setSetting ("skewt_sizeW", sz);
skewt->setSkewTSize (sz, skewt->height());
}
else if (send == cbSizeH) {
double sz = cbSizeH->itemData (cbSizeH->currentIndex()).toDouble();
Util::setSetting ("skewt_sizeH", sz);
skewt->setSkewTSize (skewt->width(), sz);
}
else if (send == cbConvBase) {
QString cbase = cbConvBase->itemData (cbConvBase->currentIndex()).toString();
Util::setSetting ("skewt_convectiveBase", cbase);
skewt->setConvectiveBase (cbase);
}
else if (send == chkShowConv) {
Util::setSetting ("skewt_showConvectiveCurves", chkShowConv->isChecked());
skewt->resetGraphic ();
cbConvBase->setEnabled (chkShowConv->isChecked());
}
else if (send == acPrint) {
QPrinter printer;
printer.setOutputFormat (QPrinter::PdfFormat);
printer.setResolution (150);
QPrintDialog *dialog = new QPrintDialog(&printer, this);
dialog->setWindowTitle (tr("Print Document"));
if (dialog->exec() == QDialog::Accepted)
{
QPainter painter;
painter.begin(&printer);
double xscale = printer.pageRect().width()/double(skewt->width());
double yscale = printer.pageRect().height()/double(skewt->height());
double scale = qMin(xscale, yscale);
painter.translate(printer.paperRect().x() + printer.pageRect().width()/2,
printer.paperRect().y() + printer.pageRect().height()/2);
painter.scale(scale, scale);
painter.translate(-skewt->width()/2, -skewt->height()/2);
skewt->setPrinterRendering (true);
skewt->render (&painter);
skewt->setPrinterRendering (false);
}
}
else if (send == acSaveImage) {
QString filename = Util::getSetting("skewt_imageSaveFilename", "").toString();
filename = Util::getSaveFileName (this,
tr("Save JPEG image"),
filename,
tr("Images (*.jpg *.jpeg)") );
if (filename != "") {
if ( ! filename.endsWith(".jpg", Qt::CaseInsensitive)
&& ! filename.endsWith(".jpeg", Qt::CaseInsensitive) )
filename += ".jpg";
Util::setSetting("skewt_imageSaveFilename", filename);
QImage image (skewt->size(), QImage::Format_RGB32);
skewt->setPrinterRendering (true);
skewt->render (&image);
skewt->setPrinterRendering (false);
image.save (filename, "JPEG", 96);
}
}
else if (send == acExportData) {
QString path = Util::getSetting("slkFilePath", "").toString();
if (path == "")
path = "./";
else
path += "/";
QString fileName;
fileName = Util::getSaveFileName (this,
tr("Save SYLK file"), path, "*.slk");
if (fileName != "")
{
if (! fileName.endsWith(".slk", Qt::CaseInsensitive))
fileName += ".slk";
SylkFile slk (fileName, "XyGrib");
//.........这里部分代码省略.........
示例14: draw_bbox
/**
coloridx: 0 - yellow, 1 - red, 2 - green, 3 - blue, if < 0 - only position without bounding box is drawn
*/
void draw_bbox(QPainter &painter, const PartBBox &part_bbox, int coloridx, int pen_width)
{
if (coloridx >= 0) {
painter.setPen(Qt::yellow);
int marker_radius = 3;
int part_axis_length = 10;
painter.drawEllipse(QRect((int)(part_bbox.part_pos(0) - marker_radius), (int)(part_bbox.part_pos(1) - marker_radius),
2*marker_radius, 2*marker_radius));
boost_math::double_vector v(2);
v = part_bbox.part_pos + part_axis_length * part_bbox.part_x_axis;
painter.drawLine((int)part_bbox.part_pos(0), (int)part_bbox.part_pos(1), (int)v(0), (int)v(1));
painter.setPen(Qt::red);
v = part_bbox.part_pos + part_axis_length * part_bbox.part_y_axis;
painter.drawLine((int)part_bbox.part_pos(0), (int)part_bbox.part_pos(1), (int)v(0), (int)v(1));
painter.setPen(Qt::yellow);
QPen pen;
if (coloridx == 0)
pen.setColor(Qt::yellow);
else if (coloridx == 1)
pen.setColor(Qt::red);
else if (coloridx == 2)
pen.setColor(Qt::green);
else if (coloridx == 3)
pen.setColor(Qt::blue);
else
pen.setColor(Qt::black);
pen.setJoinStyle(Qt::RoundJoin);
pen.setWidth(pen_width);
painter.setPen(pen);
QPolygonF polygon;
get_part_polygon(part_bbox, polygon);
painter.drawPolygon(polygon);
}
else {
painter.setPen(Qt::yellow);
if (coloridx == -1)
painter.setPen(Qt::yellow);
else if (coloridx == -2)
painter.setPen(Qt::red);
else if (coloridx == -3)
painter.setPen(Qt::green);
else
painter.setPen(Qt::blue);
int x = part_bbox.part_pos(0);
int y = part_bbox.part_pos(1);
painter.drawLine(x-1, y, x+1, y);
painter.drawLine(x, y-1, x, y+1);
}
}
示例15: paintBackground
void ManoMeter::paintBackground(QPainter & painter)
{
static const int scaleTriangle[6] = { -6,141,6,141,0,129 };
initCoordinateSystem(painter);
// Painting Malowanie obwiedni tarczy. Bia�a tarcza z czarn� skal�
QPen Pen(QColor(0,0,0)); Pen.setWidth(4);
painter.setPen(Pen);
QRadialGradient back1(QPointF(0.0,0.0),180.0,QPointF(-35.0,145.0));
back1.setColorAt(0.0,QColor(250,250,250));
back1.setColorAt(1.0,QColor(20,20,20));
QRadialGradient back2(QPointF(0.0,0.0),225.0,QPointF(76.5,135.0));
back2.setColorAt(0.0,QColor(10,10,10));
back2.setColorAt(1.0,QColor(250,250,250));
painter.setBrush(QBrush(back1));
painter.drawEllipse(-162,-162,324,324);
painter.setPen(Qt::NoPen);
painter.setBrush(QBrush(back2));
painter.drawEllipse(-152,-152,304,304);
QRadialGradient shield(QPointF(0,0),182,QPointF(-12.0,-15.0));
shield.setColorAt(0.0,Qt::white);
shield.setColorAt(0.5,QColor(240,240,240));
shield.setColorAt(1.0,QColor(215,215,215));
// internal scale circle
painter.setBrush(QBrush(shield));
painter.setPen(Pen);
painter.drawEllipse(-142,-142,284,284);
painter.setPen(Qt::NoPen);
// nominal
painter.setBrush(QColor(0,200,0));
assert(m_max-m_min != 0);
int angle = static_cast<int>( (3840 * ( m_nominal - m_min ))/(m_max-m_min) );
if (m_min <= m_nominal && m_nominal < m_max )
painter.drawPie(QRect(-141,-141,282,282),-480,3840 - angle % 5760 );
// Critical
painter.setBrush(QBrush(Qt::red));
angle = static_cast<int>( (3840 * ( m_critical - m_min ))/(m_max-m_min) );
if ( m_min <= m_critical && m_critical < m_max )
painter.drawPie(QRect(-141,-141,282,282),-480, 3840 - angle % 5760 ); //-480, 3840*( m_max-m_min - critical()-abs(m_min) )/static_cast<double>(m_max-m_min));
// bia�a obwiednia
painter.setBrush(QBrush(shield));
painter.drawEllipse(-129,-129,258,258);
// Ustawienie si� na pocz�tku skali
painter.rotate(60.0);
// Rysowanie skali kreski
painter.save();
painter.setBrush(QBrush(Qt::black));
int line_length=10;
for (int i=0;i<33;i++)
{
painter.setPen(Pen);
if (i % 4) painter.drawLine(0,140,0,140-line_length);
else {
painter.setPen(Qt::NoPen);
painter.drawConvexPolygon(QPolygon(3, scaleTriangle));
}
painter.rotate(7.5);
Pen.setWidth(3);
if (i % 2) line_length=10;
else line_length=5;
}
painter.restore();
// Rysowanie skali liczby .
if (true || digitOffset())
{
painter.setPen(Qt::black);
painter.rotate(-60.0);
painter.setFont(digitFont());
for (int i=0;i<9;i++)
{
double v = m_min + i*(m_max - m_min)/8.0;
if (fabs(v) < 0.000001 ) v = 0.0;
QString val = QString("%1").arg(v);
QSize Size = painter.fontMetrics().size(Qt::TextSingleLine, val);
painter.save();
painter.translate( digitOffset() * cos((5+i)*PI/6.0), digitOffset() * sin((5+i)*PI/6.0));
painter.drawText( QPointF( Size.width()/ -2.0, Size.height() / 4.0), val);
painter.restore();
}
}
//.........这里部分代码省略.........