]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kitemlistheader.cpp
Cleanup and minor fixes for column-handling
[dolphin.git] / src / kitemviews / kitemlistheader.cpp
1 /***************************************************************************
2 * Copyright (C) 2012 by Peter Penz <peter.penz19@gmail.com> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include "kitemlistheader.h"
21 #include "kitemlistheaderwidget_p.h"
22 #include "kitemlistview.h"
23
24 KItemListHeader::~KItemListHeader()
25 {
26 }
27
28 void KItemListHeader::setAutomaticColumnResizing(bool automatic)
29 {
30 if (m_headerWidget->automaticColumnResizing() != automatic) {
31 m_headerWidget->setAutomaticColumnResizing(automatic);
32 if (automatic) {
33 m_view->resizeColumnWidths();
34 }
35 }
36 }
37
38 bool KItemListHeader::automaticColumnResizing() const
39 {
40 return m_headerWidget->automaticColumnResizing();
41 }
42
43 void KItemListHeader::setColumnWidth(const QByteArray& role, qreal width)
44 {
45 if (!m_headerWidget->automaticColumnResizing()) {
46 m_headerWidget->setColumnWidth(role, width);
47 m_view->applyColumnWidthsFromHeader();
48 }
49 }
50
51 qreal KItemListHeader::columnWidth(const QByteArray& role) const
52 {
53 return m_headerWidget->columnWidth(role);
54 }
55
56 void KItemListHeader::setColumnWidths(const QHash<QByteArray, qreal>& columnWidths)
57 {
58 if (!m_headerWidget->automaticColumnResizing()) {
59 foreach (const QByteArray& role, m_view->visibleRoles()) {
60 const qreal width = columnWidths.value(role);
61 m_headerWidget->setColumnWidth(role, width);
62 }
63
64 m_view->applyColumnWidthsFromHeader();
65 }
66 }
67
68 qreal KItemListHeader::preferredColumnWidth(const QByteArray& role) const
69 {
70 return m_headerWidget->preferredColumnWidth(role);
71 }
72
73 KItemListHeader::KItemListHeader(KItemListView* listView) :
74 QObject(listView->parent()),
75 m_view(listView)
76 {
77 m_headerWidget = m_view->m_headerWidget;
78 Q_ASSERT(m_headerWidget);
79
80 connect(m_headerWidget, SIGNAL(columnWidthChanged(QByteArray,qreal,qreal)),
81 this, SIGNAL(columnWidthChanged(QByteArray,qreal,qreal)));
82 }
83
84 #include "kitemlistheader.moc"