[Kst] branches/work/kst/portto4/kst/src/libkstapp

Adam Treat treat at kde.org
Fri May 25 01:19:44 CEST 2007


SVN commit 668061 by treat:

* Create label command and object


 M  +5 -0      kstmainwindow.cpp  
 M  +2 -0      kstmainwindow.h  
 M  +4 -1      kstplotcommands.cpp  
 M  +11 -0     kstplotitems.cpp  
 M  +12 -1     kstplotitems.h  
 M  +2 -5      kstplotview.cpp  


--- branches/work/kst/portto4/kst/src/libkstapp/kstmainwindow.cpp #668060:668061
@@ -94,6 +94,9 @@
 
 
 void KstMainWindow::createActions() {
+  _undoAct = _undoGroup->createUndoAction(this);
+  _redoAct = _undoGroup->createRedoAction(this);
+
   _createLabelAct = new QAction(tr("&Create label"), this);
   _createLabelAct->setStatusTip(tr("Create a label for the current plot"));
   connect(_createLabelAct, SIGNAL(triggered()), this, SLOT(createLabel()));
@@ -118,6 +121,8 @@
   _fileMenu->addAction(_exitAct);
 
   _editMenu = menuBar()->addMenu(tr("&Edit"));
+  _editMenu->addAction(_undoAct);
+  _editMenu->addAction(_redoAct);
 
   _plotMenu = menuBar()->addMenu(tr("&Plot"));
   _plotMenu->addAction(_createLabelAct);
--- branches/work/kst/portto4/kst/src/libkstapp/kstmainwindow.h #668060:668061
@@ -62,6 +62,8 @@
   QToolBar *_fileToolBar;
   QToolBar *_editToolBar;
 
+  QAction *_undoAct;
+  QAction *_redoAct;
   QAction *_createLabelAct;
 
   QAction *_exitAct;
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotcommands.cpp #668060:668061
@@ -14,8 +14,10 @@
 #include "kstplotview.h"
 #include "kstplotitems.h"
 
+#include <QDebug>
 #include <QObject>
 #include <QInputDialog>
+#include <QGraphicsScene>
 
 KstPlotViewCommand::KstPlotViewCommand(const QString &text, QUndoCommand *parent)
     : QUndoCommand(text, parent), _view(kstApp->mainWindow()->currentPlotView()) {
@@ -57,7 +59,8 @@
                                        QObject::tr("label:"), QLineEdit::Normal,
                                        QString::null, &ok);
   if (ok && !text.isEmpty()) {
-    //Create the item!!
+    _item = new LabelItem(text, _view);
+    _view->scene()->addItem(_item->graphicsItem());
   }
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotitems.cpp #668060:668061
@@ -27,6 +27,17 @@
   return qobject_cast<KstPlotView*>(parent());
 }
 
+
+LabelItem::LabelItem(const QString &text, KstPlotView *parent)
+    : KstPlotItem(parent), QGraphicsSimpleTextItem(text) {
+
+}
+
+
+LabelItem::~LabelItem() {
+}
+
+
 #include "kstplotitems.moc"
 
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotitems.h #668060:668061
@@ -13,6 +13,7 @@
 #define KSTPLOTITEMS_H
 
 #include <QObject>
+#include <QGraphicsSimpleTextItem>
 
 #include "kst_export.h"
 
@@ -28,9 +29,19 @@
 
   KstPlotView *parentView() const;
 
-  virtual QGraphicsItem *graphicsItem() const = 0;
+  virtual QGraphicsItem *graphicsItem() = 0;
 };
 
+class LabelItem : public KstPlotItem, public QGraphicsSimpleTextItem
+{
+  Q_OBJECT
+public:
+  LabelItem(const QString &text, KstPlotView *parent);
+  virtual ~LabelItem();
+
+  virtual QGraphicsItem *graphicsItem() { return this; }
+};
+
 #endif
 
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/kstplotview.cpp #668060:668061
@@ -12,7 +12,7 @@
 #include "kstplotview.h"
 #include "kstmainwindow.h"
 #include "kstapplication.h"
-
+#include <QDebug>
 #include <QUndoStack>
 #include <QGraphicsScene>
 
@@ -20,11 +20,8 @@
     : QGraphicsView(kstApp->mainWindow()), _currentPlotItem(0) {
 
   _undoStack = new QUndoStack(this);
+  setScene(new QGraphicsScene(this));
 
-  QGraphicsScene *scene = new QGraphicsScene(this);
-  scene->addText("Hello, Kst Plot!");
-  setScene(scene);
-
 }
 
 


More information about the Kst mailing list