Ejemplo n.º 1
0
void TouchUI::draw( QPainter & painter )
{
	_screen_width = painter.window().width();
	_screen_height = painter.window().height();
	limitScroll();

	// draw background
	QRect rect(0,0,painter.window().width(),_height);
	painter.drawTiledPixmap( rect, _background );
	
	// draw icons
	for ( int i = 0; i < _items.count(); i++ )
	{
        UIItem * t = _items[i];
		int posx = t->x1;
		int posy = t->y1;
		if ( posx < 0 ) posx = _screen_width+posx;
		QSvgRenderer * image = t->image;
		if ( t->highlighted )
			painter.setCompositionMode( QPainter::CompositionMode_HardLight );
		else
			painter.setCompositionMode( QPainter::CompositionMode_SourceOver );
		if ( image == NULL ) continue;
		int h = image->defaultSize().height();
		int w = image->defaultSize().width();
		int img_width = g_config.ui_size;
		int img_height = g_config.ui_size;
		ImageLoadThread::fitImage( w,h, img_width, img_height, false );
		QRectF r( posx+_xoffset, posy+_yoffset, w, h );
		image->render( &painter, r );
	}
}
Ejemplo n.º 2
0
void WColorBar::drawContent(QPainter &p, bool) {
  
  int hue, selectHue, s, v;
  
  color.getHsv(hue,s,v);
  colorGroup().highlight().getHsv(selectHue,s,v);

  int left=p.window().left();
  int width=p.window().width();
  int top=p.window().top();
  
  int selecTop=-1, selecBottom=-1;
  
  if (rangeSelecting) {
    selecBottom=max(selecStartPos,selecEndPos);
    selecTop=min(selecStartPos,selecEndPos);
  }
  
  float step=float(p.window().height())/256;
  QColor paintColor;

  for (int i=0; i<256; i++) {

    float y=i*step;
    
    if (rint(y)>selecBottom || rint(y)<selecTop)
      paintColor.setHsv(hue,255,255-i);
    else
      paintColor.setHsv(selectHue,128,int(255-i*0.5));
    
    p.fillRect(left,top+int(rint(y)),width,int(rint(y+step)-rint(y)),
	       QBrush(paintColor));
  }
}
void operator<<(QPainter &painter, const Line &l)
{
    const Bare_point &s = l.point();
    Vector d = l.direction().to_vector();
    double len = d.squared_length();
    double window_dim = std::max(painter.window().width(), painter.window().height());
    d = d * window_dim/std::min(len, 1.0);
    painter << Segment(s-d, s+d);
}
Ejemplo n.º 4
0
void WLinePlot::drawContent(QPainter &p, bool completeRedraw) {

    completeRedraw=true;

    QArray<float>::Iterator xIt, yIt;

    p.eraseRect(p.window());

    if (!traces.isEmpty() && xData.count()>0) {

        if (wrapAround) {

            p.setPen(SolidLine);

            // cycle traces and draw them
            for (WGraphTrace *trace=traces.first();
                    trace !=0; trace=traces.next())
                if (trace->isVisible()) {

                    p.setPen(trace->getPen());

                    xIt=xData.begin();
                    yIt=trace->getData().begin();
                    p.moveTo(mapToViewCoords(*xIt,*yIt));
                    for (++xIt, ++yIt; xIt<xData.end(); ++xIt, ++yIt)
                        p.lineTo(mapToViewCoords(*xIt,*yIt));
                }

            // drawing new cursor at newPos+1
            if (cursorPos<traceLength()-1) {
                int x1 = mapToViewCoords(xData[cursorPos],0).x();
                int x2 = mapToViewCoords(xData[cursorPos+1],0).x()+1;
                p.fillRect(x1,p.window().top(),x2-x1,p.window().height(),red);
            }
        } else {

            float *x=xData.data(), *y;

            for (WGraphTrace *trace=traces.first();
                    trace !=0; trace=traces.next())
                if (trace->isVisible()) {

                    y=trace->getData().data();

                    p.setPen(trace->getPen());
                    p.moveTo(mapToViewCoords(x[0],y[(cursorPos+1) %
                                                    traceLength()]));

                    for (int i=1; i<traceLength(); i++)
                        p.lineTo(mapToViewCoords(x[i],y[(i+cursorPos+1) %
                                                        traceLength()]));
                }
        }
    }
}
Ejemplo n.º 5
0
void drawSingle(const QPixmap &img, int panX, int panY, QPainter &painter, qreal zoom){
    if(zoom <= 0.0)
        zoom = qMin(qreal(painter.window().width()) / qreal(img.width()), qreal(painter.window().height()) / qreal(img.height()));

    painter.translate(painter.window().width() / 2,
                      painter.window().height() / 2);

    painter.translate(panX, panY);

    painter.scale(zoom, zoom);
    painter.drawPixmap(-img.width() / 2, -img.height() / 2, img);
}
Ejemplo n.º 6
0
void ChartBase::draw_tooltip(QPainter& painter, const QPoint& mouse_position) const
{
    size_t point_index;

    if (!on_chart(mouse_position, point_index))
        return;

    const int ShiftX = 2;
    const int ShiftY = 2;
    const int MarginX = 8;
    const int MarginY = 5;
    const int FrameMargin = 3;
    const qreal CornerRadius = 2.0;
    const int Opacity = 180;
    const QColor TextColor(210, 210, 210, Opacity);
    const QColor BorderColor(40, 40, 40, Opacity);
    const QColor BackgroundColor(80, 80, 80, Opacity);

    if (m_tooltip_formatter.get() == 0)
        return;

    const Vector2d& point = m_original_points[point_index];
    const QString text = m_tooltip_formatter->format(point);
    const QRect text_rect = painter.fontMetrics().boundingRect(QRect(), Qt::AlignCenter, text);

    QRect tooltip_rect(
        mouse_position.x() + ShiftX,
        mouse_position.y() - text_rect.height() - 2 * MarginY - ShiftY,
        text_rect.width() + 2 * MarginX,
        text_rect.height() + 2 * MarginY);

    if (tooltip_rect.left() < FrameMargin)
        tooltip_rect.moveLeft(FrameMargin);

    if (tooltip_rect.top() < FrameMargin)
        tooltip_rect.moveTop(FrameMargin);

    const int MaxRight = painter.window().right() - FrameMargin;
    if (tooltip_rect.right() > MaxRight)
        tooltip_rect.moveRight(MaxRight);

    const int MaxBottom = painter.window().bottom() - FrameMargin;
    if (tooltip_rect.bottom() > MaxBottom)
        tooltip_rect.moveBottom(MaxBottom);

    painter.setPen(BorderColor);
    painter.setBrush(QBrush(BackgroundColor));
    painter.drawRoundedRect(tooltip_rect, CornerRadius, CornerRadius);

    painter.setPen(TextColor);
    painter.drawText(tooltip_rect, Qt::AlignCenter, text);
}
Ejemplo n.º 7
0
void ProjectorPCA::DrawEigenvals(QPainter &painter)
{
    int w=painter.window().width();
    int h=painter.window().height();
    int pad = 5;

    Mat& eigVal = pca.eigenvalues;
    int dim = eigVal.rows;
    float maxEigVal = 0;
#ifdef OPENCV21 // legacy
    FOR(i, dim) if(eigVal.at<float>(i,1) == eigVal.at<float>(i,1)) maxEigVal += eigVal.at<float>(i,1);
#else // OPENCV22+
    FOR(i, dim) if(eigVal.at<float>(i) == eigVal.at<float>(i)) maxEigVal += eigVal.at<float>(i);
#endif
    maxEigVal = max(1.f,maxEigVal);
    float maxAccumulator = 0;
#ifdef OPENCV21 // legacy
    FOR(i, dim) if(eigVal.at<float>(i,1) == eigVal.at<float>(i,1)) maxAccumulator += eigVal.at<float>(i,1) / maxEigVal;
#else // OPENCV22+
    FOR(i, dim) if(eigVal.at<float>(i) == eigVal.at<float>(i)) maxAccumulator += eigVal.at<float>(i) / maxEigVal;
#endif
    float accumulator = 0;

    painter.setPen(Qt::black);
    painter.drawLine(QPointF(pad, h-2*pad), QPointF(w-pad, h-2*pad));
    painter.drawLine(QPointF(pad, pad), QPointF(pad, h-2*pad));
    painter.setRenderHint(QPainter::Antialiasing);
    QPointF point(pad,pad);
    painter.setPen(Qt::red);
    FOR(i, dim)
    {
#ifdef OPENCV21 // legacy
        float eigval = eigVal.at<float>(i,1);
#else // OPENCV22+
        float eigval = eigVal.at<float>(i);
#endif
        if(eigval == eigval)
        {
            accumulator += eigval / maxEigVal;
            //qDebug() << "accumulator: " << accumulator << accumulator/maxAccumulator;
            QPointF point2 = QPointF(dim==1 ? w/2 : i * (w-2*pad) / (dim-1) + pad+(!i?1:0), (int)(accumulator/maxAccumulator * (h-2*pad)));
            painter.drawLine(point, point2);
            point = point2;
        }
        else
        {
            point.setX(dim==1 ? w/2 : i * (w-2*pad) / (dim-1) + pad+(!i?1:0));
        }
    }
void ribi::braw::QtPrintRatingDialog::Print(const std::string& filename)
{
    QPrinter printer;
    printer.setOrientation(QPrinter::Portrait);
    printer.setPaperSize(QPrinter::A4);
    printer.setFullPage(false);
    printer.setOutputFileName(filename.c_str());

    //Draw the image to painter to printer (?must be done before printing)
    QPainter painter;

    painter.begin(&printer);
    {
        //Collect widgets to print
        const std::vector<QWidget *> widgets = CollectWidgets();

        int y = 0;
        for (QWidget * const widget: widgets)
        {
            const int h = widget->height();
            if (y+h > painter.window().height())
            {
                printer.newPage();
                y = 0;
            }
            widget->render(&painter,QPoint(0,y));
            y+=h;
        }
    }
    painter.end();

}
Ejemplo n.º 9
0
bool MainWindow::eventFilter(QObject *object, QEvent *event)
{
   if ( object == ui->position && event->type() == QEvent::MouseButtonPress )
   {
      m_bDraggingPosition = true;
      return false;
   }
   else if ( object == ui->position && event->type() == QEvent::MouseButtonRelease )
   {
      m_bDraggingPosition = false;
      return false;
   }
   else if ( object == ui->sampleWindow && event->type() == QEvent::MouseButtonPress )
   {
      CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
      pMainFrame->GetVisualizerWindow()->SendMessage(WM_LBUTTONDOWN);
   }
   else if ( object == ui->sampleWindow && event->type() == QEvent::Paint )
   {      
      CMainFrame* pMainFrame = (CMainFrame*)AfxGetMainWnd();
      
      QPainter p;
      QRect rect = pMainFrame->GetVisualizerWindow()->toQWidget()->rect().adjusted(3,2,-3,-3);
      QPixmap pixmap(rect.size());
      p.begin(&pixmap);
      pMainFrame->GetVisualizerWindow()->toQWidget()->render(&p,QPoint(),QRegion(3,3,rect.width(),rect.height()));
      p.end();
      p.begin(ui->sampleWindow);
      p.drawPixmap(0,0,pixmap.scaled(p.window().size(),Qt::IgnoreAspectRatio,Qt::FastTransformation));
      p.end();
      return true;
   }
   return false;
}
Ejemplo n.º 10
0
/*!

 */
void
FieldPainter::draw( QPainter & painter )
{
    if ( Options::instance().minimumMode() )
    {
        painter.fillRect( painter.window(),
                          Qt::black );
        return;
    }

    if ( Options::instance().antiAliasing() )
    {
        painter.setRenderHint( QPainter::Antialiasing, false );
    }

    drawBackGround( painter );
    drawLines( painter );
    drawPenaltyAreaLines( painter );
    drawGoalAreaLines( painter );
    drawGoals( painter );
    if ( Options::instance().showFlag() )
    {
        drawFlags( painter );
    }
    if ( Options::instance().gridStep() > 0.0 )
    {
        drawGrid( painter );
    }

    if ( Options::instance().antiAliasing() )
    {
        painter.setRenderHint( QPainter::Antialiasing );
    }
}
Ejemplo n.º 11
0
/*!

 */
void
FieldPainter::drawBackGround( QPainter & painter ) const
{
    // fill the whole region
    painter.fillRect( painter.window(),
                      M_field_brush );
}
Ejemplo n.º 12
0
int KstLabel::fontSize(QPainter &p) {
  int x_pix, y_pix;
  double x_s, y_s, s;

  if (IsSample)
    return Size+12;

  x_s = y_s = Size + 12.0;

  QRect v = p.window();
  x_pix = v.width();
  y_pix = v.height();

  if (x_pix < y_pix) {
    x_s *= x_pix/540.0;
    y_s *= y_pix/748.0;
  } else {
    y_s *= y_pix/540.0;
    x_s *= x_pix/748.0;
  }

  s = (x_s + y_s)/2.0;

  //if (s<12.0) s = 0.5*s + 6;

  if (s < 6.0)
    s = 6.0;

  return int(s);
}
Ejemplo n.º 13
0
void SlideProperties::printInfoText(QPainter& p, int& offset, const QString& str, const QColor& pcol)
{
    if (!str.isEmpty())
    {
        offset += QFontMetrics(p.font()).lineSpacing();
        p.setPen(Qt::black);

        for (int x = -1; x <= 1; ++x)
        {
            for (int y = offset + 1; y >= offset - 1; --y)
            {
                p.drawText(x, p.window().height() - y, str);
            }
        }

        p.setPen(pcol);
        p.drawText(0, p.window().height() - offset, str);
    }
}
Ejemplo n.º 14
0
void counterWidget::paintItself(QPainter& inp)
{
    inp.save();
        int w_width = inp.window().width();
        int w_height = inp.window().height();
        // first let's draw ownership
        inp.setBrush(QBrush(Qt::NoBrush));
        if(ownerPresent_m) inp.setBrush(QBrush(playerColor2QColor(frameColor_m), Qt::Dense5Pattern));
        if(mortgage_m) inp.setBrush(QBrush(Qt::gray, Qt::Dense5Pattern));
        inp.drawRect(0, 0, w_width, w_height); // outer rectangle
        // now we need to draw counter pattern
        inp.setBrush(QBrush(Qt::blue, Qt::VerPattern));
        QRect patternRectangle(frameWidth_m, frameWidth_m, w_width- 2*frameWidth_m,
                        w_height - 2*frameWidth_m);
        inp.drawRect(patternRectangle);
        // now we need to draw name
        inp.drawText(patternRectangle, name_m, QTextOption(Qt::AlignTop| Qt::AlignHCenter));
    inp.restore();
}
Ejemplo n.º 15
0
void WGraphFrame::drawGrid(QPainter &p) {

  QArray<int>::Iterator it;

  QPen oldPen=p.pen();
  p.setPen(gridPen);
  
  if (xGridVisible && parent->xAxis()->isVisible())
    for (it=parent->xAxis()->getTickArray().begin();
	 it!=parent->xAxis()->getTickArray().end(); ++it)
      p.drawLine(*it, p.window().top(), *it, p.window().bottom());
  
  if (yGridVisible && parent->yAxis()->isVisible())
    for (it=parent->yAxis()->getTickArray().begin();
	 it!=parent->yAxis()->getTickArray().end(); ++it)
      p.drawLine(p.window().left(), *it, p.window().right(), *it);
  
  p.setPen(oldPen);
}
Ejemplo n.º 16
0
	void draw( QPainter &painter, const Slice &slice, const uiCoord2D &pithCoord, const int &intensityThreshold, const TKD::ProjectionType &view )
	{
		painter.save();
		painter.setPen(QColor(255,255,255,127));

		const uint width = painter.window().width();
		const uint height = painter.window().height();

		const qreal angularIncrement = TWO_PI/(qreal)(width);

		uint i, j, x, y;

		if ( view == TKD::Z_PROJECTION )
		{
			for ( j=0 ; j<height ; ++j )
			{
				for ( i=0 ; i<width ; ++i )
				{
					if ( slice.at(j,i) > intensityThreshold ) painter.drawPoint(i,j);
				}
			}
		}
		else if ( view == TKD::CARTESIAN_PROJECTION )
		{
			for ( j=0 ; j<height ; ++j )
			{
				for ( i=0 ; i<width ; ++i )
				{
					x = pithCoord.x + j * qCos(i*angularIncrement);
					y = pithCoord.y + j * qSin(i*angularIncrement);
					if ( slice.at(y,x) > intensityThreshold ) painter.drawPoint(i,j);
				}
			}
		}

		painter.restore();
	}
Ejemplo n.º 17
0
/** No descriptions */
void Plot2D::paintEvent(QPaintEvent*)
{
	qDebug("Plot2D::paintEvent");
  QPainter p;
  p.begin(this);
#if 0
  QRect r=p.window();
  qDebug("Plot2D::paintEvent(): %d %d %d %d",
          r.left(),
          r.top(),
          r.right(),
          r.bottom());
#endif
  p.drawPicture(picture_);
	p.end();
}
void ribi::pvdb::QtPvdbPrintRatingDialog::Print()
{
  //Start save dialog
  const boost::shared_ptr<QFileDialog> print_dialog(
    pvdb::QtFileDialog::GetSaveFileDialog(
      pvdb::QtFileDialog::FileType::pdf));
  print_dialog->setWindowTitle("Exporteer document naar PDF");
  if (print_dialog->exec() != QDialog::Accepted
    || print_dialog->selectedFiles().empty() )
  {
    return;
  }
  assert(!print_dialog->selectedFiles().empty());
  assert(print_dialog->selectedFiles().size() == 1);
  const std::string filename = print_dialog->selectedFiles()[0].toStdString();

  QPrinter printer;
  printer.setOrientation(QPrinter::Portrait);
  printer.setPaperSize(QPrinter::A4);
  printer.setFullPage(false);
  printer.setOutputFileName(filename.c_str());

  //Draw the image to painter to printer (?must be done before printing)
  QPainter painter;

  painter.begin(&printer);
  {
    //Collect widgets to print
    const std::vector<QWidget *> widgets = CollectWidgets();

    int y = 0;
    for (QWidget * const widget: widgets)
    {
      const int h = widget->height();
      if (y+h > painter.window().height())
      {
        printer.newPage();
        y = 0;
      }
      widget->render(&painter,QPoint(0,y));
      y+=h;
    }
  }
  painter.end();

}
Ejemplo n.º 19
0
void Screen::initNumber(QPainter &painter)
{  
	QRect newWindow = painter.window();
	stringXTitle = QObject::tr( "Time (hh:mm:ss)" );
	rectCordinate.setRect( newWindow.left()+FrameWidth + 2 * BaseFontHeight 
			+ 2 * BaseLineLenght,newWindow.top() + FrameWidth 
			+ 2 * SpaceMargin,newWindow.width() 
			- 2 * ( FrameWidth + BaseFontHeight + BaseLineLenght + SpaceMargin) ,
			newWindow.height() 
			- 2 * ( FrameWidth + BaseFontHeight + BaseLineLenght + SpaceMargin ) );
           
	if ( 0 != ( rectCordinate.width() % (Step*Step) ) )
	{
		int x = rectCordinate.width() % ( Step * Step );     
		rectCordinate.setWidth( rectCordinate.width() - x+1 );
	}

	if ( 0 != ( rectCordinate.height() % (Step*Step) ) )
	{
		int y = rectCordinate.height() % (Step*Step);                                
		rectCordinate.setHeight( rectCordinate.height() - y+1 );
	}
	numXTicks = (rectCordinate.width()-1) / Step;
	numYTicks = (rectCordinate.height()-1) / Step;
           
	rectYText.setRect( 
		newWindow.left() + FrameWidth-10,
		newWindow.top() + FrameWidth + 2 * SpaceMargin,
		BaseFontHeight+5, rectCordinate.height() );
	rectXText.setRect(
		rectCordinate.left(), 
		newWindow.bottom() - FrameWidth - BaseFontHeight,
		rectCordinate.width(), BaseFontHeight );
           
	fromSaveRect.setRect( 
		rectCordinate.left() + Step,
		rectCordinate.top() + 1,
		rectCordinate.width() - Step - 1, 
		rectCordinate.height() + 2 * BaseLineLenght + 2*BaseFontHeight);
	toNewRect.setRect(
		rectCordinate.left() + 1,
		rectCordinate.top() + 1,
		rectCordinate.width() - Step - 1,
		rectCordinate.height() + 2 * BaseLineLenght +2* BaseFontHeight);
}
Ejemplo n.º 20
0
 void paintEvent(QPaintEvent* event)
 {
   if(!image)
     return;
   
   painter.begin(this);
   const QRect& windowRect(painter.window());
   QSizeF maxSize(windowRect.size());
   maxSize *= scale;
   QSizeF size(image->size());
   size -= QSizeF(offset.x(), offset.y());
   if(size.width() > maxSize.width())
     size.setWidth(maxSize.width());
   if(size.height() > maxSize.height())
     size.setHeight(maxSize.height());
   painter.drawPixmap(QRectF(QPointF(0, 0), size / scale), *image, QRectF(offset, size));
   painter.end();
 }
Ejemplo n.º 21
0
void ChartBase::prepare_drawing(QPainter& painter)
{
    m_points = m_original_points;

    if (m_equidistant)
    {
        for (size_t i = 0; i < m_points.size(); ++i)
            m_points[i].x = static_cast<double>(i);

    }

    m_points_bbox = compute_points_bbox();
    m_rcp_points_bbox_extent = Vector2d(1.0) / m_points_bbox.extent();

    const QRect window = painter.window();

    m_window_origin = Vector2d(window.x(), window.y());
    m_window_size = Vector2d(window.width(), window.height());
}
Ejemplo n.º 22
0
void ImageWidget::paint(QPainter& painter)
{
  SYNC_WITH(imageView.console);

  const DebugImage* image = nullptr;
  RobotConsole::Images& currentImages = imageView.upperCam ? imageView.console.upperCamImages : imageView.console.lowerCamImages;
  RobotConsole::Images::const_iterator i = currentImages.find(imageView.background);

  if(i != currentImages.end())
  {
    image = i->second.image;
    imageWidth = image->getImageWidth();
    imageHeight = image->height;
  }
  else if(!currentImages.empty())
  {
    imageWidth = currentImages.begin()->second.image->getImageWidth();
    imageHeight = currentImages.begin()->second.image->height;
  }

  const QSize& size = painter.window().size();
  float xScale = float(size.width()) / float(imageWidth);
  float yScale = float(size.height()) / float(imageHeight);
  scale = xScale < yScale ? xScale : yScale;
  scale *= zoom;
  float imageXOffset = (float(size.width()) - float(imageWidth) * scale) * 0.5f + float(offset.x()) * scale;
  float imageYOffset = (float(size.height()) - float(imageHeight) * scale) * 0.5f + float(offset.y()) * scale;

  painter.setTransform(QTransform(scale, 0, 0, scale, imageXOffset, imageYOffset));

  if(image)
    paintImage(painter, *image);
  else
    lastImageTimeStamp = 0;

  paintDrawings(painter);
}
Ejemplo n.º 23
0
void SensorWidget::paintEvent(QPaintEvent* event)
{
  painter.begin(this);
  painter.setFont(font);
  painter.setBrush(altBrush);
  painter.setPen(fontPen);
  fillBackground = false;

  paintRect = painter.window();
  paintRectField0 = QRect(headerView->sectionViewportPosition(0) + textOffset, 0, headerView->sectionSize(0) - textOffset * 2, lineSpacing);
  paintRectField1 = QRect(headerView->sectionViewportPosition(1) + textOffset, 0, headerView->sectionSize(1) - textOffset * 2, lineSpacing);
  {
    SYNC_WITH(sensorView.console);
    paintInertialSensorData();
    newSection();
    paintSystemSensorData();
    newSection();
    paintFsrSensorData();
    newSection();
    paintKeyStates();
  }
  painter.end();
  setMinimumHeight(paintRectField1.top());
}
Ejemplo n.º 24
0
void HeliCanvas::save(QString streamID, QString headline, QString date,
                      QString filename, int xres, int yres, int dpi) {
	std::cerr << "Printing..." << std::flush;

	QPainter *painter;
	QFileInfo fi(filename);
	QPrinter *printer = NULL;
	QImage *pixmap = NULL;

	if ( fi.suffix().toLower() == "ps" ) {
		printer = new QPrinter(QPrinter::HighResolution);
		printer->setOutputFileName(filename);
		printer->setResolution(dpi);
		printer->setPageSize(QPrinter::A4);
		painter = new QPainter(printer);
	}
	else {
		pixmap = new QImage(xres,yres,QImage::Format_RGB32);
		painter = new QPainter(pixmap);
		painter->fillRect(painter->window(), _palette.color(QPalette::Base));
	}

	painter->setFont(SCScheme.fonts.base);

	int fontHeight = painter->fontMetrics().height();
	int headerHeight = fontHeight*120/100;
	if ( !headline.isEmpty() )
		headerHeight += fontHeight*120/100;

	painter->translate(0, headerHeight);

	int offset = draw(
		*painter,
		QSize(painter->viewport().width(),
		      painter->viewport().height()-headerHeight)
		);

	painter->translate(0, -headerHeight);
	painter->drawText(offset, 0, painter->viewport().width()-offset, fontHeight,
	                  Qt::AlignLeft | Qt::AlignTop, streamID);
	painter->drawText(offset, 0, painter->viewport().width()-offset, fontHeight,
	                  Qt::AlignRight | Qt::AlignTop, date);

	if ( !headline.isEmpty() )
		painter->drawText(offset, fontHeight*120/100, painter->viewport().width()-offset, fontHeight,
		                  Qt::AlignLeft | Qt::AlignTop, headline);

	painter->drawLine(0, headerHeight, painter->viewport().width(), headerHeight);

	if ( pixmap )
		pixmap->save(filename);

	painter->end();

	// Clean up
	if ( printer ) delete printer;
	if ( pixmap ) delete pixmap;
	if ( painter ) delete painter;

	std::cerr << "finished" << std::endl;
}
Ejemplo n.º 25
0
void FilmstripTile::render(QPainter& painter, const Widgets::TileInfo& tileInfo, const QVariant& data)
{
    int w = painter.window().width();
    int h = painter.window().height();

    //   painter.drawLine(0,0,w-1,h-1);
    //   painter.drawLine(0,h,w-1,0);

    // TODO: Load fonts in advance??
    painter.setFont(QFont("helvetica", 18));

    if (!data.isNull())
    {
        if ((tileInfo.tileState & Widgets::TileInfo::TileStateSelected) ==
            Widgets::TileInfo::TileStateSelected)
            painter.setBrush(QBrush(QColor(Qt::darkGray).lighter(180),
                Qt::SolidPattern));
        else
            painter.setBrush(QBrush(QColor(Qt::darkGray),
                Qt::SolidPattern));
        // draw the tile
        painter.setPen(QColor(Qt::darkGray));
        painter.drawRect(0, 0, w - 2, h - 2);
        painter.setBrush(Qt::NoBrush);

        // draw the bevel
        painter.setPen(QColor(Qt::gray));
        // draw clock wise
        painter.drawLine(0, h - 1, 0, 0);     //left side
        painter.drawLine(0, 0, w - 1, 0);     // top side
        painter.setPen(QColor(Qt::black));
        painter.drawLine(w - 1, 0, w - 1, h - 1);    // right side
        painter.drawLine(w - 1, h - 1, 0, h - 1);     // bottom side

        Photo info = data.value<Photo>();

        // draw the id text
        painter.save();
        painter.setPen(QColor(Qt::darkGray).lighter(110));
        painter.setFont(QFont(QString("Verdana"), 24, QFont::Bold));
        int fontHeight = painter.fontMetrics().height();
        painter.drawText(5, fontHeight - 5, QString::number(info.id()));

        painter.restore();

        // draw the image.
        QImage image = info.libraryPreviewsRGB();
        QRect  photoFinalDimension;

        if (!image.isNull())
        {
            float ratio = 0.90f;
            int   wf    = (int)(w * ratio);     // width frame
            int   hf    = (int)(h * ratio);     // height frame

            photoFinalDimension = fitFrame(image.size(), QSize(wf, hf));

            // move the frame to the center
            photoFinalDimension.translate((w - wf) / 2, (h - hf) / 2);
            painter.drawImage(photoFinalDimension, image);

            // draw border around image
            painter.setPen(QColor(Qt::black));
            painter.drawRect(photoFinalDimension);
        }
        else
        {
            // TODO: draw missing image indicator
            painter.setPen(QColor(Qt::red));
            painter.drawLine(w / 2 - 15, h / 2 - 15, w / 2 + 15,
                h / 2 + 15);
            painter.drawLine(w / 2 - 15, h / 2 + 15, w / 2 + 15,
                h / 2 - 15);
        }
    }
    else
    {
        // TODO: draw missing picture instead of blue cross
        painter.setPen(QColor(Qt::blue));
        painter.drawLine(0, 0, w - 1, h - 1);
        painter.drawLine(0, h - 1, w - 1, 0);
    }
}
Ejemplo n.º 26
0
void GeometryPainter::drawPolygon(QPainter& pt, const OGRPolygon* polygon, const QMatrix& m)
{
  QPen pen = pt.pen();
  QBrush brush = pt.brush();

  if (polygon->getNumInteriorRings() > 0)
  {
    QPainter* lpt = NULL;
    QImage* image = new QImage(pt.window().size(), QImage::Format_ARGB32);
    if (image->isNull() == true)
    {
      delete image;
      throw Exception("Internal Error: GeometryPainter::drawPolygon "
                      "Error allocating image.");
    }
    image->fill(qRgba(0, 0, 0, 0));
    lpt = new QPainter(image);
    lpt->setMatrix(pt.matrix());
    lpt->setPen(pen);
    lpt->setBrush(brush);

    const OGRLinearRing* ring = polygon->getExteriorRing();
    QPolygonF qp;
    _convertRingToQPolygon(ring, qp, m);

    lpt->setPen(Qt::NoPen);
    lpt->setBrush(brush);
    lpt->drawPolygon(qp, Qt::WindingFill);

    lpt->setPen(pen);
    lpt->setBrush(Qt::NoBrush);
    lpt->drawPolygon(qp);
    for (int i = 0; i < polygon->getNumInteriorRings(); i++)
    {
      ring = polygon->getInteriorRing(i);

      // draw the appropriate border around the section we erased.
      _convertRingToQPolygon(ring, qp, m);

      // clear out the hole
      lpt->setPen(Qt::NoPen);
      lpt->setBrush(QColor(0, 0, 0, 0));
      lpt->setCompositionMode(QPainter::CompositionMode_Clear);
      lpt->drawPolygon(qp, Qt::WindingFill);

      lpt->setPen(pen);
      lpt->setBrush(Qt::NoBrush);
      lpt->setCompositionMode(QPainter::CompositionMode_SourceOver);
      lpt->drawPolygon(qp, Qt::WindingFill);
    }

    lpt->end();

    QMatrix m = pt.matrix();
    pt.resetMatrix();
    pt.drawImage(pt.window(), *image);
    pt.setMatrix(m);

    delete lpt;
    delete image;
  }
  else
  {
    const OGRLinearRing* ring = polygon->getExteriorRing();
    QPolygonF qp;
    _convertRingToQPolygon(ring, qp, m);

    pt.setPen(Qt::NoPen);
    pt.setBrush(brush);
    pt.drawPolygon(qp, Qt::WindingFill);

    pt.setPen(pen);
    pt.setBrush(Qt::NoBrush);
    pt.drawPolygon(qp);
  }
}
Ejemplo n.º 27
0
void Flags::drawLabel(QPainter& painter, const QString& layoutText, bool flagShown)
{
    QFont font = painter.font();

    QRect rect = painter.window();
//	int fontSize = layoutText.length() == 2
//			? height * 7 / 10
//			: height * 5 / 10;

    int fontSize = rect.height();// * 7 /10;

    font.setPixelSize(fontSize);
    font.setWeight(QFont::DemiBold);

    QFontMetrics fm = painter.fontMetrics();
    int width = fm.width(layoutText);

    if( width > rect.width() * 2 / 3 ) {
        fontSize = round( (double)fontSize * ((double)rect.width()*2/3) / width );
    }

    int smallestReadableSize = KGlobalSettings::smallestReadableFont().pixelSize();
    if( fontSize < smallestReadableSize ) {
        fontSize = smallestReadableSize;
    }
    font.setPixelSize(fontSize);

#ifdef DONT_USE_PLASMA
    painter.setFont(font);
    painter.setPen(Qt::white);
    painter.drawText(QRect(rect).adust(1,1,0,0), Qt::AlignCenter | Qt::AlignHCenter, layoutText);
    painter.setPen(Qt::black);
    painter.drawText(rect, Qt::AlignCenter | Qt::AlignHCenter, layoutText);
#else
    // we init svg so that we get notification about theme change
    getSvg();

    Plasma::Theme theme;
    QColor textColor = flagShown ? Qt::black : theme.color(Plasma::Theme::TextColor);
    QPoint offset = QPoint(0, 0);

    auto shadowText = [&font, &textColor, &offset](QString text) {
        //don't try to paint stuff on a future null pixmap because the text is empty
        if (text.isEmpty()) {
            return QPixmap();
        }

        // Draw text
        QFontMetrics fm(font);
        QRect textRect = fm.boundingRect(text);
        QPixmap textPixmap(textRect.width(), fm.height());
        textPixmap.fill(Qt::transparent);
        QPainter p(&textPixmap);
        p.setPen(textColor);
        p.setFont(font);
        // FIXME: the center alignment here is odd: the rect should be the size needed by
        //        the text, but for some fonts and configurations this is off by a pixel or so
        //        and "centering" the text painting 'fixes' that. Need to research why
        //        this is the case and determine if we should be painting it differently here,
        //        doing soething different with the boundingRect call or if it's a problem
        //        in Qt itself
        p.drawText(textPixmap.rect(), Qt::AlignCenter, text);
        p.end();

        return textPixmap;
    };

    //    QPixmap pixmap = Plasma::PaintUtils::texturedText(layoutText, font, svg);
    QPixmap labelPixmap = shadowText(layoutText);

    int y = round((rect.height() - labelPixmap.height()) / 2.0);
    int x = round((rect.width() - labelPixmap.width()) / 2.0);
    painter.drawPixmap(QPoint(x, y), labelPixmap);
#endif
}
Ejemplo n.º 28
0
//drawing:
void G_segment::draw(QPainter &p, const G_drawstyle &d, bool selected)
{
  QRect r = p.window();

  if(!inRect(r)) return;

  G_point tmp1, tmp2;
  
  if(fabs(p1.getX()) < DRAW_MAX && fabs(p1.getY()) < DRAW_MAX) {
    tmp1 = p1;
  }
  else {
    tmp1 = getNearestPoint(G_point(0, 0));
    tmp1 += (p1 - tmp1) * (DRAW_MAX) / (p1 - tmp1).length();
  }

  if(fabs(p2.getX()) < DRAW_MAX && fabs(p2.getY()) < DRAW_MAX) {
    tmp2 = p2;
  }
  else {
    tmp2 = getNearestPoint(G_point(0, 0));
    tmp2 += (p2 - tmp2) * (DRAW_MAX) / (p2 - tmp2).length();
  }

  //Now Draw!

  if(/*p.device()->isExtDev() ||*/ p.hasViewXForm()) { //draw at higher accuracy to a printer
    tmp1 *= 8.;
    tmp2 *= 8.;
    p.scale(0.125, .125);
    
    int w = d.getPen().width() * 8;
    if(w == 0) w = 2;
    //if(!p.device()->isExtDev()) w = (d.getPen().width() == 0 ? 4 : 4 * d.getPen().width());

    p.setPen(QPen(d.getPen().color(), w, d.getPen().style()));
    p.drawLine(tmp1.toQPoint(), tmp2.toQPoint());

    p.scale(8, 8);

    return;
  }

  if(selected && KSegView::getSelectType() == KSegView::BORDER_SELECT) {
    int width = d.getPen().width() ? d.getPen().width() + 3 : 4;

    p.setPen(QPen(G_drawstyle::getBorderColor(d.getPen().color()), width));

    p.drawLine(tmp1.toQPoint(), tmp2.toQPoint());
    
  }

  p.setPen(d.getPen());
  if(selected && KSegView::getSelectType() == KSegView::BLINKING_SELECT) {
    QColor c(QTime::currentTime().msec() * 17, 255, 255, QColor::Hsv);

    p.setPen(QPen(c, d.getPen().width(), d.getPen().style()));
  }

  p.drawLine(tmp1.toQPoint(), tmp2.toQPoint());

  return;
	     
}
Ejemplo n.º 29
0
/*!

 */
void
FieldPainter::drawGrid( QPainter & painter ) const
{
    const Options & opt = Options::instance();

    const double grid_step = opt.gridStep();
    const int istep = opt.scale( grid_step );
    if ( istep <= 2 )
    {
        return;
    }

    const QFontMetrics metrics = painter.fontMetrics();
    const int text_step_x = ( opt.showGridCoord()
                              ? metrics.width( QObject::tr( "-00.000" ) )
                              : 100000 );
    const int text_step_y = ( opt.showGridCoord()
                              ? metrics.ascent()
                              : 100000 );

    const QRect win = painter.window();

    const int max_ix = win.right();
    const int min_ix = win.left();
    const int max_iy = win.bottom();
    const int min_iy = win.top();
    const double max_x = opt.fieldX( max_ix );
    const double min_x = opt.fieldX( min_ix );
    const double max_y = opt.fieldY( max_iy );
    const double min_y = opt.fieldY( min_iy );

    const int coord_x_print_y = min_iy + metrics.ascent();
    //     std::cerr << "drawGrid  min_x = " << min_x
    //               << "  max_x = " << max_x
    //               << "  min_y = " << min_y
    //               << "  max_y = " << max_y
    //               << std::endl;

    painter.setPen( M_line_pen );
    painter.setBrush( Qt::NoBrush );

    QString text;

    double x = 0.0;
    while ( x < max_x )
    {
        int ix = opt.screenX( x );
        if ( istep > text_step_x )
        {
            text.sprintf( "%.3f", x );
            painter.drawText( ix, coord_x_print_y , text );
        }
        painter.drawLine( ix, max_iy, ix, min_iy );
        x += grid_step;
    }

    x = -grid_step;
    while ( min_x < x )
    {
        int ix = opt.screenX( x );
        if ( istep > text_step_x )
        {
            text.sprintf( "%.3f", x );
            painter.drawText( ix, coord_x_print_y, text );
        }
        painter.drawLine( ix, max_iy, ix, min_iy );
        x -= grid_step;
    }


    double y = 0.0;
    while ( y < max_y )
    {
        int iy = opt.screenY( y );
        if ( istep > text_step_y )
        {
            text.sprintf( "%.3f", y );
            painter.drawText( min_ix, iy, text );
        }
        painter.drawLine( max_ix, iy, min_ix, iy );
        y += grid_step;
    }

    y = -grid_step;
    while ( min_y < y )
    {
        int iy = opt.screenY( y );
        if ( istep > text_step_y )
        {
            text.sprintf( "%.3f", y );
            painter.drawText( min_ix, iy, text );
        }
        painter.drawLine( max_ix, iy, min_ix, iy );
        y -= grid_step;
    }
}
Ejemplo n.º 30
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);
  }
}