blob: c2e9e7ca83308367ee268b45875b5671fa17d2a9 [file] [log] [blame]
Bram Moolenaar843ee412004-06-30 16:16:41 +00001/* vi:set ts=8 sts=4 sw=4:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 */
8
9/*
10 * Porting to KDE(2) was done by
11 *
12 * (C) 2000 by Thomas Capricelli <orzel@freehackers.org>
13 *
14 * Please visit http://freehackers.org/kvim for other vim- or
15 * kde-related coding.
16 *
17 * $Id$
18 *
19 */
20
21#include <assert.h>
22#include <qpainter.h>
23#include <qevent.h>
24#include <qpushbutton.h>
25#include <qscrollbar.h>
26#include <qlayout.h>
27#include <qclipboard.h>
28#include <qdragobject.h>
29#include <qstrlist.h>
30#include <qmenubar.h>
31#include <qtextcodec.h>
32#if QT_VERSION>=300
33#include <qptrlist.h>
34#include <ktip.h>
35#endif
36#include <kglobal.h>
37#include <kconfig.h>
38#include <kaboutapplication.h>
39#include <dcopclient.h>
40#include <kaboutkde.h>
41#include <kbugreport.h>
42#include <kurldrag.h>
43#include <kmenubar.h>
44#include <ktoolbar.h>
45#include <kstandarddirs.h>
46#include "gui_kde_widget.h"
47#include <qxembed.h>
48
49extern "C" {
50#include "version.h"
51}
52
53// Pixmap for dialog
54#ifdef FEAT_GUI_DIALOG
55# include "../../pixmaps/alert.xpm"
56# include "../../pixmaps/error.xpm"
57# include "../../pixmaps/generic.xpm"
58# include "../../pixmaps/info.xpm"
59# include "../../pixmaps/quest.xpm"
60#endif
61
62/**
63 * Keycodes recognized by vim.
64 */
65struct special_key {//{{{
66 int qtkey;
67 char_u code0;
68 char_u code1;
69} special_keys[] =
70{
71 { Qt::Key_Up, 'k', 'u' },
72 { Qt::Key_Down, 'k', 'd' },
73 { Qt::Key_Left, 'k', 'l' },
74 { Qt::Key_Right, 'k', 'r' },
75 { Qt::Key_F1, 'k', '1' },
76 { Qt::Key_F2, 'k', '2' },
77 { Qt::Key_F3, 'k', '3' },
78 { Qt::Key_F4, 'k', '4' },
79 { Qt::Key_F5, 'k', '5' },
80 { Qt::Key_F6, 'k', '6' },
81 { Qt::Key_F7, 'k', '7' },
82 { Qt::Key_F8, 'k', '8' },
83 { Qt::Key_F9, 'k', '9' },
84 { Qt::Key_F10, 'k', ';' },
85 { Qt::Key_F11, 'F', '1' },
86 { Qt::Key_F12, 'F', '2' },
87 { Qt::Key_F13, 'F', '3' },
88 { Qt::Key_F14, 'F', '4' },
89 { Qt::Key_F15, 'F', '5' },
90 { Qt::Key_F16, 'F', '6' },
91 { Qt::Key_F17, 'F', '7' },
92 { Qt::Key_F18, 'F', '8' },
93 { Qt::Key_F19, 'F', '9' },
94 { Qt::Key_F20, 'F', 'A' },
95 { Qt::Key_F21, 'F', 'B' },
96 { Qt::Key_F22, 'F', 'C' },
97 { Qt::Key_F23, 'F', 'D' },
98 { Qt::Key_F24, 'F', 'E' },
99 { Qt::Key_F25, 'F', 'F' },
100 { Qt::Key_F26, 'F', 'G' },
101 { Qt::Key_F27, 'F', 'H' },
102 { Qt::Key_F28, 'F', 'I' },
103 { Qt::Key_F29, 'F', 'J' },
104 { Qt::Key_F30, 'F', 'K' },
105 { Qt::Key_F31, 'F', 'L' },
106 { Qt::Key_F32, 'F', 'M' },
107 { Qt::Key_F33, 'F', 'N' },
108 { Qt::Key_F34, 'F', 'O' },
109 { Qt::Key_F35, 'F', 'P' },
110 { Qt::Key_Help, '%', '1' },
111 // { Qt::Key_Undo, '&', '8' }, <= hmmm ?
112 { Qt::Key_BackSpace, 'k', 'b' },
113 { Qt::Key_Insert, KS_EXTRA, KE_KINS },
114 { Qt::Key_Delete, KS_EXTRA, KE_KDEL },
115 { Qt::Key_Home, 'K', '1' },
116 { Qt::Key_End, 'K', '4' },
117 { Qt::Key_Prior, 'K', '3' },
118 { Qt::Key_Next, 'K', '5' },
119 { Qt::Key_Print, '%', '9' },
120
121 { Qt::Key_Plus, 'K', '6'},
122 { Qt::Key_Minus, 'K', '7'},
123 { Qt::Key_Slash, 'K', '8'},
124 { Qt::Key_multiply, 'K', '9'},
125 { Qt::Key_Enter, 'K', 'A'},
126 { Qt::Key_Period, 'K', 'B'},
127
128 { Qt::Key_0, 'K', 'C'},
129 { Qt::Key_1, 'K', 'D'},
130 { Qt::Key_2, 'K', 'E'},
131 { Qt::Key_3, 'K', 'F'},
132 { Qt::Key_4, 'K', 'G'},
133 { Qt::Key_5, 'K', 'H'},
134 { Qt::Key_6, 'K', 'I'},
135 { Qt::Key_7, 'K', 'J'},
136 { Qt::Key_8, 'K', 'K'},
137 { Qt::Key_9, 'K', 'L'},
138 /* End of list marker: */
139 { 0, 0, 0 }
140};//}}}
141
142#ifdef FEAT_CLIENTSERVER
143typedef int (*QX11EventFilter) (XEvent*);
144extern QX11EventFilter qt_set_x11_event_filter (QX11EventFilter filter);
145static QX11EventFilter oldFilter = 0;
146static int kvim_x11_event_filter( XEvent* e);
147#endif
148void gui_keypress(QKeyEvent *e);
149
150/*
151 * Return OK if the key with the termcap name "name" is supported.
152 */
153 int
154gui_mch_haskey(char_u * name)//{{{
155{
156 for (int i=0; special_keys[i].qtkey != 0; i++)
157 if (name[0] == special_keys[i].code0 &&
158 name[1] == special_keys[i].code1)
159 return OK;
160 return FAIL;
161}//}}}
162
163/*
164 * custom Frame for drawing ...
165 */
166void VimWidget::paintEvent( QPaintEvent *e)//{{{
167{
168 QRect r = e->rect();
169 gui_redraw(r.x(), r.y(), r.width(), r.height() );
170}//}}}
171
172void VimWidget::draw_string(int x, int y, QString s, int len, int flags)//{{{
173{
174 gui.current_font->setBold( flags & DRAW_BOLD );
175 gui.current_font->setUnderline( flags & DRAW_UNDERL );
176 gui.current_font->setItalic(flags & DRAW_ITALIC);
177 painter->setBackgroundMode( flags & DRAW_TRANSP ? Qt::TransparentMode : Qt::OpaqueMode);
178 painter->setFont( *(gui.current_font) );
179 painter->drawText( x, y, s, len);
180}//}}}
181
182void VimWidget::mousePressEvent(QMouseEvent *event)//{{{
183{
184 int button=0;
185 int modifiers=0;
186 ButtonState state = event->state();
187 ButtonState buttons = event->button();
188
189 //Look at button states
190 if(buttons & QMouseEvent::LeftButton) {
191 button|=MOUSE_LEFT;
192 }
193 if(buttons & QMouseEvent::RightButton) {
194 button|=MOUSE_RIGHT;
195 }
196 if(buttons & QMouseEvent::MidButton) {
197 button|=MOUSE_MIDDLE;
198 }
199 //Look for keyboard modifiers
200 if(state & QMouseEvent::ShiftButton) {
201 modifiers|=MOUSE_SHIFT;
202 }
203 if(state & QMouseEvent::ControlButton){
204 modifiers|=MOUSE_CTRL;
205 }
206 if(state & QMouseEvent::AltButton){
207 modifiers|=MOUSE_ALT;
208 }
209 gui_send_mouse_event(button,event->x(),event->y(),FALSE,modifiers);
210#if QT_VERSION>=300
211 QByteArray params;
212 QDataStream stream(params, IO_WriteOnly);
213 stream << kapp->dcopClient()->appId() << button << modifiers << gui.row << gui.col;
214 kapp->dcopClient()->emitDCOPSignal("mousePEvent(QCString,int,int,int,int)", params);
215#endif
216 event->accept();
217}//}}}
218
219#if defined(FEAT_SESSION)
220void VimMainWindow::saveGlobalProperties (KConfig *conf)
221{
222 //we write a mksession file to a file written in the user's ~/.kde/share/config/
223 //the name of the file in saved in 'conf'
224 //when restoring app, we source this file
225#if 0 //disabled for release
226 QString filename = KGlobal::dirs()->localkdedir() + KGlobal::dirs()->kde_default("config") + kapp->randomString(10);
227 QString cmd("mksession ");
228 cmd+=filename;
229 do_cmdline_cmd((char_u*)cmd.latin1());
230 conf->writePathEntry("sessionfile", filename);
231 conf->sync();
232#endif
233}
234
235void VimMainWindow::readGlobalProperties (KConfig *conf)
236{
237#if 0
238 QString filename = conf->readPathEntry("sessionfile");
239 if (filename.isNull()) return;
240 QString cmd("source ");
241 cmd+=filename;
242 do_cmdline_cmd((char_u*)cmd.latin1());
243#endif
244}
245#endif
246
247void VimMainWindow::wheelEvent (QWheelEvent *event)//{{{
248{
249 ButtonState state = event->state();
250 int button=0;
251 int modifiers=0;
252
253 if (event->delta()>0)
254 button|=MOUSE_4;
255 else button|=MOUSE_5;
256
257 if(state & ShiftButton)
258 modifiers|=MOUSE_SHIFT;
259 if(state & ControlButton)
260 modifiers|=MOUSE_CTRL;
261 if(state & AltButton)
262 modifiers|=MOUSE_ALT;
263
264 gui_send_mouse_event(button,event->x(),event->y(),FALSE,modifiers);
265#if QT_VERSION>=300
266 QByteArray params;
267 QDataStream stream(params, IO_WriteOnly);
268 stream << kapp->dcopClient()->appId() << button << modifiers << gui.row << gui.col;
269 kapp->dcopClient()->emitDCOPSignal("mouseWhlEvent(QCString, int, int,int,int)", params);
270#endif
271 event->accept();
272}//}}}
273
274void VimWidget::mouseDoubleClickEvent(QMouseEvent *event)//{{{
275{
276 ButtonState state = event->state();
277 ButtonState buttons = event->button();
278 int modifiers=0;
279 int button=0;
280
281 //Look at button states
282 if(buttons & LeftButton)
283 button|=MOUSE_LEFT;
284 if(buttons & RightButton)
285 button|=MOUSE_RIGHT;
286 if(buttons & MidButton)
287 button|=MOUSE_MIDDLE;
288
289 //Look for keyboard modifiers
290 if(state & ShiftButton)
291 modifiers|=MOUSE_SHIFT;
292 if(state & ControlButton)
293 modifiers|=MOUSE_CTRL;
294 if(state & AltButton)
295 modifiers|=MOUSE_ALT;
296
297 gui_send_mouse_event(button,event->x(),event->y(),TRUE,modifiers);
298#if QT_VERSION>=300
299 QByteArray params;
300 QDataStream stream(params, IO_WriteOnly);
301 stream << kapp->dcopClient()->appId() << button << modifiers << gui.row << gui.col;
302 kapp->dcopClient()->emitDCOPSignal("mouseDblClickEvent(QCString, int, int,int,int)", params);
303#endif
304 event->accept();
305}//}}}
306
307void VimWidget::mouseMoveEvent(QMouseEvent *event){//{{{
308 ButtonState state = event->state();
309 int modifiers=0;
310 int button=0;
311
312 gui_mch_mousehide(FALSE);
313
314 //Look at button states
315 //warning: we use state here, this is important !
316 if(state & QMouseEvent::LeftButton || state & QMouseEvent::RightButton || state & QMouseEvent::MidButton)
317 button|=MOUSE_DRAG;
318
319 //Look for keyboard modifiers
320 if(state & ShiftButton)
321 modifiers|=MOUSE_SHIFT;
322 if(state & ControlButton)
323 modifiers|=MOUSE_CTRL;
324 if(state & AltButton)
325 modifiers|=MOUSE_ALT;
326 if (button!=MOUSE_DRAG)
327 gui_mouse_moved(event->x(),event->y());
328 else
329 gui_send_mouse_event(MOUSE_DRAG,event->x(),event->y(),FALSE,modifiers);
330}//}}}
331
332void VimWidget::mouseReleaseEvent(QMouseEvent *event)//{{{
333{
334 ButtonState state = event->state();
335 int modifiers=0;
336
337 //Look for keyboard modifiers
338 if(state & ShiftButton)
339 modifiers|=MOUSE_SHIFT;
340 if(state & ControlButton)
341 modifiers|=MOUSE_CTRL;
342 if(state & AltButton)
343 modifiers|=MOUSE_ALT;
344
345 gui_send_mouse_event(MOUSE_RELEASE,event->x(),event->y(),FALSE,modifiers);
346 event->accept();
347}//}}}
348
349/*
350 * The main widget (everything but toolbar/menubar)
351 */
352 VimWidget::VimWidget( QWidget *parent, const char *name, WFlags f )//{{{
353:QWidget(parent, name, f)
354 ,DCOPObject("KVim")
355{
356 //to be able to show/hide the cursor when moving the mouse
357 setMouseTracking(true);
358 painter=new QPainter(this);
359
360 setKeyCompression(true);
361 setFocusPolicy( QWidget::StrongFocus );
362 setAcceptDrops(TRUE); // DND
363 blink_state = BLINK_NONE;
364 blink_on_time = 700;
365 blink_off_time = 400;
366 blink_wait_time = 250;
367 connect( &blink_timer, SIGNAL( timeout() ), SLOT( blink_cursor() ));
368 connect( &wait_timer, SIGNAL( timeout() ), SLOT ( wait_timeout() ));
369}//}}}
370
371void VimWidget::execNormal(QString command)//{{{
372{
373 QString cmd("execute 'normal ");
374 cmd+=command;
375 cmd+="'";
376 QCString unistring = vmw->codec->fromUnicode(cmd);
377 do_cmdline_cmd((char_u *)(const char*)unistring);
378 gui_update_screen();
379}//}}}
380
381void VimWidget::execInsert(QString command)//{{{
382{
383 QString cmd("execute 'normal i");
384 cmd+=command;
385 cmd+="'";
386 QCString unistring = vmw->codec->fromUnicode(cmd);
387 do_cmdline_cmd((char_u *)(const char*)unistring);
388 gui_update_screen();
389}//}}}
390
391void VimWidget::execRaw(QString command)//{{{
392{
393 QString cmd("execute '");
394 cmd+=command;
395 cmd+="'";
396 QCString unistring = vmw->codec->fromUnicode(cmd);
397 do_cmdline_cmd((char_u *)(const char*)unistring);
398 gui_update_screen();
399}//}}}
400
401void VimWidget::execCmd(QString command)//{{{
402{
403 QCString unistring = vmw->codec->fromUnicode(command);
404 do_cmdline_cmd((char_u *)(const char*)unistring);
405 gui_update_screen();
406}//}}}
407
408QString VimWidget::eval(QString expr)//{{{
409{
410#ifdef FEAT_EVAL
411 QCString unistring = vmw->codec->fromUnicode(expr);
412 QString val((const char *)eval_to_string((char_u *)(const char*)unistring,NULL));
413 return val;
414#else
415 return QString::null;
416#endif
417}//}}}
418
419void VimWidget::wait(long wtime)//{{{
420{
421 if ( wait_timer.isActive() ) wait_timer.stop();
422 wait_done = false;
423 wait_timer.start( wtime, true);
424}//}}}
425
426void VimWidget::wait_timeout() //{{{
427{
428 wait_done = true;
429}//}}}
430
431void VimWidget::dragEnterEvent (QDragEnterEvent *e)//{{{
432{
433#if (defined(FEAT_WINDOWS) && defined(HAVE_DROP_FILE)) || defined(PROTO)
434 e->accept(QUriDrag::canDecode(e));
435#else
436 e->ignore();
437#endif
438}//}}}
439
440void VimWidget::dropEvent (QDropEvent *e) // {{{
441{
442#if (defined(FEAT_WINDOWS) && defined(HAVE_DROP_FILE)) || defined(PROTO)
443 QStrList urls;
444
445 char_u **fnames;
446 int redo_dirs = FALSE;
447 int i;
448 int n;
449 int nfiles;
450 int url = FALSE;
451
452 /* Count how many items there may be and normalize delimiters. */
453
454 if (QUriDrag::decode(e, urls)) {
455 n = urls.count();
456 fnames = (char_u **)lalloc((n+1) * sizeof(char_u *), TRUE);
457 nfiles = 0;
458#if QT_VERSION>=300
459 QPtrListIterator<char> it(urls);
460 for( ; it.current(); ++it ) {
461 KURL u(*it);
462#else
463 for (i=0;i<urls.count();++i) {
464 KURL u(urls.at(i));
465#endif
466 if ( !u.isLocalFile() )
467 url = TRUE;
468 else {
469 fnames[nfiles] = (char_u *)strdup((const char *)u.path());
470 ++nfiles;
471 }
472 }
473 /* Real files (i.e. not http and not ftp) */
474 if (url == FALSE)
475 {
476 if (nfiles == 1)
477 {
478 if (mch_isdir(fnames[0]))
479 {
480 /* Handle dropping a directory on Vim. */
481 if (mch_chdir((char *)fnames[0]) == 0)
482 {
483 free(fnames[0]);
484 fnames[0] = NULL;
485 redo_dirs = TRUE;
486 }
487 }
488 } else {
489 /* Ignore any directories */
490 for (i = 0; i < nfiles; ++i)
491 {
492 if (mch_isdir(fnames[i]))
493 {
494 vim_free(fnames[i]);
495 fnames[i] = NULL;
496 }
497 }
498 }
499
500 if (0)
501 {
502 /* Shift held down, change to first file's directory */
503 if (fnames[0] != NULL && vim_chdirfile(fnames[0]) == OK)
504 redo_dirs = TRUE;
505 } else {
506 char_u dirname[MAXPATHL];
507 char_u *s;
508 if (mch_dirname(dirname, MAXPATHL) == OK)
509 for (i = 0; i < nfiles; ++i)
510 if (fnames[i] != NULL)
511 {
512 s = shorten_fname(fnames[i], dirname);
513 if (s != NULL && (s = vim_strsave(s)) != NULL)
514 {
515 vim_free(fnames[i]);
516 fnames[i] = s;
517 }
518 }
519 }
520 }
521
522 /* Handle the drop, :edit or :split to get to the file */
523 handle_drop(nfiles, fnames, FALSE);
524
525 if (redo_dirs)
526 shorten_fnames(TRUE);
527 }
528
529 /* Update the screen display */
530 update_screen(NOT_VALID);
531#ifdef FEAT_MENU
532 gui_update_menus(0);
533#endif
534 setcursor();
535 out_flush();
536 gui_update_cursor(FALSE, FALSE);
537 gui_mch_flush();
538#endif
539} // }}}
540
541void VimWidget::keyPressEvent( QKeyEvent *e ) // {{{
542{
543 gui_keypress(e);
544} // }}}
545
546void gui_keypress(QKeyEvent *e) { // {{{
547 int key = (int)e->key();
548 int modifiers = 0,i;
549 uchar string[256],string2[256];
550 uchar *s,*d;
551 Qt::ButtonState state = e->state();
552
553 QCString unistring = vmw->codec->fromUnicode(e->text());
554 if (unistring.length()>0)
555 strncpy((char*)string, (const char*)unistring,unistring.length());
556 string[unistring.length()] = 0;
557 int len=unistring.length();
558
559 // ignore certain keys
560 if (key == Qt::Key_Shift || key == Qt::Key_Alt || key == Qt::Key_Control || key == Qt::Key_Meta
561 || key == Qt::Key_CapsLock || key == Qt::Key_NumLock || key == Qt::Key_ScrollLock ) {
562 e->ignore();
563 return;
564 }
565
566#ifdef FEAT_MBYTE
567 if (input_conv.vc_type != CONV_NONE)
568 {
569 mch_memmove(string2, string, len);
570 len = convert_input(string2, len, sizeof(string2));
571 s = string2;
572 }
573 else
574#endif
575 s = string;
576 d = string;
577 for (i = 0; i < len; ++i)
578 {
579 *d++ = s[i];
580 if (d[-1] == CSI && d + 2 < string + sizeof(string))
581 {
582 /* Turn CSI into K_CSI. */
583 *d++ = KS_EXTRA;
584 *d++ = (int)KE_CSI;
585 }
586 }
587 len = d - string;
588
589
590 // change shift-tab (backtab) into S_TAB
591 if ( key == Qt::Key_BackTab && state & Qt::ShiftButton) {
592 key = Qt::Key_Tab;
593 }
594
595 // Change C-@ and C-2 in NUL ? Gtk does this
596 if ( (key == Qt::Key_2 || key == Qt::Key_At)
597 && state & Qt::ControlButton ) {
598 string[0] = NUL;
599 len = 1;
600 }
601 else if (len == 0 && (key == Qt::Key_Space || key == Qt::Key_Tab))
602 {
603 /* When there are modifiers, these keys get zero length; we need the
604 * original key here to be able to add a modifier below. */
605 string[0] = (key & 0xff);
606 len = 1;
607 }
608 /* Check for Alt/Meta key (Mod1Mask), but not for a BS, DEL or character
609 * that already has the 8th bit set.
610 * Don't do this for <S-M-Tab>, that should become K_S_TAB with ALT. */
611 if (len == 1
612 && (key != Qt::Key_BackSpace && key != Qt::Key_Delete)
613 && (string[0] & 0x80) == 0
614 && (state & Qt::AltButton)
615 && !(key == Qt::Key_Tab && (state & Qt::ShiftButton)))
616 {
617 string[0] |= 0x80;
618#ifdef FEAT_MBYTE
619 if (enc_utf8) // convert to utf-8
620 {
621 string[1] = string[0] & 0xbf;
622 string[0] = ((unsigned)string[0] >> 6) + 0xc0;
623 if (string[1] == CSI)
624 {
625 string[2] = KS_EXTRA;
626 string[3] = (int)KE_CSI;
627 len = 4;
628 }
629 else
630 len = 2;
631 }
632#endif
633 }
634
635 /* Check for special keys, making sure BS and DEL are recognised. */
636 if (len == 0 || key == Qt::Key_BackSpace || key == Qt::Key_Delete)
637 {
638 while (special_keys[i].qtkey != 0 && special_keys[i].qtkey != key ) i++;
639 if (special_keys[i].qtkey != 0) {
640 string[0] = CSI;
641 string[1] = special_keys[i].code0;
642 string[2] = special_keys[i].code1;
643 len = -3;
644 }
645/*
646 for (i = 0; special_keys[i].qtkey != 0 ; i++)
647 {
648 if (special_keys[i].qtkey == key ) {
649 string[0] = CSI;
650 string[1] = special_keys[i].code0;
651 string[2] = special_keys[i].code1;
652 len = -3;
653 break;
654 }
655 }*/
656 }
657
658 if (len == 0) {
659 //no need to dump that, that's a QT problem, we can't do anything
660 //dbf("Unrecognised Key : %X %s", key, e->text().latin1());
661 e->ignore();
662 return;
663 }
664
665
666 /* Special keys (and a few others) may have modifiers */
667 if (len == -3 || key == Qt::Key_Space || key == Qt::Key_Tab ||
668 key == Qt::Key_Return || key == Qt::Key_Enter ||
669 key == Qt::Key_Escape) {
670
671 modifiers = 0;
672 if (state & Qt::ShiftButton) modifiers |= MOD_MASK_SHIFT;
673 if (state & Qt::ControlButton) modifiers |= MOD_MASK_CTRL;
674 if (state & Qt::AltButton) modifiers |= MOD_MASK_ALT;
675
676 /*
677 * For some keys a shift modifier is translated into another key
678 * code. Do we need to handle the case where len != 1 and
679 * string[0] != CSI?
680 */
681 if (len == -3)
682 key = TO_SPECIAL(string[1], string[2]);
683 else
684 key = string[0];
685
686 key = simplify_key(key, &modifiers);
687 if (key == CSI) key=K_CSI;
688
689 if (IS_SPECIAL(key)) {
690 string[0] = CSI;
691 string[1] = K_SECOND(key);
692 string[2] = K_THIRD(key);
693 len = 3;
694 } else {
695 string[0] = key;
696 len = 1;
697 }
698
699
700 if (modifiers!=0) {
701 uchar string2[10];
702 string2[0] = CSI;
703 string2[1] = KS_MODIFIER;
704 string2[2] = modifiers;
705 add_to_input_buf(string2, 3);
706 }
707
708 } /* special keys */
709
710 if (len == 1 && ((string[0] == Ctrl_C && ctrl_c_interrupts)
711 || (string[0] == intr_char && intr_char != Ctrl_C)))
712 {
713 trash_input_buf();
714 got_int = TRUE;
715 }
716
717 add_to_input_buf(string, len);
718 if (p_mh) {
719 gui_mch_mousehide(TRUE);
720 }
721 //DCOP Embedding stuff
722 //if we are here then the user has type something in the window, thus we can easily imagine that :
723 // 1 - text has changed (emit textChanged())
724 // 2 - characters were interactively inserted (emit charactersInteractivelyInserted())
725 // 3 - cursor position has changed ( emit cursorPositionChanged() )
726 // 4 - selection has changed ? dunno yet //XXX
727 // 5 - undo changed too ? (each character typed in makes the undo changes anyway)
728 // conclusion : this makes a lot of things to send to the vim kpart, maybe too much
729 // for now i'll just send : keyboardEvent to the kpart with the event string as parameter,
730 // with current current position
731 // i'll do the same for mouseEvents
732#if QT_VERSION>=300
733 QByteArray params;
734 QDataStream stream(params, IO_WriteOnly);
735 stream << kapp->dcopClient()->appId() << unistring << gui.row << gui.col;
736 kapp->dcopClient()->emitDCOPSignal("keyboardEvent(QCString, QCString,int,int)", params);
737#endif
738 e->ignore();
739} // }}}
740
741#ifdef FEAT_CLIENTSERVER
742void VimWidget::serverActivate(WId id) //{{{
743{
744 if (serverName == NULL && serverDelayedStartName != NULL) {
745 commWindow = id;
746 (void)serverRegisterName(qt_xdisplay(), serverDelayedStartName);
747 } else {
748 serverChangeRegisteredWindow( qt_xdisplay(), id );
749 }
750}//}}}
751#endif
752
753#ifdef FEAT_XIM
754void VimWidget::imStartEvent(QIMEvent *e) {
755 e->accept();
756}
757
758void VimWidget::imEndEvent(QIMEvent *e) {
759 uchar string[256];
760
761 QCString unistring = vmw->codec->fromUnicode(e->text());
762 if (unistring.length()>0)
763 strncpy((char*)string, (const char*)unistring,unistring.length());
764 string[unistring.length()] = 0;
765 int len=unistring.length();
766
767 add_to_input_buf(string, len);
768 e->accept();
769}
770
771void VimWidget::imComposeEvent(QIMEvent *e) {
772 //i should do something here, displaying the text somewhere ... (status area ?)
773 e->accept();
774}
775#endif
776
777
778void VimMainWindow::lock()
779{
780 locked=true;
781}
782
783void VimMainWindow::unlock()
784{
785 locked=false;
786}
787
788bool VimMainWindow::isLocked()
789{
790 return locked;
791}
792
793// ->resize VimWidget if not locked
794//
795void VimMainWindow::resizeEvent ( QResizeEvent *e ) //{{{
796{
797 if ( vmw->isLocked() ) return;
798 //remove toolbar and menubar height
799 int height = e->size().height();
800 int width = e->size().width();
801
802 if (vmw->menuBar()->isVisible() && vmw->menuBar()->isEnabled()
803#if QT_VERSION>=300
804 && !vmw->menuBar()->isTopLevelMenu()
805#endif
806 )
807 height -= vmw->menuBar()->height();
808#ifdef FEAT_TOOLBAR
809 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() &&
810 (vmw->toolBar()->barPos()==KToolBar::Top ||
811 vmw->toolBar()->barPos()==KToolBar::Bottom))
812 height -= vmw->toolBar()->height();
813
814 if (vmw->toolBar()->isVisible() && vmw->toolBar()->isEnabled() &&
815 (vmw->toolBar()->barPos()==KToolBar::Left ||
816 vmw->toolBar()->barPos()==KToolBar::Right))
817 width -= vmw->toolBar()->width();
818#endif
819 height = ( ((int)(height/gui.char_height))*gui.char_height );
820 if (!vmw->isLocked()) gui_resize_shell(width,height);
821}//}}}
822
823void VimWidget::focusInEvent( QFocusEvent * fe ) // {{{
824{
825 gui_focus_change(true);
826
827 if (blink_state == BLINK_NONE)
828 gui_mch_start_blink();
829} // }}}
830
831void VimWidget::focusOutEvent( QFocusEvent * fe )//{{{
832{
833 gui_focus_change(false);
834
835 if (blink_state != BLINK_NONE)
836 gui_mch_stop_blink();
837}//}}}
838
839void VimWidget::set_blink_time( long wait, long on, long off)//{{{
840{
841 blink_wait_time = wait;
842 blink_on_time = on;
843 blink_off_time = off;
844}//}}}
845
846void VimWidget::start_cursor_blinking()//{{{
847{
848 if (blink_timer.isActive()) blink_timer.stop();
849
850 /* Only switch blinking on if none of the times is zero */
851 if (blink_wait_time && blink_on_time && blink_off_time && gui.in_focus) {
852 blink_state = BLINK_ON;
853 gui_update_cursor(TRUE, FALSE);
854 // The first blink appears after wait_time
855 blink_timer.start( blink_wait_time, true);
856 }
857}//}}}
858
859void VimWidget::blink_cursor()//{{{
860{
861 if (blink_state == BLINK_ON) {
862 // set cursor off
863 gui_undraw_cursor();
864 blink_state = BLINK_OFF;
865 blink_timer.start( blink_off_time, true);
866 } else {
867 // set cursor on
868 gui_update_cursor(TRUE, FALSE);
869 blink_state = BLINK_ON;
870 blink_timer.start( blink_on_time, true);
871 }
872}//}}}
873
874void VimWidget::stop_cursor_blinking()//{{{
875{
876 if (blink_timer.isActive()) blink_timer.stop();
877
878 if (blink_state == BLINK_OFF)
879 gui_update_cursor(TRUE, FALSE);
880
881 blink_state = BLINK_NONE;
882}//}}}
883
884void VimWidget::flash()//{{{
885{
886 QPainter p(this);
887
888 p.setRasterOp(Qt::XorROP);
889 p.fillRect(geometry(),QColor(0xFF,0xFF,0xFF));
890 p.flush();
891 //FIXME: Make this a little smarter. Maybe add a timer or something
892 usleep(19000);
893 p.fillRect(geometry(),QColor(0xFF,0xFF,0xFF));
894 p.flush();
895 p.end();
896}//}}}
897
898
899/*
900 * The main Window
901 */
902 VimMainWindow::VimMainWindow ( const char *name , WFlags f)//{{{
903:KMainWindow(0L, name,f)
904{
905#ifdef FEAT_CLIENTSERVER
906 oldFilter = qt_set_x11_event_filter( kvim_x11_event_filter );
907#endif
908 if (echo_wid_arg== 1) {
909 fprintf(stderr, "WID: %ld\n", (long)winId());
910 fflush(stderr);
911 }
912
913 w = new VimWidget(this, "main vim widget");
914 gui.w = w;
915 setFocusProxy(w);
916 w->setFocus();
917 have_tearoff=0;
918
919 finddlg=new KEdFind (this,0,false);
920 repldlg=new KEdReplace (this,0,false);
921 QObject::connect( finddlg, SIGNAL(search()), this, SLOT(slotSearch()) );
922 QObject::connect( repldlg, SIGNAL(find()), this, SLOT(slotFind()) );
923 QObject::connect( repldlg, SIGNAL(replace()), this, SLOT(slotReplace()) );
924 QObject::connect( repldlg, SIGNAL(replaceAll()), this, SLOT(slotReplaceAll()) );
925
926#ifdef FEAT_TOOLBAR
927 connect(toolBar(), SIGNAL(clicked(int)), this, SLOT(menu_activated(int)));
928#endif
929#ifdef FEAT_CLIENTSERVER
930 w->serverActivate(winId());
931
932 if (serverName!=NULL)
933 kapp->dcopClient()->registerAs(QCString((const char*)serverName),false);
934 else if (serverDelayedStartName!=NULL)
935 kapp->dcopClient()->registerAs(QCString((const char*)serverDelayedStartName),false);
936 else if (argServerName!=NULL)
937 kapp->dcopClient()->registerAs(argServerName->utf8(),false);
938#else
939 if (argServerName!=NULL)
940 kapp->dcopClient()->registerAs(argServerName->utf8(),false);
941#endif
942 QXEmbed::initialize();
943
944}//{{{
945
946bool VimMainWindow::queryClose()//{{{
947{
948 gui_shell_closed();
949 return true;
950}//}}}
951
952bool VimMainWindow::queryExit()//{{{
953{
954 return true;
955}//}}}
956
957void VimMainWindow::menu_activated(int dx)//{{{
958{
959#ifdef FEAT_MENU
960 if (!dx) { // tearoff
961 return;
962 }
963 gui_mch_set_foreground();
964 gui_menu_cb((VimMenu *) dx);
965#endif
966}//}}}
967
968
969void VimMainWindow::clipboard_selection_update(){//{{{
970 if(kapp->clipboard()->ownsSelection()) {
971 clip_own_selection(&clip_star);
972 } else {
973 clip_lose_selection(&clip_star);
974 }
975}//}}}
976
977void VimMainWindow::clipboard_data_update(){//{{{
978#if QT_VERSION>=300
979 if (kapp->clipboard()->ownsClipboard()) {
980 clip_own_selection(&clip_plus);
981 } else {
982 clip_lose_selection(&clip_plus);
983 }
984#else
985 if (kapp->clipboard()->ownsSelection()) {
986 clip_own_selection(&clip_star);
987 } else {
988 clip_lose_selection(&clip_star);
989 }
990#endif
991}//}}}
992
993void VimMainWindow::slotSearch()//{{{
994{
995 QString find_text;
996 bool direction_down = TRUE;
997 bool casesensitive = TRUE;
998 int flags = FRD_FINDNEXT;
999
1000 find_text = finddlg->getText();
1001 direction_down = !(finddlg->get_direction());
1002 casesensitive = finddlg->case_sensitive();
1003 // if (casesensitive) find_text = "\\C" + find_text;
1004 // else find_text = "\\c" + find_text;
1005 if (casesensitive) flags|=FRD_MATCH_CASE;
1006 QCString unistring = vmw->codec->fromUnicode(find_text);
1007 gui_do_findrepl(flags, (char_u *)(const char *)unistring, NULL,(int)direction_down);
1008}//}}}
1009
1010void VimMainWindow::slotFind()//{{{
1011{
1012 QString find_text;
1013 bool direction_down=TRUE;
1014 bool casesensitive = TRUE;
1015 int flags = FRD_R_FINDNEXT;
1016
1017 find_text=repldlg->getText();
1018 direction_down = !(repldlg->get_direction());
1019 casesensitive = repldlg->case_sensitive();
1020 // if (casesensitive) find_text = "\\C" + find_text;
1021 // else find_text = "\\c" + find_text;
1022 if (casesensitive) flags|=FRD_MATCH_CASE;
1023
1024 QCString unistring = vmw->codec->fromUnicode(find_text);
1025 gui_do_findrepl(flags, (char_u *)(const char *)unistring, NULL,(int)direction_down);
1026}//}}}
1027
1028void VimMainWindow::slotReplace()//{{{
1029{
1030 QString find_text;
1031 QString repl_text;
1032 bool direction_down=TRUE;
1033 bool casesensitive = TRUE;
1034 int flags = FRD_REPLACE;
1035
1036 find_text=repldlg->getText();
1037 repl_text=repldlg->getReplaceText();
1038 direction_down = !(repldlg->get_direction());
1039 //if (casesensitive) find_text = "\\C" + find_text;
1040 //else find_text = "\\c" + find_text;
1041 if (casesensitive) flags|=FRD_MATCH_CASE;
1042
1043 QCString unistring = vmw->codec->fromUnicode(find_text);
1044 QCString unistring2 = vmw->codec->fromUnicode(repl_text);
1045 gui_do_findrepl(flags, (char_u *)(const char *)unistring,(char_u *)(const char*)unistring2,(int)direction_down);
1046}//}}}
1047
1048void VimMainWindow::slotReplaceAll()//{{{
1049{
1050 QString find_text;
1051 QString repl_text;
1052 bool direction_down=TRUE;
1053 bool casesensitive = TRUE;
1054 int flags = FRD_REPLACEALL;
1055
1056 find_text=repldlg->getText();
1057 repl_text=repldlg->getReplaceText();
1058 direction_down = !(repldlg->get_direction());
1059 casesensitive = repldlg->case_sensitive();
1060 // if (casesensitive) find_text = "\\C" + find_text;
1061 // else find_text = "\\c" + find_text;
1062 if (casesensitive) flags|=FRD_MATCH_CASE;
1063 QCString unistring = vmw->codec->fromUnicode(find_text);
1064 QCString unistring2 = vmw->codec->fromUnicode(repl_text);
1065 gui_do_findrepl(flags, (char_u *)(const char *)unistring,(char_u *)(const char*)unistring2,(int)direction_down);
1066}//}}}
1067
1068void VimMainWindow::showAboutKDE()
1069{
1070 KAboutKDE *kde = new KAboutKDE(this);
1071 kde->show();
1072}
1073
1074void VimMainWindow::showAboutApplication()//{{{
1075{
1076 KAboutData *aboutData = new KAboutData (
1077 "kvim"
1078 , I18N_NOOP("KVim")
1079 , VIM_VERSION_SHORT
1080 , I18N_NOOP("Vim in a KDE interface")
1081 , 0
1082 , "(c) Vim Team, \":help credits\" for more infos.\nType \":help iccf\" to see how you can help the children in Uganda"
1083 , 0l
1084 , "http://freehackers.org/kvim"
1085 , "kvim-dev@freenux.org"
1086 );
1087
1088 aboutData->addAuthor("Bram Moolenaar",
1089 I18N_NOOP("Main vim author"),
1090 "Bram@vim.org",
1091 "http://www.vim.org/");
1092 aboutData->addAuthor("Thomas Capricelli",
1093 I18N_NOOP("KDE porting"),
1094 "orzel@freehackers.org",
1095 "http://orzel.freehackers.org");
1096 aboutData->addAuthor("Philippe Fremy",
1097 I18N_NOOP("KDE porting"),
1098 "pfremy@chez.com",
1099 "http://www.freehackers.org/kvim");
1100 aboutData->addAuthor("Mark Westcott",
1101 I18N_NOOP("Qtopia porting, maintainer of the Qtopia part"),
1102 "mark@houseoffish.org",
1103 "http://houseoffish.org");
1104 aboutData->addAuthor("Mickael Marchand",
1105 I18N_NOOP("KDE porting, maintainer"),
1106 "marchand@kde.org",
1107 "http://freenux.org");
1108 aboutData->addAuthor("Many other people",
1109 I18N_NOOP("type :help credits for more infos")
1110 );
1111 aboutData->addCredit("Vince Negri",
1112 I18N_NOOP("Antialiasing support, Color fixes"),
1113 "vnegri@asl-electronics.co.uk");
1114 aboutData->addCredit("Malte Starostik",
1115 I18N_NOOP("Patch for performance improvement"),
1116 "malte@kde.org");
1117 aboutData->addCredit("Mark Stosberg",
1118 I18N_NOOP("Provided a FreeBSD box to debug KVim on BSD"),
1119 "mark@summersault.com"
1120 );
1121 aboutData->addCredit("Henrik Skott",
1122 I18N_NOOP("Font patch when KDE not configured"),
1123 "henrik.skott@hem.utfors.se"
1124 );
1125 aboutData->addCredit("Kailash Sethuraman",
1126 I18N_NOOP("NetBSD configure/compilation fixes")
1127 );
1128 aboutData->setLicenseText(
1129"KVim as an extension of Vim follows Vim license : \n\
1130Vim is Charityware. You can use and copy it as much as you like, but you are\n\
1131encouraged to make a donation to orphans in Uganda. Please read the file\n\
1132runtime/doc/uganda.txt for details.\n\
1133\n\
1134There are no restrictions on distributing an unmodified copy of Vim. Parts of\n\
1135Vim may also be distributed, but this text must always be included. You are\n\
1136allowed to include executables that you made from the unmodified Vim sources,\n\
1137your own usage examples and Vim scripts.\n\
1138\n\
1139If you distribute a modified version of Vim, you are encouraged to send the\n\
1140maintainer a copy, including the source code. Or make it available to the\n\
1141maintainer through ftp; let him know where it can be found. If the number of\n\
1142changes is small (e.g., a modified Makefile) e-mailing the diffs will do.\n\
1143When the maintainer asks for it (in any way) you must make your changes,\n\
1144including source code, available to him.\n\
1145\n\
1146The maintainer reserves the right to include any changes in the official\n\
1147version of Vim. This is negotiable. You are not allowed to distribute a\n\
1148modified version of Vim when you are not willing to make the source code\n\
1149available to the maintainer.\n\
1150\n\
1151The current maintainer is Bram Moolenaar <Bram@vim.org>. If this changes, it\n\
1152will be announced in appropriate places (most likely www.vim.org and\n\
1153comp.editors). When it is completely impossible to contact the maintainer,\n\
1154the obligation to send him modified source code ceases.\n\
1155\n\
1156It is not allowed to remove these restrictions from the distribution of the\n\
1157Vim sources or parts of it. These restrictions may also be used for previous\n\
1158Vim releases instead of the text that was included with it.");
1159
1160 KAboutApplication *about = new KAboutApplication(aboutData);
1161 about->show();
1162}//}}}
1163
1164void VimMainWindow::showTipOfTheDay() {
1165#if QT_VERSION>=300
1166 KTipDialog::showTip (vmw,QString::null,true);
1167#endif
1168}
1169
1170void VimMainWindow::buffersToolbar() {
1171
1172}
1173
1174void VimMainWindow::showBugReport() {
1175 KBugReport *bug= new KBugReport(this,true);
1176 bug->show();
1177}
1178/*
1179 * Vim Dialog
1180 *
1181 * Returns:
1182 * 0: Cancel
1183 * 1- : nb of the pressed button
1184 */
1185
1186VimDialog::VimDialog (int type, /* type of dialog *///{{{
1187 char_u * title, /* title of dialog */
1188 char_u * message, /* message text */
1189 char_u * buttons, /* names of buttons */
1190 int def_but, /* default button */
1191 char_u *textfield ) /* input field */
1192:QDialog(vmw, "vim generic dialog", true), // true is for "modal"
1193 mapper(this, "dialog signal mapper")
1194{
1195 /*
1196 * Create Icon
1197 */
1198 char ** icon_data;
1199 switch (type) {
1200 case VIM_GENERIC:
1201 icon_data = generic_xpm;
1202 break;
1203 case VIM_ERROR:
1204 icon_data = error_xpm;
1205 break;
1206 case VIM_WARNING:
1207 icon_data = alert_xpm;
1208 break;
1209 case VIM_INFO:
1210 icon_data = info_xpm;
1211 break;
1212 case VIM_QUESTION:
1213 icon_data = quest_xpm;
1214 break;
1215 default:
1216 icon_data = generic_xpm;
1217 };
1218 QLabel * icon = new QLabel( this );
1219 icon->setPixmap( QPixmap( (const char **) icon_data ) );
1220 icon->setFixedSize( icon->sizeHint() );
1221
1222 QLabel * text = new QLabel( (const char *)message, this );
1223 text->setAlignment( AlignHCenter | AlignVCenter | ExpandTabs );
1224
1225 QStringList buttonText = QStringList::split( DLG_BUTTON_SEP, (char *) buttons);
1226 int butNb = buttonText.count();
1227
1228 /*
1229 * Layout
1230 */
1231
1232 QVBoxLayout * vly = new QVBoxLayout( this, 5, 5 );
1233 QHBoxLayout * hly1 = new QHBoxLayout( vly, 5);
1234 hly1->addWidget( icon );
1235 hly1->addWidget( text );
1236 QHBoxLayout * hly3 = new QHBoxLayout ( vly , 5);
1237 if (textfield!=NULL) {
1238 entry = new QLineEdit((const char *)textfield,this);
1239 entry->setText((const char *)textfield);
1240 hly3->addWidget( entry );
1241 ret=textfield;
1242 } else entry=NULL;
1243
1244 QHBoxLayout * hly2 = new QHBoxLayout( vly, 15);
1245 QString s;
1246 QPushButton * pushButton = 0L;
1247 for( int i=0; i<butNb; i++) {
1248 s = buttonText[i];
1249 pushButton = new QPushButton(s, this );
1250 if (s.find('&') != -1) {
1251 pushButton->setAccel( s.at(s.find('&')+1).latin1() );
1252 }
1253
1254 hly2->addWidget( pushButton );
1255 if (i == def_but-1) {
1256 pushButton->setDefault( true );
1257 pushButton->setAutoDefault( true );
1258 setResult( i+1 );
1259 }
1260 connect(pushButton, SIGNAL(clicked()), &mapper, SLOT(map()));
1261 mapper.setMapping(pushButton, i+1);
1262 }
1263 connect( &mapper, SIGNAL(mapped(int)), this, SLOT(done(int)));
1264
1265 setCaption((const char *) title);
1266
1267 vly->activate();
1268}//}}}
1269
1270void VimDialog::done(int r) {
1271 if (entry!=NULL) {
1272 if (r) {
1273 QCString unistring=vmw->codec->fromUnicode(entry->text());
1274 STRCPY(ret,(const char*)unistring);
1275 } else
1276 *ret=NUL;
1277 }
1278 QDialog::done(r);
1279}
1280
1281/*
1282 * ScrollBar pool handling
1283 */
1284SBPool::SBPool(void)//{{{
1285 :mapper(this, "SBPool signal mapper")
1286{
1287 connect(&mapper, SIGNAL(mapped(int)), this, SLOT(sbUsed(int)));
1288}//}}}
1289
1290
1291void SBPool::create(GuiScrollbar * sb, int orient)//{{{
1292{
1293 switch(orient) {
1294 case SBAR_HORIZ:
1295 sb->w = new QScrollBar(QScrollBar::Horizontal, vmw);
1296 break;
1297 case SBAR_VERT:
1298 sb->w = new QScrollBar(QScrollBar::Vertical, vmw);
1299 break;
1300 default:
1301 sb->w = 0;
1302 return;
1303 }
1304
1305 connect(sb->w, SIGNAL(valueChanged(int)), &mapper, SLOT(map()));
1306 mapper.setMapping(sb->w, (int)sb);
1307}//}}}
1308
1309
1310void SBPool::sbUsed(int who)//{{{
1311{
1312 GuiScrollbar *sb = (GuiScrollbar*)who;
1313 gui_drag_scrollbar( sb, sb->w->value(), FALSE);
1314}//}}}
1315
1316
1317void SBPool::destroy(GuiScrollbar * sb)//{{{
1318{
1319 if (!sb->w) return;
1320
1321 delete sb->w;
1322 sb->w = 0;
1323}//}}}
1324
1325#ifdef FEAT_CLIENTSERVER
1326static int kvim_x11_event_filter( XEvent* e)//{{{
1327{
1328 if (e->xproperty.type == PropertyNotify
1329 && e->xproperty.atom == commProperty
1330 && e->xproperty.window == commWindow
1331 && e->xproperty.state == PropertyNewValue ) {
1332 serverEventProc(qt_xdisplay(), e);
1333 }
1334
1335 if (oldFilter) return oldFilter( e );
1336 return FALSE;
1337}//}}}
1338#endif
1339
1340//add some QT 3 fonts usefull functions
1341#if QT_VERSION<300
1342QString KVimUtils::toString(QFont *f)
1343{
1344 QStringList l;
1345 l.append(f->family());
1346 l.append(QString::number(f->pointSize()));
1347 l.append(QString::number(f->pixelSize()));
1348 l.append(QString::number((int)f->styleHint()));
1349 l.append(QString::number(f->weight()));
1350 l.append(QString::number((int)f->italic()));
1351 l.append(QString::number((int)f->underline()));
1352 l.append(QString::number((int)f->strikeOut()));
1353 l.append(QString::number((int)f->fixedPitch()));
1354 l.append(QString::number((int)f->rawMode()));
1355 return l.join(",");
1356}
1357
1358bool KVimUtils::fromString(QFont *f, QString descrip)
1359{
1360 QStringList l(QStringList::split(',', descrip));
1361
1362 int count = l.count();
1363 if (count != 10 && count != 9) {
1364 return FALSE;
1365 }
1366
1367 f->setFamily(l[0]);
1368 f->setPointSize(l[1].toInt());
1369 if ( count == 9 ) {
1370 f->setStyleHint((QFont::StyleHint) l[2].toInt());
1371 f->setWeight(l[3].toInt());
1372 f->setItalic(l[4].toInt());
1373 f->setUnderline(l[5].toInt());
1374 f->setStrikeOut(l[6].toInt());
1375 f->setFixedPitch(l[7].toInt());
1376 f->setRawMode(l[8].toInt());
1377 } else {
1378 f->setPixelSize(l[2].toInt());
1379 f->setStyleHint((QFont::StyleHint) l[3].toInt());
1380 f->setWeight(l[4].toInt());
1381 f->setItalic(l[5].toInt());
1382 f->setUnderline(l[6].toInt());
1383 f->setStrikeOut(l[7].toInt());
1384 f->setFixedPitch(l[8].toInt());
1385 f->setRawMode(l[9].toInt());
1386 }
1387 return TRUE;
1388}
1389#endif
1390
1391QString KVimUtils::convertEncodingName(QString name)
1392{
1393 if (name.startsWith("ucs") || name.startsWith("utf-16")) return QString("utf16");
1394 if (name=="cp950") return QString("Big5");
1395 return QString();
1396}