File indexing completed on 2024-12-29 05:00:20

0001 /*
0002  *  SPDX-FileCopyrightText: 2015 David Rosca <nowrep@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0005  */
0006 
0007 .import org.kde.plasma.core as PlasmaCore
0008 .import org.kde.kirigami 2.20 as Kirigami
0009 
0010 function itemPadding() { return Kirigami.Units.smallSpacing / 2; }
0011 
0012 function rows()
0013 {
0014     if (vertical) {
0015         return Math.ceil(grid.count / maxSectionCount);
0016     }
0017     return Math.min(grid.count, maxSectionCount);
0018 }
0019 
0020 function cols()
0021 {
0022     if (vertical) {
0023         return Math.min(grid.count, maxSectionCount);
0024     }
0025     return Math.ceil(grid.count / maxSectionCount);
0026 }
0027 
0028 function minimumWidth()
0029 {
0030     var w = cols() * minimumCellWidth();
0031     if (!vertical && popupArrow.visible) {
0032         w += popupArrow.width;
0033     }
0034     return w;
0035 }
0036 
0037 function minimumHeight()
0038 {
0039     var h = rows() * minimumCellHeight();
0040     if (vertical && popupArrow.visible) {
0041         h += popupArrow.height;
0042     }
0043     if (title.length) {
0044         h += titleLabel.height;
0045     }
0046     return h;
0047 }
0048 
0049 function preferredWidth()
0050 {
0051     var w = cols() * preferredCellWidth();
0052     if (horizontal) {
0053         w = (preferredHeight() / rows()) * cols();
0054     }
0055     if (!vertical && popupArrow.visible) {
0056         w += popupArrow.width;
0057     }
0058     return w;
0059 }
0060 
0061 function preferredHeight()
0062 {
0063     var h = rows() * preferredCellHeight();
0064     if (vertical) {
0065         h = (preferredWidth() / cols()) * rows();
0066         if (popupArrow.visible) {
0067             h += popupArrow.height;
0068         }
0069     }
0070     if (title.length) {
0071         h += titleLabel.height;
0072     }
0073     return h;
0074 }
0075 
0076 function minimumCellWidth()
0077 {
0078   return Kirigami.Units.iconSizes.small + 2 * itemPadding();
0079 }
0080 
0081 function minimumCellHeight()
0082 {
0083   var h = Kirigami.Units.iconSizes.small + 2 * itemPadding();
0084   if (showLauncherNames) {
0085     h += Kirigami.Units.gridUnit * 2;
0086   }
0087     return h;
0088 }
0089 
0090 function preferredCellWidth()
0091 {
0092     return Math.floor(grid.width / cols());
0093 }
0094 
0095 function preferredCellHeight()
0096 {
0097     return Math.floor(grid.height / rows());
0098 }
0099 
0100 function popupItemWidth()
0101 {
0102   return Math.max(root.width, Kirigami.Units.iconSizes.medium + 20 * Kirigami.Units.gridUnit);
0103 }
0104 
0105 function popupItemHeight()
0106 {
0107   return Kirigami.Units.iconSizes.medium + 2 * itemPadding();
0108 }