本文整理汇总了C++中QwtMetricsMap类的典型用法代码示例。如果您正苦于以下问题:C++ QwtMetricsMap类的具体用法?C++ QwtMetricsMap怎么用?C++ QwtMetricsMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QwtMetricsMap类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: heightForWidth
/*!
Find the height for a given width
\param defaultFont Font, used for the calculation if the text has no font
\param width Width
\return Calculated height
*/
int QwtText::heightForWidth(int width, const QFont &defaultFont) const
{
const QwtMetricsMap map = QwtPainter::metricsMap();
width = map.layoutToScreenX(width);
#if QT_VERSION < 0x040000
const QFont font = usedFont(defaultFont);
#else
// We want to calculate in screen metrics. So
// we need a font that uses screen metrics
const QFont font(usedFont(defaultFont), QApplication::desktop());
#endif
int h = 0;
if ( d_data->layoutAttributes & MinimumLayout ) {
int left, right, top, bottom;
d_data->textEngine->textMargins(font, d_data->text,
left, right, top, bottom);
h = d_data->textEngine->heightForWidth(
font, d_data->renderFlags, d_data->text,
width + left + right);
h -= top + bottom;
} else {
h = d_data->textEngine->heightForWidth(
font, d_data->renderFlags, d_data->text, width);
}
h = map.screenToLayoutY(h);
return h;
}
示例2: fnt
QSize QwtText::textSize(const QFont &font) const
{
#if QT_VERSION < 0x040000
const QFont fnt(usedFont(font));
#else
// We want to calculate in screen metrics. So
// we need a font that uses screen metrics
const QFont fnt(usedFont(font), QApplication::desktop());
#endif
if ( !d_layoutCache->textSize.isValid()
|| d_layoutCache->font != fnt )
{
d_layoutCache->textSize = d_data->textEngine->textSize(
fnt, d_data->flags, d_data->text);
d_layoutCache->font = fnt;
}
QSize sz = d_layoutCache->textSize;
if ( d_data->layoutAttributes & MinimumLayout )
{
int left, right, top, bottom;
d_data->textEngine->textMargins(fnt, d_data->text,
left, right, top, bottom);
sz -= QSize(left + right, top + bottom);
}
const QwtMetricsMap map = QwtPainter::metricsMap();
sz = map.screenToLayout(sz);
return sz;
}
示例3: switch
void QwtScaleWidget::drawTitle(QPainter *painter,
QwtScaleDraw::Alignment align, const QRect &rect) const
{
QRect r;
double angle;
int flags = d_data->title.renderFlags() &
~(Qt::AlignTop | Qt::AlignBottom | Qt::AlignVCenter);
switch(align)
{
case QwtScaleDraw::LeftScale:
flags |= Qt::AlignTop;
angle = -90.0;
r.setRect(rect.left(), rect.bottom(), rect.height(), rect.width());
break;
case QwtScaleDraw::RightScale:
flags |= Qt::AlignTop;
angle = 90.0;
r.setRect(rect.right(), rect.top(), rect.height(), rect.width());
break;
case QwtScaleDraw::TopScale:
flags |= Qt::AlignTop;
angle = 0.0;
r = rect;
break;
case QwtScaleDraw::BottomScale:
default:
flags |= Qt::AlignBottom;
angle = 0.0;
r = rect;
break;
}
painter->save();
painter->setFont(font());
#if QT_VERSION < 0x040000
painter->setPen(colorGroup().color(QColorGroup::Text));
#else
painter->setPen(palette().color(QPalette::Text));
#endif
const QwtMetricsMap metricsMap = QwtPainter::metricsMap();
QwtPainter::resetMetricsMap();
r = metricsMap.layoutToDevice(r);
painter->translate(r.x(), r.y());
if (angle != 0.0)
painter->rotate(angle);
QwtText title = d_data->title;
title.setRenderFlags(flags);
title.draw(painter, QRect(0, 0, r.width(), r.height()));
QwtPainter::setMetricsMap(metricsMap); // restore metrics map
painter->restore();
}
示例4: font
/*!
Returns the size, that is needed to render text
\param defaultFont Font of the text
\return Caluclated size
*/
QSize QwtText::textSize(const QFont &defaultFont) const
{
#if QT_VERSION < 0x040000
const QFont font(usedFont(defaultFont));
#else
// We want to calculate in screen metrics. So
// we need a font that uses screen metrics
const QFont font(usedFont(defaultFont), QApplication::desktop());
#endif
if ( !d_layoutCache->textSize.isValid()
|| d_layoutCache->font != font )
{
d_layoutCache->textSize = d_data->textEngine->textSize(
font, d_data->renderFlags, d_data->text);
d_layoutCache->font = font;
}
QSize sz = d_layoutCache->textSize;
const QwtMetricsMap map = QwtPainter::metricsMap();
if ( d_data->layoutAttributes & MinimumLayout )
{
int left, right, top, bottom;
d_data->textEngine->textMargins(font, d_data->text,
left, right, top, bottom);
sz -= QSize(left + right, top + bottom);
#if QT_VERSION >= 0x040000
if ( !map.isIdentity() )
{
#ifdef __GNUC__
#warning Too small text size, when printing in high resolution
#endif
/*
When printing in high resolution, the tick labels
of are cut of. We need to find out why, but for
the moment we add a couple of pixels instead.
*/
sz += QSize(3, 2);
}
#endif
}
sz = map.screenToLayout(sz);
return sz;
}
示例5: majTickLength
void ScaleDraw::drawBreak(QPainter *painter) const {
ScaleEngine *sc_engine =
static_cast<ScaleEngine *>(d_plot->axisScaleEngine(axis()));
/*const QwtScaleEngine * qwtsc_engine=d_plot->axisScaleEngine(axis());
const ScaleEngine *sc_engine =dynamic_cast<const ScaleEngine*>(qwtsc_engine);
if(sc_engine!=NULL)
{*/
if (!sc_engine->hasBreak() || !sc_engine->hasBreakDecoration())
return;
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
int len = majTickLength();
QwtScaleMap scaleMap = map();
const QwtMetricsMap metricsMap = QwtPainter::metricsMap();
QPoint pos = this->pos();
if (!metricsMap.isIdentity()) {
QwtPainter::resetMetricsMap();
pos = metricsMap.layoutToDevice(pos);
if (orientation() == Qt::Vertical) {
scaleMap.setPaintInterval(metricsMap.layoutToDeviceY((int)scaleMap.p1()),
metricsMap.layoutToDeviceY((int)scaleMap.p2()));
len = metricsMap.layoutToDeviceX(len);
} else {
scaleMap.setPaintInterval(metricsMap.layoutToDeviceX((int)scaleMap.p1()),
metricsMap.layoutToDeviceX((int)scaleMap.p2()));
len = metricsMap.layoutToDeviceY(len);
}
}
int lval = scaleMap.transform(sc_engine->axisBreakLeft());
int rval = scaleMap.transform(sc_engine->axisBreakRight());
switch (alignment()) {
case LeftScale:
QwtPainter::drawLine(painter, pos.x(), lval, pos.x() - len, lval + len);
QwtPainter::drawLine(painter, pos.x(), rval, pos.x() - len, rval + len);
break;
case RightScale:
QwtPainter::drawLine(painter, pos.x(), lval, pos.x() + len, lval - len);
QwtPainter::drawLine(painter, pos.x(), rval, pos.x() + len, rval - len);
break;
case BottomScale:
QwtPainter::drawLine(painter, lval, pos.y(), lval - len, pos.y() + len);
QwtPainter::drawLine(painter, rval, pos.y(), rval - len, pos.y() + len);
break;
case TopScale:
QwtPainter::drawLine(painter, lval, pos.y(), lval + len, pos.y() - len);
QwtPainter::drawLine(painter, rval, pos.y(), rval + len, pos.y() - len);
break;
}
QwtPainter::setMetricsMap(metricsMap); // restore metrics map
painter->restore();
//}
}
示例6: map
void ScaleDraw::drawBreak(QPainter *painter) const
{
ScaleEngine *sc_engine = (ScaleEngine *)d_plot->axisScaleEngine(axis());
if (!sc_engine->hasBreak() || !sc_engine->hasBreakDecoration())
return;
painter->save();
painter->setRenderHint(QPainter::Antialiasing);
QPen pen = painter->pen();
pen.setColor(d_plot->axisWidget(axis())->palette().color(QPalette::Active, QColorGroup::Foreground));
painter->setPen(pen);
int len = d_plot->majorTickLength();
QwtScaleMap scaleMap = map();
const QwtMetricsMap metricsMap = QwtPainter::metricsMap();
QPoint pos = this->pos();
if (!d_plot->isPrinting()){
QwtPainter::resetMetricsMap();
pos = metricsMap.layoutToDevice(pos);
if ( orientation() == Qt::Vertical ){
scaleMap.setPaintInterval(
metricsMap.layoutToDeviceY((int)scaleMap.p1()),
metricsMap.layoutToDeviceY((int)scaleMap.p2()));
len = metricsMap.layoutToDeviceX(len);
} else {
scaleMap.setPaintInterval(
metricsMap.layoutToDeviceX((int)scaleMap.p1()),
metricsMap.layoutToDeviceX((int)scaleMap.p2()));
len = metricsMap.layoutToDeviceY(len);
}
}
int lval = scaleMap.transform(sc_engine->axisBreakLeft());
int rval = scaleMap.transform(sc_engine->axisBreakRight());
switch(alignment()){
case LeftScale:
case RightScale:
QwtPainter::drawLine(painter, pos.x() + len, lval - len, pos.x() - len, lval + len);
QwtPainter::drawLine(painter, pos.x() + len, rval - len, pos.x() - len, rval + len);
break;
case TopScale:
case BottomScale:
QwtPainter::drawLine(painter, lval + len, pos.y() - len, lval - len, pos.y() + len);
QwtPainter::drawLine(painter, rval + len, pos.y() - len, rval - len, pos.y() + len);
break;
}
if (!d_plot->isPrinting())
QwtPainter::setMetricsMap(metricsMap); // restore metrics map
painter->restore();
}
示例7: legend
void QwtPlot::printLegend(QPainter *painter, const QRect &rect) const
{
if ( !legend() || legend()->isEmpty() )
return;
QLayout *l = legend()->contentsWidget()->layout();
if ( l == 0 || !l->inherits("QwtDynGridLayout") )
return;
QwtDynGridLayout *legendLayout = (QwtDynGridLayout *)l;
uint numCols = legendLayout->columnsForWidth(rect.width());
#if QT_VERSION < 0x040000
QValueList<QRect> itemRects =
legendLayout->layoutItems(rect, numCols);
#else
QList<QRect> itemRects =
legendLayout->layoutItems(rect, numCols);
#endif
int index = 0;
#if QT_VERSION < 0x040000
QLayoutIterator layoutIterator = legendLayout->iterator();
for ( QLayoutItem *item = layoutIterator.current();
item != 0; item = ++layoutIterator) {
#else
for ( int i = 0; i < legendLayout->count(); i++ ) {
QLayoutItem *item = legendLayout->itemAt(i);
#endif
QWidget *w = item->widget();
if ( w ) {
painter->save();
painter->setClipping(true);
QwtPainter::setClipRect(painter, itemRects[index]);
printLegendItem(painter, w, itemRects[index]);
index++;
painter->restore();
}
}
}
/*!
Print the legend item into a given rectangle.
\param painter Painter
\param w Widget representing a legend item
\param rect Bounding rectangle
*/
void QwtPlot::printLegendItem(QPainter *painter,
const QWidget *w, const QRect &rect) const
{
if ( w->inherits("QwtLegendItem") ) {
QwtLegendItem *item = (QwtLegendItem *)w;
painter->setFont(item->font());
item->drawItem(painter, rect);
}
}
/*!
\brief Paint a scale into a given rectangle.
Paint the scale into a given rectangle.
\param painter Painter
\param axisId Axis
\param startDist Start border distance
\param endDist End border distance
\param baseDist Base distance
\param rect Bounding rectangle
*/
void QwtPlot::printScale(QPainter *painter,
int axisId, int startDist, int endDist, int baseDist,
const QRect &rect) const
{
if (!axisEnabled(axisId))
return;
const QwtScaleWidget *scaleWidget = axisWidget(axisId);
if ( scaleWidget->isColorBarEnabled()
&& scaleWidget->colorBarWidth() > 0) {
const QwtMetricsMap map = QwtPainter::metricsMap();
QRect r = map.layoutToScreen(rect);
r.setWidth(r.width() - 1);
r.setHeight(r.height() - 1);
scaleWidget->drawColorBar(painter, scaleWidget->colorBarRect(r));
const int off = scaleWidget->colorBarWidth() + scaleWidget->spacing();
if ( scaleWidget->scaleDraw()->orientation() == Qt::Horizontal )
baseDist += map.screenToLayoutY(off);
else
baseDist += map.screenToLayoutX(off);
}
//.........这里部分代码省略.........
示例8: drawBackbone
/*!
Draw a tick
\param painter Painter
\param value Value of the tick
\param len Lenght of the tick
\sa drawBackbone(), drawLabel()
*/
void QwtScaleDraw::drawTick(QPainter *painter, double value, int len) const
{
if ( len <= 0 )
return;
int pw2 = qwtMin((int)painter->pen().width(), len) / 2;
QwtScaleMap scaleMap = map();
const QwtMetricsMap metricsMap = QwtPainter::metricsMap();
QPoint pos = d_data->pos;
if ( !metricsMap.isIdentity() )
{
/*
The perfect position of the ticks is important.
To avoid rounding errors we have to use
device coordinates.
*/
QwtPainter::resetMetricsMap();
pos = metricsMap.layoutToDevice(pos);
if ( orientation() == Qt::Vertical )
{
scaleMap.setPaintInterval(
metricsMap.layoutToDeviceY((int)scaleMap.p1()),
metricsMap.layoutToDeviceY((int)scaleMap.p2())
);
len = metricsMap.layoutToDeviceX(len);
}
else
{
scaleMap.setPaintInterval(
metricsMap.layoutToDeviceX((int)scaleMap.p1()),
metricsMap.layoutToDeviceX((int)scaleMap.p2())
);
len = metricsMap.layoutToDeviceY(len);
}
}
const int tval = scaleMap.transform(value);
switch(alignment())
{
case LeftScale:
{
#if QT_VERSION < 0x040000
QwtPainter::drawLine(painter, pos.x() + pw2, tval,
pos.x() - len - 2 * pw2, tval);
#else
QwtPainter::drawLine(painter, pos.x() - pw2, tval,
pos.x() - len, tval);
#endif
break;
}
case RightScale:
{
#if QT_VERSION < 0x040000
QwtPainter::drawLine(painter, pos.x(), tval,
pos.x() + len + pw2, tval);
#else
QwtPainter::drawLine(painter, pos.x() + pw2, tval,
pos.x() + len, tval);
#endif
break;
}
case BottomScale:
{
#if QT_VERSION < 0x040000
QwtPainter::drawLine(painter, tval, pos.y(),
tval, pos.y() + len + 2 * pw2);
#else
QwtPainter::drawLine(painter, tval, pos.y() + pw2,
tval, pos.y() + len);
#endif
break;
}
case TopScale:
{
#if QT_VERSION < 0x040000
QwtPainter::drawLine(painter, tval, pos.y() + pw2,
tval, pos.y() - len - 2 * pw2);
#else
QwtPainter::drawLine(painter, tval, pos.y() - pw2,
tval, pos.y() - len);
#endif
break;
}
//.........这里部分代码省略.........
示例9: axisWidget
void Plot::printScale(QPainter *painter, int axisId, int startDist, int endDist,
int baseDist, const QRect &rect) const
{
if (!axisEnabled(axisId))
return;
const QwtScaleWidget *scaleWidget = axisWidget(axisId);
if ( scaleWidget->isColorBarEnabled()
&& scaleWidget->colorBarWidth() > 0)
{
const QwtMetricsMap map = QwtPainter::metricsMap();
const QRect r = map.layoutToScreen(rect);
scaleWidget->drawColorBar(painter, scaleWidget->colorBarRect(r));
const int off = scaleWidget->colorBarWidth() + scaleWidget->spacing();
if ( scaleWidget->scaleDraw()->orientation() == Qt::Horizontal )
baseDist += map.screenToLayoutY(off);
else
baseDist += map.screenToLayoutX(off);
}
QwtScaleDraw::Alignment align;
int x, y, w;
const int bw2 = scaleWidget->penWidth() / 2;
switch(axisId)
{
case yLeft:
{
x = rect.right() - baseDist + 1 - bw2;
y = rect.y() + startDist;
w = rect.height() - startDist - endDist;
align = QwtScaleDraw::LeftScale;
break;
}
case yRight:
{
x = rect.left() + baseDist;
if (scaleWidget->penWidth() % 2 == 0)
x += 1;
y = rect.y() + startDist;
w = rect.height() - startDist - endDist + bw2;
align = QwtScaleDraw::RightScale;
break;
}
case xTop:
{
x = rect.left() + startDist;
y = rect.bottom() - baseDist + 1;
if (scaleWidget->penWidth() % 2 == 0)
y -= bw2;
w = rect.width() - startDist - endDist;
align = QwtScaleDraw::TopScale;
break;
}
case xBottom:
{
x = rect.left() + startDist;
y = rect.top() + baseDist;
if (scaleWidget->penWidth() % 2 == 1)
y += bw2;
w = rect.width() - startDist - endDist + bw2;
align = QwtScaleDraw::BottomScale;
break;
}
default:
return;
}
scaleWidget->drawTitle(painter, align, rect);
painter->save();
painter->setFont(scaleWidget->font());
QPen pen = painter->pen();
pen.setWidth(scaleWidget->penWidth());
painter->setPen(pen);
QwtScaleDraw *sd = (QwtScaleDraw *)scaleWidget->scaleDraw();
const QPoint sdPos = sd->pos();
const int sdLength = sd->length();
sd->move(x, y);
sd->setLength(w);
#if QT_VERSION < 0x040000
sd->draw(painter, scaleWidget->palette().active());
#else
QPalette palette = scaleWidget->palette();
palette.setCurrentColorGroup(QPalette::Active);
sd->draw(painter, palette);
#endif
// reset previous values
sd->move(sdPos);
sd->setLength(sdLength);
//.........这里部分代码省略.........
示例10: r
/*!
Draw a text into a rectangle
\param painter Painter
\param rect Rectangle
*/
void QwtText::draw(QPainter *painter, const QRect &rect) const
{
if ( d_data->paintAttributes & PaintBackground )
{
if ( d_data->backgroundPen != Qt::NoPen ||
d_data->backgroundBrush != Qt::NoBrush )
{
painter->save();
painter->setPen(QwtPainter::scaledPen(d_data->backgroundPen));
painter->setBrush(d_data->backgroundBrush);
#if QT_VERSION < 0x040000
QwtPainter::drawRect(painter, rect);
#else
const QRect r(rect.x(), rect.y(),
rect.width() - 1, rect.height() - 1);
QwtPainter::drawRect(painter, r);
#endif
painter->restore();
}
}
painter->save();
if ( d_data->paintAttributes & PaintUsingTextFont )
{
painter->setFont(d_data->font);
}
if ( d_data->paintAttributes & PaintUsingTextColor )
{
if ( d_data->color.isValid() )
painter->setPen(d_data->color);
}
QRect expandedRect = rect;
if ( d_data->layoutAttributes & MinimumLayout )
{
#if QT_VERSION < 0x040000
const QFont font(painter->font());
#else
// We want to calculate in screen metrics. So
// we need a font that uses screen metrics
const QFont font(painter->font(), QApplication::desktop());
#endif
int left, right, top, bottom;
d_data->textEngine->textMargins(
font, d_data->text,
left, right, top, bottom);
const QwtMetricsMap map = QwtPainter::metricsMap();
left = map.screenToLayoutX(left);
right = map.screenToLayoutX(right);
top = map.screenToLayoutY(top);
bottom = map.screenToLayoutY(bottom);
expandedRect.setTop(rect.top() - top);
expandedRect.setBottom(rect.bottom() + bottom);
expandedRect.setLeft(rect.left() - left);
expandedRect.setRight(rect.right() + right);
}
d_data->textEngine->draw(painter, expandedRect,
d_data->renderFlags, d_data->text);
painter->restore();
}
示例11: qwtMin
void ScaleDraw::drawInwardTick(QPainter *painter, double value, int len) const
{
ScaleEngine *sc_engine = (ScaleEngine *)d_plot->axisScaleEngine(axis());
if (sc_engine->hasBreak() && (sc_engine->axisBreakLeft() <= value && sc_engine->axisBreakRight() >= value))
return;
int pw2 = qwtMin((int)painter->pen().width(), len) / 2;
QwtScaleMap scaleMap = map();
const QwtMetricsMap metricsMap = QwtPainter::metricsMap();
QPoint pos = this->pos();
int majLen = tickLength(QwtScaleDiv::MajorTick);
if ( !metricsMap.isIdentity() ){
/*
The perfect position of the ticks is important.
To avoid rounding errors we have to use
device coordinates.
*/
QwtPainter::resetMetricsMap();
pos = metricsMap.layoutToDevice(pos);
if ( orientation() == Qt::Vertical ){
scaleMap.setPaintInterval(
metricsMap.layoutToDeviceY((int)scaleMap.p1()),
metricsMap.layoutToDeviceY((int)scaleMap.p2())
);
len = metricsMap.layoutToDeviceX(len);
majLen = metricsMap.layoutToDeviceX(majLen);
} else {
scaleMap.setPaintInterval(
metricsMap.layoutToDeviceX((int)scaleMap.p1()),
metricsMap.layoutToDeviceX((int)scaleMap.p2())
);
len = metricsMap.layoutToDeviceY(len);
majLen = metricsMap.layoutToDeviceY(majLen);
}
}
const int clw = d_plot->canvasLineWidth();
const int tval = scaleMap.transform(value);
bool draw = false;
if ( orientation() == Qt::Vertical ){
int low = (int)scaleMap.p2() + majLen;
int high = (int)scaleMap.p1() - majLen;
if ((tval > low && tval < high) ||
(tval > high && !d_plot->axisEnabled (QwtPlot::xBottom) && !clw) ||
(tval < low && !d_plot->axisEnabled(QwtPlot::xTop) && !clw)) draw = true;
} else {
int low = (int)scaleMap.p1() + majLen;
int high = (int)scaleMap.p2() - majLen;
if ((tval > low && tval < high) ||
(tval > high && !d_plot->axisEnabled(QwtPlot::yRight) && !clw) ||
(tval < low && !d_plot->axisEnabled(QwtPlot::yLeft) && !clw)) draw = true;
}
if (draw){
switch(alignment()){
case LeftScale:
{
QwtPainter::drawLine(painter, pos.x() + pw2, tval, pos.x() + len, tval);
break;
}
case RightScale:
{
QwtPainter::drawLine(painter, pos.x() - pw2, tval, pos.x() - len, tval);
break;
}
case BottomScale:
{
QwtPainter::drawLine(painter, tval, pos.y() - pw2, tval, pos.y() - len);
break;
}
case TopScale:
{
QwtPainter::drawLine(painter, tval, pos.y() + pw2, tval, pos.y() + len);
break;
}
}
}
QwtPainter::setMetricsMap(metricsMap); // restore metrics map
}
示例12: scaleDiv
void ScaleDraw::drawLabel(QPainter *painter, double value) const
{
if (!d_plot)
return;
ScaleEngine *sc_engine = (ScaleEngine *)d_plot->axisScaleEngine(axis());
if (sc_engine->hasBreak() && sc_engine->axisBreakLeft() <= value && sc_engine->axisBreakRight() > value)
return;
QwtValueList majTicks = scaleDiv().ticks(QwtScaleDiv::MajorTick);
if (majTicks.contains(value)){
switch (d_show_ticks_policy){
case ShowAll:
break;
case HideBegin:
if (majTicks.first() == value)
return;
break;
case HideEnd:
if (majTicks.last() == value)
return;
break;
case HideBeginEnd:
if (majTicks.first() == value || majTicks.last() == value)
return;
break;
}
}
QwtText lbl = tickLabel(painter->font(), value);
if ( lbl.isEmpty() )
return;
QPoint pos = labelPosition(value);
QSize labelSize = lbl.textSize(painter->font());
if ( labelSize.height() % 2 )
labelSize.setHeight(labelSize.height() + 1);
const QwtMetricsMap metricsMap = QwtPainter::metricsMap();
QwtPainter::resetMetricsMap();
labelSize = metricsMap.layoutToDevice(labelSize);
pos = metricsMap.layoutToDevice(pos);
painter->save();
painter->setMatrix(labelMatrix( pos, labelSize), true);
if (d_selected)
lbl.setBackgroundPen(QPen(Qt::blue));
else
lbl.setBackgroundPen(QPen(Qt::NoPen));
lbl.setRenderFlags(labelAlignment());
lbl.draw (painter, QRect(QPoint(0, 0), labelSize) );
QwtPainter::setMetricsMap(metricsMap); // restore metrics map
painter->restore();
}
示例13: legend
//.........这里部分代码省略.........
break;
}
default:
return;
}
const QwtScaleWidget *scaleWidget = axisWidget(axisId);
scaleWidget->drawTitle(painter, align, rect);
painter->save();
painter->setFont(scaleWidget->font());
QwtScaleDraw *sd = (QwtScaleDraw *)scaleWidget->scaleDraw();
const QPoint sdPos = sd->pos();
const int sdLength = sd->length();
sd->move(x, y);
sd->setLength(w);
#if QT_VERSION < 0x040000
sd->draw(painter, scaleWidget->palette().active());
#else
QPalette palette = scaleWidget->palette();
palette.setCurrentColorGroup(QPalette::Active);
sd->draw(painter, palette);
#endif
// reset previous values
sd->move(sdPos);
sd->setLength(sdLength);
painter->restore();
}
/*!
Print the canvas into a given rectangle.
\param painter Painter
\param map Maps mapping between plot and paint device coordinates
\param canvasRect Bounding rectangle
\param pfilter Print filter
\sa QwtPlotPrintFilter
*/
void QwtPlot::printCanvas(QPainter *painter, const QRect &canvasRect,
const QwtArray<QwtScaleMap> &map, const QwtPlotPrintFilter &pfilter) const
{
if ( pfilter.options() & QwtPlotPrintFilter::PrintCanvasBackground )
{
painter->setPen(Qt::NoPen);
QBrush bgBrush;
#if QT_VERSION >= 0x040000
bgBrush = canvas()->palette().brush(backgroundRole());
#else
QColorGroup::ColorRole role =
QPalette::backgroundRoleFromMode( backgroundMode() );
bgBrush = canvas()->colorGroup().brush( role );
#endif
painter->setBrush(bgBrush);
int x1 = 0;
int x2 = 0;
int y1 = 0;
int y2 = 0;
#if QT_VERSION >= 0x040000
switch(painter->device()->paintEngine()->type())
{
case QPaintEngine::PostScript:
x2 = 1;
y2 = 1;
break;
default:;
}
#endif
const QwtMetricsMap map = QwtPainter::metricsMap();
x1 = map.screenToLayoutX(x1);
x2 = map.screenToLayoutX(x2);
y1 = map.screenToLayoutY(y1);
y2 = map.screenToLayoutY(y2);
QwtPainter::drawRect(painter,
canvasRect.x() + x1, canvasRect.y() + y1,
canvasRect.width() - x2, canvasRect.height() - y2);
}
else
{
// Paint the canvas borders instead.
painter->setPen(QPen(Qt::black));
painter->setBrush(QBrush(Qt::NoBrush));
QwtPainter::drawRect(painter, canvasRect);
}
painter->setClipping(true);
QwtPainter::setClipRect(painter, canvasRect);
drawItems(painter, canvasRect, map, pfilter);
}