• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
treecombobox.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License version 2 as published by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  **/
19 
20 #include "treecombobox.h"
21 
22 #include <tqpainter.h>
23 
24 TreeListBoxItem::TreeListBoxItem(TQListBox *lb, const TQPixmap& pix, const TQString& txt, bool oneBlock)
25  : TQListBoxPixmap(pix, txt)
26 {
27  if (oneBlock)
28  m_path = TQStringList(txt);
29  else
30  m_path = TQStringList::split('/', text(), false);
31  m_depth = m_path.count()-1;
32  m_child = m_next = m_parent = 0;
33 
34  // insert into QListBox
35  if (m_depth == 0)
36  {
37  TreeListBoxItem *item = static_cast<TreeListBoxItem*>(lb->item(0));
38  while (item && item->m_next)
39  item = item->m_next;
40  lb->insertItem(this);
41  if (item)
42  item->m_next = this;
43  }
44  else
45  {
46  TQString parentStr = txt.left(txt.length()-m_path[m_depth].length()-1);
47  TreeListBoxItem *parentItem = static_cast<TreeListBoxItem*>(lb->findItem(parentStr, TQt::ExactMatch));
48  if (!parentItem)
49  {
50  // parent not found, add parent first into QListBox
51  parentItem = new TreeListBoxItem(lb, TQPixmap(), parentStr);
52  }
53  // search last "child" of the parent item, to put the new one
54  // at the end
55  TreeListBoxItem *childItem = static_cast<TreeListBoxItem*>(parentItem), *prevItem = 0;
56  while (childItem->next())
57  {
58  TreeListBoxItem *nextItem = static_cast<TreeListBoxItem*>(childItem->next());
59  if (nextItem->m_depth >= m_depth)
60  {
61  childItem = nextItem;
62  if (childItem->m_depth == m_depth)
63  prevItem = childItem;
64  }
65  else
66  break;
67  }
68  // eventually insert item
69  lb->insertItem(this, childItem);
70  m_parent = parentItem;
71  if (prevItem)
72  prevItem->m_next = this;
73  else
74  parentItem->m_child = this;
75  }
76 }
77 
78 int TreeListBoxItem::width(const TQListBox *lb) const
79 {
80  int w = m_depth * stepSize() + 2;
81  if (pixmap())
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));
86 }
87 
88 void TreeListBoxItem::paint(TQPainter *p)
89 {
90  if(!static_cast<TreeListBox*>(listBox())->m_painting)
91  {
92  TQListBoxPixmap::paint(p);
93  return;
94  }
95 
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);
101 
102  if (m_depth > 0)
103  {
104  TQPen oldPen = p->pen();
105  p->setPen(listBox()->colorGroup().mid());
106 
107  TreeListBoxItem *item = this;
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)
112  {
113  if (item->m_next)
114  p->drawLine(s, r.top(), s, h);
115  item = item->m_parent;
116  s -= stepSize();
117  }
118 
119  p->setPen(oldPen);
120  }
121  if (pix)
122  {
123  p->drawPixmap(xo, yo, *pix);
124  xo += (pix->width() + 2);
125  }
126  p->drawText(xo, 0, r.width()-xo, height(listBox()), TQt::AlignLeft, m_path[m_depth]);
127 }
128 
129 //-----------------------------------------------------------------------------------------
130 
131 TreeListBox::TreeListBox(TQWidget *parent, const char *name)
132  : TQListBox(parent, name)
133 {
134  m_painting = false;
135 }
136 
137 void TreeListBox::paintCell(TQPainter *p, int row, int col)
138 {
139  m_painting = true;
140  TQListBox::paintCell(p, row, col);
141  m_painting = false;
142 }
143 
144 //-----------------------------------------------------------------------------------------
145 
146 TreeComboBox::TreeComboBox(TQWidget *parent, const char *name)
147  : TQComboBox(parent, name)
148 {
149  m_listbox = new TreeListBox(this);
150  setListBox(m_listbox);
151 }
152 
153 void TreeComboBox::insertItem(const TQPixmap& pix, const TQString& txt, bool oneBlock)
154 {
155  new TreeListBoxItem(m_listbox, pix, txt, oneBlock);
156 }
TreeListBoxItem
Class that represents a single object in the tree.
Definition: treecombobox.h:31
TreeListBox
Class for the listbox shown on popup.
Definition: treecombobox.h:51

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.9.1
This website is maintained by Timothy Pearson.