void OnOffButton::paintEvent(QPaintEvent *e)
{
    QPainter p(this);


    //Draw blue rect with on text inside
//******************************************************************
    QRectF rectangle3(0.1, 0.0, mPosX+5, size_height-0.1);

    p.setBrush(mOnBackGroundGradien);
    p.drawRoundedRect(rectangle3,rectRadius,rectRadius);

    p.setPen(QColor(255,255,255));
    p.drawText((-size_width/2)+mPosX+onOffset,textYOffset,"ON");
//******************************************************************

    //Draw Gray Rect rect with off text inside
//******************************************************************
    QRectF rectangle4(offAreaStart+mPosX, 0.0, offAreaEnd-mPosX,size_height-0.1);
    QLinearGradient fade1(0, 0, 0, height());
    fade1.setColorAt(0, QColor(160, 160, 160, 255));
    fade1.setColorAt(0.1,QColor(241,241,241));
    fade1.setColorAt(1, QColor(255, 255, 255, 255));
    p.setBrush(fade1);
    p.drawRoundedRect(rectangle4,rectRadius,rectRadius);

    p.setPen(QColor(136,136,136));
    p.drawText((size_width/2)+mPosX+offOffset,textYOffset,"OFF");



//******************************************************************

//Draw the handle
//******************************************************************
    p.setPen(QColor(176,176,176));
    QRectF rectangle(mPosX-3, 0.0, handle_width, size_height);
    QLinearGradient fade(0, 0, 0, height()/2);
    fade.setColorAt(0, QColor(255, 255, 255, 255));
    fade.setColorAt(0.2, QColor(201, 201, 201, 255));
    fade.setColorAt(1, QColor(252, 252, 252, 255));
    p.setBrush(fade);
    p.drawRoundedRect(rectangle,rectRadius,rectRadius);

//******************************************************************



//Draw the outher box
//******************************************************************
    p.setBrush(Qt::NoBrush);
    p.setPen(QColor(136,136,136));
    QRectF rectangle1(0.0, 0.1, size_width+startOffset, size_height);
    p.drawRoundedRect(rectangle1, rectRadius, rectRadius);
//******************************************************************



    p.end();
}
Beispiel #2
0
void display_digit(int n,float x,float y)
{
  if(n==1) {rectangle2(x,y,1);rectangle6(x,y,1);}
  else if(n==2) {rectangle1(x,y,1);rectangle2(x,y,1);rectangle4(x,y,1);rectangle5(x,y,1);rectangle7(x,y,1);}
  else if(n==3) {rectangle1(x,y,1);rectangle2(x,y,1);rectangle4(x,y,1);rectangle6(x,y,1);rectangle7(x,y,1);}
  else if(n==4) {rectangle2(x,y,1);rectangle3(x,y,1);rectangle4(x,y,1);rectangle6(x,y,1);}
  else if(n==5) {rectangle1(x,y,1);rectangle3(x,y,1);rectangle4(x,y,1);rectangle6(x,y,1);rectangle7(x,y,1);}
  else if(n==6) {rectangle1(x,y,1);rectangle3(x,y,1);rectangle4(x,y,1);rectangle5(x,y,1);rectangle6(x,y,1);rectangle7(x,y,1);}
  else if(n==7) {rectangle1(x,y,1);rectangle2(x,y,1);rectangle6(x,y,1);}
  else if(n==8) {rectangle1(x,y,1);rectangle2(x,y,1);rectangle3(x,y,1);rectangle4(x,y,1);rectangle5(x,y,1);rectangle6(x,y,1);rectangle7(x,y,1);}
  else if(n==0) {rectangle1(x,y,1);rectangle2(x,y,1);rectangle3(x,y,1);rectangle5(x,y,1);rectangle6(x,y,1);rectangle7(x,y,1);}
  else if(n==9) {rectangle1(x,y,1);rectangle2(x,y,1);rectangle3(x,y,1);rectangle4(x,y,1);rectangle6(x,y,1);rectangle7(x,y,1);}
}
Beispiel #3
0
void CSwitcher::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
{
    QPen t_pen;
    painter->setPen(t_pen);
    QBrush t_brush(Qt::white);  //笔刷填充颜色:白色
	painter->setBrush(t_brush);

    painter->save();  //保存当前painter状态
	painter->setRenderHint(QPainter::Antialiasing, true);
    QRectF rectangle(2, 7, m_boundingRect.width() - 4,m_boundingRect.height() - 4);

    if(m_switcherInfo.type == SWITCH)
    {
        painter->drawRoundedRect(rectangle,20,15);
    }
    else {
        painter->drawRoundedRect(rectangle,10,5);
    }
	painter->restore();

    painter->save();
	painter->setRenderHint(QPainter::Antialiasing, true);
	QRadialGradient radialGrad(QPointF(m_boundingRect.width()/2, m_boundingRect.height()/2), m_boundingRect.height());

    radialGrad.setColorAt(0.2, QColor(150,214,241));
    radialGrad.setColorAt(0.5, QColor(83,190,249));
    radialGrad.setColorAt(1, QColor(98,176,255));

    painter->setBrush(QBrush(radialGrad));

    QRectF rectangle1(7, 12, m_boundingRect.width() - 14, m_boundingRect.height() - 14);
    if(m_switcherInfo.type == SWITCH)
    {
        painter->drawRoundedRect(rectangle1,20,15);
    }
    else {
        painter->drawRoundedRect(rectangle1,10,5);
    }

	painter->restore();
	
	if(m_switcherInfo.portNum == 32 )
	{
		painter->save();
	    painter->setRenderHint(QPainter::Antialiasing, true);
	    t_brush.setColor(m_color);
	    painter->setBrush(t_brush);
        //painter->drawEllipse(QRectF(m_boundingRect.width()/2 - 5,m_boundingRect.height() - 2 - 8,10,8)); //M duankou
	    painter->restore();
	}
	if(m_switcherInfo.portNum == 48 )
	{
		painter->save();
		painter->setRenderHint(QPainter::Antialiasing, true);
		t_brush.setColor(m_color);
		painter->setBrush(t_brush);
		painter->drawEllipse(QRectF(m_boundingRect.width()/2 - 18,m_boundingRect.height() - 2 - 8,10,8)); //M duankou 
		painter->drawEllipse(QRectF(m_boundingRect.width()/2 + 15,m_boundingRect.height()- 2 - 8,10,8));
		painter->restore();
	}


    int t_fontSize = 10;
	QFont t_font("Times New Roman");
    t_font.setPointSize(t_fontSize);
	t_font.setBold(true);
	QFontMetrics t_textFontM(t_font);

	qreal t_textHeight = t_textFontM.height();

    QString s_id = QString("%1").arg(m_switcherInfo.ID);
    QString t_str2 = s_id +"-" + m_switcherInfo.name;
	qreal t_textWidth2 = t_textFontM.width(t_str2);

    if(t_textWidth2 > m_boundingRect.width())
    {
        t_textWidth2 = m_boundingRect.width();
    }
    if(t_textHeight > m_boundingRect.height()/2)
    {
        t_textHeight = m_boundingRect.height()/4;
    }

    //限定字体大小
    if (t_textWidth2 < m_boundingRect.width())
    {
        t_fontSize = 10;
    }
    else if (t_textWidth2 > m_boundingRect.width())
    {
        t_textWidth2 = m_boundingRect.width();
        t_fontSize = m_boundingRect.width()/10;
    }
    else if(t_textHeight > m_boundingRect.height()/3)
    {
        t_textHeight = m_boundingRect.height()/4;
        t_fontSize = m_boundingRect.width()/20;
    }

	//文字
	painter->setRenderHint(QPainter::Antialiasing, true);
	painter->setFont(t_font);
	//QPointF t_text1Pos(m_boundingRect.width()/2 - t_textWidth1/2,m_boundingRect.height()/4 /*- t_textHeight*/);
	//painter->drawText(t_text1Pos.x(),t_text1Pos.y(),t_str1);

//	QPointF t_text2Pos(m_boundingRect.width()/2 - t_textWidth2/2,m_boundingRect.height()*3/4 + t_textHeight/1.5);
//	painter->drawText(t_text2Pos.x(),t_text2Pos.y(),t_str2);
    painter->drawText(0, 5, t_str2);

	//交叉线
	painter->setRenderHint(QPainter::Antialiasing, true);
    t_pen.setWidth(2);
    if(m_switcherInfo.type == SWITCH)
    {
        t_pen.setColor(Qt::white);
        painter->setPen(t_pen);
        QPointF t_pnt1(m_boundingRect.width()/8+8,m_boundingRect.height()*3/8+5);
        QPointF t_pnt2(m_boundingRect.width()*3/8+2,m_boundingRect.height()*3/8+5);
        QPointF t_pnt3(m_boundingRect.width()*5/8-2,m_boundingRect.height()*3/8+5);
        QPointF t_pnt4(m_boundingRect.width()*7/8-8,m_boundingRect.height()*3/8+5);

        QPointF t_pnt5(m_boundingRect.width()/8+8,m_boundingRect.height()*5/8+5);
        QPointF t_pnt6(m_boundingRect.width()*3/8+2,m_boundingRect.height()*5/8+5);
        QPointF t_pnt7(m_boundingRect.width()*5/8-2,m_boundingRect.height()*5/8+5);
        QPointF t_pnt8(m_boundingRect.width()*7/8-8,m_boundingRect.height()*5/8+5);


        //箭头点坐标
        QPointF t_pnt11(m_boundingRect.width()/8+8+5,m_boundingRect.height()*3/8-3+5);
        QPointF t_pnt12(m_boundingRect.width()/8+8+5,m_boundingRect.height()*3/8+3+5);

        QPointF t_pnt41(m_boundingRect.width()*7/8-8-5,m_boundingRect.height()*3/8-3+5);
        QPointF t_pnt42(m_boundingRect.width()*7/8-8-5,m_boundingRect.height()*3/8+3+5);

        QPointF t_pnt51(m_boundingRect.width()/8+8+5,m_boundingRect.height()*5/8-3+5);
        QPointF t_pnt52(m_boundingRect.width()/8+8+5,m_boundingRect.height()*5/8+3+5);

        QPointF t_pnt81(m_boundingRect.width()*7/8-8-5,m_boundingRect.height()*5/8-3+5);
        QPointF t_pnt82(m_boundingRect.width()*7/8-8-5,m_boundingRect.height()*5/8+3+5);

        painter->setRenderHint(QPainter::Antialiasing, true);
        painter->drawLine(t_pnt1,t_pnt2);
        painter->drawLine(t_pnt3,t_pnt4);
        painter->drawLine(t_pnt5,t_pnt6);
        painter->drawLine(t_pnt7,t_pnt8);
        painter->drawLine(t_pnt2,t_pnt7);
        painter->drawLine(t_pnt3,t_pnt6);

        painter->drawLine(t_pnt1,t_pnt11);
        painter->drawLine(t_pnt1,t_pnt12);
        painter->drawLine(t_pnt4,t_pnt41);
        painter->drawLine(t_pnt4,t_pnt42);
        painter->drawLine(t_pnt5,t_pnt51);
        painter->drawLine(t_pnt5,t_pnt52);
        painter->drawLine(t_pnt8,t_pnt81);
        painter->drawLine(t_pnt8,t_pnt82);
    }
    else{
        t_pen.setColor(Qt::black);
    }

	

}
Beispiel #4
0
Datei: main.cpp Projekt: GaaH/ecs
int main(int argc, char *argv[])
{
  /*
  sf::RenderWindow app(sf::VideoMode(640, 480), "ECS");
  sf::RectangleShape rectangle(sf::Vector2f(50.f, 50.f));
  rectangle.setFillColor(sf::Color::Blue);

  sf::RectangleShape rectangle2(sf::Vector2f(50.f, 50.f));
  rectangle2.setFillColor(sf::Color::Red);

  GameObject objects[2];

  DescriptionSystem desc_sys;
  MovementSystem move_sys;
  RenderSystem renderer(&app);
  CollisionSystem collision_sys;

  DescriptionComponent desc(objects[0].getId());
  PositionComponent pos(objects[0].getId()), pos2(objects[1].getId());
  VelocityComponent vel(objects[0].getId(), 1.f), vel2(objects[1].getId(), 0.2f, 0.1f);
  DrawableComponent drawable(objects[0].getId()), drawable2(objects[1].getId());
  CollidableComponent c1(objects[0].getId(), rectangle.getGlobalBounds()), c2(objects[1].getId(), rectangle2.getGlobalBounds());
  drawable.drawable = &rectangle;
  drawable2.drawable = &rectangle2;

  //pos.position.y = 50.f;
  pos2.position.x = 250.f;
  pos2.position.y = 20.f;

  desc_sys.registerComponent("Description");

  move_sys.registerComponent("Position");
  move_sys.registerComponent("Velocity");

  renderer.registerComponent("Drawable");
  renderer.registerComponent("Position");

  collision_sys.registerComponent("Position");
  collision_sys.registerComponent("Collidable");

  objects[0].addComponent(&desc);
  objects[0].addComponent(&pos);
  objects[0].addComponent(&vel);
  objects[0].addComponent(&drawable);
  objects[0].addComponent(&c1);

  objects[1].addComponent(&vel2);
  objects[1].addComponent(&drawable2);
  objects[1].addComponent(&pos2);
  objects[1].addComponent(&c2);

  if (desc_sys.canUpdate(objects[0]))
    desc_sys.update(objects[0]);

  sf::Event event;
  while (app.isOpen())
    {
      while (app.pollEvent(event))
	{
	  if (event.type == sf::Event::Closed)
	    app.close();
	}

      for (int i(0) ; i < 2 ; ++i)
	if (move_sys.canUpdate(objects[i]))
	  move_sys.update(objects[i]);


      app.clear(sf::Color::White);

      for (int i(0) ; i < 2 ; ++i)
	if (collision_sys.canUpdate(objects[i]))
	  collision_sys.update(objects[i]);

      for (int i(0) ; i < 2 ; ++i)
	if (renderer.canUpdate(objects[i]))
	  renderer.update(objects[i]);

      app.display();
    }
*/

  GameWorld world;
  GameObject *o1(world.addObject());
  GameObject *o2(world.addObject());

  sf::RectangleShape rectangle1(sf::Vector2f(50.f, 50.f));
  rectangle1.setFillColor(sf::Color::Blue);

  sf::RectangleShape rectangle2(sf::Vector2f(50.f, 50.f));
  rectangle2.setFillColor(sf::Color::Red);

  PhysicSystem *phys_sys(new PhysicSystem);
  phys_sys->registerComponent("Physic");
  phys_sys->registerComponent("Position");
  world.addSystem(phys_sys);

  PhysicComponent phys1(o1->getId(), 50, cpMomentForBox(50, 5, 5)), phys2(o2->getId(), 50, cpMomentForBox(50, 5, 5));
  DescriptionComponent desc1(o1->getId()), desc2(o2->getId());
  PositionComponent pos1(o1->getId()), pos2(o2->getId());
  //VelocityComponent vel1(objects[0].getId(), 1.f), vel2(objects[1].getId(), 0.2f, 0.1f);
  DrawableComponent drawable1(o1->getId()), drawable2(o2->getId());
  //CollidableComponent c1(objects[0].getId(), rectangle.getGlobalBounds()), c2(objects[1].getId(), rectangle2.getGlobalBounds());

  phys1.shape = cpBoxShapeNew(phys1.body, 50.f, 50.f);
  phys2.shape = cpBoxShapeNew(phys2.body, 50.f, 50.f);
  cpBodySetPos(phys1.body, cpv(0, 0));
  cpBodySetPos(phys2.body, cpv(200, 0));

  cpSpaceAddShape(phys_sys->getSpace(), phys1.shape);
  cpSpaceAddShape(phys_sys->getSpace(), phys2.shape);

  cpSpaceAddBody(phys_sys->getSpace(), phys1.body);
  cpSpaceAddBody(phys_sys->getSpace(), phys2.body);

  drawable1.drawable = &rectangle1;
  drawable2.drawable = &rectangle2;

  pos1.position.x = 50.f;
  pos2.position = sf::Vector2f(200.f, 150.f);

  o1->addComponent(&desc1);
  o1->addComponent(&drawable1);
  o1->addComponent(&pos1);
  o1->addComponent(&phys1);

  o2->addComponent(&desc2);
  o2->addComponent(&drawable2);
  o2->addComponent(&pos2);
  o2->addComponent(&phys2);

  while (true)
    {
      world.update();
    }

  return 0;
}