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.

Location:
branches/qt-gui_qt4/src/widgets
Files:
2 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 
  • branches/qt-gui_qt4/src/widgets/mledit.h

    r5580 r6064  
    6767  bool checkSpellingEnabled() const; 
    6868 
     69  /** 
     70   * Caclulate height for widget to fit a specified number of lines with 
     71   * current font 
     72   * 
     73   * @param lines Number of text lines to calculate for 
     74   * @return Widget height in pixels 
     75   */ 
     76  int heightForLines(int lines) const; 
     77 
     78  /** 
     79   * Set size hint as number of lines of text 
     80   * 
     81   * @param lines Lines of text that should be visible 
     82   */ 
     83  void setSizeHintLines(int lines); 
     84 
     85  /** 
     86   * Get recommended widget size 
     87   * 
     88   * @return Recommended size 
     89   */ 
     90  QSize sizeHint() const; 
     91 
    6992signals: 
    7093  void ctrlEnterPressed(); 
     
    7497  bool myFixSetTextNewlines; 
    7598  bool myLastKeyWasReturn; 
     99  int myFontHeight; 
     100  int myLinesHint; 
    76101 
    77102  virtual void keyPressEvent(QKeyEvent* event);