Bibletime – a bible study tool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cplainwritedisplay.cpp 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*********
  2. *
  3. * This file is part of BibleTime's source code, http://www.bibletime.info/.
  4. *
  5. * Copyright 1999-2006 by the BibleTime developers.
  6. * The BibleTime source code is licensed under the GNU General Public License version 2.0.
  7. *
  8. **********/
  9. #include "cplainwritedisplay.h"
  10. #include "frontend/cdragdropmgr.h"
  11. #include "frontend/displaywindow/cdisplaywindow.h"
  12. #include "frontend/displaywindow/cwritewindow.h"
  13. #include "util/scoped_resource.h"
  14. //TQt includes
  15. //KDE includes
  16. #include <kaction.h>
  17. #include <klocale.h>
  18. CPlainWriteDisplay::CPlainWriteDisplay(CWriteWindow* parentWindow, TQWidget* parent) : TQTextEdit(parentWindow ? parentWindow : parent), CWriteDisplay(parentWindow) {
  19. setTextFormat(TQt::PlainText);
  20. setAcceptDrops(true);
  21. viewport()->setAcceptDrops(true);
  22. connect(this, TQT_SIGNAL(textChanged()),
  23. connectionsProxy(), TQT_SLOT(emitTextChanged()));
  24. }
  25. CPlainWriteDisplay::~CPlainWriteDisplay() {}
  26. /** Reimplementation. */
  27. void CPlainWriteDisplay::selectAll() {
  28. TQTextEdit::selectAll(true);
  29. }
  30. void CPlainWriteDisplay::setText( const TQString& newText ) {
  31. //make sure the text has been converted to show \n instead of <br/>
  32. TQString text = newText;
  33. // text.replace("\n<br /><!-- BT newline -->\n", "\n");
  34. text.replace("<br />", "\n"); //inserted by BT or the TQt textedit widget
  35. TQTextEdit::setText(text);
  36. }
  37. const bool CPlainWriteDisplay::hasSelection() {
  38. return hasSelectedText();
  39. }
  40. TQWidget* CPlainWriteDisplay::view() {
  41. tqDebug("CPlainWriteDisplay::view()");
  42. return this;
  43. }
  44. const TQString CPlainWriteDisplay::text( const CDisplay::TextType /*format*/, const CDisplay::TextPart /*part*/) {
  45. return TQString();
  46. }
  47. void CPlainWriteDisplay::print( const CDisplay::TextPart, CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions ) {
  48. }
  49. /** Sets the current status of the edit widget. */
  50. void CPlainWriteDisplay::setModified( const bool modified ) {
  51. TQTextEdit::setModified(modified);
  52. }
  53. /** Reimplementation. */
  54. const bool CPlainWriteDisplay::isModified() const {
  55. return TQTextEdit::isModified();
  56. }
  57. /** Returns the text of this edit widget. */
  58. const TQString CPlainWriteDisplay::plainText() {
  59. TQString ret = TQTextEdit::text();
  60. //in plain text mode the text just contains newlines, convert them into <br/> before we return the text for display in a HTML widget
  61. ret.replace("\n", "<br />");
  62. return ret;
  63. }
  64. /** Reimplementation from TQTextEdit. Provides an popup menu for the given position. */
  65. TQPopupMenu* CPlainWriteDisplay::createPopupMenu( const TQPoint& /*pos*/ ) {
  66. return installedPopup();
  67. }
  68. /** Reimplementation from TQTextEdit. Provides an popup menu for the given position. */
  69. TQPopupMenu* CPlainWriteDisplay::createPopupMenu( ) {
  70. return installedPopup();
  71. }
  72. /** Creates the necessary action objects and puts them on the toolbar. */
  73. void CPlainWriteDisplay::setupToolbar(TDEToolBar* /*bar*/, TDEActionCollection* /*actionCollection*/) {}
  74. /** Reimplementation to insert the text of a dragged reference into the edit view. */
  75. void CPlainWriteDisplay::contentsDragEnterEvent( TQDragEnterEvent* e ) {
  76. if (CDragDropMgr::canDecode(e)) {
  77. e->accept(true);
  78. }
  79. else {
  80. e->accept(false);
  81. e->ignore();
  82. }
  83. }
  84. /** Reimplementation to insert the text of a dragged reference into the edit view. */
  85. void CPlainWriteDisplay::contentsDragMoveEvent( TQDragMoveEvent* e ) {
  86. if (CDragDropMgr::canDecode(e)) {
  87. placeCursor(e->pos());
  88. ensureCursorVisible();
  89. e->accept(true);
  90. }
  91. else {
  92. e->accept(false);
  93. e->ignore();
  94. }
  95. }
  96. /** Reimplementation to manage drops of our drag and drop objects. */
  97. void CPlainWriteDisplay::contentsDropEvent( TQDropEvent* e ) {
  98. if ( CDragDropMgr::canDecode(e) ) {
  99. e->acceptAction();
  100. CDragDropMgr::ItemList items = CDragDropMgr::decode(e);
  101. CDragDropMgr::ItemList::iterator it;
  102. for (it = items.begin(); it != items.end(); ++it) {
  103. switch ((*it).type()) {
  104. case CDragDropMgr::Item::Bookmark: {
  105. CSwordModuleInfo* module = backend()->findModuleByName((*it).bookmarkModule());
  106. util::scoped_ptr<CSwordKey> key( CSwordKey::createInstance(module) );
  107. key->key( (*it).bookmarkKey() );
  108. TQString moduleText = key->strippedText();
  109. const TQString text = TQString::fromLatin1("%1\n(%2, %3)\n").arg(moduleText).arg((*it).bookmarkKey()).arg((*it).bookmarkModule());
  110. placeCursor( e->pos() );
  111. insert( text );
  112. break;
  113. }
  114. case CDragDropMgr::Item::Text: {
  115. placeCursor( e->pos() );
  116. insert( (*it).text() );
  117. break;
  118. }
  119. default:
  120. break;
  121. }
  122. }
  123. }
  124. }