Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

QTReader.h

Go to the documentation of this file.
00001 #ifndef __QTREADER_H
00002 #define __QTREADER_H
00003 
00004 //#define _SCROLLPIPE
00005 #include <qwidget.h>
00006 //#include <qpainter.h>
00007 #include "my_list.h"
00008 #include "BuffDoc.h"
00009 #include "FontControl.h"
00010 
00011 //#include <qtimer.h>
00012 
00013 class CDrawBuffer;
00014 //class CBuffer;
00015 #include <qpixmap.h>
00016 class QPainter;
00017 class QTimer;
00018 class QImage;
00019 
00020 #include "BGType.h"
00021 
00022 #define SPECIALSCROLL
00023 
00024 class QPainter;
00025 class COutput;
00026 
00027 class CStyle;
00028 #define USETIMER
00029 
00030 class QTReader : public QWidget
00031 {
00032     Q_OBJECT
00033       friend class QTReaderApp;
00034 #ifdef USETIMER
00035     QTimer* m_dragtimer;
00036     unsigned long m_dragtarget;
00037 #endif
00038     COutput* m_output;
00039     bool checkoutput();
00040     bool m_outofdate, m_drageligible;
00041     QPixmap *dbuff;
00042     QPainter* dbp;
00043     void drawSingleLine(int lineno);
00044     void gotoLink();
00045     void emitRedraw();
00046     CStyle* m_currentlinkstyle;
00047     int m_currentlink;
00048     int m_currentlinkoffset;
00049     QPixmap m_bgpm;
00050     bool m_bgIsScaled;
00051     bground m_bgtype;
00052     int m_scrollpos;
00053     unsigned short m_scrollstep;
00054     void blitRot(int dx, int sx, int sw, int sh, CDrawBuffer* txt);
00055     void setBackgroundBitmap(const QPixmap& _pm, bground bg)
00056       {
00057         m_bgpm = _pm;
00058         m_bgtype = bg;
00059         m_bgIsScaled = false;
00060       }
00061 
00062     QColor m_bg, m_default_bg, m_default_fg, m_negative_fg;
00063         static tchar pluckernextpart[];
00064         static tchar jplucknextpart[];
00065         CList<Bkmk>* pBkmklist;
00066       void setHyphenThreshold(int _v) { buffdoc.setHyphenThreshold(_v); }
00067     void ResetScroll();
00068     void increaseScroll();
00069     void reduceScroll();
00070     void drawText(QPainter& p, int x, int y, tchar* text);
00071     void DrawScroll( QPainter *p, int w, int h );
00072     void dorollingscroll(bool);
00073     void doinplacescroll();
00074     void dostaticscroll();
00075     void suspend();
00076     void redrawScroll(QPainter* p);
00077     int m_delay, m_scrolltype;
00078     unsigned int m_overlap;
00079     bool m_autoScroll, m_swapmouse;
00080     void drawBackground(QPainter*);
00081       bool m_rotated;
00082       void setrotated(bool);
00083     void autoscroll();
00084     QTimer* timer;
00085     int m_scrolldy1, m_scrolldy2, m_encd, m_scrollpart, m_totalscroll;
00086     void focusInEvent(QFocusEvent*);
00087     void focusOutEvent(QFocusEvent*);
00088     void processmousepositionevent( QMouseEvent* _e );
00089     void processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno);
00090     bool ChangeFont(int);
00091     bool getline(CDrawBuffer*);
00092     int m_charWidth;
00093     int m_charpc;
00094     unsigned short m_absleft_border, m_absright_border;
00095     unsigned short m_left_border, m_right_border;
00096     FontControl m_fontControl;
00097     void setBaseSize(unsigned char _s) { m_fontControl.setBaseSize(_s); }
00098     unsigned char getBaseSize() { return m_fontControl.getBaseSize(); }
00099     QString m_outputName;
00100 #ifdef _SCROLLPIPE
00101     FILE* m_pipeout;
00102     QString m_pipetarget;
00103     bool m_isPaused;
00104     bool m_pauseAfterEachPara;
00105 #endif
00106 public:
00107     QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0);
00108     //    QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0);
00109     ~QTReader();
00110     QString about();
00111     void readAloud();
00112     CList<Bkmk>* Bkmklist() { return pBkmklist; }
00113     void setBackground(const QColor& _c)
00114       {
00115         m_default_bg = _c;
00116         reset_bg();
00117       }
00118     void setForeground(const QColor& _c)
00119       {
00120         m_default_fg = _c;
00121         int r,g,b;
00122         m_default_fg.rgb(&r, &g, &b);
00123         r = 255-r;
00124         g = 255-g;
00125         b = 255-b;
00126         m_negative_fg.setRgb(r,g,b);
00127       }
00128     void zoomin();
00129     void zoomout();
00130     void setSaveData(unsigned char*& data, unsigned short& len, unsigned char* src, unsigned short srclen)
00131         {
00132             buffdoc.setSaveData(data, len, src, srclen);
00133         }
00134     void putSaveData(unsigned char*& src, unsigned short& srclen)
00135         {
00136             buffdoc.putSaveData(src, srclen);
00137         }
00138     bool empty();
00139     void setContinuous(bool _b);
00140     void toggle_autoscroll();
00141     void setautoscroll(bool);
00142     void disableAutoscroll() { m_autoScroll = false; }
00143     void copy()
00144       {
00145 /*
00146         size_t nd = locate();
00147         jumpto(m_mark);
00148         QString text;
00149         while (m_mark < nd)
00150           {
00151             text += buffdoc.getch();
00152             m_mark++;
00153           }
00154         QApplication::clipboard()->setText(text);
00155         jumpto(nd);
00156 */
00157       };
00158     void clear() {};
00159     void setText(const QString& n, const QString& s, unsigned int lcn = 0) { m_string = n; load_file((const char*)s, lcn); };
00160     /*
00161     void setText(bool oldfile)
00162       {
00163         if (oldfile)
00164           {
00165             m_string = m_lastfile;
00166             load_file((const tchar*)m_string);
00167           }
00168         else
00169           {
00170             m_string = QString::null;
00171           }
00172       };
00173     */
00174     void setlead(int _lead)
00175         {
00176             m_fontControl.setlead(_lead);
00177         }
00178     int getlead()
00179         {
00180             return m_fontControl.getlead();
00181         }
00182     void setextraspace(int _lead)
00183         {
00184             m_fontControl.setextraspace(_lead);
00185         }
00186     int getextraspace()
00187         {
00188             return m_fontControl.getextraspace();
00189         }
00190     void setpagemode(bool _b)
00191       {
00192         m_bpagemode = _b;
00193       }
00194     void setmono(bool _b)
00195       {
00196         m_bMonoSpaced = _b;
00197         ChangeFont(m_fontControl.currentsize());
00198         locate(pagelocate());
00199       }
00200     void setencoding(int _f)
00201         {
00202             m_encd = _f;
00203             setfilter(getfilter());
00204         }
00205     MarkupType PreferredMarkup();
00206     CEncoding* getencoding()
00207         {
00208 //          qDebug("m_encd:%d", m_encd);
00209             switch (m_encd)
00210             {
00211                 case 4:
00212 //                  qDebug("palm");
00213                     return new CPalm;
00214                 case 1:
00215 //                  qDebug("utf8");
00216                     return new CUtf8;
00217                 case 2:
00218 //                  qDebug("ucs16be");
00219                     return new CUcs16be;
00220                 case 3:
00221 //                  qDebug("ucs16le");
00222                     return new CUcs16le;
00223                 case 0:
00224 //                  qDebug("ascii");
00225                     return new CAscii;
00226                 default:
00227                     return new CGeneral8Bit(m_encd-MAX_ENCODING+1);
00228             }
00229         }
00230     HighlightFilter* m_highlightfilter;
00231     CFilterChain* getfilter();
00232 
00233 private slots:
00234 #ifdef USETIMER
00235   void actionDrag();
00236 #endif
00237   void dopageup();
00238   void lineDown();
00239   void lineUp();
00240   void dopagedn();
00241     void goHome();
00242     void goBack();
00243     void goForward();
00244         void doscroll();
00245     void   paintEvent( QPaintEvent * );
00246 
00247     void   resizeEvent( QResizeEvent * p );
00248 
00249   void keyPressEvent(QKeyEvent*);
00250  private:
00251   //    void   drawIt( QPainter * );
00252   void redrawall();
00253   void drawFonts();
00254   void DrawStraight(QPainter* p, int w, int h);
00255   QColor m_scrollcolor, m_scrollbarcolor;
00256   void setTwoTouch(bool _b);
00257   void init();
00258   void mouseMoveEvent( QMouseEvent* );
00259   void mousePressEvent( QMouseEvent* );
00260   void mouseReleaseEvent( QMouseEvent* );
00261 //  void mouseDoubleClickEvent( QMouseEvent* );
00262   QString m_string, m_fontname, m_reparastring;
00263   void setfont();
00264   bool m_doubleBuffered;
00265 
00266   void setDoubleBuffer(bool _b);
00267   //myoutput stuff
00268  private:
00269 #ifdef SPECIALSCROLL
00270   int m_scrolldy;
00271 #endif
00272   bool mouseUpOn;
00273   linkType getcurrentpos(int x, int y, int w, int h, int& lineno, size_t& start, size_t& offset, size_t& tgt, size_t& tgtoffset, size_t& pictgt, QImage*&, size_t&);
00274   bool m_twotouch, m_touchone;
00275   size_t m_startpos, m_startoffset;
00276   void dopageup(unsigned int);
00277   long real_delay();
00278   int m_textsize;
00279   int m_lastwidth, m_lastheight;
00280   CBufferFace<CDrawBuffer*> textarray;
00281   CBufferFace<size_t>   locnarray;
00282   unsigned int numlines;
00283 //  bool m_showlast;
00284   bool bstripcr, btextfmt, bstriphtml, bdehyphen, bdepluck, bdejpluck, bunindent, brepara, bdblspce, btight, bmakebold, bremap, bpeanut, bautofmt, bonespace, bfulljust, /*bNegative,*/ bInverse, bNoInlineTables;
00285   bool bkern, brepalm, bunderlineLink;
00286   bool m_bpagemode, m_bMonoSpaced, m_continuousDocument;
00287   unsigned char bindenter;
00288   QString m_lastfile;
00289   size_t m_lastposn;
00290   bool bDoUpdates;
00291  public:
00292   bool doOutput(const QString& wrd);
00293   void setDoUpdates(bool b) { bDoUpdates = b; }
00294   void setStripCR(bool b) { bstripcr = b; }
00295   void NavUp();
00296   void NavDown();
00297   tchar getch() { return buffdoc.getch(); }
00298   bool synch(size_t, size_t);
00299   bool tight;
00300   bool load_file(const char *newfile, unsigned int lcn=0);
00301   BuffDoc buffdoc;
00302   CList<Bkmk>* getbkmklist() { return buffdoc.getbkmklist(); }
00303   bool locate(unsigned long n);
00304   void jumpto(unsigned long n) { buffdoc.locate(n); }
00305   unsigned long locate() { return buffdoc.locate(); }
00306   unsigned long explocate() { return buffdoc.explocate(); }
00307   unsigned long pagelocate() { return locnarray[0]; }
00308   unsigned long mylastpos;
00309   void getNextLink();
00310   void setfilter(CFilterChain *f) { buffdoc.setfilter(f); if (bDoUpdates) locate(pagelocate()); }
00311   void restore() { jumpto(mylastpos); }
00312   void goUp();
00313   void refresh(bool full = false);
00314   void goDown();
00315   //  bool bold;
00316   int textsize() { return m_textsize; }
00317   void textsize(int ts) { m_textsize = ts; }
00318   bool fillbuffer(int ru = 0, int ht = -1, int newht = -1);
00319   void CalculateScrollParameters();
00320   unsigned int screenlines();
00321   void sizes(unsigned long& fs, unsigned long& ts) { buffdoc.sizes(fs,ts); }
00322   static const char *fonts[];
00323 //  unsigned int   *fontsizes;
00324   int m_ascent, m_descent, m_linespacing;
00325   int m_topmargin, m_bottommargin;
00326   int m_abstopmargin, m_absbottommargin;
00327   QFontMetrics* m_fm;
00328   QString firstword();
00329   bool hyphenate;
00330   void reset_bg()
00331     {
00332       int r,g,b;
00333       m_default_bg.rgb(&r, &g, &b);
00334       if (bInverse)
00335         {
00336           r = 255-r;
00337           g = 255-g;
00338           b = 255-b;
00339         }
00340       m_bg.setRgb(r,g,b);
00341       /*
00342       int h,s,v;
00343       m_bg.hsv(&h, &s, &v);
00344       if (bNegative)
00345         {
00346           v = 255-v;
00347           m_bg.setHsv(h,s,v);
00348         }
00349       */
00350       setBackgroundColor( m_bg );
00351     }
00352   void setInverse(bool b)
00353     {
00354       bInverse = b;
00355       reset_bg();
00356     }
00357   /*
00358   void setNegative()
00359     {
00360       bNegative = !bNegative;
00361       reset_bg();
00362     }
00363   */
00364  signals:
00365   void OnRedraw();
00366   void OnWordSelected(const QString&, size_t, size_t, const QString&);
00367   void OnShowPicture(QImage&);
00368   void OnURLSelected(const QString&, const size_t);
00369   void NewFileRequest(const QString&);
00370   void HandleKeyRequest(QKeyEvent*);
00371   void SetScrollState(bool);
00372   void RefreshBitmap();
00373 };
00374 
00375 #endif

Generated on Sat Nov 5 16:16:57 2005 for OPIE by  doxygen 1.4.2