Unity 8
 All Classes Functions
ResponsiveVerticalJournal.qml
1 /*
2  * Copyright (C) 2013-2014 Canonical, Ltd.
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; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 import QtQuick 2.0
18 import Ubuntu.Components 0.1
19 import "../Components"
20 import Dash 0.1
21 
22 /*!
23  \brief A responsive wrapper around VerticalJournal.
24 
25  Based on defined column width, delegates are laid out in columns following
26  a top-left most position rule.
27 
28  Example:
29  +-----+ +-----+ +-----+
30  | | | 2 | | |
31  | | | | | |
32  | 1 | +-----+ | 3 |
33  | | +-----+ | |
34  | | | | +-----+
35  +-----+ | 4 | +-----+
36  +-----+ | | | 5 |
37  | 6 | +-----+ | |
38  | | +-----+
39  +-----+
40 */
41 Item {
42  property real minimumColumnSpacing: units.gu(1)
43 
44  property alias columnWidth: verticalJournalView.columnWidth
45  property alias rowSpacing: verticalJournalView.rowSpacing
46  property alias model: verticalJournalView.model
47  property alias delegate: verticalJournalView.delegate
48  property alias displayMarginBeginning: verticalJournalView.displayMarginBeginning
49  property alias displayMarginEnd: verticalJournalView.displayMarginEnd
50 
51  implicitHeight: verticalJournalView.implicitHeight + rowSpacing
52  clip: height < implicitHeight
53 
54  VerticalJournal {
55  id: verticalJournalView
56  objectName: "responsiveVerticalJournalView"
57  anchors {
58  fill: parent
59  leftMargin: columnSpacing / 2
60  rightMargin: columnSpacing / 2
61  topMargin: rowSpacing / 2
62  bottomMargin: rowSpacing / 2
63  }
64 
65  function px2gu(pixels) {
66  return Math.floor(pixels / units.gu(1))
67  }
68 
69  columnSpacing: {
70  // parent.width = columns * columnWidth + (columns-1) * spacing + spacing(margins)
71  var expectedColumns = Math.max(1, Math.floor(parent.width / (columnWidth + minimumColumnSpacing)));
72  Math.floor((parent.width - expectedColumns * columnWidth) / expectedColumns);
73  }
74  }
75 }