fb2dlgs.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 <QComboBox>
  8. #include <QDialogButtonBox>
  9. #include <QLineEdit>
  10. #include <QToolBar>
  11. #include <QWebFrame>
  12. #include <QWebPage>
  13. //---------------------------------------------------------------------------
  14. // Fb2CodeFindDlg
  15. //---------------------------------------------------------------------------
  16. Fb2CodeFindDlg::Fb2CodeFindDlg(Fb2CodeEdit &edit)
  17. : QDialog(&edit)
  18. , ui(new Ui::Fb2Find)
  19. , m_edit(edit)
  20. {
  21. ui->setupUi(this);
  22. ui->checkHigh->setText(tr("Complete words"));
  23. connect(ui->btnFind, SIGNAL(clicked()), this, SLOT(find()));
  24. }
  25. Fb2CodeFindDlg::~Fb2CodeFindDlg()
  26. {
  27. delete ui;
  28. }
  29. void Fb2CodeFindDlg::find()
  30. {
  31. QString text = ui->editText->text();
  32. if (text.isEmpty()) return;
  33. QTextDocument::FindFlags options = 0;
  34. if (ui->radioUp->isChecked()) options |= QTextDocument::FindBackward;
  35. if (ui->checkCase->isChecked()) options |= QTextDocument::FindCaseSensitively;
  36. if (ui->checkHigh->isChecked()) options |= QTextDocument::FindWholeWords;
  37. m_edit.findText(text, options);
  38. }
  39. //---------------------------------------------------------------------------
  40. // Fb2TextFindDlg
  41. //---------------------------------------------------------------------------
  42. Fb2TextFindDlg::Fb2TextFindDlg(Fb2TextEdit &edit)
  43. : QDialog(&edit)
  44. , ui(new Ui::Fb2Find)
  45. , m_edit(edit)
  46. {
  47. ui->setupUi(this);
  48. connect(ui->btnFind, SIGNAL(clicked()), this, SLOT(find()));
  49. }
  50. Fb2TextFindDlg::~Fb2TextFindDlg()
  51. {
  52. m_edit.findText(QString(), QWebPage::HighlightAllOccurrences);
  53. delete ui;
  54. }
  55. void Fb2TextFindDlg::find()
  56. {
  57. QString text = ui->editText->text();
  58. if (text.isEmpty()) return;
  59. QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument;
  60. if (ui->radioUp->isChecked()) options |= QWebPage::FindBackward;
  61. if (ui->checkCase->isChecked()) options |= QWebPage::FindCaseSensitively;
  62. if (ui->checkHigh->isChecked()) options |= QWebPage::HighlightAllOccurrences;
  63. m_edit.findText(text, options);
  64. }
  65. //---------------------------------------------------------------------------
  66. // Fb2NoteDlg
  67. //---------------------------------------------------------------------------
  68. Fb2NoteDlg::Fb2NoteDlg(Fb2TextEdit &view)
  69. : QDialog(&view)
  70. {
  71. setWindowTitle(tr("Insert footnote"));
  72. resize(460, 300);
  73. QGridLayout * gridLayout = new QGridLayout(this);
  74. QLabel * label1 = new QLabel(this);
  75. label1->setText(tr("Identifier:"));
  76. gridLayout->addWidget(label1, 0, 0, 1, 1);
  77. m_key = new QComboBox(this);
  78. QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
  79. gridLayout->addWidget(m_key, 0, 1, 1, 1);
  80. QLabel * label2 = new QLabel(this);
  81. label2->setText(tr("Title:"));
  82. gridLayout->addWidget(label2, 1, 0, 1, 1);
  83. m_title = new QLineEdit(this);
  84. m_title->setObjectName(QString::fromUtf8("m_title"));
  85. gridLayout->addWidget(m_title, 1, 1, 1, 1);
  86. m_toolbar = new QToolBar(this);
  87. gridLayout->addWidget(m_toolbar, 2, 0, 1, 2);
  88. QFrame * frame = new QFrame(this);
  89. frame->setFrameShape(QFrame::StyledPanel);
  90. frame->setFrameShadow(QFrame::Sunken);
  91. gridLayout->addWidget(frame, 3, 0, 1, 2);
  92. QLayout * frameLayout = new QBoxLayout(QBoxLayout::LeftToRight, frame);
  93. frameLayout->setSpacing(0);
  94. frameLayout->setMargin(0);
  95. m_text = new QWebView(frame);
  96. m_text->setObjectName(QString::fromUtf8("m_text"));
  97. m_text->setUrl(QUrl(QString::fromUtf8("about:blank")));
  98. frameLayout->addWidget(m_text);
  99. QDialogButtonBox * buttonBox = new QDialogButtonBox(this);
  100. buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
  101. buttonBox->setOrientation(Qt::Horizontal);
  102. buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
  103. gridLayout->addWidget(buttonBox, 4, 0, 1, 2);
  104. QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
  105. QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
  106. m_key->addItem(tr("<create new>"));
  107. m_key->setCurrentIndex(0);
  108. m_title->setFocus();
  109. Fb2TextPage *page = new Fb2TextPage(this);
  110. connect(m_text, SIGNAL(loadFinished(bool)), SLOT(loadFinished()));
  111. page->setNetworkAccessManager(view.page()->networkAccessManager());
  112. page->setContentEditable(true);
  113. m_text->setPage(page);
  114. m_text->setHtml("<body><p><br></p></body>");
  115. FB2::addTools(m_toolbar, m_text);
  116. }
  117. void Fb2NoteDlg::loadFinished()
  118. {
  119. Fb2TextElement body = m_text->page()->mainFrame()->documentElement().findFirst("body");
  120. body.select();
  121. }