bool QwtPlotZoomer::accept(QwtPolygon &pa) const
{
    if ( pa.count() < 2 )
        return false;

    QRect rect = QRect(pa[0], pa[int(pa.count()) - 1]);
#if QT_VERSION < 0x040000
    rect = rect.normalize();
#else
    rect = rect.normalized();
#endif

    const int minSize = 2;
    if (rect.width() < minSize && rect.height() < minSize )
        return false; 

    const int minZoomSize = 11;

    const QPoint center = rect.center();
    rect.setSize(rect.size().expandedTo(QSize(minZoomSize, minZoomSize)));
    rect.moveCenter(center);

    pa.resize(2);
    pa[0] = rect.topLeft();
    pa[1] = rect.bottomRight();

    return true;
}
Example #2
0
void Kanagram::drawSwitcher(QPainter &p, const int xMargin, const int yMargin)
{
	const int padding = 5;
	QString text = m_game->getDocTitle();
	QFont font = m_blackboardFont;
	font.setPointSize(14);
	QFontMetrics fm(font);
	QRect r = innerRect(m_blackboardRect, xMargin, yMargin);
	r.normalize();
	r.moveBy(- padding - (m_overSwitcher ? m_arrowOver : m_arrow )->width(), yMargin);
	r.setHeight( (m_overSwitcher ? m_arrowOver : m_arrow )->height());
	m_switcherRect = p.boundingRect(r, Qt::AlignVCenter|Qt::AlignRight, text);
	p.setFont(font);
	if (m_overSwitcher)
	{
		p.setPen(m_chalkHighlightColor);
		p.drawPixmap(m_switcherRect.right() + padding, m_switcherRect.top(), *m_arrowOver);
	}
	else
	{
		p.setPen(m_chalkColor);
		p.drawPixmap(m_switcherRect.right() + padding, m_switcherRect.top(), *m_arrow);
	}
	m_switcherRect.moveBy(0, -2);
	p.drawText(m_switcherRect, Qt::AlignVCenter|Qt::AlignRight, text);
}
/*!
  Expand the selected rectangle to minZoomSize() and zoom in
  if accepted.

  \sa QwtPlotZoomer::accept()a, QwtPlotZoomer::minZoomSize()
*/
bool QwtPlotZoomer::end(bool ok)
{
    ok = QwtPlotPicker::end(ok);
    if (!ok)
        return false;

    QwtPlot *plot = QwtPlotZoomer::plot();
    if ( !plot )
        return false;

    const QwtPolygon &pa = selection();
    if ( pa.count() < 2 )
        return false;

    QRect rect = QRect(pa[0], pa[int(pa.count() - 1)]);
#if QT_VERSION < 0x040000
    rect = rect.normalize();
#else
    rect = rect.normalized();
#endif


    QwtDoubleRect zoomRect = invTransform(rect).normalized();

    const QwtDoublePoint center = zoomRect.center();
    zoomRect.setSize(zoomRect.size().expandedTo(minZoomSize()));
    zoomRect.moveCenter(center);

    zoom(zoomRect);

    return true;
}
QSObject QSRectClass::normalize(QSEnv *env)
{
  QSObject t = env->thisValue();
  QSRectClass *cl = (QSRectClass *)t.objectType();
  QRect *r = cl->rect(&t);
  return cl->construct(r->normalize());
}
Example #5
0
void ShapeTool::mouseMoveEvent(QMouseEvent* e)
{
    if (m_mousePressed) {
        m_polyline[0] = e->pos();
        QPainter painter;
        painter.begin(m_pDrawPadCanvas->currentPage()->pixmap());
        drawTemporaryShape(painter);
        painter.end();

        QRect r = m_polyline.boundingRect();
        r = r.normalize();
        r.setLeft(r.left() - m_pDrawPad->pen().width());
        r.setTop(r.top() - m_pDrawPad->pen().width());
        r.setRight(r.right() + m_pDrawPad->pen().width());
        r.setBottom(r.bottom() + m_pDrawPad->pen().width());

        QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
                           m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));

        bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
               m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height());

        m_pDrawPadCanvas->viewport()->update(viewportRect);

        m_polyline[1] = m_polyline[0];
    }
}
Example #6
0
void ShapeTool::mouseReleaseEvent(QMouseEvent* e)
{
    Q_UNUSED(e)

    QPainter painter;
    painter.begin(m_pDrawPadCanvas->currentPage()->pixmap());
    drawFinalShape(painter);
    painter.end();

    QRect r = m_polyline.boundingRect();
    r = r.normalize();
    r.setLeft(r.left() - m_pDrawPad->pen().width());
    r.setTop(r.top() - m_pDrawPad->pen().width());
    r.setRight(r.right() + m_pDrawPad->pen().width());
    r.setBottom(r.bottom() + m_pDrawPad->pen().width());

    QRect viewportRect(m_pDrawPadCanvas->contentsToViewport(r.topLeft()),
                       m_pDrawPadCanvas->contentsToViewport(r.bottomRight()));

    bitBlt(m_pDrawPadCanvas->viewport(), viewportRect.x(), viewportRect.y(),
           m_pDrawPadCanvas->currentPage()->pixmap(), r.x(), r.y(), r.width(), r.height());

    m_pDrawPadCanvas->viewport()->update(viewportRect);

    m_mousePressed = false;
}
Example #7
0
void WSpacePlot::selectRectTmp(const QRect &rect, bool select) {
  QRect r=rect.normalize();
  if (select)
    for (int x=r.left(); x<=r.right(); x++)
      for (int y=r.top(); y<=r.bottom(); y++)
	cellData[x+y*viewSize.width()].attr|=tmpSelected;
  else
    for (int x=r.left(); x<=r.right(); x++)
      for (int y=r.top(); y<=r.bottom(); y++)
	cellData[x+y*viewSize.width()].attr&=normal|marked;
}
QRect KstGfxMouseHandlerUtils::resizeRectFromCorner(const QPoint& anchorPoint, const QPoint& movePoint, const QPoint& pos, const QRect& bounds, bool maintainAspect) {
  QRect newSize;
  QPoint npos = pos;

  if (maintainAspect) {
    QPoint fakeMovePoint = anchorPoint + QPoint(quadrantSign(pos,anchorPoint)*abs((movePoint - anchorPoint).x()),abs((movePoint - anchorPoint).y())); // allow the rectangle to flip.
    npos = findNearestPtOnLine(anchorPoint, fakeMovePoint, pos, bounds);
  }

  newSize.setTopLeft(anchorPoint);
  newSize.setBottomRight(npos);

  return bounds.intersect(newSize.normalize());
}
Example #9
0
void KstTopLevelView::pressMoveLayoutModeSelect(const QPoint& pos, bool shift) {
  Q_UNUSED(shift)
  
  const QRect old(_prevBand);
  QRect r;
  r.setTopLeft(_moveOffset);
  r.setBottomRight(pos);
  _prevBand = r.normalize().intersect(_geom);
  if (old != _prevBand) {
    KstPainter p;
    p.begin(_w);
    p.setRasterOp(Qt::NotROP);
    p.drawWinFocusRect(old);
    p.drawWinFocusRect(_prevBand);
    p.end();
  }
  KstApp::inst()->slotUpdateDataMsg(QString::null);
}
Example #10
0
QRegion::QRegion( const QRect &r, RegionType t )
{
    QRect rr = r.normalize();
    data = new QRegionData;
    CHECK_PTR( data );
    data->is_null = FALSE;
    if ( t == Rectangle ) {			// rectangular region
	data->rgn = XCreateRegion();
	XRectangle xr;
	xr.x = rr.x();
	xr.y = rr.y();
	xr.width  = rr.width();
	xr.height = rr.height();
	XUnionRectWithRegion( &xr, data->rgn, data->rgn );
    } else if ( t == Ellipse ) {		// elliptic region
	QPointArray a;
	a.makeEllipse( rr.x(), rr.y(), rr.width(), rr.height() );
	data->rgn = XPolygonRegion( (XPoint*)a.data(), a.size(), EvenOddRule );
    }
}
Example #11
0
void KScienceSaver::do_refresh( const QRect & rect )
{
	if( grabPixmap )
		return;
	rect.normalize();

	if( hideBG[mode] )
	{
		XSetWindowBackground( qt_xdisplay(), winId(), black.pixel() );
		XClearArea( qt_xdisplay(), winId(), rect.left(), rect.top(),
                            rect.width(), rect.height(), false );
	}
	else
	{
		myAssert( d->xRootWin != 0, "root window not grabbed" );
		XPutImage( qt_xdisplay(), winId(), d->gc, d->xRootWin,
		           rect.left(), rect.top(),
                           rect.left(), rect.top(),
                           rect.width(), rect.height() );
	}
}
Example #12
0
void Canvas::mouseMoveEvent( QMouseEvent *e )
{
    if ( mousePressed ) {
	QPainter painter;
	painter.begin( &buffer );
	painter.setPen( pen );
	polyline[2] = polyline[1];
	polyline[1] = polyline[0];
	polyline[0] = e->pos();
	painter.drawPolyline( polyline );
	painter.end();

	QRect r = polyline.boundingRect();
	r = r.normalize();
	r.setLeft( r.left() - penWidth() );
	r.setTop( r.top() - penWidth() );
	r.setRight( r.right() + penWidth() );
	r.setBottom( r.bottom() + penWidth() );

	bitBlt( this, r.x(), r.y(), &buffer, r.x(), r.y(), r.width(), r.height() );
    }
}
void HistogramItem::drawBar(QPainter *painter,
   Qt::Orientation, const QRect& rect) const
{
   painter->save();

   const QColor color(painter->pen().color());
#if QT_VERSION >= 0x040000
   const QRect r = rect.normalized();
#else
   const QRect r = rect.normalize();
#endif

   const int factor = 125;
   const QColor light(color.light(factor));
   const QColor dark(color.dark(factor));

   painter->setBrush(color);
   painter->setPen(Qt::NoPen);
   QwtPainter::drawRect(painter, r.x() + 1, r.y() + 1,
      r.width() - 2, r.height() - 2);
   painter->setBrush(Qt::NoBrush);

   painter->setPen(QPen(light, 2));
#if QT_VERSION >= 0x040000
   QwtPainter::drawLine(painter,
      r.left() + 1, r.top() + 2, r.right() + 1, r.top() + 2);
#else
   QwtPainter::drawLine(painter,
      r.left(), r.top() + 2, r.right() + 1, r.top() + 2);
#endif

   painter->setPen(QPen(dark, 2));
#if QT_VERSION >= 0x040000
   QwtPainter::drawLine(painter, 
      r.left() + 1, r.bottom(), r.right() + 1, r.bottom());
#else
   QwtPainter::drawLine(painter, 
      r.left(), r.bottom(), r.right() + 1, r.bottom());
#endif

   painter->setPen(QPen(light, 1));

#if QT_VERSION >= 0x040000
   QwtPainter::drawLine(painter, 
      r.left(), r.top() + 1, r.left(), r.bottom());
   QwtPainter::drawLine(painter,
      r.left() + 1, r.top() + 2, r.left() + 1, r.bottom() - 1);
#else
   QwtPainter::drawLine(painter, 
      r.left(), r.top() + 1, r.left(), r.bottom() + 1);
   QwtPainter::drawLine(painter,
      r.left() + 1, r.top() + 2, r.left() + 1, r.bottom());
#endif

   painter->setPen(QPen(dark, 1));

#if QT_VERSION >= 0x040000
   QwtPainter::drawLine(painter, 
      r.right() + 1, r.top() + 1, r.right() + 1, r.bottom());
   QwtPainter::drawLine(painter, 
      r.right(), r.top() + 2, r.right(), r.bottom() - 1);
#else
   QwtPainter::drawLine(painter, 
      r.right() + 1, r.top() + 1, r.right() + 1, r.bottom() + 1);
   QwtPainter::drawLine(painter, 
      r.right(), r.top() + 2, r.right(), r.bottom());
#endif

   painter->restore();
}
Example #14
0
void HistogramItem::drawBar( QPainter *painter,
                             Qt::Orientation, const QRect& rect ) const
{
  painter->save();

#if QT_VERSION >= 0x040000
  const QRect r = rect.normalized();
#else
  const QRect r = rect.normalize();
#endif

  painter->setBrush( d_data->color );

  if ( d_data->flat )
  {
    painter->setPen( d_data->pen );
    int penWidth = d_data->pen == Qt::NoPen ? 0 :
                   ( d_data->pen.isCosmetic() ? 1 : d_data->pen.width() );
    QwtPainter::drawRect( painter, r.x(), r.y(),
                          r.width(), r.height() - penWidth );
  }
  else
  {
    const int factor = 125;
    const QColor light( d_data->color.light( factor ) );
    const QColor dark( d_data->color.dark( factor ) );

    QwtPainter::drawRect( painter, r.x() + 1, r.y() + 1,
                          r.width() - 2, r.height() - 2 );

    painter->setBrush( Qt::NoBrush );

    painter->setPen( QPen( light, 2 ) );
#if QT_VERSION >= 0x040000
    QwtPainter::drawLine( painter,
                          r.left() + 1, r.top() + 2, r.right() + 1, r.top() + 2 );
#else
    QwtPainter::drawLine( painter,
                          r.left(), r.top() + 2, r.right() + 1, r.top() + 2 );
#endif

    painter->setPen( QPen( dark, 2 ) );
#if QT_VERSION >= 0x040000
    QwtPainter::drawLine( painter,
                          r.left() + 1, r.bottom(), r.right() + 1, r.bottom() );
#else
    QwtPainter::drawLine( painter,
                          r.left(), r.bottom(), r.right() + 1, r.bottom() );
#endif

    painter->setPen( QPen( light, 1 ) );

#if QT_VERSION >= 0x040000
    QwtPainter::drawLine( painter,
                          r.left(), r.top() + 1, r.left(), r.bottom() );
    QwtPainter::drawLine( painter,
                          r.left() + 1, r.top() + 2, r.left() + 1, r.bottom() - 1 );
#else
    QwtPainter::drawLine( painter,
                          r.left(), r.top() + 1, r.left(), r.bottom() + 1 );
    QwtPainter::drawLine( painter,
                          r.left() + 1, r.top() + 2, r.left() + 1, r.bottom() );
#endif

    painter->setPen( QPen( dark, 1 ) );

#if QT_VERSION >= 0x040000
    QwtPainter::drawLine( painter,
                          r.right() + 1, r.top() + 1, r.right() + 1, r.bottom() );
    QwtPainter::drawLine( painter,
                          r.right(), r.top() + 2, r.right(), r.bottom() - 1 );
#else
    QwtPainter::drawLine( painter,
                          r.right() + 1, r.top() + 1, r.right() + 1, r.bottom() + 1 );
    QwtPainter::drawLine( painter,
                          r.right(), r.top() + 2, r.right(), r.bottom() );
#endif
  }

  painter->restore();
}
Example #15
0
void Canvas::tabletEvent( QTabletEvent *e )
{
    e->accept();
    // change the width based on range of pressure
    if ( e->device() == QTabletEvent::Stylus )	{
        if ( e->pressure() >= 0 && e->pressure() <= 32 )
            pen.setColor( saveColor.light(175) );
        else if ( e->pressure() > 32 && e->pressure() <= 64 )
            pen.setColor( saveColor.light(150) );
        else if ( e->pressure() > 64  && e->pressure() <= 96 )
            pen.setColor( saveColor.light(125) );
        else if ( e->pressure() > 96 && e->pressure() <= 128 )
            pen.setColor( saveColor );
        else if ( e->pressure() > 128 && e->pressure() <= 160 )
            pen.setColor( saveColor.dark(150) );
        else if ( e->pressure() > 160 && e->pressure() <= 192 )
            pen.setColor( saveColor.dark(200) );
        else if ( e->pressure() > 192 && e->pressure() <= 224 )
            pen.setColor( saveColor.dark(250) );
        else // pressure > 224
            pen.setColor( saveColor.dark(300) );
    } else if ( e->device() == QTabletEvent::Eraser
                && pen.color() != backgroundColor() ) {
        pen.setColor( backgroundColor() );
    }

    int xt = e->xTilt();
    int yt = e->yTilt();
    if ( ( xt > -15 && xt < 15 ) && ( yt > -15 && yt < 15 ) )
        pen.setWidth( 3 );
    else if ( ((xt < -15 && xt > -30) || (xt > 15 && xt < 30)) &&
              ((yt < -15 && yt > -30) || (yt > 15 && yt < 30 )) )
        pen.setWidth( 6 );
    else if ( ((xt < -30 && xt > -45) || (xt > 30 && xt < 45)) &&
              ((yt < -30 && yt > -45) || (yt > 30 && yt < 45)) )
        pen.setWidth( 9 );
    else if (  (xt < -45 || xt > 45 ) && ( yt < -45 || yt > 45 ) )
        pen.setWidth( 12 );

    switch ( e->type() ) {
    case QEvent::TabletPress:
        mousePressed = TRUE;
        polyline[2] = polyline[1] = polyline[0] = e->pos();
        break;
    case QEvent::TabletRelease:
        mousePressed = FALSE;
        break;
    case QEvent::TabletMove:
        if ( mousePressed ) {
            QPainter painter;
            painter.begin( &buffer );
            painter.setPen( pen );
            polyline[2] = polyline[1];
            polyline[1] = polyline[0];
            polyline[0] = e->pos();
            painter.drawPolyline( polyline );
            painter.end();

            QRect r = polyline.boundingRect();
            r = r.normalize();
            r.setLeft( r.left() - penWidth() );
            r.setTop( r.top() - penWidth() );
            r.setRight( r.right() + penWidth() );
            r.setBottom( r.bottom() + penWidth() );

            bitBlt( this, r.x(), r.y(), &buffer, r.x(), r.y(), r.width(),
                    r.height() );
        }
        break;
    default:
        break;
    }
}
Example #16
0
QRect KstTopLevelView::resizeSnapToObjects(const QRect& objGeometry, int direction) {
  QRect r = objGeometry;

  int iXMin = STICKY_THRESHOLD;
  int iYMin = STICKY_THRESHOLD;

  // check for "sticky" borders
  for (KstViewObjectList::Iterator i = _children.begin(); i != _children.end(); ++i) {
    if (_pressTarget != *i) {           
      const QRect rect((*i)->geometry());
      int overlapLo = r.top() > rect.top() ? r.top() : rect.top();
      int overlapHi = r.bottom() < rect.bottom() ? r.bottom() : rect.bottom();
      if (overlapHi - overlapLo > 0) {
        if (direction & LEFT) {
          if (labs(r.left() - rect.left()) < labs(iXMin)) {
            iXMin = r.left() - rect.left();
          } else if (labs(r.left() - rect.right()) < labs(iXMin)) {
            iXMin = r.left() - rect.right();              
          }
        } else if (direction & RIGHT) {
          if (labs(r.right() - rect.left()) < labs(iXMin)) {
            iXMin = r.right() - rect.left();
          } else if (labs(r.right() - rect.right()) < labs(iXMin)) {
            iXMin = r.right() - rect.right();
          }
        }                 
      }

      overlapLo = r.left() > rect.left() ? r.left() : rect.left();
      overlapHi = r.right() < rect.right() ? r.right() : rect.right();
      if (overlapHi - overlapLo > 0) {
        if (direction & UP) {
          if (labs(r.top() - rect.top()) < labs(iYMin)) {
            iYMin = r.top() - rect.top();
          } else if (labs(r.top() - rect.bottom()) < labs(iYMin)) {
            iYMin = r.top() - rect.bottom();              
          }
        } else if (direction & DOWN) {
          if (labs(r.bottom() - rect.top()) < labs(iYMin)) {
            iYMin = r.bottom() - rect.top();
          } else if (labs(r.bottom() - rect.bottom()) < labs(iYMin)) {
            iYMin = r.bottom() - rect.bottom();
          }
        }
      }
    }
  }

  if (labs(iYMin) < STICKY_THRESHOLD) {
    if (direction & UP) {
      r.setTop(r.top() - iYMin);
    } else if (direction & DOWN) {
      r.setBottom(r.bottom() - iYMin);
    }
  }

  if (labs(iXMin) < STICKY_THRESHOLD) {
    if (direction & LEFT) {
      r.setLeft(r.left() - iXMin);
    } else if (direction & RIGHT) {
      r.setRight(r.right() - iXMin);
    }
  }

  return r.normalize();
}
Example #17
0
void KstLabel::draw(QPainter &p, int px, int py, bool bJustify, bool doDraw) {
  int w;
  int h;
  int s;
  unsigned i;
  double dRotationRadians = 3.1415926535897932333796 * Rotation / 180.0; 
  double x;
  double y;
  double y_upper;
  double y_lower;
  double x0;
  int i_g;
  bool is_greek;
  bool bTerminate = false;
  unsigned uiLength;
  QChar C;
  QRect rect;
  QRegion rgn;
  QString str;
  QString strOut;
  QString subProcessedText;
  QString processedText;
  QFont TextFont(FontName, fontSize(p), QFont::Normal, false);
  QFont SymbolFont(SymbolFontName, fontSize(p), QFont::Normal, false);	
  int i_fp = 0;
  FPType fP[MAX_DEPTH_SUB_SUPER];
  static const GreekCharType GC[] = {{"\\Alpha", "A"}, {"\\alpha", "a"},
                                     {"\\Beta", "B"}, {"\\beta", "b"},
                                     {"\\Chi", "C"}, {"\\chi", "c"},
                                     {"\\Delta", "D"}, {"\\delta", "d"},
                                     {"\\Epsilon", "E"}, {"\\epsilon", "e"},
                                     {"\\Phi", "F"}, {"\\phi", "f"},
                                     {"\\Gamma", "G"}, {"\\gamma", "g"},
                                     {"\\Eta", "H"}, {"\\eta", "h"},
                                     {"\\Iota", "I"}, {"\\iota", "i"},
                                     {"\\Kappa", "K"}, {"\\kappa", "k"},
                                     {"\\Lambda", "L"}, {"\\lambda", "l"},
                                     {"\\Mu", "M"}, {"\\mu", "m"},
                                     {"\\Nu", "N"}, {"\\nu", "n"},
                                     {"\\Pi", "P"}, {"\\pi", "p"},
                                     {"\\Theta", "Q"}, {"\\theta", "q"},
                                     {"\\Rho", "R"}, {"\\rho", "r"},
                                     {"\\Sigma", "S"}, {"\\sigma", "s"},
                                     {"\\Tau", "T"}, {"\\tau", "t"},
                                     {"\\Omega", "W"}, {"\\omega", "w"},
                                     {"\\Psi", "Y"}, {"\\psi", "y"},
                                     {"\\Zeta", "Z"}, {"\\zeta", "z"},
                                     {"\\sum", "�"}, {"\\int", "�"}
  };
  static const int N_GREEK = sizeof( GC ) / sizeof( GreekCharType );

  p.save();
  p.setFont(TextFont);
  p.translate(px, py);
  p.rotate(Rotation);
  p.setClipping(false);

  if(doDraw) {
    w = width(p);
    h = ascent(p);
  } else {
    w = h = 0;
  }

  fP[0].locked = true;
  fP[0].dy = 0;
  fP[0].size = 0;
  fP[0].x = 0;
  x = y = 0;

  if(bJustify) {
    switch (Justify) {
    case CxBy:
      x = -w/2;
      break;
    case CxTy:
      x = -w/2;
      y = h;
      break;
    case CxCy:
      x = -w/2;
      y = h/2;
      break;
    case LxBy:
      break;
    case LxTy:
      y = h;
      break;
    case LxCy:
      y = h/2;
      break;
    case RxBy:
      x = -w;
      break;
    case RxTy:
      x = -w;
      y = h;
      break;
    case RxCy:
      x = -w;
      y = h/2;
      break;
    default:
      KstDebug::self()->log(i18n("Undefined justification %1 in label \"%2\".").arg(Justify).arg(Text), KstDebug::Debug);
      break;
    }
  }

  y_upper = y;
  y_lower = y;
  x0 = x;
  processedText = Text;

  if (doScalarReplacement) {
    ScalarsUsed.clear();
    KST::scalarList.lock().readLock();
    for (KstScalarList::iterator it = KST::scalarList.begin(); it != KST::scalarList.end(); ++it) {
      if (processedText.contains((*it)->tagLabel())) {
        ScalarsUsed.append(*it);
        processedText.replace((*it)->tagLabel(), (*it)->label());
      }
    }
    KST::scalarList.lock().readUnlock();
  }

  uiLength = processedText.length();
  for (i = 0; i < uiLength; i++) {    
    C = processedText[i];
    if( _interpret &&
        (C == '^' || C == '_' || C == '{' || C == '}' || C == '\\') ) {
      if( !strOut.isEmpty() ) {
        p.setFont( TextFont );
        if( doDraw ) {
          p.drawText(int(x),int(y + fP[i_fp].dy), strOut);
        }      
        x += p.fontMetrics().width(strOut);
        if( y + fP[i_fp].dy - (double)p.fontMetrics().ascent() < y_upper ) {
          y_upper = y + fP[i_fp].dy - (double)p.fontMetrics().ascent();
        }
        if( y + fP[i_fp].dy + (double)p.fontMetrics().descent() > y_lower ) {
          y_lower = y + fP[i_fp].dy + (double)p.fontMetrics().descent();
        }
        strOut = QString::null;
      }
        
      if (C == '^') {  // Superscript
        if (i_fp+1 < MAX_DEPTH_SUB_SUPER) {
          i_fp++;
          bTerminate  = false;
          fP[i_fp].locked = false;
          fP[i_fp].size = fP[i_fp-1].size - 1;
          fP[i_fp].dy = fP[i_fp-1].dy - p.fontMetrics().ascent()*0.4;
          fP[i_fp].x = x;
          if (p.fontMetrics().rightBearing(C) < 0) {
            x -= 2.0 * p.fontMetrics().rightBearing(C);
          }
          s = int(double(fontSize(p))*pow(1.3, double(fP[i_fp].size)));
          if (s < 5) {
            s = 5; // no smaller than 5pt font!
          }
          TextFont.setPointSize(s);
        }
      } else if (processedText[i] == '_') { // Subscript
        if (i_fp+1 < MAX_DEPTH_SUB_SUPER) {
          i_fp++;
          bTerminate  = false;
          fP[i_fp].locked = false;
          fP[i_fp].size = fP[i_fp-1].size-1;
          fP[i_fp].dy = fP[i_fp-1].dy + p.fontMetrics().height()*0.2;
          fP[i_fp].x = x;
          s = int(double(fontSize(p))*pow(1.3, double(fP[i_fp].size)));
          if (s < 5) {
            s = 5; // no smaller than 5pt font!
          }
          TextFont.setPointSize(s);
        }
      } else if (processedText[i] == '{') {
        fP[i_fp].locked = true;
      } else if (processedText[i] == '}') {
        if (i_fp > 0) {
          if (processedText[i+1] == '_' || processedText[i+1] == '^') {
            x = fP[i_fp].x;
          }
          i_fp--;
        }
      } else if( processedText[i] == '\\' ) {
        is_greek = false;
        subProcessedText = processedText.mid(i);
        for (i_g = 0; i_g < N_GREEK; i_g++) {
          if (subProcessedText.startsWith(GC[i_g].label)) {
            is_greek = true;
            str = GC[i_g].c;
            i += GC[i_g].label.length()-1;
            if (processedText[i+1] == ' ') {
              i++;
            }
            break;
          }
        }

        if (is_greek) {
          s = int(double(fontSize(p))*pow(1.3, double(fP[i_fp].size)));
          if (s < 5) {
            s = 5; // no smaller than 5pt font!
          }
          SymbolFont.setPointSize(s);
          p.setFont(SymbolFont);
          bTerminate = true;
          if( doDraw ) {
            p.drawText(int(x),int(y + fP[i_fp].dy), str);
          } 
          
          x += p.fontMetrics().width(str);
          if( y + fP[i_fp].dy - (double)p.fontMetrics().ascent() < y_upper ) {
            y_upper = y + fP[i_fp].dy - (double)p.fontMetrics().ascent();
          }
          if( y + fP[i_fp].dy + (double)p.fontMetrics().descent() > y_lower ) {
            y_lower = y + fP[i_fp].dy + (double)p.fontMetrics().descent();
          }
        } else {
          if (processedText.find( "it", i+1, FALSE ) == (int)i+1 ) {
            TextFont.setItalic(true);
            i += 2;
            if (processedText.at(i+1) == ' ') {
              i++;
            }
          } else if (processedText.find( "rm", i+1, FALSE ) == (int)i+1 ) {
            TextFont.setItalic(false);
            i += 2;
            if (processedText.at(i+1) == ' ') {
              i++;
            }
          } else {
            i++;
            bTerminate = true;
            strOut += processedText.at( i );  
          }
        }
      }
    } else {
      bTerminate = true;
      strOut += processedText[i];
    }
  
    //
    // do we need to terminate a superscript or subscript?
    //
    if (_interpret && i_fp > 0 && fP[i_fp].locked == false && bTerminate ) {
      if( !strOut.isEmpty( ) ) {
        p.setFont( TextFont );
        if( doDraw ) {
          p.drawText(int(x),int(y + fP[i_fp].dy), strOut);
        }
        x += p.fontMetrics().width(strOut);
        if( y + fP[i_fp].dy - (double)p.fontMetrics().ascent() < y_upper ) {
          y_upper = y + fP[i_fp].dy - (double)p.fontMetrics().ascent();
        }
        if( y + fP[i_fp].dy + (double)p.fontMetrics().descent() > y_lower ) {
          y_lower = y + fP[i_fp].dy + (double)p.fontMetrics().descent();      
        }
        strOut = QString::null;
      }
      if (processedText.at(i+1) == '_' || processedText.at(i+1) == '^') {
        x = fP[i_fp].x;
      } 
      
      i_fp--;
      s = int(double(fontSize(p))*pow(1.3, double(fP[i_fp].size)));
      if (s < 5) {
        s = 5; // no smaller than 5pt font!
      }
      TextFont.setPointSize(s);
    } 
  }
  
  if( !strOut.isEmpty( ) ) {
    p.setFont( TextFont );
    if( doDraw ) {
      p.drawText(int(x),int(y + fP[i_fp].dy), strOut);
    }      
    
    x += p.fontMetrics().width(strOut);
    if( y + fP[i_fp].dy - (double)p.fontMetrics().ascent() < y_upper ) {
      y_upper = y + fP[i_fp].dy - (double)p.fontMetrics().ascent();
    }
    if( y + fP[i_fp].dy + (double)p.fontMetrics().descent() > y_lower ) {
      y_lower = y + fP[i_fp].dy + (double)p.fontMetrics().descent();      
    }
  }
  
  p.restore();
  Width = x - x0;

  rect.setRect((int)(px + x0), (int)(py + y_upper), 
               (int)Width, (int)(y_lower - y_upper + 1));
  rect.normalize( );
  
  v_offset = (int)(y - y_upper);
  
  if( Rotation == 0.0 ) {
    QRegion rgn( rect );
    
    extents = rgn;
  } else {
    QPointArray points( 5 );
    int ixBase = 0;
    int iyBase = 0;
    int	ixOld = 0;
    int	iyOld = 0;
    int ix;
    int iy;
    
    switch( Justify ){
    case CxBy:
      ixBase = rect.left() + rect.width()/2;
      iyBase = rect.bottom();
      break;
    case CxTy:
      ixBase = rect.left() + rect.width()/2;
      iyBase = rect.top();
      break;
    case CxCy:
      ixBase = rect.left() + rect.width()/2;
      iyBase = rect.top() + rect.height()/2;
      break;
    case LxBy:
      ixBase = rect.left();
      iyBase = rect.bottom();
      break;
    case LxTy:
      ixBase = rect.left();
      iyBase = rect.top();
      break;
    case LxCy:
      ixBase = rect.left();
      iyBase = rect.top() + rect.height()/2;
      break;
    case RxBy:
      ixBase = rect.right();
      iyBase = rect.bottom();
      break;
    case RxTy:
      ixBase = rect.right();
      iyBase = rect.top();
      break;
    case RxCy:
      ixBase = rect.right();
      iyBase = rect.top() + rect.height()/2;
      break;
    default:
      ixBase = rect.left();
      iyBase = rect.bottom();
      break;
    }
    
    for( i=0; i<5; i++ ) {
      switch( i ) {
      case 0:
      case 4:
        ixOld = rect.left();
        iyOld = rect.top();
        break;
      case 1:
        ixOld = rect.right();
        iyOld = rect.top();
        break;
      case 2:
        ixOld = rect.right();
        iyOld = rect.bottom();
        break;
      case 3:
        ixOld = rect.left();
        iyOld = rect.bottom();
        break;
      }
      ix = ixBase + (int)((double)( ixOld - ixBase )*cos( -dRotationRadians ) + (double)( iyOld - iyBase)*sin( -dRotationRadians ));
      iy = iyBase + (int)((double)( ixOld - ixBase )*sin(  dRotationRadians ) + (double)( iyOld - iyBase)*cos( -dRotationRadians ));
      points.setPoint( i, ix, iy );
    }
    
    QRegion rgn( points );
    
    extents = rgn; 
  }
}