KOffice – TDE office suite
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

stdwidgetfactory.cpp 34KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984
  1. /***************************************************************************
  2. * Copyright (C) 2003 by Lucijan Busch <lucijan@kde.org> *
  3. * Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr> *
  4. * This program is free software; you can redistribute it and/or modify *
  5. * it under the terms of the GNU Library General Public License as *
  6. * published by the Free Software Foundation; either version 2 of the *
  7. * License, or (at your option) any later version. *
  8. ***************************************************************************/
  9. #include <tqlabel.h>
  10. #include <tqpopupmenu.h>
  11. #include <tqcursor.h>
  12. #include <tqradiobutton.h>
  13. #include <tqcheckbox.h>
  14. #include <tqslider.h>
  15. #include <tqobjectlist.h>
  16. #include <tqstring.h>
  17. #include <tqvariant.h>
  18. #include <tqheader.h>
  19. #include <tqdom.h>
  20. #include <tqstyle.h>
  21. #include <tqvaluevector.h>
  22. #include <klineedit.h>
  23. #include <kpushbutton.h>
  24. #include <knuminput.h>
  25. #include <kcombobox.h>
  26. #include <tdelistbox.h>
  27. #include <ktextedit.h>
  28. #include <tdelistview.h>
  29. #include <kprogress.h>
  30. #include <kiconloader.h>
  31. #include <kgenericfactory.h>
  32. #include <tdelocale.h>
  33. #include <kdebug.h>
  34. #include <tdeversion.h>
  35. #if TDE_VERSION < TDE_MAKE_VERSION(3,1,9)
  36. # include <tqdatetimeedit.h>
  37. # define KTimeWidget TQTimeEdit
  38. # define KDateWidget TQDateEdit
  39. # define KDateTimeWidget TQDateTimeEdit
  40. #else
  41. # include <ktimewidget.h>
  42. # include <kdatewidget.h>
  43. # include <kdatetimewidget.h>
  44. #endif
  45. #include "spring.h"
  46. #include "formIO.h"
  47. #include "form.h"
  48. #include "formmanager.h"
  49. #include "widgetlibrary.h"
  50. #include "widgetpropertyset.h"
  51. #include <koproperty/property.h>
  52. #include "stdwidgetfactory.h"
  53. // Some widgets subclass to allow event filtering and some other things
  54. KexiPictureLabel::KexiPictureLabel(const TQPixmap &pix, TQWidget *parent, const char *name)
  55. : TQLabel(parent, name)
  56. {
  57. setPixmap(pix);
  58. setScaledContents(false);
  59. }
  60. bool
  61. KexiPictureLabel::setProperty(const char *name, const TQVariant &value)
  62. {
  63. if(TQString(name) == "pixmap")
  64. resize(value.toPixmap().height(), value.toPixmap().width());
  65. return TQLabel::setProperty(name, value);
  66. }
  67. Line::Line(Qt::Orientation orient, TQWidget *parent, const char *name)
  68. : TQFrame(parent, name)
  69. {
  70. setFrameShadow(Sunken);
  71. if(orient ==Qt::Horizontal)
  72. setFrameShape(HLine);
  73. else
  74. setFrameShape(VLine);
  75. }
  76. void
  77. Line::setOrientation(Qt::Orientation orient)
  78. {
  79. if(orient ==Qt::Horizontal)
  80. setFrameShape(HLine);
  81. else
  82. setFrameShape(VLine);
  83. }
  84. Qt::Orientation
  85. Line::orientation() const
  86. {
  87. if(frameShape() == HLine)
  88. return Qt::Horizontal;
  89. else
  90. return Qt::Vertical;
  91. }
  92. // The factory itself
  93. StdWidgetFactory::StdWidgetFactory(TQObject *parent, const char *, const TQStringList &)
  94. : KFormDesigner::WidgetFactory(parent, "stdwidgets")
  95. {
  96. KFormDesigner::WidgetInfo *wFormWidget = new KFormDesigner::WidgetInfo(this);
  97. wFormWidget->setPixmap("form");
  98. wFormWidget->setClassName("FormWidgetBase");
  99. wFormWidget->setName(i18n("Form"));
  100. wFormWidget->setNamePrefix(i18n("This string will be used to name widgets of this class. It must _not_ contain white "
  101. "spaces and non latin1 characters.", "form"));
  102. wFormWidget->setDescription(i18n("A simple form widget"));
  103. addClass(wFormWidget);
  104. KFormDesigner::WidgetInfo *wCustomWidget = new KFormDesigner::WidgetInfo(this);
  105. wCustomWidget->setPixmap("unknown_widget");
  106. wCustomWidget->setClassName("CustomWidget");
  107. wCustomWidget->setName(i18n("Custom Widget"));
  108. wCustomWidget->setNamePrefix(i18n("This string will be used to name widgets of this class. It must _not_ contain white "
  109. "spaces and non latin1 characters.", "customWidget"));
  110. wCustomWidget->setDescription(i18n("A custom or non-supported widget"));
  111. addClass(wCustomWidget);
  112. KFormDesigner::WidgetInfo *wLabel = new KFormDesigner::WidgetInfo(this);
  113. wLabel->setPixmap("label");
  114. wLabel->setClassName(TQLABEL_OBJECT_NAME_STRING);
  115. wLabel->setName(i18n("Text Label"));
  116. wLabel->setNamePrefix(
  117. 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"));
  118. wLabel->setDescription(i18n("A widget to display text"));
  119. addClass(wLabel);
  120. KFormDesigner::WidgetInfo *wPixLabel = new KFormDesigner::WidgetInfo(this);
  121. wPixLabel->setPixmap("pixmaplabel");
  122. wPixLabel->setClassName("KexiPictureLabel");
  123. wPixLabel->setName(i18n("Picture Label"));
  124. //! @todo TQt designer compatibility: maybe use this class when TQLabel has a pixmap set...?
  125. //wPixLabel->addAlternateClassName(TQLABEL_OBJECT_NAME_STRING);
  126. wPixLabel->setSavingName("KexiPictureLabel");
  127. wPixLabel->setNamePrefix(
  128. 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"));
  129. wPixLabel->setDescription(i18n("A widget to display pictures"));
  130. addClass(wPixLabel);
  131. KFormDesigner::WidgetInfo *wLineEdit = new KFormDesigner::WidgetInfo(this);
  132. wLineEdit->setPixmap("lineedit");
  133. wLineEdit->setClassName("KLineEdit");
  134. wLineEdit->addAlternateClassName(TQLINEEDIT_OBJECT_NAME_STRING);
  135. wLineEdit->setIncludeFileName("klineedit.h");
  136. wLineEdit->setName(i18n("Line Edit"));
  137. wLineEdit->setNamePrefix(
  138. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "lineEdit"));
  139. wLineEdit->setDescription(i18n("A widget to input text"));
  140. addClass(wLineEdit);
  141. KFormDesigner::WidgetInfo *wSpring = new KFormDesigner::WidgetInfo(this);
  142. wSpring->setPixmap("spring");
  143. wSpring->setClassName("Spring");
  144. wSpring->setName(i18n("Spring"));
  145. wSpring->setNamePrefix(
  146. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "spring"));
  147. wSpring->setDescription(i18n("A spring to place between widgets"));
  148. addClass(wSpring);
  149. KFormDesigner::WidgetInfo *wPushButton = new KFormDesigner::WidgetInfo(this);
  150. wPushButton->setPixmap("button");
  151. wPushButton->setClassName("KPushButton");
  152. wPushButton->addAlternateClassName(TQPUSHBUTTON_OBJECT_NAME_STRING);
  153. wPushButton->setIncludeFileName("kpushbutton.h");
  154. wPushButton->setName(i18n("Push Button"));
  155. wPushButton->setNamePrefix(
  156. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "button"));
  157. wPushButton->setDescription(i18n("A simple push button to execute actions"));
  158. addClass(wPushButton);
  159. KFormDesigner::WidgetInfo *wRadioButton = new KFormDesigner::WidgetInfo(this);
  160. wRadioButton->setPixmap("radio");
  161. wRadioButton->setClassName(TQRADIOBUTTON_OBJECT_NAME_STRING);
  162. wRadioButton->setName(i18n("Option Button"));
  163. wRadioButton->setNamePrefix(
  164. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "optionButton"));
  165. wRadioButton->setDescription(i18n("An option button with text or pixmap label"));
  166. addClass(wRadioButton);
  167. KFormDesigner::WidgetInfo *wCheckBox = new KFormDesigner::WidgetInfo(this);
  168. wCheckBox->setPixmap("check");
  169. wCheckBox->setClassName(TQCHECKBOX_OBJECT_NAME_STRING);
  170. wCheckBox->setName(i18n("Check Box"));
  171. wCheckBox->setNamePrefix(
  172. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "checkBox"));
  173. wCheckBox->setDescription(i18n("A check box with text or pixmap label"));
  174. addClass(wCheckBox);
  175. KFormDesigner::WidgetInfo *wSpinBox = new KFormDesigner::WidgetInfo(this);
  176. wSpinBox->setPixmap("spin");
  177. wSpinBox->setClassName("KIntSpinBox");
  178. wSpinBox->addAlternateClassName(TQSPINBOX_OBJECT_NAME_STRING);
  179. wSpinBox->setIncludeFileName("knuminput.h");
  180. wSpinBox->setName(i18n("Spin Box"));
  181. wSpinBox->setNamePrefix(
  182. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "spinBox"));
  183. wSpinBox->setDescription(i18n("A spin box widget"));
  184. addClass(wSpinBox);
  185. KFormDesigner::WidgetInfo *wComboBox = new KFormDesigner::WidgetInfo(this);
  186. wComboBox->setPixmap("combo");
  187. wComboBox->setClassName("KComboBox");
  188. wComboBox->addAlternateClassName(TQCOMBOBOX_OBJECT_NAME_STRING);
  189. wComboBox->setIncludeFileName("kcombobox.h");
  190. wComboBox->setName(i18n("Combo Box"));
  191. wComboBox->setNamePrefix(
  192. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "comboBox"));
  193. wComboBox->setDescription(i18n("A combo box widget"));
  194. addClass(wComboBox);
  195. KFormDesigner::WidgetInfo *wListBox = new KFormDesigner::WidgetInfo(this);
  196. wListBox->setPixmap("listbox");
  197. wListBox->setClassName("TDEListBox");
  198. wListBox->addAlternateClassName(TQLISTBOX_OBJECT_NAME_STRING);
  199. wListBox->setIncludeFileName("tdelistbox.h");
  200. wListBox->setName(i18n("List Box"));
  201. wListBox->setNamePrefix(
  202. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "listBox"));
  203. wListBox->setDescription(i18n("A simple list widget"));
  204. addClass(wListBox);
  205. KFormDesigner::WidgetInfo *wTextEdit = new KFormDesigner::WidgetInfo(this);
  206. wTextEdit->setPixmap("textedit");
  207. wTextEdit->setClassName("KTextEdit");
  208. wTextEdit->addAlternateClassName(TQTEXTEDIT_OBJECT_NAME_STRING);
  209. wTextEdit->setIncludeFileName("ktextedit.h");
  210. wTextEdit->setName(i18n("Text Editor"));
  211. wTextEdit->setNamePrefix(
  212. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "textEditor"));
  213. wTextEdit->setDescription(i18n("A simple single-page rich text editor"));
  214. addClass(wTextEdit);
  215. KFormDesigner::WidgetInfo *wListView = new KFormDesigner::WidgetInfo(this);
  216. wListView->setPixmap("listview");
  217. wListView->setClassName("TDEListView");
  218. wListView->addAlternateClassName(TQLISTVIEW_OBJECT_NAME_STRING);
  219. wListView->setIncludeFileName("tdelistview.h");
  220. wListView->setName(i18n("List View"));
  221. wListView->setNamePrefix(
  222. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "listView"));
  223. wListView->setDescription(i18n("A list (or tree) widget"));
  224. addClass(wListView);
  225. KFormDesigner::WidgetInfo *wSlider = new KFormDesigner::WidgetInfo(this);
  226. wSlider->setPixmap("slider");
  227. wSlider->setClassName(TQSLIDER_OBJECT_NAME_STRING);
  228. wSlider->setName(i18n("Slider"));
  229. wSlider->setNamePrefix(
  230. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "slider"));
  231. wSlider->setDescription(i18n("An horizontal slider"));
  232. addClass(wSlider);
  233. KFormDesigner::WidgetInfo *wProgressBar = new KFormDesigner::WidgetInfo(this);
  234. wProgressBar->setPixmap("progress");
  235. wProgressBar->setClassName("KProgress");
  236. wProgressBar->addAlternateClassName(TQPROGRESSBAR_OBJECT_NAME_STRING);
  237. wProgressBar->setIncludeFileName("kprogress.h");
  238. wProgressBar->setName(i18n("Progress Bar"));
  239. wProgressBar->setNamePrefix(
  240. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "progressBar"));
  241. wProgressBar->setDescription(i18n("A progress indicator widget"));
  242. addClass(wProgressBar);
  243. KFormDesigner::WidgetInfo *wLine = new KFormDesigner::WidgetInfo(this);
  244. wLine->setPixmap("line");
  245. wLine->setClassName("Line");
  246. wLine->setName(i18n("Line"));
  247. wLine->setNamePrefix(
  248. 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"));
  249. wLine->setDescription(i18n("A line to be used as a separator"));
  250. addClass(wLine);
  251. KFormDesigner::WidgetInfo *wDate = new KFormDesigner::WidgetInfo(this);
  252. wDate->setPixmap("dateedit");
  253. wDate->setClassName("KDateWidget");
  254. #if TDE_VERSION >= TDE_MAKE_VERSION(3,1,9)
  255. wDate->addAlternateClassName(TQDATEEDIT_OBJECT_NAME_STRING);
  256. wDate->setIncludeFileName("kdatewidget.h");
  257. #endif
  258. wDate->setName(i18n("Date Widget"));
  259. wDate->setNamePrefix(
  260. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "dateWidget"));
  261. wDate->setDescription(i18n("A widget to input and display a date"));
  262. addClass(wDate);
  263. KFormDesigner::WidgetInfo *wTime = new KFormDesigner::WidgetInfo(this);
  264. wTime->setPixmap("timeedit");
  265. wTime->setClassName("KTimeWidget");
  266. #if TDE_VERSION >= TDE_MAKE_VERSION(3,1,9)
  267. wTime->addAlternateClassName(TQTIMEEDIT_OBJECT_NAME_STRING);
  268. wTime->setIncludeFileName("ktimewidget.h");
  269. #endif
  270. wTime->setName(i18n("Time Widget"));
  271. wTime->setNamePrefix(
  272. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "timeWidget"));
  273. wTime->setDescription(i18n("A widget to input and display a time"));
  274. addClass(wTime);
  275. KFormDesigner::WidgetInfo *wDateTime = new KFormDesigner::WidgetInfo(this);
  276. wDateTime->setPixmap("datetimeedit");
  277. wDateTime->setClassName("KDateTimeWidget");
  278. #if TDE_VERSION >= TDE_MAKE_VERSION(3,1,9)
  279. wDateTime->addAlternateClassName(TQDATETIMEEDIT_OBJECT_NAME_STRING);
  280. wDateTime->setIncludeFileName("kdatetimewidget.h");
  281. #endif
  282. wDateTime->setName(i18n("Date/Time Widget"));
  283. wDateTime->setNamePrefix(
  284. i18n("Widget name. This string will be used to name widgets of this class. It must _not_ contain white spaces and non latin1 characters.", "dateTimeWidget"));
  285. wDateTime->setDescription(i18n("A widget to input and display a time and a date"));
  286. addClass(wDateTime);
  287. m_propDesc["toggleButton"] = i18n("Toggle");
  288. m_propDesc["autoRepeat"] = i18n("Auto Repeat");
  289. m_propDesc["autoDefault"] = i18n("Auto Default");
  290. m_propDesc["default"] = i18n("Default");
  291. m_propDesc["flat"] = i18n("Flat");
  292. m_propDesc["echoMode"] =
  293. i18n("Echo mode for Line Edit widget eg. Normal, NoEcho, Password","Echo Mode");
  294. m_propDesc["indent"] = i18n("Indent");
  295. //line
  296. m_propDesc["orientation"] = i18n("Orientation");
  297. //checkbox
  298. m_propDesc["checked"] = i18n("Checked checkbox", "Checked");
  299. m_propDesc["tristate"] = i18n("Tristate checkbox", "Tristate");
  300. //for EchoMode
  301. m_propValDesc["Normal"] = i18n("For Echo Mode", "Normal");
  302. m_propValDesc["NoEcho"] = i18n("For Echo Mode", "No Echo");
  303. m_propValDesc["Password"] = i18n("For Echo Mode", "Password");
  304. //for spring
  305. m_propDesc["sizeType"] = i18n("Size Type");
  306. //for labels
  307. m_propDesc["textFormat"] = i18n("Text Format");
  308. m_propValDesc["PlainText"] = i18n("For Text Format", "Plain");
  309. m_propValDesc["RichText"] = i18n("For Text Format", "Hypertext");
  310. m_propValDesc["AutoText"] = i18n("For Text Format", "Auto");
  311. m_propValDesc["LogText"] = i18n("For Text Format", "Log");
  312. //KTextEdit
  313. m_propDesc["tabStopWidth"] = i18n("Tab Stop Width");
  314. m_propDesc["tabChangesFocus"] = i18n("Tab Changes Focus");
  315. m_propDesc["wrapPolicy"] = i18n("Word Wrap Policy");
  316. m_propValDesc["AtWordBoundary"] = i18n("For Word Wrap Policy", "At Word Boundary");
  317. m_propValDesc["Anywhere"] = i18n("For Word Wrap Policy", "Anywhere");
  318. m_propValDesc["AtWordOrDocumentBoundary"] = i18n("For Word Wrap Policy", "At Word Boundary If Possible");
  319. m_propDesc["wordWrap"] = i18n("Word Wrapping");
  320. m_propDesc["wrapColumnOrWidth"] = i18n("Word Wrap Position");
  321. m_propValDesc["NoWrap"] = i18n("For Word Wrap Position", "None");
  322. m_propValDesc["WidgetWidth"] = i18n("For Word Wrap Position", "Widget's Width");
  323. m_propValDesc["FixedPixelWidth"] = i18n("For Word Wrap Position", "In Pixels");
  324. m_propValDesc["FixedColumnWidth"] = i18n("For Word Wrap Position", "In Columns");
  325. m_propDesc["linkUnderline"] = i18n("Links Underlined");
  326. //internal props
  327. setInternalProperty("Line","orientationSelectionPopup","1");
  328. setInternalProperty("Line","orientationSelectionPopup:horizontalIcon","line_horizontal");
  329. setInternalProperty("Line","orientationSelectionPopup:verticalIcon","line_vertical");
  330. setInternalProperty("Line","orientationSelectionPopup:horizontalText",i18n("Insert &Horizontal Line"));
  331. setInternalProperty("Line","orientationSelectionPopup:verticalText",i18n("Insert &Vertical Line"));
  332. setInternalProperty("Spring","orientationSelectionPopup","1");
  333. setInternalProperty("Spring","orientationSelectionPopup:horizontalIcon","spring");
  334. setInternalProperty("Spring","orientationSelectionPopup:verticalIcon","spring_vertical");
  335. setInternalProperty("Spring","orientationSelectionPopup:horizontalText",i18n("Insert &Horizontal Spring"));
  336. setInternalProperty("Spring","orientationSelectionPopup:verticalText",i18n("Insert &Vertical Spring"));
  337. }
  338. StdWidgetFactory::~StdWidgetFactory()
  339. {
  340. }
  341. TQWidget*
  342. StdWidgetFactory::createWidget(const TQCString &c, TQWidget *p, const char *n,
  343. KFormDesigner::Container *container, int options)
  344. {
  345. TQWidget *w=0;
  346. TQString text( container->form()->library()->textForWidgetName(n, c) );
  347. const bool designMode = options & KFormDesigner::WidgetFactory::DesignViewMode;
  348. if(c == TQLABEL_OBJECT_NAME_STRING)
  349. w = new TQLabel(text, p, n);
  350. else if(c == "KexiPictureLabel")
  351. w = new KexiPictureLabel(DesktopIcon("image-x-generic"), p, n);
  352. else if(c == "KLineEdit")
  353. {
  354. w = new KLineEdit(p, n);
  355. if (designMode)
  356. w->setCursor(TQCursor(TQt::ArrowCursor));
  357. }
  358. else if(c == "KPushButton")
  359. w = new KPushButton(/*i18n("Button")*/text, p, n);
  360. else if(c == TQRADIOBUTTON_OBJECT_NAME_STRING)
  361. w = new TQRadioButton(/*i18n("Radio Button")*/text, p, n);
  362. else if(c == TQCHECKBOX_OBJECT_NAME_STRING)
  363. w = new TQCheckBox(/*i18n("Check Box")*/text, p, n);
  364. else if(c == "KIntSpinBox")
  365. w = new KIntSpinBox(p, n);
  366. else if(c == "KComboBox")
  367. w = new KComboBox(p, n);
  368. else if(c == "TDEListBox")
  369. w = new TDEListBox(p, n);
  370. else if(c == "KTextEdit")
  371. w = new KTextEdit(/*i18n("Enter your text here")*/text, TQString(), p, n);
  372. else if(c == "TDEListView")
  373. {
  374. w = new TDEListView(p, n);
  375. if(container->form()->interactiveMode())
  376. ((TDEListView*)w)->addColumn(i18n("Column 1"));
  377. ((TDEListView*)w)->setRootIsDecorated(true);
  378. }
  379. else if(c == TQSLIDER_OBJECT_NAME_STRING)
  380. w = new TQSlider(Qt::Horizontal, p, n);
  381. else if(c == "KProgress")
  382. w = new KProgress(p, n);
  383. else if(c == "KDateWidget")
  384. w = new KDateWidget(TQDate::currentDate(), p, n);
  385. else if(c == "KTimeWidget")
  386. w = new KTimeWidget(TQTime::currentTime(), p, n);
  387. else if(c == "KDateTimeWidget")
  388. w = new KDateTimeWidget(TQDateTime::currentDateTime(), p, n);
  389. else if(c == "Line")
  390. w = new Line(options & WidgetFactory::VerticalOrientation ? Qt::Vertical : Qt::Horizontal, p, n);
  391. else if(c == "Spring") {
  392. w = new Spring(p, n);
  393. if (0 == (options & WidgetFactory::AnyOrientation))
  394. static_cast<Spring*>(w)->setOrientation(
  395. (options & WidgetFactory::VerticalOrientation) ? Qt::Vertical : Qt::Horizontal);
  396. }
  397. if(w)
  398. return w;
  399. kdDebug() << "WARNING :: w == 0 " << endl;
  400. return 0;
  401. }
  402. bool
  403. StdWidgetFactory::previewWidget(const TQCString &classname, TQWidget *widget, KFormDesigner::Container *)
  404. {
  405. if(classname == "Spring") {
  406. ((Spring*)widget)->setPreviewMode();
  407. return true;
  408. }
  409. return false;
  410. }
  411. bool
  412. StdWidgetFactory::createMenuActions(const TQCString &classname, TQWidget *, TQPopupMenu *menu,
  413. KFormDesigner::Container *)
  414. {
  415. if((classname == TQLABEL_OBJECT_NAME_STRING) || (classname == "KTextEdit"))
  416. {
  417. menu->insertItem(SmallIconSet("edit"), i18n("Edit Rich Text"), this, TQT_SLOT(editText()));
  418. return true;
  419. }
  420. else if(classname == "TDEListView")
  421. {
  422. menu->insertItem(SmallIconSet("edit"), i18n("Edit Listview Contents"), this, TQT_SLOT(editListContents()));
  423. return true;
  424. }
  425. return false;
  426. }
  427. bool
  428. StdWidgetFactory::startEditing(const TQCString &classname, TQWidget *w, KFormDesigner::Container *container)
  429. {
  430. setWidget(w, container);
  431. // m_container = container;
  432. if(classname == "KLineEdit")
  433. {
  434. KLineEdit *lineedit = static_cast<KLineEdit*>(w);
  435. createEditor(classname, lineedit->text(), lineedit, container, lineedit->geometry(), lineedit->alignment(), true);
  436. return true;
  437. }
  438. else if(classname == TQLABEL_OBJECT_NAME_STRING)
  439. {
  440. TQLabel *label = static_cast<TQLabel*>(w);
  441. if(label->textFormat() == RichText)
  442. {
  443. //m_widget = w;
  444. // setWidget(w, container);
  445. editText();
  446. }
  447. else
  448. createEditor(classname, label->text(), label, container, label->geometry(), label->alignment());
  449. return true;
  450. }
  451. else if(classname == "KPushButton")
  452. {
  453. KPushButton *push = static_cast<KPushButton*>(w);
  454. TQRect r = w->style().subRect(TQStyle::SR_PushButtonContents, w);
  455. TQRect editorRect = TQRect(push->x() + r.x(), push->y() + r.y(), r.width(), r.height());
  456. //r.setX(r.x() + 5);
  457. //r.setY(r.y() + 5);
  458. //r.setWidth(r.width()-10);
  459. //r.setHeight(r.height() - 10);
  460. createEditor(classname, push->text(), push, container, editorRect, TQt::AlignCenter, false, false, TQt::PaletteButton);
  461. return true;
  462. }
  463. else if(classname == TQRADIOBUTTON_OBJECT_NAME_STRING)
  464. {
  465. TQRadioButton *radio = static_cast<TQRadioButton*>(w);
  466. TQRect r = w->style().subRect(TQStyle::SR_RadioButtonContents, w);
  467. TQRect editorRect = TQRect(radio->x() + r.x(), radio->y() + r.y(), r.width(), r.height());
  468. createEditor(classname, radio->text(), radio, container, editorRect, TQt::AlignAuto);
  469. return true;
  470. }
  471. else if(classname == TQCHECKBOX_OBJECT_NAME_STRING)
  472. {
  473. TQCheckBox *check = static_cast<TQCheckBox*>(w);
  474. //TQRect r(check->geometry());
  475. //r.setX(r.x() + 20);
  476. TQRect r = w->style().subRect(TQStyle::SR_CheckBoxContents, w);
  477. TQRect editorRect = TQRect(check->x() + r.x(), check->y() + r.y(), r.width(), r.height());
  478. createEditor(classname, check->text(), check, container, editorRect, TQt::AlignAuto);
  479. return true;
  480. }
  481. else if((classname == "KComboBox") || (classname == "TDEListBox"))
  482. {
  483. TQStringList list;
  484. if(classname == "TDEListBox")
  485. {
  486. TDEListBox *listbox = (TDEListBox*)w;
  487. for(uint i=0; i < listbox->count(); i++)
  488. list.append(listbox->text(i));
  489. }
  490. else if(classname == "KComboBox")
  491. {
  492. KComboBox *combo = (KComboBox*)w;
  493. for(int i=0; i < combo->count(); i++)
  494. list.append(combo->text(i));
  495. }
  496. if(editList(w, list))
  497. {
  498. if(classname == "TDEListBox")
  499. {
  500. ((TDEListBox*)w)->clear();
  501. ((TDEListBox*)w)->insertStringList(list);
  502. }
  503. else if(classname == "KComboBox")
  504. {
  505. ((KComboBox*)w)->clear();
  506. ((KComboBox*)w)->insertStringList(list);
  507. }
  508. }
  509. return true;
  510. }
  511. else if((classname == "KTextEdit") || (classname == "KDateTimeWidget") || (classname == "KTimeWidget") ||
  512. (classname == "KDateWidget") || (classname == "KIntSpinBox")) {
  513. disableFilter(w, container);
  514. return true;
  515. }
  516. return false;
  517. }
  518. bool
  519. StdWidgetFactory::clearWidgetContent(const TQCString &classname, TQWidget *w)
  520. {
  521. if(classname == "KLineEdit")
  522. ((KLineEdit*)w)->clear();
  523. else if(classname == "TDEListBox")
  524. ((TDEListBox*)w)->clear();
  525. else if(classname == "TDEListView")
  526. ((TDEListView*)w)->clear();
  527. else if(classname == "KComboBox")
  528. ((KComboBox*)w)->clear();
  529. else if(classname == "KTextEdit")
  530. ((KTextEdit*)w)->clear();
  531. else
  532. return false;
  533. return true;
  534. }
  535. bool
  536. StdWidgetFactory::changeText(const TQString &text)
  537. {
  538. TQCString n = WidgetFactory::widget()->className();
  539. TQWidget *w = WidgetFactory::widget();
  540. if(n == "KIntSpinBox")
  541. ((KIntSpinBox*)w)->setValue(text.toInt());
  542. else
  543. changeProperty("text", text, m_container->form());
  544. /* By-hand method not needed as sizeHint() can do that for us
  545. TQFontMetrics fm = w->fontMetrics();
  546. TQSize s(fm.width( text ), fm.height());
  547. int width;
  548. if(n == TQLABEL_OBJECT_NAME_STRING) // labels are resized to fit the text
  549. {
  550. w->resize(w->sizeHint());
  551. WidgetFactory::m_editor->resize(w->size());
  552. return;
  553. }
  554. // and other widgets are just enlarged if needed
  555. else if(n == "KPushButton")
  556. width = w->style().sizeFromContents( TQStyle::CT_PushButton, w, s).width();
  557. else if(n == TQCHECKBOX_OBJECT_NAME_STRING)
  558. width = w->style().sizeFromContents( TQStyle::CT_CheckBox, w, s).width();
  559. else if(n == TQRADIOBUTTON_OBJECT_NAME_STRING)
  560. width = w->style().sizeFromContents( TQStyle::CT_RadioButton, w, s).width();
  561. else
  562. return;
  563. int width = w->sizeHint().width();*/
  564. #if 0 //not needed here, size hint is used on creation in InsertWidgetCommand::execute()
  565. if(w->width() < width)
  566. {
  567. w->resize(width, w->height() );
  568. //WidgetFactory::m_editor->resize(w->size());
  569. }
  570. #endif
  571. return true;
  572. }
  573. void
  574. StdWidgetFactory::resizeEditor(TQWidget *editor, TQWidget *widget, const TQCString &classname)
  575. {
  576. TQSize s = widget->size();
  577. TQPoint p = widget->pos();
  578. TQRect r;
  579. if(classname == TQRADIOBUTTON_OBJECT_NAME_STRING)
  580. {
  581. r = widget->style().subRect(TQStyle::SR_RadioButtonContents, widget);
  582. p += r.topLeft();
  583. s.setWidth(r.width());
  584. }
  585. else if(classname == TQCHECKBOX_OBJECT_NAME_STRING)
  586. {
  587. r = widget->style().subRect(TQStyle::SR_CheckBoxContents, widget);
  588. p += r.topLeft();
  589. s.setWidth(r.width());
  590. }
  591. else if(classname == "KPushButton")
  592. {
  593. r = widget->style().subRect(TQStyle::SR_PushButtonContents, widget);
  594. p += r.topLeft();
  595. s = r.size();
  596. }
  597. editor->resize(s);
  598. editor->move(p);
  599. }
  600. bool
  601. StdWidgetFactory::saveSpecialProperty(const TQCString &classname, const TQString &name, const TQVariant &, TQWidget *w, TQDomElement &parentNode, TQDomDocument &domDoc)
  602. {
  603. if(name == "list_items" && classname == "KComboBox")
  604. {
  605. KComboBox *combo = (KComboBox*)w;
  606. for(int i=0; i < combo->count(); i++)
  607. {
  608. TQDomElement item = domDoc.createElement("item");
  609. KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", combo->text(i));
  610. parentNode.appendChild(item);
  611. }
  612. return true;
  613. }
  614. else if(name == "list_items" && classname == "TDEListBox")
  615. {
  616. TDEListBox *listbox = (TDEListBox*)w;
  617. for(uint i=0; i < listbox->count(); i++)
  618. {
  619. TQDomElement item = domDoc.createElement("item");
  620. KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", listbox->text(i));
  621. parentNode.appendChild(item);
  622. }
  623. return true;
  624. }
  625. else if(name == "list_contents" && classname == "TDEListView")
  626. {
  627. TDEListView *listview = (TDEListView*)w;
  628. // First we save the columns
  629. for(int i = 0; i < listview->columns(); i++)
  630. {
  631. TQDomElement item = domDoc.createElement("column");
  632. KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", listview->columnText(i));
  633. KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "width", listview->columnWidth(i));
  634. KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "resizable", listview->header()->isResizeEnabled(i));
  635. KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "clickable", listview->header()->isClickEnabled(i));
  636. KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "fullwidth", listview->header()->isStretchEnabled(i));
  637. parentNode.appendChild(item);
  638. }
  639. // Then we save the list view items
  640. TQListViewItem *item = listview->firstChild();
  641. while(item)
  642. {
  643. saveListItem(item, parentNode, domDoc);
  644. item = item->nextSibling();
  645. }
  646. return true;
  647. }
  648. return false;
  649. }
  650. void
  651. StdWidgetFactory::saveListItem(TQListViewItem *item, TQDomNode &parentNode, TQDomDocument &domDoc)
  652. {
  653. TQDomElement element = domDoc.createElement("item");
  654. parentNode.appendChild(element);
  655. // We save the text of each column
  656. for(int i = 0; i < item->listView()->columns(); i++)
  657. KFormDesigner::FormIO::savePropertyElement(element, domDoc, "property", "text", item->text(i));
  658. // Then we save every sub items
  659. TQListViewItem *child = item->firstChild();
  660. while(child)
  661. {
  662. saveListItem(child, element, domDoc);
  663. child = child->nextSibling();
  664. }
  665. }
  666. bool
  667. StdWidgetFactory::readSpecialProperty(const TQCString &classname, TQDomElement &node, TQWidget *w, KFormDesigner::ObjectTreeItem *)
  668. {
  669. TQString tag = node.tagName();
  670. TQString name = node.attribute("name");
  671. if((tag == "item") && (classname == "KComboBox"))
  672. {
  673. KComboBox *combo = (KComboBox*)w;
  674. TQVariant val = KFormDesigner::FormIO::readPropertyValue(node.firstChild().firstChild(), TQT_TQOBJECT(w), name);
  675. if(val.canCast(TQVariant::Pixmap))
  676. combo->insertItem(val.toPixmap());
  677. else
  678. combo->insertItem(val.toString());
  679. return true;
  680. }
  681. if((tag == "item") && (classname == "TDEListBox"))
  682. {
  683. TDEListBox *listbox = (TDEListBox*)w;
  684. TQVariant val = KFormDesigner::FormIO::readPropertyValue(node.firstChild().firstChild(), TQT_TQOBJECT(w), name);
  685. if(val.canCast(TQVariant::Pixmap))
  686. listbox->insertItem(val.toPixmap());
  687. else
  688. listbox->insertItem(val.toString());
  689. return true;
  690. }
  691. if((tag == "column") && (classname == "TDEListView"))
  692. {
  693. TDEListView *listview = (TDEListView*)w;
  694. int id=0;
  695. for(TQDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling())
  696. {
  697. TQString prop = n.toElement().attribute("name");
  698. TQVariant val = KFormDesigner::FormIO::readPropertyValue(n.firstChild(), TQT_TQOBJECT(w), name);
  699. if(prop == "text")
  700. id = listview->addColumn(val.toString());
  701. else if(prop == "width")
  702. listview->setColumnWidth(id, val.toInt());
  703. else if(prop == "resizable")
  704. listview->header()->setResizeEnabled(val.toBool(), id);
  705. else if(prop == "clickable")
  706. listview->header()->setClickEnabled(val.toBool(), id);
  707. else if(prop == "fullwidth")
  708. listview->header()->setStretchEnabled(val.toBool(), id);
  709. }
  710. return true;
  711. }
  712. else if((tag == "item") && (classname == "TDEListView"))
  713. {
  714. TDEListView *listview = (TDEListView*)w;
  715. readListItem(node, 0, listview);
  716. return true;
  717. }
  718. return false;
  719. }
  720. void
  721. StdWidgetFactory::readListItem(TQDomElement &node, TQListViewItem *parent, TDEListView *listview)
  722. {
  723. TQListViewItem *item;
  724. if(parent)
  725. item = new TDEListViewItem(parent);
  726. else
  727. item = new TDEListViewItem(listview);
  728. // We need to move the item at the end of the list
  729. TQListViewItem *last;
  730. if(parent)
  731. last = parent->firstChild();
  732. else
  733. last = listview->firstChild();
  734. while(last->nextSibling())
  735. last = last->nextSibling();
  736. item->moveItem(last);
  737. int i = 0;
  738. for(TQDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling())
  739. {
  740. TQDomElement childEl = n.toElement();
  741. TQString prop = childEl.attribute("name");
  742. TQString tag = childEl.tagName();
  743. // We read sub items
  744. if(tag == "item")
  745. {
  746. item->setOpen(true);
  747. readListItem(childEl, item, listview);
  748. }
  749. // and column texts
  750. else if((tag == "property") && (prop == "text"))
  751. {
  752. TQVariant val = KFormDesigner::FormIO::readPropertyValue(n.firstChild(), TQT_TQOBJECT(listview), "item");
  753. item->setText(i, val.toString());
  754. i++;
  755. }
  756. }
  757. }
  758. bool
  759. StdWidgetFactory::isPropertyVisibleInternal(const TQCString &classname,
  760. TQWidget *w, const TQCString &property, bool isTopLevel)
  761. {
  762. bool ok = true;
  763. if(classname == "FormWidgetBase")
  764. {
  765. if(property == "iconText"
  766. || property == "geometry" /*nonsense for toplevel widget*/)
  767. return false;
  768. }
  769. else if (classname == "CustomWidget")
  770. {
  771. }
  772. else if(classname == "Spring")
  773. {
  774. return Spring::isPropertyVisible(property);
  775. }
  776. else if(classname == "KexiPictureLabel")
  777. {
  778. if((property == "text") || (property == "indent") || (property == "textFormat") || (property == "font") || (property == "alignment"))
  779. return false;
  780. }
  781. else if(classname == TQLABEL_OBJECT_NAME_STRING)
  782. {
  783. if(property == "pixmap")
  784. return false;
  785. }
  786. else if(classname == "KLineEdit")
  787. {
  788. if(property == "vAlign")
  789. return false;
  790. }
  791. else if(classname == "KTextEdit")
  792. ok = m_showAdvancedProperties ||
  793. property!="undoDepth"
  794. && property!="undoRedoEnabled" //always true!
  795. && property!="dragAutoScroll" //always true!
  796. && property!="overwriteMode" //always false!
  797. && property!="resizePolicy"
  798. && property!="autoFormatting" //too complex
  799. #ifdef KEXI_NO_UNFINISHED
  800. && property!="paper"
  801. #endif
  802. ;
  803. else if(classname == "Line")
  804. {
  805. if((property == "frameShape") || (property == "font") || (property == "margin"))
  806. return false;
  807. }
  808. else if(classname==TQCHECKBOX_OBJECT_NAME_STRING)
  809. {
  810. ok = m_showAdvancedProperties || (property != "autoRepeat");
  811. }
  812. else if(classname==TQRADIOBUTTON_OBJECT_NAME_STRING)
  813. {
  814. ok = m_showAdvancedProperties || (property != "autoRepeat");
  815. }
  816. else if(classname=="KPushButton")
  817. {
  818. //! @todo reenable autoDefault / default if the top level window is dialog...
  819. ok = m_showAdvancedProperties || (property != "autoDefault" && property != "default");
  820. }
  821. return ok && WidgetFactory::isPropertyVisibleInternal(classname, w, property, isTopLevel);
  822. }
  823. TQValueList<TQCString>
  824. StdWidgetFactory::autoSaveProperties(const TQCString &classname)
  825. {
  826. TQValueList<TQCString> l;
  827. if(classname == TQLABEL_OBJECT_NAME_STRING)
  828. l << "text";
  829. if(classname == "KPushButton")
  830. l << "text";
  831. else if(classname == "KexiPictureLabel")
  832. l << "pixmap";
  833. else if(classname == "KComboBox")
  834. l << "list_items";
  835. else if(classname == "TDEListBox")
  836. l << "list_items";
  837. else if(classname == "TDEListView")
  838. l << "list_contents";
  839. else if(classname == "Line")
  840. l << "orientation";
  841. else if(classname == "KTimeWidget")
  842. l << "time";
  843. else if(classname == "KDateWidget")
  844. l << "date";
  845. else if(classname == "KDateTimeWidget")
  846. l << "dateTime";
  847. else if(classname == "Spring")
  848. l << "sizeType" << "orientation";
  849. else if(classname == "KTextEdit")
  850. l << "textFormat" << "text";
  851. return l;
  852. }
  853. void
  854. StdWidgetFactory::editText()
  855. {
  856. TQCString classname = widget()->className();
  857. TQString text;
  858. if(classname == "KTextEdit")
  859. text = ((KTextEdit*)widget())->text();
  860. else if(classname == TQLABEL_OBJECT_NAME_STRING)
  861. text = ((TQLabel*)widget())->text();
  862. if(editRichText(widget(), text))
  863. {
  864. changeProperty("textFormat", "RichText", m_container->form());
  865. changeProperty("text", text, m_container->form());
  866. }
  867. if(classname == TQLABEL_OBJECT_NAME_STRING)
  868. widget()->resize(widget()->sizeHint());
  869. }
  870. void
  871. StdWidgetFactory::editListContents()
  872. {
  873. if(widget()->inherits(TQLISTVIEW_OBJECT_NAME_STRING))
  874. editListView((TQListView*)widget());
  875. }
  876. void
  877. StdWidgetFactory::setPropertyOptions( KFormDesigner::WidgetPropertySet& buf, const KFormDesigner::WidgetInfo& info, TQWidget *w )
  878. {
  879. Q_UNUSED( info );
  880. Q_UNUSED( w );
  881. if (buf.contains("indent")) {
  882. buf["indent"].setOption("min", -1);
  883. buf["indent"].setOption("minValueText", i18n("default indent value", "default"));
  884. }
  885. }
  886. KFORMDESIGNER_WIDGET_FACTORY(StdWidgetFactory, stdwidgets)
  887. #include "stdwidgetfactory.moc"