/usr/lib/x86_64-linux-gnu/qt5/qml/Ubuntu/Components/1.3/AdaptivePageLayout.qml is in qml-module-ubuntu-components 1.3.1918+16.04.20160404-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 | /*
* Copyright 2015 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.4
import QtQuick.Layouts 1.1
import Ubuntu.Components 1.3
import Ubuntu.Components.Private 1.3
/*!
\qmltype AdaptivePageLayout
\inqmlmodule Ubuntu.Components 1.3
\since Ubuntu.Components 1.3
\ingroup ubuntu
\brief View with multiple columns of Pages.
The component provides a flexible way of viewing a stack of pages in one or
more columns. Unlike in PageStack, there can be more than one Page active at
a time, depending on the number of the columns in the view.
AdaptivePageLayout stores pages added in a tree. Pages are added relative to a
given page, either as sibling (\l addPageToCurrentColumn) or as child
(\l addPageToNextColumn). This means that removing a non-leaf page from the Page
tree will remove all its children from the page tree.
The columns are populated from left to right. The column a page is added to is
detected based on the source page that is given to the functions adding the page.
The pages can be added either to the same column the source page resides or to
the column next to the source page. Giving a null value to the source page will
add the page to the leftmost column of the view.
The primary page, the very first page must be specified either through the
\l primaryPage or \l primaryPageSource properties. \l primaryPage can only
hold a Page instance, \l primaryPageSource can either be a Component or a
url to a document defining a Page. \l primaryPageSource has precedence over
\l primaryPage, and when set it will report the loaded Page through \l primaryPage
property, and will replace any value set into that property.
\qml
import QtQuick 2.4
import Ubuntu.Components 1.3
MainView {
width: units.gu(100)
height: units.gu(60)
AdaptivePageLayout {
anchors.fill: parent
primaryPage: page1
Page {
id: page1
header: PageHeader {
id: header
title: "Main Page"
}
Column {
anchors.top: header.bottom
Button {
text: "Add Page2 above " + page1.title
onClicked: page1.pageStack.addPageToCurrentColumn(page1, page2)
}
Button {
text: "Add Page3 next to " + page1.title
onClicked: page1.pageStack.addPageToNextColumn(page1, page3)
}
}
}
Page {
id: page2
header: PageHeader {
title: "Page #2"
}
}
Page {
id: page3
header: PageHeader {
title: "Page #3"
}
}
}
}
\endqml
\note Observe the use of the \c Page::pageStack property in the example above.
The same property is used to share the AdaptivePageLayout instance the Page is
used in, therefore the same page can be used in a PageStack or in an AdaptivePageLayout.
However implementations must make sure the desired PageStack or AdaptivePageLayout
function exists in the instance before using it.
AdaptivePageLayout supports adaptive column handling. When the number of columns changes at
runtime the pages are automatically rearranged.
By default the component splits the layout in two columns when the width of the
layout exceeds 80 grid units. The first column is sized to 40 grid unit width and
the second one to fill the rest of the remaining space. When the 80 grid unit breakpoint
is reached, the component will switch from one column to two, and vice versa.
These defaults can be overridden through the \l layouts property by defining the
possible layouts, their column sizing and the breakpoints when the layouts should
be activated. PageColumn configurations must appear in the same order (from left
to right) as the columns appear in the layout. If none of the layouts condition
is met, a one column layout will be used.
\qml
import QtQuick 2.4
import Ubuntu.Components 1.3
MainView {
width: units.gu(100)
height: units.gu(60)
AdaptivePageLayout {
anchors.fill: parent
primaryPageSource: page1Component
layouts: PageColumnsLayout {
when: width > units.gu(80)
// column #0
PageColumn {
minimumWidth: units.gu(30)
maximumWidth: units.gu(60)
preferredWidth: units.gu(40)
}
// column #1
PageColumn {
fillWidth: true
}
}
Component {
id: page1Component
Page {
id: page1
header: PageHeader {
id: header
title: "Main page"
}
Column {
anchors.top: header.bottom
Button {
text: "Add Page2 above " + page1.title
onClicked: page1.pageStack.addPageToCurrentColumn(page1, page2)
}
Button {
text: "Add Page3 next to " + page1.title
onClicked: page1.pageStack.addPageToNextColumn(page1, page3)
}
}
}
}
Page {
id: page2
header: PageHeader {
title: "Page #2"
}
}
Page {
id: page3
header: PageHeader {
title: "Page #3"
}
}
}
}
\endqml
A column is considered to be resizable if the \l PageColumn::minimumWidth and
\l PageColumn::maximumWidth configuration differs. This implies that if a column
is not meant to be resized, it should have \l PageColumn::minimumWidth and
\l PageColumn::maximumWidth set to the same value. In the example above, the
first column can be resized to a minimum of 30, and a maximum of 60 grid units,
and the preferred width is set to 40 grid units. This width is set every time
the layout is activated.
When a \l Page with the \l Page::header property set is added to an
AdaptivePageLayout, the AdaptivePageLayout will synchronize the height of that
header with the height of the headers in other columns, i.e., the height of
each of the headers will be set to the maximum implicitHeight of all the headers.
\sa PageStack, PageColumnsLayout, PageColumn
*/
PageTreeNode {
id: layout
Page {
// AdaptivePageLayout has its own split headers, so
// disable the application header.
id: appHeaderControlPage
head {
locked: true
visible: false
}
// title is set in attachPage() when the attached Page.column === 0
}
/*!
The property holds the first Page which will be added to the view. If the
view has more than one column, the page will be added to the leftmost column.
The property can only hold a Page instance. When changed runtime (not by the
AdaptivePageLayout component itself), the \l primaryPageSource property
will be reset.
*/
property Page primaryPage
/*!
The property specifies the source of the primaryPage in case the primary
page is created from a Component or loaded from an external document. It
has precedence over \l primaryPage.
*/
property var primaryPageSource
/*!
The property drives the way the pages should be loaded, synchronously or
asynchronously. Defaults to true.
*/
property bool asynchronous: true
/*!
\qmlproperty int columns
\readonly
The property holds the number of columns shown in the layout.
*/
readonly property alias columns: d.columns
/*!
The property holds the different layout configurations overriding the default
configurations. Defaults to an empty list.
\sa PageColumnsLayout
*/
property list<PageColumnsLayout> layouts
/*!
\qmlmethod object addPageToCurrentColumn(Item sourcePage, var page[, var properties])
Adds a \c page to the column the \c sourcePage resides in and removes all pages
from the higher columns. \c page can be a Component or a file.
\c properties is a JSON object containing properties to be set when page
is created. \c sourcePage must be active.
The function creates the new page asynchronously if the new \c page to be
added is a Component or a QML document and the \l asynchronous property is
set to true. In this case the function returns an incubator which can be
used to track the page creation. For more about incubation in QML and creating
components asynchronously, see
\l {http://doc.qt.io/qt-5/qml-qtqml-component.html#incubateObject-method}
{Component.incubateObject()}.
The following example removes an element from the list model whenever the
page opened in the second column is closed. Note, the example must be run
on desktop or on a device with at least 90 grid units screen width.
\qml
import QtQuick 2.4
import Ubuntu.Components 1.3
MainView {
width: units.gu(90)
height: units.gu(70)
Component {
id: page2Component
Page {
header: PageHeader {
id: header
title: "Second Page"
}
Button {
anchors.top: header.bottom
text: "Close me"
onClicked: pageStack.removePages(pageStack.primaryPage);
}
}
}
AdaptivePageLayout {
id: pageLayout
anchors.fill: parent
primaryPage: Page {
header: PageHeader {
title: "Primary Page"
flickable: listView
}
ListView {
id: listView
anchors.fill: parent
model: 10
delegate: ListItem {
Label { text: modelData }
onClicked: {
var incubator = pageLayout.addPageToNextColumn(pageLayout.primaryPage, page2Component);
if (incubator && incubator.status == Component.Loading) {
incubator.onStatusChanged = function(status) {
if (status == Component.Ready) {
// connect page's destruction to decrement model
incubator.object.Component.destruction.connect(function() {
listView.model--;
});
}
}
}
}
}
}
}
}
}
\endqml
\sa {http://doc.qt.io/qt-5/qml-qtqml-component.html#incubateObject-method}{Component.incubateObject}
*/
function addPageToCurrentColumn(sourcePage, page, properties) {
var nextColumn = d.columnForPage(sourcePage) + 1;
d.tree.prune(nextColumn);
return d.addPageToColumn(nextColumn - 1, sourcePage, page, properties, function() {
// Clear all following columns. If we do not do this, we have no way to
// determine which page needs to be on top when the view is resized
// to have a single column.
for (var i = nextColumn; i < d.columns; i++) {
d.updatePageForColumn(i);
}
});
}
/*!
\qmlmethod Item addPageToNextColumn(Item sourcePage, var page[, var properties])
Remove all previous pages from the next column (relative to the column that
holds \c sourcePage) and all following columns, and then add \c page to the next column.
If \c sourcePage is located in the
rightmost column, the new page will be pushed to the same column as \c sourcePage.
The return value is the same as in \l addPageToCurrentColumn case.
*/
function addPageToNextColumn(sourcePage, page, properties) {
var nextColumn = d.columnForPage(sourcePage) + 1;
var wrappers = d.tree.prune(nextColumn);
return d.addPageToColumn(nextColumn, sourcePage, page, properties, function() {
for (var i = nextColumn; i < d.columns; i++) {
d.updatePageForColumn(i);
}
for (var i in wrappers) {
wrappers[i].destroyObject();
}
});
}
/*!
\qmlmethod void removePages(Item page)
The function removes and deletes all pages up to and including \c page
is reached. If the \a page is the same as the \l primaryPage, only its child
pages will be removed.
*/
function removePages(page) {
d.removeAllPages(page, page != layout.primaryPage);
}
/*
internals
*/
Component.onCompleted: {
// check layout configuration
if (layouts.length > 0) {
d.prepareLayouts();
} else {
d.relayout();
}
if (primaryPageSource) {
d.createPrimaryPage(primaryPageSource);
} else if (primaryPage) {
d.createPrimaryPage(primaryPage);
}
d.completed = true;
}
onPrimaryPageChanged: {
if (!d.completed || d.internalUpdate) {
return;
}
// reset the primaryPageSource
d.internalPropertyUpdate("primaryPageSource", undefined);
// clear the layout
d.purgeLayout();
// add the new page if valid
if (primaryPage !== null) {
d.createPrimaryPage(primaryPage);
}
}
onPrimaryPageSourceChanged: {
if (!d.completed || d.internalUpdate) {
return;
}
// remove all pages first
d.purgeLayout();
// create the new primary page if a valid component is specified
if (primaryPageSource) {
d.createPrimaryPage(primaryPageSource);
} else {
d.internalPropertyUpdate("primaryPage", null);
}
}
onLayoutsChanged: {
if (d.completed) {
// only deal with this if the layouts array changes after completion
// to avoid unnecessary rendering
d.prepareLayouts();
}
}
/*! \internal - for testing purposes */
readonly property alias __d:d
QtObject {
id: d
property bool internalUpdate: false
property bool completed: false
property var tree: Tree{}
property int columns: !layout.layouts.length ?
(layout.width >= units.gu(80) ? 2 : 1) :
(activeLayout ? activeLayout.data.length : 1)
property PageColumnsLayout activeLayout: null
property list<PageColumnsLayout> prevLayouts
property Page prevPrimaryPage
/*! internal */
onColumnsChanged: {
if (columns <= 0) {
console.warn("There must be a minimum of one column set.");
columns = 1;
}
d.relayout();
}
property real defaultColumnWidth: units.gu(40)
onDefaultColumnWidthChanged: body.applyMetrics()
function internalPropertyUpdate(propertyName, value) {
internalUpdate = true;
layout[propertyName] = value;
internalUpdate = false;
}
function createPrimaryPage(source) {
var wrapper = d.createWrapper(source);
if (wrapper.incubator) {
wrapper.pageLoaded.connect(finalizeAddingPage.bind(wrapper));
wrapper.incubator.onStatusChanged = function (status) {
if (status == Component.Ready) {
internalPropertyUpdate("primaryPage", wrapper.incubator.object);
prevPrimaryPage = wrapper.incubator.object;
}
}
} else {
finalizeAddingPage(wrapper);
prevPrimaryPage = wrapper.object;
}
}
// remove all pages, including primaryPage
function purgeLayout() {
if (prevPrimaryPage) {
removeAllPages(prevPrimaryPage, true);
prevPrimaryPage = null;
}
}
function createWrapper(page, properties) {
var wrapperObject = pageWrapperComponent.createObject(hiddenPages, {synchronous: !layout.asynchronous});
wrapperObject.pageStack = layout;
wrapperObject.properties = properties;
// set reference last because it will trigger creation of the object
// with specified properties.
wrapperObject.reference = page;
return wrapperObject;
}
function addWrappedPage(pageWrapper) {
pageWrapper.parentWrapper = d.getWrapper(pageWrapper.parentPage);
tree.add(pageWrapper.column, pageWrapper.parentWrapper, pageWrapper);
var targetColumn = MathUtils.clamp(pageWrapper.column, 0, d.columns - 1);
// replace page holder's child
var holder = body.children[targetColumn];
holder.detachCurrentPage();
holder.attachPage(pageWrapper); // sets pageWrapper.pageHolder
// set the back action for Page.header:
var page = pageWrapper.object;
if (page && page.hasOwnProperty("header") && page.header &&
page.header.hasOwnProperty("navigationActions")) {
// Page.header is an instance of PageHeader.
var backAction = backActionComponent.createObject(
pageWrapper, { 'wrapper': pageWrapper } );
page.header.navigationActions = [ backAction ] ;
}
}
function getWrapper(page) {
if (page && page.hasOwnProperty("parentNode")) {
var w = page.parentNode;
if (w && w.hasOwnProperty("object") && w.hasOwnProperty("reference")) {
if (w.object == page) {
return w;
} else {
console.error("Page is not wrapped by its parentNode. This should not happen!");
return null;
}
} else {
// invalid wrapper
return null;
}
} else {
// invalid page
return null;
}
}
function columnForPage(page) {
var wrapper = d.getWrapper(page);
return wrapper ? wrapper.column : 0;
}
function finalizeAddingPage(newWrapper) {
if (newWrapper === undefined) newWrapper = this;
d.addWrappedPage(newWrapper);
}
function addPageToColumn(column, sourcePage, page, properties, cleanupFunc) {
if (column < 0) {
console.warn("Column must be >= 0.");
return;
}
if (!sourcePage) {
console.warn("No sourcePage specified. Page will not be added.");
return;
}
var sourceWrapper = d.getWrapper(sourcePage);
if (d.tree.index(sourceWrapper) === -1) {
console.warn("sourcePage must be added to the view to add new page.");
return;
}
// Check that the Page was not already added.
if (typeof page !== "string" && !page.createObject) {
// page is neither a url or a Component so it must be a Page object.
var oldWrapper = getWrapper(page);
if (oldWrapper && d.tree.index(oldWrapper) !== -1) {
console.warn("Cannot add a Page that was already added.");
return null;
}
}
var newWrapper = d.createWrapper(page, properties);
newWrapper.parentPage = sourcePage;
newWrapper.column = column;
if (newWrapper.incubator) {
newWrapper.pageLoaded.connect(cleanupFunc);
newWrapper.pageLoaded.connect(finalizeAddingPage.bind(newWrapper));
} else {
cleanupFunc();
finalizeAddingPage(newWrapper);
}
return newWrapper.incubator;
}
// removes all pages from the layout, and may include the page itself
function removeAllPages(page, inclusive) {
inclusive = typeof inclusive !== 'undefined' ? inclusive : true;
var nodeToRemove = d.getWrapper(page);
var removedNodes = d.tree.chop(nodeToRemove, inclusive);
for (var i = removedNodes.length-1; i >= 0; i--) {
var node = removedNodes[i];
updatePageForColumn(node.column);
}
}
// update the page for the specified column
function updatePageForColumn(column) {
var effectiveColumn = MathUtils.clamp(column, 0, d.columns - 1);
var columnHolder = body.children[effectiveColumn];
var newWrapper = tree.top(effectiveColumn, effectiveColumn < d.columns - 1);
var oldWrapper = columnHolder.pageWrapper;
if (newWrapper != oldWrapper) {
columnHolder.detachCurrentPage();
oldWrapper.parent = null;
if (newWrapper) {
columnHolder.attachPage(newWrapper);
}
oldWrapper.destroyObject();
}
}
// prepares layout management, listens on layout condition changes and performs re-layouting
function prepareLayouts() {
// disconnect from the previous layouts
for (var i = 0; i < prevLayouts.length; i++) {
prevLayouts[i].whenChanged.disconnect(updateLayout);
}
prevLayouts = layouts;
for (var i = 0; i < layouts.length; i++) {
layouts[i].whenChanged.connect(updateLayout);
}
// first time evaluation
updateLayout();
}
// function called when one of the layout condition is satisfied
function updateLayout() {
var newLayout = null;
for (var i = 0; i < layouts.length; i++) {
// get the first affirmative condition
if (layouts[i].when) {
newLayout = layouts[i];
break;
}
}
d.activeLayout = newLayout;
}
// relayouts when column count changes
function relayout() {
if (body.children.length == d.columns) return;
if (body.children.length > d.columns) {
// need to remove few columns, the last ones
while (body.children.length > d.columns) {
var holder = body.children[body.children.length - 1];
holder.detachCurrentPage();
holder.parent = null;
holder.destroy();
}
} else {
var prevColumns = body.children.length;
// add columns
for (var i = 0; i < d.columns - prevColumns; i++) {
pageHolderComponent.createObject(body);
}
}
rearrangePages();
}
function rearrangePages() {
for (var column = d.columns - 1; column >= 0; column--) {
var holder = body.children[column];
var pageWrapper = tree.top(column, column < (d.columns - 1));
if (!pageWrapper) {
continue;
}
if (!pageWrapper.parent) {
// this should never happen, so if it does, we have a bug!
console.error("Found a page which wasn't parented anywhere!", pageWrapper.object.title);
continue;
}
// detach current page from holder if differs
if (holder.pageWrapper != pageWrapper) {
holder.detachCurrentPage();
}
if (pageWrapper.parent == holder.hiddenPool || pageWrapper.parent == hiddenPages) {
// add the page to the column
holder.attachPage(pageWrapper);
} else if (pageWrapper.pageHolder != holder) {
// detach the pageWrapper from its holder
if (pageWrapper.pageHolder) {
pageWrapper.pageHolder.detachCurrentPage();
}
// then attach to this holder
holder.attachPage(pageWrapper);
}
}
}
}
Component{
id: pageWrapperComponent
PageWrapper{
}
}
// default metrics
Component {
id: defaultMetrics
PageColumn {
fillWidth: __column == d.columns
minimumWidth: d.defaultColumnWidth
}
}
// An instance will be added to each Page with
Component {
id: backActionComponent
Action {
// used when the Page has a Page.header property set.
id: backAction
objectName: "apl_back_action"
iconName: "back"
text: "Back"
// set when backAction is created.
property PageWrapper wrapper
onTriggered: layout.removePages(wrapper.object)
visible: {
var parentWrapper = d.tree.parent(wrapper);
if (!parentWrapper)
// Root node has no parent node.
return false;
if (!wrapper.pageHolder) {
// columns are being re-arranged.
return false;
}
// wrapper.column is the virtual column, pageHolder.column the actual column.
var column = wrapper.pageHolder.column;
var nextInColumn = d.tree.top(column, column < d.columns - 1, 1);
return parentWrapper === nextInColumn;
}
}
}
// Page holder component, can have only one Page as child at a time, all stacked pages
// will be parented into hiddenPool
Component {
id: pageHolderComponent
// Page uses the height of the parentNode for its height, so make
// the holder a PageTreeNode that determines the Page height.
PageTreeNode {
id: holder
active: false
objectName: "ColumnHolder" + column
property var pageWrapper: pageWrapperComponent.createObject()
property int column
property alias config: subHeader.config
property PageColumn metrics: getDefaultMetrics()
readonly property real dividerThickness: units.dp(1)
readonly property alias hiddenPool: hiddenItem
Layout.fillWidth: metrics.fillWidth
Layout.fillHeight: true
Layout.preferredWidth: MathUtils.clamp(metrics.preferredWidth, metrics.minimumWidth, metrics.maximumWidth)
Layout.minimumWidth: metrics.minimumWidth
Layout.maximumWidth: metrics.maximumWidth
property var page: pageWrapper ? pageWrapper.object : null
property bool customHeader: page && page.hasOwnProperty("header") &&
page.header
onCustomHeaderChanged: {
// do not change the holderBody anchors until the new page
// for the column has been set to prevent geometry changes in
// the current/previous page.
if (page) {
if (customHeader) {
holderBody.anchors.top = holderBody.parent.top;
} else {
holderBody.anchors.top = subHeader.bottom;
}
}
}
onPageChanged: body.updateHeaderHeight(0)
Connections {
target: page
onHeaderChanged: body.updateHeaderHeight(0)
}
Connections {
target: page ? page.header : null
onImplicitHeightChanged: body.updateHeaderHeight(page.header.implicitHeight)
}
// prevent the pages from taking the app header height into account.
__propagated: null
Item {
id: holderBody
objectName: parent.objectName + "Body"
anchors {
top: subHeader.bottom // updated in onCustomHeaderChanged
bottom: parent.bottom
left: parent.left
right: parent.right
rightMargin: dividerThickness
}
Item {
id: hiddenItem
anchors.fill: parent
visible: false
}
}
// subHeader is to be deprecated in UITK 1.4 and will be replaced
// by the Page.header property (introduced in 1.3).
property alias head: subHeader
StyledItem {
id: subHeader
anchors {
left: parent.left
top: parent.top
right: parent.right
}
height: body.headerHeight
styleName: "PageHeadStyle"
objectName: "Header" + column
property real preferredHeight: subHeader.__styleInstance ?
subHeader.__styleInstance.implicitHeight :
0
onPreferredHeightChanged: {
body.updateHeaderHeight(preferredHeight);
}
property PageHeadConfiguration config: null
property Item contents: null
property color dividerColor: layout.__propagated.header.dividerColor
property color panelColor: layout.__propagated.header.panelColor
property color backgroundColor: layout.__propagated.header.backgroundColor
visible: !customHeader && holder.pageWrapper && holder.pageWrapper.active
// The multiColumn, page and showBackButton properties are used in
// PageHeadStyle to show/hide the back button.
property var multiColumn: layout
property alias page: holder.page // used in PageHeadStyle for the back button.
property bool showBackButton: {
if (!page) {
return false;
}
var parentWrapper = d.tree.parent(holder.pageWrapper);
if (!parentWrapper) {
// Root node has no parent node.
return false;
}
var nextInColumn = d.tree.top(holder.column, holder.column < d.columns - 1, 1);
return parentWrapper === nextInColumn;
}
}
Rectangle {
id: verticalDivider
anchors {
top: parent.top
bottom: parent.bottom
right: parent.right
rightMargin: dividerThickness
}
width: (column == (d.columns - 1)) || !pageWrapper ? 0 : units.dp(1)
color: theme.palette.normal.base
MouseArea {
id: resizerSensing
objectName: "Divider"
enabled: verticalDivider.width > 0
anchors {
fill: parent
leftMargin: enabled ? -units.gu(1) : 0
rightMargin: enabled ? -units.gu(1) : 0
}
cursorShape: Qt.SizeHorCursor
drag {
axis: Drag.XAxis
target: resizer
smoothed: false
minimumX: holder.Layout.minimumWidth
maximumX: holder.Layout.maximumWidth
}
onPressed: resizer.x = holder.Layout.preferredWidth
}
states: State {
name: "active"
when: resizerSensing.pressed
PropertyChanges {
target: verticalDivider
color: Qt.darker(theme.palette.normal.background, 1.7)
}
}
transitions: Transition {
from: ""
to: "*"
reversible: true
ColorAnimation {
target: verticalDivider
property: "color"
duration: UbuntuAnimation.SlowDuration
}
}
}
Item {
id: resizer
height: parent.height
onXChanged: holder.Layout.preferredWidth = x
}
function attachPage(wrapper) {
pageWrapper = wrapper;
pageWrapper.parent = holderBody;
pageWrapper.pageHolder = holder;
pageWrapper.active = true;
if (pageWrapper.object.hasOwnProperty("head")) {
subHeader.config = pageWrapper.object.head;
}
if (pageWrapper.column === 0) {
// set the application title
appHeaderControlPage.title = pageWrapper.object.title;
}
}
function detachCurrentPage() {
if (!pageWrapper) return undefined;
var wrapper = pageWrapper;
// remove header
wrapper.active = false;
subHeader.config = null;
pageWrapper = null;
wrapper.parent = hiddenPool;
wrapper.pageHolder = null;
return wrapper;
}
function getDefaultMetrics() {
var result = defaultMetrics.createObject(holder);
result.__column = Qt.binding(function() { return holder.column + 1; });
return result;
}
}
}
/*! \internal */
// Pages declared as children will be placed directly into hiddenPages
default property alias data: hiddenPages.data
PageTreeNode {
id: hiddenPages
objectName: "HiddenPagePool"
visible: false
active: false
// make sure nothing is shown eventually
clip: true
anchors.fill: parent
}
// Holds the columns holding the pages visible. Each column has only one page
// as child, the invisible stacked ones are all stored in the hiddenPool
// component within each column. The stack keeps the column index onto which
// those should be moved once they become visible.
RowLayout {
id: body
objectName: "body"
anchors.fill: parent
spacing: 0
property real headerHeight: 0
function updateHeaderHeight(newHeight) {
var page;
var i;
if (newHeight > body.headerHeight) {
body.headerHeight = newHeight;
} else {
var h = 0;
var subHeight = 0;
for (i = 0; i < children.length; i++) {
page = children[i].page;
if (page && page.hasOwnProperty("header") && page.header) {
subHeight = page.header.implicitHeight;
} else {
subHeight = children[i].head.preferredHeight;
}
if (subHeight > h) h = subHeight;
}
body.headerHeight = h;
}
// Update all the Page.header heights.
for (i = 0; i < body.children.length; i++) {
page = body.children[i].page;
if (page && page.hasOwnProperty("header") && page.header) {
page.header.height = headerHeight;
}
}
}
onChildrenChanged: {
// all children should have Layout.fillWidth false, except the last one
for (var i = 0; i < children.length; i++) {
children[i].column = i;
}
applyMetrics();
}
function applyMetrics() {
for (var i = 0; i < children.length; i++) {
var holder = children[i];
// search for the column metrics
var metrics = d.activeLayout ? d.activeLayout.data[i] : null;
if (!metrics) {
metrics = holder.getDefaultMetrics();
}
holder.metrics = metrics;
updateHeaderHeight(0);
}
}
}
}
|