[Kst] branches/work/kst/portto4/kst/src/libkstapp
Mike Fenton
mike at staikos.net
Thu Jan 15 20:12:44 CET 2009
SVN commit 911608 by fenton:
Add drawing markers to indicate current drawing mode and allow cancelling of non-active drawing.
Add Escape catching to cancel active drawing.
Update viewItem cursor changes to only trigger when in layout mode.
M +5 -0 circleitem.cpp
M +85 -20 mainwindow.cpp
M +2 -0 mainwindow.h
M +8 -0 view.cpp
M +2 -1 view.h
M +10 -0 viewitem.cpp
--- branches/work/kst/portto4/kst/src/libkstapp/circleitem.cpp #911607:911608
@@ -50,6 +50,11 @@
void CircleItem::creationPolygonChanged(View::CreationEvent event) {
+ if (event == View::EscapeEvent) {
+ ViewItem::creationPolygonChanged(event);
+ return;
+ }
+
if (event == View::MousePress) {
const QPolygonF poly = mapFromScene(parentView()->creationPolygon(View::MousePress));
setPos(poly.first().x(), poly.first().y());
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.cpp #911607:911608
@@ -336,64 +336,118 @@
}
+void MainWindow::clearDrawingMarker() {
+ _createBoxAct->setChecked(false);
+ _createSharedAxisBoxAct->setChecked(false);
+ _createCircleAct->setChecked(false);
+ _createEllipseAct->setChecked(false);
+ _createLabelAct->setChecked(false);
+ _createLineAct->setChecked(false);
+ _createArrowAct->setChecked(false);
+ _createPictureAct->setChecked(false);
+ _createPlotAct->setChecked(false);
+ _createSvgAct->setChecked(false);
+}
+
+
void MainWindow::createBox() {
- CreateBoxCommand *cmd = new CreateBoxCommand;
- cmd->createItem();
+ if (_createBoxAct->isChecked()) {
+ clearDrawingMarker();
+ _createBoxAct->setChecked(true);
+ CreateBoxCommand *cmd = new CreateBoxCommand;
+ cmd->createItem();
+ }
}
void MainWindow::createSharedAxisBox() {
- CreateSharedAxisBoxCommand *cmd = new CreateSharedAxisBoxCommand;
- cmd->createItem();
+ if (_createSharedAxisBoxAct->isChecked()) {
+ clearDrawingMarker();
+ _createSharedAxisBoxAct->setChecked(true);
+ CreateSharedAxisBoxCommand *cmd = new CreateSharedAxisBoxCommand;
+ cmd->createItem();
+ }
}
void MainWindow::createCircle() {
- CreateCircleCommand *cmd = new CreateCircleCommand;
- cmd->createItem();
+ if (_createCircleAct->isChecked()) {
+ clearDrawingMarker();
+ _createCircleAct->setChecked(true);
+ CreateCircleCommand *cmd = new CreateCircleCommand;
+ cmd->createItem();
+ }
}
void MainWindow::createEllipse() {
- CreateEllipseCommand *cmd = new CreateEllipseCommand;
- cmd->createItem();
+ if (_createEllipseAct->isChecked()) {
+ clearDrawingMarker();
+ _createEllipseAct->setChecked(true);
+ CreateEllipseCommand *cmd = new CreateEllipseCommand;
+ cmd->createItem();
+ }
}
void MainWindow::createLabel() {
- CreateLabelCommand *cmd = new CreateLabelCommand;
- cmd->createItem();
+ if (_createLabelAct->isChecked()) {
+ clearDrawingMarker();
+ _createLabelAct->setChecked(true);
+ CreateLabelCommand *cmd = new CreateLabelCommand;
+ cmd->createItem();
+ }
}
void MainWindow::createLine() {
- CreateLineCommand *cmd = new CreateLineCommand;
- cmd->createItem();
+ if (_createLineAct->isChecked()) {
+ clearDrawingMarker();
+ _createLineAct->setChecked(true);
+ CreateLineCommand *cmd = new CreateLineCommand;
+ cmd->createItem();
+ }
}
void MainWindow::createArrow() {
- CreateArrowCommand *cmd = new CreateArrowCommand;
- cmd->createItem();
+ if (_createArrowAct->isChecked()) {
+ clearDrawingMarker();
+ _createArrowAct->setChecked(true);
+ CreateArrowCommand *cmd = new CreateArrowCommand;
+ cmd->createItem();
+ }
}
void MainWindow::createPicture() {
- CreatePictureCommand *cmd = new CreatePictureCommand;
- cmd->createItem();
+ if (_createPictureAct->isChecked()) {
+ clearDrawingMarker();
+ _createPictureAct->setChecked(true);
+ CreatePictureCommand *cmd = new CreatePictureCommand;
+ cmd->createItem();
+ }
}
void MainWindow::createPlot() {
- CreatePlotCommand *cmd = new CreatePlotCommand;
- cmd->createItem();
+ if (_createPlotAct->isChecked()) {
+ clearDrawingMarker();
+ _createPlotAct->setChecked(true);
+ CreatePlotCommand *cmd = new CreatePlotCommand;
+ cmd->createItem();
+ }
}
void MainWindow::createSvg() {
- CreateSvgCommand *cmd = new CreateSvgCommand;
- cmd->createItem();
+ if (_createSvgAct->isChecked()) {
+ clearDrawingMarker();
+ _createSvgAct->setChecked(true);
+ CreateSvgCommand *cmd = new CreateSvgCommand;
+ cmd->createItem();
+ }
}
@@ -438,64 +492,75 @@
_createLabelAct->setStatusTip(tr("Create a label for the current view"));
_createLabelAct->setIcon(QPixmap(":kst_gfx_label.png"));
_createLabelAct->setShortcut(QString("F3"));
+ _createLabelAct->setCheckable(true);
connect(_createLabelAct, SIGNAL(triggered()), this, SLOT(createLabel()));
_createBoxAct = new QAction(tr("&Create box"), this);
_createBoxAct->setStatusTip(tr("Create a box for the current view"));
_createBoxAct->setIcon(QPixmap(":kst_gfx_rectangle.png"));
_createBoxAct->setShortcut(QString("F4"));
+ _createBoxAct->setCheckable(true);
connect(_createBoxAct, SIGNAL(triggered()), this, SLOT(createBox()));
_createCircleAct = new QAction(tr("&Create circle"), this);
_createCircleAct->setStatusTip(tr("Create a circle for the current view"));
_createCircleAct->setIcon(QPixmap(":kst_gfx_ellipse.png"));
_createCircleAct->setShortcut(QString("F5"));
+ _createCircleAct->setCheckable(true);
connect(_createCircleAct, SIGNAL(triggered()), this, SLOT(createCircle()));
_createEllipseAct = new QAction(tr("&Create ellipse"), this);
_createEllipseAct->setStatusTip(tr("Create an ellipse for the current view"));
_createEllipseAct->setIcon(QPixmap(":kst_gfx_ellipse.png"));
_createEllipseAct->setShortcut(QString("F6"));
+ _createEllipseAct->setCheckable(true);
connect(_createEllipseAct, SIGNAL(triggered()), this, SLOT(createEllipse()));
_createLineAct = new QAction(tr("&Create line"), this);
_createLineAct->setStatusTip(tr("Create a line for the current view"));
_createLineAct->setIcon(QPixmap(":kst_gfx_line.png"));
_createLineAct->setShortcut(QString("F7"));
+ _createLineAct->setCheckable(true);
connect(_createLineAct, SIGNAL(triggered()), this, SLOT(createLine()));
_createArrowAct = new QAction(tr("&Create arrow"), this);
_createArrowAct->setStatusTip(tr("Create a arrow for the current view"));
_createArrowAct->setIcon(QPixmap(":kst_gfx_arrow.png"));
_createArrowAct->setShortcut(QString("F8"));
+ _createArrowAct->setCheckable(true);
connect(_createArrowAct, SIGNAL(triggered()), this, SLOT(createArrow()));
_createPictureAct = new QAction(tr("&Create picture"), this);
_createPictureAct->setStatusTip(tr("Create a picture for the current view"));
_createPictureAct->setIcon(QPixmap(":kst_gfx_picture.png"));
_createPictureAct->setShortcut(QString("F9"));
+ _createPictureAct->setCheckable(true);
connect(_createPictureAct, SIGNAL(triggered()), this, SLOT(createPicture()));
_createPlotAct = new QAction(tr("&Create plot"), this);
_createPlotAct->setStatusTip(tr("Create a plot for the current view"));
_createPlotAct->setIcon(QPixmap(":kst_newplot.png"));
_createPlotAct->setShortcut(QString("F10"));
+ _createPlotAct->setCheckable(true);
connect(_createPlotAct, SIGNAL(triggered()), this, SLOT(createPlot()));
_createSvgAct = new QAction(tr("&Create svg"), this);
_createSvgAct->setStatusTip(tr("Create a svg for the current view"));
_createSvgAct->setShortcut(QString("F11"));
+ _createSvgAct->setCheckable(true);
connect(_createSvgAct, SIGNAL(triggered()), this, SLOT(createSvg()));
_createLayoutAct = new QAction(tr("&Create layout"), this);
_createLayoutAct->setStatusTip(tr("Create a layout for the current item"));
_createLayoutAct->setIcon(QPixmap(":kst_gfx_layout.png"));
+ _createLayoutAct->setCheckable(true);
// _createLayoutAct->setEnabled(false);
connect(_createLayoutAct, SIGNAL(triggered()), this, SLOT(createLayout()));
_createSharedAxisBoxAct = new QAction(tr("&Create Shared Axis Box"), this);
_createSharedAxisBoxAct->setStatusTip(tr("Create a shared axis box for the current item"));
_createSharedAxisBoxAct->setIcon(QPixmap(":kst_gfx_sharedaxisbox.png"));
+ _createSharedAxisBoxAct->setCheckable(true);
// _createSharedAxisBoxAct->setEnabled(false);
connect(_createSharedAxisBoxAct, SIGNAL(triggered()), this, SLOT(createSharedAxisBox()));
--- branches/work/kst/portto4/kst/src/libkstapp/mainwindow.h #911607:911608
@@ -72,6 +72,8 @@
void print();
void exportGraphicsFile(const QString &filename, const QString &format, int w, int h, int display);
+ void clearDrawingMarker();
+
private Q_SLOTS:
void aboutToQuit();
void about();
--- branches/work/kst/portto4/kst/src/libkstapp/view.cpp #911607:911608
@@ -32,6 +32,7 @@
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QInputDialog>
+#include <QKeyEvent>
namespace Kst {
@@ -290,6 +291,13 @@
emit creationPolygonChanged(MouseMove);
break;
}
+ case QEvent::KeyPress:
+ {
+ QKeyEvent *e = static_cast<QKeyEvent*>(event);
+ if (e->key() == Qt::Key_Escape) {
+ emit creationPolygonChanged(EscapeEvent);
+ }
+ }
default:
break;
}
--- branches/work/kst/portto4/kst/src/libkstapp/view.h #911607:911608
@@ -35,7 +35,8 @@
enum CreationEvent {
MousePress = 0x0,
MouseRelease =0x1,
- MouseMove = 0x2
+ MouseMove = 0x2,
+ EscapeEvent = 0x3
};
Q_DECLARE_FLAGS(CreationEvents, CreationEvent)
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #911607:911608
@@ -732,6 +732,12 @@
void ViewItem::creationPolygonChanged(View::CreationEvent event) {
+ if (event == View::EscapeEvent) {
+ deleteLater();
+ kstApp->mainWindow()->clearDrawingMarker();
+ return;
+ }
+
if (event == View::MousePress) {
const QPolygonF poly = mapFromScene(parentView()->creationPolygon(View::MousePress));
setPos(poly.first().x(), poly.first().y());
@@ -1660,6 +1666,9 @@
void ViewItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
QGraphicsRectItem::hoverMoveEvent(event);
+ if (parentView()->viewMode() == View::Data) {
+ return;
+ }
if (isSelected()) {
QPointF p = event->pos();
if ((isAllowed(TopLeftGrip) && topLeftGrip().contains(p)) || (isAllowed(BottomRightGrip) && bottomRightGrip().contains(p))) {
@@ -1853,6 +1862,7 @@
void CreateCommand::creationComplete() {
_view->undoStack()->push(this);
+ kstApp->mainWindow()->clearDrawingMarker();
}
More information about the Kst
mailing list