Esempio n. 1
0
void DisplayClass::drawFurniture(bool b, Furniture* f, glm::mat4 modelMatrix) {
	for (int i = 0; i < f->primitives->size(); i++) {
		switch (*f->primitives->at(i)) {
		case 0:
			drawPrimitive(b, prism, modelMatrix * *f->localTransforms->at(i));
			break;
		case 1:
			drawPrimitive(b, cylinder, modelMatrix * *f->localTransforms->at(i));
			break;
		case 2:
			drawPrimitive(b, sphere, modelMatrix * *f->localTransforms->at(i));
			break;
		}
	}
}
Esempio n. 2
0
//------------------------------------------------------------------------------
//## UniformBuffer
TEST_F(Test_Shader_Shader, UniformBuffer)
{
    auto shader1 = Shader::create(LN_ASSETFILE("Shader/UniformBufferTest-1.fx"));

    auto vertexDecl1 = newObject<VertexLayout>();
    vertexDecl1->addElement(0, VertexElementType::Float3, VertexElementUsage::Position, 0);

    Vector3 v[] = {
        { 0, 0.5, 0 },
        { 0.5, -0.25, 0 },
        { -0.5, -0.25, 0 },
    };
    auto vb1 = newObject<VertexBuffer>(sizeof(v), v, GraphicsResourceUsage::Static);

    // VertexShader からのみ参照されるパラメータ
    shader1->findParameter("_Color1")->setVector(Vector4(1, 0, 0, 1));

    // PixelShader からのみ参照されるパラメータ
    shader1->findParameter("_Color2")->setVector(Vector4(0, 0, 1, 1));

    auto ctx = Engine::graphicsContext();
    TestEnv::resetGraphicsContext(ctx);
    ctx->setVertexLayout(vertexDecl1);
    ctx->setVertexBuffer(0, vb1);
    ctx->setShaderPass(shader1->techniques()[0]->passes()[0]);
    ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
    ctx->clear(ClearFlags::All, Color::White, 1.0f, 0);
    ctx->drawPrimitive(0, 1);

    ASSERT_SCREEN(LN_ASSETFILE("Shader/Result/Test_Shader_Shader-UniformBuffer-1.png"));
}
Esempio n. 3
0
//------------------------------------------------------------------------------
//## シェーダ側とホスト側で頂点レイアウトの過不足がある場合のテスト。必要な部分さえあれば描画は可能。
TEST_F(Test_Shader_Shader, NotProvidedVertexAttribute)
{
	auto shader1 = Shader::create(LN_ASSETFILE("Shader/NotProvidedVertexAttribute-1.fx"));

	auto vertexDecl1 = newObject<VertexLayout>();
	vertexDecl1->addElement(0, VertexElementType::Float3, VertexElementUsage::Position, 0);

	Vector3 v[] = {
		{ 0, 0.5, 0 },
		{ 0.5, -0.25, 0 },
		{ -0.5, -0.25, 0 },
	};
	auto vb1 = newObject<VertexBuffer>(sizeof(v), v, GraphicsResourceUsage::Static);

	auto ctx = Engine::graphicsContext();
	TestEnv::resetGraphicsContext(ctx);
	ctx->setVertexLayout(vertexDecl1);
	ctx->setVertexBuffer(0, vb1);
	ctx->setShaderPass(shader1->techniques()[0]->passes()[0]);
	ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
	ctx->clear(ClearFlags::All, Color::White, 1.0f, 0);
	ctx->drawPrimitive(0, 1);

	ASSERT_SCREEN(LN_ASSETFILE("Shader/Result/Test_Shader_Shader-NotProvidedVertexAttribute-1.png"));
}
Esempio n. 4
0
void TestPlugin::drawSceneGL() {
    m_context->viewport(0, 0, m_rect.width, m_rect.height);
    m_context->clear(GL_COLOR_BUFFER_BIT);

    if (m_scene.primitive != PrimitiveNone)
        drawPrimitive();
}
Esempio n. 5
0
void QMdStyle::drawBronzeSpinBoxButton(SubControl which,
        const QStyleOptionComplex *option, QPainter *painter) const
{
    PrimitiveElement arrow = PE_IndicatorArrowLeft;
    QRect buttonRect = option->rect;
    if ((which == SC_SpinBoxUp)
            != (option->direction == Qt::RightToLeft)) {
        arrow = PE_IndicatorArrowRight;
        buttonRect.translate(buttonRect.width() / 2, 0);
    }
    buttonRect.setWidth((buttonRect.width() + 1) / 2);

    QStyleOption buttonOpt(*option);
    painter->save();
    painter->setClipRect(buttonRect, Qt::IntersectClip);
    if (!(option->activeSubControls & which))
        buttonOpt.state &= ~(State_MouseOver | State_On | State_Sunken);
    drawBronzeBevel(&buttonOpt, painter);

    QStyleOption arrowOpt(buttonOpt);
    arrowOpt.rect = subControlRect(CC_SpinBox, option, which)
                    .adjusted(+3, +3, -3, -3);
    if(arrowOpt.rect.isValid())
        drawPrimitive(arrow, &arrowOpt, painter);
    painter->restore();
}
Esempio n. 6
0
void QCommonStyle_QtDShell::__override_drawPrimitive(int  pe0, const QStyleOption*  opt1, QPainter*  p2, const QWidget*  w3, bool static_call) const
{
    if (static_call) {
        QCommonStyle::drawPrimitive((QStyle::PrimitiveElement )pe0, (const QStyleOption* )opt1, (QPainter* )p2, (const QWidget* )w3);
    } else {
        drawPrimitive((QStyle::PrimitiveElement )pe0, (const QStyleOption* )opt1, (QPainter* )p2, (const QWidget* )w3);
    }
}
Esempio n. 7
0
//------------------------------------------------------------------------------
//## MultiTechMultiTexture
TEST_F(Test_Shader_Shader, MultiTechMultiTexture)
{
    auto shader1 = Shader::create(LN_ASSETFILE("Shader/MultiTechMultiTexture-1.fx"));

    auto vertexDecl1 = newObject<VertexLayout>();
    vertexDecl1->addElement(0, VertexElementType::Float3, VertexElementUsage::Position, 0);

    Vector3 v[] = {
        { 0, 0.5, 0 },
        { 0.5, -0.25, 0 },
        { -0.5, -0.25, 0 },
    };
    auto vb1 = newObject<VertexBuffer>(sizeof(v), v, GraphicsResourceUsage::Static);

    auto t1 = Texture2D::create(2, 2, TextureFormat::RGBA8);
    t1->clear(Color::Red);
    shader1->findParameter("_Texture1")->setTexture(t1);

    auto t2 = Texture2D::create(2, 2, TextureFormat::RGBA8);
    t2->clear(Color::Green);
    shader1->findParameter("_Texture2")->setTexture(t2);

    auto ctx = Engine::graphicsContext();
    TestEnv::resetGraphicsContext(ctx);
    ctx->setVertexLayout(vertexDecl1);
    ctx->setVertexBuffer(0, vb1);
    ctx->setPrimitiveTopology(PrimitiveTopology::TriangleList);
    ctx->clear(ClearFlags::All, Color::White, 1.0f, 0);

	// _Texture1 のみ (赤)
    ctx->setShaderPass(shader1->techniques()[0]->passes()[0]);
    ctx->drawPrimitive(0, 1);
    ASSERT_SCREEN(LN_ASSETFILE("Shader/Result/Test_Shader_Shader-MultiTechMultiTexture-1.png"));

	// _Texture2 のみ (緑)
    ctx->setShaderPass(shader1->techniques()[1]->passes()[0]);
    ctx->drawPrimitive(0, 1);
    ASSERT_SCREEN(LN_ASSETFILE("Shader/Result/Test_Shader_Shader-MultiTechMultiTexture-2.png"));

	// _Texture1 + _Texture2 (黄)
	ctx->setShaderPass(shader1->techniques()[2]->passes()[0]);
	ctx->drawPrimitive(0, 1);
	ASSERT_SCREEN(LN_ASSETFILE("Shader/Result/Test_Shader_Shader-MultiTechMultiTexture-3.png"));
}
Esempio n. 8
0
void MetalStyle::drawPrimitive( PrimitiveElement pe,
				QPainter *p,
				const QRect &r,
				const QColorGroup &cg,
				SFlags flags, const QStyleOption& opt ) const
{
    switch( pe ) {
    case PE_HeaderSection:
	if ( flags & Style_Sunken )
	    flags ^= Style_Sunken | Style_Raised;
	// fall through
    case PE_ButtonBevel:
    case PE_ButtonCommand:
	    drawMetalButton( p, r.x(), r.y(), r.width(), r.height(),
			     (flags & (Style_Sunken|Style_On|Style_Down)),
			     TRUE, !(flags & Style_Raised) );
	    break;
    case PE_PanelMenuBar:
	drawMetalFrame( p, r.x(), r.y(), r.width(), r.height() );
	break;
    case PE_ScrollBarAddLine:	
	drawMetalButton( p, r.x(), r.y(), r.width(), r.height(),
			 flags & Style_Down, !( flags & Style_Horizontal ) );
	drawPrimitive( (flags & Style_Horizontal) ? PE_ArrowRight :PE_ArrowDown,
		       p, r, cg, flags, opt );
	break;
    case PE_ScrollBarSubLine:
	drawMetalButton( p, r.x(), r.y(), r.width(), r.height(),
			 flags & Style_Down, !( flags & Style_Horizontal ) );
	drawPrimitive( (flags & Style_Horizontal) ? PE_ArrowLeft : PE_ArrowUp,
		       p, r, cg, flags, opt );
	break;

	
    case PE_ScrollBarSlider:
	drawMetalButton( p, r.x(), r.y(), r.width(), r.height(), FALSE,
			 flags & Style_Horizontal );
	break;
    default:
	QWindowsStyle::drawPrimitive( pe, p, r, cg, flags, opt );
	break;
    }
}
Esempio n. 9
0
//------------------------------------------------------------------------------
//## Basic
TEST_F(Test_Shader_Shader, IndependentSamplerState)
{
    auto shader1 = Shader::create(LN_ASSETFILE("Shader/IndependentSamplerState.fx"));

    auto vertexDecl1 = newObject<VertexLayout>();
    vertexDecl1->addElement(0, VertexElementType::Float3, VertexElementUsage::Position, 0);
    vertexDecl1->addElement(0, VertexElementType::Float2, VertexElementUsage::TexCoord, 0);

    struct Vertex
    {
        Vector3 pos;
        Vector2 uv;
    };
    Vertex v[] = {
        { { -1, 1, 0 }, { 0, 0 }, },	// 0.5 で中央の face からサンプリングする
        { { 0, 1, 0 }, { 1, 0 }, },
        { { -1, 0, 0 }, { 0, 1 }, },
        { { 0, 0, 0 }, { 1, 1 }, },
    };
    auto vb1 = newObject<VertexBuffer>(sizeof(v), v, GraphicsResourceUsage::Static);

    auto tex1 = newObject<Texture2D>(2, 2, TextureFormat::RGBA8);
    auto bmp1 = tex1->map(MapMode::Write);
    bmp1->setPixel32(0, 0, ColorI(255, 0, 0, 255));
    bmp1->setPixel32(1, 0, ColorI(255, 0, 255, 255));
    bmp1->setPixel32(0, 1, ColorI(0, 255, 0, 255));
    bmp1->setPixel32(1, 1, ColorI(0, 0, 255, 255));

    // TODO: まだ SamplerState 直接指定をサポートしていないので Texture に対してセットする方法でテストケースだけ用意しておく。
    // 後でサポートするとき、shader1->findParameter("mySamplerState")->setSamplerState(samplerState); とかに書き換える。
    auto samplerState = newObject<SamplerState>();
    samplerState->setFilterMode(TextureFilterMode::Linear);
    tex1->setSamplerState(samplerState);

    shader1->findParameter("_Texture")->setTexture(tex1);

    auto ctx = Engine::graphicsContext();
    TestEnv::resetGraphicsContext(ctx);
    ctx->setVertexLayout(vertexDecl1);
    ctx->setVertexBuffer(0, vb1);
    ctx->setIndexBuffer(nullptr);
    ctx->setShaderPass(shader1->techniques()[0]->passes()[0]);

    // * [ ] default
    {
        ctx->clear(ClearFlags::All, Color::White, 1.0f, 0);
		ctx->setPrimitiveTopology(PrimitiveTopology::TriangleStrip);
        ctx->drawPrimitive(0, 2);

        ASSERT_SCREEN(LN_ASSETFILE("Shader/Result/Test_Shader_Shader-IndependentSamplerState-1.png"));
    }
}
Esempio n. 10
0
void Renderer::draw(Renderable* ren, int depth) {
    assert(ren);

    if (ren->getType() == PRM) {
        drawPrimitive(dynamic_cast<Primitive*>(ren));
    } else if (ren->getType() == OBJ) {
        if (depth <= MAX_RECURSION_DEPTH)
            drawObject(dynamic_cast<Object*>(ren), depth);
    } else {
        fprintf(stderr, "Renderer::draw ERROR invalid RenderableType %d\n",
            ren->getType());
        exit(1);
    }
}
Esempio n. 11
0
void MetalStyle::drawComplexControl( ComplexControl cc,
				     QPainter *p,
				     const QWidget *widget,
				     const QRect &r,
				     const QColorGroup &cg,
				     SFlags how,
				     SCFlags sub,
				     SCFlags subActive,
				     const QStyleOption& opt ) const
{
    switch ( cc ) {
    case CC_Slider:
	{
	    const QSlider *slider = ( const QSlider* ) widget;
	    QRect handle = querySubControlMetrics( CC_Slider, widget,
						   SC_SliderHandle, opt);
	    if ( sub & SC_SliderGroove )
		QWindowsStyle::drawComplexControl( cc, p, widget, r, cg, how,
						   SC_SliderGroove, subActive, opt );
	    if ( (sub & SC_SliderHandle) && handle.isValid() )
		drawMetalButton( p, handle.x(), handle.y(), handle.width(),
				 handle.height(), FALSE,
				 slider->orientation() == QSlider::Horizontal);
	    break;
	}
    case CC_ComboBox:
	{
	    // not exactly correct...
	    const QComboBox *cmb = ( const QComboBox* ) widget;
	
	    qDrawWinPanel( p, r.x(), r.y(), r.width(), r.height(), cg, TRUE,
			   cmb->isEnabled() ? &cg.brush( QColorGroup::Base ) :
			                      &cg.brush( QColorGroup::Background ) );
	    drawMetalButton( p, r.x() + r.width() - 2 - 16, r.y() + 2, 16, r.height() - 4,
			     how & Style_Sunken, TRUE );
	    drawPrimitive( PE_ArrowDown, p,
			   QRect( r.x() + r.width() - 2 - 16 + 2,
				  r.y() + 2 + 2, 16 - 4, r.height() - 4 -4 ),
			   cg,
			   cmb->isEnabled() ? Style_Enabled : Style_Default,
			   opt );
	    break;
	}
    default:
	QWindowsStyle::drawComplexControl( cc, p, widget, r, cg, how, sub, subActive,
					   opt );
	break;
    }
}
Esempio n. 12
0
void DisplayClass::drawNode(Node* n) {
	bool b = false;
	if (selectedNode == n) {
		b = true;
	}
	if (n->shape != NULL) {
		glm::mat4 id;
		if (*n->shape->kind > 98) {
			id = id;// * glm::scale(glm::mat4(), glm::vec3(0.1, 0.1, 0.1));
		}
		drawPrimitive(b, n->shape, *n->translate * *n->rotate * *n->scale * id);
	}
	if (n->furniture != NULL) {
		drawFurniture(b, n->furniture, *n->translate * *n->rotate * *n->scale);
	}
	for (int i = 0; i < n->children->size(); i++) {
		drawNode(n->children->at(i));
	}
}
Esempio n. 13
0
void Face::drawGL()
{
	//compute Transformation
	int i,num;
	
	glPushMatrix();
	base.transformGL();
	//GLTools::DrawFrame();

	num=(int)(vertex.size());
	if(num<3){
		glPopMatrix();
		return;
		}
	if(enableAlfa)
	{
		glEnable(GL_BLEND);			// Turn Blending On
		glDepthMask(GL_FALSE);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE);	// Set The Blending Function For Translucency
	}
	glColor4f(r,g,b,alfa);
