/tests/auto/linguist/lupdate/testdata/good/mergecpp_noobsolete/finddialog.cpp

https://bitbucket.org/ultra_iter/qt-vtl · C++ · 154 lines · 89 code · 23 blank · 42 comment · 17 complexity · a3d90412463f51b41f36cb36c7b91092 MD5 · raw file

  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
  4. ** All rights reserved.
  5. ** Contact: Nokia Corporation (qt-info@nokia.com)
  6. **
  7. ** This file is part of the test suite of the Qt Toolkit.
  8. **
  9. ** $QT_BEGIN_LICENSE:LGPL$
  10. ** GNU Lesser General Public License Usage
  11. ** This file may be used under the terms of the GNU Lesser General Public
  12. ** License version 2.1 as published by the Free Software Foundation and
  13. ** appearing in the file LICENSE.LGPL included in the packaging of this
  14. ** file. Please review the following information to ensure the GNU Lesser
  15. ** General Public License version 2.1 requirements will be met:
  16. ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  17. **
  18. ** In addition, as a special exception, Nokia gives you certain additional
  19. ** rights. These rights are described in the Nokia Qt LGPL Exception
  20. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  21. **
  22. ** GNU General Public License Usage
  23. ** Alternatively, this file may be used under the terms of the GNU General
  24. ** Public License version 3.0 as published by the Free Software Foundation
  25. ** and appearing in the file LICENSE.GPL included in the packaging of this
  26. ** file. Please review the following information to ensure the GNU General
  27. ** Public License version 3.0 requirements will be met:
  28. ** http://www.gnu.org/copyleft/gpl.html.
  29. **
  30. ** Other Usage
  31. ** Alternatively, this file may be used in accordance with the terms and
  32. ** conditions contained in a signed written agreement between you and Nokia.
  33. **
  34. **
  35. **
  36. **
  37. **
  38. ** $QT_END_LICENSE$
  39. **
  40. ****************************************************************************/
  41. #include "finddialog.h"
  42. #include "mainwindow.h"
  43. #include "tabbedbrowser.h"
  44. #include "helpwindow.h"
  45. #include <QTextBrowser>
  46. #include <QTextCursor>
  47. #include <QStatusBar>
  48. #include <QLineEdit>
  49. #include <QDateTime>
  50. #include <QGridLayout>
  51. CaseSensitiveModel::CaseSensitiveModel(int rows, int columns, QObject *parent)
  52. : QStandardItemModel(rows, columns, parent)
  53. {}
  54. QModelIndexList CaseSensitiveModel::match(const QModelIndex &start, int role, const QVariant &value,
  55. int hits, Qt::MatchFlags flags) const
  56. {
  57. if (flags == Qt::MatchFlags(Qt::MatchStartsWith|Qt::MatchWrap))
  58. flags |= Qt::MatchCaseSensitive;
  59. return QStandardItemModel::match(start, role, value, hits, flags);
  60. }
  61. FindDialog::FindDialog(MainWindow *parent)
  62. : QDialog(parent)
  63. {
  64. contentsWidget = new QWidget(this);
  65. ui.setupUi(contentsWidget);
  66. ui.comboFind->setModel(new CaseSensitiveModel(0, 1, ui.comboFind));
  67. QVBoxLayout *l = new QVBoxLayout(this);
  68. l->setMargin(0);
  69. l->setSpacing(0);
  70. l->addWidget(contentsWidget);
  71. lastBrowser = 0;
  72. onceFound = false;
  73. findExpr.clear();
  74. sb = new QStatusBar(this);
  75. l->addWidget(sb);
  76. sb->showMessage(tr("Enter the text you want to find."));
  77. connect(ui.findButton, SIGNAL(clicked()), this, SLOT(findButtonClicked()));
  78. connect(ui.closeButton, SIGNAL(clicked()), this, SLOT(reject()));
  79. }
  80. FindDialog::~FindDialog()
  81. {
  82. }
  83. void FindDialog::findButtonClicked()
  84. {
  85. doFind(ui.radioForward->isChecked());
  86. }
  87. void FindDialog::doFind(bool forward)
  88. {
  89. QTextBrowser *browser = static_cast<QTextBrowser*>(mainWindow()->browsers()->currentBrowser());
  90. sb->clearMessage();
  91. if (ui.comboFind->currentText() != findExpr || lastBrowser != browser)
  92. onceFound = false;
  93. findExpr = ui.comboFind->currentText();
  94. QTextDocument::FindFlags flags = 0;
  95. if (ui.checkCase->isChecked())
  96. flags |= QTextDocument::FindCaseSensitively;
  97. if (ui.checkWords->isChecked())
  98. flags |= QTextDocument::FindWholeWords;
  99. QTextCursor c = browser->textCursor();
  100. if (!c.hasSelection()) {
  101. if (forward)
  102. c.movePosition(QTextCursor::Start);
  103. else
  104. c.movePosition(QTextCursor::End);
  105. browser->setTextCursor(c);
  106. }
  107. QTextDocument::FindFlags options;
  108. if (forward == false)
  109. flags |= QTextDocument::FindBackward;
  110. QTextCursor found = browser->document()->find(findExpr, c, flags);
  111. if (found.isNull()) {
  112. if (onceFound) {
  113. if (forward)
  114. statusMessage(tr("Search reached end of the document"));
  115. else
  116. statusMessage(tr("Search reached start of the document"));
  117. } else {
  118. statusMessage(tr( "Text not found" ));
  119. }
  120. } else {
  121. browser->setTextCursor(found);
  122. }
  123. onceFound |= !found.isNull();
  124. lastBrowser = browser;
  125. }
  126. bool FindDialog::hasFindExpression() const
  127. {
  128. // statusMessage(tr( "Should be obsolete" ));
  129. //% "This is some random text"
  130. qtTrId("keep_id")
  131. }