dictbrowsersearch.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*****************************************************************************
  2. * keyboard.h - QStarDict, a StarDict clone written with using Qt *
  3. * Copyright (C) 2007 Petr Vanek *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License along *
  16. * with this program; if not, write to the Free Software Foundation, Inc., *
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
  18. *****************************************************************************/
  19. #include "dictbrowsersearch.h"
  20. namespace QStarDict
  21. {
  22. DictBrowserSearch::DictBrowserSearch(QWidget *parent) :
  23. QWidget(parent)
  24. {
  25. setupUi(this);
  26. connect(searchEdit, SIGNAL(textEdited(QString)), this, SLOT(searchAll()));
  27. connect(caseSensitiveCheckBox, SIGNAL(clicked()), this, SLOT(searchAll()));
  28. connect(wholeWordsCheckBox, SIGNAL(clicked()), this, SLOT(searchAll()));
  29. }
  30. void DictBrowserSearch::searchAll()
  31. {
  32. QTextDocument::FindFlags f = 0;
  33. if (caseSensitiveCheckBox->isChecked())
  34. f |= QTextDocument::FindCaseSensitively;
  35. if (wholeWordsCheckBox->isChecked())
  36. f |= QTextDocument::FindWholeWords;
  37. emit search(searchEdit->text(), f);
  38. }
  39. void DictBrowserSearch::searchResult(bool success)
  40. {
  41. QPalette p;
  42. if (!success)
  43. {
  44. p.setColor(QPalette::Base, Qt::red);
  45. }
  46. searchEdit->setPalette(p);
  47. }
  48. void DictBrowserSearch::showEvent(QShowEvent * event)
  49. {
  50. QWidget::showEvent(event);
  51. searchEdit->setFocus(Qt::OtherFocusReason);
  52. if (searchEdit->text().length())
  53. searchAll();
  54. }
  55. void DictBrowserSearch::closeEvent(QCloseEvent * event)
  56. {
  57. QWidget::closeEvent(event);
  58. }
  59. } // namespace