void TemplKatalogView::slNewTemplate()
{
  KatalogListView *listView = getListView();
  if( !listView ) return;

  // create new template object
  FloskelTemplate *flosTempl = new FloskelTemplate();
  flosTempl->setText( i18n( "<new template>" ) );

  // find the corresponding parent (==chapter) item
  QTreeWidgetItem *parentItem = static_cast<QTreeWidgetItem*>(listView->currentItem());
  if( parentItem )
  {
    // if it is not a chapter nor root, take the parent
    if( ! (listView->isRoot(parentItem) || listView->isChapter(parentItem)) )
    {
      parentItem = (QTreeWidgetItem*) parentItem->parent();
    }
  }

  if( parentItem ) {
    // try to find out which catalog is open/current
    CatalogChapter *chap = static_cast<CatalogChapter*>( listView->itemData( parentItem ) );
    if( chap ) {
      flosTempl->setChapterId( chap->id().toInt(), true );
    }
  }

  TemplKatalogListView *templListView = static_cast<TemplKatalogListView*>(listView);
  QTreeWidgetItem *item = templListView->addFlosTemplate(parentItem, flosTempl);
  listView->scrollToItem( item );
  listView->setCurrentItem( item );
  openDialog( item, flosTempl, true );
}
void MaterialKatalogView::slNewTemplate()
{
  KatalogListView *listview = getListView();
  if( !listview ) return;
  MaterialKatalogListView *matListView = static_cast<MaterialKatalogListView*>(listview);

  StockMaterial *newMat = new StockMaterial();
  newMat->setName( i18n( "<new material>" ) );
  QTreeWidgetItem *parentItem = static_cast<QTreeWidgetItem*>( listview->currentItem() );
  if ( parentItem ) {
    if ( ! ( matListView->isRoot( parentItem ) || matListView->isChapter( parentItem ) ) ) {
      parentItem = ( QTreeWidgetItem* ) parentItem->parent();
    }
  }

  if( parentItem && listview->isChapter( parentItem )) {
    // try to find out which catalog is open/current
    CatalogChapter *chap = static_cast<CatalogChapter*>(listview->itemData( parentItem ));
    newMat->setChapter( chap->id().toInt() );
  }

  mNewItem = matListView->addMaterialToView( parentItem, newMat );
  openDialog( mNewItem, newMat, true );

}