20 #include "kmlistview.h"
21 #include "kmprinter.h"
25 #include <tqpainter.h>
26 #include <tdelocale.h>
27 #include <kiconloader.h>
30 class KMListViewItem :
public TQListViewItem,
public KMObject
33 KMListViewItem(TQListView *parent,
const TQString& txt);
34 KMListViewItem(TQListViewItem *parent,
const TQString& txt);
35 KMListViewItem(TQListViewItem *parent, KMPrinter *p);
37 virtual void paintCell(TQPainter*,
const TQColorGroup&,
int,
int,
int);
38 void updatePrinter(KMPrinter *p);
39 bool isClass()
const {
return m_isclass; }
42 void init(KMPrinter *p = 0);
49 KMListViewItem::KMListViewItem(TQListView *parent,
const TQString& txt)
50 : TQListViewItem(parent,txt)
55 KMListViewItem::KMListViewItem(TQListViewItem *parent,
const TQString& txt)
56 : TQListViewItem(parent,txt)
61 KMListViewItem::KMListViewItem(TQListViewItem *parent, KMPrinter *p)
62 : TQListViewItem(parent)
67 void KMListViewItem::init(KMPrinter *p)
72 setSelectable(depth() == 2);
75 void KMListViewItem::updatePrinter(KMPrinter *p)
80 int oldstate = m_state;
81 int st(p->isValid() ? (
int)TDEIcon::DefaultState : (
int)TDEIcon::LockOverlay);
82 m_state = ((p->isHardDefault() ? 0x1 : 0x0) | (p->ownSoftDefault() ? 0x2 : 0x0) | (p->isValid() ? 0x4 : 0x0));
83 update = (oldstate != m_state);
84 TQString name = (p->isVirtual() ? p->instanceName() : p->name());
87 setPixmap(0, SmallIcon(p->pixmap(), 0, st));
88 m_isclass = p->isClass();
95 void KMListViewItem::paintCell(TQPainter *p,
const TQColorGroup& cg,
int c,
int w,
int a)
100 if (m_state & 0x1) f.setBold(
true);
101 if (m_state & 0x2) f.setItalic(
true);
104 TQListViewItem::paintCell(p,cg,c,w,a);
109 KMListView::KMListView(TQWidget *parent,
const char *name)
110 : TQListView(parent,name)
112 m_items.setAutoDelete(
false);
116 setFrameStyle(TQFrame::WinPanel|TQFrame::Sunken);
120 connect(
this,TQ_SIGNAL(contextMenuRequested(TQListViewItem*,
const TQPoint&,
int)),TQ_SLOT(slotRightButtonClicked(TQListViewItem*,
const TQPoint&,
int)));
121 connect(
this,TQ_SIGNAL(selectionChanged()),TQ_SLOT(slotSelectionChanged()));
122 connect(
this,TQ_SIGNAL(onItem(TQListViewItem*)),TQ_SLOT(slotOnItem(TQListViewItem*)));
123 connect(
this,TQ_SIGNAL(onViewport()),TQ_SLOT(slotOnViewport()));
125 m_root =
new KMListViewItem(
this,i18n(
"Print System"));
126 m_root->setPixmap(0,SmallIcon(
"tdeprint_printer"));
127 m_root->setOpen(
true);
128 m_classes =
new KMListViewItem(m_root,i18n(
"Classes"));
129 m_classes->setPixmap(0,SmallIcon(
"package"));
130 m_classes->setOpen(
true);
131 m_printers =
new KMListViewItem(m_root,i18n(
"Printers"));
132 m_printers->setPixmap(0,SmallIcon(
"package"));
133 m_printers->setOpen(
true);
134 m_specials =
new KMListViewItem(m_root,i18n(
"Specials"));
135 m_specials->setPixmap(0,SmallIcon(
"package"));
136 m_specials->setOpen(
true);
141 KMListView::~KMListView()
145 void KMListView::slotRightButtonClicked(TQListViewItem *item,
const TQPoint& p,
int)
147 emit rightButtonClicked(item && item->depth() == 2 ? item->text(0) : TQString::null, p);
150 KMListViewItem* KMListView::findItem(KMPrinter *p)
154 TQPtrListIterator<KMListViewItem> it(m_items);
155 bool isVirtual(p->isVirtual()), isClass(p->isClass());
156 for (;it.current();++it)
159 if (it.current()->depth() == 3 && it.current()->text(0) == p->instanceName()
160 && it.current()->parent()->text(0) == p->printerName())
165 if (it.current()->isClass() == isClass && it.current()->text(0) == p->name())
172 KMListViewItem* KMListView::findItem(
const TQString& prname)
174 TQPtrListIterator<KMListViewItem> it(m_items);
175 for (; it.current(); ++it)
176 if (it.current()->depth() == 2 && it.current()->text(0) == prname)
181 void KMListView::setPrinterList(TQPtrList<KMPrinter> *list)
185 TQPtrListIterator<KMListViewItem> it(m_items);
186 for (;it.current();++it)
187 it.current()->setDiscarded(
true);
191 TQPtrListIterator<KMPrinter> it(*list);
192 KMListViewItem *item (0);
193 for (;it.current();++it)
195 item = findItem(it.current());
198 if (it.current()->isVirtual())
200 KMListViewItem *pItem = findItem(it.current()->printerName());
203 item =
new KMListViewItem(pItem, it.current());
204 pItem->setOpen(
true);
207 item =
new KMListViewItem((it.current()->isSpecial() ? m_specials : (it.current()->isClass(
false) ? m_classes : m_printers)),it.current());
208 m_items.append(item);
212 item->updatePrinter(it.current());
216 TQPtrList<KMListViewItem> deleteList;
217 deleteList.setAutoDelete(
true);
218 for (uint i=0; i<m_items.count(); i++)
219 if (m_items.at(i)->isDiscarded())
223 KMListViewItem *item = m_items.take(i);
224 if (item->depth() == 2)
225 deleteList.append(item);
227 deleteList.prepend(item);
234 emit selectionChanged();
237 void KMListView::slotSelectionChanged()
239 KMListViewItem *item =
static_cast<KMListViewItem*
>(currentItem());
240 emit printerSelected((item && !item->isDiscarded() && item->depth() == 2 ? item->text(0) : TQString::null));
243 void KMListView::setPrinter(
const TQString& prname)
245 TQPtrListIterator<KMListViewItem> it(m_items);
246 for (;it.current();++it)
247 if (it.current()->text(0) == prname)
249 setSelected(it.current(),
true);
254 void KMListView::setPrinter(KMPrinter *p)
256 setPrinter(p ? p->name() : TQString::null);
259 void KMListView::slotOnItem(TQListViewItem *)
261 setCursor(KCursor::handCursor());
264 void KMListView::slotOnViewport()
266 setCursor(KCursor::arrowCursor());
268 #include "kmlistview.moc"