~ubuntu-branches/ubuntu/vivid/muon/vivid-proposed

« back to all changes in this revision

Viewing changes to installer/CategoryView/CategoryView.cpp

  • Committer: Package Import Robot
  • Author(s): Scarlett Clark
  • Date: 2015-03-24 07:36:31 UTC
  • mto: This revision was merged to the branch mainline in revision 86.
  • Revision ID: package-import@ubuntu.com-20150324073631-7nmay5episnfkdlt
Tags: upstream-5.2.2
Import upstream version 5.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright © 2010 Jonathan Thomas <echidnaman@kubuntu.org>             *
3
 
 *                                                                         *
4
 
 *   This program is free software; you can redistribute it and/or         *
5
 
 *   modify it under the terms of the GNU General Public License as        *
6
 
 *   published by the Free Software Foundation; either version 2 of        *
7
 
 *   the License or (at your option) version 3 or any later version        *
8
 
 *   accepted by the membership of KDE e.V. (or its successor approved     *
9
 
 *   by the membership of KDE e.V.), which shall act as a proxy            *
10
 
 *   defined in Section 14 of version 3 of the license.                    *
11
 
 *                                                                         *
12
 
 *   This program is distributed in the hope that it will be useful,       *
13
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
14
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
15
 
 *   GNU General Public License for more details.                          *
16
 
 *                                                                         *
17
 
 *   You should have received a copy of the GNU General Public License     *
18
 
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
19
 
 ***************************************************************************/
20
 
 
21
 
#include "CategoryView.h"
22
 
 
23
 
// KDE includes
24
 
#include <KDialog>
25
 
#include <KCategoryDrawer>
26
 
#include <KFileItemDelegate>
27
 
 
28
 
// Own includes
29
 
#include "CategoryDrawer.h"
30
 
 
31
 
CategoryView::CategoryView(QWidget *parent)
32
 
    : KCategorizedView(parent)
33
 
{
34
 
    CategoryDrawer *drawer = new CategoryDrawer(this);
35
 
 
36
 
    setSelectionMode(QAbstractItemView::SingleSelection);
37
 
    setSpacing(KDialog::spacingHint());
38
 
    setResizeMode(QListView::Adjust);
39
 
    setWordWrap(true);
40
 
    setCategoryDrawer(drawer);
41
 
    setViewMode(QListView::IconMode);
42
 
    setMouseTracking( true );
43
 
    viewport()->setAttribute( Qt::WA_Hover );
44
 
 
45
 
    KFileItemDelegate *delegate = new KFileItemDelegate(this);
46
 
    delegate->setWrapMode(QTextOption::WordWrap);
47
 
    setItemDelegate(delegate);
48
 
}
49
 
 
50
 
void CategoryView::setModel(QAbstractItemModel *model)
51
 
{
52
 
    //icon stuff ripped from System Settings trunk
53
 
    KCategorizedView::setModel(model);
54
 
    int maxWidth = -1;
55
 
    int maxHeight = -1;
56
 
    for (int i = 0; i < model->rowCount(); ++i) {
57
 
        const QModelIndex index = model->index(i, modelColumn(), rootIndex());
58
 
        const QSize size = sizeHintForIndex(index);
59
 
        maxWidth = qMax(maxWidth, size.width());
60
 
        maxHeight = qMax(maxHeight, size.height());
61
 
    }
62
 
    setGridSize(QSize(maxWidth, maxHeight ));
63
 
    static_cast<KFileItemDelegate*>(itemDelegate())->setMaximumSize(QSize(maxWidth, maxHeight));
64
 
}
65
 
 
66
 
#include "CategoryView.moc"