From 477c9fd7f038cd43207c8634d53d0949814ecb4c Mon Sep 17 00:00:00 2001 From: deva Date: Thu, 28 Aug 2008 14:13:48 +0000 Subject: Added common stuff in central file. Fixed help text reformatting. --- client/widgets/button.cc | 18 ++------ client/widgets/checkbox.cc | 24 ++--------- client/widgets/combobox.cc | 29 +++---------- client/widgets/common.cc | 98 ++++++++++++++++++++++++++++++++++++++++++ client/widgets/common.h | 36 ++++++++++++++++ client/widgets/frame.cc | 17 ++------ client/widgets/groupbox.cc | 49 +++------------------ client/widgets/label.cc | 14 ++---- client/widgets/lineedit.cc | 26 ++--------- client/widgets/listbox.cc | 21 +-------- client/widgets/multilist.cc | 11 +++-- client/widgets/radiobutton.cc | 21 ++------- client/widgets/radiobuttons.cc | 30 ++----------- client/widgets/textedit.cc | 31 +++---------- client/widgets/window.cc | 34 ++------------- 15 files changed, 189 insertions(+), 270 deletions(-) create mode 100644 client/widgets/common.cc create mode 100644 client/widgets/common.h (limited to 'client/widgets') diff --git a/client/widgets/button.cc b/client/widgets/button.cc index 0f9df2f..2eee811 100644 --- a/client/widgets/button.cc +++ b/client/widgets/button.cc @@ -27,24 +27,14 @@ #include "button.h" #include +#include "common.h" + Button::Button(QDomNode &node, MacroWindow *macrowindow) : QPushButton(), Widget(node, macrowindow) { - QDomElement elem = node.toElement(); - - if(elem.hasAttribute("width")) { - //resize(elem.attribute("width").toInt(), height()); - setMinimumWidth(elem.attribute("width").toInt()); - } + setCommonAttributes(this, node); - if(elem.hasAttribute("height")) { - //resize(width(), elem.attribute("height").toInt()); - setMinimumHeight(elem.attribute("height").toInt()); - } - - if(elem.hasAttribute("help")) { - setToolTip(elem.attribute("help")); - } + QDomElement elem = node.toElement(); if(elem.hasAttribute("field")) { field = elem.attribute("field"); diff --git a/client/widgets/checkbox.cc b/client/widgets/checkbox.cc index 1f089bb..f2af188 100644 --- a/client/widgets/checkbox.cc +++ b/client/widgets/checkbox.cc @@ -26,36 +26,20 @@ */ #include "checkbox.h" +#include "common.h" + CheckBox::CheckBox(QDomNode &node, MacroWindow *macrowindow) : QCheckBox(), Widget(node, macrowindow) { - QDomElement elem = node.toElement(); + setCommonAttributes(this, node); - if(elem.hasAttribute("width")) { - setMinimumWidth(elem.attribute("width").toInt()); - } + QDomElement elem = node.toElement(); - if(elem.hasAttribute("height")) { - setMinimumHeight(elem.attribute("height").toInt()); - } - if(elem.hasAttribute("caption")) { setText(elem.attribute("caption")); } - - if(elem.hasAttribute("help")) { - setToolTip(elem.attribute("help")); - } connect(this, SIGNAL(stateChanged(int)), this, SLOT(state_change())); - - /* // This is done later - if(elem.hasAttribute("value")) { - setValue(elem.attribute("value")); - } else { - setValue("false"); - } - */ } QString CheckBox::getValue() diff --git a/client/widgets/combobox.cc b/client/widgets/combobox.cc index caa7683..12c1f26 100644 --- a/client/widgets/combobox.cc +++ b/client/widgets/combobox.cc @@ -30,33 +30,18 @@ #include #include +#include "common.h" + ComboBox::ComboBox(QDomNode &node, MacroWindow *macrowindow) : QComboBox(), Widget(node, macrowindow) { - QDomElement elem = node.toElement(); + setCommonAttributes(this, node); setInsertPolicy(QComboBox::InsertAlphabetically); - if(elem.hasAttribute("width")) { - setMinimumWidth(elem.attribute("width").toInt()); - } - - if(elem.hasAttribute("height")) { - setMinimumHeight(elem.attribute("height").toInt()); - } - - if(elem.hasAttribute("help")) { - setWhatsThis(elem.attribute("help")); - } - if(elem.hasAttribute("help")) { - // setToolTip(elem.attribute("help")); - } - QDomNodeList children = node.childNodes(); QStringList itemlist; - setCurrentIndex(-1); // -1 is default for none selected - for (int i=0; i +#include +#include +#include + +//#define LINEWIDTH 80 + +static QString reformatHelpString(QString help) +{ + QString output; + + // int lastnl = 0; + for(int i = 0; i < help.size(); i++) { + if(i < help.size() - 1 && help[i] == '\\' && help[i+1] == 'n') { + //lastnl = 0; + output += '\n'; + output += '\n'; + i++; + } else { + //if(lastnl > LINEWIDTH && help[i] == ' ') { + // output += '\n'; + // lastnl = 0; + //} else { + output += help[i]; + //lastnl++; + //} + } + } + return output; +} + +void setCommonAttributes(QWidget *widget, QDomNode &node) +{ + QDomElement elem = node.toElement(); + + if(elem.hasAttribute("width")) { + widget->setMinimumWidth(elem.attribute("width").toInt()); + } + + if(elem.hasAttribute("height")) { + widget->setMinimumHeight(elem.attribute("height").toInt()); + } + + if(elem.hasAttribute("help")) { + QString helptext = reformatHelpString(elem.attribute("help")); + widget->setWhatsThis(helptext); + widget->setToolTip(helptext); + } +} + +void setCommonLayout(QWidget *widget, QDomNode &node) +{ + QDomElement elem = node.toElement(); + + if(elem.hasAttribute("layout")) { + if(elem.attribute("layout") == "hbox") { + QHBoxLayout *layout = new QHBoxLayout(); + widget->setLayout(layout); + } else if (elem.attribute("layout") == "vbox") { + QVBoxLayout *layout = new QVBoxLayout(); + widget->setLayout(layout); + } + } else { + QHBoxLayout *layout = new QHBoxLayout(); + widget->setLayout(layout); + } + + widget->setContentsMargins(0,0,0,0); + //widget->layout()->setContentsMargins(0,0,0,0); +} diff --git a/client/widgets/common.h b/client/widgets/common.h new file mode 100644 index 0000000..11ce317 --- /dev/null +++ b/client/widgets/common.h @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * common.h + * + * Thu Aug 28 15:31:52 CEST 2008 + * Copyright 2008 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * Pracro is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __PRACRO_COMMON_H__ +#define __PRACRO_COMMON_H__ + +#include +#include + +void setCommonAttributes(QWidget *widget, QDomNode &node); +void setCommonLayout(QWidget *widget, QDomNode &node); + +#endif/*__PRACRO_COMMON_H__*/ diff --git a/client/widgets/frame.cc b/client/widgets/frame.cc index 1c0955e..872c3fc 100644 --- a/client/widgets/frame.cc +++ b/client/widgets/frame.cc @@ -28,23 +28,14 @@ #include #include +#include "common.h" + Frame::Frame(QDomNode &node, MacroWindow *macrowindow) : QFrame(), Widget(node, macrowindow) { - QDomElement elem = node.toElement(); + setCommonAttributes(this, node); + setCommonLayout(this, node); - if(elem.hasAttribute("layout")) { - if(elem.attribute("layout") == "hbox") { - QHBoxLayout *layout = new QHBoxLayout(); - setLayout(layout); - } else if (elem.attribute("layout") == "vbox") { - QVBoxLayout *layout = new QVBoxLayout(); - setLayout(layout); - } - } - setLineWidth(0); - setMidLineWidth(0); - setContentsMargins(0,0,0,0); layout()->setContentsMargins(0,0,0,0); } diff --git a/client/widgets/groupbox.cc b/client/widgets/groupbox.cc index 4d40dca..2bf696f 100644 --- a/client/widgets/groupbox.cc +++ b/client/widgets/groupbox.cc @@ -30,56 +30,17 @@ #include +#include "common.h" + GroupBox::GroupBox(QDomNode &node, MacroWindow *macrowindow) : QGroupBox(), Widget(node, macrowindow) { + setCommonAttributes(this, node); + setCommonLayout(this, node); + QDomElement elem = node.toElement(); if(elem.hasAttribute("caption")) { setTitle(elem.attribute("caption")); } - - if(elem.hasAttribute("help")) { - setWhatsThis(elem.attribute("help")); - } - if(elem.hasAttribute("help")) { - QString helptext = elem.attribute("help"); - - int idx = 0; - while(idx < helptext.length() - 1) { - if(helptext[idx] == '\\' && helptext[idx+1] == 'n') { - helptext[idx] = '\n'; - helptext[idx+1] = '\n'; - } - idx++; - } - - idx = 60; - while(idx < helptext.length()) { - while(idx < helptext.length() && helptext[idx] != ' ') { - idx++; - } - helptext[idx] = '\n'; - - idx += 60; - } - setToolTip(helptext); - } - - if(elem.hasAttribute("layout")) { - if(elem.attribute("layout") == "hbox") { - QHBoxLayout *layout = new QHBoxLayout(); - setLayout(layout); - } else if (elem.attribute("layout") == "vbox") { - QVBoxLayout *layout = new QVBoxLayout(); - setLayout(layout); - } - } else { - QHBoxLayout *layout = new QHBoxLayout(); - setLayout(layout); - } - - // setLineWidth(0); - // setMidLineWidth(0); - setContentsMargins(0,10,0,0); } diff --git a/client/widgets/label.cc b/client/widgets/label.cc index 1d58665..61b60c5 100644 --- a/client/widgets/label.cc +++ b/client/widgets/label.cc @@ -27,22 +27,14 @@ #include "label.h" #include +#include "common.h" + Label::Label(QDomNode &node, MacroWindow *macrowindow) : QLabel(), Widget(node, macrowindow) { QDomElement elem = node.toElement(); - if(elem.hasAttribute("width")) { - setMinimumWidth(elem.attribute("width").toInt()); - } - - if(elem.hasAttribute("height")) { - setMinimumHeight(elem.attribute("height").toInt()); - } - - if(elem.hasAttribute("help")) { - setToolTip(elem.attribute("help")); - } + setCommonAttributes(this, node); if(elem.hasAttribute("caption")) { setText(elem.attribute("caption")); diff --git a/client/widgets/lineedit.cc b/client/widgets/lineedit.cc index 977c5a2..29ea06c 100644 --- a/client/widgets/lineedit.cc +++ b/client/widgets/lineedit.cc @@ -27,22 +27,14 @@ #include "lineedit.h" #include +#include "common.h" + LineEdit::LineEdit(QDomNode &node, MacroWindow *macrowindow) : QLineEdit(), Widget(node, macrowindow) { - QDomElement elem = node.toElement(); - - if(elem.hasAttribute("width")) { - setMinimumWidth(elem.attribute("width").toInt()); - } - - if(elem.hasAttribute("height")) { - setMinimumHeight(elem.attribute("height").toInt()); - } + setCommonAttributes(this, node); - if(elem.hasAttribute("help")) { - setWhatsThis(elem.attribute("help")); - } + QDomElement elem = node.toElement(); if(elem.hasAttribute("readonly")) { if(elem.attribute("readonly") == "true" || elem.attribute("readonly") == "1") { @@ -55,16 +47,6 @@ LineEdit::LineEdit(QDomNode &node, MacroWindow *macrowindow) } connect(this, SIGNAL(textChanged(QString)), this, SLOT(changed())); - - /* // This is done later - if(elem.hasAttribute("value")) { - setText(elem.attribute("value")); - } else { - // This is a hack to force correct background color according to regexp - setText(" "); - setText(""); - } - */ } void LineEdit::changed() diff --git a/client/widgets/listbox.cc b/client/widgets/listbox.cc index 5215c18..88a5cd2 100644 --- a/client/widgets/listbox.cc +++ b/client/widgets/listbox.cc @@ -27,6 +27,7 @@ #include "listbox.h" #include +#include "common.h" static QListWidgetItem *createItem(QDomElement &elem) { @@ -70,19 +71,7 @@ static QListWidgetItem *createItem(QDomElement &elem) ListBox::ListBox(QDomNode &node, MacroWindow *macrowindow) : QListWidget(), Widget(node, macrowindow) { - QDomElement elem = node.toElement(); - - if(elem.hasAttribute("width")) { - setMinimumWidth(elem.attribute("width").toInt()); - } - - if(elem.hasAttribute("height")) { - setMinimumHeight(elem.attribute("height").toInt()); - } - - if(elem.hasAttribute("help")) { - setToolTip(elem.attribute("help")); - } + setCommonAttributes(this, node); QDomNodeList children = node.childNodes(); @@ -91,12 +80,6 @@ ListBox::ListBox(QDomNode &node, MacroWindow *macrowindow) QDomElement list_elem = child.toElement(); addItem(createItem(list_elem)); } - - /* // This is done later - if(elem.hasAttribute("value")) { - setValue(elem.attribute("value")); - } - */ } bool ListBox::isValid() diff --git a/client/widgets/multilist.cc b/client/widgets/multilist.cc index cbda305..a33c054 100644 --- a/client/widgets/multilist.cc +++ b/client/widgets/multilist.cc @@ -34,9 +34,13 @@ #include "widgetbuilder.h" #include "formatparser.h" +#include "common.h" + MultiList::MultiList(QDomNode &node, MacroWindow *macrowindow) : QFrame(), Widget(node, macrowindow) { + setCommonAttributes(this, node); + QGridLayout *layout = new QGridLayout(); setLayout(layout); @@ -58,10 +62,6 @@ MultiList::MultiList(QDomNode &node, MacroWindow *macrowindow) inputbox->setLayout(layout); } - if(elem.hasAttribute("help")) { - setToolTip(elem.attribute("help")); - } - inputbox->layout()->setContentsMargins(0,0,0,0); QDomNodeList children = node.childNodes(); @@ -155,6 +155,9 @@ QString MultiList::getValue() void MultiList::setValue(QString values) { QString value; + + list->clear(); + int idx = 0; do { value = values.section('\n', idx, idx); diff --git a/client/widgets/radiobutton.cc b/client/widgets/radiobutton.cc index 9e04e07..6646f59 100644 --- a/client/widgets/radiobutton.cc +++ b/client/widgets/radiobutton.cc @@ -27,34 +27,21 @@ #include "radiobutton.h" #include +#include "common.h" + RadioButton::RadioButton(QDomNode &node) : QRadioButton() { - QDomElement elem = node.toElement(); - - if(elem.hasAttribute("width")) { - resize(elem.attribute("width").toInt(), height()); - } + setCommonAttributes(this, node); - if(elem.hasAttribute("height")) { - resize(width(), elem.attribute("height").toInt()); - } - - if(elem.hasAttribute("help")) { - setToolTip(elem.attribute("help")); - } + QDomElement elem = node.toElement(); if(elem.hasAttribute("caption")) { setText(elem.attribute("caption")); - } else { - setText(""); } if(elem.hasAttribute("value")) { value = elem.attribute("value"); - } else { - printf("XML ERROR!!! Radiobutton item has no value\n"); - value = "none"; } } diff --git a/client/widgets/radiobuttons.cc b/client/widgets/radiobuttons.cc index f0c9e8c..1987459 100644 --- a/client/widgets/radiobuttons.cc +++ b/client/widgets/radiobuttons.cc @@ -30,34 +30,13 @@ #include #include +#include "common.h" + RadioButtons::RadioButtons(QDomNode &node, MacroWindow *macrowindow) : QFrame(), Widget(node, macrowindow) { - QDomElement elem = node.toElement(); - - if(elem.hasAttribute("layout")) { - if(elem.attribute("layout") == "hbox") { - QHBoxLayout *layout = new QHBoxLayout(); - setLayout(layout); - } else if (elem.attribute("layout") == "vbox") { - QVBoxLayout *layout = new QVBoxLayout(); - setLayout(layout); - } - } - - if(elem.hasAttribute("width")) { - //resize(elem.attribute("width").toInt(), height()); - setMinimumWidth(elem.attribute("width").toInt()); - } - - if(elem.hasAttribute("height")) { - //resize(width(), elem.attribute("height").toInt()); - setMinimumHeight(elem.attribute("height").toInt()); - } - - if(elem.hasAttribute("help")) { - setToolTip(elem.attribute("help")); - } + setCommonAttributes(this, node); + setCommonLayout(this, node); QDomNodeList children = node.childNodes(); @@ -72,7 +51,6 @@ RadioButtons::RadioButtons(QDomNode &node, MacroWindow *macrowindow) } layout()->setContentsMargins(0,0,0,0); - } bool RadioButtons::isValid() diff --git a/client/widgets/textedit.cc b/client/widgets/textedit.cc index 0cd2d4f..8b18a3d 100644 --- a/client/widgets/textedit.cc +++ b/client/widgets/textedit.cc @@ -25,39 +25,18 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include "textedit.h" -#include #include +#include + +#include "common.h" + TextEdit::TextEdit(QDomNode &node, MacroWindow *macrowindow) : QTextEdit(), Widget(node, macrowindow) { - //setAutoFillBackground(true); /* Default is false, which disables background - // color manipulation.*/ - - QDomElement elem = node.toElement(); - - if(elem.hasAttribute("width")) { - setMinimumWidth(elem.attribute("width").toInt()); - } - - if(elem.hasAttribute("height")) { - setMinimumHeight(elem.attribute("height").toInt()); - } - - if(elem.hasAttribute("help")) { - setToolTip(elem.attribute("help")); - } + setCommonAttributes(this, node); connect(this, SIGNAL(textChanged()), this, SLOT(changed())); - - /* // This is done later - if(elem.hasAttribute("value")) { - setValue(elem.attribute("value")); - } else { - setValue(" "); - setValue(""); - } - */ } void TextEdit::changed() diff --git a/client/widgets/window.cc b/client/widgets/window.cc index c385d04..84e370c 100644 --- a/client/widgets/window.cc +++ b/client/widgets/window.cc @@ -25,29 +25,17 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include "window.h" -#include -#include +#include "common.h" Window::Window(QDomNode &node, MacroWindow *macrowindow) : QWidget(NULL), Widget(node, macrowindow) { setWindowFlags(Qt::WindowContextHelpButtonHint | Qt::WindowSystemMenuHint); - QDomElement elem = node.toElement(); - - if(elem.hasAttribute("width")) { - setMinimumWidth(elem.attribute("width").toInt()); - resize(elem.attribute("width").toInt(), height()); - } + setCommonAttributes(this, node); + setCommonLayout(this, node); - if(elem.hasAttribute("height")) { - setMinimumHeight(elem.attribute("height").toInt()); - resize(width(), elem.attribute("height").toInt()); - } - - if(elem.hasAttribute("help")) { - setToolTip(elem.attribute("help")); - } + QDomElement elem = node.toElement(); if(elem.hasAttribute("fixed")) { if(elem.attribute("fixed") == "true") { @@ -57,19 +45,5 @@ Window::Window(QDomNode &node, MacroWindow *macrowindow) if(elem.hasAttribute("caption")) { setWindowTitle(elem.attribute("caption")); - } else { - setWindowTitle(elem.attribute("")); } - - if(elem.hasAttribute("layout")) { - if(elem.attribute("layout") == "hbox") { - QHBoxLayout *layout = new QHBoxLayout(); - setLayout(layout); - } else if (elem.attribute("layout") == "vbox") { - QVBoxLayout *layout = new QVBoxLayout(); - setLayout(layout); - } - } - - setContentsMargins(0,0,0,0); } -- cgit v1.2.3