#if defined(HAVE_CONFIG) || defined (R__HAVE_CONFIG)
# include "config.h"
#endif
#ifdef R__QTWIN32
#include <process.h>
#endif
#include <assert.h>
#include <QApplication>
#include <QWidget>
#include <QPolygon>
#include <QEvent>
#include <QImageWriter>
#include <QVector>
#include <QStack>
#include <QFrame>
#include <QPicture>
#include <QDebug>
#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;
TQtTextProxy *TGQt::fgTextProxy = 0;
class TQtTextCloneProxy {
private:
TQtTextProxy *fProxy;
void *operator new(size_t);
TQtTextCloneProxy(const TQtTextCloneProxy&);
void operator=(const TQtTextCloneProxy&);
public:
TQtTextCloneProxy() : fProxy(0)
{
if ( TGQt::TextProxy())
fProxy = TGQt::TextProxy()->Clone();
}
inline ~TQtTextCloneProxy() { delete fProxy; }
inline TQtTextProxy *operator->() { return fProxy;}
};
#define NoOperation (QPaintDevice *)(-1)
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.path()+"/" + fi.completeBaseName()+ "_%04d" + "." + fi.suffix();
return saveFileMoviePattern;
}
QString TGQt::GetNewFileName(const QString &fileNamePrototype)
{
TString flN = fileNamePrototype.toStdString().c_str();
gSystem->ExpandPathName(flN);
QString fileName = (const char *)flN;
Int_t counter = 0;
QString formatPattern = SetFileName(fileName);
while (gSystem->AccessPathName(fileName.toStdString().c_str())==0) {
fileName = QString().sprintf(formatPattern.toStdString().c_str(),counter++);
}
return fileName;
}
class TQtPainter : public QPainter {
private:
TGQt *fVirtualX;
protected:
inline void UpdateBrush() { setBrush(*fVirtualX->fQBrush); }
inline void UpdatePen() { setPen(*fVirtualX->fQPen); }
inline void UpdateFont() { setFont(*fVirtualX->fQFont);
fVirtualX->fTextFontModified = 0;
}
public:
enum { kNone = 0,
kUseFeedBack = 1,
kUpdateFont = 2,
kUpdateBrush = 4,
kUpdatePen = 8
};
TQtPainter() : QPainter (), fVirtualX(0) {}
TQtPainter(QPaintDevice * dev) : QPainter ( dev ), fVirtualX(0) {}
TQtPainter( TGQt *dev, unsigned int useFeedBack=kUpdateBrush | kUpdatePen ) : fVirtualX(0)
{ begin(dev,useFeedBack); }
~TQtPainter () { fVirtualX->fQPainter = 0; }
bool begin ( TGQt *dev, unsigned int useFeedBack);
};
class TQtFeedBackWidget : public QFrame {
QPixmap *fPixBuffer;
QPixmap *fGrabBuffer;
TQtWidget *fParentWidget;
protected:
virtual void hideEvent (QHideEvent *ev) {
delete fPixBuffer; fPixBuffer = 0;
delete fGrabBuffer; fGrabBuffer = 0;
QFrame::hideEvent(ev);
if (fParentWidget) {
fParentWidget->SetIgnoreLeaveEnter(0);
SetParent(0);
}
}
virtual void paintEvent(QPaintEvent *ev) {
if (fPixBuffer) {
QRect rc = ev->rect();
{
QPainter p(this);
p.setClipRect(rc);
p.drawPixmap(0,0,*fPixBuffer);
}
ClearBuffer();
} else if (fGrabBuffer) {
QRect rc = ev->rect();
QPainter p(this);
p.setClipRect(rc);
p.drawPixmap(rc,*fGrabBuffer);
}
QFrame::paintEvent(ev);
}
public:
TQtFeedBackWidget(QWidget *mother=0, Qt::WindowFlags f=0) : QFrame(mother,f)
,fPixBuffer(0),fGrabBuffer(0),fParentWidget(0)
{
setAttribute(Qt::WA_NoSystemBackground);
setEnabled(false);
setBackgroundRole(QPalette::Window);
setAutoFillBackground(false);
QPalette p = palette();
p.setBrush(QPalette::Window, Qt::transparent);
setPalette(p);
setMouseTracking(true);
}
virtual ~TQtFeedBackWidget()
{
fParentWidget = 0;
delete fPixBuffer; fPixBuffer = 0;
delete fGrabBuffer; fGrabBuffer = 0;
}
void SetParent(TQtWidget *w) {
setParent(fParentWidget = w);
}
void Hide() {
if (fParentWidget) {
fParentWidget->SetIgnoreLeaveEnter(0);
SetParent(0);
}
}
void Show() {
if (fParentWidget) fParentWidget->SetIgnoreLeaveEnter(2);
QFrame::show();
if (fParentWidget) fParentWidget->SetIgnoreLeaveEnter();
}
QPaintDevice *PixBuffer() {
if (fParentWidget ) {
QSize canvasSize = fParentWidget->size();
setGeometry(QRect(QPoint(0,0),canvasSize));
if ( !fPixBuffer || (fPixBuffer->size() != canvasSize) ) {
delete fPixBuffer;
fPixBuffer = new QPixmap(canvasSize);
ClearBuffer();
}
}
return fPixBuffer;
}
QPaintDevice *GrabBuffer(QSize &s) {
if (fParentWidget ) {
if ( !fPixBuffer || (fPixBuffer->size() != s) ) {
delete fPixBuffer;
fPixBuffer = new QPixmap(s);
ClearBuffer();
}
}
return fPixBuffer;
}
void ClearBuffer() {
fPixBuffer->fill(Qt::transparent);
}
void SetGeometry(int xp,int yp, 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(xp,yp,w,h));
}
}
setGeometry(xp,yp,w,h);
}
};
class TQtToggleFeedBack {
TGQt *fGQt;
TQtPainter fFeedBackPainter;
public:
TQtToggleFeedBack(TGQt *gqt) : fGQt(gqt)
{
if (fGQt->fFeedBackMode && fGQt->fFeedBackWidget->isHidden()) {
fGQt->fFeedBackWidget->Show();
}
}
~TQtToggleFeedBack()
{
if (fFeedBackPainter.isActive() ) fFeedBackPainter.end();
if (fGQt->fFeedBackMode && fGQt->fFeedBackWidget)
{ fGQt->fFeedBackWidget->update(); }
}
TQtPainter &painter() {
if (!fFeedBackPainter.isActive()) {
fFeedBackPainter.begin(fGQt, TQtPainter::kUseFeedBack
| TQtPainter::kUpdatePen
| TQtPainter::kUpdateBrush);
if (fGQt->fFeedBackMode) {
fFeedBackPainter.setPen(QColor(128,128,128,128));
}
}
return fFeedBackPainter;
}
};
inline bool TQtPainter::begin ( TGQt *dev, unsigned int useFeedBack)
{
bool res = false;
if (dev && (dev->fSelectedWindow != NoOperation)) {
fVirtualX = dev;
QPaintDevice *src= 0;
if ( (useFeedBack & kUseFeedBack) && dev->fFeedBackMode
&& dev->fFeedBackWidget
&& dev->fFeedBackWidget)
{ src = dev->fFeedBackWidget->PixBuffer(); }
else {
src = dev->fSelectedWindow;
if ( src->devType() == QInternal::Widget)
{
TQtWidget *theWidget = (TQtWidget *)src;
src = theWidget->SetBuffer().Buffer();
}
}
if (!(res= QPainter::begin(src)) ) {
Error("TGQt::Begin()","Can not create Qt painter for win=0x%lx dev=0x%lx\n",(Long_t)src,(Long_t)dev);
assert(0);
} else {
dev->fQPainter = (TQtPainter*)-1;
UpdatePen();
UpdateBrush();
UpdateFont();
TGQt::TQTCLIPMAP::iterator it= (dev->fClipMap).find(src);
QRect clipRect;
if (it != (dev->fClipMap).end()) {
clipRect = it.value();
setClipRect(clipRect);
setClipping(TRUE);
}
if (src->devType() == QInternal::Image )
setCompositionMode(dev->fDrawMode);
}
}
return res;
}
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:
QStack<int> fFreeWindowsIdStack;
QVector<QPaintDevice *> fWidgetCollection;
Int_t fIDMax;
Int_t fIDTotalMax;
protected:
inline Int_t SetMaxId(Int_t newId)
{
fIDMax = newId;
if (newId>fIDTotalMax) {
fIDTotalMax = newId;
fWidgetCollection.resize(fIDTotalMax+1);
}
return fIDMax;
}
public:
TQWidgetCollection () : fIDMax(-1), fIDTotalMax(-1)
{
int kDefault = 1;
assert(!kNone);
SetMaxId (kDefault);
fWidgetCollection[kNone] = (QPaintDevice*)0;
fWidgetCollection[kDefault] = (QPaintDevice *)QApplication::desktop();
}
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 0;
}
inline const QPaintDevice *ReplaceById(Int_t Id, QPaintDevice *newDev)
{
if (newDev) {
delete fWidgetCollection[Id];
fWidgetCollection[Id] = newDev;
} else {
DeleteById(Id);
}
return newDev;
}
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 wd)
{
QPaintDevice *topDevice = 0;
if ( wd != kNone ) {
topDevice = (wd == kDefault) ?
(QPaintDevice *)QApplication::desktop()
:
(QPaintDevice*)wd;
}
return topDevice;
}
Int_t TGQt::iwid(QPaintDevice *wd)
{
Int_t intWid = kNone;
if ((ULong_t) wd == (ULong_t) -1) intWid = -1;
else {
intWid = fWidgetArray->find(wd);
assert(intWid != -1);
}
return intWid;
}
QPaintDevice *TGQt::iwid(Int_t wd)
{
QPaintDevice *topDevice = 0;
if (0 <= wd && wd <= int(fWidgetArray->MaxId()) )
topDevice = (*fWidgetArray)[wd];
if (topDevice == (QPaintDevice *)(-1) ) topDevice = 0;
else {
assert(wd <= 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)
{
qDebug() << "----- Window "<< TGQt::wid(ev.fWindow) << TGQt::wid(ev.fWindow) << " " << TGQt::wid(ev.fWindow)-> objectName();
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
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",Qt::CaseInsensitive)) 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",Qt::CaseInsensitive) ? "JPEG" : selector;
if (checkString.contains(nextFormat,Qt::CaseInsensitive) ) {
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),fhEvent ()
,fQBrush(),fQPen(),fQtMarker(),fQFont(),fQClientFilter(),fQClientFilterBuffer(0)
,fPointerGrabber(),fCodec(0),fSymbolFontFamily("Symbol"),fQtEventHasBeenProcessed(0)
,fFeedBackMode(kFALSE),fFeedBackWidget(0),fBlockRGB(kFALSE),fUseTTF(kTRUE)
{
assert(!fgTQt);
fgTQt = this;
gQt = this;
fSelectedWindow = fPrevWindow = NoOperation;
}
TGQt::TGQt(const char *name, const char *title) : TVirtualX(name,title),fDisplayOpened(kFALSE)
,fQPainter(0),fhEvent(),fCursors(kNumCursors),fQClientFilter(0),fQClientFilterBuffer(0),fPointerGrabber(0)
,fCodec(0),fSymbolFontFamily("Symbol"),fQtEventHasBeenProcessed(0)
,fFeedBackMode(kFALSE),fFeedBackWidget(0),fBlockRGB(kFALSE),fUseTTF(kTRUE)
{
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; fQClientFilter = 0;
delete fQClientFilterBuffer; fQClientFilterBuffer = 0;
delete fgTextProxy; fgTextProxy = 0;
}
TQtApplication::Terminate();
}
Bool_t TGQt::Init(void* )
{
fprintf(stderr,"** $Id: TGQt.cxx 36275 2010-10-11 08:05:21Z brun $ this=%p\n",this);
#ifndef R__QTWIN32
extern void qt_x11_set_global_double_buffer(bool);
#endif
if(fDisplayOpened) return fDisplayOpened;
fSelectedWindow = fPrevWindow = NoOperation;
fTextAlignH = 1;
fTextAlignV = 1;
fTextMagnitude = 1;
fCharacterUpX = 1;
fCharacterUpY = 1;
fDrawMode = QPainter::CompositionMode_Source;
fTextFontModified = 0;
fTextAlign = 0;
fTextSize = -1;
fTextFont = -1;
fLineWidth = -1;
fFillColor = -1;
fLineColor = -1;
fLineStyle = -1;
fMarkerSize = -1;
fMarkerStyle = -1;
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);
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");
QFont *dfFont = (QFont *)LoadQueryFont(default_font);
QApplication::setFont(*dfFont);
delete dfFont;
QString fontName(default_font);
fFontTextCode = fontName.section('-',13). toUpper();
if ( fFontTextCode.isEmpty() ) fFontTextCode = "ISO8859-5";
#ifndef R__QTWIN32
QFontDatabase fdb;
QString fontFamily;
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;
qDebug() << "Symbol font family found: " << *f;
if (*f == "Standard Symbols L") { fontFamily = *f; 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");
fontFamily = fSymbolFontFamily = "Arial";
qDebug() << " Substitute it with \""<<fontFamily <<"\"";
qDebug() << " 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";
new QSymbolCodec();
}
if (symbolFontFound) TQtPadFont::SetSymbolFontFamily(fontFamily.toAscii().data());
#endif
#if ROOT_VERSION_CODE >= ROOT_VERSION(5,26,0)
fUseTTF=gEnv->GetValue("Qt.Screen.TTF",kFALSE);
#else
fUseTTF=gEnv->GetValue("Qt.Screen.TTF",kTRUE);
#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(QStringList("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(libPath.toAscii().data());
}
} 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 *wd)
{
Int_t id = fWidgetArray->find(wd);
if (id == -1) id = fWidgetArray->GetFreeId(wd);
return id;
}
Int_t TGQt::UnRegisterWid(QPaintDevice *wd)
{
return fWidgetArray->RemoveByPointer(wd);
}
Bool_t TGQt::IsRegistered(QPaintDevice *wd)
{
return fWidgetArray->find(wd) == -1 ? kFALSE : kTRUE;
}
Int_t TGQt::InitWindow(ULong_t window)
{
TQtWidget *wd = 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);
}
wd = new TQtWidget(parent,"virtualx",Qt::FramelessWindowHint,FALSE);
wd->setCursor(*fCursors[kCross]);
Int_t id = fWidgetArray->GetFreeId(wd);
wd->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)) {
Warning("ColorIndex","Unknown color. No RGB component for the index %d was defined\n",ic);
return unknownColor;
} else {
TColor *myColor = gROOT->GetColor(ic);
Float_t a = myColor->GetAlpha();
colorBuffer = fPallete[ic];
if (TMath::Abs(colorBuffer->alphaF() - a) > 0.01) {
colorBuffer->setAlphaF(a);
}
}
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)) {
((TQtWidget *)fSelectedWindow)->Erase();
} else if (IsPixmap(fSelectedWindow) ) {
((QPixmap *)fSelectedWindow)->fill(fQBrush->color());
} else {
TQtPainter p(this);
p.eraseRect(GetQRect(*fSelectedWindow));
}
}
}
void TGQt::ClosePixmap()
{
DeleteSelectedObj();
}
void TGQt::CloseWindow()
{
DeleteSelectedObj();
}
void TGQt::DeleteSelectedObj()
{
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();
}
}
} else {
UnRegisterWid(fSelectedWindow);
delete fSelectedWindow;
}
fClipMap.remove(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 wd, int xpos, int ypos)
{
if (!wd || (wd == -1) ) return;
QPaintDevice *dev = iwid(wd);
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);
}
bool itIsWidget = fSelectedWindow->devType() == QInternal::Widget;
TQtWidget *theWidget = 0;
if (itIsWidget) {
theWidget = (TQtWidget *)fSelectedWindow;
dst = theWidget->GetOffScreenBuffer();
}
{
QPainter paint(dst);
paint.drawPixmap(xpos,ypos,*src);
}
Emitter()->EmitPadPainted(src);
if (theWidget) theWidget->EmitCanvasPainted();
}
}
void TGQt::CopyPixmap(const QPixmap &src, Int_t xpos, Int_t ypos)
{
if (fSelectedWindow )
{
QPaintDevice *dst = fSelectedWindow;
QPainter paint(dst); paint.drawPixmap(xpos,ypos,src);
}
}
void TGQt::CreateOpenGLContext(int wd)
{
if (!wd || (wd == -1) ) return;
#ifdef QtGL
if (!wd)
{
SafeCallWin32
->W32_CreateOpenGL();
}
else
{
SafeCallW32(((TQtSwitch *)wd))
->W32_CreateOpenGL();
}
#endif
}
void TGQt::DeleteOpenGLContext(int wd)
{
if (!wd || (wd == -1) ) return;
#ifdef QtGL
if (!wd)
{
SafeCallWin32
->W32_DeleteOpenGL();
}
else
{
SafeCallW32(((TQtSwitch *)wd))
->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
if (!fSelectedWindow ) return;
TQtLock lock;
if (y2 > y1) {
int swap = y1;
y1=y2; y2=swap;
}
if (x1 > x2) {
int swap = x1;
x1=x2; x2=swap;
}
if ( (fSelectedWindow->devType() == QInternal::Widget) && fFeedBackMode && fFeedBackWidget) {
fFeedBackWidget->SetGeometry(x1,y2,x2-x1,y1-y2,(TQtWidget *)fSelectedWindow);
if (fFeedBackWidget->isHidden() ) fFeedBackWidget->Show();
return;
}
if ((mode == kHollow) || (fQBrush->style() == Qt::NoBrush) )
{
TQtPainter p(this,TQtPainter::kUpdatePen);
p.setBrush(Qt::NoBrush);
p.drawRect(x1,y2,x2-x1+Q3,y1-y2+Q3);
} else if (fQBrush->GetColor().alpha() ) {
TQtPainter p(this);
if (fQBrush->style() != Qt::SolidPattern) p.setPen(fQBrush->GetColor());
p.fillRect(x1,y2,x2-x1,y1-y2,*fQBrush);
}
}
void TGQt::DrawCellArray(int x1, int y1, int x2, int y2, int nx, int ny, int *ic)
{
TQtLock lock;
if (fSelectedWindow)
{
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)
{
TQtPainter p(this,TQtPainter::kUpdatePen);
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;
p.setPen(ColorIndex(current_icol));
}
p.drawPoint(i,y1-j);
}
}
}
else
{
QRect box(x1,y1,w,h);
TQtPainter p(this,TQtPainter::kNone);
for ( i=0; i<nx; i++ ) {
for ( j=0; j<ny; j++ ) {
icol = ic[i+(nx*j)];
if(icol != current_icol){
current_icol = icol;
p.setBrush(ColorIndex(current_icol));
}
p.drawRect(box);
box.translate(0,-h);
}
box.translate(w,lh);
}
}
}
}
void TGQt::DrawFillArea(int n, TPoint *xy)
{
TQtLock lock;
if (fSelectedWindow && n>0)
{
TQtPainter p(this);
if (fQBrush->style() == Qt::SolidPattern) p.setPen(Qt::NoPen);
QPolygon qtPoints(n);
TPoint *rootPoint = xy;
for (int i =0;i<n;i++,rootPoint++) qtPoints.setPoint(i,rootPoint->fX,rootPoint->fY);
p.drawPolygon(qtPoints);
}
}
void TGQt::DrawLine(int x1, int y1, int x2, int y2)
{
TQtLock lock;
if (fSelectedWindow) {
TQtToggleFeedBack feedBack(this);
feedBack.painter().drawLine(x1,y1,x2,y2);
#if 0
if (x1> 1000) {
qDebug() << "TGQt::DrawLine " << " x1=" << x1
<< " y1=" << y1
<< " x2=" << x2
<< " y2=" << y2;
}
#endif
}
}
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);
feedBack.painter().drawPolyline(qtPoints);
}
}
void TGQt::DrawPolyMarker(int n, TPoint *xy)
{
TQtLock lock;
if (fSelectedWindow) {
TQtPainter p(this,TQtPainter::kNone);
fQtMarker->DrawPolyMarker(p,n,xy);
}
}
TQtTextProxy *TGQt::TextProxy()
{
return fgTextProxy;
}
void TGQt::SetTextProxy(TQtTextProxy *proxy)
{
fgTextProxy = proxy;
}
void TGQt::DrawText(int x, int y, float angle, float mgn, const char *text, TVirtualX::ETextMode )
{
if (text && text[0]) {
TQtLock lock;
fQFont->SetTextMagnify(mgn);
TQtPainter p(this,TQtPainter::kUpdateFont);
p.setPen(ColorIndex(fTextColor));
p.setBrush(ColorIndex(fTextColor));
unsigned int w=0;unsigned int h=0; unsigned int d = 0;
bool textProxy = false;
TQtTextCloneProxy proxy;
if (fgTextProxy) {
proxy->clear();
QFontInfo fi(*fQFont);
proxy->setBaseFontPointSize(fi.pointSize());
proxy->setForegroundColor(ColorIndex(fTextColor));
if ( ( textProxy = proxy->setContent(text) ) ) {
w = proxy->width();
h = proxy->height();
}
}
if (!textProxy) {
QFontMetrics metrics(*fQFont);
QRect bRect = metrics.boundingRect(text);
w = bRect.width();
h = bRect.height();
d = metrics.descent();
}
p.translate(x,y);
if (TMath::Abs(angle) > 0.1 ) p.rotate(-angle);
int dx =0; int dy =0;
switch( fTextAlignH ) {
case 2: dx = -int(w/2);
break;
case 3: dx = -int(w);
break;
};
switch( fTextAlignV ) {
case 2: dy = h/2 - d;
break;
case 3: dy = h - d;
};
if (textProxy)
proxy->paint(&p,dx,-dy);
else
p.drawText (dx, dy, GetTextDecoder()->toUnicode (text));
}
}
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 wd)
{
if (wd == -1 || wd == kDefault ) return 0;
assert(0);
QPaintDevice *dev = iwid(wd);
TQtWidget *widget = dynamic_cast<TQtWidget *>(dev);
return Int_t(widget && widget->IsDoubleBuffered());
}
void TGQt::GetGeometry(int wd, int &x, int &y, unsigned int &w, unsigned int &h)
{
QRect devSize(0,0,0,0);
if( wd == -1 || wd == 0 || wd == kDefault)
{
QDesktopWidget *d = QApplication::desktop();
devSize.setWidth (d->width() );
devSize.setHeight(d->height());
} else {
QPaintDevice *dev = iwid(wd);
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;
const QColor &color = ColorIndex(UpdateColor(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)
{
r = g = b = 0;
TQtLock lock;
if (fSelectedWindow != NoOperation) {
qreal R,G,B;
const QColor &color = *fPallete[index];
color.getRgbF(&R,&G,&B);
r = R; g = G; b = G;
}
}
const QTextCodec *TGQt::GetTextDecoder()
{
static QTextCodec *fGreekCodec = 0;
QTextCodec *codec = 0;
if (!fCodec) {
fCodec = QTextCodec::codecForName(fFontTextCode.toAscii());
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) {
bool textProxy = false;
if (fgTextProxy) {
TQtTextCloneProxy proxy;
proxy->clear();
QFontInfo fi(*fQFont);
proxy->setBaseFontPointSize(fi.pointSize());
if ( (textProxy = proxy->setContent(mess)) ) {
w = proxy->width();
h = proxy->height();
}
}
if (!textProxy) {
QSize textSize = QFontMetrics(*fQFont).size(Qt::TextSingleLine,GetTextDecoder()->toUnicode(mess)) ;
w = textSize.width();
h = (unsigned int)(textSize.height());
}
}
}
Int_t TGQt::GetFontAscent() const
{
Int_t ascent = 0;
if (fQFont) {
QFontMetrics fm(*fQFont);
ascent = fm.ascent();
}
return ascent;
}
Int_t TGQt::GetFontDescent() const
{
Int_t descent = 0;
if (fQFont) {
QFontMetrics fm(*fQFont);
descent = fm.descent();
}
return descent;
}
Bool_t TGQt::HasTTFonts() const {return fUseTTF;}
void TGQt::MoveWindow(Int_t wd, Int_t x, Int_t y)
{
if (wd != -1 && wd != 0 && wd != kDefault)
{
QPaintDevice *widget = iwid(wd);
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
, Qt::FramelessWindowHint
| Qt::WindowStaysOnTopHint
| Qt::Popup)
, fText(text),fEdit(this)
{
setModal(true);
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).trimmed());
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 wd, UInt_t w, UInt_t h)
{
TQtLock lock;
if (wd && wd != -1 && wd != kDefault )
{
QPaintDevice *widget = iwid(wd);
if (widget->devType() == QInternal::Widget )
{
if (QSize(w,h) != ((TQtWidget *)widget)->size()) {
((TQtWidget *)widget)->resize(w,h);
}
}
}
}
Int_t TGQt::ResizePixmap(int wd, UInt_t w, UInt_t h)
{
TQtLock lock;
if (wd && wd != -1 && wd != kDefault )
{
QPaintDevice *pixmap = iwid(wd);
if (pixmap->devType() == QInternal::Pixmap )
{
if (QSize(w,h) != ((QPixmap *)pixmap)->size()) {
QPixmap *newpix = new QPixmap(w,h);
newpix->fill();
fWidgetArray->ReplaceById(wd,newpix);
if (fSelectedWindow == pixmap) fSelectedWindow = newpix;
}
}
}
return 1;
}
void TGQt::ResizeWindow(int )
{
return;
}
void TGQt::SelectPixmap(Int_t qpixid){ SelectWindow(qpixid);}
void TGQt::SelectWindow(int wd)
{
QPaintDevice *dev = 0;
if (wd == -1 || wd == (int) kNone) {
fSelectedWindow = NoOperation;
} else {
dev = iwid(wd);
fSelectedWindow = dev ? dev : NoOperation;
}
if (fPrevWindow != fSelectedWindow)
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 wd, int x, int y, UInt_t w, UInt_t h)
{
QRect rect(x,y,w,h);
TQtLock lock;
fClipMap.remove(iwid(wd));
fClipMap.insert(iwid(wd),rect);
}
void TGQt::SetCursor(Int_t wd, ECursor cursor)
{
fCursor = cursor;
if (wd && wd != -1 && wd != kDefault)
{
QPaintDevice *widget = iwid(wd);
if ( TQtWidget *w = (TQtWidget *)IsWidget(widget) )
w->setCursor(*fCursors[fCursor]);
}
}
void TGQt::SetDoubleBuffer(int wd, int mode)
{
if (wd == -1 || wd == kDefault) return;
QPaintDevice *dev = iwid(wd);
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(0);
fFeedBackWidget->SetParent((TQtWidget *)fSelectedWindow);
} else if (fFeedBackWidget) {
fFeedBackWidget->Hide();
}
}
#if 0
QPainter::CompositionMode newMode = QPainter::CompositionMode_Source;
switch (mode) {
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;
};
if (newMode != fDrawMode)
{
fDrawMode = newMode;
if (fQPainter->isActive() && (fQPainter->device()->devType() == QInternal::Image ))
{
fQPainter->setCompositionMode(fDrawMode);
}
}
#endif
}
void TGQt::SetFillColor(Color_t cindex)
{
if (fFillColor != cindex )
fQBrush->SetColor(fFillColor = UpdateColor(cindex));
}
void TGQt::SetFillStyle(Style_t fstyle)
{
if (fFillStyle != fstyle)
fQBrush->SetStyle(fFillStyle = fstyle);
}
void TGQt::SetFillStyleIndex( Int_t style, Int_t fasi )
{
SetFillStyle(1000*style + fasi);
}
void TGQt::SetLineColor(Color_t cindex)
{
if (fLineColor != cindex) {
fLineColor = UpdateColor(cindex);
if (fLineColor >= 0) fQPen->SetLineColor(fLineColor);
}
}
void TGQt::SetLineType(int n, int*dash)
{
fQPen->SetLineType(n,dash);
}
void TGQt::SetLineStyle(Style_t linestyle)
{
if (fLineStyle != linestyle) {
fLineStyle = linestyle;
fQPen->SetLineStyle(linestyle);
}
}
void TGQt::SetLineWidth(Width_t width)
{
if (width==1) width =0;
if (fLineWidth != width) {
fLineWidth = width;
if (fLineWidth >= 0 ) fQPen->SetLineWidth(fLineWidth);
}
}
void TGQt::SetMarkerColor( Color_t cindex)
{
if (fQtMarker->GetColor() != cindex)
fQtMarker->SetColor(fMarkerColor = UpdateColor(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];
markerstyle = TMath::Abs(markerstyle);
if (markerstyle%1000 >= 31) return;
fMarkerStyle = markerstyle%1000;
Style_t penWidth = markerstyle-fMarkerStyle;
Int_t im = Int_t(4*fMarkerSize + 0.5);
switch (fMarkerStyle) {
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+penWidth,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+penWidth,8,shape);
break;
case 4:
case 24:
SetMarkerType(0+penWidth,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+penWidth,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+penWidth,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+penWidth,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+penWidth,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+penWidth,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+penWidth,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+penWidth,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+penWidth,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+penWidth,10,shape);
break;
}
case 31:
SetMarkerType(1,im*2,shape);
break;
default:
SetMarkerType(0+penWidth,0,shape);
}
}
void TGQt::SetMarkerType( int type, int n, TPoint *xy )
{
fQtMarker->SetMarker(n,xy,type);
}
int TGQt::UpdateColor(int cindex)
{
#define BIGGEST_RGB_VALUE 255 // 65535
if (cindex >= 0 ) {
if (!fPallete.contains(cindex)) {
fBlockRGB = kTRUE;
TColor *rootColor = gROOT->GetColor(cindex);
fBlockRGB = kFALSE;
if (rootColor) {
float r,g,b,a;
rootColor->GetRGB(r,g,b);
a= rootColor->GetAlpha();
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)
,int(a*BIGGEST_RGB_VALUE+0.5)
);
}
}
}
return cindex;
}
void TGQt::SetRGB(int cindex, float r, float g, float b)
{
#define BIGGEST_RGB_VALUE 255 // 65535
if ( !fBlockRGB && cindex >= 0 ) {
QMap<Color_t,QColor*>::iterator i = fPallete.find(cindex);
if (i != fPallete.end()) {
delete i.value();
fPallete.erase(i);
}
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 = UpdateColor(cindex);
if (cindex < 0) return;
}
Int_t TGQt::SetTextFont(char* , TVirtualX::ETextSetMode )
{
return 0;
}
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()-> setWindowTitle(GetTextDecoder()->toUnicode(title));
}
}
void TGQt::UpdateWindow(int mode)
{
if (fSelectedWindow && mode != 2 ) {
((TQtWidget *)fSelectedWindow)->paintFlag();
((TQtWidget *)fSelectedWindow)->repaint();
#ifndef R__WIN32
#endif
}
}
Int_t TGQt::WriteGIF(char *name)
{
WritePixmap(iwid(fSelectedWindow),UInt_t(-1),UInt_t(-1),name);
return kTRUE;
}
void TGQt::WritePixmap(int wd, UInt_t w, UInt_t h, char *pxname)
{
if (!wd || (wd == -1) ) return;
QPaintDevice &dev = *iwid(wd);
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 *finalPixmap = 0;
if ( ( (h == w) && (w == UInt_t(-1) ) ) || ( QSize(w,h) == pix->size()) ) {
finalPixmap = new QPixmap(*pix);
} else {
finalPixmap = new QPixmap(pix->scaled(w,h));
}
QString fname = pxname;
int plus = fname.indexOf("+");
if (plus>=0) fname = fname.left(plus);
QString saveType = QtFileFormat(QFileInfo(fname).suffix());
if (saveType.isEmpty()) saveType="PNG";
else if (QFileInfo(fname).suffix() == "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.toAscii().data());
}
delete finalPixmap;
}
}
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;
}