File indexing completed on 2024-12-22 04:17:25

0001 /***************************************************************************
0002  *                                                                         *
0003  *   copyright : (C) 2007 The University of Toronto                        *
0004  *                   netterfield@astro.utoronto.ca                         *
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  ***************************************************************************/
0012 
0013 #ifndef ARROWITEM_H
0014 #define ARROWITEM_H
0015 
0016 #include "lineitem.h"
0017 #include "graphicsfactory.h"
0018 
0019 namespace Kst {
0020 
0021 class ScriptInterface;
0022 
0023 class ArrowItem : public LineItem
0024 {
0025   Q_OBJECT
0026   public:
0027     explicit ArrowItem(View *parent);
0028     virtual ~ArrowItem();
0029 
0030     const QString defaultsGroupName() const {return ArrowItem::staticDefaultsGroupName();}
0031     static QString staticDefaultsGroupName() { return QString("arrow");}
0032 
0033     // for view item dialogs
0034     virtual bool hasStroke() const {return true;}
0035     virtual bool hasBrush() const {return false;}
0036 
0037     virtual void save(QXmlStreamWriter &xml);
0038     virtual void paint(QPainter *painter);
0039 
0040     bool startArrowHead() { return _startArrowHead; }
0041     void setStartArrowHead(const bool enabled) { _startArrowHead = enabled; }
0042 
0043     bool endArrowHead() { return _endArrowHead; }
0044     void setEndArrowHead(const bool enabled) { _endArrowHead = enabled; }
0045 
0046     qreal startArrowScale() { return _startArrowScale; }
0047     void setStartArrowScale(const qreal scale) { _startArrowScale = scale; }
0048 
0049     qreal endArrowScale() { return _endArrowScale; }
0050     void setEndArrowScale(const qreal scale) { _endArrowScale = scale; }
0051 
0052     virtual QPainterPath shape() const;
0053 
0054     virtual bool customDimensionsTab() {return true;}
0055     void applyDialogDefaultsHeads();
0056 
0057     virtual ScriptInterface *createScriptInterface();
0058 
0059   public Q_SLOTS:
0060     virtual void edit();
0061 
0062   private:
0063     bool _startArrowHead;
0064     bool _endArrowHead;
0065     qreal _startArrowScale;
0066     qreal _endArrowScale;
0067     QPolygonF start, end;
0068 };
0069 
0070 class CreateArrowCommand : public CreateCommand
0071 {
0072   public:
0073     CreateArrowCommand() : CreateCommand(QObject::tr("Create Arrow")) {}
0074     CreateArrowCommand(View *view) : CreateCommand(view, QObject::tr("Create Arrow")) {}
0075     virtual ~CreateArrowCommand() {}
0076     virtual void createItem();
0077 };
0078 
0079 class ArrowItemFactory : public GraphicsFactory {
0080   public:
0081     ArrowItemFactory();
0082     ~ArrowItemFactory();
0083     ViewItem* generateGraphics(QXmlStreamReader& stream, ObjectStore *store, View *view, ViewItem *parent = 0);
0084 };
0085 
0086 }
0087 
0088 #endif
0089 
0090 // vim: ts=2 sw=2 et