2017-01-09 16:55:03 +00:00
|
|
|
//
|
|
|
|
// Copyright (C) 2017 James Turner zakalawe@mac.com
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
2016-12-03 14:14:06 +00:00
|
|
|
#ifndef FGCANVASELEMENT_H
|
|
|
|
#define FGCANVASELEMENT_H
|
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QTransform>
|
|
|
|
#include <QColor>
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class LocalProp;
|
|
|
|
class FGCanvasPaintContext;
|
|
|
|
class FGCanvasGroup;
|
2017-01-09 16:55:03 +00:00
|
|
|
class CanvasItem;
|
|
|
|
class QQuickItem;
|
2017-11-03 13:56:43 +00:00
|
|
|
class CanvasConnection;
|
2016-12-03 14:14:06 +00:00
|
|
|
|
2018-06-17 14:34:00 +00:00
|
|
|
/**
|
|
|
|
* Coordinate reference frame (eg. "clip" property)
|
|
|
|
*/
|
|
|
|
enum class ReferenceFrame
|
|
|
|
{
|
|
|
|
GLOBAL, ///< Global coordinates
|
|
|
|
PARENT, ///< Coordinates relative to parent coordinate frame
|
|
|
|
LOCAL ///< Coordinates relative to local coordinates (parent
|
|
|
|
/// coordinates with local transformations applied)
|
|
|
|
};
|
|
|
|
|
2016-12-03 14:14:06 +00:00
|
|
|
class FGCanvasElement : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit FGCanvasElement(FGCanvasGroup* pr, LocalProp* prop);
|
|
|
|
|
|
|
|
void paint(FGCanvasPaintContext* context) const;
|
|
|
|
|
|
|
|
QTransform combinedTransform() const;
|
|
|
|
|
|
|
|
bool isVisible() const;
|
|
|
|
|
|
|
|
int zIndex() const;
|
|
|
|
|
|
|
|
const FGCanvasGroup* parentGroup() const;
|
|
|
|
|
2018-06-17 15:54:09 +00:00
|
|
|
const FGCanvasGroup* rootGroup() const;
|
|
|
|
|
2017-11-03 13:56:43 +00:00
|
|
|
CanvasConnection* connection() const;
|
|
|
|
|
2016-12-03 14:14:06 +00:00
|
|
|
static bool isStyleProperty(QByteArray name);
|
|
|
|
|
|
|
|
LocalProp* property() const;
|
2016-12-22 17:15:50 +00:00
|
|
|
|
|
|
|
void setHighlighted(bool hilighted);
|
|
|
|
bool isHighlighted() const;
|
2017-01-09 16:55:03 +00:00
|
|
|
|
|
|
|
virtual CanvasItem* quickItem() const;
|
|
|
|
|
2017-11-07 15:20:42 +00:00
|
|
|
virtual CanvasItem* createQuickItem(QQuickItem* parent);
|
|
|
|
|
2017-11-02 17:20:42 +00:00
|
|
|
void requestPolish();
|
|
|
|
|
|
|
|
void polish();
|
2017-11-07 15:20:42 +00:00
|
|
|
|
2016-12-03 14:14:06 +00:00
|
|
|
protected:
|
2017-11-07 15:20:42 +00:00
|
|
|
|
2016-12-03 14:14:06 +00:00
|
|
|
virtual void doPaint(FGCanvasPaintContext* context) const;
|
2017-11-02 17:20:42 +00:00
|
|
|
virtual void doPolish();
|
2016-12-03 14:14:06 +00:00
|
|
|
|
|
|
|
virtual bool onChildAdded(LocalProp* prop);
|
|
|
|
virtual bool onChildRemoved(LocalProp* prop);
|
|
|
|
|
2017-11-28 22:54:12 +00:00
|
|
|
virtual void doDestroy();
|
|
|
|
|
2016-12-03 14:14:06 +00:00
|
|
|
const LocalProp* _propertyRoot;
|
|
|
|
const FGCanvasGroup* _parent;
|
|
|
|
|
|
|
|
QColor fillColor() const;
|
|
|
|
|
|
|
|
QColor parseColorValue(QVariant value) const;
|
|
|
|
|
|
|
|
virtual void markStyleDirty();
|
|
|
|
|
|
|
|
QVariant getCascadedStyle(const char* name, QVariant defaultValue = QVariant()) const;
|
2017-11-28 22:54:12 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void onPropDestroyed();
|
|
|
|
|
2016-12-03 14:14:06 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
void onCenterChanged(QVariant value);
|
|
|
|
|
|
|
|
void markTransformsDirty();
|
|
|
|
|
|
|
|
void markZIndexDirty(QVariant value);
|
|
|
|
|
|
|
|
void onVisibleChanged(QVariant value);
|
|
|
|
|
2016-12-18 23:52:16 +00:00
|
|
|
void markClipDirty();
|
|
|
|
|
2016-12-03 14:14:06 +00:00
|
|
|
private:
|
|
|
|
friend class FGCanvasGroup;
|
|
|
|
|
2017-11-02 17:20:42 +00:00
|
|
|
bool _polishRequired = false;
|
2016-12-03 14:14:06 +00:00
|
|
|
bool _visible = true;
|
2016-12-22 17:15:50 +00:00
|
|
|
bool _highlighted = false;
|
|
|
|
|
2016-12-03 14:14:06 +00:00
|
|
|
mutable bool _transformsDirty = true;
|
|
|
|
mutable bool _styleDirty = true;
|
|
|
|
|
|
|
|
mutable QTransform _combinedTransform;
|
|
|
|
|
|
|
|
QPointF _center;
|
|
|
|
|
|
|
|
mutable QColor _fillColor;
|
|
|
|
int _zIndex = 0;
|
|
|
|
QByteArray _svgElementId;
|
2016-12-18 23:52:16 +00:00
|
|
|
|
|
|
|
mutable bool _clipDirty = true;
|
|
|
|
mutable bool _hasClip = false;
|
|
|
|
mutable QRectF _clipRect;
|
2018-06-17 14:34:00 +00:00
|
|
|
mutable ReferenceFrame _clipFrame = ReferenceFrame::GLOBAL;
|
2016-12-22 16:59:48 +00:00
|
|
|
|
2017-11-02 17:20:42 +00:00
|
|
|
void parseCSSClip(QByteArray value);
|
2016-12-22 16:59:48 +00:00
|
|
|
float parseCSSValue(QByteArray value) const;
|
2016-12-03 14:14:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
using FGCanvasElementVec = std::vector<FGCanvasElement*>;
|
|
|
|
|
|
|
|
#endif // FGCANVASELEMENT_H
|