Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void MainWindow::searchNext()
  2. {
  3.     QString strsearch = ui->edSearch->text();
  4.  
  5.     if (strsearch.isEmpty()) {
  6.         QMessageBox::warning(this, tr("QSig"), kor("검색어 입력이 필요합니다. !!!"));
  7.         ui->edSearch->setFocus();
  8.         return;
  9.     }
  10.  
  11.     int count = 0;
  12.     bool isSearch = false;
  13.     int tabint = ui->tabWidget->currentIndex();
  14.     QWidget *widget =  editorList->at(tabint);
  15.     widget->setFocus();
  16.  
  17.     if (QApplication::focusWidget()->inherits("CodeEditor")) {
  18.          CodeEditor *myeditor = static_cast<CodeEditor*>(QApplication::focusWidget());
  19.          document = myeditor->document();        
  20.      }
  21.  
  22.  
  23.     //document->setDefaultStyleSheet("background-color: red");
  24.  
  25.     QTextCursor highlightCursor(document);
  26.     QTextCursor cursor(document);
  27.  
  28.     cursor.beginEditBlock();
  29.  
  30.     QTextCharFormat plainFormat(highlightCursor.charFormat());
  31.     QTextCharFormat colorFormat = plainFormat;
  32.  
  33.     plainFormat.clearBackground();
  34.  
  35.     colorFormat.setBackground(Qt::yellow);
  36.  
  37.     while (!highlightCursor.isNull() && !highlightCursor.atEnd())
  38.     {
  39.     //       p.setColor(QPalette::Base, QColor("#f8f8f8"));
  40.     //XXX     if (searchTextList.contains())
  41.  
  42.         if (!highlightCursor.isNull())
  43.         {
  44.         count++;
  45.         //매칭되는 문자열을 기본으로, 대소문자 구분은 QTextDocument::FindCaseSensitively, wholeword 는 QTextDocument::FindWholeWords임
  46.         highlightCursor = document->find(strsearch,  highlightCursor, 0);
  47.         highlightCursor.movePosition(QTextCursor::WordRight,  QTextCursor::KeepAnchor);
  48.         highlightCursor.mergeCharFormat(colorFormat);
  49.         isSearch = true;
  50.         }
  51.     }
  52.     cursor.endEditBlock();
  53.  
  54.     if (isSearch)
  55.         searchTextList.append(strsearch);
  56.  
  57.     //search result was plus 1
  58.     count--;
  59.  
  60.     if (count > 0)
  61.         ui->logEdit->append(strsearch + kor(" 해당하는 문자열을 총 ") +  QString::number(count) + kor("개 찾았어요. !!!"));
  62.     else
  63.        QMessageBox::information(this, tr("QSig"), strsearch + kor("에 해당하는 문자열이 없어요. !!!"));
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement