ROOT logo
// @(#)root/qt:$Id$
// Author: Valeri Fine   21/01/2002

/*************************************************************************
 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
 * Copyright (C) 2002 by Valeri Fine.                                    *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TGQt
#define ROOT_TGQt


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TGQt                                                                 //
//                                                                      //
// Interface to low level Qt GUI. This class gives an access            //
// to the basic Qt graphics, pixmap, text and font handling routines.   //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include "TQtRConfig.h"

#ifndef __CINT__
#include <vector>
#include <map>

#include <qobject.h>
#include <QMap>
#include <QColor>
#include <QCursor>
#include <QPainter>
#include <QRect>
#include <qnamespace.h>

#include <QtGui/QPixmap>
#include <QtCore/QEvent>
#include <QtCore/QVector>

#include <QtGui/QFontDatabase>

#include "TQtClientGuard.h"

#else
  class QObject;
  class QEvent;
#endif  /* CINT */

class QPainter;
class QPen;
class QMarker;
//class  QFont;
class QPaintDevice;
class QTextCodec;
class QPoint;
class QString;
class QSize;
class QColor;


#include "TVirtualX.h"
#include "TQtEmitter.h"

class TQtMarker;

class TQtPen;
class TQtSwitch;
class TQtBrush;
class TQtCommand;
class TFileHandler;
class TQtApplication;
class TQtClientFilter;
class TQtEventQueue;
class TQtPadFont;
class TQtPen;
class TQtPainter;
class TQtFeedBackWidget;

//#define TRACE_TGQt() fprintf(stdout, "TGQt::%s() %d\n", __FUNCTION__, __LINE__)
class TQtTextProxy {
private:
    TQtTextProxy(const TQtTextProxy&);
    void operator=(const TQtTextProxy&);
protected:
    TQtTextProxy(){;}
public:
    virtual  ~TQtTextProxy(){;}
    virtual void clear() = 0;

    bool setContent(const char *text, QString *errorMsg = 0,
                    int *errorLine = 0, int *errorColumn = 0);
    virtual bool setContent(const QString &text, QString *errorMsg   = 0,
                    int *errorLine = 0, int *errorColumn = 0) = 0;
    virtual bool setMmlContent(const QString &text, QString *errorMsg   = 0,
                    int *errorLine = 0, int *errorColumn = 0) = 0;
    virtual void paint(QPainter *p,unsigned int x, unsigned int y) const  = 0;
    virtual unsigned int width() const = 0; 
    virtual unsigned int height()    const = 0;

    virtual void setFont(Font_t fontnumber) = 0;

    virtual int baseFontPointSize() const   = 0;
    virtual void setBaseFontPointSize(int size) = 0;
    virtual void setForegroundColor(const QColor &) = 0;
    virtual bool isMine() const { return false;};
    virtual TQtTextProxy *Clone() = 0;
};
inline bool TQtTextProxy::setContent(const char *text, QString *errorMsg,
                    int *errorLine, int *errorColumn )
{ return setContent(QString(text),errorMsg, errorLine, errorColumn); }

class TGQt  : public TVirtualX  {

#ifndef __CINT__
   friend class TQtObject;
   friend class TQtWindowsObject;
   friend class TQtPixmapObject;
   friend class TPadOpenGLView;
   friend class TQtWidget;
   friend class TQtClientWidget;
   friend class TQtImage;
   friend class TQtClientGuard;
   friend class TQtClientFilter;
   friend class TQtSynchPainting;
   friend class TQtToggleFeedBack;
   friend class TQtColorSelect;
   friend class TQt16ColorSelector;
   friend class TQtPen; 
   friend class TQtBrush; 
   friend class TQtPainter;
   friend class TQtTextProxy;

protected:
   enum DEFWINDOWID { kDefault=1 };
   QPaintDevice *fSelectedWindow;      // Pointer to the current "paintdevice: PixMap, Widget etc"
   QPaintDevice *fPrevWindow;          // Pointer to the previous "Window"
   Int_t         fDisplayOpened;
   TQtPainter     *fQPainter;
   TQtEmitter    fEmitter;             // object to emit Qt signals on behalf of TVirtualX
   static TVirtualX     *fgTQt;        // The hiden poiner to foolish  ROOT TPluginManager

   void        *fhEvent;               // The event object to synch threads

   QVector<QCursor *>      fCursors;
   ECursor         fCursor;            // Current cursor number;

   Style_t      fMarkerStyle;

   Int_t        fTextAlignH;         //Text Alignment Horizontal
   Int_t        fTextAlignV;         //Text Alignment Vertical
   Float_t      fCharacterUpX;       //Character Up vector along X
   Float_t      fCharacterUpY;       //Character Up vector along Y
   Int_t        fTextFontModified;   // Mark whether the text font has been modified
   Float_t      fTextMagnitude;      //Text Magnitude

//   Common HANDLES of the graphics attributes for all HIGZ windows

