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

tdeprint

  • tdeprint
  • management
cjanuswidget.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 "cjanuswidget.h"
21 
22 #include <tqwidgetstack.h>
23 #include <tqlabel.h>
24 #include <tqpainter.h>
25 #include <tdelistbox.h>
26 #include <tqlayout.h>
27 #include <kseparator.h>
28 
29 class CJanusWidget::CPage
30 {
31 public:
32  TQWidget *m_widget;
33  TQString m_text;
34  TQString m_header;
35  TQPixmap m_pixmap;
36  CListBoxItem *m_item;
37 };
38 
39 //***********************************************************************************
40 
41 class CJanusWidget::CListBoxItem : public TQListBoxItem
42 {
43 public:
44  CListBoxItem(TQListBox *lb, TQListBoxItem *after, const TQPixmap& pix, const TQString& text);
45  int height(const TQListBox*) const;
46  int width(const TQListBox*) const;
47 
48 protected:
49  void paint(TQPainter*);
50 
51 private:
52  TQPixmap m_pix;
53 };
54 
55 CJanusWidget::CListBoxItem::CListBoxItem(TQListBox *lb, TQListBoxItem *after, const TQPixmap& pix, const TQString& text)
56 : TQListBoxItem(lb, after), m_pix(pix)
57 {
58  setText(text);
59 }
60 
61 int CJanusWidget::CListBoxItem::height(const TQListBox *lb) const
62 {
63  return (m_pix.height() + lb->fontMetrics().lineSpacing() + 12);
64 }
65 
66 int CJanusWidget::CListBoxItem::width(const TQListBox *lb) const
67 {
68  int w = TQMAX(lb->fontMetrics().width(text()),m_pix.width());
69  return (w + 10);
70 }
71 
72 void CJanusWidget::CListBoxItem::paint(TQPainter *p)
73 {
74  int w1 = (listBox()->contentsWidth()-m_pix.width())/2;
75 
76  p->drawPixmap(w1,5,m_pix);
77  p->drawText(0,7+m_pix.height(),listBox()->contentsWidth(),p->fontMetrics().lineSpacing(),Qt::AlignHCenter,text());
78 }
79 
80 //***********************************************************************************
81 
82 class CJanusWidget::CListBox : public TDEListBox
83 {
84 public:
85  CListBox(TQWidget *parent = 0, const char *name = 0);
86  ~CListBox();
87 
88  void computeWidth();
89 
90 protected:
91  virtual bool eventFilter(TQObject*, TQEvent*);
92 };
93 
94 CJanusWidget::CListBox::CListBox(TQWidget *parent, const char *name)
95 : TDEListBox(parent,name)
96 {
97  verticalScrollBar()->installEventFilter(this);
98 }
99 
100 CJanusWidget::CListBox::~CListBox()
101 {
102 }
103 
104 bool CJanusWidget::CListBox::eventFilter(TQObject *o, TQEvent *e)
105 {
106  if (e->type() == TQEvent::Show || e->type() == TQEvent::Hide)
107  computeWidth();
108  return TDEListBox::eventFilter(o,e);
109 }
110 
111 void CJanusWidget::CListBox::computeWidth()
112 {
113  TQListBoxItem *item = firstItem();
114  int w(40);
115  while (item)
116  {
117  w = TQMAX(w,item->width(this));
118  item = item->next();
119  }
120  if (verticalScrollBar()->isVisible())
121  w += verticalScrollBar()->sizeHint().width();
122  w += (frameWidth()*2);
123  setFixedWidth(w);
124 }
125 
126 //***********************************************************************************
127 
128 CJanusWidget::CJanusWidget(TQWidget *parent, const char *name)
129 : TQWidget(parent,name)
130 {
131  m_pages.setAutoDelete(true);
132 
133  m_stack = new TQWidgetStack(this);
134  m_header = new TQLabel(this);
135  TQFont f(m_header->font());
136  f.setBold(true);
137  m_header->setFont(f);
138 
139  KSeparator* sep = new KSeparator( KSeparator::HLine, this);
140  sep->setFixedHeight(5);
141 
142  m_iconlist = new CListBox(this);
143  f = m_iconlist->font();
144  f.setBold(true);
145  m_iconlist->setFont(f);
146  connect(m_iconlist,TQT_SIGNAL(selectionChanged(TQListBoxItem*)),TQT_SLOT(slotSelected(TQListBoxItem*)));
147 
148  m_empty = new TQWidget(this, "Empty");
149  m_stack->addWidget(m_empty,0);
150 
151  TQHBoxLayout *main_ = new TQHBoxLayout(this, 0, 10);
152  TQVBoxLayout *sub_ = new TQVBoxLayout(0, 0, 5);
153  main_->addWidget(m_iconlist,0);
154  main_->addLayout(sub_,1);
155  sub_->addWidget(m_header,0);
156  sub_->addWidget(sep,0);
157  sub_->addWidget(m_stack,1);
158 }
159 
160 CJanusWidget::~CJanusWidget()
161 {
162 }
163 
164 void CJanusWidget::addPage(TQWidget *w, const TQString& text, const TQString& header, const TQPixmap& pix)
165 {
166  CPage *page = new CPage();
167  m_pages.append(page);
168  page->m_widget = w;
169  page->m_text = text;
170  page->m_header = header;
171  page->m_pixmap = pix;
172  page->m_item = new CListBoxItem(m_iconlist,findPrevItem(page),pix,text);
173  m_iconlist->computeWidth();
174  m_stack->addWidget(w,m_pages.count());
175 
176  if (m_iconlist->count() == 1)
177  m_iconlist->setSelected(page->m_item,true);
178 }
179 
180 void CJanusWidget::enablePage(TQWidget *w)
181 {
182  CPage *page = findPage(w);
183  if (page && !page->m_item)
184  {
185  page->m_item = new CListBoxItem(m_iconlist,findPrevItem(page),page->m_pixmap,page->m_text);
186  m_iconlist->computeWidth();
187  if (m_iconlist->count() == 1)
188  m_iconlist->setSelected(page->m_item,true);
189  }
190 }
191 
192 void CJanusWidget::disablePage(TQWidget *w)
193 {
194  CPage *page = findPage(w);
195  if (page && page->m_item)
196  {
197  bool needReselect(m_iconlist->isSelected(page->m_item));
198  delete page->m_item;
199  page->m_item = 0;
200  m_iconlist->computeWidth();
201  if (needReselect)
202  if (m_iconlist->count() > 0)
203  m_iconlist->setSelected(m_iconlist->firstItem(),true);
204  else
205  slotSelected(0);
206  }
207 }
208 
209 void CJanusWidget::slotSelected(TQListBoxItem *item)
210 {
211  CPage *page = findPage(item);
212  if (page)
213  {
214  m_stack->raiseWidget(page->m_widget);
215  m_header->setText(page->m_header);
216  }
217  else
218  {
219  m_header->setText("");
220  m_stack->raiseWidget(m_empty);
221  }
222 }
223 
224 CJanusWidget::CPage* CJanusWidget::findPage(TQWidget *w)
225 {
226  TQPtrListIterator<CPage> it(m_pages);
227  for (;it.current();++it)
228  if (it.current()->m_widget == w)
229  return it.current();
230  return 0;
231 }
232 
233 CJanusWidget::CPage* CJanusWidget::findPage(TQListBoxItem *i)
234 {
235  TQPtrListIterator<CPage> it(m_pages);
236  for (;it.current();++it)
237  if (it.current()->m_item == i)
238  return it.current();
239  return 0;
240 }
241 
242 TQListBoxItem* CJanusWidget::findPrevItem(CPage *p)
243 {
244  if (m_pages.findRef(p) == -1)
245  m_pages.last();
246  else
247  m_pages.prev();
248  for (;m_pages.current();m_pages.prev())
249  if (m_pages.current()->m_item)
250  return m_pages.current()->m_item;
251  return 0;
252 }
253 
254 void CJanusWidget::clearPages()
255 {
256  TQPtrListIterator<CPage> it(m_pages);
257  for (;it.current(); ++it)
258  {
259  delete it.current()->m_widget;
260  delete it.current()->m_item;
261  }
262  m_pages.clear();
263 }
264 
265 #include "cjanuswidget.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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.8.8
This website is maintained by Timothy Pearson.