--- Portfile.orig	2010-10-21 15:00:56.000000000 +0200
+++ Portfile	2010-10-29 02:19:11.000000000 +0200
@@ -6,6 +6,7 @@
 
 name                qtiplot
 version             0.9.8.3
+revision            1
 categories          aqua science
 maintainers         jonas openmaintainer
 
@@ -20,20 +21,36 @@
 platforms           darwin
 homepage            http://soft.proindependent.com/qtiplot.html
 master_sites        http://download.berlios.de/qtiplot/
-use_bzip2           yes
 
-depends_lib-append  port:muparser \
+distfiles           ${distname}.zip \
+                    QTeXEngine-0.2-opensource.zip \
+                    liborigin2-13092010.zip
+
+depends_lib-append  path:bin/qmake-mac:qt4-mac \
+                    port:muparser \
                     port:boost \
                     port:gsl \
                     port:libpng \
                     port:zlib
 
-checksums           md5     317f45128eef208b2d6b9c28a2e3fa6e \
-                    sha1    e5ffdd25f1f69611f3f39a0b22e8c23959ab51e1 \
-                    rmd160  864e45bd9e74f3dd7526c84d387ab88438c1ee70
+checksums           qtiplot-0.9.8.3.zip \
+                    md5     c90e9dc08e03dc1cd0db19dfe8941f0c \
+                    sha1    35dec539fb20b8c7ca121cca11f7b800b4ff0c6b \
+                    rmd160  2b0fd5b710d2752a1a413f83cbee9daf1e88edbf \
+                    QTeXEngine-0.2-opensource.zip \
+                    md5     fc2fe7f3fdb9e06c00d1f5c3c3e68920 \
+                    sha1    b484a4da7a0f3103e188539bfa6c1910dc9b55ca \
+                    rmd160  76ff1f2f96cd6df0ea5e6965013e0db452c55f09 \
+                    liborigin2-13092010.zip \
+                    md5     e2b41c4d8a1e2d357dd2b5b331d31375 \
+                    sha1    3f17d5a8c484ddb864a29a91a94d677b0b3b18d7 \
+                    rmd160  df7f4bafc1b9815c5921c09b435f431d8a1947e6
+
+patchfiles          patch-ApplicationWindow.diff
 
-patchfiles          patch-qtiplot-qtiplot.pro \
-                    patch-qtiplot-src-scripting-scripting.pri
+use_zip             yes
+
+universal_variant   no
 
 use_parallel_build  yes
 
@@ -52,7 +69,19 @@
     # till upstream catches up, we use a local copy of qwt
     puts $confFD "QWT_INCLUDEPATH = \$\$QTI_ROOT/3rdparty/qwt/src"
     puts $confFD "QWT_LIBS = \$\$QTI_ROOT/3rdparty/qwt/lib/libqwt.a"
+    puts $confFD "QWT3D_INCLUDEPATH = \$\$QTI_ROOT/3rdparty/qwtplot3d/include"
+    puts $confFD "unix:QWT3D_LIBS = \$\$QTI_ROOT/3rdparty/qwtplot3d/lib/libqwtplot3d.a"
     puts $confFD "LIBPNG_LIBS = -lpng"
+    puts $confFD "TEX_ENGINE_INCLUDEPATH = \$\$QTI_ROOT/3rdparty/QTeXEngine/src"
+    puts $confFD "TEX_ENGINE_LIBS = \$\$QTI_ROOT/3rdparty/QTeXEngine/libQTeXEngine.a"
+    if {[variant_isset origin]} {
+      puts $confFD "LIBORIGIN_INCLUDEPATH = \$\$QTI_ROOT/3rdparty/liborigin2"
+      puts $confFD "LIBORIGIN_LIBS = \$\$QTI_ROOT/3rdparty/liborigin2/liborigin2.a"
+    }
+
+    # linking to deprecated library
+    reinplace "s|<QAssistantClient>|\"qassistantclient.h\"|g" ${worksrcpath}/qtiplot/src/core/ApplicationWindow.cpp
+
     # target specific configuration
     puts $confFD "contains( TARGET, qtiplot ) \{"
     puts $confFD "SCRIPTING_LANGS += muParser"; # currently you can't build without
@@ -71,6 +100,28 @@
     import sys, os.path\\
     sys.path.append(os.path.dirname(__file__))
     " ${worksrcpath}/qtiplot/qtiplotrc.py
+
+    if {[variant_isset origin]} {
+      # prepare liborigin2
+      copy ${workpath}/liborigin2 ${worksrcpath}/3rdparty/liborigin2
+      reinplace "s|INCLUDEPATH += ../boost|INCLUDEPATH += ${prefix}/include|g" ${worksrcpath}/3rdparty/liborigin2/liborigin2.pro
+      reinplace "s|lboost_thread|lboost_thread-mt|g" ${worksrcpath}/3rdparty/liborigin2/liborigin2.pro
+      reinplace "s|liborigin|liborigin2|g" ${worksrcpath}/qtiplot/src/origin/origin.pri
+    }
+
+    # prepare qtexengine
+    copy ${workpath}/QTeXEngine ${worksrcpath}/3rdparty/QTexEngine
+
+    # add 3rdparty to compilation
+    reinplace "s|3rdparty/qwtplot3d \|3rdparty/qwtplot3d 3rdparty/QTeXEngine \|g" \
+    ${worksrcpath}/qtiplot.pro
+    if {[variant_isset origin]} {
+      reinplace "s|3rdparty/QTeXEngine \|3rdparty/QTeXEngine 3rdparty/liborigin2 \|g" \
+      ${worksrcpath}/qtiplot.pro
+    }
+
+    # use system-wide libraries
+    reinplace "s|#unix|unix|g" ${worksrcpath}/qtiplot/qtiplot.pro
 }
 
 configure.pre_args  "PREFIX=${prefix}"
@@ -102,6 +153,11 @@
         ${plugin_dir}
 }
 
+variant origin description "add support for originlab files" {
+    depends_lib-append port:treehh
+    patchfiles-append patch-importOPJ.cpp.diff
+}
+
 variant python25 conflicts python26 description "add support for python26 scripting" {
     depends_lib-append port:python25 \
                        port:py25-sip \
