Esempio n. 1
0
void Component::renderFill()
{
	glPushMatrix();
	{
		glTranslatef( GLfloat( m_pos.x ), GLfloat( m_pos.y ), 0 );
		if ( isSelected() )
		{
			m_colorTheme.m_active.useColor();
		}
		else
		{
			if ( m_texture == -1 ) m_colorTheme.m_fore.useColor();
			else glColor3f( 1, 1, 1 );
		}
		if ( m_texture != -1 )
		{
			glBindTexture( GL_TEXTURE_2D, TextureManager::getInstance().getUnit( m_texture ).getId() );
		}
		glBegin( GL_QUADS );
		{
			if ( m_texture != -1 )
			{
				Vector2< Sint32 > _texSize;
				switch( m_textureStyle )
				{
				case COMPONENT_TEXTURE_STYLE_NONE: // Scale
					glTexCoord2f( 0, 0 );
					glVertex2f( 0, 0 );
					glTexCoord2f( 1, 0 );
					glVertex2f( GLfloat( m_size.x ), 0 );
					glTexCoord2f( 1, 1 );
					glVertex2f( GLfloat( m_size.x ), GLfloat( m_size.y ) );
					glTexCoord2f( 0, 1 );
					glVertex2f( 0, GLfloat( m_size.y ) );
					break;
				case COMPONENT_TEXTURE_STYLE_WRAP: // Repeat
					_texSize = TextureManager::getInstance().getUnit( m_texture ).getSize();
					glTexCoord2f( 0, 0 );
					glVertex2f( 0, 0 );
					glTexCoord2f( GLfloat( m_size.x ) / _texSize.x, 0 );
					glVertex2f( GLfloat( m_size.x ), 0 );
					glTexCoord2f( GLfloat( m_size.x ) / _texSize.x, GLfloat( m_size.y ) / _texSize.y );
					glVertex2f( GLfloat( m_size.x ), GLfloat( m_size.y ) );
					glTexCoord2f( 0, GLfloat( m_size.y ) / _texSize.y );
					glVertex2f( 0, GLfloat( m_size.y ) );
					break;
				case COMPONENT_TEXTURE_STYLE_SCALE: // Repeat and Scale?
					_texSize = TextureManager::getInstance().getUnit( m_texture ).getSize();
					// Top Left corner
					glTexCoord2f( 0, 1 );
					glVertex2f( 0, 0 );
					glTexCoord2f( 0.25f, 1 );
					glVertex2f( _texSize.x / 4.f, 0 );
					glTexCoord2f( 0.25f, 0.75f );
					glVertex2f( _texSize.x / 4.f, _texSize.y / 4.f );
					glTexCoord2f( 0, 0.75f );
					glVertex2f( 0, _texSize.y / 4.f );


					// Top Right corner
					glTexCoord2f( 0.75f, 1 );
					glVertex2f( GLfloat( m_size.x ) - _texSize.x / 4.f, 0 );
					glTexCoord2f( 1, 1 );
					glVertex2f( GLfloat( m_size.x ), 0 );
					glTexCoord2f( 1, 0.75f );
					glVertex2f( GLfloat( m_size.x ), _texSize.y / 4.f );
					glTexCoord2f( 0.75f, 0.75f );
					glVertex2f( GLfloat( m_size.x ) - _texSize.x / 4.f, _texSize.y / 4.f );


					// Bottom Left corner
					glTexCoord2f( 0, 0.25f );
					glVertex2f( 0, GLfloat( m_size.y ) - _texSize.y / 4.f );
					glTexCoord2f( 0.25f, 0.25f );
					glVertex2f( _texSize.x / 4.f, GLfloat( m_size.y ) - _texSize.y / 4.f );
					glTexCoord2f( 0.25f, 0 );
					glVertex2f( _texSize.x / 4.f, GLfloat( m_size.y ) );
					glTexCoord2f( 0, 0 );
					glVertex2f( 0, GLfloat( m_size.y ) );


					// Bottom Right corner
					glTexCoord2f( 0.75f, 0.25f );
					glVertex2f( GLfloat( m_size.x ) - _texSize.x / 4.f, GLfloat( m_size.y ) - _texSize.y / 4.f );
					glTexCoord2f( 1, 0.25f );
					glVertex2f( GLfloat( m_size.x ), GLfloat( m_size.y ) - _texSize.y / 4.f );
					glTexCoord2f( 1, 0 );
					glVertex2f( GLfloat( m_size.x ), GLfloat( m_size.y ) );
					glTexCoord2f( 0.75f, 0 );
					glVertex2f( GLfloat( m_size.x ) - _texSize.x / 4.f, GLfloat( m_size.y ) );


					// Top and Bottom side
					/*
					GLfloat _width = ceilf( ( GLfloat( m_size.x ) - _texSize.x / 2.f ) / ( _texSize.x / 2.f ) ) * ( _texSize.x / 2.f );
					_width /= ( GLfloat( m_size.x ) - _texSize.x / 2.f );
					_width = 1.f / _width;
					for ( Uint16 i = 0; i < ceilf( ( GLfloat( m_size.x ) - _texSize.x / 2.f ) / ( _texSize.x / 2.f ) ); i++ )
					{
						glTexCoord2f( 0.25f, 0 );
						glVertex2f( _texSize.x / 4.f + ( i * _texSize.x / 2.f ) * _width, 0 );
						glTexCoord2f( 0.75f, 0 );
						glVertex2f( _texSize.x / 4.f + ( ( i + 1 ) * _texSize.x / 2.f ) * _width, 0 );
						glTexCoord2f( 0.75f, 0.25f );
						glVertex2f( _texSize.x / 4.f + ( ( i + 1 ) * _texSize.x / 2.f ) * _width, _texSize.y / 4.f );
						glTexCoord2f( 0.25f, 0.25f );
						glVertex2f( _texSize.x / 4.f + ( i * _texSize.x / 2.f ) * _width, _texSize.y / 4.f );


						glTexCoord2f( 0.25f, 0.75f );
						glVertex2f( _texSize.x / 4.f + ( i * _texSize.x / 2.f ) * _width, GLfloat( m_size.y ) - _texSize.y / 4.f );
						glTexCoord2f( 0.75f, 0.75f );
						glVertex2f( _texSize.x / 4.f + ( ( i + 1 ) * _texSize.x / 2.f ) * _width, GLfloat( m_size.y ) - _texSize.y / 4.f );
						glTexCoord2f( 0.75f, 1 );
						glVertex2f( _texSize.x / 4.f + ( ( i + 1 ) * _texSize.x / 2.f ) * _width, GLfloat( m_size.y ) );
						glTexCoord2f( 0.25f, 1 );
						glVertex2f( _texSize.x / 4.f + ( i * _texSize.x / 2.f ) * _width, GLfloat( m_size.y ) );
					}
					*/

					GLfloat _width = floor( ( GLfloat( m_size.x ) - _texSize.x / 2.f ) / ( _texSize.x / 2.f ) );
					GLfloat _widthF = ( ( GLfloat( m_size.x ) - _texSize.x / 2.f ) / ( _texSize.x / 2.f ) );

					// Top and Bottom side
					for ( Uint16 i = 0; i < _width; i++ )
					{
						glTexCoord2f( 0.25f, 1 );
						glVertex2f( _texSize.x / 4.f + ( i * _texSize.x / 2.f ), 0 );
						glTexCoord2f( 0.75f, 1 );
						glVertex2f( _texSize.x / 4.f + ( ( i + 1 ) * _texSize.x / 2.f ), 0 );
						glTexCoord2f( 0.75f, 0.75f );
						glVertex2f( _texSize.x / 4.f + ( ( i + 1 ) * _texSize.x / 2.f ), _texSize.y / 4.f );
						glTexCoord2f( 0.25f, 0.75f );
						glVertex2f( _texSize.x / 4.f + ( i * _texSize.x / 2.f ), _texSize.y / 4.f );


						glTexCoord2f( 0.25f, 0.25f );
						glVertex2f( _texSize.x / 4.f + ( i * _texSize.x / 2.f ), GLfloat( m_size.y ) - _texSize.y / 4.f );
						glTexCoord2f( 0.75f, 0.25f );
						glVertex2f( _texSize.x / 4.f + ( ( i + 1 ) * _texSize.x / 2.f ), GLfloat( m_size.y ) - _texSize.y / 4.f );
						glTexCoord2f( 0.75f, 0 );
						glVertex2f( _texSize.x / 4.f + ( ( i + 1 ) * _texSize.x / 2.f ), GLfloat( m_size.y ) );
						glTexCoord2f( 0.25f, 0 );
						glVertex2f( _texSize.x / 4.f + ( i * _texSize.x / 2.f ), GLfloat( m_size.y ) );
					}

					glTexCoord2f( 0.25f, 1 );
					glVertex2f( _texSize.x / 4.f + ( _width * _texSize.x / 2.f ), 0 );
					glTexCoord2f( 0.25f + 0.5f * ( _widthF - _width ), 1 );
					glVertex2f( _texSize.x / 4.f + ( ( _width + ( _widthF - _width ) ) * _texSize.x / 2.f ), 0 );
					glTexCoord2f( 0.25f + 0.5f * ( _widthF - _width ), 0.75f );
					glVertex2f( _texSize.x / 4.f + ( ( _width + ( _widthF - _width ) ) * _texSize.x / 2.f ), _texSize.y / 4.f );
					glTexCoord2f( 0.25f, 0.75f );
					glVertex2f( _texSize.x / 4.f + ( _width * _texSize.x / 2.f ), _texSize.y / 4.f );


					glTexCoord2f( 0.25f, 0.25f );
					glVertex2f( _texSize.x / 4.f + ( _width * _texSize.x / 2.f ), GLfloat( m_size.y ) - _texSize.y / 4.f );
					glTexCoord2f( 0.25f + 0.5f * ( _widthF - _width ), 0.25f );
					glVertex2f( _texSize.x / 4.f + ( ( _width + ( _widthF - _width ) ) * _texSize.x / 2.f ), GLfloat( m_size.y ) - _texSize.y / 4.f );
					glTexCoord2f( 0.25f + 0.5f * ( _widthF - _width ), 0 );
					glVertex2f( _texSize.x / 4.f + ( ( _width + ( _widthF - _width ) ) * _texSize.x / 2.f ), GLfloat( m_size.y ) );
					glTexCoord2f( 0.25f, 0 );
					glVertex2f( _texSize.x / 4.f + ( _width * _texSize.x / 2.f ), GLfloat( m_size.y ) );






					// Left and Right side
					/*  JUST A COPY OF PREVIOUS COMMENTED SECTION
					GLfloat _height = ceilf( ( GLfloat( m_size.y ) - _texSize.y / 2.f ) / ( _texSize.y / 2.f ) ) * ( _texSize.y / 2.f );
					_height /= ( GLfloat( m_size.y ) - _texSize.y / 2.f );
					_height = 1.f / _height;
					for ( Uint16 i = 0; i < ceilf( ( GLfloat( m_size.x ) - _texSize.x / 2.f ) / ( _texSize.x / 2.f ) ); i++ )
					{
						glTexCoord2f( 0.25f, 0 );
						glVertex2f( _texSize.x / 4.f + ( i * _texSize.x / 2.f ) * _height, 0 );
						glTexCoord2f( 0.75f, 0 );
						glVertex2f( _texSize.x / 4.f + ( ( i + 1 ) * _texSize.x / 2.f ) * _height, 0 );
						glTexCoord2f( 0.75f, 0.25f );
						glVertex2f( _texSize.x / 4.f + ( ( i + 1 ) * _texSize.x / 2.f ) * _height, _texSize.y / 4.f );
						glTexCoord2f( 0.25f, 0.25f );
						glVertex2f( _texSize.x / 4.f + ( i * _texSize.x / 2.f ) * _height, _texSize.y / 4.f );


						glTexCoord2f( 0.25f, 0.75f );
						glVertex2f( _texSize.x / 4.f + ( i * _texSize.x / 2.f ) * _height, GLfloat( m_size.y ) - _texSize.y / 4.f );
						glTexCoord2f( 0.75f, 0.75f );
						glVertex2f( _texSize.x / 4.f + ( ( i + 1 ) * _texSize.x / 2.f ) * _height, GLfloat( m_size.y ) - _texSize.y / 4.f );
						glTexCoord2f( 0.75f, 1 );
						glVertex2f( _texSize.x / 4.f + ( ( i + 1 ) * _texSize.x / 2.f ) * _height, GLfloat( m_size.y ) );
						glTexCoord2f( 0.25f, 1 );
						glVertex2f( _texSize.x / 4.f + ( i * _texSize.x / 2.f ) * _height, GLfloat( m_size.y ) );
					}
					*/

					GLfloat _height = floor( ( GLfloat( m_size.y ) - _texSize.y / 2.f ) / ( _texSize.y / 2.f ) );
					GLfloat _heightF = ( ( GLfloat( m_size.y ) - _texSize.y / 2.f ) / ( _texSize.y / 2.f ) );

					// Left and Right side
					for ( Uint16 i = 0; i < _height; i++ )
					{
						glTexCoord2f( 0, 0.75f );
						glVertex2f( 0, _texSize.y / 4.f + ( i * _texSize.y / 2.f ) );
						glTexCoord2f( 0, 0.25f );
						glVertex2f( 0, ( _texSize.y / 4.f + ( ( i + 1 ) * _texSize.y / 2.f ) ) );
						glTexCoord2f( 0.25f, 0.25f );
						glVertex2f( _texSize.x / 4.f, ( _texSize.y / 4.f + ( ( i + 1 ) * _texSize.y / 2.f ) ) );
						glTexCoord2f( 0.25f, 0.75f );
						glVertex2f( _texSize.x / 4.f, _texSize.y / 4.f + ( i * _texSize.y / 2.f ) );


						glTexCoord2f( 0.75f, 0.75f );
						glVertex2f( GLfloat( m_size.x ) - _texSize.y / 4.f, _texSize.y / 4.f + ( i * _texSize.y / 2.f ) );
						glTexCoord2f( 0.75f, 0.25f );
						glVertex2f( GLfloat( m_size.x ) - _texSize.y / 4.f, _texSize.y / 4.f + ( ( i + 1 ) * _texSize.y / 2.f ) );
						glTexCoord2f( 1, 0.25f );
						glVertex2f( GLfloat( m_size.x ), _texSize.y / 4.f + ( ( i + 1 ) * _texSize.y / 2.f ) );
						glTexCoord2f( 1, 0.75f );
						glVertex2f( GLfloat( m_size.x ), _texSize.y / 4.f + ( i * _texSize.y / 2.f ) );
					}

					glTexCoord2f( 0, 0.75f );
					glVertex2f( 0, _texSize.y / 4.f + ( _height * _texSize.y / 2.f ) );
					glTexCoord2f( 0, 0.75f - 0.5f * ( _heightF - _height ) );
					glVertex2f( 0, _texSize.y / 4.f + ( ( _height + ( _heightF - _height ) ) * _texSize.y / 2.f ) );
					glTexCoord2f( 0.25f, 0.75f - 0.5f * ( _heightF - _height ) );
					glVertex2f( _texSize.x / 4.f, _texSize.y / 4.f + ( ( _height + ( _heightF - _height ) ) * _texSize.y / 2.f ) );
					glTexCoord2f( 0.25f, 0.75f );
					glVertex2f( _texSize.x / 4.f, _texSize.y / 4.f + ( _height * _texSize.y / 2.f ) );


					glTexCoord2f( 0.75f, 0.75f );
					glVertex2f( GLfloat( m_size.x ) - _texSize.x / 4.f, _texSize.y / 4.f + ( _height * _texSize.y / 2.f ) );
					glTexCoord2f( 0.75f, 0.75f - 0.5f * ( _heightF - _height ) );
					glVertex2f( GLfloat( m_size.x ) - _texSize.x / 4.f, _texSize.y / 4.f + ( ( _height + ( _heightF - _height ) ) * _texSize.y / 2.f ) );
					glTexCoord2f( 1, 0.75f - 0.5f * ( _heightF - _height ) );
					glVertex2f( GLfloat( m_size.x ), _texSize.y / 4.f + ( ( _height + ( _heightF - _height ) ) * _texSize.y / 2.f ) );
					glTexCoord2f( 1, 0.75f );
					glVertex2f( GLfloat( m_size.x ), _texSize.y / 4.f + ( _height * _texSize.y / 2.f ) );


					// Center
					for ( Uint16 x = 0; x < _width; x++ )
					{
						for ( Uint16 y = 0; y < _height; y++ )
						{
							glTexCoord2f( 0.25f, 0.75f );
							glVertex2f( _texSize.x / 4.f + ( x * _texSize.x / 2.f ), _texSize.y / 4.f + ( y * _texSize.y / 2.f ) );
							glTexCoord2f( 0.75f, 0.75f );
							glVertex2f( _texSize.x / 4.f + ( ( x + 1 ) * _texSize.x / 2.f ), _texSize.y / 4.f + ( y * _texSize.y / 2.f ) );
							glTexCoord2f( 0.75f, 0.25f );
							glVertex2f( _texSize.x / 4.f + ( ( x + 1 ) * _texSize.x / 2.f ), _texSize.y / 4.f + ( ( y + 1 ) * _texSize.y / 2.f ) );
							glTexCoord2f( 0.25f, 0.25f );
							glVertex2f( _texSize.x / 4.f + ( x * _texSize.x / 2.f ), _texSize.y / 4.f + ( ( y + 1 ) * _texSize.y / 2.f ) );

						}
					}

					for ( Uint16 x = 0; x < _width; x++ )
					{
						glTexCoord2f( 0.25f, 0.75f );
						glVertex2f( _texSize.x / 4.f + ( x * _texSize.x / 2.f ), _texSize.y / 4.f + ( _height * _texSize.y / 2.f ) );
						glTexCoord2f( 0.75f, 0.75f );
						glVertex2f( _texSize.x / 4.f + ( ( x + 1 ) * _texSize.x / 2.f ), _texSize.y / 4.f + ( _height * _texSize.y / 2.f ) );
						glTexCoord2f( 0.75f, 0.75f - 0.5f * ( _heightF - _height ) );
						glVertex2f( _texSize.x / 4.f + ( ( x + 1 ) * _texSize.x / 2.f ), _texSize.y / 4.f + ( ( _height + ( _heightF - _height ) ) * _texSize.y / 2.f ) );
						glTexCoord2f( 0.25f, 0.75f - 0.5f * ( _heightF - _height ) );
						glVertex2f( _texSize.x / 4.f + ( x * _texSize.x / 2.f ), _texSize.y / 4.f + ( ( _height + ( _heightF - _height ) ) * _texSize.y / 2.f ) );
					}

					for ( Uint16 y = 0; y < _height; y++ )
					{
						glTexCoord2f( 0.25f, 0.75f );
						glVertex2f( _texSize.x / 4.f + ( _width * _texSize.y / 2.f ), _texSize.y / 4.f + ( y * _texSize.y / 2.f ) );
						glTexCoord2f( 0.25f + 0.5f * ( _widthF - _width ), 0.75f );
						glVertex2f( _texSize.x / 4.f + ( _width * _texSize.y / 2.f ), _texSize.y / 4.f + ( ( y + 1 ) * _texSize.y / 2.f ) );
						glTexCoord2f( 0.25f + 0.5f * ( _widthF - _width ), 0.25f );
						glVertex2f( _texSize.x / 4.f + ( ( _width + ( _widthF - _width ) ) * _texSize.y / 2.f ), _texSize.y / 4.f + ( ( y + 1 ) * _texSize.y / 2.f ) );
						glTexCoord2f( 0.25f, 0.25f );
						glVertex2f( _texSize.x / 4.f + ( ( _width + ( _widthF - _width ) ) * _texSize.y / 2.f ), _texSize.y / 4.f + ( y * _texSize.y / 2.f ) );
					}

					glTexCoord2f( 0.25f, 0.75f );
					glVertex2f( _texSize.x / 4.f + ( _width * _texSize.x / 2.f ), _texSize.y / 4.f + ( _height * _texSize.y / 2.f ) );
					glTexCoord2f( 0.25f + 0.5f * ( _widthF - _width ), 0.75f );
					glVertex2f( _texSize.x / 4.f + ( ( _width + ( _widthF - _width ) ) * _texSize.x / 2.f ), _texSize.y / 4.f + ( _height * _texSize.y / 2.f ) );
					glTexCoord2f( 0.25f + 0.5f * ( _widthF - _width ), 0.75f - 0.5f * ( _heightF - _height ) );
					glVertex2f( _texSize.x / 4.f + ( ( _width + ( _widthF - _width ) ) * _texSize.x / 2.f ), _texSize.y / 4.f + ( ( _height + ( _heightF - _height ) ) * _texSize.y / 2.f ) );
					glTexCoord2f( 0.25f, 0.75f - 0.5f * ( _heightF - _height ) );
					glVertex2f( _texSize.x / 4.f + ( _width * _texSize.x / 2.f ), _texSize.y / 4.f + ( ( _height + ( _heightF - _height ) ) * _texSize.y / 2.f ) );
					break;
				}
			}
			else
			{
				glVertex2f( 0, 0 );
				glVertex2f( GLfloat( GLfloat( m_size.x ) ), 0 );
				glVertex2f( GLfloat( GLfloat( m_size.x ) ), GLfloat( GLfloat( m_size.y ) ) );
				glVertex2f( 0, GLfloat( GLfloat( m_size.y ) ) );
			}
		}
		glEnd();
		glBindTexture( GL_TEXTURE_2D, 0 );
	}
	glPopMatrix();
}
Esempio n. 2
0
void RS_Ellipse::draw(RS_Painter* painter, RS_GraphicView* view, double /*patternOffset*/) {

    if (painter==NULL || view==NULL) {
        return;
    }


    if (getPen().getLineType()==RS2::SolidLine ||
            ! isSelected() ||
            view->getDrawingMode()==RS2::ModePreview) {

        painter->drawEllipse(view->toGui(getCenter()),
                             getMajorRadius() * view->getFactor().x,
                             getMinorRadius() * view->getFactor().x,
                             getAngle(),
                             getAngle1(), getAngle2(),
                             isReversed());
    } else {
        double styleFactor = getStyleFactor(view);
        if (styleFactor<0.0) {
            painter->drawEllipse(view->toGui(getCenter()),
                                 getMajorRadius() * view->getFactor().x,
                                 getMinorRadius() * view->getFactor().x,
                                 getAngle(),
                                 getAngle1(), getAngle2(),
                                 isReversed());
            return;
        }

        // Pattern:
        RS_LineTypePattern* pat;
        if (isSelected()) {
            pat = &patternSelected;
        } else {
            pat = view->getPattern(getPen().getLineType());
        }

        if (pat==NULL) {
            return;
        }

        // Pen to draw pattern is always solid:
        RS_Pen pen = painter->getPen();
        pen.setLineType(RS2::SolidLine);
        painter->setPen(pen);

        double* da;     // array of distances in x.
        int i;          // index counter

        double length = getAngleLength();

        // create pattern:
        da = new double[pat->num];

        double tot=0.0;
        i=0;
        bool done = false;
        double curA = getAngle1();
        double curR;
        RS_Vector cp = view->toGui(getCenter());
        double r1 = getMajorRadius() * view->getFactor().x;
        double r2 = getMinorRadius() * view->getFactor().x;

        do {
            curR = sqrt(RS_Math::pow(getMinorRadius()*cos(curA), 2.0)
                        + RS_Math::pow(getMajorRadius()*sin(curA), 2.0));

            if (curR>1.0e-6) {
                da[i] = fabs(pat->pattern[i] * styleFactor) / curR;
                if (pat->pattern[i] * styleFactor > 0.0) {

                    if (tot+fabs(da[i])<length) {
                        painter->drawEllipse(cp,
                                             r1, r2,
                                             getAngle(),
                                             curA,
                                             curA + da[i],
                                             false);
                    } else {
                        painter->drawEllipse(cp,
                                             r1, r2,
                                             getAngle(),
                                             curA,
                                             getAngle2(),
                                             false);
                    }
                }
            }
            curA+=da[i];
            tot+=fabs(da[i]);
            done=tot>length;

            i++;
            if (i>=pat->num) {
                i=0;
            }
        } while(!done);

        delete[] da;
    }
}
Esempio n. 3
0
/** Paint a cell of the ViewItem when in TVS_INPROGRESS state
  *
  * \param painter The paint where we draw the item
  * \param cg The color group we can use to draw
  * \param column The index of the column to draw
  * \param width The width of the cell
  * \param align Not yet used
  *
  */
