2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2010-02-16 19:07:59 +02:00
|
|
|
**
|
2016-01-15 14:59:14 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2010-02-16 19:07:59 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2010-02-16 19:07:59 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:59:14 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2010-02-16 19:07:59 +02:00
|
|
|
**
|
2015-09-18 11:34:48 +02:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
2016-01-15 14:59:14 +01:00
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2010-02-16 19:07:59 +02:00
|
|
|
|
2020-07-03 16:17:54 +02:00
|
|
|
import QtQuick 2.15
|
|
|
|
|
import QtQuick.Layouts 1.15
|
2017-03-07 16:06:02 +01:00
|
|
|
import QtQuickDesignerTheme 1.0
|
2020-07-03 16:17:54 +02:00
|
|
|
import HelperWidgets 2.0
|
2021-02-04 16:18:45 +02:00
|
|
|
import StudioControls 1.0 as StudioControls
|
2020-07-03 16:17:54 +02:00
|
|
|
import StudioTheme 1.0 as StudioTheme
|
2010-02-16 17:24:18 +02:00
|
|
|
|
2010-03-10 12:45:49 +02:00
|
|
|
/* The view displaying the item grid.
|
|
|
|
|
|
2010-03-18 13:17:24 +02:00
|
|
|
The following Qml context properties have to be set:
|
2021-02-13 01:27:20 +02:00
|
|
|
- ItemLibraryModel itemLibraryModel
|
|
|
|
|
- int itemLibraryIconWidth
|
|
|
|
|
- int itemLibraryIconHeight
|
|
|
|
|
- ItemLibraryWidget rootView
|
|
|
|
|
- QColor highlightColor
|
2010-03-18 13:17:24 +02:00
|
|
|
|
2021-02-04 16:18:45 +02:00
|
|
|
itemLibraryModel structure:
|
|
|
|
|
|
|
|
|
|
itemLibraryModel [
|
|
|
|
|
ItemLibraryImport {
|
|
|
|
|
string importName
|
|
|
|
|
string importUrl
|
|
|
|
|
bool importVisible
|
|
|
|
|
bool importUsed
|
|
|
|
|
bool importExpanded
|
|
|
|
|
|
|
|
|
|
list categoryModel [
|
|
|
|
|
ItemLibraryCategory {
|
|
|
|
|
string categoryName
|
|
|
|
|
bool categoryVisible
|
|
|
|
|
bool categoryExpanded
|
|
|
|
|
|
|
|
|
|
list itemModel [
|
|
|
|
|
ItemLibraryItem {
|
|
|
|
|
string itemName
|
|
|
|
|
string itemLibraryIconPath
|
|
|
|
|
bool itemVisible
|
|
|
|
|
string componentPath
|
|
|
|
|
var itemLibraryEntry
|
|
|
|
|
},
|
|
|
|
|
... more items
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
... more categories
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
... more imports
|
2010-03-18 13:17:24 +02:00
|
|
|
]
|
2010-03-10 12:45:49 +02:00
|
|
|
*/
|
|
|
|
|
|
2014-06-19 17:53:25 +02:00
|
|
|
ScrollView {
|
|
|
|
|
id: itemsView
|
2013-08-06 16:45:59 +02:00
|
|
|
|
2021-02-04 16:18:45 +02:00
|
|
|
property string importToRemove: ""
|
2021-03-02 17:15:59 +02:00
|
|
|
property string importToAdd: ""
|
2021-03-31 13:48:52 +03:00
|
|
|
property var currentItem: null
|
|
|
|
|
property var currentCategory: null
|
|
|
|
|
property var currentImport: null
|
2021-02-04 16:18:45 +02:00
|
|
|
|
|
|
|
|
// called from C++ to close context menu on focus out
|
|
|
|
|
function closeContextMenu()
|
|
|
|
|
{
|
2021-03-31 13:48:52 +03:00
|
|
|
moduleContextMenu.close()
|
2021-03-02 17:15:59 +02:00
|
|
|
itemContextMenu.close()
|
2021-02-04 16:18:45 +02:00
|
|
|
}
|
|
|
|
|
|
2021-04-23 14:04:49 +03:00
|
|
|
function showImportCategories()
|
|
|
|
|
{
|
|
|
|
|
currentImport.importCatVisibleState = true
|
|
|
|
|
if (!itemLibraryModel.getIsAnyCategoryHidden())
|
|
|
|
|
itemLibraryModel.isAnyCategoryHidden = false
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 13:31:42 +02:00
|
|
|
onContentHeightChanged: {
|
|
|
|
|
var maxPosition = Math.max(contentHeight - height, 0)
|
|
|
|
|
if (contentY > maxPosition)
|
|
|
|
|
contentY = maxPosition
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-19 17:53:25 +02:00
|
|
|
Item {
|
|
|
|
|
id: styleConstants
|
2016-07-01 14:35:40 +02:00
|
|
|
property int textWidth: 58
|
2018-04-09 16:26:25 +02:00
|
|
|
property int textHeight: Theme.smallFontPixelSize() * 2
|
2013-08-06 16:45:59 +02:00
|
|
|
|
2016-07-01 14:35:40 +02:00
|
|
|
property int cellHorizontalMargin: 1
|
|
|
|
|
property int cellVerticalSpacing: 2
|
|
|
|
|
property int cellVerticalMargin: 4
|
2013-08-06 16:45:59 +02:00
|
|
|
|
2014-06-19 17:53:25 +02:00
|
|
|
// the following depend on the actual shape of the item delegate
|
|
|
|
|
property int cellWidth: textWidth + 2 * cellHorizontalMargin
|
|
|
|
|
property int cellHeight: itemLibraryIconHeight + textHeight +
|
2021-02-04 16:18:45 +02:00
|
|
|
2 * cellVerticalMargin + cellVerticalSpacing
|
|
|
|
|
|
|
|
|
|
StudioControls.Menu {
|
2021-03-31 13:48:52 +03:00
|
|
|
id: moduleContextMenu
|
2021-02-04 16:18:45 +02:00
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
2021-02-13 01:27:20 +02:00
|
|
|
text: qsTr("Remove Module")
|
2021-03-31 13:48:52 +03:00
|
|
|
visible: currentCategory === null
|
|
|
|
|
height: visible ? implicitHeight : 0
|
2021-03-02 17:15:59 +02:00
|
|
|
enabled: importToRemove !== ""
|
2021-04-23 14:04:49 +03:00
|
|
|
onTriggered: {
|
|
|
|
|
showImportCategories()
|
|
|
|
|
rootView.removeImport(importToRemove)
|
|
|
|
|
}
|
2021-02-04 16:18:45 +02:00
|
|
|
}
|
2021-02-13 01:27:20 +02:00
|
|
|
|
2021-03-31 13:48:52 +03:00
|
|
|
StudioControls.MenuSeparator {
|
|
|
|
|
visible: currentCategory === null
|
|
|
|
|
height: StudioTheme.Values.border
|
|
|
|
|
}
|
2021-02-13 01:27:20 +02:00
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
|
text: qsTr("Expand All")
|
2021-03-31 13:48:52 +03:00
|
|
|
visible: currentCategory === null
|
|
|
|
|
height: visible ? implicitHeight : 0
|
2021-02-13 01:27:20 +02:00
|
|
|
onTriggered: itemLibraryModel.expandAll()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
|
text: qsTr("Collapse All")
|
2021-03-31 13:48:52 +03:00
|
|
|
visible: currentCategory === null
|
|
|
|
|
height: visible ? implicitHeight : 0
|
2021-02-13 01:27:20 +02:00
|
|
|
onTriggered: itemLibraryModel.collapseAll()
|
|
|
|
|
}
|
2021-03-31 13:48:52 +03:00
|
|
|
|
|
|
|
|
StudioControls.MenuSeparator {
|
|
|
|
|
visible: currentCategory === null
|
|
|
|
|
height: StudioTheme.Values.border
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
|
text: qsTr("Hide Category")
|
|
|
|
|
visible: currentCategory
|
|
|
|
|
height: visible ? implicitHeight : 0
|
|
|
|
|
onTriggered: {
|
|
|
|
|
itemLibraryModel.isAnyCategoryHidden = true
|
|
|
|
|
currentCategory.categoryVisible = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StudioControls.MenuSeparator {
|
|
|
|
|
visible: currentCategory
|
|
|
|
|
height: StudioTheme.Values.border
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
|
text: qsTr("Show Module Hidden Categories")
|
|
|
|
|
enabled: currentImport && !currentImport.importCatVisibleState
|
2021-04-23 14:04:49 +03:00
|
|
|
onTriggered: showImportCategories()
|
2021-03-31 13:48:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
|
text: qsTr("Show All Hidden Categories")
|
|
|
|
|
enabled: itemLibraryModel.isAnyCategoryHidden
|
|
|
|
|
onTriggered: {
|
|
|
|
|
itemLibraryModel.isAnyCategoryHidden = false
|
|
|
|
|
itemLibraryModel.showHiddenCategories()
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-02-04 16:18:45 +02:00
|
|
|
}
|
2021-03-02 17:15:59 +02:00
|
|
|
|
|
|
|
|
StudioControls.Menu {
|
|
|
|
|
id: itemContextMenu
|
|
|
|
|
// Workaround for menu item implicit width not properly propagating to menu
|
|
|
|
|
width: importMenuItem.implicitWidth
|
|
|
|
|
|
|
|
|
|
StudioControls.MenuItem {
|
|
|
|
|
id: importMenuItem
|
2021-03-22 18:18:59 +02:00
|
|
|
text: qsTr("Add Module: ") + importToAdd
|
2021-03-22 21:32:47 +02:00
|
|
|
enabled: importToAdd !== ""
|
|
|
|
|
onTriggered: rootView.addImportForItem(importToAdd)
|
2021-03-02 17:15:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
2013-08-06 16:45:59 +02:00
|
|
|
}
|
|
|
|
|
|
2020-07-03 16:17:54 +02:00
|
|
|
Column {
|
2021-02-04 16:18:45 +02:00
|
|
|
spacing: 2
|
2020-07-03 16:17:54 +02:00
|
|
|
Repeater {
|
|
|
|
|
model: itemLibraryModel // to be set in Qml context
|
|
|
|
|
delegate: Section {
|
|
|
|
|
width: itemsView.width -
|
2021-02-04 16:18:45 +02:00
|
|
|
(itemsView.verticalScrollBarVisible ? itemsView.verticalThickness : 0)
|
|
|
|
|
caption: importName
|
|
|
|
|
visible: importVisible
|
|
|
|
|
sectionHeight: 30
|
|
|
|
|
sectionFontSize: 15
|
|
|
|
|
showArrow: categoryModel.rowCount() > 0
|
2021-03-16 00:08:36 +02:00
|
|
|
labelColor: importUnimported ? StudioTheme.Values.themeUnimportedModuleColor
|
|
|
|
|
: StudioTheme.Values.themeTextColor
|
2021-02-04 16:18:45 +02:00
|
|
|
leftPadding: 0
|
|
|
|
|
rightPadding: 0
|
|
|
|
|
expanded: importExpanded
|
2021-02-22 16:53:30 +02:00
|
|
|
expandOnClick: false
|
2021-08-04 20:21:31 +02:00
|
|
|
useDefaulContextMenu: false
|
|
|
|
|
|
2021-02-18 21:14:23 +02:00
|
|
|
onToggleExpand: {
|
|
|
|
|
if (categoryModel.rowCount() > 0)
|
|
|
|
|
importExpanded = !importExpanded
|
|
|
|
|
}
|
2021-02-04 16:18:45 +02:00
|
|
|
onShowContextMenu: {
|
2021-03-02 17:15:59 +02:00
|
|
|
importToRemove = importRemovable ? importUrl : ""
|
2021-03-31 13:48:52 +03:00
|
|
|
currentImport = model
|
|
|
|
|
currentCategory = null
|
2021-05-18 17:25:09 +03:00
|
|
|
if (!rootView.isSearchActive())
|
|
|
|
|
moduleContextMenu.popup()
|
2021-02-04 16:18:45 +02:00
|
|
|
}
|
2020-07-03 16:17:54 +02:00
|
|
|
|
2021-02-04 16:18:45 +02:00
|
|
|
Column {
|
|
|
|
|
spacing: 2
|
2021-03-31 13:48:52 +03:00
|
|
|
property var currentImportModel: model // allows accessing the import model from inside the category section
|
2020-07-03 16:17:54 +02:00
|
|
|
Repeater {
|
2021-02-04 16:18:45 +02:00
|
|
|
model: categoryModel
|
|
|
|
|
delegate: Section {
|
|
|
|
|
width: itemsView.width -
|
|
|
|
|
(itemsView.verticalScrollBarVisible ? itemsView.verticalThickness : 0)
|
|
|
|
|
sectionBackgroundColor: "transparent"
|
|
|
|
|
showTopSeparator: index > 0
|
|
|
|
|
hideHeader: categoryModel.rowCount() <= 1
|
|
|
|
|
leftPadding: 0
|
|
|
|
|
rightPadding: 0
|
2021-03-19 18:47:22 +02:00
|
|
|
addTopPadding: categoryModel.rowCount() > 1
|
|
|
|
|
addBottomPadding: index != categoryModel.rowCount() - 1
|
2021-02-04 16:18:45 +02:00
|
|
|
caption: categoryName + " (" + itemModel.rowCount() + ")"
|
|
|
|
|
visible: categoryVisible
|
|
|
|
|
expanded: categoryExpanded
|
2021-02-22 16:53:30 +02:00
|
|
|
expandOnClick: false
|
2021-02-13 01:27:20 +02:00
|
|
|
onToggleExpand: categoryExpanded = !categoryExpanded
|
2021-03-31 13:48:52 +03:00
|
|
|
onShowContextMenu: {
|
|
|
|
|
currentCategory = model
|
|
|
|
|
currentImport = parent.currentImportModel
|
2021-05-18 17:25:09 +03:00
|
|
|
if (!rootView.isSearchActive())
|
|
|
|
|
moduleContextMenu.popup()
|
2021-03-31 13:48:52 +03:00
|
|
|
}
|
2021-02-04 16:18:45 +02:00
|
|
|
|
|
|
|
|
Grid {
|
|
|
|
|
id: itemGrid
|
|
|
|
|
|
2021-03-02 13:35:07 +01:00
|
|
|
property real actualWidth: parent.width - itemGrid.leftPadding -itemGrid.rightPadding
|
|
|
|
|
property int flexibleWidth: (itemGrid.actualWidth / columns) - styleConstants.cellWidth
|
|
|
|
|
|
|
|
|
|
leftPadding: 6
|
|
|
|
|
rightPadding: 6
|
|
|
|
|
columns: itemGrid.actualWidth / styleConstants.cellWidth
|
2021-02-04 16:18:45 +02:00
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
|
model: itemModel
|
|
|
|
|
delegate: ItemDelegate {
|
|
|
|
|
visible: itemVisible
|
2021-03-16 00:08:36 +02:00
|
|
|
textColor: importUnimported ? StudioTheme.Values.themeUnimportedModuleColor
|
|
|
|
|
: StudioTheme.Values.themeTextColor
|
2021-02-04 16:18:45 +02:00
|
|
|
width: styleConstants.cellWidth + itemGrid.flexibleWidth
|
|
|
|
|
height: styleConstants.cellHeight
|
2021-03-02 17:15:59 +02:00
|
|
|
onShowContextMenu: {
|
|
|
|
|
if (!itemUsable) {
|
|
|
|
|
importToAdd = itemRequiredImport
|
2021-03-22 21:32:47 +02:00
|
|
|
itemContextMenu.popup()
|
2021-03-02 17:15:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
2021-02-04 16:18:45 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-06-19 17:53:25 +02:00
|
|
|
}
|
|
|
|
|
}
|
2013-11-14 11:15:44 +01:00
|
|
|
}
|
|
|
|
|
}
|
2013-08-06 16:45:59 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|