本文整理汇总了C++中QWMatrix::translate方法的典型用法代码示例。如果您正苦于以下问题:C++ QWMatrix::translate方法的具体用法?C++ QWMatrix::translate怎么用?C++ QWMatrix::translate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QWMatrix
的用法示例。
在下文中一共展示了QWMatrix::translate方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: show
/*
void KColorGrid::show()
{
//updateScrollBars();
QWidget::show();
}
*/
void KColorGrid::paintEvent(QPaintEvent *e)
{
//kdDebug(4640) << "KColorGrid::paintEvent" << endl;
//updateScrollBars();
//QWidget::paintEvent(e);
const QRect urect = e->rect();
//kdDebug(4640) << "Update rect = ( " << //urect.left() << ", " << urect.top() << ", " << urect.width() << ", " << urect.height() << " )" << endl;
int firstcol = getX(urect.x())-1;
int firstrow = getY(urect.y())-1;
int lastcol = getX(urect.right())+1;
int lastrow = getY(urect.bottom())+1;
QWMatrix matrix;
QPixmap pm(urect.width(),urect.height());
pm.fill(paletteBackgroundColor());
QPainter p;
p.begin( &pm );
firstrow = (firstrow < 0) ? 0 : firstrow;
firstcol = (firstcol < 0) ? 0 : firstcol;
lastrow = (lastrow >= rows) ? rows : lastrow;
lastcol = (lastcol >= cols) ? cols : lastcol;
//kdDebug(4640) << urect.x() << " x " << urect.y() << " - row: " << urect.width() << " x " << urect.height() << endl;
//kdDebug(4640) << "col: " << firstcol << " -> " << lastcol << " - row: " << firstrow << " -> " << lastrow << endl;
/*
if(this->isA("KDrawGrid"))
kdDebug(4640) << "KDrawGrid\n firstcol: " << firstcol << "\n lastcol: " << lastcol << "\n firstrow: " << firstrow << "\n lastrow: " << lastrow << endl;
*/
for(int i = firstrow; i < lastrow; i++)
{
//if(this->isA("KDrawGrid"))
// kdDebug(4640) << "Updating row " << i << endl;
for(int j = firstcol; j < lastcol; j++)
{
matrix.translate( (j*cellsize)-urect.x(), (i*cellsize)-urect.y() );
p.setWorldMatrix( matrix );
//p.setClipRect(j*cellsize, i*cellsize, cellsize, cellsize);
paintCell(&p, i, j);
//p.setClipping(FALSE);
matrix.reset();
p.setWorldMatrix( matrix );
}
//kapp->processEvents();
}
matrix.translate(-urect.x(),-urect.y());
p.setWorldMatrix( matrix );
paintForeground(&p,e);
p.end();
bitBlt(this,urect.topLeft(),&pm,QRect(0,0,pm.width(),pm.height()));
}
示例2: drawColorWheel
void drawColorWheel( QPainter *p )
{
QFont f( "times", 18, QFont::Bold );
p->setFont( f );
p->setPen( Qt::black );
p->setWindow( 0, 0, 500, 500 ); // defines coordinate system
for ( int i=0; i<36; i++ ) { // draws 36 rotated rectangles
QWMatrix matrix;
matrix.translate( 250.0F, 250.0F ); // move to center
matrix.shear( 0.0F, 0.3F ); // twist it
matrix.rotate( (float)i*10 ); // rotate 0,10,20,.. degrees
p->setWorldMatrix( matrix ); // use this world matrix
QColor c;
c.setHsv( i*10, 255, 255 ); // rainbow effect
p->setBrush( c ); // solid fill with color c
p->drawRect( 70, -10, 80, 10 ); // draw the rectangle
QString n;
n.sprintf( "H=%d", i*10 );
p->drawText( 80+70+5, 0, n ); // draw the hue number
}
}
示例3: drawRect
QRect GuiPart::drawRect()
{
QRect dr = rect();
if ( m_angleDegrees%180 != 0 )
{
QWMatrix m;
m.translate( int(x()+(width()/2)), int(y()+(height()/2)) );
if ( (m_angleDegrees%180) != 0 )
m.rotate(-m_angleDegrees);
m.translate( -int(x()+(width()/2)), -int(y()+(height()/2)) );
dr = m.mapRect(dr);
}
return dr;
}
示例4: getGradientPixmap
QPixmap ClsBaseQStateArrayView::getGradientPixmap(int iImgWidth, int iImgHeight, int _iColorMode ) {
#ifdef DEBUG_CLSBASEQSTATEARRAYVIEW
cout << "ClsBaseQStateArrayView::getGradientPixmap(int iImgWidth, int iImgHeight)" << endl;
#endif
// int iColorMode = ClsBaseQStateArrayView::GRAY;
// int iColorMode = ClsBaseQStateArrayView::BLUE2RED;
// int iColorMode = ClsBaseQStateArrayView::HSV;
QPixmap pmGradient;
QPainter* paintGradient = new QPainter();
QWMatrix mxRot;
int iDiag = (int)(sqrt(double(iImgWidth * iImgWidth + iImgHeight * iImgHeight))/2.);
pmGradient.resize(2 * iDiag, 2 * iDiag);
paintGradient->begin(&pmGradient);
paintGradient->setWindow( 0, 0, 2 * iDiag, 2 * iDiag );
int iNrSices = 50;
for ( int i=0; i<iNrSices; i++ ) {
paintGradient->setWorldMatrix( mxRot );
QColor c;
if(_iColorMode == ClsBaseQStateArrayView::GRAY){
c.setRgb( i* 255 / iNrSices, i* 255 / iNrSices, i* 255 / iNrSices );
}
else if(_iColorMode == ClsBaseQStateArrayView::BLUE2RED){
if(i<iNrSices/2){
/* BLUE */
c.setRgb(0, 0, 255 - i * 510/iNrSices);
}
else {
/* RED */
c.setRgb( (i - iNrSices/2) * 255/(iNrSices/2), 0,0);
}
}
else {
c.setHsv( i* 360 / iNrSices, 255, 255 );
}
paintGradient->setBrush( c );
paintGradient->setPen( c );
//zzz QPointArray a;
QPolygon a;
a.setPoints( 4,
0, 0,
iDiag * 2 / iNrSices, 0,
iDiag * 2 / iNrSices, iDiag * 2,
0, iDiag * 2 );
paintGradient->drawPolygon( a );
mxRot.translate( (double)iDiag * 2.0 / (double)iNrSices, 0.0 );
}
paintGradient->end();
return pmGradient;
}
示例5: updateWorldMatrix
void CVBEditor::updateWorldMatrix() {
double z = p_itemView->zoomLevel();
QRect r = m_pCanvas->rect();
// QWMatrix m( z, 0.0, 0.0, z, -r.left(), -r.top() );
// QWMatrix m( z, 0.0, 0.0, z, 0.0, 0.0 );
QWMatrix m;
m.scale(z, z);
m.translate(-r.left(), -r.top());
setWorldMatrix(m);
}
示例6: show
/*
void KColorGrid::show()
{
//updateScrollBars();
QWidget::show();
}
*/
void KColorGrid::paintEvent(QPaintEvent *e)
{
//debug("KColorGrid::paintEvent");
//updateScrollBars();
//QWidget::paintEvent(e);
const QRect urect = e->rect();
//debug("Update rect = ( %i, %i, %i, %i )",
//urect.left(),urect.top(), urect.width(), urect.height() );
int firstcol = getX(urect.x())-1;
int firstrow = getY(urect.y())-1;
int lastcol = getX(urect.right())+1;
int lastrow = getY(urect.bottom())+1;
QWMatrix matrix;
QPainter p;
p.begin( this );
firstrow = (firstrow < 0) ? 0 : firstrow;
firstcol = (firstcol < 0) ? 0 : firstcol;
lastrow = (lastrow >= rows) ? rows : lastrow;
lastcol = (lastcol >= cols) ? cols : lastcol;
//debug("%d x %d - row: %d x %d", urect.x(), urect.y(), urect.width(), urect.height());
//debug("col: %d -> %d - row: %d -> %d", firstcol, lastcol, firstrow, lastrow);
/*
if(this->isA("KDrawGrid"))
debug("KDrawGrid\n firstcol: %d\n lastcol: %d\n firstrow: %d\n lastrow: %d",
firstcol, lastcol, firstrow, lastrow);
*/
for(int i = firstrow; i < lastrow; i++)
{
//if(this->isA("KDrawGrid"))
// debug("Updating row %d", i);
for(int j = firstcol; j < lastcol; j++)
{
matrix.translate( (j*cellsize), (i*cellsize) );
p.setWorldMatrix( matrix );
//p.setClipRect(j*cellsize, i*cellsize, cellsize, cellsize);
paintCell(&p, i, j);
//p.setClipping(FALSE);
matrix.reset();
p.setWorldMatrix( matrix );
}
//kapp->processEvents();
}
p.end();
}
示例7: updateCell
void KColorGrid::updateCell( int row, int col, bool erase )
{
//debug("updateCell - before repaint");
QWMatrix matrix;
QPainter p;
p.begin( this );
matrix.translate( (col*cellsize), (row*cellsize) );
p.setWorldMatrix( matrix );
paintCell(&p, row, col);
p.end();
}
示例8: drawPathText
void drawPathText( QPainter *p )
{
QPointArray a( 4 );
a.setPoint( 0, 100,200 );
a.setPoint( 1, 150,75 );
a.setPoint( 2, 250,75 );
a.setPoint( 3, 300,200 );
a = a.quadBezier(); // calculate Bezier curve
p->setPen( lightGray ); // set light gray pen
p->drawPolyline( a ); // draw Bezier point array
p->setFont( QFont("Times",24) ); // set fast font
p->setPen( black ); // set black pen
const char *text = "Troll Tech AS";
int len = strlen(text);
if ( len == 0 )
return;
int ipos = a.size()/len;
int cpos = ipos;
for ( int i=0; i<len; i++ ) { // for each char in text...
QPoint p1 = a.point( cpos-1 );
QPoint p2 = a.point( cpos+1 );
QPoint pt = a.point(cpos);
float dx = (float)(p2.x() - p1.x());
float dy = (float)(p2.y() - p1.y());
float angle = (float)atan(dy/dx); // way too simple
angle *= 180.0F/3.14F;
QWMatrix m; // setup world matrix
m.translate( (float)pt.x(), (float)pt.y() );
m.rotate( angle );
p->setWorldMatrix( m );
p->drawText( 0,0, &text[i], 1 );
cpos += ipos;
}
}
示例9: paintEvent
void AnalogClock::paintEvent( QPaintEvent * ) // paint clock
{
if ( !isVisible() ) // is is invisible
return;
time = QTime::currentTime(); // save current time
QPointArray pts;
QPainter paint( this );
paint.setBrush( foregroundColor() ); // fill with foreground color
QPoint cp = rect().center(); // widget center point
int d = QMIN(width(),height()); // we want a circular clock
QWMatrix matrix; // setup transformation matrix
matrix.translate( cp.x(), cp.y() ); // origin at widget center
matrix.scale( d/1000.0F, d/1000.0F ); // scale coordinate system
float h_angle = 30*(time.hour()%12-3) + time.minute()/2;
matrix.rotate( h_angle ); // rotate to draw hour hand
paint.setWorldMatrix( matrix );
pts.setPoints( 4, -20,0, 0,-20, 300,0, 0,20 );
paint.drawPolygon( pts ); // draw hour hand
matrix.rotate( -h_angle ); // rotate back to zero
float m_angle = (time.minute()-15)*6;
matrix.rotate( m_angle ); // rotate to draw minute hand
paint.setWorldMatrix( matrix );
pts.setPoints( 4, -10,0, 0,-10, 400,0, 0,10 );
paint.drawPolygon( pts ); // draw minute hand
matrix.rotate( -m_angle ); // rotate back to zero
for ( int i=0; i<12; i++ ) { // draw hour lines
paint.setWorldMatrix( matrix );
paint.drawLine( 450,0, 500,0 );
matrix.rotate( 30 );
}
}
示例10: qDrawMotifArrow
// motif arrows look the same whether they are used or not
// is this correct?
static void qDrawMotifArrow( QPainter *p, Qt::ArrowType type, bool down,
int x, int y, int w, int h,
const QColorGroup &g, bool )
{
QPointArray bFill; // fill polygon
QPointArray bTop; // top shadow.
QPointArray bBot; // bottom shadow.
QPointArray bLeft; // left shadow.
#ifndef QT_NO_TRANSFORMATIONS
QWMatrix matrix; // xform matrix
#endif
bool vertical = type == Qt::UpArrow || type == Qt::DownArrow;
bool horizontal = !vertical;
int dim = w < h ? w : h;
int colspec = 0x0000; // color specification array
if ( dim < 2 ) // too small arrow
return;
if ( dim > 3 ) {
if ( dim > 6 )
bFill.resize( dim & 1 ? 3 : 4 );
bTop.resize( (dim/2)*2 );
bBot.resize( dim & 1 ? dim + 1 : dim );
bLeft.resize( dim > 4 ? 4 : 2 );
bLeft.putPoints( 0, 2, 0,0, 0,dim-1 );
if ( dim > 4 )
bLeft.putPoints( 2, 2, 1,2, 1,dim-3 );
bTop.putPoints( 0, 4, 1,0, 1,1, 2,1, 3,1 );
bBot.putPoints( 0, 4, 1,dim-1, 1,dim-2, 2,dim-2, 3,dim-2 );
for( int i=0; i<dim/2-2 ; i++ ) {
bTop.putPoints( i*2+4, 2, 2+i*2,2+i, 5+i*2, 2+i );
bBot.putPoints( i*2+4, 2, 2+i*2,dim-3-i, 5+i*2,dim-3-i );
}
if ( dim & 1 ) // odd number size: extra line
bBot.putPoints( dim-1, 2, dim-3,dim/2, dim-1,dim/2 );
if ( dim > 6 ) { // dim>6: must fill interior
bFill.putPoints( 0, 2, 1,dim-3, 1,2 );
if ( dim & 1 ) // if size is an odd number
bFill.setPoint( 2, dim - 3, dim / 2 );
else
bFill.putPoints( 2, 2, dim-4,dim/2-1, dim-4,dim/2 );
}
}
else {
if ( dim == 3 ) { // 3x3 arrow pattern
bLeft.setPoints( 4, 0,0, 0,2, 1,1, 1,1 );
bTop .setPoints( 2, 1,0, 1,0 );
bBot .setPoints( 2, 1,2, 2,1 );
}
else { // 2x2 arrow pattern
bLeft.setPoints( 2, 0,0, 0,1 );
bTop .setPoints( 2, 1,0, 1,0 );
bBot .setPoints( 2, 1,1, 1,1 );
}
}
if ( type == Qt::UpArrow || type == Qt::LeftArrow ) {
#ifndef QT_NO_TRANSFORMATIONS // #### fix me!
matrix.translate( x, y );
if ( vertical ) {
matrix.translate( 0, h - 1 );
matrix.rotate( -90 );
} else {
matrix.translate( w - 1, h - 1 );
matrix.rotate( 180 );
}
#endif
if ( down )
colspec = horizontal ? 0x2334 : 0x2343;
else
colspec = horizontal ? 0x1443 : 0x1434;
}
else if ( type == Qt::DownArrow || type == Qt::RightArrow ) {
#ifndef QT_NO_TRANSFORMATIONS // #### fix me!
matrix.translate( x, y );
if ( vertical ) {
matrix.translate( w-1, 0 );
matrix.rotate( 90 );
}
#endif
if ( down )
colspec = horizontal ? 0x2443 : 0x2434;
else
colspec = horizontal ? 0x1334 : 0x1343;
}
QColor *cols[5];
cols[0] = 0;
cols[1] = (QColor *)&g.button();
cols[2] = (QColor *)&g.mid();
cols[3] = (QColor *)&g.light();
cols[4] = (QColor *)&g.dark();
#define CMID *cols[ (colspec>>12) & 0xf ]
#define CLEFT *cols[ (colspec>>8) & 0xf ]
#define CTOP *cols[ (colspec>>4) & 0xf ]
#define CBOT *cols[ colspec & 0xf ]
//.........这里部分代码省略.........
示例11: moveD
void Main::moveD()
{
QWMatrix m = editor->worldMatrix();
m.translate( 0, +16 );
editor->setWorldMatrix( m );
}
示例12: moveR
void Main::moveR()
{
QWMatrix m = editor->worldMatrix();
m.translate( +16, 0 );
editor->setWorldMatrix( m );
}
示例13: drawArrow
void QCDEStyle::drawArrow( QPainter *p, ArrowType type, bool down,
int x, int y, int w, int h,
const QColorGroup &g, bool enabled, const QBrush * /* fill */ )
{
QPointArray bFill; // fill polygon
QPointArray bTop; // top shadow.
QPointArray bBot; // bottom shadow.
QPointArray bLeft; // left shadow.
QWMatrix matrix; // xform matrix
bool vertical = type == UpArrow || type == DownArrow;
bool horizontal = !vertical;
int dim = w < h ? w : h;
int colspec = 0x0000; // color specification array
if ( dim < 2 ) // too small arrow
return;
// adjust size and center (to fix rotation below)
if ( w > dim ) {
x += (w-dim)/2;
w = dim;
}
if ( h > dim ) {
y += (h-dim)/2;
h = dim;
}
if ( dim > 3 ) {
bFill.resize( dim & 1 ? 3 : 4 );
bTop.resize( 2 );
bBot.resize( 2 );
bLeft.resize( 2 );
bLeft.putPoints( 0, 2, 0,0, 0,dim-1 );
bTop.putPoints( 0, 2, 1,0, dim-1, dim/2);
bBot.putPoints( 0, 2, 1,dim-1, dim-1, dim/2);
if ( dim > 6 ) { // dim>6: must fill interior
bFill.putPoints( 0, 2, 1,dim-1, 1,1 );
if ( dim & 1 ) // if size is an odd number
bFill.setPoint( 2, dim - 2, dim / 2 );
else
bFill.putPoints( 2, 2, dim-2,dim/2-1, dim-2,dim/2 );
}
}
else {
if ( dim == 3 ) { // 3x3 arrow pattern
bLeft.setPoints( 4, 0,0, 0,2, 1,1, 1,1 );
bTop .setPoints( 2, 1,0, 1,0 );
bBot .setPoints( 2, 1,2, 2,1 );
}
else { // 2x2 arrow pattern
bLeft.setPoints( 2, 0,0, 0,1 );
bTop .setPoints( 2, 1,0, 1,0 );
bBot .setPoints( 2, 1,1, 1,1 );
}
}
if ( type == UpArrow || type == LeftArrow ) {
matrix.translate( x, y );
if ( vertical ) {
matrix.translate( 0, h - 1 );
matrix.rotate( -90 );
} else {
matrix.translate( w - 1, h - 1 );
matrix.rotate( 180 );
}
if ( down )
colspec = horizontal ? 0x2334 : 0x2343;
else
colspec = horizontal ? 0x1443 : 0x1434;
}
else if ( type == DownArrow || type == RightArrow ) {
matrix.translate( x, y );
if ( vertical ) {
matrix.translate( w-1, 0 );
matrix.rotate( 90 );
}
if ( down )
colspec = horizontal ? 0x2443 : 0x2434;
else
colspec = horizontal ? 0x1334 : 0x1343;
}
QColor *cols[5];
if ( enabled ) {
cols[0] = 0;
cols[1] = (QColor *)&g.button();
cols[2] = (QColor *)&g.mid();
cols[3] = (QColor *)&g.light();
cols[4] = (QColor *)&g.dark();
} else {
cols[0] = 0;
cols[1] = (QColor *)&g.button();
cols[2] = (QColor *)&g.button();
cols[3] = (QColor *)&g.button();
cols[4] = (QColor *)&g.button();
}
#define CMID *cols[ (colspec>>12) & 0xf ]
#define CLEFT *cols[ (colspec>>8) & 0xf ]
#define CTOP *cols[ (colspec>>4) & 0xf ]
//.........这里部分代码省略.........