00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #if defined(HAVE_CONFIG) || defined (R__HAVE_CONFIG)
00022 # include "config.h"
00023 #endif
00024 #ifdef R__QTWIN32
00025 #include <process.h>
00026 #endif
00027
00028 #include <assert.h>
00029
00030
00031
00032 #include <QApplication>
00033 #include <QWidget>
00034 #include <QPolygon>
00035 #include <QEvent>
00036 #include <QImageWriter>
00037 #include <QVector>
00038 #include <QStack>
00039 #include <QFrame>
00040 #include <QPicture>
00041 #include <QDebug>
00042
00043 #include <qpixmap.h>
00044 #include <qcursor.h>
00045 #include <qdesktopwidget.h>
00046 #include <qimage.h>
00047 #include <qfontmetrics.h>
00048 #include <qdialog.h>
00049 #include <qlineedit.h>
00050 #include <qfileinfo.h>
00051 #include <qtextcodec.h>
00052 #include <qdir.h>
00053
00054 #include "TROOT.h"
00055 #include "TMath.h"
00056 #include "TColor.h"
00057 #include "TEnv.h"
00058 #include "TQtPen.h"
00059
00060 #include "TQtApplication.h"
00061 #include "TQtWidget.h"
00062 #include "TGQt.h"
00063 #include "TQtBrush.h"
00064 #include "TQtClientFilter.h"
00065 #include "TQtEventQueue.h"
00066 #include "TQtSymbolCodec.h"
00067 #include "TQtLock.h"
00068 #include "TQtPadFont.h"
00069 #include "TStyle.h"
00070 #include "TObjString.h"
00071 #include "TObjArray.h"
00072
00073 #include "TSystem.h"
00074 #ifdef R__QTWIN32
00075 # include "TWinNTSystem.h"
00076 # include "Win32Constants.h"
00077 # include <Winuser.h>
00078 #else
00079 # ifdef R__QTX11
00080 # include <X11/Xlib.h>
00081 # endif
00082 #endif
00083
00084 #include "TSysEvtHandler.h"
00085 #include "TQtMarker.h"
00086
00087 #include "TImage.h"
00088 #include "TError.h"
00089
00090 TGQt *gQt=0;
00091 TVirtualX *TGQt::fgTQt = 0;
00092 TQtTextProxy *TGQt::fgTextProxy = 0;
00093 class TQtTextCloneProxy {
00094 private:
00095 TQtTextProxy *fProxy;
00096 void *operator new(size_t);
00097 TQtTextCloneProxy(const TQtTextCloneProxy&);
00098 void operator=(const TQtTextCloneProxy&);
00099 public:
00100 TQtTextCloneProxy() : fProxy(0)
00101 {
00102 if ( TGQt::TextProxy())
00103 fProxy = TGQt::TextProxy()->Clone();
00104 }
00105 inline ~TQtTextCloneProxy() { delete fProxy; }
00106 inline TQtTextProxy *operator->() { return fProxy;}
00107 };
00108
00109 #define NoOperation (QPaintDevice *)(-1)
00110
00111
00112
00113 static QWidget *IsWidget(QPaintDevice *d)
00114 { return dynamic_cast<QWidget *>(d); }
00115
00116
00117 static QPixmap *IsPixmap(QPaintDevice *d)
00118 { return dynamic_cast<QPixmap *>(d); }
00119
00120 QString TGQt::SetFileName(const QString &fileName)
00121 {
00122
00123 QFileInfo fi(fileName);
00124 QString saveFileMoviePattern =
00125 fi.path()+"/" + fi.completeBaseName()+ "_%04d" + "." + fi.suffix();
00126 return saveFileMoviePattern;
00127 }
00128
00129 QString TGQt::GetNewFileName(const QString &fileNamePrototype)
00130 {
00131
00132 TString flN = fileNamePrototype.toStdString().c_str();
00133 gSystem->ExpandPathName(flN);
00134 QString fileName = (const char *)flN;
00135
00136 Int_t counter = 0;
00137 QString formatPattern = SetFileName(fileName);
00138 while (gSystem->AccessPathName(fileName.toStdString().c_str())==0) {
00139 fileName = QString().sprintf(formatPattern.toStdString().c_str(),counter++);
00140 }
00141 return fileName;
00142 }
00143
00144
00145
00146
00147 class TQtPainter : public QPainter {
00148 private:
00149 TGQt *fVirtualX;
00150 protected:
00151 inline void UpdateBrush() { setBrush(*fVirtualX->fQBrush); }
00152 inline void UpdatePen() { setPen(*fVirtualX->fQPen); }
00153 inline void UpdateFont() { setFont(*fVirtualX->fQFont);
00154 fVirtualX->fTextFontModified = 0;
00155 }
00156 public:
00157 enum { kNone = 0,
00158 kUseFeedBack = 1,
00159 kUpdateFont = 2,
00160 kUpdateBrush = 4,
00161 kUpdatePen = 8
00162 };
00163 TQtPainter() : QPainter (), fVirtualX(0) {}
00164 TQtPainter(QPaintDevice * dev) : QPainter ( dev ), fVirtualX(0) {}
00165 TQtPainter( TGQt *dev, unsigned int useFeedBack=kUpdateBrush | kUpdatePen ) : fVirtualX(0)
00166 { begin(dev,useFeedBack); }
00167 ~TQtPainter () { fVirtualX->fQPainter = 0; }
00168 bool begin ( TGQt *dev, unsigned int useFeedBack);
00169 };
00170
00171
00172
00173
00174 class TQtFeedBackWidget : public QFrame {
00175 QPixmap *fPixBuffer;
00176 QPixmap *fGrabBuffer;
00177 TQtWidget *fParentWidget;
00178 protected:
00179 virtual void hideEvent (QHideEvent *ev) {
00180
00181 delete fPixBuffer; fPixBuffer = 0;
00182 delete fGrabBuffer; fGrabBuffer = 0;
00183 QFrame::hideEvent(ev);
00184 if (fParentWidget) {
00185 fParentWidget->SetIgnoreLeaveEnter(0);
00186 SetParent(0);
00187 }
00188 }
00189 virtual void paintEvent(QPaintEvent *ev) {
00190 if (fPixBuffer) {
00191 QRect rc = ev->rect();
00192 {
00193 QPainter p(this);
00194 p.setClipRect(rc);
00195 p.drawPixmap(0,0,*fPixBuffer);
00196 }
00197 ClearBuffer();
00198 } else if (fGrabBuffer) {
00199 QRect rc = ev->rect();
00200 QPainter p(this);
00201 p.setClipRect(rc);
00202 p.drawPixmap(rc,*fGrabBuffer);
00203 }
00204 QFrame::paintEvent(ev);
00205 }
00206 public:
00207 TQtFeedBackWidget(QWidget *mother=0, Qt::WindowFlags f=0) : QFrame(mother,f)
00208 ,fPixBuffer(0),fGrabBuffer(0),fParentWidget(0)
00209 {
00210
00211 setAttribute(Qt::WA_NoSystemBackground);
00212 setEnabled(false);
00213 setBackgroundRole(QPalette::Window);
00214 setAutoFillBackground(false);
00215 QPalette p = palette();
00216 p.setBrush(QPalette::Window, Qt::transparent);
00217 setPalette(p);
00218 setMouseTracking(true);
00219 }
00220 virtual ~TQtFeedBackWidget()
00221 {
00222 fParentWidget = 0;
00223 delete fPixBuffer; fPixBuffer = 0;
00224 delete fGrabBuffer; fGrabBuffer = 0;
00225 }
00226 void SetParent(TQtWidget *w) {
00227 setParent(fParentWidget = w);
00228 }
00229 void Hide() {
00230 if (fParentWidget) {
00231 fParentWidget->SetIgnoreLeaveEnter(0);
00232 SetParent(0);
00233 }
00234 }
00235 void Show() {
00236
00237
00238 if (fParentWidget) fParentWidget->SetIgnoreLeaveEnter(2);
00239 QFrame::show();
00240 if (fParentWidget) fParentWidget->SetIgnoreLeaveEnter();
00241 }
00242 QPaintDevice *PixBuffer() {
00243
00244 if (fParentWidget ) {
00245
00246 QSize canvasSize = fParentWidget->size();
00247 setGeometry(QRect(QPoint(0,0),canvasSize));
00248 if ( !fPixBuffer || (fPixBuffer->size() != canvasSize) ) {
00249 delete fPixBuffer;
00250 fPixBuffer = new QPixmap(canvasSize);
00251 ClearBuffer();
00252 }
00253 }
00254 return fPixBuffer;
00255 }
00256 QPaintDevice *GrabBuffer(QSize &s) {
00257
00258 if (fParentWidget ) {
00259
00260 if ( !fPixBuffer || (fPixBuffer->size() != s) ) {
00261 delete fPixBuffer;
00262 fPixBuffer = new QPixmap(s);
00263 ClearBuffer();
00264 }
00265 }
00266 return fPixBuffer;
00267 }
00268 void ClearBuffer() {
00269
00270 fPixBuffer->fill(Qt::transparent);
00271 }
00272 void SetGeometry(int xp,int yp, int w, int h, TQtWidget *src=0)
00273 {
00274
00275 if (isHidden() && src ) {
00276
00277 delete fGrabBuffer; fGrabBuffer = 0;
00278 QPixmap *canvas = src->GetOffScreenBuffer();
00279 if (canvas && w > 4 && h > 4 ) {
00280 fGrabBuffer = new QPixmap(canvas->copy(xp,yp,w,h));
00281 }
00282 }
00283 setGeometry(xp,yp,w,h);
00284 }
00285 };
00286
00287
00288
00289
00290
00291
00292 class TQtToggleFeedBack {
00293 TGQt *fGQt;
00294 TQtPainter fFeedBackPainter;
00295
00296 public:
00297 TQtToggleFeedBack(TGQt *gqt) : fGQt(gqt)
00298 {
00299
00300 if (fGQt->fFeedBackMode && fGQt->fFeedBackWidget->isHidden()) {
00301 fGQt->fFeedBackWidget->Show();
00302 }
00303 }
00304 ~TQtToggleFeedBack()
00305 {
00306
00307 if (fFeedBackPainter.isActive() ) fFeedBackPainter.end();
00308 if (fGQt->fFeedBackMode && fGQt->fFeedBackWidget)
00309 { fGQt->fFeedBackWidget->update(); }
00310 }
00311 TQtPainter &painter() {
00312
00313 if (!fFeedBackPainter.isActive()) {
00314 fFeedBackPainter.begin(fGQt, TQtPainter::kUseFeedBack
00315 | TQtPainter::kUpdatePen
00316 | TQtPainter::kUpdateBrush);
00317 if (fGQt->fFeedBackMode) {
00318 fFeedBackPainter.setPen(QColor(128,128,128,128));
00319 }
00320 }
00321 return fFeedBackPainter;
00322 }
00323 };
00324
00325
00326
00327
00328
00329 inline bool TQtPainter::begin ( TGQt *dev, unsigned int useFeedBack)
00330 {
00331
00332 bool res = false;
00333 if (dev && (dev->fSelectedWindow != NoOperation)) {
00334 fVirtualX = dev;
00335 QPaintDevice *src= 0;
00336 if ( (useFeedBack & kUseFeedBack) && dev->fFeedBackMode
00337 && dev->fFeedBackWidget
00338 && dev->fFeedBackWidget)
00339 { src = dev->fFeedBackWidget->PixBuffer(); }
00340 else {
00341 src = dev->fSelectedWindow;
00342 if ( src->devType() == QInternal::Widget)
00343 {
00344 TQtWidget *theWidget = (TQtWidget *)src;
00345
00346 src = theWidget->SetBuffer().Buffer();
00347 }
00348 }
00349 if (!(res= QPainter::begin(src)) ) {
00350 Error("TGQt::Begin()","Can not create Qt painter for win=0x%lx dev=0x%lx\n",(Long_t)src,(Long_t)dev);
00351 assert(0);
00352 } else {
00353 dev->fQPainter = (TQtPainter*)-1;
00354 UpdatePen();
00355 UpdateBrush();
00356 UpdateFont();
00357 TGQt::TQTCLIPMAP::iterator it= (dev->fClipMap).find(src);
00358 QRect clipRect;
00359 if (it != (dev->fClipMap).end()) {
00360 clipRect = it.value();
00361 setClipRect(clipRect);
00362 setClipping(TRUE);
00363 }
00364 if (src->devType() == QInternal::Image )
00365 setCompositionMode(dev->fDrawMode);
00366 }
00367 }
00368 return res;
00369 }
00370
00371
00372
00373
00374 class TQtEventInputHandler : public TTimer {
00375 protected:
00376 TQtEventInputHandler() : TTimer(340) { }
00377 static TQtEventInputHandler *gfQtEventInputHandler;
00378 public:
00379
00380 static TQtEventInputHandler *Instance() {
00381 if (!gfQtEventInputHandler)
00382 gfQtEventInputHandler = new TQtEventInputHandler();
00383 gfQtEventInputHandler->Start(240);
00384 return gfQtEventInputHandler;
00385 }
00386 Bool_t Notify() {
00387 Timeout();
00388 Bool_t ret = gQt->processQtEvents();
00389 Start(240);
00390 Reset();
00391 return ret;
00392 }
00393 Bool_t ReadNotify() { return Notify(); }
00394 };
00395
00396 TQtEventInputHandler *TQtEventInputHandler::gfQtEventInputHandler = 0;
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406 class TQWidgetCollection {
00407 private:
00408 QStack<int> fFreeWindowsIdStack;
00409 QVector<QPaintDevice *> fWidgetCollection;
00410 Int_t fIDMax;
00411 Int_t fIDTotalMax;
00412 protected:
00413
00414 inline Int_t SetMaxId(Int_t newId)
00415 {
00416 fIDMax = newId;
00417 if (newId>fIDTotalMax) {
00418 fIDTotalMax = newId;
00419 fWidgetCollection.resize(fIDTotalMax+1);
00420 }
00421 return fIDMax;
00422 }
00423
00424 public:
00425
00426 TQWidgetCollection () : fIDMax(-1), fIDTotalMax(-1)
00427 {
00428
00429
00430 int kDefault = 1;
00431 assert(!kNone);
00432 SetMaxId (kDefault);
00433 fWidgetCollection[kNone] = (QPaintDevice*)0;
00434 fWidgetCollection[kDefault] = (QPaintDevice *)QApplication::desktop();
00435 }
00436
00437
00438 inline Int_t GetFreeId(QPaintDevice *device) {
00439
00440 Int_t Id = 0;
00441 if (!fFreeWindowsIdStack.isEmpty() ) {
00442 Id = fFreeWindowsIdStack.pop();
00443 if (Id > fIDMax ) SetMaxId ( Id );
00444 } else {
00445 Id = fWidgetCollection.count();
00446 assert(fIDMax <= Id );
00447 SetMaxId ( Id );
00448 }
00449 fWidgetCollection[Id] = device;
00450
00451 return Id;
00452 }
00453
00454 inline Int_t RemoveByPointer(QPaintDevice *device)
00455 {
00456
00457 Int_t intWid = kNone;
00458 if ((ULong_t) device != (ULong_t) -1) {
00459 intWid = find( device);
00460 if ( intWid != -1 &&
00461 fWidgetCollection[intWid]) {
00462 fWidgetCollection[intWid] = (QPaintDevice *)(-1);
00463 fFreeWindowsIdStack.push(intWid);
00464 if (fIDMax == intWid) SetMaxId(--fIDMax);
00465 } else {
00466 intWid = kNone;
00467 }
00468 }
00469 return intWid;
00470 }
00471
00472
00473 inline const QPaintDevice *DeleteById(Int_t Id)
00474 {
00475 QPaintDevice *device = fWidgetCollection[Id];
00476 if (device) {
00477 delete device;
00478 fWidgetCollection[Id] = (QPaintDevice *)(-1);
00479 fFreeWindowsIdStack.push(Id);
00480 if (fIDMax == Id) SetMaxId(--fIDMax);
00481 }
00482
00483 return 0;
00484 }
00485
00486 inline const QPaintDevice *ReplaceById(Int_t Id, QPaintDevice *newDev)
00487 {
00488 if (newDev) {
00489
00490 delete fWidgetCollection[Id];
00491
00492 fWidgetCollection[Id] = newDev;
00493 } else {
00494 DeleteById(Id);
00495 }
00496 return newDev;
00497 }
00498
00499
00500 inline uint count() const { return fWidgetCollection.count();}
00501
00502 inline uint MaxId() const { return fIDMax;}
00503
00504 inline uint MaxTotalId() const { return fIDTotalMax;}
00505
00506 inline int find(const QPaintDevice *device, uint i=0) const
00507 {
00508 return fWidgetCollection.indexOf((QPaintDevice*)device,i);
00509 }
00510
00511 inline QPaintDevice *operator[](int i) const {return fWidgetCollection[i];}
00512 };
00513 TQWidgetCollection *fWidgetArray = 0;
00514
00515 QPaintDevice *TGQt::iwid(Window_t wd)
00516 {
00517
00518 QPaintDevice *topDevice = 0;
00519 if ( wd != kNone ) {
00520 topDevice = (wd == kDefault) ?
00521 (QPaintDevice *)QApplication::desktop()
00522 :
00523 (QPaintDevice*)wd;
00524 }
00525 return topDevice;
00526 }
00527
00528
00529 Int_t TGQt::iwid(QPaintDevice *wd)
00530 {
00531
00532 Int_t intWid = kNone;
00533
00534 if ((ULong_t) wd == (ULong_t) -1) intWid = -1;
00535 else {
00536 intWid = fWidgetArray->find(wd);
00537 assert(intWid != -1);
00538
00539 }
00540 return intWid;
00541 }
00542
00543
00544 QPaintDevice *TGQt::iwid(Int_t wd)
00545 {
00546
00547 QPaintDevice *topDevice = 0;
00548 if (0 <= wd && wd <= int(fWidgetArray->MaxId()) )
00549 topDevice = (*fWidgetArray)[wd];
00550 if (topDevice == (QPaintDevice *)(-1) ) topDevice = 0;
00551 else {
00552 assert(wd <= Int_t(fWidgetArray->MaxTotalId()));
00553
00554
00555
00556 }
00557 return topDevice;
00558 }
00559
00560
00561 QWidget *TGQt::winid(Window_t id)
00562 {
00563
00564 return (id != kNone)? TGQt::wid(id)->topLevelWidget():0;
00565 }
00566
00567
00568 Window_t TGQt::wid(TQtClientWidget *widget)
00569 {
00570 return rootwid(widget);
00571 }
00572
00573 Window_t TGQt::rootwid(QPaintDevice *dev)
00574 {
00575 return Window_t(dev);
00576 }
00577
00578 QWidget *TGQt::wid(Window_t id)
00579 {
00580
00581 QPaintDevice *dev = 0;
00582 if (id == (Window_t)kNone || id == (Window_t)(-1) ) return (QWidget *)dev;
00583 if ( id <= fWidgetArray->MaxId() )
00584 dev = (*fWidgetArray)[id];
00585 else
00586 dev = (QPaintDevice *)id;
00587
00588
00589 #if 0
00590 if ( dev->devType() != QInternal::Widget) {
00591 fprintf(stderr," %s %i type=%d QInternal::Widget = %d id =%x id = %d\n", "TGQt::wid", __LINE__
00592 , dev->devType()
00593 , QInternal::Widget, id, id );
00594
00595 }
00596 #endif
00597 assert(dev->devType() == QInternal::Widget);
00598 return (QWidget *)dev;
00599 }
00600
00601
00602 void TGQt::PrintEvent(Event_t &ev)
00603 {
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622 qDebug() << "----- Window "<< TGQt::wid(ev.fWindow) << TGQt::wid(ev.fWindow) << " " << TGQt::wid(ev.fWindow)-> objectName();
00623 fprintf(stderr,"event type = %x, key or button code %d \n", ev.fType, ev.fCode);
00624 fprintf(stderr,"fX, fY, fXRoot, fYRoot = %d %d :: %d %d\n", ev.fX, ev.fY,ev.fXRoot, ev.fYRoot);
00625 }
00626
00627 int TGQt::fgCoinFlag = 0;
00628 int TGQt::fgCoinLoaded = 0;
00629
00630
00631 int TGQt::CoinFlag()
00632 {
00633
00634 TQtLock lock;
00635 int ret = fgCoinFlag;
00636 return ret;
00637 }
00638
00639
00640 void TGQt::SetCoinFlag(int flag)
00641 {
00642
00643 TQtLock lock;
00644 fgCoinFlag=flag;
00645 }
00646
00647
00648 void TGQt::SetCoinLoaded() { fgCoinLoaded = 1; }
00649
00650
00651 Int_t TGQt::IsCoinLoaded(){ return fgCoinLoaded;}
00652
00653 #if ROOT_VERSION_CODE < ROOT_VERSION(5,13,0)
00654
00655 QPixmap *TGQt::MakeIcon(Int_t i)
00656 {
00657
00658 QPixmap *tempIcon = NULL;
00659 if (i) { }
00660 #ifdef R__QTWIN32
00661 HICON largeIcon[1];
00662 HICON smallIcon[1];
00663 HICON icon = ((TWinNTSystem *)gSystem)->GetNormalIcon(i);
00664 #if 0
00665 int numIcons = ::ExtractIconEx(
00666 "c:\winnt\explorer.exe",
00667 0,
00668 largeIcon,
00669 smallIcon,
00670 1);
00671 if (numIcons > 0)
00672 {
00673 #endif
00674 tempIcon =new QPixmap (GetSystemMetrics(SM_CXSMICON),
00675 GetSystemMetrics(SM_CYSMICON));
00676 HDC dc = tempIcon->handle();
00677 DrawIcon (dc, 0, 0, icon);
00678 #else
00679 # ifdef ROOTICONPATH
00680 gSystem->ExpandPathName(ROOTICONPATH);
00681 # else
00682 gSystem->ExpandPathName("$ROOTSYS/icons/");
00683
00684 # endif
00685 #endif
00686 return tempIcon;
00687 }
00688 #endif
00689
00690
00691 ClassImp(TGQt)
00692
00693
00694
00695
00696
00697 QString TGQt::RootFileFormat(const char *selector)
00698 { return RootFileFormat(QString(selector)); }
00699
00700
00701 QString TGQt::RootFileFormat(const QString &selector)
00702 {
00703
00704
00705
00706 QString saveType;
00707 QString defExtension[] = {"cpp","cxx","eps","svg","root","pdf","ps","xml"
00708 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,13,0)
00709 ,"gif"
00710 #endif
00711 ,"C"};
00712 UInt_t nExt = sizeof(defExtension)/sizeof(const char *);
00713 UInt_t i = 0;
00714 for (i=0; i < nExt; i++) {
00715 if (selector.contains(defExtension[i], Qt::CaseSensitive)) {
00716 saveType = defExtension[i];
00717 break;
00718 }
00719 }
00720 if (saveType.contains("C",Qt::CaseInsensitive)) saveType= "cxx";
00721 return saveType;
00722 }
00723
00724
00725 QString TGQt::QtFileFormat(const char *selector)
00726 { return QtFileFormat(QString(selector)); }
00727
00728
00729 QString TGQt::QtFileFormat(const QString &selector)
00730 {
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740 QString saveType="PNG";
00741 if (!selector.isEmpty()) {
00742 QList<QByteArray> formats = QImageWriter::supportedImageFormats();
00743 QList<QByteArray>::const_iterator j;
00744 for (j = formats.constBegin(); j != formats.constEnd(); ++j)
00745 {
00746 QString nextFormat = *j;
00747
00748 QString checkString = selector.contains("jpg",Qt::CaseInsensitive) ? "JPEG" : selector;
00749 if (checkString.contains(nextFormat,Qt::CaseInsensitive) ) {
00750 saveType = nextFormat;
00751 break;
00752 }
00753 }
00754
00755
00756
00757
00758 }
00759 return saveType;
00760 }
00761
00762
00763 TQtApplication *TGQt::CreateQtApplicationImp()
00764 {
00765
00766 static TQtApplication *app = 0;
00767 if (!app) {
00768
00769 static TString argvString (
00770 #ifdef ROOTBINDIR
00771 ROOTBINDIR "/root.exe"
00772 #else
00773 "$ROOTSYS/bin/root.exe"
00774 #endif
00775 );
00776 gSystem->ExpandPathName(argvString);
00777 static char *argv[] = {(char *)argvString.Data()};
00778 static int nArg = 1;
00779 app = new TQtApplication("Qt",nArg,argv);
00780 }
00781 return app;
00782 }
00783
00784
00785 void TGQt::PostQtEvent(QObject *receiver, QEvent *event)
00786 {
00787
00788
00789 QApplication::postEvent(receiver,event);
00790 }
00791
00792
00793 TGQt::TGQt() : TVirtualX(),fDisplayOpened(kFALSE),fQPainter(0),fhEvent ()
00794 ,fQBrush(),fQPen(),fQtMarker(),fQFont(),fQClientFilter(),fQClientFilterBuffer(0)
00795 ,fPointerGrabber(),fCodec(0),fSymbolFontFamily("Symbol"),fQtEventHasBeenProcessed(0)
00796 ,fFeedBackMode(kFALSE),fFeedBackWidget(0),fBlockRGB(kFALSE),fUseTTF(kTRUE)
00797 {
00798
00799
00800 assert(!fgTQt);
00801 fgTQt = this;
00802 gQt = this;
00803 fSelectedWindow = fPrevWindow = NoOperation;
00804 }
00805
00806
00807 TGQt::TGQt(const char *name, const char *title) : TVirtualX(name,title),fDisplayOpened(kFALSE)
00808 ,fQPainter(0),fhEvent(),fCursors(kNumCursors),fQClientFilter(0),fQClientFilterBuffer(0),fPointerGrabber(0)
00809 ,fCodec(0),fSymbolFontFamily("Symbol"),fQtEventHasBeenProcessed(0)
00810 ,fFeedBackMode(kFALSE),fFeedBackWidget(0),fBlockRGB(kFALSE),fUseTTF(kTRUE)
00811 {
00812
00813
00814 assert(!fgTQt);
00815 fgTQt = this;
00816 gQt = this;
00817 fSelectedWindow = fPrevWindow = NoOperation;
00818 CreateQtApplicationImp();
00819 Init();
00820 }
00821
00822
00823 TGQt::~TGQt()
00824 {
00825
00826
00827 {
00828 TQtLock lock;
00829 gVirtualX = gGXBatch;
00830 gROOT->SetBatch();
00831
00832 QMap<Color_t,QColor*>::const_iterator it;
00833 for (it = fPallete.begin();it !=fPallete.end();++it) {
00834 QColor *c = *it; delete c;
00835 }
00836 qDeleteAll(fCursors.begin(), fCursors.end());
00837
00838 delete fQClientFilter; fQClientFilter = 0;
00839 delete fQClientFilterBuffer; fQClientFilterBuffer = 0;
00840 delete fgTextProxy; fgTextProxy = 0;
00841
00842 }
00843
00844 TQtApplication::Terminate();
00845
00846 }
00847
00848
00849 Bool_t TGQt::Init(void* )
00850 {
00851
00852
00853 fprintf(stderr,"** $Id: TGQt.cxx 36275 2010-10-11 08:05:21Z brun $ this=%p\n",this);
00854 #ifndef R__QTWIN32
00855 extern void qt_x11_set_global_double_buffer(bool);
00856
00857 #endif
00858
00859 if(fDisplayOpened) return fDisplayOpened;
00860 fSelectedWindow = fPrevWindow = NoOperation;
00861 fTextAlignH = 1;
00862 fTextAlignV = 1;
00863 fTextMagnitude = 1;
00864 fCharacterUpX = 1;
00865 fCharacterUpY = 1;
00866 fDrawMode = QPainter::CompositionMode_Source;
00867 fTextFontModified = 0;
00868
00869 fTextAlign = 0;
00870 fTextSize = -1;
00871 fTextFont = -1;
00872 fLineWidth = -1;
00873 fFillColor = -1;
00874 fLineColor = -1;
00875 fLineStyle = -1;
00876 fMarkerSize = -1;
00877 fMarkerStyle = -1;
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891 fCursors[kBottomLeft] = new QCursor(Qt::SizeBDiagCursor);
00892 fCursors[kBottomRight] = new QCursor(Qt::SizeFDiagCursor);
00893 fCursors[kTopLeft] = new QCursor(Qt::SizeFDiagCursor);
00894 fCursors[kTopRight] = new QCursor(Qt::SizeBDiagCursor);
00895
00896
00897
00898
00899 fCursors[kBottomSide] = new QCursor(Qt::SizeVerCursor);
00900 fCursors[kLeftSide] = new QCursor(Qt::SizeHorCursor);
00901 fCursors[kTopSide] = new QCursor(Qt::SizeVerCursor);
00902 fCursors[kRightSide] = new QCursor(Qt::SizeHorCursor);
00903
00904 fCursors[kMove] = new QCursor(Qt::SizeAllCursor);
00905 fCursors[kCross] = new QCursor(Qt::CrossCursor);
00906 fCursors[kArrowHor] = new QCursor(Qt::SizeHorCursor);
00907 fCursors[kArrowVer] = new QCursor(Qt::SizeVerCursor);
00908 fCursors[kHand] = new QCursor(Qt::PointingHandCursor);
00909 fCursors[kRotate] = new QCursor(Qt::ForbiddenCursor);
00910 fCursors[kPointer] = new QCursor(Qt::ArrowCursor);
00911 fCursors[kArrowRight] = new QCursor(Qt::UpArrowCursor);
00912 fCursors[kCaret] = new QCursor(Qt::IBeamCursor);
00913 fCursors[kWatch] = new QCursor(Qt::WaitCursor);
00914
00915
00916
00917 fCursor = kCross;
00918
00919
00920 fQPen = new TQtPen;
00921 fQBrush = new TQtBrush;
00922 fQtMarker = new TQtMarker;
00923 fQFont = new TQtPadFont();
00924
00925 fQClientFilter = new TQtClientFilter();
00926
00927
00928 fFontTextCode = "ISO8859-1";
00929 const char *default_font =
00930 gEnv->GetValue("Gui.DefaultFont", "-adobe-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
00931 QFont *dfFont = (QFont *)LoadQueryFont(default_font);
00932 QApplication::setFont(*dfFont);
00933 delete dfFont;
00934
00935 QString fontName(default_font);
00936 fFontTextCode = fontName.section('-',13). toUpper();
00937 if ( fFontTextCode.isEmpty() ) fFontTextCode = "ISO8859-5";
00938 #ifndef R__QTWIN32
00939
00940 QFontDatabase fdb;
00941 QString fontFamily;
00942 QStringList families = fdb.families();
00943 Bool_t symbolFontFound = kFALSE;
00944 Bool_t isXdfSupport = !gSystem->Getenv("QT_X11_NO_FONTCONFIG");
00945 for ( QStringList::Iterator f = families.begin(); f != families.end(); ++f ) {
00946
00947 if ( (isXdfSupport && (*f).contains(fSymbolFontFamily)
00948 && fdb.writingSystems(*f).contains(QFontDatabase::Symbol)
00949 ) || (!isXdfSupport && ((*f) == fSymbolFontFamily)) )
00950 {
00951 symbolFontFound = kTRUE;
00952 qDebug() << "Symbol font family found: " << *f;
00953 if (*f == "Standard Symbols L") { fontFamily = *f; break; }
00954 }
00955 }
00956
00957 if (isXdfSupport && !symbolFontFound) {
00958
00959 QString fontdir =
00960 #ifdef TTFFONTDIR
00961 TTFFONTDIR
00962 #else
00963 "$ROOOTSYS/fonts"
00964 #endif
00965 ;
00966 QString symbolFontFile = fontdir + "/" + QString(fSymbolFontFamily).toLower() + ".ttf";
00967 symbolFontFound = QFontDatabase::addApplicationFont(symbolFontFile);
00968 }
00969 if (!symbolFontFound) {
00970 fprintf(stderr, "The font \"symbol.ttf\" was not installed yet\n");
00971
00972 fontFamily = fSymbolFontFamily = "Arial";
00973 qDebug() << " Substitute it with \""<<fontFamily <<"\"";
00974 qDebug() << " Make sure your local \"~/.fonts.conf\" or \"/etc/fonts/fonts.conf\" file points to \""
00975 <<
00976 #ifdef TTFFONTDIR
00977 TTFFONTDIR
00978 #else
00979 "$ROOOTSYS/fonts"
00980 #endif
00981 << "\" directory to get the proper support for ROOT TLatex class";
00982
00983 new QSymbolCodec();
00984 }
00985 if (symbolFontFound) TQtPadFont::SetSymbolFontFamily(fontFamily.toAscii().data());
00986 #endif
00987 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,0)
00988 fUseTTF=gEnv->GetValue("Qt.Screen.TTF",kFALSE);
00989 #else
00990 fUseTTF=gEnv->GetValue("Qt.Screen.TTF",kTRUE);
00991 #endif
00992
00993
00994
00995 fWidgetArray = new TQWidgetCollection();
00996 fDisplayOpened = kTRUE;
00997 TQtEventInputHandler::Instance();
00998
00999
01000 if (gSystem->Getenv("QTDIR")) {
01001 TString qtdir = "$(QTDIR)/include/";
01002
01003 gSystem->ExpandPathName(qtdir);
01004 TString testQtHeader = qtdir + "Qt/qglobal.h";
01005 if (!gSystem->AccessPathName((const char *)testQtHeader) ) {
01006 void *qtdirHandle = gSystem->OpenDirectory(qtdir);
01007 if (qtdirHandle) {
01008 TString incpath = " -I"; incpath+=qtdir;
01009 while(const char *nextQtInclude = gSystem->GetDirEntry(qtdirHandle)) {
01010
01011 if (nextQtInclude[0] != '.') {
01012 incpath += " -I"; incpath+=qtdir; incpath+=nextQtInclude;
01013 }
01014 }
01015 gSystem->FreeDirectory(qtdirHandle);
01016 gSystem->AddIncludePath((const char*)incpath);
01017 }
01018 #ifdef R__WIN32
01019 QString libPath = gSystem->GetLinkedLibs();
01020
01021 TString qtlibdir= "$(QTDIR)";
01022 qtlibdir += QDir::separator().toAscii();
01023 qtlibdir += "lib";
01024
01025 gSystem->ExpandPathName(qtlibdir);
01026 QDir qtdir((const char*)qtlibdir);
01027 if (qtdir.isReadable ()) {
01028 QStringList qtLibFile = qtdir.entryList(QStringList("Q*4.lib"),QDir::Files);
01029 QStringListIterator libFiles(qtLibFile);
01030 if (libFiles.hasNext()) {
01031 libPath += " -LIBPATH:\"";libPath += qtlibdir; libPath += "\" ";
01032 #if 0
01033 while (libFiles.hasNext()) {
01034 QString nf = libFiles.next();
01035 if (nf.contains("d4")) continue;
01036 libPath += nf.toLocal8Bit().constData();
01037 libPath += " ";
01038 }
01039 #else
01040 libPath += "QtCore4.lib QtGui4.lib QtOpenGL4.lib Qt3Support4.lib";
01041 #endif
01042 gSystem->SetLinkedLibs(libPath.toAscii().data());
01043 }
01044 } else {
01045 qWarning(" Can not open the QTDIR %s",(const char*)qtlibdir);
01046 }
01047 #endif
01048 }
01049 }
01050 TString newPath =
01051 # ifdef CINTINCDIR
01052 CINTINCDIR
01053 # else
01054 "$(ROOTSYS)/cint/"
01055 # endif
01056 ; newPath += "include";
01057 #ifndef R__WIN32
01058 newPath += ":";
01059 #else
01060 newPath += ";";
01061 #endif
01062 newPath += gSystem->GetDynamicPath();
01063 gSystem->SetDynamicPath(newPath.Data());
01064 return fDisplayOpened;
01065 }
01066
01067
01068 Int_t TGQt::CreatROOTThread()
01069 {
01070
01071
01072 return 0;
01073 }
01074
01075 Int_t TGQt::RegisterWid(QPaintDevice *wd)
01076 {
01077
01078 Int_t id = fWidgetArray->find(wd);
01079 if (id == -1) id = fWidgetArray->GetFreeId(wd);
01080 return id;
01081 }
01082
01083 Int_t TGQt::UnRegisterWid(QPaintDevice *wd)
01084 {
01085
01086
01087 return fWidgetArray->RemoveByPointer(wd);
01088 }
01089
01090 Bool_t TGQt::IsRegistered(QPaintDevice *wd)
01091 {
01092
01093 return fWidgetArray->find(wd) == -1 ? kFALSE : kTRUE;
01094 }
01095
01096 Int_t TGQt::InitWindow(ULong_t window)
01097 {
01098
01099
01100
01101
01102
01103
01104 TQtWidget *wd = 0;
01105 QWidget *parent = 0;
01106 if (window <= fWidgetArray->MaxId() )
01107 parent = dynamic_cast<TQtWidget *> (iwid(int (window)));
01108 else {
01109 QPaintDevice *dev = dynamic_cast<QPaintDevice *>(iwid(Window_t(window)));
01110 parent = dynamic_cast<QWidget *>(dev);
01111 }
01112
01113
01114
01115 wd = new TQtWidget(parent,"virtualx",Qt::FramelessWindowHint,FALSE);
01116 wd->setCursor(*fCursors[kCross]);
01117 Int_t id = fWidgetArray->GetFreeId(wd);
01118
01119 wd->SetDoubleBuffer(1);
01120
01121 return id;
01122 }
01123
01124
01125 Int_t TGQt::OpenPixmap(UInt_t w, UInt_t h)
01126 {
01127
01128 QPixmap *obj = new QPixmap(w,h);
01129
01130 return fWidgetArray->GetFreeId(obj);
01131
01132 }
01133
01134
01135 const QColor &TGQt::ColorIndex(Color_t ic) const
01136 {
01137
01138 QColor *colorBuffer=0;
01139 static QColor unknownColor;
01140
01141
01142
01143 if (!fPallete.contains(ic)) {
01144 Warning("ColorIndex","Unknown color. No RGB component for the index %d was defined\n",ic);
01145 return unknownColor;
01146 } else {
01147
01148
01149 TColor *myColor = gROOT->GetColor(ic);
01150 Float_t a = myColor->GetAlpha();
01151 colorBuffer = fPallete[ic];
01152 if (TMath::Abs(colorBuffer->alphaF() - a) > 0.01) {
01153 colorBuffer->setAlphaF(a);
01154 }
01155 }
01156 return *colorBuffer;
01157 }
01158
01159
01160 UInt_t TGQt::ExecCommand(TGWin32Command* )
01161 {
01162
01163 fprintf(stderr,"** Error **: TGQt::ExecCommand no implementation\n");
01164 return 0;
01165 }
01166
01167
01168 void TGQt::SetDoubleBufferOFF()
01169 {
01170
01171 fprintf(stderr,"** Error **: TGQt::SetDoubleBufferOFF no implementation\n");
01172 }
01173
01174
01175 void TGQt::SetDoubleBufferON()
01176 {
01177
01178 fprintf(stderr,"** Error **: TGQt::SetDoubleBufferON no implementation\n");
01179 }
01180
01181
01182 void TGQt::GetPlanes(Int_t &nplanes){
01183
01184
01185
01186
01187 nplanes = QPixmap::defaultDepth();
01188 }
01189
01190
01191 void TGQt::ClearWindow()
01192 {
01193
01194 if (fSelectedWindow && fSelectedWindow != NoOperation)
01195 {
01196 if (IsWidget(fSelectedWindow)) {
01197 ((TQtWidget *)fSelectedWindow)->Erase();
01198 } else if (IsPixmap(fSelectedWindow) ) {
01199 ((QPixmap *)fSelectedWindow)->fill(fQBrush->color());
01200 } else {
01201 TQtPainter p(this);
01202 p.eraseRect(GetQRect(*fSelectedWindow));
01203 }
01204 }
01205 }
01206
01207
01208 void TGQt::ClosePixmap()
01209 {
01210
01211 DeleteSelectedObj();
01212 }
01213
01214
01215 void TGQt::CloseWindow()
01216 {
01217
01218 DeleteSelectedObj();
01219 }
01220
01221
01222 void TGQt::DeleteSelectedObj()
01223 {
01224
01225 if (fSelectedWindow->devType() == QInternal::Widget) {
01226 TQtWidget *canvasWidget = dynamic_cast<TQtWidget *>(fSelectedWindow);
01227 if (canvasWidget) {
01228 canvasWidget->ResetCanvas();
01229 }
01230 QWidget *wrapper = 0;
01231 if (canvasWidget && (wrapper=canvasWidget->GetRootID())) {
01232 wrapper->hide();
01233 DestroyWindow(rootwid(wrapper) );
01234 } else {
01235
01236 if(UnRegisterWid(fSelectedWindow) != (Int_t) kNone) {
01237 ((QWidget *)fSelectedWindow)->hide();
01238 ((QWidget *)fSelectedWindow)->close();
01239 }
01240 }
01241 } else {
01242 UnRegisterWid(fSelectedWindow);
01243 delete fSelectedWindow;
01244 }
01245 fClipMap.remove(fSelectedWindow);
01246 fSelectedWindow = 0;
01247 fPrevWindow = 0;
01248 }
01249
01250
01251 QRect TGQt::GetQRect(QPaintDevice &dev)
01252 {
01253
01254 QRect res(0,0,0,0);
01255
01256 switch (dev.devType() ) {
01257 case QInternal::Widget:
01258 res = ((TQtWidget*)&dev)->rect();
01259 break;
01260
01261 default:
01262 res.setSize(QSize(dev.width(),dev.height()));
01263 break;
01264 };
01265 return res;
01266 }
01267
01268
01269 void TGQt::CopyPixmap(int wd, int xpos, int ypos)
01270 {
01271
01272
01273 if (!wd || (wd == -1) ) return;
01274 QPaintDevice *dev = iwid(wd);
01275 assert(dev->devType() == QInternal::Pixmap);
01276 QPixmap *src = (QPixmap *)dev;
01277
01278
01279
01280 if (fSelectedWindow )
01281 {
01282 QPaintDevice *dst = fSelectedWindow;
01283 if (dst == (QPaintDevice *)-1) {
01284 Error("TGQt::CopyPixmap","Wrong TGuiFactory implementation was provided. Please, check your plugin settings");
01285 assert(dst != (QPaintDevice *)-1);
01286 }
01287 bool itIsWidget = fSelectedWindow->devType() == QInternal::Widget;
01288 TQtWidget *theWidget = 0;
01289 if (itIsWidget) {
01290 theWidget = (TQtWidget *)fSelectedWindow;
01291 dst = theWidget->GetOffScreenBuffer();
01292 }
01293 {
01294 QPainter paint(dst);
01295 paint.drawPixmap(xpos,ypos,*src);
01296 }
01297 Emitter()->EmitPadPainted(src);
01298 if (theWidget) theWidget->EmitCanvasPainted();
01299 }
01300 }
01301
01302 void TGQt::CopyPixmap(const QPixmap &src, Int_t xpos, Int_t ypos)
01303 {
01304
01305 if (fSelectedWindow )
01306 {
01307 QPaintDevice *dst = fSelectedWindow;
01308 QPainter paint(dst); paint.drawPixmap(xpos,ypos,src);
01309 }
01310 }
01311
01312 void TGQt::CreateOpenGLContext(int wd)
01313 {
01314
01315
01316
01317 if (!wd || (wd == -1) ) return;
01318
01319 #ifdef QtGL
01320 if (!wd)
01321 {
01322 SafeCallWin32
01323 ->W32_CreateOpenGL();
01324 }
01325 else
01326 {
01327 SafeCallW32(((TQtSwitch *)wd))
01328 ->W32_CreateOpenGL();
01329 }
01330 #endif
01331
01332 }
01333
01334
01335 void TGQt::DeleteOpenGLContext(int wd)
01336 {
01337
01338 if (!wd || (wd == -1) ) return;
01339
01340 #ifdef QtGL
01341 if (!wd)
01342 {
01343 SafeCallWin32
01344 ->W32_DeleteOpenGL();
01345 }
01346 else
01347 {
01348 SafeCallW32(((TQtSwitch *)wd))
01349 ->W32_DeleteOpenGL();
01350 }
01351 #endif
01352 }
01353
01354
01355 void TGQt::DrawBox(int x1, int y1, int x2, int y2, EBoxMode mode)
01356 {
01357
01358
01359
01360 #if QT_VERSION < 0x40000
01361 static const int Q3=1;
01362 #else
01363
01364
01365
01366
01367
01368 static const int Q3=0;
01369 #endif
01370 if (!fSelectedWindow ) return;
01371 TQtLock lock;
01372
01373
01374
01375 if (y2 > y1) {
01376
01377 int swap = y1;
01378 y1=y2; y2=swap;
01379 }
01380 if (x1 > x2) {
01381
01382 int swap = x1;
01383 x1=x2; x2=swap;
01384 }
01385 if ( (fSelectedWindow->devType() == QInternal::Widget) && fFeedBackMode && fFeedBackWidget) {
01386 fFeedBackWidget->SetGeometry(x1,y2,x2-x1,y1-y2,(TQtWidget *)fSelectedWindow);
01387 if (fFeedBackWidget->isHidden() ) fFeedBackWidget->Show();
01388 return;
01389 }
01390
01391 if ((mode == kHollow) || (fQBrush->style() == Qt::NoBrush) )
01392 {
01393 TQtPainter p(this,TQtPainter::kUpdatePen);
01394 p.setBrush(Qt::NoBrush);
01395 p.drawRect(x1,y2,x2-x1+Q3,y1-y2+Q3);
01396 } else if (fQBrush->GetColor().alpha() ) {
01397 TQtPainter p(this);
01398 if (fQBrush->style() != Qt::SolidPattern) p.setPen(fQBrush->GetColor());
01399 p.fillRect(x1,y2,x2-x1,y1-y2,*fQBrush);
01400 }
01401 }
01402
01403
01404 void TGQt::DrawCellArray(int x1, int y1, int x2, int y2, int nx, int ny, int *ic)
01405 {
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416 TQtLock lock;
01417 if (fSelectedWindow)
01418 {
01419 int i,j,icol,ix,w,h,current_icol,lh;
01420
01421 current_icol = -1;
01422 w = TMath::Max((x2-x1)/(nx),1);
01423 h = TMath::Max((y1-y2)/(ny),1);
01424 lh = y1-y2;
01425 ix = x1;
01426
01427 if (w+h == 2)
01428 {
01429
01430 TQtPainter p(this,TQtPainter::kUpdatePen);
01431 for ( i=x1; i<x1+nx; i++){
01432 for (j = 0; j<ny; j++){
01433 icol = ic[i+(nx*j)];
01434 if (current_icol != icol) {
01435 current_icol = icol;
01436 p.setPen(ColorIndex(current_icol));
01437 }
01438 p.drawPoint(i,y1-j);
01439 }
01440 }
01441 }
01442 else
01443 {
01444
01445 QRect box(x1,y1,w,h);
01446 TQtPainter p(this,TQtPainter::kNone);
01447 for ( i=0; i<nx; i++ ) {
01448 for ( j=0; j<ny; j++ ) {
01449 icol = ic[i+(nx*j)];
01450 if(icol != current_icol){
01451 current_icol = icol;
01452 p.setBrush(ColorIndex(current_icol));
01453 }
01454 p.drawRect(box);
01455 box.translate(0,-h);
01456 }
01457 box.translate(w,lh);
01458 }
01459 }
01460 }
01461 }
01462
01463
01464 void TGQt::DrawFillArea(int n, TPoint *xy)
01465 {
01466
01467
01468
01469
01470 TQtLock lock;
01471 if (fSelectedWindow && n>0)
01472 {
01473 TQtPainter p(this);
01474 if (fQBrush->style() == Qt::SolidPattern) p.setPen(Qt::NoPen);
01475 QPolygon qtPoints(n);
01476 TPoint *rootPoint = xy;
01477 for (int i =0;i<n;i++,rootPoint++) qtPoints.setPoint(i,rootPoint->fX,rootPoint->fY);
01478 p.drawPolygon(qtPoints);
01479 }
01480 }
01481
01482
01483 void TGQt::DrawLine(int x1, int y1, int x2, int y2)
01484 {
01485
01486
01487
01488
01489 TQtLock lock;
01490 if (fSelectedWindow) {
01491 TQtToggleFeedBack feedBack(this);
01492 feedBack.painter().drawLine(x1,y1,x2,y2);
01493 #if 0
01494 if (x1> 1000) {
01495
01496 qDebug() << "TGQt::DrawLine " << " x1=" << x1
01497 << " y1=" << y1
01498 << " x2=" << x2
01499 << " y2=" << y2;
01500
01501 }
01502 #endif
01503 }
01504 }
01505
01506
01507 void TGQt::DrawPolyLine(int n, TPoint *xy)
01508 {
01509
01510
01511
01512
01513 TQtLock lock;
01514 if (fSelectedWindow) {
01515 TQtToggleFeedBack feedBack(this);
01516 QPolygon qtPoints(n);
01517 TPoint *rootPoint = xy;
01518 for (int i =0;i<n;i++,rootPoint++) qtPoints.setPoint(i,rootPoint->fX,rootPoint->fY);
01519 feedBack.painter().drawPolyline(qtPoints);
01520 }
01521 }
01522
01523
01524 void TGQt::DrawPolyMarker(int n, TPoint *xy)
01525 {
01526
01527
01528
01529 TQtLock lock;
01530 if (fSelectedWindow) {
01531 TQtPainter p(this,TQtPainter::kNone);
01532 fQtMarker->DrawPolyMarker(p,n,xy);
01533 }
01534 }
01535
01536 TQtTextProxy *TGQt::TextProxy()
01537 {
01538
01539 return fgTextProxy;
01540 }
01541
01542 void TGQt::SetTextProxy(TQtTextProxy *proxy)
01543 {
01544
01545 fgTextProxy = proxy;
01546 }
01547
01548
01549 void TGQt::DrawText(int x, int y, float angle, float mgn, const char *text, TVirtualX::ETextMode )
01550 {
01551
01552
01553
01554
01555
01556
01557
01558
01559
01560
01561
01562
01563 if (text && text[0]) {
01564 TQtLock lock;
01565 fQFont->SetTextMagnify(mgn);
01566 TQtPainter p(this,TQtPainter::kUpdateFont);
01567 p.setPen(ColorIndex(fTextColor));
01568 p.setBrush(ColorIndex(fTextColor));
01569 unsigned int w=0;unsigned int h=0; unsigned int d = 0;
01570 bool textProxy = false;
01571 TQtTextCloneProxy proxy;
01572 if (fgTextProxy) {
01573 proxy->clear();
01574 QFontInfo fi(*fQFont);
01575 proxy->setBaseFontPointSize(fi.pointSize());
01576 proxy->setForegroundColor(ColorIndex(fTextColor));
01577 if ( ( textProxy = proxy->setContent(text) ) ) {
01578 w = proxy->width();
01579 h = proxy->height();
01580 }
01581 }
01582 if (!textProxy) {
01583 QFontMetrics metrics(*fQFont);
01584 QRect bRect = metrics.boundingRect(text);
01585 w = bRect.width();
01586 h = bRect.height();
01587 d = metrics.descent();
01588 }
01589 p.translate(x,y);
01590 if (TMath::Abs(angle) > 0.1 ) p.rotate(-angle);
01591 int dx =0; int dy =0;
01592
01593 switch( fTextAlignH ) {
01594 case 2: dx = -int(w/2);
01595 break;
01596 case 3: dx = -int(w);
01597 break;
01598 };
01599 switch( fTextAlignV ) {
01600 case 2: dy = h/2 - d;
01601 break;
01602 case 3: dy = h - d;
01603 };
01604 if (textProxy)
01605 proxy->paint(&p,dx,-dy);
01606 else
01607 p.drawText (dx, dy, GetTextDecoder()->toUnicode (text));
01608 }
01609 }
01610
01611
01612 void TGQt::GetCharacterUp(Float_t &chupx, Float_t &chupy)
01613 {
01614
01615
01616 TQtLock lock;
01617 chupx = fCharacterUpX;
01618 chupy = fCharacterUpY;
01619 }
01620
01621
01622 QPaintDevice *TGQt::GetDoubleBuffer(QPaintDevice *dev)
01623 {
01624
01625
01626 QPaintDevice *buffer = 0;
01627 if (dev) {
01628 TQtWidget *widget = dynamic_cast<TQtWidget *>(dev);
01629 buffer = widget && widget->IsDoubleBuffered() ? widget->SetBuffer().Buffer() : 0;
01630 }
01631 return buffer;
01632 }
01633
01634 Int_t TGQt::GetDoubleBuffer(Int_t wd)
01635 {
01636
01637
01638
01639 if (wd == -1 || wd == kDefault ) return 0;
01640 assert(0);
01641 QPaintDevice *dev = iwid(wd);
01642 TQtWidget *widget = dynamic_cast<TQtWidget *>(dev);
01643 return Int_t(widget && widget->IsDoubleBuffered());
01644 }
01645
01646
01647 void TGQt::GetGeometry(int wd, int &x, int &y, unsigned int &w, unsigned int &h)
01648 {
01649
01650 QRect devSize(0,0,0,0);
01651 if( wd == -1 || wd == 0 || wd == kDefault)
01652 {
01653 QDesktopWidget *d = QApplication::desktop();
01654 devSize.setWidth (d->width() );
01655 devSize.setHeight(d->height());
01656 } else {
01657 QPaintDevice *dev = iwid(wd);
01658 if (dev) {
01659 if ( dev->devType() == QInternal::Widget) {
01660 TQtWidget &thisWidget = *(TQtWidget *)dev;
01661 if (thisWidget.GetRootID() ) {
01662
01663 devSize = thisWidget.parentWidget()->geometry();
01664 } else{
01665 devSize = thisWidget.geometry();
01666 }
01667 devSize.moveTopLeft(thisWidget.mapToGlobal(QPoint(0,0)));
01668 } else {
01669 devSize = GetQRect(*dev);
01670 }
01671 }
01672 }
01673 x = devSize.left();
01674 y = devSize.top();
01675 w = devSize.width();
01676 h = devSize.height();
01677
01678 }
01679
01680
01681 const char *TGQt::DisplayName(const char *){ return "localhost"; }
01682
01683
01684 ULong_t TGQt::GetPixel(Color_t cindex)
01685 {
01686
01687
01688 ULong_t rootPixel = 0;
01689 const QColor &color = ColorIndex(UpdateColor(cindex));
01690 #ifdef R__WIN32
01691 rootPixel = ( color.blue () & 255 );
01692 rootPixel = (rootPixel << 8) | ( color.green() & 255 ) ;
01693 rootPixel = (rootPixel << 8) | ( color.red () & 255 );
01694 #else
01695 rootPixel = ( color.red () & 255 );
01696 rootPixel = (rootPixel << 8) | ( color.green() & 255 ) ;
01697 rootPixel = (rootPixel << 8) | ( color.blue ()& 255 );
01698 #endif
01699 return rootPixel;
01700 }
01701
01702
01703 void TGQt::GetRGB(int index, float &r, float &g, float &b)
01704 {
01705
01706 r = g = b = 0;
01707 TQtLock lock;
01708 if (fSelectedWindow != NoOperation) {
01709 qreal R,G,B;
01710 const QColor &color = *fPallete[index];
01711 color.getRgbF(&R,&G,&B);
01712 r = R; g = G; b = G;
01713 }
01714 }
01715
01716
01717 const QTextCodec *TGQt::GetTextDecoder()
01718 {
01719 static QTextCodec *fGreekCodec = 0;
01720 QTextCodec *codec = 0;
01721 if (!fCodec) {
01722 fCodec = QTextCodec::codecForName(fFontTextCode.toAscii());
01723 if (!fCodec)
01724 fCodec=QTextCodec::codecForLocale();
01725 else
01726 QTextCodec::setCodecForLocale(fCodec);
01727 }
01728 codec = fCodec;
01729 if (fTextFont/10 == 12 ) {
01730
01731 if (!fGreekCodec) {
01732 if (QString(fSymbolFontFamily).contains("Symbol")) {
01733 fGreekCodec = (fFontTextCode == "ISO8859-1") ? fCodec:
01734 QTextCodec::codecForName("ISO8859-1");
01735 } else {
01736 fGreekCodec = QTextCodec::codecForName("symbol");
01737 }
01738 }
01739 if (fGreekCodec) codec=fGreekCodec;
01740 }
01741 return codec;
01742 }
01743
01744
01745 Float_t TGQt::GetTextMagnitude(){return fTextMagnitude;}
01746
01747
01748 void TGQt::SetTextMagnitude(Float_t mgn){ fTextMagnitude = mgn;}
01749
01750
01751 void TGQt::GetTextExtent(unsigned int &w, unsigned int &h, char *mess)
01752 {
01753
01754
01755
01756
01757
01758 TQtLock lock;
01759 if (fQFont) {
01760 bool textProxy = false;
01761 if (fgTextProxy) {
01762 TQtTextCloneProxy proxy;
01763 proxy->clear();
01764 QFontInfo fi(*fQFont);
01765 proxy->setBaseFontPointSize(fi.pointSize());
01766 if ( (textProxy = proxy->setContent(mess)) ) {
01767 w = proxy->width();
01768 h = proxy->height();
01769 }
01770 }
01771 if (!textProxy) {
01772 QSize textSize = QFontMetrics(*fQFont).size(Qt::TextSingleLine,GetTextDecoder()->toUnicode(mess)) ;
01773 w = textSize.width();
01774 h = (unsigned int)(textSize.height());
01775 }
01776
01777
01778
01779 }
01780 }
01781
01782 Int_t TGQt::GetFontAscent() const
01783 {
01784
01785
01786
01787 Int_t ascent = 0;
01788 if (fQFont) {
01789 QFontMetrics fm(*fQFont);
01790 ascent = fm.ascent();
01791 }
01792 return ascent;
01793 }
01794
01795
01796 Int_t TGQt::GetFontDescent() const
01797 {
01798
01799
01800
01801 Int_t descent = 0;
01802 if (fQFont) {
01803 QFontMetrics fm(*fQFont);
01804 descent = fm.descent();
01805 }
01806 return descent;
01807 }
01808
01809
01810 Bool_t TGQt::HasTTFonts() const {return fUseTTF;}
01811
01812
01813 void TGQt::MoveWindow(Int_t wd, Int_t x, Int_t y)
01814 {
01815
01816
01817
01818
01819
01820 if (wd != -1 && wd != 0 && wd != kDefault)
01821 {
01822 QPaintDevice *widget = iwid(wd);
01823 assert(widget->devType() == QInternal::Widget );
01824 ((TQtWidget *)widget)->move(x,y);
01825 }
01826 }
01827
01828
01829 void TGQt::PutByte(Byte_t )
01830 {
01831 }
01832
01833
01834 void TGQt::QueryPointer(int &ix, int &iy)
01835 {
01836
01837
01838
01839 QPoint pos = QCursor::pos();
01840 ix = pos.x(); iy = pos.y();
01841 }
01842
01843
01844 Pixmap_t TGQt::ReadGIF(Int_t x0, Int_t y0, const char *file, Window_t id)
01845 {
01846
01847
01848
01849 Int_t thisId = 0;
01850 QPixmap *pix = new QPixmap( QString (file) );
01851 if ( pix->isNull () ) { delete pix; pix = 0; }
01852 else {
01853 thisId=fWidgetArray->GetFreeId(pix);
01854 if (!id ) { CopyPixmap(thisId,x0,y0); fWidgetArray->DeleteById(thisId); thisId = 0;}
01855 }
01856 return thisId;
01857 }
01858
01859
01860 Int_t TGQt::RequestLocator(Int_t , Int_t , Int_t &, Int_t &)
01861 {
01862
01863 return 0;
01864 }
01865
01866 class requestString : public QDialog {
01867 public:
01868 QString fText;
01869 QLineEdit fEdit;
01870 requestString(const char *text="") : QDialog(0
01871 , Qt::FramelessWindowHint
01872 | Qt::WindowStaysOnTopHint
01873 | Qt::Popup)
01874 , fText(text),fEdit(this)
01875 {
01876 setModal(true);
01877 connect(&fEdit,SIGNAL( returnPressed () ), this, SLOT( accept() ));
01878 }
01879 ~requestString(){;}
01880 };
01881
01882 Int_t TGQt::RequestString(int x, int y, char *text)
01883 {
01884
01885
01886
01887
01888
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898
01899 int res = QDialog::Rejected;
01900 if (fSelectedWindow->devType() == QInternal::Widget ) {
01901 TQtWidget *w = (TQtWidget *)fSelectedWindow;
01902 static requestString reqDialog;
01903 reqDialog.fEdit.setText(QString(text).trimmed());
01904 int yFrame = reqDialog.frameGeometry().height() - reqDialog.geometry().height() + reqDialog.fontMetrics().height();
01905 reqDialog.move(w->mapToGlobal(QPoint(x,y-yFrame)));
01906 if (QClientFilter() && QClientFilter()->PointerGrabber() ) {
01907
01908
01909 QClientFilter()->PointerGrabber()->DisactivateGrabbing();
01910 }
01911 res = reqDialog.exec();
01912 if (res == QDialog::Accepted ) {
01913
01914 Font_t textFontSave = fTextFont;
01915 fTextFont = 62;
01916 QByteArray obr = GetTextDecoder()->fromUnicode(reqDialog.fEdit.text());
01917 const char *r = obr.constData();
01918 qstrcpy(text, (const char *)r);
01919
01920 fTextFont = textFontSave;
01921 }
01922 reqDialog.hide();
01923 if (QClientFilter() && QClientFilter()->PointerGrabber()) {
01924
01925
01926 QClientFilter()->PointerGrabber()->ActivateGrabbing();
01927 }
01928 }
01929 return res == QDialog::Accepted ? 1 : 0;
01930 }
01931
01932
01933 void TGQt::RescaleWindow(int wd, UInt_t w, UInt_t h)
01934 {
01935
01936
01937
01938
01939
01940 TQtLock lock;
01941 if (wd && wd != -1 && wd != kDefault )
01942 {
01943 QPaintDevice *widget = iwid(wd);
01944 if (widget->devType() == QInternal::Widget )
01945 {
01946 if (QSize(w,h) != ((TQtWidget *)widget)->size()) {
01947
01948 ((TQtWidget *)widget)->resize(w,h);
01949 }
01950 }
01951 }
01952 }
01953
01954
01955 Int_t TGQt::ResizePixmap(int wd, UInt_t w, UInt_t h)
01956 {
01957
01958
01959
01960
01961 TQtLock lock;
01962 if (wd && wd != -1 && wd != kDefault )
01963 {
01964 QPaintDevice *pixmap = iwid(wd);
01965 if (pixmap->devType() == QInternal::Pixmap )
01966 {
01967 if (QSize(w,h) != ((QPixmap *)pixmap)->size()) {
01968 QPixmap *newpix = new QPixmap(w,h);
01969 newpix->fill();
01970 fWidgetArray->ReplaceById(wd,newpix);
01971 if (fSelectedWindow == pixmap) fSelectedWindow = newpix;
01972
01973 }
01974 }
01975 }
01976 return 1;
01977 }
01978
01979
01980 void TGQt::ResizeWindow(int )
01981 {
01982
01983
01984
01985 return;
01986 }
01987
01988
01989 void TGQt::SelectPixmap(Int_t qpixid){ SelectWindow(qpixid);}
01990
01991
01992 void TGQt::SelectWindow(int wd)
01993 {
01994
01995
01996
01997 QPaintDevice *dev = 0;
01998 if (wd == -1 || wd == (int) kNone) {
01999 fSelectedWindow = NoOperation;
02000
02001 } else {
02002 dev = iwid(wd);
02003 fSelectedWindow = dev ? dev : NoOperation;
02004 }
02005 if (fPrevWindow != fSelectedWindow)
02006 fPrevWindow = fSelectedWindow;
02007 }
02008
02009
02010 void TGQt::SetCharacterUp(Float_t chupx, Float_t chupy)
02011 {
02012
02013
02014 TQtLock lock;
02015 if (chupx == fCharacterUpX && chupy == fCharacterUpY) {
02016
02017 return;
02018 }
02019
02020 if (chupx == 0 && chupy == 0) fTextAngle = 0;
02021 else if (chupx == 0 && chupy == 1) fTextAngle = 0;
02022 else if (chupx == -1 && chupy == 0) fTextAngle = 90;
02023 else if (chupx == 0 && chupy == -1) fTextAngle = 180;
02024 else if (chupx == 1 && chupy == 0) fTextAngle = 270;
02025 else {
02026 fTextAngle = ((TMath::ACos(chupx/TMath::Sqrt(chupx*chupx +chupy*chupy))*180.)/3.14159)-90;
02027 if (chupy < 0) fTextAngle = 180 - fTextAngle;
02028 if (TMath::Abs(fTextAngle) < 0.01) fTextAngle = 0;
02029 }
02030
02031 fCharacterUpX = chupx;
02032 fCharacterUpY = chupy;
02033 }
02034
02035
02036 void TGQt::SetClipOFF(Int_t )
02037 {
02038
02039
02040
02041 }
02042
02043
02044 void TGQt::SetClipRegion(int wd, int x, int y, UInt_t w, UInt_t h)
02045 {
02046
02047
02048
02049
02050
02051 QRect rect(x,y,w,h);
02052 TQtLock lock;
02053 fClipMap.remove(iwid(wd));
02054 fClipMap.insert(iwid(wd),rect);
02055 }
02056
02057
02058 void TGQt::SetCursor(Int_t wd, ECursor cursor)
02059 {
02060
02061 fCursor = cursor;
02062 if (wd && wd != -1 && wd != kDefault)
02063 {
02064 QPaintDevice *widget = iwid(wd);
02065 if ( TQtWidget *w = (TQtWidget *)IsWidget(widget) )
02066 w->setCursor(*fCursors[fCursor]);
02067 }
02068 }
02069
02070
02071 void TGQt::SetDoubleBuffer(int wd, int mode)
02072 {
02073
02074
02075
02076
02077
02078 if (wd == -1 || wd == kDefault) return;
02079 QPaintDevice *dev = iwid(wd);
02080 TQtWidget *widget = 0;
02081 if (dev && (widget = (TQtWidget *)IsWidget(dev) )) {
02082 widget->SetDoubleBuffer(mode);
02083
02084 }
02085 }
02086
02087
02088 void TGQt::SetDrawMode(TVirtualX::EDrawMode mode)
02089 {
02090
02091
02092
02093
02094 Bool_t feedBack = (mode==kInvert);
02095 if (feedBack != fFeedBackMode) {
02096 fFeedBackMode = feedBack;
02097 if (fFeedBackMode) {
02098
02099 if (!fFeedBackWidget) {
02100 fFeedBackWidget = new TQtFeedBackWidget;
02101 fFeedBackWidget->setFrameStyle(QFrame::Box);
02102 }
02103
02104
02105
02106
02107 fFeedBackWidget->SetParent(0);
02108 fFeedBackWidget->SetParent((TQtWidget *)fSelectedWindow);
02109 } else if (fFeedBackWidget) {
02110 fFeedBackWidget->Hide();
02111 }
02112 }
02113 #if 0
02114 QPainter::CompositionMode newMode = QPainter::CompositionMode_Source;
02115 switch (mode) {
02116 case kCopy: newMode = QPainter::CompositionMode_Source; break;
02117 case kXor: newMode = QPainter::CompositionMode_Xor; break;
02118 case kInvert: newMode = QPainter::CompositionMode_Destination; break;
02119 default: newMode = QPainter::CompositionMode_Source; break;
02120 };
02121 if (newMode != fDrawMode)
02122 {
02123 fDrawMode = newMode;
02124
02125 if (fQPainter->isActive() && (fQPainter->device()->devType() == QInternal::Image ))
02126 {
02127 fQPainter->setCompositionMode(fDrawMode);
02128 }
02129
02130 }
02131 #endif
02132 }
02133
02134
02135 void TGQt::SetFillColor(Color_t cindex)
02136 {
02137
02138
02139 if (fFillColor != cindex )
02140 fQBrush->SetColor(fFillColor = UpdateColor(cindex));
02141 }
02142
02143
02144 void TGQt::SetFillStyle(Style_t fstyle)
02145 {
02146
02147
02148
02149
02150
02151
02152
02153
02154
02155 if (fFillStyle != fstyle)
02156 fQBrush->SetStyle(fFillStyle = fstyle);
02157 }
02158
02159
02160 void TGQt::SetFillStyleIndex( Int_t style, Int_t fasi )
02161 {
02162
02163
02164 SetFillStyle(1000*style + fasi);
02165 }
02166
02167
02168 void TGQt::SetLineColor(Color_t cindex)
02169 {
02170
02171
02172
02173
02174
02175 if (fLineColor != cindex) {
02176 fLineColor = UpdateColor(cindex);
02177 if (fLineColor >= 0) fQPen->SetLineColor(fLineColor);
02178 }
02179 }
02180
02181
02182 void TGQt::SetLineType(int n, int*dash)
02183 {
02184
02185
02186
02187
02188
02189
02190
02191
02192
02193
02194
02195
02196
02197
02198
02199
02200 fQPen->SetLineType(n,dash);
02201 }
02202
02203
02204 void TGQt::SetLineStyle(Style_t linestyle)
02205 {
02206
02207
02208
02209
02210
02211
02212
02213
02214
02215
02216
02217
02218
02219
02220
02221
02222 if (fLineStyle != linestyle) {
02223 fLineStyle = linestyle;
02224 fQPen->SetLineStyle(linestyle);
02225 }
02226 }
02227
02228
02229 void TGQt::SetLineWidth(Width_t width)
02230 {
02231
02232
02233
02234
02235 if (width==1) width =0;
02236 if (fLineWidth != width) {
02237 fLineWidth = width;
02238 if (fLineWidth >= 0 ) fQPen->SetLineWidth(fLineWidth);
02239 }
02240 }
02241
02242
02243 void TGQt::SetMarkerColor( Color_t cindex)
02244 {
02245
02246
02247
02248
02249
02250 if (fQtMarker->GetColor() != cindex)
02251 fQtMarker->SetColor(fMarkerColor = UpdateColor(cindex));
02252 }
02253
02254
02255 void TGQt::SetMarkerSize(Float_t markersize)
02256 {
02257
02258
02259
02260
02261
02262 if (markersize != fMarkerSize) {
02263
02264 fMarkerSize = markersize;
02265 if (markersize >= 0) {
02266 SetMarkerStyle(-fMarkerStyle);
02267 }
02268 }
02269 }
02270
02271
02272 void TGQt::SetMarkerStyle(Style_t markerstyle){
02273
02274
02275
02276 if (fMarkerStyle == markerstyle) return;
02277 TPoint shape[15];
02278 markerstyle = TMath::Abs(markerstyle);
02279 if (markerstyle%1000 >= 31) return;
02280 fMarkerStyle = markerstyle%1000;
02281 Style_t penWidth = markerstyle-fMarkerStyle;
02282 Int_t im = Int_t(4*fMarkerSize + 0.5);
02283 switch (fMarkerStyle) {
02284
02285 case 2:
02286
02287 shape[0].SetX(-im); shape[0].SetY( 0);
02288 shape[1].SetX(im); shape[1].SetY( 0);
02289 shape[2].SetX(0) ; shape[2].SetY( -im);
02290 shape[3].SetX(0) ; shape[3].SetY( im);
02291 SetMarkerType(4+penWidth,4,shape);
02292 break;
02293
02294 case 3:
02295
02296 shape[0].SetX(-im); shape[0].SetY( 0);
02297 shape[1].SetX( im); shape[1].SetY( 0);
02298 shape[2].SetX( 0); shape[2].SetY(-im);
02299 shape[3].SetX( 0); shape[3].SetY( im);
02300 im = Int_t(0.707*Float_t(im) + 0.5);
02301 shape[4].SetX(-im); shape[4].SetY(-im);
02302 shape[5].SetX( im); shape[5].SetY( im);
02303 shape[6].SetX(-im); shape[6].SetY( im);
02304 shape[7].SetX( im); shape[7].SetY(-im);
02305 SetMarkerType(4+penWidth,8,shape);
02306 break;
02307
02308 case 4:
02309 case 24:
02310
02311 SetMarkerType(0+penWidth,im*2,shape);
02312 break;
02313
02314 case 5:
02315
02316 im = Int_t(0.707*Float_t(im) + 0.5);
02317 shape[0].SetX(-im); shape[0].SetY(-im);
02318 shape[1].SetX( im); shape[1].SetY( im);
02319 shape[2].SetX(-im); shape[2].SetY( im);
02320 shape[3].SetX( im); shape[3].SetY(-im);
02321 SetMarkerType(4+penWidth,4,shape);
02322 break;
02323
02324 case 6:
02325
02326 shape[0].SetX(-1); shape[0].SetY( 0);
02327 shape[1].SetX( 1); shape[1].SetY( 0);
02328 shape[2].SetX( 0); shape[2].SetY(-1);
02329 shape[3].SetX( 0); shape[3].SetY( 1);
02330 SetMarkerType(4+penWidth,4,shape);
02331 break;
02332
02333 case 7:
02334
02335 shape[0].SetX(-1); shape[0].SetY( 1);
02336 shape[1].SetX( 1); shape[1].SetY( 1);
02337 shape[2].SetX(-1); shape[2].SetY( 0);
02338 shape[3].SetX( 1); shape[3].SetY( 0);
02339 shape[4].SetX(-1); shape[4].SetY(-1);
02340 shape[5].SetX( 1); shape[5].SetY(-1);
02341 SetMarkerType(4+penWidth,6,shape);
02342 break;
02343 case 8:
02344 case 20:
02345
02346 SetMarkerType(1,im*2,shape);
02347 break;
02348 case 21:
02349
02350 shape[0].SetX(-im); shape[0].SetY(-im);
02351 shape[1].SetX( im); shape[1].SetY(-im);
02352 shape[2].SetX( im); shape[2].SetY( im);
02353 shape[3].SetX(-im); shape[3].SetY( im);
02354
02355 SetMarkerType(3,4,shape);
02356 break;
02357 case 22:
02358
02359 shape[0].SetX(-im); shape[0].SetY( im);
02360 shape[1].SetX( im); shape[1].SetY( im);
02361 shape[2].SetX( 0); shape[2].SetY(-im);
02362
02363 SetMarkerType(3,3,shape);
02364 break;
02365 case 23:
02366
02367 shape[0].SetX( 0); shape[0].SetY( im);
02368 shape[1].SetX( im); shape[1].SetY(-im);
02369 shape[2].SetX(-im); shape[2].SetY(-im);
02370
02371 SetMarkerType(3,3,shape);
02372 break;
02373 case 25:
02374
02375 shape[0].SetX(-im); shape[0].SetY(-im);
02376 shape[1].SetX( im); shape[1].SetY(-im);
02377 shape[2].SetX( im); shape[2].SetY( im);
02378 shape[3].SetX(-im); shape[3].SetY( im);
02379
02380 SetMarkerType(2+penWidth,4,shape);
02381 break;
02382 case 26:
02383
02384 shape[0].SetX(-im); shape[0].SetY( im);
02385 shape[1].SetX( im); shape[1].SetY( im);
02386 shape[2].SetX( 0); shape[2].SetY(-im);
02387
02388 SetMarkerType(2+penWidth,3,shape);
02389 break;
02390 case 27: {
02391
02392 Int_t imx = Int_t(2.66*fMarkerSize + 0.5);
02393 shape[0].SetX(-imx); shape[0].SetY( 0);
02394 shape[1].SetX( 0); shape[1].SetY(-im);
02395 shape[2].SetX(imx); shape[2].SetY( 0);
02396 shape[3].SetX( 0); shape[3].SetY( im);
02397
02398 SetMarkerType(2+penWidth,4,shape);
02399 break;
02400 }
02401 case 28: {
02402
02403 Int_t imx = Int_t(1.33*fMarkerSize + 0.5);
02404 shape[0].SetX(-im); shape[0].SetY(-imx);
02405 shape[1].SetX(-imx); shape[1].SetY(-imx);
02406 shape[2].SetX(-imx); shape[2].SetY( -im);
02407 shape[3].SetX(imx); shape[3].SetY( -im);
02408 shape[4].SetX(imx); shape[4].SetY(-imx);
02409 shape[5].SetX( im); shape[5].SetY(-imx);
02410 shape[6].SetX( im); shape[6].SetY( imx);
02411 shape[7].SetX(imx); shape[7].SetY( imx);
02412 shape[8].SetX(imx); shape[8].SetY( im);
02413 shape[9].SetX(-imx); shape[9].SetY( im);
02414 shape[10].SetX(-imx);shape[10].SetY(imx);
02415 shape[11].SetX(-im); shape[11].SetY(imx);
02416
02417 SetMarkerType(2+penWidth,12,shape);
02418 break;
02419 }
02420 case 29: {
02421
02422 Int_t im1 = Int_t(0.66*fMarkerSize + 0.5);
02423 Int_t im2 = Int_t(2.00*fMarkerSize + 0.5);
02424 Int_t im3 = Int_t(2.66*fMarkerSize + 0.5);
02425 Int_t im4 = Int_t(1.33*fMarkerSize + 0.5);
02426 shape[0].SetX(-im); shape[0].SetY( im4);
02427 shape[1].SetX(-im2); shape[1].SetY(-im1);
02428 shape[2].SetX(-im3); shape[2].SetY( -im);
02429 shape[3].SetX( 0); shape[3].SetY(-im2);
02430 shape[4].SetX(im3); shape[4].SetY( -im);
02431 shape[5].SetX(im2); shape[5].SetY(-im1);
02432 shape[6].SetX( im); shape[6].SetY( im4);
02433 shape[7].SetX(im4); shape[7].SetY( im4);
02434 shape[8].SetX( 0); shape[8].SetY( im);
02435 shape[9].SetX(-im4); shape[9].SetY( im4);
02436
02437 SetMarkerType(3+penWidth,10,shape);
02438 break;
02439 }
02440
02441 case 30: {
02442
02443 Int_t im1 = Int_t(0.66*fMarkerSize + 0.5);
02444 Int_t im2 = Int_t(2.00*fMarkerSize + 0.5);
02445 Int_t im3 = Int_t(2.66*fMarkerSize + 0.5);
02446 Int_t im4 = Int_t(1.33*fMarkerSize + 0.5);
02447 shape[0].SetX(-im); shape[0].SetY( im4);
02448 shape[1].SetX(-im2); shape[1].SetY(-im1);
02449 shape[2].SetX(-im3); shape[2].SetY( -im);
02450 shape[3].SetX( 0); shape[3].SetY(-im2);
02451 shape[4].SetX(im3); shape[4].SetY( -im);
02452 shape[5].SetX(im2); shape[5].SetY(-im1);
02453 shape[6].SetX( im); shape[6].SetY( im4);
02454 shape[7].SetX(im4); shape[7].SetY( im4);
02455 shape[8].SetX( 0); shape[8].SetY( im);
02456 shape[9].SetX(-im4); shape[9].SetY( im4);
02457 SetMarkerType(2+penWidth,10,shape);
02458 break;
02459 }
02460
02461 case 31:
02462
02463 SetMarkerType(1,im*2,shape);
02464 break;
02465 default:
02466
02467 SetMarkerType(0+penWidth,0,shape);
02468 }
02469 }
02470
02471
02472 void TGQt::SetMarkerType( int type, int n, TPoint *xy )
02473 {
02474
02475
02476
02477
02478
02479
02480
02481
02482
02483
02484
02485
02486
02487
02488 fQtMarker->SetMarker(n,xy,type);
02489 }
02490
02491
02492 int TGQt::UpdateColor(int cindex)
02493 {
02494
02495 #define BIGGEST_RGB_VALUE 255 // 65535
02496
02497 if (cindex >= 0 ) {
02498
02499
02500 if (!fPallete.contains(cindex)) {
02501
02502 fBlockRGB = kTRUE;
02503 TColor *rootColor = gROOT->GetColor(cindex);
02504 fBlockRGB = kFALSE;
02505 if (rootColor) {
02506 float r,g,b,a;
02507 rootColor->GetRGB(r,g,b);
02508 a= rootColor->GetAlpha();
02509
02510 fPallete[cindex] = new QColor(
02511 int(r*BIGGEST_RGB_VALUE+0.5)
02512 ,int(g*BIGGEST_RGB_VALUE+0.5)
02513 ,int(b*BIGGEST_RGB_VALUE+0.5)
02514 ,int(a*BIGGEST_RGB_VALUE+0.5)
02515 );
02516 }
02517 }
02518 }
02519 return cindex;
02520 }
02521
02522 void TGQt::SetRGB(int cindex, float r, float g, float b)
02523 {
02524 #define BIGGEST_RGB_VALUE 255 // 65535
02525
02526 if ( !fBlockRGB && cindex >= 0 ) {
02527
02528
02529
02530 QMap<Color_t,QColor*>::iterator i = fPallete.find(cindex);
02531 if (i != fPallete.end()) {
02532 delete i.value();
02533 fPallete.erase(i);
02534 }
02535 fPallete[cindex] = new QColor(
02536 int(r*BIGGEST_RGB_VALUE+0.5)
02537 ,int(g*BIGGEST_RGB_VALUE+0.5)
02538 ,int(b*BIGGEST_RGB_VALUE+0.5)
02539 );
02540 }
02541 }
02542
02543 void TGQt::SetRGB(Int_t cindex, Float_t r, Float_t g, Float_t b, Float_t a)
02544 {
02545
02546 SetRGB(cindex, r, g,b);
02547 SetAlpha(cindex,a);
02548 }
02549
02550 void TGQt::SetAlpha(Int_t cindex, Float_t a)
02551 {
02552
02553 if (cindex < 0 || a < 0 ) return;
02554 QColor *color = fPallete[cindex];
02555 if (color) color->setAlphaF(a);
02556
02557 }
02558
02559 void TGQt::GetRGBA(Int_t cindex, Float_t &r, Float_t &g, Float_t &b, Float_t &a)
02560 {
02561
02562 GetRGB(cindex,r,g,b);
02563 a = GetAlpha(cindex);
02564 }
02565
02566 Float_t TGQt::GetAlpha(Int_t cindex)
02567 {
02568
02569 if (cindex < 0 ) return 1.0;
02570 const QColor *color = fPallete[cindex];
02571 return (Float_t)color->alphaF();
02572 }
02573
02574 void TGQt::SetTextAlign(Short_t talign)
02575 {
02576
02577
02578
02579
02580
02581
02582 Int_t txalh = talign/10;
02583 Int_t txalv = talign%10;
02584
02585 fTextAlignH = txalh;
02586 fTextAlignV = txalv;
02587
02588 fTextAlign = Qt::AlignLeft;
02589 switch( txalh ) {
02590
02591 case 2:
02592 fTextAlign |= Qt::AlignHCenter;
02593 break;
02594
02595 case 3:
02596 fTextAlign |= Qt::AlignRight;
02597 break;
02598
02599 default:
02600 fTextAlign |= Qt::AlignLeft;
02601 }
02602
02603 switch( txalv ) {
02604
02605 case 1:
02606 fTextAlign |= Qt::AlignBottom;
02607 break;
02608
02609 case 2:
02610 fTextAlign |= Qt::AlignVCenter;
02611 break;
02612
02613 case 3:
02614 fTextAlign |= Qt::AlignTop;
02615 break;
02616
02617 default:
02618 fTextAlign = Qt::AlignBottom;
02619 }
02620 }
02621
02622
02623 void TGQt::SetTextColor(Color_t cindex)
02624 {
02625
02626
02627
02628
02629
02630 if (fTextColor == cindex) return;
02631 fTextColor = UpdateColor(cindex);
02632 if (cindex < 0) return;
02633 }
02634
02635
02636 Int_t TGQt::SetTextFont(char* , TVirtualX::ETextSetMode )
02637 {
02638
02639
02640
02641
02642
02643
02644
02645
02646
02647
02648 return 0;
02649 }
02650
02651
02652 void TGQt::SetTextFont(Font_t fontnumber)
02653 {
02654
02655
02656
02657
02658
02659
02660
02661
02662
02663
02664
02665
02666
02667
02668
02669
02670
02671
02672
02673
02674 if ( fTextFont == fontnumber) return;
02675 fTextFont = fontnumber;
02676 if (fTextFont == -1) {
02677 fTextFontModified = 1;
02678 return;
02679 }
02680 fQFont->SetTextFont(fontnumber);
02681 fTextFontModified = 1;
02682 }
02683
02684
02685 void TGQt::SetTextSize(Float_t textsize)
02686 {
02687
02688
02689 if ( fTextSize != textsize ) {
02690 fTextSize = textsize;
02691 if (fTextSize > 0) {
02692 fQFont->SetTextSize(textsize);
02693 fTextFontModified = 1;
02694 }
02695 }
02696 }
02697
02698
02699 void TGQt::SetTitle(const char *title)
02700 {
02701
02702
02703 if (fSelectedWindow->devType() == QInternal::Widget)
02704 {
02705 ((TQtWidget *)fSelectedWindow)->topLevelWidget()-> setWindowTitle(GetTextDecoder()->toUnicode(title));
02706 }
02707 }
02708
02709
02710 void TGQt::UpdateWindow(int mode)
02711 {
02712
02713
02714
02715
02716 if (fSelectedWindow && mode != 2 ) {
02717 ((TQtWidget *)fSelectedWindow)->paintFlag();
02718 ((TQtWidget *)fSelectedWindow)->repaint();
02719 #ifndef R__WIN32
02720
02721
02722
02723
02724
02725 #endif
02726 }
02727 }
02728
02729
02730 Int_t TGQt::WriteGIF(char *name)
02731 {
02732
02733
02734
02735
02736
02737
02738
02739
02740
02741
02742
02743
02744
02745 WritePixmap(iwid(fSelectedWindow),UInt_t(-1),UInt_t(-1),name);
02746 return kTRUE;
02747 }
02748
02749
02750 void TGQt::WritePixmap(int wd, UInt_t w, UInt_t h, char *pxname)
02751 {
02752
02753
02754
02755
02756
02757
02758
02759
02760
02761
02762
02763
02764
02765 if (!wd || (wd == -1) ) return;
02766
02767 QPaintDevice &dev = *iwid(wd);
02768 QPixmap grabWidget;
02769 QPixmap *pix=0;
02770 switch (dev.devType()) {
02771 case QInternal::Widget: {
02772 TQtWidget *thisWidget = (TQtWidget*)&dev;
02773 if (thisWidget->IsDoubleBuffered() ) {
02774 pix = ((const TQtWidget*)&dev)->GetOffScreenBuffer();
02775 } else {
02776
02777
02778 grabWidget = QPixmap::grabWindow(thisWidget->winId());
02779 pix = &grabWidget;
02780 }
02781 }
02782 break;
02783
02784 case QInternal::Pixmap: {
02785 pix = (QPixmap *)&dev;
02786 break;
02787 }
02788 case QInternal::Picture:
02789 case QInternal::Printer:
02790 default: assert(0);
02791 break;
02792 };
02793 if (pix) {
02794
02795 QPixmap *finalPixmap = 0;
02796 if ( ( (h == w) && (w == UInt_t(-1) ) ) || ( QSize(w,h) == pix->size()) ) {
02797 finalPixmap = new QPixmap(*pix);
02798 } else {
02799 finalPixmap = new QPixmap(pix->scaled(w,h));
02800 }
02801
02802 QString fname = pxname;
02803 int plus = fname.indexOf("+");
02804 if (plus>=0) fname = fname.left(plus);
02805
02806
02807 QString saveType = QtFileFormat(QFileInfo(fname).suffix());
02808
02809
02810 if (saveType.isEmpty()) saveType="PNG";
02811
02812 else if (QFileInfo(fname).suffix() == "gif") {
02813
02814
02815 Int_t saver = gErrorIgnoreLevel;
02816 gErrorIgnoreLevel = kFatal;
02817 TImage *img = TImage::Create();
02818 if (img) {
02819 img->SetImage(Pixmap_t(rootwid(finalPixmap)),0);
02820 img->WriteImage(pxname,
02821 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,13,0)
02822 plus>=0 ? TImage::kAnimGif: TImage::kGif);
02823 #else
02824 TImage::kGif);
02825 #endif
02826 delete img;
02827 }
02828 gErrorIgnoreLevel = saver;
02829 } else {
02830 if (plus>=0) fname = GetNewFileName(fname);
02831 finalPixmap->save(fname,saveType.toAscii().data());
02832 }
02833 delete finalPixmap;
02834 }
02835 }
02836
02837
02838 TVirtualX *TGQt::GetVirtualX(){ return fgTQt;}
02839
02840
02841 Int_t TGQt::LoadQt(const char *shareLibFileName)
02842 {
02843
02844 return gSystem->Load(shareLibFileName);
02845 }
02846
02847
02848 Int_t TGQt::processQtEvents(Int_t maxtime)
02849 {
02850
02851 QCoreApplication::processEvents(QEventLoop::AllEvents,maxtime);
02852
02853 return 0;
02854 }