00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef KPTDOUBLELISTVIEWBASE_H
00021 #define KPTDOUBLELISTVIEWBASE_H
00022
00023 #include <QMap>
00024 #include <QSplitter>
00025 #include <QTreeWidget>
00026
00027 class QColor;
00028 class QStringList;
00029 class QTreeWidgetItem;
00030 class QTreeWidgetItem;
00031
00032 class KPrinter;
00033
00034 namespace KPlato
00035 {
00036
00037 class View;
00038 class Project;
00039
00040 class ListView : public QTreeWidget
00041 {
00042 public:
00043 ListView(QWidget *parent)
00044 : QTreeWidget(parent)
00045 {}
00046
00047 virtual void paintToPrinter(QPainter * p, int cx, int cy, int cw, int ch);
00048 };
00049
00058 class DoubleListViewBase : public QSplitter
00059 {
00060 Q_OBJECT
00061 public:
00062
00063 DoubleListViewBase(QWidget *parent, bool description=false);
00064
00065
00066
00067 ListView *masterListView() const { return m_masterList; }
00068 ListView *slaveListView() const { return m_slaveList; }
00069 void setOpen(QTreeWidgetItem *item, bool open);
00070
00071 void setNameHeader(QString text);
00072 void setTotalHeader(QString text);
00073 void setDescriptionHeader(QString text);
00074 void setSlaveLabels(const QStringList &text);
00075 virtual void print(KPrinter &printer);
00076
00077 virtual void calculate();
00078 void clearLists();
00079 virtual void createSlaveItems();
00080 void clearSlaveList();
00081 void setFormat(int fieldwidth=0, char fmt='f', int prec=0);
00082 void setMasterFormat(int fieldwidth=0, char fmt='f', int prec=0);
00083 void setSlaveFormat(int fieldwidth=0, char fmt='f', int prec=0);
00084 virtual QSize sizeHint() const;
00085
00086 class MasterListItem;
00087 class SlaveListItem : public QTreeWidgetItem {
00088 public:
00089 SlaveListItem(MasterListItem *master, QTreeWidget *parent, QTreeWidgetItem *after, bool highlight=false);
00090 SlaveListItem(MasterListItem *master, QTreeWidgetItem *parent, QTreeWidgetItem *after, bool highlight=false);
00091 ~SlaveListItem();
00092 void masterItemDeleted() { m_masterItem = 0; }
00093
00094 virtual void setColumn(int col, double value);
00095 virtual void clearColumn(int col);
00096
00097 double value(int col) const { return m_valueMap[col]; }
00098 void setLimit(int col, double limit);
00099 void setHighlight(bool on) { m_highlight = on; }
00100
00101 virtual void paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align);
00102
00103 void setFormat(int fieldwidth=0, char fmt='f', int prec=0);
00104
00105 protected:
00106 MasterListItem *m_masterItem;
00107 double m_value;
00108 bool m_highlight;
00109
00110 QMap<int, double> m_valueMap;
00111 QMap<int, double> m_limitMap;
00112
00113 int m_fieldwidth;
00114 char m_fmt;
00115 int m_prec;
00116 };
00117
00118 class MasterListItem : public QTreeWidgetItem {
00119 public:
00120 MasterListItem(QTreeWidget *parent, bool highlight=false);
00121 MasterListItem(QTreeWidget *parent, QString text, bool highlight=false);
00122 MasterListItem(QTreeWidgetItem *parent, bool highlight=false);
00123 MasterListItem(QTreeWidgetItem *parent, QString text, bool highlight=false);
00124 ~MasterListItem();
00125
00127 void createSlaveItems(QTreeWidget *lv, QTreeWidgetItem *after=0);
00128 void slaveItemDeleted();
00129 void setSlaveOpen(bool on);
00130 SlaveListItem *slaveItem() const { return m_slaveItem; }
00131 double value() const { return m_value; }
00132
00133 void setTotal(double tot);
00134 double calcTotal();
00135 void addToTotal(double v);
00136 void setSlaveItem(int col, double value);
00137 void setSlaveLimit(int col, double limit);
00138 void setLimit(double limit) { m_limit = limit; }
00139 void setHighlight(bool on) { m_highlight = on; }
00140 void setSlaveHighlight(bool on);
00141 void clearColumn(int col);
00142 void calcSlaveItems();
00143 virtual double calcSlaveItems(int col);
00144
00145 virtual void paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int align);
00146
00147 void setFormat(int fieldwidth=0, char fmt='f', int prec=0);
00148
00149 protected:
00150 SlaveListItem *m_slaveItem;
00151 double m_value;
00152 double m_limit;
00153 bool m_highlight;
00154
00155 QMap<int, double> m_valueMap;
00156
00157 int m_fieldwidth;
00158 char m_fmt;
00159 int m_prec;
00160 };
00161
00162 public:
00163 QList<QTreeWidgetItem*> masterItems() {
00164 return m_masterList->findItems("*", Qt::MatchWildcard|Qt::MatchRecursive);
00165 }
00166 QList<QTreeWidgetItem*> slaveItems() {
00167 return m_slaveList->findItems("*", Qt::MatchWildcard|Qt::MatchRecursive);
00168 }
00169 virtual void paintContents(QPainter *p);
00170
00171 protected slots:
00172 void slotExpanded(QTreeWidgetItem* item);
00173 void slotCollapsed(QTreeWidgetItem* item);
00174
00175 private:
00176
00177 private:
00178 ListView *m_masterList;
00179 ListView *m_slaveList;
00180
00181 int m_fieldwidth;
00182 char m_fmt;
00183 int m_prec;
00184 };
00185
00186 }
00187
00188 #endif