#include "Riostream.h"
#include "qevent.h"
#include "qdialog.h"
#include "qpushbutton.h"
#include "qlabel.h"
#include "qpainter.h"
#if (QT_VERSION > 0x039999) // Added by cholm@nbi.dk - for Qt 4
# include "qnamespace.h"
using namespace Qt;
# include "q3dragobject.h"
typedef Q3TextDrag QTextDrag;
#endif
#include "TQRootCanvas.h"
#include "TROOT.h"
#include "TClass.h"
#include "TCanvas.h"
#include "TQCanvasMenu.h"
ClassImp(TQRootCanvas)
TQRootCanvas::TQRootCanvas( QWidget *parent, const char *name, TCanvas *c )
: QWidget( parent, name ,WRepaintNoErase | WResizeNoErase ),
fNeedResize(kTRUE)
{
setUpdatesEnabled( kTRUE );
setMouseTracking(kTRUE);
setFocusPolicy( TabFocus );
setCursor( Qt::crossCursor );
fWid=gVirtualX->AddWindow((ULong_t)winId(),100,30);
if (c == 0) {
fIsCanvasOwned = kTRUE;
fCanvas=new TCanvas(name,width(),height(),fWid);
}
else {
fIsCanvasOwned= kFALSE;
fCanvas=c;
}
fContextMenu = new TQCanvasMenu( parent, fCanvas );
if ( parent ) {
parent->installEventFilter( this );
fParent = parent;
}
else
fParent=0;
setAcceptDrops(kTRUE);
}
TQRootCanvas::TQRootCanvas( QWidget *parent, QWidget* tabWin, const char *name, TCanvas *c )
: QWidget( tabWin, name ,WRepaintNoErase | WResizeNoErase ),
fNeedResize(kTRUE)
{
setUpdatesEnabled( kTRUE );
setMouseTracking(kTRUE);
setFocusPolicy( TabFocus );
setCursor( Qt::crossCursor );
fWid=gVirtualX->AddWindow((ULong_t)winId(),100,30);
if (c == 0) {
fIsCanvasOwned = kTRUE;
fCanvas=new TCanvas(name,width(),height(),fWid);
}
else {
fIsCanvasOwned= kFALSE;
fCanvas=c;
}
fContextMenu = new TQCanvasMenu( parent, tabWin, fCanvas );
if ( parent ) {
parent->installEventFilter( this );
fParent = parent;
}
else
fParent=0;
if ( tabWin )
fTabWin = tabWin;
setAcceptDrops(TRUE);
}
void TQRootCanvas::mouseMoveEvent(QMouseEvent *e)
{
if (fCanvas) {
if (e->state() & LeftButton) {
fCanvas->HandleInput(kButton1Motion, e->x(), e->y());
}
else {
fCanvas->HandleInput(kMouseMotion, e->x(), e->y());
}
}
}
void TQRootCanvas::mousePressEvent( QMouseEvent *e )
{
TPad *pad=0;
TObjLink *pickobj=0;
TObject *selected=0;
Int_t px=e->x();
Int_t py=e->y();
TString selectedOpt;
switch (e->button()) {
case LeftButton :
fCanvas->HandleInput(kButton1Down, e->x(), e->y());
break;
case RightButton :
selected=fCanvas->GetSelected();
pad = fCanvas->Pick(px, py, pickobj);
if (pad) {
if (!pickobj) {
fCanvas->SetSelected(pad); selected=pad;
selectedOpt = "";
}
else {
if (!selected) {
selected = pickobj->GetObject();
selectedOpt = pickobj->GetOption();
}
}
}
pad->cd();
fCanvas->SetSelectedPad(pad);
gROOT->SetSelectedPrimitive(selected);
fContextMenu->Popup(selected,gPad->AbsPixeltoX(gPad->GetEventX()), gPad->AbsPixeltoY(gPad->GetEventY()), e);
break;
case MidButton :
pad = fCanvas->Pick(px, py, pickobj);
emit SelectedPadChanged(pad);
fCanvas->HandleInput(kButton2Down, e->x(), e->y());
break;
case NoButton :
break;
default:
break;
}
}
void TQRootCanvas::mouseReleaseEvent( QMouseEvent *e )
{
switch (e->button()) {
case LeftButton :
fCanvas->HandleInput(kButton1Up, e->x(), e->y());
break;
case RightButton :
fCanvas->HandleInput(kButton3Up, e->x(), e->y());
break;
case MidButton :
fCanvas->HandleInput(kButton2Up, e->x(), e->y());
break;
case NoButton :
break;
default:
break;
}
}
void TQRootCanvas::mouseDoubleClickEvent( QMouseEvent *e )
{
switch (e->button()) {
case LeftButton :
fCanvas->HandleInput(kButton1Double, e->x(), e->y());
break;
case RightButton :
fCanvas->HandleInput(kButton3Double, e->x(), e->y());
break;
case MidButton :
fCanvas->HandleInput(kButton2Double, e->x(), e->y());
break;
case NoButton :
break;
default:
break;
}
}
void TQRootCanvas::resizeEvent( QResizeEvent *e )
{
QWidget::resizeEvent( e );
fNeedResize=kTRUE;
}
void TQRootCanvas::paintEvent( QPaintEvent * )
{
if (fCanvas) {
QPainter p;
p.begin( this);
p.end();
if (fNeedResize) {
fCanvas->Resize();
fNeedResize=kFALSE;
}
fCanvas->Update();
}
}
void TQRootCanvas::leaveEvent( QEvent * )
{
if (fCanvas) fCanvas->HandleInput(kMouseLeave, 0, 0);
}
Bool_t TQRootCanvas ::eventFilter( QObject *o, QEvent *e )
{
if ( e->type() == QEvent::Close) {
if (fCanvas && (fIsCanvasOwned== kFALSE) ) {
delete fCanvas;
fCanvas=0;
}
if ( e->type() == QEvent::ChildRemoved ) {
}
return FALSE;
}
if ( e->type() == QEvent::Destroy) {
return FALSE;
}
if ( e->type() == QEvent::Paint) {
return FALSE;
}
if ( e->type() == QEvent::Move) {
return FALSE;
}
return QWidget::eventFilter( o, e );
}
void TQRootCanvas::dragEnterEvent( QDragEnterEvent *e )
{
if ( QTextDrag::canDecode(e))
e->accept();
}
void TQRootCanvas::dropEvent( QDropEvent *Event )
{
QString str;
if ( QTextDrag::decode( Event, str ) ) {
TObject *dragedObject = gROOT->FindObject(str);
QPoint Pos = Event->pos();
TObject *object=0;
TPad *pad = fCanvas->Pick(Pos.x(), Pos.y(), object);
if (dragedObject!=0) {
if (dragedObject->InheritsFrom("TH1")) {
pad->cd();
dragedObject->Draw();
pad->Update();
}
}
else
cout << "object " <<
#if (QT_VERSION > 0x039999) // Added by cholm@nbi.dk - for Qt 4
str.data()
#else
str
#endif
<< " not found by ROOT" << endl;
}
}
void TQRootCanvas::cd(Int_t subpadnumber)
{
fCanvas->cd(subpadnumber);
}
void TQRootCanvas::Browse(TBrowser *b)
{
fCanvas->Browse(b);
}
void TQRootCanvas::Clear(Option_t *option)
{
fCanvas->Clear(option);
}
void TQRootCanvas::Close(Option_t *option)
{
fCanvas->Close(option);
}
void TQRootCanvas::Draw(Option_t *option)
{
fCanvas->Draw(option);
}
TObject *TQRootCanvas::DrawClone(Option_t *option)
{
return fCanvas->DrawClone(option);
}
TObject *TQRootCanvas::DrawClonePad()
{
return fCanvas->DrawClonePad();
}
void TQRootCanvas::EditorBar()
{
fCanvas->EditorBar();
}
void TQRootCanvas::EnterLeave(TPad *prevSelPad, TObject *prevSelObj)
{
fCanvas->EnterLeave(prevSelPad, prevSelObj);
}
void TQRootCanvas::FeedbackMode(Bool_t set)
{
fCanvas->FeedbackMode(set);
}
void TQRootCanvas::Flush()
{
fCanvas->Flush();
}
void TQRootCanvas::UseCurrentStyle()
{
fCanvas->UseCurrentStyle();
}
void TQRootCanvas::ForceUpdate()
{
fCanvas->ForceUpdate() ;
}
const char *TQRootCanvas::GetDISPLAY()
{
return fCanvas->GetDISPLAY() ;
}
TContextMenu *TQRootCanvas::GetContextMenu()
{
return fCanvas->GetContextMenu() ;
}
Int_t TQRootCanvas::GetDoubleBuffer()
{
return fCanvas->GetDoubleBuffer();
}
Int_t TQRootCanvas::GetEvent()
{
return fCanvas->GetEvent();
}
Int_t TQRootCanvas::GetEventX()
{
return fCanvas->GetEventX() ;
}
Int_t TQRootCanvas::GetEventY()
{
return fCanvas->GetEventY() ;
}
Color_t TQRootCanvas::GetHighLightColor()
{
return fCanvas->GetHighLightColor() ;
}
TVirtualPad *TQRootCanvas::GetPadSave()
{
return fCanvas->GetPadSave();
}
TObject *TQRootCanvas::GetSelected()
{
return fCanvas->GetSelected() ;
}
Option_t *TQRootCanvas::GetSelectedOpt()
{
return fCanvas->GetSelectedOpt();
}
TVirtualPad *TQRootCanvas::GetSelectedPad()
{
return fCanvas->GetSelectedPad();
}
Bool_t TQRootCanvas::GetShowEventStatus()
{
return fCanvas->GetShowEventStatus() ;
}
Bool_t TQRootCanvas::GetAutoExec()
{
return fCanvas->GetAutoExec();
}
Size_t TQRootCanvas::GetXsizeUser()
{
return fCanvas->GetXsizeUser();
}
Size_t TQRootCanvas::GetYsizeUser()
{
return fCanvas->GetYsizeUser();
}
Size_t TQRootCanvas::GetXsizeReal()
{
return fCanvas->GetXsizeReal();
}
Size_t TQRootCanvas::GetYsizeReal()
{
return fCanvas->GetYsizeReal();
}
Int_t TQRootCanvas::GetCanvasID()
{
return fCanvas->GetCanvasID();
}
Int_t TQRootCanvas::GetWindowTopX()
{
return fCanvas->GetWindowTopX();
}
Int_t TQRootCanvas::GetWindowTopY()
{
return fCanvas->GetWindowTopY();
}
UInt_t TQRootCanvas::GetWindowWidth()
{
return fCanvas->GetWindowWidth() ;
}
UInt_t TQRootCanvas::GetWindowHeight()
{
return fCanvas->GetWindowHeight();
}
UInt_t TQRootCanvas::GetWw()
{
return fCanvas->GetWw();
}
UInt_t TQRootCanvas::GetWh()
{
return fCanvas->GetWh() ;
}
void TQRootCanvas::GetCanvasPar(Int_t &wtopx, Int_t &wtopy, UInt_t &ww, UInt_t &wh)
{
fCanvas->GetCanvasPar(wtopx, wtopy, ww, wh);
}
void TQRootCanvas::HandleInput(EEventType button, Int_t x, Int_t y)
{
fCanvas->HandleInput(button, x, y);
}
Bool_t TQRootCanvas::HasMenuBar()
{
return fCanvas->HasMenuBar() ;
}
void TQRootCanvas::Iconify()
{
fCanvas->Iconify();
}
Bool_t TQRootCanvas::IsBatch()
{
return fCanvas->IsBatch() ;
}
Bool_t TQRootCanvas::IsRetained()
{
return fCanvas->IsRetained();
}
void TQRootCanvas::ls(Option_t *option)
{
fCanvas->ls(option);
}
void TQRootCanvas::MoveOpaque(Int_t set)
{
fCanvas->MoveOpaque(set);
}
Bool_t TQRootCanvas::OpaqueMoving()
{
return fCanvas->OpaqueMoving();
}
Bool_t TQRootCanvas::OpaqueResizing()
{
return fCanvas->OpaqueResizing();
}
void TQRootCanvas::Paint(Option_t *option)
{
fCanvas->Paint(option);
}
TPad *TQRootCanvas::Pick(Int_t px, Int_t py, TObjLink *&pickobj)
{
return fCanvas->Pick(px, py, pickobj);
}
TPad *TQRootCanvas::Pick(Int_t px, Int_t py, TObject *prevSelObj)
{
return fCanvas->Pick(px, py, prevSelObj);
}
void TQRootCanvas::Resize(Option_t *option)
{
fCanvas->Resize(option);
}
void TQRootCanvas::ResizeOpaque(Int_t set)
{
fCanvas->ResizeOpaque(set);
}
void TQRootCanvas::SaveSource(const char *filename, Option_t *option)
{
fCanvas->SaveSource(filename, option);
}
void TQRootCanvas::SetCursor(ECursor cursor)
{
fCanvas->SetCursor(cursor);
}
void TQRootCanvas::SetDoubleBuffer(Int_t mode)
{
fCanvas->SetDoubleBuffer(mode);
}
void TQRootCanvas::SetWindowPosition(Int_t x, Int_t y)
{
fCanvas->SetWindowPosition(x, y) ;
}
void TQRootCanvas::SetWindowSize(UInt_t ww, UInt_t wh)
{
fCanvas->SetWindowSize(ww,wh) ;
}
void TQRootCanvas::SetCanvasSize(UInt_t ww, UInt_t wh)
{
fCanvas->SetCanvasSize(ww, wh);
}
void TQRootCanvas::SetHighLightColor(Color_t col)
{
fCanvas->SetHighLightColor(col);
}
void TQRootCanvas::SetSelected(TObject *obj)
{
fCanvas->SetSelected(obj);
}
void TQRootCanvas::SetSelectedPad(TPad *pad)
{
fCanvas->SetSelectedPad(pad);
}
void TQRootCanvas::Show()
{
fCanvas->Show() ;
}
void TQRootCanvas::Size(Float_t xsizeuser, Float_t ysizeuser)
{
fCanvas->Size(xsizeuser, ysizeuser);
}
void TQRootCanvas::SetBatch(Bool_t batch)
{
fCanvas->SetBatch(batch);
}
void TQRootCanvas::SetRetained(Bool_t retained)
{
fCanvas->SetRetained(retained);
}
void TQRootCanvas::SetTitle(const char *title)
{
fCanvas->SetTitle(title);
}
void TQRootCanvas::ToggleEventStatus()
{
fCanvas->ToggleEventStatus();
}
void TQRootCanvas::ToggleAutoExec()
{
fCanvas->ToggleAutoExec();
}
void TQRootCanvas::Update()
{
fCanvas->Update();
}
void TQRootCanvas::closeEvent( QCloseEvent * e)
{
if ( fIsCanvasOwned ) {
delete fCanvas;
fCanvas = 0;
}
e->accept();
return;
}
TQRootCanvas::~TQRootCanvas()
{
if (fContextMenu) {
delete fContextMenu;
fContextMenu=0;
}
if ( fIsCanvasOwned && fCanvas ) {
delete fCanvas;
fCanvas = 0;
}
}
Last change: Wed Jun 25 08:51:44 2008
Last generated: 2008-06-25 08:51
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.