fb2dlgs.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #include "fb2dlgs.hpp"
  2. #include "fb2code.hpp"
  3. #include "fb2tree.hpp"
  4. #include "fb2view.hpp"
  5. #include "fb2utils.h"
  6. #include "ui_fb2find.h"
  7. #include "ui_fb2note.h"
  8. #include <QWebFrame>
  9. #include <QWebPage>
  10. //---------------------------------------------------------------------------
  11. // Fb2CodeFindDlg
  12. //---------------------------------------------------------------------------
  13. Fb2CodeFindDlg::Fb2CodeFindDlg(Fb2CodeEdit &edit)
  14. : QDialog(&edit)
  15. , ui(new Ui::Fb2Find)
  16. , m_edit(edit)
  17. {
  18. ui->setupUi(this);
  19. ui->checkHigh->setText(tr("Complete words"));
  20. connect(ui->btnFind, SIGNAL(clicked()), this, SLOT(find()));
  21. }
  22. Fb2CodeFindDlg::~Fb2CodeFindDlg()
  23. {
  24. delete ui;
  25. }
  26. void Fb2CodeFindDlg::find()
  27. {
  28. QString text = ui->editText->text();
  29. if (text.isEmpty()) return;
  30. QTextDocument::FindFlags options = 0;
  31. if (ui->radioUp->isChecked()) options |= QTextDocument::FindBackward;
  32. if (ui->checkCase->isChecked()) options |= QTextDocument::FindCaseSensitively;
  33. if (ui->checkHigh->isChecked()) options |= QTextDocument::FindWholeWords;
  34. m_edit.findText(text, options);
  35. }
  36. //---------------------------------------------------------------------------
  37. // Fb2TextFindDlg
  38. //---------------------------------------------------------------------------
  39. Fb2TextFindDlg::Fb2TextFindDlg(Fb2WebView &edit)
  40. : QDialog(&edit)
  41. , ui(new Ui::Fb2Find)
  42. , m_edit(edit)
  43. {
  44. ui->setupUi(this);
  45. connect(ui->btnFind, SIGNAL(clicked()), this, SLOT(find()));
  46. }
  47. Fb2TextFindDlg::~Fb2TextFindDlg()
  48. {
  49. m_edit.findText(QString(), QWebPage::HighlightAllOccurrences);
  50. delete ui;
  51. }
  52. void Fb2TextFindDlg::find()
  53. {
  54. QString text = ui->editText->text();
  55. if (text.isEmpty()) return;
  56. QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument;
  57. if (ui->radioUp->isChecked()) options |= QWebPage::FindBackward;
  58. if (ui->checkCase->isChecked()) options |= QWebPage::FindCaseSensitively;
  59. if (ui->checkHigh->isChecked()) options |= QWebPage::HighlightAllOccurrences;
  60. m_edit.findText(text, options);
  61. }
  62. //---------------------------------------------------------------------------
  63. // Fb2NoteDlg
  64. //---------------------------------------------------------------------------
  65. Fb2NoteDlg::Fb2NoteDlg(Fb2WebView &view)
  66. : QDialog(&view)
  67. , ui(new Ui::Fb2Note)
  68. {
  69. ui->setupUi(this);
  70. ui->m_key->addItem(tr("<create new>"));
  71. ui->m_key->setCurrentIndex(0);
  72. ui->m_title->setFocus();
  73. Fb2WebPage *page = new Fb2WebPage(this);
  74. connect(ui->m_text, SIGNAL(loadFinished(bool)), SLOT(loadFinished()));
  75. page->setNetworkAccessManager(view.page()->networkAccessManager());
  76. page->setContentEditable(true);
  77. ui->m_text->setPage(page);
  78. ui->m_text->setHtml("<body><p></p></body>");
  79. FB2::addTools(ui->m_toolbar, ui->m_text);
  80. }
  81. Fb2NoteDlg::~Fb2NoteDlg()
  82. {
  83. delete ui;
  84. }
  85. void Fb2NoteDlg::loadFinished()
  86. {
  87. Fb2WebElement body = ui->m_text->page()->mainFrame()->documentElement().findFirst("body");
  88. body.select();
  89. }