[Kst] branches/work/kst/portto4/kst/src/libkstapp
Adam Treat
treat at kde.org
Sat May 26 04:37:52 CEST 2007
SVN commit 668338 by treat:
* Create label properly by choosing a spot first
M +5 -15 kstplotcommands.cpp
M +42 -6 kstplotitems.cpp
M +4 -1 kstplotitems.h
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotcommands.cpp #668337:668338
@@ -16,7 +16,6 @@
#include <QDebug>
#include <QObject>
-#include <QInputDialog>
#include <QGraphicsScene>
KstPlotViewCommand::KstPlotViewCommand(const QString &text,
@@ -93,22 +92,13 @@
void CreateLabelCommand::createItem() {
- bool ok;
- QString text = QInputDialog::getText(_view, QObject::tr("label"),
- QObject::tr("label:"), QLineEdit::Normal,
- QString::null, &ok);
- if (ok && !text.isEmpty()) {
- _item = new LabelItem(text, _view);
- _view->scene()->addItem(_item->graphicsItem());
- _item->graphicsItem()->setZValue(1);
+ _item = new LabelItem(_view);
+ connect(_item, SIGNAL(creationComplete()), this, SLOT(creationComplete()));
- //If the item is interrupted while creating itself it will destroy itself
- //need to delete this too in response...
- connect(_item, SIGNAL(destroyed(QObject*)), this, SLOT(deleteLater()));
+ //If the item is interrupted while creating itself it will destroy itself
+ //need to delete this too in response...
+ connect(_item, SIGNAL(destroyed(QObject*)), this, SLOT(deleteLater()));
- creationComplete();
- }
-
}
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotitems.cpp #668337:668338
@@ -12,6 +12,7 @@
#include "kstplotitems.h"
#include <QDebug>
+#include <QInputDialog>
#include <QGraphicsItem>
#include <QGraphicsScene>
@@ -45,14 +46,17 @@
#endif
-LabelItem::LabelItem(const QString &text, KstPlotView *parent)
- : KstPlotItem(parent), QGraphicsSimpleTextItem(text) {
+LabelItem::LabelItem(KstPlotView *parent)
+ : KstPlotItem(parent) {
+ setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable);
+ parent->setMouseMode(KstPlotView::Create);
-#ifdef DEBUG_GEOMETRY
- debugGeometry();
-#endif
+ //If the mouseMode is changed again before we're done with creation
+ //delete ourself.
+ connect(parent, SIGNAL(mouseModeChanged()), this, SLOT(deleteLater()));
- setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable);
+ connect(parent, SIGNAL(creationPolygonChanged(KstPlotView::CreationEvent)),
+ this, SLOT(creationPolygonChanged(KstPlotView::CreationEvent)));
}
@@ -60,6 +64,38 @@
}
+void LabelItem::creationPolygonChanged(KstPlotView::CreationEvent event) {
+ if (event == KstPlotView::MousePress) {
+
+ bool ok;
+ QString text = QInputDialog::getText(parentView(), QObject::tr("label"),
+ QObject::tr("label:"), QLineEdit::Normal,
+ QString::null, &ok);
+ if (!ok || text.isEmpty()) {
+ //This will delete...
+ parentView()->setMouseMode(KstPlotView::Default);
+ return;
+ }
+
+ const QPolygonF poly = mapFromScene(parentView()->creationPolygon(KstPlotView::MousePress));
+ setText(text);
+ setPos(poly[0]);
+ parentView()->scene()->addItem(this);
+ setZValue(1);
+
+#ifdef DEBUG_GEOMETRY
+ debugGeometry();
+#endif
+
+ parentView()->disconnect(this, SLOT(deleteLater())); //Don't delete ourself
+ parentView()->disconnect(this, SLOT(creationPolygonChanged(KstPlotView::CreationEvent)));
+ parentView()->setMouseMode(KstPlotView::Default);
+ emit creationComplete();
+ return;
+ }
+}
+
+
LineItem::LineItem(KstPlotView *parent)
: KstPlotItem(parent) {
setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable);
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotitems.h #668337:668338
@@ -51,10 +51,13 @@
{
Q_OBJECT
public:
- LabelItem(const QString &text, KstPlotView *parent);
+ LabelItem(KstPlotView *parent);
virtual ~LabelItem();
virtual QGraphicsItem *graphicsItem() { return this; }
+
+private Q_SLOTS:
+ void creationPolygonChanged(KstPlotView::CreationEvent event);
};
class LineItem : public KstPlotItem, public QGraphicsLineItem
More information about the Kst
mailing list