#if defined(HAVE_CONFIG) || defined (R__HAVE_CONFIG)
# include "config.h"
#endif
#ifdef R__QTWIN32
#include <process.h>
#endif
#include <assert.h>
#include <qapplication.h>
#if (QT_VERSION < 0x030200)
# include <qthread.h>
#endif
#include <qwidget.h>
#if QT_VERSION < 0x40000
# include <qptrvector.h>
# include <qvaluestack.h>
# include <qpicture.h>
#else /* QT_VERSION */
# include <QPolygon>
# include <QEvent>
# include <QImageWriter>
# include <QVector>
# include <QStack>
# include <QFrame>
# include <QPicture>
# include <QDebug>
#endif /* QT_VERSION */
#include <qpixmap.h>
#include <qcursor.h>
#include <qdesktopwidget.h>
#include <qimage.h>
#include <qfontmetrics.h>
#include <qdialog.h>
#include <qlineedit.h>
#include <qfileinfo.h>
#include <qtextcodec.h>
#include <qdir.h>
#include "TROOT.h"
#include "TMath.h"
#include "TColor.h"
#include "TEnv.h"
#include "TQtPen.h"
#include "TQtApplication.h"
#include "TQtWidget.h"
#include "TGQt.h"
#include "TQtBrush.h"
#include "TQtClientFilter.h"
#include "TQtEventQueue.h"
#include "TQtSymbolCodec.h"
#include "TQtLock.h"
#include "TQtPadFont.h"
#include "TStyle.h"
#include "TObjString.h"
#include "TObjArray.h"
#include "TSystem.h"
#ifdef R__QTWIN32
# include "TWinNTSystem.h"
# include "Win32Constants.h"
# include <Winuser.h>
#else
# ifdef R__QTX11
# include <X11/Xlib.h>
# endif
#endif
#include "TSysEvtHandler.h"
#include "TQtMarker.h"
#include "TImage.h"
#include "TError.h"
TGQt *gQt=0;
TVirtualX *TGQt::fgTQt = 0;
static QWidget *IsWidget(QPaintDevice *d)
{ return dynamic_cast<QWidget *>(d); }
static QPixmap *IsPixmap(QPaintDevice *d)
{ return dynamic_cast<QPixmap *>(d); }
QString TGQt::SetFileName(const QString &fileName)
{
QFileInfo fi(fileName);
QString saveFileMoviePattern =
fi.dirPath()+"/" + fi.baseName(TRUE)+ "_%04d" + "." + fi.extension(FALSE);
return saveFileMoviePattern;
}
QString TGQt::GetNewFileName(const QString &fileNamePrototype)
{
TString flN = (const char *)fileNamePrototype;
gSystem->ExpandPathName(flN);
QString fileName = (const char *)flN;
Int_t counter = 0;
QString formatPattern = SetFileName(fileName);
while (gSystem->AccessPathName((const char *)fileName)==0) {
fileName = QString().sprintf(formatPattern,counter++);
}
return fileName;
}
class TQtPainter : public QPainter {
protected:
bool isQWidget(QPaintDevice * dev) const {
return dev ? dev->devType() == QInternal::Widget : false;
}
public:
TQtPainter() : QPainter () {}
TQtPainter(QPaintDevice * device) : QPainter ( device ) {}
~TQtPainter () {}
void save () { if (!isQWidget(device()) && isActive()) QPainter::save(); }
void restore () { if (!isQWidget(device()) && isActive()) QPainter::restore();}
bool begin ( QPaintDevice * dev ) {return isQWidget(dev) ? false : QPainter::begin(dev);}
};
class TQtFeedBackWidget : public QFrame {
#ifdef R__WIN32
QPixmap *fPixBuffer;
#else
QImage *fPixBuffer;
#endif
bool fFirst;
QPixmap *fGrabBuffer;
protected:
virtual void paintEvent(QPaintEvent *event) {
if (fPixBuffer) {
QRect rect = event->rect();
{
QPainter p(this);
p.setClipRect(rect);
#ifdef R__WIN32
p.drawPixmap(0,0,*fPixBuffer);
#else
p.drawImage(0,0,*fPixBuffer);
#endif
}
ClearBuffer();
} else if (fGrabBuffer) {
QRect rect = event->rect();
QPainter p(this);
p.setClipRect(rect);
p.drawPixmap(rect,*fGrabBuffer);
}
QFrame::paintEvent(event);
}
public:
TQtFeedBackWidget(QWidget *parent=0, Qt::WindowFlags f=0) : QFrame(parent,f)
,fPixBuffer(0),fFirst(true),fGrabBuffer(0)
{
setAttribute(Qt::WA_NoSystemBackground);
setDisabled(true);
setBackgroundRole(QPalette::Window);
setAutoFillBackground(false);
QPalette p = palette();
p.setBrush(QPalette::Window, Qt::transparent);
setPalette(p);
}
virtual ~TQtFeedBackWidget()
{
delete fPixBuffer; fPixBuffer = 0;
delete fGrabBuffer; fGrabBuffer = 0;
}
void hide() {
delete fPixBuffer; fPixBuffer = 0;
delete fGrabBuffer; fGrabBuffer = 0;
QFrame::hide();
}
QPaintDevice *PixBuffer() {
QWidget *canvasWidget = parentWidget();
if (canvasWidget ) {
QSize canvasSize = canvasWidget->size();
setGeometry(QRect(QPoint(0,0),canvasSize));
if ( !fPixBuffer || (fPixBuffer->size() != canvasSize) ) {
delete fPixBuffer;
#ifdef R__WIN32
fPixBuffer = new QPixmap(canvasSize);
#else
fPixBuffer = new QImage(canvasSize,QImage::Format_ARGB32_Premultiplied);
#endif
ClearBuffer();
}
}
return fPixBuffer;
}
QPaintDevice *GrabBuffer(QSize &s) {
QWidget *canvasWidget = parentWidget();
if (canvasWidget ) {
if ( !fPixBuffer || (fPixBuffer->size() != s) ) {
delete fPixBuffer;
#ifdef R__WIN32
fPixBuffer = new QPixmap(s);
#else
fPixBuffer = new QImage(s,QImage::Format_ARGB32_Premultiplied);
#endif
ClearBuffer();
}
}
return fPixBuffer;
}
void ClearBuffer() {
#ifdef R__WIN32
fPixBuffer->fill(Qt::transparent);
#else
fPixBuffer->fill(0);
fFirst = true;
#endif
}
void SetGeometry(int x,int y, int w, int h, TQtWidget *src=0)
{
if (isHidden() && src ) {
delete fGrabBuffer; fGrabBuffer = 0;
QPixmap *canvas = src->GetOffScreenBuffer();
if (canvas && w > 4 && h > 4 ) {
fGrabBuffer = new QPixmap(canvas->copy(x,y,w,h));
}
}
setGeometry(x,y,w,h);
}
#ifndef R__WIN32
bool IsFirst() {
bool c = fFirst;
fFirst = false;
return c;
}
#endif
};
class TQtToggleFeedBack {
TGQt *fGQt;
TQtPainter fFeedBackPainter;
TQtPainter *fSavePainter;
public:
TQtToggleFeedBack(TGQt *gqt) : fGQt(gqt), fSavePainter(0)
{
if (fGQt->fFeedBackMode) {
fSavePainter = fGQt->fQPainter;
fGQt->fQPainter = &fFeedBackPainter;
fFeedBackPainter.begin(fGQt->fFeedBackWidget->PixBuffer());
#ifndef R__WIN32
if (!fGQt->fFeedBackWidget->IsFirst() )
fFeedBackPainter.setCompositionMode(QPainter::CompositionMode_Xor);
#endif
fFeedBackPainter.setPen(QColor(128,128,128,128));
fGQt->fFeedBackWidget->show();
}
}
~TQtToggleFeedBack()
{
if (fSavePainter) {
fFeedBackPainter.end();
fGQt->fQPainter = fSavePainter;
fGQt->fFeedBackWidget->update();
#ifndef R__WIN32
#endif
}
}
};
class TQtEventInputHandler : public TTimer {
protected:
TQtEventInputHandler() : TTimer(340) { }
static TQtEventInputHandler *gfQtEventInputHandler;
public:
static TQtEventInputHandler *Instance() {
if (!gfQtEventInputHandler)
gfQtEventInputHandler = new TQtEventInputHandler();
gfQtEventInputHandler->Start(240);
return gfQtEventInputHandler;
}
Bool_t Notify() {
Timeout();
Bool_t ret = gQt->processQtEvents();
Start(240);
Reset();
return ret;
}
Bool_t ReadNotify() { return Notify(); }
};
TQtEventInputHandler *TQtEventInputHandler::gfQtEventInputHandler = 0;
class TQWidgetCollection {
private:
#if QT_VERSION < 0x40000
QValueStack<int> fFreeWindowsIdStack;
QPtrVector<QPaintDevice> fWidgetCollection;
#else /* QT_VERSION */
QStack<int> fFreeWindowsIdStack;
QVector<QPaintDevice *> fWidgetCollection;
#endif /* QT_VERSION */
Int_t fIDMax;
Int_t fIDTotalMax;
protected:
inline Int_t SetMaxId(Int_t newId)
{
fIDMax = newId;
if (newId>fIDTotalMax) {
fIDTotalMax = newId;
#if QT_VERSION >= 0x40000
fWidgetCollection.resize(fIDTotalMax+1);
#endif
}
return fIDMax;
}
public:
TQWidgetCollection () : fIDMax(-1), fIDTotalMax(-1)
{
int kDefault = 1;
assert(!kNone);
#if QT_VERSION < 0x40000
fWidgetCollection.resize(20);
#endif
SetMaxId (kDefault);
#if QT_VERSION < 0x40000
fWidgetCollection.insert(kNone,(QPaintDevice*)0);
fWidgetCollection.insert(kDefault,(QPaintDevice *)QApplication::desktop());
#else
fWidgetCollection[kNone] = (QPaintDevice*)0;
fWidgetCollection[kDefault] = (QPaintDevice *)QApplication::desktop();
#endif
}
inline Int_t GetFreeId(QPaintDevice *device) {
Int_t Id = 0;
if (!fFreeWindowsIdStack.isEmpty() ) {
Id = fFreeWindowsIdStack.pop();
if (Id > fIDMax ) SetMaxId ( Id );
} else {
Id = fWidgetCollection.count();
assert(fIDMax <= Id );
SetMaxId ( Id );
}
fWidgetCollection[Id] = device;
return Id;
}
inline Int_t RemoveByPointer(QPaintDevice *device)
{
Int_t intWid = kNone;
if ((ULong_t) device != (ULong_t) -1) {
intWid = find( device);
if ( intWid != -1 &&
fWidgetCollection[intWid]) {
fWidgetCollection[intWid] = (QPaintDevice *)(-1);
fFreeWindowsIdStack.push(intWid);
if (fIDMax == intWid) SetMaxId(--fIDMax);
} else {
intWid = kNone;
}
}
return intWid;
}
inline const QPaintDevice *DeleteById(Int_t Id)
{
QPaintDevice *device = fWidgetCollection[Id];
if (device) {
delete device;
fWidgetCollection[Id] = (QPaintDevice *)(-1);
fFreeWindowsIdStack.push(Id);
if (fIDMax == Id) SetMaxId(--fIDMax);
}
return device;
}
inline uint count() const { return fWidgetCollection.count();}
inline uint MaxId() const { return fIDMax;}
inline uint MaxTotalId() const { return fIDTotalMax;}
inline int find(const QPaintDevice *device, uint i=0) const
{
return fWidgetCollection.indexOf((QPaintDevice*)device,i);
}
inline QPaintDevice *operator[](int i) const {return fWidgetCollection[i];}
};
TQWidgetCollection *fWidgetArray = 0;
QPaintDevice *TGQt::iwid(Window_t wid)
{
QPaintDevice *topDevice = 0;
if ( wid != kNone ) {
topDevice = (wid == kDefault) ?
(QPaintDevice *)QApplication::desktop()
:
(QPaintDevice*)wid;
}
return topDevice;
}
Int_t TGQt::iwid(QPaintDevice *wid)
{
Int_t intWid = kNone;
if ((ULong_t) wid == (ULong_t) -1) intWid = -1;
else {
intWid = fWidgetArray->find(wid);
assert(intWid != -1);
}
return intWid;
}
QPaintDevice *TGQt::iwid(Int_t wid)
{
QPaintDevice *topDevice = 0;
if (0 <= wid && wid <= int(fWidgetArray->MaxId()) )
topDevice = (*fWidgetArray)[wid];
if (topDevice == (QPaintDevice *)(-1) ) topDevice = 0;
else {
assert(wid <= Int_t(fWidgetArray->MaxTotalId()));
}
return topDevice;
}
QWidget *TGQt::winid(Window_t id)
{
return (id != kNone)? TGQt::wid(id)->topLevelWidget():0;
}
Window_t TGQt::wid(TQtClientWidget *widget)
{
return rootwid(widget);
}
Window_t TGQt::rootwid(QPaintDevice *dev)
{
return Window_t(dev);
}
QWidget *TGQt::wid(Window_t id)
{
QPaintDevice *dev = 0;
if (id == (Window_t)kNone || id == (Window_t)(-1) ) return (QWidget *)dev;
if ( id <= fWidgetArray->MaxId() )
dev = (*fWidgetArray)[id];
else
dev = (QPaintDevice *)id;
#if 0
if ( dev->devType() != QInternal::Widget) {
fprintf(stderr," %s %i type=%d QInternal::Widget = %d id =%x id = %d\n", "TGQt::wid", __LINE__
, dev->devType()
, QInternal::Widget, id, id );
}
#endif
assert(dev->devType() == QInternal::Widget);
return (QWidget *)dev;
}
void TGQt::PrintEvent(Event_t &ev)
{
fprintf(stderr,"----- Window %p %s\n", TGQt::wid(ev.fWindow),(const char *)TGQt::wid(ev.fWindow)->name());
fprintf(stderr,"event type = %x, key or button code %d \n", ev.fType, ev.fCode);
fprintf(stderr,"fX, fY, fXRoot, fYRoot = %d %d :: %d %d\n", ev.fX, ev.fY,ev.fXRoot, ev.fYRoot);
}
int TGQt::fgCoinFlag = 0;
int TGQt::fgCoinLoaded = 0;
int TGQt::CoinFlag()
{
TQtLock lock;
int ret = fgCoinFlag;
return ret;
}
void TGQt::SetCoinFlag(int flag)
{
TQtLock lock;
fgCoinFlag=flag;
}
void TGQt::SetCoinLoaded() { fgCoinLoaded = 1; }
Int_t TGQt::IsCoinLoaded(){ return fgCoinLoaded;}
#if ROOT_VERSION_CODE < ROOT_VERSION(5,13,0)
QPixmap *TGQt::MakeIcon(Int_t i)
{
QPixmap *tempIcon = NULL;
if (i) { }
#ifdef R__QTWIN32
HICON largeIcon[1];
HICON smallIcon[1];
HICON icon = ((TWinNTSystem *)gSystem)->GetNormalIcon(i);
#if 0
int numIcons = ::ExtractIconEx(
"c:\winnt\explorer.exe",
0,
largeIcon,
smallIcon,
1);
if (numIcons > 0)
{
#endif
tempIcon =new QPixmap (GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON));
HDC dc = tempIcon->handle();
DrawIcon (dc, 0, 0, icon);
#else
# ifdef ROOTICONPATH
gSystem->ExpandPathName(ROOTICONPATH);
# else
gSystem->ExpandPathName("$ROOTSYS/icons/");
# endif
#endif
return tempIcon;
}
#endif
#define NoOperation (QPaintDevice *)(-1)
ClassImp(TGQt)
QString TGQt::RootFileFormat(const char *selector)
{ return RootFileFormat(QString(selector)); }
QString TGQt::RootFileFormat(const QString &selector)
{
QString saveType;
QString defExtension[] = {"cpp","cxx","eps","svg","root","pdf","ps","xml"
#if ROOT_VERSION_CODE >= ROOT_VERSION(5,13,0)
,"gif"
#endif
,"C"};
UInt_t nExt = sizeof(defExtension)/sizeof(const char *);
UInt_t i = 0;
for (i=0; i < nExt; i++) {
if (selector.contains(defExtension[i], Qt::CaseSensitive)) {
saveType = defExtension[i];
break;
}
}
if (saveType.contains("C",FALSE)) saveType= "cxx";
return saveType;
}
QString TGQt::QtFileFormat(const char *selector)
{ return QtFileFormat(QString(selector)); }
QString TGQt::QtFileFormat(const QString &selector)
{
QString saveType="PNG";
if (!selector.isEmpty()) {
QList<QByteArray> formats = QImageWriter::supportedImageFormats();
QList<QByteArray>::const_iterator j;
for (j = formats.constBegin(); j != formats.constEnd(); ++j)
{
QString nextFormat = *j;
QString checkString = selector.contains("jpg",FALSE) ? "JPEG" : selector;
if (checkString.contains(nextFormat,FALSE) ) {
saveType = nextFormat;
break;
}
}
}
return saveType;
}
TQtApplication *TGQt::CreateQtApplicationImp()
{
static TQtApplication *app = 0;
if (!app) {
static TString argvString (
#ifdef ROOTBINDIR
ROOTBINDIR "/root.exe"
#else
"$ROOTSYS/bin/root.exe"
#endif
);
gSystem->ExpandPathName(argvString);
static char *argv[] = {(char *)argvString.Data()};
static int nArg = 1;
app = new TQtApplication("Qt",nArg,argv);
}
return app;
}
void TGQt::PostQtEvent(QObject *receiver, QEvent *event)
{
QApplication::postEvent(receiver,event);
}
TGQt::TGQt() : TVirtualX(),fDisplayOpened(kFALSE),fQPainter(0),fQClientFilterBuffer(0)
,fCodec(0),fSymbolFontFamily("Symbol"),fQtEventHasBeenProcessed(0)
,fFeedBackMode(kFALSE),fFeedBackWidget(0)
{
assert(!fgTQt);
fgTQt = this;
gQt = this;
fSelectedWindow = fPrevWindow = NoOperation;
}
TGQt::TGQt(const char *name, const char *title) : TVirtualX(name,title),fDisplayOpened(kFALSE)
,fQPainter(0),fCursors(kNumCursors),fQClientFilter(0),fQClientFilterBuffer(0),fPointerGrabber(0)
,fCodec(0),fSymbolFontFamily("Symbol"),fQtEventHasBeenProcessed(0)
,fFeedBackMode(kFALSE),fFeedBackWidget(0)
{
assert(!fgTQt);
fgTQt = this;
gQt = this;
fSelectedWindow = fPrevWindow = NoOperation;
CreateQtApplicationImp();
Init();
}
TGQt::~TGQt()
{
{
TQtLock lock;
gVirtualX = gGXBatch;
gROOT->SetBatch();
QMap<Color_t,QColor*>::const_iterator it;
for (it = fPallete.begin();it !=fPallete.end();++it) {
QColor *c = *it; delete c;
}
qDeleteAll(fCursors.begin(), fCursors.end());
delete fQClientFilter;
delete fQClientFilterBuffer;
delete fQPainter; fQPainter = 0;
}
TQtApplication::Terminate();
}
Bool_t TGQt::Init(void* )
{
fprintf(stderr,"** $Id: TGQt.cxx 26689 2008-12-06 07:03:04Z brun $ this=%p\n",this);
#if QT_VERSION >= 0x40000
#ifndef R__QTWIN32
extern void qt_x11_set_global_double_buffer(bool);
#endif
#endif
if(fDisplayOpened) return fDisplayOpened;
fSelectedWindow = fPrevWindow = NoOperation;
fTextAlignH = 1;
fTextAlignV = 1;
fTextMagnitude = 1;
fCharacterUpX = 1;
fCharacterUpY = 1;
#if QT_VERSION < 0x40000
fDrawMode = Qt::CopyROP;
#else /* QT_VERSION */
fDrawMode = QPainter::CompositionMode_Source;
#endif /* QT_VERSION */
fTextFontModified = 0;
fTextAlign = 0;
fTextSize = -1;
fTextFont = -1;
fLineWidth = -1;
fFillColor = -1;
fLineColor = -1;
fLineStyle = -1;
fMarkerSize = -1;
fMarkerStyle = -1;
#if QT_VERSION < 0x40000
fCursors.setAutoDelete(true);
fCursors.insert(kBottomLeft, new QCursor(Qt::SizeBDiagCursor));
fCursors.insert(kBottomRight,new QCursor(Qt::SizeFDiagCursor));
fCursors.insert(kTopLeft, new QCursor(Qt::SizeFDiagCursor));
fCursors.insert(kTopRight, new QCursor(Qt::SizeBDiagCursor));
fCursors.insert(kBottomSide, new QCursor(Qt::SizeVerCursor));
fCursors.insert(kLeftSide, new QCursor(Qt::SizeHorCursor));
fCursors.insert(kTopSide, new QCursor(Qt::SizeVerCursor));
fCursors.insert(kRightSide, new QCursor(Qt::SizeHorCursor));
fCursors.insert(kMove, new QCursor(Qt::SizeAllCursor));
fCursors.insert(kCross, new QCursor(Qt::CrossCursor));
fCursors.insert(kArrowHor, new QCursor(Qt::SizeHorCursor));
fCursors.insert(kArrowVer, new QCursor(Qt::SizeVerCursor));
fCursors.insert(kHand, new QCursor(Qt::PointingHandCursor));
fCursors.insert(kRotate, new QCursor(Qt::ForbiddenCursor));
fCursors.insert(kPointer, new QCursor(Qt::ArrowCursor));
fCursors.insert(kArrowRight, new QCursor(Qt::UpArrowCursor));
#if QT_VERSION < 0x40000
fCursors.insert(kCaret, new QCursor(Qt::IbeamCursor));
#else /* QT_VERSION */
fCursors.insert(kCaret, new QCursor(Qt::IBeamCursor));
#endif /* QT_VERSION */
fCursors.insert(kWatch, new QCursor(Qt::WaitCursor));
#else
fCursors[kBottomLeft] = new QCursor(Qt::SizeBDiagCursor);
fCursors[kBottomRight] = new QCursor(Qt::SizeFDiagCursor);
fCursors[kTopLeft] = new QCursor(Qt::SizeFDiagCursor);
fCursors[kTopRight] = new QCursor(Qt::SizeBDiagCursor);
fCursors[kBottomSide] = new QCursor(Qt::SizeVerCursor);
fCursors[kLeftSide] = new QCursor(Qt::SizeHorCursor);
fCursors[kTopSide] = new QCursor(Qt::SizeVerCursor);
fCursors[kRightSide] = new QCursor(Qt::SizeHorCursor);
fCursors[kMove] = new QCursor(Qt::SizeAllCursor);
fCursors[kCross] = new QCursor(Qt::CrossCursor);
fCursors[kArrowHor] = new QCursor(Qt::SizeHorCursor);
fCursors[kArrowVer] = new QCursor(Qt::SizeVerCursor);
fCursors[kHand] = new QCursor(Qt::PointingHandCursor);
fCursors[kRotate] = new QCursor(Qt::ForbiddenCursor);
fCursors[kPointer] = new QCursor(Qt::ArrowCursor);
fCursors[kArrowRight] = new QCursor(Qt::UpArrowCursor);
fCursors[kCaret] = new QCursor(Qt::IBeamCursor);
fCursors[kWatch] = new QCursor(Qt::WaitCursor);
#endif
fCursor = kCross;
fQPen = new TQtPen;
fQBrush = new TQtBrush;
fQtMarker = new TQtMarker;
fQFont = new TQtPadFont();
fQClientFilter = new TQtClientFilter();
fFontTextCode = "ISO8859-1";
const char *default_font =
gEnv->GetValue("Gui.DefaultFont", "-adobe-helvetica-medium-r-*-*-12-*-*-*-*-*-iso8859-1");
QApplication::setFont(*(QFont *)LoadQueryFont(default_font));
QString fontName(default_font);
fFontTextCode = fontName.section('-',13).upper();
if ( fFontTextCode.isEmpty() ) fFontTextCode = "ISO8859-5";
#ifndef R__QTWIN32
QFontDatabase fdb;
QStringList families = fdb.families();
Bool_t symbolFontFound = kFALSE;
Bool_t isXdfSupport = !gSystem->Getenv("QT_X11_NO_FONTCONFIG");
for ( QStringList::Iterator f = families.begin(); f != families.end(); ++f ) {
if ( (isXdfSupport && (*f).contains(fSymbolFontFamily)
&& fdb.writingSystems(*f).contains(QFontDatabase::Symbol)
) || (!isXdfSupport && ((*f) == fSymbolFontFamily)) )
{
symbolFontFound = kTRUE;
fSymbolFontFamily = *f;
TQtPadFont::SetSymbolFontFamily(*f);
qDebug() << "Symbol font family found:" << fSymbolFontFamily;
break;
}
}
if (isXdfSupport && !symbolFontFound) {
QString fontdir =
#ifdef TTFFONTDIR
TTFFONTDIR
#else
"$ROOOTSYS/fonts"
#endif
;
QString symbolFontFile = fontdir + "/" + QString(fSymbolFontFamily).toLower() + ".ttf";
symbolFontFound = QFontDatabase::addApplicationFont(symbolFontFile);
}
if (!symbolFontFound) {
fprintf(stderr, "The font \"symbol.ttf\" was not installed yet\n");
fSymbolFontFamily = "Arial";
fprintf(stderr, " Substitute it with \"%s\"\n",fSymbolFontFamily);
fprintf(stderr, " Make sure your local \"~/.fonts.conf\" or \"/etc/fonts/fonts.conf\" file points to \""
#ifdef TTFFONTDIR
TTFFONTDIR
#else
"$ROOOTSYS/fonts"
#endif
"\" directory to get the proper support for ROOT TLatex class\n");
new QSymbolCodec();
}
#endif
fWidgetArray = new TQWidgetCollection();
fDisplayOpened = kTRUE;
TQtEventInputHandler::Instance();
if (gSystem->Getenv("QTDIR")) {
TString qtdir = "$(QTDIR)/include/";
gSystem->ExpandPathName(qtdir);
TString testQtHeader = qtdir + "Qt/qglobal.h";
if (!gSystem->AccessPathName((const char *)testQtHeader) ) {
void *qtdirHandle = gSystem->OpenDirectory(qtdir);
if (qtdirHandle) {
TString incpath = " -I"; incpath+=qtdir;
while(const char *nextQtInclude = gSystem->GetDirEntry(qtdirHandle)) {
if (nextQtInclude[0] != '.') {
incpath += " -I"; incpath+=qtdir; incpath+=nextQtInclude;
}
}
gSystem->FreeDirectory(qtdirHandle);
gSystem->AddIncludePath((const char*)incpath);
}
#ifdef R__WIN32
QString libPath = gSystem->GetLinkedLibs();
TString qtlibdir= "$(QTDIR)";
qtlibdir += QDir::separator().toAscii();
qtlibdir += "lib";
gSystem->ExpandPathName(qtlibdir);
QDir qtdir((const char*)qtlibdir);
if (qtdir.isReadable ()) {
QStringList qtLibFile = qtdir.entryList("Q*4.lib",QDir::Files);
QStringListIterator libFiles(qtLibFile);
if (libFiles.hasNext()) {
libPath += " -LIBPATH:\"";libPath += qtlibdir; libPath += "\" ";
#if 0
while (libFiles.hasNext()) {
QString nf = libFiles.next();
if (nf.contains("d4")) continue;
libPath += nf.toLocal8Bit().constData();
libPath += " ";
}
#else
libPath += "QtCore4.lib QtGui4.lib QtOpenGL4.lib Qt3Support4.lib";
#endif
gSystem->SetLinkedLibs((const char*)libPath);
}
} else {
qWarning(" Can not open the QTDIR %s",(const char*)qtlibdir);
}
#endif
}
}
TString newPath =
# ifdef CINTINCDIR
CINTINCDIR
# else
"$(ROOTSYS)/cint/"
# endif
; newPath += "include";
#ifndef R__WIN32
newPath += ":";
#else
newPath += ";";
#endif
newPath += gSystem->GetDynamicPath();
gSystem->SetDynamicPath(newPath.Data());
return fDisplayOpened;
}
Int_t TGQt::CreatROOTThread()
{
return 0;
}
Int_t TGQt::RegisterWid(QPaintDevice *wid)
{
Int_t id = fWidgetArray->find(wid);
if (id == -1) id = fWidgetArray->GetFreeId(wid);
return id;
}
Int_t TGQt::UnRegisterWid(QPaintDevice *wid)
{
return fWidgetArray->RemoveByPointer(wid);
}
Bool_t TGQt::IsRegistered(QPaintDevice *wid)
{
return fWidgetArray->find(wid) == -1 ? kFALSE : kTRUE;
}
Int_t TGQt::InitWindow(ULong_t window)
{
TQtWidget *wid = 0;
QWidget *parent = 0;
if (window <= fWidgetArray->MaxId() )
parent = dynamic_cast<TQtWidget *> (iwid(int (window)));
else {
QPaintDevice *dev = dynamic_cast<QPaintDevice *>(iwid(Window_t(window)));
parent = dynamic_cast<QWidget *>(dev);
}
wid = new TQtWidget(parent,"virtualx",Qt::WStyle_NoBorder,FALSE);
wid->setCursor(*fCursors[kCross]);
Int_t id = fWidgetArray->GetFreeId(wid);
wid->SetDoubleBuffer(1);
return id;
}
Int_t TGQt::OpenPixmap(UInt_t w, UInt_t h)
{
QPixmap *obj = new QPixmap(w,h);
return fWidgetArray->GetFreeId(obj);
}
const QColor &TGQt::ColorIndex(Color_t ic) const
{
QColor *colorBuffer=0;
static QColor unknownColor;
if (!fPallete.contains(ic)) {
TColor *myColor = gROOT->GetColor(ic);
if (myColor) {
((TGQt *)this)->SetRGB(ic,myColor->GetRed()
,myColor->GetGreen()
,myColor->GetBlue()
,myColor->GetAlpha()
);
} else {
Warning("ColorIndex","Unknown color. No RGB component for the index %d was defined\n",ic);
return unknownColor;
}
}
colorBuffer = fPallete[ic];
return *colorBuffer;
}
UInt_t TGQt::ExecCommand(TGWin32Command* )
{
fprintf(stderr,"** Error **: TGQt::ExecCommand no implementation\n");
return 0;
}
void TGQt::SetDoubleBufferOFF()
{
fprintf(stderr,"** Error **: TGQt::SetDoubleBufferOFF no implementation\n");
}
void TGQt::SetDoubleBufferON()
{
fprintf(stderr,"** Error **: TGQt::SetDoubleBufferON no implementation\n");
}
void TGQt::GetPlanes(Int_t &nplanes){
nplanes = QPixmap::defaultDepth();
}
void TGQt::ClearWindow()
{
if (fSelectedWindow && fSelectedWindow != NoOperation)
{
if (IsWidget(fSelectedWindow)) {
End();
((TQtWidget *)fSelectedWindow)->Erase();
Begin();
} else if (IsPixmap(fSelectedWindow) ) {
End();
# ifdef R__WIN32
((QPixmap *)fSelectedWindow)->fill(fQBrush->color());
# else
{ QPainter p(fSelectedWindow);
p.fillRect(GetQRect(*fSelectedWindow),*fQBrush);
}
# endif
Begin();
} else {
fQPainter->eraseRect(GetQRect(*fSelectedWindow));
}
}
}
void TGQt::ClosePixmap()
{
DeleteSelectedObj();
}
void TGQt::CloseWindow()
{
DeleteSelectedObj();
}
void TGQt::DeleteSelectedObj()
{
End();
if (fSelectedWindow->devType() == QInternal::Widget) {
TQtWidget *canvasWidget = dynamic_cast<TQtWidget *>(fSelectedWindow);
if (canvasWidget) {
canvasWidget->ResetCanvas();
}
QWidget *wrapper = 0;
if (canvasWidget && (wrapper=canvasWidget->GetRootID())) {
wrapper->hide();
DestroyWindow(rootwid(wrapper) );
} else {
if(UnRegisterWid(fSelectedWindow) != (Int_t) kNone) {
((QWidget *)fSelectedWindow)->hide();
((QWidget *)fSelectedWindow)->close(true);
}
}
} else {
UnRegisterWid(fSelectedWindow);
delete fSelectedWindow;
}
fSelectedWindow = 0;
fPrevWindow = 0;
}
QRect TGQt::GetQRect(QPaintDevice &dev)
{
QRect res(0,0,0,0);
switch (dev.devType() ) {
case QInternal::Widget:
res = ((TQtWidget*)&dev)->rect();
break;
default:
res.setSize(QSize(dev.width(),dev.height()));
break;
};
return res;
}
void TGQt::CopyPixmap(int wid, int xpos, int ypos)
{
if (!wid || (wid == -1) ) return;
QPaintDevice *dev = iwid(wid);
assert(dev->devType() == QInternal::Pixmap);
QPixmap *src = (QPixmap *)dev;
if (fSelectedWindow )
{
QPaintDevice *dst = fSelectedWindow;
if (dst == (QPaintDevice *)-1) {
Error("TGQt::CopyPixmap","Wrong TGuiFactory implementation was provided. Please, check your plugin settings");
assert(dst != (QPaintDevice *)-1);
}
End();
TQtWidget *theWidget = (TQtWidget *)fSelectedWindow;
dst = theWidget->GetOffScreenBuffer();
{
QPainter paint(dst);
paint.drawPixmap(xpos,ypos,*src);
}
Emitter()->EmitPadPainted(src);
if ( fSelectedWindow->devType() == QInternal::Widget )
{ theWidget->EmitCanvasPainted(); }
}
Begin();
}
void TGQt::CopyPixmap(const QPixmap &src, Int_t xpos, Int_t ypos)
{
if (fSelectedWindow )
{
QPaintDevice *dst = fSelectedWindow;
bool isPainted = dst->paintingActive ();
if (isPainted) End();
{ QPainter paint(dst); paint.drawPixmap(xpos,ypos,src); }
if (isPainted) Begin();
}
}
void TGQt::CreateOpenGLContext(int wid)
{
if (!wid || (wid == -1) ) return;
#ifdef QtGL
if (!wid)
{
SafeCallWin32
->W32_CreateOpenGL();
}
else
{
SafeCallW32(((TQtSwitch *)wid))
->W32_CreateOpenGL();
}
#endif
}
void TGQt::DeleteOpenGLContext(int wid)
{
if (!wid || (wid == -1) ) return;
#ifdef QtGL
if (!wid)
{
SafeCallWin32
->W32_DeleteOpenGL();
}
else
{
SafeCallW32(((TQtSwitch *)wid))
->W32_DeleteOpenGL();
}
#endif
}
void TGQt::DrawBox(int x1, int y1, int x2, int y2, EBoxMode mode)
{
#if QT_VERSION < 0x40000
static const int Q3=1;
#else
static const int Q3=0;
#endif
TQtLock lock;
if ( (fSelectedWindow->devType() == QInternal::Widget) && fFeedBackMode && fFeedBackWidget) {
fFeedBackWidget->SetGeometry(x1,y2,x2-x1,y1-y2,(TQtWidget *)fSelectedWindow);
if (fFeedBackWidget->isHidden() ) fFeedBackWidget->show();
return;
}
if (fSelectedWindow )
{
fQPainter->save();
if ((mode == kHollow) || (fQBrush->style() == Qt::NoBrush) )
{
fQPainter->setBrush(Qt::NoBrush);
fQPainter->drawRect(x1,y2,x2-x1+Q3,y1-y2+Q3);
} else {
if (fQBrush->style() != Qt::SolidPattern) fQPainter->setPen(fQBrush->GetColor());
fQPainter->fillRect(x1,y2,x2-x1+1,y1-y2+1,*fQBrush);
}
fQPainter->restore();
}
}
void TGQt::DrawCellArray(int x1, int y1, int x2, int y2, int nx, int ny, int *ic)
{
TQtLock lock;
if (fSelectedWindow)
{
fQPainter->save();
int i,j,icol,ix,w,h,current_icol,lh;
current_icol = -1;
w = TMath::Max((x2-x1)/(nx),1);
h = TMath::Max((y1-y2)/(ny),1);
lh = y1-y2;
ix = x1;
if (w+h == 2)
{
for ( i=x1; i<x1+nx; i++){
for (j = 0; j<ny; j++){
icol = ic[i+(nx*j)];
if (current_icol != icol) {
current_icol = icol;
fQPainter->setPen(ColorIndex(current_icol));
}
fQPainter->drawPoint(i,y1-j);
}
}
}
else
{
QRect box(x1,y1,w,h);
for ( i=0; i<nx; i++ ) {
for ( j=0; j<ny; j++ ) {
icol = ic[i+(nx*j)];
if(icol != current_icol){
current_icol = icol;
fQPainter->setBrush(ColorIndex(current_icol));
}
fQPainter->drawRect(box);
box.moveBy(0,-h);
}
box.moveBy(w,lh);
}
}
fQPainter->restore();
}
}
void TGQt::DrawFillArea(int n, TPoint *xy)
{
TQtLock lock;
if (fSelectedWindow && n>0)
{
fQPainter->save();
if (fQBrush->style() == Qt::SolidPattern) fQPainter->setPen(Qt::NoPen);
QPolygon qtPoints(n);
TPoint *rootPoint = xy;
for (int i =0;i<n;i++,rootPoint++) qtPoints.setPoint(i,rootPoint->fX,rootPoint->fY);
fQPainter->drawPolygon(qtPoints);
fQPainter->restore();
}
}
void TGQt::DrawLine(int x1, int y1, int x2, int y2)
{
TQtLock lock;
if (fSelectedWindow) {
TQtToggleFeedBack feedBack(this);
fQPainter->drawLine(x1,y1,x2,y2);
}
}
void TGQt::DrawPolyLine(int n, TPoint *xy)
{
TQtLock lock;
if (fSelectedWindow) {
TQtToggleFeedBack feedBack(this);
QPolygon qtPoints(n);
TPoint *rootPoint = xy;
for (int i =0;i<n;i++,rootPoint++) qtPoints.setPoint(i,rootPoint->fX,rootPoint->fY);
fQPainter->drawPolyline(qtPoints);
}
}
void TGQt::DrawPolyMarker(int n, TPoint *xy)
{
TQtLock lock;
if (fSelectedWindow)
{
fQPainter->save();
TQtMarker *CurMarker = fQtMarker;
const QColor &mColor = ColorIndex(fMarkerColor);
if( CurMarker->GetNumber() <= 0 )
{
fQPainter->setPen(mColor);
QPolygon qtPoints(n);
TPoint *rootPoint = xy;
for (int i=0;i<n;i++,rootPoint++)
qtPoints.setPoint(i,rootPoint->fX,rootPoint->fY);
fQPainter->drawPoints(qtPoints);
} else {
int r = CurMarker->GetNumber()/2;
fQPainter->setPen(mColor);
switch (CurMarker -> GetType())
{
case 1:
case 3:
default:
fQPainter->setBrush(mColor);
break;
case 0:
case 2:
fQPainter->setBrush(Qt::NoBrush);
break;
case 4:
break;
}
for( int m = 0; m < n; m++ )
{
int i;
switch( CurMarker->GetType() )
{
case 0:
case 1:
fQPainter->drawEllipse(xy[m].fX-r, xy[m].fY-r, 2*r, 2*r);
break;
case 2:
case 3:
{
QPolygon &mxy = fQtMarker->GetNodes();
QPoint delta(xy[m].fX,xy[m].fY);
for( i = 0; i < CurMarker->GetNumber(); i++ )
{
mxy[i] += delta;
}
fQPainter->drawPolygon(mxy);
for( i = 0; i < CurMarker->GetNumber(); i++ )
{
mxy[i] -= delta;
}
break;
}
case 4:
{
QPolygon &mxy = fQtMarker->GetNodes();
QPoint delta(xy[m].fX,xy[m].fY);
for( i = 0; i < CurMarker->GetNumber(); i++ ) mxy[i] += delta;
fQPainter->drawLineSegments(mxy);
for( i = 0; i < CurMarker->GetNumber(); i++ ) mxy[i] -= delta;
break;
}
}
}
}
fQPainter->restore();
}
}
void TGQt::DrawText(int x, int y, float angle, float mgn, const char *text, TVirtualX::ETextMode )
{
#if 0
if (fROOTFont.lfEscapement != (LONG) fTextAngle*10) {
fTextFontModified=1;
fROOTFont.lfEscapement = (LONG) fTextAngle*10;
}
#endif
if (text && text[0]) {
TQtLock lock;
fQFont->SetTextMaginfy(mgn);
UpdateFont();
fQPainter->save();
fQPainter->setPen(ColorIndex(fTextColor));
fQPainter->setBrush(ColorIndex(fTextColor));
QFontMetrics metrics(*fQFont);
QRect bRect = metrics.boundingRect(text);
fQPainter->translate(x,y);
if (TMath::Abs(angle) > 0.1 ) fQPainter->rotate(-angle);
int dx =0; int dy =0;
switch( fTextAlignH ) {
case 2: dx = -bRect.width()/2;
break;
case 3: dx = -bRect.width();
break;
};
switch( fTextAlignV ) {
case 2: dy = bRect.height()/2 - metrics.descent();
break;
case 3: dy = bRect.height() - metrics.descent();
};
fQPainter->drawText (dx, dy, GetTextDecoder()->toUnicode (text));
fQPainter->restore();
}
}
void TGQt::GetCharacterUp(Float_t &chupx, Float_t &chupy)
{
TQtLock lock;
chupx = fCharacterUpX;
chupy = fCharacterUpY;
}
QPaintDevice *TGQt::GetDoubleBuffer(QPaintDevice *dev)
{
QPaintDevice *buffer = 0;
if (dev) {
TQtWidget *widget = dynamic_cast<TQtWidget *>(dev);
buffer = widget && widget->IsDoubleBuffered() ? widget->SetBuffer().Buffer() : 0;
}
return buffer;
}
Int_t TGQt::GetDoubleBuffer(Int_t wid)
{
if (wid == -1 || wid == kDefault ) return 0;
assert(0);
QPaintDevice *dev = iwid(wid);
TQtWidget *widget = dynamic_cast<TQtWidget *>(dev);
return Int_t(widget && widget->IsDoubleBuffered());
}
void TGQt::GetGeometry(int wid, int &x, int &y, unsigned int &w, unsigned int &h)
{
QRect devSize(0,0,0,0);
if( wid == -1 || wid == 0 || wid == kDefault)
{
QDesktopWidget *d = QApplication::desktop();
devSize.setWidth (d->width() );
devSize.setHeight(d->height());
} else {
QPaintDevice *dev = iwid(wid);
if (dev) {
if ( dev->devType() == QInternal::Widget) {
TQtWidget &thisWidget = *(TQtWidget *)dev;
if (thisWidget.GetRootID() ) {
devSize = thisWidget.parentWidget()->geometry();
} else{
devSize = thisWidget.geometry();
}
devSize.moveTopLeft(thisWidget.mapToGlobal(QPoint(0,0)));
} else {
devSize = GetQRect(*dev);
}
}
}
x = devSize.left();
y = devSize.top();
w = devSize.width();
h = devSize.height();
}
const char *TGQt::DisplayName(const char *){ return "localhost"; }
ULong_t TGQt::GetPixel(Color_t cindex)
{
ULong_t rootPixel = 0;
QColor color = ColorIndex(cindex);
#ifdef R__WIN32
rootPixel = ( color.blue () & 255 );
rootPixel = (rootPixel << 8) | ( color.green() & 255 ) ;
rootPixel = (rootPixel << 8) | ( color.red () & 255 );
#else
rootPixel = ( color.red () & 255 );
rootPixel = (rootPixel << 8) | ( color.green() & 255 ) ;
rootPixel = (rootPixel << 8) | ( color.blue () & 255 );
#endif
return rootPixel;
}
void TGQt::GetRGB(int index, float &r, float &g, float &b)
{
const float BIGGEST_RGB_VALUE=255.;
r = g = b = 0;
TQtLock lock;
if (fSelectedWindow != NoOperation) {
int c[3];
const QColor &color = *fPallete[index];
color.rgb(&c[0],&c[1],&c[2]);
r = c[0]/BIGGEST_RGB_VALUE;
g = c[1]/BIGGEST_RGB_VALUE;
b = c[2]/BIGGEST_RGB_VALUE;
}
}
const QTextCodec *TGQt::GetTextDecoder()
{
static QTextCodec *fGreekCodec = 0;
QTextCodec *codec = 0;
if (!fCodec) {
fCodec = QTextCodec::codecForName(fFontTextCode);
if (!fCodec)
fCodec=QTextCodec::codecForLocale();
else
QTextCodec::setCodecForLocale(fCodec);
}
codec = fCodec;
if (fTextFont/10 == 12 ) {
if (!fGreekCodec) {
if (QString(fSymbolFontFamily).contains("Symbol")) {
fGreekCodec = (fFontTextCode == "ISO8859-1") ? fCodec:
QTextCodec::codecForName("ISO8859-1");
} else {
fGreekCodec = QTextCodec::codecForName("symbol");
}
}
if (fGreekCodec) codec=fGreekCodec;
}
return codec;
}
Float_t TGQt::GetTextMagnitude(){return fTextMagnitude;}
void TGQt::SetTextMagnitude(Float_t mgn){ fTextMagnitude = mgn;}
void TGQt::GetTextExtent(unsigned int &w, unsigned int &h, char *mess)
{
TQtLock lock;
if (fQFont) {
#if QT_VERSION < 0x40000
QSize textSize = QFontMetrics(*fQFont).size(Qt::SingleLine,GetTextDecoder()->toUnicode(mess)) ;
#else /* QT_VERSION */
QSize textSize = QFontMetrics(*fQFont).size(Qt::TextSingleLine,GetTextDecoder()->toUnicode(mess)) ;
#endif /* QT_VERSION */
w = textSize.width() ;
h = (unsigned int)(textSize.height());
}
}
Bool_t TGQt::HasTTFonts() const {return kTRUE;}
void TGQt::MoveWindow(Int_t wid, Int_t x, Int_t y)
{
if (wid != -1 && wid != 0 && wid != kDefault)
{
QPaintDevice *widget = iwid(wid);
assert(widget->devType() == QInternal::Widget );
((TQtWidget *)widget)->move(x,y);
}
}
void TGQt::PutByte(Byte_t )
{
}
void TGQt::QueryPointer(int &ix, int &iy)
{
QPoint pos = QCursor::pos();
ix = pos.x(); iy = pos.y();
}
Pixmap_t TGQt::ReadGIF(Int_t x0, Int_t y0, const char *file, Window_t id)
{
Int_t thisId = 0;
QPixmap *pix = new QPixmap( QString (file) );
if ( pix->isNull () ) { delete pix; pix = 0; }
else {
thisId=fWidgetArray->GetFreeId(pix);
if (!id ) { CopyPixmap(thisId,x0,y0); fWidgetArray->DeleteById(thisId); thisId = 0;}
}
return thisId;
}
Int_t TGQt::RequestLocator(Int_t , Int_t , Int_t &, Int_t &)
{
return 0;
}
class requestString : public QDialog {
public:
QString fText;
QLineEdit fEdit;
requestString(const char *text="") : QDialog(0,0
, TRUE,Qt::WStyle_Customize | Qt::WStyle_NoBorder|Qt::WStyle_StaysOnTop | Qt::WType_Popup)
, fText(text),fEdit(this)
{
setBackgroundMode(Qt::NoBackground);
connect(&fEdit,SIGNAL( returnPressed () ), this, SLOT( accept() ));
}
~requestString(){;}
};
Int_t TGQt::RequestString(int x, int y, char *text)
{
int res = QDialog::Rejected;
if (fSelectedWindow->devType() == QInternal::Widget ) {
TQtWidget *w = (TQtWidget *)fSelectedWindow;
static requestString reqDialog;
reqDialog.fEdit.setText(QString(text).stripWhiteSpace());
int yFrame = reqDialog.frameGeometry().height() - reqDialog.geometry().height() + reqDialog.fontMetrics().height();
reqDialog.move(w->mapToGlobal(QPoint(x,y-yFrame)));
if (QClientFilter() && QClientFilter()->PointerGrabber() ) {
QClientFilter()->PointerGrabber()->DisactivateGrabbing();
}
res = reqDialog.exec();
if (res == QDialog::Accepted ) {
Font_t textFontSave = fTextFont;
fTextFont = 62;
QByteArray obr = GetTextDecoder()->fromUnicode(reqDialog.fEdit.text());
const char *r = obr.constData();
qstrcpy(text, (const char *)r);
fTextFont = textFontSave;
}
reqDialog.hide();
if (QClientFilter() && QClientFilter()->PointerGrabber()) {
QClientFilter()->PointerGrabber()->ActivateGrabbing();
}
}
return res == QDialog::Accepted ? 1 : 0;
}
void TGQt::RescaleWindow(int wid, UInt_t w, UInt_t h)
{
TQtLock lock;
if (wid && wid != -1 && wid != kDefault )
{
QPaintDevice *widget = iwid(wid);
if (widget->devType() == QInternal::Widget )
{
if (QSize(w,h) != ((TQtWidget *)widget)->size()) {
if (((TQtWidget *)widget)->paintingActive() ) End();
((TQtWidget *)widget)->resize(w,h);
}
}
}
}
Int_t TGQt::ResizePixmap(int wid, UInt_t w, UInt_t h)
{
TQtLock lock;
if (wid && wid != -1 && wid != kDefault )
{
QPaintDevice *pixmap = iwid(wid);
if (pixmap->devType() == QInternal::Pixmap )
{
if (QSize(w,h) != ((QPixmap *)pixmap)->size()) {
bool paintStatus = pixmap->paintingActive ();
if (paintStatus ) End();
((QPixmap *)pixmap)->resize(w,h);
((QPixmap *)pixmap)->fill();
if (paintStatus) Begin();
}
}
}
return 1;
}
void TGQt::ResizeWindow(int )
{
return;
}
void TGQt::SelectPixmap(Int_t qpixid){ SelectWindow(qpixid);}
void TGQt::SelectWindow(int wid)
{
QPaintDevice *dev = 0;
if (wid == -1 || wid == (int) kNone) {
fSelectedWindow = NoOperation;
} else {
dev = iwid(wid);
fSelectedWindow = dev ? dev : NoOperation;
}
if (fPrevWindow != fSelectedWindow) {
if (fPrevWindow && fPrevWindow != (void *)-1 && (fWidgetArray->find(fPrevWindow) != -1) ) {
End();
}
if (fSelectedWindow && (fSelectedWindow != NoOperation)) {
Begin();
}
fPrevWindow = fSelectedWindow;
}
}
void TGQt::SetCharacterUp(Float_t chupx, Float_t chupy)
{
TQtLock lock;
if (chupx == fCharacterUpX && chupy == fCharacterUpY) {
return;
}
if (chupx == 0 && chupy == 0) fTextAngle = 0;
else if (chupx == 0 && chupy == 1) fTextAngle = 0;
else if (chupx == -1 && chupy == 0) fTextAngle = 90;
else if (chupx == 0 && chupy == -1) fTextAngle = 180;
else if (chupx == 1 && chupy == 0) fTextAngle = 270;
else {
fTextAngle = ((TMath::ACos(chupx/TMath::Sqrt(chupx*chupx +chupy*chupy))*180.)/3.14159)-90;
if (chupy < 0) fTextAngle = 180 - fTextAngle;
if (TMath::Abs(fTextAngle) < 0.01) fTextAngle = 0;
}
fCharacterUpX = chupx;
fCharacterUpY = chupy;
}
void TGQt::SetClipOFF(Int_t )
{
}
void TGQt::SetClipRegion(int wid, int x, int y, UInt_t w, UInt_t h)
{
QRect rect(x,y,w,h);
TQtLock lock;
fClipMap.replace(iwid(wid),rect);
if (fSelectedWindow == iwid(wid) && fSelectedWindow->paintingActive())
{
UpdateClipRectangle();
}
}
void TGQt::SetCursor(Int_t wid, ECursor cursor)
{
fCursor = cursor;
if (wid && wid != -1 && wid != kDefault)
{
QPaintDevice *widget = iwid(wid);
if ( TQtWidget *w = (TQtWidget *)IsWidget(widget) )
w->setCursor(*fCursors[fCursor]);
}
}
void TGQt::SetDoubleBuffer(int wid, int mode)
{
if (wid == -1 || wid == kDefault) return;
QPaintDevice *dev = iwid(wid);
TQtWidget *widget = 0;
if ( dev && (widget = (TQtWidget *)IsWidget(dev)) ) {
widget->SetDoubleBuffer(mode);
}
}
void TGQt::SetDrawMode(TVirtualX::EDrawMode mode)
{
Bool_t feedBack = (mode==kInvert);
if (feedBack != fFeedBackMode) {
fFeedBackMode = feedBack;
if (fFeedBackMode) {
if (!fFeedBackWidget) {
fFeedBackWidget = new TQtFeedBackWidget;
fFeedBackWidget->setFrameStyle(QFrame::Box);
}
fFeedBackWidget->setParent((TQtWidget *)fSelectedWindow);
} else if (fFeedBackWidget) {
fFeedBackWidget->hide();
fFeedBackWidget->setParent(0);
}
}
#if 0
#if QT_VERSION < 0x40000
Qt::RasterOp newMode = Qt::CopyROP;
#else /* QT_VERSION */
QPainter::CompositionMode newMode = QPainter::CompositionMode_Source;
#endif /* QT_VERSION */
switch (mode) {
#if QT_VERSION < 0x40000
case kCopy: newMode = Qt::CopyROP; break;
case kXor: newMode = Qt::XorROP; break;
case kInvert: newMode = Qt::NotROP; break;
default: newMode = Qt::CopyROP; break;
#else /* QT_VERSION */
case kCopy: newMode = QPainter::CompositionMode_Source; break;
case kXor: newMode = QPainter::CompositionMode_Xor; break;
case kInvert: newMode = QPainter::CompositionMode_Destination; break;
default: newMode = QPainter::CompositionMode_Source; break;
#endif /* QT_VERSION */
};
if (newMode != fDrawMode)
{
fDrawMode = newMode;
#if QT_VERSION < 0x40000
if (fQPainter->isActive()) { fQPainter->setRasterOp(fDrawMode); }
#else /* QT_VERSION */
if (fQPainter->isActive() && (fQPainter->device()->devType() == QInternal::Image ))
{
fQPainter->setCompositionMode(fDrawMode);
}
#endif /* QT_VERSION */
}
#endif
}
void TGQt::SetFillColor(Color_t cindex)
{
if (fFillColor != cindex )
{
fFillColor = cindex;
if (fFillColor != -1) {
fQBrush->SetColor(ColorIndex(cindex));
UpdateBrush();
}
}
}
void TGQt::SetFillStyle(Style_t fstyle)
{
if (fFillStyle != fstyle)
{
fFillStyle = fstyle;
if (fFillStyle != -1) {
fQBrush->SetStyle(fFillStyle);
UpdateBrush();
}
}
}
void TGQt::SetFillStyleIndex( Int_t style, Int_t fasi )
{
SetFillStyle(1000*style + fasi);
}
void TGQt::SetLineColor(Color_t cindex)
{
if (fLineColor != cindex) {
fLineColor = cindex;
if (fLineColor >= 0) {
fQPen->SetLineColor(fLineColor);
UpdatePen();
}
}
}
void TGQt::SetLineType(int n, int*dash)
{
fQPen->SetLineType(n,dash);
UpdatePen();
}
void TGQt::SetLineStyle(Style_t linestyle)
{
if (fLineStyle != linestyle) {
fLineStyle = linestyle;
fQPen->SetLineStyle(linestyle);
UpdatePen();
}
}
void TGQt::SetLineWidth(Width_t width)
{
if (width==1) width =0;
if (fLineWidth != width) {
fLineWidth = width;
if (fLineWidth >= 0 ) {
fQPen->SetLineWidth(fLineWidth);
UpdatePen();
}
}
}
void TGQt::SetMarkerColor( Color_t cindex)
{
if (fMarkerColor != cindex) fMarkerColor = cindex;
}
void TGQt::SetMarkerSize(Float_t markersize)
{
if (markersize != fMarkerSize) {
fMarkerSize = markersize;
if (markersize >= 0) {
SetMarkerStyle(-fMarkerStyle);
}
}
}
void TGQt::SetMarkerStyle(Style_t markerstyle){
if (fMarkerStyle == markerstyle) return;
TPoint shape[15];
if (markerstyle >= 31) return;
markerstyle = TMath::Abs(markerstyle);
fMarkerStyle = markerstyle;
Int_t im = Int_t(4*fMarkerSize + 0.5);
switch (markerstyle) {
case 2:
shape[0].SetX(-im); shape[0].SetY( 0);
shape[1].SetX(im); shape[1].SetY( 0);
shape[2].SetX(0) ; shape[2].SetY( -im);
shape[3].SetX(0) ; shape[3].SetY( im);
SetMarkerType(4,4,shape);
break;
case 3:
shape[0].SetX(-im); shape[0].SetY( 0);
shape[1].SetX( im); shape[1].SetY( 0);
shape[2].SetX( 0); shape[2].SetY(-im);
shape[3].SetX( 0); shape[3].SetY( im);
im = Int_t(0.707*Float_t(im) + 0.5);
shape[4].SetX(-im); shape[4].SetY(-im);
shape[5].SetX( im); shape[5].SetY( im);
shape[6].SetX(-im); shape[6].SetY( im);
shape[7].SetX( im); shape[7].SetY(-im);
SetMarkerType(4,8,shape);
break;
case 4:
case 24:
SetMarkerType(0,im*2,shape);
break;
case 5:
im = Int_t(0.707*Float_t(im) + 0.5);
shape[0].SetX(-im); shape[0].SetY(-im);
shape[1].SetX( im); shape[1].SetY( im);
shape[2].SetX(-im); shape[2].SetY( im);
shape[3].SetX( im); shape[3].SetY(-im);
SetMarkerType(4,4,shape);
break;
case 6:
shape[0].SetX(-1); shape[0].SetY( 0);
shape[1].SetX( 1); shape[1].SetY( 0);
shape[2].SetX( 0); shape[2].SetY(-1);
shape[3].SetX( 0); shape[3].SetY( 1);
SetMarkerType(4,4,shape);
break;
case 7:
shape[0].SetX(-1); shape[0].SetY( 1);
shape[1].SetX( 1); shape[1].SetY( 1);
shape[2].SetX(-1); shape[2].SetY( 0);
shape[3].SetX( 1); shape[3].SetY( 0);
shape[4].SetX(-1); shape[4].SetY(-1);
shape[5].SetX( 1); shape[5].SetY(-1);
SetMarkerType(4,6,shape);
break;
case 8:
case 20:
SetMarkerType(1,im*2,shape);
break;
case 21:
shape[0].SetX(-im); shape[0].SetY(-im);
shape[1].SetX( im); shape[1].SetY(-im);
shape[2].SetX( im); shape[2].SetY( im);
shape[3].SetX(-im); shape[3].SetY( im);
SetMarkerType(3,4,shape);
break;
case 22:
shape[0].SetX(-im); shape[0].SetY( im);
shape[1].SetX( im); shape[1].SetY( im);
shape[2].SetX( 0); shape[2].SetY(-im);
SetMarkerType(3,3,shape);
break;
case 23:
shape[0].SetX( 0); shape[0].SetY( im);
shape[1].SetX( im); shape[1].SetY(-im);
shape[2].SetX(-im); shape[2].SetY(-im);
SetMarkerType(3,3,shape);
break;
case 25:
shape[0].SetX(-im); shape[0].SetY(-im);
shape[1].SetX( im); shape[1].SetY(-im);
shape[2].SetX( im); shape[2].SetY( im);
shape[3].SetX(-im); shape[3].SetY( im);
SetMarkerType(2,4,shape);
break;
case 26:
shape[0].SetX(-im); shape[0].SetY( im);
shape[1].SetX( im); shape[1].SetY( im);
shape[2].SetX( 0); shape[2].SetY(-im);
SetMarkerType(2,3,shape);
break;
case 27: {
Int_t imx = Int_t(2.66*fMarkerSize + 0.5);
shape[0].SetX(-imx); shape[0].SetY( 0);
shape[1].SetX( 0); shape[1].SetY(-im);
shape[2].SetX(imx); shape[2].SetY( 0);
shape[3].SetX( 0); shape[3].SetY( im);
SetMarkerType(2,4,shape);
break;
}
case 28: {
Int_t imx = Int_t(1.33*fMarkerSize + 0.5);
shape[0].SetX(-im); shape[0].SetY(-imx);
shape[1].SetX(-imx); shape[1].SetY(-imx);
shape[2].SetX(-imx); shape[2].SetY( -im);
shape[3].SetX(imx); shape[3].SetY( -im);
shape[4].SetX(imx); shape[4].SetY(-imx);
shape[5].SetX( im); shape[5].SetY(-imx);
shape[6].SetX( im); shape[6].SetY( imx);
shape[7].SetX(imx); shape[7].SetY( imx);
shape[8].SetX(imx); shape[8].SetY( im);
shape[9].SetX(-imx); shape[9].SetY( im);
shape[10].SetX(-imx);shape[10].SetY(imx);
shape[11].SetX(-im); shape[11].SetY(imx);
SetMarkerType(2,12,shape);
break;
}
case 29: {
Int_t im1 = Int_t(0.66*fMarkerSize + 0.5);
Int_t im2 = Int_t(2.00*fMarkerSize + 0.5);
Int_t im3 = Int_t(2.66*fMarkerSize + 0.5);
Int_t im4 = Int_t(1.33*fMarkerSize + 0.5);
shape[0].SetX(-im); shape[0].SetY( im4);
shape[1].SetX(-im2); shape[1].SetY(-im1);
shape[2].SetX(-im3); shape[2].SetY( -im);
shape[3].SetX( 0); shape[3].SetY(-im2);
shape[4].SetX(im3); shape[4].SetY( -im);
shape[5].SetX(im2); shape[5].SetY(-im1);
shape[6].SetX( im); shape[6].SetY( im4);
shape[7].SetX(im4); shape[7].SetY( im4);
shape[8].SetX( 0); shape[8].SetY( im);
shape[9].SetX(-im4); shape[9].SetY( im4);
SetMarkerType(3,10,shape);
break;
}
case 30: {
Int_t im1 = Int_t(0.66*fMarkerSize + 0.5);
Int_t im2 = Int_t(2.00*fMarkerSize + 0.5);
Int_t im3 = Int_t(2.66*fMarkerSize + 0.5);
Int_t im4 = Int_t(1.33*fMarkerSize + 0.5);
shape[0].SetX(-im); shape[0].SetY( im4);
shape[1].SetX(-im2); shape[1].SetY(-im1);
shape[2].SetX(-im3); shape[2].SetY( -im);
shape[3].SetX( 0); shape[3].SetY(-im2);
shape[4].SetX(im3); shape[4].SetY( -im);
shape[5].SetX(im2); shape[5].SetY(-im1);
shape[6].SetX( im); shape[6].SetY( im4);
shape[7].SetX(im4); shape[7].SetY( im4);
shape[8].SetX( 0); shape[8].SetY( im);
shape[9].SetX(-im4); shape[9].SetY( im4);
SetMarkerType(2,10,shape);
break;
}
case 31:
SetMarkerType(1,im*2,shape);
break;
default:
SetMarkerType(0,0,shape);
}
}
void TGQt::SetMarkerType( int type, int n, TPoint *xy )
{
fQtMarker->SetMarker(n,xy,type);
}
void TGQt::SetRGB(int cindex, float r, float g, float b)
{
#define BIGGEST_RGB_VALUE 255 // 65535
if (cindex < 0 ) return;
else {
if (fPallete.contains(cindex)) delete fPallete[cindex];
fPallete[cindex] = new QColor(
int(r*BIGGEST_RGB_VALUE+0.5)
,int(g*BIGGEST_RGB_VALUE+0.5)
,int(b*BIGGEST_RGB_VALUE+0.5)
);
}
}
void TGQt::SetRGB(Int_t cindex, Float_t r, Float_t g, Float_t b, Float_t a)
{
SetRGB(cindex, r, g,b);
SetAlpha(cindex,a);
}
void TGQt::SetAlpha(Int_t cindex, Float_t a)
{
if (cindex < 0 || a < 0 ) return;
QColor *color = fPallete[cindex];
if (color) color->setAlphaF(a);
}
void TGQt::GetRGBA(Int_t cindex, Float_t &r, Float_t &g, Float_t &b, Float_t &a)
{
GetRGB(cindex,r,g,b);
a = GetAlpha(cindex);
}
Float_t TGQt::GetAlpha(Int_t cindex)
{
if (cindex < 0 ) return 1.0;
const QColor *color = fPallete[cindex];
return (Float_t)color->alphaF();
}
void TGQt::SetTextAlign(Short_t talign)
{
Int_t txalh = talign/10;
Int_t txalv = talign%10;
fTextAlignH = txalh;
fTextAlignV = txalv;
fTextAlign = Qt::AlignLeft;
switch( txalh ) {
case 2:
fTextAlign |= Qt::AlignHCenter;
break;
case 3:
fTextAlign |= Qt::AlignRight;
break;
default:
fTextAlign |= Qt::AlignLeft;
}
switch( txalv ) {
case 1:
fTextAlign |= Qt::AlignBottom;
break;
case 2:
fTextAlign |= Qt::AlignVCenter;
break;
case 3:
fTextAlign |= Qt::AlignTop;
break;
default:
fTextAlign = Qt::AlignBottom;
}
}
void TGQt::SetTextColor(Color_t cindex)
{
if (fTextColor == cindex) return;
fTextColor = cindex;
if (cindex < 0) return;
}
Int_t TGQt::SetTextFont(char* , TVirtualX::ETextSetMode )
{
return 0;
}
#if 0
void TGQt::SetTextFont(const char *fontname, int italic, int bold)
{
fQFont->SetTextFont(fontname, italic, bold);
fTextFontModified = 1;
}
#endif
void TGQt::SetTextFont(Font_t fontnumber)
{
if ( fTextFont == fontnumber) return;
fTextFont = fontnumber;
if (fTextFont == -1) {
fTextFontModified = 1;
return;
}
fQFont->SetTextFont(fontnumber);
fTextFontModified = 1;
}
void TGQt::SetTextSize(Float_t textsize)
{
if ( fTextSize != textsize ) {
fTextSize = textsize;
if (fTextSize > 0) {
fQFont->SetTextSize(textsize);
fTextFontModified = 1;
}
}
}
void TGQt::SetTitle(const char *title)
{
if (fSelectedWindow->devType() == QInternal::Widget)
{
((TQtWidget *)fSelectedWindow)->topLevelWidget()->setCaption(GetTextDecoder()->toUnicode(title));
}
}
void TGQt::UpdateWindow(int mode)
{
if (fSelectedWindow && mode != 2 ) {
((TQtWidget *)fSelectedWindow)->paintFlag();
((TQtWidget *)fSelectedWindow)->repaint();
#ifndef R__WIN32
QCoreApplication::processEvents(QEventLoop::ExcludeUserInput | QEventLoop::ExcludeSocketNotifiers, 200);
#endif
}
}
Int_t TGQt::WriteGIF(char *name)
{
WritePixmap(iwid(fSelectedWindow),UInt_t(-1),UInt_t(-1),name);
return kTRUE;
}
void TGQt::WritePixmap(int wid, UInt_t w, UInt_t h, char *pxname)
{
if (!wid || (wid == -1) ) return;
QPaintDevice &dev = *iwid(wid);
QPixmap grabWidget;
QPixmap *pix=0;
switch (dev.devType()) {
case QInternal::Widget: {
TQtWidget *thisWidget = (TQtWidget*)&dev;
if (thisWidget->IsDoubleBuffered() ) {
pix = ((const TQtWidget*)&dev)->GetOffScreenBuffer();
} else {
grabWidget = QPixmap::grabWindow(thisWidget->winId());
pix = &grabWidget;
}
}
break;
case QInternal::Pixmap: {
pix = (QPixmap *)&dev;
break;
}
case QInternal::Picture:
case QInternal::Printer:
default: assert(0);
break;
};
if (pix) {
QPixmap outMap(0,0);
QPixmap *finalPixmap = pix;
if ( ( (h == w) && (w == UInt_t(-1) ) ) || ( QSize(w,h) == pix->size()) ) {
} else {
outMap.resize(w,h);
QPainter pnt(&outMap);
pnt.drawPixmap(outMap.rect(),*pix);
finalPixmap = &outMap;
}
QString fname = pxname;
int plus = fname.find("+");
if (plus>=0) fname = fname.left(plus);
QString saveType = QtFileFormat(QFileInfo(fname).extension(FALSE));
if (saveType.isEmpty()) saveType="PNG";
else if (QFileInfo(fname).extension(FALSE) == "gif") {
Int_t saver = gErrorIgnoreLevel;
gErrorIgnoreLevel = kFatal;
TImage *img = TImage::Create();
if (img) {
img->SetImage(Pixmap_t(rootwid(finalPixmap)),0);
img->WriteImage(pxname,
#if ROOT_VERSION_CODE >= ROOT_VERSION(5,13,0)
plus>=0 ? TImage::kAnimGif: TImage::kGif);
#else
TImage::kGif);
#endif
delete img;
}
gErrorIgnoreLevel = saver;
} else {
if (plus>=0) fname = GetNewFileName(fname);
finalPixmap->save(fname,saveType);
}
}
}
void TGQt::UpdateFont()
{
if (fQFont && fQPainter->isActive()) {
fQPainter->setFont(*fQFont);
fTextFontModified = 0;
}
}
void TGQt::UpdatePen()
{
if (fQPen && fQPainter->isActive()) {
fQPainter->setPen(*fQPen);
}
}
void TGQt::UpdateBrush()
{
if (!fQPainter) fQPainter = new TQtPainter();
if (fQBrush && fQPainter->isActive())
{
fQPainter->setBrush(*fQBrush);
}
}
void TGQt::UpdateClipRectangle()
{
if (!fQPainter->isActive()) return;
TQTCLIPMAP::iterator it= fClipMap.find(fSelectedWindow);
QRect clipRect;
if (it != fClipMap.end()) {
clipRect = it.data();
fQPainter->setClipRect(clipRect);
fQPainter->setClipping(TRUE);
}
}
void TGQt::Begin()
{
if (!fQPainter || !fQPainter->isActive() )
{
QPaintDevice *src = fSelectedWindow;
assert(dynamic_cast<QPaintDevice *>(src));
if ( fSelectedWindow->devType() == QInternal::Widget)
{
TQtWidget *theWidget = (TQtWidget *)fSelectedWindow;
theWidget->AdjustBufferSize();
src = theWidget->SetBuffer().Buffer();
}
if (!fQPainter) fQPainter = new TQtPainter();
if (!fQPainter->begin(src) ) {
Error("TGQt::Begin()","Can not create Qt painter for win=%lp dev=%lp\n",src,fQPainter->device());
} else {
UpdatePen();
UpdateBrush();
UpdateFont();
TQTCLIPMAP::iterator it= fClipMap.find(fSelectedWindow);
QRect clipRect;
if (it != fClipMap.end()) {
clipRect = it.data();
fQPainter->setClipRect(clipRect);
fQPainter->setClipping(TRUE);
}
if (fQPainter->device()->devType() == QInternal::Image )
fQPainter->setCompositionMode(fDrawMode);
}
}
}
void TGQt::End()
{
if ( fQPainter && fQPainter->isActive() )
{
fQPainter->end();
}
}
TVirtualX *TGQt::GetVirtualX(){ return fgTQt;}
Int_t TGQt::LoadQt(const char *shareLibFileName)
{
return gSystem->Load(shareLibFileName);
}
Int_t TGQt::processQtEvents(Int_t maxtime)
{
QCoreApplication::processEvents(QEventLoop::AllEvents,maxtime);
return 0;
}
Last change: Mon Dec 8 10:00:32 2008
Last generated: 2008-12-08 10:00
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.