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

tdeprint

  • tdeprint
  • management
kmlistview.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 "kmlistview.h"
21#include "kmprinter.h"
22#include "kmobject.h"
23
24#include <tqheader.h>
25#include <tqpainter.h>
26#include <tdelocale.h>
27#include <kiconloader.h>
28#include <kcursor.h>
29
30class KMListViewItem : public TQListViewItem, public KMObject
31{
32public:
33 KMListViewItem(TQListView *parent, const TQString& txt);
34 KMListViewItem(TQListViewItem *parent, const TQString& txt);
35 KMListViewItem(TQListViewItem *parent, KMPrinter *p);
36
37 virtual void paintCell(TQPainter*, const TQColorGroup&, int, int, int);
38 void updatePrinter(KMPrinter *p);
39 bool isClass() const { return m_isclass; }
40
41protected:
42 void init(KMPrinter *p = 0);
43
44private:
45 int m_state;
46 bool m_isclass;
47};
48
49KMListViewItem::KMListViewItem(TQListView *parent, const TQString& txt)
50: TQListViewItem(parent,txt)
51{
52 init();
53}
54
55KMListViewItem::KMListViewItem(TQListViewItem *parent, const TQString& txt)
56: TQListViewItem(parent,txt)
57{
58 init();
59}
60
61KMListViewItem::KMListViewItem(TQListViewItem *parent, KMPrinter *p)
62: TQListViewItem(parent)
63{
64 init(p);
65}
66
67void KMListViewItem::init(KMPrinter *p)
68{
69 m_state = 0;
70 if (p)
71 updatePrinter(p);
72 setSelectable(depth() == 2);
73}
74
75void KMListViewItem::updatePrinter(KMPrinter *p)
76{
77 bool update(false);
78 if (p)
79 {
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());
85 if (name != text(0))
86 setText(0, name);
87 setPixmap(0, SmallIcon(p->pixmap(), 0, st));
88 m_isclass = p->isClass();
89 }
90 setDiscarded(false);
91 if (update)
92 repaint();
93}
94
95void KMListViewItem::paintCell(TQPainter *p, const TQColorGroup& cg, int c, int w, int a)
96{
97 if (m_state != 0)
98 {
99 TQFont f(p->font());
100 if (m_state & 0x1) f.setBold(true);
101 if (m_state & 0x2) f.setItalic(true);
102 p->setFont(f);
103 }
104 TQListViewItem::paintCell(p,cg,c,w,a);
105}
106
107//************************************************************************************************
108
109KMListView::KMListView(TQWidget *parent, const char *name)
110: TQListView(parent,name)
111{
112 m_items.setAutoDelete(false);
113
114 addColumn("");
115 header()->hide();
116 setFrameStyle(TQFrame::WinPanel|TQFrame::Sunken);
117 setLineWidth(1);
118 setSorting(0);
119
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()));
124
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);
137
138 sort();
139}
140
141KMListView::~KMListView()
142{
143}
144
145void KMListView::slotRightButtonClicked(TQListViewItem *item, const TQPoint& p, int)
146{
147 emit rightButtonClicked(item && item->depth() == 2 ? item->text(0) : TQString::null, p);
148}
149
150KMListViewItem* KMListView::findItem(KMPrinter *p)
151{
152 if (p)
153 {
154 TQPtrListIterator<KMListViewItem> it(m_items);
155 bool isVirtual(p->isVirtual()), isClass(p->isClass());
156 for (;it.current();++it)
157 if (isVirtual)
158 {
159 if (it.current()->depth() == 3 && it.current()->text(0) == p->instanceName()
160 && it.current()->parent()->text(0) == p->printerName())
161 return it.current();
162 }
163 else
164 {
165 if (it.current()->isClass() == isClass && it.current()->text(0) == p->name())
166 return it.current();
167 }
168 }
169 return 0;
170}
171
172KMListViewItem* KMListView::findItem(const TQString& prname)
173{
174 TQPtrListIterator<KMListViewItem> it(m_items);
175 for (; it.current(); ++it)
176 if (it.current()->depth() == 2 && it.current()->text(0) == prname)
177 return it.current();
178 return 0;
179}
180
181void KMListView::setPrinterList(TQPtrList<KMPrinter> *list)
182{
183 bool changed(false);
184
185 TQPtrListIterator<KMListViewItem> it(m_items);
186 for (;it.current();++it)
187 it.current()->setDiscarded(true);
188
189 if (list)
190 {
191 TQPtrListIterator<KMPrinter> it(*list);
192 KMListViewItem *item (0);
193 for (;it.current();++it)
194 {
195 item = findItem(it.current());
196 if (!item)
197 {
198 if (it.current()->isVirtual())
199 {
200 KMListViewItem *pItem = findItem(it.current()->printerName());
201 if (!pItem)
202 continue;
203 item = new KMListViewItem(pItem, it.current());
204 pItem->setOpen(true);
205 }
206 else
207 item = new KMListViewItem((it.current()->isSpecial() ? m_specials : (it.current()->isClass(false) ? m_classes : m_printers)),it.current());
208 m_items.append(item);
209 changed = true;
210 }
211 else
212 item->updatePrinter(it.current());
213 }
214 }
215
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())
220 {
221 // instance items are put in front of the list
222 // so that they are destroyed first
223 KMListViewItem *item = m_items.take(i);
224 if (item->depth() == 2)
225 deleteList.append(item);
226 else
227 deleteList.prepend(item);
228 i--;
229 changed = true;
230 }
231 deleteList.clear();
232
233 if (changed) sort();
234 emit selectionChanged();
235}
236
237void KMListView::slotSelectionChanged()
238{
239 KMListViewItem *item = static_cast<KMListViewItem*>(currentItem());
240 emit printerSelected((item && !item->isDiscarded() && item->depth() == 2 ? item->text(0) : TQString::null));
241}
242
243void KMListView::setPrinter(const TQString& prname)
244{
245 TQPtrListIterator<KMListViewItem> it(m_items);
246 for (;it.current();++it)
247 if (it.current()->text(0) == prname)
248 {
249 setSelected(it.current(),true);
250 break;
251 }
252}
253
254void KMListView::setPrinter(KMPrinter *p)
255{
256 setPrinter(p ? p->name() : TQString::null);
257}
258
259void KMListView::slotOnItem(TQListViewItem *)
260{
261 setCursor(KCursor::handCursor());
262}
263
264void KMListView::slotOnViewport()
265{
266 setCursor(KCursor::arrowCursor());
267}
268#include "kmlistview.moc"

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.4
This website is maintained by Timothy Pearson.