   TQtBrush  *fQBrush;
   TQtPen    *fQPen;
   TQtMarker *fQtMarker;
   TQtPadFont *fQFont;
   QPainter::CompositionMode  fDrawMode;

   typedef QMap<QPaintDevice *,QRect> TQTCLIPMAP;
   TQTCLIPMAP fClipMap;

//
//  Colors staff
//

//   QMemArray<QColor> QMap<Key, T>::const_iterator;
    QMap<Color_t,QColor*> fPallete;
    TQtClientFilter *fQClientFilter;
    TQtEventQueue   *fQClientFilterBuffer;
    TQtClientGuard       fQClientGuard;  // guard TQtClientWibdget against of dead pointers
    TQtPixmapGuard       fQPixmapGuard;  // guard TQtClientWibdget against of dead pointers
    typedef std::map<ULong_t, QColor * > COLORMAP;
    COLORMAP fColorMap;  // to back the TG widgets
    TQtClientWidget       *fPointerGrabber;
    QTextCodec            *fCodec;            // The Current text decoder
    QString                fFontTextCode;     // The default code text code page (from the Gui.DefaultFont)
    const char            *fSymbolFontFamily; // the name of the font to substiute the non-standard "Symbol"
    Int_t                 fQtEventHasBeenProcessed; // Flag whether the events were processed
    Bool_t                fFeedBackMode;      // TCanvas feedback mode 
    TQtFeedBackWidget    *fFeedBackWidget;    // The dedicated widget for TCanvas feedback mode
    Bool_t                fBlockRGB;          // Protect against color double setting
    Bool_t                fUseTTF;            // Flag whether ROOT font has a priority
    
    static TQtTextProxy   *fgTextProxy;       // proxy for the custom text rendering engine
//
//   Text management
//

   //Qt::AlignmentFlags fTextAlign;

   // void  SetTextFont(const char *fontname, Int_t italic, Int_t bold);
   Int_t CreatROOTThread();
   void  DeleteSelectedObj();

//  Qt methods
   static QRect GetQRect(QPaintDevice &dev);
   int  UpdateColor(int cindex);
   QPaintDevice *GetDoubleBuffer(QPaintDevice *dev);

#endif
   static Int_t   RegisterWid(QPaintDevice *wid);   // register QWidget for the embedded TCanvas
   static Int_t   UnRegisterWid(QPaintDevice *wid); // unregister QWidget of the TCanvas
   static Bool_t  IsRegistered(QPaintDevice *wid);  // Check whether the object has been registered
private:
   TGQt& operator=(const TGQt&);
public:

    TGQt();
    TGQt(const TGQt &vx): TVirtualX(vx) { MayNotUse("TGQt(const TGQt &)"); }   // without dict does not compile? (rdm)
    TGQt(const char *name, const char *title);
    virtual ~TGQt();
// Include the base TVirtualX class interface
#include "TVirtualX.interface.h"
#ifndef __CINT__
// extracted methods
    virtual QPaintDevice *GetSelectedWindow(){ return fSelectedWindow; }
    virtual void      SetFillStyleIndex( Int_t style, Int_t fasi);
    virtual void      SetMarkerType( Int_t type, Int_t n, TPoint *xy );
    virtual void      SetTitle(const char *title);
    virtual void      CopyPixmap(const QPixmap &p, Int_t px1, Int_t py1);
    virtual void      SetTextDecoder(const char * /*textDeocerName*/){;}  // for the future
    virtual const QTextCodec *GetTextDecoder();
#endif
// obsolete methods
        virtual void      PutByte(Byte_t b);
// ---------------------------------------------

   virtual Bool_t       IsHandleValid(Window_t id);


   // static methods:
   static TQtApplication *CreateQtApplicationImp();
   static Int_t          iwid(QPaintDevice *wid);
   static QPaintDevice  *iwid(Int_t wid);
   static QPaintDevice  *iwid(Window_t wid);
#ifndef __CINT__
#if ROOT_VERSION_CODE < ROOT_VERSION(5,13,0)
   static QPixmap       *MakeIcon(Int_t indx);
#endif
   static TVirtualX     *GetVirtualX();
   static QWidget       *winid(Window_t id);
   static QWidget       *wid(Window_t id);
   static Window_t       wid(TQtClientWidget *widget);
   static Window_t       rootwid(QPaintDevice *dev);
   static void           PrintEvent(Event_t &);
   static QString        SetFileName(const QString &fileName);
   static QString        GetNewFileName(const QString &fileNamePrototype);
   static TQtTextProxy  *TextProxy();
   static void           SetTextProxy(TQtTextProxy  *proxy);

