[Kst] kdeextragear-2/kst/kst
Andrew Walker
arwalker at sumusltd.com
Sat Jan 3 01:38:37 CET 2004
CVS commit by arwalker:
Provide better positioning of a text label after it has been moved by a drag/drop operation. Also, draw the text properly in the pixmap used during the drag operation, regardless of the text justification used.
M +46 -39 kstlabel.cpp 1.24
M +2 -3 kstlabel.h 1.16
M +8 -6 kstview.cpp 1.69
--- kdeextragear-2/kst/kst/kstlabel.cpp #1.23:1.24
@@ -73,4 +73,9 @@ void KstLabel::setRelPosition(float in_X
}
+void KstLabel::offsetRelPosition(float offset_X, float offset_Y) {
+ _x += offset_X;
+ _y += offset_Y;
+}
+
void KstLabel::setJustification(KstJustifyType in_j) {
if (Justify != in_j) {
@@ -84,5 +89,5 @@ int KstLabel::width(QPainter &p) {
// FIXME: this is still expensive.
if (Width < 0) {
- draw(p, 0, 0, false); // Do a dummy draw to evaluate the width
+ draw(p, 0, 0, true, false); // Do a dummy draw to evaluate the width
}
return int(Width);
@@ -126,5 +131,5 @@ typedef struct GreekCharType {
};
-void KstLabel::draw(QPainter &p, int px, int py, bool doDraw) {
+void KstLabel::draw(QPainter &p, int px, int py, bool bJustify, bool doDraw) {
int w;
int h;
@@ -183,5 +188,5 @@ void KstLabel::draw(QPainter &p, int px,
p.setClipping(false);
- if (doDraw) {
+ if(doDraw) {
w = width(p);
h = ascent(p);
@@ -196,4 +201,5 @@ void KstLabel::draw(QPainter &p, int px,
x = y = 0;
+ if(bJustify) {
switch (Justify) {
case CxBy:
@@ -232,4 +238,5 @@ void KstLabel::draw(QPainter &p, int px,
break;
}
+ }
y_upper = y;
--- kdeextragear-2/kst/kst/kstlabel.h #1.15:1.16
@@ -43,4 +43,5 @@ public:
void setRotation(float new_rotation);
void setRelPosition(float new_x, float new_y);
+ void offsetRelPosition(float offset_x, float offset_y);
void setJustification(KstJustifyType Justify);
@@ -55,5 +56,5 @@ public:
/** draw the label with painter at px, py */
- void draw(QPainter &p, int px, int py, bool doDraw=true);
+ void draw(QPainter &p, int px, int py, bool bJustify=true, bool doDraw=true);
void setSize(int size);
@@ -62,6 +63,4 @@ public:
int size();
- void move(float x, float y) { _x = x; _y = y; }
-
void save(QTextStream &ts);
void read(QDomElement &e);
--- kdeextragear-2/kst/kst/kstview.cpp #1.68:1.69
@@ -471,5 +471,5 @@ void KstView::mouseMoveEvent(QMouseEvent
QPainter p(&pm);
p.setBackgroundColor(KstSettings::globalSettings()->backgroundColor);
- label->draw(p, 2, rectBounding.height() + 2, true);
+ label->draw(p, 0, rectBounding.height(), false);
}
@@ -478,9 +478,9 @@ void KstView::mouseMoveEvent(QMouseEvent
// drawing a partially uninitialised pixmap during the drag operation...
//
- iWidth = rectBounding.width() + 4;
+ iWidth = rectBounding.width();
if( plot->GetWinRegion().width() < iWidth ) {
iWidth = plot->GetWinRegion().width();
}
- iHeight = rectBounding.height() + 4;
+ iHeight = rectBounding.height();
if( plot->GetWinRegion().height() < iHeight ) {
iHeight = plot->GetWinRegion().height();
@@ -840,8 +840,10 @@ void KstView::dropEvent(QDropEvent *e) {
}
- QPoint pos = e->pos() - plotPtr->GetPlotRegion().topLeft() - hs + QPoint(2 /* border offset */, 2 /* border offset */ + 8 /* fudge factor */);
+ QPoint pos = e->pos() - plotPtr->GetWinRegion().topLeft() - hs;
+ QRect rectBounding = l->extents.boundingRect();
+ pos.setX( pos.x() - rectBounding.left() );
+ pos.setY( pos.y() - rectBounding.top() );
QSize divisor = plotPtr->GetPlotRegion().size();
- l->move(float(pos.x())/divisor.width(), float(pos.y())/divisor.height());
- l->extents.translate(pos.x()-hs.x(), pos.y()-hs.y());
+ l->offsetRelPosition(float(pos.x())/divisor.width(), float(pos.y())/divisor.height());
e->accept(true);
update();
More information about the Kst
mailing list