shapes.h 6.37 KB
Newer Older
Jochen Becher's avatar
Jochen Becher committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
/***************************************************************************
**
** Copyright (C) 2015 Jochen Becher
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

#ifndef QMT_SHAPES_H
#define QMT_SHAPES_H

#include "shape.h"
#include "qmt/infrastructure/qmt_global.h"

#include "shapevalue.h"
#include "shapevisitor.h"

#include <QList>


namespace qmt {

class QMT_EXPORT LineShape
        : public IShape
{
public:

    LineShape()
    {
    }

    LineShape(const ShapePointF &pos1, const ShapePointF &pos2)
55 56
        : m_pos1(pos1),
          m_pos2(pos2)
Jochen Becher's avatar
Jochen Becher committed
57 58 59 60 61
    {
    }

public:

62
    ShapePointF pos1() const { return m_pos1; }
Jochen Becher's avatar
Jochen Becher committed
63

64
    ShapePointF pos2() const { return m_pos2; }
Jochen Becher's avatar
Jochen Becher committed
65 66 67 68 69 70 71 72 73 74 75 76 77

public:

    IShape *Clone() const;

public:

    void accept(ShapeVisitor *visitor);

    void accept(ShapeConstVisitor *visitor) const;

private:

78 79
    ShapePointF m_pos1;
    ShapePointF m_pos2;
Jochen Becher's avatar
Jochen Becher committed
80 81 82 83 84 85 86 87 88 89 90 91 92
};


class QMT_EXPORT RectShape
        : public IShape
{
public:

    RectShape()
    {
    }

    RectShape(const ShapePointF &pos, const ShapeSizeF &size)
93 94
        : m_pos(pos),
          m_size(size)
Jochen Becher's avatar
Jochen Becher committed
95 96 97 98 99
    {
    }

public:

100
    ShapePointF pos() const { return m_pos; }
Jochen Becher's avatar
Jochen Becher committed
101

102
    ShapeSizeF size() const { return m_size; }
Jochen Becher's avatar
Jochen Becher committed
103 104 105 106 107 108 109 110 111 112 113 114 115

public:

    IShape *Clone() const;

public:

    void accept(ShapeVisitor *visitor);

    void accept(ShapeConstVisitor *visitor) const;

private:

116 117
    ShapePointF m_pos;
    ShapeSizeF m_size;
Jochen Becher's avatar
Jochen Becher committed
118 119 120 121 122 123 124 125 126 127 128 129 130
};


class QMT_EXPORT RoundedRectShape
        : public IShape
{
public:

    RoundedRectShape()
    {
    }

    RoundedRectShape(const ShapePointF &pos, const ShapeSizeF &size, const ShapeValueF &radius)
131 132 133
        : m_pos(pos),
          m_size(size),
          m_radius(radius)
Jochen Becher's avatar
Jochen Becher committed
134 135 136 137 138
    {
    }

public:

139
    ShapePointF pos() const { return m_pos; }
Jochen Becher's avatar
Jochen Becher committed
140

141
    ShapeSizeF size() const { return m_size; }
Jochen Becher's avatar
Jochen Becher committed
142

143
    ShapeValueF radius() const { return m_radius; }
Jochen Becher's avatar
Jochen Becher committed
144 145 146 147 148 149 150 151 152 153 154 155 156

public:

    IShape *Clone() const;

public:

    void accept(ShapeVisitor *visitor);

    void accept(ShapeConstVisitor *visitor) const;

private:

157 158 159
    ShapePointF m_pos;
    ShapeSizeF m_size;
    ShapeValueF m_radius;
Jochen Becher's avatar
Jochen Becher committed
160 161 162 163 164 165 166 167 168 169 170 171 172
};


class QMT_EXPORT CircleShape
        : public IShape
{
public:

    CircleShape()
    {
    }

    CircleShape(const ShapePointF &center, const ShapeValueF &radius)
173 174
        : m_center(center),
          m_radius(radius)
Jochen Becher's avatar
Jochen Becher committed
175 176 177 178 179
    {
    }

public:

180
    ShapePointF center() const { return m_center; }
Jochen Becher's avatar
Jochen Becher committed
181

182
    ShapeValueF radius() const { return m_radius; }
Jochen Becher's avatar
Jochen Becher committed
183 184 185 186 187 188 189 190 191 192 193 194 195

public:

    IShape *Clone() const;

public:

    void accept(ShapeVisitor *visitor);

    void accept(ShapeConstVisitor *visitor) const;

private:

196 197
    ShapePointF m_center;
    ShapeValueF m_radius;
Jochen Becher's avatar
Jochen Becher committed
198 199 200 201 202 203 204 205 206 207 208 209
};


class QMT_EXPORT EllipseShape
        : public IShape
{
public:
    EllipseShape()
    {
    }

    EllipseShape(const ShapePointF &center, const ShapeSizeF &radius)
210 211
        : m_center(center),
          m_radius(radius)
Jochen Becher's avatar
Jochen Becher committed
212 213 214 215 216
    {
    }

public:

217
    ShapePointF center() const { return m_center; }
Jochen Becher's avatar
Jochen Becher committed
218

219
    ShapeSizeF radius() const { return m_radius; }
Jochen Becher's avatar
Jochen Becher committed
220 221 222 223 224 225 226 227 228 229 230 231 232

public:

    IShape *Clone() const;

public:

    void accept(ShapeVisitor *visitor);

    void accept(ShapeConstVisitor *visitor) const;

private:

233 234
    ShapePointF m_center;
    ShapeSizeF m_radius;
Jochen Becher's avatar
Jochen Becher committed
235 236 237 238 239 240 241 242 243 244 245
};


class QMT_EXPORT ArcShape
        : public IShape
{
public:
    ArcShape()
    {
    }

246
    ArcShape(const ShapePointF &center, const ShapeSizeF &radius, qreal startAngle, qreal spanAngle)
247 248
        : m_center(center),
          m_radius(radius),
249 250
          m_startAngle(startAngle),
          m_spanAngle(spanAngle)
Jochen Becher's avatar
Jochen Becher committed
251 252 253 254 255
    {
    }

public:

256
    ShapePointF center() const { return m_center; }
Jochen Becher's avatar
Jochen Becher committed
257

258
    ShapeSizeF radius() const { return m_radius; }
Jochen Becher's avatar
Jochen Becher committed
259

260
    qreal startAngle() const { return m_startAngle; }
Jochen Becher's avatar
Jochen Becher committed
261

262
    qreal spanAngle() const { return m_spanAngle; }
Jochen Becher's avatar
Jochen Becher committed
263 264 265 266 267 268 269 270 271 272 273 274 275

public:

    IShape *Clone() const;

public:

    void accept(ShapeVisitor *visitor);

    void accept(ShapeConstVisitor *visitor) const;

private:

276 277 278 279
    ShapePointF m_center;
    ShapeSizeF m_radius;
    qreal m_startAngle;
    qreal m_spanAngle;
Jochen Becher's avatar
Jochen Becher committed
280 281 282 283 284 285 286 287 288
};


class QMT_EXPORT PathShape
        : public IShape
{
public:

    enum ElementType {
289 290 291 292 293 294
        TypeNone,
        TypeMoveto,
        TypeLineto,
        TypeArcmoveto,
        TypeArcto,
        TypeClose
Jochen Becher's avatar
Jochen Becher committed
295 296
    };

297 298 299
    class Element
    {
    public:
300
        explicit Element(ElementType element = TypeNone)
301 302 303
            : m_elementType(element),
              m_angle1(0.0),
              m_angle2(0.0)
Jochen Becher's avatar
Jochen Becher committed
304 305 306
        {
        }

307 308 309 310 311
        ElementType m_elementType;
        ShapePointF m_position;
        ShapeSizeF m_size;
        qreal m_angle1;
        qreal m_angle2;
Jochen Becher's avatar
Jochen Becher committed
312 313 314 315 316 317 318 319 320
    };

public:
    PathShape();

    ~PathShape();

public:

321
    QList<Element> elements() const { return m_elements; }
Jochen Becher's avatar
Jochen Becher committed
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340

public:

    IShape *Clone() const;

public:

    void accept(ShapeVisitor *visitor);

    void accept(ShapeConstVisitor *visitor) const;

public:

    void moveTo(const ShapePointF &pos);

    void lineTo(const ShapePointF &pos);

    void arcMoveTo(const ShapePointF &center, const ShapeSizeF &radius, qreal angle);

341
    void arcTo(const ShapePointF &center, const ShapeSizeF &radius, qreal startAngle, qreal sweepLength);
Jochen Becher's avatar
Jochen Becher committed
342 343 344 345 346

    void close();

private:

347
    QList<Element> m_elements;
Jochen Becher's avatar
Jochen Becher committed
348 349 350 351 352 353

};

}

#endif // QMT_SHAPES_H