void RainbruRPG::Network::Ftp::TransferVisual::
drawInProgress(QPainter * painter,const QColorGroup & cg, int column, 
	   int width, int align){

  // controls
  if (ip.isEmpty()){
    LOGW("IP address is empty");
  }

  if (isSelected()){
    painter->setPen(Qt::NoPen);
    painter->setBrush(cg.color(QPalette::Highlight));
    painter->drawRect(0, 0, width, height());
  }

  QLinearGradient linearGrad(QPointF(0, 0), QPointF(0, height()));
  linearGrad.setColorAt(0,    QColor( 34,  80, 184));
  linearGrad.setColorAt(0.25, QColor(150, 189, 231));
  linearGrad.setColorAt(0.50, QColor( 88, 154, 227));
  linearGrad.setColorAt(0.75, QColor(150, 189, 231));
  linearGrad.setColorAt(1,    QColor(127, 205, 255));

  QLinearGradient linearGrad2(QPointF(0, 0), QPointF(0, height()));
  linearGrad2.setColorAt(0,    QColor(163, 163, 163));
  linearGrad2.setColorAt(0.25, QColor(231, 231, 231));
  linearGrad2.setColorAt(0.50, QColor(217, 217, 217));
  linearGrad2.setColorAt(0.75, QColor(244, 244, 244));
  linearGrad2.setColorAt(1,    QColor(248, 248, 248));

  QPen pen(Qt::gray, 1); 

  if (column==6){
    // Progress bar
    int totalW=width-4;
    int leftW=(int)(totalW*percent)/100;
    int rightW=totalW-leftW;

    // Drawing ProgressBar
    painter->setPen(Qt::NoPen);
    painter->setBrush(QBrush(linearGrad));
    painter->drawRect( 2, 2, leftW, height()-4 );
    painter->setBrush(QBrush(linearGrad2));
    painter->drawRect( leftW+2, 2, rightW, height()-4 );

    painter->setPen(pen);
    painter->setBrush(Qt::NoBrush);
    painter->drawRect(0, 0, width-1, height()-1);

    QFont f=painter->font();
    f.setPointSize(f.pointSize()-1);

    painter->setFont(f);
    painter->setPen(Qt::black);

    QString s=QString::number(percent, 'f', 2);
    s+=" %";
    painter->drawText( 0, 0, width, height(), Qt::AlignCenter, s );
  }
  else{

    painter->setPen(Qt::black);
    QString s;
    switch(column){
    case 0:
      drawIpPort(painter, width, height());
      break;
    case 1:
      // Filename
      s=absoluteFilename;
      painter->drawText( 0, 0, width, height(), 
			 Qt::AlignLeft|Qt::AlignVCenter, s);
      break;
    case 2:
      // Green or Red arrow
      drawArrow(painter, width, height());
      break;
    case 3:
      // Download rate
      s=QString::number(rate, 'f', 2);
      s+=" kB/s";
      painter->drawText( 0, 0, width, height(), 
			 Qt::AlignRight|Qt::AlignVCenter, s);
      break;
    case 4:
      // File size
      painter->drawText( 0, 0, width, height(), 
			 Qt::AlignRight|Qt::AlignVCenter, fileSizeToString());
      break;
    case 5:
      // Remaining time
      painter->drawText( 0, 0, width, height(), 
			 Qt::AlignRight|Qt::AlignVCenter, remainingTime);
      break;
   }
  }
}
Esempio n. 4
0
void SE_NewGeometry::renderScene(SE_Camera* camera, SE_RenderManager* renderManager, SE_CULL_TYPE cullType)
{
    if(!isVisible())
        return;
    SE_BoundingVolume* bv = getWorldBoundingVolume();
	SE_CULL_TYPE currCullType = SE_PART_CULL;
    if(bv && cullType == SE_PART_CULL)
    {
        int culled = camera->cullBV(*bv);
        if(culled == SE_FULL_CULL)
            return;
		else
		    currCullType = (SE_CULL_TYPE)culled;
    }
    SE_NewGeometry::_Impl::SimObjectList::iterator it;
    for(it = mImpl->attachObject.begin() ; it != mImpl->attachObject.end() ; it++)
    {
        SE_SimObject* so = *it;
        SE_SimObject::RenderUnitVector renderUnitVector = so->createRenderUnit();
        SE_SimObject::RenderUnitVector::iterator itRU;
        for(itRU = renderUnitVector.begin() ; itRU!= renderUnitVector.end(); itRU++)
        {
            if(*itRU)
            {
                //transparency object should be draw after normal object.
                const SE_ProgramDataID& spID = (*itRU)->getSurface()->getProgramDataID();
                std::string spid = spID.getStr();
                if(spid.compare("fadeinout_shader") == 0)
                {
                    renderManager->addRenderUnit(*itRU,SE_RenderManager::RQ5);                    
                    
                }
                else if((*itRU)->isDrawStencil())
                {
                    //draw stencil buffer, first
                    renderManager->addRenderUnit(*itRU,SE_RenderManager::RQ2); 
                }
                else if((*itRU)->isMirroredObject())
                {
                    //draw stencil buffer, first
                    renderManager->addRenderUnit(*itRU,SE_RenderManager::RQ3); 
                }
                else
                {
				    renderManager->addRenderUnit(*itRU, SE_RenderManager::RQ4);
            }
        }
    }
    }
    if(isSelected())
    {
        SE_RenderUnit* ru = createSelectedFrame(this);
        if(ru != NULL)
            renderManager->addRenderUnit(ru, SE_RenderManager::RQ7);
        else
        {
            SE_NewGeometry::_Impl::SimObjectList::iterator it;
            for(it = mImpl->attachObject.begin() ; it != mImpl->attachObject.end() ; it++)
            {
                SE_SimObject* so = *it;
                SE_RenderUnit* ru = so->createWireRenderUnit();
                renderManager->addRenderUnit(ru, SE_RenderManager::RQ7);
            }
        }
    }
    std::list<SE_Spatial*>::iterator itchild = mImplchild->children.begin();
    for(; itchild != mImplchild->children.end() ; itchild++)
    {
        SE_Spatial* s = *itchild;
        s->renderScene(camera, renderManager, currCullType);
    }
}
Esempio n. 5
0
bool MMSLabelWidget::draw(bool *backgroundFilled) {
    int width, height, x, y;
    bool myBackgroundFilled = false;

    if(!surface)
        return false;

    if (backgroundFilled) {
        if (this->has_own_surface)
            *backgroundFilled = false;
    }
    else
        backgroundFilled = &myBackgroundFilled;

    // lock
    this->surface->lock();

    // draw widget basics
    if (MMSWidget::draw(backgroundFilled)) {
        // draw my things
        if (prepareText(&width, &height)) {
            // text is translated and font is set
            MMSFBRectangle surfaceGeom = getSurfaceGeometry();

            // save the width of the text
            this->slide_width = width;

            switch ((!this->swap_left_right) ? getAlignment() : swapAlignmentHorizontal(getAlignment())) {
            case MMSALIGNMENT_LEFT:
                x = surfaceGeom.x;
                y = ((surfaceGeom.h - height) / 2) + surfaceGeom.y;
                break;
            case MMSALIGNMENT_RIGHT:
                x = surfaceGeom.x + surfaceGeom.w - width;
                y = ((surfaceGeom.h - height) / 2) + surfaceGeom.y;
                break;
            case MMSALIGNMENT_CENTER:
                x = ((surfaceGeom.w - width) / 2) + surfaceGeom.x;
                y = ((surfaceGeom.h - height) / 2) + surfaceGeom.y;
                break;
            case MMSALIGNMENT_TOP_CENTER:
                x = ((surfaceGeom.w - width) / 2) + surfaceGeom.x;
                y = surfaceGeom.y;
                break;
            case MMSALIGNMENT_TOP_LEFT:
                x = surfaceGeom.x;
                y = surfaceGeom.y;
                break;
            case MMSALIGNMENT_TOP_RIGHT:
                x = surfaceGeom.x + surfaceGeom.w - width;
                y = surfaceGeom.y;
                break;
            case MMSALIGNMENT_BOTTOM_CENTER:
                x = ((surfaceGeom.w - width) / 2) + surfaceGeom.x;
                y = surfaceGeom.y + surfaceGeom.h - height;
                break;
            case MMSALIGNMENT_BOTTOM_LEFT:
                x = surfaceGeom.x;
                y = surfaceGeom.y + surfaceGeom.h - height;
                break;
            case MMSALIGNMENT_BOTTOM_RIGHT:
                x = surfaceGeom.x + surfaceGeom.w - width;
                y = surfaceGeom.y + surfaceGeom.h - height;
                break;
            default:
                x = ((surfaceGeom.w - width) / 2) + surfaceGeom.x;
                y = ((surfaceGeom.h - height) / 2) + surfaceGeom.y;
                break;
            }

            // get color
            MMSFBColor color;
            getForeground(&color);
            this->current_fgcolor   = color;
            this->current_fgset     = true;

            if (color.a) {
                // prepare for drawing
                this->surface->setDrawingColorAndFlagsByBrightnessAndOpacity(
                    color,
                    (isSelected())?getSelShadowColor(MMSPOSITION_TOP):getShadowColor(MMSPOSITION_TOP),
                    (isSelected())?getSelShadowColor(MMSPOSITION_BOTTOM):getShadowColor(MMSPOSITION_BOTTOM),
                    (isSelected())?getSelShadowColor(MMSPOSITION_LEFT):getShadowColor(MMSPOSITION_LEFT),
                    (isSelected())?getSelShadowColor(MMSPOSITION_RIGHT):getShadowColor(MMSPOSITION_RIGHT),
                    (isSelected())?getSelShadowColor(MMSPOSITION_TOP_LEFT):getShadowColor(MMSPOSITION_TOP_LEFT),
                    (isSelected())?getSelShadowColor(MMSPOSITION_TOP_RIGHT):getShadowColor(MMSPOSITION_TOP_RIGHT),
                    (isSelected())?getSelShadowColor(MMSPOSITION_BOTTOM_LEFT):getShadowColor(MMSPOSITION_BOTTOM_LEFT),
                    (isSelected())?getSelShadowColor(MMSPOSITION_BOTTOM_RIGHT):getShadowColor(MMSPOSITION_BOTTOM_RIGHT),
                    getBrightness(), getOpacity());

                // draw the text
                this->surface->drawString(this->translated_text, -1, x - this->slide_offset, y);
            }
        }

        // update window surface with an area of surface
        updateWindowSurfaceWithSurface(!*backgroundFilled);
    }

    // unlock
    this->surface->unlock();

    // draw widgets debug frame
    return MMSWidget::drawDebug();
}
Esempio n. 6
0
void Place::paint ( QPainter * painter, const QStyleOptionGraphicsItem * option,
			 QWidget * widget )
{
    Q_UNUSED(option);
    Q_UNUSED(widget);

    QColor PenColor;
    QColor BrushColor;

    if((input.isEmpty()) && (output.isEmpty()))
    {
        PenColor = Qt::darkRed;
        BrushColor = QColor(255, 240, 240);
    }
    else if(isSelected())
    {
        foreach(Arc * arc, input)
            arc->setSelected(true);
        foreach(Arc * arc, output)
            arc->setSelected(true);

        PenColor = Qt::blue;
        BrushColor = QColor(240, 240, 255);
    }
    else
    {
        PenColor = Qt::black;
        BrushColor = Qt::white;
    }


    painter->setPen (QPen(PenColor, 1, Qt::SolidLine,
	 Qt::RoundCap, Qt::MiterJoin));
    label->setBrush (PenColor);
    painter->setBrush (BrushColor);
    painter->setRenderHint (QPainter::Antialiasing);
    painter->drawEllipse (0, 0, place_diameter, place_diameter);

    painter->setBrush (PenColor);

    if(tokens == 1)
     painter->drawEllipse(19, 19, 4, 4);
    else if(tokens == 2)
    {
        painter->drawEllipse(20, 20, 4, 4);
        painter->drawEllipse(6, 6, 4, 4);
    }
    else if(tokens == 3)
    {
        painter->drawEllipse(20, 20, 4, 4);
        painter->drawEllipse(13, 13, 4, 4);
        painter->drawEllipse(6, 6, 4, 4);
    }
    else if(tokens == 4)
    {
        painter->drawEllipse(20, 20, 4, 4);
        painter->drawEllipse(6, 6, 4, 4);
        painter->drawEllipse(6, 20, 4, 4);
        painter->drawEllipse(20, 6, 4, 4);
    }
    else if(tokens == 5)
    {
        painter->drawEllipse(20, 20, 4, 4);
        painter->drawEllipse(6, 6, 4, 4);
        painter->drawEllipse(13, 13, 4, 4);
        painter->drawEllipse(6, 20, 4, 4);
        painter->drawEllipse(20, 6, 4, 4);
    }
    else if(tokens == 6)
    {
        painter->drawEllipse(20, 20, 4, 4);
        painter->drawEllipse(6, 6, 4, 4);
        painter->drawEllipse(6, 20, 4, 4);
        painter->drawEllipse(20, 6, 4, 4);
        painter->drawEllipse(6, 13, 4, 4);
        painter->drawEllipse(20, 13, 4, 4);
    }
    else if(tokens == 7)
    {
        painter->drawEllipse(20, 20, 4, 4);
        painter->drawEllipse(6, 6, 4, 4);
        painter->drawEllipse(6, 20, 4, 4);
        painter->drawEllipse(20, 6, 4, 4);
        painter->drawEllipse(6, 13, 4, 4);
        painter->drawEllipse(20, 13, 4, 4);
        painter->drawEllipse(13, 13, 4, 4);
    }
    else if(tokens == 8)
    {
        painter->drawEllipse(20, 20, 4, 4);
        painter->drawEllipse(6, 6, 4, 4);
        painter->drawEllipse(6, 20, 4, 4);
        painter->drawEllipse(20, 6, 4, 4);
        painter->drawEllipse(6, 13, 4, 4);
        painter->drawEllipse(20, 13, 4, 4);
        painter->drawEllipse(13, 6, 4, 4);
        painter->drawEllipse(13, 20, 4, 4);
    }

    else if(tokens == 9)
    {
        painter->drawEllipse(20, 20, 4, 4);
        painter->drawEllipse(6, 6, 4, 4);
        painter->drawEllipse(6, 20, 4, 4);
        painter->drawEllipse(20, 6, 4, 4);
        painter->drawEllipse(6, 13, 4, 4);
        painter->drawEllipse(20, 13, 4, 4);
        painter->drawEllipse(13, 13, 4, 4);
        painter->drawEllipse(13, 6, 4, 4);
        painter->drawEllipse(13, 20, 4, 4);
    }
    else if(tokens > 9)
    {
        QVariant v(tokens);
        if(tokens < 100)
            painter->drawText(7, 20, QString(v.toString()));
        else
            painter->drawText(4, 20, QString(v.toString()));
    }

}
Esempio n. 7
0
void RS_Circle::draw(RS_Painter* painter, RS_GraphicView* view, double& /*patternOffset*/) {

    if (painter==NULL || view==NULL) {
        return;
    }
    RS_Vector cp(view->toGui(getCenter()));
    double ra(fabs(getRadius()*view->getFactor().x));
    //double styleFactor = getStyleFactor();

    // simple style-less lines
    if ( !isSelected() && (
             getPen().getLineType()==RS2::SolidLine ||
             view->getDrawingMode()==RS2::ModePreview)) {

        painter->drawArc(cp,
                         ra,
                         0.0, 2*M_PI,
                         false);
        return;
    }
//    double styleFactor = getStyleFactor(view);
    //        if (styleFactor<0.0) {
    //            painter->drawArc(cp,
    //                             ra,
    //                             0.0, 2*M_PI,
    //                             false);
    //            return;
    //        }

    // Pattern:
    RS_LineTypePattern* pat;
    if (isSelected()) {
        pat = &patternSelected;
    } else {
        pat = view->getPattern(getPen().getLineType());
    }

    if (pat==NULL) {
        return;
    }

    if (ra<1.){
        painter->drawArc(cp,
                         ra,
                         0.0, 2*M_PI,
                         false);
        return;
    }

    // Pen to draw pattern is always solid:
    RS_Pen pen = painter->getPen();
    pen.setLineType(RS2::SolidLine);
    painter->setPen(pen);

    // create pattern:
    double* da=new double[pat->num>0?pat->num:0];
    int i(0),j(0);          // index counter
    if(pat->num>0){
        while(i<pat->num){
            //        da[j] = pat->pattern[i++] * styleFactor;
            //fixme, styleFactor needed
            da[i] = pat->pattern[i]/ra ;
            i++;
        }
        j=i;
    }else {
        //invalid pattern
        delete[] da;
        painter->drawArc(cp,
                         ra,
                         0.,2.*M_PI,
                         false);
        return;
    }

    double curA ( 0.0);
    double a2;
    bool notDone=true;

    for(i=0;notDone;i=(i+1)%j) {
        a2= curA+fabs(da[i]);
        if(a2>2.*M_PI) {
            a2=2.*M_PI;
            notDone=false;
        }
        if (da[i]>0.){
            painter->drawArc(cp, ra,
                             curA,
                             a2,
                             false);
        }
        curA=a2;
    }

    delete[] da;
}
void WGraphicsRectItem::paint(WPainter* painter)
{
	WPainterProxy proxy(painter);
	painter->setRenderHint(Ws::Antialiasing, false);
	painter->setRenderHint(Ws::TextAntialiasing, false);
	painter->setWorldTransform(getRotateMatrix(), true); //设置旋转矩阵

	painter->setBrush(brush());
	painter->setPen(pen());
	painter->drawRect(data()->rect); //绘制矩形
	
	if (isSelected()) //矩形被选中,绘制所有的控制点
	{
		painter->drawLine(WWorldLineF(_rotate_pt, WWorldPointF(_rotate_pt.x(), data()->rect.top())));

		painter->setPen(CP_PEN);
		painter->setBrush(CP_BRUSH);
		for (unsigned i=0; i<array_size(_cp); ++i)
		{
			if (i & 1)
			{
				painter->drawRect(WWorldRectF(_cp[i].x() - CP_RADIUS, _cp[i].y() - CP_RADIUS, CP_RADIUS * 2, CP_RADIUS * 2));
			}
			else
			{
				painter->drawEllipse(WWorldRectF(_cp[i].x() - CP_RADIUS, _cp[i].y() - CP_RADIUS, CP_RADIUS * 2, CP_RADIUS * 2));
			}
		}
		
		painter->setBrush(ROTATE_BRUSH);
		painter->drawEllipse(WWorldRectF(_rotate_pt.x() - CP_RADIUS, _rotate_pt.y() - CP_RADIUS, CP_RADIUS * 2, CP_RADIUS * 2));
	}

	if (_dragging) //矩形在拖动,绘制正在拖动的矩形
	{
		WWorldPointF pos = scene()->attachedPoint(scene()->mousePos());
		WPen dragPen = data()->pen;
		WBrush dragBrush = data()->brush;
		dragPen.setColor(dragPen.color().lighter(2.0));
		dragBrush.setColor(dragBrush.color().lighter(2.0));
		painter->setPen(dragPen);
		painter->setBrush(dragBrush);

		if (_select_flag != SF_ROTATE)
		{
			if (_select_flag != SF_CONTENT || isMovable())
			{
				WWorldPointF offset = pos - scene()->dragStartPos();
				const int (&f)[4] = ADJUST_TABLE[bit(_select_flag)];
				painter->drawRect(data()->rect.adjusted(offset.x() * f[0], offset.y() * f[1], offset.x() * f[2], offset.y() * f[3]));
			}
		}
		else
		{
			painter->setWorldTransform(getRotateMatrix_1(), true);

			WWorldPointF c = data()->rect.center();
			double ag = WWorldLineF(c, pos).angle() - 90;
			painter->setWorldTransform(WMatrix().translate(-c.x(), -c.y()) * WMatrix().rotate(ag + data()->angle) * WMatrix().translate(c.x(), c.y()));
			painter->drawRect(data()->rect);
		}
	}
}
bool WGraphicsRectItem::contains(const WWorldPointF& point) const
{
	bool b = data()->rect.adjusted(-CP_RADIUS, -CP_RADIUS, CP_RADIUS, CP_RADIUS).contains(point);
	return isSelected() ? (b || distance(point, _rotate_pt) < CP_RADIUS) : b;
}
void MismatchingConnectorWidget::mousePressEvent(QMouseEvent * event) {
	if(!isSelected()) {
		setSelected(true);
	}
	QFrame::mousePressEvent(event);
}
Esempio n. 11
0
  void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  {
    Q_UNUSED(option);
    Q_UNUSED(widget);

    if (d->points.size() < 2) return ;

    // draw the bounding rect if the arrow is selected
    if (isSelected() /* && !m_hoverBegin && !m_hoverEnd */) {
      painter->save();
      painter->setPen(Qt::blue);
      painter->drawRect(boundingRect());
      painter->restore();
    }

    if (d->points.isEmpty()) return ;

    // prepare pen and brush
    painter->save();
    QPen pen;
    pen.setWidthF(lineWidth()) ;
    pen.setCapStyle(Qt::RoundCap) ;
    pen.setJoinStyle(Qt::RoundJoin) ;
    pen.setColor(getColor()) ;
    painter->setPen(pen) ;

    QPainterPath path ;
    // draw the line
    path.moveTo(d->points.first()) ;
    if (d->spline && splinePossible(d->points.size()))
    {
      for (int i = 1 ; i+2 < d->points.size() ; i += 3)
        path.cubicTo(d->points[i],
                     d->points[i+1],
            d->points[i+2]);
      if (isSelected()) // Draw help lines
      {
        painter->save();
        painter->setPen(Qt::gray) ;
        QPointF previous(d->points.first()) ;
        for (int i = 1 ; i+2 < d->points.size() ; i += 3)
        {
          painter->drawLine(previous, d->points[i]) ;
          painter->drawLine(d->points[i+1], d->points[i+2]);
          previous = d->points[i+2] ;
        }
        painter->restore();
      }
    }
    else
      foreach(const QPointF p, d->points.mid(1))
        path.lineTo(p) ;

    path.translate(-pos());
    painter->drawPath(path) ;

    // draw arrow tips
    painter->setBrush(pen.color());
    qreal tipScaling = relativeWidth();
    if (MolScene *sc = qobject_cast<MolScene*>(scene()))
      tipScaling *= sc->settings()->arrowTipWidth()->get();
    if ((UpperBackward | LowerBackward) & d->arrowType)
      painter->drawPath(generateArrowTip(d->points.last(),
                                         d->points[d->points.size()-2],
                        pos(),
                        UpperBackward & d->arrowType,
                        LowerBackward & d->arrowType,
                        tipScaling
                        ));
    if ((UpperForward | LowerForward) & d->arrowType)
      painter->drawPath(generateArrowTip(d->points.first(),
                                         d->points[1],
                        pos(),
                        LowerForward & d->arrowType,
                        UpperForward & d->arrowType,
                        tipScaling
                        )) ;
    painter->restore();

    graphicsItem::paint(painter, option, widget);
  }
