Changeset 960

Show
Ignore:
Timestamp:
10/31/08 10:31:07 (2 months ago)
Author:
liamMT
Message:

- add highlighting to messages
- quit the app when the main window is closed

Location:
mchelper/branches/v25
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • mchelper/branches/v25/include/MainWindow.h

    r950 r960  
    7777  About *about; 
    7878  QListWidgetItem deviceListPlaceholder; 
     79  QTextCharFormat grayText, blackText; 
    7980  bool no_ui; 
    8081  bool hideOscMsgs; 
     
    8788  bool winEvent( MSG* msg, long* result ); 
    8889  #endif 
     90  void addMessage( QString time, QString msg, QString tofrom, QTextBlockFormat bkgnd ); 
     91  bool messagesEnabled( MsgType::Type type ); 
    8992   
    9093private slots: 
  • mchelper/branches/v25/src/MainWindow.cpp

    r950 r960  
    3131  actionResetDevice->setEnabled(false); 
    3232  actionSAMBA->setEnabled(false); 
     33   
     34  grayText.setForeground( Qt::gray ); 
     35  blackText.setForeground( Qt::black ); 
    3336   
    3437  // initializations 
     
    137140{ 
    138141  writeSettings( ); 
     142  qDebug( "closing" ); 
    139143  qcloseevent->accept(); 
     144  qApp->quit(); // in case the inspector or anything else is still open 
    140145} 
    141146 
     
    348353void MainWindow::message(QStringList msgs, MsgType::Type type, QString from) 
    349354{ 
    350   QStringList post; 
     355  if( !messagesEnabled( type ) ) 
     356    return; 
    351357  QString currentTime = QTime::currentTime().toString(); 
    352358  QTextBlockFormat format; 
    353359  format.setBackground(msgColor(type)); 
    354360  QString tofrom("from"); 
    355   if(type == MsgType::Command || type == MsgType::XMLMessage || type == MsgType::Response) 
    356   { 
    357     if( hideOscMsgs ) 
    358       return; 
    359   } 
    360361  if(type == MsgType::Command) 
    361362    tofrom = "to"; 
    362363 
     364  outputConsole->setUpdatesEnabled(false); 
     365  QString tf = QString("%1 %2").arg(tofrom).arg(from); 
    363366  foreach(QString msg, msgs) 
    364     post << QString("%1    %2 %3 %4").arg(currentTime).arg(msg).arg(tofrom).arg(from); 
    365  
    366   // because the format will be the same for all lines added via insertPlainText() 
    367   // we need to add a blank line to set our format, then insert the message 
    368   outputConsole->moveCursor(QTextCursor::End); 
    369   if(outputConsole->blockCount()) 
    370     outputConsole->insertPlainText("\n"); 
    371   outputConsole->textCursor().setBlockFormat(format); 
    372   outputConsole->insertPlainText(post.join("\n")); 
    373   outputConsole->ensureCursorVisible(); 
     367    addMessage( currentTime, msg, tf, format); 
     368  outputConsole->setUpdatesEnabled(true); 
    374369} 
    375370 
     
    383378  else 
    384379  { 
     380    if( !messagesEnabled( type ) ) 
     381      return; 
    385382    QTextBlockFormat format; 
    386383    format.setBackground(msgColor(type)); 
    387384    QString tofrom = tr("from"); 
    388     if(type == MsgType::Command || type == MsgType::XMLMessage || type == MsgType::Response) 
    389     { 
    390       if( hideOscMsgs ) 
    391         return; 
    392     } 
     385     
    393386    if(type == MsgType::Command) 
    394387      tofrom = tr("to"); 
    395388     
    396     msg.prepend(QTime::currentTime().toString() + "    "); // todo - maybe make the time text gray 
    397     msg += QString(" %1 %2").arg(tofrom).arg(from); 
    398     outputConsole->appendPlainText(msg); // insert the message 
    399     outputConsole->moveCursor(QTextCursor::End); // move the cursor to the end 
    400     outputConsole->textCursor().setBlockFormat(format); // so that when we set the color, it colors the right block 
    401     outputConsole->ensureCursorVisible(); 
    402   } 
     389    outputConsole->setUpdatesEnabled(false); 
     390    addMessage( QTime::currentTime().toString(), msg, QString("%1 %2").arg(tofrom).arg(from), format); 
     391    outputConsole->setUpdatesEnabled(true); 
     392  } 
     393} 
     394 
     395void MainWindow::addMessage( QString time, QString msg, QString tofrom, QTextBlockFormat bkgnd ) 
     396{ 
     397  outputConsole->setCurrentCharFormat(grayText); 
     398  outputConsole->appendPlainText(time + "   "); 
     399  outputConsole->setCurrentCharFormat(blackText); 
     400  outputConsole->insertPlainText(msg); 
     401  outputConsole->setCurrentCharFormat(grayText); 
     402  outputConsole->insertPlainText(" " + tofrom); 
     403  outputConsole->textCursor().setBlockFormat(bkgnd); 
     404} 
     405 
     406bool MainWindow::messagesEnabled( MsgType::Type type ) 
     407{ 
     408  bool retval = true; 
     409  if(type == MsgType::Command || type == MsgType::XMLMessage || type == MsgType::Response || type == MsgType::Warning) 
     410  { 
     411    if( hideOscMsgs ) 
     412      retval = false; 
     413  } 
     414  return retval; 
    403415} 
    404416