Show
Ignore:
Timestamp:
02/20/08 04:08:08 (10 months ago)
Author:
flynd
Message:

Allow size hint on mledit based on font size and default chat dialog input to three lines of text.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/qt-gui_qt4/src/widgets/mledit.cpp

    r5892 r6064  
    3535  : BaseClass(parent), 
    3636    myFixSetTextNewlines(true), 
    37     myLastKeyWasReturn(false) 
     37    myLastKeyWasReturn(false), 
     38    myLinesHint(0) 
    3839{ 
    3940  setObjectName(name); 
     
    228229 
    229230  // Get height of current font 
    230   int textHeight = fontMetrics().height(); 
    231  
    232   // Set minimum height of text area to one line of text We need to 
    233   // add frame width and the added height of the scroll area as we're 
    234   // setting height on the widget, not the viewport 
    235   setMinimumHeight(textHeight + height() - viewport()->height() + 2 * frameWidth()); 
     231  myFontHeight = fontMetrics().height(); 
     232 
     233  // Set minimum height of text area to one line of text. 
     234  setMinimumHeight(heightForLines(1)); 
     235} 
     236 
     237int MLEdit::heightForLines(int lines) const 
     238{ 
     239  // We need to add frame width and the added height of the scroll area as 
     240  // we're calculating height for the widget, not the viewport. 
     241  return lines*myFontHeight + height() - viewport()->height() + 2 * frameWidth(); 
     242} 
     243 
     244void MLEdit::setSizeHintLines(int lines) 
     245{ 
     246  myLinesHint = lines; 
     247} 
     248 
     249QSize MLEdit::sizeHint() const 
     250{ 
     251  QSize s = BaseClass::sizeHint(); 
     252  if (myLinesHint > 0) 
     253    s.setHeight(heightForLines(myLinesHint)); 
     254  return s; 
    236255} 
    237256