Esempio n. 1
0
void ParameterSetCanvas::draw(QPainter & p) {
    if (! visible()) return;

    QBrush brsh = p.brush();
    QColor bckgrnd = p.backgroundColor();

    p.setBackgroundMode((used_color == UmlTransparent)
                        ? ::Qt::TransparentMode
                        : ::Qt::OpaqueMode);

    QColor co = color(used_color);
    QRect r = rect();
    FILE * fp = svg();

    p.setBackgroundColor(co);

    if (used_color != UmlTransparent)
        p.setBrush(co);

    if (fp != 0)
        fprintf(fp, "<g>\n"
                "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
                " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n"
                "</g>\n",
                svg_color(used_color),
                r.x(), r.y(), r.width() - 1, r.height() - 1);

    p.drawRect(r);

    p.setBackgroundColor(bckgrnd);
    p.setBrush(brsh);

    if (selected())
        show_mark(p, r);
}
Esempio n. 2
0
void SubjectCanvas::draw(QPainter & p) {
  if (! visible()) return;
  p.setRenderHint(QPainter::Antialiasing, true);
  QRect r = rect();
  QColor bckgrnd = p.backgroundColor();

  p.setBackgroundMode((used_color == UmlTransparent) ? ::Qt::TransparentMode : ::Qt::OpaqueMode);

  QColor co = color(used_color);
  FILE * fp = svg();

  if (fp != 0)
    fputs("<g>\n", fp);  
  
  p.setBackgroundColor(co);
  p.setFont(the_canvas()->get_font(UmlNormalBoldFont));
  
  if (used_color != UmlTransparent)
    p.fillRect(r, co);
  
  if (fp != 0)
    fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
	    " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
	    svg_color(used_color), 
	    r.x(), r.y(), r.width() - 1, r.height() - 1);

  p.drawRect(r);
  
  r.setTop(r.top() + (int) (2*the_canvas()->zoom()));
  p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, name);
  if (fp != 0) {
    draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, name,
	      p.font(), fp);
    fputs("</g>\n", fp);
  }
    
  p.setBackgroundColor(bckgrnd);
  
  if (selected())
    show_mark(p, rect());
}
Esempio n. 3
0
void InterruptibleActivityRegionCanvas::draw(QPainter & p) {
  if (! visible()) return;
  
  QRect r = rect();
  QBrush brsh = p.brush();
  QColor bckgrnd = p.backgroundColor();
  
  p.setBackgroundMode((used_color == UmlTransparent)
		      ? ::Qt::TransparentMode
		      : ::Qt::OpaqueMode);

  QColor co = color(used_color);
  
  p.setBackgroundColor(co);
  
  if (used_color != UmlTransparent) 
    p.setBrush(co);
  
  p.setPen(::Qt::DotLine);
  p.drawRoundRect(r, 8, 8);

  FILE * fp = svg();

  if (fp != 0)
    fprintf(fp,
	    "\t<rect fill=\"%s\" stroke=\"black\" stroke-dasharray=\"4,4\" stroke-opacity=\"1\""
	    " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"10\" />\n",
	    svg_color(used_color),
	    r.left(), r.top(), r.width() - 1, r.height() - 1);
  
  p.setPen(::Qt::SolidLine);      
  p.setBackgroundColor(bckgrnd);
  p.setBrush(brsh);
  
  if (selected())
    show_mark(p, r);
}
Esempio n. 4
0
void TextCanvas::draw(QPainter & p) {
    if (! visible()) return;

    QColor bgcolor = p.backgroundColor();
    QPen fgcolor = p.pen();

    if (bg_c == UmlTransparent)
        p.setBackgroundMode(::Qt::TransparentMode);
    else {
        p.setBackgroundMode(::Qt::OpaqueMode);
        p.setBackgroundColor(color(bg_c));
    }

    if (fg_c != UmlTransparent)
        p.setPen(color(fg_c));

    QRect r = rect();

    p.setFont(the_canvas()->get_font(itsfont));
    p.drawText (r.left(), r.top(), r.width(), r.height(),
                ::Qt::AlignLeft + ::Qt::AlignTop + ::Qt::WordBreak, text);

    FILE * fp = svg();

    if (fp != 0)
        draw_text (r.left(), r.top(), r.width(), r.height(),
                   ::Qt::AlignLeft + ::Qt::AlignTop + ::Qt::WordBreak,
                   text, p.font(), fp, fg_c, bg_c);

    p.setFont(the_canvas()->get_font(UmlNormalFont));
    p.setBackgroundColor(bgcolor);
    p.setPen(fgcolor);

    if (selected())
        show_mark(p, r);
}
Esempio n. 5
0
QPixmap KoPictureClipart::generatePixmap(const QSize& size, bool /*smoothScale*/)
{
    // Not sure if it works, but it worked for KoPictureFilePreviewWidget::setClipart
    QPixmap pixmap(size);
    QPainter p;

    p.begin( &pixmap );
    p.setBackgroundColor( Qt::white );
    pixmap.fill( Qt::white );

    QRect br = m_clipart.boundingRect();
    if ( br.width() && br.height() )
        p.scale( (double)pixmap.width() / (double)br.width(), (double)pixmap.height() / (double)br.height() );
    p.drawPicture( m_clipart );
    p.end();
    return pixmap;
}
QPixmap QSettingColorTableItem::CreatePixmap() const
{
	if (m_pSetting == NULL || (m_pSetting->GetType() & 0xF) != Setting::SettingTypeColor)
		return QPixmap();
	else
	{
		QPixmap bmpImage(sizeHint().height() - 4, sizeHint().height() - 4);
		QPainter dcImage;
		QColor clrBackground(m_pSetting->GetValue().strValue);
		dcImage.begin(&bmpImage, table()->viewport());
		dcImage.setBackgroundColor(clrBackground.isValid() ? clrBackground : QColor(0, 0, 0));
		dcImage.eraseRect(bmpImage.rect());
		dcImage.drawRect(bmpImage.rect());
		dcImage.end();
		return bmpImage;
	}
}
Esempio n. 7
0
void UcUseCaseCanvas::draw(QPainter & p) {
  if (! visible()) return;
  
  QRect r = rect();
  UseCaseData * data = (UseCaseData *) browser_node->get_data();
  p.setRenderHint(QPainter::Antialiasing, true);
  used_color = (itscolor == UmlDefaultColor)
    ? the_canvas()->browser_diagram()->get_color(UmlUseCase)
    : itscolor;
  
  QColor col = color(used_color);
  QBrush brsh = p.brush();
  bool realizationp =
    !strcmp(data->get_short_stereotype(), "realization");
  FILE * fp = svg();
  int rx = width()/2 - 1;
  int ry = height()/2 - 1;

  if (fp != 0)
    fputs("<g>\n", fp);
  
  if (used_color != UmlTransparent) {
    const int shadow = the_canvas()->shadow() - 1;
    
    if (shadow != -1) {
      r.setRight(r.right() - shadow);
      r.setBottom(r.bottom() - shadow);
      p.setPen(::Qt::NoPen);
      p.setBrush(::Qt::darkGray);
      p.drawEllipse(r.left() + shadow, r.top() + shadow, r.width(), r.height());

      if (fp != 0) {
	rx = width()/2 - 1;
	ry = height()/2 - 1;

	fprintf(fp, "\t<ellipse fill=\"#%06x\" stroke=\"none\""
		" cx=\"%d\" cy=\"%d\" rx=\"%d\" ry=\"%d\" />\n",
		QColor(::Qt::darkGray).rgb()&0xffffff,
		r.left() + shadow + rx, r.top() + shadow + ry, rx, ry);
      }
    }

    if (fp != 0)
      fprintf(fp, "\t<ellipse fill=\"%s\" stroke=\"black\"%s stroke-width=\"1\" stroke-opacity=\"1\""
	      " cx=\"%d\" cy=\"%d\" rx=\"%d\" ry=\"%d\" />\n",
	      svg_color(used_color),
	      (realizationp) ? " stroke-dasharray=\"4,4\"" : "",
	      r.left() + rx, r.top() + ry, rx, ry);
  }
  else if (fp != 0)
    fprintf(fp, "\t<ellipse fill=\"none\" stroke=\"black\"%s stroke-width=\"1\" stroke-opacity=\"1\""
	    " cx=\"%d\" cy=\"%d\" rx=\"%d\" ry=\"%d\" />\n",
	    (realizationp) ? " stroke-dasharray=\"4,4\"" : "",
	    r.left() + rx, r.top() + ry, rx, ry);
  
  p.setBackgroundMode((used_color == UmlTransparent) ? ::Qt::TransparentMode : ::Qt::OpaqueMode);
  p.setBrush(col);

  if (realizationp)
    p.setPen(::Qt::DotLine);
  else
    p.setPen(::Qt::SolidLine);
  p.drawEllipse(r.left(), r.top(), r.width(), r.height());
  if (realizationp)
    p.setPen(::Qt::SolidLine);

  QString ep = data->get_extension_points();
  
  if (!ep.isEmpty()) {
    QFontMetrics fbm(the_canvas()->get_font(UmlNormalBoldFont));
    const int two = (int) (2 * the_canvas()->zoom());
    int he = fbm.height() + two;
    int py = (int) y() + height()/4;
    int dx = width() / 15;
    int px = (int) x() + dx;
    
    p.drawLine(px, py, r.right() - dx, py);
    if (fp != 0)
      fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
	      " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
	      px, py, r.right() - dx, py);
    
    int h = (height() * 3) / 4 - two;
    int w = width() - dx - dx;
    QColor bckgrnd = p.backgroundColor();
    
    py += two;
    p.setBackgroundColor(col);
    p.setFont(the_canvas()->get_font(UmlNormalBoldFont));

    p.drawText(px, py, w, h, ::Qt::AlignHCenter + ::Qt::AlignTop,
	       "Extension Points");
    if (fp != 0)
      draw_text(px, py, w, h, ::Qt::AlignHCenter + ::Qt::AlignTop, 
		"Extension Points", p.font(), fp);
    
    h -= he;
    
    if (h > he) {
      // at least one line may be written
      py += he;
      p.setFont(the_canvas()->get_font(UmlNormalFont));
      p.drawText(px, py, w, h, ::Qt::AlignCenter, ep);
      p.setBackgroundColor(bckgrnd);
      
      if (fp != 0)
	draw_text(px, py, w, h, ::Qt::AlignCenter, ep, p.font(), fp);
    }
  }
  
  if (fp != 0)
    fputs("</g>\n", fp);
  
  p.setBrush(brsh);
  
  if (selected())
    show_mark(p, rect());
}
Esempio n. 8
0
void WSpacePlot::drawContent(QPainter &p,bool) {

  QBrush brush;
  QColor color;
  int hue, selectHue, s, v;
  
  paintColor.getHsv(hue,s,v);
  colorGroup().highlight().getHsv(selectHue,s,v);
  
  QArray<SpaceCell>::Iterator it;
  QArray<SpaceCell>::Iterator end=cellData.end();

  if (drawGrid) {
    p.eraseRect(p.window());
    for (it=cellData.begin(); it!=end; ++it) {
      if (it->attr & selected) {
	p.fillRect(it->rect,colorGroup().highlight());
	p.setPen(colorGroup().highlight().light());
      } else p.setPen(colorGroup().mid());
      p.drawRect(it->rect);
    } 
  } else {   

    p.setBackgroundMode(OpaqueMode);
    p.setBackgroundColor(QColor(64,64,64));
    p.fillRect(p.window(),QBrush(black,Dense6Pattern));
    
    for (it=cellData.begin(); it!=end; ++it)
      if (it->visible) 
	if (it->attr&normal) {
	  
	  float val=clampf(dataRange.scaleValue(it->data));
	  
	  if (finite(val)) {
	    
	    if (it->attr & selected) 
	      color.setHsv(selectHue,128,int((0.5+0.5*val)*255));
	    else
	      color.setHsv(hue,255,int(val*255));
	    
	    p.fillRect(it->rect,color);	
	    
	    if (it->attr&marked) {
	      if (it->attr&selected) 
		color.setHsv(hue,255,int(val*255));
	      else 
		color.setHsv(selectHue,128,int((0.5+0.5*val)*255));	    
	      p.setPen(color);
	      p.drawRect(it->rect);
	    }
	  } else 
	    p.fillRect(it->rect,QBrush(paintColor,DiagCrossPattern));
	} 
  }
  
  if (hasFocus() && QRect(QPoint(0,0),viewSize).contains(currCell)) {
    p.setRasterOp(XorROP);
    p.setPen(white);
    p.drawRect(cellData[currCell.x()+currCell.y()*viewSize.width()].rect);
    p.setRasterOp(CopyROP);
  }
  
  if (!cellLabelRect.isEmpty()) {
    p.setBackgroundMode(TransparentMode);
    p.setPen(QToolTip::palette().active().text());
    p.fillRect(cellLabelRect,QToolTip::palette().active().background());
    p.drawRect(cellLabelRect);
    p.drawText(cellLabelRect,AlignCenter,cellLabelString);
  }
}
Esempio n. 9
0
void DeploymentNodeCanvas::draw(QPainter & p) {
  if (! visible()) return;
  p.setRenderHint(QPainter::Antialiasing, true);
  QRect r = rect();
  FILE * fp = svg();

  if (fp != 0)
    fputs("<g>\n", fp);

  const int three = (int) (3 * the_canvas()->zoom());  
  QColor bckgrnd = p.backgroundColor();
  const QPixmap * px = 
    ProfiledStereotypes::diagramPixmap(browser_node->get_data()->get_stereotype(), the_canvas()->zoom());
  
  if (px != 0) {
    p.setBackgroundMode(::Qt::TransparentMode);
    
    int lft = (px->width() < width()) ? r.x() + (width() - px->width())/2 : r.x();
    
    p.drawPixmap(lft, r.y(), *px);
    if (fp != 0)
      // pixmap not really exported in SVG
      fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
	      " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
	      svg_color(UmlBlack), lft, r.y(), px->width() - 1, px->height() - 1);
    
    r.setTop(r.top() + px->height());
    p.setFont(the_canvas()->get_font(UmlNormalBoldFont));
  }
  else {  
    UmlColor c;
    
    if (itscolor != UmlDefaultColor)
      c = itscolor;
    else {
      if (used_color == UmlDefaultColor)
	used_color = the_canvas()->browser_diagram()->get_color(UmlDeploymentNode);
      c = used_color;
    }
    
    QColor co = color(c);
    const int added = (int) (DEPLOYMENTNODE_CANVAS_ADDED * the_canvas()->zoom());
    Q3PointArray a(7);
    
    r.setTop(r.top() + added);
    r.setRight(r.right() - added);
    
    a.setPoint(0, r.left(), r.top());
    a.setPoint(1, r.left() + added, r.top() - added);
    a.setPoint(2, r.right() + added, r.top() - added);
    a.setPoint(3, r.right() + added, r.bottom() - added);
    a.setPoint(4, r.right(), r.bottom());
    a.setPoint(5, r.right(), r.top());
    a.setPoint(6, r.left(), r.top());
    
    if (c == UmlTransparent) {
      p.setBackgroundMode(::Qt::TransparentMode);
      p.setBackgroundColor(co);
      p.drawPolyline(a);
      
      if (fp != 0) {
	fprintf(fp, "\t<rect fill=\"none\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
		" x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
		r.x(), r.y(), r.width() - 1, r.height() - 1);
	draw_poly(fp, a, UmlTransparent);
      }
    }
    else {
      QBrush brsh = p.brush();
      
      p.setBackgroundMode(::Qt::OpaqueMode);
      p.fillRect(r, co);
      p.setBrush(co);
      p.drawPolygon(a, TRUE, 0, 6);
      p.setBrush(brsh);
      p.setBackgroundColor(co);
      
      if (fp != 0) {
	fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
		" x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
		svg_color(c),
		r.x(), r.y(), r.width() - 1, r.height() - 1);
	draw_poly(fp, a, c);
      }
    }
    
    p.drawRect(r);
    p.drawLine(r.topRight(), a.point(2));
    
    if (fp != 0)
      fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
	      " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
	      r.right(), r.top(), a.point(2).x(), a.point(2).y());
    
    QFontMetrics fm(the_canvas()->get_font(UmlNormalFont));
    const char * st = browser_node->get_data()->get_short_stereotype();
    QString s;
    
    r.setTop(r.top() + three);
    p.setFont(the_canvas()->get_font(UmlNormalFont));  
    
    if (st[0]) {
      s = QString("<<") + toUnicode(st) + ">>";
      p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, s);
      if (fp != 0)
	draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, s, p.font(), fp);
      r.setTop(r.top() + fm.height() + three);
    }
  }
    
  QFontMetrics fm(p.font());
  
  if (horiz) {
    QString s = iname + ":" + browser_node->get_name();
    
    p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, s);
    if (fp != 0)
      draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, s, p.font(), fp);
  }
  else {
    QString s = iname + ":";
    
    p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, s);
    if (fp != 0)
      draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, s, p.font(), fp);
    r.setTop(r.top() + fm.height() + three);
    s = browser_node->get_name();
    p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, s);
    if (fp != 0)
      draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, s, p.font(), fp);
  }
  
  p.setFont(the_canvas()->get_font(UmlNormalFont));  
  p.setBackgroundColor(bckgrnd);
  
  if (fp != 0)
    fputs("</g>\n", fp);
  
  if (selected())
    show_mark(p, rect());
}
Esempio n. 10
0
void ArtifactCanvas::draw(QPainter & p) {
  if (! visible()) return;
  p.setRenderHint(QPainter::Antialiasing, true);
  QRect r = rect();
  const BasicData * data = browser_node->get_data();
  FILE * fp = svg();

  if (fp != 0)
    fputs("<g>\n", fp);
  
  const QPixmap * px = 
    ProfiledStereotypes::diagramPixmap(browser_node->get_data()->get_stereotype(), the_canvas()->zoom());
  
  if (px != 0) {
    p.setBackgroundMode(::Qt::TransparentMode);
    
    int lft = (px->width() < width()) ? r.x() + (width() - px->width())/2 : r.x();
    
    p.drawPixmap(lft, r.y(), *px);
    if (fp != 0)
      // pixmap not really exported in SVG
      fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
	      " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
	      svg_color(UmlBlack), lft, r.y(), px->width() - 1, px->height() - 1);
    
    r.moveBy(0, px->height());
    p.setFont(the_canvas()->get_font(UmlNormalBoldFont));
    p.drawText(r, ::Qt::AlignHCenter, browser_node->get_name());
    
    if (fp != 0) {
      draw_text(r, ::Qt::AlignHCenter, browser_node->get_name(), p.font(), fp);
      fputs("</g>\n", fp);
    }
  }
  else {  
    QColor bckgrnd = p.backgroundColor();
    
    p.setBackgroundMode((used_color == UmlTransparent) ? ::Qt::TransparentMode : ::Qt::OpaqueMode);
    
    QColor co = color(used_color);
    
    p.setBackgroundColor(co);
    
    // <<artifact>>/stereotype on 2*font_height with the icon on the right
    // the icon height = 2*font_height
    // the icon width = 3*height/4
    // name on font_height+4 points
    const int four = (int) (4 * the_canvas()->zoom());
    QFontMetrics fm(the_canvas()->get_font(UmlNormalBoldFont));
    const int he = fm.height();
    if (used_color != UmlTransparent) {
      const int shadow = the_canvas()->shadow();
      
      if (shadow != 0) {
	r.setRight(r.right() - shadow);
	r.setBottom(r.bottom() - shadow);
	
	p.fillRect (r.right(), r.top() + shadow,
		    shadow, r.height() - 1,
		    ::Qt::darkGray);
	p.fillRect (r.left() + shadow, r.bottom(),
		    r.width() - 1, shadow,
		    ::Qt::darkGray);
	
	if (fp != 0) {
	  fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\""
		  " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
		  QColor(::Qt::darkGray).rgb()&0xffffff,
		  r.right(), r.top() + shadow, shadow - 1, r.height() - 1 - 1);
	  
	  fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\""
		  " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
		  QColor(::Qt::darkGray).rgb()&0xffffff,
		  r.left() + shadow, r.bottom(), r.width() - 1 - 1, shadow - 1);
	}
      }
    }
    
    QRect re = r;
    
    if (used_color != UmlTransparent) {
      p.fillRect(r, co);
      
      if (fp != 0)
	fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
		" x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
		svg_color(used_color), 
		r.x(), r.y(), r.width() - 1, r.height() - 1);
    }
    else if (fp != 0)
      fprintf(fp, "\t<rect fill=\"none\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
	      " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
	      r.x(), r.y(), r.width() - 1, r.height() - 1);
    
    p.drawRect(r);
    
    r.setHeight(he*2);
    p.setFont(the_canvas()->get_font(UmlNormalFont));
    if (data->get_stereotype()[0]) {
      p.drawText(r, ::Qt::AlignCenter,
		 QString("<<") + toUnicode(data->get_short_stereotype()) + ">>");
      if (fp != 0)
	draw_text(r, ::Qt::AlignCenter,
		  QString("<<") + toUnicode(data->get_short_stereotype()) + ">>",
		  p.font(), fp);
    }
    else {
      p.drawText(r, ::Qt::AlignCenter, "<<artifact>>");
      if (fp != 0)
	draw_text(r, ::Qt::AlignCenter, "<<artifact>>",
		  p.font(), fp);
    }
    
    r.moveBy(0, r.height());
    r.setHeight(he+four);
    p.setFont(the_canvas()->get_font(UmlNormalBoldFont));
    p.drawText(r, ::Qt::AlignCenter, browser_node->get_name());
    if (fp != 0)
      draw_text(r, ::Qt::AlignCenter, browser_node->get_name(),
		p.font(), fp);
    p.setFont(the_canvas()->get_font(UmlNormalFont));
    
    // draw icon
    re.setLeft(re.right() - 6*he/4 + four);
    re.setRight(re.right() - four);
    re.setTop(re.top() + four);
    re.setHeight(2*(he - four));
    
    Q3PointArray a(7);
    const int corner_size = re.width()/3;
    
    a.setPoint(0, re.left(), re.top());
    a.setPoint(1, re.right() - corner_size, re.top());
    a.setPoint(2, re.right() - corner_size, re.top() + corner_size);
    a.setPoint(3, re.right(), re.top() + corner_size);
    a.setPoint(4, re.right(), re.bottom());
    a.setPoint(5, re.left(), re.bottom());
    a.setPoint(6, re.left(), re.top());
    p.drawPolyline(a);
    //p.moveTo(re.right() - corner_size, re.top());
    //p.lineTo(re.right(), re.top() + corner_size);
    p.drawLine(re.right() - corner_size, re.top(), re.right(), re.top() + corner_size);
    
    if (fp != 0) {
      draw_poly(fp, a, UmlTransparent);
      fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
	      " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n"
	      "</g>\n",
	      re.right() - corner_size, re.top(), re.right(), re.top() + corner_size);
    }
    
    p.setBackgroundColor(bckgrnd);
  }
  
  if (selected())
    show_mark(p, rect());
}
Esempio n. 11
0
void FragmentCanvas::draw(QPainter & p) {
  if (! visible()) return;
  p.setRenderHint(QPainter::Antialiasing, true);
  QFontMetrics fm(the_canvas()->get_font(UmlNormalFont));
  int w = fm.width((name.isEmpty()) ? QString("X") : name);
  int h = fm.height() / 2;  
  QRect r = rect();
  QRect rname = r;
  
  rname.setWidth(w + h);
  rname.setHeight(fm.height() + h);
  
  int h1 = (fm.height() + h)/2;
  int x1 = rname.right() + h1;
  int y1 = rname.bottom() - h1;
  
  QColor bckgrnd = p.backgroundColor();

  p.setBackgroundMode((used_color == UmlTransparent) ? ::Qt::TransparentMode : ::Qt::OpaqueMode);

  QColor co = color(used_color);
  FILE * fp = svg();

  if (fp != 0)
    fputs("<g>\n", fp);
  
  p.setBackgroundColor(co);
  p.setFont(the_canvas()->get_font(UmlNormalFont));
  
  if (used_color != UmlTransparent)
    p.fillRect(r, co);
  else if (!name.isEmpty()) {
    Q3PointArray a(6);
    QBrush brsh = p.brush();
    
    a.setPoint(0, rname.left(), rname.top());
    a.setPoint(1, x1, rname.top());
    a.setPoint(2, x1, y1);
    a.setPoint(3, rname.right(), rname.bottom());
    a.setPoint(4, rname.left(), rname.bottom());
    a.setPoint(5, rname.left(), rname.top());

    p.setBrush(UmlWhiteColor);
    p.drawPolygon(a, TRUE, 0, 5);
    p.setBrush(brsh);
    
    if (fp != 0)
      draw_poly(fp, a, UmlWhite);
  }

  if (fp != 0)
    fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
	    " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
	    svg_color(used_color), 
	    r.x(), r.y(), r.width() - 1, r.height() - 1);
  
  p.drawRect(r);
  
  if (refer != 0) {
    QString s = refer->get_name() + form;
    QRect r2(r.left(), r.top() + 2*fm.height(),
	     r.width(), fm.height());

    p.drawText(r2, ::Qt::AlignCenter, s);
    
    if (fp != 0)
      draw_text(r2, ::Qt::AlignCenter, s,
		p.font(), fp);
  }
  
  if (!name.isEmpty())
    p.drawText(rname, ::Qt::AlignCenter, name);
  if (fp != 0)
    draw_text(rname, ::Qt::AlignCenter, name,
	      p.font(), fp);
  
  p.drawLine(rname.left(), rname.bottom(), rname.right(), rname.bottom());
  p.drawLine(rname.right(), rname.bottom(), x1, y1);
  p.drawLine(x1, y1, x1, rname.top());

  if (fp != 0) {
    fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
	    " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
	    rname.left(), rname.bottom(), rname.right(), rname.bottom());
    fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
	    " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
	    rname.right(), rname.bottom(), x1, y1);
    fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
	    " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
	    x1, y1, x1, rname.top());
    fputs("</g>\n", fp);
  }
	       
  p.setBackgroundColor(bckgrnd);
  
  if (selected())
    show_mark(p, r);
}
Esempio n. 12
0
void ActivityActionCanvas::draw(QPainter & p) {
  if (! visible()) return;
  
  QRect r = rect();
  QBrush brsh = p.brush();
  QColor bckgrnd = p.backgroundColor();
  
  p.setBackgroundMode((used_color == UmlTransparent)
		      ? ::Qt::TransparentMode
		      : ::Qt::OpaqueMode);

  QColor co = color(used_color);
  
  p.setBackgroundColor(co);
  
  const ActivityActionData * data =
    (ActivityActionData *) browser_node->get_data();
  const int shadow = the_canvas()->shadow();
  int margin;
  FILE * fp = svg();

  if (fp != 0)
    fputs("<g>\n", fp);  
  
  switch (data->get_action_kind()) {
  case UmlAcceptEventAction:
    if (((AcceptEventAction *) data->get_action())->timeevent) {
      // don't draw shadow
      margin = (int) (21 * the_canvas()->zoom());
      
      int t = (r.y() + r.bottom() - margin)/2;
      
      p.setPen(::Qt::SolidLine);
      p.setBackgroundMode(::Qt::TransparentMode);
      p.drawLine(r.right() - margin, t, r.right() - 1, t);
      p.lineTo(r.right() - margin - 1, t + margin);
      p.lineTo(r.right() - 1, t + margin);
      p.lineTo(r.right() - margin - 1, t);

      if (fp != 0) {
	fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
		" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
		r.right() - margin, t, r.right() - 1, t);
	fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
		" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
		r.right() - 1, t, r.right() - margin - 1, t + margin);
	fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
		" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
		r.right() - margin - 1, t + margin, r.right() - 1, t + margin);
	fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
		" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
		r.right() - 1, t + margin, r.right() - margin - 1, t);
      }

      r.setWidth(r.width() - margin - 1);
      margin = (int) (3 * the_canvas()->zoom());
    }
    else {
      if ((used_color != UmlTransparent) && (shadow != 0)) {
	r.setRight(r.right() - shadow);
	r.setBottom(r.bottom() - shadow);
      }
      
      margin = ((r.height() < r.width()) ? r.height() : r.width()) / 4;
      
      QPointArray a(6);
      
      a.setPoint(0, r.x(), r.y());
      a.setPoint(1, r.right(), r.y());
      a.setPoint(2, r.right(), r.bottom());
      a.setPoint(3, r.x(), r.bottom());
      a.setPoint(4, r.x() + margin, (r.y() + r.bottom())/2);
      a.setPoint(5, r.x(), r.y());
  
      if (used_color == UmlTransparent) {
	p.drawPolyline(a);

	if (fp != 0)
	  draw_poly(fp, a, UmlTransparent);
      }
      else {
	if (shadow != 0) {
	  QPointArray b(6);
	  
	  b.setPoint(0, r.x() + shadow, r.y() + shadow);
	  b.setPoint(1, r.right() + shadow, r.y() + shadow);
	  b.setPoint(2, r.right() + shadow, r.bottom() + shadow);
	  b.setPoint(3, r.x() + shadow, r.bottom() + shadow);
	  b.setPoint(4, r.x() + margin + shadow, (r.y() + r.bottom())/2 + shadow);
	  b.setPoint(5, r.x() + shadow, r.y() + shadow);
	  p.setBrush(::Qt::darkGray);
	  p.setPen(::Qt::NoPen);
	  p.drawPolygon(b, TRUE, 0, 5);
	  p.setPen(::Qt::SolidLine);

	  if (fp != 0)
	    draw_shadow(fp, b);
	}
	
	p.setBrush(co);
	p.drawPolygon(a, TRUE, 0, 5);

	if (fp != 0)
	  draw_poly(fp, a, used_color);
      }
      r.setLeft(r.left() + margin);
      margin = (int) (6 * the_canvas()->zoom());
    }
    break;
  case UmlSendSignalAction:
  case UmlBroadcastSignalAction:
    {
      if ((used_color != UmlTransparent) && (shadow != 0)) {
	r.setRight(r.right() - shadow);
	r.setBottom(r.bottom() - shadow);
      }
      
      margin = ((r.height() < r.width()) ? r.height() : r.width()) / 4;
      
      QPointArray a(6);
      
      a.setPoint(0, r.x(), r.y());
      a.setPoint(1, r.right() - margin, r.y());
      a.setPoint(2, r.right(), (r.y() + r.bottom())/2);
      a.setPoint(3, r.right() - margin, r.bottom());
      a.setPoint(4, r.x(), r.bottom());
      a.setPoint(5, r.x(), r.y());
  
      if (used_color == UmlTransparent) {
	p.drawPolyline(a);
	if (fp != 0)
	  draw_poly(fp, a, UmlTransparent);
      }
      else {
	if (shadow != 0) {
	  QPointArray b(6);
	  
	  b.setPoint(0, r.x() + shadow, r.y() + shadow);
	  b.setPoint(1, r.right() - margin + shadow, r.y() + shadow);
	  b.setPoint(2, r.right() + shadow, (r.y() + r.bottom())/2 + shadow);
	  b.setPoint(3, r.right() - margin + shadow, r.bottom() + shadow);
	  b.setPoint(4, r.x() + shadow, r.bottom() + shadow);
	  b.setPoint(5, r.x() + shadow, r.y() + shadow);
	  p.setBrush(::Qt::darkGray);
	  p.setPen(::Qt::NoPen);
	  p.drawPolygon(b, TRUE, 0, 5);
	  p.setPen(::Qt::SolidLine);

	  if (fp != 0)
	    draw_shadow(fp, b);
	}
      
	p.setBrush(co);
	p.drawPolygon(a, TRUE, 0, 5);

	if (fp != 0)
	  draw_poly(fp, a, used_color);
      }
      r.setWidth(r.width() - margin);
      margin = (int) (6 * the_canvas()->zoom());
    }
    break;
  default:      
    margin = (int) (9 * the_canvas()->zoom());
      
    if ((used_color != UmlTransparent) && (shadow != 0)) {
      r.setRight(r.right() - shadow);
      r.setBottom(r.bottom() - shadow);
      p.setPen(::Qt::NoPen);
      p.setBrush(::Qt::darkGray);
      p.drawRoundRect(r.left() + shadow, r.top() + shadow, r.width(), r.height());
      
      if (fp != 0)
	fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\""
		" x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"10\" />\n",
		::Qt::darkGray.rgb()&0xffffff,
		r.left() + shadow, r.top() + shadow, r.width() - 1, r.height() - 1);

      p.setPen(::Qt::SolidLine);
    }
    
    p.setBrush(co);
    p.drawRoundRect(r);

    if (fp != 0)
      fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-opacity=\"1\""
	      " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" rx=\"10\" />\n",
	      svg_color(used_color),
	      r.left(), r.top(), r.width() - 1, r.height() - 1);
    
    if (data->get_action_kind() == UmlCallBehaviorAction) {
      BrowserNode * behavior =
	((CallBehaviorAction *) data->get_action())->behavior;
      
      if ((behavior != 0) && (behavior->get_type() == UmlActivity)) {
	int l = (int) (6 * the_canvas()->zoom());
	int lx = r.right() - margin - l;
	int ty = r.bottom() - margin - l;
	int mx = lx + l;
	int my = ty + l;
	int rx = mx + l;
	int by = my + l;
	
	p.drawLine(lx, my, rx, my);
	p.drawLine(mx, ty, mx, by);
	p.drawLine(lx, my, lx, by);
	p.drawLine(rx, my, rx, by);

	if (fp != 0) {
	  fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
		  " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
		  lx, my, rx, my);
	  fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
		  " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
		  mx, ty, mx, by);
	  fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
		  " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
		  lx, my, lx, by);
	  fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
		  " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
		  rx, my, rx, by);
	}
      }
    }
    break;
  }
  
  p.setFont(the_canvas()->get_font(UmlNormalFont));
  p.drawText(r.x() + margin,
	     r.y() + margin,
	     r.width() - margin - margin,
	     r.height() - margin - margin,
	     align, s);
  
  if (fp != 0) {
    fputs("</g>\n", fp);
    draw_text(r.x() + margin,
	      r.y() + margin,
	      r.width() - margin - margin,
	      r.height() - margin - margin,
	      align, s, p.font(), fp);
  }
  
  p.setBackgroundColor(bckgrnd);
  p.setBrush(brsh);
  
  if (selected())
    show_mark(p, rect());
}
Esempio n. 13
0
void NoteCanvas::draw(QPainter & p)
{
    if (! visible()) return;

    p.setRenderHint(QPainter::Antialiasing, true);
    QRect r = rect();
    QBrush brsh = p.brush();
    QColor bckgrnd = p.backgroundColor();
    QPen fgcolor = p.pen();
    Q3PointArray a(7);

    used_color = (itscolor == UmlDefaultColor)
                 ? the_canvas()->browser_diagram()->get_color(UmlNote)
                 : itscolor;

    QColor co = color(used_color);

    const int corner_size = (int)(NOTE_MARGIN * the_canvas()->zoom());

    a.setPoint(0, r.left(), r.top());
    a.setPoint(1, r.right() - corner_size, r.top());
    a.setPoint(2, r.right() - corner_size, r.top() + corner_size);
    a.setPoint(3, r.right(), r.top() + corner_size);
    a.setPoint(4, r.right(), r.bottom());
    a.setPoint(5, r.left(), r.bottom());
    a.setPoint(6, r.left(), r.top());

    FILE * fp = svg();

    if (fp != 0)
        fputs("<g>\n", fp);

    if (used_color == UmlTransparent) {
        p.setBackgroundMode(::Qt::TransparentMode);
        p.setBackgroundColor(co);
        p.drawPolyline(a);

        if (fp != 0)
            draw_poly(fp, a, UmlTransparent);
    }
    else {
        p.setBackgroundMode(::Qt::OpaqueMode);
        p.setBrush(co);
        p.drawPolygon(a, TRUE, 0, 6);
        p.setBrush(brsh);
        p.setBackgroundColor(co);

        if (fp != 0)
            draw_poly(fp, a, used_color);
    }

    p.drawLine(r.right() - corner_size, r.top(),
               r.right(), r.top() + corner_size);

    if (fp != 0)
        fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
                " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
                r.right() - corner_size, r.top(), r.right(), r.top() + corner_size);

    p.setFont(the_canvas()->get_font(itsfont));

    if (fg_c != UmlTransparent)
        p.setPen(color(fg_c));

    p.drawText(r.left() + corner_size, r.top() + corner_size,
               r.width() - 2 * corner_size, r.height() - 2 * corner_size,
               ::Qt::AlignLeft + ::Qt::AlignTop + ::Qt::TextWordWrap,
               note);

    if (fp != 0) {
        draw_text(r.left() + corner_size, r.top() + corner_size,
                  r.width() - 2 * corner_size, r.height() - 2 * corner_size,
                  ::Qt::AlignLeft + ::Qt::AlignTop + ::Qt::TextWordWrap,
                  note, p.font(), fp, fg_c);
        fputs("</g>\n", fp);
    }

    p.setFont(the_canvas()->get_font(UmlNormalFont));
    p.setBackgroundColor(bckgrnd);
    p.setPen(fgcolor);

    if (selected())
        show_mark(p, r);
}
Esempio n. 14
0
void PackageCanvas::draw(QPainter & p) {
  if (! visible()) return;
  p.setRenderHint(QPainter::Antialiasing, true);
  QRect r = rect();
  const BasicData * data = browser_node->get_data();  
  const QPixmap * px = 
    ProfiledStereotypes::diagramPixmap(data->get_stereotype(),
				       the_canvas()->zoom());
  FILE * fp = svg();
  
  if (fp != 0)
    fputs("<g>\n", fp);

  if (px != 0) {
    p.setBackgroundMode(::Qt::TransparentMode);
    
    
    int lft = (px->width() < width()) ? r.x() + (width() - px->width())/2 : r.x();
    
    p.drawPixmap(lft, r.y(), *px);
    if (fp != 0)
      // pixmap not really exported in SVG
      fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
	      " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
	      svg_color(UmlBlack), lft, r.y(), px->width() - 1, px->height() - 1);
    
    r.moveBy(0, px->height());
    p.setFont(the_canvas()->get_font(UmlNormalBoldFont));
    p.drawText(r, ::Qt::AlignHCenter, browser_node->get_name());
    
    // pixmap not yet exported in SVG
    if (fp != 0)
      draw_text(r, ::Qt::AlignHCenter, browser_node->get_name(),
		p.font(), fp);
    p.setFont(the_canvas()->get_font(UmlNormalFont));
  }
  else {
    QColor bckgrnd = p.backgroundColor();
    QColor co = color(used_color);
    
    p.setBackgroundMode((used_color == UmlTransparent) ? ::Qt::TransparentMode : ::Qt::OpaqueMode);
    p.setBackgroundColor(co);
    p.setFont(the_canvas()->get_font(UmlNormalFont));
    
    QFontMetrics fm(the_canvas()->get_font(UmlNormalFont));
    const int four = (int) (4 * the_canvas()->zoom());
    const int he = fm.height();
    const int shadow = the_canvas()->shadow();
    if ((used_color != UmlTransparent) && (shadow != 0)) {
      r.setRight(r.right() - shadow);
      r.setBottom(r.bottom() - shadow);
    }
    
    r.setWidth(r.width() * 2 / 5);
    r.setHeight(he + four);
    if (used_color != UmlTransparent)
      p.fillRect(r, co);
    
    if (fp != 0)
      fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
	      " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
	      svg_color(used_color), 
	      r.x(), r.y(), r.width() - 1, r.height() - 1);
    
    p.drawRect(r);
    
    if ((used_color != UmlTransparent) && (shadow != 0)) {
      p.fillRect (r.right(), r.top() + shadow,
		  shadow, r.height() - 1 - shadow,
		  ::Qt::darkGray);
      
      if (fp != 0)
	fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\""
		" x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
		QColor(::Qt::darkGray).rgb()&0xffffff,
		r.right(), r.top() + shadow, shadow - 1, r.height() - 1 - shadow - 1);
    }
    
    const char * name = browser_node->get_name();
    
    if (in_tab) {
      p.drawText(r, ::Qt::AlignCenter, name);
      if (fp != 0)
	draw_text(r, ::Qt::AlignCenter, name,
		  p.font(), fp);
    }
    
    r = rect();
    if ((used_color != UmlTransparent) && (shadow != 0)) {
      r.setRight(r.right() - shadow);
      r.setBottom(r.bottom() - shadow);
    }
    
    r.setTop(r.top() + he + four - 1);
    if (used_color != UmlTransparent)
      p.fillRect(r, co);
    
    if (fp != 0)
      fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
	      " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
	      svg_color(used_color),
	      r.x(), r.y(), r.width() - 1, r.height() - 1);
    
    p.drawRect(r);
    
    if ((used_color != UmlTransparent) && (shadow != 0)) {
      p.fillRect (r.right(), r.top() + shadow,
		  shadow, r.height() - 1,
		  ::Qt::darkGray);
      p.fillRect (r.left() + shadow, r.bottom(),
		  r.width() - 1, shadow,
		  ::Qt::darkGray);
      
      if (fp != 0) {
	fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\""
		" x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
		QColor(::Qt::darkGray).rgb()&0xffffff,
		r.right(), r.top() + shadow, shadow - 1, r.height() - 1 - 1);
	
	fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\""
		" x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
		QColor(::Qt::darkGray).rgb()&0xffffff,
		r.left() + shadow, r.bottom(), r.width() - 1 - 1, shadow - 1);
      }
    }
    
    const int three = (int) (3 * the_canvas()->zoom());
    
    r.setTop(r.top() + three);
    
    if (! in_tab) {
      p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, name);
      if (fp != 0)
	draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, name,
		  p.font(), fp);
      r.setTop(r.top() + he + three);
    }
    
    if (data->get_stereotype()[0]) {
      p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, 
		 QString("<<") + toUnicode(data->get_short_stereotype()) + ">>");
      if (fp != 0)
	draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, 
		  QString("<<") + toUnicode(data->get_short_stereotype()) + ">>",
		  p.font(), fp);
      r.setTop(r.top() + he + three);
    }
    
    if (full_name != name) {
      p.setFont(the_canvas()->get_font(UmlNormalItalicFont));
      p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, full_name);
      if (fp != 0)
	draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, full_name,
		  p.font(), fp);
      p.setFont(the_canvas()->get_font(UmlNormalFont));
    }
  
    p.setBackgroundColor(bckgrnd);
  }
  
  if (fp != 0)
    fputs("</g>\n", fp);
  
  if (selected())
    show_mark(p, rect());
}
Esempio n. 15
0
void StateActionCanvas::draw(QPainter & p) {
  if (! visible()) return;
  
  QRect r = rect();
  const BasicData * data = browser_node->get_data();
  double zoom = the_canvas()->zoom();
  const QPixmap * px = 
    ProfiledStereotypes::diagramPixmap(data->get_stereotype(),
				       the_canvas()->zoom());
  FILE * fp = svg();

  if (fp != 0)
    fputs("<g>\n", fp);
    
  if (px != 0) {
    p.setBackgroundMode(::Qt::TransparentMode);
    
    int lft = (px->width() < width()) ? r.x() + (width() - px->width())/2 : r.x();
    
    p.drawPixmap(lft, r.y(), *px);
    if (fp != 0)
      // pixmap not really exported in SVG
      fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
	      " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
	      svg_color(UmlBlack), lft, r.y(), px->width() - 1, px->height() - 1);
  }
  else {
    QColor bckgrnd = p.backgroundColor();
    int mw = min_width;
    QBrush brsh = p.brush();
    QFontMetrics fm(the_canvas()->get_font(UmlNormalFont));
    const char * st = data->get_short_stereotype();
    const int shadow = the_canvas()->shadow();
    
    QColor co = color(used_color);
    
    p.setBackgroundMode((used_color == UmlTransparent)
			? ::Qt::TransparentMode
			: ::Qt::OpaqueMode);

    p.setBackgroundColor(co);
    
    p.setFont(the_canvas()->get_font(UmlNormalFont));
    
    if (!strcmp(st, "send-signal")) {
      QPointArray a(6);
      
      if ((used_color != UmlTransparent) && (shadow != 0)) {
	r.setRight(r.right() - shadow);
	r.setBottom(r.bottom() - shadow);
      }
      
      const int hh = r.height()/2;
      
      a.setPoint(0, r.left(), r.top());
      a.setPoint(1, r.right() - hh, r.top());
      a.setPoint(2, r.right(), r.top() + hh);
      a.setPoint(3, r.right() - hh, r.bottom());
      a.setPoint(4, r.left(), r.bottom());
      a.setPoint(5, r.left(), r.top());
      
      if (used_color == UmlTransparent) {
	p.drawPolyline(a);
	if (fp != 0)
	  draw_poly(fp, a, UmlTransparent);
      }
      else {
	if (shadow != 0) {
	  QPointArray b(6);
	  
	  b.setPoint(0, r.left() + shadow, r.top() + shadow);
	  b.setPoint(1, r.right() - hh + shadow, r.top() + shadow);
	  b.setPoint(2, r.right() + shadow, r.top() + hh + shadow);
	  b.setPoint(3, r.right() - hh + shadow, r.bottom() + shadow);
	  b.setPoint(4, r.left() + shadow, r.bottom() + shadow);
	  b.setPoint(5, r.left() + shadow, r.top() + shadow);
	  p.setBrush(::Qt::darkGray);
	  p.setPen(::Qt::NoPen);
	  p.drawPolygon(b, TRUE, 0, 5);
	  p.setPen(::Qt::SolidLine);
	  
	  if (fp != 0)
	    draw_shadow(fp, b);
	}
	
	p.setBrush(co);
	p.drawPolygon(a, TRUE, 0, 5);
	
	if (fp != 0)
	  draw_poly(fp, a, used_color);
      }
      
      r.setRight(r.right() - hh);
      mw -= hh;
    }
    else if (!strcmp(st, "receive-signal")) {
      QPointArray a(6);
      
      if ((used_color != UmlTransparent) && (shadow != 0)) {
	r.setRight(r.right() - shadow);
	r.setBottom(r.bottom() - shadow);
      }
      
      const int hh = r.height()/2;
      
      a.setPoint(0, r.left(), r.top());
      a.setPoint(1, r.right(), r.top());
      a.setPoint(2, r.right() - hh, r.top() + hh);
      a.setPoint(3, r.right(), r.bottom());
      a.setPoint(4, r.left(), r.bottom());
      a.setPoint(5, r.left(), r.top());
      
      if (used_color == UmlTransparent) {
	p.drawPolyline(a);
	
	if (fp != 0)
	  draw_poly(fp, a, UmlTransparent);
      }
      else {
	if (shadow != 0) {
	  QPointArray b(6);
	  
	  b.setPoint(0, r.left() + shadow, r.top() + shadow);
	  b.setPoint(1, r.right() + shadow, r.top() + shadow);
	  b.setPoint(2, r.right() - hh + shadow, r.top() + hh + shadow);
	  b.setPoint(3, r.right() + shadow, r.bottom() + shadow);
	  b.setPoint(4, r.left() + shadow, r.bottom() + shadow);
	  b.setPoint(5, r.left() + shadow, r.top() + shadow);
	  p.setBrush(::Qt::darkGray);
	  p.setPen(::Qt::NoPen);
	  p.drawPolygon(b, TRUE, 0, 5);
	  p.setPen(::Qt::SolidLine);
	  
	  if (fp != 0)
	    draw_shadow(fp, b);
	}
	
	p.setBrush(co);
	p.drawPolygon(a, TRUE, 0, 5);
	
	if (fp != 0)
	  draw_poly(fp, a, used_color);
      }
      
      r.setRight(r.right() - hh);
      mw -= hh;
    }
    else {
      if (used_color != UmlTransparent) {
	if (shadow != 0) {
	  r.setRight(r.right() - shadow);
	  r.setBottom(r.bottom() - shadow);
	  
	  p.fillRect (r.right(), r.top() + shadow,
		      shadow, r.height() - 1,
		      ::Qt::darkGray);
	  p.fillRect (r.left() + shadow, r.bottom(),
		      r.width() - 1, shadow,
		      ::Qt::darkGray);
	  
	  if (fp != 0) {
	    fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\""
		    " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
		    ::Qt::darkGray.rgb()&0xffffff,
		    r.right(), r.top() + shadow, shadow - 1, r.height() - 1 - 1);
	    
	    fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\""
		    " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
		    ::Qt::darkGray.rgb()&0xffffff,
		    r.left() + shadow, r.bottom(), r.width() - 1 - 1, shadow - 1);
	  }
	}
      }
      
      p.setBrush(co);
      p.drawRect(r);
      
      if (fp != 0)
	fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
		" x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
		svg_color(used_color), 
		r.x(), r.y(), r.width() - 1, r.height() - 1);
      
      if (st[0] != 0) {
	r.setTop(r.top() + fm.height() / 2);
	p.drawText(r, ::Qt::AlignHCenter, QString("<<") + toUnicode(st) + ">>");
	if (fp != 0)
	  draw_text(r, ::Qt::AlignHCenter, QString("<<") + toUnicode(st) + ">>",
		    p.font(), fp);
	r.setTop(r.top() + 3*fm.height()/2);
      }
    }
    
    r.setLeft(r.left() + (r.width() + (int) (8 * zoom) - mw)/2 + 1);
    p.drawText(r, ::Qt::AlignVCenter, s);
    if (fp != 0) {
      draw_text(r, ::Qt::AlignVCenter, s,
		p.font(), fp);
      fputs("</g>\n", fp);
    }
      
    p.setBrush(brsh);
    p.setBackgroundColor(bckgrnd);
  }
  
  if (selected())
    show_mark(p, rect());
}
Esempio n. 16
0
void OdClassInstCanvas::draw(QPainter & p) {
  if (visible()) {
    QRect r = rect();
    QFontMetrics fm(the_canvas()->get_font(UmlNormalFont));
    QColor bckgrnd = p.backgroundColor();
    double zoom = the_canvas()->zoom();

    p.setBackgroundMode((used_color == UmlTransparent) ? ::Qt::TransparentMode : ::Qt::OpaqueMode);
    
    QColor co = color(used_color);
    FILE * fp = svg();

    if (fp != 0)
      fputs("<g>\n", fp);
    
    if (used_color != UmlTransparent) {
      const int shadow = the_canvas()->shadow();
      
      if (shadow != 0) {
	r.setRight(r.right() - shadow);
	r.setBottom(r.bottom() - shadow);
	
	p.fillRect (r.right(), r.top() + shadow,
		    shadow, r.height() - 1,
		    ::Qt::darkGray);
	p.fillRect (r.left() + shadow, r.bottom(),
		    r.width() - 1, shadow,
		    ::Qt::darkGray);

	if (fp != 0) {
	  fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\""
		  " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
		  ::Qt::darkGray.rgb()&0xffffff,
		  r.right(), r.top() + shadow, shadow - 1, r.height() - 1 - 1);

	  fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\""
		  " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
		  ::Qt::darkGray.rgb()&0xffffff,
		  r.left() + shadow, r.bottom(), r.width() - 1 - 1, shadow - 1);
	}
      }
    }
    
    p.setBackgroundColor(co);
    
    if (used_color != UmlTransparent)
      p.fillRect(r, co);

    if (fp != 0)
      fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
	      " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
	      svg_color(used_color), 
	      r.x(), r.y(), r.width() - 1, r.height() - 1);

    p.drawRect(r);
    
    BrowserClass * cl = 
      ((ClassInstanceData *) browser_node->get_data())->get_class();
	  
    if (((ClassData *) cl->get_data())->get_is_active()) {
      const int eight = (int) (8 * zoom);
      
      r.setLeft(r.left() + eight);
      r.setRight(r.right() - eight);
      
      p.drawLine(r.topLeft(), r.bottomLeft());
      p.drawLine(r.topRight(), r.bottomRight());

      if (fp != 0)
	fprintf(fp,
		"\t<line stroke=\"black\" stroke-opacity=\"1\""
		" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n"
		"\t<line stroke=\"black\" stroke-opacity=\"1\""
		" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
		r.left(), r.top(), r.left(), r.bottom(),
		r.right(), r.top(), r.right(), r.bottom());
    }
    
    const int two = (int) (2 * zoom);
    int he = fm.height() + two;
    
    p.setFont(the_canvas()->get_font(UmlNormalUnderlinedFont));

    r.setTop(r.top() + two);
    if (horiz) {
      p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop,
		 full_name());
      if (fp != 0)
	draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop,
		  full_name(),
		  p.font(), fp);
    }
    else {
      p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop,
		 get_name() + ":");
      if (fp != 0)
	draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop,
		  get_name() + ":",
		  p.font(), fp);
      r.setTop(r.top() + fm.height());
      
      p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop,
		 cl->contextual_name(used_show_context_mode));
      if (fp != 0)
	draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop,
		  cl->contextual_name(used_show_context_mode),
		  p.font(), fp);
    }
    
    p.setFont(the_canvas()->get_font(UmlNormalFont));

    const QValueList<SlotAttr> & attributes = 
      ((ClassInstanceData *) browser_node->get_data())->get_attributes();

    if (!attributes.isEmpty()) {
      r.setTop(r.top() + he + two);
      p.drawLine(r.topLeft(), r.topRight());
      if (fp != 0)
	fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
		" x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
		r.left(), r.top(), r.right(), r.top());

      r.setTop(r.top() + two);
      r.setLeft(r.left() + (int) (4 * zoom));
      
      QValueList<SlotAttr>::ConstIterator it = attributes.begin();
      QString egal = " = ";

      do {
	QString s = (*it).att->get_name() + egal + (*it).value;

	p.drawText(r, ::Qt::AlignTop, s);
	if (fp != 0)
	  draw_text(r, ::Qt::AlignTop, s,
		    p.font(), fp);
	r.setTop(r.top() + he);
	++it;
      } while (it != attributes.end());
    }

    if (fp != 0)
      fputs("</g>\n", fp);
        
    if (selected())
      show_mark(p, rect());
  }
}
Esempio n. 17
0
// Repaint the state of a window. Active or inactive windows differ
// only in the look of the titlebar. If only_label is true then only
// the label string is repainted. This is used for the titlebar
// animation with animate = TRUE.
void KMDITitleLabel::paintState(bool only_label, bool colors_have_changed,
  bool animate){
  KMDIWindow *w;
  QRect title_rect=QRect(0,0,width(),height());
  QRect r = title_rect;
  bool double_buffering = false;
  QPixmap* buffer = 0;
  int x;

//  Nice, but this would make the class KWM dependant.
//  if (r.width() <= 0 || r.height() <= 0
//      || getDecoration()!=KWM::normalDecoration)
//    return;
//  int x;

  w=(KMDIWindow *)(parent()->parent()->parent());
  is_active=w->IsSelected();

  TITLEBAR_LOOK look = options.TitlebarLook;

  if (look == H_SHADED || look == V_SHADED){
    // the new("horizontal") horizontal (and vertical) shading code
    if (colors_have_changed){
      aShadepm.resize(0,0);
      iaShadepm.resize(0,0);
    }

    // the user selected shading. Do a plain titlebar anyway if the
    // shading would be senseless (higher performance and less memory
    // consumption)
    if (is_active){
      if ( kapp->activeTitleColor
          ==  activeTitleBlend)
	look = PLAIN;
    }
    else {
      if ( kapp->inactiveTitleColor
         ==  inactiveTitleBlend)
	look = PLAIN;
    }
  }

  // the following is the old/handmade vertical shading code

//   if (options.TitlebarLook == SHADED){
//     if (is_active && shaded_pm_active && shaded_pm_active_color != myapp->activeTitleColor){
//       delete shaded_pm_active;
//       shaded_pm_active = 0;
//     }
//     if (is_active && shaded_pm_inactive && shaded_pm_inactive_color != myapp->inactiveTitleColor){
//       delete shaded_pm_inactive;
//       shaded_pm_inactive = 0;
//     }
//   }

//   if (options.TitlebarLook == SHADED
//       &&
//       (is_active && (!shaded_pm_active)
//        || (!is_active && !shaded_pm_inactive))
//       ){
//     int i,y;
//     QImage image (50, TITLEBAR_HEIGHT, 8, TITLEBAR_HEIGHT);
//     QColor col = is_active ? myapp->activeTitleColor : myapp->inactiveTitleColor;
//     for ( i=0; i<TITLEBAR_HEIGHT; i++ ){
//       image.setColor( i, col.light(100+(i-TITLEBAR_HEIGHT/2)*3).rgb());
//     }
//     for (y=0; y<TITLEBAR_HEIGHT; y++ ) {
//       uchar *pix = image.scanLine(y);
//       for (x=0; x<50; x++)
//         *pix++ = is_active ? TITLEBAR_HEIGHT-1-y : y;
//     }
//     if (is_active){
//       shaded_pm_active = new("QPixmap") QPixmap;
//       *shaded_pm_active = image;
//       shaded_pm_active_color = myapp->activeTitleColor;
//     }
//     else{
//       shaded_pm_inactive = new("QPixmap") QPixmap;
//       *shaded_pm_inactive = image;
//       shaded_pm_inactive_color = myapp->inactiveTitleColor;
//     }
//   }

  QPainter p;

  if (only_label && animate){
    double_buffering = (look == H_SHADED || look == V_SHADED || look == PIXMAP);
    titlestring_offset += titlestring_offset_delta;
    if (!double_buffering){
      if (titlestring_offset_delta > 0)
	bitBlt(this,
	       r.x()+titlestring_offset_delta, r.y(),
	       this,
	       r.x(), r.y(),
	       r.width()-titlestring_offset_delta, r.height());
      else
	bitBlt(this,
	       r.x(), r.y(),
	       this,
	       r.x()-titlestring_offset_delta, r.y(),
	       r.width()+titlestring_offset_delta, r.height());
    }
  }

  if (!double_buffering)
    p.begin( this );
  else {
    // enable double buffering to avoid flickering with horizontal shading
    buffer = new("QPixmap") QPixmap(r.width(), r.height());
    p.begin(buffer);
    r.setRect(0,0,r.width(),r.height());
  }

  QPixmap *pm;
  p.setClipRect(r);
  p.setClipping(True);

  // old handmade vertical shading code

//   if (options.TitlebarLook == SHADED || options.TitlebarLook == PIXMAP){

//     if (options.TitlebarLook == SHADED)
//       pm = is_active ? shaded_pm_active : shaded_pm_inactive;
//     else

  if (look == PIXMAP){
      pm = is_active ? options.titlebarPixmapActive: options.titlebarPixmapInactive;
      for (x = r.x(); x < r.x() + r.width(); x+=pm->width())
	p.drawPixmap(x, r.y(), *pm);
  }
  else if (look == H_SHADED || look == V_SHADED ){
    // the new("horizontal") horizontal shading code
    QPixmap* pm = 0;
    if (is_active){
      if (aShadepm.size() != r.size()){
	aShadepm.resize(r.width(), r.height());
	kwm_gradientFill( aShadepm, 
          kapp->activeTitleColor,
          activeTitleBlend, look == V_SHADED );
	//aShadepm.gradientFill( activeTitleColor, activeTitleBlend, look == V_SHADED );
      }
      pm = &aShadepm;
    }
    else {
      if (iaShadepm.size() != r.size()){
	iaShadepm.resize(r.width(), r.height());
	kwm_gradientFill( iaShadepm,
          kapp->inactiveTitleColor,
          inactiveTitleBlend, look == V_SHADED ); 
//	iaShadepm.gradientFill(inactiveTitleColor, inactiveTitleBlend,
//        look == V_SHADED );
       }
       pm = &iaShadepm;
    }

    p.drawPixmap( r.x(), r.y(), *pm );
  }
  else { // TitlebarLook == TITLEBAR_PLAIN
    p.setBackgroundColor( is_active ? 
      kapp->activeTitleColor : 
      kapp->inactiveTitleColor);
    if (only_label && !double_buffering && animate){
       p.eraseRect(QRect(r.x(), r.y(), TITLE_ANIMATION_STEP+1, r.height()));
       p.eraseRect(QRect(r.x()+r.width()-TITLE_ANIMATION_STEP-1, r.y(),
 			TITLE_ANIMATION_STEP+1, r.height()));
    }
    else {
      p.eraseRect(r);
    }
  }
  p.setClipping(False);

  if (is_active)
    qDrawShadePanel( &p, r, colorGroup(), true );

  p.setPen(is_active ? 
    kapp->activeTextColor : 
    kapp->inactiveTextColor);

  QFont fnt = kapp->generalFont;
  fnt.setPointSize(12);
  fnt.setBold(true);
  p.setFont(fnt);
  bool titlestring_too_large = 
    (p.fontMetrics().width(QString(" ")+label+" ")>r.width());
  if (titlestring_offset_delta > 0){
    if (titlestring_offset > 0
	&& titlestring_offset > r.width() - p.fontMetrics().width(QString(" ")+label+" ")){
      titlestring_offset_delta *= -1;
    }
  }
  else {
    if (titlestring_offset < 0
	&& titlestring_offset +
	p.fontMetrics().width(QString(" ")+label+" ") < r.width()){
      titlestring_offset_delta *= -1;
    }
  }

  if (!titlestring_too_large)
    titlestring_offset = 0;
  p.setClipRect(r);
  p.setClipping(True);
  p.drawText(r.x()+(options.TitleAnimation?titlestring_offset:0),
	     r.y()+p.fontMetrics().ascent(),
	     QString(" ")+label+" ");
  p.setClipping(False);
  p.end();
  if (double_buffering){
    bitBlt(this,
	   title_rect.x(), title_rect.y(),
	   buffer,
	   0,0,
	   buffer->width(), buffer->height());
    delete buffer;
  }
}
Esempio n. 18
0
void UcClassCanvas::draw(QPainter & p) {
  if (! visible()) return;
  p.setRenderHint(QPainter::Antialiasing, true);
  QRect r = rect();
  QFontMetrics fm(the_canvas()->get_font(UmlNormalFont));
  QFontMetrics fim(the_canvas()->get_font(UmlNormalItalicFont));
  QColor bckgrnd = p.backgroundColor();
  double zoom = the_canvas()->zoom();
  FILE * fp = svg();

  if (fp != 0)
    fputs("<g>\n", fp);

  p.setBackgroundMode((used_color == UmlTransparent) ? ::Qt::TransparentMode : ::Qt::OpaqueMode);

  QColor co = color(used_color);
  
  if (used_view_mode == asClass) {
    if (used_color != UmlTransparent) {
      const int shadow = the_canvas()->shadow();

      if (shadow != 0) {
	r.setRight(r.right() - shadow);
	r.setBottom(r.bottom() - shadow);
	
	p.fillRect (r.right(), r.top() + shadow,
		    shadow, r.height() - 1,
		    ::Qt::darkGray);
	p.fillRect (r.left() + shadow, r.bottom(),
		    r.width() - 1, shadow,
		    ::Qt::darkGray);

	if (fp != 0) {
	  fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\""
		  " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
		  QColor(::Qt::darkGray).rgb()&0xffffff,
		  r.right(), r.top() + shadow, shadow - 1, r.height() - 1 - 1);

	  fprintf(fp, "\t<rect fill=\"#%06x\" stroke=\"none\" stroke-opacity=\"1\""
		  " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
		  QColor(::Qt::darkGray).rgb()&0xffffff,
		  r.left() + shadow, r.bottom(), r.width() - 1 - 1, shadow - 1);
	}
      }
    }
    
    p.setBackgroundColor(co);
  
    if (used_color != UmlTransparent) {
      p.fillRect(r, co);

      if (fp != 0)
	fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
		" x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
		svg_color(used_color), 
		r.x(), r.y(), r.width() - 1, r.height() - 1);
    }
    else if (fp != 0)
      fprintf(fp, "\t<rect fill=\"none\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
	      " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
	      r.x(), r.y(), r.width() - 1, r.height() - 1);

    p.drawRect(r);
  }
  
  const ClassData * data = ((ClassData *) browser_node->get_data());
  const int two = (int) (2 * zoom);
  int he = fm.height() + two;
  
  if (data->get_n_formalparams() != 0)
    r.setTop(r.top() + fm.height());
  
  switch (used_view_mode) {
  case asInterface:
    draw_interface_icon(p, r, used_color, zoom);
    r.setTop(r.top() + (int) (INTERFACE_SIZE * zoom) + two);
    break;
  case asControl:
    draw_control_icon(p, r, used_color, zoom);
    r.setTop(r.top() + (int) (CONTROL_HEIGHT * zoom) + two);
    break;
  case asBoundary:
    draw_boundary_icon(p, r, used_color, zoom);
    r.setTop(r.top() + (int) (BOUNDARY_HEIGHT * zoom) + two);
    break;
  case asEntity:
    draw_entity_icon(p, r, used_color, zoom);
    r.setTop(r.top() + (int) (ENTITY_SIZE * zoom) + two);
    break;
  case asActor:
    {
      QRect ra = r;
      
      ra.setHeight((int) (ACTOR_SIZE * zoom));
      ra.setLeft(ra.left() + 
		 (int) ((ra.width() - ACTOR_SIZE * zoom)/2));
      ra.setWidth(ra.height());
      draw_actor(&p, ra);
    }
    r.setTop(r.top() + (int) (ACTOR_SIZE * zoom) + two);
    break;
  case Natural:
    {
      const QPixmap * px = 
	ProfiledStereotypes::diagramPixmap(data->get_stereotype(), zoom);
      int lft = (px->width() < width()) ? r.x() + (width() - px->width())/2 : r.x();

      p.drawPixmap(lft, r.y(), *px);
      if (fp != 0)
	// pixmap not really exported in SVG
	fprintf(fp, "\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
		" x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
		svg_color(UmlBlack), lft, r.y(), px->width() - 1, px->height() - 1);

      r.setTop(r.top() + px->height());
    }
    break;
  default:	// class
    r.setTop(r.top() + two);
    if (data->get_stereotype()[0]) {
      p.setFont(the_canvas()->get_font(UmlNormalFont));
      p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, 
		 QString("<<") + toUnicode(data->get_short_stereotype()) + ">>");
      if (fp != 0)
	draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, 
		  QString("<<") + toUnicode(data->get_short_stereotype()) + ">>",
		  p.font(), fp);
      r.setTop(r.top() + he + two);
    }
  }
  
  p.setBackgroundMode(::Qt::TransparentMode);
  p.setFont((data->get_is_abstract())
	    ? the_canvas()->get_font(UmlNormalItalicFont)
	    : the_canvas()->get_font(UmlNormalFont));
  p.drawText(r, ::Qt::AlignHCenter + ::Qt::AlignTop, full_name);
  if (fp != 0)
    draw_text(r, ::Qt::AlignHCenter + ::Qt::AlignTop, full_name, p.font(), fp);

  p.setFont(the_canvas()->get_font(UmlNormalFont));
  
  if (used_view_mode == asClass) {
    r.setTop(r.top() + he);
    p.drawLine(r.topLeft(), r.topRight());
    
    if (fp != 0)
      fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
	      " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
	      r.left(), r.top(), r.right(), r.top());
    
    r.setTop(r.top() + (int) (8 * zoom));
    p.drawLine(r.topLeft(), r.topRight());
    
    if (fp != 0)
      fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
	      " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
	      r.left(), r.top(), r.right(), r.top());
  }
  
  if (fp != 0)
    fputs("</g>\n", fp);
    
  p.setBackgroundColor(bckgrnd);
  
  if (selected())
    show_mark(p, rect());
}
Esempio n. 19
0
void ActivityPartitionCanvas::draw(QPainter & p) {
  if (! visible()) return;
  p.setRenderHint(QPainter::Antialiasing, true);
  
  QRect r = rect();
  FILE * fp = svg();
  QColor bckgrnd = p.backgroundColor();
  QColor co = color(used_color);
  
  p.setBackgroundMode((used_color == UmlTransparent)
		      ? ::Qt::TransparentMode
		      : ::Qt::OpaqueMode);

  
  p.setBackgroundColor(co);
  
  if (used_color != UmlTransparent)
    p.fillRect(r, co);
    
  p.setFont(the_canvas()->get_font(UmlNormalFont));
  
  QFontMetrics fm(p.font());
  int h = 3*fm.height();
    
  if (fp != 0) {
    fprintf(fp, "<g>\n\t<rect fill=\"%s\" stroke=\"black\" stroke-width=\"1\" stroke-opacity=\"1\""
	    " x=\"%d\" y=\"%d\" width=\"%d\" height=\"%d\" />\n",
	    svg_color(used_color), 
	    r.x(), r.y(), r.width() - 1, r.height() - 1);
  }
  
  p.drawRect(r);

  if (horiz) {
    if (! str.isEmpty()) { 
      p.save();
      p.rotate(-90);
      p.drawText(-r.y(), r.x(), -r.height(), h,
		 ::Qt::AlignCenter, str);
      p.restore();
      
      if (fp != 0) {
	int index = str.find('\n');
	
	if (index == -1)
	  draw_rotate_text(r.x() + h/2, r.y() + r.height()/2,
			   270, str, p.font(), fp);
	else {
	  int vc = r.y() + r.height()/2;
	  
	  draw_rotate_text(r.x() + h/4, vc,
			   270, str.left(index), p.font(), fp);
	  draw_rotate_text(r.x() + (h*3)/4, vc,
			   270, str.mid(index + 1), p.font(), fp);
	}
      }
    }
    
    r.setLeft(r.left() + h);
    p.drawLine(r.topLeft(), r.bottomLeft());
    
    if (fp) {
      fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
	      " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
	      r.left(), r.top(), r.left(), r.bottom());
      fputs("</g>\n", fp);
    }
  }
  else {
    if (! str.isEmpty()) { 
      p.drawText(r.x(), r.y(), r.width(), h,
		 ::Qt::AlignCenter, str);
      
      if (fp != 0)
	draw_text(r.x(), r.y(), r.width(), h,
		  ::Qt::AlignCenter, str, p.font(), fp);
    }
    
    r.setTop(r.top() + h);
    p.drawLine(r.topLeft(), r.topRight());
    
    if (fp) {
      fprintf(fp, "\t<line stroke=\"black\" stroke-opacity=\"1\""
	      " x1=\"%d\" y1=\"%d\" x2=\"%d\" y2=\"%d\" />\n",
	      r.left(), r.top(), r.right(), r.top());
      fputs("</g>\n", fp);
    }
  }
  
  p.setBackgroundColor(bckgrnd);
  
  if (selected())
    show_mark(p, rect());
}
Esempio n. 20
0
/*!\reimp
*/
void QRadioButton::drawButton( QPainter *paint )
{
    QPainter	*p = paint;
    const QColorGroup & g = colorGroup();
    int		 x, y;

    QFontMetrics fm = fontMetrics();
    QSize lsz = fm.size(ShowPrefix, text());
    QSize sz = style().exclusiveIndicatorSize();
    x = text().isEmpty() ? 1 : 0;
    y = (height() - lsz.height() + fm.height() - sz.height())/2;

#ifndef QT_NO_TEXTSTREAM
#define SAVE_RADIOBUTTON_PIXMAPS
#endif

#if defined(SAVE_RADIOBUTTON_PIXMAPS)
    QString pmkey;				// pixmap key
    int kf = 0;
    if ( isDown() )
	kf |= 1;
    if ( isOn() )
	kf |= 2;
    if ( isEnabled() )
	kf |= 4;
    QTextOStream os(&pmkey);
    os << "$qt_radio_" << style().className() << "_"
			 << palette().serialNumber() << "_" << kf;
    QPixmap *pm = QPixmapCache::find( pmkey );
    if ( pm ) {					// pixmap exists
	drawButtonLabel( p );
	p->drawPixmap( x, y, *pm );
	return;
    }
    bool use_pm = TRUE;
    QPainter pmpaint;
    int wx, wy;
    if ( use_pm ) {
	pm = new QPixmap( sz );			// create new pixmap
	CHECK_PTR( pm );
	pmpaint.begin( pm );
	p = &pmpaint;				// draw in pixmap
	wx=x;  wy=y;				// save x,y coords
	x = y = 0;
	p->setBackgroundColor( g.background() );
    }
#endif

#define QCOORDARRLEN(x) sizeof(x)/(sizeof(QCOORD)*2)

    style().drawExclusiveIndicator(p, x, y, sz.width(), sz.height(), g, isOn(), isDown(), isEnabled() );

#if defined(SAVE_RADIOBUTTON_PIXMAPS)
    if ( use_pm ) {
	pmpaint.end();
	if ( backgroundPixmap() || backgroundMode() == X11ParentRelative ) {
	    QBitmap bm( pm->size() );
	    bm.fill( color0 );
	    pmpaint.begin( &bm );
	    style().drawExclusiveIndicatorMask( &pmpaint, 0, 0, bm.width(), bm.height(), isOn() );
	    pmpaint.end();
	    pm->setMask( bm );
	}
	p = paint;				// draw in default device
	p->drawPixmap( wx, wy, *pm );
	if (!QPixmapCache::insert(pmkey, pm) )	// save in cache
	    delete pm;
    }
#endif
    drawButtonLabel( p );
}