kplato

kptdoublelistviewbase.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Dag Andersen <kplato@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
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 #ifndef KPTDOUBLELISTVIEWBASE_H
00021 #define KPTDOUBLELISTVIEWBASE_H
00022 
00023 #include <qcolor.h>
00024 #include <qmap.h>
00025 #include <qptrvector.h>
00026 #include <qsplitter.h>
00027 
00028 #include <klistview.h>
00029 
00030 class QListViewItem;
00031 
00032 class KListViewItem;
00033 class KPrinter;
00034 
00035 namespace KPlato
00036 {
00037 
00038 class View;
00039 class Project;
00040 
00041 class ListView : public KListView
00042 {
00043 public:
00044     ListView(QWidget *parent)
00045     : KListView(parent)
00046     {}
00047     
00048     virtual void paintToPrinter(QPainter * p, int cx, int cy, int cw, int ch);
00049 };
00050 
00059 class DoubleListViewBase : public QSplitter
00060 {
00061     Q_OBJECT
00062 public:
00063 
00064     DoubleListViewBase(QWidget *parent, bool description=false);
00065 
00066     //~DoubleListViewBase();
00067 
00068     ListView *masterListView() const { return m_masterList; }
00069     ListView *slaveListView() const { return m_slaveList; }
00070     void setOpen(QListViewItem *item, bool open);
00071     
00072     void setNameHeader(QString text);
00073     void setTotalHeader(QString text);
00074     void setDescriptionHeader(QString text);
00075     void addSlaveColumn(QString text);
00076     virtual void print(KPrinter &printer);
00077 
00078     virtual void calculate();
00079     void clearLists();
00080     virtual void createSlaveItems();
00081     void clearSlaveList();
00082     void setFormat(int fieldwidth=0, char fmt='f', int prec=0);
00083     void setMasterFormat(int fieldwidth=0, char fmt='f', int prec=0);
00084     void setSlaveFormat(int fieldwidth=0, char fmt='f', int prec=0);
00085     virtual QSize sizeHint() const;
00086     
00087     class MasterListItem;
00088     class SlaveListItem : public KListViewItem {
00089     public:
00090         SlaveListItem(MasterListItem *master, QListView *parent, QListViewItem *after, bool highlight=false);
00091         SlaveListItem(MasterListItem *master, QListViewItem *parent, QListViewItem *after, bool highlight=false);
00092         ~SlaveListItem();
00093         void masterItemDeleted() { m_masterItem = 0; }
00094         
00095         virtual void setColumn(int col, double value);
00096         virtual void clearColumn(int col);
00097         
00098         double value(int col) const { return m_valueMap[col]; }
00099         void setLimit(int col, double limit);
00100         void setHighlight(bool on) { m_highlight = on; }
00101 
00102         virtual void paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align);
00103         
00104         void setFormat(int fieldwidth=0, char fmt='f', int prec=0);
00105 
00106     protected:
00107         MasterListItem *m_masterItem;
00108         double m_value;
00109         bool m_highlight;
00110 
00111         QMap<int, double> m_valueMap;
00112         QMap<int, double> m_limitMap;
00113         
00114         int m_fieldwidth;
00115         char m_fmt;
00116         int m_prec;
00117     };
00118 
00119     class MasterListItem : public KListViewItem {
00120     public:
00121         MasterListItem(QListView *parent, bool highlight=false);
00122         MasterListItem(QListView *parent, QString text, bool highlight=false);
00123         MasterListItem(QListViewItem *parent, bool highlight=false);
00124         MasterListItem(QListViewItem *parent, QString text, bool highlight=false);
00125         ~MasterListItem();
00126         
00128         void createSlaveItems(QListView *lv, QListViewItem *after=0);
00129         void slaveItemDeleted();
00130         void setSlaveOpen(bool on);
00131         SlaveListItem *slaveItem() const { return m_slaveItem; }
00132         double value() const { return m_value; }
00133         
00134         void setTotal(double tot);
00135         double calcTotal();
00136         void addToTotal(double v);
00137         void setSlaveItem(int col, double value);
00138         void setSlaveLimit(int col, double limit);
00139         void setLimit(double limit) { m_limit = limit; }
00140         void setHighlight(bool on) { m_highlight = on; }
00141         void setSlaveHighlight(bool on);
00142         void clearColumn(int col);
00143         void calcSlaveItems();
00144         virtual double calcSlaveItems(int col);
00145 
00146         virtual void paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align);    
00147 
00148         void setFormat(int fieldwidth=0, char fmt='f', int prec=0);
00149 
00150     protected:
00151         SlaveListItem *m_slaveItem;
00152         double m_value;
00153         double m_limit;
00154         bool m_highlight;
00155         
00156         QMap<int, double> m_valueMap;
00157     
00158         int m_fieldwidth;
00159         char m_fmt;
00160         int m_prec;
00161     };
00162 
00163 public:
00164     virtual void paintContents(QPainter *p);
00165     
00166 protected slots:
00167     void slotExpanded(QListViewItem* item);
00168     void slotCollapsed(QListViewItem* item);
00169 
00170 private:
00171 
00172 private:
00173     ListView *m_masterList;
00174     ListView *m_slaveList;
00175     
00176     int m_fieldwidth;
00177     char m_fmt;
00178     int m_prec;
00179 };
00180 
00181 }  //KPlato namespace
00182 
00183 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys