summaryrefslogtreecommitdiffstats
path: root/examples/qtapp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/qtapp')
-rw-r--r--examples/qtapp/main.cpp24
-rw-r--r--examples/qtapp/myqt.cpp111
-rw-r--r--examples/qtapp/myqt.h33
-rw-r--r--examples/qtapp/qtapp.pro11
4 files changed, 179 insertions, 0 deletions
diff --git a/examples/qtapp/main.cpp b/examples/qtapp/main.cpp
new file mode 100644
index 0000000..91c4052
--- /dev/null
+++ b/examples/qtapp/main.cpp
@@ -0,0 +1,24 @@
+#include "myqt.h"
+
+#include <qapplication.h>
+#include <qvbox.h>
+#include <qpushbutton.h>
+
+int main(int argc, char **argv)
+{
+ QApplication a(argc, argv);
+
+ QVBox *v = new QVBox;
+ QPushButton *b = new QPushButton("Show w3.bmp !", v);
+ MyQT *qt = new MyQT(v);
+
+ QVBox::connect(b, SIGNAL(clicked()), qt, SLOT(bind()));
+
+ v->setStretchFactor(qt, 1);
+
+ a.setMainWidget(v);
+ v->resize(512, 256);
+ v->show();
+
+ return a.exec();
+}
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());
+}
diff --git a/examples/qtapp/myqt.h b/examples/qtapp/myqt.h
new file mode 100644
index 0000000..9e63d4f
--- /dev/null
+++ b/examples/qtapp/myqt.h
@@ -0,0 +1,33 @@
+#ifndef GLWIDGET_H
+#define GLWIDGET_H
+
+#include <qlabel.h>
+
+#include <csetjmp>
+
+#include "ksquirrel-libs/fmt_types.h"
+#include "ksquirrel-libs/fileio.h"
+#include "ksquirrel-libs/fmt_codec_base.h"
+
+class MyQT : public QLabel
+{
+ Q_OBJECT
+
+ public:
+ MyQT(QWidget *parent = 0, const char *name = 0);
+ ~MyQT();
+
+ QPixmap loadImage();
+
+ public slots:
+ void bind();
+
+ private:
+ fmt_codec_base* (*codec_create)();
+ void (*codec_destroy)(fmt_codec_base*);
+
+ fmt_codec_base *codeK;
+
+};
+
+#endif
diff --git a/examples/qtapp/qtapp.pro b/examples/qtapp/qtapp.pro
new file mode 100644
index 0000000..9c658c0
--- /dev/null
+++ b/examples/qtapp/qtapp.pro
@@ -0,0 +1,11 @@
+######################################################################
+# Automatically generated by qmake (1.06c) Thu Mar 3 02:54:53 2005
+######################################################################
+
+TEMPLATE = app
+INCLUDEPATH += .
+INCLUDEPATH += ../../kernel/include
+
+# Input
+HEADERS += myqt.h
+SOURCES += main.cpp myqt.cpp ../../kernel/ksquirrel-libs/fmt_utils.cpp