//	GLTools::Color(RED,0.55f);
	glEnable(GL_LIGHTING);
	glNormal3d(0,0,1.0);
		
	drawPrimitive();		

	glDisable(GL_BLEND);
	glDepthMask(GL_TRUE);
	//GLTools::Color(CYAN,1.0f);
	glColor4f(r,g,b,1);
	glDisable(GL_LIGHTING);
	glBegin(GL_LINE_STRIP);
	for(i=0;i<num;i++)glVertex3f(vertex[i].x,vertex[i].y,0);
	glVertex3f(vertex[0].x,vertex[0].y,0);
	glEnd();
	
	glEnable(GL_LIGHTING);
	glPopMatrix();
}
Esempio n. 14
0
File: 1.cpp Progetto: artfly/nsu_old
int main( int argc, char** argv ) {
    if( argc != 2) {
     std::cout <<" Usage: display_image ImageToLoadAndDisplay" << std::endl;
     return -1;
    }

    cv::Mat image;
    image = cv::imread(argv[1], CV_LOAD_IMAGE_COLOR);   // Read the file

    if(!image.data ) {
        std::cout << "Could not open or find the image" << std::endl;
    }

    countPixels(image);
    drawPrimitive(image);

    cv::namedWindow( "Display window", cv::WINDOW_AUTOSIZE );// Create a window for display.
    cv::imshow( "Display window", image );                   // Show our image inside it.

    cv::waitKey(0);                                          // Wait for a keystroke in the window
    return 0;
}
Esempio n. 15
0
void WindowsModernStyle::drawComplexControl( ComplexControl control, const QStyleOptionComplex* option,
	QPainter* painter, const QWidget* widget ) const
{
	switch ( control ) {
		case CC_ToolButton: {
			QToolBar* toolBar;
			if ( widget && ( toolBar = qobject_cast<QToolBar*>( widget->parentWidget() ) ) ) {
				if ( const QStyleOptionToolButton* optionToolButton = qstyleoption_cast<const QStyleOptionToolButton*>( option ) ) {
					QRect buttonRect = subControlRect( control, option, SC_ToolButton, widget );
					QStyle::State buttonState = option->state & ~State_Sunken;
					if ( option->state & State_Sunken ) {
						if ( optionToolButton->activeSubControls & SC_ToolButton )
							buttonState |= State_Sunken;
						else if ( optionToolButton->activeSubControls & SC_ToolButtonMenu )
							buttonState |= State_MouseOver;
					}
					bool selected = buttonState & State_MouseOver && option->state & State_Enabled;
					bool checked = buttonState & State_On;
					bool sunken = buttonState & State_Sunken;
					if ( selected || checked || sunken ) {
						QRect rect = buttonRect.adjusted( 0, 0, -1, -1 );
						painter->setPen( m_colorItemBorder );
						QLinearGradient gradient;
						if ( toolBar->orientation() == Qt::Vertical )
							gradient = QLinearGradient( rect.topLeft(), rect.topRight() );
						else
							gradient = QLinearGradient( rect.topLeft(), rect.bottomLeft() );
						if ( sunken || (selected && checked) ) {
							gradient.setColorAt( 0.0, m_colorItemSunkenBegin );
							gradient.setColorAt( 0.5, m_colorItemSunkenMiddle );
							gradient.setColorAt( 1.0, m_colorItemSunkenEnd );
						} else if ( checked ) {
							gradient.setColorAt( 0.0, m_colorItemCheckedBegin );
							gradient.setColorAt( 0.5, m_colorItemCheckedMiddle );
							gradient.setColorAt( 1.0, m_colorItemCheckedEnd );
						} else {
							gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
							gradient.setColorAt( 0.5, m_colorItemBackgroundMiddle );
							gradient.setColorAt( 1.0, m_colorItemBackgroundEnd );
						}
						painter->setBrush( gradient );
						painter->drawRect( rect );
					}
					QStyleOptionToolButton optionLabel = *optionToolButton;
					int fw = pixelMetric( PM_DefaultFrameWidth, option, widget );
					optionLabel.rect = buttonRect.adjusted( fw, fw, -fw, -fw );
					drawControl( CE_ToolButtonLabel, &optionLabel, painter, widget );
					if ( optionToolButton->subControls & SC_ToolButtonMenu ) {
						QStyleOption optionMenu = *optionToolButton;
						optionMenu.rect = subControlRect( control, option, SC_ToolButtonMenu, widget );
						optionMenu.state = optionToolButton->state & ~State_Sunken;
						if ( optionToolButton->state & State_Sunken ) {
							if ( optionToolButton->activeSubControls & SC_ToolButton )
								optionMenu.state |= State_MouseOver | State_Sunken;
							else if ( optionToolButton->activeSubControls & SC_ToolButtonMenu )
								optionMenu.state |= State_Sunken;
						}
						drawPrimitive( PE_IndicatorButtonDropDown, &optionMenu, painter, widget );
					} else if ( optionToolButton->features & QStyleOptionToolButton::HasMenu ) {
						int size = pixelMetric( PM_MenuButtonIndicator, option, widget );
						QRect rect = optionToolButton->rect;
						QStyleOptionToolButton optionArrow = *optionToolButton;
						optionArrow.rect = QRect( rect.right() + 4 - size, rect.height() - size + 4, size - 5, size - 5 );
						drawPrimitive( PE_IndicatorArrowDown, &optionArrow, painter, widget );
					}
					return;
				}
			}
			break;
		}

		default:
			break;
	}

	if ( useVista() )
		QWindowsVistaStyle::drawComplexControl( control, option, painter, widget );
	else
		QWindowsXPStyle::drawComplexControl( control, option, painter, widget );
}
Esempio n. 16
0
void WindowsModernStyle::drawControl( ControlElement element, const QStyleOption* option,
	QPainter* painter, const QWidget* widget ) const
{
	switch ( element ) {
		case CE_MenuBarEmptyArea:
			return;

		case CE_MenuBarItem:
			if ( option->state & QStyle::State_Sunken && option->state & QStyle::State_Enabled ) {
				painter->setPen( m_colorMenuBorder );
				QLinearGradient gradient( option->rect.topLeft(), option->rect.bottomLeft() );
				gradient.setColorAt( 0.0, m_colorMenuTitleBegin );
				gradient.setColorAt( 1.0, m_colorMenuTitleEnd );
				painter->setBrush( gradient );
				painter->drawRect( option->rect.adjusted( 0, 0, -1, 0 ) );
			} else if ( option->state & QStyle::State_Selected && option->state & QStyle::State_Enabled ) {
				painter->setPen( m_colorItemBorder );
				QLinearGradient gradient( option->rect.topLeft(), option->rect.bottomLeft() );
				gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
				gradient.setColorAt( 1.0, m_colorItemBackgroundEnd );
				painter->setBrush( gradient );
				painter->drawRect( option->rect.adjusted( 0, 0, -1, -1 ) );
			}
			if ( const QStyleOptionMenuItem* optionItem = qstyleoption_cast<const QStyleOptionMenuItem*>( option ) ) {
				int flags = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
				if ( !styleHint( SH_UnderlineShortcut, option, widget ) )
					flags |= Qt::TextHideMnemonic;
				if ( !optionItem->icon.isNull() ) {
					QPixmap pixmap = optionItem->icon.pixmap( pixelMetric( PM_SmallIconSize, option, widget ), QIcon::Normal );
					drawItemPixmap( painter, option->rect, flags, pixmap );
				} else {
					drawItemText( painter, option->rect, flags, option->palette, true, optionItem->text, QPalette::Text );
				}
			}
			return;

		case CE_MenuEmptyArea:
			painter->fillRect( option->rect, m_colorMenuBackground );
			return;

		case CE_MenuItem: {
			if ( option->state & QStyle::State_Selected && option->state & QStyle::State_Enabled ) {
				painter->setPen( m_colorItemBorder );
				painter->setBrush( m_colorItemBackgroundBegin );
				painter->drawRect( option->rect.adjusted( 1, 0, -3, -1 ) );
			} else {
				QLinearGradient gradient( QPoint( 0, 0 ), QPoint( 25, 0 ) );
				gradient.setColorAt( 0.0, m_colorBarBegin );
				gradient.setColorAt( 1.0, m_colorBarEnd );
				QRect margin = option->rect;
				margin.setWidth( 25 );
				painter->fillRect( margin, gradient );
				QRect background = option->rect;
				background.setLeft( margin.right() + 1 );
				painter->fillRect( background, m_colorMenuBackground );
			}
			if ( const QStyleOptionMenuItem* optionItem = qstyleoption_cast<const QStyleOptionMenuItem*>( option ) ) {
				if ( optionItem->menuItemType == QStyleOptionMenuItem::Separator ) {
					painter->setPen( m_colorSeparator );
					painter->drawLine( option->rect.left() + 32, ( option->rect.top() + option->rect.bottom() ) / 2,
						option->rect.right(), ( option->rect.top() + option->rect.bottom() ) / 2 );
					return;
				}
				QRect checkRect = option->rect.adjusted( 2, 1, -2, -2 );
				checkRect.setWidth( 20 );
				if ( optionItem->checked && option->state & QStyle::State_Enabled ) {
					painter->setPen( m_colorItemBorder );
					if ( option->state & QStyle::State_Selected && option->state & QStyle::State_Enabled )
						painter->setBrush( m_colorItemSunkenBegin );
					else
						painter->setBrush( m_colorItemCheckedBegin );
					painter->drawRect( checkRect );
				}
				if ( !optionItem->icon.isNull() ) {
					QIcon::Mode mode;
					if ( optionItem->state & State_Enabled )
						mode = ( optionItem->state & State_Selected ) ? QIcon::Active : QIcon::Normal;
					else
						mode = QIcon::Disabled;
					QIcon::State state = optionItem->checked ? QIcon::On : QIcon::Off;
					QPixmap pixmap = optionItem->icon.pixmap( pixelMetric( PM_SmallIconSize, option, widget ), mode, state );
					QRect rect = pixmap.rect();
					rect.moveCenter( checkRect.center() );
					painter->drawPixmap( rect.topLeft(), pixmap );
				} else if ( optionItem->checked ) {
					QStyleOption optionCheckMark;
					optionCheckMark.initFrom( widget );
					optionCheckMark.rect = checkRect;
					if ( !( option->state & State_Enabled ) )
						optionCheckMark.palette.setBrush( QPalette::Text, optionCheckMark.palette.brush( QPalette::Disabled, QPalette::Text ) );
					drawPrimitive( PE_IndicatorMenuCheckMark, &optionCheckMark, painter, widget );
				}
				QRect textRect = option->rect.adjusted( 32, 1, -16, -1 );
				int flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
				if ( !styleHint( SH_UnderlineShortcut, option, widget ) )
					flags |= Qt::TextHideMnemonic;
				QString text = optionItem->text;
				int pos = text.indexOf( '\t' );
				if ( pos >= 0 ) {
					drawItemText( painter, textRect, flags | Qt::AlignRight, option->palette, option->state & State_Enabled,
						text.mid( pos + 1 ), QPalette::Text );
					text = text.left( pos );
				}
				drawItemText( painter, textRect, flags, option->palette, option->state & State_Enabled, text, QPalette::Text );
				if ( optionItem->menuItemType == QStyleOptionMenuItem::SubMenu ) {
					QStyleOption optionArrow;
					optionArrow.initFrom( widget );
					optionArrow.rect = option->rect.adjusted( 0, 4, -4, -4 );
					optionArrow.rect.setLeft( option->rect.right() - 12 );
					optionArrow.state = option->state & State_Enabled;
					drawPrimitive( PE_IndicatorArrowRight, &optionArrow, painter, widget );
				}
			}
			return;
		}

		case CE_ToolBar: {
			QRect rect = option->rect;
			bool vertical = false;
			if ( const QToolBar* toolBar = qobject_cast<const QToolBar*>( widget ) ) {
				vertical = ( toolBar->orientation() == Qt::Vertical );
				if ( vertical )
					rect.setBottom( toolBar->childrenRect().bottom() + 2 );
				else
					rect.setRight( toolBar->childrenRect().right() + 2 );
			}
			painter->save();
			QRegion region = rect.adjusted( 2, 0, -2, 0 );
			region += rect.adjusted( 0, 2, 0, -2 );
			region += rect.adjusted( 1, 1, -1, -1 );
			painter->setClipRegion( region );
			QLinearGradient gradient;
			if ( vertical )
				gradient = QLinearGradient( rect.topLeft(), rect.topRight() );
			else
				gradient = QLinearGradient( rect.topLeft(), rect.bottomLeft() );
			gradient.setColorAt( 0.0, m_colorBarBegin );
			gradient.setColorAt( 0.4, m_colorBarMiddle );
			gradient.setColorAt( 0.6, m_colorBarMiddle );
			gradient.setColorAt( 1.0, m_colorBarEnd );
			painter->fillRect( rect, gradient );

			painter->setPen( vertical ? m_colorBorderLight : m_colorBorder );
			painter->drawLine( rect.bottomLeft() + QPoint( 2, 0 ), rect.bottomRight() - QPoint( 2, 0 ) );
			painter->setPen( vertical ? m_colorBorder : m_colorBorderLight );
			painter->drawLine( rect.topRight() + QPoint( 0, 2 ), rect.bottomRight() - QPoint( 0, 2 ) );
			painter->setPen( m_colorBorderLight );
			painter->drawPoint( rect.bottomRight() - QPoint( 1, 1 ) );
			painter->restore();
			return;
		}

		case CE_DockWidgetTitle: {
			QLinearGradient gradient( option->rect.topLeft(), option->rect.bottomLeft() );
			gradient.setColorAt( 0.0, m_colorBarBegin );
			gradient.setColorAt( 1.0, m_colorBarEnd );
			painter->fillRect( option->rect, gradient );
			if ( const QStyleOptionDockWidget* optionDockWidget = qstyleoption_cast<const QStyleOptionDockWidget*>( option ) ) {
				QRect rect = option->rect.adjusted( 6, 0, -4, 0 );
				if ( optionDockWidget->closable )
					rect.adjust( 0, 0, -16, 0 );
				if ( optionDockWidget->floatable )
					rect.adjust( 0, 0, -16, 0 );
				QString text = painter->fontMetrics().elidedText( optionDockWidget->title, Qt::ElideRight, rect.width() );
				drawItemText( painter, rect, Qt::AlignLeft | Qt::AlignVCenter, option->palette,
					option->state & State_Enabled, text, QPalette::WindowText );
			}
			return;
		}

		case CE_TabBarTabShape:
			if ( isStyledTabBar( widget ) ) {
				bool firstTab = false;
				bool lastTab = false;
				bool bottom = false;
				if ( const QStyleOptionTab* optionTab = qstyleoption_cast<const QStyleOptionTab*>( option ) ) {
					if ( optionTab->position == QStyleOptionTab::Beginning )
						firstTab = true;
					else if ( optionTab->position == QStyleOptionTab::End )
						lastTab = true;
					else if ( optionTab->position == QStyleOptionTab::OnlyOneTab )
						firstTab = lastTab = true;
					if ( optionTab->shape == QTabBar::RoundedSouth )
						bottom = true;
				}
				QRect rect = option->rect;
				painter->save();
				if ( option->state & State_Selected ) {
					if ( bottom )
						rect.adjust( firstTab ? 0 : -2, -1, lastTab ? -1 : 1, -1 );
					else
						rect.adjust( firstTab ? 0 : -2, 0, lastTab ? -1 : 1, 1 );
				} else {
					if ( bottom ) {
						rect.adjust( 0, -1, lastTab ? -1 : 0, -2 );
						painter->setClipRect( rect.adjusted( 0, 1, 1, 1 ) );
					} else {
						rect.adjust( 0, 1, lastTab ? -1 : 0, 0 );
						painter->setClipRect( rect.adjusted( 0, 0, 1, 0 ) );
					}
				}
				QLinearGradient gradient;
				if ( bottom )
					gradient = QLinearGradient( rect.bottomLeft(), rect.topLeft() );
				else
					gradient = QLinearGradient( rect.topLeft(), rect.bottomLeft() );
				if ( option->state & State_Selected ) {
					gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
					gradient.setColorAt( 1.0, option->palette.window().color() );
					painter->setPen( m_colorBorder );
				} else if ( option->state & State_MouseOver && option->state & State_Enabled ) {
					gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
					gradient.setColorAt( 1.0, m_colorItemBackgroundEnd );
					painter->setPen( m_colorBorderLight );
				} else {
					gradient.setColorAt( 0.0, m_colorBarMiddle );
					gradient.setColorAt( 1.0, m_colorBarEnd );
					painter->setPen( m_colorBorderLight );
				}
				painter->setBrush( gradient );
				painter->drawRect( rect );
				painter->restore();
				return;
			}
			break;

		case CE_ToolBoxTabShape: {
			QRect rect = option->rect.adjusted( 0, 0, -1, -1 );
			QLinearGradient gradient( rect.topLeft(), rect.bottomLeft() );
			if ( option->state & QStyle::State_Sunken ) {
				gradient.setColorAt( 0.0, m_colorItemSunkenBegin );
				gradient.setColorAt( 1.0, m_colorItemSunkenEnd );
				painter->setPen( m_colorBorder );
			} else if ( option->state & State_MouseOver && option->state & State_Enabled ) {
				gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
				gradient.setColorAt( 1.0, m_colorItemBackgroundEnd );
				painter->setPen( m_colorBorder );
			} else {
				gradient.setColorAt( 0.0, m_colorBarMiddle );
				gradient.setColorAt( 1.0, m_colorBarEnd );
				painter->setPen( m_colorBorderLight );
			}
			painter->setBrush( gradient );
			painter->drawRect( rect );
			return;
		}

		case CE_Splitter:
			if ( qobject_cast<const QMainWindow*>( widget->window() ) )
				return;
			break;

		default:
			break;
	}

	if ( useVista() )
		QWindowsVistaStyle::drawControl( element, option, painter, widget );
	else
		QWindowsXPStyle::drawControl( element, option, painter, widget );
}
Esempio n. 17
0
void WindowsModernStyle::drawPrimitive( PrimitiveElement element, const QStyleOption* option,
	QPainter* painter, const QWidget* widget ) const
{
	switch ( element ) {
		case PE_Widget:
			if ( qobject_cast<const QMainWindow*>( widget ) ) {
				QRect rect = option->rect;
				if ( QStatusBar* statusBar = widget->findChild<QStatusBar*>() ) {
					rect.adjust( 0, 0, 0, -statusBar->height() );
					painter->setPen( option->palette.light().color() );
					painter->drawLine( rect.bottomLeft() + QPoint( 0, 1 ),
						rect.bottomRight() + QPoint( 0, 1 ) );
				}
				QLinearGradient gradient( option->rect.topLeft(), option->rect.topRight() );
				gradient.setColorAt( 0.0, m_colorBackgroundBegin );
				gradient.setColorAt( 0.6, m_colorBackgroundEnd );
				painter->fillRect( rect, gradient );
				return;
			}

			if ( qobject_cast<const QToolBox*>( widget ) ) {
				QLinearGradient gradient( option->rect.topLeft(), option->rect.topRight() );
				gradient.setColorAt( 0.4, m_colorBackgroundBegin );
				gradient.setColorAt( 1.0, m_colorBackgroundEnd );
				painter->fillRect( option->rect, gradient );
				return;
			}

			if ( isToolBoxPanel( widget ) ) {
				QLinearGradient gradient( option->rect.topLeft(), option->rect.topRight() );
				gradient.setColorAt( 0.4, m_colorBarMiddle );
				gradient.setColorAt( 1.0, m_colorBarBegin );
				painter->fillRect( option->rect, gradient );
				return;
			}
			break;

		case PE_WindowGradient: {
			QLinearGradient gradient( option->rect.topLeft(), option->rect.topRight() );
			gradient.setColorAt( 0.0, m_colorBackgroundBegin );
			gradient.setColorAt( 0.6, m_colorBackgroundEnd );
			painter->fillRect( option->rect, gradient );
			return;
		}

		case PE_PanelMenuBar:
			return;

		case PE_FrameMenu:
			painter->setPen( m_colorMenuBorder );
			painter->setBrush( Qt::NoBrush );
			painter->drawRect( option->rect.adjusted( 0, 0, -1, -1 ) );

			if ( const QMenu* menu = qobject_cast<const QMenu*>( widget ) ) {
				if ( const QMenuBar* menuBar = qobject_cast<const QMenuBar*>( menu->parent() ) ) {
					QRect rect = menuBar->actionGeometry( menu->menuAction() );
					if ( !rect.isEmpty() ) {
						painter->setPen( m_colorMenuBackground );
						painter->drawLine( 1, 0, rect.width() - 2, 0 );
					}
				}
			}

			if ( const QToolBar* toolBar = qobject_cast<const QToolBar*>( widget ) ) {
				QRect rect = option->rect.adjusted( 1, 1, -1, -1 );
				QLinearGradient gradient;
				if ( toolBar->orientation() == Qt::Vertical )
					gradient = QLinearGradient( rect.topLeft(), rect.topRight() );
				else
					gradient = QLinearGradient( rect.topLeft(), rect.bottomLeft() );
				gradient.setColorAt( 0.0, m_colorBarBegin );
				gradient.setColorAt( 0.4, m_colorBarMiddle );
				gradient.setColorAt( 0.6, m_colorBarMiddle );
				gradient.setColorAt( 1.0, m_colorBarEnd );
				painter->fillRect( rect, gradient );
			}
			return;

		case PE_IndicatorToolBarHandle:
			if ( option->state & State_Horizontal ) {
				for ( int i = option->rect.height() / 5; i <= 4 * ( option->rect.height() / 5 ); i += 5 ) {
					int x = option->rect.left() + 3;
					int y = option->rect.top() + i + 1;
					painter->fillRect( x + 1, y, 2, 2, m_colorHandleLight );
					painter->fillRect( x, y - 1, 2, 2, m_colorHandle );
				}
			} else {
				for ( int i = option->rect.width() / 5; i <= 4 * ( option->rect.width() / 5 ); i += 5 ) {
					int x = option->rect.left() + i + 1;
					int y = option->rect.top() + 3;
					painter->fillRect( x, y + 1, 2, 2, m_colorHandleLight );
					painter->fillRect( x - 1, y, 2, 2, m_colorHandle );
				}
			}
			return;

		case PE_IndicatorToolBarSeparator:
			painter->setPen( m_colorSeparator );
			if ( option->state & State_Horizontal )
				painter->drawLine( ( option->rect.left() + option->rect.right() - 1 ) / 2, option->rect.top() + 2,
					( option->rect.left() + option->rect.right() - 1 ) / 2, option->rect.bottom() - 2 );
			else
				painter->drawLine( option->rect.left() + 2, ( option->rect.top() + option->rect.bottom() - 1 ) / 2,
					option->rect.right() - 2, ( option->rect.top() + option->rect.bottom() - 1 ) / 2 );
			painter->setPen( m_colorSeparatorLight );
			if ( option->state & State_Horizontal )
				painter->drawLine( ( option->rect.left() + option->rect.right() + 1 ) / 2, option->rect.top() + 2,
					( option->rect.left() + option->rect.right() + 1 ) / 2, option->rect.bottom() - 2 );
			else
				painter->drawLine( option->rect.left() + 2, ( option->rect.top() + option->rect.bottom() + 1 ) / 2,
					option->rect.right() - 2, ( option->rect.top() + option->rect.bottom() + 1 ) / 2 );
			return;

		case PE_IndicatorButtonDropDown: {
			QToolBar* toolBar;
			if ( widget && ( toolBar = qobject_cast<QToolBar*>( widget->parentWidget() ) ) ) {
				QRect rect = option->rect.adjusted( -1, 0, -1, -1 );
				bool selected = option->state & State_MouseOver && option->state & State_Enabled;
				bool sunken = option->state & State_Sunken;
				if ( selected || sunken ) {
					painter->setPen( m_colorItemBorder );
					if ( toolBar->orientation() == Qt::Vertical ) {
						if ( sunken )
							painter->setBrush( m_colorItemSunkenEnd );
						else
							painter->setBrush( m_colorItemBackgroundEnd );
					} else {
						QLinearGradient gradient( rect.topLeft(), rect.bottomLeft() );
						if ( sunken ) {
							gradient.setColorAt( 0.0, m_colorItemSunkenBegin );
							gradient.setColorAt( 0.5, m_colorItemSunkenMiddle );
							gradient.setColorAt( 1.0, m_colorItemSunkenEnd );
						} else {
							gradient.setColorAt( 0.0, m_colorItemBackgroundBegin );
							gradient.setColorAt( 0.5, m_colorItemBackgroundMiddle );
							gradient.setColorAt( 1.0, m_colorItemBackgroundEnd );
						}
						painter->setBrush( gradient );
					}
					painter->drawRect( rect );
				}
				QStyleOption optionArrow = *option;
				optionArrow.rect.adjust( 2, 2, -2, -2 );
				drawPrimitive( PE_IndicatorArrowDown, &optionArrow, painter, widget );
				return;
			}
		}

		case PE_IndicatorDockWidgetResizeHandle:
			return;

		case PE_PanelButtonTool:
			if ( widget && widget->inherits( "QDockWidgetTitleButton" ) ) {
				if ( option->state & ( QStyle::State_MouseOver | QStyle::State_Sunken ) ) {
					painter->setPen( m_colorItemBorder );
					painter->setBrush( ( option->state & QStyle::State_Sunken ) ? m_colorItemSunkenMiddle : m_colorItemBackgroundMiddle );
					painter->drawRect( option->rect.adjusted( 0, 0, -1, -1 ) );
				}
				return;
			}
			break;

		case PE_FrameTabWidget:
			if ( isStyledTabWidget( widget ) ) {
				painter->fillRect( option->rect, option->palette.window() );
				return;
			}
			break;

		case PE_FrameTabBarBase:
			if ( isStyledTabBar( widget ) )
				return;
			break;

		default:
			break;
	}

	if ( useVista() )
		QWindowsVistaStyle::drawPrimitive( element, option, painter, widget );
	else
		QWindowsXPStyle::drawPrimitive( element, option, painter, widget );
}
Esempio n. 18
0
void MetalStyle::drawControl( ControlElement element,
			      QPainter *p,
			      const QWidget *widget,
			      const QRect &r,
			      const QColorGroup &cg,
			      SFlags how,
			      const QStyleOption& opt ) const
{
    switch( element ) {
    case CE_PushButton:
	{
	    const QPushButton *btn;
	    btn = (const QPushButton*)widget;
	    int x1, y1, x2, y2;
	
	    r.coords( &x1, &y1, &x2, &y2 );
	
	    p->setPen( cg.foreground() );
	    p->setBrush( QBrush(cg.button(), NoBrush) );

	
	    QBrush fill;
	    if ( btn->isDown() )
		fill = cg.brush( QColorGroup::Mid );
	    else if ( btn->isOn() )
		fill = QBrush( cg.mid(), Dense4Pattern );
	    else
		fill = cg.brush( QColorGroup::Button );
	
	    if ( btn->isDefault() ) {
		QPointArray a;
		a.setPoints( 9,
			     x1, y1, x2, y1, x2, y2, x1, y2, x1, y1+1,
			     x2-1, y1+1, x2-1, y2-1, x1+1, y2-1, x1+1, y1+1 );
		p->setPen( Qt::black );
		p->drawPolyline( a );
		x1 += 2;
		y1 += 2;
		x2 -= 2;
		y2 -= 2;
	    }
	    SFlags flags = Style_Default;
	    if ( btn->isOn() )
		flags |= Style_On;
	    if ( btn->isDown() )
		flags |= Style_Down;
	    if ( !btn->isFlat() && !btn->isDown() )
		flags |= Style_Raised;
	    drawPrimitive( PE_ButtonCommand, p,
			   QRect( x1, y1, x2 - x1 + 1, y2 - y1 + 1),
			   cg, flags, opt );
	
	    if ( btn->isMenuButton() ) {
		flags = Style_Default;
		if ( btn->isEnabled() )
		    flags |= Style_Enabled;
		
		int dx = ( y1 - y2 - 4 ) / 3;
		drawPrimitive( PE_ArrowDown, p,
			       QRect(x2 - dx, dx, y1, y2 - y1),
			       cg, flags, opt );
	    }
	    if ( p->brush().style() != NoBrush )
		p->setBrush( NoBrush );
	    break;
	}
    case CE_PushButtonLabel:
	{
	    const QPushButton *btn;
	    btn = (const QPushButton*)widget;
	    int x, y, w, h;
	    r.rect( &x, &y, &w, &h );
	
	    int x1, y1, x2, y2;
	    r.coords( &x1, &y1, &x2, &y2 );
	    int dx = 0;
	    int dy = 0;
	    if ( btn->isMenuButton() )
		dx = ( y2 - y1 ) / 3;
	    if ( btn->isOn() || btn->isDown() ) {
		dx--;
		dy--;
	    }
	    if ( dx || dy )
		p->translate( dx, dy );
	    x += 2;
	    y += 2;
	    w -= 4;
	    h -= 4;
	    drawItem( p, QRect( x, y, w, h ),
		      AlignCenter|ShowPrefix,
		      cg, btn->isEnabled(),
		      btn->pixmap(), btn->text(), -1,
		      (btn->isDown() || btn->isOn())? &cg.brightText() : &cg.buttonText() );
	    if ( dx || dy )
		p->translate( -dx, -dy );
	    break;
	}
    default:
	QWindowsStyle::drawControl( element, p, widget, r, cg, how, opt );
	break;
    }
}
Esempio n. 19
0
void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
                                   QPainter *painter, const QWidget *widget) const
{
    if (!panelWidget(widget))
        return QProxyStyle::drawPrimitive(element, option, painter, widget);

    bool animating = (option->state & State_Animating);
    int state = option->state;
    QRect rect = option->rect;
    QRect oldRect;
    QRect newRect;
    if (widget && (element == PE_PanelButtonTool) && !animating) {
        QWidget *w = const_cast<QWidget *> (widget);
        int oldState = w->property("_q_stylestate").toInt();
        oldRect = w->property("_q_stylerect").toRect();
        newRect = w->rect();
        w->setProperty("_q_stylestate", (int)option->state);
        w->setProperty("_q_stylerect", w->rect());

        // Determine the animated transition
        bool doTransition = ((state & State_On)         != (oldState & State_On)     ||
                             (state & State_MouseOver)  != (oldState & State_MouseOver));
        if (oldRect != newRect)
        {
            doTransition = false;
            d->animator.stopAnimation(widget);
        }

        if (doTransition) {
            QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
            QImage endImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
            Animation *anim = d->animator.widgetAnimation(widget);
            QStyleOption opt = *option;
            opt.state = (QStyle::State)oldState;
            opt.state |= (State)State_Animating;
            startImage.fill(0);
            Transition *t = new Transition;
            t->setWidget(w);
            QPainter startPainter(&startImage);
            if (!anim) {
                drawPrimitive(element, &opt, &startPainter, widget);
            } else {
                anim->paint(&startPainter, &opt);
                d->animator.stopAnimation(widget);
            }
            QStyleOption endOpt = *option;
            endOpt.state |= (State)State_Animating;
            t->setStartImage(startImage);
            d->animator.startAnimation(t);
            endImage.fill(0);
            QPainter endPainter(&endImage);
            drawPrimitive(element, &endOpt, &endPainter, widget);
            t->setEndImage(endImage);
            if (oldState & State_MouseOver)
                t->setDuration(150);
            else
                t->setDuration(75);
            t->setStartTime(QTime::currentTime());
        }
    }

    switch (element) {
    case PE_IndicatorDockWidgetResizeHandle:
        painter->fillRect(option->rect, Utils::StyleHelper::borderColor());
        break;
    case PE_FrameDockWidget:
        QCommonStyle::drawPrimitive(element, option, painter, widget);
        break;
    case PE_PanelLineEdit:
        {
            painter->save();

            // Fill the line edit background
            QRect filledRect = option->rect.adjusted(1, 1, -1, -1);
            painter->setBrushOrigin(filledRect.topLeft());
            painter->fillRect(filledRect, option->palette.base());

            if (option->state & State_Enabled)
                Utils::StyleHelper::drawCornerImage(d->lineeditImage, painter, option->rect, 5, 5, 5, 5);
            else
                Utils::StyleHelper::drawCornerImage(d->lineeditImage_disabled, painter, option->rect, 5, 5, 5, 5);

            if (option->state & State_HasFocus || option->state & State_MouseOver) {
                QColor hover = Utils::StyleHelper::baseColor();
                if (state & State_HasFocus)
                    hover.setAlpha(100);
                else
                    hover.setAlpha(50);

                painter->setPen(QPen(hover, 1));
                painter->drawRect(option->rect.adjusted(1, 1, -2 ,-2));
            }
            painter->restore();
        }
        break;

    case PE_FrameStatusBarItem:
        break;

    case PE_PanelButtonTool: {
            Animation *anim = d->animator.widgetAnimation(widget);
            if (!animating && anim) {
                anim->paint(painter, option);
            } else {
                bool pressed = option->state & State_Sunken || option->state & State_On;
                QColor shadow(0, 0, 0, 30);
                painter->setPen(shadow);
                if (pressed) {
                    QColor shade(0, 0, 0, 40);
                    painter->fillRect(rect, shade);
                    painter->drawLine(rect.topLeft() + QPoint(1, 0), rect.topRight() - QPoint(1, 0));
                    painter->drawLine(rect.topLeft(), rect.bottomLeft());
                    painter->drawLine(rect.topRight(), rect.bottomRight());
                   // painter->drawLine(rect.bottomLeft()  + QPoint(1, 0), rect.bottomRight()  - QPoint(1, 0));
                    QColor highlight(255, 255, 255, 30);
                    painter->setPen(highlight);
                }
                else if (option->state & State_Enabled &&
                         option->state & State_MouseOver) {
                    QColor lighter(255, 255, 255, 37);
                    painter->fillRect(rect, lighter);
                }
                if (option->state & State_HasFocus && (option->state & State_KeyboardFocusChange)) {
                    QColor highlight = option->palette.highlight().color();
                    highlight.setAlphaF(0.4);
                    painter->setPen(QPen(highlight.lighter(), 1));
                    highlight.setAlphaF(0.3);
                    painter->setBrush(highlight);
                    painter->setRenderHint(QPainter::Antialiasing);
                    QRectF rect = option->rect;
                    rect.translate(0.5, 0.5);
                    painter->drawRoundedRect(rect.adjusted(2, 2, -3, -3), 2, 2);
                }
           }
        }
        break;

    case PE_PanelStatusBar:
        {
            painter->save();
            QLinearGradient grad(option->rect.topLeft(), QPoint(rect.center().x(), rect.bottom()));
            QColor startColor = Utils::StyleHelper::shadowColor().darker(164);
            QColor endColor = Utils::StyleHelper::baseColor().darker(130);
            grad.setColorAt(0, startColor);
            grad.setColorAt(1, endColor);
            painter->fillRect(option->rect, grad);
            painter->setPen(QColor(255, 255, 255, 60));
            painter->drawLine(rect.topLeft() + QPoint(0,1),
                              rect.topRight()+ QPoint(0,1));
            painter->setPen(Utils::StyleHelper::borderColor().darker(110));
            painter->drawLine(rect.topLeft(), rect.topRight());
            painter->restore();
        }
        break;

    case PE_IndicatorToolBarSeparator:
        {
            QColor separatorColor = Utils::StyleHelper::borderColor();
            separatorColor.setAlpha(100);
            painter->setPen(separatorColor);
            const int margin = 6;
            if (option->state & State_Horizontal) {
                const int offset = rect.width()/2;
                painter->drawLine(rect.bottomLeft().x() + offset,
                            rect.bottomLeft().y() - margin,
                            rect.topLeft().x() + offset,
                            rect.topLeft().y() + margin);
            } else { //Draw vertical separator
                const int offset = rect.height()/2;
                painter->setPen(QPen(option->palette.background().color().darker(110)));
                painter->drawLine(rect.topLeft().x() + margin ,
                            rect.topLeft().y() + offset,
                            rect.topRight().x() - margin,
                            rect.topRight().y() + offset);
            }
        }
        break;

    case PE_IndicatorToolBarHandle:
        {
            bool horizontal = option->state & State_Horizontal;
            painter->save();
            QPainterPath path;
            int x = option->rect.x() + (horizontal ? 2 : 6);
            int y = option->rect.y() + (horizontal ? 6 : 2);
            static const int RectHeight = 2;
            if (horizontal) {
                while (y < option->rect.height() - RectHeight - 6) {
                    path.moveTo(x, y);
                    path.addRect(x, y, RectHeight, RectHeight);
                    y += 6;
                }
            } else {
                while (x < option->rect.width() - RectHeight - 6) {
                    path.moveTo(x, y);
                    path.addRect(x, y, RectHeight, RectHeight);
                    x += 6;
                }
            }

            painter->setPen(Qt::NoPen);
            QColor dark = Utils::StyleHelper::borderColor();
            dark.setAlphaF(0.4);

            QColor light = Utils::StyleHelper::baseColor();
            light.setAlphaF(0.4);

            painter->fillPath(path, light);
            painter->save();
            painter->translate(1, 1);
            painter->fillPath(path, dark);
            painter->restore();
            painter->translate(3, 3);
            painter->fillPath(path, light);
            painter->translate(1, 1);
            painter->fillPath(path, dark);
            painter->restore();
        }
        break;
    case PE_IndicatorArrowUp:
    case PE_IndicatorArrowDown:
    case PE_IndicatorArrowRight:
    case PE_IndicatorArrowLeft:
        {
            Utils::StyleHelper::drawArrow(element, painter, option);
        }
        break;

    default:
        QProxyStyle::drawPrimitive(element, option, painter, widget);
        break;
    }
}
Esempio n. 20
0
void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
                                        QPainter *painter, const QWidget *widget) const
{
    if (!panelWidget(widget))
         return     QProxyStyle::drawComplexControl(control, option, painter, widget);

    QRect rect = option->rect;
    switch (control) {
    case CC_ToolButton:
        if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
            QRect button, menuarea;
            button = subControlRect(control, toolbutton, SC_ToolButton, widget);
            menuarea = subControlRect(control, toolbutton, SC_ToolButtonMenu, widget);

            State bflags = toolbutton->state;
            if (bflags & State_AutoRaise) {
                if (!(bflags & State_MouseOver)) {
                    bflags &= ~State_Raised;
                }
            }

            State mflags = bflags;
            if (toolbutton->state & State_Sunken) {
                if (toolbutton->activeSubControls & SC_ToolButton)
                    bflags |= State_Sunken;
                if (toolbutton->activeSubControls & SC_ToolButtonMenu)
                    mflags |= State_Sunken;
            }

            QStyleOption tool(0);
            tool.palette = toolbutton->palette;
            if (toolbutton->subControls & SC_ToolButton) {
                tool.rect = button;
                tool.state = bflags;
                drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
            }

            QStyleOptionToolButton label = *toolbutton;

            label.palette = panelPalette(option->palette, lightColored(widget));
            int fw = pixelMetric(PM_DefaultFrameWidth, option, widget);
            label.rect = button.adjusted(fw, fw, -fw, -fw);

            drawControl(CE_ToolButtonLabel, &label, painter, widget);

            if (toolbutton->subControls & SC_ToolButtonMenu) {
                tool.state = mflags;
                tool.rect = menuarea.adjusted(1, 1, -1, -1);
                if (mflags & (State_Sunken | State_On | State_Raised)) {
                    painter->setPen(Qt::gray);
                    painter->drawLine(tool.rect.topLeft(), tool.rect.bottomLeft());
                    if (mflags & (State_Sunken)) {
                        QColor shade(0, 0, 0, 50);
                        painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade);
                    }
#ifndef Q_WS_MAC
                    else if (mflags & (State_MouseOver)) {
                        QColor shade(255, 255, 255, 50);
                        painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade);
                    }
#endif
                }
                tool.rect = tool.rect.adjusted(2, 2, -2, -2);
                drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
            } else if (toolbutton->features & QStyleOptionToolButton::HasMenu
                       && !widget->property("noArrow").toBool()) {
                int arrowSize = 6;
                QRect ir = toolbutton->rect.adjusted(1, 1, -1, -1);
                QStyleOptionToolButton newBtn = *toolbutton;
                newBtn.palette = panelPalette(option->palette);
                newBtn.rect = QRect(ir.right() - arrowSize - 1,
                                    ir.height() - arrowSize - 2, arrowSize, arrowSize);
                drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
            }
        }
        break;

    case CC_ComboBox:
        if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
            painter->save();
            bool isEmpty = cb->currentText.isEmpty() && cb->currentIcon.isNull();
            bool reverse = option->direction == Qt::RightToLeft;
            bool drawborder = !(widget && widget->property("hideborder").toBool());
            bool alignarrow = !(widget && widget->property("alignarrow").toBool());

            // Draw tool button
            if (drawborder) {
                QLinearGradient grad(option->rect.topRight(), option->rect.bottomRight());
                grad.setColorAt(0, QColor(255, 255, 255, 20));
                grad.setColorAt(0.4, QColor(255, 255, 255, 60));
                grad.setColorAt(0.7, QColor(255, 255, 255, 50));
                grad.setColorAt(1, QColor(255, 255, 255, 40));
                painter->setPen(QPen(grad, 0));
                painter->drawLine(rect.topRight(), rect.bottomRight());
                grad.setColorAt(0, QColor(0, 0, 0, 30));
                grad.setColorAt(0.4, QColor(0, 0, 0, 70));
                grad.setColorAt(0.7, QColor(0, 0, 0, 70));
                grad.setColorAt(1, QColor(0, 0, 0, 40));
                painter->setPen(QPen(grad, 0));
                if (!reverse)
                    painter->drawLine(rect.topRight() - QPoint(1,0), rect.bottomRight() - QPoint(1,0));
                else
                    painter->drawLine(rect.topLeft(), rect.bottomLeft());
            }
            QStyleOption toolbutton = *option;
            if (isEmpty)
                toolbutton.state &= ~(State_Enabled | State_Sunken);
            painter->save();
            if (drawborder)
                painter->setClipRect(toolbutton.rect.adjusted(0, 0, -2, 0));
            drawPrimitive(PE_PanelButtonTool, &toolbutton, painter, widget);
            painter->restore();
            // Draw arrow
            int menuButtonWidth = 12;
            int left = !reverse ? rect.right() - menuButtonWidth : rect.left();
            int right = !reverse ? rect.right() : rect.left() + menuButtonWidth;
            QRect arrowRect((left + right) / 2 + (reverse ? 6 : -6), rect.center().y() - 3, 9, 9);

            if (!alignarrow) {
                int labelwidth = option->fontMetrics.width(cb->currentText);
                if (reverse)
                    arrowRect.moveLeft(qMax(rect.width() - labelwidth - menuButtonWidth - 2, 4));
                else
                    arrowRect.moveLeft(qMin(labelwidth + menuButtonWidth - 2, rect.width() - menuButtonWidth - 4));
            }
            if (option->state & State_On)
                arrowRect.translate(QProxyStyle::pixelMetric(PM_ButtonShiftHorizontal, option, widget),
                                    QProxyStyle::pixelMetric(PM_ButtonShiftVertical, option, widget));

            QStyleOption arrowOpt = *option;
            arrowOpt.rect = arrowRect;
            if (isEmpty)
                arrowOpt.state &= ~(State_Enabled | State_Sunken);

            if (styleHint(SH_ComboBox_Popup, option, widget)) {
                arrowOpt.rect.translate(0, -3);
                drawPrimitive(PE_IndicatorArrowUp, &arrowOpt, painter, widget);
                arrowOpt.rect.translate(0, 6);
                drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget);
            } else {
                drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget);
            }

            painter->restore();
        }
        break;

    default:
        QProxyStyle::drawComplexControl(control, option, painter, widget);
        break;
    }
}
Esempio n. 21
0
	void MailTreeDelegate::paint (QPainter *painter,
			const QStyleOptionViewItem& stockItem, const QModelIndex& index) const
	{
		const bool isEnabled = index.flags () & Qt::ItemIsEnabled;

		QStyleOptionViewItemV4 option { stockItem };
		if (!isEnabled)
			option.font.setStrikeOut (true);

		const auto style = GetStyle (option);

		painter->save ();

		style->drawPrimitive (QStyle::PE_PanelItemViewItem, &option, painter, option.widget);

		if (option.state & QStyle::State_Selected)
			painter->setPen (option.palette.color (QPalette::HighlightedText));

		if (Mode_ == MailListMode::MultiSelect)
			DrawCheckbox (painter, style, option, index);

		const auto& subject = GetString (index, MailModel::Column::Subject);

		const auto& subjFontInfo = GetSubjectFont (index, option);
		const auto subjHeight = subjFontInfo.second.boundingRect (subject).height ();
		auto y = option.rect.top () + subjHeight;

		const auto actionsWidth = GetActionsBarWidth (index, option, subjHeight);

		painter->setFont (subjFontInfo.first);
		painter->drawText (option.rect.left (),
				y,
				subjFontInfo.second.elidedText (subject, Qt::ElideRight,
						option.rect.width () - actionsWidth));

		const QFontMetrics fontFM { option.font };

		auto stringHeight = [&fontFM] (const QString& str)
		{
			return fontFM.boundingRect (str).height ();
		};

		auto from = GetString (index, MailModel::Column::From);
		if (const auto childrenCount = index.data (MailModel::MailRole::TotalChildrenCount).toInt ())
		{
			from += " (";
			if (const auto unread = index.data (MailModel::MailRole::UnreadChildrenCount).toInt ())
				from += QString::number (unread) + "/";
			from += QString::number (childrenCount) + ")";
		}
		const auto& date = GetString (index, MailModel::Column::Date);

		y += std::max ({ stringHeight (from), stringHeight (date) });

		painter->setFont (option.font);

		const auto dateWidth = fontFM.boundingRect (date).width ();
		painter->drawText (option.rect.right () - dateWidth,
				y,
				date);

		painter->drawText (option.rect.left (),
				y,
				fontFM.elidedText (from, Qt::ElideRight, option.rect.width () - dateWidth - 5 * Padding));

		painter->restore ();
	}
