Changeset 6166

Show
Ignore:
Timestamp:
04/22/08 04:18:22 (7 months ago)
Author:
flynd
Message:

Reduce height of view event dialog and hide buttons when non of them are enabled.

Location:
trunk/qt4-gui/src
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/qt4-gui/src/userevents/userviewevent.cpp

    r6160 r6166  
    8282 
    8383  myMessageView = new MLView(); 
     84  myMessageView->setSizeHintLines(5); 
    8485  myReadSplitter->addWidget(myMessageView); 
    8586 
     
    9293      SLOT(sentEvent(ICQEvent*))); 
    9394 
    94   QGroupBox* h_action = new QGroupBox(); 
     95  myActionsBox = new QGroupBox(); 
    9596  myMainWidget->addSpacing(10); 
    96   myMainWidget->addWidget(h_action); 
    97  
    98   QHBoxLayout* h_action_lay = new QHBoxLayout(h_action); 
     97  myMainWidget->addWidget(myActionsBox); 
     98 
     99  QHBoxLayout* h_action_lay = new QHBoxLayout(myActionsBox); 
    99100 
    100101  myRead1Button = new QPushButton(); 
     
    637638  myRead3Button->setText(""); 
    638639  myRead4Button->setText(""); 
    639   myRead1Button->setEnabled(false); 
    640   myRead2Button->setEnabled(false); 
    641   myRead3Button->setEnabled(false); 
    642   myRead4Button->setEnabled(false); 
    643640  myEncoding->setEnabled(true); 
    644641 
     
    763760  }  // if 
    764761 
    765   if (!myRead1Button->text().isEmpty()) 
    766     myRead1Button->setEnabled(true); 
    767   if (!myRead2Button->text().isEmpty()) 
    768     myRead2Button->setEnabled(true); 
    769   if (!myRead3Button->text().isEmpty()) 
    770     myRead3Button->setEnabled(true); 
    771   if (!myRead4Button->text().isEmpty()) 
    772     myRead4Button->setEnabled(true); 
     762  myRead1Button->setEnabled(!myRead1Button->text().isEmpty()); 
     763  myRead2Button->setEnabled(!myRead2Button->text().isEmpty()); 
     764  myRead3Button->setEnabled(!myRead3Button->text().isEmpty()); 
     765  myRead4Button->setEnabled(!myRead4Button->text().isEmpty()); 
     766 
     767  myActionsBox->setVisible( 
     768      myRead1Button->isEnabled() || myRead2Button->isEnabled() || 
     769      myRead3Button->isEnabled() || myRead4Button->isEnabled()); 
    773770 
    774771  myRead1Button->setFocus(); 
  • trunk/qt4-gui/src/userevents/userviewevent.h

    r6108 r6166  
    2525 
    2626class QCheckBox; 
     27class QGroupBox; 
    2728class QPushButton; 
    2829class QSplitter; 
     
    5455  CUserEvent* myCurrentEvent; 
    5556  QCheckBox* myAutoCloseCheck; 
     57  QGroupBox* myActionsBox; 
    5658  QPushButton* myRead1Button; 
    5759  QPushButton* myRead2Button; 
  • trunk/qt4-gui/src/widgets/mlview.cpp

    r6160 r6166  
    3434 
    3535#include "config/emoticons.h" 
     36#include "config/general.h" 
    3637#include "core/licqgui.h" 
    3738 
     
    4647  setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); 
    4748  connect(this, SIGNAL(selectionChanged()), SLOT(slotCopy())); 
     49 
     50  updateFont(); 
     51  connect(Config::General::instance(), SIGNAL(fontChanged()), SLOT(updateFont())); 
    4852} 
    4953 
     
    358362  return textCursor().selectedText(); 
    359363} 
     364 
     365void MLView::updateFont() 
     366{ 
     367  setFont(Config::General::instance()->editFont()); 
     368 
     369  // Get height of current font 
     370  myFontHeight = fontMetrics().height(); 
     371 
     372  // Set minimum height of text area to one line of text. 
     373  setMinimumHeight(heightForLines(1)); 
     374} 
     375 
     376int MLView::heightForLines(int lines) const 
     377{ 
     378  // We need to add frame width and the added height of the scroll area as 
     379  // we're calculating height for the widget, not the viewport. 
     380  return lines*myFontHeight + height() - viewport()->height() + 2 * frameWidth(); 
     381} 
     382 
     383void MLView::setSizeHintLines(int lines) 
     384{ 
     385  myLinesHint = lines; 
     386} 
     387 
     388QSize MLView::sizeHint() const 
     389{ 
     390  QSize s = QTextBrowser::sizeHint(); 
     391  if (myLinesHint > 0) 
     392    s.setHeight(heightForLines(myLinesHint)); 
     393  return s; 
     394} 
  • trunk/qt4-gui/src/widgets/mlview.h

    r6160 r6166  
    4646  static QString toRichText(const QString& s, bool highlightURLs = false, bool useHTML = false, QRegExp highlight = QRegExp()); 
    4747 
     48  /** 
     49   * Caclulate height for widget to fit a specified number of lines with 
     50   * current font 
     51   * 
     52   * @param lines Number of text lines to calculate for 
     53   * @return Widget height in pixels 
     54   */ 
     55  int heightForLines(int lines) const; 
     56 
     57  /** 
     58   * Set size hint as number of lines of text 
     59   * 
     60   * @param lines Lines of text that should be visible 
     61   */ 
     62  void setSizeHintLines(int lines); 
     63 
     64  /** 
     65   * Get recommended widget size 
     66   * 
     67   * @return Recommended size 
     68   */ 
     69  QSize sizeHint() const; 
     70 
    4871protected: 
    4972  virtual void contextMenuEvent(QContextMenuEvent* event); 
     
    5679  void slotCopyUrl(); 
    5780  void makeQuote(); 
     81  void updateFont(); 
    5882 
    5983private: 
    6084  bool m_handleLinks; 
    6185  QString m_url; 
     86  int myFontHeight; 
     87  int myLinesHint; 
    6288 
    6389signals: