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

tdeprint

  • tdeprint
  • management
kmiconview.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 "kmiconview.h"
21 #include "kmprinter.h"
22 
23 #include <tqpainter.h>
24 #include <kiconloader.h>
25 #include <kdebug.h>
26 
27 KMIconViewItem::KMIconViewItem(TQIconView *parent, KMPrinter *p)
28 : TQIconViewItem(parent)
29 {
30  m_state = 0;
31  m_mode = parent->itemTextPos();
32  m_pixmap = TQString();
33  m_isclass = false;
34  updatePrinter(p, m_mode);
35 }
36 
37 void KMIconViewItem::paintItem(TQPainter *p, const TQColorGroup& cg)
38 {
39  if (m_state != 0)
40  {
41  TQFont f(p->font());
42  if (m_state & 0x1) f.setBold(true);
43  if (m_state & 0x2) f.setItalic(true);
44  p->setFont(f);
45  }
46  TQIconViewItem::paintItem(p,cg);
47 }
48 
49 void KMIconViewItem::calcRect(const TQString&)
50 {
51  TQRect ir(rect()), pr, tr;
52 
53  // pixmap rect
54  pr.setWidth(pixmap()->width());
55  pr.setHeight(pixmap()->height());
56 
57  // text rect
58  TQFont f(iconView()->font());
59  if (m_state & 0x1) f.setBold(true);
60  if (m_state & 0x2) f.setItalic(true);
61  TQFontMetrics fm(f);
62  if (m_mode == TQIconView::Bottom)
63  tr = fm.boundingRect(0, 0, iconView()->maxItemWidth(), 0xFFFFFF, AlignHCenter|AlignTop|WordBreak|BreakAnywhere, text()+"X");
64  else
65  tr = fm.boundingRect(0, 0, 0xFFFFFF, 0xFFFFFF, AlignLeft|AlignTop, text()+"X");
66 
67  // item rect
68  if (m_mode == TQIconView::Bottom)
69  {
70  ir.setHeight(pr.height() + tr.height() + 15);
71  ir.setWidth(TQMAX(pr.width(), tr.width()) + 10);
72  pr = TQRect((ir.width()-pr.width())/2, 5, pr.width(), pr.height());
73  tr = TQRect((ir.width()-tr.width())/2, 10+pr.height(), tr.width(), tr.height());
74  }
75  else
76  {
77  ir.setHeight(TQMAX(pr.height(), tr.height()) + 4);
78  ir.setWidth(pr.width() + tr.width() + 6);
79  pr = TQRect(2, (ir.height()-pr.height())/2, pr.width(), pr.height());
80  tr = TQRect(4+pr.width(), (ir.height()-tr.height())/2, tr.width(), tr.height());
81  }
82 
83  // set rects
84  setItemRect(ir);
85  setTextRect(tr);
86  setPixmapRect(pr);
87 }
88 
89 void KMIconViewItem::updatePrinter(KMPrinter *p, int mode)
90 {
91  bool update(false);
92  int oldstate = m_state;
93  if (p)
94  {
95  m_state = ((p->isHardDefault() ? 0x1 : 0x0) | (p->ownSoftDefault() ? 0x2 : 0x0) | (p->isValid() ? 0x4 : 0x0));
96  update = (oldstate != m_state);
97  if (p->name() != text() || update)
98  {
99  setText(TQString::null);
100  setText(p->name());
101  }
102  setKey(TQString::fromLatin1("%1_%2").arg((p->isSpecial() ? "special" : (p->isClass(false) ? "class" : "printer"))).arg(p->name()));
103  m_isclass = p->isClass(false);
104  }
105  if (mode != m_mode || ((oldstate&0x4) != (m_state&0x4)) || (p && p->pixmap() != m_pixmap))
106  {
107  int iconstate = (m_state&0x4 ? (int)TDEIcon::DefaultState : (int)TDEIcon::LockOverlay);
108  if (p)
109  m_pixmap = p->pixmap();
110  m_mode = mode;
111  if (m_mode == TQIconView::Bottom)
112  setPixmap(DesktopIcon(m_pixmap, 0, iconstate));
113  else
114  setPixmap(SmallIcon(m_pixmap, 0, iconstate));
115  }
116  //if (update)
117  // repaint();
118  setDiscarded(false);
119 }
120 
121 KMIconView::KMIconView(TQWidget *parent, const char *name)
122 : TDEIconView(parent,name)
123 {
124  setMode(TDEIconView::Select);
125  setSelectionMode(TQIconView::Single);
126  setItemsMovable(false);
127  setResizeMode(TQIconView::Adjust);
128 
129  m_items.setAutoDelete(false);
130  setViewMode(KMIconView::Big);
131 
132  connect(this,TQ_SIGNAL(contextMenuRequested(TQIconViewItem*,const TQPoint&)),TQ_SLOT(slotRightButtonClicked(TQIconViewItem*,const TQPoint&)));
133  connect(this,TQ_SIGNAL(selectionChanged()),TQ_SLOT(slotSelectionChanged()));
134 }
135 
136 KMIconView::~KMIconView()
137 {
138 }
139 
140 KMIconViewItem* KMIconView::findItem(KMPrinter *p)
141 {
142  if (p)
143  {
144  TQPtrListIterator<KMIconViewItem> it(m_items);
145  for (;it.current();++it)
146  if (it.current()->text() == p->name()
147  && it.current()->isClass() == p->isClass())
148  return it.current();
149  }
150  return 0;
151 }
152 
153 void KMIconView::setPrinterList(TQPtrList<KMPrinter> *list)
154 {
155  bool changed(false);
156 
157  TQPtrListIterator<KMIconViewItem> it(m_items);
158  for (;it.current();++it)
159  it.current()->setDiscarded(true);
160 
161  if (list)
162  {
163  TQPtrListIterator<KMPrinter> it(*list);
164  KMIconViewItem *item(0);
165  for (;it.current();++it)
166  {
167  // only keep real printers (no instances)
168  if (!it.current()->instanceName().isEmpty())
169  continue;
170  item = findItem(it.current());
171  if (!item)
172  {
173  item = new KMIconViewItem(this,it.current());
174  m_items.append(item);
175  changed = true;
176  }
177  else
178  item->updatePrinter(it.current(), itemTextPos());
179  }
180  }
181 
182  for (uint i=0; i<m_items.count(); i++)
183  if (m_items.at(i)->isDiscarded())
184  {
185  delete m_items.take(i);
186  i--;
187  changed = true;
188  }
189 
190  if (changed) sort();
191  emit selectionChanged();
192 }
193 
194 void KMIconView::setViewMode(ViewMode m)
195 {
196  m_mode = m;
197  bool big = (m == KMIconView::Big);
198  int mode = (big ? TQIconView::Bottom : TQIconView::Right);
199 
200  TQPtrListIterator<KMIconViewItem> it(m_items);
201  for (;it.current();++it)
202  it.current()->updatePrinter(0, mode);
203 
204  setArrangement((big ? TQIconView::LeftToRight : TQIconView::TopToBottom));
205  setItemTextPos((TQIconView::ItemTextPos)mode);
206  //setGridX((big ? 60 : -1));
207  setWordWrapIconText(true);
208 }
209 
210 void KMIconView::slotRightButtonClicked(TQIconViewItem *item, const TQPoint& p)
211 {
212  emit rightButtonClicked(item ? item->text() : TQString::null, p);
213 }
214 
215 void KMIconView::slotSelectionChanged()
216 {
217  KMIconViewItem *item = static_cast<KMIconViewItem*>(currentItem());
218  emit printerSelected((item && !item->isDiscarded() && item->isSelected() ? item->text() : TQString::null));
219 }
220 
221 void KMIconView::setPrinter(const TQString& prname)
222 {
223  TQPtrListIterator<KMIconViewItem> it(m_items);
224  for (; it.current(); ++it)
225  if (it.current()->text() == prname)
226  {
227  setSelected(it.current(), true);
228  break;
229  }
230 }
231 
232 void KMIconView::setPrinter(KMPrinter *p)
233 {
234  setPrinter(p ? p->name() : TQString::null);
235 }
236 
237 #include "kmiconview.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.1
This website is maintained by Timothy Pearson.