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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 "cdisplay.h"
  10. #include "chtmlreaddisplay.h"
  11. #include "cplainwritedisplay.h"
  12. #include "chtmlwritedisplay.h"
  13. #include "backend/creferencemanager.h"
  14. #include "util/ctoolclass.h"
  15. //TQt includes
  16. #include <tqclipboard.h>
  17. #include <tqpopupmenu.h>
  18. #include <tqtimer.h>
  19. //KDE includes
  20. #include <tdeapplication.h>
  21. #include <tdefiledialog.h>
  22. #include <tdelocale.h>
  23. CDisplayConnections::CDisplayConnections( CDisplay* display ) : m_display(display) {}
  24. void CDisplayConnections::selectAll() {
  25. m_display->selectAll();
  26. }
  27. void CDisplayConnections::saveAsHTML() {
  28. m_display->save(CDisplay::HTMLText, CDisplay::Document);
  29. }
  30. void CDisplayConnections::saveAsPlain() {
  31. m_display->save(CDisplay::PlainText, CDisplay::Document);
  32. }
  33. /** Emits the signal. */
  34. void CDisplayConnections::emitReferenceClicked( const TQString& module, const TQString& key) {
  35. emit referenceClicked( module, key );
  36. }
  37. /** Emits the signal. */
  38. void CDisplayConnections::emitReferenceDropped( const TQString& key) {
  39. emit referenceDropped(key);
  40. }
  41. /** Emits the signal. */
  42. void CDisplayConnections::emitTextChanged() {
  43. emit textChanged();
  44. }
  45. void CDisplayConnections::copyAll() {
  46. m_display->copy(CDisplay::PlainText, CDisplay::Document);
  47. }
  48. /** No descriptions */
  49. void CDisplayConnections::copySelection() {
  50. tqWarning("copyign the selected text");
  51. m_display->copy(CDisplay::PlainText, CDisplay::SelectedText);
  52. }
  53. void CDisplayConnections::printAll(CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions) {
  54. m_display->print(CDisplay::Document, displayOptions, filterOptions);
  55. }
  56. void CDisplayConnections::printAnchorWithText(CSwordBackend::DisplayOptions displayOptions, CSwordBackend::FilterOptions filterOptions) {
  57. m_display->print(CDisplay::AnchorWithText, displayOptions, filterOptions);
  58. }
  59. void CDisplayConnections::copyAnchorOnly() {
  60. m_display->copy(CDisplay::PlainText, CDisplay::AnchorOnly);
  61. }
  62. void CDisplayConnections::copyAnchorTextOnly() {
  63. m_display->copy(CDisplay::PlainText, CDisplay::AnchorTextOnly);
  64. }
  65. void CDisplayConnections::copyAnchorWithText() {
  66. m_display->copy(CDisplay::PlainText, CDisplay::AnchorWithText);
  67. }
  68. void CDisplayConnections::saveAnchorWithText() {
  69. m_display->save(CDisplay::PlainText, CDisplay::AnchorWithText);
  70. }
  71. void CDisplayConnections::clear() {
  72. m_display->setText(TQString());
  73. }
  74. void CDisplayConnections::zoomIn() {
  75. m_display->zoomIn();
  76. }
  77. void CDisplayConnections::zoomOut() {
  78. m_display->zoomOut();
  79. }
  80. void CDisplayConnections::openFindTextDialog() {
  81. m_display->openFindTextDialog();
  82. }
  83. /*----------------------*/
  84. CReadDisplay* CDisplay::createReadInstance( CReadWindow* readWindow, TQWidget* parent ) {
  85. return new CHTMLReadDisplay(readWindow, parent);
  86. }
  87. CWriteDisplay* CDisplay::createWriteInstance( CWriteWindow* writeWindow, const CWriteDisplay::WriteDisplayType& type, TQWidget* parent ) {
  88. // tqWarning("CDisplay::createWriteInstance");
  89. if (type == PlainTextDisplay) {
  90. return new CPlainWriteDisplay(writeWindow, parent);
  91. }
  92. else {
  93. return new CHTMLWriteDisplay(writeWindow, parent);
  94. };
  95. }
  96. CDisplay::CDisplay(CDisplayWindow* parent) :
  97. m_parentWindow(parent),
  98. m_connections( new CDisplayConnections( this ) ),
  99. m_popup(0) {}
  100. CDisplay::~CDisplay() {
  101. delete m_connections;
  102. }
  103. const bool CDisplay::copy( const CDisplay::TextType format, const CDisplay::TextPart part ) {
  104. const TQString content = text(format, part);
  105. TQClipboard* cb = TDEApplication::clipboard();
  106. cb->setText(content);
  107. return true;
  108. }
  109. const bool CDisplay::save( const CDisplay::TextType format, const CDisplay::TextPart part ) {
  110. // tqWarning("CDisplay::save( const CDisplay::TextType format, const CDisplay::TextPart part )");
  111. const TQString content = text(format, part);
  112. TQString filter = TQString();
  113. switch (format) {
  114. case HTMLText:
  115. filter = TQString("*.html *.htm | ") + i18n("HTML files") + TQString("\n *.* | All files (*.*)");
  116. break;
  117. case PlainText:
  118. filter = TQString("*.txt | ") + i18n("Text files") + TQString("\n *.* | All files (*.*)");
  119. break;
  120. };
  121. const TQString filename = KFileDialog::getSaveFileName(TQString(), filter, 0, i18n("Save document ..."));
  122. if (!filename.isEmpty()) {
  123. CToolClass::savePlainFile(filename, content);
  124. }
  125. return true;
  126. }
  127. /** Emits the signal which used when a reference was clicked. */
  128. void CDisplay::emitReferenceClicked( const TQString& reference ) {
  129. tqWarning("reference clicked %s", reference.latin1());
  130. TQString module;
  131. TQString key;
  132. CReferenceManager::Type type;
  133. /*const bool ok = */
  134. CReferenceManager::decodeHyperlink(reference, module, key, type);
  135. if (module.isEmpty()) {
  136. module = CReferenceManager::preferredModule( type );
  137. }
  138. m_connections->emitReferenceClicked(module, key);
  139. }
  140. /** Used when a reference was dropped onto the widget. */
  141. void CDisplay::emitReferenceDropped( const TQString& reference ) {
  142. TQString module;
  143. TQString key;
  144. CReferenceManager::Type type;
  145. /*const bool ok = */
  146. CReferenceManager::decodeHyperlink(reference, module, key, type);
  147. // if (module.isEmpty()) {
  148. // module = CReferenceManager::preferredModule( type );
  149. // }
  150. m_connections->emitReferenceDropped(key);
  151. }
  152. /** Returns the connections obect used for signas and slots. */
  153. CDisplayConnections* const CDisplay::connectionsProxy() const {
  154. return m_connections;
  155. }
  156. CDisplayWindow* const CDisplay::parentWindow() const {
  157. return m_parentWindow;
  158. }
  159. /** Installs the popup which should be opened when the right mouse button was pressed. */
  160. void CDisplay::installPopup( TQPopupMenu* popup ) {
  161. m_popup = popup;
  162. }
  163. /** Returns the popup menu which was set by installPopupMenu() */
  164. TQPopupMenu* const CDisplay::installedPopup() {
  165. Q_ASSERT(m_popup);
  166. return m_popup;
  167. }
  168. #include "cdisplay.moc"