fb2dlgs.cpp 4.9 KB

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