Exemplo n.º 1
0
void ScTreeWidget::handleMousePress(QTreeWidgetItem *item)
{
    if (item == 0)
        return;
    if (item->parent() == 0)
    {
        if (item->isDisabled())
        {
            setItemExpanded(item, false);
            return;
        }
        int wide = 0;
        int tops = topLevelItemCount();
        if (m_toolbox_mode)
        {
            for (int t = 0; t < tops; t++)
            {
                setItemExpanded(topLevelItem(t), false);
            }
            setCurrentItem(item);
            setItemExpanded(item, true);
            if (item->childCount() != 0)
            {
                QTreeWidgetItem *child = item->child(0);
                if (child != 0)
                    wide = itemWidget(child, 0)->minimumSizeHint().width()+5;
            }
            if (wide != 0)
                setColumnWidth(0, wide);
            else
                resizeColumnToContents(0);
        }
        else
        {
            setItemExpanded(item, !isItemExpanded(item));
            for (int t = 0; t < tops; t++)
            {
                QTreeWidgetItem *top = topLevelItem(t);
                if (isItemExpanded(top))
                {
                    if (top->childCount() != 0)
                    {
                        QTreeWidgetItem *child = top->child(0);
                        if (child != 0)
                            wide = qMax(wide, itemWidget(child, 0)->minimumSizeHint().width()+5);
                    }
                }
            }
        }
        if (wide != 0)
            setColumnWidth(0, wide);
        else
            resizeColumnToContents(0);
        emit currentChanged2(indexOfTopLevelItem(item));
    }
}
Exemplo n.º 2
0
void XbelTree::parseFolderElement(const QDomElement &element,
                                  QTreeWidgetItem *parentItem)
{
    QTreeWidgetItem *item = createItem(element, parentItem);

    QString title = element.attribute("title");
    QString value_ergo = element.attribute("value_ergo");
    QString value_ves = element.attribute("value_ves");
    QString value_number = element.attribute("value_number");
    QString foldedString = element.attribute("folded");

    item->setFlags(item->flags() | Qt::ItemIsEditable);
    item->setIcon(0, folderIcon);
    item->setText(0, title);
    item->setText(1, value_ergo);
    item->setText(2, value_ves);
    item->setText(3, value_number);
    item->setText(4, foldedString);

    bool folded = (element.attribute("folded") != "no");
    setItemExpanded(item, !folded);

    QDomElement child = element.firstChildElement();
    while (!child.isNull()) {
        if (child.tagName() == "folder") {
            parseFolderElement(child, item);
        } else if (child.tagName() == "separator") {
            QTreeWidgetItem *childItem = createItem(child, item);
            childItem->setFlags(item->flags() & ~(Qt::ItemIsSelectable | Qt::ItemIsEditable));
            childItem->setText(0, QString(30, 0xB7));
        }
        child = child.nextSiblingElement();
    }
}
Exemplo n.º 3
0
void ViewListTreeWidget::handleMousePress( QTreeWidgetItem *item )
{
    //kDebug(planDbg());
    if ( item == 0 )
        return ;

    if ( item->parent() == 0 ) {
        setItemExpanded( item, !isItemExpanded( item ) );
        return ;
    }
}
Exemplo n.º 4
0
void WidgetBoxTreeWidget::handleMousePress(QTreeWidgetItem *item)
{
    if (item == 0)
        return;

    if (QApplication::mouseButtons() != Qt::LeftButton)
        return;

    if (item->parent() == 0) {
        setItemExpanded(item, !isItemExpanded(item));
        return;
    }
}
Exemplo n.º 5
0
void ItemBoxTreeWidget::addCategory(const Category &cat, int index)
{
//    if (cat.itemCount() == 0)
//        return;

    const bool isScratchPad = cat.type() == Category::Scratchpad;
    ItemBoxCategoryListView *categoryView = 0;
    QTreeWidgetItem *cat_item = 0;

    if (isScratchPad) {
        const int idx = ensureScratchpad();
        categoryView = categoryViewAt(idx);
        cat_item = topLevelItem(idx);
    } else {
        const int existingIndex = indexOfCategory(cat.id());
        if (existingIndex == -1) {
            cat_item = new QTreeWidgetItem();
            cat_item->setData(0, Qt::UserRole, QVariant(cat.id()));
            cat_item->setText(0, cat.name());
            setTopLevelRole(NORMAL_ITEM, cat_item);
            // insert before scratchpad
            const int scratchPadIndex = indexOfScratchpad();
            if (scratchPadIndex == -1) {
                if(index == -1) {
                    addTopLevelItem(cat_item);
                } else {
                    insertTopLevelItem(index, cat_item);
                }

            } else {
                insertTopLevelItem(scratchPadIndex, cat_item);
            }
            setItemExpanded(cat_item, true);
            categoryView = addCategoryView(cat_item, m_iconMode);
        } else {
            categoryView = categoryViewAt(existingIndex);
            cat_item = topLevelItem(existingIndex);
        }
    }
    // The same categories are read from the file $HOME, avoid duplicates
    const int widgetCount = cat.itemCount();
    for (int i = 0; i < widgetCount; ++i) {
        const Item w = cat.item(i);
        if (!categoryView->containsItem(w.name())) {
            categoryView->addItem(w, w.icon(), isScratchPad);
        }
    }
    adjustSubListSize(cat_item);

}
Exemplo n.º 6
0
void ScTreeWidget::setCurrentIndex(int index)
{
    if ((index < 0) || (index >= topLevelItemCount()))
        return;
    int tops = topLevelItemCount();
    for (int t = 0; t < tops; t++)
    {
        setItemExpanded(topLevelItem(t), false);
    }
    QTreeWidgetItem *top = topLevelItem(index);
    setCurrentItem(top);
    setItemExpanded(top, true);
    int wide = 0;
    if (top->childCount() != 0)
    {
        QTreeWidgetItem *child = top->child(0);
        if (child != 0)
            wide = itemWidget(child, 0)->minimumSizeHint().width()+5;
    }
    if (wide != 0)
        setColumnWidth(0, wide);
    else
        resizeColumnToContents(0);
}
Exemplo n.º 7
0
void XbelTree::parseFolderElement(const QDomElement &element,
                                  QTreeWidgetItem *parentItem)
{
    QTreeWidgetItem *item = createItem(element, parentItem);

    QString title = element.firstChildElement("title").text();
    if (title.isEmpty())
        title = QObject::tr("Folder");

    item->setFlags(item->flags() | Qt::ItemIsEditable);
    item->setIcon(0, folderIcon);
    item->setText(0, title);

    bool folded = (element.attribute("folded") != "no");
    setItemExpanded(item, !folded);

    QDomElement child = element.firstChildElement();
    while (!child.isNull()) {
        if (child.tagName() == "folder") {
            parseFolderElement(child, item);
        } else if (child.tagName() == "bookmark") {
            QTreeWidgetItem *childItem = createItem(child, item);

            QString title = child.firstChildElement("title").text();
            if (title.isEmpty())
                title = QObject::tr("Folder");

            childItem->setFlags(item->flags() | Qt::ItemIsEditable);
            childItem->setIcon(0, bookmarkIcon);
            childItem->setText(0, title);
            childItem->setText(1, child.attribute("href"));
        } else if (child.tagName() == "separator") {
            QTreeWidgetItem *childItem = createItem(child, item);
            childItem->setFlags(item->flags() & ~(Qt::ItemIsSelectable | Qt::ItemIsEditable));
            childItem->setText(0, QString(30, 0xB7));
        }
        child = child.nextSiblingElement();
    }
}
Exemplo n.º 8
0
//------------------------------------------------------------------------------
// Name: addCategory(const QString &name)
// Desc:
//------------------------------------------------------------------------------
QTreeWidgetItem *QCategoryList::addCategory(const QString &name) {
	QTreeWidgetItem *const cat = new QTreeWidgetItem(this);
	cat->setText(0, name);
	setItemExpanded(cat, true);
	return cat;
}
Exemplo n.º 9
0
//------------------------------------------------------------------------------
// Name: handleMousePress(QTreeWidgetItem *item)
// Desc:
//------------------------------------------------------------------------------
void QCategoryList::handleMousePress(QTreeWidgetItem *item) {
	if(isCategory(item)) {
	    setItemExpanded(item, !isItemExpanded(item));
	}
}
Exemplo n.º 10
0
void XbelTree::parseFolderElement(const QDomElement &element,
                                  QTreeWidgetItem *parentItem)
{
    QTreeWidgetItem *item = createItem(element, parentItem);
    QString title = element.firstChildElement("title").text();
    if (title.isEmpty())
        title = QObject::tr("Folder");
    item->setFlags(item->flags());
    item->setIcon(0, folderIcon);
    if( !domElementForItem[item].attribute("device").isNull() ) {
        if( QString(domElementForItem[item].attribute("device")).toInt() >= devices )
            devices++;
        item->setText(0, QString::fromUtf8("%1 - %2").arg(title).arg(domElementForItem[item].attribute("device")));
    }
    else
        item->setText(0, title);
    bool folded = (element.attribute("folded") != "no");
    setItemExpanded(item, !folded);
    QDomElement child = element.firstChildElement();
    while (!child.isNull()) {
        if (child.tagName() == "folder") {
            parseFolderElement(child, item);
        } else if (child.tagName() == "bookmark") {
            QTreeWidgetItem *childItem = createItem(child, item);
            QString title = child.firstChildElement("title").text();
            if (title.isEmpty())
                title = QObject::tr("Folder");
            childItem->setFlags(item->flags());
            childItem->setIcon(0, bookmarkIcon);
            childItem->setText(0, title);
            if( child.attribute("property") == "clicked" ) {
                childItem->setFlags(childItem->flags() | Qt::ItemIsUserCheckable);
                if( child.attribute("href") == "1" )
                    childItem->setCheckState(1, Qt::Checked);
                else
                    childItem->setCheckState(1, Qt::Unchecked);
            }
            if( child.attribute("name") == "proto") {
                JComboBox *cmb = new JComboBox(childItem);
                QString variants = child.attribute("variants");
                QStringList qsl = variants.split("|");
                int currentIndex = child.attribute("href").toInt();
                for(int i=0; i<qsl.size(); i++) {
                    cmb->addItem( qsl[i] );
                }
                cmb->setCurrentIndex(currentIndex);
                this->setItemWidget( childItem, 1, cmb );
                childItem->setIcon(0, QIcon(":/images/protocol.png"));
            }
            if( child.attribute("name") == "cycle") {
                childItem->setIcon(0, QIcon(":/images/cycle.png"));
            }
            if( child.attribute("name") == "registers") {
                childItem->setIcon(0, QIcon(":/images/registers.png"));
            }
            if( child.attribute("name") == "comport") {
                childItem->setIcon(0, QIcon(":/images/com_port.png"));
            }
            if( child.attribute("name") == "address") {
                childItem->setIcon(0, QIcon(":/images/address.png"));
            }
            if( child.attribute("name") == "mbit") {
                childItem->setIcon(0, QIcon(":/images/switch.png"));
            }
            if( child.attribute("name") == "mqpassword") {
                JLineEdit *qle = new JLineEdit(childItem);
                qle->setMaxLength(_mqpassword_length);
                qle->setEchoMode(QLineEdit::Password);
                qle->setText(child.attribute("href"));
                this->setItemWidget( childItem, 1, qle);
                childItem->setIcon(0, QIcon(":/images/password.png"));
            }
            if( child.attribute("name") == "registers"||child.attribute("name") == "cycle"||child.attribute("name") == "comport"||child.attribute("name") == "address"||child.attribute("name") == "begin_TU"||child.attribute("name") == "end_TU"||child.attribute("name") == "tic") {
                JSpinBox *sbx = new JSpinBox(childItem);
                sbx->setMaximum(0xffff);
                sbx->setMinimum(0);
                sbx->setValue(child.attribute("href").toInt());
                this->setItemWidget( childItem, 1, sbx );
            }
            if( (!child.attributeNode("ico").isNull())&&(child.attribute("ico") != "") ) {
                childItem->setIcon(0, QIcon(child.attribute("ico")));
            }
        } else if (child.tagName() == "separator") {
            QTreeWidgetItem *childItem = createItem(child, item);
            childItem->setFlags(item->flags() & ~(Qt::ItemIsSelectable | Qt::ItemIsEditable));
            childItem->setText(0, QString(30, 0xB7));
        }
        child = child.nextSiblingElement();
    }
}
Exemplo n.º 11
0
void Bookmarks::parseFolderElement(const QDomElement &element,
                                   QTreeWidgetItem* parentItem, const QString &/*elementID*/)
{
    QDomElement parentElement(element);
    QString id = "";
    if (parentElement.tagName() == "folder") {
        //old files that their 'folder' tag don't use 'id' attribute
        // just contain 'folder' tag of type 'Verses'!
        id = parentElement.attribute("id", "Verses");
        parentElement.setAttribute("id", id);
    }

    QTreeWidgetItem* item = createItem(parentElement, parentItem, id);

    QString title;
    if (id == "Verses") {
        title = tr("Verses");
    }
    else {
        title = element.firstChildElement("title").text();
    }
    if (title.isEmpty()) {
        title = QObject::tr("Folder");
    }

    item->setIcon(0, m_folderIcon);
    item->setText(0, title);
    item->setToolTip(0, title);

    bool folded = (parentElement.attribute("folded") != "no");
    setItemExpanded(item, !folded);

    QDomElement child = parentElement.firstChildElement();
    while (!child.isNull()) {
        if (child.tagName() == "folder") {
//TODO: we can save labguage within a 'metadata' tag of this 'folder'
//          //update node title by new loaded translation
            QString id = child.attribute("id");
            QString title = child.firstChildElement("title").text();

            if (id.isEmpty()) {
                //old files that their 'folder' tags don't use 'id' attribute just contain 'folder' tags of type 'Verses'!
                id = "Verses";
                title = tr(title.toLocal8Bit().data());
                QDomElement oldTitleElement = child.firstChildElement("title");
                QDomElement newTitleElement = m_domDocument.createElement("title");
                QDomText newTitleText = m_domDocument.createTextNode(tr("Verses"));
                newTitleElement.appendChild(newTitleText);

                child.replaceChild(newTitleElement, oldTitleElement);
                child.setAttribute("id", "Verses");
            }
            parseFolderElement(child, item, id);
        }
        else if (child.tagName() == "bookmark") {
            QTreeWidgetItem* childItem = createItem(child, item);

            QString title = child.firstChildElement("title").text();
            if (title.isEmpty()) {
                title = QObject::tr("Folder");
            }

            QDomElement infoChild = child.firstChildElement("info");
            QDomElement metaData = infoChild.firstChildElement("metadata");
            while (!metaData.isNull()) {
                QString owner = metaData.attribute("owner");
                if (owner == "http://saaghar.pozh.org") {
                    break;
                }
                metaData = metaData.nextSiblingElement("metadata");
            }
            if (!metaData.isNull() && metaData.attribute("owner") == "http://saaghar.pozh.org") {
                childItem->setData(0, Qt::UserRole, metaData.text());
            }
            else {
                qDebug() << "This DOM-NODE SHOULD deleted--->" << title;
            }
            //href data URL data
            childItem->setData(1, Qt::UserRole, child.attribute("href", "http://saaghar.pozh.org"));
            childItem->setIcon(0, m_bookmarkIcon);
            childItem->setText(0, title);
            childItem->setToolTip(0, title);
            childItem->setText(1, child.firstChildElement("desc").text());
            childItem->setToolTip(1, child.firstChildElement("desc").text());
        }
        else if (child.tagName() == "separator") {
            QTreeWidgetItem* childItem = createItem(child, item);
            childItem->setFlags(item->flags() & ~(Qt::ItemIsSelectable | Qt::ItemIsEditable));
            childItem->setText(0, QString(30, 0xB7));
        }
        child = child.nextSiblingElement();
    }
}