]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/kitemlistheader.cpp
Merge branch 'stashAction'
[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 "kitemlistview.h"
22
23 #include "private/kitemlistheaderwidget.h"
24
25 KItemListHeader::~KItemListHeader()
26 {
27 }
28
29 void KItemListHeader::setAutomaticColumnResizing(bool automatic)
30 {
31 if (m_headerWidget->automaticColumnResizing() != automatic) {
32 m_headerWidget->setAutomaticColumnResizing(automatic);
33 if (automatic) {
34 m_view->applyAutomaticColumnWidths();
35 m_view->doLayout(KItemListView::NoAnimation);
36 }
37 }
38 }
39
40 bool KItemListHeader::automaticColumnResizing() const
41 {
42 return m_headerWidget->automaticColumnResizing();
43 }
44
45 void KItemListHeader::setColumnWidth(const QByteArray& role, qreal width)
46 {
47 if (!m_headerWidget->automaticColumnResizing()) {
48 m_headerWidget->setColumnWidth(role, width);
49 m_view->applyColumnWidthsFromHeader();
50 m_view->doLayout(KItemListView::NoAnimation);
51 }
52 }
53
54 qreal KItemListHeader::columnWidth(const QByteArray& role) const
55 {
56 return m_headerWidget->columnWidth(role);
57 }
58
59 void KItemListHeader::setColumnWidths(const QHash<QByteArray, qreal>& columnWidths)
60 {
61 if (!m_headerWidget->automaticColumnResizing()) {
62 foreach (const QByteArray& role, m_view->visibleRoles()) {
63 const qreal width = columnWidths.value(role);
64 m_headerWidget->setColumnWidth(role, width);
65 }
66
67 m_view->applyColumnWidthsFromHeader();
68 m_view->doLayout(KItemListView::NoAnimation);
69 }
70 }
71
72 qreal KItemListHeader::preferredColumnWidth(const QByteArray& role) const
73 {
74 return m_headerWidget->preferredColumnWidth(role);
75 }
76
77 KItemListHeader::KItemListHeader(KItemListView* listView) :
78 QObject(listView->parent()),
79 m_view(listView)
80 {
81 m_headerWidget = m_view->m_headerWidget;
82 Q_ASSERT(m_headerWidget);
83
84 connect(m_headerWidget, &KItemListHeaderWidget::columnWidthChanged,
85 this, &KItemListHeader::columnWidthChanged);
86 connect(m_headerWidget, &KItemListHeaderWidget::columnWidthChangeFinished,
87 this, &KItemListHeader::columnWidthChangeFinished);
88 }
89