20 #include "treecombobox.h"
22 #include <tqpainter.h>
24 TreeListBoxItem::TreeListBoxItem(TQListBox *lb,
const TQPixmap& pix,
const TQString& txt,
bool oneBlock)
25 : TQListBoxPixmap(pix, txt)
28 m_path = TQStringList(txt);
30 m_path = TQStringList::split(
'/', text(),
false);
31 m_depth = m_path.count()-1;
32 m_child = m_next = m_parent = 0;
38 while (item && item->m_next)
46 TQString parentStr = txt.left(txt.length()-m_path[m_depth].length()-1);
56 while (childItem->next())
59 if (nextItem->m_depth >= m_depth)
62 if (childItem->m_depth == m_depth)
69 lb->insertItem(
this, childItem);
70 m_parent = parentItem;
72 prevItem->m_next =
this;
74 parentItem->m_child =
this;
78 int TreeListBoxItem::width(
const TQListBox *lb)
const
80 int w = m_depth * stepSize() + 2;
82 w += (pixmap()->width() + 2);
83 if (!m_path[m_depth].isEmpty())
84 w += (lb->fontMetrics().width(m_path[m_depth]) + 2);
85 return TQMAX(w, TQListBoxPixmap::width(lb));
88 void TreeListBoxItem::paint(TQPainter *p)
90 if(!
static_cast<TreeListBox*
>(listBox())->m_painting)
92 TQListBoxPixmap::paint(p);
96 const TQPixmap *pix = pixmap();
97 TQRect r = p->viewport();
98 int h = height(listBox());
99 int xo = (m_depth * stepSize() + 2);
100 int yo = (pix ? (h-pix->height())/2 : 0);
104 TQPen oldPen = p->pen();
105 p->setPen(listBox()->colorGroup().mid());
108 int s = xo-stepSize()/2;
109 p->drawLine(s, r.top(), s, h/2);
110 p->drawLine(s, h/2, s+stepSize()/2-2, h/2);
111 while (item->m_parent)
114 p->drawLine(s, r.top(), s, h);
115 item = item->m_parent;
123 p->drawPixmap(xo, yo, *pix);
124 xo += (pix->width() + 2);
126 p->drawText(xo, 0, r.width()-xo, height(listBox()), TQt::AlignLeft, m_path[m_depth]);
131 TreeListBox::TreeListBox(TQWidget *parent,
const char *name)
132 : TQListBox(parent, name)
137 void TreeListBox::paintCell(TQPainter *p,
int row,
int col)
140 TQListBox::paintCell(p, row, col);
146 TreeComboBox::TreeComboBox(TQWidget *parent,
const char *name)
147 : TQComboBox(parent, name)
150 setListBox(m_listbox);
153 void TreeComboBox::insertItem(
const TQPixmap& pix,
const TQString& txt,
bool oneBlock)
Class that represents a single object in the tree.
Class for the listbox shown on popup.