summaryrefslogtreecommitdiffstats
path: root/examples/qtapp/myqt.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 17:43:19 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-02-24 17:43:19 +0000
commit0292059f4a16434600564cfa3f0ad2309a508a54 (patch)
treed95953cd53011917c4df679b96aedca39401b54f /examples/qtapp/myqt.cpp
downloadlibksquirrel-0292059f4a16434600564cfa3f0ad2309a508a54.tar.gz
libksquirrel-0292059f4a16434600564cfa3f0ad2309a508a54.zip
Added libksquirrel for KDE3
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/libraries/libksquirrel@1095624 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'examples/qtapp/myqt.cpp')
-rw-r--r--examples/qtapp/myqt.cpp111
1 files changed, 111 insertions, 0 deletions
diff --git a/examples/qtapp/myqt.cpp b/examples/qtapp/myqt.cpp
new file mode 100644
index 0000000..9cd4b80
--- /dev/null
+++ b/examples/qtapp/myqt.cpp
@@ -0,0 +1,111 @@
+#include <qlibrary.h>
+#include <qapplication.h>
+#include <qfile.h>
+
+#include <qimage.h>
+
+#include "myqt.h"
+
+#include "ksquirrel-libs/fmt_utils.h"
+#include "ksquirrel-libs/error.h"
+
+MyQT::MyQT(QWidget *parent, const char *name) : QLabel(parent, name)
+{
+ setAlignment(Qt::AlignCenter);
+}
+
+MyQT::~MyQT()
+{}
+
+QPixmap MyQT::loadImage()
+{
+ QLibrary lib("/usr/lib/ksquirrel-libs/libkls_bmp.so");
+ lib.load();
+
+ if(!lib.isLoaded())
+ {
+ qWarning("Can't load BMP library.");
+ qApp->quit();
+ }
+
+ int i = 0;
+ fmt_info finfo;
+ RGBA *image;
+ int current = 0;
+
+ codec_create = (fmt_codec_base*(*)())lib.resolve("codec_create");
+ codec_destroy = (void (*)(fmt_codec_base*))lib.resolve("codec_destroy");
+
+ if(!codec_create || !codec_destroy)
+ {
+ qWarning("Library corrupted.");
+ lib.unload();
+ qApp->quit();
+ }
+
+ const char *s = "../w3.bmp";
+
+ if(!QFile::exists(s))
+ {
+ qWarning("Can't find example image.");
+ lib.unload();
+ qApp->quit();
+ }
+
+ codeK = codec_create();
+
+ i = codeK->read_init(s);
+
+ if(i != SQE_OK)
+ {
+ codeK->read_close();
+ return QPixmap();
+ }
+
+ i = codeK->read_next();
+
+ finfo = codeK->information();
+
+ if(i != SQE_OK)
+ {
+ codeK->read_close();
+ return QPixmap();
+ }
+
+ image = (RGBA*)calloc(finfo.image[current].w * finfo.image[current].h, sizeof(RGBA));
+
+ if(!image)
+ {
+ codeK->read_close();
+ return QPixmap();
+ }
+
+ memset(image, 255, finfo.image[current].w * finfo.image[current].h * sizeof(RGBA));
+
+ RGBA *scan;
+
+ for(int pass = 0;pass < finfo.image[current].passes;pass++)
+ {
+ codeK->read_next_pass();
+
+ for(int j = 0;j < finfo.image[current].h;j++)
+ {
+ scan = image + j * finfo.image[current].w;
+ codeK->read_scanline(scan);
+ }
+ }
+
+ if(finfo.image[current].needflip)
+ fmt_utils::flipv((char*)image, finfo.image[current].w * sizeof(RGBA), finfo.image[current].h);
+
+ codeK->read_close();
+
+ QImage im((unsigned char*)image, finfo.image[current].w, finfo.image[current].h, 32, 0, 0, QImage::LittleEndian);
+
+ return QPixmap(im.swapRGB());
+}
+
+void MyQT::bind()
+{
+ setPixmap(loadImage());
+}