Esempio n. 12
0
void ChannelListItem::paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int align )
{
	QPixmap back( width, height() );
	QPainter paint( &back );
	//KListViewItem::paintCell( &paint, cg, column, width, align );
	// PASTED FROM KLISTVIEWITEM:
	// set the alternate cell background colour if necessary
	QColorGroup _cg = cg;
	if (isAlternate())
		if (listView()->viewport()->backgroundMode()==Qt::FixedColor)
			_cg.setColor(QColorGroup::Background, static_cast< KListView* >(listView())->alternateBackground());
		else
			_cg.setColor(QColorGroup::Base, static_cast< KListView* >(listView())->alternateBackground());
	// PASTED FROM QLISTVIEWITEM
	{
		QPainter *p = &paint;

		QListView *lv = listView();
		if ( !lv )
			return;
		QFontMetrics fm( p->fontMetrics() );

		// any text we render is done by the Components, not by this class, so make sure we've nothing to write
		QString t;

		// removed text truncating code from Qt - we do that differently, further on

		int marg = lv->itemMargin();
		int r = marg;
	//	const QPixmap * icon = pixmap( column );

		const BackgroundMode bgmode = lv->viewport()->backgroundMode();
		const QColorGroup::ColorRole crole = QPalette::backgroundRoleFromMode( bgmode );

		if ( _cg.brush( crole ) != lv->colorGroup().brush( crole ) )
			p->fillRect( 0, 0, width, height(), _cg.brush( crole ) );
		else
		{
			// all copied from QListView::paintEmptyArea

			//lv->paintEmptyArea( p, QRect( 0, 0, width, height() ) );
			QStyleOption opt( lv->sortColumn(), 0 ); // ### hack; in 3.1, add a property in QListView and QHeader
			QStyle::SFlags how = QStyle::Style_Default;
			if ( lv->isEnabled() )
				how |= QStyle::Style_Enabled;

			lv->style().drawComplexControl( QStyle::CC_ListView,
						p, lv, QRect( 0, 0, width, height() ), lv->colorGroup(),
						how, QStyle::SC_ListView, QStyle::SC_None,
						opt );
		}



		if ( isSelected() &&
		(column == 0 || lv->allColumnsShowFocus()) ) {
			p->fillRect( r - marg, 0, width - r + marg, height(),
					_cg.brush( QColorGroup::Highlight ) );
	// removed text pen setting code from Qt
		}

		// removed icon drawing code from Qt

		// draw the tree gubbins
		if ( multiLinesEnabled() && column == 0 && isOpen() && childCount() ) {
			int textheight = fm.size( align, t ).height() + 2 * lv->itemMargin();
			textheight = QMAX( textheight, QApplication::globalStrut().height() );
			if ( textheight % 2 > 0 )
				textheight++;
			if ( textheight < height() ) {
				int w = lv->treeStepSize() / 2;
				lv->style().drawComplexControl( QStyle::CC_ListView, p, lv,
								QRect( 0, textheight, w + 1, height() - textheight + 1 ), _cg,
								lv->isEnabled() ? QStyle::Style_Enabled : QStyle::Style_Default,
								QStyle::SC_ListViewExpand,
								(uint)QStyle::SC_All, QStyleOption( this ) );
			}
		}
	}
	// END OF PASTE


	//do you see a better way to tell the TextComponent we are selected ?  - Olivier 2004-09-02
	if ( isSelected() )
		_cg.setColor(QColorGroup::Text , _cg.highlightedText() );

	QSimpleRichText myrichtext( text(column), paint.font() );
	myrichtext.draw(  &paint, 0, 0, paint.window(), _cg );

	paint.end();
	p->drawPixmap( 0, 0, back );
}
Esempio n. 13
0
void JucerTreeViewBase::paintItem (Graphics& g, int /*width*/, int /*height*/)
{
    if (isSelected())
        g.fillAll (getOwnerView()->findColour (treeviewHighlightColourId));
}
Esempio n. 14
0
/**
 * Creates a vertex from the endpoint of the last element or 
 * sets the startpoint to the point 'v'.
 *
 * The very first vertex added is the starting point.
 * 
 * @param v vertex coordinate
 * @param bulge The bulge of the arc (see DXF documentation)
 * @param prepend true: Prepend instead of append at end
 *
 * @return Pointer to the entity that was created or NULL if this
 *         was the first vertex added.
 */
