void PropertyPanel::setTitleFont()
{
	QFont titleFont = font();
	titleFont.setPointSizeFloat( titleFont.pointSizeFloat()*1.5f );
	moduleNameLabel->setFont( titleFont );
	titleFont = font();
	titleFont.setPointSizeFloat( titleFont.pointSizeFloat()*1.15f );
	selectedLabel->setFont( titleFont );
}
Esempio n. 2
0
/**
 * Update the count of unread messages.  If there are unread messages,
 * overlay the count on top of a transparent version of the KMail icon.
 * If there is no unread mail, restore the normal KMail icon.
 */
void KMSystemTray::updateCount()
{
  if(mCount != 0)
  {
    int oldPixmapWidth = pixmap()->size().width();
    int oldPixmapHeight = pixmap()->size().height();

    QString countString = QString::number( mCount );
    QFont countFont = KGlobalSettings::generalFont();
    countFont.setBold(true);

    // decrease the size of the font for the number of unread messages if the
    // number doesn't fit into the available space
    float countFontSize = countFont.pointSizeFloat();
    QFontMetrics qfm( countFont );
    int width = qfm.width( countString );
    if( width > oldPixmapWidth )
    {
      countFontSize *= float( oldPixmapWidth ) / float( width );
      countFont.setPointSizeFloat( countFontSize );
    }

    // Create an image which represents the number of unread messages
    // and which has a transparent background.
    // Unfortunately this required the following twisted code because for some
    // reason text that is drawn on a transparent pixmap is invisible
    // (apparently the alpha channel isn't changed when the text is drawn).
    // Therefore I have to draw the text on a solid background and then remove
    // the background by making it transparent with QPixmap::setMask. This
    // involves the slow createHeuristicMask() function (from the API docs:
    // "This function is slow because it involves transformation to a QImage,
    // non-trivial computations and a transformation back to a QBitmap."). Then
    // I have to convert the resulting QPixmap to a QImage in order to overlay
    // the light KMail icon with the number (because KIconEffect::overlay only
    // works with QImage). Finally the resulting QImage has to be converted
    // back to a QPixmap.
    // That's a lot of work for overlaying the KMail icon with the number of
    // unread messages, but every other approach I tried failed miserably.
    //                                                           IK, 2003-09-22
    QPixmap numberPixmap( oldPixmapWidth, oldPixmapHeight );
    numberPixmap.fill( Qt::white );
    QPainter p( &numberPixmap );
    p.setFont( countFont );
    p.setPen( Qt::blue );
    p.drawText( numberPixmap.rect(), Qt::AlignCenter, countString );
    numberPixmap.setMask( numberPixmap.createHeuristicMask() );
    QImage numberImage = numberPixmap.convertToImage();

    // Overlay the light KMail icon with the number image
    QImage iconWithNumberImage = mLightIconImage.copy();
    KIconEffect::overlay( iconWithNumberImage, numberImage );

    QPixmap iconWithNumber;
    iconWithNumber.convertFromImage( iconWithNumberImage );
    setPixmap( iconWithNumber );
  } else
  {
    setPixmap( mDefaultIcon );
  }
}
Esempio n. 3
0
Dot_Bottom::Dot_Bottom()
{
  Description = QObject::tr("Bottom");

  QFont f = QucsSettings.font;
  f.setWeight(QFont::Light);
  f.setPointSizeFloat(12.0);
  QFontMetrics  metrics(f);
  QSize r = metrics.size(0, QObject::tr("Bottom"));
  int xb = r.width()  >> 1;
  int yb = r.height() >> 1;

  Lines.append(new Line(-xb, -yb, -xb,  yb,QPen(Qt::darkBlue,2)));
  Lines.append(new Line(-xb,  yb,  xb+3,yb,QPen(Qt::darkBlue,2)));
  Texts.append(new Text(-xb+4,  -yb-3, QObject::tr("Bottom"),
			QColor(0,0,0), 12.0));

  x1 = -xb-3;  y1 = -yb-5;
  x2 =  xb+9; y2 =  yb+3;

  tx = x1+4;
  ty = y2+4;
  Model = ".bottom";
  Name  = "bottom";

/*  Props.append(new Property("Model name", "", true,
  			QObject::tr("Name of the model.")));
  Props.append(new Property("Element name", "", true,
  			QObject::tr("Name of the element that will use the model.")));  */
			
			
  Props.append(new Property("Bottom", "", true,
  			QObject::tr("This text will be placed at the bottom of the netlist")));
}
Esempio n. 4
0
Equation::Equation()
{
  Type = isComponent; // Analogue and digital component.
  Description = QObject::tr("equation");

  QFont f = QucsSettings.font;
  f.setWeight(QFont::Light);
  f.setPointSizeFloat(12.0);
  QFontMetrics  metrics(f);
  QSize r = metrics.size(0, QObject::tr("Equation"));
  int xb = r.width()  >> 1;
  int yb = r.height() >> 1;

  Lines.append(new Line(-xb, -yb, -xb,  yb,QPen(QPen::darkBlue,2)));
  Lines.append(new Line(-xb,  yb,  xb+3,yb,QPen(QPen::darkBlue,2)));
  Texts.append(new Text(-xb+4,  -yb-3, QObject::tr("Equation"),
			QColor(0,0,0), 12.0));

  x1 = -xb-3;  y1 = -yb-5;
  x2 =  xb+9; y2 =  yb+3;

  tx = x1+4;
  ty = y2+4;
  Model = "Eqn";
  Name  = "Eqn";

  Props.append(new Property("y", "1", true));
  Props.append(new Property("Export", "yes", false,
  		QObject::tr("put result into dataset")+" [yes, no]"));
}
Esempio n. 5
0
// -------------------------------------------------------------
void ViewPainter::init(QPainter *p, float Scale_, int DX_, int DY_, int dx_, int dy_)
{
  Painter = p;
  Scale = Scale_;
  DX = floor(float(DX_) * Scale) - float(dx_);
  DY = floor(float(DY_) * Scale) - float(dy_);

  QFont f = p->font();
  f.setPointSizeFloat( Scale * float(f.pointSize()) );
  p->setFont(f);
  LineSpacing = p->fontMetrics().lineSpacing();
  p->setWorldXForm(false);   // we use our own coordinate transformation
}
Esempio n. 6
0
void resize_font(int i)
{
    NormalFont.setPointSizeFloat(i);
    BoldFont.setPointSizeFloat(i);
    ItalicFont.setPointSizeFloat(i);
    BoldItalicFont.setPointSizeFloat(i);
    UnderlineFont.setPointSizeFloat(i);
    BoldUnderlineFont.setPointSizeFloat(i);
    StrikeOutFont.setPointSizeFloat(i);

    QFont fn = QApplication::font();

    fn.setPointSizeFloat(i);
    QApplication::setFont(fn, TRUE);
}
Esempio n. 7
0
/** Calculates the height of the drawed object */
int MLabelObject::calcHeight(FLStylePainter *p) const
{
  if (!changeHeight)
    return 0;

  if (pixmap && !pixmap->isNull())
    return height;

  // Font
  QFont fnt;
  int tf;
  fnt.setFamily(fontFamily);
  fnt.setPointSizeFloat(fontSize);
  fnt.setWeight(fontWeight);
  fnt.setItalic(fontItalic);
  p->painter()->setFont(fnt);

  // Horizontal
  switch (hAlignment) {
    case MLabelObject::Left:
      tf = QPainter::AlignLeft;
      break;
    case MLabelObject::Center:
      tf = QPainter::AlignHCenter;
      break;
    case MLabelObject::Right:
      tf = QPainter::AlignRight;
  }

  // Vertical
  switch (vAlignment) {
    case MLabelObject::Top:
      tf = tf | QPainter::AlignTop;
      break;
    case MLabelObject::Bottom:
      tf = tf | QPainter::AlignBottom;
      break;
    case MLabelObject::Middle:
      tf = tf | QPainter::AlignVCenter;
  }

  // Word wrap
  if (wordWrap)
    tf = tf | QPainter::WordBreak;

  QRect maxRect = p->painter()->boundingRect(0, 0, width, height, tf, text);
  return (maxRect.height() > height ? maxRect.height() : height);
}
Esempio n. 8
0
// -------------------------------------------------------------
void ViewPainter::init(QPainter *p, float Scale_, int DX_, int DY_, int dx_, int dy_, float FontScale_, float PrintScale_)
{
  Painter = p;
  Scale = Scale_;
  FontScale = FontScale_;
  PrintScale = PrintScale_;
  DX = floor(float(DX_) * Scale) - float(dx_);
  DY = floor(float(DY_) * Scale) - float(dy_);

  QFont f = p->font();
  if(FontScale == 0.0)
    FontScale = Scale;
#ifdef __MINGW32__
  FontScale = Scale;
#endif
  f.setPointSizeFloat( FontScale * float(f.pointSize()) );
  p->setFont(f);
  LineSpacing = p->fontMetrics().lineSpacing();
  p->setWorldXForm(false);   // we use our own coordinate transformation
}
Esempio n. 9
0
// -------------------------------------------------------
void Component::paint(ViewPainter *p)
{
  int x, y, a, b, xb, yb;
  QFont f = p->Painter->font();   // save current font
  QFont newFont = f;
  if(Model.at(0) == '.') {   // is simulation component (dc, ac, ...)
    newFont.setPointSizeFloat(p->Scale * Texts.first()->Size);
    newFont.setWeight(QFont::DemiBold);
    p->Painter->setFont(newFont);
    p->map(cx, cy, x, y);

    p->Painter->setPen(QPen(Qt::darkBlue,2));
    a = b = 0;
    QRect r, t;
    foreach(Text *pt, Texts) {
      t.setRect(x, y+b, 0, 0);
      p->Painter->drawText(t, Qt::AlignLeft|Qt::TextDontClip, pt->s, -1, &r);
      b += r.height();
      if(a < r.width())  a = r.width();
    }
Esempio n. 10
0
// -------------------------------------------------------------
// Returns width of text (and height if pointer is not null).
int ViewPainter::drawTextMapped(const QString& Text, int x1, int y1,
				int *Height)
{
  QRect r;
  int y = 0;
  int x = 0;
  int h = 0;
  int w = 0;
  int i = 0;

  while (!Text[i].isNull()) {
    if ((Text[i].latin1() == '_' || Text[i].latin1() == '^') &&
	!Text[i+1].isNull()) {
      bool is_sub = Text[i++].latin1() == '_';
      int len = 0;

      if (Text[i] == '{') {
        i++;
        while (!Text[i+len].isNull() && Text[i+len].latin1() != '}') len++;
      }

#ifdef __MINGW32__
      float scale = 1.0;
#else
      float scale = PrintScale;
#endif
      QFont fbak = Painter->font();
      QFont f = Painter->font();
      f.setPointSizeFloat(f.pointSizeFloat()*0.8);
      Painter->setFont(f);
      Painter->drawText(x1+x,
			y1+y + (is_sub ? +0.6 : -0.3) *
			fbak.pointSizeFloat() * scale,
			0, 0, Qt::DontClip,
			Text.mid(i, len ? len : 1), -1, &r);
      Painter->setFont(fbak);
      x += r.width();
      if (x > w) w = x;
      i += len ? len + 1 : 1;
    }
    else
    {
      int len = 0;
      while (!Text[i+len].isNull() && Text[i+len].latin1() != '_' &&
	     Text[i+len].latin1() != '^' && Text[i+len].latin1() != '\n')
	len++;
      Painter->drawText(x1+x, y1+y,
			0, 0, Qt::DontClip, Text.mid(i, len), -1, &r);
      if (h < r.height()) {
        h = r.height();
      }
      x += r.width();
      if (x > w) w = x;
      if (Text[i+len].latin1() == '\n') {
	y += h;
	x = 0;
	i++;
      }
      i += len;
    }
  }

  if(Height) *Height = y+h;
  return w;
}
Esempio n. 11
0
void renderGraph(QPainter & paint, const QRect & rect, ORGraphData & gData, XSqlQuery * query, const QMap<QString, QColor> & _colorMap) {
    QPaintDeviceMetrics dpm(paint.device());
    int dpi = dpm.logicalDpiX();

    QFont fnt;

    tGraph graph(rect);
    fnt = gData.font;
    fnt.setPointSizeFloat((100.0/dpi)*fnt.pointSize());
    graph.setFont(fnt);
    if(gData.title.string.length() > 0) {
        graph.setTitle(gData.title.string);
        if(gData.title.font_defined) {
            fnt = gData.title.font;
            fnt.setPointSizeFloat((100.0/dpi)*fnt.pointSize());
            graph.setTitleFont(&fnt);
        }
    }

    QString lbl_clmn = gData.dataaxis.column;
    if(lbl_clmn.length() > 0 && gData.dataaxis.font_defined) {
        fnt = gData.dataaxis.font;
        fnt.setPointSizeFloat((100.0/dpi)*fnt.pointSize());
        graph.setDataFont(&fnt);
    }
    if(gData.dataaxis.title.string.length() > 0) {
        graph.setDataLabel(gData.dataaxis.title.string);
        if(gData.dataaxis.title.font_defined) {
            fnt = gData.dataaxis.title.font;
            fnt.setPointSizeFloat((100.0/dpi)*fnt.pointSize());
            graph.setDataLabelFont(&fnt);
        }
    }

    graph.setAutoMinMax(gData.valueaxis.autominmax);
    graph.setMinValue(gData.valueaxis.min);
    graph.setMaxValue(gData.valueaxis.max);
    if(gData.valueaxis.font_defined) {
        fnt = gData.valueaxis.font;
        fnt.setPointSizeFloat((100.0/dpi)*fnt.pointSize());
        graph.setValueFont(&fnt);
    }
    if(gData.valueaxis.title.string.length() > 0) {
        graph.setValueLabel(gData.valueaxis.title.string);
        if(gData.valueaxis.title.font_defined) {
            fnt = gData.valueaxis.title.font;
            fnt.setPointSizeFloat((100.0/dpi)*fnt.pointSize());
            graph.setValueLabelFont(&fnt);
        }
    }

    // setup the sets/series
    unsigned int snum = 0;
    ORSeriesData * sd = 0;
    for(snum = 0; snum < gData.series.count(); snum++) {
        sd = gData.series.at(snum);
        if(sd) {
            graph.setSetColor(snum, &_colorMap[sd->color]);
            graph.setSetStyle(snum, sd->style);
        }
    }

    // populate the data
    if(query->first()) {
        do {
            if(lbl_clmn.length() > 0) {
                graph.setReferenceLabel(query->at(), query->value(lbl_clmn).toString());
            }
            for(snum = 0; snum < gData.series.count(); snum++) {
                sd = gData.series.at(snum);
                if(sd) {
                    graph.setSetValue(query->at(), snum, query->value(sd->column).toDouble());
                }
            }
        } while(query->next());
    }

    // draw the graph
    graph.draw(paint);
}
Esempio n. 12
0
// -----------------------------------------------------------
// Is called if user clicked on component text of if return is
// pressed in the component text QLineEdit.
// In "view->MAx3" is the number of the current property.
void QucsApp::slotApplyCompText()
{
  QString s;
  QFont f = QucsSettings.font;
  Schematic *Doc = (Schematic*)DocumentTab->currentPage();
  f.setPointSizeFloat( Doc->Scale * float(f.pointSize()) );
  editText->setFont(f);

  Property  *pp = 0;
  Component *pc = (Component*)view->focusElement;
  if(!pc) return;  // should never happen
  view->MAx1 = pc->cx + pc->tx;
  view->MAy1 = pc->cy + pc->ty;

  int z, n=0;  // "n" is number of property on screen
  pp = pc->Props.first();
  for(z=view->MAx3; z>0; z--) {  // calculate "n"
    if(!pp) {  // should never happen
      editText->setHidden(true);
      return;
    }
    if(pp->display) n++;   // is visible ?
    pp = pc->Props.next();
  }
  
  pp = 0;
  if(view->MAx3 > 0)  pp = pc->Props.at(view->MAx3-1); // current property
  else s = pc->Name;

  if(!editText->isHidden()) {   // is called the first time ?
    // no -> apply value to current property
    if(view->MAx3 == 0) {   // component name ?
      Component *pc2;
      if(!editText->text().isEmpty())
        if(pc->Name != editText->text()) {
          for(pc2 = Doc->Components->first(); pc2!=0; pc2 = Doc->Components->next())
            if(pc2->Name == editText->text())
              break;  // found component with the same name ?
          if(!pc2) {
            pc->Name = editText->text();
            Doc->setChanged(true, true);  // only one undo state
          }
        }
    }
    else if(pp) {  // property was applied
      if(pp->Value != editText->text()) {
        pp->Value = editText->text();
        Doc->recreateComponent(pc);  // because of "Num" and schematic symbol
        Doc->setChanged(true, true); // only one undo state
      }
    }

    n++;     // next row on screen
    (view->MAx3)++;  // next property
    pp = pc->Props.at(view->MAx3-1);  // search for next property

    Doc->viewport()->update();
    view->drawn = false;

    if(!pp) {     // was already last property ?
      editText->setHidden(true);
      return;
    }


    while(!pp->display) {  // search for next visible property
      (view->MAx3)++;  // next property
      pp = pc->Props.next();
      if(!pp) {     // was already last property ?
        editText->setHidden(true);
        return;
      }
    }
  }

  // avoid seeing the property text behind the line edit
  if(pp)  // Is it first property or component name ?
    s = pp->Value;
  editText->setMinimumWidth(editText->fontMetrics().width(s)+4);


  Doc->contentsToViewport(int(Doc->Scale * float(view->MAx1 - Doc->ViewX1)),
			 int(Doc->Scale * float(view->MAy1 - Doc->ViewY1)),
			 view->MAx2, view->MAy2);
  editText->setReadOnly(false);
  if(pp) {  // is it a property ?
    s = pp->Value;
    view->MAx2 += editText->fontMetrics().width(pp->Name+"=");
    if(pp->Description.find('[') >= 0)  // is selection list ?
      editText->setReadOnly(true);
    Expr_CompProp.setPattern("[^\"]*");
    if(!pc->showName) n--;
  }
  else   // it is the component name
    Expr_CompProp.setPattern("[\\w_]+");
  Val_CompProp.setRegExp(Expr_CompProp);
  editText->setValidator(&Val_CompProp);

  z = editText->fontMetrics().lineSpacing();
  view->MAy2 += n*z;
  editText->setText(s);
  editText->setPaletteBackgroundColor(QucsSettings.BGColor);
  editText->setFocus();
  editText->selectAll();
  editText->reparent(Doc->viewport(), 0, QPoint(view->MAx2, view->MAy2), true);
}
Esempio n. 13
0
/** Draws the label */
int MLabelObject::draw(FLStylePainter *p)
{
  // Draw the pixmap
  if (!paintFunction.isEmpty()) {
    FLDomNodeInterface *dni = 0;
    QSArgumentList l;
    l << QVariant(text);
    if (!domNodeData.isNull()) {
      dni = new FLDomNodeInterface(domNodeData);
      l << dni;
    }

    QSArgument v = aqApp->call(paintFunction, l, 0);
    QSArgument::Type tp = v.type();
    if (tp != QSArgument::Invalid) {
      QPixmap pix;
      if (tp == QSArgument::VoidPointer) {
        QPixmap *vPix = static_cast<QPixmap *>(v.ptr());
        if (vPix)
          pix = *vPix;
      } else if (tp == QSArgument::Variant)
        pix = v.variant().toPixmap();

      if (!pix.isNull() && drawPixmap(p, &pix))
        return (changeHeight ? height : 0);
    }
  }

  if (pixmap && pixmap->isNull()) {
    delete pixmap;
    pixmap = 0;
  } else if (pixmap && drawPixmap(p, pixmap))
    return (changeHeight ? height : 0);

  if (text.isEmpty()) {
    drawBase(p);
    return 0;
  }

#if defined(Q_OS_MACX)
  FLStylePainter *pt = new FLStylePainter;
  int retVal = 0;
  uint originalHeight = height;
  QFont fnt;
  int tf;

  // Horizontal
  switch (hAlignment) {
    case MLabelObject::Left:
      tf = QPainter::AlignLeft;
      break;
    case MLabelObject::Center:
      tf = QPainter::AlignHCenter;
      break;
    case MLabelObject::Right:
      tf = QPainter::AlignRight;
  }

  // Vertical
  switch (vAlignment) {
    case MLabelObject::Top:
      tf = tf | QPainter::AlignTop;
      break;
    case MLabelObject::Bottom:
      tf = tf | QPainter::AlignBottom;
      break;
    case MLabelObject::Middle:
      tf = tf | QPainter::AlignVCenter;
  }

  // Word wrap
  if (wordWrap)
    tf = tf | QPainter::WordBreak;

  int nw = width * 4;
  int nh = height * 4;
  QPixmap pm(nw, nh);
  pm.fill(backgroundColor);
  pt->painter()->begin(&pm);

  fnt.setFamily(fontFamily);
  fnt.setPointSizeFloat(fontSize * 4);
  fnt.setWeight(fontWeight);
  fnt.setItalic(fontItalic);
  pt->painter()->setFont(fnt);

  if (changeHeight) {
    QRect maxRect(p->painter()->boundingRect(0, 0, nw, nh, tf, text));
    if (maxRect.height() > height) {
      height = maxRect.height();
      retVal = height;
    }
  }

  drawBase(pt);

  pt->painter()->setPen(foregroundColor);

  if (!transparent) {
    pt->painter()->setBackgroundColor(backgroundColor);
    pt->painter()->setBackgroundMode(Qt::OpaqueMode);
  }

  if (adjustFontSize && !wordWrap && !changeHeight) {
    float factor = (float)nw / (float)p->painter()->fontMetrics().width(text);
    if (factor < 1.0) {
      QFont f = p->painter()->font();
      f.setPointSizeFloat(f.pointSizeFloat() * factor);
      p->painter()->setFont(f);
    }
  }

  pt->painter()->drawText(0, 0, nw, nh, tf, text);

  pt->painter()->end();
  delete pt;

  drawPixmap(p, &pm);

  height = originalHeight;
  return retVal;
#else
  int retVal = 0;
  uint originalHeight = height;
  QFont fnt;
  int tf;
  Qt::BGMode oldBgMode;
  QColor oldBgColor;
  bool restoreBg = false;

  // Horizontal
  switch (hAlignment) {
    case MLabelObject::Left:
      tf = QPainter::AlignLeft;
      break;
    case MLabelObject::Center:
      tf = QPainter::AlignHCenter;
      break;
    case MLabelObject::Right:
      tf = QPainter::AlignRight;
  }

  // Vertical
  switch (vAlignment) {
    case MLabelObject::Top:
      tf = tf | QPainter::AlignTop;
      break;
    case MLabelObject::Bottom:
      tf = tf | QPainter::AlignBottom;
      break;
    case MLabelObject::Middle:
      tf = tf | QPainter::AlignVCenter;
  }

  // Word wrap
  if (wordWrap)
    tf = tf | QPainter::WordBreak;

  fnt.setFamily(fontFamily);
  fnt.setPointSizeFloat(fontSize);
  fnt.setWeight(fontWeight);
  fnt.setItalic(fontItalic);
  p->painter()->setFont(fnt);

  if (changeHeight) {
    QRect maxRect(p->painter()->boundingRect(0, 0, width, height, tf, text));
    if (maxRect.height() > height) {
      height = maxRect.height();
      retVal = height;
    }
  }

  drawBase(p);

  p->painter()->setPen(foregroundColor);

  if (!transparent) {
    restoreBg = true;
    oldBgMode = p->painter()->backgroundMode();
    oldBgColor = p->painter()->backgroundColor();
    p->painter()->setBackgroundColor(backgroundColor);
    p->painter()->setBackgroundMode(Qt::OpaqueMode);
  }

  if (!p->drawText(text, tf, this)) {
    bool restore = false;
    if (p->errCode() == FLStylePainter::IdNotFound) {
      p->painter()->save(QObject::name());
      p->applyTransforms();
      p->painter()->translate(xpos, ypos);
      restore = true;
    }

    if (adjustFontSize && !wordWrap && !changeHeight) {
      float factor = (float)width / (float)p->painter()->fontMetrics().width(text);
      if (factor < 1.0) {
        QFont f = p->painter()->font();
        f.setPointSizeFloat(f.pointSizeFloat() * factor);
        p->painter()->setFont(f);
      }
    }

    p->painter()->drawText(0, 0, width, height, tf, text);

    if (restore)
      p->painter()->restore();
  }

  if (restoreBg) {
    p->painter()->setBackgroundMode(oldBgMode);
    p->painter()->setBackgroundColor(oldBgColor);
  }

  height = originalHeight;
  return retVal;
#endif
}
toTreeWidgetItem *toListView::printPage(TOPrinter *printer, QPainter *painter, toTreeWidgetItem *top, int &column, int &level, int pageNo, bool paint)
{
    Q3PaintDeviceMetrics wmetr(this);
    Q3PaintDeviceMetrics metrics(printer);

    double wpscalex = (double(metrics.width()) * wmetr.widthMM() / metrics.widthMM() / wmetr.width());
    double wpscaley = (double(metrics.height()) * wmetr.heightMM() / metrics.heightMM() / wmetr.height());

    painter->save();
    QFont font = painter->font();
    font.setPointSizeFloat(font.pointSizeFloat() / std::max(wpscalex, wpscaley));
    painter->setFont(font);

    painter->scale(wpscalex, wpscaley);

    double mwidth = metrics.width() / wpscalex;
    double mheight = metrics.height() / wpscaley;
    double x = 0;
    if (paint)
    {
        QString numPage(tr("Page: %1").arg(pageNo));
        painter->drawText(0, int(metrics.height() / wpscaley) - header()->height(), int(metrics.width() / wpscalex),
                          header()->height(),
                          Qt::SingleLine | Qt::AlignRight | Qt::AlignVCenter,
                          numPage);
        painter->drawText(0, int(metrics.height() / wpscaley) - header()->height(), int(metrics.width() / wpscalex),
                          header()->height(),
                          Qt::SingleLine | Qt::AlignHCenter | Qt::AlignVCenter,
                          middleString());
        painter->drawText(0, int(metrics.height() / wpscaley) - header()->height(), int(metrics.width() / wpscalex),
                          header()->height(),
                          Qt::SingleLine | Qt::AlignLeft | Qt::AlignVCenter,
                          sqlName());
        painter->drawLine(0, header()->height() - 1, int(mwidth), header()->height() - 1);
    }
    font = toListView::font();
    font.setPointSizeFloat(font.pointSizeFloat() / std::max(wpscalex, wpscaley));
    painter->setFont(font);

    for (int i = column; i < columns(); i++)
    {
        double width = columnWidth(i);
        if (width + x >= mwidth)
        {
            if (i == column)
                width = mwidth - x - 1;
            else
                break;
        }
        if (paint)
            painter->drawText(int(x), 0, int(width),
                              header()->height(),
                              Qt::SingleLine | Qt::AlignLeft | Qt::AlignVCenter, header()->label(i));
        x += width;
    }
    if (paint)
        painter->translate(0, header()->height());

    double y = (header()->height() + 1) + header()->height();
    int curLevel = level;
    int tree = rootIsDecorated() ? treeStepSize() : 0;
    int newCol = -1;
    toTreeWidgetItem *item = top;
    while (item && (y < mheight || item == top))
    {
        if (column == 0)
            x = curLevel;
        else
            x = 0;
        painter->translate(x, 0);
        for (int i = column; i < columns(); i++)
        {
            double width = columnWidth(i);
            if (width + x >= mwidth)
            {
                if (i == column)
                    width = mwidth - x - 1;
                else
                {
                    newCol = i;
                    break;
                }
            }
            if (i == 0)
                width -= curLevel;
            if (paint)
            {
                item->setSelected(false);
                item->paintCell(painter, qApp->palette().active(), i, int(width), columnAlignment(i));
                painter->translate(width, 0);
            }
            x += width;
        }
        if (paint)
            painter->translate(-x, item->height());
        y += item->height();
        if (item->firstChild())
        {
            item = item->firstChild();
            curLevel += tree;
        }
        else if (item->nextSibling())
            item = item->nextSibling();
        else
        {
            do
            {
                item = item->parent();
                curLevel -= tree;
            }
            while (item && !item->nextSibling());
            if (item)
                item = item->nextSibling();
        }
    }
    if (paint)
        painter->drawLine(0, 0, int(mwidth), 0);
    painter->restore();
    if (newCol >= 0)
    {
        column = newCol;
        return top;
    }
    column = 0;
    level = curLevel;
    return item;
}