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

tdeprint

cjanuswidget.cpp

00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License version 2 as published by the Free Software Foundation.
00008  *
00009  *  This library is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *  Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Library General Public License
00015  *  along with this library; see the file COPYING.LIB.  If not, write to
00016  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  *  Boston, MA 02110-1301, USA.
00018  **/
00019 
00020 #include "cjanuswidget.h"
00021 
00022 #include <tqwidgetstack.h>
00023 #include <tqlabel.h>
00024 #include <tqpainter.h>
00025 #include <tdelistbox.h>
00026 #include <tqlayout.h>
00027 #include <kseparator.h>
00028 
00029 class CJanusWidget::CPage
00030 {
00031 public:
00032     TQWidget    *m_widget;
00033     TQString    m_text;
00034     TQString    m_header;
00035     TQPixmap    m_pixmap;
00036     CListBoxItem    *m_item;
00037 };
00038 
00039 //***********************************************************************************
00040 
00041 class CJanusWidget::CListBoxItem : public TQListBoxItem
00042 {
00043 public:
00044     CListBoxItem(TQListBox *lb, TQListBoxItem *after, const TQPixmap& pix, const TQString& text);
00045     int height(const TQListBox*) const;
00046     int width(const TQListBox*) const;
00047 
00048 protected:
00049     void paint(TQPainter*);
00050 
00051 private:
00052     TQPixmap    m_pix;
00053 };
00054 
00055 CJanusWidget::CListBoxItem::CListBoxItem(TQListBox *lb, TQListBoxItem *after, const TQPixmap& pix, const TQString& text)
00056 : TQListBoxItem(lb, after), m_pix(pix)
00057 {
00058     setText(text);
00059 }
00060 
00061 int CJanusWidget::CListBoxItem::height(const TQListBox *lb) const
00062 {
00063     return (m_pix.height() + lb->fontMetrics().lineSpacing() + 12);
00064 }
00065 
00066 int CJanusWidget::CListBoxItem::width(const TQListBox *lb) const
00067 {
00068     int w = TQMAX(lb->fontMetrics().width(text()),m_pix.width());
00069     return (w + 10);
00070 }
00071 
00072 void CJanusWidget::CListBoxItem::paint(TQPainter *p)
00073 {
00074     int w1 = (listBox()->contentsWidth()-m_pix.width())/2;
00075 
00076     p->drawPixmap(w1,5,m_pix);
00077     p->drawText(0,7+m_pix.height(),listBox()->contentsWidth(),p->fontMetrics().lineSpacing(),Qt::AlignHCenter,text());
00078 }
00079 
00080 //***********************************************************************************
00081 
00082 class CJanusWidget::CListBox : public TDEListBox
00083 {
00084 public:
00085     CListBox(TQWidget *parent = 0, const char *name = 0);
00086     ~CListBox();
00087 
00088     void computeWidth();
00089 
00090 protected:
00091     virtual bool eventFilter(TQObject*, TQEvent*);
00092 };
00093 
00094 CJanusWidget::CListBox::CListBox(TQWidget *parent, const char *name)
00095 : TDEListBox(parent,name)
00096 {
00097     verticalScrollBar()->installEventFilter(this);
00098 }
00099 
00100 CJanusWidget::CListBox::~CListBox()
00101 {
00102 }
00103 
00104 bool CJanusWidget::CListBox::eventFilter(TQObject *o, TQEvent *e)
00105 {
00106     if (e->type() == TQEvent::Show || e->type() == TQEvent::Hide)
00107         computeWidth();
00108     return TDEListBox::eventFilter(o,e);
00109 }
00110 
00111 void CJanusWidget::CListBox::computeWidth()
00112 {
00113     TQListBoxItem   *item = firstItem();
00114     int w(40);
00115     while (item)
00116     {
00117         w = TQMAX(w,item->width(this));
00118         item = item->next();
00119     }
00120     if (verticalScrollBar()->isVisible())
00121         w += verticalScrollBar()->sizeHint().width();
00122     w += (frameWidth()*2);
00123     setFixedWidth(w);
00124 }
00125 
00126 //***********************************************************************************
00127 
00128 CJanusWidget::CJanusWidget(TQWidget *parent, const char *name)
00129 : TQWidget(parent,name)
00130 {
00131     m_pages.setAutoDelete(true);
00132 
00133     m_stack = new TQWidgetStack(this);
00134     m_header = new TQLabel(this);
00135     TQFont  f(m_header->font());
00136     f.setBold(true);
00137     m_header->setFont(f);
00138 
00139     KSeparator* sep = new KSeparator( KSeparator::HLine, this);
00140     sep->setFixedHeight(5);
00141 
00142     m_iconlist = new CListBox(this);
00143     f = m_iconlist->font();
00144     f.setBold(true);
00145     m_iconlist->setFont(f);
00146     connect(m_iconlist,TQT_SIGNAL(selectionChanged(TQListBoxItem*)),TQT_SLOT(slotSelected(TQListBoxItem*)));
00147 
00148     m_empty = new TQWidget(this, "Empty");
00149     m_stack->addWidget(m_empty,0);
00150 
00151     TQHBoxLayout    *main_ = new TQHBoxLayout(this, 0, 10);
00152     TQVBoxLayout    *sub_ = new TQVBoxLayout(0, 0, 5);
00153     main_->addWidget(m_iconlist,0);
00154     main_->addLayout(sub_,1);
00155     sub_->addWidget(m_header,0);
00156     sub_->addWidget(sep,0);
00157     sub_->addWidget(m_stack,1);
00158 }
00159 
00160 CJanusWidget::~CJanusWidget()
00161 {
00162 }
00163 
00164 void CJanusWidget::addPage(TQWidget *w, const TQString& text, const TQString& header, const TQPixmap& pix)
00165 {
00166     CPage   *page = new CPage();
00167     m_pages.append(page);
00168     page->m_widget = w;
00169     page->m_text = text;
00170     page->m_header = header;
00171     page->m_pixmap = pix;
00172     page->m_item = new CListBoxItem(m_iconlist,findPrevItem(page),pix,text);
00173     m_iconlist->computeWidth();
00174     m_stack->addWidget(w,m_pages.count());
00175 
00176     if (m_iconlist->count() == 1)
00177         m_iconlist->setSelected(page->m_item,true);
00178 }
00179 
00180 void CJanusWidget::enablePage(TQWidget *w)
00181 {
00182     CPage   *page = findPage(w);
00183     if (page && !page->m_item)
00184     {
00185         page->m_item = new CListBoxItem(m_iconlist,findPrevItem(page),page->m_pixmap,page->m_text);
00186         m_iconlist->computeWidth();
00187         if (m_iconlist->count() == 1)
00188             m_iconlist->setSelected(page->m_item,true);
00189     }
00190 }
00191 
00192 void CJanusWidget::disablePage(TQWidget *w)
00193 {
00194     CPage   *page = findPage(w);
00195     if (page && page->m_item)
00196     {
00197         bool    needReselect(m_iconlist->isSelected(page->m_item));
00198         delete page->m_item;
00199         page->m_item = 0;
00200         m_iconlist->computeWidth();
00201         if (needReselect)
00202             if (m_iconlist->count() > 0)
00203                 m_iconlist->setSelected(m_iconlist->firstItem(),true);
00204             else
00205                 slotSelected(0);
00206     }
00207 }
00208 
00209 void CJanusWidget::slotSelected(TQListBoxItem *item)
00210 {
00211     CPage   *page = findPage(item);
00212     if (page)
00213     {
00214         m_stack->raiseWidget(page->m_widget);
00215         m_header->setText(page->m_header);
00216     }
00217     else
00218     {
00219         m_header->setText("");
00220         m_stack->raiseWidget(m_empty);
00221     }
00222 }
00223 
00224 CJanusWidget::CPage* CJanusWidget::findPage(TQWidget *w)
00225 {
00226     TQPtrListIterator<CPage>    it(m_pages);
00227     for (;it.current();++it)
00228         if (it.current()->m_widget == w)
00229             return it.current();
00230     return 0;
00231 }
00232 
00233 CJanusWidget::CPage* CJanusWidget::findPage(TQListBoxItem *i)
00234 {
00235     TQPtrListIterator<CPage>    it(m_pages);
00236     for (;it.current();++it)
00237         if (it.current()->m_item == i)
00238             return it.current();
00239     return 0;
00240 }
00241 
00242 TQListBoxItem* CJanusWidget::findPrevItem(CPage *p)
00243 {
00244     if (m_pages.findRef(p) == -1)
00245         m_pages.last();
00246     else
00247         m_pages.prev();
00248     for (;m_pages.current();m_pages.prev())
00249         if (m_pages.current()->m_item)
00250             return m_pages.current()->m_item;
00251     return 0;
00252 }
00253 
00254 void CJanusWidget::clearPages()
00255 {
00256     TQPtrListIterator<CPage>    it(m_pages);
00257     for (;it.current(); ++it)
00258     {
00259         delete it.current()->m_widget;
00260         delete it.current()->m_item;
00261     }
00262     m_pages.clear();
00263 }
00264 
00265 #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
  • 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.7.1
This website is maintained by Timothy Pearson.