comparison libqterminal/unix/TerminalView.cpp @ 15675:22bd268429d3

Cursor is now blinking in the terminal.
author Jacob Dawid <jacob.dawid@gmail.com>
date Fri, 20 Jul 2012 11:55:56 -0400
parents 76452c97add8
children aa6cba8ae88b
comparison
equal deleted inserted replaced
15674:2318531b7880 15675:22bd268429d3
61 61
62 // scroll increment used when dragging selection at top/bottom of window. 62 // scroll increment used when dragging selection at top/bottom of window.
63 63
64 // static 64 // static
65 bool TerminalView::_antialiasText = true; 65 bool TerminalView::_antialiasText = true;
66 bool TerminalView::HAVE_TRANSPARENCY = false;
67 66
68 /* ------------------------------------------------------------------------- */ 67 /* ------------------------------------------------------------------------- */
69 /* */ 68 /* */
70 /* Colors */ 69 /* Colors */
71 /* */ 70 /* */
244 ,_image(0) 243 ,_image(0)
245 ,_randomSeed(0) 244 ,_randomSeed(0)
246 ,_resizing(false) 245 ,_resizing(false)
247 ,_terminalSizeHint(false) 246 ,_terminalSizeHint(false)
248 ,_terminalSizeStartup(true) 247 ,_terminalSizeStartup(true)
249 ,_bidiEnabled(false)
250 ,_actSel(0) 248 ,_actSel(0)
251 ,_wordSelectionMode(false) 249 ,_wordSelectionMode(false)
252 ,_lineSelectionMode(false) 250 ,_lineSelectionMode(false)
253 ,_preserveLineBreaks(false) 251 ,_preserveLineBreaks(false)
254 ,_columnSelectionMode(false) 252 ,_columnSelectionMode(false)
498 QColor TerminalView::keyboardCursorColor() const 496 QColor TerminalView::keyboardCursorColor() const
499 { 497 {
500 return _cursorColor; 498 return _cursorColor;
501 } 499 }
502 500
503 void TerminalView::setOpacity(qreal opacity) 501 void TerminalView::drawBackground(QPainter& painter, const QRect& rect, const QColor& backgroundColor)
504 {
505 QColor color(_blendColor);
506 color.setAlphaF(opacity);
507
508 // enable automatic background filling to prevent the display
509 // flickering if there is no transparency
510 if ( color.alpha() == 255 )
511 {
512 setAutoFillBackground(true);
513 }
514 else
515 {
516 setAutoFillBackground(false);
517 }
518
519 _blendColor = color.rgba();
520 }
521
522 void TerminalView::drawBackground(QPainter& painter, const QRect& rect, const QColor& backgroundColor, bool useOpacitySetting )
523 { 502 {
524 // the area of the widget showing the contents of the terminal display is drawn 503 // the area of the widget showing the contents of the terminal display is drawn
525 // using the background color from the color scheme set with setColorTable() 504 // using the background color from the color scheme set with setColorTable()
526 // 505 //
527 // the area of the widget behind the scroll-bar is drawn using the background 506 // the area of the widget behind the scroll-bar is drawn using the background
530 // applications. 509 // applications.
531 // 510 //
532 QRect scrollBarArea = _scrollBar->isVisible() ? 511 QRect scrollBarArea = _scrollBar->isVisible() ?
533 rect.intersected(_scrollBar->geometry()) : 512 rect.intersected(_scrollBar->geometry()) :
534 QRect(); 513 QRect();
514
535 QRegion contentsRegion = QRegion(rect).subtracted(scrollBarArea); 515 QRegion contentsRegion = QRegion(rect).subtracted(scrollBarArea);
536 QRect contentsRect = contentsRegion.boundingRect(); 516 QRect contentsRect = contentsRegion.boundingRect();
537 517
538 if ( HAVE_TRANSPARENCY && qAlpha(_blendColor) < 0xff && useOpacitySetting ) 518 painter.fillRect(contentsRect, backgroundColor);
539 {
540 QColor color(backgroundColor);
541 color.setAlpha(qAlpha(_blendColor));
542
543 painter.save();
544 painter.setCompositionMode(QPainter::CompositionMode_Source);
545 painter.fillRect(contentsRect, color);
546 painter.restore();
547 }
548 else {
549 painter.fillRect(contentsRect, backgroundColor);
550 }
551
552 painter.fillRect(scrollBarArea,_scrollBar->palette().background()); 519 painter.fillRect(scrollBarArea,_scrollBar->palette().background());
553 } 520 }
554 521
555 void TerminalView::drawCursor(QPainter& painter, 522 void TerminalView::drawCursor(QPainter& painter,
556 const QRect& rect, 523 const QRect& rect,
663 const QColor foregroundColor = style->foregroundColor.color(_colorTable); 630 const QColor foregroundColor = style->foregroundColor.color(_colorTable);
664 const QColor backgroundColor = style->backgroundColor.color(_colorTable); 631 const QColor backgroundColor = style->backgroundColor.color(_colorTable);
665 632
666 // draw background if different from the display's background color 633 // draw background if different from the display's background color
667 if ( backgroundColor != palette().background().color() ) 634 if ( backgroundColor != palette().background().color() )
668 drawBackground(painter,rect,backgroundColor, false /* do not use transparency */); 635 drawBackground(painter,rect,backgroundColor);
669 636
670 // draw cursor shape if the current character is the cursor 637 // draw cursor shape if the current character is the cursor
671 // this may alter the foreground and background colors 638 // this may alter the foreground and background colors
672 bool invertCharacterColor = false; 639 bool invertCharacterColor = false;
673 640
1072 QPainter paint(this); 1039 QPainter paint(this);
1073 //qDebug("%s %d paintEvent %d %d", __FILE__, __LINE__, paint.window().top(), paint.window().right()); 1040 //qDebug("%s %d paintEvent %d %d", __FILE__, __LINE__, paint.window().top(), paint.window().right());
1074 1041
1075 foreach (QRect rect, (pe->region() & contentsRect()).rects()) 1042 foreach (QRect rect, (pe->region() & contentsRect()).rects())
1076 { 1043 {
1077 drawBackground(paint,rect,palette().background().color(), true /* use opacity setting */); 1044 drawBackground(paint,rect,palette().background().color());
1078 drawContents(paint, rect); 1045 drawContents(paint, rect);
1079 } 1046 }
1080 // drawBackground(paint,contentsRect(),palette().background().color(), true /* use opacity setting */); 1047 // drawBackground(paint,contentsRect(),palette().background().color(), true /* use opacity setting */);
1081 // drawContents(paint, contentsRect()); 1048 // drawContents(paint, contentsRect());
1082 //drawInputMethodPreeditString(paint,preeditRect()); 1049 drawInputMethodPreeditString(paint,preeditRect());
1083 //paintFilters(paint); 1050 paintFilters(paint);
1084
1085 paint.end(); 1051 paint.end();
1086 } 1052 }
1087 1053
1088 QPoint TerminalView::cursorPosition() const 1054 QPoint TerminalView::cursorPosition() const
1089 { 1055 {
1116 bool invertColors = false; 1082 bool invertColors = false;
1117 const QColor background = _colorTable[DEFAULT_BACK_COLOR].color; 1083 const QColor background = _colorTable[DEFAULT_BACK_COLOR].color;
1118 const QColor foreground = _colorTable[DEFAULT_FORE_COLOR].color; 1084 const QColor foreground = _colorTable[DEFAULT_FORE_COLOR].color;
1119 const Character* style = &_image[loc(cursorPos.x(),cursorPos.y())]; 1085 const Character* style = &_image[loc(cursorPos.x(),cursorPos.y())];
1120 1086
1121 drawBackground(painter,rect,background,true); 1087 drawBackground(painter,rect,background);
1122 drawCursor(painter,rect,foreground,background,invertColors); 1088 drawCursor(painter,rect,foreground,background,invertColors);
1123 drawCharacters(painter,rect,_inputMethodData.preeditString,style,invertColors); 1089 drawCharacters(painter,rect,_inputMethodData.preeditString,style,invertColors);
1124 1090
1125 _inputMethodData.previousPreeditRect = rect; 1091 _inputMethodData.previousPreeditRect = rect;
1126 } 1092 }