util
focusedtreeview.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "focusedtreeview.h"
00018 #include <QScrollBar>
00019
00020 namespace KDevelop {
00021
00022 FocusedTreeView::FocusedTreeView(QWidget* parent) : QTreeView(parent) {
00023 setVerticalScrollMode(ScrollPerItem);
00024 connect(verticalScrollBar(), SIGNAL(valueChanged(int)), SLOT(resizeColumnsToContents()));
00025 }
00026
00027 int FocusedTreeView::sizeHintForColumn(int column) const {
00028 QModelIndex i = indexAt(QPoint(0, 0));
00029 if(i.isValid()) {
00030 QSize hint = sizeHintForIndex(i);
00031 int maxWidth = hint.width();
00032 if(hint.height()) {
00033
00034
00035 for(int a = -1; a < (height() / hint.height())+1; ++a) {
00036 QModelIndex current = i.sibling(i.row()+a, column);
00037 QSize tempHint = sizeHintForIndex(current);
00038 if(tempHint.width() > maxWidth)
00039 maxWidth = tempHint.width();
00040 }
00041 }
00042 return maxWidth;
00043 }
00044 return columnWidth(column);
00045 }
00046
00047 void FocusedTreeView::resizeColumnsToContents() {
00048 for(int a = 0; a < model()->columnCount(); ++a)
00049 resizeColumnToContents(a);
00050 }
00051
00052 void FocusedTreeView::rowsInserted(const QModelIndex& parent, int start, int end) {
00053 QTreeView::rowsInserted(parent, start, end);
00054 resizeColumnsToContents();
00055 }
00056
00057 }
00058
00059 #include "focusedtreeview.moc"