[Kst] branches/work/kst/portto4/kst/src/libkstapp
Adam Treat
treat at kde.org
Fri Aug 24 17:29:53 CEST 2007
SVN commit 704306 by treat:
* More label work
M +42 -8 plotitem.cpp
M +2 -2 plotitem.h
M +6 -9 plotrenderitem.cpp
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #704305:704306
@@ -24,10 +24,13 @@
#include <QDebug>
+static qreal MARGIN_WIDTH = 20.0;
+static qreal MARGIN_HEIGHT = 20.0;
+
namespace Kst {
PlotItem::PlotItem(View *parent)
- : ViewItem(parent), _marginWidth(20), _marginHeight(20) {
+ : ViewItem(parent), _marginWidth(0), _marginHeight(0) {
// FIXME fake data for testing rendering
KstVectorPtr xTest = new KstSVector(0.0, 100.0, 10000, KstObjectTag::fromString("X vector"));
@@ -81,7 +84,7 @@
painter->translate(QPointF(rect().x(), rect().y()));
//Calculate and adjust the margins based on the bounds...
-// calculateLeftLabelBound(painter);
+ calculateLeftLabelBound(painter);
// calculateBottomLabelBound(painter);
// calculateRightLabelBound(painter);
// calculateTopLabelBound(painter);
@@ -101,7 +104,9 @@
QRectF leftLabelRect = verticalLabelRect();
leftLabelRect.moveTopLeft(QPointF(0.0, marginHeight()));
- painter->drawText(t.mapRect(leftLabelRect), Qt::AlignCenter, leftLabel());
+ qDebug() << "leftLabelRect" << leftLabelRect << endl;
+
+ painter->drawText(t.mapRect(leftLabelRect), Qt::TextWordWrap | Qt::AlignCenter, leftLabel());
painter->restore();
}
@@ -117,7 +122,7 @@
QRectF rightLabelRect = verticalLabelRect();
rightLabelRect.moveTopLeft(QPointF(0.0, marginHeight()));
- painter->drawText(t.mapRect(rightLabelRect), Qt::AlignCenter, rightLabel());
+ painter->drawText(t.mapRect(rightLabelRect), Qt::TextWordWrap | Qt::AlignCenter, rightLabel());
painter->restore();
}
@@ -126,7 +131,13 @@
qreal PlotItem::marginWidth() const {
- return _marginWidth;
+ qreal m = qMax(MARGIN_WIDTH, _marginWidth);
+
+ //No more than 1/4 the width of the plot
+ if (width() < m * 4)
+ return width() / 4;
+
+ return m;
}
@@ -137,7 +148,13 @@
qreal PlotItem::marginHeight() const {
- return _marginHeight;
+ qreal m = qMax(MARGIN_HEIGHT, _marginHeight);
+
+ //No more than 1/4 the height of the plot
+ if (height() < m * 4)
+ return height() / 4;
+
+ return m;
}
@@ -194,12 +211,29 @@
void PlotItem::calculateLeftLabelBound(QPainter *painter) {
+
+// painter->save();
+// QTransform t;
+// t.rotate(90.0);
+// painter->rotate(-90.0);
+//
+// QRectF leftLabelRect = verticalLabelRect();
+// leftLabelRect.moveTopLeft(QPointF(0.0, marginHeight()));
+//
+// painter->drawText(t.mapRect(leftLabelRect), Qt::AlignCenter, leftLabel());
+// painter->restore();
+
+
painter->save();
QTransform t;
t.rotate(90.0);
painter->rotate(-90.0);
- QRectF leftLabelBound = painter->boundingRect(t.mapRect(verticalLabelRect()),
- Qt::AlignCenter, leftLabel());
+
+ QRectF leftLabelRect = verticalLabelRect();
+ leftLabelRect.moveTopLeft(QPointF(0.0, marginHeight()));
+
+ QRectF leftLabelBound = painter->boundingRect(t.mapRect(leftLabelRect),
+ Qt::TextWordWrap | Qt::AlignCenter, leftLabel());
painter->restore();
qDebug() << leftLabelBound << endl;
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.h #704305:704306
@@ -32,8 +32,8 @@
virtual ~PlotItem();
void paint(QPainter *painter);
- qreal width() const { return viewRect().width(); }
- qreal height() const { return viewRect().height(); }
+ qreal width() const { return viewRect().normalized().width(); }
+ qreal height() const { return viewRect().normalized().height(); }
qreal marginWidth() const;
void setMarginWidth(qreal marginWidth);
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.cpp #704305:704306
@@ -34,14 +34,11 @@
void PlotRenderItem::updateGeometry() {
- //FIXME bound this so that the rect is never larger than parent rect...
- QRectF rect = plotItem()->rect();
- rect = rect.normalized();
- rect = rect.adjusted(plotItem()->marginWidth(),
- plotItem()->marginHeight(),
- -(plotItem()->marginHeight()),
- -(plotItem()->marginHeight()));
- setRect(rect);
+ QRectF rect = plotItem()->rect().normalized();
+ QPointF margin(plotItem()->marginWidth(), plotItem()->marginHeight());
+ QPointF topLeft(rect.topLeft() + margin);
+ QPointF bottomRight(rect.bottomRight() - margin);
+ setRect(QRectF(topLeft, bottomRight));
}
@@ -77,7 +74,7 @@
Q_UNUSED(option);
Q_UNUSED(widget);
painter->fillRect(rect(), Qt::white);
- paint(painter);
+// paint(painter);
}
More information about the Kst
mailing list