File indexing completed on 2024-04-14 15:01:02

0001 /* This file is part of the KDE project
0002  *
0003  * Copyright (C) 2005-2007 Koos Vriezen <koos.vriezen@gmail.com>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Library General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, write to
0017  * the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019  */
0020 
0021 #ifndef _KMPLAYER_SMILL_H_
0022 #define _KMPLAYER_SMILL_H_
0023 
0024 #include "config-kmplayer.h"
0025 #include <qstring.h>
0026 #include <qstringlist.h>
0027 
0028 #include "kmplayerplaylist.h"
0029 #include "surface.h"
0030 
0031 struct TransTypeInfo;
0032 
0033 namespace KMPlayer {
0034 
0035 class ImageMedia;
0036 class Expression;
0037 
0038 /*
0039  * Interpretation of sizes
0040  */
0041 class KMPLAYER_NO_EXPORT SizeType {
0042 public:
0043     SizeType ();
0044     SizeType (const QString & s, bool force_perc=false);
0045     void reset ();
0046     SizeType & operator = (const QString & s);
0047     SizeType & operator = (Single d);
0048     SizeType & operator += (const SizeType & s);
0049     SizeType & operator -= (const SizeType & s);
0050     SizeType & operator /= (const int i)
0051         { perc_size /= i; abs_size /= i; return *this; }
0052     SizeType & operator *= (const float f)
0053         { perc_size *= f; abs_size *= f; return *this; }
0054     Single size (Single relative_to = 100) const;
0055     bool isSet () const { return isset; }
0056     QString toString () const;
0057 private:
0058     Single perc_size;
0059     Single abs_size;
0060     bool isset;
0061     bool has_percentage;
0062 };
0063 
0064 /**
0065  * For RegPoint, Region and MediaType, having sizes
0066  */
0067 class KMPLAYER_NO_EXPORT CalculatedSizer {
0068 public:
0069     KDE_NO_CDTOR_EXPORT CalculatedSizer () {}
0070     KDE_NO_CDTOR_EXPORT ~CalculatedSizer () {}
0071 
0072     void resetSizes ();
0073     void calcSizes (Node *, CalculatedSizer *region_sz, Single w, Single h,
0074             Single & xoff, Single & yoff, Single & w1, Single & h1);
0075     bool applyRegPoints (Node *, CalculatedSizer *region_sz, Single w, Single h,
0076             Single & xoff, Single & yoff, Single & w1, Single & h1);
0077     SizeType left, top, width, height, right, bottom;
0078     QString reg_point, reg_align;
0079     bool setSizeParam (const TrieString &name, const QString &value);
0080     void move (const SizeType &x, const SizeType &y);
0081 };
0082 
0083 /**
0084  * Live representation of a SMIL element having timings
0085  */
0086 class KMPLAYER_NO_EXPORT Runtime {
0087 public:
0088     enum TimingState {
0089         TimingsInit = 0, TimingsInitialized, TimingsDisabled,
0090         timings_began, timings_started, TimingsTransIn, timings_paused,
0091         timings_stopped, timings_freezed
0092     };
0093     enum Fill {
0094         fill_default, fill_inherit, fill_remove, fill_freeze,
0095         fill_hold, fill_transition, fill_auto
0096     };
0097     enum DurationTime { BeginTime = 0, DurTime, EndTime, DurTimeLast };
0098     enum Duration {
0099         DurIndefinite = -1,
0100         DurTimer = (int) MsgEventTimer,
0101         DurActivated = (int) MsgEventClicked,
0102         DurInBounds = (int) MsgEventPointerInBounds,
0103         DurOutBounds = (int) MsgEventPointerOutBounds,
0104         DurStart = (int) MsgEventStarted,
0105         DurEnd = (int) MsgEventStopped,
0106         DurMedia = (int)MsgMediaFinished,
0107         DurStateChanged = (int)MsgStateChanged,
0108         DurAccessKey = (int)MsgAccessKey,
0109         DurTransition,
0110         DurLastDuration
0111     };
0112     Runtime (Element *e);
0113     ~Runtime ();
0114     /**
0115      * Called when element is pulled in scope, from Node::activate()
0116      */
0117     void start ();
0118     void tryFinish () { propagateStop (false); }
0119     void doFinish () { propagateStop (true); }
0120     void finish ();
0121     void startAndBeginNode (); // skip start timer (if any)
0122     /**
0123      * Reset all data, called from end() and init()
0124      */
0125     void init ();
0126     void initialize ();
0127     bool parseParam (const TrieString & name, const QString & value);
0128     TimingState state () const { return timingstate; }
0129     void message (MessageType msg, void *content=NULL);
0130     void *role (RoleType msg, void *content=NULL);
0131     /**
0132      * Duration items, begin/dur/end, length information or connected element
0133      */
0134     struct DurationItem {
0135         DurationItem ();
0136         DurationItem &operator = (const DurationItem &other);
0137         bool matches (const Duration dur, const Posting *post);
0138         void clear();
0139         Duration durval;
0140         int offset;
0141         VirtualVoid *payload;
0142         ConnectionLink connection;
0143         DurationItem *next;
0144     } durations [(const int) DurTimeLast];
0145     void setDuration ();
0146     bool started () const;
0147     bool active () const {
0148         return timingstate >= timings_started && timingstate != timings_stopped;
0149     }
0150     void stopped ();
0151     KDE_NO_EXPORT DurationItem & beginTime () { return durations[BeginTime]; }
0152     KDE_NO_EXPORT DurationItem & durTime () { return durations[DurTime]; }
0153     KDE_NO_EXPORT DurationItem & endTime () { return durations [EndTime]; }
0154 
0155     TimingState timingstate;
0156     TimingState unpaused_state;
0157     int repeat_count;
0158     QString expr;
0159     ConnectionList m_StartListeners;        // Element about to be started
0160     ConnectionList m_StartedListeners;      // Element is started
0161     ConnectionList m_StoppedListeners;      // Element stopped
0162     Posting *begin_timer;
0163     Posting *duration_timer;
0164     Posting *started_timer;
0165     Posting *stopped_timer;
0166     NodePtrW paused_by;
0167     unsigned int start_time;
0168     unsigned int finish_time;
0169     unsigned int paused_time;
0170     Fill fill;
0171     Fill fill_def;
0172     Fill fill_active;
0173     Element *element;
0174     int trans_in_dur;
0175 private:
0176     void propagateStop (bool forced);
0177     void propagateStart ();
0178     int repeat;
0179 };
0180 
0181 class KMPLAYER_NO_EXPORT MouseListeners {
0182 public:
0183     MouseListeners();
0184 
0185     ConnectionList *receivers (MessageType msg);
0186 
0187     ConnectionList m_ActionListeners;      // mouse clicked
0188     ConnectionList m_OutOfBoundsListeners; // mouse left
0189     ConnectionList m_InBoundsListeners;    // mouse entered
0190 };
0191 
0192 /**
0193  * Translates string to centi-seconds or 'special' high number
0194  */
0195 bool parseTime (const QString & val, int & dur /*,const QString & dateformat*/);
0196 
0197 class KMPLAYER_NO_EXPORT SmilTextProperties {
0198 public:
0199     enum Align { AlignInherit, AlignLeft, AlignCenter, AlignRight };
0200     enum FontWeight { WeightNormal, WeightBold, WeightInherit };
0201     enum Spacing { SpaceDefault, SpacePreserve };
0202     enum Style {
0203         StyleNormal, StyleItalic, StyleOblique, StyleRevOblique, StyleInherit
0204     };
0205     enum TextDirection { DirLtr, DirRtl, DirLtro, DirRtlo, DirInherit };
0206     enum TextMode { ModeAppend, ModeReplace, ModeInherit };
0207     enum TextPlace { PlaceStart, PlaceCenter, PlaceEnd, PlaceInherit };
0208     enum TextWrap { Wrap, NoWrap, WrapInherit };
0209     enum TextWriting { WritingLrTb, WritingRlTb, WritingTbLr, WritingTbRl };
0210 
0211     void init ();
0212     bool parseParam (const TrieString &name, const QString &value);
0213     void mask (const SmilTextProperties &props);
0214 
0215     QString font_family;
0216     QString text_style;
0217     int font_color;
0218     int background_color;
0219     unsigned char text_direction;
0220     unsigned char font_style;
0221     unsigned char font_weight;
0222     unsigned char text_mode;
0223     unsigned char text_place;
0224     unsigned char text_wrap;
0225     unsigned char space;
0226     unsigned char text_writing;
0227     unsigned char text_align;
0228     unsigned char padding;
0229     SizeType font_size;
0230 };
0231 
0232 class KMPLAYER_NO_EXPORT SmilColorProperty {
0233 public:
0234     void init ();
0235     void setColor (const QString &value);
0236     void setOpacity (const QString &value);
0237 
0238     unsigned int color;
0239     int opacity;
0240 };
0241 
0242 class KMPLAYER_NO_EXPORT MediaOpacity {
0243 public:
0244     void init ();
0245 
0246     unsigned short opacity;
0247     unsigned short bg_opacity;
0248 };
0249 
0250 class KMPLAYER_NO_EXPORT TransitionModule {
0251 public:
0252     TransitionModule ()
0253      : trans_start_time (0),
0254        trans_out_timer (NULL),
0255        trans_out_active (false) {}
0256 
0257     void init ();
0258     void begin (Node *n, Runtime *r);
0259     bool handleMessage (Node *n, Runtime *r, Surface *s, MessageType m, void *);
0260     void cancelTimer (Node *n);
0261     void finish (Node *n);
0262 
0263     NodePtrW trans_in;
0264     NodePtrW trans_out;
0265     NodePtrW active_trans;
0266     unsigned int trans_start_time;
0267     unsigned int trans_end_time;
0268     Posting *trans_out_timer;
0269     float trans_gain;
0270     ConnectionList m_TransformedIn;        // transIn ready
0271     ConnectionLink transition_updater;
0272     bool trans_out_active;
0273 };
0274 
0275 //-----------------------------------------------------------------------------
0276 
0277 namespace SMIL {
0278 
0279 const short id_node_smil = 100;
0280 const short id_node_head = 101;
0281 const short id_node_state = 102;
0282 const short id_node_layout = 103;
0283 const short id_node_root_layout = 104;
0284 const short id_node_region = 105;
0285 const short id_node_regpoint = 106;
0286 const short id_node_transition = 107;
0287 const short id_node_body = 110;
0288 const short id_node_par = 111;
0289 const short id_node_seq = 112;
0290 const short id_node_switch = 113;
0291 const short id_node_excl = 114;
0292 const short id_node_text = 120;
0293 const short id_node_ref = 121;
0294 const short id_node_brush = 122;
0295 const short id_node_smil_text = 123;
0296 const short id_node_tev = 124;
0297 const short id_node_clear = 125;
0298 const short id_node_text_styling = 126;
0299 const short id_node_set_value = 127;
0300 const short id_node_new_value = 128;
0301 const short id_node_del_value = 129;
0302 const short id_node_send = 130;
0303 const short id_node_set = 132;
0304 const short id_node_animate = 133;
0305 const short id_node_animate_color = 134;
0306 const short id_node_animate_motion = 135;
0307 const short id_node_title = 140;
0308 const short id_node_param = 141;
0309 const short id_node_meta = 142;
0310 const short id_node_priorityclass = 143;
0311 const short id_node_div = 144;
0312 const short id_node_span = 145;
0313 const short id_node_p = 146;
0314 const short id_node_br = 147;
0315 const short id_node_anchor = 150;
0316 const short id_node_area = 151;
0317 const short id_node_state_data = 151;
0318 const short id_node_first = id_node_smil;
0319 const short id_node_first_timed_mrl = id_node_body;
0320 const short id_node_last_timed_mrl = id_node_animate_motion;
0321 const short id_node_first_mediatype = id_node_text;
0322 const short id_node_last_mediatype = id_node_brush;
0323 const short id_node_first_group = id_node_body;
0324 const short id_node_last_group = id_node_excl;
0325 const short id_node_last = 200; // reserve 100 ids
0326 
0327 /**
0328  * '<smil>' tag
0329  */
0330 class Smil : public Mrl {
0331 public:
0332     KDE_NO_CDTOR_EXPORT Smil (NodePtr & d) : Mrl (d, id_node_smil) {}
0333     Node *childFromTag (const QString & tag);
0334     KDE_NO_EXPORT const char * nodeName () const { return "smil"; }
0335     PlayType playType () { return play_type_video; }
0336     void activate ();
0337     void deactivate ();
0338     void closed ();
0339     void *role (RoleType msg, void *content=NULL);
0340     void message (MessageType msg, void *content=NULL);
0341     void accept (Visitor *v) { v->visit (this); }
0342     void jump (const QString & id);
0343     static Smil * findSmilNode (Node * node);
0344 
0345     NodePtrW layout_node;
0346     NodePtrW state_node;
0347 };
0348 
0349 /**
0350  * Represents optional 'head' tag of SMIL document as in
0351  * &lt;smil&gt;&lt;head/&gt;&lt;body/&gt;&lt;/smil&gt;
0352  */
0353 class KMPLAYER_NO_EXPORT Head : public Element {
0354 public:
0355     KDE_NO_CDTOR_EXPORT Head (NodePtr & d) : Element (d, id_node_head) {}
0356     Node *childFromTag (const QString & tag);
0357     KDE_NO_EXPORT const char * nodeName () const { return "head"; }
0358     void closed ();
0359     void message (MessageType msg, void *content=NULL);
0360 };
0361 
0362 /**
0363  * Defines state, should reside below 'head' element
0364  */
0365 class KMPLAYER_NO_EXPORT State : public Element {
0366 public:
0367     enum Where { before, after, child };
0368     enum Method { get, put };
0369     enum Replace { all, instance, none };
0370 
0371     State (NodePtr & d);
0372 
0373     virtual Node *childFromTag (const QString & tag);
0374     virtual void closed ();
0375     virtual void activate ();
0376     virtual void parseParam (const TrieString & name, const QString & value);
0377     virtual void deactivate ();
0378     virtual void message (MessageType msg, void *content=NULL);
0379     virtual void *role (RoleType msg, void *content=NULL);
0380     KDE_NO_EXPORT virtual const char * nodeName () const { return "state"; }
0381 
0382     QString domain ();
0383     void newValue (Node *ref, Where w, const QString &name, const QString &val);
0384     void setValue (Node *ref, const QString &value);
0385     void delValue (Node *ref);
0386     void stateChanged (Node *ref);
0387 
0388     ConnectionList m_StateChangeListeners;        // setValue changed a value
0389     PostponePtr postpone_lock;                    // pause while loading src
0390     MediaInfo *media_info;
0391     QString m_url;
0392 };
0393 
0394 /**
0395  * Defines region layout, should reside below 'head' element
0396  */
0397 class KMPLAYER_NO_EXPORT Layout : public Element {
0398 public:
0399     Layout (NodePtr & d);
0400     Node *childFromTag (const QString & tag);
0401     KDE_NO_EXPORT const char * nodeName () const { return "layout"; }
0402     void closed ();
0403     void message (MessageType msg, void *content=NULL);
0404     void accept (Visitor *v) { v->visit (this); }
0405 
0406     NodePtrW root_layout;
0407 };
0408 
0409 /**
0410  * Base class for SMIL::Region, SMIL::RootLayout and SMIL::Layout
0411  */
0412 class KMPLAYER_NO_EXPORT RegionBase : public Element {
0413 public:
0414     enum ShowBackground { ShowAlways, ShowWhenActive };
0415 
0416     ~RegionBase ();
0417     virtual void activate ();
0418     virtual void deactivate ();
0419     virtual void parseParam (const TrieString & name, const QString & value);
0420     virtual void message (MessageType msg, void *content=NULL);
0421     virtual void *role (RoleType msg, void *content=NULL);
0422     virtual void accept (Visitor *v) { v->visit (this); }
0423     /**
0424      * repaints region, calls scheduleRepaint(x,y,w,h) on view
0425      */
0426     void repaint ();
0427     void repaint (const SRect & rect);
0428 
0429     SurfacePtrW region_surface;
0430     MediaInfo *media_info;
0431     CalculatedSizer sizes;
0432 
0433     int z_order;
0434     SmilColorProperty background_color;
0435     MediaOpacity media_opacity;
0436     QString background_image;
0437     enum BackgroundRepeat {
0438         BgRepeat, BgRepeatX, BgRepeatY, BgNoRepeat, BgInherit
0439     } bg_repeat;
0440     ShowBackground show_background;
0441     Fit fit;
0442     SmilTextProperties font_props;
0443     ConnectionList m_AttachedMediaTypes;   // active attached mediatypes
0444 protected:
0445     RegionBase (NodePtr & d, short id);
0446     PostponePtr postpone_lock;               // pause while loading bg image
0447     void dataArrived (); // image downloaded
0448 };
0449 
0450 /**
0451  * Represents the root area for the other regions
0452  */
0453 class KMPLAYER_NO_EXPORT RootLayout : public RegionBase {
0454 public:
0455     KDE_NO_CDTOR_EXPORT RootLayout (NodePtr & d)
0456         : RegionBase (d, id_node_root_layout) {}
0457     ~RootLayout ();
0458     void closed ();
0459     void deactivate ();
0460     void message (MessageType msg, void *content=NULL);
0461     void *role (RoleType msg, void *content=NULL);
0462     KDE_NO_EXPORT const char * nodeName () const { return "root-layout"; }
0463 };
0464 
0465 /**
0466  * Represents a rectangle on the viewing area
0467  */
0468 class KMPLAYER_NO_EXPORT Region : public RegionBase {
0469 public:
0470     Region (NodePtr & d);
0471     ~Region ();
0472     void deactivate ();
0473     KDE_NO_EXPORT const char * nodeName () const { return "region"; }
0474     Node *childFromTag (const QString & tag);
0475     void message (MessageType msg, void *content=NULL);
0476     void *role (RoleType msg, void *content=NULL);
0477 private:
0478     MouseListeners mouse_listeners;
0479 };
0480 
0481 /**
0482  * Represents a regPoint element for alignment inside regions
0483  */
0484 class KMPLAYER_NO_EXPORT RegPoint : public Element {
0485 public:
0486     KDE_NO_CDTOR_EXPORT RegPoint (NodePtr & d) : Element(d, id_node_regpoint) {}
0487     KDE_NO_CDTOR_EXPORT ~RegPoint () {}
0488     KDE_NO_EXPORT const char * nodeName () const { return "regPoint"; }
0489     void parseParam (const TrieString & name, const QString & value);
0490     CalculatedSizer sizes;
0491 };
0492 
0493 /**
0494  * Represents a transition element for starting media types
0495  */
0496 class KMPLAYER_NO_EXPORT Transition : public Element {
0497 public:
0498     enum TransType {
0499         TransTypeNone = 0,
0500         BarWipe, IrisWipe, ClockWipe, SnakeWipe, // required, TODO
0501         BoxWipe, FourBoxWipe, BarnDoorWipe, DiagonalWipe, BowTieWipe,
0502         MiscDiagonalWipe, VeeWipe, BarnVeeWipe, ZigZagWipe, BarnZigZagWipe,
0503         TriangleWipe, ArrowHeadWipe, PentagonWipe, HexagonWipe, EllipseWipe,
0504         EyeWipe, RoundRectWipe, StarWipe, MiscShapeWipe,
0505         PinWheelWipe, SingleSweepWipe, FanWipe, DoubleFanWipe,
0506         DoubleSweepWipe, SaloonDoorWipe, WindShieldWipe,
0507         SpiralWipe, ParallelSnakesWipe, BoxSnakesWipe, WaterFallWipe,
0508         PushWipe, SideWipe, Fade,
0509         TransLast
0510     };
0511     enum TransSubType {
0512         SubTransTypeNone = 0,
0513         SubLeftToRight, SubTopToBottom, SubTopLeft, SubTopRight,
0514         SubBottomRight, SubBottomLeft,
0515         SubTopCenter, SubRightCenter, SubBottomCenter, SubLeftCenter,
0516         SubCornersIn, SubCornersOut,
0517         SubCircle, SubVertical, SubHorizontal,
0518         SubFromLeft, SubFromTop, SubFromRight, SubFromBottom,
0519         SubCrossfade, SubFadeToColor, SubFadeFromColor,
0520         SubRectangle, SubDiamond,
0521         SubClockwiseTwelve, SubClockwiseThree, SubClockwiseSix,
0522         SubClockwiseNine,
0523          // and lots more .. TODO
0524         SubTransLast
0525     };
0526     Transition (NodePtr & d);
0527     KDE_NO_CDTOR_EXPORT ~Transition () {}
0528     void activate ();
0529     KDE_NO_EXPORT void accept (Visitor * v) { v->visit (this); }
0530     KDE_NO_EXPORT const char * nodeName () const { return "transition"; }
0531     void parseParam (const TrieString & name, const QString & value);
0532     bool supported ();
0533     TransType type;
0534     TransSubType sub_type;
0535     TransTypeInfo *type_info;
0536     enum { dir_forward, dir_reverse } direction;
0537     int dur; // centi seconds
0538     float start_progress, end_progress;
0539     unsigned int fade_color;
0540 };
0541 
0542 /**
0543  * Abstract base for the group elements (par/seq/excl/..)
0544  */
0545 class KMPLAYER_NO_EXPORT GroupBase : public Element {
0546 public:
0547     ~GroupBase ();
0548     Node *childFromTag (const QString & tag);
0549     PlayType playType () { return play_type_none; }
0550     void parseParam (const TrieString &name, const QString &value);
0551     void init ();
0552     void finish ();
0553     void activate ();
0554     void deactivate ();
0555     void reset ();
0556     void message (MessageType msg, void *content=NULL);
0557     void *role (RoleType msg, void *content=NULL);
0558     void setJumpNode (NodePtr);
0559     Runtime *runtime;
0560 protected:
0561     GroupBase (NodePtr & d, short id);
0562     NodePtrW jump_node;
0563 };
0564 
0565 /**
0566  * A Par represents parallel processing of all its children
0567  */
0568 class KMPLAYER_NO_EXPORT Par : public GroupBase {
0569 public:
0570     KDE_NO_CDTOR_EXPORT Par (NodePtr & d) : GroupBase (d, id_node_par) {}
0571     KDE_NO_EXPORT const char * nodeName () const { return "par"; }
0572     void begin ();
0573     void reset ();
0574     void message (MessageType msg, void *content=NULL);
0575     void *role (RoleType msg, void *content=NULL);
0576     KDE_NO_EXPORT void accept (Visitor * v) { v->visit (this); }
0577 };
0578 
0579 /**
0580  * A Seq represents sequential processing of all its children
0581  */
0582 class KMPLAYER_NO_EXPORT Seq : public GroupBase {
0583 public:
0584     KDE_NO_CDTOR_EXPORT Seq (NodePtr & d) : GroupBase(d, id_node_seq) {}
0585     KDE_NO_EXPORT const char * nodeName () const { return "seq"; }
0586     void begin ();
0587     void message (MessageType msg, void *content=NULL);
0588     void *role (RoleType msg, void *content=NULL);
0589     KDE_NO_EXPORT void accept (Visitor * v) { v->visit (this); }
0590     ConnectionLink starting_connection;
0591     ConnectionLink trans_connection;
0592 protected:
0593     KDE_NO_CDTOR_EXPORT Seq (NodePtr & d, short id) : GroupBase(d, id) {}
0594 };
0595 
0596 /**
0597  * Represents the 'body' tag of SMIL document as in
0598  * &lt;smil&gt;&lt;head/&gt;&lt;body/&gt;&lt;/smil&gt;
0599  */
0600 class KMPLAYER_NO_EXPORT Body : public Seq {
0601 public:
0602     KDE_NO_CDTOR_EXPORT Body (NodePtr & d) : Seq (d, id_node_body) {}
0603     KDE_NO_EXPORT const char * nodeName () const { return "body"; }
0604 };
0605 
0606 /**
0607  * An Excl represents exclusive processing of one of its children
0608  */
0609 class KMPLAYER_NO_EXPORT Excl : public GroupBase {
0610 public:
0611     Excl (NodePtr & d);
0612     ~Excl ();
0613     KDE_NO_EXPORT const char * nodeName () const { return "excl"; }
0614     Node *childFromTag (const QString & tag);
0615     void begin ();
0616     void deactivate ();
0617     void message (MessageType msg, void *content=NULL);
0618     KDE_NO_EXPORT void accept (Visitor * v) { v->visit (this); }
0619 
0620     struct ConnectionItem {
0621         ConnectionItem (ConnectionItem *n) : next (n) {}
0622         ConnectionLink link;
0623         ConnectionItem *next;
0624     } *started_event_list;
0625     ConnectionLink stopped_connection;
0626     NodeRefList priority_queue;
0627     NodePtrW cur_node;
0628 };
0629 
0630 /**
0631  * A PriorityClass groups children within an Excl element
0632  */
0633 class KMPLAYER_NO_EXPORT PriorityClass : public Element {
0634 public:
0635     KDE_NO_CDTOR_EXPORT PriorityClass (NodePtr &d)
0636         : Element (d, id_node_priorityclass) {}
0637     KDE_NO_EXPORT const char * nodeName () const { return "priorityClass"; }
0638     Node *childFromTag (const QString & tag);
0639     void init ();
0640     void parseParam (const TrieString &, const QString &);
0641     void message (MessageType msg, void *content=NULL);
0642     KDE_NO_EXPORT void accept (Visitor * v) { v->visit (this); }
0643 
0644     enum { PeersStop, PeersPause, PeersDefer, PeersNever } peers;
0645     enum { HigherStop, HigherPause } higher;
0646     enum { LowerDefer, LowerNever } lower;
0647     enum { PauseDisplayDisable, PauseDisplayHide, PauseDisplayShow } pause_display;
0648 };
0649 
0650 /*
0651  * An automatic selection between child elements based on a condition
0652  */
0653 class KMPLAYER_NO_EXPORT Switch : public GroupBase {
0654 public:
0655     KDE_NO_CDTOR_EXPORT Switch (NodePtr &d) : GroupBase (d, id_node_switch) {}
0656     KDE_NO_EXPORT const char * nodeName () const { return "switch"; }
0657     // Condition
0658     void begin ();
0659     void init ();
0660     void deactivate ();
0661     void reset ();
0662     void message (MessageType msg, void *content=NULL);
0663     KDE_NO_EXPORT void accept (Visitor * v) { v->visit (this); }
0664 
0665     Node *chosenOne ();
0666 private:
0667     NodePtrW chosen_one;
0668 };
0669 
0670 class KMPLAYER_NO_EXPORT LinkingBase : public Element {
0671 public:
0672     KDE_NO_CDTOR_EXPORT ~LinkingBase () {}
0673     void deactivate ();
0674     void parseParam (const TrieString & name, const QString & value);
0675     ConnectionLink mediatype_attach;
0676     QString href;
0677     QString target;
0678     enum { show_new, show_replace } show;
0679 protected:
0680     LinkingBase (NodePtr & d, short id);
0681 };
0682 
0683 class KMPLAYER_NO_EXPORT Anchor : public LinkingBase {
0684 public:
0685     Anchor (NodePtr & d);
0686     KDE_NO_CDTOR_EXPORT ~Anchor () {}
0687     void activate ();
0688     void message (MessageType msg, void *content=NULL);
0689     void *role (RoleType msg, void *content=NULL);
0690     KDE_NO_EXPORT const char * nodeName () const { return "a"; }
0691     Node *childFromTag (const QString & tag);
0692     KDE_NO_EXPORT void accept (Visitor * v) { v->visit (this); }
0693 };
0694 
0695 class KMPLAYER_NO_EXPORT Area : public LinkingBase {
0696 public:
0697     Area (NodePtr & d, const QString & tag);
0698     ~Area ();
0699     void activate ();
0700     KDE_NO_EXPORT const char * nodeName () const { return tag.constData (); }
0701     KDE_NO_EXPORT void accept (Visitor * v) { v->visit (this); }
0702     void parseParam (const TrieString & name, const QString & value);
0703     void *role (RoleType msg, void *content=NULL);
0704     SizeType * coords;
0705     int nr_coords;
0706     const QByteArray tag;
0707     MouseListeners mouse_listeners;
0708 };
0709 
0710 /**
0711  * Abstract base for the MediaType classes (video/audio/text/img/..)
0712  */
0713 class KMPLAYER_NO_EXPORT MediaType : public Mrl {
0714 public:
0715     MediaType (NodePtr & d, const QByteArray& t, short id);
0716     ~MediaType ();
0717 
0718     Node *childFromTag (const QString & tag);
0719     KDE_NO_EXPORT const char * nodeName () const { return m_type.constData (); }
0720     virtual void closed ();
0721     virtual void init ();
0722     virtual void activate ();
0723     virtual void deactivate ();
0724     virtual void defer ();
0725     virtual void undefer ();
0726     virtual void begin ();
0727     virtual void finish ();
0728     virtual void reset ();
0729     SRect calculateBounds ();
0730     virtual void parseParam (const TrieString & name, const QString & value);
0731     virtual void message (MessageType msg, void *content=NULL);
0732     virtual void *role (RoleType msg, void *content=NULL);
0733     virtual void accept (Visitor *v) { v->visit (this); }
0734 
0735     Surface *surface ();
0736 
0737     Runtime *runtime;
0738     SurfacePtrW sub_surface;
0739     NodePtrW external_tree; // if src points to playlist, the resolved top node
0740     TransitionModule transition;
0741     NodePtrW region_node;
0742     QByteArray m_type;
0743     CalculatedSizer sizes;
0744     CalculatedSizer *pan_zoom;
0745     Fit fit;
0746     Fit effective_fit;
0747     SmilColorProperty background_color;
0748     MediaOpacity media_opacity;
0749     unsigned int bitrate;
0750     enum { sens_opaque, sens_transparent, sens_percentage } sensitivity;
0751 
0752 protected:
0753     virtual void prefetch ();
0754     virtual void clipStart ();
0755     virtual void clipStop ();
0756 
0757     MouseListeners mouse_listeners;
0758     ConnectionList m_MediaAttached;
0759     ConnectionLink region_attach;          // attached to region
0760     ConnectionLink document_postponed;     // pause audio/video accordantly
0761     PostponePtr postpone_lock;
0762 };
0763 
0764 class KMPLAYER_NO_EXPORT RefMediaType : public MediaType {
0765 public:
0766     RefMediaType (NodePtr &doc, const QByteArray &tag);
0767     Node *childFromTag (const QString & tag);
0768     virtual void activate ();
0769     virtual void begin ();
0770     virtual void finish ();
0771     virtual PlayType playType ();
0772     virtual void accept (Visitor *);
0773     virtual void message (MessageType msg, void *content=NULL);
0774     virtual void *role (RoleType msg, void *content=NULL);
0775     virtual void prefetch ();
0776     virtual void clipStart ();
0777 };
0778 
0779 class KMPLAYER_NO_EXPORT TextMediaType : public MediaType {
0780 public:
0781     TextMediaType (NodePtr & d);
0782     PlayType playType () { return play_type_info; }
0783     virtual void init ();
0784     virtual void accept (Visitor *);
0785     virtual void parseParam (const TrieString &, const QString &);
0786     virtual void prefetch ();
0787 
0788     QString font_name;
0789     int font_size;
0790     unsigned int font_color;
0791     enum { align_left, align_center, align_right } halign;
0792 };
0793 
0794 class KMPLAYER_NO_EXPORT Brush : public MediaType {
0795 public:
0796     Brush (NodePtr & d);
0797     virtual void init ();
0798     virtual void accept (Visitor *);
0799     virtual void parseParam (const TrieString &, const QString &);
0800     SmilColorProperty color;
0801 };
0802 
0803 class KMPLAYER_NO_EXPORT SmilText : public Element {
0804 public:
0805     SmilText (NodePtr &doc);
0806     ~SmilText ();
0807     virtual void init ();
0808     virtual void activate ();
0809     virtual void begin ();
0810     virtual void finish ();
0811     virtual void deactivate ();
0812     virtual void reset ();
0813     KDE_NO_EXPORT const char *nodeName () const { return "smilText"; }
0814     Node *childFromTag (const QString & tag);
0815     virtual void parseParam (const TrieString &name, const QString &value);
0816     virtual void message (MessageType msg, void *content=NULL);
0817     virtual void *role (RoleType msg, void *content=NULL);
0818     virtual void accept (Visitor *v) { v->visit (this); }
0819 
0820     Surface *surface ();
0821     void updateBounds (bool remove);
0822 
0823     SmilColorProperty background_color;
0824     MediaOpacity media_opacity;
0825     TransitionModule transition;
0826     SmilTextProperties props;
0827     SurfacePtrW text_surface;
0828     NodePtrW region_node;
0829     CalculatedSizer sizes;
0830     SSize size;
0831     ConnectionLink region_attach;
0832     ConnectionList media_attached;
0833     MouseListeners mouse_listeners;
0834     Runtime *runtime;
0835 };
0836 
0837 class KMPLAYER_NO_EXPORT TextFlow : public Element {
0838 public:
0839     TextFlow (NodePtr &doc, short id, const QByteArray &tag);
0840     ~TextFlow ();
0841 
0842     virtual void init ();
0843     virtual void activate ();
0844     KDE_NO_EXPORT const char *nodeName () const { return tag.data (); }
0845     Node *childFromTag (const QString &tag);
0846     virtual void parseParam (const TrieString &name, const QString &value);
0847     virtual void accept (Visitor *v) { v->visit (this); }
0848 
0849     SmilTextProperties props;
0850     QByteArray tag;
0851 };
0852 
0853 class KMPLAYER_NO_EXPORT TemporalMoment : public Element {
0854 public:
0855     TemporalMoment (NodePtr &doc, short id, const QByteArray &tag);
0856     ~TemporalMoment ();
0857     virtual void init ();
0858     virtual void activate ();
0859     virtual void begin ();
0860     virtual void deactivate ();
0861     KDE_NO_EXPORT const char *nodeName () const { return tag.data (); }
0862     Node *childFromTag (const QString & tag);
0863     virtual void parseParam (const TrieString &name, const QString &value);
0864     virtual void message (MessageType msg, void *content=NULL);
0865     virtual void *role (RoleType msg, void *content=NULL);
0866     virtual void accept (Visitor *v) { v->visit (this); }
0867 
0868     Runtime *runtime;
0869     QByteArray tag;
0870 };
0871 
0872 class KMPLAYER_NO_EXPORT StateValue : public Element {
0873 public:
0874     ~StateValue ();
0875 
0876     virtual void init ();
0877     virtual void activate ();
0878     virtual void finish ();
0879     virtual void deactivate ();
0880     virtual void reset ();
0881     virtual void parseParam (const TrieString &name, const QString &value);
0882     virtual void message (MessageType msg, void *content=NULL);
0883     virtual void *role (RoleType msg, void *content=NULL);
0884 protected:
0885     StateValue (NodePtr &d, short _id);
0886 
0887     QString value;
0888     NodePtrW state;
0889     Expression *ref;
0890     Runtime *runtime;
0891 };
0892 
0893 class KMPLAYER_NO_EXPORT NewValue : public StateValue {
0894 public:
0895     NewValue (NodePtr &d) : StateValue (d, id_node_new_value) {}
0896 
0897     virtual void init ();
0898     virtual void begin ();
0899     virtual void parseParam (const TrieString &name, const QString &value);
0900     KDE_NO_EXPORT const char *nodeName () const { return "newvalue"; }
0901 
0902 private:
0903     QString name;
0904     SMIL::State::Where where;
0905 };
0906 
0907 class KMPLAYER_NO_EXPORT SetValue : public StateValue {
0908 public:
0909     SetValue (NodePtr &d) : StateValue (d, id_node_set_value) {}
0910 
0911     virtual void begin ();
0912     KDE_NO_EXPORT const char *nodeName () const { return "setvalue"; }
0913 };
0914 
0915 class KMPLAYER_NO_EXPORT DelValue : public StateValue {
0916 public:
0917     DelValue (NodePtr &d) : StateValue (d, id_node_del_value) {}
0918 
0919     virtual void begin ();
0920     KDE_NO_EXPORT const char *nodeName () const { return "delvalue"; }
0921 };
0922 
0923 class KMPLAYER_NO_EXPORT Send : public StateValue {
0924 public:
0925     Send (NodePtr &d) : StateValue (d, id_node_send), media_info (NULL) {}
0926 
0927     virtual void init ();
0928     virtual void begin ();
0929     virtual void deactivate ();
0930     virtual void parseParam (const TrieString &name, const QString &value);
0931     virtual void message (MessageType msg, void *content=NULL);
0932     KDE_NO_EXPORT const char *nodeName () const { return "send"; }
0933 
0934 private:
0935     QString action;
0936     SMIL::State::Replace replace;
0937     SMIL::State::Method method;
0938     MediaInfo *media_info;
0939 };
0940 
0941 class KMPLAYER_NO_EXPORT AnimateGroup : public Element {
0942 public:
0943     ~AnimateGroup ();
0944     virtual void init ();
0945     virtual void activate ();
0946     virtual void finish ();
0947     virtual void deactivate ();
0948     virtual void reset ();
0949     virtual void parseParam (const TrieString & name, const QString & value);
0950     virtual void message (MessageType msg, void *content=NULL);
0951     virtual void *role (RoleType msg, void *content=NULL);
0952     Runtime *runtime;
0953 protected:
0954     virtual void restoreModification ();
0955     Node *targetElement ();
0956     AnimateGroup (NodePtr &d, short _id);
0957     NodePtrW target_element;
0958     TrieString changed_attribute;
0959     QString target_id;
0960     QString change_to;
0961     int modification_id;
0962 };
0963 
0964 class KMPLAYER_NO_EXPORT Set : public AnimateGroup {
0965 public:
0966     KDE_NO_CDTOR_EXPORT Set (NodePtr & d) : AnimateGroup (d, id_node_set) {}
0967     virtual void begin ();
0968     KDE_NO_EXPORT const char * nodeName () const { return "set"; }
0969     PlayType playType () { return play_type_none; }
0970 };
0971 
0972 class KMPLAYER_NO_EXPORT AnimateBase : public AnimateGroup {
0973 public:
0974     struct Point2D {
0975         float x;
0976         float y;
0977     };
0978     AnimateBase (NodePtr &d, short id);
0979     ~AnimateBase ();
0980 
0981     virtual void init ();
0982     virtual void begin ();
0983     virtual void finish ();
0984     virtual void deactivate ();
0985     virtual void parseParam (const TrieString & name, const QString & value);
0986     virtual void message (MessageType msg, void *content=NULL);
0987     virtual void accept (Visitor *v) { v->visit (this); }
0988     PlayType playType () { return play_type_none; }
0989 
0990     Posting *anim_timer;
0991 protected:
0992     virtual bool timerTick (unsigned int cur_time) = 0;
0993     virtual void applyStep () = 0;
0994 
0995     bool setInterval ();
0996 
0997     enum { acc_none, acc_sum } accumulate;
0998     enum { add_replace, add_sum } additive;
0999     enum { calc_discrete, calc_linear, calc_paced, calc_spline } calcMode;
1000     QString change_from;
1001     QString change_by;
1002     QStringList values;
1003     ConnectionLink change_updater;
1004     float *keytimes;
1005     Point2D *spline_table;
1006     QStringList splines;
1007     float control_point[4];
1008     unsigned int keytime_count;
1009     unsigned int keytime_steps;
1010     unsigned int interval;
1011     unsigned int interval_start_time;
1012     unsigned int interval_end_time;
1013 };
1014 
1015 class KMPLAYER_NO_EXPORT Animate : public AnimateBase {
1016 public:
1017     Animate (NodePtr &doc);
1018 
1019     virtual void init ();
1020     virtual void begin ();
1021     virtual void finish ();
1022     virtual void deactivate ();
1023     //virtual void accept (Visitor *v) { v->visit (this); }
1024     KDE_NO_EXPORT const char * nodeName () const { return "animate"; }
1025 
1026 private:
1027     virtual bool timerTick (unsigned int cur_time);
1028     virtual void applyStep ();
1029 
1030     void cleanUp ();
1031 
1032     int num_count;
1033     SizeType *begin_;
1034     SizeType *cur;
1035     SizeType *delta;
1036     SizeType *end;
1037 };
1038 
1039 class KMPLAYER_NO_EXPORT AnimateMotion : public AnimateBase {
1040 public:
1041     AnimateMotion (NodePtr &d) : AnimateBase (d, id_node_animate_motion) {}
1042 
1043     virtual void init ();
1044     virtual void begin ();
1045     virtual void finish ();
1046     //virtual void accept (Visitor *v) { v->visit (this); }
1047     KDE_NO_EXPORT const char * nodeName () const { return "animateMotion"; }
1048 
1049 private:
1050     virtual void restoreModification ();
1051     virtual bool timerTick (unsigned int cur_time);
1052     virtual void applyStep ();
1053 
1054     CalculatedSizer old_sizes;
1055     SizeType begin_x, begin_y;
1056     SizeType cur_x, cur_y;
1057     SizeType delta_x, delta_y;
1058     SizeType end_x, end_y;
1059 };
1060 
1061 class KMPLAYER_NO_EXPORT AnimateColor : public AnimateBase {
1062 public:
1063     struct Channels {
1064         short blue;
1065         short green;
1066         short red;
1067         short alpha;
1068         unsigned int argb ();
1069         void clear ();
1070         Channels &operator *= (const float f);
1071         Channels &operator += (const Channels &c);
1072         Channels &operator -= (const Channels &c);
1073     };
1074 
1075     AnimateColor (NodePtr &d) : AnimateBase (d, id_node_animate_color) {}
1076 
1077     virtual void init ();
1078     virtual void begin ();
1079     virtual void finish ();
1080     //virtual void accept (Visitor *v) { v->visit (this); }
1081     KDE_NO_EXPORT const char * nodeName () const { return "animateColor"; }
1082 
1083 private:
1084     virtual bool timerTick (unsigned int cur_time);
1085     virtual void applyStep ();
1086 
1087     Channels begin_c;
1088     Channels cur_c;
1089     Channels delta_c;
1090     Channels end_c;
1091 };
1092 
1093 // TODO transitionFilter
1094 
1095 class KMPLAYER_NO_EXPORT Param : public Element {
1096 public:
1097     KDE_NO_CDTOR_EXPORT Param (NodePtr & d) : Element (d, id_node_param) {}
1098     KDE_NO_EXPORT const char * nodeName () const { return "param"; }
1099     void activate ();
1100 };
1101 
1102 } // SMIL namespace
1103 
1104 }  // KMPlayer namespace
1105 
1106 #endif //_KMPLAYER_SMIL_H_