From d3a524f3aa7061218688e7fb4d5c6cb2dbb2e2a7 Mon Sep 17 00:00:00 2001
From: Rene Brun <Rene.Brun@cern.ch>
Date: Tue, 24 Jun 2008 13:21:30 +0000
Subject: [PATCH] From Bertrand: - Port QtGsi tests to Qt4, keeping them
 compatible with Qt3

git-svn-id: http://root.cern.ch/svn/root/trunk@24514 27541ba8-7e3a-0410-8455-c3a389f83636
---
 gui/qtgsi/test/example1/Makefile            |  5 +-
 gui/qtgsi/test/example1/Makefile.win        |  4 +-
 gui/qtgsi/test/example1/qtroot.cpp          | 97 ++++++++++++---------
 gui/qtgsi/test/example1/qtroot.h            | 16 +++-
 gui/qtgsi/test/example2/Makefile.win        |  9 +-
 gui/qtgsi/test/example2/qtrootexample.pro   |  6 +-
 gui/qtgsi/test/example2/qtrootexample1.ui.h | 67 ++++++++------
 7 files changed, 128 insertions(+), 76 deletions(-)

diff --git a/gui/qtgsi/test/example1/Makefile b/gui/qtgsi/test/example1/Makefile
index 28411637ddf..23a6b092a9e 100644
--- a/gui/qtgsi/test/example1/Makefile
+++ b/gui/qtgsi/test/example1/Makefile
@@ -41,10 +41,11 @@ SYSCONF_LINK_LIB_SHARED	=  $(LD) -shared -Wl,-soname,lib$(TARGET).so.$(VER_MAJ)
 
 ####### Compiler, tools and options
 
-QTCXXFLAGS=	-I$(QTINCDIR) $(CXXFLAGS) -DDEBUG_LEVEL=$(QDL) $(shell root-config --cflags)
+#QTCXXFLAGS=	-I$(QTINCDIR) $(CXXFLAGS) -DQT3_SUPPORT -DDEBUG_LEVEL=$(QDL) $(shell root-config --cflags)
+QTCXXFLAGS=	-I. $(QTINCDIR:%=-I%) $(CXXFLAGS) -DQT3_SUPPORT -DQT_QT3SUPPORT_LIB -DDEBUG_LEVEL=$(QDL) $(shell root-config --cflags)
 INCPATH =	-I../../../include
 LFLAGS	=	$(LDFLAGS) $(QTLIBDIR) $(X11LIBDIR)
-LIBS	=	$(QTLIB) $(SYSCONF_LIBS_X11) $(shell root-config --prefix=../../../ --glibs) -lQtGSI
+LIBS	=	$(QTLIB) $(SYSCONF_LIBS_X11) $(shell root-config --glibs) -lQtGSI
 
 ####### Target
 
diff --git a/gui/qtgsi/test/example1/Makefile.win b/gui/qtgsi/test/example1/Makefile.win
index 5218d141a94..ebc47b14e36 100644
--- a/gui/qtgsi/test/example1/Makefile.win
+++ b/gui/qtgsi/test/example1/Makefile.win
@@ -14,13 +14,13 @@ LD            = link
 ifdef is_debug
 # Debugging:
 OPTIMIZE  := -Zi -MDd
-LINKDEBUG := -debug
+LINKDEBUG := -debug -nodefaultlib:msvcrt.lib
 else
 # Full optimization:
 OPTIMIZE  := -Ox -MD
 endif
 
-QTCXXFLAGS   := -GR $(OPTIMIZE) -W3 -nologo $(shell root-config --cflags) -D_CRT_SECURE_NO_DEPRECATE -DQT_DLL -DQT_THREAD_SUPPORT
+QTCXXFLAGS   := -GR $(OPTIMIZE) -W3 -nologo $(shell root-config --cflags) -FIw32pragma.h -D_CRT_SECURE_NO_DEPRECATE -DQT_DLL -DQT_THREAD_SUPPORT -DQT3_SUPPORT $(QTINCDIR:%=-I%)
 LFLAGS       := -nologo -machine:ix86 $(LINKDEBUG)
 ROOTGLIBS    := $(shell root-config --glibs)
 QTGSILIBS    := $(QTLIB) $(ROOTGLIBS) '$(ROOTSYS)\lib\libqtgsi.lib'