RS_Entity* RS_Polyline::createVertex(const RS_Vector& v, double bulge, bool prepend) {

    RS_Entity* entity=NULL;

    RS_DEBUG->print("RS_Polyline::createVertex: %f/%f to %f/%f bulge: %f",
                    data.endpoint.x, data.endpoint.y, v.x, v.y, bulge);

    // create line for the polyline:
    if (fabs(bulge)<RS_TOLERANCE) {
		if (prepend==false) {
        	entity = new RS_Line(this, RS_LineData(data.endpoint, v));
		}
		else {
        	entity = new RS_Line(this, RS_LineData(v, data.startpoint));
		}
        entity->setSelected(isSelected());
        entity->setPen(RS_Pen(RS2::FlagInvalid));
        entity->setLayer(NULL);
        //RS_EntityContainer::addEntity(entity);
        //data.endpoint = v;
    }

    // create arc for the polyline:
    else {
        bool reversed = (bulge<0.0);
        double alpha = atan(bulge)*4.0;

        double radius;
        RS_Vector center;
        RS_Vector middle;
        double dist;
        double angle;

		if (prepend==false) {
	        middle = (data.endpoint+v)/2.0;
    	    dist = data.endpoint.distanceTo(v)/2.0;
        	angle = data.endpoint.angleTo(v);
		}
		else {
	        middle = (data.startpoint+v)/2.0;
    	    dist = data.startpoint.distanceTo(v)/2.0;
        	angle = v.angleTo(data.startpoint);
		}

        // alpha can't be 0.0 at this point
        radius = fabs(dist / sin(alpha/2.0));

        double wu = fabs(RS_Math::pow(radius, 2.0) - RS_Math::pow(dist, 2.0));
        double h = sqrt(wu);

        if (bulge>0.0) {
            angle+=M_PI/2.0;
        } else {
            angle-=M_PI/2.0;
        }

        if (fabs(alpha)>M_PI) {
            h*=-1.0;
        }

        center.setPolar(h, angle);
        center+=middle;

		double a1;
		double a2;

		if (prepend==false) {
			a1 = center.angleTo(data.endpoint);
			a2 = center.angleTo(v);
		}
		else {
			a1 = center.angleTo(v);
			a2 = center.angleTo(data.startpoint);
		}

        RS_ArcData d(center, radius,
                     a1, a2,
                     reversed);

        entity = new RS_Arc(this, d);
        entity->setSelected(isSelected());
        entity->setPen(RS_Pen(RS2::FlagInvalid));
        entity->setLayer(NULL);
    }

    return entity;
}
Esempio n. 15
0
void UMLInheritanceLink::draw(Gtk::DrawingArea* drawingArea)
{
	Cairo::RefPtr<Cairo::Context> cr = drawingArea->get_window()->create_cairo_context();

	Arrows::draw_arrow(cr, getX1(), getY1(), getX2(), getY2(), Line::FULL, Arrow::NORMAL, Arrow::NONE, isSelected());
}
void WGraphicsRectItem::mouseMoveEvent(WGraphicsSceneMouseEvent* event)
{
	WMatrix matrix = getRotateMatrix_1();
	WWorldPointF pos = matrix.map(event->scenePos());
	
	if (isSelected())
	{
		if (event->buttons() & Ws::LeftButton) //drag move
		{
			_dragging = true;

			WWorldPointF lastPos = matrix.map(event->lastScenePos());
			WWorldPointF dragPos = matrix.map(scene()->dragStartPos());

			WWorldRectF r = boundingRect();
			if (_select_flag != SF_ROTATE) //矩形不是在旋转
			{
				if (_select_flag != SF_CONTENT || isMovable()) //矩形不是整个被选中
				{
					const int (&f)[4] = ADJUST_TABLE[bit(_select_flag)];

					WWorldPointF offsetFrom = lastPos - dragPos;
					WWorldPointF offsetTo = pos - dragPos;
					WWorldRectF rectFrom = data()->rect.adjusted(offsetFrom.x() * f[0], offsetFrom.y() * f[1], offsetFrom.x() * f[2], offsetFrom.y() * f[3]);
					WWorldRectF rectTo = data()->rect.adjusted(offsetTo.x() * f[0], offsetTo.y() * f[1], offsetTo.x() * f[2], offsetTo.y() * f[3]);
					scene()->update(expanded(rectFrom | rectTo | boundingRect()));
				}
			}
			else //矩形在旋转
			{
				double radius = std::max(data()->rect.width() / 2, data()->rect.height() / 2);
				WWorldPointF c = data()->rect.center();
				scene()->update(WWorldRectF(c.x(), c.y(), 0.0, 0.0).adjusted(-radius, -radius, radius, radius));
			}
		}
		else //update select flag (status transfer) 
		{
			int old_flag = _select_flag;
			if (!contains(pos)) //other status ---> none selected
			{
				_select_flag = SF_NONE;
			}
			else
			{
				unsigned i=0;
				unsigned size = array_size(_cp);
				for (; i<size; ++i)
				{
					if (distance(pos, _cp[i]) < CP_RADIUS) //detect wheter control point is selected
					{
						_select_flag = (1 << i); //control point _cp[i] is presently selected
						break;
					}
				}

				if (i == size)
				{
					_select_flag = (distance(_rotate_pt, pos) < CP_RADIUS) ? SF_ROTATE : SF_CONTENT;
				}
			}

			if (_select_flag != old_flag) //select status changed
			{
				scene()->update(boundingRect());
				event->widget()->setCursor(WCursor(getCursorShape(_select_flag)));
			}
		}
	}
}
Esempio n. 17
0
void QgsComposerPicture::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
{
  Q_UNUSED( itemStyle );
  Q_UNUSED( pWidget );
  if ( !painter )
  {
    return;
  }

  drawBackground( painter );

  //int newDpi = ( painter->device()->logicalDpiX() + painter->device()->logicalDpiY() ) / 2;

  //picture resizing
  if ( mMode != Unknown )
  {
    double boundRectWidthMM;
    double boundRectHeightMM;
    QRect imageRect;
    if ( mResizeMode == QgsComposerPicture::Zoom || mResizeMode == QgsComposerPicture::ZoomResizeFrame )
    {
      boundRectWidthMM = mPictureWidth;
      boundRectHeightMM = mPictureHeight;
      imageRect = QRect( 0, 0, mImage.width(), mImage.height() );
    }
    else if ( mResizeMode == QgsComposerPicture::Stretch )
    {
      boundRectWidthMM = rect().width();
      boundRectHeightMM = rect().height();
      imageRect = QRect( 0, 0, mImage.width(), mImage.height() );
    }
    else if ( mResizeMode == QgsComposerPicture::Clip )
    {
      boundRectWidthMM = rect().width();
      boundRectHeightMM = rect().height();
      int imageRectWidthPixels = mImage.width();
      int imageRectHeightPixels = mImage.height();
      imageRect = clippedImageRect( boundRectWidthMM, boundRectHeightMM ,
                                    QSize( imageRectWidthPixels, imageRectHeightPixels ) );
    }
    else
    {
      boundRectWidthMM = rect().width();
      boundRectHeightMM = rect().height();
      imageRect = QRect( 0, 0, rect().width() * mComposition->printResolution() / 25.4,
                         rect().height() * mComposition->printResolution() / 25.4 );
    }
    painter->save();
    //antialiasing on
    painter->setRenderHint( QPainter::Antialiasing, true );

    //zoom mode - calculate anchor point and rotation
    if ( mResizeMode == Zoom )
    {
      //TODO - allow placement modes with rotation set. for now, setting a rotation
      //always places picture in center of frame
      if ( mPictureRotation != 0 )
      {
        painter->translate( rect().width() / 2.0, rect().height() / 2.0 );
        painter->rotate( mPictureRotation );
        painter->translate( -boundRectWidthMM / 2.0, -boundRectHeightMM / 2.0 );
      }
      else
      {
        //shift painter to edge/middle of frame depending on placement
        double diffX = rect().width() - boundRectWidthMM;
        double diffY = rect().height() - boundRectHeightMM;

        double dX = 0;
        double dY = 0;
        switch ( mPictureAnchor )
        {
          case UpperLeft:
          case MiddleLeft:
          case LowerLeft:
            //nothing to do
            break;
          case UpperMiddle:
          case Middle:
          case LowerMiddle:
            dX = diffX / 2.0;
            break;
          case UpperRight:
          case MiddleRight:
          case LowerRight:
            dX = diffX;
            break;
        }
        switch ( mPictureAnchor )
        {
          case UpperLeft:
          case UpperMiddle:
          case UpperRight:
            //nothing to do
            break;
          case MiddleLeft:
          case Middle:
          case MiddleRight:
            dY = diffY / 2.0;
            break;
          case LowerLeft:
          case LowerMiddle:
          case LowerRight:
            dY = diffY;
            break;
        }
        painter->translate( dX, dY );
      }
    }

    if ( mMode == SVG )
    {
      mSVG.render( painter, QRectF( 0, 0, boundRectWidthMM,  boundRectHeightMM ) );
    }
    else if ( mMode == RASTER )
    {
      painter->drawImage( QRectF( 0, 0, boundRectWidthMM,  boundRectHeightMM ), mImage, imageRect );
    }

    painter->restore();
  }

  //frame and selection boxes
  drawFrame( painter );
  if ( isSelected() )
  {
    drawSelectionBoxes( painter );
  }
}
Esempio n. 18
0
void QgsComposerTable::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
{
  Q_UNUSED( itemStyle );
  Q_UNUSED( pWidget );
  if ( !painter )
  {
    return;
  }
  if ( !shouldDrawItem() )
  {
    return;
  }

  if ( mComposition->plotStyle() == QgsComposition::Print ||
       mComposition->plotStyle() == QgsComposition::Postscript )
  {
    //exporting composition, so force an attribute refresh
    //we do this in case vector layer has changed via an external source (eg, another database user)
    refreshAttributes();
  }

  drawBackground( painter );
  painter->save();
  //antialiasing on
  painter->setRenderHint( QPainter::Antialiasing, true );

  painter->setPen( Qt::SolidLine );

  //now draw the text
  double currentX = mGridStrokeWidth;
  double currentY;

  QList<QgsComposerTableColumn*>::const_iterator columnIt = mColumns.constBegin();

  int col = 0;
  double cellHeaderHeight = QgsComposerUtils::fontAscentMM( mHeaderFont ) + 2 * mLineTextDistance;
  double cellBodyHeight = QgsComposerUtils::fontAscentMM( mContentFont ) + 2 * mLineTextDistance;
  QRectF cell;
  for ( ; columnIt != mColumns.constEnd(); ++columnIt )
  {
    currentY = mGridStrokeWidth;
    currentX += mLineTextDistance;

    cell = QRectF( currentX, currentY, mMaxColumnWidthMap[col], cellHeaderHeight );

    //calculate alignment of header
    Qt::AlignmentFlag headerAlign = Qt::AlignLeft;
    switch ( mHeaderHAlignment )
    {
      case FollowColumn:
        headerAlign = ( *columnIt )->hAlignment();
        break;
      case HeaderLeft:
        headerAlign = Qt::AlignLeft;
        break;
      case HeaderCenter:
        headerAlign = Qt::AlignHCenter;
        break;
      case HeaderRight:
        headerAlign = Qt::AlignRight;
        break;
    }

    QgsComposerUtils::drawText( painter, cell, ( *columnIt )->heading(), mHeaderFont, mHeaderFontColor, headerAlign, Qt::AlignVCenter, Qt::TextDontClip );

    currentY += cellHeaderHeight;
    currentY += mGridStrokeWidth;

    //draw the attribute values
    QList<QgsAttributeMap>::const_iterator attIt = mAttributeMaps.begin();
    for ( ; attIt != mAttributeMaps.end(); ++attIt )
    {
      cell = QRectF( currentX, currentY, mMaxColumnWidthMap[col], cellBodyHeight );

      const QgsAttributeMap &currentAttributeMap = *attIt;
      QString str = currentAttributeMap[ col ].toString();
      QgsComposerUtils::drawText( painter, cell, str, mContentFont, mContentFontColor, ( *columnIt )->hAlignment(), Qt::AlignVCenter, Qt::TextDontClip );

      currentY += cellBodyHeight;
      currentY += mGridStrokeWidth;
    }

    currentX += mMaxColumnWidthMap[ col ];
    currentX += mLineTextDistance;
    currentX += mGridStrokeWidth;
    col++;
  }

  //and the borders
  if ( mShowGrid )
  {
    QPen gridPen;
    gridPen.setWidthF( mGridStrokeWidth );
    gridPen.setColor( mGridColor );
    gridPen.setJoinStyle( Qt::MiterJoin );
    painter->setPen( gridPen );
    drawHorizontalGridLines( painter, mAttributeMaps.size() );
    drawVerticalGridLines( painter, mMaxColumnWidthMap );
  }

  painter->restore();

  //draw frame and selection boxes if necessary
  drawFrame( painter );
  if ( isSelected() )
  {
    drawSelectionBoxes( painter );
  }
}
Esempio n. 19
0
bool QgsFeatureSelectionModel::isSelected( const QModelIndex &index )
{
  return isSelected( index.model()->data( index, QgsAttributeTableModel::FeatureIdRole ).toLongLong() );
}
Esempio n. 20
0
void CNItem::initPainter( QPainter &p )
{
	if ( isSelected() )
		p.setPen(m_selectedCol);
}
Esempio n. 21
0
void FileSystemActor::onRender(uint flags)
{
#ifdef TESTING_ALTERNATE_RENDERING
	
	if (isActorType(Invisible))
		return;

	// _isAnimatedTexture is always false right now since we don't robustly support animated gifs
	if (_isAnimatedTexture)
	{
		bool successful = true;
		
		// if this is an animated texture and we've never loaded the animation
		// then do so now

		if (!_animatedTextureSource.load())
			_isAnimatedTexture = false;

		if (_animatedTextureSource.numFrames() <= 1)
			successful = false;
		else
		{
			AnimatedTextureFrame * frame = _animatedTextureSource.getCurrentTextureFrame();
			Vec3 sz = getDims();

			glPushAttribToken token(GL_ENABLE_BIT);
			glEnable(GL_DEPTH_TEST);
			glEnable(GL_BLEND);
			glEnable(GL_TEXTURE_2D);

			// Conditionals
			if (isSelected() || isActorType(Temporary)) glDisable(GL_DEPTH_TEST);
			if (isActorType(Invisible)) return;

			//transform our unit cube:
			glPushMatrix();

				ShapeVis::setupGLMatrix(getGlobalPosition(), getGlobalOrientation());
				glScaled(sz.x, sz.y, sz.z);

				// render the current index
				glBindTexture(GL_TEXTURE_2D, _animatedTextureSource.GLId());			
				glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, frame->width, frame->height, GL_BGRA, GL_UNSIGNED_BYTE, frame->pixelData);
				
				// Set the Texture
				glColor4f(1, 1, 1, getAlpha());

				// Scale the image
				uint squareSize = closestPowerOfTwo(NxMath::max(frame->width, frame->height));
				float w = (float) frame->width / squareSize;
				float h = (float) frame->height / squareSize;
				h = 1.0f - (h * w);

				glBegin(GL_QUADS);
					glNormal3f(0,0,1);
					glTexCoord2f(w,0); 	glVertex3f(1,1,1);
					glTexCoord2f(0,0); 	glVertex3f(-1,1,1);
					glTexCoord2f(0,h); 	glVertex3f(-1,-1,1);
					glTexCoord2f(w,h); 	glVertex3f(1,-1,1);

					glNormal3f(0,0,-1);
					glTexCoord2f(0,h); 	glVertex3f(1,-1,-1);
					glTexCoord2f(w,h); 	glVertex3f(-1,-1,-1);
					glTexCoord2f(w,0); 	glVertex3f(-1,1,-1);
					glTexCoord2f(0,0); 	glVertex3f(1,1,-1);
				glEnd();

			glPopMatrix();
		}

		// skip the normal rendering routine
		if (successful)
			return;
	}

	// Render the previous actor first
	Actor::onRender(flags);

	// Render an overlay
	bool isLinkOverlay = (isFileSystemType(Link) || isFileSystemType(DeadLink)) && GLOBAL(settings).manualArrowOverlay;
	bool isFileTypeOverlay = !getTextIcon().isEmpty();
	
	if (isLinkOverlay || isFileTypeOverlay)
	{
		glPushAttribToken token(GL_ENABLE_BIT);
		glDisable(GL_DEPTH_TEST);
		glEnable(GL_BLEND);
		glEnable(GL_TEXTURE_2D);

		// Render the shortcut/file type icon Arrow
		QString renderTextureId = QT_NT("icon.linkOverlay");
		Vec3 renderPos = getGlobalPosition();
		Vec3 renderDims = getDims();
		bool shouldScaleIcon = false;
		if (isFileTypeOverlay)
		{
			renderTextureId = getTextIcon();
			shouldScaleIcon = true;
		}
		else if (isLinkOverlay)
		{
			// If the creator of the theme has a bad icon link overlay, we need to re-size it so it does not take up the entire actor
			// A "good" icon link overlay is 256x255; with the actual overlay part taking up 77x75 in the bottom-left corner
			Vec3 dimensions = texMgr->getTextureDims(renderTextureId);
			if (dimensions.x > 0 && dimensions.y > 0) 
			{
				if ((closestPowerOfTwo(dimensions.x) != 256) || (closestPowerOfTwo(dimensions.y) != 256))
				{
					shouldScaleIcon = true;
					
					// position the link icon to the corner of the actual actor (instead of scaling/stretching it)
					float maxSide = max(dimensions.x, dimensions.y);
					renderDims.x = renderDims.y = maxSide;
				}
			}
		}

		if (shouldScaleIcon)
		{
			Vec3 offset(getDims().x, -getDims().y, 0);
			
			// Scale the actor to proper size (256/77 =~ 3.4; 255/75 = 3.4)
			renderDims.x /= 3.4f;
			renderDims.y /= 3.4f;
			
			offset += Vec3(-renderDims.x - 0.25f, renderDims.y + 0.25f, 0);
			offset = getGlobalOrientation() * offset;
			renderPos += offset;
		}
		glBindTexture(GL_TEXTURE_2D, texMgr->getGLTextureId(renderTextureId));
		glColor4f(1, 1, 1, getAlpha());
		ShapeVis::renderSideLessBox(renderPos, getGlobalOrientation(), renderDims);
	}