Esempio n. 22
0
void Style::drawComplexControl
( ComplexControl control, const QStyleOptionComplex * option,
  QPainter * painter, const QWidget * widget ) const
{
    if (shouldNotHandle(widget)) {
        QProxyStyle::drawComplexControl(control, option, painter, widget);
        return;
    }

    switch(control) {
    // FIXME: this is a workaround for the WebKit bug #104116 (or a variation on it).
    case QStyle::CC_ScrollBar:
    {
        if (qobject_cast<const QWebView*>(widget) != 0 && option->type == QStyleOption::SO_Slider)
        {
            // WebKit tries to hide scrollbars, but mistakenly hides QWebView - NULL-ify styleObject to prevent.
            const QStyleOptionSlider *optSlider = static_cast<const QStyleOptionSlider*>(option);
            QStyleOptionSlider opt2( *optSlider );
            opt2.styleObject = NULL;
            
            QProxyStyle::drawComplexControl( control, &opt2, painter, widget );
            return;
        }
    }
    case QStyle::CC_ToolButton:
    {
        // TODO: We only draw either text, or icon, or arrow

        const QToolButton *toolBtn = qobject_cast<const QToolButton*>(widget);
        if (!toolBtn)
            break;

        Q_ASSERT(toolBtn);

        const QStyleOptionToolButton *toolOption =
                static_cast<const QStyleOptionToolButton*>(option);

        painter->save();

        QRect r = option->rect;

        if (option->state & QStyle::State_On) {
            painter->setBrush( option->palette.color(QPalette::Dark) );
            painter->setPen( option->palette.color(QPalette::Shadow) );
            painter->drawRect( r.adjusted(0,0,-1,-1) );
        }
        else {
            bool highlight = option->state & QStyle::State_MouseOver;

            if (highlight) {
                QColor fill = option->palette.color(QPalette::Button);
                painter->setBrush(fill);
                painter->setPen(Qt::NoPen);
                painter->drawRect(r.adjusted(0,0,0,-1));
            }

            if (qobject_cast<QTabBar*>(toolBtn->parent())) {
                if (!highlight) {
                    QColor fill = option->palette.color(QPalette::Mid);
                    painter->setBrush(fill);
                    painter->setPen(Qt::NoPen);
                    painter->drawRect(r.adjusted(0,0,0,-1));
                }
                if (toolBtn->arrowType() == Qt::LeftArrow) {
                    painter->setPen( option->palette.color(QPalette::Shadow) );
                    painter->drawLine( option->rect.topLeft(), option->rect.bottomLeft() );
                }
            }
        }

        painter->restore();

        QIcon icon = toolOption->icon;
        if (!icon.isNull())
        {
            QIcon::Mode iconMode =
                    option->state & QStyle::State_Enabled
                    ? ( option->state & QStyle::State_MouseOver
                        ? QIcon::Active
                        : QIcon::Normal )
                    : QIcon::Disabled;

            QIcon::State iconState =
                    option ->state & QStyle::State_Selected
                    ? QIcon::On : QIcon::Off;

            QPixmap pixmap = icon.pixmap(toolOption->iconSize, iconMode, iconState);
            QRect pixRect = pixmap.rect();
            pixRect.moveCenter( option->rect.center() );
            painter->drawPixmap(pixRect.topLeft(), pixmap);
        }
        else {
            QStyle::PrimitiveElement elem = Style::PE_CustomBase;
            switch(toolBtn->arrowType()) {
            case Qt::LeftArrow:
                elem = PE_IndicatorArrowLeft; break;
            case Qt::RightArrow:
                elem = PE_IndicatorArrowRight; break;
            case Qt::DownArrow:
                elem = PE_IndicatorArrowDown; break;
            case Qt::UpArrow:
                elem = PE_IndicatorArrowUp; break;
            default:
                break;
            }
            if (elem != Style::PE_CustomBase) {
                drawPrimitive( elem, option, painter, widget );
            }
            else if (!toolOption->text.isEmpty()) {
                painter->drawText( toolOption->rect,
                                   Qt::AlignCenter | Qt::TextShowMnemonic,
                                   toolOption->text );
            }
        }
        return;
    }
    default:
        break;
    }
    QProxyStyle::drawComplexControl(control, option, painter, widget);
}
Esempio n. 23
0
// draw custom slider + handle for volume widget
void MpcVolumeSlideStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
                                       QPainter *p, const QWidget *widget) const
{
    if( cc == CC_Slider )
    {
        if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
            QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, widget);
            QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, widget);

            if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {

                p->setPen(slider->palette.shadow().color());
                if (slider->orientation == Qt::Horizontal) {
                    static QPoint points[3] = {
                                QPoint(groove.x() , groove.y() + slider->rect.height() ),
                                QPoint(groove.x() + groove.width() -2 , groove.y() + slider->rect.height() ),
                                QPoint(groove.x() + groove.width() -2 , groove.y()  ),
                            };
                    QPen oldPen = p->pen();
                    
                    p->setPen(slider->palette.dark().color());
                    p->drawLine(QPoint(points[0].x(), points[0].y() -2 ),QPoint(points[2].x(), points[2].y()));

                    QPoint b[3] = { QPoint(points[0].x(),points[0].y()-1), QPoint(points[1].x()-1, points[1].y()-1), QPoint(points[2].x()-1,points[2].y()) };
                    p->setPen(slider->palette.light().color());
                    p->drawPolyline(b, 3);
                    p->setPen(oldPen);
                }
            }


            if (slider->subControls & SC_SliderTickmarks) {
                QStyleOptionSlider tmpSlider = *slider;
                tmpSlider.subControls = SC_SliderTickmarks;
                QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget);
            }

            if (slider->subControls & SC_SliderHandle) {
                QBrush handleBrush;

                if (slider->state & State_Enabled) {
                    handleBrush = slider->palette.color(QPalette::Button);
                } else {
                    handleBrush = QBrush(slider->palette.color(QPalette::Button),
                                         Qt::Dense4Pattern);
                }


                int x = handle.x() , y = handle.y(),
                   wi = handle.width() - 2, he = slider->rect.height();

                if (slider->state & State_HasFocus) {
                    QStyleOptionFocusRect fropt;
                    fropt.QStyleOption::operator=(*slider);
                    fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
                    drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
                }

                Qt::BGMode oldMode = p->backgroundMode();
                p->setBackgroundMode(Qt::OpaqueMode);
                qDrawWinButton(p, QRect(x, y, wi, he), slider->palette, false,
                                   &handleBrush);
                p->setBackgroundMode(oldMode);

            }
        }
    }
    else
    {
        QWindowsStyle::drawComplexControl(cc,opt,p,widget);
    }
}
Esempio n. 24
0
void TabBarWidgetMacStyle::drawControl(ControlElement pElement,
                                       const QStyleOption *pOption,
                                       QPainter *pPainter,
                                       const QWidget *pWidget) const
{
    // Draw a tab bar tab label
    // Note: anything else is done by our parent...

    if (pElement == CE_TabBarTabLabel) {
        // Note: adapted from QCommonStyle::drawControl()...

        if (auto tab = qstyleoption_cast<const QStyleOptionTab *>(pOption)) {
            uint alignment = Qt::AlignCenter|Qt::TextShowMnemonic;

            if (styleHint(SH_UnderlineShortcut, pOption, pWidget) == 0) {
                alignment |= Qt::TextHideMnemonic;
            }

            bool isVerticalTab =    (tab->shape == QTabBar::RoundedWest)
                                 || (tab->shape == QTabBar::RoundedEast)
                                 || (tab->shape == QTabBar::TriangularWest)
                                 || (tab->shape == QTabBar::TriangularEast);
            QRect tabRect = tab->rect;

            if (isVerticalTab) {
                pPainter->save();

                int x, y, rotation;

                if (   (tab->shape == QTabBar::RoundedEast)
                    || (tab->shape == QTabBar::TriangularEast)) {
                    x = tabRect.x()+tabRect.width();
                    y = tabRect.y();

                    rotation = 90;
                } else {
                    x = tabRect.x();
                    y = tabRect.y()+tabRect.height();

                    rotation = -90;
                }

                QTransform transform = QTransform::fromTranslate(x, y);

                transform.rotate(rotation);

                pPainter->setTransform(transform, true);
            }

            QRect iconRect;

            tabLayout(tab, pWidget, &tabRect, &iconRect);

            if (!tab->icon.isNull()) {
                pPainter->drawPixmap(iconRect.x(), iconRect.y(),
                                     tab->icon.pixmap(pWidget->window()->windowHandle(),
                                                      tab->iconSize,
                                                      ((tab->state & State_Enabled) != 0)?
                                                          QIcon::Normal:
                                                          QIcon::Disabled,
                                                      ((tab->state & State_Selected) != 0)?
                                                          QIcon::On:
                                                          QIcon::Off));
            }

            drawItemText(pPainter, tabRect, int(alignment), tab->palette,
                         (tab->state & State_Enabled) != 0, tab->text,
                         (   ((tab->state & State_Selected) != 0)
                          && ((tab->state & State_Active) != 0))?
                             QPalette::BrightText:
                             QPalette::WindowText);

            if (isVerticalTab) {
                pPainter->restore();
            }

            if ((tab->state & State_HasFocus) != 0) {
                const int Offset = 1+pixelMetric(PM_DefaultFrameWidth);

                int x1 = tab->rect.left();
                int x2 = tab->rect.right()-1;

                QStyleOptionFocusRect option;

                option.QStyleOption::operator=(*tab);

                option.rect.setRect(x1+1+Offset, tab->rect.y()+Offset,
                                    x2-x1-2*Offset, tab->rect.height()-2*Offset);

                drawPrimitive(PE_FrameFocusRect, &option, pPainter, pWidget);
            }
        }
    } else {
        QProxyStyle::drawControl(pElement, pOption, pPainter, pWidget);
    }
}
Esempio n. 25
0
void ManhattanStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
                                   QPainter *painter, const QWidget *widget) const {
    if (!panelWidget(widget))
        return d->style->drawPrimitive(element, option, painter, widget);

    bool animating = (option->state & State_Animating);
    int state = option->state;
    QRect rect = option->rect;
    QRect oldRect;
    QRect newRect;
    if (widget && (element == PE_PanelButtonTool) && !animating) {
        QWidget *w = const_cast<QWidget *> (widget);
        int oldState = w->property("_q_stylestate").toInt();
        oldRect = w->property("_q_stylerect").toRect();
        newRect = w->rect();
        w->setProperty("_q_stylestate", (int)option->state);
        w->setProperty("_q_stylerect", w->rect());

        // Determine the animated transition
        bool doTransition = ((state & State_On)         != (oldState & State_On)     ||
                             (state & State_MouseOver)  != (oldState & State_MouseOver));
        if (oldRect != newRect) {
            doTransition = false;
            d->animator.stopAnimation(widget);
        }

        if (doTransition) {
            QImage startImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
            QImage endImage(option->rect.size(), QImage::Format_ARGB32_Premultiplied);
            Animation *anim = d->animator.widgetAnimation(widget);
            QStyleOption opt = *option;
            opt.state = (QStyle::State)oldState;
            opt.state |= (State)State_Animating;
            startImage.fill(0);
            Transition *t = new Transition;
            t->setWidget(w);
            QPainter startPainter(&startImage);
            if (!anim) {
                drawPrimitive(element, &opt, &startPainter, widget);
            } else {
                anim->paint(&startPainter, &opt);
                d->animator.stopAnimation(widget);
            }
            QStyleOption endOpt = *option;
            endOpt.state |= (State)State_Animating;
            t->setStartImage(startImage);
            d->animator.startAnimation(t);
            endImage.fill(0);
            QPainter endPainter(&endImage);
            drawPrimitive(element, &endOpt, &endPainter, widget);
            t->setEndImage(endImage);
            t->setDuration(130);
            t->setStartTime(QTime::currentTime());
        }
    }

    switch (element) {
    case PE_PanelLineEdit: {
        painter->save();
        if (option->state & State_Enabled)
            drawCornerImage(d->lineeditImage, painter, option->rect, 2, 2, 2, 2);
        else
            drawCornerImage(d->lineeditImage_disabled, painter, option->rect, 2, 2, 2, 2);

        if (option->state & State_HasFocus || option->state & State_MouseOver) {
            QColor hover = StyleHelper::baseColor();
            if (state & State_HasFocus)
                hover.setAlpha(100);
            else
                hover.setAlpha(50);

            painter->setPen(QPen(hover, 1));
            painter->drawRect(option->rect.adjusted(1, 1, -2 ,-2));
        }
        painter->restore();
    }
    break;

    case PE_FrameStatusBarItem:
        break;

    case PE_PanelButtonTool: {
        Animation *anim = d->animator.widgetAnimation(widget);
        if (!animating && anim) {
            anim->paint(painter, option);
        } else {
            bool pressed = option->state & State_Sunken || option->state & State_On;
            QColor shadow(0, 0, 0, 30);
            painter->setPen(shadow);
            if (pressed) {
                QColor shade(0, 0, 0, 40);
                painter->fillRect(rect, shade);
                painter->drawLine(rect.topLeft() + QPoint(1, 0), rect.topRight() - QPoint(1, 0));
                painter->drawLine(rect.topLeft(), rect.bottomLeft());
                painter->drawLine(rect.topRight(), rect.bottomRight());
                // painter->drawLine(rect.bottomLeft()  + QPoint(1, 0), rect.bottomRight()  - QPoint(1, 0));
                QColor highlight(255, 255, 255, 30);
                painter->setPen(highlight);
            } else if (option->state & State_Enabled &&
                       option->state & State_MouseOver) {
                QColor lighter(255, 255, 255, 37);
                painter->fillRect(rect, lighter);
            }
        }
    }
    break;

    case PE_PanelStatusBar: {
        painter->save();
        QLinearGradient grad(option->rect.topLeft(), QPoint(rect.center().x(), rect.bottom()));
        QColor startColor = StyleHelper::shadowColor().darker(164);
        QColor endColor = StyleHelper::baseColor().darker(130);
        grad.setColorAt(0, endColor);
        grad.setColorAt(1, endColor);
        painter->fillRect(option->rect, grad);
        painter->setPen(QColor(255, 255, 255, 60));
        painter->drawLine(rect.topLeft() + QPoint(0,1),
                          rect.topRight()+ QPoint(0,1));
        painter->setPen(StyleHelper::borderColor().darker(110));
        painter->drawLine(rect.topLeft(), rect.topRight());
        painter->restore();
    }
    break;

    case PE_IndicatorToolBarSeparator: {
        QColor separatorColor = StyleHelper::borderColor();
        separatorColor.setAlpha(100);
        painter->setPen(separatorColor);
        const int margin = 3;
        if (option->state & State_Horizontal) {
            const int offset = rect.width()/2;
            painter->drawLine(rect.bottomLeft().x() + offset,
                              rect.bottomLeft().y() - margin,
                              rect.topLeft().x() + offset,
                              rect.topLeft().y() + margin);
        } else { //Draw vertical separator
            const int offset = rect.height()/2;
            painter->setPen(QPen(option->palette.background().color().darker(110)));
            painter->drawLine(rect.topLeft().x() + margin ,
                              rect.topLeft().y() + offset,
                              rect.topRight().x() - margin,
                              rect.topRight().y() + offset);
        }
    }
    break;

    case PE_IndicatorToolBarHandle: {
        bool horizontal = option->state & State_Horizontal;
        painter->save();
        QPainterPath path;
        int x = option->rect.x() + horizontal ? 2 : 6;
        int y = option->rect.y() + horizontal ? 6 : 2;
        static const int RectHeight = 2;
        if (horizontal) {
            while (y < option->rect.height() - RectHeight - 6) {
                path.moveTo(x, y);
                path.addRect(x, y, RectHeight, RectHeight);
                y += 6;
            }
        } else {
            while (x < option->rect.width() - RectHeight - 6) {
                path.moveTo(x, y);
                path.addRect(x, y, RectHeight, RectHeight);
                x += 6;
            }
        }

        painter->setPen(Qt::NoPen);
        QColor dark = StyleHelper::borderColor();
        dark.setAlphaF(0.4);

        QColor light = StyleHelper::baseColor();
        light.setAlphaF(0.4);

        painter->fillPath(path, light);
        painter->save();
        painter->translate(1, 1);
        painter->fillPath(path, dark);
        painter->restore();
        painter->translate(3, 3);
        painter->fillPath(path, light);
        painter->translate(1, 1);
        painter->fillPath(path, dark);
        painter->restore();
    }
    break;
    case PE_IndicatorArrowUp:
    case PE_IndicatorArrowDown:
    case PE_IndicatorArrowRight:
    case PE_IndicatorArrowLeft: {
        // From windowsstyle but modified to enable AA
        if (option->rect.width() <= 1 || option->rect.height() <= 1)
            break;

        QRect r = option->rect;
        int size = qMin(r.height(), r.width());
        QPixmap pixmap;
        QString pixmapName;
        pixmapName.sprintf("%s-%s-%d-%d-%d-%lld",
                           "$qt_ia", metaObject()->className(),
                           uint(option->state), element,
                           size, option->palette.cacheKey());
        if (!QPixmapCache::find(pixmapName, pixmap)) {
            int border = size/5;
            int sqsize = 2*(size/2);
            QImage image(sqsize, sqsize, QImage::Format_ARGB32);
            image.fill(Qt::transparent);
            QPainter imagePainter(&image);
            imagePainter.setRenderHint(QPainter::Antialiasing, true);
            imagePainter.translate(0.5, 0.5);
            QPolygon a;
            switch (element) {
            case PE_IndicatorArrowUp:
                a.setPoints(3, border, sqsize/2,  sqsize/2, border,  sqsize - border, sqsize/2);
                break;
            case PE_IndicatorArrowDown:
                a.setPoints(3, border, sqsize/2,  sqsize/2, sqsize - border,  sqsize - border, sqsize/2);
                break;
            case PE_IndicatorArrowRight:
                a.setPoints(3, sqsize - border, sqsize/2,  sqsize/2, border,  sqsize/2, sqsize - border);
                break;
            case PE_IndicatorArrowLeft:
                a.setPoints(3, border, sqsize/2,  sqsize/2, border,  sqsize/2, sqsize - border);
                break;
            default:
                break;
            }

            int bsx = 0;
            int bsy = 0;

            if (option->state & State_Sunken) {
                bsx = pixelMetric(PM_ButtonShiftHorizontal);
                bsy = pixelMetric(PM_ButtonShiftVertical);
            }

            QRect bounds = a.boundingRect();
            int sx = sqsize / 2 - bounds.center().x() - 1;
            int sy = sqsize / 2 - bounds.center().y() - 1;
            imagePainter.translate(sx + bsx, sy + bsy);

            if (!(option->state & State_Enabled)) {
                QColor foreGround(150, 150, 150, 150);
                imagePainter.setBrush(option->palette.mid().color());
                imagePainter.setPen(option->palette.mid().color());
            } else {
                QColor shadow(0, 0, 0, 100);
                imagePainter.translate(0, 1);
                imagePainter.setPen(shadow);
                imagePainter.setBrush(shadow);
                QColor foreGround(255, 255, 255, 210);
                imagePainter.drawPolygon(a);
                imagePainter.translate(0, -1);
                imagePainter.setPen(foreGround);
                imagePainter.setBrush(foreGround);
            }
            imagePainter.drawPolygon(a);
            imagePainter.end();
            pixmap = QPixmap::fromImage(image);
            QPixmapCache::insert(pixmapName, pixmap);
        }
        int xOffset = r.x() + (r.width() - size)/2;
        int yOffset = r.y() + (r.height() - size)/2;
        painter->drawPixmap(xOffset, yOffset, pixmap);
    }
    break;

    default:
        d->style->drawPrimitive(element, option, painter, widget);
        break;
    }
}
Esempio n. 26
0
/*! \reimp */
void QCompactStyle::drawControl( ControlElement element, QPainter *p, const QWidget *widget, const QRect &r,
		  const QColorGroup &g, SFlags flags, const QStyleOption& opt )
{
    switch ( element ) {
    case CE_PopupMenuItem:
	{
	    if (! widget || opt.isDefault())
		break;

	    const QPopupMenu *popupmenu = (const QPopupMenu *) widget;
	    QMenuItem *mi = opt.menuItem();
	    if ( !mi )
		break;

	    int tab = opt.tabWidth();
	    int maxpmw = opt.maxIconWidth();
	    bool dis = !(flags & Style_Enabled);
	    bool checkable = popupmenu->isCheckable();
	    bool act = flags & Style_Active;
	    int x, y, w, h;
	    r.rect( &x, &y, &w, &h );

	    QColorGroup itemg = g;

	    if ( checkable )
		maxpmw = QMAX( maxpmw, 8 ); // space for the checkmarks

	    int checkcol	  =     maxpmw;

	    if ( mi && mi->isSeparator() ) {			// draw separator
		p->setPen( g.dark() );
		p->drawLine( x, y, x+w, y );
		p->setPen( g.light() );
		p->drawLine( x, y+1, x+w, y+1 );
		return;
	    }

	    QBrush fill = act? g.brush( QColorGroup::Highlight ) :
				    g.brush( QColorGroup::Button );
	    p->fillRect( x, y, w, h, fill);

	    if ( !mi )
		return;

	    if ( mi->isChecked() ) {
		if ( act && !dis ) {
		    qDrawShadePanel( p, x, y, checkcol, h,
				     g, TRUE, 1, &g.brush( QColorGroup::Button ) );
		} else {
		    qDrawShadePanel( p, x, y, checkcol, h,
				     g, TRUE, 1, &g.brush( QColorGroup::Midlight ) );
		}
	    } else if ( !act ) {
		p->fillRect(x, y, checkcol , h,
			    g.brush( QColorGroup::Button ));
	    }

	    if ( mi->iconSet() ) {		// draw iconset
		QIconSet::Mode mode = dis ? QIconSet::Disabled : QIconSet::Normal;
		if (act && !dis )
		    mode = QIconSet::Active;
		QPixmap pixmap;
		if ( checkable && mi->isChecked() )
		    pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode, QIconSet::On );
		else
		    pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
		int pixw = pixmap.width();
		int pixh = pixmap.height();
		if ( act && !dis ) {
		    if ( !mi->isChecked() )
			qDrawShadePanel( p, x, y, checkcol, h, g, FALSE,  1, &g.brush( QColorGroup::Button ) );
		}
		QRect cr( x, y, checkcol, h );
		QRect pmr( 0, 0, pixw, pixh );
		pmr.moveCenter( cr.center() );
		p->setPen( itemg.text() );
		p->drawPixmap( pmr.topLeft(), pixmap );

		QBrush fill = act? g.brush( QColorGroup::Highlight ) :
				      g.brush( QColorGroup::Button );
		p->fillRect( x+checkcol + 1, y, w - checkcol - 1, h, fill);
	    } else  if ( checkable ) {	// just "checking"...
		int mw = checkcol + motifItemFrame;
		int mh = h - 2*motifItemFrame;
		if ( mi->isChecked() ) {

		    SFlags cflags = Style_Default;
		    if (! dis)
			cflags |= Style_Enabled;
		    if (act)
			cflags |= Style_On;

		    drawPrimitive( PE_CheckMark, p, QRect(x + motifItemFrame + 2, y + motifItemFrame,
				    mw, mh), itemg, cflags, opt );
		}
	    }

	    p->setPen( act ? g.highlightedText() : g.buttonText() );

	    QColor discol;
	    if ( dis ) {
		discol = itemg.text();
		p->setPen( discol );
	    }

	    int xm = motifItemFrame + checkcol + motifItemHMargin;

	    if ( mi->custom() ) {
		int m = motifItemVMargin;
		p->save();
		if ( dis && !act ) {
		    p->setPen( g.light() );
		    mi->custom()->paint( p, itemg, act, !dis,
					 x+xm+1, y+m+1, w-xm-tab+1, h-2*m );
		    p->setPen( discol );
		}
		mi->custom()->paint( p, itemg, act, !dis,
				     x+xm, y+m, w-xm-tab+1, h-2*m );
		p->restore();
	    }
	    QString s = mi->text();
	    if ( !s.isNull() ) {			// draw text
		int t = s.find( '\t' );
		int m = motifItemVMargin;
		const int text_flags = AlignVCenter|ShowPrefix | DontClip | SingleLine;
		if ( t >= 0 ) {				// draw tab text
		    if ( dis && !act ) {
			p->setPen( g.light() );
			p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame+1,
				     y+m+1, tab, h-2*m, text_flags, s.mid( t+1 ));
			p->setPen( discol );
		    }
		    p->drawText( x+w-tab-windowsRightBorder-motifItemHMargin-motifItemFrame,
				 y+m, tab, h-2*m, text_flags, s.mid( t+1 ) );
		    s = s.left( t );
		}
		if ( dis && !act ) {
		    p->setPen( g.light() );
		    p->drawText( x+xm+1, y+m+1, w-xm+1, h-2*m, text_flags, s, t );
		    p->setPen( discol );
		}
		p->drawText( x+xm, y+m, w-xm-tab+1, h-2*m, text_flags, s, t );
	    } else if ( mi->pixmap() ) {			// draw pixmap
		QPixmap *pixmap = mi->pixmap();
		if ( pixmap->depth() == 1 )
		    p->setBackgroundMode( OpaqueMode );
		p->drawPixmap( x+xm, y+motifItemFrame, *pixmap );
		if ( pixmap->depth() == 1 )
		    p->setBackgroundMode( TransparentMode );
	    }
	    if ( mi->popup() ) {			// draw sub menu arrow
		int dim = (h-2*motifItemFrame) / 2;
		if ( act ) {
		    if ( !dis )
			discol = white;
		    QColorGroup g2( discol, g.highlight(),
				    white, white,
				    dis ? discol : white,
				    discol, white );
		    drawPrimitive(PE_ArrowRight, p, QRect(x+w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2, dim, dim),
				  g2, Style_Enabled);
		} else {
		    drawPrimitive(PE_ArrowRight, p, QRect(x+w - motifArrowHMargin - motifItemFrame - dim, y + h / 2 - dim / 2, dim, dim),
				  g, !dis ? Style_Enabled : Style_Default);
		}
	    }
	}
	break;

    default:
	QWindowsStyle::drawControl( element, p, widget, r, g, flags, opt );
	break;
    }
}
Esempio n. 27
0
void GFXDevice::drawPrimitive( U32 primitiveIndex )
{
   AssertFatal( mCurrentPrimitiveBuffer.isValid(), "Trying to call drawPrimitive with no current primitive buffer, call setPrimitiveBuffer()" );
   AssertFatal( primitiveIndex < mCurrentPrimitiveBuffer->mPrimitiveCount, "Out of range primitive index.");
   drawPrimitive( mCurrentPrimitiveBuffer->mPrimitiveArray[primitiveIndex] );
}
Esempio n. 28
0
// draw custom slider + handle for timeslide widget
void MpcTimeSlideStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
                                       QPainter *p, const QWidget *widget) const
{
    if( cc == CC_Slider )
    {
        if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
            QRect groove = subControlRect(CC_Slider, slider, SC_SliderGroove, widget);
            QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, widget);

            if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
                if (slider->orientation == Qt::Horizontal) {
                    int x = groove.x() + 2;
                    int y = slider->rect.height() / 2 - 4;
                    int w = groove.width() - 4;
                    int h = 7;
                    qDrawShadeRect (p,x,y,w,h, slider->palette, true,1,0,
                        &slider->palette.brush(QPalette::Light));
                }
            }


            if (slider->subControls & SC_SliderTickmarks) {
                QStyleOptionSlider tmpSlider = *slider;
                tmpSlider.subControls = SC_SliderTickmarks;
                QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget);
            }

            if (slider->subControls & SC_SliderHandle) {
                QBrush handleBrush;

                if (slider->state & State_Enabled) {
                    handleBrush = slider->palette.color(QPalette::Button);
                } else {
                    handleBrush = QBrush(slider->palette.color(QPalette::Button),
                                         Qt::Dense4Pattern);
                }


                int x = handle.x() , y = handle.y() + 1,
                   wi = 13, he = 14;

                if (slider->state & State_HasFocus) {
                    QStyleOptionFocusRect fropt;
                    fropt.QStyleOption::operator=(*slider);
                    fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
                    drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
                }

                Qt::BGMode oldMode = p->backgroundMode();
                p->setBackgroundMode(Qt::OpaqueMode);
                qDrawWinPanel(p, QRect(x, y, wi, he), slider->palette, false,
                               &handleBrush);
                qDrawShadeRect (p, QRect(x+2,y+3, wi-4, he-6), slider->palette, true,1,0,
                               &slider->palette.brush(QPalette::Light));
                p->setBackgroundMode(oldMode);
            }
        }
    }
    else
    {
        QWindowsStyle::drawComplexControl(cc,opt,p,widget);
    }
}
Esempio n. 29
0
void ManhattanStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
                                        QPainter *painter, const QWidget *widget) const {
    if (!panelWidget(widget))
        return d->style->drawComplexControl(control, option, painter, widget);

    QRect rect = option->rect;
    switch (control) {
    case CC_ToolButton:
        if (const QStyleOptionToolButton *toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
            QString buttonType = widget->property("type").toString();
            QRect button, menuarea;
            button = subControlRect(control, toolbutton, SC_ToolButton, widget);
            menuarea = subControlRect(control, toolbutton, SC_ToolButtonMenu, widget);

            State bflags = toolbutton->state;
            if (bflags & State_AutoRaise) {
                if (!(bflags & State_MouseOver)) {
                    bflags &= ~State_Raised;
                }
            }

            State mflags = bflags;
            if (toolbutton->state & State_Sunken) {
                if (toolbutton->activeSubControls & SC_ToolButton)
                    bflags |= State_Sunken;
                if (toolbutton->activeSubControls & SC_ToolButtonMenu)
                    mflags |= State_Sunken;
            }

            QStyleOption tool(0);
            tool.palette = toolbutton->palette;
            if (toolbutton->subControls & SC_ToolButton) {
//                if (buttonType == "dockbutton") {
                tool.rect = button;
                tool.state = bflags;
                drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
//                }
                /*else {  // paint status bar button style
                                    if (bflags & State_Sunken || bflags & State_On)
                                        drawCornerImage(d->buttonImage_pressed, painter, option->rect, 2, 2, 2, 2);
                                    else if (bflags & State_Enabled) {
                #ifndef Q_WS_MAC
                                        if (bflags & State_MouseOver) {
                                            drawCornerImage(d->buttonImage, painter, option->rect, 2, 2, 2, 2);
                                            QColor shade(255, 255, 255, 50);
                                            painter->fillRect(button.adjusted(1, 1, -1, -1), shade);
                                        }
                #endif
                                    }

                                }*/
            }

            if (toolbutton->state & State_HasFocus) {
                QStyleOptionFocusRect fr;
                fr.QStyleOption::operator=(*toolbutton);
                fr.rect.adjust(3, 3, -3, -3);
                if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup)
                    fr.rect.adjust(0, 0, -pixelMetric(QStyle::PM_MenuButtonIndicator,
                                                      toolbutton, widget), 0);
                QPen oldPen = painter->pen();
                QColor focusColor = StyleHelper::panelTextColor();
                focusColor.setAlpha(120);
                QPen outline(focusColor, 1);
                outline.setStyle(Qt::DotLine);
                painter->setPen(outline);
                QRect r = option->rect.adjusted(2, 2, -2, -2);
                painter->drawRect(r);
                painter->setPen(oldPen);
            }

            QStyleOptionToolButton label = *toolbutton;
            label.palette = panelPalette(option->palette);
            int fw = pixelMetric(PM_DefaultFrameWidth, option, widget);
            label.rect = button.adjusted(fw, fw, -fw, -fw);
            drawControl(CE_ToolButtonLabel, &label, painter, widget);

            if (toolbutton->subControls & SC_ToolButtonMenu) {
                tool.state = mflags;
                tool.rect = menuarea.adjusted(1, 1, -1, -1);
                if (mflags & (State_Sunken | State_On | State_Raised)) {
                    painter->setPen(Qt::gray);
                    painter->drawLine(tool.rect.topLeft(), tool.rect.bottomLeft());
                    if (mflags & (State_Sunken)) {
                        QColor shade(0, 0, 0, 50);
                        painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade);
                    }
#ifndef Q_WS_MAC
                    else if (mflags & (State_MouseOver)) {
                        QColor shade(255, 255, 255, 50);
                        painter->fillRect(tool.rect.adjusted(0, -1, 1, 1), shade);
                    }
#endif
                }
                tool.rect = tool.rect.adjusted(2, 2, -2, -2);
                drawPrimitive(PE_IndicatorArrowDown, &tool, painter, widget);
            } else if (toolbutton->features & QStyleOptionToolButton::HasMenu) {
                int arrowSize = 6;
                QRect ir = toolbutton->rect.adjusted(1, 1, -1, -1);
                QStyleOptionToolButton newBtn = *toolbutton;
                newBtn.palette = panelPalette(option->palette);
                newBtn.rect = QRect(ir.right() - arrowSize - 1,
                                    ir.height() - arrowSize - 2, arrowSize, arrowSize);
                drawPrimitive(PE_IndicatorArrowDown, &newBtn, painter, widget);
            }
        }
        break;

    case CC_ComboBox:
        if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
            painter->save();
            bool isEmpty = cb->currentText.isEmpty() && cb->currentIcon.isNull();
            bool reverse = option->direction == Qt::RightToLeft;

            // Draw tool button
            QLinearGradient grad(option->rect.topRight(), option->rect.bottomRight());
            grad.setColorAt(0, QColor(255, 255, 255, 20));
            grad.setColorAt(0.4, QColor(255, 255, 255, 60));
            grad.setColorAt(0.7, QColor(255, 255, 255, 50));
            grad.setColorAt(1, QColor(255, 255, 255, 40));
            painter->setPen(QPen(grad, 0));
            painter->drawLine(rect.topRight(), rect.bottomRight());
            painter->drawLine(rect.topLeft(), rect.bottomLeft());
            grad.setColorAt(0, QColor(0, 0, 0, 30));
            grad.setColorAt(0.4, QColor(0, 0, 0, 70));
            grad.setColorAt(0.7, QColor(0, 0, 0, 70));
            grad.setColorAt(1, QColor(0, 0, 0, 40));
            painter->setPen(QPen(grad, 0));
            if (!reverse)
                painter->drawLine(rect.topRight() - QPoint(1,0), rect.bottomRight() - QPoint(1,0));
            else
                painter->drawLine(rect.topLeft(), rect.bottomLeft());
            QStyleOption toolbutton = *option;
            if (isEmpty)
                toolbutton.state &= ~(State_Enabled | State_Sunken);
            painter->save();
            painter->setClipRect(toolbutton.rect.adjusted(0, 0, -2, 0));
            drawPrimitive(PE_PanelButtonTool, &toolbutton, painter, widget);
            painter->restore();
            // Draw arrow
            int menuButtonWidth = 12;
            int left = !reverse ? rect.right() - menuButtonWidth : rect.left();
            int right = !reverse ? rect.right() : rect.left() + menuButtonWidth;
            QRect arrowRect((left + right) / 2 + (reverse ? 6 : -6), rect.center().y() - 3, 9, 9);
            if (option->state & State_On)
                arrowRect.translate(d->style->pixelMetric(PM_ButtonShiftHorizontal, option, widget),
                                    d->style->pixelMetric(PM_ButtonShiftVertical, option, widget));

            QStyleOption arrowOpt = *option;
            arrowOpt.rect = arrowRect;
            if (isEmpty)
                arrowOpt.state &= ~(State_Enabled | State_Sunken);

            if (styleHint(SH_ComboBox_Popup, option, widget)) {
                arrowOpt.rect.translate(0, -3);
                drawPrimitive(PE_IndicatorArrowUp, &arrowOpt, painter, widget);
                arrowOpt.rect.translate(0, 6);
                drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget);
            } else {
                drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, painter, widget);
            }
            painter->restore();
        }
        break;
    default:
        d->style->drawComplexControl(control, option, painter, widget);
        break;
    }
}
Esempio n. 30
0
/*!\reimp
 */
