KOffice – TDE office suite
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.

kexireportfactory.cpp 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* This file is part of the KDE project
  2. Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public License
  12. along with this library; see the file COPYING.LIB. If not, write to
  13. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  14. * Boston, MA 02110-1301, USA.
  15. */
  16. #include <tqpopupmenu.h>
  17. #include <tqvaluevector.h>
  18. #include <kgenericfactory.h>
  19. #include <tdelocale.h>
  20. #include <kiconloader.h>
  21. #include <kdebug.h>
  22. #include <klineedit.h>
  23. #include <container.h>
  24. #include <form.h>
  25. #include <formmanager.h>
  26. #include <widgetlibrary.h>
  27. #include "reportwidgets.h"
  28. #include "kexireportfactory.h"
  29. KexiReportFactory::KexiReportFactory(TQObject *parent, const char *name, const TQStringList &)
  30. : KFormDesigner::WidgetFactory(parent, name)
  31. {
  32. KFormDesigner::WidgetInfo *wView = new KFormDesigner::WidgetInfo(this);
  33. wView->setPixmap("report");
  34. wView->setClassName("KexiReportForm");
  35. wView->setName(i18n("Report"));
  36. wView->setNamePrefix(
  37. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "report"));
  38. wView->setDescription(i18n("A report"));
  39. addClass(wView);
  40. KFormDesigner::WidgetInfo *wLabel = new KFormDesigner::WidgetInfo(this);
  41. wLabel->setPixmap("label");
  42. wLabel->setClassName("Label");
  43. wLabel->setName(i18n("Label"));
  44. wLabel->setNamePrefix(
  45. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "label"));
  46. wLabel->setDescription(i18n("A label to display text"));
  47. addClass(wLabel);
  48. KFormDesigner::WidgetInfo *wPicLabel = new KFormDesigner::WidgetInfo(this);
  49. wPicLabel->setPixmap("pixmaplabel");
  50. wPicLabel->setClassName("PicLabel");
  51. wPicLabel->setName(i18n("Picture Label"));
  52. wPicLabel->setNamePrefix(
  53. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "picture"));
  54. wPicLabel->setDescription(i18n("A label to display images or icons"));
  55. addClass(wPicLabel);
  56. KFormDesigner::WidgetInfo *wLine = new KFormDesigner::WidgetInfo(this);
  57. wLine->setPixmap("line");
  58. wLine->setClassName("ReportLine");
  59. wLine->setName(i18n("Line"));
  60. wLine->setNamePrefix(
  61. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "line"));
  62. wLine->setDescription(i18n("A simple line"));
  63. addClass(wLine);
  64. KFormDesigner::WidgetInfo *wSubReport = new KFormDesigner::WidgetInfo(this);
  65. wSubReport->setPixmap("report");
  66. wSubReport->setClassName("KexiSubReport");
  67. wSubReport->setName(i18n("Sub Report"));
  68. wSubReport->setNamePrefix(
  69. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "subReport"));
  70. wSubReport->setDescription(i18n("A report embedded in another report"));
  71. addClass(wSubReport);
  72. }
  73. KexiReportFactory::~KexiReportFactory()
  74. {
  75. }
  76. TQString
  77. KexiReportFactory::name()
  78. {
  79. return "kexireportwidgets";
  80. }
  81. TQWidget*
  82. KexiReportFactory::createWidget(const TQCString &c, TQWidget *p, const char *n,
  83. KFormDesigner::Container *container, int options)
  84. {
  85. Q_UNUSED(options);
  86. kexipluginsdbg << "KexiReportFactory::create() " << this << endl;
  87. TQString text( container->form()->library()->textForWidgetName(n, c) );
  88. if(c == "Label")
  89. return new Label(text, p, n);
  90. else if(c == "PicLabel")
  91. return new PicLabel(DesktopIcon("image-x-generic"), p, n);
  92. else if(c == "ReportLine")
  93. return new ReportLine(p, n);
  94. else if(c == "KexiSubReport")
  95. return new KexiSubReport(p, n);
  96. return 0;
  97. }
  98. bool
  99. KexiReportFactory::createMenuActions(const TQCString &classname, TQWidget *w,
  100. TQPopupMenu *menu, KFormDesigner::Container *container)
  101. {
  102. Q_UNUSED(w);
  103. Q_UNUSED(container);
  104. if(classname == "Label") {
  105. /*! @todo use TDEAction */
  106. menu->insertItem(SmallIconSet("edit"), i18n("Edit Rich Text"), this, TQT_SLOT(editText()));
  107. return true;
  108. }
  109. return false;
  110. }
  111. bool
  112. KexiReportFactory::startEditing(const TQCString &c, TQWidget *w, KFormDesigner::Container *container)
  113. {
  114. m_container = container;
  115. if(c == "Label") {
  116. TQLabel *label = static_cast<TQLabel*>(w);
  117. if(label->textFormat() == RichText) {
  118. m_widget = w;
  119. editText();
  120. }
  121. else
  122. createEditor(c, label->text(), label, container, label->geometry(), label->alignment());
  123. return true;
  124. }
  125. return false;
  126. }
  127. bool
  128. KexiReportFactory::isPropertyVisibleInternal(const TQCString &classname, TQWidget *w, const TQCString &property, bool isTopLevel)
  129. {
  130. if(classname == "Label") {
  131. if(property == "pixmap")
  132. return false;
  133. }
  134. else if(classname == "PicLabel") {
  135. if((property == "text") || (property == "indent") || (property == "textFormat") || (property == "font") || (property == "alignment"))
  136. return false;
  137. }
  138. return WidgetFactory::isPropertyVisibleInternal(classname, w, property, isTopLevel);
  139. }
  140. TQValueList<TQCString>
  141. KexiReportFactory::autoSaveProperties(const TQCString &classname)
  142. {
  143. TQValueList<TQCString> l;
  144. if(classname == "Label")
  145. l << "text";
  146. else if(classname == "PicLabel")
  147. l << "pixmap";
  148. return l;
  149. }
  150. /*
  151. void
  152. KexiReportFactory::changeText(const TQString &text)
  153. {
  154. TQWidget *w = WidgetFactory::m_widget;
  155. changeProperty("text", text, m_container);
  156. int width = w->sizeHint().width();
  157. if(w->width() < width)
  158. w->resize(width, w->height() );
  159. }
  160. void
  161. KexiReportFactory::resizeEditor(TQWidget *widget, const TQCString &)
  162. {
  163. TQSize s = widget->size();
  164. TQPoint p = widget->pos();
  165. TQRect r;
  166. m_editor->resize(s);
  167. m_editor->move(p);
  168. }*/
  169. void
  170. KexiReportFactory::editText()
  171. {
  172. TQCString classname = m_widget->className();
  173. TQString text;
  174. if(classname == "Label")
  175. text = ((TQLabel*)m_widget)->text();
  176. if(editRichText(m_widget, text)) {
  177. changeProperty("textFormat", "RichText", m_container->form());
  178. changeProperty("text", text, m_container->form());
  179. }
  180. if(classname == "Label")
  181. m_widget->resize(m_widget->sizeHint());
  182. }
  183. bool
  184. KexiReportFactory::previewWidget(const TQCString &, TQWidget *, KFormDesigner::Container *)
  185. {
  186. return false;
  187. }
  188. KFORMDESIGNER_WIDGET_FACTORY(KexiReportFactory, kexireportwidgets)
  189. #include "kexireportfactory.moc"