File indexing completed on 2024-05-12 03:48:24

0001 /*
0002     File                 : WorksheetElementPrivate.h
0003     Project              : LabPlot
0004     Description          : Private member of WorksheetElement
0005     --------------------------------------------------------------------
0006     SPDX-FileCopyrightText: 2012-2021 Martin Marmsoler <martin.marmsoler@gmail.com>
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #ifndef WORKSHEETELEMENTPRIVATE_H
0011 #define WORKSHEETELEMENTPRIVATE_H
0012 
0013 #include "Worksheet.h"
0014 #include <QGraphicsItem>
0015 
0016 class WorksheetElement;
0017 
0018 class WorksheetElementPrivate : public QGraphicsItem {
0019 public:
0020     WorksheetElementPrivate(WorksheetElement*);
0021 
0022     // position in parent's coordinate system, the label gets aligned around this point
0023     // TODO: try to get away the Worksheet dependency
0024     WorksheetElement::PositionWrapper position{
0025         QPointF(Worksheet::convertToSceneUnits(1, Worksheet::Unit::Centimeter), Worksheet::convertToSceneUnits(1, Worksheet::Unit::Centimeter)),
0026         WorksheetElement::HorizontalPosition::Center,
0027         WorksheetElement::VerticalPosition::Center,
0028         WorksheetElement::PositionLimit::None};
0029     WorksheetElement::HorizontalAlignment horizontalAlignment{WorksheetElement::HorizontalAlignment::Center};
0030     WorksheetElement::VerticalAlignment verticalAlignment{WorksheetElement::VerticalAlignment::Center};
0031     bool positionInvalid{false};
0032     bool coordinateBindingEnabled{false};
0033     QPointF positionLogical;
0034     bool suppressItemChangeEvent{false};
0035     bool suppressRetransform{false};
0036     bool suppressRecalc{false};
0037     WorksheetElement* const q{nullptr};
0038     bool insidePlot{true}; // point inside the plot (visible) or not
0039     bool lock{false};
0040 
0041     bool swapVisible(bool on);
0042     QString name() const;
0043     virtual void retransform() = 0;
0044     virtual void recalcShapeAndBoundingRect() = 0;
0045     void updatePosition();
0046     virtual QRectF boundingRect() const override;
0047     virtual QPainterPath shape() const override;
0048     void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget* widget = nullptr) override;
0049     virtual void keyPressEvent(QKeyEvent*) override;
0050     virtual void mouseMoveEvent(QGraphicsSceneMouseEvent*) override;
0051     virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent*) override;
0052     virtual QVariant itemChange(GraphicsItemChange, const QVariant& value) override;
0053     virtual bool sceneEvent(QEvent* event) override;
0054     QPointF mapParentToPlotArea(QPointF) const;
0055     QPointF mapPlotAreaToParent(QPointF) const;
0056     void setHover(bool);
0057     bool isHovered() const;
0058 
0059 private:
0060     virtual void hoverEnterEvent(QGraphicsSceneHoverEvent*) override;
0061     virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent*) override;
0062     virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent*) override;
0063 
0064 protected:
0065     bool m_hovered{false};
0066     bool m_moveStarted{false};
0067     QRectF m_boundingRectangle; // bounding rectangle of the element
0068     QPainterPath m_shape;
0069 };
0070 
0071 #endif