Changeset 6448

Show
Ignore:
Timestamp:
07/13/08 03:39:22 (4 months ago)
Author:
flynd
Message:

Searching in history dialog will now mark all dates with matching entries in green.

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

Legend:

Unmodified
Added
Removed
  • trunk/qt4-gui/src/dialogs/historydlg.cpp

    r6374 r6448  
    133133  searchLayout->addLayout(findLayout); 
    134134  connect(myPatternEdit, SIGNAL(textChanged(const QString&)), SLOT(searchTextChanged(const QString&))); 
     135  myPatternChanged = true; 
    135136 
    136137  // Shortcuts for searching 
     
    392393  QRegExp regExp(getRegExp()); 
    393394 
     395  // If search pattern has changed, find all matching dates and mark them in the calendar 
     396  if (myPatternChanged) 
     397  { 
     398    myCalendar->clearMatches(); 
     399 
     400    for (HistoryListIter i = myHistoryList.begin(); i != myHistoryList.end(); ++i) 
     401    { 
     402      QString messageText; 
     403      if ((*i)->SubCommand() == ICQ_CMDxSUB_SMS) // SMSs are always in UTF-8 
     404        messageText = QString::fromUtf8((*i)->Text()); 
     405      else 
     406        messageText = myContactCodec->toUnicode((*i)->Text()); 
     407 
     408      if (messageText.contains(regExp)) 
     409      { 
     410        QDate date = QDateTime::fromTime_t((*i)->Time()).date(); 
     411        myCalendar->addMatch(date); 
     412      } 
     413    } 
     414 
     415    // No need to do this again next time 
     416    myPatternChanged = false; 
     417  } 
     418 
    394419  myStatusLabel->setText(QString()); 
    395420 
     
    469494  // Clear failed status from previous search 
    470495  myPatternEdit->setStyleSheet(""); 
     496 
     497  // Mark that pattern has changed since previous search 
     498  myPatternChanged = true; 
     499 
     500  // Search field is cleared so clear status message and matching dates 
     501  if (text.isEmpty()) 
     502  { 
     503    myStatusLabel->setText(QString()); 
     504    myCalendar->clearMatches(); 
     505  } 
    471506} 
    472507 
  • trunk/qt4-gui/src/dialogs/historydlg.h

    r6186 r6448  
    153153  QTextCodec* myContactCodec; 
    154154  bool myUseHtml; 
     155  bool myPatternChanged; 
    155156 
    156157  HistoryList myHistoryList; 
  • trunk/qt4-gui/src/widgets/calendar.cpp

    r5996 r6448  
    5454} 
    5555 
    56 void Calendar::markDate(QDate date) 
     56void Calendar::markDate(const QDate& date) 
    5757{ 
    5858  QTextCharFormat textFormat = dateTextFormat(date); 
     
    6262  textFormat.setBackground(Qt::transparent); 
    6363  setDateTextFormat(date, textFormat); 
     64} 
     65 
     66void Calendar::addMatch(const QDate& date) 
     67{ 
     68  if (myMatches.contains(date)) 
     69    return; 
     70 
     71  myMatches.append(date); 
     72  updateCell(date); 
     73} 
     74 
     75void Calendar::clearMatches() 
     76{ 
     77  myMatches.clear(); 
     78  updateCells(); 
    6479} 
    6580 
     
    7489    painter->setPen(Qt::NoPen); 
    7590    painter->setRenderHints(painter->renderHints() | QPainter::Antialiasing); 
    76     painter->setBrush(Qt::yellow); 
     91    painter->setBrush(myMatches.contains(date) ? Qt::green : Qt::yellow); 
    7792    painter->drawEllipse(center); 
    7893    painter->restore(); 
  • trunk/qt4-gui/src/widgets/calendar.h

    r5996 r6448  
    2525 
    2626#include <QCalendarWidget> 
     27#include <QDate> 
     28#include <QList> 
    2729 
    2830namespace LicqQtGui 
     
    5456   * @param date Date to mark 
    5557   */ 
    56   void markDate(QDate date); 
     58  void markDate(const QDate& date); 
     59 
     60  /** 
     61   * Mark a search match in the calendar 
     62   * Note: Date must already be marked with markDate() 
     63   * 
     64   * @param date Date of the match 
     65   */ 
     66  void addMatch(const QDate& date); 
     67 
     68  /** 
     69   * Clear all search matches 
     70   */ 
     71  void clearMatches(); 
    5772 
    5873protected: 
     
    6580   */ 
    6681  virtual void paintCell(QPainter* painter, const QRect& rect, const QDate& date) const; 
     82 
     83private: 
     84  QList<QDate> myMatches; 
    6785}; 
    6886