#elif !defined DXRENDER
	// _isAnimatedTexture is always false right now since we don't robustly support animated gifs
	if (_isAnimatedTexture)
	{
		bool successful = true;
		
		// if this is an animated texture and we've never loaded the animation
		// then do so now

		if (!_animatedTextureSource.load())
			_isAnimatedTexture = false;

		if (_animatedTextureSource.numFrames() <= 1)
			successful = false;
		else
		{
			AnimatedTextureFrame * frame = _animatedTextureSource.getCurrentTextureFrame();
			Vec3 sz = getDims();

			glPushAttribToken token(GL_ENABLE_BIT);
			glEnable(GL_DEPTH_TEST);
			glEnable(GL_BLEND);
			glEnable(GL_TEXTURE_2D);

			// Conditionals
			if (isSelected() || isActorType(Temporary)) glDisable(GL_DEPTH_TEST);
			if (isActorType(Invisible)) return;

			//transform our unit cube:
			glPushMatrix();

				ShapeVis::setupGLMatrix(getGlobalPosition(), getGlobalOrientation());
				glScaled(sz.x, sz.y, sz.z);

				// render the current index
				glBindTexture(GL_TEXTURE_2D, _animatedTextureSource.GLId());			
				glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, frame->width, frame->height, GL_BGRA, GL_UNSIGNED_BYTE, frame->pixelData);
				
				// Set the Texture
				glColor4f(1, 1, 1, getAlpha());

				// Scale the image
				uint squareSize = closestPowerOfTwo(NxMath::max(frame->width, frame->height));
				float w = (float) frame->width / squareSize;
				float h = (float) frame->height / squareSize;
				h = 1.0f - (h * w);

				glBegin(GL_QUADS);
					glNormal3f(0,0,1);
					glTexCoord2f(w,0); 	glVertex3f(1,1,1);
					glTexCoord2f(0,0); 	glVertex3f(-1,1,1);
					glTexCoord2f(0,h); 	glVertex3f(-1,-1,1);
					glTexCoord2f(w,h); 	glVertex3f(1,-1,1);

					glNormal3f(0,0,-1);
					glTexCoord2f(0,h); 	glVertex3f(1,-1,-1);
					glTexCoord2f(w,h); 	glVertex3f(-1,-1,-1);
					glTexCoord2f(w,0); 	glVertex3f(-1,1,-1);
					glTexCoord2f(0,0); 	glVertex3f(1,1,-1);
				glEnd();

			glPopMatrix();
		}

		// skip the normal rendering routine
		if (successful)
			return;
	}

	// Render the previous actor first
	Actor::onRender(flags);

	// Render a link overlay arrow
	if ((isFileSystemType(Link) || isFileSystemType(DeadLink)) && !isActorType(Invisible))
	{
		glPushAttribToken token(GL_ENABLE_BIT);
		glDisable(GL_DEPTH_TEST);
		glEnable(GL_BLEND);
		glEnable(GL_TEXTURE_2D);

		// Render the shortcut Arrow
		if (GLOBAL(settings).manualArrowOverlay)
		{
			glBindTexture(GL_TEXTURE_2D, texMgr->getGLTextureId("icon.linkOverlay"));

			bool scaleOverlayActor = false;

			//If the creator of the theme has a bad icon link overlay, we need to re-size it so it does not take up the entire actor
			Vec3 dimensions = texMgr->getTextureDims("icon.linkOverlay");

			//A "good" icon link overlay is 256x255; with the actual overlay part taking up 77x75 in the bottom-left corner
			if(dimensions.x > 0 && dimensions.y > 0) {
				if((closestPowerOfTwo(dimensions.x) != 256)||(closestPowerOfTwo(dimensions.y) != 256))
					scaleOverlayActor = true;
			}

			glColor4f(1, 1, 1, getAlpha());

			// Render Shape
			Vec3 pos = getGlobalPosition();
			Vec3 dims = getDims();
			Vec3 normalizedDims = dims;

			// position the link icon to the corner of the actual actor (instead of scaling/stretching it)
			float maxSide = max(dims.x, dims.y);
			normalizedDims.x = normalizedDims.y = maxSide;

			// Scale the actor to proper size (256/77 =~ 3.4; 255/75 = 3.4)
			if(scaleOverlayActor){
				normalizedDims.x /= 3.4f;
				normalizedDims.y /= 3.4f;
			}
			
			if(scaleOverlayActor) {
				Vec3 offset(dims.x, -dims.y, 0);
				offset = getGlobalOrientation() * offset;
				pos += offset;
			} else {
				pos.x -= normalizedDims.x - dims.x;
				pos.z += normalizedDims.y - dims.y;
			}

			ShapeVis::renderSideLessBox(pos, getGlobalOrientation(), normalizedDims);
		}
	}