void QPlatinumStyle::drawComplexControl( ComplexControl control,
					 QPainter *p,
					 const QWidget *widget,
					 const QRect &r,
					 const QColorGroup &cg,
					 SFlags how,
					 SCFlags sub,
					 SCFlags subActive,
					 const QStyleOption& opt ) const
{
    switch ( control ) {
    case CC_ComboBox:
	{
	    int x,
		y,
		w,
		h;
	    r.rect( &x, &y, &w, &h );
	    p->fillRect( x + 2,  y + 2, w - 4,
			 h - 4, cg.brush(QColorGroup::Button) );
	    // the bright side
	    p->setPen(cg.shadow());
	    p->drawLine( x, y, x + w - 1, y );
	    p->drawLine( x, y, x, y + h - 1 );

	    p->setPen( cg.light() );
	    p->drawLine( x + 1, y + 1,
			 x + w - 2, y + 1 );
	    p->drawLine( x + 1, y + 1,
			 x + 1, y + h - 2 );

	    // the dark side!


	    p->setPen( cg.mid() );
	    p->drawLine( x + 2, y + h - 2,
			 x + w - 2, y + h - 2 );
	    p->drawLine( x + w - 2, y + 2,
			 x + w - 2, y + h - 2 );

	    p->setPen (cg.shadow() );
	    p->drawLine( x + 1, y + h - 1,
			 x + w - 1, y + h - 1 );
	    p->drawLine( x + w - 1, y,
			 x + w - 1, y + h - 1 );

	    // top left corner:
	    p->setPen( cg.background() );
	    p->drawPoint( x, y );
	    p->drawPoint( x + 1, y );
	    p->drawPoint( x, y + 1 );
	    p->setPen( cg.shadow() );
	    p->drawPoint( x + 1, y + 1 );
	    p->setPen( white );
	    p->drawPoint( x + 3, y + 3 );
	    // bottom left corner:
	    p->setPen( cg.background() );
	    p->drawPoint( x, y + h - 1 );
	    p->drawPoint( x + 1, y + h - 1 );
	    p->drawPoint( x, y + h - 2 );
	    p->setPen( cg.shadow() );
	    p->drawPoint( x + 1, y + h - 2 );
	    // top right corner:
	    p->setPen( cg.background() );
	    p->drawPoint( x + w - 1, y );
	    p->drawPoint( x + w - 2, y );
	    p->drawPoint( x + w - 1, y + 1 );
	    p->setPen( cg.shadow() );
	    p->drawPoint( x + w - 2, y + 1 );
	    // bottom right corner:
	    p->setPen( cg.background() );
	    p->drawPoint( x + w - 1, y + h - 1 );
	    p->drawPoint( x + w - 2, y + h - 1 );
	    p->drawPoint( x + w - 1, y + h - 2 );
	    p->setPen( cg.shadow() );
	    p->drawPoint( x + w - 2, y + h - 2 );
	    p->setPen( cg.dark() );
	    p->drawPoint( x + w - 3, y + h - 3 );

	    if ( sub & SC_ComboBoxArrow ) {
		QRect rTmp = querySubControlMetrics( CC_ComboBox, widget,
						     SC_ComboBoxArrow, opt );
		int xx = rTmp.x(),
		    yy = rTmp.y(),
		    ww = rTmp.width(),
		    hh = rTmp.height();
		// the bright side

		p->setPen( cg.mid() );
		p->drawLine( xx, yy+2, xx, yy+hh-3 );

		p->setPen( cg.button() );
		p->drawLine( xx+1, yy+1, xx+ww-2, yy+1 );
		p->drawLine( xx+1, yy+1, xx+1, yy+hh-2 );

		p->setPen( cg.light() );
		p->drawLine( xx+2, yy+2, xx+2, yy+hh-2 );
		p->drawLine( xx+2, yy+2, xx+ww-2, yy+2 );


		// the dark side!

		p->setPen( cg.mid() );
		p->drawLine( xx+3, yy+hh-3 ,xx+ww-3, yy+hh-3 );
		p->drawLine( xx+ww-3, yy+3, xx+ww-3, yy+hh-3 );

		p->setPen( cg.dark() );
		p->drawLine( xx+2, yy+hh-2 ,xx+ww-2, yy+hh-2 );
		p->drawLine( xx+ww-2, yy+2, xx+ww-2, yy+hh-2 );

		p->setPen( cg.shadow() );
		p->drawLine( xx+1, yy+hh-1,xx+ww-1, yy+hh-1 );
		p->drawLine( xx+ww-1, yy, xx+ww-1, yy+hh-1 );

		// top right corner:
		p->setPen( cg.background() );
		p->drawPoint( xx + ww - 1, yy );
		p->drawPoint( xx + ww - 2, yy );
		p->drawPoint( xx + ww - 1, yy + 1 );
		p->setPen( cg.shadow() );
		p->drawPoint( xx + ww - 2, yy + 1 );
		// bottom right corner:
		p->setPen( cg.background() );
		p->drawPoint( xx + ww - 1, yy + hh - 1 );
		p->drawPoint( xx + ww - 2, yy + hh - 1 );
		p->drawPoint( xx + ww - 1, yy + hh - 2 );
		p->setPen( cg.shadow() );
		p->drawPoint( xx + ww - 2, yy + hh - 2 );
		p->setPen( cg.dark() );
		p->drawPoint( xx + ww - 3, yy + hh - 3 );
		p->setPen( cg.mid() );
		p->drawPoint( xx + ww - 4, yy + hh - 4 );

		// and the arrows
		p->setPen( cg.foreground() );
		QPointArray a ;
		a.setPoints(  7, -3,1, 3,1, -2,0, 2,0, -1,-1, 1,-1, 0,-2  );
		a.translate( xx + ww / 2, yy + hh / 2 - 3 );
		p->drawLineSegments( a, 0, 3 );		// draw arrow
		p->drawPoint( a[6] );
		a.setPoints( 7, -3,-1, 3,-1, -2,0, 2,0, -1,1, 1,1, 0,2 );
		a.translate( xx + ww / 2, yy + hh / 2 + 2 );
		p->drawLineSegments( a, 0, 3 );		// draw arrow
		p->drawPoint( a[6] );

	    }
#ifndef QT_NO_COMBOBOX
	    if ( sub & SC_ComboBoxEditField ) {
		const QComboBox *cmb;
		cmb = (const QComboBox*)widget;
		// sadly this is pretty much the windows code, except
		// for the first fillRect call...
		QRect re =
		    QStyle::visualRect( querySubControlMetrics( CC_ComboBox,
								widget,
								SC_ComboBoxEditField ),
					widget );
		if ( cmb->hasFocus() && !cmb->editable() )
		    p->fillRect( re.x() + 1, re.y() + 1,
				 re.width() - 2, re.height() - 2,
				 cg.brush( QColorGroup::Highlight ) );

		if ( cmb->hasFocus() ) {
		    p->setPen( cg.highlightedText() );
		    p->setBackgroundColor( cg.highlight() );
		} else {
		    p->setPen( cg.text() );
		    p->setBackgroundColor( cg.background() );
		}

		if ( cmb->hasFocus() && !cmb->editable() ) {
		    QRect re =
			QStyle::visualRect( subRect( SR_ComboBoxFocusRect,
						     cmb ),
					    widget );
		    drawPrimitive( PE_FocusRect, p, re, cg,
				   Style_FocusAtBorder,
				   QStyleOption(cg.highlight()));
		}
		if ( cmb->editable() ) {
		    // need this for the moment...
		    // was the code in comboButton rect
		    QRect ir( x + 3, y + 3,
			      w - 6 - 16, h - 6 );
		    if ( QApplication::reverseLayout() )
			ir.moveBy( 16, 0 );
		    // end comboButtonRect...
		    ir.setRect( ir.left() - 1, ir.top() - 1, ir.width() + 2,
				ir.height() + 2 );
		    qDrawShadePanel( p, ir, cg, TRUE, 2, 0 );
		}
	    }
#endif
	    break;
	}
    case CC_Slider:
	{
#ifndef QT_NO_SLIDER
	    const QSlider *slider = (const QSlider *) widget;
	    int thickness = pixelMetric( PM_SliderControlThickness, widget );
	    int len = pixelMetric( PM_SliderLength, widget );
	    int ticks = slider->tickmarks();

	    QRect groove = querySubControlMetrics(CC_Slider, widget, SC_SliderGroove,
						  opt),
		  handle = querySubControlMetrics(CC_Slider, widget, SC_SliderHandle,
						  opt);

	    if ((sub & SC_SliderGroove) && groove.isValid()) {
		p->fillRect( groove, cg.brush(QColorGroup::Background) );

		int x, y, w, h;
		int mid = thickness / 2;

		if ( ticks & QSlider::Above )
		    mid += len / 8;
		if ( ticks & QSlider::Below )
		    mid -= len / 8;

		if ( slider->orientation() == Horizontal ) {
		    x = 0;
		    y = groove.y() + mid - 3;
		    w = slider->width();
		    h = 7;
		} else {
		    x = groove.x() + mid - 3;
		    y = 0;
		    w = 7;
		    h = slider->height();
		}

		p->fillRect( x, y, w, h, cg.brush( QColorGroup::Dark ));
		// the dark side
		p->setPen( cg.dark() );
		p->drawLine( x, y, x + w - 1, y );
		p->drawLine( x, y, x, y + h - 1);
		p->setPen( cg.shadow() );
		p->drawLine( x + 1, y + 1, x + w - 2, y + 1 );
		p->drawLine( x + 1, y + 1, x + 1, y + h - 2 );
		// the bright side!
		p->setPen(cg.shadow());
		p->drawLine( x + 1,  y + h - 2, x + w - 2,  y + h - 2 );
		p->drawLine( x + w - 2, y + 1, x + w - 2, y + h - 2 );
		p->setPen( cg.light() );
		p->drawLine( x, y + h - 1, x + w - 1, y + h - 1 );
		p->drawLine( x + w - 1, y, x + w - 1, y + h - 1 );
		// top left corner:
		p->setPen(cg.background());
		p->drawPoint( x, y );
		p->drawPoint( x + 1, y );
		p->drawPoint( x, y + 1 );
		p->setPen(cg.shadow());
		p->drawPoint( x + 1, y + 1 );
		// bottom left corner:
		p->setPen( cg.background() );
		p->drawPoint( x, y + h - 1 );
		p->drawPoint( x + 1, y + h - 1 );
		p->drawPoint( x, y + h - 2 );
		p->setPen( cg.light() );
		p->drawPoint( x + 1, y + h - 2 );
		// top right corner:
		p->setPen( cg.background() );
		p->drawPoint( x + w - 1, y );
		p->drawPoint( x + w - 2, y );
		p->drawPoint( x + w - 1, y + 1 );
		p->setPen( cg.dark() );
		p->drawPoint( x + w - 2, y + 1 );
		// bottom right corner:
		p->setPen( cg.background() );
		p->drawPoint( x + w - 1, y + h - 1 );
		p->drawPoint( x + w - 2, y + h - 1 );
		p->drawPoint( x + w - 1, y + h - 2 );
		p->setPen( cg.light() );
		p->drawPoint( x + w - 2, y + h - 2 );
		p->setPen( cg.dark() );
		p->drawPoint( x + w - 3, y + h - 3 );
		// ### end slider groove

		if ( how & Style_HasFocus )
		    drawPrimitive( PE_FocusRect, p, groove, cg );
	    }

	    if ((sub & SC_SliderHandle) && handle.isValid()) {
		const QColor c0 = cg.shadow();
		const QColor c1 = cg.dark();
		const QColor c3 = cg.light();

		int x1 = handle.x();
		int x2 = handle.x() + handle.width() - 1;
		int y1 = handle.y();
		int y2 = handle.y() + handle.height() - 1;
		int mx = handle.width() / 2;
		int my = handle.height() / 2;

		if ( slider->orientation() == Vertical ) {
		    // Background
		    QBrush oldBrush = p->brush();
		    p->setBrush( cg.brush( QColorGroup::Button ) );
		    p->setPen( NoPen );
		    QPointArray a(6);
		    a.setPoint( 0, x1 + 1, y1 + 1 );
		    a.setPoint( 1, x2 - my + 2, y1 + 1 );
		    a.setPoint( 2, x2 - 1, y1 + my - 1 );
		    a.setPoint( 3, x2 - 1, y2 - my + 1 );
		    a.setPoint( 4, x2 - my + 2, y2 - 1 );
		    a.setPoint( 5, x1 + 1, y2 - 1 );
		    p->drawPolygon( a );
		    p->setBrush( oldBrush );

		    // shadow border
		    p->setPen( c0 );
		    p->drawLine( x1, y1 + 1, x1,y2 - 1 );
		    p->drawLine( x2 - my + 2, y1, x2, y1 + my - 2 );
		    p->drawLine( x2 - my + 2, y2, x2, y1 + my + 2 );
		    p->drawLine( x2, y1 + my - 2, x2, y1 + my + 2 );
		    p->drawLine( x1 + 1, y1, x2 - my + 2, y1 );
		    p->drawLine( x1 + 1, y2, x2 - my + 2, y2 );

		    // light shadow
		    p->setPen( c3 );
		    p->drawLine( x1 + 1, y1 + 2, x1 + 1, y2 - 2 );
		    p->drawLine( x1 + 1, y1 + 1, x2 - my + 2, y1 + 1 );
		    p->drawLine( x2 - my + 2, y1 + 1, x2 - 1, y1 + my - 2 );

		    // dark shadow
		    p->setPen(c1);
		    p->drawLine( x2 - 1, y1 + my - 2, x2 - 1, y1 + my + 2 );
		    p->drawLine( x2 - my + 2, y2 - 1, x2 - 1, y1 + my + 2 );
		    p->drawLine( x1 + 1, y2 - 1, x2 -my + 2, y2 - 1 );

		    drawRiffles( p, handle.x(), handle.y() + 2, handle.width() - 3,
				 handle.height() - 4, cg, TRUE );
		} else {  // Horizontal
		    QBrush oldBrush = p->brush();
		    p->setBrush( cg.brush( QColorGroup::Button ) );
		    p->setPen( NoPen );
		    QPointArray a(6);
		    a.setPoint( 0, x2 - 1, y1 + 1 );
		    a.setPoint( 1, x2 - 1, y2 - mx + 2 );
		    a.setPoint( 2, x2 - mx + 1, y2 - 1 );
		    a.setPoint( 3, x1 + mx - 1, y2 - 1 );
		    a.setPoint( 4, x1 + 1, y2 - mx + 2 );
		    a.setPoint( 5, x1 + 1, y1 + 1 );
		    p->drawPolygon( a );
		    p->setBrush( oldBrush );

		    // shadow border
		    p->setPen( c0 );
		    p->drawLine( x1 + 1, y1, x2 - 1, y1 );
		    p->drawLine( x1, y2 - mx + 2, x1 + mx - 2, y2 );
		    p->drawLine( x2, y2 - mx + 2, x1 + mx + 2, y2 );
		    p->drawLine( x1 + mx - 2, y2, x1 + mx + 2, y2 );
		    p->drawLine( x1, y1 + 1, x1, y2 - mx + 2 );
		    p->drawLine( x2, y1 + 1, x2, y2 - mx + 2 );

		    // light shadow
		    p->setPen(c3);
		    p->drawLine( x1 + 1, y1 + 1, x2 - 1, y1 + 1 );
		    p->drawLine( x1 + 1, y1 + 1, x1 + 1, y2 - mx + 2 );

		    // dark shadow
		    p->setPen(c1);
		    p->drawLine( x2 - 1, y1 + 1, x2 - 1, y2 - mx + 2 );
		    p->drawLine( x1 + 1, y2 - mx + 2, x1 + mx - 2, y2 - 1 );
		    p->drawLine( x2 - 1, y2 - mx + 2, x1 + mx + 2, y2 - 1 );
		    p->drawLine( x1 + mx - 2, y2 - 1, x1 + mx + 2, y2 - 1 );

		    drawRiffles( p, handle.x() + 2, handle.y(), handle.width() - 4,
				 handle.height() - 5, cg, FALSE );
		}
	    }

	    if ( sub & SC_SliderTickmarks )
		QCommonStyle::drawComplexControl( control, p, widget, r,
						  cg, how, SC_SliderTickmarks,
						  subActive, opt );
#endif
	    break;
	}
    default:
	QWindowsStyle::drawComplexControl( control, p, widget, r, cg,
					   how, sub, subActive, opt );
	break;
    }
}