1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "kitemlistheader.h"
21 #include "kitemlistview.h"
22 #include "private/kitemlistheaderwidget.h"
24 KItemListHeader::~KItemListHeader()
28 void KItemListHeader::setAutomaticColumnResizing(bool automatic
)
30 if (m_headerWidget
->automaticColumnResizing() != automatic
) {
31 m_headerWidget
->setAutomaticColumnResizing(automatic
);
33 m_view
->applyAutomaticColumnWidths();
34 m_view
->doLayout(KItemListView::NoAnimation
);
39 bool KItemListHeader::automaticColumnResizing() const
41 return m_headerWidget
->automaticColumnResizing();
44 void KItemListHeader::setColumnWidth(const QByteArray
& role
, qreal width
)
46 if (!m_headerWidget
->automaticColumnResizing()) {
47 m_headerWidget
->setColumnWidth(role
, width
);
48 m_view
->applyColumnWidthsFromHeader();
49 m_view
->doLayout(KItemListView::NoAnimation
);
53 qreal
KItemListHeader::columnWidth(const QByteArray
& role
) const
55 return m_headerWidget
->columnWidth(role
);
58 void KItemListHeader::setColumnWidths(const QHash
<QByteArray
, qreal
>& columnWidths
)
60 if (!m_headerWidget
->automaticColumnResizing()) {
61 foreach (const QByteArray
& role
, m_view
->visibleRoles()) {
62 const qreal width
= columnWidths
.value(role
);
63 m_headerWidget
->setColumnWidth(role
, width
);
66 m_view
->applyColumnWidthsFromHeader();
67 m_view
->doLayout(KItemListView::NoAnimation
);
71 qreal
KItemListHeader::preferredColumnWidth(const QByteArray
& role
) const
73 return m_headerWidget
->preferredColumnWidth(role
);
76 KItemListHeader::KItemListHeader(KItemListView
* listView
) :
80 m_headerWidget
= m_view
->m_headerWidget
;
81 Q_ASSERT(m_headerWidget
);
83 connect(m_headerWidget
, &KItemListHeaderWidget::columnWidthChanged
,
84 this, &KItemListHeader::columnWidthChanged
);
85 connect(m_headerWidget
, &KItemListHeaderWidget::columnWidthChangeFinished
,
86 this, &KItemListHeader::columnWidthChangeFinished
);