fb2dlgs.cpp 4.9 KB

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