ActivityDelegate: Make the row height public accessible.

Now it can be used to be set on the other two treeviews.
This commit is contained in:
Klaas Freitag 2015-11-06 11:41:32 +01:00
parent cb1571c6c5
commit a1551ef6ab
2 changed files with 35 additions and 12 deletions

View file

@ -28,23 +28,41 @@
namespace OCC {
int ActivityItemDelegate::_iconHeight = 0;
int ActivityItemDelegate::_margin = 0;
int ActivityItemDelegate::iconHeight()
{
if( _iconHeight == 0 ) {
QStyleOptionViewItem option;
QFont font = option.font;
QFontMetrics fm(font);
_iconHeight = qRound(fm.height() / 5.0 * 8.0);
}
return _iconHeight;
}
int ActivityItemDelegate::rowHeight()
{
if( _margin == 0 ) {
QStyleOptionViewItem opt;
QFont f = opt.font;
QFontMetrics fm(f);
_margin = fm.height()/4;
}
return iconHeight() + 2 * _margin;
}
QSize ActivityItemDelegate::sizeHint(const QStyleOptionViewItem & option ,
const QModelIndex & /* index */) const
{
QFont font = option.font;
QFontMetrics fm(font);
int iconHeight = qRound(fm.height() / 5.0 * 8.0);
int margin = fm.height()/4;
// TODO: set a different height for the day-line
// calc height
int h = iconHeight; // lets display the icon
h += 2*margin; // two times margin
return QSize( 0, h);
return QSize( 0, rowHeight() );
}
void ActivityItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,

View file

@ -39,6 +39,11 @@ public:
bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option,
const QModelIndex& index ) Q_DECL_OVERRIDE;
static int rowHeight();
static int iconHeight();
private:
static int _margin;
static int _iconHeight;
};
} // namespace OCC