   void SetQClientFilter(TQtClientFilter *filter) {fQClientFilter = filter;}
   TQtClientFilter  *QClientFilter() const {return fQClientFilter;}
   QColor QtColor(ULong_t pixel);
   void SendDestroyEvent(TQtClientWidget *) const;

   TQtEmitter *Emitter(){ return &fEmitter;}
#endif
// Future interface :
   virtual void      SetRGB(Int_t cindex, Float_t r, Float_t g, Float_t b, Float_t a);
   virtual void      SetAlpha(Int_t cindex, Float_t a);
   virtual void      GetRGBA(Int_t cindex, Float_t &r, Float_t &g, Float_t &b, Float_t &a);
   virtual Float_t   GetAlpha(Int_t cindex);
   virtual const QColor& ColorIndex(Color_t indx) const;

   virtual Int_t LoadQt(const char *shareLibFileName);
   static void PostQtEvent(QObject *receiver, QEvent *event);
   virtual Int_t processQtEvents(Int_t maxtime=300); //milliseconds
   // temporary this should be moved to the QTGL interface
   private:
      static int fgCoinFlag; // no coin viewer;
      static int fgCoinLoaded; // no coin viewer;
   public:
      static int CoinFlag();
      static void SetCoinFlag(int flag);
      static void SetCoinLoaded();
      static Int_t IsCoinLoaded();
#ifndef __CINT__
      static QString RootFileFormat(const char *selector);
      static QString RootFileFormat(const QString &selector);
      static QString QtFileFormat(const char *selector);
      static QString QtFileFormat(const QString &selector);
#endif

#ifndef Q_MOC_RUN
   ClassDef(TGQt,0)  //Interface to Qt GUI
#endif

};

R__EXTERN  TGQt *gQt;


