1 /*************************************************************************** 2 * Copyright (C) 2010 by Pierre Marchand * 3 * pierre@oep-h.com * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU General Public License as published by * 7 * the Free Software Foundation; either version 2 of the License, or * 8 * (at your option) any later version. * 9 * * 10 * This program is distributed in the hope that it will be useful, * 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 * GNU General Public License for more details. * 14 * * 15 * You should have received a copy of the GNU General Public License * 16 * along with this program; if not, write to the * 17 * Free Software Foundation, Inc., * 18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 ***************************************************************************/ 20 21 #ifndef SAMPLEWIDGET_H 22 #define SAMPLEWIDGET_H 23 24 #include "floatingwidget.h" 25 #include "fmotf.h" 26 27 #include <QString> 28 #include <QByteArray> 29 #include <QTime> 30 #include <QThread> 31 #include <QFileInfo> 32 33 class QGraphicsScene; 34 class FMLayout; 35 class QButtonGroup; 36 class QAbstractButton; 37 class QFileSystemWatcher; 38 class QTimer; 39 class SampleToolBar; 40 class QTreeWidgetItem; 41 class QStyledItemDelegate; 42 class FontItem; 43 44 namespace Ui { 45 class SampleWidget; 46 } 47 48 #define VIEW_PAGE_FREETYPE 0 49 #define VIEW_PAGE_ABSOLUTE 1 50 #define VIEW_PAGE_OPENTYPE 3 51 //#define VIEW_PAGE_SETTINGS 1 52 #define VIEW_PAGE_SAMPLES 4 53 54 class FMLayoutThread : public QThread 55 { 56 FMLayout * pLayout; 57 QList<GlyphList> gl; 58 double fontSize; 59 FontItem * font; 60 unsigned int fHinting; 61 62 public: 63 void setLayout(FMLayout * l, const QList<GlyphList>& spec , double fs, FontItem * f, unsigned int hinting); 64 void run(); 65 }; 66 67 class SampleWidget : public FloatingWidget 68 { 69 Q_OBJECT 70 71 public: 72 struct State 73 { 74 bool set; StateState75 State() : set(false) {} StateState76 State(const QString& sn, double fs, unsigned int rh, const QString& sh, const QString& sc): 77 set(true), 78 sampleName(sn), 79 fontSize(fs), 80 renderHinting(rh), 81 shaper(sh), 82 script(sc) 83 {} StateState84 State(const State& other) 85 : set(true) 86 { 87 sampleName = other.sampleName; 88 fontSize = other.fontSize; 89 renderHinting = other.renderHinting; 90 shaper = other.shaper; 91 script = other.script; 92 } 93 QString sampleName; 94 double fontSize; 95 unsigned int renderHinting; // 0 = No; 1 = Normal; 2 = Light 96 QString shaper; 97 QString script; 98 QByteArray toByteArray() const; 99 State fromByteArray(QByteArray b); 100 101 // private: 102 // State operator= (const State&){} 103 }; 104 105 static const QString Name; 106 explicit SampleWidget(const QString& fid, QWidget *parent = 0); 107 ~SampleWidget(); 108 109 QGraphicsScene* textScene() const; 110 State state() const; 111 void setState(const State& s); 112 113 protected: 114 void changeEvent(QEvent *e); 115 void refillSampleList(); 116 unsigned int hinting(); 117 118 private: 119 Ui::SampleWidget *ui; 120 SampleToolBar * sampleToolBar; 121 QTreeWidgetItem * uRoot; 122 QTreeWidgetItem * newSampleName; 123 QStyledItemDelegate * sampleNameEditor; 124 125 const QString fontIdentifier; 126 QGraphicsScene *loremScene; 127 QGraphicsScene *ftScene; 128 FMLayout *textLayoutVect; 129 FMLayout *textLayoutFT; 130 // QButtonGroup *radioRenderGroup; 131 QButtonGroup *radioFTHintingGroup; 132 double sampleFontSize; 133 double sampleInterSize; 134 double sampleRatio; 135 int toolPanelWidth; 136 QFileSystemWatcher *sysWatcher; 137 QTimer *reloadTimer; 138 139 void createConnections(); 140 void removeConnections(); 141 142 void fillOTTree(); 143 OTFSet deFillOTTree(); 144 145 bool layoutForPrint; 146 bool firstUpdateRequest; 147 int firstUpdateRequestTimeStamp; 148 QTime layoutTime; 149 QTimer *layoutTimer; 150 int layoutWait; 151 FMLayoutThread * layoutThread; 152 bool layoutSwitch; 153 int pixmapDrawn; 154 #ifdef PLATFORM_APPLE 155 QFileInfo fileInfo; 156 qint64 fileLastModified; 157 #endif reSize(double fSize,double lSize)158 void reSize(double fSize, double lSize){sampleFontSize = fSize; sampleInterSize = lSize;} 159 160 private slots: 161 void slotView(); 162 void drawPixmap(int index, double fontsize, double x, double y); 163 void drawBaseline(double y); 164 void clearFTScene(); 165 void endLayout(); 166 // void slotChangeViewPage(QAbstractButton* ); 167 // void slotHintChanged(int); 168 // void slotChangeViewPageSetting(bool); 169 void slotUpdateSView(); 170 void slotZoom(int z); 171 void slotUpdateRView(); 172 void slotSampleChanged(); 173 void slotLiveFontSize(double); 174 void slotFeatureChanged(); 175 void slotDefaultOTF(); 176 void slotResetOTF(); 177 void slotChangeScript(); 178 void slotProgressionChanged(); 179 void slotWantShape(); 180 void slotFileChanged(const QString&); 181 void slotReload(); 182 void slotScriptChange(); 183 184 void slotAddSample(); 185 void slotSampleNameEdited(QWidget* w); 186 void slotRemoveSample(); 187 void slotEditSample(); 188 void slotUpdateSample(); 189 190 void slotShowSamples(bool); 191 void slotShowOpenType(bool); 192 193 void slotPrint(); 194 void slotDoPrinting(); 195 196 void saveState(); 197 198 signals: 199 void stopLayout(); 200 void stateChanged(); 201 202 203 204 }; 205 206 #endif // SAMPLEWIDGET_H 207