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(); }
int WidgetBoxTreeWidget::indexOfScratchpad() const { if (const int numTopLevels = topLevelItemCount()) { for (int i = numTopLevels - 1; i >= 0; --i) { if (topLevelRole(topLevelItem(i)) == SCRATCHPAD_ITEM) return i; } } return -1; }
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(); }
void ItemBoxTreeWidget::contextMenuEvent(QContextMenuEvent *e) { QTreeWidgetItem *item = itemAt(e->pos()); if(!item) { return; } const bool scratchpad_menu = item != 0 && item->parent() != 0 && topLevelRole(item->parent()) == SCRATCHPAD_ITEM; QMenu menu; menu.addAction(tr("Expand all"), this, SLOT(expandAll())); menu.addAction(tr("Collapse all"), this, SLOT(collapseAll())); menu.addSeparator(); QAction *listModeAction = menu.addAction(tr("List View")); QAction *iconModeAction = menu.addAction(tr("Icon View")); listModeAction->setCheckable(true); iconModeAction->setCheckable(true); QActionGroup *viewModeGroup = new QActionGroup(&menu); viewModeGroup->addAction(listModeAction); viewModeGroup->addAction(iconModeAction); if (m_iconMode) { iconModeAction->setChecked(true); } else { listModeAction->setChecked(true); } connect(listModeAction, SIGNAL(triggered()), SLOT(slotListMode())); connect(iconModeAction, SIGNAL(triggered()), SLOT(slotIconMode())); if (scratchpad_menu) { menu.addSeparator(); menu.addAction(tr("Remove"), itemWidget(item, 0), SLOT(removeCurrentItem())); if (!m_iconMode) { menu.addAction(tr("Edit name"), itemWidget(item, 0), SLOT(editCurrentItem())); } } e->accept(); // menu.exec(mapToGlobal(e->pos())); // m_core->handleContextMenuEventOnCategory(item->text(0), mapToGlobal(e->pos()), &menu); m_core->handleContextMenuEventOnCategory(item->data(0, Qt::UserRole).toString(), mapToGlobal(e->pos()), &menu); }
ItemBoxTreeWidget::Category ItemBoxTreeWidget::category(int cat_idx) const { if (cat_idx >= topLevelItemCount()) { return Category(); } QTreeWidgetItem *cat_item = topLevelItem(cat_idx); QTreeWidgetItem *embedItem = cat_item->child(0); ItemBoxCategoryListView *categoryView = static_cast<ItemBoxCategoryListView *>(itemWidget(embedItem, 0)); Category result = categoryView->category(); result.setName(cat_item->text(0)); switch (topLevelRole(cat_item)) { case SCRATCHPAD_ITEM: result.setType(Category::Scratchpad); break; default: result.setType(Category::Default); break; } return result; }