00001 #ifndef _QDBTTABLECELL_H 00002 #define _QDBTTABLECELL_H 00003 00004 #include <qcolor.h> 00005 #include <qpixmap.h> 00006 #include <qrect.h> 00007 #include <qstring.h> 00008 00009 #include <qdbt/qdbtglobal.h> 00010 #include "qdbtbasecell.h" 00011 00012 class QPainter; 00013 class QdbtLineEdit; 00014 class QdbtBaseTabular; 00015 00016 class QDBT_EXPORT QdbtTableCell : public QdbtBaseCell 00017 { 00018 public: 00019 enum BorderType { LeftBorder = 0x0001, RightBorder = 0x0002, 00020 TopBorder = 0x0004, BottomBorder = 0x0008 }; 00021 00022 QdbtTableCell(); 00023 QdbtTableCell( const QdbtTableCell & ); 00024 QdbtTableCell( QString text, const QPixmap *pixmap, 00025 const QColor &color = QColor(), int align = Qt::AlignLeft, 00026 bool edit = FALSE ); 00027 virtual ~QdbtTableCell(); 00028 00029 virtual void setText( QString text ) 00030 { 00031 txt = text.stripWhiteSpace(); 00032 } 00033 virtual QString text() const 00034 { 00035 return txt; 00036 } 00037 00038 void setPixmap( const QPixmap *pixmap ) 00039 { 00040 if ( pixmap ) 00041 pmap = *pixmap; 00042 else 00043 pmap = QPixmap(); 00044 } 00045 const QPixmap &pixmap() const 00046 { 00047 return pmap; 00048 } 00049 00050 virtual void setColor( const QColor &color ) 00051 { 00052 col = color; 00053 } 00054 virtual const QColor &color( QdbtBaseTabular * ) const; 00055 00056 virtual void setBackground( const QColor &color ) 00057 { 00058 bg = color; 00059 } 00060 virtual const QColor &background( QdbtBaseTabular * ) const; 00061 00062 void setAlignment( int alignment ) 00063 { 00064 align = alignment; 00065 } 00066 int alignment() const { return align; } 00067 00068 void setPixmapAlignment( int alignment ) 00069 { 00070 pmapAlign = alignment; 00071 } 00072 int pixmapAlignment() const 00073 { 00074 return pmapAlign; 00075 } 00076 00077 virtual int widthHint( const QFontMetrics &fm ) const; 00078 virtual int heightHint( const QFontMetrics &fm ) const; 00079 00080 int borderMode(); 00081 void setBorderMode( int borderStyle ); 00082 00083 protected: 00084 virtual QWidget *editor( QdbtBaseTabular * ) const; 00085 virtual void paint( QPainter *p, QdbtBaseTabular *t, const QRect & r, 00086 bool selected, bool editing = FALSE ); 00087 virtual QRect getTextArea() const; 00088 virtual QRect getEditArea( int width ) const; 00089 virtual QdbtBaseCell *clone( QdbtBaseTabular * ) const; 00090 00091 virtual bool beginEdit( QdbtBaseTabular *, int row, int col, 00092 const QRect cellGeometry ) const; 00093 virtual bool acceptEdit( QdbtBaseTabular *, int row, int col ); 00094 virtual bool cancelEdit( QdbtBaseTabular *, int row, int col ); 00095 00096 private: 00097 QPixmap pmap; 00098 QString txt; 00099 QColor col; 00100 QColor bg; 00101 QRect tr; 00102 int align; 00103 int pmapAlign; 00104 short _borderFlags; 00105 }; 00106 00107 #endif