ColumnLayout.js 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. /**
  2. * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved.
  3. *
  4. * This file is part of the QCAD project.
  5. *
  6. * QCAD is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * QCAD is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with QCAD.
  18. */
  19. //include("scripts/library.js");
  20. // TODO: move to C++, cannot store QWidgetItem pointers in variant
  21. //function ColumnLayout(parent, toolBar, buttonSize) {
  22. // QLayout.call(this, parent);
  23. // this.setContentsMargins(2,2,2,2);
  24. // this.setProperty("toolBar", toolBar);
  25. // this.setProperty("sHint", new QSize());
  26. // this.itemList = [];
  27. //}
  28. //ColumnLayout.prototype = new QLayout();
  29. //ColumnLayout.prototype.toString = function() {
  30. // return "ColumnLayout [JS]";
  31. //};
  32. //ColumnLayout.prototype.removeAction = function(a) {
  33. // qDebug("001");
  34. // //var itemList = this.property("ItemList");
  35. // if (isNull(this.itemList)) {
  36. // return;
  37. // }
  38. // var index = -1;
  39. // for (var i=0; i<this.itemList.length; ++i) {
  40. // if (!isOfType(this.itemList[i], QToolButton)) {
  41. // continue;
  42. // }
  43. // if (this.itemList[i].defaultAction()===a) {
  44. // index = i;
  45. // }
  46. // }
  47. // if (index!==-1) {
  48. // this.itemList.splice(index, 1);
  49. // }
  50. // //this.setProperty("ItemList", itemList);
  51. //};
  52. ///**
  53. // * \param item A widget (e.g. QToolButton) with property "SortOrder" set to the
  54. // * desired sort order. Or a separator action, also with property "SortOrder"
  55. // * set.
  56. // */
  57. //ColumnLayout.prototype.addItem = function(item) {
  58. // qDebug("ColumnLayout.prototype.addItem:" + item);
  59. // //var itemList = this.property("ItemList");
  60. // //if (typeof(itemList)=="undefined" || itemList.length===0) {
  61. // if (this.itemList.length===0) {
  62. // // first item:
  63. // //this.setProperty("ItemList", new Array(item));
  64. // //this.setProperty("ItemList", [item]);
  65. // this.itemList = [item];
  66. // return;
  67. // }
  68. // // next item:
  69. // // keep sorted:
  70. // var so = ColumnLayout.getAccumulatedSortOrder(item, this.parent().objectName);
  71. // if (so!==0) {
  72. // for (var i=0; i<this.itemList.length; ++i) {
  73. // if (typeof(this.itemList[i].property("SortOrder"))!="number") {
  74. // continue;
  75. // }
  76. // var so2 = ColumnLayout.getAccumulatedSortOrder(this.itemList[i], this.parent().objectName);
  77. // if (isNull(so2)) {
  78. // continue;
  79. // }
  80. // if (so2>so) {
  81. // this.itemList.splice(i, 0, item);
  82. // //this.setProperty("ItemList", itemList);
  83. // return;
  84. // }
  85. // }
  86. // }
  87. // this.itemList.push(item);
  88. // //this.setProperty("ItemList", itemList);
  89. //};
  90. //ColumnLayout.getAccumulatedSortOrder = function(item, objectName) {
  91. // return ColumnLayout.getSortOrder(item, objectName) + ColumnLayout.getGroupSortOrder(item, objectName)*100000;
  92. //};
  93. //ColumnLayout.getSortOrder = function(item, objectName) {
  94. // var n = "SortOrderOverride" + objectName;
  95. // if (typeof(item.property(n))=="number") {
  96. // return item.property(n);
  97. // }
  98. // if (typeof(item.property("SortOrder"))=="number") {
  99. // return item.property("SortOrder");
  100. // }
  101. // return 0;
  102. //};
  103. //ColumnLayout.getGroupSortOrder = function(item, objectName) {
  104. // var n = "GroupSortOrderOverride" + objectName;
  105. // if (typeof(item.property(n))=="number") {
  106. // return item.property(n);
  107. // }
  108. // if (typeof(item.property("GroupSortOrder"))=="number") {
  109. // return item.property("GroupSortOrder");
  110. // }
  111. // return 0;
  112. //};
  113. //ColumnLayout.prototype.minimumSize = function() {
  114. // //qDebug("010");
  115. // return this.sizeHint();
  116. //};
  117. //ColumnLayout.prototype.sizeHint = function() {
  118. // //qDebug("020");
  119. // if (isNull(this.sHint)) {
  120. // return new QSize(0,0);
  121. // }
  122. // this.setGeometry();
  123. // return this.sHint;
  124. //};
  125. //ColumnLayout.prototype.setGeometry = function(rect) {
  126. // qDebug("030");
  127. // var dbg = false;
  128. // if (this.parent().objectName==="MainToolsPanel") {
  129. // dbg = true;
  130. // }
  131. // //var itemList = this.property("ItemList");
  132. //// if (typeof(itemList)=="undefined") {
  133. //// return;
  134. //// }
  135. // var columns = RSettings.getIntValue("CadToolBar/Columns", 2);
  136. // var width = this.parentWidget().width;
  137. // var height = this.parentWidget().height;
  138. // var verticalWhenFloating = RSettings.getBoolValue("CadToolBar/VerticalWhenFloating", false);
  139. // var horizontal = this.toolBar.orientation===Qt.Horizontal;
  140. // if (this.toolBar.floating && verticalWhenFloating) {
  141. // horizontal = false;
  142. // }
  143. // var iconSize = RSettings.getIntValue("CadToolBar/IconSize", 32);
  144. // if (this.property("sHintColumns")===columns &&
  145. // this.property("sHintWidth")===width &&
  146. // this.property("sHintHeight")===height &&
  147. // this.property("sHintVerticalWhenFloating")===verticalWhenFloating &&
  148. // this.property("sHintHorizontal")===horizontal &&
  149. // this.property("sHintIconSize")===iconSize) {
  150. // return this.sHint;
  151. // }
  152. // var w = (horizontal && this.toolBar.movable) ? 2 : 0;
  153. // var h = (!horizontal && this.toolBar.movable) ? 2 : 0;
  154. // var buttonSize = iconSize * 1.25;
  155. // var c=0;
  156. // var groupOrder=-1;
  157. // //if (dbg) qDebug("===============");
  158. // //if (dbg) qDebug(itemList);
  159. // for (var i=0; i<this.itemList.length; ++i) {
  160. // if (isOfType(this.itemList[i], QToolButton)) {
  161. // this.itemList[i].iconSize = new QSize(iconSize, iconSize);
  162. // if (this.itemList[i].defaultAction().visible===false) {
  163. // this.itemList[i].visible = false;
  164. // continue;
  165. // }
  166. // }
  167. // // back button at the top or left:
  168. // if (this.itemList[i].objectName === "BackButton") {
  169. // if (horizontal) {
  170. // this.itemList[i].setGeometry(0,0, buttonSize*0.75,height);
  171. // w+=buttonSize*0.75 + 8;
  172. // h=0;
  173. // }
  174. // else {
  175. // this.itemList[i].setGeometry(0,0, width,buttonSize*0.75);
  176. // h+=buttonSize*0.75 + 8;
  177. // w=0;
  178. // }
  179. //// if (dbg) qDebug("BackButton");
  180. // continue;
  181. // }
  182. // // separator:
  183. // if (isFunction(this.itemList[i].isSeparator) && this.itemList[i].isSeparator()) {
  184. //// if (dbg) qDebug("Separator");
  185. // if (horizontal) {
  186. // if (h===0) {
  187. // w+=8;
  188. // }
  189. // else {
  190. // w+=buttonSize+8;
  191. // h = 0;
  192. // c = 0;
  193. // }
  194. // }
  195. // else {
  196. // if (w===0) {
  197. // h+=8;
  198. // }
  199. // else {
  200. // h+=buttonSize+8;
  201. // w = 0;
  202. // c = 0;
  203. // }
  204. // }
  205. // continue;
  206. // }
  207. //// if (dbg) qDebug("Button");
  208. // this.itemList[i].setGeometry(w,h, buttonSize,buttonSize);
  209. // if (horizontal) {
  210. // h+=buttonSize;
  211. // c++;
  212. // //if (y+buttonSize>height) {
  213. // if (c>=columns) {
  214. // h = 0;
  215. // c = 0;
  216. // w+=buttonSize;
  217. // }
  218. // }
  219. // else {
  220. // w+=buttonSize;
  221. // c++;
  222. // //if (x+buttonSize>width) {
  223. // if (c>=columns) {
  224. // w = 0;
  225. // c = 0;
  226. // h+=buttonSize;
  227. // }
  228. // }
  229. // }
  230. // if (horizontal) {
  231. // h+=buttonSize;
  232. // }
  233. // else {
  234. // w+=buttonSize;
  235. // }
  236. // if (horizontal) {
  237. // this.setProperty("sHint", new QSize(w, buttonSize*columns));
  238. // }
  239. // else {
  240. // this.setProperty("sHint", new QSize(buttonSize*columns, h));
  241. // }
  242. // // store settings used for calculation, so we don't have to calculate
  243. // // size again if not necessary:
  244. // this.setProperty("sHintColumns", columns);
  245. // this.setProperty("sHintWidth", width);
  246. // this.setProperty("sHintHeight", height);
  247. // this.setProperty("sHintVerticalWhenFloating", verticalWhenFloating);
  248. // this.setProperty("sHintHorizontal", horizontal);
  249. // this.setProperty("sHintIconSize", iconSize);
  250. //};
  251. ////ColumnLayout.prototype.count = function(index) {
  252. //// qDebug("ColumnLayout.prototype.count...");
  253. //// qDebug("ColumnLayout.prototype.count: DONE");
  254. //// return 0;
  255. ////};
  256. //ColumnLayout.prototype.itemAt = function(index) {
  257. // qDebug("040");
  258. // //var itemList = this.property("ItemList");
  259. // //if (typeof(itemList)=="undefined" || index>=itemList.length) {
  260. // if (index>=this.itemList.length) {
  261. // qDebug("040a: DONE");
  262. // return undefined;
  263. // }
  264. // qDebug("040b: DONE");
  265. // qDebug("itemList[index]:" + this.itemList[index]);
  266. // return this.itemList[index];
  267. //};