ROOT logo
// @(#)root/qt:$Id$
/*************************************************************************
 * 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_TQtClientWidget
#define ROOT_TQtClientWidget


#ifndef __CINT__
# include <QKeySequence>
# include <QFrame>
# include <QCursor>
# include <map>
#else
  class QFrame;
  class QColor;
  class QPixmap;
#endif
  
#include "GuiTypes.h"

//________________________________________________________________________
//
// TQtClientWidget  is a QFrame implemantation backing  ROOT TGWindow objects
// It tries to mimic the X11 Widget behaviour, that kind the ROOT Gui relies on heavily.
//________________________________________________________________________

class QCursor;
class QCloseEvent;
class QPaintEvent;
class TQtClientGuard;
class TQtWidget;
class QShortcut;
class TGWindow;

class TQtClientWidget: public QFrame {
#ifndef __CINT__
     Q_OBJECT
#endif

private:
         void  operator=(const TQtClientWidget&);
         TQtClientWidget(const TQtClientWidget&);
protected:

       UInt_t fGrabButtonMask;        // modifier button mask for TVirtualX::GrabButton
       UInt_t fGrabEventPointerMask;  // input event mask for TVirtualX::GrabPointer
       UInt_t fGrabEventButtonMask;   // input event mask for TVirtualX::GrabButton
       UInt_t fSelectEventMask;       // input mask for SelectInput
       UInt_t fSaveSelectInputMask;   // To save dutinr the grabbing the selectInput
       EMouseButton fButton;
#ifndef __CINT__
       std::map<QKeySequence,QShortcut*>  fGrabbedKey;
#endif
       Bool_t   fPointerOwner;
       QCursor *fNormalPointerCursor;
       QCursor *fGrabPointerCursor;
       QCursor *fGrabButtonCursor;
       bool     fIsClosing;
       bool     fDeleteNotify;
       TQtClientGuard  *fGuard;
       TQtWidget       *fCanvasWidget;
       TGWindow *fMyRootWindow;  // back pointer to the host window object
       QColor   *fEraseColor;    // Color to paint widget background with our PainEvent
       QPixmap  *fErasePixmap;   // pixmap to paint widget background with our PainEvent
       friend class TQtClientGuard;
       friend class TGQt;
#ifndef __CINT__
      TQtClientWidget(TQtClientGuard *guard, QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
#else
      TQtClientWidget(TQtClientGuard *guard, QWidget* parent=0, const char* name=0, WFlags f=0);
#endif
      void SetCanvasWidget(TQtWidget *widget);
      virtual void paintEvent       ( QPaintEvent * );
public:
    enum {kRemove = -1, kTestKey = 0, kInsert = 1};
    virtual ~TQtClientWidget();
    virtual void closeEvent(QCloseEvent *ev);
    virtual void setEraseColor(const QColor &color);
    virtual void setErasePixmap (const QPixmap &pixmap);
    bool   DeleteNotify();
    TQtWidget *GetCanvasWidget() const;
    void   GrabEvent(Event_t &ev,bool own=TRUE);
//    Q3Accel *HasAccel() const ;
    bool   IsClosing();
    bool   IsGrabbed       (Event_t &ev);
    bool   IsGrabPointerSelected(UInt_t evmask) const;
    bool   IsGrabButtonSelected (UInt_t evmask) const;
    TQtClientWidget *IsKeyGrabbed(const Event_t &ev);
    UInt_t IsEventSelected (UInt_t evmask) const;
    bool   IsGrabOwner()   { return fPointerOwner;}
    void   SetAttributeEventMask(UInt_t evmask);
    void   SetButtonMask   (UInt_t modifier=kAnyModifier,EMouseButton button=kAnyButton);
    void   SetClosing(bool flag=kTRUE);
    void   SetCursor();
    void   SetCursor(Cursor_t cursor);
    void   SetDeleteNotify(bool flag=true);
    void   SetButtonEventMask(UInt_t evmask,Cursor_t cursor=0);
    void   SelectInput       (UInt_t evmask);
    Bool_t SetKeyMask        (Int_t keycode = 0, UInt_t modifier=kAnyModifier,int insert=kInsert);
    void   UnSetButtonMask   (bool dtor=false);
    void   UnSetKeyMask(Int_t keycode = 0, UInt_t modifier=kAnyModifier);
    QCursor *GrabButtonCursor() const;
    QCursor *GrabPointerCursor() const;
    UInt_t ButtonMask  ()    const;
    UInt_t ButtonEventMask() const;
    UInt_t SelectEventMask() const;
    EMouseButton Button()    const;
    UInt_t PointerMask ()    const;
#ifndef __CINT__
protected slots:
      void Disconnect();
#endif
public slots:
    virtual void Accelerate();
#ifndef Q_MOC_RUN
    ClassDef(TQtClientWidget,0) // QFrame implementation backing  ROOT TGWindow objects
#endif
};

//______________________________________________________________________________
inline bool TQtClientWidget::DeleteNotify(){return fDeleteNotify; }

//______________________________________________________________________________
inline TQtWidget *TQtClientWidget::GetCanvasWidget() const
{ return fCanvasWidget;}
//______________________________________________________________________________
//inline Q3Accel *TQtClientWidget::HasAccel() const 
//{  return fGrabbedKey; }

//______________________________________________________________________________
inline bool  TQtClientWidget::IsClosing(){ return fIsClosing; }

//______________________________________________________________________________
inline UInt_t TQtClientWidget::IsEventSelected (UInt_t evmask) const
{
   //if (evmask & (kButtonPressMask | kButtonMotionMask) )
   //   fprintf(stderr,"TQtClientWidget::IsEventSelected event %x, mask %x. match %x\n"
   //   , evmask, fSelectEventtMask, evmask & (kButtonPressMask | kButtonMotionMask));
   return  (evmask & fSelectEventMask); //  || (IsGrabPointerSelected(evmask)) ;
}

//______________________________________________________________________________
inline void TQtClientWidget::SetCursor()
{ // Set this widget pre-defined cursor
   if (fNormalPointerCursor) setCursor(*fNormalPointerCursor);
}
//______________________________________________________________________________
inline void TQtClientWidget::SetCursor(Cursor_t crsr)
{
   // Change the pre-define curos shape and set it
   fNormalPointerCursor = (QCursor *)crsr;
   SetCursor();
}

//______________________________________________________________________________
inline void  TQtClientWidget::SetClosing(bool flag) { fIsClosing = flag;}
//______________________________________________________________________________
inline void  TQtClientWidget::SetDeleteNotify(bool flag){fDeleteNotify = flag;}

//______________________________________________________________________________
inline void TQtClientWidget::SetAttributeEventMask(UInt_t evmask) { SelectInput (evmask);}

//______________________________________________________________________________
inline void TQtClientWidget::SetButtonEventMask(UInt_t evmask,Cursor_t crsr)
{ fGrabEventButtonMask = evmask; fGrabButtonCursor =(QCursor *) crsr; }

//______________________________________________________________________________
inline EMouseButton TQtClientWidget::Button() const { return fButton;          }

//______________________________________________________________________________
inline UInt_t TQtClientWidget::ButtonEventMask() const { return fGrabEventButtonMask;}

//______________________________________________________________________________
inline UInt_t TQtClientWidget::ButtonMask()  const { return fGrabButtonMask;   }

//______________________________________________________________________________
inline UInt_t TQtClientWidget::PointerMask() const { return fGrabEventPointerMask;}

//______________________________________________________________________________
inline UInt_t TQtClientWidget::SelectEventMask() const {return fSelectEventMask;}

//______________________________________________________________________________
inline QCursor *TQtClientWidget::GrabButtonCursor() const
{      return   fGrabButtonCursor;                                                }

//______________________________________________________________________________
inline QCursor *TQtClientWidget::GrabPointerCursor() const
{      return   fGrabPointerCursor;                                                }

//______________________________________________________________________________
inline bool TQtClientWidget::IsGrabPointerSelected(UInt_t evmask) const
{  return  evmask & PointerMask(); }

//______________________________________________________________________________
inline bool  TQtClientWidget::IsGrabButtonSelected (UInt_t evmask) const
{ return  evmask & ButtonEventMask(); }

#endif
 TQtClientWidget.h:1
 TQtClientWidget.h:2
 TQtClientWidget.h:3
 TQtClientWidget.h:4
 TQtClientWidget.h:5
 TQtClientWidget.h:6
 TQtClientWidget.h:7
 TQtClientWidget.h:8
 TQtClientWidget.h:9
 TQtClientWidget.h:10
 TQtClientWidget.h:11
 TQtClientWidget.h:12
 TQtClientWidget.h:13
 TQtClientWidget.h:14
 TQtClientWidget.h:15
 TQtClientWidget.h:16
 TQtClientWidget.h:17
 TQtClientWidget.h:18
 TQtClientWidget.h:19
 TQtClientWidget.h:20
 TQtClientWidget.h:21
 TQtClientWidget.h:22
 TQtClientWidget.h:23
 TQtClientWidget.h:24
 TQtClientWidget.h:25
 TQtClientWidget.h:26
 TQtClientWidget.h:27
 TQtClientWidget.h:28
 TQtClientWidget.h:29
 TQtClientWidget.h:30
 TQtClientWidget.h:31
 TQtClientWidget.h:32
 TQtClientWidget.h:33
 TQtClientWidget.h:34
 TQtClientWidget.h:35
 TQtClientWidget.h:36
 TQtClientWidget.h:37
 TQtClientWidget.h:38
 TQtClientWidget.h:39
 TQtClientWidget.h:40
 TQtClientWidget.h:41
 TQtClientWidget.h:42
 TQtClientWidget.h:43
 TQtClientWidget.h:44
 TQtClientWidget.h:45
 TQtClientWidget.h:46
 TQtClientWidget.h:47
 TQtClientWidget.h:48
 TQtClientWidget.h:49
 TQtClientWidget.h:50
 TQtClientWidget.h:51
 TQtClientWidget.h:52
 TQtClientWidget.h:53
 TQtClientWidget.h:54
 TQtClientWidget.h:55
 TQtClientWidget.h:56
 TQtClientWidget.h:57
 TQtClientWidget.h:58
 TQtClientWidget.h:59
 TQtClientWidget.h:60
 TQtClientWidget.h:61
 TQtClientWidget.h:62
 TQtClientWidget.h:63
 TQtClientWidget.h:64
 TQtClientWidget.h:65
 TQtClientWidget.h:66
 TQtClientWidget.h:67
 TQtClientWidget.h:68
 TQtClientWidget.h:69
 TQtClientWidget.h:70
 TQtClientWidget.h:71
 TQtClientWidget.h:72
 TQtClientWidget.h:73
 TQtClientWidget.h:74
 TQtClientWidget.h:75
 TQtClientWidget.h:76
 TQtClientWidget.h:77
 TQtClientWidget.h:78
 TQtClientWidget.h:79
 TQtClientWidget.h:80
 TQtClientWidget.h:81
 TQtClientWidget.h:82
 TQtClientWidget.h:83
 TQtClientWidget.h:84
 TQtClientWidget.h:85
 TQtClientWidget.h:86
 TQtClientWidget.h:87
 TQtClientWidget.h:88
 TQtClientWidget.h:89
 TQtClientWidget.h:90
 TQtClientWidget.h:91
 TQtClientWidget.h:92
 TQtClientWidget.h:93
 TQtClientWidget.h:94
 TQtClientWidget.h:95
 TQtClientWidget.h:96
 TQtClientWidget.h:97
 TQtClientWidget.h:98
 TQtClientWidget.h:99
 TQtClientWidget.h:100
 TQtClientWidget.h:101
 TQtClientWidget.h:102
 TQtClientWidget.h:103
 TQtClientWidget.h:104
 TQtClientWidget.h:105
 TQtClientWidget.h:106
 TQtClientWidget.h:107
 TQtClientWidget.h:108
 TQtClientWidget.h:109
 TQtClientWidget.h:110
 TQtClientWidget.h:111
 TQtClientWidget.h:112
 TQtClientWidget.h:113
 TQtClientWidget.h:114
 TQtClientWidget.h:115
 TQtClientWidget.h:116
 TQtClientWidget.h:117
 TQtClientWidget.h:118
 TQtClientWidget.h:119
 TQtClientWidget.h:120
 TQtClientWidget.h:121
 TQtClientWidget.h:122
 TQtClientWidget.h:123
 TQtClientWidget.h:124
 TQtClientWidget.h:125
 TQtClientWidget.h:126
 TQtClientWidget.h:127
 TQtClientWidget.h:128
 TQtClientWidget.h:129
 TQtClientWidget.h:130
 TQtClientWidget.h:131
 TQtClientWidget.h:132
 TQtClientWidget.h:133
 TQtClientWidget.h:134
 TQtClientWidget.h:135
 TQtClientWidget.h:136
 TQtClientWidget.h:137
 TQtClientWidget.h:138
 TQtClientWidget.h:139
 TQtClientWidget.h:140
 TQtClientWidget.h:141
 TQtClientWidget.h:142
 TQtClientWidget.h:143
 TQtClientWidget.h:144
 TQtClientWidget.h:145
 TQtClientWidget.h:146
 TQtClientWidget.h:147
 TQtClientWidget.h:148
 TQtClientWidget.h:149
 TQtClientWidget.h:150
 TQtClientWidget.h:151
 TQtClientWidget.h:152
 TQtClientWidget.h:153
 TQtClientWidget.h:154
 TQtClientWidget.h:155
 TQtClientWidget.h:156
 TQtClientWidget.h:157
 TQtClientWidget.h:158
 TQtClientWidget.h:159
 TQtClientWidget.h:160
 TQtClientWidget.h:161
 TQtClientWidget.h:162
 TQtClientWidget.h:163
 TQtClientWidget.h:164
 TQtClientWidget.h:165
 TQtClientWidget.h:166
 TQtClientWidget.h:167
 TQtClientWidget.h:168
 TQtClientWidget.h:169
 TQtClientWidget.h:170
 TQtClientWidget.h:171
 TQtClientWidget.h:172
 TQtClientWidget.h:173
 TQtClientWidget.h:174
 TQtClientWidget.h:175
 TQtClientWidget.h:176
 TQtClientWidget.h:177
 TQtClientWidget.h:178
 TQtClientWidget.h:179
 TQtClientWidget.h:180
 TQtClientWidget.h:181
 TQtClientWidget.h:182
 TQtClientWidget.h:183
 TQtClientWidget.h:184
 TQtClientWidget.h:185
 TQtClientWidget.h:186
 TQtClientWidget.h:187
 TQtClientWidget.h:188
 TQtClientWidget.h:189
 TQtClientWidget.h:190
 TQtClientWidget.h:191
 TQtClientWidget.h:192
 TQtClientWidget.h:193
 TQtClientWidget.h:194
 TQtClientWidget.h:195
 TQtClientWidget.h:196
 TQtClientWidget.h:197
 TQtClientWidget.h:198
 TQtClientWidget.h:199
 TQtClientWidget.h:200
 TQtClientWidget.h:201
 TQtClientWidget.h:202
 TQtClientWidget.h:203
 TQtClientWidget.h:204
 TQtClientWidget.h:205