diff --git a/gui/qtgsi/test/example1/qtroot.cpp b/gui/qtgsi/test/example1/qtroot.cpp
index 151bce84383..e16ade709d2 100644
--- a/gui/qtgsi/test/example1/qtroot.cpp
+++ b/gui/qtgsi/test/example1/qtroot.cpp
@@ -3,40 +3,64 @@
 *****************************************************************************/
 
 #include "qtroot.h"
+
+#if QT_VERSION >= 0x40000
+//Added by qt3to4:
+#include <QCloseEvent>
+#include "q3toolbar.h"
+#include "q3filedialog.h"
+#include "q3strlist.h"
+#include "q3popupmenu.h"
+#include "q3intdict.h"
+#include "q3action.h"
+#include "q3toolbar.h"
+#include "qnamespace.h"
+#include "q3filedialog.h"
+#include "q3whatsthis.h"
+#include "Q3MimeSourceFactory"
+#else
+#include "qfiledialog.h"
+#include "qstrlist.h"
+#include "qpopupmenu.h"
+#include "qintdict.h"
+#include "qaction.h"
+#include "qtoolbar.h"
+#include "qnamespace.h"
+#include "qfiledialog.h"
+#include "qwhatsthis.h"
+#include "qkeycode.h"
+typedef QToolBar Q3ToolBar;
+typedef QPopupMenu Q3PopupMenu;
+typedef QAction Q3Action;
+typedef QWhatsThis Q3WhatsThis;
+typedef QFileDialog Q3FileDialog;
+typedef QMimeSourceFactory Q3MimeSourceFactory;
+#endif
+
 #include "stdlib.h"
 #include "qevent.h"
 #include "qpainter.h"
 #include "qprinter.h"
-#include "qtoolbar.h"
 #include "qtoolbutton.h"
 #include "qspinbox.h"
 #include "qtooltip.h"
 #include "qrect.h"
 #include "qpoint.h"
 #include "qcolordialog.h"
-#include "qfiledialog.h"
 #include "qcursor.h"
 #include "qimage.h"
-#include "qstrlist.h"
-#include "qpopupmenu.h"
-#include "qintdict.h"
 #include "qpushbutton.h"
-#include "qaction.h"
 #include "Riostream.h"
 using namespace std;
 #include "qdial.h"
 #include "qapplication.h"
 #include "qimage.h"
 #include "qpixmap.h"
-#include "qtoolbar.h"
 #include "qtoolbutton.h"
 #include "qmenubar.h"
-#include "qkeycode.h"
 #include "qfile.h"
-#include "qfiledialog.h"
 #include "qstatusbar.h"
 #include "qmessagebox.h"
-#include "qwhatsthis.h"
 #include "qdialog.h"
 #include "qlabel.h"
 
@@ -47,8 +71,6 @@ using namespace std;
 #include "qtbuttonsupdate.xpm"
 #include "qtbuttonsclear.xpm"
 
-
-
 #include "TPad.h"
 #include "TList.h"
 #include "TObject.h"
@@ -92,67 +114,62 @@ const char* clearHisto = " clear histograms ";
 
 
 ApplicationWindow::ApplicationWindow()
