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

tdeprint

  • tdeprint
driveritem.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 "driveritem.h"
21#include "driver.h"
22
23#include <tqpainter.h>
24#include <kiconloader.h>
25#include <kdebug.h>
26
27DriverItem::DriverItem(TQListView *parent, DrBase *item)
28: TQListViewItem(parent), m_item(item), m_conflict(false)
29{
30 setOpen(depth() < 3);
31 setPixmap(0,SmallIcon("document-print"));
32 updateText();
33}
34
35DriverItem::DriverItem(TQListViewItem *parent, TQListViewItem *after, DrBase *item)
36: TQListViewItem(parent, after), m_item(item), m_conflict(false)
37{
38 setOpen(depth() < 3);
39 if (item) setPixmap(0,SmallIcon((item->isOption() ? "text-x-generic" : "folder")));
40 updateText();
41}
42
43void DriverItem::updateText()
44{
45 if (m_item)
46 {
47 TQString s(m_item->get("text"));
48 if (m_item->isOption())
49 s.append(TQString::fromLatin1(": <%1>").arg(m_item->prettyText()));
50 if (m_item->type() == DrBase::List)
51 {
52 // remove all children: something has changed (otherwise this
53 // function would not be called), so it make sense to remove
54 // those children in all cases.
55 while (firstChild())
56 delete firstChild();
57 DrBase *ch = static_cast<DrListOption*>(m_item)->currentChoice();
58 if (ch && ch->type() == DrBase::ChoiceGroup)
59 {
60 // add new children
61 static_cast<DrChoiceGroup*>(ch)->createItem(this);
62 setOpen(true);
63 }
64 }
65 setText(0,s);
66 }
67 else
68 setText(0,"ERROR");
69 widthChanged();
70}
71
72void DriverItem::paintCell(TQPainter *p, const TQColorGroup& cg, int, int width, int)
73{
74 // background
75 p->fillRect(0, 0, width, height(), cg.base());
76
77 // highlight rectangle
78 if (isSelected())
79 p->fillRect(0, 0, /*2+p->fontMetrics().width(text(0))+(pixmap(0) ? pixmap(0)->width()+2 : 0)*/ width, height(), (m_conflict ? red : cg.highlight()));
80
81 // draw pixmap
82 int w(0);
83 if (pixmap(0) && !pixmap(0)->isNull())
84 {
85 int h((height()-pixmap(0)->height())/2);
86 p->drawPixmap(w,h,*pixmap(0));
87 w += (pixmap(0)->width()+2);
88 }
89
90 // draw Text
91 if (!m_item || !m_item->isOption() || isSelected())
92 {
93 p->setPen((isSelected() ? cg.highlightedText() : (m_conflict ? red : cg.text())));
94 p->drawText(w,0,width-w,height(),TQt::AlignLeft|TQt::AlignVCenter,text(0));
95 }
96 else
97 {
98 int w1(0);
99 TQString s(m_item->get("text") + ": <");
100 w1 = p->fontMetrics().width(s);
101 p->setPen(cg.text());
102 p->drawText(w,0,w1,height(),TQt::AlignLeft|TQt::AlignVCenter,s);
103 w += w1;
104 p->setPen((m_conflict ? red : darkGreen));
105 s = m_item->prettyText();
106 w1 = p->fontMetrics().width(s);
107 p->drawText(w,0,w1,height(),TQt::AlignLeft|TQt::AlignVCenter,s);
108 w += w1;
109 p->setPen(cg.text());
110 s = TQString::fromLatin1(">");
111 w1 = p->fontMetrics().width(s);
112 p->drawText(w,0,w1,height(),TQt::AlignLeft|TQt::AlignVCenter,s);
113 }
114}
115
116bool DriverItem::updateConflict()
117{
118 m_conflict = false;
119 if (m_item)
120 {
121 if (!m_item->isOption())
122 {
123 DriverItem *item = (DriverItem*)firstChild();
124 while (item)
125 {
126 if (item->updateConflict())
127 m_conflict = true;
128 item = (DriverItem*)item->nextSibling();
129 }
130 }
131 else
132 {
133 m_conflict = (m_item->conflict());
134 }
135 }
136 repaint();
137 return m_conflict;
138}
139
140void DriverItem::updateTextRecursive()
141{
142 if ( m_item->isOption() )
143 updateText();
144
145 DriverItem *item = static_cast<DriverItem*>( firstChild() );
146 while ( item )
147 {
148 item->updateTextRecursive();
149 item = static_cast<DriverItem*>( item->nextSibling() );
150 }
151}

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.