bibletime
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.

chtmlwritedisplay.cpp 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 "chtmlwritedisplay.h"
  10. #include "frontend/displaywindow/cwritewindow.h"
  11. #include "util/cresmgr.h"
  12. //TQt includes
  13. #include <tqpopupmenu.h>
  14. #include <tqtooltip.h>
  15. //KDE includes
  16. #include <kaction.h>
  17. #include <ktoolbar.h>
  18. #include <klocale.h>
  19. #include <kfontcombo.h>
  20. #include <kcolorbutton.h>
  21. #include <kpopupmenu.h>
  22. CHTMLWriteDisplay::CHTMLWriteDisplay(CWriteWindow* parentWindow, TQWidget* parent)
  23. : CPlainWriteDisplay(parentWindow,parent) {
  24. m_actions.bold = 0;
  25. m_actions.italic = 0;
  26. m_actions.underline = 0;
  27. m_actions.selectAll = 0;
  28. setTextFormat(TQt::RichText);
  29. setAcceptDrops(true);
  30. viewport()->setAcceptDrops(true);
  31. }
  32. CHTMLWriteDisplay::~CHTMLWriteDisplay() {}
  33. void CHTMLWriteDisplay::setText( const TQString& newText ) {
  34. TQString text = newText;
  35. // text.replace("\n<br/><!-- BT newline -->\n", "\n");
  36. TQTextEdit::setText(text);
  37. }
  38. const TQString CHTMLWriteDisplay::plainText() {
  39. return TQTextEdit::text();
  40. };
  41. void CHTMLWriteDisplay::toggleBold() {
  42. setBold( m_actions.bold->isChecked() );
  43. };
  44. void CHTMLWriteDisplay::toggleItalic() {
  45. setItalic( m_actions.italic->isChecked() );
  46. };
  47. void CHTMLWriteDisplay::toggleUnderline() {
  48. setUnderline( m_actions.underline->isChecked() );
  49. };
  50. void CHTMLWriteDisplay::alignLeft() {
  51. setAlignment(TQt::AlignLeft);
  52. };
  53. void CHTMLWriteDisplay::alignCenter() {
  54. setAlignment(TQt::AlignHCenter);
  55. };
  56. void CHTMLWriteDisplay::alignRight() {
  57. setAlignment(TQt::AlignRight);
  58. };
  59. /** The text's alignment changed. Enable the right buttons. */
  60. void CHTMLWriteDisplay::slotAlignmentChanged( int a ) {
  61. bool alignLeft = false;
  62. bool alignCenter = false;
  63. bool alignRight = false;
  64. // bool alignJustify = false;
  65. if (a & TQt::AlignLeft) {
  66. alignLeft = true;
  67. }
  68. else if ((a & TQt::AlignHCenter) || (a & TQt::AlignCenter)) {
  69. alignCenter = true;
  70. }
  71. else if (a & TQt::AlignRight) {
  72. alignRight = true;
  73. }
  74. // else if (a & TQt::AlignJustify) {
  75. // alignJustify = true;
  76. // }
  77. else {
  78. alignLeft = true;
  79. tqWarning("unknown alignment %i", a);
  80. }
  81. m_actions.alignLeft->setChecked( alignLeft );
  82. m_actions.alignCenter->setChecked( alignCenter );
  83. m_actions.alignRight->setChecked( alignRight );
  84. // m_actions.alignJustify->setChecked( alignJustify );
  85. }
  86. /** Is called when a new color was selected. */
  87. void CHTMLWriteDisplay::slotColorSelected( const TQColor& c) {
  88. setColor( c );
  89. }
  90. /** Is called when a text with another color was selected. */
  91. void CHTMLWriteDisplay::slotColorChanged(const TQColor& c) {
  92. m_colorButton->setColor(c);
  93. }
  94. void CHTMLWriteDisplay::slotFontChanged( const TQFont& font ) {
  95. m_actions.fontChooser->setFont( font.family() );
  96. m_actions.fontSizeChooser->setFontSize( font.pointSize() );
  97. m_actions.bold->setChecked( font.bold() );
  98. m_actions.italic->setChecked( font.italic() );
  99. m_actions.underline->setChecked( font.underline() );
  100. };
  101. void CHTMLWriteDisplay::setupToolbar(TDEToolBar * bar, TDEActionCollection * actions) {
  102. m_actions.fontChooser = new TDEFontAction( i18n("Choose a font"),
  103. CResMgr::displaywindows::writeWindow::underlinedText::accel,
  104. actions,
  105. CResMgr::displaywindows::writeWindow::fontFamily::actionName
  106. );
  107. m_actions.fontChooser->setToolTip( CResMgr::displaywindows::writeWindow::fontFamily::tooltip );
  108. m_actions.fontChooser->plug(bar);
  109. connect(m_actions.fontChooser, TQT_SIGNAL(activated(const TQString&)), TQT_TQOBJECT(this), TQT_SLOT(setFamily(const TQString&)));
  110. m_actions.fontSizeChooser = new TDEFontSizeAction( i18n("Choose a font size"),
  111. CResMgr::displaywindows::writeWindow::fontSize::accel,
  112. actions,
  113. CResMgr::displaywindows::writeWindow::fontSize::actionName
  114. );
  115. m_actions.fontSizeChooser->setToolTip( CResMgr::displaywindows::writeWindow::fontSize::tooltip );
  116. m_actions.fontSizeChooser->plug(bar);
  117. connect(m_actions.fontSizeChooser, TQT_SIGNAL(fontSizeChanged(int)), TQT_TQOBJECT(this), TQT_SLOT(setPointSize(int)));
  118. m_colorButton = new KColorButton(bar);
  119. connect(m_colorButton, TQT_SIGNAL(changed(const TQColor&)), TQT_TQOBJECT(this), TQT_SLOT(slotColorSelected(const TQColor&)));
  120. bar->insertWidget(50, m_colorButton->sizeHint().width(), m_colorButton);
  121. TQToolTip::add
  122. (m_colorButton, CResMgr::displaywindows::writeWindow::fontColor::tooltip );
  123. (new TDEActionSeparator())->plug(bar); //seperate font options from formatting buttons
  124. m_actions.bold = new TDEToggleAction( i18n("Bold"),
  125. CResMgr::displaywindows::writeWindow::boldText::icon,
  126. CResMgr::displaywindows::writeWindow::boldText::accel,
  127. TQT_TQOBJECT(this), TQT_SLOT(toggleBold()),
  128. actions,
  129. CResMgr::displaywindows::writeWindow::boldText::actionName
  130. );
  131. m_actions.bold->setToolTip( CResMgr::displaywindows::writeWindow::boldText::tooltip );
  132. m_actions.bold->plug(bar);
  133. m_actions.italic = new TDEToggleAction( i18n("Italic"),
  134. CResMgr::displaywindows::writeWindow::italicText::icon,
  135. CResMgr::displaywindows::writeWindow::italicText::accel,
  136. TQT_TQOBJECT(this), TQT_SLOT(toggleItalic()),
  137. actions,
  138. CResMgr::displaywindows::writeWindow::italicText::actionName
  139. );
  140. m_actions.italic->setToolTip( CResMgr::displaywindows::writeWindow::italicText::tooltip );
  141. m_actions.italic->plug(bar);
  142. m_actions.underline = new TDEToggleAction( i18n("Underline"),
  143. CResMgr::displaywindows::writeWindow::underlinedText::icon,
  144. CResMgr::displaywindows::writeWindow::underlinedText::accel,
  145. TQT_TQOBJECT(this), TQT_SLOT(toggleUnderline()),
  146. actions,
  147. CResMgr::displaywindows::writeWindow::underlinedText::actionName
  148. );
  149. m_actions.underline->setToolTip( CResMgr::displaywindows::writeWindow::underlinedText::tooltip );
  150. m_actions.underline->plug(bar);
  151. (new TDEActionSeparator())->plug(bar); //seperate formatting from alignment buttons
  152. m_actions.alignLeft = new TDEToggleAction( i18n("Left"),
  153. CResMgr::displaywindows::writeWindow::alignLeft::icon,
  154. CResMgr::displaywindows::writeWindow::alignLeft::accel,
  155. TQT_TQOBJECT(this), TQT_SLOT( alignLeft() ),
  156. actions,
  157. CResMgr::displaywindows::writeWindow::alignLeft::actionName
  158. );
  159. m_actions.alignLeft->setToolTip( CResMgr::displaywindows::writeWindow::alignLeft::tooltip );
  160. m_actions.alignLeft->plug(bar);
  161. m_actions.alignCenter = new TDEToggleAction( i18n("Center"),
  162. CResMgr::displaywindows::writeWindow::alignCenter::icon,
  163. CResMgr::displaywindows::writeWindow::alignCenter::accel,
  164. TQT_TQOBJECT(this), TQT_SLOT(alignCenter()),
  165. actions,
  166. CResMgr::displaywindows::writeWindow::alignCenter::actionName
  167. );
  168. m_actions.alignCenter->setToolTip( CResMgr::displaywindows::writeWindow::alignCenter::tooltip );
  169. m_actions.alignCenter->plug(bar);
  170. m_actions.alignRight = new TDEToggleAction( i18n("Right"),
  171. CResMgr::displaywindows::writeWindow::alignRight::icon,
  172. CResMgr::displaywindows::writeWindow::alignRight::accel,
  173. TQT_TQOBJECT(this), TQT_SLOT(alignRight()),
  174. actions,
  175. CResMgr::displaywindows::writeWindow::alignRight::actionName
  176. );
  177. m_actions.alignRight->setToolTip( CResMgr::displaywindows::writeWindow::alignRight::tooltip );
  178. m_actions.alignRight->plug(bar);
  179. // m_actions.alignJustify = new TDEToggleAction( i18n("Justify"),
  180. // CResMgr::displaywindows::writeWindow::alignJustify::icon,
  181. // CResMgr::displaywindows::writeWindow::alignJustify::accel,
  182. // this, TQT_SLOT( alignJustify() ),
  183. // actions
  184. // );
  185. // m_actions.alignJustify->setToolTip( CResMgr::displaywindows::writeWindow::alignJustify::tooltip );
  186. // m_actions.alignJustify->plug(bar);
  187. connect(this, TQT_SIGNAL(currentFontChanged(const TQFont&)), TQT_SLOT(slotFontChanged(const TQFont&)));
  188. connect(this, TQT_SIGNAL(currentAlignmentChanged(int)), TQT_SLOT(slotAlignmentChanged(int)));
  189. connect(this, TQT_SIGNAL(currentColorChanged(const TQColor&)), TQT_SLOT(slotColorChanged(const TQColor&)));
  190. //set initial values for toolbar items
  191. slotFontChanged( font() );
  192. slotAlignmentChanged( alignment() );
  193. slotColorChanged( color() );
  194. }
  195. /** Reimplementation to show a popup menu if the right mouse butoon was clicked. */
  196. TQPopupMenu* CHTMLWriteDisplay::createPopupMenu( const TQPoint& /*pos*/ ) {
  197. if (!m_actions.selectAll) {
  198. m_actions.selectAll = new TDEAction(i18n("Select all"), TDEShortcut(0), TQT_TQOBJECT(this), TQT_SLOT(selectAll()), TQT_TQOBJECT(this));
  199. }
  200. TDEPopupMenu* popup = new TDEPopupMenu(this);
  201. popup->insertTitle(i18n("HTML editor window"));
  202. m_actions.selectAll->plug(popup);
  203. return popup;
  204. };