From fbd6f357c5d187e6cc2e4dce82bcb72d75133972 Mon Sep 17 00:00:00 2001 From: Elvio Basello Date: Wed, 24 Sep 2008 15:58:04 +0000 Subject: removed KviTalListView in favour of KviTalTreeWidget; updated TODOs; git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@2549 17fca916-40b9-46aa-a4ea-0a15b648b75c --- src/modules/aliaseditor/aliaseditor.cpp | 364 +++++++-------- src/modules/aliaseditor/aliaseditor.h | 111 +++-- src/modules/objects/CMakeLists.txt | 18 +- src/modules/objects/class_listview.cpp | 650 --------------------------- src/modules/objects/class_listview.h | 101 ----- src/modules/objects/class_listviewitem.cpp | 489 -------------------- src/modules/objects/class_listviewitem.h | 93 ---- src/modules/objects/class_treewidget.cpp | 650 +++++++++++++++++++++++++++ src/modules/objects/class_treewidget.h | 97 ++++ src/modules/objects/class_treewidgetitem.cpp | 480 ++++++++++++++++++++ src/modules/objects/class_treewidgetitem.h | 92 ++++ src/modules/objects/libkviobjects.cpp | 7 +- 12 files changed, 1568 insertions(+), 1584 deletions(-) delete mode 100644 src/modules/objects/class_listview.cpp delete mode 100644 src/modules/objects/class_listview.h delete mode 100644 src/modules/objects/class_listviewitem.cpp delete mode 100644 src/modules/objects/class_listviewitem.h create mode 100644 src/modules/objects/class_treewidget.cpp create mode 100644 src/modules/objects/class_treewidget.h create mode 100644 src/modules/objects/class_treewidgetitem.cpp create mode 100644 src/modules/objects/class_treewidgetitem.h (limited to 'src/modules') diff --git a/src/modules/aliaseditor/aliaseditor.cpp b/src/modules/aliaseditor/aliaseditor.cpp index 4653bc642..73fb5be5d 100644 --- a/src/modules/aliaseditor/aliaseditor.cpp +++ b/src/modules/aliaseditor/aliaseditor.cpp @@ -57,13 +57,13 @@ extern KviAliasEditorWindow * g_pAliasEditorWindow; extern KviModule * g_pAliasEditorModule; -KviAliasEditorListViewItem::KviAliasEditorListViewItem(QTreeWidget * pListView,Type eType,const QString &szName) -: QTreeWidgetItem(pListView), m_eType(eType), m_pParentNamespaceItem(0), KviHeapObject() +KviAliasEditorTreeWidgetItem::KviAliasEditorTreeWidgetItem(QTreeWidget * pTreeWidget,Type eType,const QString &szName) +: QTreeWidgetItem(pTreeWidget), m_eType(eType), m_pParentNamespaceItem(0), KviHeapObject() { setName(szName); } -KviAliasEditorListViewItem::KviAliasEditorListViewItem(KviAliasNamespaceListViewItem * pParentNamespaceItem,Type eType,const QString &szName) +KviAliasEditorTreeWidgetItem::KviAliasEditorTreeWidgetItem(KviAliasNamespaceTreeWidgetItem * pParentNamespaceItem,Type eType,const QString &szName) : QTreeWidgetItem(pParentNamespaceItem), m_eType(eType), m_pParentNamespaceItem(pParentNamespaceItem) { setName(szName); @@ -72,7 +72,7 @@ KviAliasEditorListViewItem::KviAliasEditorListViewItem(KviAliasNamespaceListView -QString KviAliasEditorListViewItem::key(int column,bool bAsc) const +QString KviAliasEditorTreeWidgetItem::key(int column,bool bAsc) const { QString ret; if(m_eType == Namespace)ret = "1"; @@ -81,14 +81,14 @@ QString KviAliasEditorListViewItem::key(int column,bool bAsc) const return ret; } -void KviAliasEditorListViewItem::setName(const QString &szName) +void KviAliasEditorTreeWidgetItem::setName(const QString &szName) { m_szName = szName; setText(0,m_szName); } -KviAliasListViewItem::KviAliasListViewItem(KviAliasNamespaceListViewItem * pParentNamespaceItem,const QString &szName) -: KviAliasEditorListViewItem(pParentNamespaceItem,KviAliasEditorListViewItem::Alias,szName) +KviAliasTreeWidgetItem::KviAliasTreeWidgetItem(KviAliasNamespaceTreeWidgetItem * pParentNamespaceItem,const QString &szName) +: KviAliasEditorTreeWidgetItem(pParentNamespaceItem,KviAliasEditorTreeWidgetItem::Alias,szName) { setIcon(0,QIcon(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_ALIAS)))); m_cPos=0; @@ -96,73 +96,73 @@ KviAliasListViewItem::KviAliasListViewItem(KviAliasNamespaceListViewItem * pPare } -KviAliasListViewItem::KviAliasListViewItem(QTreeWidget * pListView,const QString &szName) -: KviAliasEditorListViewItem(pListView,KviAliasEditorListViewItem::Alias,szName) +KviAliasTreeWidgetItem::KviAliasTreeWidgetItem(QTreeWidget * pTreeWidget,const QString &szName) +: KviAliasEditorTreeWidgetItem(pTreeWidget,KviAliasEditorTreeWidgetItem::Alias,szName) { setIcon(0,QIcon(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_ALIAS)))); m_cPos=0; } -KviAliasListViewItem::~KviAliasListViewItem() +KviAliasTreeWidgetItem::~KviAliasTreeWidgetItem() { } -KviAliasNamespaceListViewItem::KviAliasNamespaceListViewItem(QTreeWidget * pListView,const QString &szName) -: KviAliasEditorListViewItem(pListView,KviAliasEditorListViewItem::Namespace,szName) +KviAliasNamespaceTreeWidgetItem::KviAliasNamespaceTreeWidgetItem(QTreeWidget * pTreeWidget,const QString &szName) +: KviAliasEditorTreeWidgetItem(pTreeWidget,KviAliasEditorTreeWidgetItem::Namespace,szName) { setIcon(0,QIcon(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_NAMESPACE)))); } -KviAliasNamespaceListViewItem::KviAliasNamespaceListViewItem(KviAliasNamespaceListViewItem * pParentNamespaceItem,const QString &szName) -: KviAliasEditorListViewItem(pParentNamespaceItem,KviAliasEditorListViewItem::Namespace,szName) +KviAliasNamespaceTreeWidgetItem::KviAliasNamespaceTreeWidgetItem(KviAliasNamespaceTreeWidgetItem * pParentNamespaceItem,const QString &szName) +: KviAliasEditorTreeWidgetItem(pParentNamespaceItem,KviAliasEditorTreeWidgetItem::Namespace,szName) { setIcon(0,QIcon(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_NAMESPACE)))); } -KviAliasNamespaceListViewItem::~KviAliasNamespaceListViewItem() +KviAliasNamespaceTreeWidgetItem::~KviAliasNamespaceTreeWidgetItem() { debug("Deleting %s and pointer %d",this->text(0).toUtf8().data(),this); } -KviAliasNamespaceListViewItem * KviAliasNamespaceListViewItem::findNamespaceItem(const QString &szName) +KviAliasNamespaceTreeWidgetItem * KviAliasNamespaceTreeWidgetItem::findNamespaceItem(const QString &szName) { for (int i=0;iisNamespace()) - if(KviQString::equalCI(szName,((KviAliasEditorListViewItem *)child(i))->name()))return (KviAliasNamespaceListViewItem *)child(i); + if (((KviAliasEditorTreeWidgetItem *)child(i))->isNamespace()) + if(KviQString::equalCI(szName,((KviAliasEditorTreeWidgetItem *)child(i))->name()))return (KviAliasNamespaceTreeWidgetItem *)child(i); } return 0; } -KviAliasNamespaceListViewItem * KviAliasNamespaceListViewItem::getNamespaceItem(const QString &szName) +KviAliasNamespaceTreeWidgetItem * KviAliasNamespaceTreeWidgetItem::getNamespaceItem(const QString &szName) { - KviAliasNamespaceListViewItem * it = findNamespaceItem(szName); + KviAliasNamespaceTreeWidgetItem * it = findNamespaceItem(szName); if(it)return it; - it = new KviAliasNamespaceListViewItem(this,szName); + it = new KviAliasNamespaceTreeWidgetItem(this,szName); return it; } -KviAliasListViewItem * KviAliasNamespaceListViewItem::findAliasItem(const QString &szName) +KviAliasTreeWidgetItem * KviAliasNamespaceTreeWidgetItem::findAliasItem(const QString &szName) { for (int i=0;iisAlias()) - if(KviQString::equalCI(szName,((KviAliasEditorListViewItem *)child(i))->name()))return (KviAliasListViewItem *)child(i); + if (((KviAliasEditorTreeWidgetItem *)child(i))->isAlias()) + if(KviQString::equalCI(szName,((KviAliasEditorTreeWidgetItem *)child(i))->name()))return (KviAliasTreeWidgetItem *)child(i); } return 0; } -KviAliasListViewItem * KviAliasNamespaceListViewItem::getAliasItem(const QString &szName) +KviAliasTreeWidgetItem * KviAliasNamespaceTreeWidgetItem::getAliasItem(const QString &szName) { - KviAliasListViewItem * it = findAliasItem(szName); + KviAliasTreeWidgetItem * it = findAliasItem(szName); if(it)return it; - it = new KviAliasListViewItem(this,szName); + it = new KviAliasTreeWidgetItem(this,szName); return it; } -KviAliasListViewItem * KviAliasNamespaceListViewItem::createFullAliasItem(const QString &szFullName) +KviAliasTreeWidgetItem * KviAliasNamespaceTreeWidgetItem::createFullAliasItem(const QString &szFullName) { QStringList lNamespaces; QString szName; @@ -173,7 +173,7 @@ KviAliasListViewItem * KviAliasNamespaceListViewItem::createFullAliasItem(const QStringList::Iterator it = lNamespaces.begin(); - KviAliasNamespaceListViewItem * nit = getNamespaceItem(*it); + KviAliasNamespaceTreeWidgetItem * nit = getNamespaceItem(*it); ++it; while(it != lNamespaces.end()) { @@ -184,7 +184,7 @@ KviAliasListViewItem * KviAliasNamespaceListViewItem::createFullAliasItem(const return nit->getAliasItem(szName); } -KviAliasNamespaceListViewItem * KviAliasNamespaceListViewItem::createFullNamespaceItem(const QString &szFullName) +KviAliasNamespaceTreeWidgetItem * KviAliasNamespaceTreeWidgetItem::createFullNamespaceItem(const QString &szFullName) { QStringList lNamespaces; QString szName; @@ -195,7 +195,7 @@ KviAliasNamespaceListViewItem * KviAliasNamespaceListViewItem::createFullNamespa QStringList::Iterator it = lNamespaces.begin(); - KviAliasNamespaceListViewItem * nit = getNamespaceItem(*it); + KviAliasNamespaceTreeWidgetItem * nit = getNamespaceItem(*it); ++it; while(it != lNamespaces.end()) { @@ -205,7 +205,7 @@ KviAliasNamespaceListViewItem * KviAliasNamespaceListViewItem::createFullNamespa return nit->getNamespaceItem(szName); } -KviAliasEditorListView::KviAliasEditorListView(QWidget * par) +KviAliasEditorTreeWidget::KviAliasEditorTreeWidget(QWidget * par) : QTreeWidget(par) { setColumnCount (1); @@ -215,7 +215,7 @@ KviAliasEditorListView::KviAliasEditorListView(QWidget * par) setRootIsDecorated(true); setAnimated(true); } -void KviAliasEditorListView::mousePressEvent (QMouseEvent *e) +void KviAliasEditorTreeWidget::mousePressEvent (QMouseEvent *e) { if (e->button() == Qt::RightButton) { @@ -241,7 +241,7 @@ KviAliasEditor::KviAliasEditor(QWidget * par) box->setSpacing(0); box->setMargin(0); - m_pListView = new KviAliasEditorListView(box); + m_pTreeWidget = new KviAliasEditorTreeWidget(box); box = new KviTalVBox(m_pSplitter); @@ -271,66 +271,66 @@ KviAliasEditor::~KviAliasEditor() KviScriptEditor::destroyInstance(m_pEditor); } -KviAliasNamespaceListViewItem * KviAliasEditor::findNamespaceItem(const QString &szName) +KviAliasNamespaceTreeWidgetItem * KviAliasEditor::findNamespaceItem(const QString &szName) { - int count=m_pListView->topLevelItemCount(); + int count=m_pTreeWidget->topLevelItemCount(); for (int i=0;itopLevelItem(i); + KviAliasNamespaceTreeWidgetItem * item=(KviAliasNamespaceTreeWidgetItem *)m_pTreeWidget->topLevelItem(i); if(KviQString::equalCI(szName,item->name())) return item; } return 0; } -KviAliasNamespaceListViewItem * KviAliasEditor::getNamespaceItem(const QString &szName) +KviAliasNamespaceTreeWidgetItem * KviAliasEditor::getNamespaceItem(const QString &szName) { - KviAliasNamespaceListViewItem * it = findNamespaceItem(szName); + KviAliasNamespaceTreeWidgetItem * it = findNamespaceItem(szName); if(it)return it; - it = new KviAliasNamespaceListViewItem(m_pListView,szName); + it = new KviAliasNamespaceTreeWidgetItem(m_pTreeWidget,szName); return it; } -KviAliasListViewItem * KviAliasEditor::findAliasItemRecursive(KviAliasEditorListViewItem *parent,const QString &szName) +KviAliasTreeWidgetItem * KviAliasEditor::findAliasItemRecursive(KviAliasEditorTreeWidgetItem *parent,const QString &szName) { for (int i=0;ichildCount();i++) { - KviAliasEditorListViewItem *item=(KviAliasEditorListViewItem *)parent->child(i); + KviAliasEditorTreeWidgetItem *item=(KviAliasEditorTreeWidgetItem *)parent->child(i); if (!item->isAlias()){ - KviAliasListViewItem * itemret=findAliasItemRecursive(item,szName); - if (itemret) return (KviAliasListViewItem*)itemret; + KviAliasTreeWidgetItem * itemret=findAliasItemRecursive(item,szName); + if (itemret) return (KviAliasTreeWidgetItem*)itemret; } else{ if(KviQString::equalCI(szName,item->name())) - return (KviAliasListViewItem*)item; + return (KviAliasTreeWidgetItem*)item; } } return false; } -KviAliasListViewItem * KviAliasEditor::findAliasItem(const QString &szName) +KviAliasTreeWidgetItem * KviAliasEditor::findAliasItem(const QString &szName) { - for (int i=0;itopLevelItemCount();i++) + for (int i=0;itopLevelItemCount();i++) { - KviAliasEditorListViewItem *item=(KviAliasEditorListViewItem *)m_pListView->topLevelItem(i); + KviAliasEditorTreeWidgetItem *item=(KviAliasEditorTreeWidgetItem *)m_pTreeWidget->topLevelItem(i); if (!item->isAlias()) { - KviAliasListViewItem * it=findAliasItemRecursive(item,szName); + KviAliasTreeWidgetItem * it=findAliasItemRecursive(item,szName); if (it) return it; } else { - if(KviQString::equalCI(szName,item->name())) return (KviAliasListViewItem*)item; + if(KviQString::equalCI(szName,item->name())) return (KviAliasTreeWidgetItem*)item; } } return false; } -KviAliasListViewItem * KviAliasEditor::getAliasItem(const QString &szName) +KviAliasTreeWidgetItem * KviAliasEditor::getAliasItem(const QString &szName) { - KviAliasListViewItem * it = findAliasItem(szName); + KviAliasTreeWidgetItem * it = findAliasItem(szName); if(it)return it; - it = new KviAliasListViewItem(m_pListView,szName); + it = new KviAliasTreeWidgetItem(m_pTreeWidget,szName); return it; } @@ -347,11 +347,11 @@ void KviAliasEditor::splitFullAliasOrNamespaceName(const QString &szFullName,QSt lNamespaces.removeLast(); } -QString KviAliasEditor::buildFullItemName(KviAliasEditorListViewItem * it) +QString KviAliasEditor::buildFullItemName(KviAliasEditorTreeWidgetItem * it) { if(!it) return QString::null; QString szName = it->name(); - KviAliasNamespaceListViewItem * nit = it->parentNamespaceItem(); + KviAliasNamespaceTreeWidgetItem * nit = it->parentNamespaceItem(); while(nit) { QString tmp = nit->name(); @@ -366,7 +366,7 @@ QString KviAliasEditor::buildFullItemName(KviAliasEditorListViewItem * it) } -KviAliasListViewItem * KviAliasEditor::createFullAliasItem(const QString &szFullName) +KviAliasTreeWidgetItem * KviAliasEditor::createFullAliasItem(const QString &szFullName) { QStringList lNamespaces; QString szName; @@ -377,7 +377,7 @@ KviAliasListViewItem * KviAliasEditor::createFullAliasItem(const QString &szFull QStringList::Iterator it = lNamespaces.begin(); - KviAliasNamespaceListViewItem * nit = getNamespaceItem(*it); + KviAliasNamespaceTreeWidgetItem * nit = getNamespaceItem(*it); ++it; while(it != lNamespaces.end()) { @@ -388,7 +388,7 @@ KviAliasListViewItem * KviAliasEditor::createFullAliasItem(const QString &szFull return nit->getAliasItem(szName); } -KviAliasNamespaceListViewItem * KviAliasEditor::createFullNamespaceItem(const QString &szFullName) +KviAliasNamespaceTreeWidgetItem * KviAliasEditor::createFullNamespaceItem(const QString &szFullName) { QStringList lNamespaces; QString szName; @@ -399,7 +399,7 @@ KviAliasNamespaceListViewItem * KviAliasEditor::createFullNamespaceItem(const QS QStringList::Iterator it = lNamespaces.begin(); - KviAliasNamespaceListViewItem * nit = getNamespaceItem(*it); + KviAliasNamespaceTreeWidgetItem * nit = getNamespaceItem(*it); ++it; while(it != lNamespaces.end()) { @@ -417,7 +417,7 @@ void KviAliasEditor::oneTimeSetup() KviPointerHashTableIterator it(*a); - KviAliasListViewItem * item; + KviAliasTreeWidgetItem * item; while(it.current()) { KviKvsScript * alias = it.current(); @@ -426,21 +426,21 @@ void KviAliasEditor::oneTimeSetup() ++it; } - connect(m_pListView,SIGNAL(currentItemChanged(QTreeWidgetItem *,QTreeWidgetItem *)),this,SLOT(currentItemChanged(QTreeWidgetItem *,QTreeWidgetItem *))); - connect(m_pListView,SIGNAL(rightButtonPressed(QTreeWidgetItem *,QPoint)), + connect(m_pTreeWidget,SIGNAL(currentItemChanged(QTreeWidgetItem *,QTreeWidgetItem *)),this,SLOT(currentItemChanged(QTreeWidgetItem *,QTreeWidgetItem *))); + connect(m_pTreeWidget,SIGNAL(rightButtonPressed(QTreeWidgetItem *,QPoint)), this,SLOT(itemPressed(QTreeWidgetItem *,QPoint))); - connect(m_pListView,SIGNAL(itemChanged(QTreeWidgetItem *,int)),this,SLOT(itemRenamed(QTreeWidgetItem *,int))); + connect(m_pTreeWidget,SIGNAL(itemChanged(QTreeWidgetItem *,int)),this,SLOT(itemRenamed(QTreeWidgetItem *,int))); - m_pListView->sortItems(0,Qt::AscendingOrder); + m_pTreeWidget->sortItems(0,Qt::AscendingOrder); } void KviAliasEditor::itemRenamed(QTreeWidgetItem *it,int col) { - ((KviAliasEditorListViewItem *)it)->setName(it->text(col)); - QString szNam = buildFullItemName((KviAliasEditorListViewItem *)it); + ((KviAliasEditorTreeWidgetItem *)it)->setName(it->text(col)); + QString szNam = buildFullItemName((KviAliasEditorTreeWidgetItem *)it); QString szLabelText; - if(((KviAliasEditorListViewItem *)it)->isNamespace()) + if(((KviAliasEditorTreeWidgetItem *)it)->isNamespace()) szLabelText = __tr2qs("Namespace"); else szLabelText = __tr2qs("Alias"); @@ -453,16 +453,16 @@ bool KviAliasEditor::hasSelectedItemsRecursive(QTreeWidgetItem *it) { for (int i=0;ichildCount();i++) { - if (!it->child(i)->isSelected()) hasSelectedItemsRecursive((KviAliasEditorListViewItem *)it->child(i)); + if (!it->child(i)->isSelected()) hasSelectedItemsRecursive((KviAliasEditorTreeWidgetItem *)it->child(i)); else return true; } return false; } bool KviAliasEditor::hasSelectedItems() { - for (int i=0;itopLevelItemCount();i++) + for (int i=0;itopLevelItemCount();i++) { - if (hasSelectedItemsRecursive(m_pListView->topLevelItem(i))) return true; + if (hasSelectedItemsRecursive(m_pTreeWidget->topLevelItem(i))) return true; } return false; } @@ -471,16 +471,16 @@ bool KviAliasEditor::itemExists(QTreeWidgetItem *pSearchFor) debug("Check if %s exists",pSearchFor->text(0).toUtf8().data()); if(!pSearchFor)return false; - for (int i=0;itopLevelItemCount();i++) + for (int i=0;itopLevelItemCount();i++) { debug("Check in top level %d",i); - if(m_pListView->topLevelItem(i)==pSearchFor) return true; + if(m_pTreeWidget->topLevelItem(i)==pSearchFor) return true; else { - if(!((KviAliasEditorListViewItem *)m_pListView->topLevelItem(i))->isAlias()) + if(!((KviAliasEditorTreeWidgetItem *)m_pTreeWidget->topLevelItem(i))->isAlias()) { - debug ("search into name space %s",m_pListView->topLevelItem(i)->text(0).toUtf8().data()); - if (itemExistsRecursive(pSearchFor,m_pListView->topLevelItem(i))) return true; + debug ("search into name space %s",m_pTreeWidget->topLevelItem(i)->text(0).toUtf8().data()); + if (itemExistsRecursive(pSearchFor,m_pTreeWidget->topLevelItem(i))) return true; } } } @@ -495,7 +495,7 @@ bool KviAliasEditor::itemExistsRecursive(QTreeWidgetItem *pSearchFor,QTreeWidget if(pSearchFor == pSearchAt->child(i))return true; else { - //if(!((KviAliasEditorListViewItem *)pSearchAt->child(i))->isAlias()) + //if(!((KviAliasEditorTreeWidgetItem *)pSearchAt->child(i))->isAlias()) if (pSearchAt->child(i)->childCount()) { if (itemExistsRecursive(pSearchFor,pSearchAt->child(i))) return true; } @@ -508,7 +508,7 @@ void KviAliasEditor::itemPressed(QTreeWidgetItem *it,QPoint pnt) { m_pContextPopup->clear(); - m_pLastClickedItem = (KviAliasEditorListViewItem *)it; + m_pLastClickedItem = (KviAliasEditorTreeWidgetItem *)it; int id; @@ -522,7 +522,7 @@ void KviAliasEditor::itemPressed(QTreeWidgetItem *it,QPoint pnt) __tr2qs("Add Namespace"), this,SLOT(newNamespace())); - bool bHasItems = m_pListView->topLevelItemCount(); + bool bHasItems = m_pTreeWidget->topLevelItemCount(); bool bHasSelected = hasSelectedItems(); m_pContextPopup->insertSeparator(); @@ -571,29 +571,29 @@ void KviAliasEditor::itemPressed(QTreeWidgetItem *it,QPoint pnt) m_pContextPopup->popup(pnt); } -void KviAliasEditor::recursiveSearchReplace(const QString &szSearch,KviAliasEditorListViewItem * it,bool bReplace,const QString &szReplace) +void KviAliasEditor::recursiveSearchReplace(const QString &szSearch,KviAliasEditorTreeWidgetItem * it,bool bReplace,const QString &szReplace) { if(!it)return; for(int i=0;i< it->childCount();i++) { - if(((KviAliasListViewItem *)it->child(i))->isAlias()) + if(((KviAliasTreeWidgetItem *)it->child(i))->isAlias()) { - if(((KviAliasListViewItem *)it->child(i))->buffer().indexOf(szSearch,0,Qt::CaseInsensitive) != -1) + if(((KviAliasTreeWidgetItem *)it->child(i))->buffer().indexOf(szSearch,0,Qt::CaseInsensitive) != -1) { it->child(i)->setIcon(0,QIcon(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_ALIASHIGHLIGHTED)))); - if (bReplace) ((QString &)((KviAliasListViewItem *)it->child(i))->buffer()).replace(szSearch,szReplace,Qt::CaseInsensitive); + if (bReplace) ((QString &)((KviAliasTreeWidgetItem *)it->child(i))->buffer()).replace(szSearch,szReplace,Qt::CaseInsensitive); openParentItems(it); } //else //it->child(i)->setIcon(0,QIcon(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_ALIAS)))); } else { - recursiveSearchReplace(szSearch,(KviAliasEditorListViewItem *)(it->child(i)),bReplace,szReplace); + recursiveSearchReplace(szSearch,(KviAliasEditorTreeWidgetItem *)(it->child(i)),bReplace,szReplace); } } //} - //recursiveSearchReplace(szSearch,(KviAliasEditorListViewItem *)(it->nextSibling()),bReplace,szReplace); + //recursiveSearchReplace(szSearch,(KviAliasEditorTreeWidgetItem *)(it->nextSibling()),bReplace,szReplace); } @@ -615,17 +615,17 @@ void KviAliasEditor::slotFind() if(!bOk)return; if(szSearch.isEmpty())return; m_pEditor->setFindText(szSearch); - for (int i=0;itopLevelItemCount();i++) + for (int i=0;itopLevelItemCount();i++) { - if(((KviAliasListViewItem *)m_pListView->topLevelItem(i))->isAlias()) + if(((KviAliasTreeWidgetItem *)m_pTreeWidget->topLevelItem(i))->isAlias()) { - if(((KviAliasListViewItem *)m_pListView->topLevelItem(i))->buffer().indexOf(szSearch,0,Qt::CaseInsensitive) != -1) + if(((KviAliasTreeWidgetItem *)m_pTreeWidget->topLevelItem(i))->buffer().indexOf(szSearch,0,Qt::CaseInsensitive) != -1) { - m_pListView->topLevelItem(i)->setIcon(0,QIcon(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_ALIASHIGHLIGHTED)))); + m_pTreeWidget->topLevelItem(i)->setIcon(0,QIcon(*(g_pIconManager->getSmallIcon(KVI_SMALLICON_ALIASHIGHLIGHTED)))); } } else { - recursiveSearchReplace(szSearch,(KviAliasEditorListViewItem *)m_pListView->topLevelItem(i)); + recursiveSearchReplace(szSearch,(KviAliasEditorTreeWidgetItem *)m_pTreeWidget->topLevelItem(i)); } } } @@ -634,11 +634,11 @@ void KviAliasEditor::slotFindWord(const QString &szSearch) { m_pEditor->setFindText(szSearch); -// recursiveSearchReplace(szSearch,(KviAliasEditorListViewItem *)m_pListView->firstChild()); +// recursiveSearchReplace(szSearch,(KviAliasEditorTreeWidgetItem *)m_pTreeWidget->firstChild()); } -void KviAliasEditor::recursiveCollapseNamespaces(KviAliasEditorListViewItem * it) +void KviAliasEditor::recursiveCollapseNamespaces(KviAliasEditorTreeWidgetItem * it) { if(!it)return; for (int i=0;ichildCount();i++) @@ -646,32 +646,32 @@ void KviAliasEditor::recursiveCollapseNamespaces(KviAliasEditorListViewItem * it if(it->child(i)->childCount()) { it->child(i)->setExpanded(false); - recursiveCollapseNamespaces((KviAliasEditorListViewItem *)it->child(i)); + recursiveCollapseNamespaces((KviAliasEditorTreeWidgetItem *)it->child(i)); } } -// recursiveCollapseNamespaces((KviAliasEditorListViewItem *)(it->nextSibling())); +// recursiveCollapseNamespaces((KviAliasEditorTreeWidgetItem *)(it->nextSibling())); // it->setExpanded(false); } void KviAliasEditor::slotCollapseNamespaces() { - for (int i=0;itopLevelItemCount();i++) + for (int i=0;itopLevelItemCount();i++) { - if (m_pListView->topLevelItem(i)->childCount()){ - m_pListView->topLevelItem(i)->setExpanded(false); - recursiveCollapseNamespaces((KviAliasEditorListViewItem *)m_pListView->topLevelItem(i)); + if (m_pTreeWidget->topLevelItem(i)->childCount()){ + m_pTreeWidget->topLevelItem(i)->setExpanded(false); + recursiveCollapseNamespaces((KviAliasEditorTreeWidgetItem *)m_pTreeWidget->topLevelItem(i)); } } - //recursiveCollapseNamespaces((KviAliasEditorListViewItem *)m_pListView->firstChild()); + //recursiveCollapseNamespaces((KviAliasEditorTreeWidgetItem *)m_pTreeWidget->firstChild()); } void KviAliasEditor::slotReplaceAll(const QString &before,const QString &after) { - //recursiveSearchReplace(before,(KviAliasEditorListViewItem *)m_pListView->firstChild(),true,after); + //recursiveSearchReplace(before,(KviAliasEditorTreeWidgetItem *)m_pTreeWidget->firstChild(),true,after); } -void KviAliasEditor::getExportAliasBuffer(QString &buffer,KviAliasListViewItem * it) +void KviAliasEditor::getExportAliasBuffer(QString &buffer,KviAliasTreeWidgetItem * it) { QString szBuf = it->buffer(); KviCommandFormatter::blockFromBuffer(szBuf); @@ -699,7 +699,7 @@ void KviAliasEditor::exportSelected() exportAliases(true); } -void KviAliasEditor::exportSelectionInSinglesFiles(KviPointerList *l) +void KviAliasEditor::exportSelectionInSinglesFiles(KviPointerList *l) { if(!m_szDir.endsWith(QString(KVI_PATH_SEPARATOR)))m_szDir += KVI_PATH_SEPARATOR; debug ("dir %s",m_szDir.toUtf8().data()); @@ -722,7 +722,7 @@ void KviAliasEditor::exportSelectionInSinglesFiles(KviPointerListfirst();it;it = l->next()) + for(KviAliasTreeWidgetItem * it = l->first();it;it = l->next()) { QString tmp; getExportAliasBuffer(tmp,it); @@ -754,7 +754,7 @@ void KviAliasEditor::exportAliases(bool bSelectedOnly,bool bSingleFiles) { saveLastEditedItem(); - KviPointerList l; + KviPointerList l; l.setAutoDelete(false); QString out; @@ -767,8 +767,8 @@ void KviAliasEditor::exportAliases(bool bSelectedOnly,bool bSingleFiles) } int count=0; - KviAliasListViewItem * tempitem=0; - for(KviAliasListViewItem * it = l.first();it;it = l.next()) + KviAliasTreeWidgetItem * tempitem=0; + for(KviAliasTreeWidgetItem * it = l.first();it;it = l.next()) { tempitem=it; count ++; @@ -833,55 +833,55 @@ void KviAliasEditor::loadProperties(KviConfig *cfg) m_pSplitter->setSizes(cfg->readIntListEntry("Sizes",def)); QString tmp = cfg->readEntry("LastAlias",QString::null); - KviAliasEditorListViewItem * it = findAliasItem(tmp); + KviAliasEditorTreeWidgetItem * it = findAliasItem(tmp); if(!it)it = findNamespaceItem(tmp); if(it)activateItem(it); } -void KviAliasEditor::appendAliasItems(KviPointerList * l,bool bSelectedOnly) +void KviAliasEditor::appendAliasItems(KviPointerList * l,bool bSelectedOnly) { - for (int i=0;itopLevelItemCount();i++) + for (int i=0;itopLevelItemCount();i++) { - if (((KviAliasListViewItem *)m_pListView->topLevelItem(i))->isAlias()) + if (((KviAliasTreeWidgetItem *)m_pTreeWidget->topLevelItem(i))->isAlias()) { if(bSelectedOnly) { - if(m_pListView->topLevelItem(i)->isSelected()) - l->append(((KviAliasListViewItem *)m_pListView->topLevelItem(i))); + if(m_pTreeWidget->topLevelItem(i)->isSelected()) + l->append(((KviAliasTreeWidgetItem *)m_pTreeWidget->topLevelItem(i))); } else { - l->append(((KviAliasListViewItem *)m_pListView->topLevelItem(i))); + l->append(((KviAliasTreeWidgetItem *)m_pTreeWidget->topLevelItem(i))); } } else { if(bSelectedOnly) { - if(m_pListView->topLevelItem(i)->isSelected()) - appendAliasItemsRecursive(l,m_pListView->topLevelItem(i),false); + if(m_pTreeWidget->topLevelItem(i)->isSelected()) + appendAliasItemsRecursive(l,m_pTreeWidget->topLevelItem(i),false); else - appendAliasItemsRecursive(l,m_pListView->topLevelItem(i),true); + appendAliasItemsRecursive(l,m_pTreeWidget->topLevelItem(i),true); } else - appendAliasItemsRecursive(l,m_pListView->topLevelItem(i),false); + appendAliasItemsRecursive(l,m_pTreeWidget->topLevelItem(i),false); } } } -void KviAliasEditor::appendAliasItemsRecursive(KviPointerList * l,QTreeWidgetItem * pStartFrom,bool bSelectedOnly) +void KviAliasEditor::appendAliasItemsRecursive(KviPointerList * l,QTreeWidgetItem * pStartFrom,bool bSelectedOnly) { for (int i=0;ichildCount();i++) { - if (((KviAliasListViewItem *)pStartFrom->child(i))->isAlias()) + if (((KviAliasTreeWidgetItem *)pStartFrom->child(i))->isAlias()) { if(bSelectedOnly) { if(pStartFrom->child(i)->isSelected()) - l->append((KviAliasListViewItem *)pStartFrom->child(i)); + l->append((KviAliasTreeWidgetItem *)pStartFrom->child(i)); } else { - l->append((KviAliasListViewItem *)pStartFrom->child(i)); + l->append((KviAliasTreeWidgetItem *)pStartFrom->child(i)); } } else @@ -901,51 +901,51 @@ void KviAliasEditor::appendAliasItemsRecursive(KviPointerList * l,bool bSelectedOnly) +void KviAliasEditor::appendNamespaceItems(KviPointerList * l,bool bSelectedOnly) { - for (int i=0;itopLevelItemCount();i++) + for (int i=0;itopLevelItemCount();i++) { - if (((KviAliasListViewItem *)m_pListView->topLevelItem(i))->isNamespace()) + if (((KviAliasTreeWidgetItem *)m_pTreeWidget->topLevelItem(i))->isNamespace()) { if(bSelectedOnly) { - if(m_pListView->topLevelItem(i)->isSelected()) - l->append(((KviAliasListViewItem *)m_pListView->topLevelItem(i))); + if(m_pTreeWidget->topLevelItem(i)->isSelected()) + l->append(((KviAliasTreeWidgetItem *)m_pTreeWidget->topLevelItem(i))); } else { - l->append(((KviAliasListViewItem *)m_pListView->topLevelItem(i))); + l->append(((KviAliasTreeWidgetItem *)m_pTreeWidget->topLevelItem(i))); } } else { if(bSelectedOnly) { - if(m_pListView->topLevelItem(i)->isSelected()) - appendNamespaceItemsRecursive(l,m_pListView->topLevelItem(i),false); + if(m_pTreeWidget->topLevelItem(i)->isSelected()) + appendNamespaceItemsRecursive(l,m_pTreeWidget->topLevelItem(i),false); else - appendNamespaceItemsRecursive(l,m_pListView->topLevelItem(i),true); + appendNamespaceItemsRecursive(l,m_pTreeWidget->topLevelItem(i),true); } else - appendNamespaceItemsRecursive(l,m_pListView->topLevelItem(i),false); + appendNamespaceItemsRecursive(l,m_pTreeWidget->topLevelItem(i),false); } } } -void KviAliasEditor::appendNamespaceItemsRecursive(KviPointerList * l,QTreeWidgetItem * pStartFrom,bool bSelectedOnly) +void KviAliasEditor::appendNamespaceItemsRecursive(KviPointerList * l,QTreeWidgetItem * pStartFrom,bool bSelectedOnly) { for (int i=0;ichildCount();i++) { - if (((KviAliasListViewItem *)pStartFrom->child(i))->isNamespace()) + if (((KviAliasTreeWidgetItem *)pStartFrom->child(i))->isNamespace()) { if(bSelectedOnly) { if(pStartFrom->child(i)->isSelected()) - l->append((KviAliasListViewItem *)pStartFrom->child(i)); + l->append((KviAliasTreeWidgetItem *)pStartFrom->child(i)); } else { - l->append((KviAliasListViewItem *)pStartFrom->child(i)); + l->append((KviAliasTreeWidgetItem *)pStartFrom->child(i)); } } else @@ -964,14 +964,14 @@ void KviAliasEditor::appendNamespaceItemsRecursive(KviPointerList * l,QTreeWidgetItem *it) +void KviAliasEditor::appendSelectedItemsRecursive(KviPointerList * l,QTreeWidgetItem *it) { for (int i=0;ichildCount();i++) { if (it->child(i)->isSelected()) { - l->append((KviAliasEditorListViewItem *)it->child(i)); + l->append((KviAliasEditorTreeWidgetItem *)it->child(i)); } else { @@ -980,32 +980,32 @@ void KviAliasEditor::appendSelectedItemsRecursive(KviPointerList * l) +void KviAliasEditor::appendSelectedItems(KviPointerList * l) { - for (int i=0;itopLevelItemCount();i++) + for (int i=0;itopLevelItemCount();i++) { - if (m_pListView->topLevelItem(i)->isSelected()) + if (m_pTreeWidget->topLevelItem(i)->isSelected()) { - l->append((KviAliasEditorListViewItem *)m_pListView->topLevelItem(i)); + l->append((KviAliasEditorTreeWidgetItem *)m_pTreeWidget->topLevelItem(i)); } else { - if (m_pListView->topLevelItem(i)->childCount()) - appendSelectedItemsRecursive(l,m_pListView->topLevelItem(i)); + if (m_pTreeWidget->topLevelItem(i)->childCount()) + appendSelectedItemsRecursive(l,m_pTreeWidget->topLevelItem(i)); } } } -void KviAliasEditor::removeItemChildren(KviAliasEditorListViewItem *it) +void KviAliasEditor::removeItemChildren(KviAliasEditorTreeWidgetItem *it) { debug("Deleting"); for (int i=0;ichildCount();i++) { - if (it->child(i)->childCount()) removeItemChildren((KviAliasEditorListViewItem *)it->child(i)); + if (it->child(i)->childCount()) removeItemChildren((KviAliasEditorTreeWidgetItem *)it->child(i)); delete it->child(i); } } -bool KviAliasEditor::removeItem(KviAliasEditorListViewItem *it,bool * pbYesToAll,bool bDeleteEmptyTree) +bool KviAliasEditor::removeItem(KviAliasEditorTreeWidgetItem *it,bool * pbYesToAll,bool bDeleteEmptyTree) { if(!it)return true; QString szMsg; @@ -1051,7 +1051,7 @@ bool KviAliasEditor::removeItem(KviAliasEditorListViewItem *it,bool * pbYesToAll { while(it) { - KviAliasEditorListViewItem * par = (KviAliasEditorListViewItem *)(it->parent()); + KviAliasEditorTreeWidgetItem * par = (KviAliasEditorTreeWidgetItem *)(it->parent()); delete it; if(par) { @@ -1070,12 +1070,12 @@ bool KviAliasEditor::removeItem(KviAliasEditorListViewItem *it,bool * pbYesToAll void KviAliasEditor::removeSelectedItems() { - KviPointerList l; + KviPointerList l; l.setAutoDelete(false); appendSelectedItems(&l); bool bYesToAll = false; - for(KviAliasEditorListViewItem *it = l.first();it;it = l.next()) + for(KviAliasEditorTreeWidgetItem *it = l.first();it;it = l.next()) { if(!removeItem(it,&bYesToAll,false))return; } @@ -1244,8 +1244,8 @@ void KviAliasEditor::selectOneItem(QTreeWidgetItem * it,QTreeWidgetItem *pStartF void KviAliasEditor::activateItem(QTreeWidgetItem * it) { openParentItems(it); - //selectOneItem(it,m_pListView->child(0)); - m_pListView->setCurrentItem(it); + //selectOneItem(it,m_pTreeWidget->child(0)); + m_pTreeWidget->setCurrentItem(it); } void KviAliasEditor::newAlias() @@ -1260,12 +1260,12 @@ void KviAliasEditor::newAlias() QString szNewName = askForAliasName(__tr2qs("Add Alias"),__tr2qs("Please enter the name for the new alias"),"myfunction"); if(szNewName.isEmpty())return; - getUniqueItemName(m_pLastClickedItem,szNewName,KviAliasEditorListViewItem::Alias); + getUniqueItemName(m_pLastClickedItem,szNewName,KviAliasEditorTreeWidgetItem::Alias); - KviAliasListViewItem * it; + KviAliasTreeWidgetItem * it; if(m_pLastClickedItem) - it = ((KviAliasNamespaceListViewItem *)m_pLastClickedItem)->createFullAliasItem(szNewName); + it = ((KviAliasNamespaceTreeWidgetItem *)m_pLastClickedItem)->createFullAliasItem(szNewName); else it = createFullAliasItem(szNewName); @@ -1285,12 +1285,12 @@ void KviAliasEditor::newNamespace() QString szNewName = askForNamespaceName(__tr2qs("Add Namespace"),__tr2qs("Please enter the name for the new namespace"),"mynamespace"); if(szNewName.isEmpty())return; - getUniqueItemName(m_pLastClickedItem,szNewName,KviAliasEditorListViewItem::Namespace); + getUniqueItemName(m_pLastClickedItem,szNewName,KviAliasEditorTreeWidgetItem::Namespace); - KviAliasNamespaceListViewItem * it; + KviAliasNamespaceTreeWidgetItem * it; if(m_pLastClickedItem) - it = ((KviAliasNamespaceListViewItem *)m_pLastClickedItem)->createFullNamespaceItem(szNewName); + it = ((KviAliasNamespaceTreeWidgetItem *)m_pLastClickedItem)->createFullNamespaceItem(szNewName); else it = createFullNamespaceItem(szNewName); @@ -1299,11 +1299,11 @@ void KviAliasEditor::newNamespace() bool KviAliasEditor::aliasExists(QString &szFullItemName) { - KviPointerList l; + KviPointerList l; l.setAutoDelete(false); appendAliasItems(&l,false); - for(KviAliasListViewItem * it = l.first();it;it = l.next()) + for(KviAliasTreeWidgetItem * it = l.first();it;it = l.next()) { if (KviQString::equalCI(buildFullItemName(it),szFullItemName)) { @@ -1315,11 +1315,11 @@ bool KviAliasEditor::aliasExists(QString &szFullItemName) bool KviAliasEditor::namespaceExists(QString &szFullItemName) { - KviPointerList l; + KviPointerList l; l.setAutoDelete(false); appendNamespaceItems(&l,false); - for(KviAliasListViewItem * it = l.first();it;it = l.next()) + for(KviAliasTreeWidgetItem * it = l.first();it;it = l.next()) { if (KviQString::equalCI(buildFullItemName(it),szFullItemName)) { @@ -1329,11 +1329,11 @@ bool KviAliasEditor::namespaceExists(QString &szFullItemName) return false; } /* -void KviAliasEditor::appendItems(KviPointerList * l,QTreeWidgetItem *it) +void KviAliasEditor::appendItems(KviPointerList * l,QTreeWidgetItem *it) { for (int i=0;ichildCount();i++) { - l->append((KviAliasEditorListViewItem *) it->child(i); + l->append((KviAliasEditorTreeWidgetItem *) it->child(i); if(it->child(i)->childCount()) appendItemd(it->child(i)); } } @@ -1404,7 +1404,7 @@ void KviAliasEditor::renameItem() } */ /* for(it = lChildren.first();it;it = lChildren.next()) - m_pListView->takeItem(it); + m_pTreeWidget->takeItem(it); */ bool bYesToAll = true; removeItem(m_pLastEditedItem,&bYesToAll,true); @@ -1414,18 +1414,18 @@ void KviAliasEditor::renameItem() if(bAlias) { - KviAliasListViewItem * ait = createFullAliasItem(szNewName); + KviAliasTreeWidgetItem * ait = createFullAliasItem(szNewName); ait->setBuffer(szCode); ait->setCursorPosition(pntCursor); activateItem(ait); } else { - KviAliasNamespaceListViewItem * nit = createFullNamespaceItem(szNewName); + KviAliasNamespaceTreeWidgetItem * nit = createFullNamespaceItem(szNewName); activateItem(nit); for(int i=0;isetParentNamespaceItem(nit); + ((KviAliasEditorTreeWidgetItem*)lChildren.at(i))->setParentNamespaceItem(nit); nit->insertChild(nit->childCount(),lChildren.at(i)); } @@ -1440,21 +1440,21 @@ void KviAliasEditor::saveLastEditedItem() if(!m_pEditor->isModified()){debug ("Alreary saved");return;} // nothing to save if(!itemExists(m_pLastEditedItem)){debug("Item does not exists");return;} // dead ? debug("Check last edit item %s",m_pLastEditedItem->text(0).toUtf8().data()); - ((KviAliasListViewItem *)m_pLastEditedItem)->setCursorPosition(m_pEditor->getCursor()); + ((KviAliasTreeWidgetItem *)m_pLastEditedItem)->setCursorPosition(m_pEditor->getCursor()); if(m_pLastEditedItem->isNamespace()){debug("Is namespace");return;} QString newCode; m_pEditor->getText(newCode); debug("Saving %s",newCode.toUtf8().data()); - ((KviAliasListViewItem *)m_pLastEditedItem)->setBuffer(newCode); + ((KviAliasTreeWidgetItem *)m_pLastEditedItem)->setBuffer(newCode); } void KviAliasEditor::currentItemChanged(QTreeWidgetItem *it,QTreeWidgetItem *prev) { saveLastEditedItem(); - m_pLastEditedItem = (KviAliasEditorListViewItem *)it; + m_pLastEditedItem = (KviAliasEditorTreeWidgetItem *)it; if(!m_pLastEditedItem) { @@ -1485,14 +1485,14 @@ void KviAliasEditor::currentItemChanged(QTreeWidgetItem *it,QTreeWidgetItem *pre szLabelText += ""; m_pNameLabel->setText(szLabelText); m_pRenameButton->setEnabled(true); - m_pEditor->setText(((KviAliasListViewItem *)it)->buffer()); + m_pEditor->setText(((KviAliasTreeWidgetItem *)it)->buffer()); m_pEditor->setFocus(); - m_pEditor->setCursorPosition(((KviAliasListViewItem *)it)->cursorPosition()); + m_pEditor->setCursorPosition(((KviAliasTreeWidgetItem *)it)->cursorPosition()); m_pEditor->setEnabled(true); } -void KviAliasEditor::recursiveCommit(KviAliasEditorListViewItem * it) +void KviAliasEditor::recursiveCommit(KviAliasEditorTreeWidgetItem * it) { if(!it)return; if(it->isAlias()) @@ -1502,14 +1502,14 @@ void KviAliasEditor::recursiveCommit(KviAliasEditorListViewItem * it) //debug("ADDING %s",szName.latin1()); // WARNING: On MSVC operator new here is valid ONLY because // KviKvsScript has a non virtual detructor! - KviKvsScript * a = new KviKvsScript(szName,((KviAliasListViewItem *)it)->buffer()); + KviKvsScript * a = new KviKvsScript(szName,((KviAliasTreeWidgetItem *)it)->buffer()); KviKvsAliasManager::instance()->add(szName,a); return; } else { for (int i=0;ichildCount();i++) { - recursiveCommit((KviAliasEditorListViewItem *) it->child(i)); + recursiveCommit((KviAliasEditorTreeWidgetItem *) it->child(i)); } } } @@ -1518,20 +1518,20 @@ void KviAliasEditor::commit() { saveLastEditedItem(); KviKvsAliasManager::instance()->clear(); - for(int i=0;itopLevelItemCount();i++) + for(int i=0;itopLevelItemCount();i++) { - KviAliasEditorListViewItem *item=(KviAliasEditorListViewItem *)m_pListView->topLevelItem(i); + KviAliasEditorTreeWidgetItem *item=(KviAliasEditorTreeWidgetItem *)m_pTreeWidget->topLevelItem(i); recursiveCommit(item); } g_pApp->saveAliases(); } -void KviAliasEditor::getUniqueItemName(KviAliasEditorListViewItem *item,QString &buffer,KviAliasEditorListViewItem::Type eType) +void KviAliasEditor::getUniqueItemName(KviAliasEditorTreeWidgetItem *item,QString &buffer,KviAliasEditorTreeWidgetItem::Type eType) { QString ret; int idx = 0; - KviAliasEditorListViewItem * found; + KviAliasEditorTreeWidgetItem * found; for(;;) { @@ -1551,12 +1551,12 @@ void KviAliasEditor::getUniqueItemName(KviAliasEditorListViewItem *item,QString return; } - if(eType == KviAliasEditorListViewItem::Namespace) - found = ((KviAliasNamespaceListViewItem *)item)->findNamespaceItem(ret); + if(eType == KviAliasEditorTreeWidgetItem::Namespace) + found = ((KviAliasNamespaceTreeWidgetItem *)item)->findNamespaceItem(ret); else - found = ((KviAliasNamespaceListViewItem *)item)->findAliasItem(ret); + found = ((KviAliasNamespaceTreeWidgetItem *)item)->findAliasItem(ret); } else { - if(eType == KviAliasEditorListViewItem::Namespace) + if(eType == KviAliasEditorTreeWidgetItem::Namespace) found = findNamespaceItem(ret); else found = findAliasItem(ret); diff --git a/src/modules/aliaseditor/aliaseditor.h b/src/modules/aliaseditor/aliaseditor.h index a8a861c5f..449516dea 100644 --- a/src/modules/aliaseditor/aliaseditor.h +++ b/src/modules/aliaseditor/aliaseditor.h @@ -29,7 +29,6 @@ #include "kvi_pointerlist.h" #include "kvi_tal_popupmenu.h" #include "kvi_heapobject.h" -//#include "kvi_tal_listview.h" #include #include @@ -40,20 +39,20 @@ class QSplitter; class KviScriptEditor; -class KviAliasNamespaceListViewItem; +class KviAliasNamespaceTreeWidgetItem; +class KviAliasTreeWidgetItem; - -class KviAliasEditorListViewItem : public QTreeWidgetItem, public KviHeapObject +class KviAliasEditorTreeWidgetItem : public QTreeWidgetItem, public KviHeapObject { public: enum Type { Alias, Namespace }; public: - KviAliasEditorListViewItem(QTreeWidget * pListView,Type eType,const QString &szName); - KviAliasEditorListViewItem(KviAliasNamespaceListViewItem * pParentNamespaceItem,Type eType,const QString &szName); - ~KviAliasEditorListViewItem(){}; + KviAliasEditorTreeWidgetItem(QTreeWidget * pTreeWidget,Type eType,const QString &szName); + KviAliasEditorTreeWidgetItem(KviAliasNamespaceTreeWidgetItem * pParentNamespaceItem,Type eType,const QString &szName); + ~KviAliasEditorTreeWidgetItem(){}; protected: Type m_eType; - KviAliasNamespaceListViewItem * m_pParentNamespaceItem; + KviAliasNamespaceTreeWidgetItem * m_pParentNamespaceItem; QString m_szName; public: const QString & name(){ return m_szName; }; @@ -61,35 +60,34 @@ public: Type type(){ return m_eType; }; bool isAlias(){ return m_eType == Alias; }; bool isNamespace(){ return m_eType == Namespace; }; - void setParentNamespaceItem(KviAliasNamespaceListViewItem* it){ m_pParentNamespaceItem=it; }; - KviAliasNamespaceListViewItem * parentNamespaceItem(){ return m_pParentNamespaceItem; }; + void setParentNamespaceItem(KviAliasNamespaceTreeWidgetItem* it){ m_pParentNamespaceItem=it; }; + KviAliasNamespaceTreeWidgetItem * parentNamespaceItem(){ return m_pParentNamespaceItem; }; virtual QString key(int column,bool bAsc) const; }; -class KviAliasListViewItem; -class KviAliasNamespaceListViewItem : public KviAliasEditorListViewItem +class KviAliasNamespaceTreeWidgetItem : public KviAliasEditorTreeWidgetItem { public: - KviAliasNamespaceListViewItem(QTreeWidget * pListView,const QString &szName); - KviAliasNamespaceListViewItem(KviAliasNamespaceListViewItem * pParentNamespace,const QString &szName); - ~KviAliasNamespaceListViewItem(); + KviAliasNamespaceTreeWidgetItem(QTreeWidget * pTreeWidget,const QString &szName); + KviAliasNamespaceTreeWidgetItem(KviAliasNamespaceTreeWidgetItem * pParentNamespace,const QString &szName); + ~KviAliasNamespaceTreeWidgetItem(); public: - KviAliasNamespaceListViewItem * findNamespaceItem(const QString &szName); - KviAliasNamespaceListViewItem * getNamespaceItem(const QString &szName); - KviAliasListViewItem * findAliasItem(const QString &szName); - KviAliasListViewItem * getAliasItem(const QString &szName); - KviAliasListViewItem * createFullAliasItem(const QString &szFullName); - KviAliasNamespaceListViewItem * createFullNamespaceItem(const QString &szFullName); + KviAliasNamespaceTreeWidgetItem * findNamespaceItem(const QString &szName); + KviAliasNamespaceTreeWidgetItem * getNamespaceItem(const QString &szName); + KviAliasTreeWidgetItem * findAliasItem(const QString &szName); + KviAliasTreeWidgetItem * getAliasItem(const QString &szName); + KviAliasTreeWidgetItem * createFullAliasItem(const QString &szFullName); + KviAliasNamespaceTreeWidgetItem * createFullNamespaceItem(const QString &szFullName); }; -class KviAliasEditorListView : public QTreeWidget +class KviAliasEditorTreeWidget : public QTreeWidget { Q_OBJECT public: - KviAliasEditorListView(QWidget*); - ~KviAliasEditorListView(){}; + KviAliasEditorTreeWidget(QWidget*); + ~KviAliasEditorTreeWidget(){}; protected: void mousePressEvent (QMouseEvent *e); signals: @@ -97,12 +95,13 @@ signals: }; -class KviAliasListViewItem : public KviAliasEditorListViewItem + +class KviAliasTreeWidgetItem : public KviAliasEditorTreeWidgetItem { public: - KviAliasListViewItem(KviAliasNamespaceListViewItem * pParentNamespace,const QString &szName); - KviAliasListViewItem(QTreeWidget *pListView,const QString &szName); - ~KviAliasListViewItem(); + KviAliasTreeWidgetItem(KviAliasNamespaceTreeWidgetItem * pParentNamespace,const QString &szName); + KviAliasTreeWidgetItem(QTreeWidget *pTreeWidget,const QString &szName); + ~KviAliasTreeWidgetItem(); public: QString m_szBuffer; int m_cPos; @@ -121,12 +120,12 @@ public: ~KviAliasEditor(); public: KviScriptEditor * m_pEditor; - KviAliasEditorListView * m_pListView; + KviAliasEditorTreeWidget * m_pTreeWidget; QLabel * m_pNameLabel; QPushButton * m_pRenameButton; - KviAliasEditorListViewItem * m_pLastEditedItem; - KviAliasEditorListViewItem * m_pLastClickedItem; - //KviAliasListViewItem * m_pLastEditedItem; + KviAliasEditorTreeWidgetItem * m_pLastEditedItem; + KviAliasEditorTreeWidgetItem * m_pLastClickedItem; + //KviAliasTreeWidgetItem * m_pLastEditedItem; KviTalPopupMenu * m_pContextPopup; QSplitter * m_pSplitter; QString m_szDir; @@ -134,7 +133,7 @@ public: //bool modified(){ return m_bModified; }; void commit(); void exportAliases(bool,bool=false); - void exportSelectionInSinglesFiles(KviPointerList *l); + void exportSelectionInSinglesFiles(KviPointerList *l); void saveProperties(KviConfig *); void loadProperties(KviConfig *); @@ -155,27 +154,27 @@ protected slots: void slotReplaceAll(const QString &before,const QString &after); void itemRenamed(QTreeWidgetItem *it,int col); protected: -// QString const & findWord(const QString &txt,bool); - void recursiveCollapseNamespaces(KviAliasEditorListViewItem * it); - void recursiveSearchReplace(const QString &szSearch,KviAliasEditorListViewItem * it,bool bReplace=false,const QString &szReplace="n"); + //QString const & findWord(const QString &txt,bool); + void recursiveCollapseNamespaces(KviAliasEditorTreeWidgetItem * it); + void recursiveSearchReplace(const QString &szSearch,KviAliasEditorTreeWidgetItem * it,bool bReplace=false,const QString &szReplace="n"); - void recursiveCommit(KviAliasEditorListViewItem * it); - void getExportAliasBuffer(QString &buffer,KviAliasListViewItem * it); + void recursiveCommit(KviAliasEditorTreeWidgetItem * it); + void getExportAliasBuffer(QString &buffer,KviAliasTreeWidgetItem * it); void oneTimeSetup(); void selectOneItem(QTreeWidgetItem * it,QTreeWidgetItem *pStartFrom); void saveLastEditedItem(); - void getUniqueItemName(KviAliasEditorListViewItem *item,QString &buffer,KviAliasEditorListViewItem::Type eType); - void appendSelectedItems(KviPointerList * l); - void appendSelectedItemsRecursive(KviPointerList * l,QTreeWidgetItem *it); + void getUniqueItemName(KviAliasEditorTreeWidgetItem *item,QString &buffer,KviAliasEditorTreeWidgetItem::Type eType); + void appendSelectedItems(KviPointerList * l); + void appendSelectedItemsRecursive(KviPointerList * l,QTreeWidgetItem *it); - void appendAliasItems(KviPointerList * l,bool bSelectedOnly); - void appendAliasItemsRecursive(KviPointerList * l,QTreeWidgetItem * pStartFrom,bool bSelectedOnly); - void appendNamespaceItemsRecursive(KviPointerList * l,QTreeWidgetItem * pStartFrom,bool bSelectedOnly); - void appendNamespaceItems(KviPointerList * l,bool bSelectedOnly); + void appendAliasItems(KviPointerList * l,bool bSelectedOnly); + void appendAliasItemsRecursive(KviPointerList * l,QTreeWidgetItem * pStartFrom,bool bSelectedOnly); + void appendNamespaceItemsRecursive(KviPointerList * l,QTreeWidgetItem * pStartFrom,bool bSelectedOnly); + void appendNamespaceItems(KviPointerList * l,bool bSelectedOnly); - //void appendNamespaceItems(KviPointerList * l,KviAliasEditorListViewItem * pStartFrom,bool bSelectedOnly); - bool removeItem(KviAliasEditorListViewItem *it,bool * pbYesToAll,bool bDeleteEmptyTree); - void removeItemChildren(KviAliasEditorListViewItem *it); + //void appendNamespaceItems(KviPointerList * l,KviAliasEditorTreeWidgetItem * pStartFrom,bool bSelectedOnly); + bool removeItem(KviAliasEditorTreeWidgetItem *it,bool * pbYesToAll,bool bDeleteEmptyTree); + void removeItemChildren(KviAliasEditorTreeWidgetItem *it); void openParentItems(QTreeWidgetItem * it); void activateItem(QTreeWidgetItem * it); @@ -187,14 +186,14 @@ protected: bool aliasExists(QString &szFullItemName); bool hasSelectedItems(); bool hasSelectedItemsRecursive(QTreeWidgetItem *); - KviAliasNamespaceListViewItem * findNamespaceItem(const QString &szName); - KviAliasNamespaceListViewItem * getNamespaceItem(const QString &szName); - KviAliasListViewItem * findAliasItem(const QString &szName); - KviAliasListViewItem * findAliasItemRecursive(KviAliasEditorListViewItem *it,const QString &szName); - KviAliasListViewItem * getAliasItem(const QString &szName); - KviAliasListViewItem * createFullAliasItem(const QString &szFullName); - KviAliasNamespaceListViewItem * createFullNamespaceItem(const QString &szFullName); - QString buildFullItemName(KviAliasEditorListViewItem * it); + KviAliasNamespaceTreeWidgetItem * findNamespaceItem(const QString &szName); + KviAliasNamespaceTreeWidgetItem * getNamespaceItem(const QString &szName); + KviAliasTreeWidgetItem * findAliasItem(const QString &szName); + KviAliasTreeWidgetItem * findAliasItemRecursive(KviAliasEditorTreeWidgetItem *it,const QString &szName); + KviAliasTreeWidgetItem * getAliasItem(const QString &szName); + KviAliasTreeWidgetItem * createFullAliasItem(const QString &szFullName); + KviAliasNamespaceTreeWidgetItem * createFullNamespaceItem(const QString &szFullName); + QString buildFullItemName(KviAliasEditorTreeWidgetItem * it); }; diff --git a/src/modules/objects/CMakeLists.txt b/src/modules/objects/CMakeLists.txt index 9c713ba83..80bfdd078 100644 --- a/src/modules/objects/CMakeLists.txt +++ b/src/modules/objects/CMakeLists.txt @@ -16,8 +16,6 @@ SET(kviobjects_MOC_HDRS class_http.h class_lineedit.h class_listbox.h - class_listview.h - class_listviewitem.h class_multilineedit.h class_painter.h class_pixmap.h @@ -31,6 +29,8 @@ SET(kviobjects_MOC_HDRS class_tbrowser.h class_toolbar.h class_toolbutton.h + class_treewidget.h + class_treewidgetitem.h class_widget.h class_window.h class_wizard.h @@ -49,6 +49,7 @@ SET(kviobjects_SRCS class_file.cpp class_ftp.cpp class_groupbox.cpp + class_hbox.cpp class_http.cpp class_label.cpp class_layout.cpp @@ -56,11 +57,11 @@ SET(kviobjects_SRCS class_lineedit.cpp class_list.cpp class_listbox.cpp - class_listview.cpp - class_listviewitem.cpp class_mainwindow.cpp class_menubar.cpp class_multilineedit.cpp + class_painter.cpp + class_pixmap.cpp class_popupmenu.cpp class_process.cpp class_progressbar.cpp @@ -69,19 +70,18 @@ SET(kviobjects_SRCS class_socket.cpp class_spinbox.cpp class_tabwidget.cpp + class_tbrowser.cpp class_toolbar.cpp class_toolbutton.cpp - class_painter.cpp - class_pixmap.cpp - class_tbrowser.cpp + class_treewidget.cpp + class_treewidgetitem.cpp + class_vbox.cpp class_widget.cpp class_window.cpp class_wizard.cpp class_workspace.cpp class_wrapper.cpp class_xmlreader.cpp - class_vbox.cpp - class_hbox.cpp ) # After this call, files will be moc'ed to moc_kvi_*.cpp diff --git a/src/modules/objects/class_listview.cpp b/src/modules/objects/class_listview.cpp deleted file mode 100644 index 2936b9ac7..000000000 --- a/src/modules/objects/class_listview.cpp +++ /dev/null @@ -1,650 +0,0 @@ -//============================================================================= -// -// File : class_listview.cpp -// Creation date : Fri Jan 28 14:21:48 CEST 2005 -// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) -// -// This file is part of the KVirc irc client distribution -// Copyright (C) 2005-2008 Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -//============================================================================= - -#include "class_listview.h" - -#include "kvi_error.h" -#include "kvi_debug.h" -#include "kvi_locale.h" -#include "kvi_iconmanager.h" -#include "kvi_tal_treewidget.h" - -// FIXME: fix the doc (function QT4 renamed) -// OLD: -// itemRenamed signal -// itemRenamed event -// NEW: -// itemActivated signal -// itemActavatedEvent - - -#include -#include -#include -#include - -/* - @doc: treewidget - @keyterms: - treewidget widget class - @title: - treewidget class - @type: - class - @short: - A treewidget class - @inherits: - [class]widget[/class] - @description: - It can display and control a hierarchy of multi-column items, and provides the ability to add new items at any time. - The items are added by creating children [class]treewidgetitem[/class] objects: simply allocating them with $new - will add the items to the treewidget and simply deleting them will remove them. - Allocating a [class]treewidgetitem[/class] item2 as a child of item1 will insert it to the same treewidget creating - a subtree of items spannig from item1. The subtree can be opened or closed by a simple click either - on the parent item or on the little plus sign on the side of it (when [classfnc:treewidget]$setRootIsDecorated[/classfnc] - is set to $true. The treewidget can be in Single, Multi, Extended or NoSelection selection mode. - In single selection mode there can be only one selected item at a time and the selected item is also - the current item (this mode is the default). In Multi and Extended selection mode there can be multiple selected items - and the current item is one of them. The difference between Multi and Extended is in the way - that items can be selected by the mouse actions: experiment with the two modes :). - The NoSelection mode has obviously no selection at all. - @functions: - !fn: $addColumn( ) - Adds a width pixels wide column with the column header label to the list view. - - !fn: $setSorting(,) - Sets the list view to be sorted by column column in ascending order if ascending is 1 or descending order if it is FALSE. - If column is -1, sorting is disabled and the user cannot sort columns by clicking on the column headers - - !fn: $hideListViewHeader() - Hide the treewidget column header. - - !fn: $showListViewHeader() - Show the treewidget column header. - - !fn: $isListViewHeaderVisible() - Returns '1' if the treewidget header is currently visible. Otherwise this function returns '0'. - - !fn: $setAllColumnsShowFocus() - When the argument is $true, causes the treewidget to display the focus and selection - by highlighting all the columns of the item. When the argument is $false then - only the first column is selected/highlighted. - - !fn: $setSelectionMode() - Sets the selection mode for this treewidget. can be one of "Single","NoSelection","Multi" or "Extended". - - !fn: $selectedItem() - Returns the currently selected [class]treewidgetitem[/class] or $null if no items are selected. - This function works only if the list view is in single selection mode. - - !fn: $currentItem() - Returns the current [class]treewidgetitem[/class] or $null if no item is current at the moment. - - !fn: $firstChild() - Returns the first child [class]treewidgetitem[/class] of this treewidget or $null if there are no items at all. - - !fn: $clickEvent() - This function is called when the user clicks in the list view. - In its argument the [class]treewidgetitem[/class] object clicked or 0 if the user didn't click on an item.[br] - The default implementation emits the [classfnc]$clicked[/classfnc]() signal. - - !fn: $selectionChangedEvent() - This event handle whenever the set of selected items has changed. - The argument is the newly selected item if the treewidget is in single selection mode.[br] - When the treewidget is in Multi or Extended selection mode then item is always $null.[br] - The default implementation emits the [classfnc]$selectionChanged[/classfnc]() signal. - - !fn: $currentChangedEvent() - This event are called whenever the current item has changed. - In its argument is the newly selected item or 0 if the change made no item current.[br] - The default implementation emits the [classfnc]$currentChanged[/classfnc]() signal. - - !fn: $returnPressedEvent() - This function is called by the framework when the enter key is pressed.[br] - In its arument the currrent item.[br] - The default implementation emits the [classfnc]$returnPressed[/classfnc]() signal. - - !fn: $spacePressedEvent() - This function is called by the framework when the space key is pressed.[br] - In its arument the currrent item.[br] - The default implementation emits the [classfnc]$spacePressed[/classfnc]() signal. - - !fn: $onItemEvent() - This event is called when an item has been expanded, i.e. when the children of item are shown. - The default implementation emits the [classfnc]$expanded[/classfnc]() signal. - - !fn: $itemCollapsedEvent() - This event is called when an item has been collapsed, i.e. when the children of item are hidden. - The default implementation emits the [classfnc]$collapsed[/classfnc]() signal. - - !fn: $itemRenamedEvent(,,) - This event is called when the item has been renamed in text, e.g. by in in-place renaming, in column col.[br] - The default implementation emits the [classfnc]$itemRenamed[/classfnc]() signal. - - !fn: $rightButtonClickEvent(,,>y:integer>) - This signal is emitted when the right button is clicked.[br] - The arguments are the relevant item (may be 0), the point in global coordinates and the relevant column (or -1 if the click was outside the list). - The default implementation emits the [classfnc]$rightButtonClicked[/classfnc]() signal. - @signals: - !sg: $clicked() - This signal is emitted by the default implementation of [classfnc]$clickEvent[/classfnc](). - !sg: $selectionChanged() - This signal is emitted by the default implementation of [classfnc]$selectionChangedEvent[/classfnc](). - !sg: $currentChanged() - This signal is emitted by the default implementation of [classfnc]$currentChangedEvent[/classfnc](). - !sg: $returnPressed() - This signal is emitted by the default implementation of [classfnc]$returnPressedEvent[/classfnc](). - !sg: $spacePressed() - This signal is emitted by the default implementation of [classfnc]$spacePredssedEvent[/classfnc](). - !sg: $onItem() - This signal is emitted by the default implementation of [classfnc]$onItemEvent[/classfnc](). - !sg: $itemExpanded() - This signal is emitted by the default implementation of [classfnc]$itemExpandedEvent[/classfnc](). - !sg: $itemCollapsed() - This signal is emitted by the default implementation of [classfnc]$itemCollapsedEvent[/classfnc](). - !sg: $itemRenamed() - This signal is emitted by the default implementation of [classfnc]$itemRenamedEvent[/classfnc](). - !sg: $rightButtonClicked() - This signal is emitted by the default implementation of [classfnc]$rightButtonClickedEvent[/classfnc](). - - -*/ - -//--------------------------------------------------------------------------------- - -KVSO_BEGIN_REGISTERCLASS(KviKvsObject_treewidget,"listview","widget") - - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"setHeaderLabels",function_setHeaderLabels) - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"addColumn",function_addColumn) - - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"setColumnText",function_setColumnText) - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"setColumnCount",function_setColumnCount) - - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"setSorting",function_setSorting) - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"setRootIsDecorated",function_setRootIsDecorated) - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"setAllColumnsShowFocus",function_setAllColumnsShowFocus) - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"clear",function_clear) - //FIXME - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"selectedItem",function_selectedItems)//<--- remove this - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"selectedItems",function_selectedItems) - - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"currentItem",function_currentItem) - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"setSelectionMode",function_setSelectionMode) - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"listViewHeaderIsVisible",function_listViewHeaderIsVisible) - - - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"hideListViewHeader",function_hideListViewHeader) - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"showListViewHeader",function_showListViewHeader) - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"firstChild",function_firstChild) - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"selectionChangedEvent",function_selectionChangedEvent); - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"currentChangedEvent",function_currentChangedEvent); - - // FIX-ME - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"returnPressedEvent",function_itemActivatedEvent);//<- remove me - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"itemActivatedEvent",function_itemActivatedEvent); - // - -// KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"spacePressedEvent",function_spacePressedEvent); - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"onItemEvent",function_onItemEvent); - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"itemClickedEvent",function_itemClickedEvent); - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"itemExpandedEvent",function_itemExpandedEvent); - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"itemCollapsedEvent",function_itemCollapsedEvent); - - //FIXME - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"itemRenamedEvent",function_itemChangedEvent);//<- remove me - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"itemChangedEvent",function_itemChangedEvent); - // - - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"rightButtonClickedEvent",function_customContextMenuRequestedEvent); - KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"customContextMenuRequestedEvent",function_customContextMenuRequestedEvent); - - KVSO_REGISTER_STANDARD_NOTHINGRETURN_HANDLER(KviKvsObject_treewidget,"fileDroppedEvent") - -KVSO_END_REGISTERCLASS(KviKvsObject_treewidget) - -KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_treewidget,KviKvsObject_widget) - -KVSO_END_CONSTRUCTOR(KviKvsObject_treewidget) - - -KVSO_BEGIN_DESTRUCTOR(KviKvsObject_treewidget) - -KVSO_END_CONSTRUCTOR(KviKvsObject_treewidget) - -bool KviKvsObject_treewidget::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) -{ - setObject(new KviKvsMdmListView(parentScriptWidget(),getName().toUtf8().data(),this),true); - - // hack for compatibility with "old" addColumn method; - ((KviTalTreeWidget*) widget())->setColumnCount(0); - - connect(widget(),SIGNAL(itemClicked(KviTalTreeWidgetItem *,int)),this,SLOT(slotClicked(KviTalTreeWidgetItem *,int))); - connect(widget(),SIGNAL(itemSelectionChanged()),this,SLOT(slotSelectionChanged())); - connect(widget(),SIGNAL(currentItemChanged(KviTalTreeWidgetItem *,KviTalTreeWidgetItem *)),this,SLOT(slotCurrentChanged(KviTalTreeWidgetItem *,KviTalTreeWidgetItem *))); - connect(widget(),SIGNAL(itemActivated(KviTalTreeWidgetItem *,int)),this,SLOT(slotItemActivated(KviTalTreeWidgetItem *,int))); - connect(widget(),SIGNAL(itemEntered(KviTalTreeWidgetItem *,int)),this,SLOT(slotOnItemEntered(KviTalTreeWidgetItem *,int))); - connect(widget(),SIGNAL(itemExpanded(KviTalTreeWidgetItem *)),this,SLOT(slotItemExpanded(KviTalTreeWidgetItem *))); - connect(widget(),SIGNAL(itemCollapsed(KviTalTreeWidgetItem *)),this,SLOT(slotItemCollapsed(KviTalTreeWidgetItem *))); - //connect(widget(),SIGNAL(rightButtonClicked(KviTalTreeWidgetItem *,const QPoint &,int)),this,SLOT(slotRightButtonClicked(KviTalTreeWidgetItem *,const QPoint &,int))); - connect(widget(),SIGNAL(itemChanged(KviTalTreeWidgetItem *,int)),this,SLOT(slotItemChanged(KviTalTreeWidgetItem *,int))); - - widget()->setContextMenuPolicy(Qt::CustomContextMenu); - connect(widget(),SIGNAL(customContextMenuRequested(const QPoint &)),this,SLOT(customContextMenuRequested(const QPoint &))); - - return true; -} - -bool KviKvsObject_treewidget::function_setHeaderLabels(KviKvsObjectFunctionCall *c) -{ - QStringList columns; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("labels",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,columns) - KVSO_PARAMETERS_END(c) - if (widget()){ - ((KviTalTreeWidget *)object())->setHeaderLabels(columns); - } - return true; -} - -bool KviKvsObject_treewidget::function_setColumnText(KviKvsObjectFunctionCall *c) -{ - if (!widget()) return true; - QString szLabel; - kvs_int_t iCol; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("column",KVS_PT_INT,0,iCol) - KVSO_PARAMETER("label",KVS_PT_STRING,0,szLabel) - KVSO_PARAMETERS_END(c) - QTreeWidgetItem *header=((KviTalTreeWidget *)widget())->headerItem(); - header->setText(iCol,szLabel); - return true; -} - -bool KviKvsObject_treewidget::function_addColumn(KviKvsObjectFunctionCall *c) -{ - if (!widget()) return true; - QString szLabel; - kvs_int_t iW; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("label",KVS_PT_STRING,0,szLabel) - KVSO_PARAMETER("width",KVS_PT_INT,0,iW) - KVSO_PARAMETERS_END(c) - int col=((KviTalTreeWidget *)widget())->columnCount(); - QTreeWidgetItem *header=((KviTalTreeWidget *)widget())->headerItem(); - header->setText(col,szLabel); - ((KviTalTreeWidget *)widget())->setColumnWidth(col,iW); - col++; - ((KviTalTreeWidget *)widget())->setColumnCount(col); - //col++; - return true; -} -/* -bool KviKvsObject_treewidget::function_setAcceptDrops(KviKvsObjectFunctionCall *c) -{ - bool bEnable; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("bEnable",KVS_PT_BOOLEAN,0,bEnable) - KVSO_PARAMETERS_END(c) - if (widget()) - ((KviTalTreeWidget *)object())->setAcceptDrops(bEnable); - return true; -} -*/ -bool KviKvsObject_treewidget::function_clear(KviKvsObjectFunctionCall *c) -{ - if (widget()) - ((KviTalTreeWidget *)object())->clear(); - return true; -} - -bool KviKvsObject_treewidget::function_selectedItems(KviKvsObjectFunctionCall *c) -{ - if(widget()) - { - QList list=((KviTalTreeWidget *)widget())->selectedItems(); - KviKvsArray * pArray = new KviKvsArray(); - c->returnValue()->setArray(pArray); - for (int i=0;iset(i,new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle((KviTalTreeWidgetItem*)list.at(i)))); - } - else - c->returnValue()->setHObject((kvs_hobject_t)0); - return true; -} - -bool KviKvsObject_treewidget::function_firstChild(KviKvsObjectFunctionCall *c) -{ - if(widget()) - c->returnValue()->setHObject(KviKvsObject_treewidgetitem::itemToHandle((KviTalTreeWidgetItem*)((KviTalTreeWidget *)widget())->topLevelItem(0))); - else - c->returnValue()->setHObject((kvs_hobject_t)0); - return true; -} - -bool KviKvsObject_treewidget::function_currentItem(KviKvsObjectFunctionCall *c) -{ - if(widget()) - c->returnValue()->setHObject(KviKvsObject_treewidgetitem::itemToHandle((KviTalTreeWidgetItem*)((KviTalTreeWidget *)widget())->currentItem())); - else - c->returnValue()->setHObject((kvs_hobject_t)0); - return true; -} -/* -bool KviKvsObject_treewidget::function_setColumnText(KviKvsObjectFunctionCall *c) -{ - kvs_int_t uCol; - QString szText; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) - KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) - KVSO_PARAMETERS_END(c) - if (widget())((KviTalTreeWidget *)widget())->setColumnText(uCol,szText); - return true; -} -*/ -bool KviKvsObject_treewidget::function_setColumnCount(KviKvsObjectFunctionCall *c) -{ - kvs_int_t uCol; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) - KVSO_PARAMETERS_END(c) - if (widget())((KviTalTreeWidget *)widget())->setColumnCount(uCol); - return true; -} - -bool KviKvsObject_treewidget::function_setSelectionMode(KviKvsObjectFunctionCall *c) -{ - QString szMode; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("mode",KVS_PT_NONEMPTYSTRING,0,szMode) - KVSO_PARAMETERS_END(c) - if(!widget())return true; - if(KviQString::equalCI(szMode,"NoSelection")) - ((KviTalTreeWidget *)widget())->setSelectionMode(QAbstractItemView::NoSelection); - else if(KviQString::equalCI(szMode,"Multi")) - ((KviTalTreeWidget *)widget())->setSelectionMode(KviTalTreeWidget::MultiSelection); - else if(KviQString::equalCI(szMode,"Extended")) - ((KviTalTreeWidget *)widget())->setSelectionMode(KviTalTreeWidget::ExtendedSelection); - else if(KviQString::equalCI(szMode,"Single")) - ((KviTalTreeWidget *)widget())->setSelectionMode(KviTalTreeWidget::SingleSelection); - else c->warning(__tr2qs("Invalid selection mode '%Q'"),&szMode); - return true; -} - -bool KviKvsObject_treewidget::function_setSorting(KviKvsObjectFunctionCall *c) -{ - kvs_int_t iCol; - bool bEnables; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("column",KVS_PT_INT,0,iCol) - KVSO_PARAMETER("sorting",KVS_PT_BOOLEAN,0,bEnables) - KVSO_PARAMETERS_END(c) - if (!widget())return true; - if (iCol<0) - ((KviTalTreeWidget *)widget())->setSortingEnabled(false); - else - if(!bEnables) ((KviTalTreeWidget *)widget())->sortItems(iCol,Qt::DescendingOrder); - else ((KviTalTreeWidget *)widget())->sortItems(iCol,Qt::AscendingOrder); - return true; -} - -bool KviKvsObject_treewidget::function_setRootIsDecorated(KviKvsObjectFunctionCall *c) -{ - bool bEnabled; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) - KVSO_PARAMETERS_END(c) - if (widget()) ((KviTalTreeWidget *)widget())->setRootIsDecorated(bEnabled); - return true; -} - -bool KviKvsObject_treewidget::function_setAllColumnsShowFocus(KviKvsObjectFunctionCall *c) -{ - bool bEnabled; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("bAllColumnsShowFocus",KVS_PT_BOOL,0,bEnabled) - KVSO_PARAMETERS_END(c) - if (widget())((KviTalTreeWidget *)widget())->setAllColumnsShowFocus(bEnabled); - return true; -} - -bool KviKvsObject_treewidget::function_hideListViewHeader(KviKvsObjectFunctionCall *c) -{ - ((KviTalTreeWidget *)widget())->header()->hide(); - return true; -} - -bool KviKvsObject_treewidget::function_showListViewHeader(KviKvsObjectFunctionCall *c) -{ - ((KviTalTreeWidget *)widget())->header()->show(); - return true; -} - -bool KviKvsObject_treewidget::function_listViewHeaderIsVisible(KviKvsObjectFunctionCall *c) -{ - c->returnValue()->setBoolean(((KviTalTreeWidget *)widget())->header()->isVisible()); - return true; -} - -bool KviKvsObject_treewidget::function_itemClickedEvent(KviKvsObjectFunctionCall *c) -{ - emitSignal("itemClicked",c,c->params()); - return true; -} - -void KviKvsObject_treewidget::slotClicked(KviTalTreeWidgetItem * i,int col) -{ - KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col); - - KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)),column); - callFunction(this,"itemClickedEvent",0,¶ms); -} - -bool KviKvsObject_treewidget::function_selectionChangedEvent(KviKvsObjectFunctionCall *c) -{ - emitSignal("selectionChanged",c,c->params()); - return true; -} - -void KviKvsObject_treewidget::slotSelectionChanged() -{ - if (((KviTalTreeWidget *)widget())->selectionMode()==KviTalTreeWidget::SingleSelection) - { - KviTalTreeWidgetItem *it=(KviTalTreeWidgetItem *) ((KviTalTreeWidget *)widget())->currentItem(); - KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(it))); - callFunction(this,"selectionChangedEvent",0,¶ms); - } - else{ - KviKvsVariantList params(new KviKvsVariant((kvs_hobject_t)0)); - callFunction(this,"selectionChangedEvent",0,¶ms); - } -} - -bool KviKvsObject_treewidget::function_currentChangedEvent(KviKvsObjectFunctionCall *c) -{ - emitSignal("currentChanged",c,c->params()); - return true; -} - -void KviKvsObject_treewidget::slotCurrentChanged(KviTalTreeWidgetItem * i,KviTalTreeWidgetItem *prev) -{ - KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)),new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(prev))); - callFunction(this,"currentChangedEvent",0,¶ms); -} - -bool KviKvsObject_treewidget::function_itemActivatedEvent(KviKvsObjectFunctionCall *c) -{ - //FIXME: compatibility - emitSignal("returnPressed",c,c->params());//<----remove me - // - - emitSignal("itemActivated",c,c->params()); - return true; -} - -void KviKvsObject_treewidget::slotItemActivated(KviTalTreeWidgetItem * i,int col) -{ - KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col); - KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)),column); - callFunction(this,"itemActivatedEvent",0,¶ms); -} - -bool KviKvsObject_treewidget::function_onItemEvent(KviKvsObjectFunctionCall *c) -{ - - emitSignal("onItem",c,c->params()); - return true; -} - -void KviKvsObject_treewidget::slotOnItemEntered(KviTalTreeWidgetItem * i,int col) -{ - KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col); - - KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)),column); - callFunction(this,"onItemEvent",0,¶ms); -} - -bool KviKvsObject_treewidget::function_itemExpandedEvent(KviKvsObjectFunctionCall *c) -{ - emitSignal("itemExpanded",c,c->params()); - return true; -} - -void KviKvsObject_treewidget::slotItemExpanded(KviTalTreeWidgetItem * i) -{ - KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i))); - callFunction(this,"itemExpandedEvent",0,¶ms); -} - -bool KviKvsObject_treewidget::function_itemCollapsedEvent(KviKvsObjectFunctionCall *c) -{ - emitSignal("itemCollapsed",c,c->params()); - return true; -} - -void KviKvsObject_treewidget::slotItemCollapsed(KviTalTreeWidgetItem * i) -{ - KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i))); - callFunction(this,"itemCollapsedEvent",0,¶ms); -} - -bool KviKvsObject_treewidget::function_customContextMenuRequestedEvent(KviKvsObjectFunctionCall *c) -{ - emitSignal("rightButtonClicked",c,c->params()); - emitSignal("customContextMenuRequested",c,c->params()); - return true; -} - -void KviKvsObject_treewidget::customContextMenuRequested(const QPoint &pnt) -{ - KviKvsVariant *xpos=new KviKvsVariant((kvs_int_t)pnt.x()); - KviKvsVariant *ypos=new KviKvsVariant((kvs_int_t)pnt.y()); - KviTalTreeWidgetItem *it=(KviTalTreeWidgetItem *) ((KviTalTreeWidget *)widget())->itemAt(pnt); - KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(it)),xpos,ypos); - callFunction(this,"customContextMenuRequestedEvent",0,¶ms); -} - -bool KviKvsObject_treewidget::function_itemChangedEvent(KviKvsObjectFunctionCall *c) -{ - //FIXME - emitSignal("itemRenamed",c,c->params());//<--remove me - - emitSignal("itemChanged",c,c->params()); - return true; -} - -void KviKvsObject_treewidget::slotItemChanged(KviTalTreeWidgetItem *item,int col) -{ - KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col); - KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(item)),column); - callFunction(this,"itemChangedEvent",0,¶ms); -} - -void KviKvsObject_treewidget::fileDropped(QString &szFile,KviTalTreeWidgetItem *item) -{ - KviKvsVariant *file=new KviKvsVariant(szFile); - KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(item)),file); - callFunction(this,"fileDroppedEvent",0,¶ms); -} - -KviKvsMdmListView::KviKvsMdmListView(QWidget * par,const char * name,KviKvsObject_treewidget *parent) -:KviTalTreeWidget(par) -{ - m_pParentScript=parent; - setAcceptDrops(true); - setDragEnabled(true); - setDropIndicatorShown(true); - setDragDropMode(QAbstractItemView::DragDrop); - viewport()->setAcceptDrops(true); -} - -KviKvsMdmListView::~KviKvsMdmListView() -{ -} - -void KviKvsMdmListView::dragEnterEvent( QDragEnterEvent * e ) -{ - debug("Drag enter event"); - if(!e->mimeData()->hasUrls()) - { - debug("Ignore drag"); - e->ignore(); - return; - } -} - -void KviKvsMdmListView::dropEvent(QDropEvent * e) -{ - debug("Drop event"); - QList list; - if(e->mimeData()->hasUrls()) - { - list = e->mimeData()->urls(); - - if(!list.isEmpty()) - { - QList::Iterator it = list.begin(); - for( ; it != list.end(); ++it ) - { - QUrl url = *it; - QString path = url.path(); - debug("path %s",path.toUtf8().data()); - #if !defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MINGW) - if(path[0] != '/')path.prepend("/"); //HACK HACK HACK for Qt bug (?!?) - #endif - // KviTalTreeWidgetItem *i = itemAt( contentsToViewport(e->pos()) ); - // m_pParentScript->fileDropped(path,i); - } - } - } -} - -#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES -#include "m_class_listview.moc" -#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/class_listview.h b/src/modules/objects/class_listview.h deleted file mode 100644 index 90e6a71d9..000000000 --- a/src/modules/objects/class_listview.h +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef _CLASS_LISTVIEW_H_ -#define _CLASS_LISTVIEW_H_ -//============================================================================= -// -// File : class_listview.h -// Creation date : Fri Jan 28 14:21:48 CEST 2005 -// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) -// -// This file is part of the KVirc irc client distribution -// Copyright (C) 2005-2008 Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -//============================================================================= - -#include "kvi_tal_treewidget.h" -#include "class_widget.h" -#include "class_listviewitem.h" - -#include "object_macros.h" - -class KviKvsObject_treewidget : public KviKvsObject_widget -{ - Q_OBJECT -public: - KVSO_DECLARE_OBJECT(KviKvsObject_treewidget) - -public: - QWidget * widget() { return (QWidget *)object(); }; - void fileDropped(QString &,KviTalTreeWidgetItem *); -protected: - virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); - - bool function_addColumn(KviKvsObjectFunctionCall *c); - bool function_setColumnText(KviKvsObjectFunctionCall *c); - bool function_takeItem(KviKvsObjectFunctionCall *c); - bool function_setSorting(KviKvsObjectFunctionCall *c); - bool function_setRootIsDecorated(KviKvsObjectFunctionCall *c); - bool function_clear(KviKvsObjectFunctionCall *c); - bool function_setAllColumnsShowFocus(KviKvsObjectFunctionCall *c); - bool function_itemClickedEvent(KviKvsObjectFunctionCall *c); - bool function_selectionChangedEvent(KviKvsObjectFunctionCall *c); - bool function_currentChangedEvent(KviKvsObjectFunctionCall *c); - bool function_itemActivatedEvent(KviKvsObjectFunctionCall *c); - bool function_onItemEvent(KviKvsObjectFunctionCall *c); - bool function_itemExpandedEvent(KviKvsObjectFunctionCall *c); - bool function_itemCollapsedEvent(KviKvsObjectFunctionCall *c); - bool function_itemChangedEvent(KviKvsObjectFunctionCall *c); - bool function_customContextMenuRequestedEvent(KviKvsObjectFunctionCall *c); - bool function_selectedItems(KviKvsObjectFunctionCall *c); - bool function_currentItem(KviKvsObjectFunctionCall *c); - bool function_setSelectionMode(KviKvsObjectFunctionCall *c); - bool function_firstChild(KviKvsObjectFunctionCall *c); - bool function_listViewHeaderIsVisible(KviKvsObjectFunctionCall *c); - bool function_showListViewHeader(KviKvsObjectFunctionCall *c); - bool function_hideListViewHeader(KviKvsObjectFunctionCall *c); - bool function_setAcceptDrops(KviKvsObjectFunctionCall *c); - bool function_setHeaderLabels(KviKvsObjectFunctionCall *c); - bool function_setColumnCount(KviKvsObjectFunctionCall *c); - - -protected slots: - void slotClicked(KviTalTreeWidgetItem *,int); - void customContextMenuRequested(const QPoint &pnt); - void slotSelectionChanged(); - void slotCurrentChanged(KviTalTreeWidgetItem *,KviTalTreeWidgetItem *); - void slotItemActivated(KviTalTreeWidgetItem *,int col); - void slotOnItemEntered(KviTalTreeWidgetItem *,int col); - void slotItemExpanded(KviTalTreeWidgetItem *); - void slotItemCollapsed(KviTalTreeWidgetItem *); - void slotItemChanged(KviTalTreeWidgetItem *,int); -}; - -class KviKvsMdmListView : public KviTalTreeWidget -{ - Q_OBJECT -public: - KviKvsMdmListView(QWidget * par,const char * name,KviKvsObject_treewidget *); - - virtual ~KviKvsMdmListView(); -protected: - KviKvsObject_treewidget *m_pParentScript; - void dropEvent(QDropEvent *e); - void dragEnterEvent( QDragEnterEvent *e ); - - - -}; -#endif //!_CLASS_LISTVIEW_H_ diff --git a/src/modules/objects/class_listviewitem.cpp b/src/modules/objects/class_listviewitem.cpp deleted file mode 100644 index 627892f4c..000000000 --- a/src/modules/objects/class_listviewitem.cpp +++ /dev/null @@ -1,489 +0,0 @@ -//============================================================================= -// -// File : class_listviewitem.cpp -// Creation date : Fri Jan 28 14:21:48 CEST 2005 -// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) -// -// This file is part of the KVirc irc client distribution -// Copyright (C) 2005-2008 Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -//============================================================================= - -#include "class_listviewitem.h" -#include "class_pixmap.h" -#include "kvi_error.h" -#include "kvi_debug.h" -#include "kvi_locale.h" -#include "kvi_iconmanager.h" - -const int item_flags[] = { - Qt::ItemIsSelectable, - Qt::ItemIsEditable, - Qt::ItemIsDragEnabled, - Qt::ItemIsDropEnabled, - Qt::ItemIsUserCheckable, - Qt::ItemIsEnabled, - Qt::ItemIsTristate -}; - -const char * const itemflags_tbl[] = { - "selectable", - "editable", - "dragEnabled", - "dropEnabled", - "userCheckable", - "enabled", - "tristate" -}; - -#define itemflags_num (sizeof(itemflags_tbl) / sizeof(itemflags_tbl[0])) - - - -/* - @doc: treewidgetitem - @keyterms: - treewidget treewidgetitem class - @title: - treewidgetitem class - @type: - class - @short: - A treewidgetitem class - @inherits: - [class]treewidgetitem[/class] - @description: - The treewidgetitem class implements a list view item. - A list view item is a multi-column object capable of displaying itself in a [class]treewidget[/class]. - To use this class you must instantiate it with another treewidgetitem or a [class]treewidget[/class] - as parent. The item will be automatically displayed. - You can set the text and a pixmap in each column and you can make it checkable - with [classfnc:treewidgetitem]$setCheckable[/classfnc](). - A checkable treewidgetitem will display a small check mark in the first column. - @functions: - !fn: $setText(,) - Sets the text in column column to text, if column is a valid column number and text is different from the existing text. - - !fn: $text() - Returs the text of the specified column. - - !fn: $setPixmap(,) - Sets the pixmap in column column to pm, if pm is non-null and different from the current pixmap, and if column is non-negative. - Pixmap can be a Kvirc imageid, an image file or a [class]pixmap[/class] object. - - !fn: $setRenameEnabled(,) - If b is TRUE (1), this item can be in-place renamed in the column col by the user; otherwise it cannot be renamed in-place. - - !fn: $setEnabled() - Enables or disables the item - - !fn: $isEnabled() - Returns $true if this item is enabled and $false otherwise - - !fn: $setOpen() - Opens or closes the item to show its children items - - !fn: $isOpen() - Returns the open state of this item - - !fn: $setCheckable() - Makes this item checkable or not. This function should be called immediately - after the item creation: changing this property later at runtime may have - strange results (like the item being moved inside the list, text disappearing, - hidden children etc... don't do it :D ). - - !fn: $isCheckable() - Returns $true if this item is checkable and $false otherwise - - !fn: $setChecked() - Sets this item to be checked or not. [classfnc:treewidgetitem]$setCheckable[/classfnc]() must - have been previously called. - - !fn: $isChecked() - Returns the check status of this item. [classfnc:treewidgetitem]$setCheckable[/classfnc]() must - have been previously called. - - !fn: $firstChild() - Returns the first child item of this treewidgetitem or $null if this item has no children. - - !fn: $nextSibling() - Returns the next sibling item of this treewidgetitem or $null if there are no sibling items. - Next sibling stands for the item at the same tree level coming just after :) -*/ - - -//=========================================================================================== - -KVSO_BEGIN_REGISTERCLASS(KviKvsObject_treewidgetitem,"listviewitem","object") - KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"setText",function_setText) - KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"text",function_text) - KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"setPixmap",function_setPixmap); - KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"setRenameEnabled",function_setRenameEnabled); - //KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"setEnabled",function_setEnabled); - //KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"isEnabled",function_isEnabled); - KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"setOpen",function_setOpen); - KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"isOpen",function_isOpen); - //KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"setCheckable",function_setCheckable); - //KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"isCheckable",function_isCheckable); - KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"setChecked",function_setChecked); - KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"isChecked",function_isChecked); - KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"firstChild",function_firstChild); - KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"setFlags",function_setFlags); - - // KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"nextSibling",function_nextSibling); -KVSO_END_REGISTERCLASS(KviKvsObject_treewidgetitem) - - -KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_treewidgetitem,KviKvsObject) - - m_pListViewItem = 0; - -KVSO_END_CONSTRUCTOR(KviKvsObject_treewidgetitem) - - -KVSO_BEGIN_DESTRUCTOR(KviKvsObject_treewidgetitem) - - if(m_pListViewItem)delete m_pListViewItem; - -KVSO_END_CONSTRUCTOR(KviKvsObject_treewidgetitem) - -bool KviKvsObject_treewidgetitem::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) -{ - if (!parentObject()) - { - pContext->error(__tr2qs("The treewidgetitem cannot be parentless")); - return false; - } - if(parentObject()->inherits("KviKvsObject_treewidgetitem")) - { - m_pListViewItem = new KviKvsMdmStandardListViewItem(this,((KviKvsObject_treewidgetitem *)parentObject())->m_pListViewItem); - } else { - if(parentObject()->inherits("KviKvsObject_treewidget")) - m_pListViewItem = new KviKvsMdmStandardListViewItem(this,((KviTalTreeWidget *)parentScriptWidget())); - else { - pContext->error(__tr2qs("The parent of the treewidgetitem must be either another treewidgetitem or a treewidget")); - return false; - } - } - return true; -} - -void KviKvsObject_treewidgetitem::childDestroyed() -{ - if(m_pListViewItem == 0)return; - m_pListViewItem = 0; - die(); -} - -KviKvsMdmStandardListViewItem::KviKvsMdmStandardListViewItem(KviKvsObject_treewidgetitem * ob,KviTalTreeWidget * par) -:KviTalTreeWidgetItem(par), m_pMasterObject(ob) -{ -} - -KviKvsMdmStandardListViewItem::KviKvsMdmStandardListViewItem(KviKvsObject_treewidgetitem * ob,KviTalTreeWidgetItem * par) -:KviTalTreeWidgetItem(par), m_pMasterObject(ob) -{ -} - -KviKvsMdmStandardListViewItem::~KviKvsMdmStandardListViewItem() -{ - if(m_pMasterObject)m_pMasterObject->childDestroyed(); -} -/* - - -KviKvsMdmCheckListViewItem::KviKvsMdmCheckListViewItem(KviKvsObject_treewidgetitem * ob,KviTalTreeWidget * par) -:KviTalCheckListItem(par,QString::null,KviTalCheckListItem::CheckBox), m_pMasterObject(ob) -{ -} - -KviKvsMdmCheckListViewItem::KviKvsMdmCheckListViewItem(KviKvsObject_treewidgetitem * ob,KviTalTreeWidgetItem * par) -:KviTalCheckListItem(par,QString::null,KviTalCheckListItem::CheckBox), m_pMasterObject(ob) -{ -} - -KviKvsMdmCheckListViewItem::~KviKvsMdmCheckListViewItem() -{ - if(m_pMasterObject)m_pMasterObject->childDestroyed(); -} -*/ - -kvs_hobject_t KviKvsObject_treewidgetitem::itemToHandle(KviTalTreeWidgetItem * it) -{ - if(!it)return (kvs_hobject_t)0; - KviKvsObject_treewidgetitem * pObject; -// if(it->rtti() == 1)pObject = ((KviKvsMdmCheckListViewItem *)it)->masterObject(); -// else - pObject = ((KviKvsMdmStandardListViewItem *)it)->masterObject(); - if(!pObject)return (kvs_hobject_t)0; - return pObject->handle(); -} - - -bool KviKvsObject_treewidgetitem::function_setText(KviKvsObjectFunctionCall *c) -{ - kvs_uint_t uCol; - QString szText; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) - KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) - KVSO_PARAMETERS_END(c) - if(m_pListViewItem) - m_pListViewItem->setText(uCol,szText); - return true; -} - -bool KviKvsObject_treewidgetitem::function_firstChild(KviKvsObjectFunctionCall *c) -{ - if(m_pListViewItem) - c->returnValue()->setHObject(itemToHandle((KviTalTreeWidgetItem*)m_pListViewItem->child(0))); - else - c->returnValue()->setHObject((kvs_hobject_t)0); - return true; -} -/* -bool KviKvsObject_treewidgetitem::function_nextSibling(KviKvsObjectFunctionCall *c) -{ - if(m_pListViewItem) - c->returnValue()->setHObject(itemToHandle(m_pListViewItem->nextSibling())); - else - c->returnValue()->setHObject((kvs_hobject_t)0); - return true; -} -*/ -bool KviKvsObject_treewidgetitem::function_setRenameEnabled(KviKvsObjectFunctionCall *c) -{ - kvs_uint_t uCol; - bool bEnabled; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) - KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) - KVSO_PARAMETERS_END(c) - if(m_pListViewItem) - m_pListViewItem->setFlags(m_pListViewItem->flags()|Qt::ItemIsEditable); - return true; - -} - -bool KviKvsObject_treewidgetitem::function_setFlags(KviKvsObjectFunctionCall *c) -{ - QStringList itemflags; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("flags",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,itemflags) - KVSO_PARAMETERS_END(c) - int flag,sum=0; - for ( int i=0;isetCheckState(0,Qt::Unchecked); - sum = sum | flag; - } - else - c->warning(__tr2qs("Unknown item flag: %s"),&itemflags.at(i)); - - } - if(m_pListViewItem) - m_pListViewItem->setFlags((Qt::ItemFlags)sum); - - return true; - - - -} -/* -bool KviKvsObject_treewidgetitem::function_setEnabled(KviKvsObjectFunctionCall *c) -{ - bool bEnabled; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) - KVSO_PARAMETERS_END(c) - if(m_pListViewItem) - m_pListViewItem->setEnabled(bEnabled); - return true; -} - -bool KviKvsObject_treewidgetitem::function_isEnabled(KviKvsObjectFunctionCall *c) -{ - if(!m_pListViewItem) - { - c->returnValue()->setBoolean(false); - return true; - } - c->returnValue()->setBoolean(m_pListViewItem->isEnabled()); - return true; -} -*/ -bool KviKvsObject_treewidgetitem::function_setOpen(KviKvsObjectFunctionCall *c) -{ - bool bEnabled; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) - KVSO_PARAMETERS_END(c) - if(m_pListViewItem) - m_pListViewItem->setExpanded(bEnabled); - return true; -} - -bool KviKvsObject_treewidgetitem::function_isOpen(KviKvsObjectFunctionCall *c) -{ - if(!m_pListViewItem) - { - c->returnValue()->setBoolean(false); - return true; - } - c->returnValue()->setBoolean(m_pListViewItem->isExpanded()); - return true; -} - - -bool KviKvsObject_treewidgetitem::function_setChecked(KviKvsObjectFunctionCall *c) -{ - bool bChecked; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("bChecked",KVS_PT_BOOL,0,bChecked) - KVSO_PARAMETERS_END(c) - if(!m_pListViewItem)return true; -// if(m_pListViewItem->rtti() != 1)return true; // not a QCheckListItem - ((KviTalTreeWidgetItem *)m_pListViewItem)->setCheckState(0,bChecked?Qt::Checked:Qt::Unchecked); - return true; -} - -bool KviKvsObject_treewidgetitem::function_isChecked(KviKvsObjectFunctionCall *c) -{ - if(!m_pListViewItem) - { - c->returnValue()->setBoolean(false); - return true; - } - /*if(m_pListViewItem->rtti() != 1) - { - c->returnValue()->setBoolean(false); - return true; - } - */ - c->returnValue()->setBoolean(((KviTalTreeWidgetItem *)m_pListViewItem)->checkState(0)==Qt::Checked?1:0); - return true; -} -/* -bool KviKvsObject_treewidgetitem::function_setCheckable(KviKvsObjectFunctionCall *c) -{ - bool bCheckable; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("bCheckable",KVS_PT_BOOL,0,bCheckable) - KVSO_PARAMETERS_END(c) - if(!m_pListViewItem)return true; - if(bCheckable) - { - if(m_pListViewItem->rtti() == 1)return true; // a QCheckListItem already - KviTalTreeWidgetItem * pParent = m_pListViewItem->parent(); - KviTalTreeWidget * pLV = (KviTalTreeWidget *)m_pListViewItem->listView(); - // swap the items, so we don't die now - KviTalTreeWidgetItem * pThis = m_pListViewItem; - m_pListViewItem = 0; - delete pThis; - if(pParent) - m_pListViewItem = new KviKvsMdmCheckListViewItem(this,pParent); - else - m_pListViewItem = new KviKvsMdmCheckListViewItem(this,pLV); - } else { - if(m_pListViewItem->rtti() != 1)return true; // not a QCheckListItem yet - KviTalTreeWidgetItem * pParent = m_pListViewItem->parent(); - KviTalTreeWidget * pLV = (KviTalTreeWidget *)m_pListViewItem->listView(); - // swap the items, so we don't die now - KviTalTreeWidgetItem * pThis = m_pListViewItem; - m_pListViewItem = 0; - delete pThis; - if(pParent) - m_pListViewItem = new KviKvsMdmStandardListViewItem(this,pParent); - else - m_pListViewItem = new KviKvsMdmStandardListViewItem(this,pLV); - } - return true; -} - -bool KviKvsObject_treewidgetitem::function_isCheckable(KviKvsObjectFunctionCall *c) -{ - if(!m_pListViewItem) - { - c->returnValue()->setBoolean(false); - return true; - } - c->returnValue()->setBoolean(m_pListViewItem->rtti() == 1); - return true; -} -*/ -bool KviKvsObject_treewidgetitem::function_text(KviKvsObjectFunctionCall *c) -{ - kvs_uint_t uCol; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) - KVSO_PARAMETERS_END(c) - if(m_pListViewItem) - c->returnValue()->setString(m_pListViewItem->text(uCol)); - return true; -} - -bool KviKvsObject_treewidgetitem::function_setPixmap(KviKvsObjectFunctionCall *c) -{ - kvs_uint_t uCol; - KviKvsObject *obPixmap; - kvs_hobject_t obHpixmap; - KviKvsVariant * vPixmap; - KVSO_PARAMETERS_BEGIN(c) - KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) - KVSO_PARAMETER("pixmap",KVS_PT_VARIANT,0,vPixmap) - KVSO_PARAMETERS_END(c) - QPixmap *pix = 0; - if(vPixmap->isHObject()) - { - vPixmap->asHObject(obHpixmap); - obPixmap=KviKvsKernel::instance()->objectController()->lookupObject(obHpixmap); - if (!obPixmap->inherits("KviKvsObject_pixmap")) - { - c->warning(__tr2qs("Pixmap object or image Id required")); - return true; - } - pix=((KviKvsObject_pixmap *)obPixmap)->getPixmap(); - } else { - QString szPix; - vPixmap->asString(szPix); - pix=g_pIconManager->getImage(szPix); - if(!pix) - { - c->warning(__tr2qs("Error occured: the suitable file '%Q' is not of the correct format or it is not a valid icon number."),&szPix); - return true; - } - } - m_pListViewItem->setIcon(uCol,QIcon(*pix)); - return true; -} - -#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES -#include "m_class_listviewitem.moc" -#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES - diff --git a/src/modules/objects/class_listviewitem.h b/src/modules/objects/class_listviewitem.h deleted file mode 100644 index e7e14fb13..000000000 --- a/src/modules/objects/class_listviewitem.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef _CLASS_LISTVIEWITEM_H_ -#define _CLASS_LISTVIEWITEM_H_ -//============================================================================= -// -// File : class_listviewitem.h -// Creation date : Fri Jan 28 14:21:48 CEST 2005 -// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) -// -// This file is part of the KVirc irc client distribution -// Copyright (C) 2005-2008 Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) -// -// This program is FREE software. You can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your opinion) any later version. -// -// This program is distributed in the HOPE that it will be USEFUL, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -// See the GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, write to the Free Software Foundation, -// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -// -//============================================================================= - -#include "kvi_tal_treewidget.h" -#include "class_widget.h" - - - -#include "object_macros.h" - -class KviKvsObject_treewidgetitem : public KviKvsObject -{ - Q_OBJECT -public: - KVSO_DECLARE_OBJECT(KviKvsObject_treewidgetitem) - void childDestroyed(); -protected: - KviTalTreeWidgetItem * m_pListViewItem; -protected: - virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); -protected: - bool function_setText(KviKvsObjectFunctionCall *c); - bool function_insertItem(KviKvsObjectFunctionCall *c); - bool function_setPixmap(KviKvsObjectFunctionCall *c); - bool function_setRenameEnabled(KviKvsObjectFunctionCall *c); - bool function_setEnabled(KviKvsObjectFunctionCall *c); - bool function_isEnabled(KviKvsObjectFunctionCall *c); - bool function_setOpen(KviKvsObjectFunctionCall *c); - bool function_isOpen(KviKvsObjectFunctionCall *c); - bool function_text(KviKvsObjectFunctionCall *c); - bool function_setCheckable(KviKvsObjectFunctionCall *c); - bool function_isCheckable(KviKvsObjectFunctionCall *c); - bool function_setChecked(KviKvsObjectFunctionCall *c); - bool function_isChecked(KviKvsObjectFunctionCall *c); - bool function_firstChild(KviKvsObjectFunctionCall *c); - //bool function_nextSibling(KviKvsObjectFunctionCall *c); - bool function_setFlags(KviKvsObjectFunctionCall *c); - -public: - static kvs_hobject_t itemToHandle(KviTalTreeWidgetItem * it); -}; - - - -class KviKvsMdmStandardListViewItem : public KviTalTreeWidgetItem -{ -public: - KviKvsMdmStandardListViewItem(KviKvsObject_treewidgetitem * ob,KviTalTreeWidget * par); - KviKvsMdmStandardListViewItem(KviKvsObject_treewidgetitem * ob,KviTalTreeWidgetItem * par); - virtual ~KviKvsMdmStandardListViewItem(); -protected: - KviKvsObject_treewidgetitem * m_pMasterObject; -public: - KviKvsObject_treewidgetitem * masterObject(){ return m_pMasterObject; } -}; -/* -class KviKvsMdmCheckListViewItem : public KviTalCheckListItem -{ -public: - KviKvsMdmCheckListViewItem(KviKvsObject_treewidgetitem * ob,KviTalTreeWidget * par); - KviKvsMdmCheckListViewItem(KviKvsObject_treewidgetitem * ob,KviTalTreeWidgetItem * par); - virtual ~KviKvsMdmCheckListViewItem(); -protected: - KviKvsObject_treewidgetitem * m_pMasterObject; -public: - KviKvsObject_treewidgetitem * masterObject(){ return m_pMasterObject; } -}; -*/ -#endif // !_CLASS_LISTVIEWITEM_H_ diff --git a/src/modules/objects/class_treewidget.cpp b/src/modules/objects/class_treewidget.cpp new file mode 100644 index 000000000..91f8ea6f4 --- /dev/null +++ b/src/modules/objects/class_treewidget.cpp @@ -0,0 +1,650 @@ +//============================================================================= +// +// File : class_treewidget.cpp +// Creation date : Fri Jan 28 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2005-2008 Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= + +#include "class_treewidget.h" + +#include "kvi_error.h" +#include "kvi_debug.h" +#include "kvi_locale.h" +#include "kvi_iconmanager.h" +#include "kvi_tal_treewidget.h" + +// FIXME: fix the doc (function QT4 renamed) +// OLD: +// itemRenamed signal +// itemRenamed event +// NEW: +// itemActivated signal +// itemActavatedEvent + + +#include +#include +#include +#include + +/* + @doc: treewidget + @keyterms: + treewidget widget class + @title: + treewidget class + @type: + class + @short: + A treewidget class + @inherits: + [class]widget[/class] + @description: + It can display and control a hierarchy of multi-column items, and provides the ability to add new items at any time. + The items are added by creating children [class]treewidgetitem[/class] objects: simply allocating them with $new + will add the items to the treewidget and simply deleting them will remove them. + Allocating a [class]treewidgetitem[/class] item2 as a child of item1 will insert it to the same treewidget creating + a subtree of items spannig from item1. The subtree can be opened or closed by a simple click either + on the parent item or on the little plus sign on the side of it (when [classfnc:treewidget]$setRootIsDecorated[/classfnc] + is set to $true. The treewidget can be in Single, Multi, Extended or NoSelection selection mode. + In single selection mode there can be only one selected item at a time and the selected item is also + the current item (this mode is the default). In Multi and Extended selection mode there can be multiple selected items + and the current item is one of them. The difference between Multi and Extended is in the way + that items can be selected by the mouse actions: experiment with the two modes :). + The NoSelection mode has obviously no selection at all. + @functions: + !fn: $addColumn( ) + Adds a width pixels wide column with the column header label to the list view. + + !fn: $setSorting(,) + Sets the list view to be sorted by column column in ascending order if ascending is 1 or descending order if it is FALSE. + If column is -1, sorting is disabled and the user cannot sort columns by clicking on the column headers + + !fn: $hideListViewHeader() + Hide the treewidget column header. + + !fn: $showListViewHeader() + Show the treewidget column header. + + !fn: $isListViewHeaderVisible() + Returns '1' if the treewidget header is currently visible. Otherwise this function returns '0'. + + !fn: $setAllColumnsShowFocus() + When the argument is $true, causes the treewidget to display the focus and selection + by highlighting all the columns of the item. When the argument is $false then + only the first column is selected/highlighted. + + !fn: $setSelectionMode() + Sets the selection mode for this treewidget. can be one of "Single","NoSelection","Multi" or "Extended". + + !fn: $selectedItem() + Returns the currently selected [class]treewidgetitem[/class] or $null if no items are selected. + This function works only if the list view is in single selection mode. + + !fn: $currentItem() + Returns the current [class]treewidgetitem[/class] or $null if no item is current at the moment. + + !fn: $firstChild() + Returns the first child [class]treewidgetitem[/class] of this treewidget or $null if there are no items at all. + + !fn: $clickEvent() + This function is called when the user clicks in the list view. + In its argument the [class]treewidgetitem[/class] object clicked or 0 if the user didn't click on an item.[br] + The default implementation emits the [classfnc]$clicked[/classfnc]() signal. + + !fn: $selectionChangedEvent() + This event handle whenever the set of selected items has changed. + The argument is the newly selected item if the treewidget is in single selection mode.[br] + When the treewidget is in Multi or Extended selection mode then item is always $null.[br] + The default implementation emits the [classfnc]$selectionChanged[/classfnc]() signal. + + !fn: $currentChangedEvent() + This event are called whenever the current item has changed. + In its argument is the newly selected item or 0 if the change made no item current.[br] + The default implementation emits the [classfnc]$currentChanged[/classfnc]() signal. + + !fn: $returnPressedEvent() + This function is called by the framework when the enter key is pressed.[br] + In its arument the currrent item.[br] + The default implementation emits the [classfnc]$returnPressed[/classfnc]() signal. + + !fn: $spacePressedEvent() + This function is called by the framework when the space key is pressed.[br] + In its arument the currrent item.[br] + The default implementation emits the [classfnc]$spacePressed[/classfnc]() signal. + + !fn: $onItemEvent() + This event is called when an item has been expanded, i.e. when the children of item are shown. + The default implementation emits the [classfnc]$expanded[/classfnc]() signal. + + !fn: $itemCollapsedEvent() + This event is called when an item has been collapsed, i.e. when the children of item are hidden. + The default implementation emits the [classfnc]$collapsed[/classfnc]() signal. + + !fn: $itemRenamedEvent(,,) + This event is called when the item has been renamed in text, e.g. by in in-place renaming, in column col.[br] + The default implementation emits the [classfnc]$itemRenamed[/classfnc]() signal. + + !fn: $rightButtonClickEvent(,,>y:integer>) + This signal is emitted when the right button is clicked.[br] + The arguments are the relevant item (may be 0), the point in global coordinates and the relevant column (or -1 if the click was outside the list). + The default implementation emits the [classfnc]$rightButtonClicked[/classfnc]() signal. + @signals: + !sg: $clicked() + This signal is emitted by the default implementation of [classfnc]$clickEvent[/classfnc](). + !sg: $selectionChanged() + This signal is emitted by the default implementation of [classfnc]$selectionChangedEvent[/classfnc](). + !sg: $currentChanged() + This signal is emitted by the default implementation of [classfnc]$currentChangedEvent[/classfnc](). + !sg: $returnPressed() + This signal is emitted by the default implementation of [classfnc]$returnPressedEvent[/classfnc](). + !sg: $spacePressed() + This signal is emitted by the default implementation of [classfnc]$spacePredssedEvent[/classfnc](). + !sg: $onItem() + This signal is emitted by the default implementation of [classfnc]$onItemEvent[/classfnc](). + !sg: $itemExpanded() + This signal is emitted by the default implementation of [classfnc]$itemExpandedEvent[/classfnc](). + !sg: $itemCollapsed() + This signal is emitted by the default implementation of [classfnc]$itemCollapsedEvent[/classfnc](). + !sg: $itemRenamed() + This signal is emitted by the default implementation of [classfnc]$itemRenamedEvent[/classfnc](). + !sg: $rightButtonClicked() + This signal is emitted by the default implementation of [classfnc]$rightButtonClickedEvent[/classfnc](). + + +*/ + +//--------------------------------------------------------------------------------- + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_treewidget,"listview","widget") + + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"setHeaderLabels",function_setHeaderLabels) + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"addColumn",function_addColumn) + + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"setColumnText",function_setColumnText) + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"setColumnCount",function_setColumnCount) + + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"setSorting",function_setSorting) + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"setRootIsDecorated",function_setRootIsDecorated) + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"setAllColumnsShowFocus",function_setAllColumnsShowFocus) + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"clear",function_clear) + //FIXME + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"selectedItem",function_selectedItems)//<--- remove this + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"selectedItems",function_selectedItems) + + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"currentItem",function_currentItem) + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"setSelectionMode",function_setSelectionMode) + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"listViewHeaderIsVisible",function_listViewHeaderIsVisible) + + + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"hideListViewHeader",function_hideListViewHeader) + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"showListViewHeader",function_showListViewHeader) + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"firstChild",function_firstChild) + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"selectionChangedEvent",function_selectionChangedEvent); + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"currentChangedEvent",function_currentChangedEvent); + + // FIX-ME + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"returnPressedEvent",function_itemActivatedEvent);//<- remove me + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"itemActivatedEvent",function_itemActivatedEvent); + // + +// KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"spacePressedEvent",function_spacePressedEvent); + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"onItemEvent",function_onItemEvent); + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"itemClickedEvent",function_itemClickedEvent); + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"itemExpandedEvent",function_itemExpandedEvent); + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"itemCollapsedEvent",function_itemCollapsedEvent); + + //FIXME + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"itemRenamedEvent",function_itemChangedEvent);//<- remove me + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"itemChangedEvent",function_itemChangedEvent); + // + + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"rightButtonClickedEvent",function_customContextMenuRequestedEvent); + KVSO_REGISTER_HANDLER(KviKvsObject_treewidget,"customContextMenuRequestedEvent",function_customContextMenuRequestedEvent); + + KVSO_REGISTER_STANDARD_NOTHINGRETURN_HANDLER(KviKvsObject_treewidget,"fileDroppedEvent") + +KVSO_END_REGISTERCLASS(KviKvsObject_treewidget) + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_treewidget,KviKvsObject_widget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_treewidget) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_treewidget) + +KVSO_END_CONSTRUCTOR(KviKvsObject_treewidget) + +bool KviKvsObject_treewidget::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + setObject(new KviKvsTreeWidget(parentScriptWidget(),getName().toUtf8().data(),this),true); + + // hack for compatibility with "old" addColumn method; + ((KviTalTreeWidget*) widget())->setColumnCount(0); + + connect(widget(),SIGNAL(itemClicked(KviTalTreeWidgetItem *,int)),this,SLOT(slotClicked(KviTalTreeWidgetItem *,int))); + connect(widget(),SIGNAL(itemSelectionChanged()),this,SLOT(slotSelectionChanged())); + connect(widget(),SIGNAL(currentItemChanged(KviTalTreeWidgetItem *,KviTalTreeWidgetItem *)),this,SLOT(slotCurrentChanged(KviTalTreeWidgetItem *,KviTalTreeWidgetItem *))); + connect(widget(),SIGNAL(itemActivated(KviTalTreeWidgetItem *,int)),this,SLOT(slotItemActivated(KviTalTreeWidgetItem *,int))); + connect(widget(),SIGNAL(itemEntered(KviTalTreeWidgetItem *,int)),this,SLOT(slotOnItemEntered(KviTalTreeWidgetItem *,int))); + connect(widget(),SIGNAL(itemExpanded(KviTalTreeWidgetItem *)),this,SLOT(slotItemExpanded(KviTalTreeWidgetItem *))); + connect(widget(),SIGNAL(itemCollapsed(KviTalTreeWidgetItem *)),this,SLOT(slotItemCollapsed(KviTalTreeWidgetItem *))); + //connect(widget(),SIGNAL(rightButtonClicked(KviTalTreeWidgetItem *,const QPoint &,int)),this,SLOT(slotRightButtonClicked(KviTalTreeWidgetItem *,const QPoint &,int))); + connect(widget(),SIGNAL(itemChanged(KviTalTreeWidgetItem *,int)),this,SLOT(slotItemChanged(KviTalTreeWidgetItem *,int))); + + widget()->setContextMenuPolicy(Qt::CustomContextMenu); + connect(widget(),SIGNAL(customContextMenuRequested(const QPoint &)),this,SLOT(customContextMenuRequested(const QPoint &))); + + return true; +} + +bool KviKvsObject_treewidget::function_setHeaderLabels(KviKvsObjectFunctionCall *c) +{ + QStringList columns; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("labels",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,columns) + KVSO_PARAMETERS_END(c) + if (widget()){ + ((KviTalTreeWidget *)object())->setHeaderLabels(columns); + } + return true; +} + +bool KviKvsObject_treewidget::function_setColumnText(KviKvsObjectFunctionCall *c) +{ + if (!widget()) return true; + QString szLabel; + kvs_int_t iCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_INT,0,iCol) + KVSO_PARAMETER("label",KVS_PT_STRING,0,szLabel) + KVSO_PARAMETERS_END(c) + QTreeWidgetItem *header=((KviTalTreeWidget *)widget())->headerItem(); + header->setText(iCol,szLabel); + return true; +} + +bool KviKvsObject_treewidget::function_addColumn(KviKvsObjectFunctionCall *c) +{ + if (!widget()) return true; + QString szLabel; + kvs_int_t iW; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("label",KVS_PT_STRING,0,szLabel) + KVSO_PARAMETER("width",KVS_PT_INT,0,iW) + KVSO_PARAMETERS_END(c) + int col=((KviTalTreeWidget *)widget())->columnCount(); + QTreeWidgetItem *header=((KviTalTreeWidget *)widget())->headerItem(); + header->setText(col,szLabel); + ((KviTalTreeWidget *)widget())->setColumnWidth(col,iW); + col++; + ((KviTalTreeWidget *)widget())->setColumnCount(col); + //col++; + return true; +} +/* +bool KviKvsObject_treewidget::function_setAcceptDrops(KviKvsObjectFunctionCall *c) +{ + bool bEnable; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnable",KVS_PT_BOOLEAN,0,bEnable) + KVSO_PARAMETERS_END(c) + if (widget()) + ((KviTalTreeWidget *)object())->setAcceptDrops(bEnable); + return true; +} +*/ +bool KviKvsObject_treewidget::function_clear(KviKvsObjectFunctionCall *c) +{ + if (widget()) + ((KviTalTreeWidget *)object())->clear(); + return true; +} + +bool KviKvsObject_treewidget::function_selectedItems(KviKvsObjectFunctionCall *c) +{ + if(widget()) + { + QList list=((KviTalTreeWidget *)widget())->selectedItems(); + KviKvsArray * pArray = new KviKvsArray(); + c->returnValue()->setArray(pArray); + for (int i=0;iset(i,new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle((KviTalTreeWidgetItem*)list.at(i)))); + } + else + c->returnValue()->setHObject((kvs_hobject_t)0); + return true; +} + +bool KviKvsObject_treewidget::function_firstChild(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setHObject(KviKvsObject_treewidgetitem::itemToHandle((KviTalTreeWidgetItem*)((KviTalTreeWidget *)widget())->topLevelItem(0))); + else + c->returnValue()->setHObject((kvs_hobject_t)0); + return true; +} + +bool KviKvsObject_treewidget::function_currentItem(KviKvsObjectFunctionCall *c) +{ + if(widget()) + c->returnValue()->setHObject(KviKvsObject_treewidgetitem::itemToHandle((KviTalTreeWidgetItem*)((KviTalTreeWidget *)widget())->currentItem())); + else + c->returnValue()->setHObject((kvs_hobject_t)0); + return true; +} +/* +bool KviKvsObject_treewidget::function_setColumnText(KviKvsObjectFunctionCall *c) +{ + kvs_int_t uCol; + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if (widget())((KviTalTreeWidget *)widget())->setColumnText(uCol,szText); + return true; +} +*/ +bool KviKvsObject_treewidget::function_setColumnCount(KviKvsObjectFunctionCall *c) +{ + kvs_int_t uCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETERS_END(c) + if (widget())((KviTalTreeWidget *)widget())->setColumnCount(uCol); + return true; +} + +bool KviKvsObject_treewidget::function_setSelectionMode(KviKvsObjectFunctionCall *c) +{ + QString szMode; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("mode",KVS_PT_NONEMPTYSTRING,0,szMode) + KVSO_PARAMETERS_END(c) + if(!widget())return true; + if(KviQString::equalCI(szMode,"NoSelection")) + ((KviTalTreeWidget *)widget())->setSelectionMode(QAbstractItemView::NoSelection); + else if(KviQString::equalCI(szMode,"Multi")) + ((KviTalTreeWidget *)widget())->setSelectionMode(KviTalTreeWidget::MultiSelection); + else if(KviQString::equalCI(szMode,"Extended")) + ((KviTalTreeWidget *)widget())->setSelectionMode(KviTalTreeWidget::ExtendedSelection); + else if(KviQString::equalCI(szMode,"Single")) + ((KviTalTreeWidget *)widget())->setSelectionMode(KviTalTreeWidget::SingleSelection); + else c->warning(__tr2qs("Invalid selection mode '%Q'"),&szMode); + return true; +} + +bool KviKvsObject_treewidget::function_setSorting(KviKvsObjectFunctionCall *c) +{ + kvs_int_t iCol; + bool bEnables; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_INT,0,iCol) + KVSO_PARAMETER("sorting",KVS_PT_BOOLEAN,0,bEnables) + KVSO_PARAMETERS_END(c) + if (!widget())return true; + if (iCol<0) + ((KviTalTreeWidget *)widget())->setSortingEnabled(false); + else + if(!bEnables) ((KviTalTreeWidget *)widget())->sortItems(iCol,Qt::DescendingOrder); + else ((KviTalTreeWidget *)widget())->sortItems(iCol,Qt::AscendingOrder); + return true; +} + +bool KviKvsObject_treewidget::function_setRootIsDecorated(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if (widget()) ((KviTalTreeWidget *)widget())->setRootIsDecorated(bEnabled); + return true; +} + +bool KviKvsObject_treewidget::function_setAllColumnsShowFocus(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bAllColumnsShowFocus",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if (widget())((KviTalTreeWidget *)widget())->setAllColumnsShowFocus(bEnabled); + return true; +} + +bool KviKvsObject_treewidget::function_hideListViewHeader(KviKvsObjectFunctionCall *c) +{ + ((KviTalTreeWidget *)widget())->header()->hide(); + return true; +} + +bool KviKvsObject_treewidget::function_showListViewHeader(KviKvsObjectFunctionCall *c) +{ + ((KviTalTreeWidget *)widget())->header()->show(); + return true; +} + +bool KviKvsObject_treewidget::function_listViewHeaderIsVisible(KviKvsObjectFunctionCall *c) +{ + c->returnValue()->setBoolean(((KviTalTreeWidget *)widget())->header()->isVisible()); + return true; +} + +bool KviKvsObject_treewidget::function_itemClickedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("itemClicked",c,c->params()); + return true; +} + +void KviKvsObject_treewidget::slotClicked(KviTalTreeWidgetItem * i,int col) +{ + KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col); + + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)),column); + callFunction(this,"itemClickedEvent",0,¶ms); +} + +bool KviKvsObject_treewidget::function_selectionChangedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("selectionChanged",c,c->params()); + return true; +} + +void KviKvsObject_treewidget::slotSelectionChanged() +{ + if (((KviTalTreeWidget *)widget())->selectionMode()==KviTalTreeWidget::SingleSelection) + { + KviTalTreeWidgetItem *it=(KviTalTreeWidgetItem *) ((KviTalTreeWidget *)widget())->currentItem(); + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(it))); + callFunction(this,"selectionChangedEvent",0,¶ms); + } + else{ + KviKvsVariantList params(new KviKvsVariant((kvs_hobject_t)0)); + callFunction(this,"selectionChangedEvent",0,¶ms); + } +} + +bool KviKvsObject_treewidget::function_currentChangedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("currentChanged",c,c->params()); + return true; +} + +void KviKvsObject_treewidget::slotCurrentChanged(KviTalTreeWidgetItem * i,KviTalTreeWidgetItem *prev) +{ + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)),new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(prev))); + callFunction(this,"currentChangedEvent",0,¶ms); +} + +bool KviKvsObject_treewidget::function_itemActivatedEvent(KviKvsObjectFunctionCall *c) +{ + //FIXME: compatibility + emitSignal("returnPressed",c,c->params());//<----remove me + // + + emitSignal("itemActivated",c,c->params()); + return true; +} + +void KviKvsObject_treewidget::slotItemActivated(KviTalTreeWidgetItem * i,int col) +{ + KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col); + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)),column); + callFunction(this,"itemActivatedEvent",0,¶ms); +} + +bool KviKvsObject_treewidget::function_onItemEvent(KviKvsObjectFunctionCall *c) +{ + + emitSignal("onItem",c,c->params()); + return true; +} + +void KviKvsObject_treewidget::slotOnItemEntered(KviTalTreeWidgetItem * i,int col) +{ + KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col); + + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i)),column); + callFunction(this,"onItemEvent",0,¶ms); +} + +bool KviKvsObject_treewidget::function_itemExpandedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("itemExpanded",c,c->params()); + return true; +} + +void KviKvsObject_treewidget::slotItemExpanded(KviTalTreeWidgetItem * i) +{ + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i))); + callFunction(this,"itemExpandedEvent",0,¶ms); +} + +bool KviKvsObject_treewidget::function_itemCollapsedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("itemCollapsed",c,c->params()); + return true; +} + +void KviKvsObject_treewidget::slotItemCollapsed(KviTalTreeWidgetItem * i) +{ + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(i))); + callFunction(this,"itemCollapsedEvent",0,¶ms); +} + +bool KviKvsObject_treewidget::function_customContextMenuRequestedEvent(KviKvsObjectFunctionCall *c) +{ + emitSignal("rightButtonClicked",c,c->params()); + emitSignal("customContextMenuRequested",c,c->params()); + return true; +} + +void KviKvsObject_treewidget::customContextMenuRequested(const QPoint &pnt) +{ + KviKvsVariant *xpos=new KviKvsVariant((kvs_int_t)pnt.x()); + KviKvsVariant *ypos=new KviKvsVariant((kvs_int_t)pnt.y()); + KviTalTreeWidgetItem *it=(KviTalTreeWidgetItem *) ((KviTalTreeWidget *)widget())->itemAt(pnt); + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(it)),xpos,ypos); + callFunction(this,"customContextMenuRequestedEvent",0,¶ms); +} + +bool KviKvsObject_treewidget::function_itemChangedEvent(KviKvsObjectFunctionCall *c) +{ + //FIXME + emitSignal("itemRenamed",c,c->params());//<--remove me + + emitSignal("itemChanged",c,c->params()); + return true; +} + +void KviKvsObject_treewidget::slotItemChanged(KviTalTreeWidgetItem *item,int col) +{ + KviKvsVariant *column=new KviKvsVariant((kvs_int_t)col); + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(item)),column); + callFunction(this,"itemChangedEvent",0,¶ms); +} + +void KviKvsObject_treewidget::fileDropped(QString &szFile,KviTalTreeWidgetItem *item) +{ + KviKvsVariant *file=new KviKvsVariant(szFile); + KviKvsVariantList params(new KviKvsVariant(KviKvsObject_treewidgetitem::itemToHandle(item)),file); + callFunction(this,"fileDroppedEvent",0,¶ms); +} + +KviKvsTreeWidget::KviKvsTreeWidget(QWidget * par,const char * name,KviKvsObject_treewidget *parent) +:KviTalTreeWidget(par) +{ + m_pParentScript=parent; + setAcceptDrops(true); + setDragEnabled(true); + setDropIndicatorShown(true); + setDragDropMode(QAbstractItemView::DragDrop); + viewport()->setAcceptDrops(true); +} + +KviKvsTreeWidget::~KviKvsTreeWidget() +{ +} + +void KviKvsTreeWidget::dragEnterEvent( QDragEnterEvent * e ) +{ + debug("Drag enter event"); + if(!e->mimeData()->hasUrls()) + { + debug("Ignore drag"); + e->ignore(); + return; + } +} + +void KviKvsTreeWidget::dropEvent(QDropEvent * e) +{ + debug("Drop event"); + QList list; + if(e->mimeData()->hasUrls()) + { + list = e->mimeData()->urls(); + + if(!list.isEmpty()) + { + QList::Iterator it = list.begin(); + for( ; it != list.end(); ++it ) + { + QUrl url = *it; + QString path = url.path(); + debug("path %s",path.toUtf8().data()); + #if !defined(COMPILE_ON_WINDOWS) && !defined(COMPILE_ON_MINGW) + if(path[0] != '/')path.prepend("/"); //HACK HACK HACK for Qt bug (?!?) + #endif + // KviTalTreeWidgetItem *i = itemAt( contentsToViewport(e->pos()) ); + // m_pParentScript->fileDropped(path,i); + } + } + } +} + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_class_listview.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/class_treewidget.h b/src/modules/objects/class_treewidget.h new file mode 100644 index 000000000..8e72486bf --- /dev/null +++ b/src/modules/objects/class_treewidget.h @@ -0,0 +1,97 @@ +#ifndef _CLASS_TREEWIDGET_H_ +#define _CLASS_TREEWIDGET_H_ +//============================================================================= +// +// File : class_treewidget.h +// Creation date : Fri Jan 28 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2005-2008 Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= + +#include "class_widget.h" +#include "class_treewidgetitem.h" +#include "object_macros.h" + +#include "kvi_tal_treewidget.h" + +class KviKvsObject_treewidget : public KviKvsObject_widget +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_treewidget) + +public: + QWidget * widget() { return (QWidget *)object(); }; + void fileDropped(QString &,KviTalTreeWidgetItem *); +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); + + bool function_addColumn(KviKvsObjectFunctionCall *c); + bool function_setColumnText(KviKvsObjectFunctionCall *c); + bool function_takeItem(KviKvsObjectFunctionCall *c); + bool function_setSorting(KviKvsObjectFunctionCall *c); + bool function_setRootIsDecorated(KviKvsObjectFunctionCall *c); + bool function_clear(KviKvsObjectFunctionCall *c); + bool function_setAllColumnsShowFocus(KviKvsObjectFunctionCall *c); + bool function_itemClickedEvent(KviKvsObjectFunctionCall *c); + bool function_selectionChangedEvent(KviKvsObjectFunctionCall *c); + bool function_currentChangedEvent(KviKvsObjectFunctionCall *c); + bool function_itemActivatedEvent(KviKvsObjectFunctionCall *c); + bool function_onItemEvent(KviKvsObjectFunctionCall *c); + bool function_itemExpandedEvent(KviKvsObjectFunctionCall *c); + bool function_itemCollapsedEvent(KviKvsObjectFunctionCall *c); + bool function_itemChangedEvent(KviKvsObjectFunctionCall *c); + bool function_customContextMenuRequestedEvent(KviKvsObjectFunctionCall *c); + bool function_selectedItems(KviKvsObjectFunctionCall *c); + bool function_currentItem(KviKvsObjectFunctionCall *c); + bool function_setSelectionMode(KviKvsObjectFunctionCall *c); + bool function_firstChild(KviKvsObjectFunctionCall *c); + bool function_listViewHeaderIsVisible(KviKvsObjectFunctionCall *c); + bool function_showListViewHeader(KviKvsObjectFunctionCall *c); + bool function_hideListViewHeader(KviKvsObjectFunctionCall *c); + bool function_setAcceptDrops(KviKvsObjectFunctionCall *c); + bool function_setHeaderLabels(KviKvsObjectFunctionCall *c); + bool function_setColumnCount(KviKvsObjectFunctionCall *c); +protected slots: + void slotClicked(KviTalTreeWidgetItem *,int); + void customContextMenuRequested(const QPoint &pnt); + void slotSelectionChanged(); + void slotCurrentChanged(KviTalTreeWidgetItem *,KviTalTreeWidgetItem *); + void slotItemActivated(KviTalTreeWidgetItem *,int col); + void slotOnItemEntered(KviTalTreeWidgetItem *,int col); + void slotItemExpanded(KviTalTreeWidgetItem *); + void slotItemCollapsed(KviTalTreeWidgetItem *); + void slotItemChanged(KviTalTreeWidgetItem *,int); +}; + +class KviKvsTreeWidget : public KviTalTreeWidget +{ + Q_OBJECT +public: + KviKvsTreeWidget(QWidget * par, const char * name, KviKvsObject_treewidget *); + virtual ~KviKvsTreeWidget(); +protected: + KviKvsObject_treewidget * m_pParentScript; +protected: + void dropEvent(QDropEvent * e); + void dragEnterEvent(QDragEnterEvent * e); +}; + +#endif // _CLASS_TREEWIDGET_H_ diff --git a/src/modules/objects/class_treewidgetitem.cpp b/src/modules/objects/class_treewidgetitem.cpp new file mode 100644 index 000000000..7ff677f2f --- /dev/null +++ b/src/modules/objects/class_treewidgetitem.cpp @@ -0,0 +1,480 @@ +//============================================================================= +// +// File : class_treewidgetitem.cpp +// Creation date : Fri Jan 28 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2005-2008 Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= + +#include "class_treewidgetitem.h" +#include "class_pixmap.h" + +#include "kvi_error.h" +#include "kvi_debug.h" +#include "kvi_locale.h" +#include "kvi_iconmanager.h" + +const int item_flags[] = { + Qt::ItemIsSelectable, + Qt::ItemIsEditable, + Qt::ItemIsDragEnabled, + Qt::ItemIsDropEnabled, + Qt::ItemIsUserCheckable, + Qt::ItemIsEnabled, + Qt::ItemIsTristate +}; + +const char * const itemflags_tbl[] = { + "selectable", + "editable", + "dragEnabled", + "dropEnabled", + "userCheckable", + "enabled", + "tristate" +}; + +#define itemflags_num (sizeof(itemflags_tbl) / sizeof(itemflags_tbl[0])) + + + +/* + @doc: treewidgetitem + @keyterms: + treewidget treewidgetitem class + @title: + treewidgetitem class + @type: + class + @short: + A treewidgetitem class + @inherits: + [class]treewidgetitem[/class] + @description: + The treewidgetitem class implements a list view item. + A list view item is a multi-column object capable of displaying itself in a [class]treewidget[/class]. + To use this class you must instantiate it with another treewidgetitem or a [class]treewidget[/class] + as parent. The item will be automatically displayed. + You can set the text and a pixmap in each column and you can make it checkable + with [classfnc:treewidgetitem]$setCheckable[/classfnc](). + A checkable treewidgetitem will display a small check mark in the first column. + @functions: + !fn: $setText(,) + Sets the text in column column to text, if column is a valid column number and text is different from the existing text. + + !fn: $text() + Returs the text of the specified column. + + !fn: $setPixmap(,) + Sets the pixmap in column column to pm, if pm is non-null and different from the current pixmap, and if column is non-negative. + Pixmap can be a Kvirc imageid, an image file or a [class]pixmap[/class] object. + + !fn: $setRenameEnabled(,) + If b is TRUE (1), this item can be in-place renamed in the column col by the user; otherwise it cannot be renamed in-place. + + !fn: $setEnabled() + Enables or disables the item + + !fn: $isEnabled() + Returns $true if this item is enabled and $false otherwise + + !fn: $setOpen() + Opens or closes the item to show its children items + + !fn: $isOpen() + Returns the open state of this item + + !fn: $setCheckable() + Makes this item checkable or not. This function should be called immediately + after the item creation: changing this property later at runtime may have + strange results (like the item being moved inside the list, text disappearing, + hidden children etc... don't do it :D ). + + !fn: $isCheckable() + Returns $true if this item is checkable and $false otherwise + + !fn: $setChecked() + Sets this item to be checked or not. [classfnc:treewidgetitem]$setCheckable[/classfnc]() must + have been previously called. + + !fn: $isChecked() + Returns the check status of this item. [classfnc:treewidgetitem]$setCheckable[/classfnc]() must + have been previously called. + + !fn: $firstChild() + Returns the first child item of this treewidgetitem or $null if this item has no children. + + !fn: $nextSibling() + Returns the next sibling item of this treewidgetitem or $null if there are no sibling items. + Next sibling stands for the item at the same tree level coming just after :) +*/ + + +//=========================================================================================== + +KVSO_BEGIN_REGISTERCLASS(KviKvsObject_treewidgetitem,"listviewitem","object") + KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"setText",function_setText) + KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"text",function_text) + KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"setPixmap",function_setPixmap); + KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"setRenameEnabled",function_setRenameEnabled); + //KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"setEnabled",function_setEnabled); + //KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"isEnabled",function_isEnabled); + KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"setOpen",function_setOpen); + KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"isOpen",function_isOpen); + //KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"setCheckable",function_setCheckable); + //KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"isCheckable",function_isCheckable); + KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"setChecked",function_setChecked); + KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"isChecked",function_isChecked); + KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"firstChild",function_firstChild); + KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"setFlags",function_setFlags); + + //KVSO_REGISTER_HANDLER(KviKvsObject_treewidgetitem,"nextSibling",function_nextSibling); +KVSO_END_REGISTERCLASS(KviKvsObject_treewidgetitem) + + +KVSO_BEGIN_CONSTRUCTOR(KviKvsObject_treewidgetitem,KviKvsObject) + + m_pTreeWidgetItem = 0; + +KVSO_END_CONSTRUCTOR(KviKvsObject_treewidgetitem) + + +KVSO_BEGIN_DESTRUCTOR(KviKvsObject_treewidgetitem) + + if(m_pTreeWidgetItem)delete m_pTreeWidgetItem; + +KVSO_END_CONSTRUCTOR(KviKvsObject_treewidgetitem) + +bool KviKvsObject_treewidgetitem::init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams) +{ + if (!parentObject()) + { + pContext->error(__tr2qs("The treewidgetitem cannot be parentless")); + return false; + } + if(parentObject()->inherits("KviKvsObject_treewidgetitem")) + { + m_pTreeWidgetItem = new KviKvsStandardTreeWidgetItem(this,((KviKvsObject_treewidgetitem *)parentObject())->m_pTreeWidgetItem); + } else { + if(parentObject()->inherits("KviKvsObject_treewidget")) + m_pTreeWidgetItem = new KviKvsStandardTreeWidgetItem(this,((KviTalTreeWidget *)parentScriptWidget())); + else { + pContext->error(__tr2qs("The parent of the treewidgetitem must be either another treewidgetitem or a treewidget")); + return false; + } + } + return true; +} + +void KviKvsObject_treewidgetitem::childDestroyed() +{ + if(m_pTreeWidgetItem == 0)return; + m_pTreeWidgetItem = 0; + die(); +} + +KviKvsStandardTreeWidgetItem::KviKvsStandardTreeWidgetItem(KviKvsObject_treewidgetitem * ob,KviTalTreeWidget * par) +:KviTalTreeWidgetItem(par), m_pMasterObject(ob) +{ +} + +KviKvsStandardTreeWidgetItem::KviKvsStandardTreeWidgetItem(KviKvsObject_treewidgetitem * ob,KviTalTreeWidgetItem * par) +:KviTalTreeWidgetItem(par), m_pMasterObject(ob) +{ +} + +KviKvsStandardTreeWidgetItem::~KviKvsStandardTreeWidgetItem() +{ + if(m_pMasterObject)m_pMasterObject->childDestroyed(); +} + +/* +KviKvsCheckTreeWidgetItem::KviKvsCheckTreeWidgetItem(KviKvsObject_treewidgetitem * ob,KviTalTreeWidget * par) +:KviTalCheckListItem(par,QString::null,KviTalCheckListItem::CheckBox), m_pMasterObject(ob) +{ +} + +KviKvsCheckTreeWidgetItem::KviKvsCheckTreeWidgetItem(KviKvsObject_treewidgetitem * ob,KviTalTreeWidgetItem * par) +:KviTalCheckListItem(par,QString::null,KviTalCheckListItem::CheckBox), m_pMasterObject(ob) +{ +} + +KviKvsCheckTreeWidgetItem::~KviKvsCheckTreeWidgetItem() +{ + if(m_pMasterObject)m_pMasterObject->childDestroyed(); +} +*/ + +kvs_hobject_t KviKvsObject_treewidgetitem::itemToHandle(KviTalTreeWidgetItem * it) +{ + if(!it)return (kvs_hobject_t)0; + KviKvsObject_treewidgetitem * pObject; + //if(it->rtti() == 1)pObject = ((KviKvsCheckTreeWidgetItem *)it)->masterObject(); + //else + pObject = ((KviKvsStandardTreeWidgetItem *)it)->masterObject(); + if(!pObject)return (kvs_hobject_t)0; + return pObject->handle(); +} + +bool KviKvsObject_treewidgetitem::function_setText(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uCol; + QString szText; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETER("text",KVS_PT_STRING,0,szText) + KVSO_PARAMETERS_END(c) + if(m_pTreeWidgetItem) + m_pTreeWidgetItem->setText(uCol,szText); + return true; +} + +bool KviKvsObject_treewidgetitem::function_firstChild(KviKvsObjectFunctionCall *c) +{ + if(m_pTreeWidgetItem) + c->returnValue()->setHObject(itemToHandle((KviTalTreeWidgetItem*)m_pTreeWidgetItem->child(0))); + else + c->returnValue()->setHObject((kvs_hobject_t)0); + return true; +} +/* +bool KviKvsObject_treewidgetitem::function_nextSibling(KviKvsObjectFunctionCall *c) +{ + if(m_pTreeWidgetItem) + c->returnValue()->setHObject(itemToHandle(m_pTreeWidgetItem->nextSibling())); + else + c->returnValue()->setHObject((kvs_hobject_t)0); + return true; +} +*/ +bool KviKvsObject_treewidgetitem::function_setRenameEnabled(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uCol; + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(m_pTreeWidgetItem) + m_pTreeWidgetItem->setFlags(m_pTreeWidgetItem->flags()|Qt::ItemIsEditable); + return true; +} + +bool KviKvsObject_treewidgetitem::function_setFlags(KviKvsObjectFunctionCall *c) +{ + QStringList itemflags; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("flags",KVS_PT_STRINGLIST,KVS_PF_OPTIONAL,itemflags) + KVSO_PARAMETERS_END(c) + int flag,sum=0; + for ( int i=0;isetCheckState(0,Qt::Unchecked); + sum = sum | flag; + } + else + c->warning(__tr2qs("Unknown item flag: %s"),&itemflags.at(i)); + } + if(m_pTreeWidgetItem) + m_pTreeWidgetItem->setFlags((Qt::ItemFlags)sum); + + return true; +} +/* +bool KviKvsObject_treewidgetitem::function_setEnabled(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(m_pTreeWidgetItem) + m_pTreeWidgetItem->setEnabled(bEnabled); + return true; +} + +bool KviKvsObject_treewidgetitem::function_isEnabled(KviKvsObjectFunctionCall *c) +{ + if(!m_pTreeWidgetItem) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(m_pTreeWidgetItem->isEnabled()); + return true; +} +*/ +bool KviKvsObject_treewidgetitem::function_setOpen(KviKvsObjectFunctionCall *c) +{ + bool bEnabled; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bEnabled",KVS_PT_BOOL,0,bEnabled) + KVSO_PARAMETERS_END(c) + if(m_pTreeWidgetItem) + m_pTreeWidgetItem->setExpanded(bEnabled); + return true; +} + +bool KviKvsObject_treewidgetitem::function_isOpen(KviKvsObjectFunctionCall *c) +{ + if(!m_pTreeWidgetItem) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(m_pTreeWidgetItem->isExpanded()); + return true; +} + +bool KviKvsObject_treewidgetitem::function_setChecked(KviKvsObjectFunctionCall *c) +{ + bool bChecked; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bChecked",KVS_PT_BOOL,0,bChecked) + KVSO_PARAMETERS_END(c) + if(!m_pTreeWidgetItem)return true; + //if(m_pTreeWidgetItem->rtti() != 1)return true; // not a QCheckListItem + ((KviTalTreeWidgetItem *)m_pTreeWidgetItem)->setCheckState(0,bChecked?Qt::Checked:Qt::Unchecked); + return true; +} + +bool KviKvsObject_treewidgetitem::function_isChecked(KviKvsObjectFunctionCall *c) +{ + if(!m_pTreeWidgetItem) + { + c->returnValue()->setBoolean(false); + return true; + } + /*if(m_pTreeWidgetItem->rtti() != 1) + { + c->returnValue()->setBoolean(false); + return true; + } + */ + c->returnValue()->setBoolean(((KviTalTreeWidgetItem *)m_pTreeWidgetItem)->checkState(0)==Qt::Checked?1:0); + return true; +} +/* +bool KviKvsObject_treewidgetitem::function_setCheckable(KviKvsObjectFunctionCall *c) +{ + bool bCheckable; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("bCheckable",KVS_PT_BOOL,0,bCheckable) + KVSO_PARAMETERS_END(c) + if(!m_pTreeWidgetItem)return true; + if(bCheckable) + { + if(m_pTreeWidgetItem->rtti() == 1)return true; // a QCheckListItem already + KviTalTreeWidgetItem * pParent = m_pTreeWidgetItem->parent(); + KviTalTreeWidget * pLV = (KviTalTreeWidget *)m_pTreeWidgetItem->listView(); + // swap the items, so we don't die now + KviTalTreeWidgetItem * pThis = m_pTreeWidgetItem; + m_pTreeWidgetItem = 0; + delete pThis; + if(pParent) + m_pTreeWidgetItem = new KviKvsCheckTreeWidgetItem(this,pParent); + else + m_pTreeWidgetItem = new KviKvsCheckTreeWidgetItem(this,pLV); + } else { + if(m_pTreeWidgetItem->rtti() != 1)return true; // not a QCheckListItem yet + KviTalTreeWidgetItem * pParent = m_pTreeWidgetItem->parent(); + KviTalTreeWidget * pLV = (KviTalTreeWidget *)m_pTreeWidgetItem->listView(); + // swap the items, so we don't die now + KviTalTreeWidgetItem * pThis = m_pTreeWidgetItem; + m_pTreeWidgetItem = 0; + delete pThis; + if(pParent) + m_pTreeWidgetItem = new KviKvsStandardTreeWidgetItem(this,pParent); + else + m_pTreeWidgetItem = new KviKvsStandardTreeWidgetItem(this,pLV); + } + return true; +} + +bool KviKvsObject_treewidgetitem::function_isCheckable(KviKvsObjectFunctionCall *c) +{ + if(!m_pTreeWidgetItem) + { + c->returnValue()->setBoolean(false); + return true; + } + c->returnValue()->setBoolean(m_pTreeWidgetItem->rtti() == 1); + return true; +} +*/ +bool KviKvsObject_treewidgetitem::function_text(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uCol; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETERS_END(c) + if(m_pTreeWidgetItem) + c->returnValue()->setString(m_pTreeWidgetItem->text(uCol)); + return true; +} + +bool KviKvsObject_treewidgetitem::function_setPixmap(KviKvsObjectFunctionCall *c) +{ + kvs_uint_t uCol; + KviKvsObject *obPixmap; + kvs_hobject_t obHpixmap; + KviKvsVariant * vPixmap; + KVSO_PARAMETERS_BEGIN(c) + KVSO_PARAMETER("column",KVS_PT_UNSIGNEDINTEGER,0,uCol) + KVSO_PARAMETER("pixmap",KVS_PT_VARIANT,0,vPixmap) + KVSO_PARAMETERS_END(c) + QPixmap *pix = 0; + if(vPixmap->isHObject()) + { + vPixmap->asHObject(obHpixmap); + obPixmap=KviKvsKernel::instance()->objectController()->lookupObject(obHpixmap); + if (!obPixmap->inherits("KviKvsObject_pixmap")) + { + c->warning(__tr2qs("Pixmap object or image Id required")); + return true; + } + pix=((KviKvsObject_pixmap *)obPixmap)->getPixmap(); + } else { + QString szPix; + vPixmap->asString(szPix); + pix=g_pIconManager->getImage(szPix); + if(!pix) + { + c->warning(__tr2qs("Error occured: the suitable file '%Q' is not of the correct format or it is not a valid icon number."),&szPix); + return true; + } + } + m_pTreeWidgetItem->setIcon(uCol,QIcon(*pix)); + return true; +} + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "m_class_listviewitem.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/modules/objects/class_treewidgetitem.h b/src/modules/objects/class_treewidgetitem.h new file mode 100644 index 000000000..2fa65975c --- /dev/null +++ b/src/modules/objects/class_treewidgetitem.h @@ -0,0 +1,92 @@ +#ifndef _CLASS_TREEWIDGETITEM_H_ +#define _CLASS_TREEWIDGETITEM_H_ +//============================================================================= +// +// File : class_treewidgetitem.h +// Creation date : Fri Jan 28 14:21:48 CEST 2005 +// by Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2005-2008 Tonino Imbesi(Grifisx) and Alessandro Carbone(Noldor) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +// See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, write to the Free Software Foundation, +// Inc. ,59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +//============================================================================= + + +#include "class_widget.h" +#include "object_macros.h" + +#include "kvi_tal_treewidget.h" + +class KviKvsObject_treewidgetitem : public KviKvsObject +{ + Q_OBJECT +public: + KVSO_DECLARE_OBJECT(KviKvsObject_treewidgetitem) + void childDestroyed(); +protected: + KviTalTreeWidgetItem * m_pTreeWidgetItem; +protected: + virtual bool init(KviKvsRunTimeContext * pContext,KviKvsVariantList *pParams); +protected: + bool function_setText(KviKvsObjectFunctionCall *c); + bool function_insertItem(KviKvsObjectFunctionCall *c); + bool function_setPixmap(KviKvsObjectFunctionCall *c); + bool function_setRenameEnabled(KviKvsObjectFunctionCall *c); + bool function_setEnabled(KviKvsObjectFunctionCall *c); + bool function_isEnabled(KviKvsObjectFunctionCall *c); + bool function_setOpen(KviKvsObjectFunctionCall *c); + bool function_isOpen(KviKvsObjectFunctionCall *c); + bool function_text(KviKvsObjectFunctionCall *c); + bool function_setCheckable(KviKvsObjectFunctionCall *c); + bool function_isCheckable(KviKvsObjectFunctionCall *c); + bool function_setChecked(KviKvsObjectFunctionCall *c); + bool function_isChecked(KviKvsObjectFunctionCall *c); + bool function_firstChild(KviKvsObjectFunctionCall *c); + //bool function_nextSibling(KviKvsObjectFunctionCall *c); + bool function_setFlags(KviKvsObjectFunctionCall *c); + +public: + static kvs_hobject_t itemToHandle(KviTalTreeWidgetItem * it); +}; + + +class KviKvsStandardTreeWidgetItem : public KviTalTreeWidgetItem +{ +public: + KviKvsStandardTreeWidgetItem(KviKvsObject_treewidgetitem * ob,KviTalTreeWidget * par); + KviKvsStandardTreeWidgetItem(KviKvsObject_treewidgetitem * ob,KviTalTreeWidgetItem * par); + virtual ~KviKvsStandardTreeWidgetItem(); +protected: + KviKvsObject_treewidgetitem * m_pMasterObject; +public: + KviKvsObject_treewidgetitem * masterObject(){ return m_pMasterObject; } +}; + +/* +class KviKvsCheckTreeWidgetItem : public KviTalCheckListItem +{ +public: + KviKvsCheckTreeWidgetItem(KviKvsObject_treewidgetitem * ob,KviTalTreeWidget * par); + KviKvsCheckTreeWidgetItem(KviKvsObject_treewidgetitem * ob,KviTalTreeWidgetItem * par); + virtual ~KviKvsCheckTreeWidgetItem(); +protected: + KviKvsObject_treewidgetitem * m_pMasterObject; +public: + KviKvsObject_treewidgetitem * masterObject(){ return m_pMasterObject; } +}; +*/ +#endif // _CLASS_TREEWIDGETITEM_H_ diff --git a/src/modules/objects/libkviobjects.cpp b/src/modules/objects/libkviobjects.cpp index 275f1a06a..af33d636b 100644 --- a/src/modules/objects/libkviobjects.cpp +++ b/src/modules/objects/libkviobjects.cpp @@ -33,13 +33,12 @@ #include "class_buttongroup.h" #include "class_hbox.h" #include "class_http.h" +#include "class_label.h" #include "class_layout.h" #include "class_lcd.h" #include "class_lineedit.h" #include "class_list.h" #include "class_listbox.h" -#include "class_listview.h" -#include "class_listviewitem.h" #include "class_mainwindow.h" #include "class_menubar.h" #include "class_multilineedit.h" @@ -56,7 +55,8 @@ #include "class_tbrowser.h" #include "class_toolbar.h" #include "class_toolbutton.h" -#include "class_label.h" +#include "class_treewidget.h" +#include "class_treewidgetitem.h" #include "class_vbox.h" #include "class_widget.h" #include "class_window.h" @@ -77,7 +77,6 @@ #include "kvi_out.h" #include "kvi_app.h" #include "kvi_fileutils.h" -#include "kvi_tal_listview.h" #include #include -- cgit v1.3.1-10-gc9f91