1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
// QWeb - An SGML Web Browser
// Copyright (C) 1997 Sean Vyain
// svyain@mail.tds.net
// smvyain@softart.com
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
extern "C" {
#include <stdio.h>
#include <stdlib.h>
}
#include <qpainter.h>
#include <qpixmap.h>
#include "Browser.h"
#include "DownloadRenderer.h"
#include "FormRenderer.h"
#include "ImageRenderer.h"
#include "Request.h"
extern "C" {
extern char* GIF_DATA;
extern int GIF_DATA_INDEX;
extern int GIF_DATA_LENGTH;
extern unsigned char* GIF_IMAGE;
extern void ReadGIF( int );
#define MAXCOLORMAPSIZE 256
extern struct GifScreen_struct {
unsigned int Width;
unsigned int Height;
unsigned char ColorMap[3][MAXCOLORMAPSIZE];
unsigned int BitPixel;
unsigned int ColorResolution;
unsigned int Background;
unsigned int AspectRatio;
} GifScreen;
extern struct Gif89_struct {
int transparent;
int delayTime;
int inputFlag;
int disposal;
} Gif89;
};
ImageRenderer::ImageRenderer( QString src,
int width,
int height,
bool ismap,
bool isSubmit,
QString url,
Browser* browser,
int clipWidth,
QWidget* parent,
const char* name )
: FormObjectRenderer( browser, clipWidth, parent, name ),
_src( src.copy() ),
_pixmap( 0 ),
_ismap( ismap ),
_url( url ),
_x( 0 ),
_y( 0 ),
_isSubmit( isSubmit )
{
// printf( "ImageRenderer::ImageRenderer() -- src = '%s', ismap = %d\n", src.data(), ismap );
if ( ( width >= 0 ) && ( height >= 0 ) ) {
resize( width, height );
_minimumWidth = width;
_maximumWidth = width;
}
Request* req = new Request( Url( &browser->baseUrl(), src ), browser );
connect( req, SIGNAL( status( QString ) ) , browser, SLOT( status( QString ) ) );
connect( req, SIGNAL( data( const char*, int ) ), this , SLOT( data( const char*, int ) ) );
connect( req, SIGNAL( endOfData() ) , this , SLOT( endOfData() ) );
if ( req->open() ) {
browser->registerRequest( req );
} else {
delete req;
}
}
ImageRenderer::~ImageRenderer()
{
delete _pixmap;
}
QString ImageRenderer::value()
{
QString nm = name();
if ( nm.length() == 0 ) {
return "";
}
Url::encode( nm );
QString tmp;
tmp.sprintf( "%s.x=%d&%s.y=%d", nm.data(), _x, nm.data(), _y );
return tmp;
}
void ImageRenderer::reset()
{
}
void ImageRenderer::redraw()
{
// Do I need to do anything?
if ( !_needRedraw ) return;
_minimumWidth = width();
_maximumWidth = width();
paintEvent( 0 );
_needRedraw = FALSE;
}
void ImageRenderer::paintEvent( QPaintEvent* )
{
if ( _pixmap ) {
bitBlt( this, 0, 0, _pixmap, 0, 0, _pixmap->width(), _pixmap->height(), CopyROP );
} else {
QPainter p;
p.begin( this );
p.setPen( QColor( "black" ) );
p.drawRect( 0, 0, width(), height() );
p.setFont( QFont( "helvetica" ) );
p.drawText( 4, 16, _src );
p.end();
}
}
void ImageRenderer::data( const char* bytes, int length )
{
int i;
int oldSize = _data.size();
_data.resize( oldSize + length );
for ( i = 0; i < length; i++ ) {
_data[oldSize+i] = bytes[i];
}
}
void ImageRenderer::endOfData()
{
GIF_DATA = _data.data();
GIF_DATA_INDEX = 0;
GIF_DATA_LENGTH = _data.size();
if ( !_data.size() ) return;
ReadGIF( 1 );
if ( !GifScreen.Width || !GifScreen.Height ) {
// Not a GIF file.
return;
}
// Copy image to pixmap.
_pixmap = new QPixmap( GifScreen.Width, GifScreen.Height );
int index, r, g, b;
uint x, y;
QPainter p;
p.begin( _pixmap );
for ( y = 0; y < GifScreen.Height; y++ ) {
for ( x = 0; x < GifScreen.Width; x++ ) {
index = GIF_IMAGE[y*GifScreen.Width+x];
r = GifScreen.ColorMap[0][index];
g = GifScreen.ColorMap[1][index];
b = GifScreen.ColorMap[2][index];
p.setPen( QColor( r, g, b ) );
p.drawPoint( x, y );
}
}
p.end();
free( GIF_IMAGE );
resize( GifScreen.Width, GifScreen.Height );
// redraw();
// paintEvent( 0 );
needRedraw();
}
void ImageRenderer::mouseReleaseEvent( QMouseEvent* e )
{
if ( e->button() == LeftButton ) {
if ( _isSubmit ) {
// An INPUT image on a FORM.
_x = e->x();
_y = e->y();
FormRenderer* f = form();
if ( f ) {
f->submit( this );
}
} else {
// Normal inlined image.
if ( _url.length() ) {
browser()->stop();
if ( _ismap ) {
Url url( &browser()->baseUrl(), _url );
QString tmp;
tmp.sprintf( "%d,%d", e->pos().x(), e->pos().y() );
url.setQuery( tmp );
if ( e->state() & ShiftButton ) {
DownloadRenderer* dr = new DownloadRenderer( url );
dr->show();
} else {
browser()->open( url.url() );
}
} else {
if ( e->state() & ShiftButton ) {
DownloadRenderer* dr = new DownloadRenderer( Url( &browser()->baseUrl(), _url ) );
dr->show();
} else {
browser()->open( Url( &browser()->baseUrl(), _url ) );
}
}
}
}
}
}
void ImageRenderer::enterEvent( QEvent* )
{
if ( ( _isSubmit ) || ( _url.length() ) ) {
browser()->status( Url( &browser()->baseUrl(), _url ).url() );
setCursor( crossCursor );
} else {
setCursor( arrowCursor );
}
}
void ImageRenderer::leaveEvent( QEvent* )
{
setCursor( arrowCursor );
}
|