fb2dlgs.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #include "fb2dlgs.hpp"
  2. #include "fb2code.hpp"
  3. #include "fb2text.hpp"
  4. #include "fb2tree.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. // FbCodeFindDlg
  15. //---------------------------------------------------------------------------
  16. FbCodeFindDlg::FbCodeFindDlg(FbCodeEdit &edit)
  17. : QDialog(&edit)
  18. , ui(new Ui::FbFind)
  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. FbCodeFindDlg::~FbCodeFindDlg()
  26. {
  27. delete ui;
  28. }
  29. void FbCodeFindDlg::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. // FbTextFindDlg
  41. //---------------------------------------------------------------------------
  42. FbTextFindDlg::FbTextFindDlg(FbTextEdit &edit)
  43. : QDialog(&edit)
  44. , ui(new Ui::FbFind)
  45. , m_edit(edit)
  46. {
  47. ui->setupUi(this);
  48. ui->checkHigh->hide();
  49. connect(ui->btnFind, SIGNAL(clicked()), this, SLOT(find()));
  50. }
  51. FbTextFindDlg::~FbTextFindDlg()
  52. {
  53. m_edit.findText(QString(), QWebPage::HighlightAllOccurrences);
  54. delete ui;
  55. }
  56. void FbTextFindDlg::find()
  57. {
  58. QString text = ui->editText->text();
  59. if (text.isEmpty()) return;
  60. QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument;
  61. if (ui->radioUp->isChecked()) options |= QWebPage::FindBackward;
  62. if (ui->checkCase->isChecked()) options |= QWebPage::FindCaseSensitively;
  63. m_edit.findText(text, options);
  64. options |= QWebPage::HighlightAllOccurrences;
  65. m_edit.findText(text, options);
  66. }
  67. //---------------------------------------------------------------------------
  68. // FbNoteDlg
  69. //---------------------------------------------------------------------------
  70. FbNoteDlg::FbNoteDlg(FbTextEdit &view)
  71. : QDialog(&view)
  72. {
  73. setWindowTitle(tr("Insert footnote"));
  74. resize(460, 300);
  75. QGridLayout * gridLayout = new QGridLayout(this);
  76. QLabel * label1 = new QLabel(this);
  77. label1->setText(tr("Identifier:"));
  78. gridLayout->addWidget(label1, 0, 0, 1, 1);
  79. m_key = new QComboBox(this);
  80. QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
  81. gridLayout->addWidget(m_key, 0, 1, 1, 1);
  82. QLabel * label2 = new QLabel(this);
  83. label2->setText(tr("Title:"));
  84. gridLayout->addWidget(label2, 1, 0, 1, 1);
  85. m_title = new QLineEdit(this);
  86. m_title->setObjectName(QString::fromUtf8("m_title"));
  87. gridLayout->addWidget(m_title, 1, 1, 1, 1);
  88. m_toolbar = new QToolBar(this);
  89. gridLayout->addWidget(m_toolbar, 2, 0, 1, 2);
  90. QFrame * frame = new QFrame(this);
  91. frame->setFrameShape(QFrame::StyledPanel);
  92. frame->setFrameShadow(QFrame::Sunken);
  93. gridLayout->addWidget(frame, 3, 0, 1, 2);
  94. QLayout * frameLayout = new QBoxLayout(QBoxLayout::LeftToRight, frame);
  95. frameLayout->setSpacing(0);
  96. frameLayout->setMargin(0);
  97. m_text = new FbTextBase(frame);
  98. m_text->setObjectName(QString::fromUtf8("m_text"));
  99. m_text->setUrl(QUrl(QString::fromUtf8("about:blank")));
  100. frameLayout->addWidget(m_text);
  101. QDialogButtonBox * buttonBox = new QDialogButtonBox(this);
  102. buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
  103. buttonBox->setOrientation(Qt::Horizontal);
  104. buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
  105. gridLayout->addWidget(buttonBox, 4, 0, 1, 2);
  106. QObject::connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
  107. QObject::connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
  108. m_key->addItem(tr("<create new>"));
  109. m_key->setCurrentIndex(0);
  110. m_title->setFocus();
  111. FbTextPage *page = new FbTextPage(this);
  112. connect(m_text, SIGNAL(loadFinished(bool)), SLOT(loadFinished()));
  113. page->setNetworkAccessManager(view.page()->networkAccessManager());
  114. page->setContentEditable(true);
  115. m_text->setPage(page);
  116. m_text->setHtml("<body><p><br></p></body>");
  117. m_text->addTools(m_toolbar);
  118. }
  119. void FbNoteDlg::loadFinished()
  120. {
  121. FbTextElement body = m_text->page()->mainFrame()->documentElement().findFirst("body");
  122. body.select();
  123. }