File indexing completed on 2024-06-02 04:35:05
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 LABELITEM_H 0014 #define LABELITEM_H 0015 0016 #include "viewitem.h" 0017 #include "labelrenderer.h" 0018 #include "graphicsfactory.h" 0019 0020 namespace Label { 0021 struct Parsed; 0022 } 0023 0024 namespace Kst { 0025 0026 class ScriptInterface; 0027 0028 class LabelItem : public ViewItem { 0029 Q_OBJECT 0030 public: 0031 LabelItem(View *parent, const QString& labelText); 0032 virtual ~LabelItem(); 0033 0034 const QString defaultsGroupName() const {return LabelItem::staticDefaultsGroupName();} 0035 static QString staticDefaultsGroupName() { return QString("label");} 0036 0037 // for view item dialogs 0038 virtual bool hasStroke() const {return true;} 0039 virtual bool hasBrush() const {return true;} 0040 virtual bool hasFont() const {return true;} 0041 0042 virtual void save(QXmlStreamWriter &xml); 0043 virtual void paint(QPainter *painter); 0044 0045 QString labelText(); 0046 void setLabelText(const QString &text); 0047 0048 qreal labelScale(); 0049 void setLabelScale(const qreal scale); 0050 0051 QColor labelColor() const; 0052 void setLabelColor(const QColor &color); 0053 0054 QFont labelFont() const; 0055 void setLabelFont(const QFont &font); 0056 0057 void applyDefaults(); 0058 void saveAsDialogDefaults() const; 0059 static void saveDialogDefaultsFont(const QFont &F, const QColor &C); 0060 0061 virtual void setFont(const QFont &f, const QColor &c); 0062 0063 virtual void updateDataRelativeRect(bool force = false); 0064 virtual void applyDataLockedDimensions(); 0065 virtual void updateChildGeometry(const QRectF &oldParentRect, const QRectF &newParentRect); 0066 0067 bool fixLeft() const {return _fixleft;} 0068 void setFixLeft(bool fix_left) {_fixleft = fix_left;} 0069 0070 virtual bool customDimensionsTab() {return true;} 0071 0072 Label::RenderContext *_labelRc; 0073 0074 bool inputsChanged(qint64 serial); 0075 0076 virtual ScriptInterface *createScriptInterface(); 0077 public Q_SLOTS: 0078 virtual void edit(); 0079 void setDirty() { _dirty = true; } 0080 void triggerUpdate(); 0081 0082 protected Q_SLOTS: 0083 virtual void creationPolygonChanged(View::CreationEvent event); 0084 virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event); 0085 0086 private: 0087 void generateLabel(QPainter *p); 0088 0089 QTransform _paintTransform; 0090 bool _dirty; 0091 QString _text; 0092 qreal _scale; 0093 QColor _color; 0094 QFont _font; 0095 qreal _height; 0096 bool _resized; 0097 bool _dataRelativeDimValid; 0098 bool _fixleft; 0099 qint64 _serialOfLastChange; 0100 }; 0101 0102 0103 class CreateLabelCommand : public CreateCommand { 0104 public: 0105 CreateLabelCommand() : CreateCommand(QObject::tr("Create Label")) {} 0106 CreateLabelCommand(View *view): CreateCommand(view, QObject::tr("Create Label")) {} 0107 virtual ~CreateLabelCommand() {} 0108 virtual void createTextItem(QString *inText = 0); 0109 virtual void createItem(); 0110 }; 0111 0112 class LabelItemFactory : public GraphicsFactory { 0113 public: 0114 LabelItemFactory(); 0115 ~LabelItemFactory(); 0116 ViewItem* generateGraphics(QXmlStreamReader& stream, ObjectStore *store, View *view, ViewItem *parent = 0); 0117 }; 0118 0119 } 0120 0121 #endif 0122 0123 // vim: ts=2 sw=2 et