Пример #1
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);

}
Пример #2
0
void ItemBoxTreeWidget::removeItem(const QString &cat_id, const QString &item_id)
{

    qDebug() << "--ItemBoxTreeWidget::removeObjectItem()";

    int cat_Idx = indexOfCategory(cat_id);
    if (cat_Idx >= topLevelItemCount() || cat_Idx < 0) {
        return ;
    }

    // unfiltered access
    const ItemBoxCategoryListView::AccessMode am = ItemBoxCategoryListView::UnfilteredAccess;

    ItemBoxCategoryListView *categoryview = categoryViewAt(cat_Idx);
    int item_idx = categoryview->indexOfItem(item_id);
    //TreeWidget::ObjectItem objItem = old_categoryView->objectItemAt(am, item_idx);
    //if(objItem.isNull()){return;}

    if (item_idx >= categoryview->count(am)) {
        return;
    }
    categoryview->removeRow(am, item_idx);
    categoryview->updateGeometry();
    adjustSubListSize(topLevelItem(cat_Idx));

    updateGeometries();
    //viewport()->update();

}
Пример #3
0
void ItemBoxTreeWidget::addItem(int cat_idx, const Item &item)
{
    qDebug() << "--ItemBoxTreeWidget::addItem(...) cat_idx:" << cat_idx << " item.id():" << item.id();

    if (cat_idx >= topLevelItemCount() || cat_idx < 0) {
        qCritical() << "ERROR! Invalid category index!";
        return;
    }

    QTreeWidgetItem *cat_item = topLevelItem(cat_idx);
    ItemBoxCategoryListView *categoryView = categoryViewAt(cat_idx);

    const bool scratch = topLevelRole(cat_item) == SCRATCHPAD_ITEM;
    //const bool scratch = topLevelRole(cat_item) == NORMAL_ITEM;

    // The same categories are read from the file $HOME, avoid duplicates
    if (!categoryView->containsItem(item.id())) {
        categoryView->addItem(item, item.icon(), scratch);
        categoryView->updateGeometry();
    } else {
        qWarning() << "ERROR! Item " << item.id() << " already exists!";
    }

    adjustSubListSize(cat_item);

    updateGeometries();

}
Пример #4
0
void ItemBoxTreeWidget::filter(const QString &f)
{
    const bool empty = f.isEmpty();
    QRegExp re = empty ? QRegExp() : QRegExp(f, Qt::CaseInsensitive, QRegExp::FixedString);
    const int numTopLevels = topLevelItemCount();
    bool changed = false;
    for (int i = 0; i < numTopLevels; i++) {
        QTreeWidgetItem *tl = topLevelItem(i);
        ItemBoxCategoryListView *categoryView = categoryViewAt(i);
        // Anything changed? -> Enable the category
        const int oldCount = categoryView->count(ItemBoxCategoryListView::FilteredAccess);
        categoryView->filter(re);
        const int newCount = categoryView->count(ItemBoxCategoryListView::FilteredAccess);
        if (oldCount != newCount) {
            changed = true;
            const bool categoryEnabled = newCount > 0 || empty;
            if (categoryEnabled) {
                categoryView->adjustSize();
                adjustSubListSize(tl);
            }
            setRowHidden (i, QModelIndex(), !categoryEnabled);
        }
    }
    if (changed) {
        updateGeometries();
    }
}
Пример #5
0
int ItemBoxTreeWidget::itemCount(int cat_idx) const
{
    if (cat_idx >= topLevelItemCount()) {
        return 0;
    }
    // SDK functions want unfiltered access
    return categoryViewAt(cat_idx)->count(ItemBoxCategoryListView::UnfilteredAccess);
}
Пример #6
0
ItemBoxTreeWidget::Item ItemBoxTreeWidget::item(int cat_idx, int item_idx) const
{
    if (cat_idx >= topLevelItemCount()) {
        return Item();
    }
    // SDK functions want unfiltered access
    ItemBoxCategoryListView *categoryView = categoryViewAt(cat_idx);
    return categoryView->itemAt(ItemBoxCategoryListView::UnfilteredAccess, item_idx);
}
Пример #7
0
void WidgetBoxTreeWidget::addCustomCategories(bool replace)
{
    if (replace) {
        // clear out all existing custom widgets
        if (const int numTopLevels =  topLevelItemCount()) {
            for (int t = 0; t < numTopLevels ; ++t)
                categoryViewAt(t)->removeCustomWidgets();
        }
    }
    // re-add
    const CategoryList customList = loadCustomCategoryList();
    const CategoryList::const_iterator cend = customList.constEnd();
    for (CategoryList::const_iterator it = customList.constBegin(); it != cend; ++it)
        addCategory(*it);
}
Пример #8
0
void ItemBoxTreeWidget::moveItem(int old_cat_idx, int new_cat_idx, const QString &item_id)
{

    qDebug() << "--ItemBoxTreeWidget::moveObjectItem()";

    if (old_cat_idx >= topLevelItemCount() || new_cat_idx >= topLevelItemCount()) {
        qCritical() << "ERROR! Invalid old_cat_idx or new_cat_idx!";
        return ;
    }

    // unfiltered access
    const ItemBoxCategoryListView::AccessMode am = ItemBoxCategoryListView::UnfilteredAccess;

    ItemBoxCategoryListView *old_categoryView = categoryViewAt(old_cat_idx);
    int item_idx = old_categoryView->indexOfItem(item_id);
    ItemBoxTreeWidget::Item objItem = old_categoryView->itemAt(am, item_idx);
    if(objItem.isNull()) {
        return;
    }

    //if (item_idx >= old_categoryView->count(am)){return;}
    old_categoryView->removeRow(am, item_idx);
    adjustSubListSize(topLevelItem(old_cat_idx));

    addItem(new_cat_idx, objItem);


    //    QTreeWidgetItem *cat_item = topLevelItem(new_cat_idx);
    //    CategoryListView *categoryView = categoryViewAt(new_cat_idx);

    //    const bool scratch = topLevelRole(cat_item) == SCRATCHPAD_ITEM;
    //    //const bool scratch = topLevelRole(cat_item) == NORMAL_ITEM;

    //    // The same categories are read from the file $HOME, avoid duplicates
    //    if (!categoryView->containsObjectItem(objItem.id())){
    //        categoryView->addObjectItem(objItem, iconForObjectItem(objItem.iconName(), objItem.iconMode()), scratch);
    //    }else{
    //        qWarning()<<"ERROR! Item "<<objItem.id()<<" already exists!";
    //    }

    //    adjustSubListSize(cat_item);

    updateGeometries();



}
Пример #9
0
void ItemBoxTreeWidget::updateViewMode()
{
    if (const int numTopLevels = topLevelItemCount()) {
        for (int i = numTopLevels - 1; i >= 0; --i) {
            QTreeWidgetItem *topLevel = topLevelItem(i);
            // Scratch pad stays in list mode.
            const QListView::ViewMode viewMode  = m_iconMode && (topLevelRole(topLevel) != SCRATCHPAD_ITEM) ? QListView::IconMode : QListView::ListMode;
            ItemBoxCategoryListView *categoryView = categoryViewAt(i);
            if (viewMode != categoryView->viewMode()) {
                categoryView->setViewMode(viewMode);
                adjustSubListSize(topLevelItem(i));
            }
        }
    }

    updateGeometries();
}
Пример #10
0
void ItemBoxTreeWidget::removeItem(int cat_idx, int wgt_idx)
{
    if (cat_idx >= topLevelItemCount()) {
        return;
    }

    ItemBoxCategoryListView *categoryView = categoryViewAt(cat_idx);

    // SDK functions want unfiltered access
    const ItemBoxCategoryListView::AccessMode am = ItemBoxCategoryListView::UnfilteredAccess;
    if (wgt_idx >= categoryView->count(am)) {
        return;
    }

    categoryView->removeRow(am, wgt_idx);
    categoryView->updateGeometry();

}