Example #1
0
void QCommonStyle_QtDShell::__override_drawControl(int  element0, const QStyleOption*  opt1, QPainter*  p2, const QWidget*  w3, bool static_call) const
{
    if (static_call) {
        QCommonStyle::drawControl((QStyle::ControlElement )element0, (const QStyleOption* )opt1, (QPainter* )p2, (const QWidget* )w3);
    } else {
        drawControl((QStyle::ControlElement )element0, (const QStyleOption* )opt1, (QPainter* )p2, (const QWidget* )w3);
    }
}
Example #2
0
  void CursynthGui::placeControl(std::string name, const Control* control,
                                 int x, int y, int width) {
    DisplayDetails* details = initControl(name, control);
    details->x = x;
    details->y = y;
    details->width = width;
    details->label = name;
    details->bipolar = control->isBipolar();

    details_lookup_[control] = details;
    drawControl(control, false);
  }
void FileManager::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
	BarBase::paint( painter, option, widget );
	painter->save();
	//*********************************************************
	drawDropArea( painter );
	drawFileArea( painter );
	drawVisArea( painter );
	renderItem( painter );
	drawControl( painter );
	drawViews( painter );
	drawColorBar( painter );
	//*********************************************************
	painter->restore();
	//*********************************************************
	return;
}
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;
    }
}
Example #5
0
void display(void)
{
	if(wIsDown) 
	{
		if(nearTree()) player->playerHitTree();
		player->goForward();
		
	}
	else
		player->stop();
	if(sIsDown)
	{
			player->goBackwards();
	}
	if(qIsDown) 
	{
		mapAngle-=0.02;	
	}
	if(eIsDown)
	{
			mapAngle+=0.02;
	}
	if(jumping)
	{
			player->jump();
	}
	player->heightUpdate();
	if(player->isNextControl())
	{
		
		//punshControl(map);
		controlIsFound = true;
			
		player->setNextControl(world->getControlPos(player->getPunshedControls()));		

	}
	

	// clear the screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	
	
	printError("pre display");

	mat4 total, modelView, translate;
	modelView= IdentityMatrix();


	//Draw Sky box

	glUseProgram(skyProgram);
	glDisable(GL_DEPTH_TEST);
	mat4 camMatrix2 = player->getCamMatrix();

	camMatrix2.m[3] = 0;
	camMatrix2.m[7] = 0;
	camMatrix2.m[11] = 0;	

	mat4 modelView2 = modelView;

	mat4 translate2 = T(0,-0.5,0);
	modelView2 = Mult(modelView2,translate2);

	glUniformMatrix4fv(glGetUniformLocation(skyProgram, "mdlMatrix"), 1, GL_TRUE, modelView2.m);
	glUniformMatrix4fv(glGetUniformLocation(skyProgram, "camMatrix"), 1, GL_TRUE, camMatrix2.m);

	glActiveTexture(GL_TEXTURE5);
	glBindTexture(GL_TEXTURE_2D, skyTex);
	glUniform1i(glGetUniformLocation(skyProgram, "tex1"), 5);

	DrawModel(sky, skyProgram, "inPosition", NULL, "inTexCoord");
	
	glEnable(GL_DEPTH_TEST);
	
	glUseProgram(program);


	//Draw world
	glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, modelView.m);
	glUniformMatrix4fv(glGetUniformLocation(program, "camMatrix"), 1, GL_TRUE, player->getCamMatrix().m);
	
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, tex1);
	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_2D, tex2);
	glActiveTexture(GL_TEXTURE3);
	glBindTexture(GL_TEXTURE_2D, tex4);
	glUniform1i(glGetUniformLocation(program, "tex1"), 1);
	glUniform1i(glGetUniformLocation(program, "tex2"), 2);
	glUniform1i(glGetUniformLocation(program, "tex3"), 3);
	DrawModel(tm, program, "inPosition", "inNormal", "inTexCoord");


	//Draw trees
	glUseProgram(billBoardProgram);
	glEnable(GL_ALPHA_TEST);
	glActiveTexture(GL_TEXTURE4);
	glBindTexture(GL_TEXTURE_2D, treeTex);
	glUniform1i(glGetUniformLocation(billBoardProgram, "tex1"), 4);

	for(int x=2; x<254; x=x+3)
	{
		for(int z=2; z<254; z=z+3)
		{
			if(posIsTree[x][z]){
				DrawBillboard(bill,x,z,modelView);
			}
		}
	}	

	//Draw controls
	glDisable(GL_CULL_FACE);
	drawControl(110,72);
	drawControl(50,151);
	drawControl(106,233);
	drawControl(179,103);
	drawControl(226,111);
	glEnable(GL_CULL_FACE);
	//Draw map
	glActiveTexture(GL_TEXTURE6);
	glBindTexture(GL_TEXTURE_2D, mapTex);
	glUniform1i(glGetUniformLocation(billBoardProgram, "tex1"), 6);

	if(showMap)
	{
			DrawMap(map,compass,modelView); 
	}

	//Check if near control
	if(player->getPunshedControls() <=4){
		glActiveTexture(GL_TEXTURE7);
		glBindTexture(GL_TEXTURE_2D, punshTex);
		glUniform1i(glGetUniformLocation(billBoardProgram, "tex1"), 7);
	
		if(controlIsFound)
		{
				punshControl(punsh, modelView);
				controlPunshedFor++;
		}
		if(controlPunshedFor>100){
			controlIsFound = false;
			controlPunshedFor = 0;
		}
	}
	else
	{
		glActiveTexture(GL_TEXTURE7);
		glBindTexture(GL_TEXTURE_2D, goalTex);
		glUniform1i(glGetUniformLocation(billBoardProgram, "tex1"), 7);
		punshControl(punsh, modelView);

	}
	glDisable(GL_ALPHA_TEST);
	
	glutSwapBuffers();
	
}
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 );
}
Example #7
0
void Target_draw() {
	float ratio = textureImages[textureIndex].ratio;
	float minTexCoordX = (ratio > 1.0f ? -0.5f : -0.5f / ratio) * (extendedTexCoords ? 2.0f : 1.0f) + 0.5f;
	float maxTexCoordX = (ratio > 1.0f ?  0.5f :  0.5f / ratio) * (extendedTexCoords ? 2.0f : 1.0f) + 0.5f;
	float minTexCoordY = (ratio < 1.0f ? -0.5f : -0.5f * ratio) * (extendedTexCoords ? 2.0f : 1.0f) + 0.5f;
	float maxTexCoordY = (ratio < 1.0f ?  0.5f :  0.5f * ratio) * (extendedTexCoords ? 2.0f : 1.0f) + 0.5f;
	struct vertex_p3f_t2f vertices[] = {
		{{-0.5f, -0.5f, 0.0f}, {minTexCoordX, minTexCoordY}},
		{{ 0.5f, -0.5f, 0.0f}, {maxTexCoordX, minTexCoordY}},
		{{ 0.5f,  0.5f, 0.0f}, {maxTexCoordX, maxTexCoordY}},
		{{ 0.5f,  0.5f, 0.0f}, {maxTexCoordX, maxTexCoordY}},
		{{-0.5f,  0.5f, 0.0f}, {minTexCoordX, maxTexCoordY}},
		{{-0.5f, -0.5f, 0.0f}, {minTexCoordX, minTexCoordY}},
		
		{{-0.5f, -0.75f, -0.5f}, {minTexCoordX, minTexCoordY}},
		{{ 0.5f, -0.75f, -0.5f}, {maxTexCoordX, minTexCoordY}},
		{{ 0.5f, -0.75f,  0.5f}, {maxTexCoordX, maxTexCoordY}},
		{{ 0.5f, -0.75f,  0.5f}, {maxTexCoordX, maxTexCoordY}},
		{{-0.5f, -0.75f,  0.5f}, {minTexCoordX, maxTexCoordY}},
		{{-0.5f, -0.75f, -0.5f}, {minTexCoordX, minTexCoordY}},
		
		{{-0.5f, 0.75f, -0.5f}, {minTexCoordX, minTexCoordY}},
		{{ 0.5f, 0.75f, -0.5f}, {maxTexCoordX, minTexCoordY}},
		{{ 0.5f, 0.75f,  0.5f}, {maxTexCoordX, maxTexCoordY}},
		{{ 0.5f, 0.75f,  0.5f}, {maxTexCoordX, maxTexCoordY}},
		{{-0.5f, 0.75f,  0.5f}, {minTexCoordX, maxTexCoordY}},
		{{-0.5f, 0.75f, -0.5f}, {minTexCoordX, minTexCoordY}}
	};
	Matrix matrix;
	
	if (whiteBackground) {
		glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
	} else {
		glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	}
	
	glClear(GL_COLOR_BUFFER_BIT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	matrix = Matrix_perspective(Matrix_identity(), 60.0f, (float) viewportWidth / viewportHeight, 0.25f, 100.0f);
	glMultMatrixf(matrix.m);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glTranslatef(0.0f, 0.0f, zoomedOut ? -5.0f : -2.0f);
	
	texture->activate(texture);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glColor4ub(0xFF, 0xFF, 0xFF, 0xFF);
	glVertexPointer(3, GL_FLOAT, sizeof(struct vertex_p3f_t2f), vertices[0].position);
	glTexCoordPointer(2, GL_FLOAT, sizeof(struct vertex_p3f_t2f), vertices[0].texCoords);
	glDrawArrays(GL_TRIANGLES, 0, sizeof(vertices) / sizeof(struct vertex_p3f_t2f));
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	texture->deactivate(texture);
	
	if (iPhoneMode) {
		float viewRatio = (float) viewportWidth / viewportHeight;
		
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		matrix = Matrix_ortho(Matrix_identity(), 0.0f, viewRatio, 0.0f, 1.0f, -1.0f, 1.0f);
		glMultMatrixf(matrix.m);
		glMatrixMode(GL_MODELVIEW);
		
		drawControl(0.0f, 0.0f / 6.0f, 1.0f / 6.0f, textureIndex);
		drawControl(0.0f, 1.0f / 6.0f, 1.0f / 6.0f, autoBlendModeIndex);
		drawControl(0.0f, 2.0f / 6.0f, 1.0f / 6.0f, minFilterIndex);
		drawControl(0.0f, 3.0f / 6.0f, 1.0f / 6.0f, magFilterIndex);
		drawControl(0.0f, 4.0f / 6.0f, 1.0f / 6.0f, wrapSModeIndex);
		drawControl(0.0f, 5.0f / 6.0f, 1.0f / 6.0f, wrapTModeIndex);
		drawControl(viewRatio - 1.0f / 6.0f, 0.0f / 6.0f, 1.0f / 6.0f, autoMipmap);
		drawControl(viewRatio - 1.0f / 6.0f, 1.0f / 6.0f, 1.0f / 6.0f, anisotropicFilter);
		drawControl(viewRatio - 1.0f / 6.0f, 2.0f / 6.0f, 1.0f / 6.0f, extendedTexCoords);
		drawControl(viewRatio - 1.0f / 6.0f, 3.0f / 6.0f, 1.0f / 6.0f, whiteBackground);
		drawControl(viewRatio - 1.0f / 6.0f, 4.0f / 6.0f, 1.0f / 6.0f, zoomedOut);
		drawControl(viewRatio - 1.0f / 6.0f, 5.0f / 6.0f, 1.0f / 6.0f, 0);
	}
}
Example #8
0
void GtkProxyStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget) const
{
    if (SB_Standard!=sbarType && CC_ScrollBar==control) {
        if (const QStyleOptionSlider *sb = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
            QRect r=option->rect;
            QRect slider=subControlRect(control, option, SC_ScrollBarSlider, widget);
            painter->save();
            #ifdef ENABLE_OVERLAYSCROLLBARS
            bool usePlain=!sbarThumb || usePlainScrollbars(widget);
            #else
            bool usePlain=true;
            #endif

            if (usePlain) {
                #if 0
                QLinearGradient grad(r.topLeft(), Qt::Horizontal==sb->orientation ? r.bottomLeft() : r.topRight());
                QColor col=option->palette.base().color();
                grad.setColorAt(0, col.darker(110));
                grad.setColorAt(1, col.darker(102));
                painter->fillRect(r, grad);
                #else
                if (widget && widget->property(constOnCombo).toBool()) {
                    painter->fillRect(r, option->palette.background());
                } else if (!widget || widget->testAttribute(Qt::WA_OpaquePaintEvent)) {
                    painter->fillRect(r, option->palette.base());
                }
                #endif
            }
            #ifdef ENABLE_OVERLAYSCROLLBARS
            else {
                painter->fillRect(r, usePlain ? option->palette.base() : option->palette.background());
                const QAbstractItemView *v=view(widget);
                if (v && qobject_cast<const QTreeView *>(v) && ((const QTreeView *)v)->header()&& ((const QTreeView *)v)->header()->isVisible()) {
                    QStyleOptionHeader ho;
                    ho.rect=QRect(r.x()+r.width()-(sbarWidth), r.y(), sbarWidth, ((const QTreeView *)v)->header()->height());
                    ho.state=option->state;
                    ho.palette=option->palette;
                    painter->save();
                    drawControl(CE_Header, &ho, painter, ((const QTreeView *)v)->header());
                    painter->restore();
                }
            }
            #endif
            if (slider.isValid()) {
                if (usePlain) {
                    bool inactive=!(sb->activeSubControls&SC_ScrollBarSlider && (option->state&State_MouseOver || option->state&State_Sunken));
                    int adjust=inactive ? 3 : 1;
                    painter->setRenderHint(QPainter::Antialiasing, true);
                    if (Qt::Horizontal==sb->orientation) {
                        slider.adjust(1, adjust, -1, -adjust);
                    } else {
                        slider.adjust(adjust, 1, -adjust, -1);
                    }
                    int dimension=(Qt::Horizontal==sb->orientation ? slider.height() : slider.width());
                    QPainterPath path=buildPath(QRectF(slider.x()+0.5, slider.y()+0.5, slider.width()-1, slider.height()-1),
                                                dimension>6 ? (dimension/4.0) : (dimension/8.0));
                    QColor col(option->palette.highlight().color());
                    if (!(option->state&State_Active)) {
                        col=col.darker(115);
                    }
                    painter->fillPath(path, col);
                    painter->setPen(col);
                    painter->drawPath(path);
                }
                #ifdef ENABLE_OVERLAYSCROLLBARS
                else {
                    QRect toThumb;
                    QPalette::ColorGroup cg=option->palette.currentColorGroup();
                    if (sbarThumb && sbarThumbTarget && sbarThumbTarget==widget && sbarThumb->isVisible()) {
                        QPoint p=sbarThumbTarget->mapFromGlobal(sbarThumb->pos())+QPoint(1, 1);
                        if (Qt::Horizontal==sb->orientation) {
                            if (p.x()<slider.x()) {
                                toThumb=QRect(p.x(), slider.y(), slider.x()-p.x(), slider.width());
                            } else if (p.x()>(slider.x()+slider.width())) {
                                toThumb=QRect(slider.x()+slider.width(), slider.x(), p.x()-(slider.y()+slider.width()), slider.width());
                            }
                        } else {
                            if (p.y()<slider.y()) {
                                toThumb=QRect(slider.x(), p.y(), slider.width(), slider.y()-p.y());
                            } else if (p.y()>(slider.y()+slider.height())) {
                                toThumb=QRect(slider.x(), slider.y()+slider.height(), slider.width(), p.y()-(slider.y()+slider.height()));
                            }
                        }
                        cg=QPalette::Active;
                    }
                    if (toThumb.isValid()) {
                        QColor col(option->palette.color(cg, QPalette::Text));
                        col.setAlphaF(0.35);
                        painter->fillRect(toThumb, col);
                    }
                    painter->fillRect(slider, option->palette.color(cg, QPalette::Highlight));
                }
                #endif
            }

            painter->restore();
            return;
        }
    }
    baseStyle()->drawComplexControl(control, option, painter, widget);
}
Example #9
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;
    }
}