#elif defined DXRENDER
	// Render the previous actor first
	Actor::onRender(flags);

	// Render a link overlay arrow
	if ((isFileSystemType(Link) || isFileSystemType(DeadLink)) && !isActorType(Invisible))
	{
		// Render the shortcut Arrow
		if (GLOBAL(settings).manualArrowOverlay)
		{
			bool scaleOverlayActor = false;

			//If the creator of the theme has a bad icon link overlay, we need to re-size it so it does not take up the entire actor
			Vec3 dimensions = texMgr->getTextureDims("icon.linkOverlay");

			//A "good" icon link overlay is 256x255; with the actual overlay part taking up 77x75 in the bottom-left corner
			if(dimensions.x > 0 && dimensions.y > 0) {
				if((closestPowerOfTwo(dimensions.x) != 256)||(closestPowerOfTwo(dimensions.y) != 256))
					scaleOverlayActor = true;
			}

			// Render Shape
			Vec3 pos = getGlobalPosition();
			Vec3 dims = getDims();
			Vec3 normalizedDims = dims;

			// position the link icon to the corner of the actual actor (instead of scaling/stretching it)
			float maxSide = max(dims.x, dims.y);
			normalizedDims.x = normalizedDims.y = maxSide;

			// Scale the actor to proper size (256/77 =~ 3.4; 255/75 = 3.4)
			if(scaleOverlayActor){
				normalizedDims.x /= 3.4f;
				normalizedDims.y /= 3.4f;
			}
			
			if(scaleOverlayActor) {
				Vec3 offset(dims.x, -dims.y, 0);
				offset = getGlobalOrientation() * offset;
				pos += offset;
			} else {
				pos.x -= normalizedDims.x - dims.x;
				pos.z += normalizedDims.y - dims.y;
			}
			
			dxr->device->SetRenderState(D3DRS_ZENABLE, false);
			dxr->renderSideLessBox(pos, getGlobalOrientation(), normalizedDims, texMgr->getGLTextureId("icon.linkOverlay"));
			dxr->device->SetRenderState(D3DRS_ZENABLE, true);
		}
	}
