#include <KDGanttLegend>
This is an item view class showing a small Gantt item and it's text defined by LegendRole.
Definition at line 35 of file kdganttlegend.h.
Public Member Functions | |
QModelIndex | indexAt (const QPoint &point) const |
Legend (QWidget *parent=0) | |
QSize | minimumSizeHint () const |
void | scrollTo (const QModelIndex &, ScrollHint=EnsureVisible) |
void | setModel (QAbstractItemModel *model) |
QSize | sizeHint () const |
QRect | visualRect (const QModelIndex &index) const |
virtual | ~Legend () |
Protected Slots | |
virtual void | modelDataChanged () |
Protected Member Functions | |
virtual QRect | drawItem (QPainter *painter, const QModelIndex &index, const QPoint &pos=QPoint()) const |
virtual StyleOptionGanttItem | getStyleOption (const QModelIndex &index) const |
int | horizontalOffset () const |
bool | isIndexHidden (const QModelIndex &) const |
virtual QSize | measureItem (const QModelIndex &index, bool recursive=true) const |
QModelIndex | moveCursor (CursorAction, Qt::KeyboardModifiers) |
void | paintEvent (QPaintEvent *event) |
void | setSelection (const QRect &, QItemSelectionModel::SelectionFlags) |
int | verticalOffset () const |
QRegion | visualRegionForSelection (const QItemSelection &) const |
Legend::Legend | ( | QWidget * | parent = 0 |
) | [explicit] |
Constructor. Creates a Legend with parent parent. The QObject parent is not used for anything internally.
Definition at line 47 of file kdganttlegend.cpp.
00048 : QAbstractItemView( parent ), 00049 _d( new Private ) 00050 { 00051 setItemDelegate( new ItemDelegate( this ) ); 00052 setFrameStyle( QFrame::NoFrame ); 00053 }
Legend::~Legend | ( | ) | [virtual] |
QRect Legend::drawItem | ( | QPainter * | painter, | |
const QModelIndex & | index, | |||
const QPoint & | pos = QPoint() | |||
) | const [protected, virtual] |
Draws the legend item at index and all of it's children recursively at pos onto painter. Reimplement this if you want to draw items in an user defined way.
Definition at line 144 of file kdganttlegend.cpp.
References KDGantt::StyleOptionGanttItem::boundingRect, d, getStyleOption(), KDGantt::StyleOptionGanttItem::itemRect, KDGantt::ItemTypeRole, measureItem(), KDGantt::ItemDelegate::paintGanttItem(), r, KDGantt::StyleOptionGanttItem::text, and KDGantt::TypeEvent.
Referenced by paintEvent().
00145 { 00146 int xPos = pos.x(); 00147 int yPos = pos.y(); 00148 00149 if( index.isValid() && index.model() == &d->proxyModel ) 00150 { 00151 ItemDelegate* const delegate = qobject_cast< ItemDelegate* >( itemDelegate( index ) ); 00152 assert( delegate != 0 ); 00153 const QRect r( pos, measureItem( index, false ) ); 00154 StyleOptionGanttItem opt = getStyleOption( index ); 00155 opt.rect = r; 00156 opt.rect.setWidth( r.height() ); 00157 00158 const ItemType typ = static_cast<ItemType>( index.model()->data( index, ItemTypeRole ).toInt() ); 00159 const int dx = (typ == TypeEvent) ? (r.height() / 2) : 0; 00160 00161 opt.itemRect = opt.rect.adjusted(dx,0,dx,0); 00162 opt.boundingRect = r; 00163 opt.boundingRect.setWidth( r.width() + r.height() ); 00164 if( !opt.text.isNull() ) 00165 delegate->paintGanttItem( painter, opt, index ); 00166 00167 xPos = r.right(); 00168 yPos = r.bottom(); 00169 } 00170 00171 00172 const int rowCount = d->proxyModel.rowCount( index ); 00173 for( int row = 0; row < rowCount; ++row ) 00174 { 00175 const QRect r = drawItem( painter, d->proxyModel.index( row, 0, index ), QPoint( pos.x(), yPos ) ); 00176 xPos = qMax( xPos, r.right() ); 00177 yPos = qMax( yPos, r.bottom() ); 00178 } 00179 00180 return QRect( pos, QPoint( xPos, yPos ) ); 00181 }
StyleOptionGanttItem Legend::getStyleOption | ( | const QModelIndex & | index | ) | const [protected, virtual] |
Creates a StyleOptionGanttItem with all style options filled in except the target rectangles.
Definition at line 129 of file kdganttlegend.cpp.
References d, KDGantt::StyleOptionGanttItem::displayPosition, KDGantt::LegendRole, KDGantt::StyleOptionGanttItem::Right, and KDGantt::StyleOptionGanttItem::text.
Referenced by drawItem().
00130 { 00131 StyleOptionGanttItem opt; 00132 opt.displayPosition = StyleOptionGanttItem::Right; 00133 opt.displayAlignment = Qt::Alignment( d->proxyModel.data( index, Qt::TextAlignmentRole ).toInt() ); 00134 opt.text = index.model()->data( index, LegendRole ).toString(); 00135 opt.font = qVariantValue< QFont >( index.model()->data( index, Qt::FontRole ) ); 00136 return opt; 00137 }
int KDGantt::Legend::horizontalOffset | ( | ) | const [protected] |
QModelIndex Legend::indexAt | ( | const QPoint & | point | ) | const |
bool KDGantt::Legend::isIndexHidden | ( | const QModelIndex & | ) | const [protected] |
QSize Legend::measureItem | ( | const QModelIndex & | index, | |
bool | recursive = true | |||
) | const [protected, virtual] |
Calculates the needed space for the legend item at index and, if recursive is true, all child items.
Definition at line 186 of file kdganttlegend.cpp.
References d, and KDGantt::LegendRole.
Referenced by drawItem(), minimumSizeHint(), and sizeHint().
00187 { 00188 if( model() == 0 ) 00189 return QSize(); 00190 00191 QSize baseSize; 00192 if( index.model() != 0 ) 00193 { 00194 QFontMetrics fm( qVariantValue< QFont >( index.model()->data( index, Qt::FontRole ) ) ); 00195 const QString text = index.model()->data( index, LegendRole ).toString(); 00196 if( !text.isEmpty() ) 00197 baseSize += QSize( fm.width( text ) + fm.height() + 2, fm.height() + 2 ); 00198 } 00199 00200 if( !recursive ) 00201 return baseSize; 00202 00203 QSize childrenSize; 00204 00205 const int rowCount = d->proxyModel.rowCount( index ); 00206 for( int row = 0; row < rowCount; ++row ) 00207 { 00208 const QSize childSize = measureItem( d->proxyModel.index( row, 0, index ) ); 00209 childrenSize.setWidth( qMax( childrenSize.width(), childSize.width() ) ); 00210 childrenSize.rheight() += childSize.height(); 00211 } 00212 return baseSize + childrenSize; 00213 }
QSize Legend::minimumSizeHint | ( | ) | const |
Definition at line 80 of file kdganttlegend.cpp.
References measureItem().
00081 { 00082 return measureItem( rootIndex() ); 00083 }
void Legend::modelDataChanged | ( | ) | [protected, virtual, slot] |
Triggers repainting of the legend.
Definition at line 108 of file kdganttlegend.cpp.
Referenced by setModel().
QModelIndex KDGantt::Legend::moveCursor | ( | CursorAction | , | |
Qt::KeyboardModifiers | ||||
) | [protected] |
void Legend::paintEvent | ( | QPaintEvent * | event | ) | [protected] |
Definition at line 114 of file kdganttlegend.cpp.
References drawItem(), and p.
00115 { 00116 Q_UNUSED( event ); 00117 // no model, no legend... 00118 if( model() == 0 ) 00119 return; 00120 00121 QPainter p( viewport() ); 00122 p.fillRect( viewport()->rect(), palette().color( QPalette::Window ) ); 00123 drawItem( &p, rootIndex() ); 00124 }
void KDGantt::Legend::scrollTo | ( | const QModelIndex & | , | |
ScrollHint | = EnsureVisible | |||
) |
void Legend::setModel | ( | QAbstractItemModel * | model | ) |
Definition at line 85 of file kdganttlegend.cpp.
References d, and modelDataChanged().
00086 { 00087 if( this->model() != 0 ) 00088 { 00089 disconnect( this->model(), SIGNAL( dataChanged( QModelIndex, QModelIndex ) ), this, SLOT( modelDataChanged() ) ); 00090 disconnect( this->model(), SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( modelDataChanged() ) ); 00091 disconnect( this->model(), SIGNAL( columnsRemoved( QModelIndex, int, int ) ), this, SLOT( modelDataChanged() ) ); 00092 } 00093 00094 QAbstractItemView::setModel( model ); 00095 d->proxyModel.setSourceModel( model ); 00096 00097 if( this->model() != 0 ) 00098 { 00099 connect( this->model(), SIGNAL( dataChanged( QModelIndex, QModelIndex ) ), this, SLOT( modelDataChanged() ) ); 00100 connect( this->model(), SIGNAL( rowsRemoved( QModelIndex, int, int ) ), this, SLOT( modelDataChanged() ) ); 00101 connect( this->model(), SIGNAL( columnsRemoved( QModelIndex, int, int ) ), this, SLOT( modelDataChanged() ) ); 00102 } 00103 00104 }
void KDGantt::Legend::setSelection | ( | const QRect & | , | |
QItemSelectionModel::SelectionFlags | ||||
) | [protected] |
QSize Legend::sizeHint | ( | ) | const |
Definition at line 75 of file kdganttlegend.cpp.
References measureItem().
00076 { 00077 return measureItem( rootIndex() ); 00078 }
int KDGantt::Legend::verticalOffset | ( | ) | const [protected] |
QRect Legend::visualRect | ( | const QModelIndex & | index | ) | const |
QRegion KDGantt::Legend::visualRegionForSelection | ( | const QItemSelection & | ) | const [protected] |