00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <qlabel.h>
00011 #include <qpopupmenu.h>
00012 #include <qcursor.h>
00013 #include <qradiobutton.h>
00014 #include <qcheckbox.h>
00015 #include <qslider.h>
00016 #include <qobjectlist.h>
00017 #include <qstring.h>
00018 #include <qvariant.h>
00019 #include <qheader.h>
00020 #include <qdom.h>
00021 #include <qstyle.h>
00022 #include <qvaluevector.h>
00023
00024 #include <klineedit.h>
00025 #include <kpushbutton.h>
00026 #include <knuminput.h>
00027 #include <kcombobox.h>
00028 #include <klistbox.h>
00029 #include <ktextedit.h>
00030 #include <klistview.h>
00031 #include <kprogress.h>
00032 #include <kiconloader.h>
00033 #include <kgenericfactory.h>
00034 #include <klocale.h>
00035 #include <kdebug.h>
00036 #include <kdeversion.h>
00037
00038 #if KDE_VERSION < KDE_MAKE_VERSION(3,1,9)
00039 # include <qdatetimeedit.h>
00040 # define KTimeWidget QTimeEdit
00041 # define KDateWidget QDateEdit
00042 # define KDateTimeWidget QDateTimeEdit
00043 #else
00044 # include <ktimewidget.h>
00045 # include <kdatewidget.h>
00046 # include <kdatetimewidget.h>
00047 #endif
00048
00049 #include "spring.h"
00050 #include "formIO.h"
00051 #include "form.h"
00052 #include "formmanager.h"
00053 #include "widgetlibrary.h"
00054 #include "widgetpropertyset.h"
00055 #include <koproperty/property.h>
00056
00057 #include "stdwidgetfactory.h"
00058
00059
00060 KexiPictureLabel::KexiPictureLabel(const QPixmap &pix, QWidget *parent, const char *name)
00061 : QLabel(parent, name)
00062 {
00063 setPixmap(pix);
00064 setScaledContents(false);
00065 }
00066
00067 bool
00068 KexiPictureLabel::setProperty(const char *name, const QVariant &value)
00069 {
00070 if(QString(name) == "pixmap")
00071 resize(value.toPixmap().height(), value.toPixmap().width());
00072 return QLabel::setProperty(name, value);
00073 }
00074
00075 Line::Line(Qt::Orientation orient, QWidget *parent, const char *name)
00076 : QFrame(parent, name)
00077 {
00078 setFrameShadow(Sunken);
00079 if(orient == Horizontal)
00080 setFrameShape(HLine);
00081 else
00082 setFrameShape(VLine);
00083 }
00084
00085 void
00086 Line::setOrientation(Qt::Orientation orient)
00087 {
00088 if(orient == Horizontal)
00089 setFrameShape(HLine);
00090 else
00091 setFrameShape(VLine);
00092 }
00093
00094 Qt::Orientation
00095 Line::orientation() const
00096 {
00097 if(frameShape() == HLine)
00098 return Horizontal;
00099 else
00100 return Vertical;
00101 }
00102
00103
00104
00105 StdWidgetFactory::StdWidgetFactory(QObject *parent, const char *, const QStringList &)
00106 : KFormDesigner::WidgetFactory(parent, "stdwidgets")
00107 {
00108 KFormDesigner::WidgetInfo *wFormWidget = new KFormDesigner::WidgetInfo(this);
00109 wFormWidget->setPixmap("form");
00110 wFormWidget->setClassName("FormWidgetBase");
00111 wFormWidget->setName(i18n("Form"));
00112 wFormWidget->setNamePrefix(i18n("This string will be used to name widgets of this class. It must _not_ contain white "
00113 "spaces and non latin1 characters.", "form"));
00114 wFormWidget->setDescription(i18n("A simple form widget"));
00115 addClass(wFormWidget);
00116
00117 KFormDesigner::WidgetInfo *wCustomWidget = new KFormDesigner::WidgetInfo(this);
00118 wCustomWidget->setPixmap("unknown_widget");
00119 wCustomWidget->setClassName("CustomWidget");
00120 wCustomWidget->setName(i18n("Custom Widget"));
00121 wCustomWidget->setNamePrefix(i18n("This string will be used to name widgets of this class. It must _not_ contain white "
00122 "spaces and non latin1 characters.", "customWidget"));
00123 wCustomWidget->setDescription(i18n("A custom or non-supported widget"));
00124 addClass(wCustomWidget);
00125
00126 KFormDesigner::WidgetInfo *wLabel = new KFormDesigner::WidgetInfo(this);
00127 wLabel->setPixmap("label");
00128 wLabel->setClassName("QLabel");
00129 wLabel->setName(i18n("Text Label"));
00130 wLabel->setNamePrefix(
00131 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"));
00132 wLabel->setDescription(i18n("A widget to display text"));
00133 addClass(wLabel);
00134
00135 KFormDesigner::WidgetInfo *wPixLabel = new KFormDesigner::WidgetInfo(this);
00136 wPixLabel->setPixmap("pixmaplabel");
00137 wPixLabel->setClassName("KexiPictureLabel");
00138 wPixLabel->setName(i18n("Picture Label"));
00140
00141 wPixLabel->setSavingName("KexiPictureLabel");
00142 wPixLabel->setNamePrefix(
00143 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"));
00144 wPixLabel->setDescription(i18n("A widget to display pictures"));
00145 addClass(wPixLabel);
00146
00147 KFormDesigner::WidgetInfo *wLineEdit = new KFormDesigner::WidgetInfo(this);
00148 wLineEdit->setPixmap("lineedit");
00149 wLineEdit->setClassName("KLineEdit");
00150 wLineEdit->addAlternateClassName("QLineEdit");
00151 wLineEdit->setIncludeFileName("klineedit.h");
00152 wLineEdit->setName(i18n("Line Edit"));
00153 wLineEdit->setNamePrefix(
00154 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"));
00155 wLineEdit->setDescription(i18n("A widget to input text"));
00156 addClass(wLineEdit);
00157
00158 KFormDesigner::WidgetInfo *wSpring = new KFormDesigner::WidgetInfo(this);
00159 wSpring->setPixmap("spring");
00160 wSpring->setClassName("Spring");
00161 wSpring->setName(i18n("Spring"));
00162 wSpring->setNamePrefix(
00163 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"));
00164 wSpring->setDescription(i18n("A spring to place between widgets"));
00165 addClass(wSpring);
00166
00167 KFormDesigner::WidgetInfo *wPushButton = new KFormDesigner::WidgetInfo(this);
00168 wPushButton->setPixmap("button");
00169 wPushButton->setClassName("KPushButton");
00170 wPushButton->addAlternateClassName("QPushButton");
00171 wPushButton->setIncludeFileName("kpushbutton.h");
00172 wPushButton->setName(i18n("Push Button"));
00173 wPushButton->setNamePrefix(
00174 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"));
00175 wPushButton->setDescription(i18n("A simple push button to execute actions"));
00176 addClass(wPushButton);
00177
00178 KFormDesigner::WidgetInfo *wRadioButton = new KFormDesigner::WidgetInfo(this);
00179 wRadioButton->setPixmap("radio");
00180 wRadioButton->setClassName("QRadioButton");
00181 wRadioButton->setName(i18n("Option Button"));
00182 wRadioButton->setNamePrefix(
00183 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"));
00184 wRadioButton->setDescription(i18n("An option button with text or pixmap label"));
00185 addClass(wRadioButton);
00186
00187 KFormDesigner::WidgetInfo *wCheckBox = new KFormDesigner::WidgetInfo(this);
00188 wCheckBox->setPixmap("check");
00189 wCheckBox->setClassName("QCheckBox");
00190 wCheckBox->setName(i18n("Check Box"));
00191 wCheckBox->setNamePrefix(
00192 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"));
00193 wCheckBox->setDescription(i18n("A check box with text or pixmap label"));
00194 addClass(wCheckBox);
00195
00196 KFormDesigner::WidgetInfo *wSpinBox = new KFormDesigner::WidgetInfo(this);
00197 wSpinBox->setPixmap("spin");
00198 wSpinBox->setClassName("KIntSpinBox");
00199 wSpinBox->addAlternateClassName("QSpinBox");
00200 wSpinBox->setIncludeFileName("knuminput.h");
00201 wSpinBox->setName(i18n("Spin Box"));
00202 wSpinBox->setNamePrefix(
00203 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"));
00204 wSpinBox->setDescription(i18n("A spin box widget"));
00205 addClass(wSpinBox);
00206
00207 KFormDesigner::WidgetInfo *wComboBox = new KFormDesigner::WidgetInfo(this);
00208 wComboBox->setPixmap("combo");
00209 wComboBox->setClassName("KComboBox");
00210 wComboBox->addAlternateClassName("QComboBox");
00211 wComboBox->setIncludeFileName("kcombobox.h");
00212 wComboBox->setName(i18n("Combo Box"));
00213 wComboBox->setNamePrefix(
00214 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"));
00215 wComboBox->setDescription(i18n("A combo box widget"));
00216 addClass(wComboBox);
00217
00218 KFormDesigner::WidgetInfo *wListBox = new KFormDesigner::WidgetInfo(this);
00219 wListBox->setPixmap("listbox");
00220 wListBox->setClassName("KListBox");
00221 wListBox->addAlternateClassName("QListBox");
00222 wListBox->setIncludeFileName("klistbox.h");
00223 wListBox->setName(i18n("List Box"));
00224 wListBox->setNamePrefix(
00225 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"));
00226 wListBox->setDescription(i18n("A simple list widget"));
00227 addClass(wListBox);
00228
00229 KFormDesigner::WidgetInfo *wTextEdit = new KFormDesigner::WidgetInfo(this);
00230 wTextEdit->setPixmap("textedit");
00231 wTextEdit->setClassName("KTextEdit");
00232 wTextEdit->addAlternateClassName("QTextEdit");
00233 wTextEdit->setIncludeFileName("ktextedit.h");
00234 wTextEdit->setName(i18n("Text Editor"));
00235 wTextEdit->setNamePrefix(
00236 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"));
00237 wTextEdit->setDescription(i18n("A simple single-page rich text editor"));
00238 addClass(wTextEdit);
00239
00240 KFormDesigner::WidgetInfo *wListView = new KFormDesigner::WidgetInfo(this);
00241 wListView->setPixmap("listview");
00242 wListView->setClassName("KListView");
00243 wListView->addAlternateClassName("QListView");
00244 wListView->setIncludeFileName("klistview.h");
00245 wListView->setName(i18n("List View"));
00246 wListView->setNamePrefix(
00247 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"));
00248 wListView->setDescription(i18n("A list (or tree) widget"));
00249 addClass(wListView);
00250
00251 KFormDesigner::WidgetInfo *wSlider = new KFormDesigner::WidgetInfo(this);
00252 wSlider->setPixmap("slider");
00253 wSlider->setClassName("QSlider");
00254 wSlider->setName(i18n("Slider"));
00255 wSlider->setNamePrefix(
00256 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"));
00257 wSlider->setDescription(i18n("An horizontal slider"));
00258 addClass(wSlider);
00259
00260 KFormDesigner::WidgetInfo *wProgressBar = new KFormDesigner::WidgetInfo(this);
00261 wProgressBar->setPixmap("progress");
00262 wProgressBar->setClassName("KProgress");
00263 wProgressBar->addAlternateClassName("QProgressBar");
00264 wProgressBar->setIncludeFileName("kprogress.h");
00265 wProgressBar->setName(i18n("Progress Bar"));
00266 wProgressBar->setNamePrefix(
00267 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"));
00268 wProgressBar->setDescription(i18n("A progress indicator widget"));
00269 addClass(wProgressBar);
00270
00271 KFormDesigner::WidgetInfo *wLine = new KFormDesigner::WidgetInfo(this);
00272 wLine->setPixmap("line");
00273 wLine->setClassName("Line");
00274 wLine->setName(i18n("Line"));
00275 wLine->setNamePrefix(
00276 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"));
00277 wLine->setDescription(i18n("A line to be used as a separator"));
00278 addClass(wLine);
00279
00280 KFormDesigner::WidgetInfo *wDate = new KFormDesigner::WidgetInfo(this);
00281 wDate->setPixmap("dateedit");
00282 wDate->setClassName("KDateWidget");
00283 #if KDE_VERSION >= KDE_MAKE_VERSION(3,1,9)
00284 wDate->addAlternateClassName("QDateEdit");
00285 wDate->setIncludeFileName("kdatewidget.h");
00286 #endif
00287 wDate->setName(i18n("Date Widget"));
00288 wDate->setNamePrefix(
00289 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"));
00290 wDate->setDescription(i18n("A widget to input and display a date"));
00291 addClass(wDate);
00292
00293 KFormDesigner::WidgetInfo *wTime = new KFormDesigner::WidgetInfo(this);
00294 wTime->setPixmap("timeedit");
00295 wTime->setClassName("KTimeWidget");
00296 #if KDE_VERSION >= KDE_MAKE_VERSION(3,1,9)
00297 wTime->addAlternateClassName("QTimeEdit");
00298 wTime->setIncludeFileName("ktimewidget.h");
00299 #endif
00300 wTime->setName(i18n("Time Widget"));
00301 wTime->setNamePrefix(
00302 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"));
00303 wTime->setDescription(i18n("A widget to input and display a time"));
00304 addClass(wTime);
00305
00306 KFormDesigner::WidgetInfo *wDateTime = new KFormDesigner::WidgetInfo(this);
00307 wDateTime->setPixmap("datetimeedit");
00308 wDateTime->setClassName("KDateTimeWidget");
00309 #if KDE_VERSION >= KDE_MAKE_VERSION(3,1,9)
00310 wDateTime->addAlternateClassName("QDateTimeEdit");
00311 wDateTime->setIncludeFileName("kdatetimewidget.h");
00312 #endif
00313 wDateTime->setName(i18n("Date/Time Widget"));
00314 wDateTime->setNamePrefix(
00315 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"));
00316 wDateTime->setDescription(i18n("A widget to input and display a time and a date"));
00317 addClass(wDateTime);
00318
00319 m_propDesc["toggleButton"] = i18n("Toggle");
00320 m_propDesc["autoRepeat"] = i18n("Auto Repeat");
00321 m_propDesc["autoDefault"] = i18n("Auto Default");
00322 m_propDesc["default"] = i18n("Default");
00323 m_propDesc["flat"] = i18n("Flat");
00324 m_propDesc["echoMode"] =
00325 i18n("Echo mode for Line Edit widget eg. Normal, NoEcho, Password","Echo Mode");
00326 m_propDesc["indent"] = i18n("Indent");
00327
00328 m_propDesc["orientation"] = i18n("Orientation");
00329
00330 m_propDesc["checked"] = i18n("Checked checkbox", "Checked");
00331 m_propDesc["tristate"] = i18n("Tristate checkbox", "Tristate");
00332
00333
00334 m_propValDesc["Normal"] = i18n("For Echo Mode", "Normal");
00335 m_propValDesc["NoEcho"] = i18n("For Echo Mode", "No Echo");
00336 m_propValDesc["Password"] = i18n("For Echo Mode", "Password");
00337
00338
00339 m_propDesc["sizeType"] = i18n("Size Type");
00340
00341
00342 m_propDesc["textFormat"] = i18n("Text Format");
00343 m_propValDesc["PlainText"] = i18n("For Text Format", "Plain");
00344 m_propValDesc["RichText"] = i18n("For Text Format", "Hypertext");
00345 m_propValDesc["AutoText"] = i18n("For Text Format", "Auto");
00346 m_propValDesc["LogText"] = i18n("For Text Format", "Log");
00347
00348
00349 m_propDesc["tabStopWidth"] = i18n("Tab Stop Width");
00350 m_propDesc["tabChangesFocus"] = i18n("Tab Changes Focus");
00351 m_propDesc["wrapPolicy"] = i18n("Word Wrap Policy");
00352 m_propValDesc["AtWordBoundary"] = i18n("For Word Wrap Policy", "At Word Boundary");
00353 m_propValDesc["Anywhere"] = i18n("For Word Wrap Policy", "Anywhere");
00354 m_propValDesc["AtWordOrDocumentBoundary"] = i18n("For Word Wrap Policy", "At Word Boundary If Possible");
00355 m_propDesc["wordWrap"] = i18n("Word Wrapping");
00356 m_propDesc["wrapColumnOrWidth"] = i18n("Word Wrap Position");
00357 m_propValDesc["NoWrap"] = i18n("For Word Wrap Position", "None");
00358 m_propValDesc["WidgetWidth"] = i18n("For Word Wrap Position", "Widget's Width");
00359 m_propValDesc["FixedPixelWidth"] = i18n("For Word Wrap Position", "In Pixels");
00360 m_propValDesc["FixedColumnWidth"] = i18n("For Word Wrap Position", "In Columns");
00361 m_propDesc["linkUnderline"] = i18n("Links Underlined");
00362
00363
00364 setInternalProperty("Line","orientationSelectionPopup","1");
00365 setInternalProperty("Line","orientationSelectionPopup:horizontalIcon","line_horizontal");
00366 setInternalProperty("Line","orientationSelectionPopup:verticalIcon","line_vertical");
00367 setInternalProperty("Line","orientationSelectionPopup:horizontalText",i18n("Insert &Horizontal Line"));
00368 setInternalProperty("Line","orientationSelectionPopup:verticalText",i18n("Insert &Vertical Line"));
00369 setInternalProperty("Spring","orientationSelectionPopup","1");
00370 setInternalProperty("Spring","orientationSelectionPopup:horizontalIcon","spring");
00371 setInternalProperty("Spring","orientationSelectionPopup:verticalIcon","spring_vertical");
00372 setInternalProperty("Spring","orientationSelectionPopup:horizontalText",i18n("Insert &Horizontal Spring"));
00373 setInternalProperty("Spring","orientationSelectionPopup:verticalText",i18n("Insert &Vertical Spring"));
00374 }
00375
00376 StdWidgetFactory::~StdWidgetFactory()
00377 {
00378 }
00379
00380 QWidget*
00381 StdWidgetFactory::createWidget(const QCString &c, QWidget *p, const char *n,
00382 KFormDesigner::Container *container, int options)
00383 {
00384 QWidget *w=0;
00385 QString text( container->form()->library()->textForWidgetName(n, c) );
00386 const bool designMode = options & KFormDesigner::WidgetFactory::DesignViewMode;
00387
00388 if(c == "QLabel")
00389 w = new QLabel(text, p, n);
00390 else if(c == "KexiPictureLabel")
00391 w = new KexiPictureLabel(DesktopIcon("image"), p, n);
00392
00393 else if(c == "KLineEdit")
00394 {
00395 w = new KLineEdit(p, n);
00396 if (designMode)
00397 w->setCursor(QCursor(Qt::ArrowCursor));
00398 }
00399 else if(c == "KPushButton")
00400 w = new KPushButton(text, p, n);
00401
00402 else if(c == "QRadioButton")
00403 w = new QRadioButton(text, p, n);
00404
00405 else if(c == "QCheckBox")
00406 w = new QCheckBox(text, p, n);
00407
00408 else if(c == "KIntSpinBox")
00409 w = new KIntSpinBox(p, n);
00410
00411 else if(c == "KComboBox")
00412 w = new KComboBox(p, n);
00413
00414 else if(c == "KListBox")
00415 w = new KListBox(p, n);
00416
00417 else if(c == "KTextEdit")
00418 w = new KTextEdit(text, QString::null, p, n);
00419
00420 else if(c == "KListView")
00421 {
00422 w = new KListView(p, n);
00423 if(container->form()->interactiveMode())
00424 ((KListView*)w)->addColumn(i18n("Column 1"));
00425 ((KListView*)w)->setRootIsDecorated(true);
00426 }
00427 else if(c == "QSlider")
00428 w = new QSlider(Qt::Horizontal, p, n);
00429
00430 else if(c == "KProgress")
00431 w = new KProgress(p, n);
00432
00433 else if(c == "KDateWidget")
00434 w = new KDateWidget(QDate::currentDate(), p, n);
00435
00436 else if(c == "KTimeWidget")
00437 w = new KTimeWidget(QTime::currentTime(), p, n);
00438
00439 else if(c == "KDateTimeWidget")
00440 w = new KDateTimeWidget(QDateTime::currentDateTime(), p, n);
00441
00442 else if(c == "Line")
00443 w = new Line(options & WidgetFactory::VerticalOrientation ? Line::Vertical : Line::Horizontal, p, n);
00444
00445 else if(c == "Spring") {
00446 w = new Spring(p, n);
00447 if (0 == (options & WidgetFactory::AnyOrientation))
00448 static_cast<Spring*>(w)->setOrientation(
00449 (options & WidgetFactory::VerticalOrientation) ? Qt::Vertical : Qt::Horizontal);
00450 }
00451
00452 if(w)
00453 return w;
00454
00455 kdDebug() << "WARNING :: w == 0 " << endl;
00456 return 0;
00457 }
00458
00459 bool
00460 StdWidgetFactory::previewWidget(const QCString &classname, QWidget *widget, KFormDesigner::Container *)
00461 {
00462 if(classname == "Spring") {
00463 ((Spring*)widget)->setPreviewMode();
00464 return true;
00465 }
00466 return false;
00467 }
00468
00469 bool
00470 StdWidgetFactory::createMenuActions(const QCString &classname, QWidget *, QPopupMenu *menu,
00471 KFormDesigner::Container *)
00472 {
00473 if((classname == "QLabel") || (classname == "KTextEdit"))
00474 {
00475 menu->insertItem(SmallIconSet("edit"), i18n("Edit Rich Text"), this, SLOT(editText()));
00476 return true;
00477 }
00478 else if(classname == "KListView")
00479 {
00480 menu->insertItem(SmallIconSet("edit"), i18n("Edit Listview Contents"), this, SLOT(editListContents()));
00481 return true;
00482 }
00483
00484 return false;
00485 }
00486
00487 bool
00488 StdWidgetFactory::startEditing(const QCString &classname, QWidget *w, KFormDesigner::Container *container)
00489 {
00490 setWidget(w, container);
00491
00492 if(classname == "KLineEdit")
00493 {
00494 KLineEdit *lineedit = static_cast<KLineEdit*>(w);
00495 createEditor(classname, lineedit->text(), lineedit, container, lineedit->geometry(), lineedit->alignment(), true);
00496 return true;
00497 }
00498 else if(classname == "QLabel")
00499 {
00500 QLabel *label = static_cast<QLabel*>(w);
00501 if(label->textFormat() == RichText)
00502 {
00503
00504
00505 editText();
00506 }
00507 else
00508 createEditor(classname, label->text(), label, container, label->geometry(), label->alignment());
00509 return true;
00510 }
00511 else if(classname == "KPushButton")
00512 {
00513 KPushButton *push = static_cast<KPushButton*>(w);
00514 QRect r = w->style().subRect(QStyle::SR_PushButtonContents, w);
00515 QRect editorRect = QRect(push->x() + r.x(), push->y() + r.y(), r.width(), r.height());
00516
00517
00518
00519
00520 createEditor(classname, push->text(), push, container, editorRect, Qt::AlignCenter, false, false, Qt::PaletteButton);
00521 return true;
00522 }
00523 else if(classname == "QRadioButton")
00524 {
00525 QRadioButton *radio = static_cast<QRadioButton*>(w);
00526 QRect r = w->style().subRect(QStyle::SR_RadioButtonContents, w);
00527 QRect editorRect = QRect(radio->x() + r.x(), radio->y() + r.y(), r.width(), r.height());
00528 createEditor(classname, radio->text(), radio, container, editorRect, Qt::AlignAuto);
00529 return true;
00530 }
00531 else if(classname == "QCheckBox")
00532 {
00533 QCheckBox *check = static_cast<QCheckBox*>(w);
00534
00535
00536 QRect r = w->style().subRect(QStyle::SR_CheckBoxContents, w);
00537 QRect editorRect = QRect(check->x() + r.x(), check->y() + r.y(), r.width(), r.height());
00538 createEditor(classname, check->text(), check, container, editorRect, Qt::AlignAuto);
00539 return true;
00540 }
00541 else if((classname == "KComboBox") || (classname == "KListBox"))
00542 {
00543 QStringList list;
00544 if(classname == "KListBox")
00545 {
00546 KListBox *listbox = (KListBox*)w;
00547 for(uint i=0; i < listbox->count(); i++)
00548 list.append(listbox->text(i));
00549 }
00550 else if(classname == "KComboBox")
00551 {
00552 KComboBox *combo = (KComboBox*)w;
00553 for(int i=0; i < combo->count(); i++)
00554 list.append(combo->text(i));
00555 }
00556
00557 if(editList(w, list))
00558 {
00559 if(classname == "KListBox")
00560 {
00561 ((KListBox*)w)->clear();
00562 ((KListBox*)w)->insertStringList(list);
00563 }
00564 else if(classname == "KComboBox")
00565 {
00566 ((KComboBox*)w)->clear();
00567 ((KComboBox*)w)->insertStringList(list);
00568 }
00569 }
00570 return true;
00571 }
00572 else if((classname == "KTextEdit") || (classname == "KDateTimeWidget") || (classname == "KTimeWidget") ||
00573 (classname == "KDateWidget") || (classname == "KIntSpinBox")) {
00574 disableFilter(w, container);
00575 return true;
00576 }
00577 return false;
00578 }
00579
00580 bool
00581 StdWidgetFactory::clearWidgetContent(const QCString &classname, QWidget *w)
00582 {
00583 if(classname == "KLineEdit")
00584 ((KLineEdit*)w)->clear();
00585 else if(classname == "KListBox")
00586 ((KListBox*)w)->clear();
00587 else if(classname == "KListView")
00588 ((KListView*)w)->clear();
00589 else if(classname == "KComboBox")
00590 ((KComboBox*)w)->clear();
00591 else if(classname == "KTextEdit")
00592 ((KTextEdit*)w)->clear();
00593 else
00594 return false;
00595 return true;
00596 }
00597
00598 bool
00599 StdWidgetFactory::changeText(const QString &text)
00600 {
00601 QCString n = WidgetFactory::widget()->className();
00602 QWidget *w = WidgetFactory::widget();
00603 if(n == "KIntSpinBox")
00604 ((KIntSpinBox*)w)->setValue(text.toInt());
00605 else
00606 changeProperty("text", text, m_container->form());
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629 #if 0 //not needed here, size hint is used on creation in InsertWidgetCommand::execute()
00630 if(w->width() < width)
00631 {
00632 w->resize(width, w->height() );
00633
00634 }
00635 #endif
00636 return true;
00637 }
00638
00639 void
00640 StdWidgetFactory::resizeEditor(QWidget *editor, QWidget *widget, const QCString &classname)
00641 {
00642 QSize s = widget->size();
00643 QPoint p = widget->pos();
00644 QRect r;
00645
00646 if(classname == "QRadioButton")
00647 {
00648 r = widget->style().subRect(QStyle::SR_RadioButtonContents, widget);
00649 p += r.topLeft();
00650 s.setWidth(r.width());
00651 }
00652 else if(classname == "QCheckBox")
00653 {
00654 r = widget->style().subRect(QStyle::SR_CheckBoxContents, widget);
00655 p += r.topLeft();
00656 s.setWidth(r.width());
00657 }
00658 else if(classname == "KPushButton")
00659 {
00660 r = widget->style().subRect(QStyle::SR_PushButtonContents, widget);
00661 p += r.topLeft();
00662 s = r.size();
00663 }
00664
00665 editor->resize(s);
00666 editor->move(p);
00667 }
00668
00669 bool
00670 StdWidgetFactory::saveSpecialProperty(const QCString &classname, const QString &name, const QVariant &, QWidget *w, QDomElement &parentNode, QDomDocument &domDoc)
00671 {
00672 if(name == "list_items" && classname == "KComboBox")
00673 {
00674 KComboBox *combo = (KComboBox*)w;
00675 for(int i=0; i < combo->count(); i++)
00676 {
00677 QDomElement item = domDoc.createElement("item");
00678 KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", combo->text(i));
00679 parentNode.appendChild(item);
00680 }
00681 return true;
00682 }
00683 else if(name == "list_items" && classname == "KListBox")
00684 {
00685 KListBox *listbox = (KListBox*)w;
00686 for(uint i=0; i < listbox->count(); i++)
00687 {
00688 QDomElement item = domDoc.createElement("item");
00689 KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", listbox->text(i));
00690 parentNode.appendChild(item);
00691 }
00692 return true;
00693 }
00694 else if(name == "list_contents" && classname == "KListView")
00695 {
00696 KListView *listview = (KListView*)w;
00697
00698 for(int i = 0; i < listview->columns(); i++)
00699 {
00700 QDomElement item = domDoc.createElement("column");
00701 KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "text", listview->columnText(i));
00702 KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "width", listview->columnWidth(i));
00703 KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "resizable", listview->header()->isResizeEnabled(i));
00704 KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "clickable", listview->header()->isClickEnabled(i));
00705 KFormDesigner::FormIO::savePropertyElement(item, domDoc, "property", "fullwidth", listview->header()->isStretchEnabled(i));
00706 parentNode.appendChild(item);
00707 }
00708
00709
00710 QListViewItem *item = listview->firstChild();
00711 while(item)
00712 {
00713 saveListItem(item, parentNode, domDoc);
00714 item = item->nextSibling();
00715 }
00716 return true;
00717 }
00718
00719 return false;
00720 }
00721
00722 void
00723 StdWidgetFactory::saveListItem(QListViewItem *item, QDomNode &parentNode, QDomDocument &domDoc)
00724 {
00725 QDomElement element = domDoc.createElement("item");
00726 parentNode.appendChild(element);
00727
00728
00729 for(int i = 0; i < item->listView()->columns(); i++)
00730 KFormDesigner::FormIO::savePropertyElement(element, domDoc, "property", "text", item->text(i));
00731
00732
00733 QListViewItem *child = item->firstChild();
00734 while(child)
00735 {
00736 saveListItem(child, element, domDoc);
00737 child = child->nextSibling();
00738 }
00739 }
00740
00741 bool
00742 StdWidgetFactory::readSpecialProperty(const QCString &classname, QDomElement &node, QWidget *w, KFormDesigner::ObjectTreeItem *)
00743 {
00744 QString tag = node.tagName();
00745 QString name = node.attribute("name");
00746
00747 if((tag == "item") && (classname == "KComboBox"))
00748 {
00749 KComboBox *combo = (KComboBox*)w;
00750 QVariant val = KFormDesigner::FormIO::readPropertyValue(node.firstChild().firstChild(), w, name);
00751 if(val.canCast(QVariant::Pixmap))
00752 combo->insertItem(val.toPixmap());
00753 else
00754 combo->insertItem(val.toString());
00755 return true;
00756 }
00757
00758 if((tag == "item") && (classname == "KListBox"))
00759 {
00760 KListBox *listbox = (KListBox*)w;
00761 QVariant val = KFormDesigner::FormIO::readPropertyValue(node.firstChild().firstChild(), w, name);
00762 if(val.canCast(QVariant::Pixmap))
00763 listbox->insertItem(val.toPixmap());
00764 else
00765 listbox->insertItem(val.toString());
00766 return true;
00767 }
00768
00769 if((tag == "column") && (classname == "KListView"))
00770 {
00771 KListView *listview = (KListView*)w;
00772 int id=0;
00773 for(QDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling())
00774 {
00775 QString prop = n.toElement().attribute("name");
00776 QVariant val = KFormDesigner::FormIO::readPropertyValue(n.firstChild(), w, name);
00777 if(prop == "text")
00778 id = listview->addColumn(val.toString());
00779 else if(prop == "width")
00780 listview->setColumnWidth(id, val.toInt());
00781 else if(prop == "resizable")
00782 listview->header()->setResizeEnabled(val.toBool(), id);
00783 else if(prop == "clickable")
00784 listview->header()->setClickEnabled(val.toBool(), id);
00785 else if(prop == "fullwidth")
00786 listview->header()->setStretchEnabled(val.toBool(), id);
00787 }
00788 return true;
00789 }
00790 else if((tag == "item") && (classname == "KListView"))
00791 {
00792 KListView *listview = (KListView*)w;
00793 readListItem(node, 0, listview);
00794 return true;
00795 }
00796
00797 return false;
00798 }
00799
00800 void
00801 StdWidgetFactory::readListItem(QDomElement &node, QListViewItem *parent, KListView *listview)
00802 {
00803 QListViewItem *item;
00804 if(parent)
00805 item = new KListViewItem(parent);
00806 else
00807 item = new KListViewItem(listview);
00808
00809
00810 QListViewItem *last;
00811 if(parent)
00812 last = parent->firstChild();
00813 else
00814 last = listview->firstChild();
00815
00816 while(last->nextSibling())
00817 last = last->nextSibling();
00818 item->moveItem(last);
00819
00820 int i = 0;
00821 for(QDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling())
00822 {
00823 QDomElement childEl = n.toElement();
00824 QString prop = childEl.attribute("name");
00825 QString tag = childEl.tagName();
00826
00827
00828 if(tag == "item")
00829 {
00830 item->setOpen(true);
00831 readListItem(childEl, item, listview);
00832 }
00833
00834 else if((tag == "property") && (prop == "text"))
00835 {
00836 QVariant val = KFormDesigner::FormIO::readPropertyValue(n.firstChild(), listview, "item");
00837 item->setText(i, val.toString());
00838 i++;
00839 }
00840 }
00841 }
00842
00843 bool
00844 StdWidgetFactory::isPropertyVisibleInternal(const QCString &classname,
00845 QWidget *w, const QCString &property, bool isTopLevel)
00846 {
00847 bool ok = true;
00848 if(classname == "FormWidgetBase")
00849 {
00850 if(property == "iconText"
00851 || property == "geometry" )
00852 return false;
00853 }
00854 else if (classname == "CustomWidget")
00855 {
00856 }
00857 else if(classname == "Spring")
00858 {
00859 return Spring::isPropertyVisible(property);
00860 }
00861 else if(classname == "KexiPictureLabel")
00862 {
00863 if((property == "text") || (property == "indent") || (property == "textFormat") || (property == "font") || (property == "alignment"))
00864 return false;
00865 }
00866 else if(classname == "QLabel")
00867 {
00868 if(property == "pixmap")
00869 return false;
00870 }
00871 else if(classname == "KLineEdit")
00872 {
00873 if(property == "vAlign")
00874 return false;
00875 }
00876 else if(classname == "KTextEdit")
00877 ok = m_showAdvancedProperties ||
00878 property!="undoDepth"
00879 && property!="undoRedoEnabled"
00880 && property!="dragAutoScroll"
00881 && property!="overwriteMode"
00882 && property!="resizePolicy"
00883 && property!="autoFormatting"
00884 #ifdef KEXI_NO_UNFINISHED
00885 && property!="paper"
00886 #endif
00887 ;
00888 else if(classname == "Line")
00889 {
00890 if((property == "frameShape") || (property == "font") || (property == "margin"))
00891 return false;
00892 }
00893 else if(classname=="QCheckBox")
00894 {
00895 ok = m_showAdvancedProperties || (property != "autoRepeat");
00896 }
00897 else if(classname=="QRadioButton")
00898 {
00899 ok = m_showAdvancedProperties || (property != "autoRepeat");
00900 }
00901 else if(classname=="KPushButton")
00902 {
00904 ok = m_showAdvancedProperties || (property != "autoDefault" && property != "default");
00905 }
00906 return ok && WidgetFactory::isPropertyVisibleInternal(classname, w, property, isTopLevel);
00907 }
00908
00909 QValueList<QCString>
00910 StdWidgetFactory::autoSaveProperties(const QCString &classname)
00911 {
00912 QValueList<QCString> l;
00913
00914 if(classname == "QLabel")
00915 l << "text";
00916 if(classname == "KPushButton")
00917 l << "text";
00918 else if(classname == "KexiPictureLabel")
00919 l << "pixmap";
00920 else if(classname == "KComboBox")
00921 l << "list_items";
00922 else if(classname == "KListBox")
00923 l << "list_items";
00924 else if(classname == "KListView")
00925 l << "list_contents";
00926 else if(classname == "Line")
00927 l << "orientation";
00928 else if(classname == "KTimeWidget")
00929 l << "time";
00930 else if(classname == "KDateWidget")
00931 l << "date";
00932 else if(classname == "KDateTimeWidget")
00933 l << "dateTime";
00934 else if(classname == "Spring")
00935 l << "sizeType" << "orientation";
00936 else if(classname == "KTextEdit")
00937 l << "textFormat" << "text";
00938
00939 return l;
00940 }
00941
00942 void
00943 StdWidgetFactory::editText()
00944 {
00945 QCString classname = widget()->className();
00946 QString text;
00947 if(classname == "KTextEdit")
00948 text = ((KTextEdit*)widget())->text();
00949 else if(classname == "QLabel")
00950 text = ((QLabel*)widget())->text();
00951
00952 if(editRichText(widget(), text))
00953 {
00954 changeProperty("textFormat", "RichText", m_container->form());
00955 changeProperty("text", text, m_container->form());
00956 }
00957
00958 if(classname == "QLabel")
00959 widget()->resize(widget()->sizeHint());
00960 }
00961
00962 void
00963 StdWidgetFactory::editListContents()
00964 {
00965 if(widget()->inherits("QListView"))
00966 editListView((QListView*)widget());
00967 }
00968
00969 void
00970 StdWidgetFactory::setPropertyOptions( KFormDesigner::WidgetPropertySet& buf, const KFormDesigner::WidgetInfo& info, QWidget *w )
00971 {
00972 Q_UNUSED( info );
00973 Q_UNUSED( w );
00974
00975 if (buf.contains("indent")) {
00976 buf["indent"].setOption("min", -1);
00977 buf["indent"].setOption("minValueText", i18n("default indent value", "default"));
00978 }
00979 }
00980
00981 KFORMDESIGNER_WIDGET_FACTORY(StdWidgetFactory, stdwidgets)
00982
00983 #include "stdwidgetfactory.moc"
00984