#endif
}
Esempio n. 22
0
void GCUserViewGroupItem::paintCell(QPainter *p, const QColorGroup & cg, int column, int width, int alignment)
{
	QColorGroup xcg = cg;
	QFont f = p->font();
	f.setPointSize(common_smallFontSize);
	p->setFont(f);
	xcg.setColor(QColorGroup::Text, PsiOptions::instance()->getOption("options.ui.look.colors.contactlist.grouping.header-foreground").value<QColor>());
	if (!PsiOptions::instance()->getOption("options.ui.look.contactlist.use-slim-group-headings").toBool()) {
		#if QT_VERSION < 0x040301
			xcg.setColor(QColorGroup::Background, PsiOptions::instance()->getOption("options.ui.look.colors.contactlist.grouping.header-background").value<QColor>());
		#else
			xcg.setColor(QColorGroup::Base, PsiOptions::instance()->getOption("options.ui.look.colors.contactlist.grouping.header-background").value<QColor>());
		#endif
	}
	Q3ListViewItem::paintCell(p, xcg, column, width, alignment);
	if (PsiOptions::instance()->getOption("options.ui.look.contactlist.use-slim-group-headings").toBool() && !isSelected()) {
		QFontMetrics fm(p->font());
		int x = fm.width(text(column)) + 8;
		if(x < width - 8) {
			int h = (height() / 2) - 1;
			p->setPen(QPen(PsiOptions::instance()->getOption("options.ui.look.colors.contactlist.grouping.header-background").value<QColor>()));
			p->drawLine(x, h, width - 8, h);
			h++;
			p->setPen(QPen(PsiOptions::instance()->getOption("options.ui.look.colors.contactlist.grouping.header-foreground").value<QColor>()));
			p->drawLine(x, h, width - 8, h);
		}
	}
}
Esempio n. 23
0
QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )
{
  QSizeF size;
  double maxXCoord = 0;



  //go through model...
  QStandardItem* rootItem = mLegendModel.invisibleRootItem();
  if ( !rootItem )
  {
    return size;
  }


  if ( painter )
  {
    painter->save();
    drawBackground( painter );
    painter->setPen( QPen( QColor( 0, 0, 0 ) ) );
  }

  int numLayerItems = rootItem->rowCount();
  QStandardItem* currentLayerItem = 0;
  double currentYCoordinate = mBoxSpace;

  //font metrics

  //draw title
  currentYCoordinate += fontAscentMillimeters( mTitleFont );
  if ( painter )
  {
    painter->setPen( QColor( 0, 0, 0 ) );
    drawText( painter, mBoxSpace, currentYCoordinate, mTitle, mTitleFont );
  }


  maxXCoord = 2 * mBoxSpace + textWidthMillimeters( mTitleFont, mTitle );

  double currentItemMaxX = 0; //maximum x-coordinate for current item
  for ( int i = 0; i < numLayerItems; ++i )
  {
    currentLayerItem = rootItem->child( i );
    QgsComposerLegendItem* currentLegendItem = dynamic_cast<QgsComposerLegendItem*>( currentLayerItem );
    if ( currentLegendItem )
    {
      QgsComposerLegendItem::ItemType type = currentLegendItem->itemType();
      if ( type == QgsComposerLegendItem::GroupItem )
      {
        drawGroupItem( painter, dynamic_cast<QgsComposerGroupItem*>( currentLegendItem ), currentYCoordinate, currentItemMaxX );
        maxXCoord = qMax( maxXCoord, currentItemMaxX );
      }
      else if ( type == QgsComposerLegendItem::LayerItem )
      {
        drawLayerItem( painter, dynamic_cast<QgsComposerLayerItem*>( currentLegendItem ), currentYCoordinate, currentItemMaxX );
        maxXCoord = qMax( maxXCoord, currentItemMaxX );
      }
    }
  }

  currentYCoordinate += mBoxSpace;

  size.setHeight( currentYCoordinate );
  size.setWidth( maxXCoord );

  //adjust box if width or height is to small
  if ( painter && currentYCoordinate > rect().height() )
  {
    setSceneRect( QRectF( transform().dx(), transform().dy(), rect().width(), currentYCoordinate ) );
  }
  if ( painter && maxXCoord > rect().width() )
  {
    setSceneRect( QRectF( transform().dx(), transform().dy(), maxXCoord, rect().height() ) );
  }

  if ( painter )
  {
    painter->restore();

    //draw frame and selection boxes if necessary
    drawFrame( painter );
    if ( isSelected() )
    {
      drawSelectionBoxes( painter );
    }
  }

  return size;
}
Esempio n. 24
0
void OSListItem::toggleSelected()
{
  setSelected( ! isSelected() );
}
Esempio n. 25
0
void BrushInstance::renderClipPlane (Renderer& renderer, const VolumeTest& volume) const
{
	if (GlobalSelectionSystem().ManipulatorMode() == SelectionSystem::eClip && isSelected()) {
		m_clipPlane.render(renderer, volume, localToWorld());
	}
}
Esempio n. 26
0
 inline bool isSelected(const ServerData *ui_data, bool channel_only) const {
     return isSelected(*ui_data->arg, channel_only);
 }
