Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void MainWindow::searchNext()
- {
- QString strsearch = ui->edSearch->text();
- if (strsearch.isEmpty()) {
- QMessageBox::warning(this, tr("QSig"), kor("검색어 입력이 필요합니다. !!!"));
- ui->edSearch->setFocus();
- return;
- }
- int count = 0;
- bool isSearch = false;
- int tabint = ui->tabWidget->currentIndex();
- QWidget *widget = editorList->at(tabint);
- widget->setFocus();
- if (QApplication::focusWidget()->inherits("CodeEditor")) {
- CodeEditor *myeditor = static_cast<CodeEditor*>(QApplication::focusWidget());
- document = myeditor->document();
- }
- //document->setDefaultStyleSheet("background-color: red");
- QTextCursor highlightCursor(document);
- QTextCursor cursor(document);
- cursor.beginEditBlock();
- QTextCharFormat plainFormat(highlightCursor.charFormat());
- QTextCharFormat colorFormat = plainFormat;
- plainFormat.clearBackground();
- colorFormat.setBackground(Qt::yellow);
- while (!highlightCursor.isNull() && !highlightCursor.atEnd())
- {
- // p.setColor(QPalette::Base, QColor("#f8f8f8"));
- //XXX if (searchTextList.contains())
- if (!highlightCursor.isNull())
- {
- count++;
- //매칭되는 문자열을 기본으로, 대소문자 구분은 QTextDocument::FindCaseSensitively, wholeword 는 QTextDocument::FindWholeWords임
- highlightCursor = document->find(strsearch, highlightCursor, 0);
- highlightCursor.movePosition(QTextCursor::WordRight, QTextCursor::KeepAnchor);
- highlightCursor.mergeCharFormat(colorFormat);
- isSearch = true;
- }
- }
- cursor.endEditBlock();
- if (isSearch)
- searchTextList.append(strsearch);
- //search result was plus 1
- count--;
- if (count > 0)
- ui->logEdit->append(strsearch + kor(" 해당하는 문자열을 총 ") + QString::number(count) + kor("개 찾았어요. !!!"));
- else
- QMessageBox::information(this, tr("QSig"), strsearch + kor("에 해당하는 문자열이 없어요. !!!"));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement