# HG changeset patch
# User Daniel J Sebald <daniel.sebald@ieee.org>
# Date 1372107774 18000
# Node ID 2f1a29002b978568b6cbc40ec5a3dad8aeb5800d
# Parent  893e9cec62f1f4874be1b7a63110c396d7ca9437
Align terminal window contents with bottom of view

* TerminalView.cc (TerminalDisplay::setCursorPos): Retrieve bottomLeft corner
of view and compute top as bL.y()-2*_topMargin-_fontHeight*_lines+1.
(TerminalView::scrollImage): Compute top using contentsRect().height() -
_topMargin - (_lines * _fontHeight) rather than _topMargin.
(TerminalView::updateImage, TerminalView::preeditRect,
TerminalView::drawContents, TerminalView::imageToWidget,
TerminalView::extendSelection): Retrieve bottomLeft corner of view and compute
top as bL.y()-2*_topMargin-_fontHeight*_lines+1.

diff --git a/libgui/qterminal/libqterminal/unix/TerminalView.cpp b/libgui/qterminal/libqterminal/unix/TerminalView.cpp
--- a/libgui/qterminal/libqterminal/unix/TerminalView.cpp
+++ b/libgui/qterminal/libqterminal/unix/TerminalView.cpp
@@ -657,9 +657,10 @@
 */
 void TerminalDisplay::setCursorPos(const int curx, const int cury)
 {
-  QPoint tL  = contentsRect().topLeft();
-  int    tLx = tL.x();
-  int    tLy = tL.y();
+  // Align contents with bottom of view by computing top coordinate
+  QPoint bL  = contentsRect().bottomLeft();
+  int    tLx = bL.x();
+  int    tLy = bL.y()-2*_topMargin-_fontHeight*_lines+1;
 
   int xpos, ypos;
   ypos = _topMargin + tLy + _fontHeight*(cury-1) + _fontAscent;
@@ -711,7 +712,7 @@
   void* firstCharPos = &_image[ region.top() * this->_columns ];
   void* lastCharPos = &_image[ (region.top() + abs(lines)) * this->_columns ];
 
-  int top = _topMargin + (region.top() * _fontHeight);
+  int top = contentsRect().height() - _topMargin - (_lines * _fontHeight) + (region.top() * _fontHeight);
   int linesToMove = region.height() - abs(lines);
   int bytesToMove = linesToMove *
       this->_columns *
@@ -826,10 +827,10 @@
 
   int y,x,len;
 
-  QPoint tL  = contentsRect().topLeft();
-
-  int    tLx = tL.x();
-  int    tLy = tL.y();
+  // Align contents with bottom of view by computing top coordinate
+  QPoint bL  = contentsRect().bottomLeft();
+  int    tLx = bL.x();
+  int    tLy = bL.y()-2*_topMargin-_fontHeight*_lines+1;
   _hasBlinker = false;
 
   CharacterColor cf;       // undefined
@@ -1090,8 +1091,13 @@
   if ( preeditLength == 0 )
     return QRect();
 
+  // Align contents with bottom of view by computing top coordinate
+  QPoint bL  = contentsRect().bottomLeft();
+  int    tLx = bL.x();
+  int    tLy = bL.y()-2*_topMargin-_fontHeight*_lines+1;
+
   return QRect(_leftMargin + _fontWidth*cursorPosition().x(),
-               _topMargin + _fontHeight*cursorPosition().y(),
+               _topMargin + tLy + _fontHeight*cursorPosition().y(),
                _fontWidth*preeditLength,
                _fontHeight);
 }
@@ -1205,9 +1211,10 @@
 {
   //qDebug("%s %d drawContents and rect x=%d y=%d w=%d h=%d", __FILE__, __LINE__, rect.x(), rect.y(),rect.width(),rect.height());
 
-  QPoint topLeft  = contentsRect().topLeft();
-  // Take the topmost vertical position for the view.
-  int topLeftY = topLeft.y();
+  // Align contents with bottom of view by computing top coordinate
+  QPoint bottomLeft  = contentsRect().bottomLeft();
+  int bottomLeftY = bottomLeft.y();
+  int topLeftY = bottomLeftY-2*_topMargin-_fontHeight*_lines+1;
 
   // In Konsole, the view has been centered. Don't do that here, since there
   // are strange hopping effects during a resize when the view does no match
@@ -1353,10 +1360,15 @@
 
 QRect TerminalView::imageToWidget(const QRect& imageArea) const
 {
+  // Align contents with bottom of view by computing top coordinate
+  QPoint bL  = contentsRect().bottomLeft();
+  int    tLx = bL.x();
+  int    tLy = bL.y()-2*_topMargin-_fontHeight*_lines+1;
+
   //qDebug("%s %d imageToWidget", __FILE__, __LINE__);
   QRect result;
   result.setLeft( _leftMargin + _fontWidth * imageArea.left() );
-  result.setTop( _topMargin + _fontHeight * imageArea.top() );
+  result.setTop( _topMargin + tLy + _fontHeight * imageArea.top() );
   result.setWidth( _fontWidth * imageArea.width() );
   result.setHeight( _fontHeight * imageArea.height() );
 
@@ -1722,9 +1734,10 @@
       return;
     }
 
-  QPoint tL  = contentsRect().topLeft();
-  int    tLx = tL.x();
-  int    tLy = tL.y();
+  // Align contents with bottom of view by computing top coordinate
+  QPoint bL  = contentsRect().bottomLeft();
+  int    tLx = bL.x();
+  int    tLy = bL.y()-2*_topMargin-_fontHeight*_lines+1;
   int    scroll = _scrollBar->value();
 
   // we're in the process of moving the mouse with the left button pressed
exporting patch:
<fdopen>