Esempio n. 27
0
void RS_Line::draw(RS_Painter* painter, RS_GraphicView* view, double& patternOffset) {
    if (painter==NULL || view==NULL) {
        return;
    }

    //only draw the visible portion of line
    QVector<RS_Vector> endPoints(0);
        RS_Vector vpMin(view->toGraph(0,view->getHeight()));
        RS_Vector vpMax(view->toGraph(view->getWidth(),0));
         QPolygonF visualBox(QRectF(vpMin.x,vpMin.y,vpMax.x-vpMin.x, vpMax.y-vpMin.y));
    if( getStartpoint().isInWindowOrdered(vpMin, vpMax) ) endPoints<<getStartpoint();
    if( getEndpoint().isInWindowOrdered(vpMin, vpMax) ) endPoints<<getEndpoint();
    if(endPoints.size()<2){

         QVector<RS_Vector> vertex;
         for(unsigned short i=0;i<4;i++){
             const QPointF& vp(visualBox.at(i));
             vertex<<RS_Vector(vp.x(),vp.y());
         }
         for(unsigned short i=0;i<4;i++){
             RS_Line line(NULL,RS_LineData(vertex.at(i),vertex.at((i+1)%4)));
             auto&& vpIts=RS_Information::getIntersection(static_cast<RS_Entity*>(this), &line, true);
             if( vpIts.size()==0) continue;
             endPoints<<vpIts.get(0);
         }
    }
    if(endPoints.size()<2) return;
    if( (endPoints[0] - getStartpoint()).squared() >
            (endPoints[1] - getStartpoint()).squared() ) std::swap(endPoints[0],endPoints[1]);

    RS_Vector pStart(view->toGui(endPoints.at(0)));
    RS_Vector pEnd(view->toGui(endPoints.at(1)));
    //    std::cout<<"draw line: "<<pStart<<" to "<<pEnd<<std::endl;
    RS_Vector direction=pEnd-pStart;
    if(isHelpLayer(true) && direction.squared() > RS_TOLERANCE){
        //extend line on a help layer to fill the whole view
        RS_Vector lb(0,0);
        RS_Vector rt(view->getWidth(),view->getHeight());
        QList<RS_Vector> rect;
        rect<<lb<<RS_Vector(rt.x,lb.y);
        rect<<rt<<RS_Vector(lb.x,rt.y);
        rect<<lb;
        RS_VectorSolutions sol;
        RS_Line dLine(pStart,pEnd);
        for(int i=0;i<4;i++){
            RS_Line bLine(rect.at(i),rect.at(i+1));
            RS_VectorSolutions sol2=RS_Information::getIntersection(&bLine, &dLine);
            if( sol2.getNumber()>0 && bLine.isPointOnEntity(sol2.get(0),RS_TOLERANCE)) {
                sol.push_back(sol2.get(0));
            }
        }
        switch(sol.getNumber()){
        case 2:
            pStart=sol.get(0);
            pEnd=sol.get(1);
            break;
        case 3:
        case 4:
            pStart=sol.get(0);
            pEnd=sol.get(2);
            break;
        default:
            return;
        }
        direction=pEnd-pStart;
    }
    double  length=direction.magnitude();
    patternOffset -= length;
    if (( !isSelected() && (
              getPen().getLineType()==RS2::SolidLine ||
              view->getDrawingMode()==RS2::ModePreview)) ) {
        //if length is too small, attempt to draw the line, could be a potential bug
        painter->drawLine(pStart,pEnd);
        return;
    }
    //    double styleFactor = getStyleFactor(view);


    // Pattern:
    RS_LineTypePattern* pat;
    if (isSelected()) {
//        styleFactor=1.;
        pat = &patternSelected;
    } else {
        pat = view->getPattern(getPen().getLineType());
    }
    if (pat==NULL) {
//        patternOffset -= length;
        RS_DEBUG->print(RS_Debug::D_WARNING,
                        "RS_Line::draw: Invalid line pattern");
        painter->drawLine(pStart,pEnd);
        return;
    }
//    patternOffset = remainder(patternOffset - length-0.5*pat->totalLength,pat->totalLength)+0.5*pat->totalLength;
    if(length<=RS_TOLERANCE){
        painter->drawLine(pStart,pEnd);
        return; //avoid division by zero
    }
    direction/=length; //cos(angle), sin(angle)
    // Pen to draw pattern is always solid:
    RS_Pen pen = painter->getPen();

    pen.setLineType(RS2::SolidLine);
    painter->setPen(pen);

    // index counter
    int i;

    // pattern segment length:
    double patternSegmentLength = pat->totalLength;

  double styleFactor = view->getStyleFactor();    /* ++++++++++++++++ new added, in SETTINGS adapt. */

    // create pattern:
    RS_Vector* dp=new RS_Vector[pat->num > 0?pat->num:0];
    double* ds=new double[pat->num > 0?pat->num:0];
    if (pat->num >0 ){
        double dpmm=static_cast<RS_PainterQt*>(painter)->getDpmm();
        for (i=0; i<pat->num; ++i) {
            //        ds[j]=pat->pattern[i] * styleFactor;
            //fixme, styleFactor support needed

            ds[i]=dpmm * styleFactor * pat->pattern[i];
            if( fabs(ds[i]) < 1. ) ds[i] = (ds[i]>=0.)?1.:-1.;
            dp[i] = direction * fabs(ds[i]);
        }
    }else {
        delete[] dp;
        delete[] ds;
        RS_DEBUG->print(RS_Debug::D_WARNING,"invalid line pattern for line, draw solid line instread");
        painter->drawLine(view->toGui(getStartpoint()),
                          view->toGui(getEndpoint()));
        return;
    }
    double total= remainder(patternOffset-0.5*patternSegmentLength,patternSegmentLength) -0.5*patternSegmentLength;
    //    double total= patternOffset-patternSegmentLength;

    RS_Vector p1,p2,p3;
    RS_Vector curP(pStart+direction*total);
    double t2;
    for(int j=0;total<length;j=(j+1)%i) {

        // line segment (otherwise space segment)
        t2=total+fabs(ds[j]);
        p3=curP+dp[j];
        if (ds[j]>0.0 && t2 > 0.0) {
            // drop the whole pattern segment line, for ds[i]<0:
            // trim end points of pattern segment line to line
            p1 =(total > -0.5)? curP:pStart;
            p2 =(t2<length+0.5)?p3:pEnd;
            painter->drawLine(p1,p2);
        }
        total=t2;
        curP=p3;
    }
    delete[] dp;
    delete[] ds;

}
Esempio n. 28
0
 inline bool isSelected(const ChannelData *ui_data) const {
     return isSelected(*ui_data->arg);
 }
Esempio n. 29
0
void
EditorItem::paintCell(QPainter *p, const QColorGroup & cg, int column, int width, int align)
{
	//int margin = static_cast<Editor*>(listView())->itemMargin();
	if(!d->property)
		return;

	if(column == 0)
	{
		QFont font = listView()->font();
		if(d->property->isModified())
			font.setBold(true);
		p->setFont(font);
		p->setBrush(cg.highlight());
		p->setPen(cg.highlightedText());
		KListViewItem::paintCell(p, cg, column, width, align);
		p->fillRect(parent() ? 0 : 50, 0, width, height()-1,
			QBrush(isSelected() ? cg.highlight() : backgroundColor()));
		p->setPen(isSelected() ? cg.highlightedText() : cg.text());
		int delta = -20+KPROPEDITOR_ITEM_MARGIN;
		if ((firstChild() && dynamic_cast<EditorGroupItem*>(parent()))) {
			delta = -KPROPEDITOR_ITEM_MARGIN-1;
		}
		if (dynamic_cast<EditorDummyItem*>(parent())) {
			delta = KPROPEDITOR_ITEM_MARGIN*2;
		}
		else if (parent() && dynamic_cast<EditorDummyItem*>(parent()->parent())) {
			if (dynamic_cast<EditorGroupItem*>(parent()))
				delta += KPROPEDITOR_ITEM_MARGIN*2;
			else
				delta += KPROPEDITOR_ITEM_MARGIN*5;
		}
		p->drawText(
			QRect(delta,2, width+listView()->columnWidth(1)-KPROPEDITOR_ITEM_MARGIN*2, height()),
			Qt::AlignLeft | Qt::AlignTop /*| Qt::SingleLine*/, text(0));

		p->setPen( KPROPEDITOR_ITEM_BORDER_COLOR );
		p->drawLine(width-1, 0, width-1, height()-1);
		p->drawLine(0, -1, width-1, -1);

		p->setPen( KPROPEDITOR_ITEM_BORDER_COLOR ); //! \todo custom color?
		if (dynamic_cast<EditorDummyItem*>(parent()))
			p->drawLine(0, 0, 0, height()-1 );
	}
	else if(column == 1)
	{
		QColorGroup icg(cg);
		icg.setColor(QColorGroup::Background, backgroundColor());
		p->setBackgroundColor(backgroundColor());
		Widget *widget = d->editor->createWidgetForProperty(d->property, false /*don't change Widget::property() */);
		if(widget) {
			QRect r(0, 0, d->editor->header()->sectionSize(1), height() - (widget->hasBorders() ? 0 : 1));
			p->setClipRect(r, QPainter::CoordPainter);
			p->setClipping(true);
			widget->drawViewer(p, icg, r, d->property->value());
			p->setClipping(false);
		}
	}
	p->setPen( KPROPEDITOR_ITEM_BORDER_COLOR ); //! \todo custom color?
	p->drawLine(0, height()-1, width, height()-1 );
}
Esempio n. 30
0
void Box::update(Events gameEvents)
{
    // ------------------------------- ACTIVE -------------------------------
    if(body->IsActive())
    {
        // Update UserData
        body->SetUserData(this);

        // ------------------------------- Dynamic only -------------------------------
        if(body->GetType() == b2_dynamicBody)
        {
            sprite.setPosition(body->GetPosition().x * SCALE, body->GetPosition().y * SCALE);
            sprite.setRotation(180/b2_pi * body->GetAngle());
            overlaySprite.setPosition(body->GetPosition().x * SCALE, body->GetPosition().y * SCALE);
            overlaySprite.setRotation(180/b2_pi * body->GetAngle());

            lastMouse.x = gameEvents.lastMouse.x;
            lastMouse.y = gameEvents.lastMouse.y;

            // Movement
            moveToTargetArea();

            // AI
            ai();

            // Atack
            attack();
        }
        else // ------------------------------- Static only -------------------------------
        {
            ai();
            attack();
            checkNotifications();
            checkForConversion();
        }
        // ------------------------------- Both -------------------------------
        processImpulse();

        // Deletes boxes that have fallen out of the world
        checkHeight();

        // MouseOver
        if(isSelected(gameEvents.lastMouse.x, gameEvents.lastMouse.y))
        {
            isInfo = true;
            sprite.setColor(sf::Color(120, 120, 120, 255));
        }
        else
        {
            isInfo = false;
            sprite.setColor(sf::Color(255, 255, 255, 255));
        }
    }
    else // ------------------------------- INACTIVE -------------------------------
    {
        if(body->GetType() == b2_staticBody)
        {
            checkNotifications();

            if(isSelected(gameEvents.lastMouse.x, gameEvents.lastMouse.y))
            {
                sprite.setColor(sf::Color(120, 120, 120, 255));
            }
            else
            {
                sprite.setColor(sf::Color(200, 200, 200, 255));
            }
        }
    }

    // ------------------------------- Independant of active status -------------------------------
    // Check for minimap
//    float percX = gameEvents.lastMouseWindow.x / window_width;
//    float percY = gameEvents.lastMouseWindow.y / window_height;
//
//    if(percX >= 0.0f && percX <= minimapSize && percY >= 1.0f - minimapSize && percY <= 1.0f)
//    {
//        sprite.setColor(sf::Color(255, 255, 255, 255));
//    }

    // Flicker as long as the timer is active
    if(!hitTimer.timeReached())
    {
        sprite.setColor(sf::Color::Red);
    }

    // Update timer
    hitTimer.update();
    hitNumberTimer.update();
}