2
// Copyright (C) 1999-2000 Szymon Stefanek (stefanek@tin.it)
4
// This program is FREE software. You can redistribute it and/or
5
// modify it under the terms of the GNU General Public License
6
// as published by the Free Software Foundation; either version 2
7
// of the License, or (at your opinion) any later version.
9
// This program is distributed in the HOPE that it will be USEFUL,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
// See the GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program. If not, write to the Free Software Foundation,
16
// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#define __KVIRC_PLUGIN__
22
#include "kvirc_plugin.h"
24
#include "libkviimage.h"
26
#include "kvi_ircview.h"
27
#include "kvi_locale.h"
28
#include "kvi_malloc.h"
30
#include <qtoolbutton.h>
31
#include <qpopupmenu.h>
33
#include <qfiledialog.h>
35
#include <qfileinfo.h>
37
KviImageView::KviImageView(QWidget * parent)
40
m_pOriginalPixmap = 0;
46
KviImageView::~KviImageView()
48
if(m_pViewedImage)delete m_pViewedImage;
49
if(m_pOriginalPixmap)delete m_pOriginalPixmap;
52
bool KviImageView::loadImage(const char *fName)
55
if(pix.isNull())return false;
56
if(m_pOriginalPixmap)delete m_pOriginalPixmap;
57
m_pOriginalPixmap = new QPixmap(pix);
58
if(m_pViewedImage)delete m_pViewedImage;
59
m_pViewedImage = new QImage();
60
*m_pViewedImage = pix;
62
resizeContents(m_pViewedImage->width(),m_pViewedImage->height());
67
void KviImageView::setZoom(unsigned int zoom)
69
if(!m_pOriginalPixmap)m_uZoom = 100;
71
if(zoom < 1)m_uZoom = 1;
72
if(zoom > 100000)m_uZoom = 100000; //enough ? :)
73
if(m_pViewedImage)delete m_pViewedImage;
74
m_pViewedImage = new QImage();
75
*m_pViewedImage = *m_pOriginalPixmap;
76
int newW = (m_pOriginalPixmap->width() * m_uZoom) / 100;
77
int newH = (m_pOriginalPixmap->height() * m_uZoom) / 100;
78
*m_pViewedImage = m_pViewedImage->smoothScale(newW,newH);
79
resizeContents(m_pViewedImage->width(),m_pViewedImage->height());
83
void KviImageView::drawContents(QPainter *p,int clipx,int clipy,int clipw,int cliph)
85
// debug("%d,%d,%d,%d",clipx,clipy,clipw,cliph);
87
int w = m_pViewedImage->width() - clipx;
88
int h = m_pViewedImage->height() - clipy;
89
if(w > clipw)w = clipw;
90
if(h > cliph)h = cliph;
91
if((w >= 0) && (h >= 0))p->drawImage(clipx,clipy,*m_pViewedImage,clipx,clipy,w,h);
95
static const char * zoom_up_xpm[] = {
316
" s g N.E.+.P E L.M.c. . . ",
317
" d.o.b.7 1 w R l.p x h u M.9. . . . . . . ",
318
" d.D.. m C U.*+z.}.T.$+0 2 W O [. . . . . . . ",
319
" o.. |.@ D &.z #.h.d + {.t.B [.p. . . ",
320
" s o m M ,+F .+k.5.H d C.{.1.=+U 9.} . . ",
321
" 9.7 /+&+(+).'+T j.W.:+c n Y ! f % l ",
322
" ` P 1 /+D H.'+a T j.].#+x.Y.3.f *._.(.N ",
323
" 9 E.w 4 &.T F 8 5 f.a.!.q.g.>+# @.^+k 8. ",
324
" %.P.w r 0.4.k.j.~ !+#+'.Y.3+*.# Z.[ v.8. ",
325
" -.w.R }.| { A t a.; '.e.y.~+@.q :.i -.N. ",
326
" v.E ' >.X X.X.:+!._+<+U y # q [ :.,.G > ",
327
" <.L.x + K.L _ ^./ <+y.y # q [ i ,.;.- +. ",
328
" M.h 6 6 R.2.]+g.3+>+# q [ i ,.e V W ",
329
" < u +t.0 1.[+3.*.# @.[ :.,.e , %.o ",
330
" M.W -+[+3 ! f *.q [ :.,.e ..O.s. ",
331
" M.[.[.S ! f # @.Z.:.i ) ;.` m.b.. ",
332
" r.r.9.% %+}+Z.:.:.;.V %.s.. . . . ",
333
" u r.(.k v.v.I.- m.o . 9.Q.. . ",
334
" $ 8.E P P.E. . 9.Q.. . ",
346
static const char * zoom_none_xpm[] = {
518
" & & & & * = - ; > , ' ) ! ~ & & & ",
519
" & & & & & { ] ^ / ( _ : < [ } & & & & ",
520
" & & & & & & | 1 2 3 4 5 6 7 & & & & & ",
521
" & & & & & & 8 9 0 a b & & & & & & ",
522
" c { & & & & & & d e f & & & & & g h ",
523
" i j k & & & & & & l m & & & & n o p ",
524
" q r s t u v & & & & & & & & & w x y z A ",
525
" B ; C D E F G & & & & & & & & H I J K L ",
526
" M > N O P Q R S & & & & & & T U V W % X ",
527
" Y , Z ` ...+.@.#.& & & & & & V W $.$ - ",
528
" %.' &.*.=.-.;.& & & & & & & & & & >.,.'. ",
529
" ).!.~.{.].^.& & & & & & & & & & & /.(._. ",
530
" :.<.[.}.|.& & & & & 1.2.& & & & & & ",
531
" 3.4.5.6.& & & & 7.8.9.0.a.& & & & & & ",
532
" b.c.& & & & & d.e.f.g.h.i.& & & & & ",
533
" ! & & & & & d.j.f.g.h.i.k.q l.& & & ",
534
" & & & & & m.n.o.p.q.r.s.t.u.v.& & & ",
535
" & & & & w.x.K % $ ,.y.z.A. B.C.D.B.B. ",
536
" & & & E.F.G.H.I.J. B.C.D.B.B. ",
548
static const char * zoom_down_xpm[] = {
769
" s g N.E.+.P E L.M.c. ",
770
" d.o.b.7 1 w R l.p x h u M.9. . . . . . . ",
771
" d.D.. m C U.*+z.}.T.$+0 2 W O [. . . . . . . ",
772
" o.. |.@ D &.z #.h.d + {.t.B [.p. ",
773
" s o m M ,+F .+k.5.H d C.{.1.=+U 9.} ",
774
" 9.7 /+&+(+).'+T j.W.:+c n Y ! f % l ",
775
" ` P 1 /+D H.'+a T j.].#+x.Y.3.f *._.(.N ",
776
" 9 E.w 4 &.T F 8 5 f.a.!.q.g.>+# @.^+k 8. ",
777
" %.P.w r 0.4.k.j.~ !+#+'.Y.3+*.# Z.[ v.8. ",
778
" -.w.R }.| { A t a.; '.e.y.~+@.q :.i -.N. ",
779
" v.E ' >.X X.X.:+!._+<+U y # q [ :.,.G > ",
780
" <.L.x + K.L _ ^./ <+y.y # q [ i ,.;.- +. ",
781
" M.h 6 6 R.2.]+g.3+>+# q [ i ,.e V W ",
782
" < u +t.0 1.[+3.*.# @.[ :.,.e , %.o ",
783
" M.W -+[+3 ! f *.q [ :.,.e ..O.s. ",
784
" M.[.[.S ! f # @.Z.:.i ) ;.` m.b.. ",
785
" r.r.9.% %+}+Z.:.:.;.V %.s.. . . . ",
786
" u r.(.k v.v.I.- m.o . 9.Q.. . ",
787
" $ 8.E P P.E. . 9.Q.. . ",
799
static const char * open_file_xpm[] = {
1016
" . . + @ # $ % & * = - ; > , ' ) ! ~ { ] ^ / ( _ ",
1017
" . + @ : < [ } | 1 2 3 4 5 6 7 8 9 0 a b ^ / c _ d e ",
1018
" f g h i j k l m n o p > q ' r s t u v w x y z A B C ",
1019
" D E . . . . . F G E H I J K L | M n - N O P q Q R S T ~ ",
1020
" U V . . W X U h Y Z [ ` l .= ..3 +.> @.#.7 ) s $.%.a ] ",
1021
" &.Y *.=.-.: ;.>.,.'.).1 !.o ; ~.5 {.' ].^./.(._.:.<.[./ ",
1022
" : < }.|.1.% } 2.m 3.4.5.4 6., 7.8.9.! t 0.a.b b.x c.d._ ",
1023
" i j 1.e.f.* g.2 h.p i.j.6 k.r l.m.n.{ o.p.q.r.c s.A t.u. ",
1024
" Z e.l M n - N O P q Q R S T ~ v.w.x.^ y.y z.A.d B.C C. ",
1025
" D.m ..3 +.> @.#.7 ) s $.%.a ] E.F.G.( H.I.J.K.L.M.N.O. ",
1026
" ,.o ~.5 {.' ].^./.(._.:.<.[./ P.z Q.R.e S.T.U.V.W.X.Y. ",
1027
" L i.7.8.9.! t 0.a.b b.x c.d._ Z.B `. +.+++@+#+$+%+&+&+ ",
1028
" l {.l.m.n.{ o.p.q.r.c s.A t.u.*+=+-+;+>+,+'+&+&+&+&+&+ ",
1029
" S s v.w.x.^ y.y z.A.d B.C C.)+!+~+{+]+^+&+&+&+&+&+&+ ",
1030
" 0.] E.F.G.( H.I.J.K.L.M.N.O./+(+_+&+&+&+&+&+&+&+&+&+ ",
1031
" [./ P.z Q.R.e S.T.U.V.W.X.Y.&+&+&+&+&+&+&+&+&+&+&+&+ ",
1032
" d._ Z.B `. +.+++@+#+$+%+&+&+&+&+&+&+&+&+&+&+&+&+&+&+ ",
1033
" t.u.*+&+&+&+&+,+'+&+&+&+&+&+&+&+&+&+&+&+&+&+&+&+&+&+ ",
1034
" &+&+&+&+&+&+&+&+&+&+&+&+&+&+&+&+&+&+&+&+&+&+&+&+ ",
1043
static const char * icon_xpm[] = {
1198
". . . + @ # $ % & * = - ; > , ' ",
1199
". ) ) ) ) ) ) ! ~ { ] ^ / ( _ : ",
1200
"< ) [ , } | 1 2 3 4 5 6 7 8 9 0 ",
1201
"a ) b b & c d e f g h i j 8 k l ",
1202
"m ) n o p q r 1 s t u v w x y z ",
1203
"A ) : B i C D E F 9 / G H I C J ",
1204
"c K L M l z N O P Q 4 R S T U g ",
1205
"V W X u Y J Z ` ...+.@.8 W #.$.",
1206
"%.@._ F &.( *.=.h N -.;.T >.,.'.",
1207
").6 !.~.w } $.$.{. .} I W ].D ^.",
1208
"E ^ /.(., 1 F _.:.[ <.e [.}.|.1.",
1209
"2.3._...4.i 5.7 6.7.C 8.'.9.0.a.",
1210
"b.s R :.c.=.d.8 T W e.f.Q g.h.:.",
1211
"C t ;.8 8 I T W >.].}.9.K i.. ;.",
1212
"' j.k.l.C m.n.o.p.c q.r.. . . W ",
1213
": 0 *.u t &.( 4 /.s.t.u.x 8 v.! "
1216
static QPixmap * g_pIcon;
1217
static KviStr g_szLastBrowsedDirectory("/");
1220
KviImageWindow::KviImageWindow(KviFrame *lpFrm)
1221
:KviWindow("!Image Viewer: No file loaded",KVI_WND_TYPE_PLUGIN,lpFrm)
1223
m_pImageView = new KviImageView(this);
1224
m_pToolBar = new QToolBar("toolbar",lpFrm,this);
1226
QToolButton * b = new QToolButton(QPixmap(open_file_xpm),"Open image","Open image",this,SLOT(openFile()),m_pToolBar);
1227
b->setUsesBigPixmap(true);
1228
b = new QToolButton(QPixmap(zoom_up_xpm),"Zoom in","Zoom in",this,SLOT(zoomIn10()),m_pToolBar);
1229
#if QT_VERSION >= 210
1230
QPopupMenu * m = new QPopupMenu(this);
1231
m->insertItem("+ 1 %",this,SLOT(zoomIn()));
1232
m->insertItem("+ 5 %",this,SLOT(zoomIn5()));
1233
m->insertItem("+ 10 %",this,SLOT(zoomIn10()));
1234
m->insertItem("+ 50 %",this,SLOT(zoomIn50()));
1235
m->insertItem("+ 100 %",this,SLOT(zoomIn100()));
1238
b->setUsesBigPixmap(true);
1239
b = new QToolButton(QPixmap(zoom_down_xpm),"Zoom out","Zoom out",this,SLOT(zoomOut10()),m_pToolBar);
1240
#if QT_VERSION >= 210
1241
m = new QPopupMenu(this);
1242
m->insertItem("- 1 %",this,SLOT(zoomOut()));
1243
m->insertItem("- 5 %",this,SLOT(zoomOut5()));
1244
m->insertItem("- 10 %",this,SLOT(zoomOut10()));
1245
m->insertItem("- 50 %",this,SLOT(zoomOut50()));
1246
m->insertItem("- 100 %",this,SLOT(zoomOut100()));
1249
b->setUsesBigPixmap(true);
1250
b = new QToolButton(QPixmap(zoom_none_xpm),"No zoom","No zoom",this,SLOT(noZoom()),m_pToolBar);
1251
b->setUsesBigPixmap(true);
1253
setFocusHandler(m_pImageView);
1256
KviImageWindow::~KviImageWindow()
1260
QPixmap * KviImageWindow::myIconPtr()
1265
void KviImageWindow::resizeEvent(QResizeEvent *)
1267
int hght = m_pToolBar->sizeHint().height();
1268
m_pToolBar->setGeometry(0,0,width(),hght);
1269
m_pImageView->setGeometry(0,hght,width(),height() - hght);
1275
bool KviImageWindow::loadImage(const char *fName)
1277
KviStr filename = fName;
1278
filename.stripWhiteSpace();
1279
if(filename.isEmpty())filename = QFileDialog::getOpenFileName(g_szLastBrowsedDirectory.ptr());
1280
if(filename.isEmpty())return true;
1281
if(!m_pImageView->loadImage(filename.ptr())){
1282
g_pApp->warningBox(__tr("Could not load image %s"),filename.ptr());
1285
QFileInfo fi(filename.ptr());
1286
g_szLastBrowsedDirectory = fi.filePath();
1287
KviStr tmp(KviStr::Format,"!Image Viewer: %s",filename.ptr());
1288
setWindowCaption(tmp.ptr());
1292
void KviImageWindow::openFile()
1297
void KviImageWindow::zoomIn(){ m_pImageView->setZoom(m_pImageView->zoom() + 1); }
1298
void KviImageWindow::zoomIn5(){ m_pImageView->setZoom(m_pImageView->zoom() + 5); }
1299
void KviImageWindow::zoomIn10(){ m_pImageView->setZoom(m_pImageView->zoom() + 10); }
1300
void KviImageWindow::zoomIn50(){ m_pImageView->setZoom(m_pImageView->zoom() + 50); }
1301
void KviImageWindow::zoomIn100(){ m_pImageView->setZoom(m_pImageView->zoom() + 100); }
1302
void KviImageWindow::zoomOut(){ m_pImageView->setZoom(m_pImageView->zoom() - 1); }
1303
void KviImageWindow::zoomOut5(){ m_pImageView->setZoom(m_pImageView->zoom() - 5); }
1304
void KviImageWindow::zoomOut10(){ m_pImageView->setZoom(m_pImageView->zoom() - 10); }
1305
void KviImageWindow::zoomOut50(){ m_pImageView->setZoom(m_pImageView->zoom() - 50); }
1306
void KviImageWindow::zoomOut100(){ m_pImageView->setZoom(m_pImageView->zoom() - 100); }
1308
void KviImageWindow::noZoom()
1310
m_pImageView->setZoom(100);
1313
bool image_plugin_command_image(KviPluginCommandStruct *cmd)
1315
KviImageWindow * wnd = new KviImageWindow(cmd->frame);
1316
kvirc_plugin_add_window(cmd->handle,cmd->frame,wnd);
1317
KviStr tmp = kvirc_plugin_param(cmd,1);
1318
wnd->loadImage(tmp.ptr());
1322
bool image_plugin_init(KviPluginCommandStruct *cmd)
1324
g_pIcon = new QPixmap(icon_xpm);
1325
g_szLastBrowsedDirectory = QDir::homeDirPath();
1326
kvirc_plugin_register_command(cmd->handle,"IMAGE",image_plugin_command_image);
1327
return true; // success
1330
void image_plugin_cleanup()
1333
kvirc_plugin_unregister_meta_object("KviImageView");
1334
kvirc_plugin_unregister_meta_object("KviImageWindow");
1338
@document: doc_plugin_image.kvihelp
1339
@title: The image viewer plugin
1340
Adds a simple internal image viewer to KVIrc.<br>
1341
You can view images by using the command<br>
1342
<b>/image [filename]</b><br>
1343
Filename must be an absolute file path.<br>
1344
If no filename is specified , a "file open" dialog
1345
will be shown to allow selecting a file.<br>
1346
The image types supported are depending on
1347
the underlying Qt and compilation options.<br>
1348
Generally, bmp, png, pnm and xpm are available.<br>
1349
If KVIrc has been compiled with the jpeg support, that
1350
format will be also viewable.<br>
1351
You can use the viewer as the default "player"
1352
of images (see <a href="play.kvihelp">PLAY</a>).<br>
1353
In order to do so , put "IMAGE <a href="s_execfilename.kvihelp">$execFileName</a>" in the
1354
"Run script" field (misc options dialog , mimetypes tab)
1355
for the mimetypes that you want to play with the viewer.<br>
1357
If you unload the plugin , the /IMAGE command will no longer work.<br>
1358
Here comes a simple workaround "commandline field" script for this problem:<br>
1359
Version 1: Use the plugin if is loaded.<br>
1360
<b><a href="if.kvihelp">if</a>(<a href="s_pluginLoaded.kvihelp">$pluginLoaded</a>(image))image <a href="s_execfilename.kvihelp">$ExecFileName</a>; else <a href="exec.kvihelp">exec</a> -q myviewer <a href="s_execfilename.kvihelp">$ExecFileName</a></b><br>
1361
Workaround 2: Use the plugin always, if it is not loaded , load it.<br>
1362
<b><a href="if.kvihelp">if</a>(!<a href="s_pluginloaded.kvihelp">$pluginLoaded</a>(image))<a href="plugin.kvihelp">PLUGIN</a> load libkviimage.so; image <a href="s_execfilename.kvihelp">$ExecFileName</a></b><br>
1365
void image_plugin_help()
1367
kvirc_plugin_show_help_page("doc_plugin_image.kvihelp");
1370
KviPlugin kvirc_plugin =
1373
"A simple image viewer" ,
1375
"Szymon Stefanek <stefanek@tin.it>" ,
1376
"Exports the /IMAGE command" ,
1378
image_plugin_cleanup ,
1383
#include "m_libkviimage.moc"