#endif
 TGQt.h:1
 TGQt.h:2
 TGQt.h:3
 TGQt.h:4
 TGQt.h:5
 TGQt.h:6
 TGQt.h:7
 TGQt.h:8
 TGQt.h:9
 TGQt.h:10
 TGQt.h:11
 TGQt.h:12
 TGQt.h:13
 TGQt.h:14
 TGQt.h:15
 TGQt.h:16
 TGQt.h:17
 TGQt.h:18
 TGQt.h:19
 TGQt.h:20
 TGQt.h:21
 TGQt.h:22
 TGQt.h:23
 TGQt.h:24
 TGQt.h:25
 TGQt.h:26
 TGQt.h:27
 TGQt.h:28
 TGQt.h:29
 TGQt.h:30
 TGQt.h:31
 TGQt.h:32
 TGQt.h:33
 TGQt.h:34
 TGQt.h:35
 TGQt.h:36
 TGQt.h:37
 TGQt.h:38
 TGQt.h:39
 TGQt.h:40
 TGQt.h:41
 TGQt.h:42
 TGQt.h:43
 TGQt.h:44
 TGQt.h:45
 TGQt.h:46
 TGQt.h:47
 TGQt.h:48
 TGQt.h:49
 TGQt.h:50
 TGQt.h:51
 TGQt.h:52
 TGQt.h:53
 TGQt.h:54
 TGQt.h:55
 TGQt.h:56
 TGQt.h:57
 TGQt.h:58
 TGQt.h:59
 TGQt.h:60
 TGQt.h:61
 TGQt.h:62
 TGQt.h:63
 TGQt.h:64
 TGQt.h:65
 TGQt.h:66
 TGQt.h:67
 TGQt.h:68
 TGQt.h:69
 TGQt.h:70
 TGQt.h:71
 TGQt.h:72
 TGQt.h:73
 TGQt.h:74
 TGQt.h:75
 TGQt.h:76
 TGQt.h:77
 TGQt.h:78
 TGQt.h:79
 TGQt.h:80
 TGQt.h:81
 TGQt.h:82
 TGQt.h:83
 TGQt.h:84
 TGQt.h:85
 TGQt.h:86
 TGQt.h:87
 TGQt.h:88
 TGQt.h:89
 TGQt.h:90
 TGQt.h:91
 TGQt.h:92
 TGQt.h:93
 TGQt.h:94
 TGQt.h:95
 TGQt.h:96
 TGQt.h:97
 TGQt.h:98
 TGQt.h:99
 TGQt.h:100
 TGQt.h:101
 TGQt.h:102
 TGQt.h:103
 TGQt.h:104
 TGQt.h:105
 TGQt.h:106
 TGQt.h:107
 TGQt.h:108
 TGQt.h:109
 TGQt.h:110
 TGQt.h:111
 TGQt.h:112
 TGQt.h:113
 TGQt.h:114
 TGQt.h:115
 TGQt.h:116
 TGQt.h:117
 TGQt.h:118
 TGQt.h:119
 TGQt.h:120
 TGQt.h:121
 TGQt.h:122
 TGQt.h:123
 TGQt.h:124
 TGQt.h:125
 TGQt.h:126
 TGQt.h:127
 TGQt.h:128
 TGQt.h:129
 TGQt.h:130
 TGQt.h:131
 TGQt.h:132
 TGQt.h:133
 TGQt.h:134
 TGQt.h:135
 TGQt.h:136
 TGQt.h:137
 TGQt.h:138
 TGQt.h:139
 TGQt.h:140
 TGQt.h:141
 TGQt.h:142
 TGQt.h:143
 TGQt.h:144
 TGQt.h:145
 TGQt.h:146
 TGQt.h:147
 TGQt.h:148
 TGQt.h:149
 TGQt.h:150
 TGQt.h:151
 TGQt.h:152
 TGQt.h:153
 TGQt.h:154
 TGQt.h:155
 TGQt.h:156
 TGQt.h:157
 TGQt.h:158
 TGQt.h:159
 TGQt.h:160
 TGQt.h:161
 TGQt.h:162
 TGQt.h:163
 TGQt.h:164
 TGQt.h:165
 TGQt.h:166
 TGQt.h:167
 TGQt.h:168
 TGQt.h:169
 TGQt.h:170
 TGQt.h:171
 TGQt.h:172
 TGQt.h:173
 TGQt.h:174
 TGQt.h:175
 TGQt.h:176
 TGQt.h:177
 TGQt.h:178
 TGQt.h:179
 TGQt.h:180
 TGQt.h:181
 TGQt.h:182
 TGQt.h:183
 TGQt.h:184
 TGQt.h:185
 TGQt.h:186
 TGQt.h:187
 TGQt.h:188
 TGQt.h:189
 TGQt.h:190
 TGQt.h:191
 TGQt.h:192
 TGQt.h:193
 TGQt.h:194
 TGQt.h:195
 TGQt.h:196
 TGQt.h:197
 TGQt.h:198
 TGQt.h:199
 TGQt.h:200
 TGQt.h:201
 TGQt.h:202
 TGQt.h:203
 TGQt.h:204
 TGQt.h:205
 TGQt.h:206
 TGQt.h:207
 TGQt.h:208
 TGQt.h:209
 TGQt.h:210
 TGQt.h:211
 TGQt.h:212
 TGQt.h:213
 TGQt.h:214
 TGQt.h:215
 TGQt.h:216
 TGQt.h:217
 TGQt.h:218
 TGQt.h:219
 TGQt.h:220
 TGQt.h:221
 TGQt.h:222
 TGQt.h:223
 TGQt.h:224
 TGQt.h:225
 TGQt.h:226
 TGQt.h:227
 TGQt.h:228
 TGQt.h:229
 TGQt.h:230
 TGQt.h:231
 TGQt.h:232
 TGQt.h:233
 TGQt.h:234
 TGQt.h:235
 TGQt.h:236
 TGQt.h:237
 TGQt.h:238
 TGQt.h:239
 TGQt.h:240
 TGQt.h:241
 TGQt.h:242
 TGQt.h:243
 TGQt.h:244
 TGQt.h:245
 TGQt.h:246
 TGQt.h:247
 TGQt.h:248
 TGQt.h:249
 TGQt.h:250
 TGQt.h:251
 TGQt.h:252
 TGQt.h:253
 TGQt.h:254
 TGQt.h:255
 TGQt.h:256
 TGQt.h:257
 TGQt.h:258
 TGQt.h:259
 TGQt.h:260
 TGQt.h:261
 TGQt.h:262
 TGQt.h:263
 TGQt.h:264
 TGQt.h:265
 TGQt.h:266
 TGQt.h:267
 TGQt.h:268
 TGQt.h:269
 TGQt.h:270
 TGQt.h:271
 TGQt.h:272
 TGQt.h:273
 TGQt.h:274
 TGQt.h:275
 TGQt.h:276
 TGQt.h:277
 TGQt.h:278
 TGQt.h:279
 TGQt.h:280
 TGQt.h:281
 TGQt.h:282
 TGQt.h:283
 TGQt.h:284
 TGQt.h:285
 TGQt.h:286
 TGQt.h:287
 TGQt.h:288
 TGQt.h:289
 TGQt.h:290
 TGQt.h:291
 TGQt.h:292
 TGQt.h:293
 TGQt.h:294
 TGQt.h:295
 TGQt.h:296
 TGQt.h:297
 TGQt.h:298
 TGQt.h:299
 TGQt.h:300
 TGQt.h:301
 TGQt.h:302