[Kst] branches/work/kst/portto4/kst/src/libkstapp
Adam Treat
treat at kde.org
Mon Oct 15 17:39:27 CEST 2007
SVN commit 725511 by treat:
* Add plot axis and labels for major ticks.
This design will need to be rethought as I think
the PlotAxisItem class will need to be merged with
the PlotItem class. However, I want to get this
under version control as this contains a lot of sep
moving parts.
* ZOrder fixes for all viewitems.
* Event and shortcut fixes.
* Other bugfixes and stuff.
M +3 -0 boxitem.cpp
M +1 -1 cartesianrenderitem.cpp
M +3 -0 ellipseitem.cpp
M +3 -0 labelitem.cpp
M +4 -3 layoutboxitem.cpp
M +5 -0 libkstapp.pro
M +5 -1 lineitem.cpp
M +2 -0 pictureitem.cpp
A plotaxisitem.cpp [License: GPL (v2+)]
A plotaxisitem.h [License: GPL (v2+)]
M +17 -2 plotitem.cpp
M +12 -1 plotitem.h
M +15 -10 plotrenderitem.cpp
A scene.cpp [License: GPL (v2+)]
A scene.h [License: GPL (v2+)]
M +3 -0 svgitem.cpp
M +12 -5 view.cpp
M +15 -12 viewitem.cpp
M +12 -0 viewitem.h
A viewitemzorder.h [License: GPL (v2+)]
--- branches/work/kst/portto4/kst/src/libkstapp/boxitem.cpp #725510:725511
@@ -11,6 +11,8 @@
#include "boxitem.h"
+#include "viewitemzorder.h"
+
#include <debug.h>
#include <QDebug>
@@ -21,6 +23,7 @@
BoxItem::BoxItem(View *parent)
: ViewItem(parent) {
setName("Box");
+ setZValue(BOX_ZVALUE);
setBrush(Qt::white);
}
--- branches/work/kst/portto4/kst/src/libkstapp/cartesianrenderitem.cpp #725510:725511
@@ -23,7 +23,7 @@
CartesianRenderItem::CartesianRenderItem(PlotItem *parentItem)
: PlotRenderItem(parentItem) {
setType(Cartesian);
- setName(tr("Cartesian Render Item"));
+ setName(tr("Cartesian Render"));
}
--- branches/work/kst/portto4/kst/src/libkstapp/ellipseitem.cpp #725510:725511
@@ -11,6 +11,8 @@
#include "ellipseitem.h"
+#include "viewitemzorder.h"
+
#include <QDebug>
#include <QGraphicsItem>
#include <QGraphicsScene>
@@ -22,6 +24,7 @@
EllipseItem::EllipseItem(View *parent)
: ViewItem(parent) {
setName("Ellipse");
+ setZValue(ELLIPSE_ZVALUE);
setBrush(Qt::white);
}
--- branches/work/kst/portto4/kst/src/libkstapp/labelitem.cpp #725510:725511
@@ -10,8 +10,10 @@
***************************************************************************/
#include "labelitem.h"
+
#include <labelparser.h>
#include "labelrenderer.h"
+#include "viewitemzorder.h"
#include "debug.h"
@@ -25,6 +27,7 @@
LabelItem::LabelItem(View *parent, const QString& txt)
: ViewItem(parent), _parsed(0), _text(txt) {
setName("Label");
+ setZValue(LABEL_ZVALUE);
setAllowedGripModes(Move /*| Resize*/ | Rotate /*| Scale*/);
}
--- branches/work/kst/portto4/kst/src/libkstapp/layoutboxitem.cpp #725510:725511
@@ -10,10 +10,10 @@
***************************************************************************/
#include "layoutboxitem.h"
+
#include "viewgridlayout.h"
+#include "viewitemzorder.h"
-#include <debug.h>
-
#include <QDebug>
#include <QMenu>
#include <QTimer>
@@ -25,12 +25,13 @@
LayoutBoxItem::LayoutBoxItem(View *parent)
: ViewItem(parent) {
setName("Layout Box");
+ setZValue(LAYOUTBOX_ZVALUE);
setPen(Qt::NoPen);
setBrush(Qt::NoBrush);
setAllowedGripModes(Move);
parentView()->scene()->addItem(this);
- setZValue(1);
+ //setZValue(1);
setPos(parentView()->sceneRect().topLeft());
setViewRect(parentView()->sceneRect());
--- branches/work/kst/portto4/kst/src/libkstapp/libkstapp.pro #725510:725511
@@ -60,10 +60,12 @@
matrixmodel.cpp \
memorywidget.cpp \
pictureitem.cpp \
+ plotaxisitem.cpp \
plotitem.cpp \
plotitemmanager.cpp \
plotrenderitem.cpp \
qgetoptions.cpp \
+ scene.cpp \
selectionrect.cpp \
sessionmodel.cpp \
scalardialog.cpp \
@@ -123,10 +125,12 @@
matrixmodel.h \
memorywidget.h \
pictureitem.h \
+ plotaxisitem.h \
plotitem.h \
plotitemmanager.h \
plotrenderitem.h \
qgetoptions.h \
+ scene.h \
selectionrect.h \
sessionmodel.h \
scalardialog.h \
@@ -142,6 +146,7 @@
viewgridlayout.h \
viewitemdialog.h \
viewitem.h \
+ viewitemzorder.h \
viewmanager.h
FORMS += \
--- branches/work/kst/portto4/kst/src/libkstapp/lineitem.cpp #725510:725511
@@ -10,7 +10,10 @@
***************************************************************************/
#include "lineitem.h"
+
#include "view.h"
+#include "viewitemzorder.h"
+
#include <debug.h>
#include <QDebug>
@@ -22,6 +25,7 @@
LineItem::LineItem(View *parent)
: ViewItem(parent) {
setName("Line");
+ setZValue(LINE_ZVALUE);
setAllowedGrips(RightMidGrip | LeftMidGrip);
}
@@ -122,7 +126,7 @@
setPos(poly.first().x(), poly.first().y());
setViewRect(QRectF(0.0, 0.0, 0.0, sizeOfGrip().height()));
parentView()->scene()->addItem(this);
- setZValue(1);
+ //setZValue(1);
return;
}
--- branches/work/kst/portto4/kst/src/libkstapp/pictureitem.cpp #725510:725511
@@ -11,6 +11,7 @@
#include "pictureitem.h"
+#include "viewitemzorder.h"
#include "debug.h"
#include <QDebug>
@@ -27,6 +28,7 @@
_image = QPixmap::fromImage(image);
}
setName("Picture");
+ setZValue(PICTURE_ZVALUE);
setLockAspectRatio(true);
}
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.cpp #725510:725511
@@ -11,6 +11,8 @@
#include "plotitem.h"
+#include "viewitemzorder.h"
+#include "plotaxisitem.h"
#include "plotitemmanager.h"
#include "plotrenderitem.h"
@@ -42,7 +44,10 @@
_calculatedMarginWidth(0.0),
_calculatedMarginHeight(0.0) {
+ _axisItem = new PlotAxisItem(this);
+
setName("Plot");
+ setZValue(PLOT_ZVALUE);
setBrush(Qt::white);
PlotItemManager::self()->addPlot(this);
@@ -118,7 +123,8 @@
}
-QRectF PlotItem::plotRegion() const {
+QRectF PlotItem::plotAxisRect() const {
+ //the PlotAxisItem uses this to set its rect
qreal left = isLeftLabelVisible() ? marginWidth() : 0.0;
qreal bottom = isBottomLabelVisible() ? marginHeight() : 0.0;
qreal right = isRightLabelVisible() ? marginWidth() : 0.0;
@@ -131,6 +137,15 @@
}
+QRectF PlotItem::plotRect() const {
+ //the PlotRenderItems use this to set their rects
+ QRectF plot = plotAxisRect();
+ plot.setLeft(plot.left() + _axisItem->marginWidth());
+ plot.setBottom(plot.bottom() - _axisItem->marginHeight());
+ return plot;
+}
+
+
QRectF PlotItem::projectionRect() const {
QRectF rect;
foreach (PlotRenderItem *renderer, renderItems()) {
@@ -479,7 +494,7 @@
_item = new PlotItem(_view);
_item->setPos(center);
_item->setViewRect(0.0, 0.0, 200.0, 200.0);
- _item->setZValue(1);
+ //_item->setZValue(1);
_view->scene()->addItem(_item);
if (_createLayout) {
--- branches/work/kst/portto4/kst/src/libkstapp/plotitem.h #725510:725511
@@ -22,6 +22,8 @@
namespace Kst {
+class PlotAxisItem;
+
class PlotItem : public ViewItem, public PlotItemInterface
{
Q_OBJECT
@@ -36,7 +38,13 @@
virtual void paint(QPainter *painter);
- QRectF plotRegion() const;
+ /* This is the rectangle of the PlotAxisItem and includes the axis labels. */
+ QRectF plotAxisRect() const;
+
+ /* This is the rectangle of the PlotRenderItem's and includes the actual curves. */
+ QRectF plotRect() const;
+
+ /* This is the rectangle containing the union of all the PlotRenderItem's projections. */
QRectF projectionRect() const;
bool isTiedZoom() const;
@@ -64,6 +72,8 @@
void setLabelsVisible(bool visible);
+ PlotAxisItem *plotAxisItem() const { return _axisItem; }
+
Q_SIGNALS:
void labelVisibilityChanged();
@@ -87,6 +97,7 @@
QSizeF calculateTopLabelBound(QPainter *painter);
private:
+ PlotAxisItem *_axisItem;
QHash<PlotRenderItem::RenderType, PlotRenderItem*> _renderers;
bool _isTiedZoom;
bool _isLeftLabelVisible;
--- branches/work/kst/portto4/kst/src/libkstapp/plotrenderitem.cpp #725510:725511
@@ -11,6 +11,12 @@
#include "plotrenderitem.h"
+#include "plotitem.h"
+#include "plotaxisitem.h"
+#include "viewitemzorder.h"
+#include "plotitemmanager.h"
+#include "application.h"
+
#include <QTime>
#include <QMenu>
#include <QStatusBar>
@@ -19,10 +25,6 @@
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsSceneContextMenuEvent>
-#include "plotitem.h"
-#include "plotitemmanager.h"
-#include "application.h"
-
// #define CURVE_DRAWING_TIME
namespace Kst {
@@ -37,13 +39,16 @@
_yLogBase(10.0) {
setName(tr("Plot Render"));
+ setZValue(PLOTRENDER_ZVALUE);
setParentItem(parentItem);
setHasStaticGeometry(true);
setAllowedGripModes(0);
setAllowedGrips(0);
- connect(parentItem, SIGNAL(geometryChanged()),
+ connect(parentItem->plotAxisItem(), SIGNAL(marginChanged()),
this, SLOT(updateGeometry()));
+ connect(parentItem->plotAxisItem(), SIGNAL(geometryChanged()),
+ this, SLOT(updateGeometry()));
connect(parentItem, SIGNAL(labelVisibilityChanged()),
this, SLOT(updateGeometry()));
connect(parentItem->parentView(), SIGNAL(viewModeChanged(View::ViewMode)),
@@ -215,9 +220,9 @@
painter->setRenderHint(QPainter::Antialiasing, true);
painter->fillPath(checkBox(), Qt::white);
if (isHovering()) {
- QRectF check = checkBox().boundingRect();
+ QRectF check = checkBox().controlPointRect();
check.setSize(QSizeF(check.width() / 1.8, check.height() / 1.8));
- check.moveCenter(checkBox().boundingRect().center());
+ check.moveCenter(checkBox().controlPointRect().center());
QPainterPath p;
p.addEllipse(check);
painter->fillPath(p, Qt::black);
@@ -460,7 +465,7 @@
updateCursor(event->pos());
const QPointF p = mapToProjection(event->pos());
- QString message = QString("(%1, %2)").arg(QString::number(p.x())).arg(QString::number(p.y()));
+ QString message = QString("(%1, %2)").arg(QString::number(p.x(), 'G')).arg(QString::number(p.y()));
kstApp->mainWindow()->statusBar()->showMessage(message);
}
@@ -488,7 +493,7 @@
QTransform PlotRenderItem::projectionTransform() const {
QTransform t;
- QRectF v = QRectF(rect().bottomLeft(), viewRect().topRight());
+ QRectF v = QRectF(rect().bottomLeft(), rect().topRight());
QPolygonF from_ = QPolygonF(v);
from_.pop_back(); //get rid of last closed point
@@ -680,7 +685,7 @@
void PlotRenderItem::updateGeometry() {
- setViewRect(plotItem()->plotRegion());
+ setViewRect(plotItem()->plotRect());
}
--- branches/work/kst/portto4/kst/src/libkstapp/svgitem.cpp #725510:725511
@@ -12,6 +12,8 @@
#include "svgitem.h"
#include "debug.h"
+#include "viewitemzorder.h"
+
#include <QDebug>
#include <QFileDialog>
#include <QGraphicsScene>
@@ -36,6 +38,7 @@
}
//FIXME need to set the element id??
setName("Svg");
+ setZValue(SVG_ZVALUE);
setLockAspectRatio(true);
}
--- branches/work/kst/portto4/kst/src/libkstapp/view.cpp #725510:725511
@@ -10,6 +10,7 @@
***************************************************************************/
#include "view.h"
+#include "scene.h"
#include "viewitem.h"
#include "layoutboxitem.h"
#include "mainwindow.h"
@@ -40,7 +41,7 @@
_snapToGridVertical(false) {
_undoStack = new QUndoStack(this);
- setScene(new QGraphicsScene(this));
+ setScene(new Scene(this));
scene()->installEventFilter(this);
setInteractive(true);
setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform);
@@ -188,10 +189,17 @@
if (event->type() == QEvent::Shortcut) {
QShortcutEvent *e = static_cast<QShortcutEvent*>(event);
+
QPointF mousePos = mapToScene(mapFromGlobal(QCursor::pos()));
- ViewItem *item = qgraphicsitem_cast<ViewItem*>(scene()->itemAt(mousePos));
- if (item && item->tryShortcut(e->key()))
- return true;
+ QList<QGraphicsItem*> list = scene()->items(mousePos);
+ foreach (QGraphicsItem *item, list) {
+ ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(item);
+ if (!viewItem)
+ continue;
+
+ if (viewItem && viewItem->tryShortcut(e->key()))
+ return true;
+ }
}
return QGraphicsView::event(event);
@@ -334,7 +342,6 @@
}
}
-
}
// vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #725510:725511
@@ -46,11 +46,14 @@
_lockAspectRatio(false),
_hasStaticGeometry(false),
_hovering(false),
+ _acceptsChildItems(true),
+ _acceptsContextMenuEvents(true),
_layout(0),
_activeGrip(NoGrip),
_allowedGrips(TopLeftGrip | TopRightGrip | BottomRightGrip | BottomLeftGrip |
TopMidGrip | RightMidGrip | BottomMidGrip | LeftMidGrip) {
+ setZValue(1);
setName("View Item");
setAcceptsHoverEvents(true);
setFlags(ItemIsMovable | ItemIsSelectable | ItemIsFocusable);
@@ -575,7 +578,7 @@
QRectF ViewItem::selectBoundingRect() const {
#if INKSCAPE_MODE
- return mapToScene(itemShape()).boundingRect();
+ return mapToScene(itemShape()).controlPointRect();
#else
return rect();
#endif
@@ -724,7 +727,7 @@
setPos(poly.first().x(), poly.first().y());
setViewRect(0.0, 0.0, 0.0, 0.0);
parentView()->scene()->addItem(this);
- setZValue(1);
+ //setZValue(1);
return;
}
@@ -837,21 +840,21 @@
#else
switch(_activeGrip) {
case TopLeftGrip:
- rotateTowards(topLeftGrip().boundingRect().center(), p); break;
+ rotateTowards(topLeftGrip().controlPointRect().center(), p); break;
case TopRightGrip:
- rotateTowards(topRightGrip().boundingRect().center(), p); break;
+ rotateTowards(topRightGrip().controlPointRect().center(), p); break;
case BottomRightGrip:
- rotateTowards(bottomRightGrip().boundingRect().center(), p); break;
+ rotateTowards(bottomRightGrip().controlPointRect().center(), p); break;
case BottomLeftGrip:
- rotateTowards(bottomLeftGrip().boundingRect().center(), p); break;
+ rotateTowards(bottomLeftGrip().controlPointRect().center(), p); break;
case TopMidGrip:
- rotateTowards(topMidGrip().boundingRect().center(), p); break;
+ rotateTowards(topMidGrip().controlPointRect().center(), p); break;
case RightMidGrip:
- rotateTowards(rightMidGrip().boundingRect().center(), p); break;
+ rotateTowards(rightMidGrip().controlPointRect().center(), p); break;
case BottomMidGrip:
- rotateTowards(bottomMidGrip().boundingRect().center(), p); break;
+ rotateTowards(bottomMidGrip().controlPointRect().center(), p); break;
case LeftMidGrip:
- rotateTowards(leftMidGrip().boundingRect().center(), p); break;
+ rotateTowards(leftMidGrip().controlPointRect().center(), p); break;
case NoGrip:
break;
}
@@ -1290,7 +1293,7 @@
foreach (QGraphicsItem *item, collisions) {
ViewItem *viewItem = qgraphicsitem_cast<ViewItem*>(item);
- if (!viewItem) /*bah*/
+ if (!viewItem || !viewItem->acceptsChildItems()) /*bah*/
continue;
if (!viewItem->collidesWithItem(this, Qt::ContainsItemShape)) /*doesn't contain*/
@@ -1861,7 +1864,7 @@
void LowerCommand::undo() {
Q_ASSERT(_item);
- _item->setZValue(_item->zValue() +1);
+ _item->setZValue(_item->zValue() + 1);
}
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #725510:725511
@@ -115,6 +115,15 @@
bool isHovering() const { return _hovering; }
+ bool acceptsChildItems() const { return _acceptsChildItems; }
+ void setAcceptsChildItems(bool acceptsChildItems) { _acceptsChildItems = acceptsChildItems; }
+
+ //This is a workaround for context menu bug in Qt4.3 graphicsview
+ bool acceptsContextMenuEvents() const
+ { return _acceptsContextMenuEvents; }
+ void setAcceptsContextMenuEvents(bool acceptsContextMenuEvents)
+ { _acceptsContextMenuEvents = acceptsContextMenuEvents; }
+
Q_SIGNALS:
void geometryChanged();
void creationComplete();
@@ -191,6 +200,8 @@
bool _lockAspectRatio;
bool _hasStaticGeometry;
bool _hovering;
+ bool _acceptsChildItems;
+ bool _acceptsContextMenuEvents;
ViewGridLayout *_layout;
QPointF _originalPosition;
QRectF _originalRect;
@@ -203,6 +214,7 @@
QHash<QString, QAction*> _shortcutMap;
friend class View;
+ friend class Scene;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(ViewItem::GripModes)
More information about the Kst
mailing list