-    : QMainWindow( 0, "example application main window", WDestructiveClose )
+    : Q3MainWindow( 0, "example application main window", Qt::WDestructiveClose )
 {
    // create a printer
    printer = new QPrinter;
    // create user interface actions
-   QAction *fileNewAction, *fileOpenAction, *fileSaveAction,
-           *fileSaveAsAction, *filePrintAction, *fileCloseAction,
-           *fileQuitAction;
 
-   fileNewAction = new QAction( "New", "&New", CTRL+Key_N, this, "new" );
+   Q3Action *fileNewAction = new Q3Action( "New", "&New", Qt::CTRL+Qt::Key_N, this, "new" );
+
    connect( fileNewAction, SIGNAL( activated() ) , this, SLOT( newDoc() ) );
 
-   fileOpenAction = new QAction( "Open File", QPixmap( fileopen ), "&Open", CTRL+Key_O, this, "open" );
+   Q3Action *fileOpenAction = new Q3Action( "Open File", QPixmap( fileopen ), "&Open", Qt::CTRL+Qt::Key_O, this, "open" );
    connect( fileOpenAction, SIGNAL( activated() ) , this, SLOT( load() ) );
-   QMimeSourceFactory::defaultFactory()->setPixmap( "fileopen", QPixmap( fileopen ) );
+   Q3MimeSourceFactory::defaultFactory()->setPixmap( "fileopen", QPixmap( fileopen ) );
    fileOpenAction->setWhatsThis( fileOpenText );
 
-   fileSaveAction = new QAction( "Save File", QPixmap( filesave ), "&Save", CTRL+Key_S, this, "save" );
+   Q3Action *fileSaveAction = new Q3Action( "Save File", QPixmap( filesave ), "&Save", Qt::CTRL+Qt::Key_S, this, "save" );
    connect( fileSaveAction, SIGNAL( activated() ) , this, SLOT( save() ) );
    fileSaveAction->setWhatsThis( fileSaveText );
 
-   fileSaveAsAction = new QAction( "Save File As", "Save &as", 0,  this, "save as" );
+   Q3Action *fileSaveAsAction = new Q3Action( "Save File As", "Save &as", 0,  this, "save as" );
    connect( fileSaveAsAction, SIGNAL( activated() ) , this, SLOT( saveAs() ) );
    fileSaveAsAction->setWhatsThis( fileSaveText );
 
-   filePrintAction = new QAction( "Print File", QPixmap( fileprint ), "&Print", CTRL+Key_P, this, "print" );
+   Q3Action *filePrintAction = new Q3Action( "Print File", QPixmap( fileprint ), "&Print", Qt::CTRL+Qt::Key_P, this, "print" );
    connect( filePrintAction, SIGNAL( activated() ) , this, SLOT( print() ) );
    filePrintAction->setWhatsThis( filePrintText );
 
-   fileCloseAction = new QAction( "Close", "&Close", CTRL+Key_W, this, "close" );
+   Q3Action *fileCloseAction = new Q3Action( "Close", "&Close", Qt::CTRL+Qt::Key_W, this, "close" );
    connect( fileCloseAction, SIGNAL( activated() ) , this, SLOT( close() ) );
 
-   fileQuitAction = new QAction( "Quit", "&Quit", CTRL+Key_Q, this, "quit" );
+   Q3Action *fileQuitAction = new Q3Action( "Quit", "&Quit", Qt::CTRL+Qt::Key_Q, this, "quit" );
    connect( fileQuitAction, SIGNAL( activated() ) , qApp, SLOT( quit() ) );
 
    // create button for histo handling
-   QAction *Update_histo, *clear_histo;
-   Update_histo = new QAction("Update Histo",QPixmap("qtbuttonsupdate.xpm"),"&Update", CTRL+Key_0, this, "update");
+   Q3Action *Update_histo = new Q3Action("Update Histo",QPixmap("qtbuttonsupdate.xpm"),"&Update", Qt::CTRL+Qt::Key_0, this, "update");
    connect( Update_histo, SIGNAL( activated() ) , this, SLOT( execute() ) );
-   QMimeSourceFactory::defaultFactory()->setPixmap( "update", QPixmap("qtbuttonsupdate.xpm" ) );
+   Q3MimeSourceFactory::defaultFactory()->setPixmap( "update", QPixmap("qtbuttonsupdate.xpm" ) );
    Update_histo->setWhatsThis( updateHisto );
 
-   clear_histo = new QAction("Clear Histo",QPixmap("qtbuttonsclear.xpm"),"&Clear", CTRL+Key_0, this, "clear");
-   connect( clear_histo, SIGNAL( activated() ) , this, SLOT( clear_histo() ) );
-   QMimeSourceFactory::defaultFactory()->setPixmap( "clear", QPixmap("qtbuttonsclear.xpm" ) );
+   Q3Action *clear_histo = new Q3Action("Clear Histo",QPixmap("qtbuttonsclear.xpm"),"&Clear", Qt::CTRL+Qt::Key_0, this, "clear");   connect( clear_histo, SIGNAL( activated() ) , this, SLOT( clear_histo() ) );
+   Q3MimeSourceFactory::defaultFactory()->setPixmap( "clear", QPixmap("qtbuttonsclear.xpm" ) );
    clear_histo->setWhatsThis( clearHisto );
 
    // populate a tool bar with some actions
 
-   QToolBar* fileTools = new QToolBar( this, "file operations" );
+   Q3ToolBar* fileTools = new Q3ToolBar( this, "file operations" );
    fileTools->setLabel( tr( "File Operations" ) );
    fileOpenAction->addTo( fileTools );
    fileSaveAction->addTo( fileTools );
    filePrintAction->addTo( fileTools );
    Update_histo->addTo ( fileTools );
    clear_histo->addTo ( fileTools );
-   (void)QWhatsThis::whatsThisButton( fileTools );
-
+   (void)Q3WhatsThis::whatsThisButton( fileTools );
    // popuplate a menu with all actions
 
-   QPopupMenu * file = new QPopupMenu( this );
+   Q3PopupMenu * file = new Q3PopupMenu( this );
    menuBar()->insertItem( "&File", file );
    fileNewAction->addTo( file );
    fileOpenAction->addTo( file );
@@ -166,21 +183,21 @@ ApplicationWindow::ApplicationWindow()
 
    // add a help menu
 
-   QPopupMenu * help = new QPopupMenu( this );
+   Q3PopupMenu * help = new Q3PopupMenu( this );
    menuBar()->insertSeparator();
    menuBar()->insertItem( "&Help", help );
-   help->insertItem( "&About", this, SLOT(about()), Key_F1 );
+   help->insertItem( "&About", this, SLOT(about()), Qt::Key_F1 );
    help->insertItem( "About &Qt", this, SLOT(aboutQt()) );
    help->insertSeparator();
-   help->insertItem( "What's &This", this, SLOT(whatsThis()), SHIFT+Key_F1 );
+   help->insertItem( "What's &This", this, SLOT(whatsThis()), Qt::SHIFT+Qt::Key_F1 );
 
    // create and define the ROOT Canvas central widget
    tab = new QTabWidget(this);
    tab->show();
    setCentralWidget( tab );
 
-   QMainWindow *win1 = new QMainWindow( 0, "tab1 main window", WDestructiveClose );
-   QMainWindow *win2 = new QMainWindow( 0, "tab2 main window", WDestructiveClose );
+   Q3MainWindow *win1 = new Q3MainWindow( 0, "tab1 main window", Qt::WDestructiveClose );
+   Q3MainWindow *win2 = new Q3MainWindow( 0, "tab2 main window", Qt::WDestructiveClose );
    aCanvas = new TQRootCanvas(this, win1,"Qt&Root");
    aCanvas2 = new TQRootCanvas(this, win2,"Qt&Root");
 
@@ -317,7 +334,7 @@ void ApplicationWindow::newDoc()
 
 void ApplicationWindow::load()
 {
-   QString fn = QFileDialog::getOpenFileName(QString::null, QString::null, this);
+   QString fn = Q3FileDialog::getOpenFileName(QString::null, QString::null, this);
    if ( !fn.isEmpty() )
       load( fn );
    else
diff --git a/gui/qtgsi/test/example1/qtroot.h b/gui/qtgsi/test/example1/qtroot.h
index 711bffe4c76..a9b1343587e 100644
--- a/gui/qtgsi/test/example1/qtroot.h
+++ b/gui/qtgsi/test/example1/qtroot.h
@@ -3,12 +3,24 @@
 
 #include "Riostream.h"
 using namespace std;
-#include "qmainwindow.h"
+
 #include "qprinter.h"
 #include "qstring.h"
 #include "qthread.h"
 #include "qtabwidget.h"
 
+#if QT_VERSION >= 0x40000
+//Added by qt3to4:
+#include <QPaintEvent>
+#include <QResizeEvent>
+#include <QMouseEvent>
+#include <QCloseEvent>
+#include "q3mainwindow.h"
+#else
+#include "qmainwindow.h"
+typedef QMainWindow Q3MainWindow;
+#endif
+
 #include "TObject.h"
 #include "TCanvas.h"
 #include "TVirtualX.h"
@@ -57,7 +69,7 @@ class QPaintEvent;
 */
 
 
-class ApplicationWindow: public QMainWindow
+class ApplicationWindow: public Q3MainWindow
 {
     Q_OBJECT
 public:
diff --git a/gui/qtgsi/test/example2/Makefile.win b/gui/qtgsi/test/example2/Makefile.win
index a1deb3cc31f..63d1f3dd8ca 100644
--- a/gui/qtgsi/test/example2/Makefile.win
+++ b/gui/qtgsi/test/example2/Makefile.win
@@ -6,6 +6,7 @@ include $(ROOTSYS)/config/Makefile.config
 ####### Compiler, tools and options
 
 is_debug := $(findstring debug,$(strip $(shell root-config --config)))
+QT4      := $(findstring QtCore, $(QTINCDIR))
 
 OutPutOpt     = -out:
 CXX           = cl
@@ -14,18 +15,22 @@ LD            = link
 ifdef is_debug
 # Debugging:
 OPTIMIZE  := -Zi -MDd
-LINKDEBUG := -debug
+LINKDEBUG := -debug -nodefaultlib:msvcrt.lib
 else
 # Full optimization:
 OPTIMIZE  := -Ox -MD
 endif
 
-QTCXXFLAGS   := -GR $(OPTIMIZE) -W3 -nologo $(shell root-config --cflags) -D_CRT_SECURE_NO_DEPRECATE -DQT_DLL -DQT_THREAD_SUPPORT
+QTCXXFLAGS   := -GR $(OPTIMIZE) -W3 -nologo $(shell root-config --cflags) -FIw32pragma.h -D_CRT_SECURE_NO_DEPRECATE -DQT_DLL -DQT_THREAD_SUPPORT -DQT3_SUPPORT $(QTINCDIR:%=-I%)
 LFLAGS       := -nologo -machine:ix86 $(LINKDEBUG)
 ROOTGLIBS    := $(shell root-config --glibs)
 QTGSILIBS    := $(QTLIB) $(ROOTGLIBS) '$(ROOTSYS)\lib\libqtgsi.lib'
 
+ifeq (,$(QT4))
 UIC         = '$(QTDIR)\bin\uic.exe'
+else
+UIC         = '$(QTDIR)\bin\uic3.exe'
+endif
 
 ####### Files
 
diff --git a/gui/qtgsi/test/example2/qtrootexample.pro b/gui/qtgsi/test/example2/qtrootexample.pro
index b35211b6cfc..c9e27e3101a 100644
--- a/gui/qtgsi/test/example2/qtrootexample.pro
+++ b/gui/qtgsi/test/example2/qtrootexample.pro
@@ -1,9 +1,13 @@
+
+QT += qt3support
+CONFIG += uic3
+
 SOURCES	+= main.cpp
 FORMS	= qtrootexample1.ui 
 IMAGES	= images/qtroot_canvas.png images/h1_t.png images/h2_t.png 
 TEMPLATE	=app
 CONFIG	+= qt warn_on thread 
 INCLUDEPATH	+= $(ROOTSYS)/include
-LIBS	+= -L$(ROOTSYS)/lib -lCore -lCint -lHist -lGraf -lGraf3d -lGpad -lGui -lTree -lRint -lPostscript -lMatrix -lPhysics -lQtGSI -lnsl -lm -ldl -rdynamic $(SYSLIBS)
+LIBS	+= -L$(ROOTSYS)/lib -lCore -lRIO -lNet -lMathCore -lCint -lHist -lGraf -lGraf3d -lGpad -lGui -lTree -lRint -lPostscript -lMatrix -lPhysics -lQtGSI -lnsl -lm -ldl -rdynamic $(SYSLIBS)
 DBFILE	= qtrootexample.db
 LANGUAGE	= C++
diff --git a/gui/qtgsi/test/example2/qtrootexample1.ui.h b/gui/qtgsi/test/example2/qtrootexample1.ui.h
index 0eebf11c626..e06db515b40 100644
--- a/gui/qtgsi/test/example2/qtrootexample1.ui.h
+++ b/gui/qtgsi/test/example2/qtrootexample1.ui.h
@@ -7,30 +7,43 @@
 *****************************************************************************/
 #include "TCanvas.h"
 #include "TClass.h"
+#include "TFile.h"
+
+#if QT_VERSION >= 0x40000
+//Added by qt3to4:
+#include <QPixmap>
+#include <QMimeSource>
+#include <Q3MimeSourceFactory>
+#include <Q3ImageDrag>
+#include <Q3ListViewItem>
+typedef Q3ListViewItem QListViewItem;
+typedef Q3DragObject QDragObject;
+typedef Q3TextDrag QTextDrag;
+typedef Q3ImageDrag QImageDrag;
+typedef Q3MimeSourceFactory QMimeSourceFactory;
+#endif
 
 static QPixmap uic_load_pixmap( const QString &name )
 {
-    const QMimeSource *m = QMimeSourceFactory::defaultFactory()->data( name );
-    if ( !m )
-	return QPixmap();
-    QPixmap pix;
-    QImageDrag::decode( m, pix );
-    return pix;
+   const QMimeSource *m = QMimeSourceFactory::defaultFactory()->data( name );
+   if ( !m )
+      return QPixmap();
+   QPixmap pix;
+   QImageDrag::decode( m, pix );
+   return pix;
 }
 
 void qtrootexample1::init()
 {
-    TKey *key;
-    TFile *fxDiskFile;
+   TKey *key;
+   TFile *fxDiskFile;
     
    (TQRootCanvas1->GetCanvas())->Divide(2,2);
-      fxDiskFile = new TFile("test.root");
-    TIter next(fxDiskFile->GetListOfKeys());
-    
-    while((key = (TKey*) next())) {
-	AddItemToListView1(key->ReadObj());
-    }
-    
+   fxDiskFile = new TFile("test.root");
+   TIter next(fxDiskFile->GetListOfKeys());
+   while ((key = (TKey*) next())) {
+      AddItemToListView1(key->ReadObj());
+   }
 }
 
 void qtrootexample1::destroy()
@@ -40,21 +53,21 @@ void qtrootexample1::destroy()
 
 void qtrootexample1::ListView1_mouseButtonPressed( int, QListViewItem *SelectedItem, const QPoint &, int )
 {
-  if(SelectedItem!=0){
-		QDragObject *d = new QTextDrag(SelectedItem->text(0),ListView1);
-		d->dragCopy();
-    }
+   if (SelectedItem!=0) {
+      QDragObject *d = new QTextDrag(SelectedItem->text(0),ListView1);
+      d->dragCopy();
+   }
 }
 
 void qtrootexample1::AddItemToListView1(TObject *Key)
 {
-     if( Key->IsA()->InheritsFrom("TH2") ) {
-	 QListViewItem * item1 = new QListViewItem(ListView1,  Key->GetName() ,"TH2");
-	 item1->setPixmap( 0, uic_load_pixmap( "h2_t.png" ) );
-     }else if (Key->IsA()->InheritsFrom("TH1")) {
-	 QListViewItem * item1 = new QListViewItem(ListView1,   Key->GetName(),"TH1");
-	 item1->setPixmap( 0, uic_load_pixmap( "h1_t.png" ) );
-     }
-    
+   if( Key->IsA()->InheritsFrom("TH2") ) {
+      QListViewItem * item1 = new QListViewItem(ListView1, Key->GetName() ,"TH2");
+      item1->setPixmap( 0, uic_load_pixmap( "h2_t.png" ) );
+   }
+   else if (Key->IsA()->InheritsFrom("TH1")) {
+      QListViewItem * item1 = new QListViewItem(ListView1, Key->GetName(),"TH1");
+      item1->setPixmap( 0, uic_load_pixmap( "h1_t.png" ) );
+   }
 }
 
-- 
GitLab