1 // 2 // C++ Interface: fmlayout 3 // 4 // Description: 5 // 6 // 7 // Author: Pierre Marchand <pierremarc@oep-h.com>, (C) 2008 8 // 9 // Copyright: See COPYING file that comes with this distribution 10 // 11 // 12 #ifndef FMLAYOUT_H 13 #define FMLAYOUT_H 14 15 16 #include <QObject> 17 #include <QString> 18 #include <QRectF> 19 #include <QPointF> 20 #include <QMap> 21 #include <QThread> 22 23 #include "fmsharestruct.h" 24 25 class QGraphicsScene; 26 class FontItem; 27 class QGraphicsPixmapItem; 28 class QGraphicsPathItem; 29 class QGraphicsRectItem; 30 class QGraphicsProxyWidget; 31 class QProgressBar; 32 class QAction; 33 class QMenu; 34 class QMutex; 35 class FMLayOptWidget; 36 class QDialog; 37 class QGridLayout; 38 39 /** 40 Finally, we want to layout text elsewhere than _in_ the font or _in_ the view. 41 And it’s "peu ou prou" forced if we really want to experiment in Fontmatrix 42 I hope it will not be too much more than just copy & paste from FontItem & MainViewWidget - pm 43 It has been quite more! - pm 44 **/ 45 46 #define INFINITE 99999999L 47 48 class FMLayout; 49 50 51 struct Node 52 { 53 struct ListItem 54 { 55 ListItem(); 56 ListItem ( Node* N, double D ); 57 ~ListItem() ; 58 Node* n; 59 double distance; 60 61 62 // private: 63 // ListItem (const ListItem& v); 64 }; 65 66 Node (FMLayout * layoutEngine, int i ) ; 67 ~Node(); 68 69 QList<ListItem*> nodes; 70 FMLayout *lyt; 71 int index; 72 73 bool hasNode ( int idx ) ; 74 void nodes_clear(); 75 void nodes_insert(ListItem * v); 76 77 void sPath ( double dist, QList< int > curList, QList<int>& theList, double& theScore ); 78 int deepCount(); 79 80 private: NodeNode81 Node() {} 82 83 }; 84 85 86 87 class FMLayout : public QObject 88 { 89 Q_OBJECT 90 91 public: 92 explicit FMLayout ( QGraphicsScene* scene, FontItem* font = 0, QRectF rect = QRectF()); 93 ~FMLayout(); 94 void doLayout(const QList<GlyphList>& spec , double fs, FontItem* font = 0 ); 95 96 private://methods 97 /// Build a graph on node 98 virtual void doGraph(); 99 /// Build the good list of lines 100 virtual void doLines(); 101 102 void clearCaches(); 103 104 void run(); 105 106 public:// utils 107 double distance ( int start, int end, const GlyphList& gl , bool strip = false ); 108 int sepCount( int start, int end, const GlyphList& gl); 109 void resetScene(); 110 isLayoutFinished()111 bool isLayoutFinished() {return layoutIsFinished;} 112 113 QList<int> breakList; 114 QList<int> hyphenList; 115 GlyphList theString; 116 double lineWidth ( int l ); 117 // QMutex *layoutMutex; 118 bool stopIt; 119 int drawnLines; 120 121 void setContext(bool c); 122 123 public slots: 124 void stopLayout(); 125 126 private:// data 127 // Argued 128 // static FMLayout *instance; 129 bool contextIsMainThread; 130 QGraphicsScene* theScene; 131 FontItem* theFont; 132 QList<GlyphList> paragraphs; 133 QList<GlyphList> lines; 134 QRectF theRect;// Not really argued now, will come soon 135 QGraphicsRectItem *rules; 136 FMLayOptWidget *optionsWidget; 137 QGridLayout *optionLayout; 138 bool persistentScene; 139 140 // built 141 Node *node; 142 QList<int> indices; 143 QList<QGraphicsPixmapItem *> pixList; 144 QList<QGraphicsPathItem*> glyphList; 145 QMap<int, QMap<int, double > > distCache; 146 QMap<int, QMap<int, double > > stripCache; 147 QMap<int, QMap<int, int > > sepCache; 148 bool justRedraw; 149 bool optionHasChanged; 150 QPointF lastOrigine; 151 152 // accessed 153 bool processFeatures; 154 QString script; 155 bool processScript; 156 double fontSize; 157 double adjustedSampleInter; 158 int textProgressionBlock; 159 int textProgressionLine; 160 bool deviceIndy; 161 QPointF origine; 162 163 bool layoutIsFinished; 164 165 public: //accessors getRect()166 QRectF getRect()const{return theRect;} setRect(const QRectF & r)167 void setRect(const QRectF& r){theRect = r;} setProcessFeatures(bool theValue)168 void setProcessFeatures ( bool theValue ){processFeatures = theValue;} setScript(const QString & theValue)169 void setScript ( const QString& theValue ){script = theValue;} setProcessScript(bool theValue)170 void setProcessScript ( bool theValue ) {processScript = theValue;} 171 void setAdjustedSampleInter ( double theValue ); setTextProgressionBlock(int theValue)172 void setTextProgressionBlock ( int theValue ){textProgressionBlock = theValue;} setTextProgressionLine(int theValue)173 void setTextProgressionLine ( int theValue ){textProgressionLine = theValue;} setOrigine(const QPoint & theValue)174 void setOrigine ( const QPoint& theValue ){origine = theValue;} setFontSize(bool theValue)175 void setFontSize ( bool theValue ){fontSize = theValue;} setDeviceIndy(bool theValue)176 void setDeviceIndy( bool theValue ){deviceIndy = theValue;} 177 // void setTheScene ( QGraphicsScene* theValue , QRectF rect = QRectF()); 178 // void setTheFont ( FontItem* theValue ); setPersistentScene(bool p)179 void setPersistentScene(bool p){persistentScene = p;} 180 181 182 private slots: 183 /// Put lines on stage 184 void doDraw(); 185 void endOfRun(); 186 void endOfParagraph(); 187 188 void slotOption(int v); 189 190 signals: 191 // needed if layout is executed outside the main (GUI) thread 192 // receiver is expected to know with what font and on which scene; 193 void drawPixmapForMe(int index, double fontsize, double x, double y); 194 void drawBaselineForMe(double y); 195 void clearScene(); 196 void objectWanted(QObject*); 197 void updateLayout(); 198 void layoutFinished(); 199 void paragraphFinished(); 200 void paintFinished(); 201 public: 202 QWidget *optionDialog; 203 204 double FM_LAYOUT_NODE_SOON_F; 205 double FM_LAYOUT_NODE_FIT_F; 206 double FM_LAYOUT_NODE_LATE_F; 207 double FM_LAYOUT_NODE_END_F; 208 double FM_LAYOUT_HYPHEN_PENALTY; 209 double FM_LAYOUT_MAX_COMPRESSION; 210 QMenu * secretMenu; 211 212 213 }; 214 215 216 #endif 217 218