本文整理汇总了C++中QPainter::device方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainter::device方法的具体用法?C++ QPainter::device怎么用?C++ QPainter::device使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainter
的用法示例。
在下文中一共展示了QPainter::device方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintEvent
void PanelRadar::paintEvent(QPaintEvent* event) {
const qreal scale0 = 0.14644660940672623779957781894758;
const qreal scale1 = (1.0 - scale0);
PanelWidget::paintEvent(event);
QPainter p;
p.begin(this);
setMargins(&p);
p.setRenderHint(QPainter::Antialiasing, true);
p.setRenderHint(QPainter::TextAntialiasing, true);
QPen pen = p.pen();
pen.setWidth(1);
p.setPen(QColor("black"));
QPainterPath path;
qreal rx = p.device()->width();
qreal ry = p.device()->height();
QPointF point(0.5 * rx, 0.5 * ry);
path.addEllipse(point, 0.50 * rx, 0.50 * ry);
p.fillPath(path, QColor("white"));
path.addEllipse(point, 0.25 * rx, 0.25 * ry);
p.drawPath(path);
p.drawLine(0, 0.5 * ry, rx, 0.5 * ry);
p.drawLine(0.5 * rx, 0, 0.5 * rx, ry);
p.drawLine(rx * scale0 + 1, ry * scale0 + 1, rx * scale1 - 1, ry * scale1 - 1);
p.drawLine(rx * scale0 + 1, ry * scale1 - 1, rx * scale1 - 1, ry * scale0 + 1);
drawItems(&p);
p.end();
}
示例2: paint
void paint(QPainter &painter){
painter.setRenderHint(QPainter::Antialiasing,true);
const T w=painter.device()->width();
const T h=painter.device()->height();
QPen base(QBrush(Qt::NoBrush),2);
QPen brown(base);
brown.setWidthF(0.01);
brown.setStyle(Qt::SolidLine);
brown.setColor(QColor("brown"));
QPen green(base);
green.setWidthF(0.04);
green.setColor(QColor("green"));
QPen purple(base);
purple.setWidthF(0.01);
purple.setColor(QColor("purple").darker());
painter.translate(w/2,h/2);
qreal s=qMin(w,h);
painter.scale(s,s);
T step=0.02;
T gx=cx/step;
gx-=floor(gx);
gx*=-step;
T gy=cy/step;
gy-=floor(gy);
gy*=-step;
painter.setPen(brown);
for(T y=gy-h;y<h;y+=step){
painter.drawLine(QPointF(0,y-1),QPointF(w,y+1));
}
for(T x=gx-w;x<w;x+=step){
painter.drawLine(QPointF(x-1,0),QPointF(x+1,h));
}
if(singleLimbMode){
limbs[0]->paint(painter);
}
else{
for(quint32 i=0;i<limbCount;++i){
limbs[i]->paint(painter);
}
const T r=0.01;
QPointF cob(cobx,coby);
painter.setPen(green);
painter.drawEllipse(cob,r,r);
QPointF cog(cogx,cogy);
painter.setPen(purple);
painter.drawEllipse(cog,r,r);
}
}
示例3: drawImage
void ImageDisplayer::drawImage(QPainter &painter)
{
if(img.data != NULL) {
//QRectF target(0.0f, 0.0f, this->width()*2*(1+zoomFactor/10.0), this->height()*2*(1+zoomFactor/10.0));
//cout << painter.device()->width() << endl;
//cout << painter.device()->height() << endl;
QRectF source(0.0f, 0.0f, painter.device()->width(), painter.device()->height());
QRectF target(source);
//painter.drawImage(target, temImage, source);
painter.drawImage(source, qimg);
}
}
示例4: Draw
extern "C" VIS_SPECTSHARED_EXPORT void Draw(QPainter &paint, float *fft ){
paint.fillRect(0, 0, paint.device()->width(), paint.device()->height(), QColor(0x00, 0x00, 0x00));
paint.setPen(QColor(0x00, 0xff, 0x00));
float c = 0;
int h = 0;
int j1 = 0;
for(int i = 0, j = 0; i < 1024; i+=8, j++){
for(int l = 0; l < 8; l+=2){
c += fft[i+l];
}
c = c / 4; //вычисление среднего из 4х "соседних частот"
h = (int)(paint.device()->height() - (c * 10 * paint.device()->height() * 3));
if(h < (paint.device()->height() / 2)){
h = (int)((paint.device()->height() / 2) + (h / 10)); //"урезание"
}
if(h <= pik[j]){
pik[j] = h - 2;
}
j1 = j * 2;
paint.drawLine(j1, paint.device()->height(), j1, h);
j1++;
paint.drawLine(j1, paint.device()->height(), j1, h);
c = 0;
}
for(int k = 0; k < 128; k++){
pik[k]+=2;
}
paint.setPen(QColor(0xff, 0x00, 0x00));
for(int k = 0; k < 128; k++){
paint.drawLine(k * 2 + 1, pik[k], k * 2 + 2, pik[k+1]);
}
}
示例5: paintImage
//void Object::paintImage(QPainter &painter, int frameNumber, const QRectF &source, const QRectF &target, bool background, qreal curveOpacity, bool antialiasing, bool niceGradients) {
void Object::paintImage(QPainter& painter, int frameNumber, bool background, qreal curveOpacity, bool antialiasing, int gradients)
{
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
//painter.setWorldMatrix(matrix);
painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
// paints the background
if (background)
{
painter.setPen(Qt::NoPen);
painter.setBrush(Qt::white);
painter.setWorldMatrixEnabled(false);
painter.drawRect( QRect(0,0, painter.device()->width(), painter.device()->height() ) );
painter.setWorldMatrixEnabled(true);
}
for(int i=0; i < getLayerCount(); i++)
{
Layer* layer = getLayer(i);
if (layer->visible)
{
painter.setOpacity(1.0);
// paints the bitmap images
if (layer->type == Layer::BITMAP)
{
LayerBitmap* layerBitmap = (LayerBitmap*)layer;
/*BitmapImage* bitmapImage = layerBitmap->getLastBitmapImageAtFrame(frameNumber, 0);
// TO BE FIXED
if (bitmapImage != NULL) {
if ( mirror) {
painter.drawImage(target, (*(bitmapImage->image)).mirrored(true, false), source);
} else {
painter.drawImage(target, *(bitmapImage->image), source);
}
}*/
layerBitmap->getLastBitmapImageAtFrame(frameNumber, 0)->paintImage(painter);
}
// paints the vector images
if (layer->type == Layer::VECTOR)
{
LayerVector* layerVector = (LayerVector*)layer;
layerVector->getLastVectorImageAtFrame(frameNumber, 0)->paintImage(painter, false, false, curveOpacity, antialiasing, gradients);
}
}
}
}
示例6: metrics
/*!
* \en
* Print browser content.
* \_en
* \ru
* Печатает содержимое браузера.
* \_ru
*/
void
aReportBrowser::print()
{
QPrinter printer;
QPainter p;
if (!printer.setup()) return;
if ( p.begin( &printer ) ){
QPaintDeviceMetrics metrics( p.device() );
int dpiy = metrics.logicalDpiY();
int margin = (int) ( (2/2.54)*dpiy ); // 2 cm margins
QRect body( margin, margin, metrics.width() - 2*margin, metrics.height() - 2*margin );
QSimpleRichText richText( textBrowser->text(),
QFont(),
textBrowser->context(),
textBrowser->styleSheet(),
textBrowser->mimeSourceFactory(),
body.height() );
richText.setWidth( &p, body.width() );
QRect view( body );
int page = 1;
do {
richText.draw( &p, body.left(), body.top(), view, colorGroup() );
view.moveBy( 0, body.height() );
p.translate( 0 , -body.height() );
p.drawText( view.right() - p.fontMetrics().width( QString::number( page ) ),
view.bottom() + p.fontMetrics().ascent() + 5, QString::number( page ) );
if ( view.top() >= richText.height() )
break;
printer.newPage();
page++;
} while (TRUE);
}
}
示例7: beginTransparencyLayer
void GraphicsContext::beginTransparencyLayer(float opacity)
{
if (paintingDisabled())
return;
int x, y, w, h;
x = y = 0;
QPainter *p = m_data->p();
const QPaintDevice *device = p->device();
w = device->width();
h = device->height();
QRectF clip = p->clipPath().boundingRect();
bool ok;
QTransform transform = p->transform().inverted(&ok);
if (ok) {
QRectF deviceClip = transform.mapRect(clip);
x = int(qBound(qreal(0), deviceClip.x(), (qreal)w));
y = int(qBound(qreal(0), deviceClip.y(), (qreal)h));
w = int(qBound(qreal(0), deviceClip.width(), (qreal)w) + 2);
h = int(qBound(qreal(0), deviceClip.height(), (qreal)h) + 2);
}
TransparencyLayer * layer = new TransparencyLayer(m_data->p(), QRect(x, y, w, h));
layer->opacity = opacity;
m_data->layers.push(layer);
}
示例8: draw
void PictureImage::draw(QPainter& painter, int x, int y, int width, int height, int sx, int sy, int sw, int sh, bool fastMode)
{
//kDebug(30508) <<"KoImage::draw currentSize:" << currentSize.width() <<"x" << currentSize.height();
if (!width || !height)
return;
QSize origSize = getOriginalSize();
const bool scaleImage = dynamic_cast<QPrinter*>(painter.device()) != 0 // we are printing
&& ((width <= origSize.width()) || (height <= origSize.height()));
if (scaleImage) {
// use full resolution of image
qreal xScale = qreal(width) / qreal(origSize.width());
qreal yScale = qreal(height) / qreal(origSize.height());
painter.save();
painter.translate(x, y);
painter.scale(xScale, yScale);
// Note that sx, sy, sw and sh are unused in this case. Not a problem, since it's about printing.
// Note 2: we do not cache the QPixmap. As we are printing, the next time we will probably
// need again the screen version.
painter.drawImage(0, 0, m_originalImage);
painter.restore();
} else {
QSize screenSize(width, height);
//kDebug(30508) <<"PictureImage::draw screenSize=" << screenSize.width() <<"x" << screenSize.height();
scaleAndCreatePixmap(screenSize, fastMode);
// sx,sy,sw,sh is meant to be used as a cliprect on the pixmap, but drawPixmap
// translates it to the (x,y) point -> we need (x+sx, y+sy).
painter.drawPixmap(x + sx, y + sy, m_cachedPixmap, sx, sy, sw, sh);
}
}
示例9: QSize
void Plot2D::reCalcGui(QPainter &dc)
{
dm_dirty = false;
// calc the off set stuff
dm_offset.rx() = border*2;
dm_offset.ry() = border;
dm_area = QSize(dc.device()->width(), dc.device()->height());
dm_area.rwidth() += -3 * border;
dm_area.rheight() += -2 * border;
// calc the min max
bool clean_slate = true;
for (int i=0; i<dm_data.size(); ++i) {
double d;
if (dm_data[i].xvalues.empty())
continue;
scopira::basekit::min(dm_data[i].xvalues, d);
if (clean_slate || d < dm_data_xmin)
dm_data_xmin = d;
scopira::basekit::max(dm_data[i].xvalues, d);
if (clean_slate || d > dm_data_xmax)
dm_data_xmax = d;
scopira::basekit::min(dm_data[i].yvalues, d);
if (clean_slate || d < dm_data_ymin)
dm_data_ymin = d;
scopira::basekit::max(dm_data[i].yvalues, d);
if (clean_slate || d > dm_data_ymax)
dm_data_ymax = d;
clean_slate = false;
}
dm_emptydata = clean_slate || dm_data_xmin >= dm_data_xmax || dm_data_ymin >= dm_data_ymax;
if (dm_xrange_auto) {
dm_view_xmin = dm_data_xmin;
dm_view_xmax = dm_data_xmax;
}
if (dm_yrange_auto) {
dm_view_ymin = dm_data_ymin;
dm_view_ymax = dm_data_ymax;
}
}
示例10: paintImage
void Object::paintImage( QPainter& painter, int frameNumber,
bool background,
bool antialiasing )
{
painter.setRenderHint( QPainter::Antialiasing, true );
painter.setRenderHint( QPainter::SmoothPixmapTransform, true );
//painter.setTransform(matrix);
painter.setCompositionMode( QPainter::CompositionMode_SourceOver );
// paints the background
if ( background )
{
painter.setPen( Qt::NoPen );
painter.setBrush( Qt::white );
painter.setWorldMatrixEnabled( false );
painter.drawRect( QRect( 0, 0, painter.device()->width(), painter.device()->height() ) );
painter.setWorldMatrixEnabled( true );
}
for ( int i = 0; i < getLayerCount(); i++ )
{
Layer* layer = getLayer( i );
if ( layer->visible )
{
painter.setOpacity( 1.0 );
// paints the bitmap images
if ( layer->type() == Layer::BITMAP )
{
LayerBitmap* layerBitmap = ( LayerBitmap* )layer;
layerBitmap->getLastBitmapImageAtFrame( frameNumber, 0 )->paintImage( painter );
}
// paints the vector images
if ( layer->type() == Layer::VECTOR )
{
LayerVector* layerVector = ( LayerVector* )layer;
layerVector->getLastVectorImageAtFrame( frameNumber, 0 )->paintImage( painter,
false,
false,
antialiasing );
}
}
}
}
示例11: render
void Stickman::render(QPainter &painter) const
{
// Draw the stickman at the bottom of the screen
int yPos = painter.device()->height() - getHeight();
// Find how much to scale the sprite image by to match the bounding box of the stickman
// If x velocity is negative, we flip the image as well.
float scaleX = getWidth() / getSprite().width() * (m_xVelocity < 0 ? -1 : 1);
float scaleY = getHeight() / getSprite().height();
painter.drawPixmap(m_xOffset, yPos, getSprite().transformed(QTransform().scale(scaleX, scaleY)));
}
示例12: Init
void SurfaceImpl::Init(SurfaceID sid, WindowID)
{
Release();
// This method, and the SurfaceID type, is only used when printing. As it
// is actually a void * we pass (when using SCI_FORMATRANGE) a pointer to a
// QPainter rather than a pointer to a SurfaceImpl as might be expected.
QPainter *p = reinterpret_cast<QPainter *>(sid);
pd = p->device();
painter = p;
}
示例13:
static void
draw_measure(const vmd_measure_t *measure, void *_painter)
{
QPainter *painter = static_cast<QPainter *>(_painter);
WPiano *piano = static_cast<WPiano *>(painter->device());
vmd_time_t cell_size = piano->grid_size() > 0 ? piano->grid_size() : measure->part_size;
painter->setPen(piano->palette().windowText().color());
for (vmd_time_t t = measure->beg; t < measure->end; t += cell_size) {
int x = piano->time2x(t);
painter->drawLine(x, 0, x, piano->height());
painter->setPen(piano->palette().mid().color());
}
}
示例14: drawVertCmRuler
static void drawVertCmRuler(QPainter &painter, int x, int y1, int y2)
{
painter.drawLine(x, y1, x, y2);
const int dpI = painter.device()->logicalDpiY();
const int dpCm = qRound(double(dpI) / 2.54);
const int h = dpCm / 2;
const QFontMetrics fm(painter.font());
for (int cm = 0, y = y1; y < y2; y += dpCm, ++cm) {
painter.drawLine(x, y, x + h, y);
if (cm) {
const QString n = QString::number(cm);
const QRect br = fm.boundingRect(n);
painter.drawText(x + h + 10, y + br.height() / 2, n);
}
}
}
示例15: drawHorizCmRuler
static void drawHorizCmRuler(QPainter &painter, int x1, int x2, int y)
{
painter.drawLine(x1, y, x2, y);
const int dpI = painter.device()->logicalDpiX();
const int dpCm = qRound(double(dpI) / 2.54);
const int h = dpCm / 2;
const QFontMetrics fm(painter.font());
for (int cm = 0, x = x1; x < x2; x += dpCm, ++cm) {
painter.drawLine(x, y, x, y - h);
if (cm) {
const QString n = QString::number(cm);
const QRect br = fm.boundingRect(n);
painter.drawText(x - br.width() / 2, y - h - 10, n);
}
}
}