#include "treecombobox.h"
CTreeComboBox::CTreeComboBox(QWidget *parent) :
QComboBox(parent),newmenu(),lastadded(0),lfont()
{
}
void CTreeComboBox::showPopup()
{
if(lastadded)
{
newmenu.setMinimumWidth(width());
QAction * a=newmenu.exec(mapToGlobal(QPoint(0,0)));
if(a)
setCurrentIndex(a->data().toInt());
}
}
void CTreeComboBox::hidePopup()
{
newmenu.close();
}
void CTreeComboBox::appendBranch(QString const & branch)
{
lastadded=newmenu.addMenu(branch);
lastadded->setFont(lfont);
//menulist.append(branch);
}
void CTreeComboBox::appendItemToLastBranch(QString const & item,const QVariant & userData)
{
if(lastadded)
{
addItem(item,userData);
QAction * a=lastadded->addAction(item);
a->setData((int)(count()-1));
}
}
void CTreeComboBox::clear()
{
QComboBox::clear();
newmenu.clear();
lastadded=0;
}
void CTreeComboBox::setFont(QFont const & f)
{
lfont=f;
QComboBox::setFont(lfont);
newmenu.setFont(lfont);
}