예제 #1
0
void JabberSearch::addWidget(JabberAgentInfo *data)
{
    QWidget *widget = NULL;
    bool bJoin = false;
    if (!data->Type.str().isEmpty()){
        if (data->Type.str() == "x"){
            m_bXData = true;
            vector<QWidget*>::iterator it;
            for (it = m_widgets.begin(); it != m_widgets.end(); ++it)
                if (*it)
                    delete (*it);
            m_widgets.clear();
            for (it = m_labels.begin(); it != m_labels.end(); ++it)
                if (*it)
                    delete (*it);
            m_labels.clear();
            for (it = m_descs.begin(); it != m_descs.end(); ++it)
                if (*it)
                    delete (*it);
            m_descs.clear();
            m_instruction = QString::null;
        }else if (data->Type.str() == "title"){
            if (!data->Value.str().isEmpty())
                m_title = data->Value.str();
        }else if (data->Type.str() == "text-single"){
            widget = new QLineEdit(this, data->Field.str());
            connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
            connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
            if (!data->Value.str().isEmpty())
                static_cast<QLineEdit*>(widget)->setText(data->Value.str());
        }else if (data->Type.str() == "text-private"){
            widget = new QLineEdit(this, data->Field.str());
            static_cast<QLineEdit*>(widget)->setEchoMode(QLineEdit::Password);
            connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
            connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
            if (!data->Value.str().isEmpty())
                static_cast<QLineEdit*>(widget)->setText(data->Value.str());
        }else if (data->Type.str() == "text-multi"){
            widget = new QMultiLineEdit(this, data->Field.str());
            connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
            if (!data->Value.str().isEmpty())
                static_cast<QMultiLineEdit*>(widget)->setText(data->Value.str());
        }else if (data->Type.str() == "boolean" && !data->Label.str().isEmpty()){
            widget = new QCheckBox(data->Label.str(), this, data->Field.str());
            if (!data->Value.str().isEmpty() && !data->Value.str().startsWith("0"))
                static_cast<QCheckBox*>(widget)->setChecked(true);
            data->Label.clear();
            bJoin = true;
        }else if (data->Type.str() == "fixed"){
            if (!data->Value.str().isEmpty()){
                QString text = i18(data->Value.str());
                text = text.replace(QRegExp("  +"), "\n");
                if (m_bFirst){
                    if (!m_label.isEmpty())
                        m_label += '\n';
                    m_label += text;
                }else{
                    QLabel *label = new QLabel(text, this);
                    label->setAlignment(WordBreak);
                    widget = label;
                    bJoin = true;
                }
            }
        }else if (data->Type.str() == "instructions"){
            if (!data->Value.str().isEmpty()){
                QString text = i18(data->Value.str());
                text = text.replace(QRegExp("  +"), "\n");
                if (!m_instruction.isEmpty())
                    m_instruction += '\n';
                m_instruction += text;
            }
        }else if (data->Type.str() == "list-single"){
            CComboBox *box = new CComboBox(this, data->Field.str());
            int cur = 0;
            int n = 0;
            for (unsigned i = 0; i < data->nOptions.toULong(); i++){
                QString label = get_str(data->OptionLabels, i);
                QString val   = get_str(data->Options, i);
                if (label && val){
                    box->addItem(i18(label), val);
                    if (data->Value.str() == val)
                        cur = n;
                    n++;
                }
            }
            box->setCurrentItem(cur);
            widget = box;
        }else if (data->Type.str() == "key"){
            if (!data->Value.str().isEmpty())
                m_key = data->Value.str();
        }else if (data->Type.str() == "password"){
            widget = new QLineEdit(this, "password");
            static_cast<QLineEdit*>(widget)->setEchoMode(QLineEdit::Password);
            connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
            connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
            data->Label.str() = "Password";
        }else if (data->Type.str() == "online"){
            widget = new QCheckBox(this, "online");
            static_cast<QCheckBox*>(widget)->setText(i18n("Online only"));
            bJoin = true;
        }else if (data->Type.str() == "sex"){
            CComboBox *box = new CComboBox(this, data->Field.str());
            box->addItem(QString::null, "0");
            box->addItem(i18n("Male"), "1");
            box->addItem(i18n("Female"), "2");
            data->Label.str() == I18N_NOOP("Gender");
            widget = box;
        }else{
            defFlds *f;
            for (f = fields; f->tag; f++)
                if (data->Type.str() == QString::fromUtf8(f->tag))
                    break;
            if (f->tag){
                widget = new QLineEdit(this, f->tag);
                connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
                connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
                if (!data->Value.str().isEmpty())
                    static_cast<QLineEdit*>(widget)->setText(data->Value.str());
                data->Label.str() = QString::fromUtf8(f->name);
                if (f->bRequired && m_bRegister)
                    data->bRequired.asBool() = true;
            }else if (!data->Label.str().isEmpty()){
                widget = new QLineEdit(this, data->Field.str());
                connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
                connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
                if (!data->Value.str().isEmpty())
                    static_cast<QLineEdit*>(widget)->setText(data->Value.str());
            }
        }
    }else{
        createLayout();
        m_widgets.clear();
        m_labels.clear();
        m_descs.clear();
        m_bDirty = true;
        QTimer::singleShot(0, this, SLOT(setSize()));
        return;
    }
    if (widget){
        m_bFirst = false;
        if (data->bRequired.toBool())
            m_required.push_back(widget);
        QLabel *label = NULL;
        if (!bJoin && !data->Label.str().isEmpty()){
            QString text = i18(data->Label.str());
            if (!text.isEmpty() && (text[(int)(text.length() - 1)] != ':'))
                text += ':';
            label = new QLabel(text, this);
            label->setAlignment(AlignRight);
        }
        QWidget *help = NULL;
        if (!data->Desc.str().isEmpty())
            help = new HelpButton(data->Desc.str(), this);
        m_labels.push_back(label);
        m_widgets.push_back(widget);
        m_descs.push_back(help);
    }
}
예제 #2
0
void JabberSearch::addWidget(JabberAgentInfo *data)
{
    QWidget *widget = NULL;
    bool bJoin = false;
    if (data->Type.ptr){
        if (!strcmp(data->Type.ptr, "x")){
            m_bXData = true;
        }else if (!strcmp(data->Type.ptr, "title")){
            if (data->Value.ptr && *data->Value.ptr)
                m_title = QString::fromUtf8(data->Value.ptr);
        }else if (!strcmp(data->Type.ptr, "text-single")){
            widget = new QLineEdit(this, data->Field.ptr);
            connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
            connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
            if (data->Value.ptr && *data->Value.ptr)
                static_cast<QLineEdit*>(widget)->setText(QString::fromUtf8(data->Value.ptr));
        }else if (!strcmp(data->Type.ptr, "text-private")){
            widget = new QLineEdit(this, data->Field.ptr);
            static_cast<QLineEdit*>(widget)->setEchoMode(QLineEdit::Password);
            connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
            connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
            if (data->Value.ptr && *data->Value.ptr)
                static_cast<QLineEdit*>(widget)->setText(QString::fromUtf8(data->Value.ptr));
        }else if (!strcmp(data->Type.ptr, "text-multi")){
            widget = new QMultiLineEdit(this, data->Field.ptr);
            connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
            if (data->Value.ptr && *data->Value.ptr)
                static_cast<QMultiLineEdit*>(widget)->setText(QString::fromUtf8(data->Value.ptr));
        }else if (!strcmp(data->Type.ptr, "boolean") && data->Label.ptr){
            widget = new QCheckBox(QString::fromUtf8(data->Label.ptr), this, data->Field.ptr);
            if (data->Value.ptr && *data->Value.ptr && (*data->Value.ptr != '0'))
                static_cast<QCheckBox*>(widget)->setChecked(true);
            set_str(&data->Label.ptr, NULL);
            bJoin = true;
        }else if (!strcmp(data->Type.ptr, "fixed")){
            if (data->Value.ptr){
                QString text = i18(data->Value.ptr);
                text = text.replace(QRegExp("  +"), "\n");
                if (m_bFirst){
                    if (!m_label.isEmpty())
                        m_label += "\n";
                    m_label += text;
                }else{
                    QLabel *label = new QLabel(text, this);
                    label->setAlignment(WordBreak);
                    widget = label;
                    bJoin = true;
                }
            }
        }else if (!strcmp(data->Type.ptr, "instructions")){
            if (data->Value.ptr){
                QString text = i18(data->Value.ptr);
                text = text.replace(QRegExp("  +"), "\n");
                if (!m_instruction.isEmpty())
                    m_instruction += "\n";
                m_instruction += text;
            }
        }else if (!strcmp(data->Type.ptr, "list-single")){
            CComboBox *box = new CComboBox(this, data->Field.ptr);
            int cur = 0;
            int n = 0;
            for (unsigned i = 0; i < data->nOptions.value; i++){
                const char *label = get_str(data->OptionLabels, i);
                const char *val   = get_str(data->Options, i);
                if (label && val){
                    box->addItem(i18(label), val);
                    if (data->Value.ptr && !strcmp(data->Value.ptr, val))
                        cur = n;
                    n++;
                }
            }
            box->setCurrentItem(cur);
            widget = box;
        }else if (!strcmp(data->Type.ptr, "key")){
            if (data->Value.ptr)
                m_key = data->Value.ptr;
        }else if (!strcmp(data->Type.ptr, "password")){
            widget = new QLineEdit(this, "password");
            static_cast<QLineEdit*>(widget)->setEchoMode(QLineEdit::Password);
            connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
            connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
            set_str(&data->Label.ptr, "Password");
        }else if (!strcmp(data->Type.ptr, "online")){
            widget = new QCheckBox(this, "online");
            static_cast<QCheckBox*>(widget)->setText(i18n("Online only"));
            bJoin = true;
        }else if (!strcmp(data->Type.ptr, "sex")){
            CComboBox *box = new CComboBox(this, data->Field.ptr);
            box->addItem("", "0");
            box->addItem(i18n("Male"), "1");
            box->addItem(i18n("Female"), "2");
            set_str(&data->Label.ptr, I18N_NOOP("Gender"));
            widget = box;
        }else{
            defFlds *f;
            for (f = fields; f->tag; f++)
                if (!strcmp(data->Type.ptr, f->tag))
                    break;
            if (f->tag){
                widget = new QLineEdit(this, f->tag);
                connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
                connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
                if (data->Value.ptr && *data->Value.ptr)
                    static_cast<QLineEdit*>(widget)->setText(QString::fromUtf8(data->Value.ptr));
                set_str(&data->Label.ptr, f->name);
                if (f->bRequired && m_bRegister)
                    data->bRequired.bValue = true;
            }else if (data->Label.ptr){
                widget = new QLineEdit(this, data->Field.ptr);
                connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
                connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
                if (data->Value.ptr && *data->Value.ptr)
                    static_cast<QLineEdit*>(widget)->setText(QString::fromUtf8(data->Value.ptr));
            }
        }
    }else{
        if (!m_widgets.empty()){
            unsigned nCols = (m_widgets.size() + MAX_ELEMENTS - 1) / MAX_ELEMENTS;
            unsigned nRows = (m_widgets.size() + nCols - 1) / nCols;
            unsigned start = 0;
            if (!m_label.isEmpty()){
                QLabel *label = new QLabel(m_label, this);
                label->setAlignment(WordBreak);
                lay->addMultiCellWidget(label, 0, 0, 0, nCols * 2 + 1);
                m_label = "";
                start = 1;
            }
            unsigned row = start;
            unsigned col = 0;
            for (unsigned i = 0; i < m_widgets.size(); i++, row++){
                if (row >= nRows + start){
                    row  = 0;
                    col += 2;
                }
                if (m_labels[i]){
                    lay->addWidget(m_labels[i], row, col);
                    lay->addWidget(m_widgets[i], row, col + 1);
                    m_labels[i]->show();
                }else{
                    lay->addMultiCellWidget(m_widgets[i], row, row, col, col + 1);
                }
                m_widgets[i]->show();
            }
            if (!m_instruction.isEmpty()){
                QLabel *label = new QLabel(m_instruction, this);
                label->setAlignment(WordBreak);
                lay->addMultiCellWidget(label, nRows + start, nRows + start, 0, nCols * 2 + 1);
                m_instruction = "";
            }
        }
        m_widgets.clear();
        m_labels.clear();
        m_bDirty = true;
        QTimer::singleShot(0, this, SLOT(setSize()));
        return;
    }
    if (widget){
        m_bFirst = false;
        if (data->bRequired.bValue)
            m_required.push_back(widget);
        QLabel *label = NULL;
        if (!bJoin && data->Label.ptr){
            label = new QLabel(i18(data->Label.ptr), this);
            label->setAlignment(AlignRight);
        }
        m_labels.push_back(label);
        m_widgets.push_back(widget);
    }
}
예제 #3
0
void JabberSearch::addWidget(JabberAgentInfo *data)
{
    QWidget *widget = NULL;
    bool bJoin = false;
    if (data->Type){
        if (!strcmp(data->Type, "x")){
            m_bXData = true;
		}else if (!strcmp(data->Type, "title")){
			if (data->Value && *data->Value)
				m_title = QString::fromUtf8(data->Value);
        }else if (!strcmp(data->Type, "text-single")){
            widget = new QLineEdit(this, data->Field);
            connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
            connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
			if (data->Value && *data->Value)
				static_cast<QLineEdit*>(widget)->setText(QString::fromUtf8(data->Value));
        }else if (!strcmp(data->Type, "text-private")){
            widget = new QLineEdit(this, data->Field);
			static_cast<QLineEdit*>(widget)->setEchoMode(QLineEdit::Password);
            connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
            connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
			if (data->Value && *data->Value)
				static_cast<QLineEdit*>(widget)->setText(QString::fromUtf8(data->Value));
        }else if (!strcmp(data->Type, "text-multi")){
            widget = new QMultiLineEdit(this, data->Field);
            connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
			if (data->Value && *data->Value)
				static_cast<QMultiLineEdit*>(widget)->setText(QString::fromUtf8(data->Value));
        }else if (!strcmp(data->Type, "boolean") && data->Label){
            widget = new QCheckBox(QString::fromUtf8(data->Label), this, data->Field);
			if (data->Value && *data->Value && (*data->Value != '0'))
				static_cast<QCheckBox*>(widget)->setChecked(true);
			set_str(&data->Label, NULL);
			bJoin = true;
        }else if (!strcmp(data->Type, "fixed") || !strcmp(data->Type, "instructions")){
            if (data->Value){
                QString text = i18(data->Value);
                text = text.replace(QRegExp("  +"), "\n");
                QLabel *label = new QLabel(text, this);
                label->setAlignment(WordBreak);
                widget = label;
                bJoin = true;
				if (m_nPos == 0)
					m_nPosStart = 1;
            }
        }else if (!strcmp(data->Type, "list-single")){
            CComboBox *box = new CComboBox(this, data->Field);
			int cur = 0;
			int n = 0;
            for (unsigned i = 0; i < data->nOptions; i++){
                const char *label = get_str(data->OptionLabels, i);
                const char *val   = get_str(data->Options, i);
                if (label && val){
                    box->addItem(i18(label), val);
					if (data->Value && !strcmp(data->Value, val))
						cur = n;
					n++;
				}
            }
			box->setCurrentItem(cur);
            widget = box;
        }else if (!strcmp(data->Type, "key")){
            if (data->Value)
                m_key = data->Value;
        }else if (!strcmp(data->Type, "password")){
            widget = new QLineEdit(this, "password");
            static_cast<QLineEdit*>(widget)->setEchoMode(QLineEdit::Password);
            connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
            connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
            set_str(&data->Label, "Password");
        }else if (!strcmp(data->Type, "online")){
            widget = new QCheckBox(this, "online");
            static_cast<QCheckBox*>(widget)->setText(i18n("Online only"));
            bJoin = true;
        }else if (!strcmp(data->Type, "sex")){
            CComboBox *box = new CComboBox(this, data->Field);
            box->addItem("", "0");
            box->addItem(i18n("Male"), "1");
            box->addItem(i18n("Female"), "2");
            set_str(&data->Label, I18N_NOOP("Gender"));
            widget = box;
        }else{
            defFlds *f;
            for (f = fields; f->tag; f++)
                if (!strcmp(data->Type, f->tag))
                    break;
            if (f->tag){
                widget = new QLineEdit(this, f->tag);
                connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
                connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
				if (data->Value && *data->Value)
					static_cast<QLineEdit*>(widget)->setText(QString::fromUtf8(data->Value));
                set_str(&data->Label, f->name);
                if (f->bRequired)
                    data->bRequired = true;
            }else if (data->Label){
                widget = new QLineEdit(this, data->Field);
                connect(widget, SIGNAL(returnPressed()), m_receiver, SLOT(search()));
                connect(widget, SIGNAL(textChanged(const QString&)), m_receiver, SLOT(textChanged(const QString&)));
				if (data->Value && *data->Value)
					static_cast<QLineEdit*>(widget)->setText(QString::fromUtf8(data->Value));
            }
        }
    }
    if (widget){
        if (data->bRequired)
            m_required.push_back(widget);
        if (bJoin){
            lay->addMultiCellWidget(widget, m_nPos, m_nPos, m_nCol, m_nCol + 1);
        }else{
            lay->addWidget(widget, m_nPos, m_nCol + 1);
            if (data->Label){
                QLabel *label = new QLabel(i18(data->Label), this);
                label->setAlignment(AlignRight);
                lay->addWidget(label, m_nPos, m_nCol);
                label->show();
            }
        }
        widget->show();
        m_nPos++;
		if (m_nPos >= MAX_ELEMENTS){
			m_nPos  = m_nPosStart;
			m_nCol += 2;
		}
        m_bDirty = true;
        QTimer::singleShot(0, this, SLOT(setSize()));
    }
}