<commit_before>/*
  Q Light Controller Plus
  Fixture2DItem.qml

  Copyright (c) <NAME>

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0.txt

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/

import QtQuick 2.2

import "CanvasDrawFunctions.js" as DrawFuncs
import "."

Rectangle
{
    id: fixtureItem
    x: (gridCellSize * mmXPos) / gridUnits
    y: (gridCellSize * mmYPos) / gridUnits
    z: 2
    width: (gridCellSize * mmWidth) / gridUnits
    height: (gridCellSize * mmHeight) / gridUnits

    color: "#2A2A2A"
    border.width: isSelected ? 2 : 1
    border.color: isSelected ? (isDragging ? "#00FF00" : UISettings.selection) : (isDragging ? "#00FF00" : "#AAA")

    Drag.active: fxMouseArea.drag.active

    property int fixtureID: fixtureManager.invalidFixture()
    property string fixtureName: ""

    property real gridCellSize: parent ? parent.cellSize : 100
    property int gridUnits: parent ? parent.gridUnits : 1000

    property real mmXPos: 0
    property real mmYPos: 0
    property real mmHeight: 300
    property real mmWidth: 300

    property int headsNumber: 1
    property real headSide: 10
    property int headColumns: 1
    property int headRows: 1

    property int panMaxDegrees: 0
    property int tiltMaxDegrees: 0

    property bool isSelected: false
    property bool isDragging: false
    property bool showLabel: false

    onWidthChanged: calculateHeadSize();
    onHeightChanged: calculateHeadSize();
    onHeadsNumberChanged: calculateHeadSize();

    function calculateHeadSize()
    {
        var areaSqrt = Math.sqrt((width * height) / headsNumber)
        var columns = parseInt((width / areaSqrt) + 0.5)
        var rows = parseInt((height / areaSqrt) + 0.5)

        // dirty workaround to correctly display right columns on one row
        if (rows === 1) columns = headsNumber
        if (columns === 1) rows = headsNumber

        if (columns > headsNumber)
            columns = headsNumber

        if (rows < 1) rows = 1
        if (columns < 1) columns = 1

        var cellWidth = width / columns
        var cellHeight = height / rows
        headSide = Math.min(cellWidth, cellHeight) - 1
        headColumns = columns
        headRows = rows
    }

    function setHeadIntensity(headIndex, intensity)<commit_msg>qmlui/2Dview: improved head rendering to avoid overflowing<commit_after>/*
  Q Light Controller Plus
  Fixture2DItem.qml

  Copyright (c) <NAME>

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0.txt

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/

import QtQuick 2.2

import "CanvasDrawFunctions.js" as DrawFuncs
import "."

Rectangle
{
    id: fixtureItem
    x: (gridCellSize * mmXPos) / gridUnits
    y: (gridCellSize * mmYPos) / gridUnits
    z: 2
    width: (gridCellSize * mmWidth) / gridUnits
    height: (gridCellSize * mmHeight) / gridUnits

    color: "#2A2A2A"
    border.width: isSelected ? 2 : 1
    border.color: isSelected ? (isDragging ? "#00FF00" : UISettings.selection) : (isDragging ? "#00FF00" : "#AAA")

    Drag.active: fxMouseArea.drag.active

    property int fixtureID: fixtureManager.invalidFixture()
    property string fixtureName: ""

    property real gridCellSize: parent ? parent.cellSize : 100
    property int gridUnits: parent ? parent.gridUnits : 1000

    property real mmXPos: 0
    property real mmYPos: 0
    property real mmHeight: 300
    property real mmWidth: 300

    property int headsNumber: 1
    property real headSide: 10
    property int headColumns: 1
    property int headRows: 1

    property int panMaxDegrees: 0
    property int tiltMaxDegrees: 0

    property bool isSelected: false
    property bool isDragging: false
    property bool showLabel: false

    onWidthChanged: calculateHeadSize();
    onHeightChanged: calculateHeadSize();
    onHeadsNumberChanged: calculateHeadSize();

    function calculateHeadSize()
    {
        var areaSqrt = Math.sqrt((width * height) / headsNumber)
        var columns = parseInt((width / areaSqrt) + 0.5)
        var rows = parseInt((height / areaSqrt) + 0.5)

        // dirty workaround to correctly display right columns on one row
        if (rows === 1) columns = headsNumber
        if (columns === 1) rows = headsNumber

        if (columns > headsNumber)
            columns = headsNumber

        if (rows < 1) rows = 1
        if (columns < 1) columns = 1

        var cellWidth = width / columns
        var cellHeight = height / rows
        headSide = parseInt(Math.min(cellWidth, cellHeight))
        headColumns = columns
        headRows = rows
    }

    function setHeadIntensity(headIndex, intensity)
{'fraction_non_alphanumeric': 0.07717569786535304, 'fraction_numerical': 0.019704433497536946, 'mean_word_length': 2.975344452501813, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7311560', 'n_tokens_mistral': 1632, 'n_tokens_neox': 1522, 'n_words': 564}