[Kst] branches/work/kst/portto4/kst/src/libkstapp
Adam Treat
treat at kde.org
Fri May 25 05:32:17 CEST 2007
SVN commit 668094 by treat:
* Add some lines
M +11 -0 kstmainwindow.cpp
M +3 -0 kstmainwindow.h
M +1 -1 kstplotcommands.cpp
M +21 -3 kstplotitems.cpp
M +13 -1 kstplotitems.h
M +1 -1 kstplotview.cpp
--- branches/work/kst/portto4/kst/src/libkstapp/kstmainwindow.cpp #668093:668094
@@ -102,6 +102,12 @@
}
+void KstMainWindow::createLine() {
+ CreateLineCommand *cmd = new CreateLineCommand;
+ cmd->createItem();
+}
+
+
void KstMainWindow::createActions() {
_undoAct = _undoGroup->createUndoAction(this);
_redoAct = _undoGroup->createRedoAction(this);
@@ -110,6 +116,10 @@
_createLabelAct->setStatusTip(tr("Create a label for the current plot"));
connect(_createLabelAct, SIGNAL(triggered()), this, SLOT(createLabel()));
+ _createLineAct = new QAction(tr("&Create line"), this);
+ _createLineAct->setStatusTip(tr("Create a line for the current plot"));
+ connect(_createLineAct, SIGNAL(triggered()), this, SLOT(createLine()));
+
_exitAct = new QAction(tr("E&xit"), this);
_exitAct->setShortcut(tr("Ctrl+Q"));
_exitAct->setStatusTip(tr("Exit the application"));
@@ -135,6 +145,7 @@
_plotMenu = menuBar()->addMenu(tr("&Plot"));
_plotMenu->addAction(_createLabelAct);
+ _plotMenu->addAction(_createLineAct);
_settingsMenu = menuBar()->addMenu(tr("&Settings"));
--- branches/work/kst/portto4/kst/src/libkstapp/kstmainwindow.h #668093:668094
@@ -39,7 +39,9 @@
void about();
void currentPlotChanged();
void plotViewDestroyed(QObject *object);
+
void createLabel();
+ void createLine();
private:
void createActions();
@@ -66,6 +68,7 @@
QAction *_undoAct;
QAction *_redoAct;
QAction *_createLabelAct;
+ QAction *_createLineAct;
QAction *_exitAct;
QAction *_aboutAct;
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotcommands.cpp #668093:668094
@@ -92,7 +92,7 @@
void CreateLineCommand::createItem() {
- /*nada yet*/
+ _item = new LineItem(_view);
}
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotitems.cpp #668093:668094
@@ -14,6 +14,7 @@
#include <QDebug>
#include <QGraphicsItem>
+#include <QGraphicsScene>
KstPlotItem::KstPlotItem(KstPlotView *parent)
: QObject(parent) {
@@ -39,12 +40,29 @@
}
-void LabelItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
- qDebug() << "LabelItem::mousePressEvent" << endl;
- QGraphicsItem::mousePressEvent(event);
+LineItem::LineItem(KstPlotView *parent)
+ : KstPlotItem(parent) {
+
+ parent->setMouseMode(KstPlotView::Create);
+ connect(parent, SIGNAL(creationPolygonChanged()),
+ this, SLOT(creationPolygonChanged()));
}
+LineItem::~LineItem() {
+}
+
+
+void LineItem::creationPolygonChanged() {
+ const QPolygonF poly = mapFromScene(parentView()->creationPolygon());
+ if (poly.count() > 1) {
+ setLine(QLineF(poly[0], poly[1]));
+ parentView()->scene()->addItem(this);
+ parentView()->setMouseMode(KstPlotView::Default);
+ parentView()->disconnect(this);
+ }
+}
+
#include "kstplotitems.moc"
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotitems.h #668093:668094
@@ -13,6 +13,7 @@
#define KSTPLOTITEMS_H
#include <QObject>
+#include <QGraphicsLineItem>
#include <QGraphicsSimpleTextItem>
#include "kst_export.h"
@@ -40,8 +41,19 @@
virtual ~LabelItem();
virtual QGraphicsItem *graphicsItem() { return this; }
+};
- virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
+class LineItem : public KstPlotItem, public QGraphicsLineItem
+{
+ Q_OBJECT
+public:
+ LineItem(KstPlotView *parent);
+ virtual ~LineItem();
+
+ virtual QGraphicsItem *graphicsItem() { return this; }
+
+private Q_SLOTS:
+ void creationPolygonChanged();
};
#endif
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotview.cpp #668093:668094
@@ -70,7 +70,7 @@
{
QGraphicsSceneMouseEvent *e = static_cast<QGraphicsSceneMouseEvent*>(event);
if (_mouseMode == Create) {
- _creationPolygon << e->buttonDownScreenPos(Qt::LeftButton);
+ _creationPolygon << e->buttonDownScenePos(Qt::LeftButton);
emit creationPolygonChanged();
return false;
}
More information about the Kst
mailing list