author | zecke <zecke> | 2004-10-13 19:50:45 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-10-13 19:50:45 (UTC) |
commit | 2e51b60e861912fa525597f6b9de6b83c9cedf94 (patch) (unidiff) | |
tree | c212077850c4cdf9570f7d47bb2805fe33d6bfe6 | |
parent | 43fdc7bdf61f0e16be759c4083bd340afcf826f8 (diff) | |
download | opie-2e51b60e861912fa525597f6b9de6b83c9cedf94.zip opie-2e51b60e861912fa525597f6b9de6b83c9cedf94.tar.gz opie-2e51b60e861912fa525597f6b9de6b83c9cedf94.tar.bz2 |
Remove odebug/owarn
-rw-r--r-- | noncore/apps/opie-console/widget.cpp | 5 |
1 files changed, 0 insertions, 5 deletions
diff --git a/noncore/apps/opie-console/widget.cpp b/noncore/apps/opie-console/widget.cpp index c51983f..4a578be 100644 --- a/noncore/apps/opie-console/widget.cpp +++ b/noncore/apps/opie-console/widget.cpp | |||
@@ -230,1054 +230,1049 @@ static QChar vt100extended(QChar c) | |||
230 | case 0x2260 : return 29; | 230 | case 0x2260 : return 29; |
231 | case 0x00a3 : return 30; | 231 | case 0x00a3 : return 30; |
232 | case 0x00b7 : return 31; | 232 | case 0x00b7 : return 31; |
233 | } | 233 | } |
234 | return c; | 234 | return c; |
235 | } | 235 | } |
236 | 236 | ||
237 | static QChar identicalMap(QChar c) | 237 | static QChar identicalMap(QChar c) |
238 | { | 238 | { |
239 | return c; | 239 | return c; |
240 | } | 240 | } |
241 | 241 | ||
242 | void Widget::fontChange(const QFont &) | 242 | void Widget::fontChange(const QFont &) |
243 | { | 243 | { |
244 | QFontMetrics fm(font()); | 244 | QFontMetrics fm(font()); |
245 | font_h = fm.height(); | 245 | font_h = fm.height(); |
246 | font_w = fm.maxWidth(); | 246 | font_w = fm.maxWidth(); |
247 | font_a = fm.ascent(); | 247 | font_a = fm.ascent(); |
248 | //printf("font_h: %d\n",font_h); | 248 | //printf("font_h: %d\n",font_h); |
249 | //printf("font_w: %d\n",font_w); | 249 | //printf("font_w: %d\n",font_w); |
250 | //printf("font_a: %d\n",font_a); | 250 | //printf("font_a: %d\n",font_a); |
251 | //printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii()); | 251 | //printf("charset: %s\n",QFont::encodingName(font().charSet()).ascii()); |
252 | //printf("rawname: %s\n",font().rawName().ascii()); | 252 | //printf("rawname: %s\n",font().rawName().ascii()); |
253 | fontMap = | 253 | fontMap = |
254 | #if QT_VERSION < 300 | 254 | #if QT_VERSION < 300 |
255 | strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646") | 255 | strcmp(QFont::encodingName(font().charSet()).ascii(),"iso10646") |
256 | ? vt100extended | 256 | ? vt100extended |
257 | : | 257 | : |
258 | #endif | 258 | #endif |
259 | identicalMap; | 259 | identicalMap; |
260 | propagateSize(); | 260 | propagateSize(); |
261 | update(); | 261 | update(); |
262 | } | 262 | } |
263 | 263 | ||
264 | void Widget::setVTFont(const QFont& f) | 264 | void Widget::setVTFont(const QFont& f) |
265 | { | 265 | { |
266 | QFrame::setFont(f); | 266 | QFrame::setFont(f); |
267 | } | 267 | } |
268 | 268 | ||
269 | QFont Widget::getVTFont() { | 269 | QFont Widget::getVTFont() { |
270 | return font(); | 270 | return font(); |
271 | } | 271 | } |
272 | 272 | ||
273 | void Widget::setFont(const QFont &) | 273 | void Widget::setFont(const QFont &) |
274 | { | 274 | { |
275 | // ignore font change request if not coming from konsole itself | 275 | // ignore font change request if not coming from konsole itself |
276 | } | 276 | } |
277 | 277 | ||
278 | /* ------------------------------------------------------------------------- */ | 278 | /* ------------------------------------------------------------------------- */ |
279 | /* */ | 279 | /* */ |
280 | /* Constructor / Destructor */ | 280 | /* Constructor / Destructor */ |
281 | /* */ | 281 | /* */ |
282 | /* ------------------------------------------------------------------------- */ | 282 | /* ------------------------------------------------------------------------- */ |
283 | 283 | ||
284 | Widget::Widget(QWidget *parent, const char *name) : QFrame(parent,name) | 284 | Widget::Widget(QWidget *parent, const char *name) : QFrame(parent,name) |
285 | { | 285 | { |
286 | #ifndef QT_NO_CLIPBOARD | 286 | #ifndef QT_NO_CLIPBOARD |
287 | cb = QApplication::clipboard(); | 287 | cb = QApplication::clipboard(); |
288 | QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), | 288 | QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), |
289 | this, SLOT(onClearSelection()) ); | 289 | this, SLOT(onClearSelection()) ); |
290 | #endif | 290 | #endif |
291 | 291 | ||
292 | scrollbar = new QScrollBar(this); | 292 | scrollbar = new QScrollBar(this); |
293 | scrollbar->setCursor( arrowCursor ); | 293 | scrollbar->setCursor( arrowCursor ); |
294 | connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); | 294 | connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); |
295 | 295 | ||
296 | Config cfg("Konsole"); | 296 | Config cfg("Konsole"); |
297 | cfg.setGroup("ScrollBar"); | 297 | cfg.setGroup("ScrollBar"); |
298 | switch( cfg.readNumEntry("Position",2)){ | 298 | switch( cfg.readNumEntry("Position",2)){ |
299 | case 0: | 299 | case 0: |
300 | scrollLoc = SCRNONE; | 300 | scrollLoc = SCRNONE; |
301 | break; | 301 | break; |
302 | case 1: | 302 | case 1: |
303 | scrollLoc = SCRLEFT; | 303 | scrollLoc = SCRLEFT; |
304 | break; | 304 | break; |
305 | case 2: | 305 | case 2: |
306 | scrollLoc = SCRRIGHT; | 306 | scrollLoc = SCRRIGHT; |
307 | break; | 307 | break; |
308 | }; | 308 | }; |
309 | 309 | ||
310 | blinkT = new QTimer(this); | 310 | blinkT = new QTimer(this); |
311 | connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent())); | 311 | connect(blinkT, SIGNAL(timeout()), this, SLOT(blinkEvent())); |
312 | // blinking = FALSE; | 312 | // blinking = FALSE; |
313 | blinking = TRUE; | 313 | blinking = TRUE; |
314 | 314 | ||
315 | resizing = FALSE; | 315 | resizing = FALSE; |
316 | actSel = 0; | 316 | actSel = 0; |
317 | image = 0; | 317 | image = 0; |
318 | lines = 1; | 318 | lines = 1; |
319 | columns = 1; | 319 | columns = 1; |
320 | font_w = 1; | 320 | font_w = 1; |
321 | font_h = 1; | 321 | font_h = 1; |
322 | font_a = 1; | 322 | font_a = 1; |
323 | word_selection_mode = FALSE; | 323 | word_selection_mode = FALSE; |
324 | 324 | ||
325 | setMouseMarks(TRUE); | 325 | setMouseMarks(TRUE); |
326 | setVTFont( QFont("fixed") ); | 326 | setVTFont( QFont("fixed") ); |
327 | setColorTable(base_color_table); // init color table | 327 | setColorTable(base_color_table); // init color table |
328 | 328 | ||
329 | qApp->installEventFilter( this ); //FIXME: see below | 329 | qApp->installEventFilter( this ); //FIXME: see below |
330 | // KCursor::setAutoHideCursor( this, true ); | 330 | // KCursor::setAutoHideCursor( this, true ); |
331 | 331 | ||
332 | // Init DnD //////////////////////////////////////////////////////////////// | 332 | // Init DnD //////////////////////////////////////////////////////////////// |
333 | currentSession = NULL; | 333 | currentSession = NULL; |
334 | // setAcceptDrops(true); // attempt | 334 | // setAcceptDrops(true); // attempt |
335 | // m_drop = new QPopupMenu(this); | 335 | // m_drop = new QPopupMenu(this); |
336 | // m_drop->insertItem( QString("Paste"), 0); | 336 | // m_drop->insertItem( QString("Paste"), 0); |
337 | // m_drop->insertItem( QString("cd"), 1); | 337 | // m_drop->insertItem( QString("cd"), 1); |
338 | // connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int))); | 338 | // connect(m_drop, SIGNAL(activated(int)), SLOT(drop_menu_activated(int))); |
339 | 339 | ||
340 | // we need focus so that the auto-hide cursor feature works | 340 | // we need focus so that the auto-hide cursor feature works |
341 | setFocus(); | 341 | setFocus(); |
342 | setFocusPolicy( WheelFocus ); | 342 | setFocusPolicy( WheelFocus ); |
343 | } | 343 | } |
344 | 344 | ||
345 | //FIXME: make proper destructor | 345 | //FIXME: make proper destructor |
346 | // Here's a start (David) | 346 | // Here's a start (David) |
347 | Widget::~Widget() | 347 | Widget::~Widget() |
348 | { | 348 | { |
349 | qApp->removeEventFilter( this ); | 349 | qApp->removeEventFilter( this ); |
350 | if (image) free(image); | 350 | if (image) free(image); |
351 | } | 351 | } |
352 | 352 | ||
353 | /* ------------------------------------------------------------------------- */ | 353 | /* ------------------------------------------------------------------------- */ |
354 | /* */ | 354 | /* */ |
355 | /* Display Operations */ | 355 | /* Display Operations */ |
356 | /* */ | 356 | /* */ |
357 | /* ------------------------------------------------------------------------- */ | 357 | /* ------------------------------------------------------------------------- */ |
358 | 358 | ||
359 | /*! | 359 | /*! |
360 | attributed string draw primitive | 360 | attributed string draw primitive |
361 | */ | 361 | */ |
362 | 362 | ||
363 | void Widget::drawAttrStr(QPainter &paint, QRect rect, | 363 | void Widget::drawAttrStr(QPainter &paint, QRect rect, |
364 | QString& str, Character attr, BOOL pm, BOOL clear) | 364 | QString& str, Character attr, BOOL pm, BOOL clear) |
365 | { | 365 | { |
366 | if (pm && color_table[attr.b].transparent) | 366 | if (pm && color_table[attr.b].transparent) |
367 | { | 367 | { |
368 | paint.setBackgroundMode( TransparentMode ); | 368 | paint.setBackgroundMode( TransparentMode ); |
369 | if (clear) erase(rect); | 369 | if (clear) erase(rect); |
370 | } | 370 | } |
371 | else | 371 | else |
372 | { | 372 | { |
373 | if (blinking) | 373 | if (blinking) |
374 | paint.fillRect(rect, color_table[attr.b].color); | 374 | paint.fillRect(rect, color_table[attr.b].color); |
375 | else | 375 | else |
376 | { | 376 | { |
377 | paint.setBackgroundMode( OpaqueMode ); | 377 | paint.setBackgroundMode( OpaqueMode ); |
378 | paint.setBackgroundColor( color_table[attr.b].color ); | 378 | paint.setBackgroundColor( color_table[attr.b].color ); |
379 | } | 379 | } |
380 | } | 380 | } |
381 | 381 | ||
382 | if (color_table[attr.f].bold) | 382 | if (color_table[attr.f].bold) |
383 | paint.setPen(QColor( 0x8F, 0x00, 0x00 )); | 383 | paint.setPen(QColor( 0x8F, 0x00, 0x00 )); |
384 | else | 384 | else |
385 | paint.setPen(color_table[attr.f].color); | 385 | paint.setPen(color_table[attr.f].color); |
386 | 386 | ||
387 | paint.drawText(rect.x(),rect.y()+font_a, str); | 387 | paint.drawText(rect.x(),rect.y()+font_a, str); |
388 | 388 | ||
389 | if (attr.r & RE_UNDERLINE) | 389 | if (attr.r & RE_UNDERLINE) |
390 | paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 ); | 390 | paint.drawLine(rect.left(), rect.y()+font_a+1, rect.right(),rect.y()+font_a+1 ); |
391 | } | 391 | } |
392 | 392 | ||
393 | /*! | 393 | /*! |
394 | The image can only be set completely. | 394 | The image can only be set completely. |
395 | 395 | ||
396 | The size of the new image may or may not match the size of the widget. | 396 | The size of the new image may or may not match the size of the widget. |
397 | */ | 397 | */ |
398 | 398 | ||
399 | void Widget::setImage(const Character* const newimg, int lines, int columns) | 399 | void Widget::setImage(const Character* const newimg, int lines, int columns) |
400 | { int y,x,len; | 400 | { int y,x,len; |
401 | const QPixmap* pm = backgroundPixmap(); | 401 | const QPixmap* pm = backgroundPixmap(); |
402 | QPainter paint; | 402 | QPainter paint; |
403 | setUpdatesEnabled(FALSE); | 403 | setUpdatesEnabled(FALSE); |
404 | paint.begin( this ); | 404 | paint.begin( this ); |
405 | HCNT("setImage"); | 405 | HCNT("setImage"); |
406 | 406 | ||
407 | QPoint tL = contentsRect().topLeft(); | 407 | QPoint tL = contentsRect().topLeft(); |
408 | int tLx = tL.x(); | 408 | int tLx = tL.x(); |
409 | int tLy = tL.y(); | 409 | int tLy = tL.y(); |
410 | hasBlinker = FALSE; | 410 | hasBlinker = FALSE; |
411 | 411 | ||
412 | int cf = -1; // undefined | 412 | int cf = -1; // undefined |
413 | int cb = -1; // undefined | 413 | int cb = -1; // undefined |
414 | int cr = -1; // undefined | 414 | int cr = -1; // undefined |
415 | 415 | ||
416 | int lins = QMIN(this->lines, QMAX(0,lines )); | 416 | int lins = QMIN(this->lines, QMAX(0,lines )); |
417 | int cols = QMIN(this->columns,QMAX(0,columns)); | 417 | int cols = QMIN(this->columns,QMAX(0,columns)); |
418 | QChar *disstrU = new QChar[cols]; | 418 | QChar *disstrU = new QChar[cols]; |
419 | 419 | ||
420 | //{ static int cnt = 0; printf("setImage %d\n",cnt++); } | 420 | //{ static int cnt = 0; printf("setImage %d\n",cnt++); } |
421 | for (y = 0; y < lins; y++) | 421 | for (y = 0; y < lins; y++) |
422 | { | 422 | { |
423 | const Character* lcl = &image[y*this->columns]; | 423 | const Character* lcl = &image[y*this->columns]; |
424 | const Character* const ext = &newimg[y*columns]; | 424 | const Character* const ext = &newimg[y*columns]; |
425 | if (!resizing) // not while resizing, we're expecting a paintEvent | 425 | if (!resizing) // not while resizing, we're expecting a paintEvent |
426 | for (x = 0; x < cols; x++) | 426 | for (x = 0; x < cols; x++) |
427 | { | 427 | { |
428 | hasBlinker |= (ext[x].r & RE_BLINK); | 428 | hasBlinker |= (ext[x].r & RE_BLINK); |
429 | if (ext[x] != lcl[x]) | 429 | if (ext[x] != lcl[x]) |
430 | { | 430 | { |
431 | cr = ext[x].r; | 431 | cr = ext[x].r; |
432 | cb = ext[x].b; | 432 | cb = ext[x].b; |
433 | if (ext[x].f != cf) cf = ext[x].f; | 433 | if (ext[x].f != cf) cf = ext[x].f; |
434 | int lln = cols - x; | 434 | int lln = cols - x; |
435 | disstrU[0] = fontMap(ext[x+0].c); | 435 | disstrU[0] = fontMap(ext[x+0].c); |
436 | for (len = 1; len < lln; len++) | 436 | for (len = 1; len < lln; len++) |
437 | { | 437 | { |
438 | if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr || | 438 | if (ext[x+len].f != cf || ext[x+len].b != cb || ext[x+len].r != cr || |
439 | ext[x+len] == lcl[x+len] ) | 439 | ext[x+len] == lcl[x+len] ) |
440 | break; | 440 | break; |
441 | disstrU[len] = fontMap(ext[x+len].c); | 441 | disstrU[len] = fontMap(ext[x+len].c); |
442 | } | 442 | } |
443 | QString unistr(disstrU,len); | 443 | QString unistr(disstrU,len); |
444 | drawAttrStr(paint, | 444 | drawAttrStr(paint, |
445 | QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), | 445 | QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), |
446 | unistr, ext[x], pm != NULL, true); | 446 | unistr, ext[x], pm != NULL, true); |
447 | x += len - 1; | 447 | x += len - 1; |
448 | } | 448 | } |
449 | } | 449 | } |
450 | // finally, make `image' become `newimg'. | 450 | // finally, make `image' become `newimg'. |
451 | memcpy((void*)lcl,(const void*)ext,cols*sizeof(Character)); | 451 | memcpy((void*)lcl,(const void*)ext,cols*sizeof(Character)); |
452 | } | 452 | } |
453 | drawFrame( &paint ); | 453 | drawFrame( &paint ); |
454 | paint.end(); | 454 | paint.end(); |
455 | setUpdatesEnabled(TRUE); | 455 | setUpdatesEnabled(TRUE); |
456 | if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms | 456 | if ( hasBlinker && !blinkT->isActive()) blinkT->start(1000); // 1000 ms |
457 | if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; } | 457 | if (!hasBlinker && blinkT->isActive()) { blinkT->stop(); blinking = FALSE; } |
458 | delete [] disstrU; | 458 | delete [] disstrU; |
459 | } | 459 | } |
460 | 460 | ||
461 | // paint Event //////////////////////////////////////////////////// | 461 | // paint Event //////////////////////////////////////////////////// |
462 | 462 | ||
463 | /*! | 463 | /*! |
464 | The difference of this routine vs. the `setImage' is, | 464 | The difference of this routine vs. the `setImage' is, |
465 | that the drawing does not include a difference analysis | 465 | that the drawing does not include a difference analysis |
466 | between the old and the new image. Instead, the internal | 466 | between the old and the new image. Instead, the internal |
467 | image is used and the painting bound by the PaintEvent box. | 467 | image is used and the painting bound by the PaintEvent box. |
468 | */ | 468 | */ |
469 | 469 | ||
470 | void Widget::paintEvent( QPaintEvent* pe ) | 470 | void Widget::paintEvent( QPaintEvent* pe ) |
471 | { | 471 | { |
472 | 472 | ||
473 | //{ static int cnt = 0; printf("paint %d\n",cnt++); } | 473 | //{ static int cnt = 0; printf("paint %d\n",cnt++); } |
474 | const QPixmap* pm = backgroundPixmap(); | 474 | const QPixmap* pm = backgroundPixmap(); |
475 | QPainter paint; | 475 | QPainter paint; |
476 | setUpdatesEnabled(FALSE); | 476 | setUpdatesEnabled(FALSE); |
477 | paint.begin( this ); | 477 | paint.begin( this ); |
478 | paint.setBackgroundMode( TransparentMode ); | 478 | paint.setBackgroundMode( TransparentMode ); |
479 | HCNT("paintEvent"); | 479 | HCNT("paintEvent"); |
480 | 480 | ||
481 | // Note that the actual widget size can be slightly larger | 481 | // Note that the actual widget size can be slightly larger |
482 | // that the image (the size is truncated towards the smaller | 482 | // that the image (the size is truncated towards the smaller |
483 | // number of characters in `resizeEvent'. The paint rectangle | 483 | // number of characters in `resizeEvent'. The paint rectangle |
484 | // can thus be larger than the image, but less then the size | 484 | // can thus be larger than the image, but less then the size |
485 | // of one character. | 485 | // of one character. |
486 | 486 | ||
487 | QRect rect = pe->rect().intersect(contentsRect()); | 487 | QRect rect = pe->rect().intersect(contentsRect()); |
488 | 488 | ||
489 | QPoint tL = contentsRect().topLeft(); | 489 | QPoint tL = contentsRect().topLeft(); |
490 | int tLx = tL.x(); | 490 | int tLx = tL.x(); |
491 | int tLy = tL.y(); | 491 | int tLy = tL.y(); |
492 | 492 | ||
493 | int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w)); | 493 | int lux = QMIN(columns-1, QMAX(0,(rect.left() - tLx - blX ) / font_w)); |
494 | int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h)); | 494 | int luy = QMIN(lines-1, QMAX(0,(rect.top() - tLy - bY ) / font_h)); |
495 | int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w)); | 495 | int rlx = QMIN(columns-1, QMAX(0,(rect.right() - tLx - blX ) / font_w)); |
496 | int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h)); | 496 | int rly = QMIN(lines-1, QMAX(0,(rect.bottom() - tLy - bY ) / font_h)); |
497 | 497 | ||
498 | /* | 498 | /* |
499 | printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly, | 499 | printf("paintEvent: %d..%d, %d..%d (%d..%d, %d..%d)\n",lux,rlx,luy,rly, |
500 | rect.left(), rect.right(), rect.top(), rect.bottom()); | 500 | rect.left(), rect.right(), rect.top(), rect.bottom()); |
501 | */ | 501 | */ |
502 | 502 | ||
503 | // if (pm != NULL && color_table[image->b].transparent) | 503 | // if (pm != NULL && color_table[image->b].transparent) |
504 | // erase(rect); | 504 | // erase(rect); |
505 | // BL: I have no idea why we need this, and it breaks the refresh. | 505 | // BL: I have no idea why we need this, and it breaks the refresh. |
506 | 506 | ||
507 | QChar *disstrU = new QChar[columns]; | 507 | QChar *disstrU = new QChar[columns]; |
508 | for (int y = luy; y <= rly; y++) | 508 | for (int y = luy; y <= rly; y++) |
509 | for (int x = lux; x <= rlx; x++) | 509 | for (int x = lux; x <= rlx; x++) |
510 | { | 510 | { |
511 | int len = 1; | 511 | int len = 1; |
512 | disstrU[0] = fontMap(image[loc(x,y)].c); | 512 | disstrU[0] = fontMap(image[loc(x,y)].c); |
513 | int cf = image[loc(x,y)].f; | 513 | int cf = image[loc(x,y)].f; |
514 | int cb = image[loc(x,y)].b; | 514 | int cb = image[loc(x,y)].b; |
515 | int cr = image[loc(x,y)].r; | 515 | int cr = image[loc(x,y)].r; |
516 | while (x+len <= rlx && | 516 | while (x+len <= rlx && |
517 | image[loc(x+len,y)].f == cf && | 517 | image[loc(x+len,y)].f == cf && |
518 | image[loc(x+len,y)].b == cb && | 518 | image[loc(x+len,y)].b == cb && |
519 | image[loc(x+len,y)].r == cr ) | 519 | image[loc(x+len,y)].r == cr ) |
520 | { | 520 | { |
521 | disstrU[len] = fontMap(image[loc(x+len,y)].c); | 521 | disstrU[len] = fontMap(image[loc(x+len,y)].c); |
522 | len += 1; | 522 | len += 1; |
523 | } | 523 | } |
524 | QString unistr(disstrU,len); | 524 | QString unistr(disstrU,len); |
525 | drawAttrStr(paint, | 525 | drawAttrStr(paint, |
526 | QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), | 526 | QRect(blX+tLx+font_w*x,bY+tLy+font_h*y,font_w*len,font_h), |
527 | unistr, image[loc(x,y)], pm != NULL, false); | 527 | unistr, image[loc(x,y)], pm != NULL, false); |
528 | x += len - 1; | 528 | x += len - 1; |
529 | } | 529 | } |
530 | delete [] disstrU; | 530 | delete [] disstrU; |
531 | drawFrame( &paint ); | 531 | drawFrame( &paint ); |
532 | paint.end(); | 532 | paint.end(); |
533 | setUpdatesEnabled(TRUE); | 533 | setUpdatesEnabled(TRUE); |
534 | } | 534 | } |
535 | 535 | ||
536 | void Widget::blinkEvent() | 536 | void Widget::blinkEvent() |
537 | { | 537 | { |
538 | blinking = !blinking; | 538 | blinking = !blinking; |
539 | repaint(FALSE); | 539 | repaint(FALSE); |
540 | } | 540 | } |
541 | 541 | ||
542 | /* ------------------------------------------------------------------------- */ | 542 | /* ------------------------------------------------------------------------- */ |
543 | /* */ | 543 | /* */ |
544 | /* Resizing */ | 544 | /* Resizing */ |
545 | /* */ | 545 | /* */ |
546 | /* ------------------------------------------------------------------------- */ | 546 | /* ------------------------------------------------------------------------- */ |
547 | 547 | ||
548 | void Widget::resizeEvent(QResizeEvent* ev) | 548 | void Widget::resizeEvent(QResizeEvent* ev) |
549 | { | 549 | { |
550 | // printf("resize: %d,%d\n",ev->size().width(),ev->size().height()); | 550 | // printf("resize: %d,%d\n",ev->size().width(),ev->size().height()); |
551 | //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h); | 551 | //printf("approx: %d,%d\n",ev->size().width()/font_w,ev->size().height()/font_h); |
552 | //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h); | 552 | //printf("leaves: %d,%d\n",ev->size().width()%font_w,ev->size().height()%font_h); |
553 | //printf("curren: %d,%d\n",width(),height()); | 553 | //printf("curren: %d,%d\n",width(),height()); |
554 | HCNT("resizeEvent"); | 554 | HCNT("resizeEvent"); |
555 | 555 | ||
556 | // see comment in `paintEvent' concerning the rounding. | 556 | // see comment in `paintEvent' concerning the rounding. |
557 | //FIXME: could make a routine here; check width(),height() | 557 | //FIXME: could make a routine here; check width(),height() |
558 | assert(ev->size().width() == width()); | 558 | assert(ev->size().width() == width()); |
559 | assert(ev->size().height() == height()); | 559 | assert(ev->size().height() == height()); |
560 | 560 | ||
561 | propagateSize(); | 561 | propagateSize(); |
562 | } | 562 | } |
563 | 563 | ||
564 | void Widget::propagateSize() | 564 | void Widget::propagateSize() |
565 | { | 565 | { |
566 | Character* oldimg = image; | 566 | Character* oldimg = image; |
567 | int oldlin = lines; | 567 | int oldlin = lines; |
568 | int oldcol = columns; | 568 | int oldcol = columns; |
569 | makeImage(); | 569 | makeImage(); |
570 | // we copy the old image to reduce flicker | 570 | // we copy the old image to reduce flicker |
571 | int lins = QMIN(oldlin,lines); | 571 | int lins = QMIN(oldlin,lines); |
572 | int cols = QMIN(oldcol,columns); | 572 | int cols = QMIN(oldcol,columns); |
573 | if (oldimg) | 573 | if (oldimg) |
574 | { | 574 | { |
575 | for (int lin = 0; lin < lins; lin++) | 575 | for (int lin = 0; lin < lins; lin++) |
576 | memcpy((void*)&image[columns*lin], | 576 | memcpy((void*)&image[columns*lin], |
577 | (void*)&oldimg[oldcol*lin],cols*sizeof(Character)); | 577 | (void*)&oldimg[oldcol*lin],cols*sizeof(Character)); |
578 | free(oldimg); //FIXME: try new,delete | 578 | free(oldimg); //FIXME: try new,delete |
579 | } | 579 | } |
580 | else | 580 | else |
581 | clearImage(); | 581 | clearImage(); |
582 | 582 | ||
583 | //NOTE: control flows from the back through the chest right into the eye. | 583 | //NOTE: control flows from the back through the chest right into the eye. |
584 | // `emu' will call back via `setImage'. | 584 | // `emu' will call back via `setImage'. |
585 | 585 | ||
586 | resizing = TRUE; | 586 | resizing = TRUE; |
587 | emit changedImageSizeSignal(lines, columns); // expose resizeEvent | 587 | emit changedImageSizeSignal(lines, columns); // expose resizeEvent |
588 | resizing = FALSE; | 588 | resizing = FALSE; |
589 | } | 589 | } |
590 | 590 | ||
591 | /* ------------------------------------------------------------------------- */ | 591 | /* ------------------------------------------------------------------------- */ |
592 | /* */ | 592 | /* */ |
593 | /* Scrollbar */ | 593 | /* Scrollbar */ |
594 | /* */ | 594 | /* */ |
595 | /* ------------------------------------------------------------------------- */ | 595 | /* ------------------------------------------------------------------------- */ |
596 | 596 | ||
597 | void Widget::scrollChanged(int) | 597 | void Widget::scrollChanged(int) |
598 | { | 598 | { |
599 | emit changedHistoryCursor(scrollbar->value()); //expose | 599 | emit changedHistoryCursor(scrollbar->value()); //expose |
600 | } | 600 | } |
601 | 601 | ||
602 | void Widget::setScroll(int cursor, int slines) | 602 | void Widget::setScroll(int cursor, int slines) |
603 | { | 603 | { |
604 | disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); | 604 | disconnect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); |
605 | scrollbar->setRange(0,slines); | 605 | scrollbar->setRange(0,slines); |
606 | scrollbar->setSteps(1,lines); | 606 | scrollbar->setSteps(1,lines); |
607 | scrollbar->setValue(cursor); | 607 | scrollbar->setValue(cursor); |
608 | connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); | 608 | connect(scrollbar, SIGNAL(valueChanged(int)), this, SLOT(scrollChanged(int))); |
609 | } | 609 | } |
610 | 610 | ||
611 | void Widget::setScrollbarLocation(int loc) | 611 | void Widget::setScrollbarLocation(int loc) |
612 | { | 612 | { |
613 | if (scrollLoc == loc) return; // quickly | 613 | if (scrollLoc == loc) return; // quickly |
614 | scrollLoc = loc; | 614 | scrollLoc = loc; |
615 | propagateSize(); | 615 | propagateSize(); |
616 | update(); | 616 | update(); |
617 | } | 617 | } |
618 | 618 | ||
619 | /* ------------------------------------------------------------------------- */ | 619 | /* ------------------------------------------------------------------------- */ |
620 | /* */ | 620 | /* */ |
621 | /* Mouse */ | 621 | /* Mouse */ |
622 | /* */ | 622 | /* */ |
623 | /* ------------------------------------------------------------------------- */ | 623 | /* ------------------------------------------------------------------------- */ |
624 | 624 | ||
625 | /*! | 625 | /*! |
626 | Three different operations can be performed using the mouse, and the | 626 | Three different operations can be performed using the mouse, and the |
627 | routines in this section serve all of them: | 627 | routines in this section serve all of them: |
628 | 628 | ||
629 | 1) The press/release events are exposed to the application | 629 | 1) The press/release events are exposed to the application |
630 | 2) Marking (press and move left button) and Pasting (press middle button) | 630 | 2) Marking (press and move left button) and Pasting (press middle button) |
631 | 3) The right mouse button is used from the configuration menu | 631 | 3) The right mouse button is used from the configuration menu |
632 | 632 | ||
633 | NOTE: During the marking process we attempt to keep the cursor within | 633 | NOTE: During the marking process we attempt to keep the cursor within |
634 | the bounds of the text as being displayed by setting the mouse position | 634 | the bounds of the text as being displayed by setting the mouse position |
635 | whenever the mouse has left the text area. | 635 | whenever the mouse has left the text area. |
636 | 636 | ||
637 | Two reasons to do so: | 637 | Two reasons to do so: |
638 | 1) QT does not allow the `grabMouse' to confine-to the Widget. | 638 | 1) QT does not allow the `grabMouse' to confine-to the Widget. |
639 | Thus a `XGrapPointer' would have to be used instead. | 639 | Thus a `XGrapPointer' would have to be used instead. |
640 | 2) Even if so, this would not help too much, since the text area | 640 | 2) Even if so, this would not help too much, since the text area |
641 | of the Widget is normally not identical with it's bounds. | 641 | of the Widget is normally not identical with it's bounds. |
642 | 642 | ||
643 | The disadvantage of the current handling is, that the mouse can visibly | 643 | The disadvantage of the current handling is, that the mouse can visibly |
644 | leave the bounds of the widget and is then moved back. Because of the | 644 | leave the bounds of the widget and is then moved back. Because of the |
645 | current construction, and the reasons mentioned above, we cannot do better | 645 | current construction, and the reasons mentioned above, we cannot do better |
646 | without changing the overall construction. | 646 | without changing the overall construction. |
647 | */ | 647 | */ |
648 | 648 | ||
649 | /*! | 649 | /*! |
650 | */ | 650 | */ |
651 | 651 | ||
652 | void Widget::mousePressEvent(QMouseEvent* ev) | 652 | void Widget::mousePressEvent(QMouseEvent* ev) |
653 | { | 653 | { |
654 | //printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); | 654 | //printf("press [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); |
655 | if ( !contentsRect().contains(ev->pos()) ) return; | 655 | if ( !contentsRect().contains(ev->pos()) ) return; |
656 | QPoint tL = contentsRect().topLeft(); | 656 | QPoint tL = contentsRect().topLeft(); |
657 | int tLx = tL.x(); | 657 | int tLx = tL.x(); |
658 | int tLy = tL.y(); | 658 | int tLy = tL.y(); |
659 | 659 | ||
660 | word_selection_mode = FALSE; | 660 | word_selection_mode = FALSE; |
661 | 661 | ||
662 | //printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY); | 662 | //printf("press top left [%d,%d] by=%d\n",tLx,tLy, bY); |
663 | if ( ev->button() == LeftButton) | 663 | if ( ev->button() == LeftButton) |
664 | { | 664 | { |
665 | QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); | 665 | QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); |
666 | 666 | ||
667 | if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ; | 667 | if ( ev->state() & ControlButton ) preserve_line_breaks = FALSE ; |
668 | 668 | ||
669 | if (mouse_marks || (ev->state() & ShiftButton)) | 669 | if (mouse_marks || (ev->state() & ShiftButton)) |
670 | { | 670 | { |
671 | emit clearSelectionSignal(); | 671 | emit clearSelectionSignal(); |
672 | iPntSel = pntSel = pos; | 672 | iPntSel = pntSel = pos; |
673 | actSel = 1; // left mouse button pressed but nothing selected yet. | 673 | actSel = 1; // left mouse button pressed but nothing selected yet. |
674 | grabMouse( /*crossCursor*/ ); // handle with care! | 674 | grabMouse( /*crossCursor*/ ); // handle with care! |
675 | } | 675 | } |
676 | else | 676 | else |
677 | { | 677 | { |
678 | emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button | 678 | emit mouseSignal( 0, pos.x() + 1, pos.y() + 1 ); // left button |
679 | } | 679 | } |
680 | } | 680 | } |
681 | if ( ev->button() == MidButton ) | 681 | if ( ev->button() == MidButton ) |
682 | { | 682 | { |
683 | emitSelection(); | 683 | emitSelection(); |
684 | } | 684 | } |
685 | if ( ev->button() == RightButton ) // Configure | 685 | if ( ev->button() == RightButton ) // Configure |
686 | { | 686 | { |
687 | emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() ); | 687 | emit configureRequest( this, ev->state()&(ShiftButton|ControlButton), ev->x(), ev->y() ); |
688 | } | 688 | } |
689 | } | 689 | } |
690 | 690 | ||
691 | void Widget::mouseMoveEvent(QMouseEvent* ev) | 691 | void Widget::mouseMoveEvent(QMouseEvent* ev) |
692 | { | 692 | { |
693 | // for auto-hiding the cursor, we need mouseTracking | 693 | // for auto-hiding the cursor, we need mouseTracking |
694 | if (ev->state() == NoButton ) return; | 694 | if (ev->state() == NoButton ) return; |
695 | 695 | ||
696 | if (actSel == 0) return; | 696 | if (actSel == 0) return; |
697 | 697 | ||
698 | // don't extend selection while pasting | 698 | // don't extend selection while pasting |
699 | if (ev->state() & MidButton) return; | 699 | if (ev->state() & MidButton) return; |
700 | 700 | ||
701 | //if ( !contentsRect().contains(ev->pos()) ) return; | 701 | //if ( !contentsRect().contains(ev->pos()) ) return; |
702 | QPoint tL = contentsRect().topLeft(); | 702 | QPoint tL = contentsRect().topLeft(); |
703 | int tLx = tL.x(); | 703 | int tLx = tL.x(); |
704 | int tLy = tL.y(); | 704 | int tLy = tL.y(); |
705 | int scroll = scrollbar->value(); | 705 | int scroll = scrollbar->value(); |
706 | 706 | ||
707 | // we're in the process of moving the mouse with the left button pressed | 707 | // we're in the process of moving the mouse with the left button pressed |
708 | // the mouse cursor will kept catched within the bounds of the text in | 708 | // the mouse cursor will kept catched within the bounds of the text in |
709 | // this widget. | 709 | // this widget. |
710 | 710 | ||
711 | // Adjust position within text area bounds. See FIXME above. | 711 | // Adjust position within text area bounds. See FIXME above. |
712 | QPoint pos = ev->pos(); | 712 | QPoint pos = ev->pos(); |
713 | if ( pos.x() < tLx+blX ) pos.setX( tLx+blX ); | 713 | if ( pos.x() < tLx+blX ) pos.setX( tLx+blX ); |
714 | if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w ); | 714 | if ( pos.x() > tLx+blX+columns*font_w-1 ) pos.setX( tLx+blX+columns*font_w ); |
715 | if ( pos.y() < tLy+bY ) pos.setY( tLy+bY ); | 715 | if ( pos.y() < tLy+bY ) pos.setY( tLy+bY ); |
716 | if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 ); | 716 | if ( pos.y() > tLy+bY+lines*font_h-1 ) pos.setY( tLy+bY+lines*font_h-1 ); |
717 | // check if we produce a mouse move event by this | 717 | // check if we produce a mouse move event by this |
718 | if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos)); | 718 | if ( pos != ev->pos() ) cursor().setPos(mapToGlobal(pos)); |
719 | 719 | ||
720 | if ( pos.y() == tLy+bY+lines*font_h-1 ) | 720 | if ( pos.y() == tLy+bY+lines*font_h-1 ) |
721 | { | 721 | { |
722 | scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward | 722 | scrollbar->setValue(scrollbar->value()+yMouseScroll); // scrollforward |
723 | } | 723 | } |
724 | if ( pos.y() == tLy+bY ) | 724 | if ( pos.y() == tLy+bY ) |
725 | { | 725 | { |
726 | scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback | 726 | scrollbar->setValue(scrollbar->value()-yMouseScroll); // scrollback |
727 | } | 727 | } |
728 | 728 | ||
729 | QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h); | 729 | QPoint here = QPoint((pos.x()-tLx-blX)/font_w,(pos.y()-tLy-bY)/font_h); |
730 | QPoint ohere; | 730 | QPoint ohere; |
731 | bool swapping = FALSE; | 731 | bool swapping = FALSE; |
732 | 732 | ||
733 | if ( word_selection_mode ) | 733 | if ( word_selection_mode ) |
734 | { | 734 | { |
735 | // Extend to word boundaries | 735 | // Extend to word boundaries |
736 | int i; | 736 | int i; |
737 | int selClass; | 737 | int selClass; |
738 | 738 | ||
739 | bool left_not_right = ( here.y() < iPntSel.y() || | 739 | bool left_not_right = ( here.y() < iPntSel.y() || |
740 | here.y() == iPntSel.y() && here.x() < iPntSel.x() ); | 740 | here.y() == iPntSel.y() && here.x() < iPntSel.x() ); |
741 | bool old_left_not_right = ( pntSel.y() < iPntSel.y() || | 741 | bool old_left_not_right = ( pntSel.y() < iPntSel.y() || |
742 | pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() ); | 742 | pntSel.y() == iPntSel.y() && pntSel.x() < iPntSel.x() ); |
743 | swapping = left_not_right != old_left_not_right; | 743 | swapping = left_not_right != old_left_not_right; |
744 | 744 | ||
745 | // Find left (left_not_right ? from here : from start) | 745 | // Find left (left_not_right ? from here : from start) |
746 | QPoint left = left_not_right ? here : iPntSel; | 746 | QPoint left = left_not_right ? here : iPntSel; |
747 | i = loc(left.x(),left.y()); | 747 | i = loc(left.x(),left.y()); |
748 | selClass = charClass(image[i].c); | 748 | selClass = charClass(image[i].c); |
749 | while ( left.x() > 0 && charClass(image[i-1].c) == selClass ) | 749 | while ( left.x() > 0 && charClass(image[i-1].c) == selClass ) |
750 | { i--; left.rx()--; } | 750 | { i--; left.rx()--; } |
751 | 751 | ||
752 | // Find left (left_not_right ? from start : from here) | 752 | // Find left (left_not_right ? from start : from here) |
753 | QPoint right = left_not_right ? iPntSel : here; | 753 | QPoint right = left_not_right ? iPntSel : here; |
754 | i = loc(right.x(),right.y()); | 754 | i = loc(right.x(),right.y()); |
755 | selClass = charClass(image[i].c); | 755 | selClass = charClass(image[i].c); |
756 | while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass ) | 756 | while ( right.x() < columns-1 && charClass(image[i+1].c) == selClass ) |
757 | { i++; right.rx()++; } | 757 | { i++; right.rx()++; } |
758 | 758 | ||
759 | // Pick which is start (ohere) and which is extension (here) | 759 | // Pick which is start (ohere) and which is extension (here) |
760 | if ( left_not_right ) | 760 | if ( left_not_right ) |
761 | { | 761 | { |
762 | here = left; ohere = right; | 762 | here = left; ohere = right; |
763 | } | 763 | } |
764 | else | 764 | else |
765 | { | 765 | { |
766 | here = right; ohere = left; | 766 | here = right; ohere = left; |
767 | } | 767 | } |
768 | } | 768 | } |
769 | 769 | ||
770 | if (here == pntSel && scroll == scrollbar->value()) return; // not moved | 770 | if (here == pntSel && scroll == scrollbar->value()) return; // not moved |
771 | 771 | ||
772 | if ( word_selection_mode ) { | 772 | if ( word_selection_mode ) { |
773 | if ( actSel < 2 || swapping ) { | 773 | if ( actSel < 2 || swapping ) { |
774 | emit beginSelectionSignal( ohere.x(), ohere.y() ); | 774 | emit beginSelectionSignal( ohere.x(), ohere.y() ); |
775 | } | 775 | } |
776 | } else if ( actSel < 2 ) { | 776 | } else if ( actSel < 2 ) { |
777 | emit beginSelectionSignal( pntSel.x(), pntSel.y() ); | 777 | emit beginSelectionSignal( pntSel.x(), pntSel.y() ); |
778 | } | 778 | } |
779 | 779 | ||
780 | actSel = 2; // within selection | 780 | actSel = 2; // within selection |
781 | pntSel = here; | 781 | pntSel = here; |
782 | emit extendSelectionSignal( here.x(), here.y() ); | 782 | emit extendSelectionSignal( here.x(), here.y() ); |
783 | } | 783 | } |
784 | 784 | ||
785 | void Widget::mouseReleaseEvent(QMouseEvent* ev) | 785 | void Widget::mouseReleaseEvent(QMouseEvent* ev) |
786 | { | 786 | { |
787 | //printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); | 787 | //printf("release [%d,%d] %d\n",ev->x()/font_w,ev->y()/font_h,ev->button()); |
788 | if ( ev->button() == LeftButton) | 788 | if ( ev->button() == LeftButton) |
789 | { | 789 | { |
790 | if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks); | 790 | if ( actSel > 1 ) emit endSelectionSignal(preserve_line_breaks); |
791 | preserve_line_breaks = TRUE; | 791 | preserve_line_breaks = TRUE; |
792 | actSel = 0; | 792 | actSel = 0; |
793 | 793 | ||
794 | //FIXME: emits a release event even if the mouse is | 794 | //FIXME: emits a release event even if the mouse is |
795 | // outside the range. The procedure used in `mouseMoveEvent' | 795 | // outside the range. The procedure used in `mouseMoveEvent' |
796 | // applies here, too. | 796 | // applies here, too. |
797 | 797 | ||
798 | QPoint tL = contentsRect().topLeft(); | 798 | QPoint tL = contentsRect().topLeft(); |
799 | int tLx = tL.x(); | 799 | int tLx = tL.x(); |
800 | int tLy = tL.y(); | 800 | int tLy = tL.y(); |
801 | 801 | ||
802 | if (!mouse_marks && !(ev->state() & ShiftButton)) | 802 | if (!mouse_marks && !(ev->state() & ShiftButton)) |
803 | emit mouseSignal( 3, // release | 803 | emit mouseSignal( 3, // release |
804 | (ev->x()-tLx-blX)/font_w + 1, | 804 | (ev->x()-tLx-blX)/font_w + 1, |
805 | (ev->y()-tLy-bY)/font_h + 1 ); | 805 | (ev->y()-tLy-bY)/font_h + 1 ); |
806 | releaseMouse(); | 806 | releaseMouse(); |
807 | } | 807 | } |
808 | } | 808 | } |
809 | 809 | ||
810 | void Widget::mouseDoubleClickEvent(QMouseEvent* ev) | 810 | void Widget::mouseDoubleClickEvent(QMouseEvent* ev) |
811 | { | 811 | { |
812 | if ( ev->button() != LeftButton) return; | 812 | if ( ev->button() != LeftButton) return; |
813 | 813 | ||
814 | QPoint tL = contentsRect().topLeft(); | 814 | QPoint tL = contentsRect().topLeft(); |
815 | int tLx = tL.x(); | 815 | int tLx = tL.x(); |
816 | int tLy = tL.y(); | 816 | int tLy = tL.y(); |
817 | QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); | 817 | QPoint pos = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); |
818 | 818 | ||
819 | // pass on double click as two clicks. | 819 | // pass on double click as two clicks. |
820 | if (!mouse_marks && !(ev->state() & ShiftButton)) | 820 | if (!mouse_marks && !(ev->state() & ShiftButton)) |
821 | { | 821 | { |
822 | emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button | 822 | emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button |
823 | emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release | 823 | emit mouseSignal( 3, pos.x()+1, pos.y()+1 ); // release |
824 | emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button | 824 | emit mouseSignal( 0, pos.x()+1, pos.y()+1 ); // left button |
825 | return; | 825 | return; |
826 | } | 826 | } |
827 | 827 | ||
828 | 828 | ||
829 | emit clearSelectionSignal(); | 829 | emit clearSelectionSignal(); |
830 | QPoint bgnSel = pos; | 830 | QPoint bgnSel = pos; |
831 | QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); | 831 | QPoint endSel = QPoint((ev->x()-tLx-blX)/font_w,(ev->y()-tLy-bY)/font_h); |
832 | int i = loc(bgnSel.x(),bgnSel.y()); | 832 | int i = loc(bgnSel.x(),bgnSel.y()); |
833 | iPntSel = bgnSel; | 833 | iPntSel = bgnSel; |
834 | 834 | ||
835 | word_selection_mode = TRUE; | 835 | word_selection_mode = TRUE; |
836 | 836 | ||
837 | // find word boundaries... | 837 | // find word boundaries... |
838 | int selClass = charClass(image[i].c); | 838 | int selClass = charClass(image[i].c); |
839 | { | 839 | { |
840 | // set the start... | 840 | // set the start... |
841 | int x = bgnSel.x(); | 841 | int x = bgnSel.x(); |
842 | while ( x > 0 && charClass(image[i-1].c) == selClass ) | 842 | while ( x > 0 && charClass(image[i-1].c) == selClass ) |
843 | { i--; x--; } | 843 | { i--; x--; } |
844 | bgnSel.setX(x); | 844 | bgnSel.setX(x); |
845 | emit beginSelectionSignal( bgnSel.x(), bgnSel.y() ); | 845 | emit beginSelectionSignal( bgnSel.x(), bgnSel.y() ); |
846 | 846 | ||
847 | // set the end... | 847 | // set the end... |
848 | i = loc( endSel.x(), endSel.y() ); | 848 | i = loc( endSel.x(), endSel.y() ); |
849 | x = endSel.x(); | 849 | x = endSel.x(); |
850 | while( x < columns-1 && charClass(image[i+1].c) == selClass ) | 850 | while( x < columns-1 && charClass(image[i+1].c) == selClass ) |
851 | { i++; x++ ; } | 851 | { i++; x++ ; } |
852 | endSel.setX(x); | 852 | endSel.setX(x); |
853 | actSel = 2; // within selection | 853 | actSel = 2; // within selection |
854 | emit extendSelectionSignal( endSel.x(), endSel.y() ); | 854 | emit extendSelectionSignal( endSel.x(), endSel.y() ); |
855 | emit endSelectionSignal(preserve_line_breaks); | 855 | emit endSelectionSignal(preserve_line_breaks); |
856 | preserve_line_breaks = TRUE; | 856 | preserve_line_breaks = TRUE; |
857 | } | 857 | } |
858 | } | 858 | } |
859 | 859 | ||
860 | void Widget::focusInEvent( QFocusEvent * ) | 860 | void Widget::focusInEvent( QFocusEvent * ) |
861 | { | 861 | { |
862 | 862 | ||
863 | // do nothing, to prevent repainting | 863 | // do nothing, to prevent repainting |
864 | } | 864 | } |
865 | 865 | ||
866 | 866 | ||
867 | void Widget::focusOutEvent( QFocusEvent * ) | 867 | void Widget::focusOutEvent( QFocusEvent * ) |
868 | { | 868 | { |
869 | // do nothing, to prevent repainting | 869 | // do nothing, to prevent repainting |
870 | } | 870 | } |
871 | 871 | ||
872 | bool Widget::focusNextPrevChild( bool next ) | 872 | bool Widget::focusNextPrevChild( bool next ) |
873 | { | 873 | { |
874 | if (next) | 874 | if (next) |
875 | return false; // This disables changing the active part in konqueror | 875 | return false; // This disables changing the active part in konqueror |
876 | // when pressing Tab | 876 | // when pressing Tab |
877 | return QFrame::focusNextPrevChild( next ); | 877 | return QFrame::focusNextPrevChild( next ); |
878 | } | 878 | } |
879 | 879 | ||
880 | 880 | ||
881 | int Widget::charClass(char ch) const | 881 | int Widget::charClass(char ch) const |
882 | { | 882 | { |
883 | // This might seem like overkill, but imagine if ch was a Unicode | 883 | // This might seem like overkill, but imagine if ch was a Unicode |
884 | // character (Qt 2.0 QChar) - it might then be sensible to separate | 884 | // character (Qt 2.0 QChar) - it might then be sensible to separate |
885 | // the different language ranges, etc. | 885 | // the different language ranges, etc. |
886 | 886 | ||
887 | if ( isspace(ch) ) return ' '; | 887 | if ( isspace(ch) ) return ' '; |
888 | 888 | ||
889 | static const char *word_characters = ":@-./_~"; | 889 | static const char *word_characters = ":@-./_~"; |
890 | if ( isalnum(ch) || strchr(word_characters, ch) ) | 890 | if ( isalnum(ch) || strchr(word_characters, ch) ) |
891 | return 'a'; | 891 | return 'a'; |
892 | 892 | ||
893 | // Everything else is weird | 893 | // Everything else is weird |
894 | return 1; | 894 | return 1; |
895 | } | 895 | } |
896 | 896 | ||
897 | void Widget::setMouseMarks(bool on) | 897 | void Widget::setMouseMarks(bool on) |
898 | { | 898 | { |
899 | mouse_marks = on; | 899 | mouse_marks = on; |
900 | setCursor( mouse_marks ? ibeamCursor : arrowCursor ); | 900 | setCursor( mouse_marks ? ibeamCursor : arrowCursor ); |
901 | } | 901 | } |
902 | 902 | ||
903 | /* ------------------------------------------------------------------------- */ | 903 | /* ------------------------------------------------------------------------- */ |
904 | /* */ | 904 | /* */ |
905 | /* Clipboard */ | 905 | /* Clipboard */ |
906 | /* */ | 906 | /* */ |
907 | /* ------------------------------------------------------------------------- */ | 907 | /* ------------------------------------------------------------------------- */ |
908 | 908 | ||
909 | #undef KeyPress | 909 | #undef KeyPress |
910 | 910 | ||
911 | void Widget::emitSelection() | 911 | void Widget::emitSelection() |
912 | // Paste Clipboard by simulating keypress events | 912 | // Paste Clipboard by simulating keypress events |
913 | { | 913 | { |
914 | #ifndef QT_NO_CLIPBOARD | 914 | #ifndef QT_NO_CLIPBOARD |
915 | QString text = QApplication::clipboard()->text(); | 915 | QString text = QApplication::clipboard()->text(); |
916 | if ( ! text.isNull() ) | 916 | if ( ! text.isNull() ) |
917 | { | 917 | { |
918 | text.replace(QRegExp("\n"), "\r"); | 918 | text.replace(QRegExp("\n"), "\r"); |
919 | QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); | 919 | QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); |
920 | emit keyPressedSignal(&e); // expose as a big fat keypress event | 920 | emit keyPressedSignal(&e); // expose as a big fat keypress event |
921 | emit clearSelectionSignal(); | 921 | emit clearSelectionSignal(); |
922 | } | 922 | } |
923 | #endif | 923 | #endif |
924 | } | 924 | } |
925 | 925 | ||
926 | void Widget::emitText(QString text) | 926 | void Widget::emitText(QString text) |
927 | { | 927 | { |
928 | QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); | 928 | QKeyEvent e(QEvent::KeyPress, 0, -1, 0, text); |
929 | emit keyPressedSignal(&e); // expose as a big fat keypress event | 929 | emit keyPressedSignal(&e); // expose as a big fat keypress event |
930 | } | 930 | } |
931 | 931 | ||
932 | void Widget::pasteClipboard( ) | 932 | void Widget::pasteClipboard( ) |
933 | { | 933 | { |
934 | emitSelection(); | 934 | emitSelection(); |
935 | } | 935 | } |
936 | 936 | ||
937 | void Widget::setSelection(const QString& t) | 937 | void Widget::setSelection(const QString& t) |
938 | { | 938 | { |
939 | #ifndef QT_NO_CLIPBOARD | 939 | #ifndef QT_NO_CLIPBOARD |
940 | // Disconnect signal while WE set the clipboard | 940 | // Disconnect signal while WE set the clipboard |
941 | QObject *cb = QApplication::clipboard(); | 941 | QObject *cb = QApplication::clipboard(); |
942 | QObject::disconnect( cb, SIGNAL(dataChanged()), | 942 | QObject::disconnect( cb, SIGNAL(dataChanged()), |
943 | this, SLOT(onClearSelection()) ); | 943 | this, SLOT(onClearSelection()) ); |
944 | 944 | ||
945 | QApplication::clipboard()->setText(t); | 945 | QApplication::clipboard()->setText(t); |
946 | 946 | ||
947 | QObject::connect( cb, SIGNAL(dataChanged()), | 947 | QObject::connect( cb, SIGNAL(dataChanged()), |
948 | this, SLOT(onClearSelection()) ); | 948 | this, SLOT(onClearSelection()) ); |
949 | #endif | 949 | #endif |
950 | } | 950 | } |
951 | 951 | ||
952 | void Widget::onClearSelection() | 952 | void Widget::onClearSelection() |
953 | { | 953 | { |
954 | emit clearSelectionSignal(); | 954 | emit clearSelectionSignal(); |
955 | } | 955 | } |
956 | 956 | ||
957 | /* ------------------------------------------------------------------------- */ | 957 | /* ------------------------------------------------------------------------- */ |
958 | /* */ | 958 | /* */ |
959 | /* Keyboard */ | 959 | /* Keyboard */ |
960 | /* */ | 960 | /* */ |
961 | /* ------------------------------------------------------------------------- */ | 961 | /* ------------------------------------------------------------------------- */ |
962 | 962 | ||
963 | //FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' | 963 | //FIXME: an `eventFilter' has been installed instead of a `keyPressEvent' |
964 | // due to a bug in `QT' or the ignorance of the author to prevent | 964 | // due to a bug in `QT' or the ignorance of the author to prevent |
965 | // repaint events being emitted to the screen whenever one leaves | 965 | // repaint events being emitted to the screen whenever one leaves |
966 | // or reenters the screen to/from another application. | 966 | // or reenters the screen to/from another application. |
967 | // | 967 | // |
968 | // Troll says one needs to change focusInEvent() and focusOutEvent(), | 968 | // Troll says one needs to change focusInEvent() and focusOutEvent(), |
969 | // which would also let you have an in-focus cursor and an out-focus | 969 | // which would also let you have an in-focus cursor and an out-focus |
970 | // cursor like xterm does. | 970 | // cursor like xterm does. |
971 | 971 | ||
972 | // for the auto-hide cursor feature, I added empty focusInEvent() and | 972 | // for the auto-hide cursor feature, I added empty focusInEvent() and |
973 | // focusOutEvent() so that update() isn't called. | 973 | // focusOutEvent() so that update() isn't called. |
974 | // For auto-hide, we need to get keypress-events, but we only get them when | 974 | // For auto-hide, we need to get keypress-events, but we only get them when |
975 | // we have focus. | 975 | // we have focus. |
976 | 976 | ||
977 | void Widget::doScroll(int lines) | 977 | void Widget::doScroll(int lines) |
978 | { | 978 | { |
979 | scrollbar->setValue(scrollbar->value()+lines); | 979 | scrollbar->setValue(scrollbar->value()+lines); |
980 | } | 980 | } |
981 | 981 | ||
982 | bool Widget::eventFilter( QObject *obj, QEvent *e ) | 982 | bool Widget::eventFilter( QObject *obj, QEvent *e ) |
983 | { | 983 | { |
984 | if ( (e->type() == QEvent::Accel || | 984 | if ( (e->type() == QEvent::Accel || |
985 | e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { | 985 | e->type() == QEvent::AccelAvailable ) && qApp->focusWidget() == this ) { |
986 | static_cast<QKeyEvent *>( e )->ignore(); | 986 | static_cast<QKeyEvent *>( e )->ignore(); |
987 | return true; | 987 | return true; |
988 | } | 988 | } |
989 | if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) | 989 | if ( obj != this /* when embedded */ && obj != parent() /* when standalone */ ) |
990 | return FALSE; // not us | 990 | return FALSE; // not us |
991 | if ( e->type() == QEvent::Wheel) { | 991 | if ( e->type() == QEvent::Wheel) { |
992 | QApplication::sendEvent(scrollbar, e); | 992 | QApplication::sendEvent(scrollbar, e); |
993 | } | 993 | } |
994 | 994 | ||
995 | #ifdef FAKE_CTRL_AND_ALT | 995 | #ifdef FAKE_CTRL_AND_ALT |
996 | static bool control = FALSE; | 996 | static bool control = FALSE; |
997 | static bool alt = FALSE; | 997 | static bool alt = FALSE; |
998 | // odebug << " Has a keyboard with no CTRL and ALT keys, but we fake it:" << oendl; | ||
999 | bool dele=FALSE; | 998 | bool dele=FALSE; |
1000 | if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { | 999 | if ( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) { |
1001 | QKeyEvent* ke = (QKeyEvent*)e; | 1000 | QKeyEvent* ke = (QKeyEvent*)e; |
1002 | bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); | 1001 | bool keydown = e->type() == QEvent::KeyPress || ke->isAutoRepeat(); |
1003 | switch (ke->key()) { | 1002 | switch (ke->key()) { |
1004 | case Key_F9: // let this be "Control" | 1003 | case Key_F9: // let this be "Control" |
1005 | control = keydown; | 1004 | control = keydown; |
1006 | e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); | 1005 | e = new QKeyEvent(QEvent::KeyPress, Key_Control, 0, ke->state()); |
1007 | dele=TRUE; | 1006 | dele=TRUE; |
1008 | break; | 1007 | break; |
1009 | case Key_F13: // let this be "Alt" | 1008 | case Key_F13: // let this be "Alt" |
1010 | alt = keydown; | 1009 | alt = keydown; |
1011 | e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); | 1010 | e = new QKeyEvent(QEvent::KeyPress, Key_Alt, 0, ke->state()); |
1012 | dele=TRUE; | 1011 | dele=TRUE; |
1013 | break; | 1012 | break; |
1014 | default: | 1013 | default: |
1015 | if ( control ) { | 1014 | if ( control ) { |
1016 | int a = toupper(ke->ascii())-64; | 1015 | int a = toupper(ke->ascii())-64; |
1017 | if ( a >= 0 && a < ' ' ) { | 1016 | if ( a >= 0 && a < ' ' ) { |
1018 | e = new QKeyEvent(e->type(), ke->key(), | 1017 | e = new QKeyEvent(e->type(), ke->key(), |
1019 | a, ke->state()|ControlButton, QChar(a,0)); | 1018 | a, ke->state()|ControlButton, QChar(a,0)); |
1020 | dele=TRUE; | 1019 | dele=TRUE; |
1021 | } | 1020 | } |
1022 | } | 1021 | } |
1023 | if ( alt ) { | 1022 | if ( alt ) { |
1024 | e = new QKeyEvent(e->type(), ke->key(), | 1023 | e = new QKeyEvent(e->type(), ke->key(), |
1025 | ke->ascii(), ke->state()|AltButton, ke->text()); | 1024 | ke->ascii(), ke->state()|AltButton, ke->text()); |
1026 | dele=TRUE; | 1025 | dele=TRUE; |
1027 | } | 1026 | } |
1028 | } | 1027 | } |
1029 | } | 1028 | } |
1030 | #endif | 1029 | #endif |
1031 | 1030 | ||
1032 | if ( e->type() == QEvent::KeyPress ) { | 1031 | if ( e->type() == QEvent::KeyPress ) { |
1033 | QKeyEvent* ke = (QKeyEvent*)e; | 1032 | QKeyEvent* ke = (QKeyEvent*)e; |
1034 | actSel=0; // Key stroke implies a screen update, so Widget won't | 1033 | actSel=0; // Key stroke implies a screen update, so Widget won't |
1035 | // know where the current selection is. | 1034 | // know where the current selection is. |
1036 | 1035 | ||
1037 | // odebug << "key pressed is 0x" << ke->key() << "" << oendl; | ||
1038 | |||
1039 | if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker | 1036 | if( ke->state() == ShiftButton && ke->key() == Key_Tab) { //lets hardcode this sucker |
1040 | |||
1041 | // odebug << "key pressed 2 is 0x" << ke->key() << "" << oendl; | ||
1042 | emitText("\\"); // expose | 1037 | emitText("\\"); // expose |
1043 | } else | 1038 | } else |
1044 | emit keyPressedSignal(ke); // expose | 1039 | emit keyPressedSignal(ke); // expose |
1045 | ke->accept(); | 1040 | ke->accept(); |
1046 | #ifdef FAKE_CTRL_AND_ALT | 1041 | #ifdef FAKE_CTRL_AND_ALT |
1047 | if ( dele ) delete e; | 1042 | if ( dele ) delete e; |
1048 | #endif | 1043 | #endif |
1049 | return true; // stop the event | 1044 | return true; // stop the event |
1050 | } | 1045 | } |
1051 | if ( e->type() == QEvent::Enter ) { | 1046 | if ( e->type() == QEvent::Enter ) { |
1052 | QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), | 1047 | QObject::disconnect( (QObject*)cb, SIGNAL(dataChanged()), |
1053 | this, SLOT(onClearSelection()) ); | 1048 | this, SLOT(onClearSelection()) ); |
1054 | } | 1049 | } |
1055 | if ( e->type() == QEvent::Leave ) { | 1050 | if ( e->type() == QEvent::Leave ) { |
1056 | QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), | 1051 | QObject::connect( (QObject*)cb, SIGNAL(dataChanged()), |
1057 | this, SLOT(onClearSelection()) ); | 1052 | this, SLOT(onClearSelection()) ); |
1058 | } | 1053 | } |
1059 | return QFrame::eventFilter( obj, e ); | 1054 | return QFrame::eventFilter( obj, e ); |
1060 | } | 1055 | } |
1061 | 1056 | ||
1062 | /* ------------------------------------------------------------------------- */ | 1057 | /* ------------------------------------------------------------------------- */ |
1063 | /* */ | 1058 | /* */ |
1064 | /* Frame */ | 1059 | /* Frame */ |
1065 | /* */ | 1060 | /* */ |
1066 | /* ------------------------------------------------------------------------- */ | 1061 | /* ------------------------------------------------------------------------- */ |
1067 | 1062 | ||
1068 | void Widget::frameChanged() | 1063 | void Widget::frameChanged() |
1069 | { | 1064 | { |
1070 | propagateSize(); | 1065 | propagateSize(); |
1071 | update(); | 1066 | update(); |
1072 | } | 1067 | } |
1073 | 1068 | ||
1074 | /* ------------------------------------------------------------------------- */ | 1069 | /* ------------------------------------------------------------------------- */ |
1075 | /* */ | 1070 | /* */ |
1076 | /* Sound */ | 1071 | /* Sound */ |
1077 | /* */ | 1072 | /* */ |
1078 | /* ------------------------------------------------------------------------- */ | 1073 | /* ------------------------------------------------------------------------- */ |
1079 | 1074 | ||
1080 | void Widget::Bell() | 1075 | void Widget::Bell() |
1081 | { | 1076 | { |
1082 | QApplication::beep(); | 1077 | QApplication::beep(); |
1083 | } | 1078 | } |
1084 | 1079 | ||
1085 | /* ------------------------------------------------------------------------- */ | 1080 | /* ------------------------------------------------------------------------- */ |
1086 | /* */ | 1081 | /* */ |
1087 | /* Auxiluary */ | 1082 | /* Auxiluary */ |
1088 | /* */ | 1083 | /* */ |
1089 | /* ------------------------------------------------------------------------- */ | 1084 | /* ------------------------------------------------------------------------- */ |
1090 | 1085 | ||
1091 | void Widget::clearImage() | 1086 | void Widget::clearImage() |
1092 | // initialize the image | 1087 | // initialize the image |
1093 | // for internal use only | 1088 | // for internal use only |
1094 | { | 1089 | { |
1095 | for (int y = 0; y < lines; y++) | 1090 | for (int y = 0; y < lines; y++) |
1096 | for (int x = 0; x < columns; x++) | 1091 | for (int x = 0; x < columns; x++) |
1097 | { | 1092 | { |
1098 | image[loc(x,y)].c = 0xff; //' '; | 1093 | image[loc(x,y)].c = 0xff; //' '; |
1099 | image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; | 1094 | image[loc(x,y)].f = 0xff; //DEFAULT_FORE_COLOR; |
1100 | image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; | 1095 | image[loc(x,y)].b = 0xff; //DEFAULT_BACK_COLOR; |
1101 | image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; | 1096 | image[loc(x,y)].r = 0xff; //DEFAULT_RENDITION; |
1102 | } | 1097 | } |
1103 | } | 1098 | } |
1104 | 1099 | ||
1105 | // Create Image /////////////////////////////////////////////////////// | 1100 | // Create Image /////////////////////////////////////////////////////// |
1106 | 1101 | ||
1107 | void Widget::calcGeometry() | 1102 | void Widget::calcGeometry() |
1108 | { | 1103 | { |
1109 | //FIXME: set rimX == rimY == 0 when running in full screen mode. | 1104 | //FIXME: set rimX == rimY == 0 when running in full screen mode. |
1110 | 1105 | ||
1111 | scrollbar->resize(QApplication::style().scrollBarExtent().width(), | 1106 | scrollbar->resize(QApplication::style().scrollBarExtent().width(), |
1112 | contentsRect().height()); | 1107 | contentsRect().height()); |
1113 | switch(scrollLoc) | 1108 | switch(scrollLoc) |
1114 | { | 1109 | { |
1115 | case SCRNONE : | 1110 | case SCRNONE : |
1116 | columns = ( contentsRect().width() - 2 * rimX ) / font_w; | 1111 | columns = ( contentsRect().width() - 2 * rimX ) / font_w; |
1117 | blX = (contentsRect().width() - (columns*font_w) ) / 2; | 1112 | blX = (contentsRect().width() - (columns*font_w) ) / 2; |
1118 | brX = blX; | 1113 | brX = blX; |
1119 | scrollbar->hide(); | 1114 | scrollbar->hide(); |
1120 | break; | 1115 | break; |
1121 | case SCRLEFT : | 1116 | case SCRLEFT : |
1122 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; | 1117 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; |
1123 | brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; | 1118 | brX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; |
1124 | blX = brX + scrollbar->width(); | 1119 | blX = brX + scrollbar->width(); |
1125 | scrollbar->move(contentsRect().topLeft()); | 1120 | scrollbar->move(contentsRect().topLeft()); |
1126 | scrollbar->show(); | 1121 | scrollbar->show(); |
1127 | break; | 1122 | break; |
1128 | case SCRRIGHT: | 1123 | case SCRRIGHT: |
1129 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; | 1124 | columns = ( contentsRect().width() - 2 * rimX - scrollbar->width()) / font_w; |
1130 | blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; | 1125 | blX = (contentsRect().width() - (columns*font_w) - scrollbar->width() ) / 2; |
1131 | brX = blX; | 1126 | brX = blX; |
1132 | scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); | 1127 | scrollbar->move(contentsRect().topRight() - QPoint(scrollbar->width()-1,0)); |
1133 | scrollbar->show(); | 1128 | scrollbar->show(); |
1134 | break; | 1129 | break; |
1135 | } | 1130 | } |
1136 | //FIXME: support 'rounding' styles | 1131 | //FIXME: support 'rounding' styles |
1137 | lines = ( contentsRect().height() - 2 * rimY ) / font_h; | 1132 | lines = ( contentsRect().height() - 2 * rimY ) / font_h; |
1138 | bY = (contentsRect().height() - (lines *font_h)) / 2; | 1133 | bY = (contentsRect().height() - (lines *font_h)) / 2; |
1139 | } | 1134 | } |
1140 | 1135 | ||
1141 | void Widget::makeImage() | 1136 | void Widget::makeImage() |
1142 | //FIXME: rename 'calcGeometry? | 1137 | //FIXME: rename 'calcGeometry? |
1143 | { | 1138 | { |
1144 | calcGeometry(); | 1139 | calcGeometry(); |
1145 | image = (Character*) malloc(lines*columns*sizeof(Character)); | 1140 | image = (Character*) malloc(lines*columns*sizeof(Character)); |
1146 | clearImage(); | 1141 | clearImage(); |
1147 | } | 1142 | } |
1148 | 1143 | ||
1149 | // calculate the needed size | 1144 | // calculate the needed size |
1150 | QSize Widget::calcSize(int cols, int lins) const | 1145 | QSize Widget::calcSize(int cols, int lins) const |
1151 | { | 1146 | { |
1152 | int frw = width() - contentsRect().width(); | 1147 | int frw = width() - contentsRect().width(); |
1153 | int frh = height() - contentsRect().height(); | 1148 | int frh = height() - contentsRect().height(); |
1154 | int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); | 1149 | int scw = (scrollLoc==SCRNONE?0:scrollbar->width()); |
1155 | return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh ); | 1150 | return QSize( font_w*cols + 2*rimX + frw + scw, font_h*lins + 2*rimY + frh ); |
1156 | } | 1151 | } |
1157 | 1152 | ||
1158 | QSize Widget::sizeHint() const | 1153 | QSize Widget::sizeHint() const |
1159 | { | 1154 | { |
1160 | return size(); | 1155 | return size(); |
1161 | } | 1156 | } |
1162 | 1157 | ||
1163 | void Widget::styleChange(QStyle &) | 1158 | void Widget::styleChange(QStyle &) |
1164 | { | 1159 | { |
1165 | propagateSize(); | 1160 | propagateSize(); |
1166 | } | 1161 | } |
1167 | 1162 | ||
1168 | #ifndef QT_NO_DRAGANDDROP | 1163 | #ifndef QT_NO_DRAGANDDROP |
1169 | 1164 | ||
1170 | /* --------------------------------------------------------------------- */ | 1165 | /* --------------------------------------------------------------------- */ |
1171 | /* */ | 1166 | /* */ |
1172 | /* Drag & Drop */ | 1167 | /* Drag & Drop */ |
1173 | /* */ | 1168 | /* */ |
1174 | /* --------------------------------------------------------------------- */ | 1169 | /* --------------------------------------------------------------------- */ |
1175 | 1170 | ||
1176 | 1171 | ||
1177 | void Widget::dragEnterEvent(QDragEnterEvent* e) | 1172 | void Widget::dragEnterEvent(QDragEnterEvent* e) |
1178 | { | 1173 | { |
1179 | e->accept(QTextDrag::canDecode(e) || | 1174 | e->accept(QTextDrag::canDecode(e) || |
1180 | QUriDrag::canDecode(e)); | 1175 | QUriDrag::canDecode(e)); |
1181 | } | 1176 | } |
1182 | 1177 | ||
1183 | void Widget::dropEvent(QDropEvent* event) | 1178 | void Widget::dropEvent(QDropEvent* event) |
1184 | { | 1179 | { |
1185 | // The current behaviour when url(s) are dropped is | 1180 | // The current behaviour when url(s) are dropped is |
1186 | // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd | 1181 | // * if there is only ONE url and if it's a LOCAL one, ask for paste or cd |
1187 | // * in all other cases, just paste | 1182 | // * in all other cases, just paste |
1188 | // (for non-local ones, or for a list of URLs, 'cd' is nonsense) | 1183 | // (for non-local ones, or for a list of URLs, 'cd' is nonsense) |
1189 | QStrList strlist; | 1184 | QStrList strlist; |
1190 | int file_count = 0; | 1185 | int file_count = 0; |
1191 | dropText = ""; | 1186 | dropText = ""; |
1192 | bool bPopup = true; | 1187 | bool bPopup = true; |
1193 | 1188 | ||
1194 | if(QUriDrag::decode(event, strlist)) { | 1189 | if(QUriDrag::decode(event, strlist)) { |
1195 | if (strlist.count()) { | 1190 | if (strlist.count()) { |
1196 | for(const char* p = strlist.first(); p; p = strlist.next()) { | 1191 | for(const char* p = strlist.first(); p; p = strlist.next()) { |
1197 | if(file_count++ > 0) { | 1192 | if(file_count++ > 0) { |
1198 | dropText += " "; | 1193 | dropText += " "; |
1199 | bPopup = false; // more than one file, don't popup | 1194 | bPopup = false; // more than one file, don't popup |
1200 | } | 1195 | } |
1201 | 1196 | ||
1202 | /* | 1197 | /* |
1203 | KURL url(p); | 1198 | KURL url(p); |
1204 | if (url.isLocalFile()) { | 1199 | if (url.isLocalFile()) { |
1205 | dropText += url.path(); // local URL : remove protocol | 1200 | dropText += url.path(); // local URL : remove protocol |
1206 | } | 1201 | } |
1207 | else { | 1202 | else { |
1208 | dropText += url.prettyURL(); | 1203 | dropText += url.prettyURL(); |
1209 | bPopup = false; // a non-local file, don't popup | 1204 | bPopup = false; // a non-local file, don't popup |
1210 | } | 1205 | } |
1211 | */ | 1206 | */ |
1212 | 1207 | ||
1213 | } | 1208 | } |
1214 | 1209 | ||
1215 | if (bPopup) | 1210 | if (bPopup) |
1216 | // m_drop->popup(pos() + event->pos()); | 1211 | // m_drop->popup(pos() + event->pos()); |
1217 | m_drop->popup(mapToGlobal(event->pos())); | 1212 | m_drop->popup(mapToGlobal(event->pos())); |
1218 | else | 1213 | else |
1219 | { | 1214 | { |
1220 | if (currentSession) { | 1215 | if (currentSession) { |
1221 | //currentSession->getEmulation()->sendString(dropText.local8Bit()); | 1216 | //currentSession->getEmulation()->sendString(dropText.local8Bit()); |
1222 | QByteArray tmp; | 1217 | QByteArray tmp; |
1223 | // ibot: this should be pretty wrong... | 1218 | // ibot: this should be pretty wrong... |
1224 | // now it sends to the right layer | 1219 | // now it sends to the right layer |
1225 | currentSession-> emulationLayer()->send( tmp.setRawData( dropText.local8Bit())); | 1220 | currentSession-> emulationLayer()->send( tmp.setRawData( dropText.local8Bit())); |
1226 | } | 1221 | } |
1227 | // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; | 1222 | // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; |
1228 | } | 1223 | } |
1229 | } | 1224 | } |
1230 | } | 1225 | } |
1231 | else if(QTextDrag::decode(event, dropText)) { | 1226 | else if(QTextDrag::decode(event, dropText)) { |
1232 | // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; | 1227 | // kdDebug() << "Drop:" << dropText.local8Bit() << "\n"; |
1233 | if (currentSession) { | 1228 | if (currentSession) { |
1234 | //currentSession->getEmulation()->sendString(dropText.local8Bit()); | 1229 | //currentSession->getEmulation()->sendString(dropText.local8Bit()); |
1235 | QByteArray tmp; | 1230 | QByteArray tmp; |
1236 | currentSession->emulationLayer()->send( tmp.setRawData( dropText.local8Bit())); | 1231 | currentSession->emulationLayer()->send( tmp.setRawData( dropText.local8Bit())); |
1237 | } | 1232 | } |
1238 | // Paste it | 1233 | // Paste it |
1239 | } | 1234 | } |
1240 | } | 1235 | } |
1241 | #endif | 1236 | #endif |
1242 | 1237 | ||
1243 | 1238 | ||
1244 | void Widget::drop_menu_activated(int item) | 1239 | void Widget::drop_menu_activated(int item) |
1245 | { | 1240 | { |
1246 | #ifndef QT_NO_DRAGANDDROP | 1241 | #ifndef QT_NO_DRAGANDDROP |
1247 | QByteArray tmp; | 1242 | QByteArray tmp; |
1248 | switch (item) | 1243 | switch (item) |
1249 | { | 1244 | { |
1250 | case 0: // paste | 1245 | case 0: // paste |
1251 | //currentSession->getEmulation()->sendString(dropText.local8Bit()); | 1246 | //currentSession->getEmulation()->sendString(dropText.local8Bit()); |
1252 | currentSession->emulationLayer()->send( tmp.setRawData( dropText.local8Bit())); | 1247 | currentSession->emulationLayer()->send( tmp.setRawData( dropText.local8Bit())); |
1253 | 1248 | ||
1254 | // KWM::activate((Window)this->winId()); | 1249 | // KWM::activate((Window)this->winId()); |
1255 | break; | 1250 | break; |
1256 | case 1: // cd ... | 1251 | case 1: // cd ... |
1257 | //currentSession->getEmulation()->sendString("cd "); | 1252 | //currentSession->getEmulation()->sendString("cd "); |
1258 | tmp.setRawData( "cd " ); | 1253 | tmp.setRawData( "cd " ); |
1259 | currentSession->emulationLayer()->send( tmp ); | 1254 | currentSession->emulationLayer()->send( tmp ); |
1260 | struct stat statbuf; | 1255 | struct stat statbuf; |
1261 | if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) | 1256 | if ( ::stat( QFile::encodeName( dropText ), &statbuf ) == 0 ) |
1262 | { | 1257 | { |
1263 | if ( !S_ISDIR(statbuf.st_mode) ) | 1258 | if ( !S_ISDIR(statbuf.st_mode) ) |
1264 | { | 1259 | { |
1265 | /* | 1260 | /* |
1266 | KURL url; | 1261 | KURL url; |
1267 | url.setPath( dropText ); | 1262 | url.setPath( dropText ); |
1268 | dropText = url.directory( true, false ); // remove filename | 1263 | dropText = url.directory( true, false ); // remove filename |
1269 | */ | 1264 | */ |
1270 | } | 1265 | } |
1271 | } | 1266 | } |
1272 | dropText.replace(QRegExp(" "), "\\ "); // escape spaces | 1267 | dropText.replace(QRegExp(" "), "\\ "); // escape spaces |
1273 | QByteArray tmp2; | 1268 | QByteArray tmp2; |
1274 | tmp.setRawDate( dropText.local8Bit() + "\n" ); | 1269 | tmp.setRawDate( dropText.local8Bit() + "\n" ); |
1275 | //currentSession->getEmulation()->sendString(dropText.local8Bit()); | 1270 | //currentSession->getEmulation()->sendString(dropText.local8Bit()); |
1276 | //currentSession->getEmulation()->sendString("\n"); | 1271 | //currentSession->getEmulation()->sendString("\n"); |
1277 | currentSession->emulationLayer()->send( tmp ); | 1272 | currentSession->emulationLayer()->send( tmp ); |
1278 | // KWM::activate((Window)this->winId()); | 1273 | // KWM::activate((Window)this->winId()); |
1279 | break; | 1274 | break; |
1280 | } | 1275 | } |
1281 | #endif | 1276 | #endif |
1282 | } | 1277 | } |
1283 | 1278 | ||