TabBar.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. function TabBar() {
  20. }
  21. TabBar.getPreferencesCategory = function() {
  22. return [ qsTr("Widgets"), qsTr("Tab Bar") ];
  23. };
  24. TabBar.applyPreferences = function(doc, mdiChild) {
  25. var appWin = RMainWindowQt.getMainWindow();
  26. var mdiArea = appWin.getMdiArea();
  27. if (isNull(mdiArea)) {
  28. return;
  29. }
  30. //if (RSettings.getBoolValue("TabBar/ShowTabBar", true)===false) {
  31. // mdiArea.viewMode = QMdiArea.SubWindowView;
  32. // if (!isNull(mdiChild)) {
  33. // mdiChild.showMaximized();
  34. // }
  35. //}
  36. //else {
  37. // mdiArea.viewMode = QMdiArea.TabbedView;
  38. // TabBar.initTabBar();
  39. //}
  40. };
  41. TabBar.init = function(basePath) {
  42. var appWin = RMainWindowQt.getMainWindow();
  43. var mdiArea = appWin.getMdiArea();
  44. if (isNull(mdiArea)) {
  45. return;
  46. }
  47. mdiArea.documentMode = true;
  48. //if (RSettings.getBoolValue("TabBar/ShowTabBar", true)===false) {
  49. mdiArea.viewMode = QMdiArea.SubWindowView;
  50. //}
  51. //else {
  52. // mdiArea.viewMode = QMdiArea.TabbedView;
  53. // TabBar.initTabBar();
  54. //}
  55. };
  56. TabBar.initTabBar = function() {
  57. var appWin = RMainWindowQt.getMainWindow();
  58. var tabBar = appWin.getTabBar();
  59. if (isNull(tabBar)) {
  60. return;
  61. }
  62. tabBar.elideMode = Qt.ElideRight;
  63. tabBar.tabsClosable = true;
  64. tabBar.usesScrollButtons = true;
  65. tabBar.contextMenuPolicy = Qt.NoContextMenu;
  66. // somewhat buggy:
  67. //tabBar.movable = true;
  68. if (RSettings.getQtVersionString().startsWith("4.7.")) {
  69. // starting with Qt 4.8, this is no longer necessary:
  70. tabBar.tabCloseRequested.connect(function(tabIndex) {
  71. tabBar.setCurrentIndex(tabIndex);
  72. var closeEvent = new RCloseCurrentEvent();
  73. QCoreApplication.postEvent(appWin, closeEvent);
  74. });
  75. }
  76. if (RSettings.getBoolValue("TabBar/ShowAddTabButton", false)) {
  77. var mdiArea = appWin.getMdiArea();
  78. if (!isNull(mdiArea)) {
  79. var button = mdiArea.getAddTabButton();
  80. button.styleSheet = "border:0px";
  81. var fileNewAction = RGuiAction.getByScriptFile("scripts/File/NewFile/NewFile.js");
  82. //action.icon = new QIcon(autoPath("scripts/Widgets/TabBar/AddTab.svg"));
  83. //button.icon = new QIcon(autoPath("scripts/Widgets/TabBar/AddTab.svg"));
  84. var action = new RGuiAction(fileNewAction.text, RMainWindowQt.getMainWindow());
  85. action.setProperty("Configurable", false);
  86. action.setRequiresDocument(false);
  87. action.setScriptFile(fileNewAction.getScriptFile(), true);
  88. action.setIcon(autoPath("scripts/Widgets/TabBar/AddTab.svg"));
  89. action.setNoState();
  90. button.setDefaultAction(action);
  91. }
  92. }
  93. };