/*
ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
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
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.
*/
#ifndef MCUCONF_H
#define MCUCONF_H
/*
* STM32F4xx drivers configuration.
* The following settings override the default settings present in
* the various device driver implementation headers.
* Note that the settings for each driver only have effect if the whole
* driver is enabled in halconf.h.
*
* IRQ priorities:
* 15...0 Lowest...Highest.
*
* DMA priorities:
* 0...3 Lowest...Highest.
*/
#define STM32F4xx_MCUCONF
/*
* HAL driver system settings.
*/
#define STM32_NO_INIT FALSE
#define STM32_HSI_ENABLED TRUE
#define STM32_LSI_ENABLED TRUE
#define STM32_HSE_ENABLED TRUE
#define STM32_LSE_ENABLED FALSE
#define STM32_CLOCK48_REQUIRED TRUE
#define STM32_SW STM32_SW_PLL
#define STM32_PLLSRC STM32_PLLSRC_HSE
#define STM32_PLLM_VALUE 8
#define STM32_PLLN_VALUE 336
#define STM32_PLLP_VALUE 2
#define STM32_PLLQ_VALUE 7
#define STM32_HPRE STM32_HPRE_DIV1
#define STM32_PPRE1 STM32_PPRE1_DIV4
#define STM32_PPRE2 STM32_PPRE2_DIV2
#define STM32_RTCSEL STM32_RTCSEL_LSI
#define STM32_RTCPRE_VALUE 8
#define STM32_MCO1SEL STM32_MCO1SEL_HSI
#define STM32_MCO1PRE STM32_MCO1PRE_DIV1
#define STM32_MCO2SEL STM32_MCO2SEL_SYSCLK
#define STM32_MCO2PRE STM32_MCO2PRE_DIV5
#define STM32_I2SSRC STM32_I2SSRC_CKIN
#define STM32_PLLI2SN_VALUE 192
#define STM32_PLLI2SR_VALUE 5
#define STM32_PVD_ENABLE FALSE
#define STM32_PLS STM32_PLS_LEV0
#define STM32_BKPRAM_ENABLE FALSE
/*
* ADC driver system settings.
*/
#define STM32_ADC_ADCPRE ADC_CCR_ADCPRE_DIV4
#define STM32_ADC_USE_ADC1 TRUE
#define STM32_ADC_USE_ADC2 TRUE
#define STM32_ADC_USE_ADC3 TRUE
#define STM32_ADC_ADC1_DMA_STREAM STM32_DMA_STREAM_ID(2, 4)
#define STM32_ADC_ADC2_DMA_STREAM STM32_DMA_STREAM_ID(2, 2)
#define STM32_ADC_ADC3_DMA_STREAM STM32_DMA_STREAM_ID(2, 1)
#define STM32_ADC_ADC1_DMA_PRIORITY 2
#define STM32_ADC_ADC2_DMA_PRIORITY 2
#define STM32_ADC_ADC3_DMA_PRIORITY 2
#define STM32_ADC_IRQ_PRIORITY 6
#define STM32_ADC_ADC1_DMA_IRQ_PRIORITY 6
#define STM32_ADC_ADC2_DMA_IRQ_PRIORITY 6
#define STM32_ADC_ADC3_DMA_IRQ_PRIORITY 6
/*
* CAN driver system settings.
*/
#define STM32_CAN_USE_CAN1 FALSE
#define STM32_CAN_USE_CAN2 FALSE
#define STM32_CAN_CAN1_IRQ_PRIORITY 11
#define STM32_CAN_CAN2_IRQ_PRIORITY 11
/*
* DAC driver system settings.
*/
#define STM32_DAC_DUAL_MODE FALSE
#define STM32_DAC_USE_DAC1_CH1 FALSE
#define STM32_DAC_USE_DAC1_CH2 FALSE
#define STM32_DAC_DAC1_CH1_IRQ_PRIORITY 10
#define STM32_DAC_DAC1_CH2_IRQ_PRIORITY 10
#define STM32_DAC_DAC1_CH1_DMA_PRIORITY 2
#define STM32_DAC_DAC1_CH2_DMA_PRIORITY 2
#define STM32_DAC_DAC1_CH1_DMA_STREAM STM32_DMA_STREAM_ID(1, 5)
#define STM32_DAC_DAC1_CH2_DMA_STREAM STM32_DMA_STREAM_ID(1, 6)
/*
* EXT driver system settings.
*/
#define STM32_EXT_EXTI0_IRQ_PRIORITY 6
#define STM32_EXT_EXTI1_IRQ_PRIORITY 6
#define STM32_EXT_EXTI2_IRQ_PRIORITY 6
#define STM32_EXT_EXTI3_IRQ_PRIORITY 6
#define STM32_EXT_EXTI4_IRQ_PRIORITY 6
#define STM32_EXT_EXTI5_9_IRQ_PRIORITY 6
#define STM32_EXT_EXTI10_15_IRQ_PRIORITY 6
#define STM32_EXT_EXTI16_IRQ_PRIORITY 6
#define STM32_EXT_EXTI17_IRQ_PRIORITY 15
#define STM32_EXT_EXTI18_IRQ_PRIORITY 6
#define STM32_EXT_EXTI19_IRQ_PRIORITY 6
#define STM32_EXT_EXTI20_IRQ_PRIORITY 6
#define STM32_EXT_EXTI21_IRQ_PRIORITY 15
#define STM32_EXT_EXTI22_IRQ_PRIORITY 15
/*
* GPT driver system settings.
*/
#define STM32_GPT_USE_TIM1 FALSE
#define STM32_GPT_USE_TIM2 FALSE
#define STM32_GPT_USE_TIM3 FALSE
#define STM32_GPT_USE_TIM4 FALSE
#define STM32_GPT_USE_TIM5 FALSE
#define STM32_GPT_USE_TIM6 FALSE
#define STM32_GPT_USE_TIM7 FALSE
#define STM32_GPT_USE_TIM8 FALSE
#define STM32_GPT_USE_TIM9 FALSE
#define STM32_GPT_USE_TIM11 FALSE
#define STM32_GPT_USE_TIM12 FALSE
#define STM32_GPT_USE_TIM14 FALSE
#define STM32_GPT_TIM1_IRQ_PRIORITY 7
#define STM32_GPT_TIM2_IRQ_PRIORITY 7
#define STM32_GPT_TIM3_IRQ_PRIORITY 7
#define STM32_GPT_TIM4_IRQ_PRIORITY 7
#define STM32_GPT_TIM5_IRQ_PRIORITY 7
#define STM32_GPT_TIM6_IRQ_PRIORITY 7
#define STM32_GPT_TIM7_IRQ_PRIORITY 7
#define STM32_GPT_TIM8_IRQ_PRIORITY 7
#define STM32_GPT_TIM9_IRQ_PRIORITY 7
#define STM32_GPT_TIM11_IRQ_PRIORITY 7
#define STM32_GPT_TIM12_IRQ_PRIORITY 7
#define STM32_GPT_TIM14_IRQ_PRIORITY 7
/*
* I2C driver system settings.
*/
#define STM32_I2C_USE_I2C1 FALSE
#define STM32_I2C_USE_I2C2 FALSE
#define STM32_I2C_USE_I2C3 FALSE
#define STM32_I2C_BUSY_TIMEOUT 50
#define STM32_I2C_I2C1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0)
#define STM32_I2C_I2C1_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 6)
#define STM32_I2C_I2C2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2)
#define STM32_I2C_I2C2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7)
#define STM32_I2C_I2C3_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2)
#define STM32_I2C_I2C3_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
#define STM32_I2C_I2C1_IRQ_PRIORITY 5
#define STM32_I2C_I2C2_IRQ_PRIORITY 5
#define STM32_I2C_I2C3_IRQ_PRIORITY 5
#define STM32_I2C_I2C1_DMA_PRIORITY 3
#define STM32_I2C_I2C2_DMA_PRIORITY 3
#define STM32_I2C_I2C3_DMA_PRIORITY 3
#define STM32_I2C_DMA_ERROR_HOOK(i2cp) osalSysHalt("DMA failure")
/*
* I2S driver system settings.
*/
#define STM32_I2S_USE_SPI2 FALSE
#define STM32_I2S_USE_SPI3 FALSE
#define STM32_I2S_SPI2_IRQ_PRIORITY 10
#define STM32_I2S_SPI3_IRQ_PRIORITY 10
#define STM32_I2S_SPI2_DMA_PRIORITY 1
#define STM32_I2S_SPI3_DMA_PRIORITY 1
#define STM32_I2S_SPI2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)
#define STM32_I2S_SPI2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
#define STM32_I2S_SPI3_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0)
#define STM32_I2S_SPI3_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7)
#define STM32_I2S_DMA_ERROR_HOOK(i2sp) osalSysHalt("DMA failure")
/*
* ICU driver system settings.
*/
#define STM32_ICU_USE_TIM1 FALSE
#define STM32_ICU_USE_TIM2 FALSE
#define STM32_ICU_USE_TIM3 FALSE
#define STM32_ICU_USE_TIM4 FALSE
#define STM32_ICU_USE_TIM5 FALSE
#define STM32_ICU_USE_TIM8 FALSE
#define STM32_ICU_USE_TIM9 FALSE
#define STM32_ICU_TIM1_IRQ_PRIORITY 7
#define STM32_ICU_TIM2_IRQ_PRIORITY 7
#define STM32_ICU_TIM3_IRQ_PRIORITY 7
#define STM32_ICU_TIM4_IRQ_PRIORITY 7
#define STM32_ICU_TIM5_IRQ_PRIORITY 7
#define STM32_ICU_TIM8_IRQ_PRIORITY 7
#define STM32_ICU_TIM9_IRQ_PRIORITY 7
/*
* MAC driver system settings.
*/
#define STM32_MAC_TRANSMIT_BUFFERS 2
#define STM32_MAC_RECEIVE_BUFFERS 4
#define STM32_MAC_BUFFERS_SIZE 1522
#define STM32_MAC_PHY_TIMEOUT 100
#define STM32_MAC_ETH1_CHANGE_PHY_STATE TRUE
#define STM32_MAC_ETH1_IRQ_PRIORITY 13
#define STM32_MAC_IP_CHECKSUM_OFFLOAD 0
/*
* PWM driver system settings.
*/
#define STM32_PWM_USE_ADVANCED FALSE
#define STM32_PWM_USE_TIM1 FALSE
#define STM32_PWM_USE_TIM2 FALSE
#define STM32_PWM_USE_TIM3 FALSE
#define STM32_PWM_USE_TIM4 FALSE
#define STM32_PWM_USE_TIM5 FALSE
#define STM32_PWM_USE_TIM8 FALSE
#define STM32_PWM_USE_TIM9 FALSE
#define STM32_PWM_TIM1_IRQ_PRIORITY 7
#define STM32_PWM_TIM2_IRQ_PRIORITY 7
#define STM32_PWM_TIM3_IRQ_PRIORITY 7
#define STM32_PWM_TIM4_IRQ_PRIORITY 7
#define STM32_PWM_TIM5_IRQ_PRIORITY 7
#define STM32_PWM_TIM8_IRQ_PRIORITY 7
#define STM32_PWM_TIM9_IRQ_PRIORITY 7
/*
* SDC driver system settings.
*/
#define STM32_SDC_SDIO_DMA_PRIORITY 3
#define STM32_SDC_SDIO_IRQ_PRIORITY 9
#define STM32_SDC_WRITE_TIMEOUT_MS 250
#define STM32_SDC_READ_TIMEOUT_MS 25
#define STM32_SDC_CLOCK_ACTIVATION_DELAY 10
#define STM32_SDC_SDIO_UNALIGNED_SUPPORT TRUE
#define STM32_SDC_SDIO_DMA_STREAM STM32_DMA_STREAM_ID(2, 3)
/*
* SERIAL driver system settings.
*/
#define STM32_SERIAL_USE_USART1 FALSE
#define STM32_SERIAL_USE_USART2 FALSE
#define STM32_SERIAL_USE_USART3 FALSE
#define STM32_SERIAL_USE_UART4 FALSE
#define STM32_SERIAL_USE_UART5 FALSE
#define STM32_SERIAL_USE_USART6 FALSE
#define STM32_SERIAL_USART1_PRIORITY 12
#define STM32_SERIAL_USART2_PRIORITY 12
#define STM32_SERIAL_USART3_PRIORITY 12
#define STM32_SERIAL_UART4_PRIORITY 12
#define STM32_SERIAL_UART5_PRIORITY 12
#define STM32_SERIAL_USART6_PRIORITY 12
/*
* SPI driver system settings.
*/
#define STM32_SPI_USE_SPI1 FALSE
#define STM32_SPI_USE_SPI2 FALSE
#define STM32_SPI_USE_SPI3 FALSE
#define STM32_SPI_SPI1_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 0)
#define STM32_SPI_SPI1_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 3)
#define STM32_SPI_SPI2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)
#define STM32_SPI_SPI2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
#define STM32_SPI_SPI3_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0)
#define STM32_SPI_SPI3_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7)
#define STM32_SPI_SPI1_DMA_PRIORITY 1
#define STM32_SPI_SPI2_DMA_PRIORITY 1
#define STM32_SPI_SPI3_DMA_PRIORITY 1
#define STM32_SPI_SPI1_IRQ_PRIORITY 10
#define STM32_SPI_SPI2_IRQ_PRIORITY 10
#define STM32_SPI_SPI3_IRQ_PRIORITY 10
#define STM32_SPI_DMA_ERROR_HOOK(spip) osalSysHalt("DMA failure")
/*
* ST driver system settings.
*/
#define STM32_ST_IRQ_PRIORITY 8
#define STM32_ST_USE_TIMER 2
/*
* UART driver system settings.
*/
#define STM32_UART_USE_USART1 FALSE
#define STM32_UART_USE_USART2 FALSE
#define STM32_UART_USE_USART3 FALSE
#define STM32_UART_USE_UART4 FALSE
#define STM32_UART_USE_UART5 FALSE
#define STM32_UART_USE_USART6 FALSE
#define STM32_UART_USART1_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 5)
#define STM32_UART_USART1_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 7)
#define STM32_UART_USART2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 5)
#define STM32_UART_USART2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 6)
#define STM32_UART_USART3_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 1)
#define STM32_UART_USART3_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3)
#define STM32_UART_UART4_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2)
#define STM32_UART_UART4_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4)
#define STM32_UART_UART5_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0)
#define STM32_UART_UART5_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7)
#define STM32_UART_USART6_RX_DMA_STREAM STM32_DMA_STREAM_ID(2, 2)
#define STM32_UART_USART6_TX_DMA_STREAM STM32_DMA_STREAM_ID(2, 7)
#define STM32_UART_USART1_IRQ_PRIORITY 12
#define STM32_UART_USART2_IRQ_PRIORITY 12
#define STM32_UART_USART3_IRQ_PRIORITY 12
#define STM32_UART_UART4_IRQ_PRIORITY 12
#define STM32_UART_UART5_IRQ_PRIORITY 12
#define STM32_UART_USART6_IRQ_PRIORITY 12
#define STM32_UART_USART1_DMA_PRIORITY 0
#define STM32_UART_USART2_DMA_PRIORITY 0
#define STM32_UART_USART3_DMA_PRIORITY 0
#define STM32_UART_UART4_DMA_PRIORITY 0
#define STM32_UART_UART5_DMA_PRIORITY 0
#define STM32_UART_USART6_DMA_PRIORITY 0
#define STM32_UART_DMA_ERROR_HOOK(uartp) osalSysHalt("DMA failure")
/*
* USB driver system settings.
*/
#define STM32_USB_USE_OTG1 FALSE
#define STM32_USB_USE_OTG2 FALSE
#define STM32_USB_OTG1_IRQ_PRIORITY 14
#define STM32_USB_OTG2_IRQ_PRIORITY 14
#define STM32_USB_OTG1_RX_FIFO_SIZE 512
#define STM32_USB_OTG2_RX_FIFO_SIZE 1024
#define STM32_USB_OTG_THREAD_PRIO LOWPRIO
#define STM32_USB_OTG_THREAD_STACK_SIZE 128
#define STM32_USB_OTGFIFO_FILL_BASEPRI 0
/*
* WDG driver system settings.
*/
#define STM32_WDG_USE_IWDG FALSE
#endif pre { line-height: 125%; margin: 0; }
td.linenos pre { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
span.linenos { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
td.linenos pre.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight { background: #ffffff; }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long *//****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of a Qt Solutions component.
**
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
** the names of its contributors may be used to endorse or promote
** products derived from this software without specific prior written
** permission.
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
****************************************************************************/
#include "qttreepropertybrowser.h"
#include <QtCore/QSet>
#include <QIcon>
#include <QTreeWidget>
#include <QItemDelegate>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QPainter>
#include <QApplication>
#include <QFocusEvent>
#include <QStyle>
#include <QPalette>
#if QT_VERSION >= 0x040400
QT_BEGIN_NAMESPACE
#endif
class QtPropertyEditorView;
class QtTreePropertyBrowserPrivate
{
QtTreePropertyBrowser *q_ptr;
Q_DECLARE_PUBLIC(QtTreePropertyBrowser)
public:
QtTreePropertyBrowserPrivate();
void init(QWidget *parent);
void propertyInserted(QtBrowserItem *index, QtBrowserItem *afterIndex);
void propertyRemoved(QtBrowserItem *index);
void propertyChanged(QtBrowserItem *index);
QWidget *createEditor(QtProperty *property, QWidget *parent) const
{ return q_ptr->createEditor(property, parent); }
QtProperty *indexToProperty(const QModelIndex &index) const;
QTreeWidgetItem *indexToItem(const QModelIndex &index) const;
QtBrowserItem *indexToBrowserItem(const QModelIndex &index) const;
QtBrowserItem *itemToBrowserItem(QTreeWidgetItem *item) const { return m_itemToIndex.value(item); };
bool lastColumn(int column) const;
void disableItem(QTreeWidgetItem *item) const;
void enableItem(QTreeWidgetItem *item) const;
bool hasValue(QTreeWidgetItem *item) const;
void slotCollapsed(const QModelIndex &index);
void slotExpanded(const QModelIndex &index);
void onHoverPropertyChanged(QtBrowserItem *item);
QColor calculatedBackgroundColor(QtBrowserItem *item) const;
QtPropertyEditorView *treeWidget() const { return m_treeWidget; }
bool markPropertiesWithoutValue() const { return m_markPropertiesWithoutValue; }
QtBrowserItem *currentItem() const;
void setCurrentItem(QtBrowserItem *browserItem, bool block);
void editItem(QtBrowserItem *browserItem);
void slotCurrentBrowserItemChanged(QtBrowserItem *item);
void slotCurrentTreeItemChanged(QTreeWidgetItem *newItem, QTreeWidgetItem *);
QTreeWidgetItem *editedItem() const;
private:
void updateItem(QTreeWidgetItem *item);
QMap<QtBrowserItem *, QTreeWidgetItem *> m_indexToItem;
QMap<QTreeWidgetItem *, QtBrowserItem *> m_itemToIndex;
QMap<QtBrowserItem *, QColor> m_indexToBackgroundColor;
QtPropertyEditorView *m_treeWidget;
bool m_headerVisible;
QtTreePropertyBrowser::ResizeMode m_resizeMode;
class QtPropertyEditorDelegate *m_delegate;
bool m_markPropertiesWithoutValue;
bool m_browserChangedBlocked;
QIcon m_expandIcon;
};
// ------------ QtPropertyEditorView
class QtPropertyEditorView : public QTreeWidget
{
Q_OBJECT
public:
QtPropertyEditorView(QWidget *parent = 0);
void setEditorPrivate(QtTreePropertyBrowserPrivate *editorPrivate)
{ m_editorPrivate = editorPrivate; }
QTreeWidgetItem *indexToItem(const QModelIndex &index) const
{ return itemFromIndex(index); }
protected:
void mouseMoveEvent(QMouseEvent *event) override;
void leaveEvent(QEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
Q_SIGNALS:
void hoverPropertyChanged(QtBrowserItem *item);
private:
QtTreePropertyBrowserPrivate *m_editorPrivate;
QModelIndex current;
};
QtPropertyEditorView::QtPropertyEditorView(QWidget *parent) :
QTreeWidget(parent),
m_editorPrivate(0)
{
connect(header(), SIGNAL(sectionDoubleClicked(int)), this, SLOT(resizeColumnToContents(int)));
}
void QtPropertyEditorView::drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItem opt = option;
bool hasValue = true;
if (m_editorPrivate) {
QtProperty *property = m_editorPrivate->indexToProperty(index);
if (property)
hasValue = property->hasValue();
}
if (!hasValue && m_editorPrivate->markPropertiesWithoutValue()) {
const QColor c = option.palette.color(QPalette::Dark);
painter->fillRect(option.rect, c);
opt.palette.setColor(QPalette::AlternateBase, c);
} else {
const QColor c = m_editorPrivate->calculatedBackgroundColor(m_editorPrivate->indexToBrowserItem(index));
if (c.isValid()) {
painter->fillRect(option.rect, c);
opt.palette.setColor(QPalette::AlternateBase, c.lighter(112));
}
}
QTreeWidget::drawRow(painter, opt, index);
QColor color = static_cast<QRgb>(QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor, &opt));
painter->save();
painter->setPen(QPen(color));
painter->drawLine(opt.rect.x(), opt.rect.bottom(), opt.rect.right(), opt.rect.bottom());
painter->restore();
}
void QtPropertyEditorView::mouseMoveEvent(QMouseEvent *event)
{
QModelIndex index = indexAt(event->pos());
if (index!=current) {
current = index;
Q_EMIT hoverPropertyChanged(m_editorPrivate->indexToBrowserItem(index));
}
QTreeWidget::mouseMoveEvent(event);
}
void QtPropertyEditorView::leaveEvent(QEvent *event)
{
Q_EMIT hoverPropertyChanged(nullptr);
}
void QtPropertyEditorView::keyPressEvent(QKeyEvent *event)
{
switch (event->key()) {
case Qt::Key_Return:
case Qt::Key_Enter:
case Qt::Key_Space: // Trigger Edit
if (!m_editorPrivate->editedItem())
if (const QTreeWidgetItem *item = currentItem())
if (item->columnCount() >= 2 && ((item->flags() & (Qt::ItemIsEditable | Qt::ItemIsEnabled)) == (Qt::ItemIsEditable | Qt::ItemIsEnabled))) {
event->accept();
// If the current position is at column 0, move to 1.
QModelIndex index = currentIndex();
if (index.column() == 0) {
index = index.sibling(index.row(), 1);
setCurrentIndex(index);
}
edit(index);
return;
}
break;
default:
break;
}
QTreeWidget::keyPressEvent(event);
}
void QtPropertyEditorView::mousePressEvent(QMouseEvent *event)
{
QTreeWidget::mousePressEvent(event);
QTreeWidgetItem *item = itemAt(event->pos());
if (item) {
if ((item != m_editorPrivate->editedItem()) && (event->button() == Qt::LeftButton)
&& (header()->logicalIndexAt(event->pos().x()) == 1)
&& ((item->flags() & (Qt::ItemIsEditable | Qt::ItemIsEnabled)) == (Qt::ItemIsEditable | Qt::ItemIsEnabled))) {
editItem(item, 1);
} else if (!m_editorPrivate->hasValue(item) && m_editorPrivate->markPropertiesWithoutValue() && !rootIsDecorated()) {
if (event->pos().x() + header()->offset() < 20)
item->setExpanded(!item->isExpanded());
}
}
}
// ------------ QtPropertyEditorDelegate
class QtPropertyEditorDelegate : public QItemDelegate
{
Q_OBJECT
public:
QtPropertyEditorDelegate(QObject *parent = 0)
: QItemDelegate(parent), m_editorPrivate(0), m_editedItem(0), m_editedWidget(0), m_disablePainting(false)
{}
void setEditorPrivate(QtTreePropertyBrowserPrivate *editorPrivate)
{ m_editorPrivate = editorPrivate; }
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setModelData(QWidget *, QAbstractItemModel *,
const QModelIndex &) const {}
void setEditorData(QWidget *, const QModelIndex &) const {}
bool eventFilter(QObject *object, QEvent *event);
void closeEditor(QtProperty *property);
QTreeWidgetItem *editedItem() const { return m_editedItem; }
protected:
void drawDecoration(QPainter *painter, const QStyleOptionViewItem &option,
const QRect &rect, const QPixmap &pixmap) const;
void drawDisplay(QPainter *painter, const QStyleOptionViewItem &option,
const QRect &rect, const QString &text) const;
private slots:
void slotEditorDestroyed(QObject *object);
private:
int indentation(const QModelIndex &index) const;
typedef QMap<QWidget *, QtProperty *> EditorToPropertyMap;
mutable EditorToPropertyMap m_editorToProperty;
typedef QMap<QtProperty *, QWidget *> PropertyToEditorMap;
mutable PropertyToEditorMap m_propertyToEditor;
QtTreePropertyBrowserPrivate *m_editorPrivate;
mutable QTreeWidgetItem *m_editedItem;
mutable QWidget *m_editedWidget;
mutable bool m_disablePainting;
};
int QtPropertyEditorDelegate::indentation(const QModelIndex &index) const
{
if (!m_editorPrivate)
return 0;
QTreeWidgetItem *item = m_editorPrivate->indexToItem(index);
int indent = 0;
while (item->parent()) {
item = item->parent();
++indent;
}
if (m_editorPrivate->treeWidget()->rootIsDecorated())
++indent;
return indent * m_editorPrivate->treeWidget()->indentation();
}
void QtPropertyEditorDelegate::slotEditorDestroyed(QObject *object)
{
if (QWidget *w = qobject_cast<QWidget *>(object)) {
const EditorToPropertyMap::iterator it = m_editorToProperty.find(w);
if (it != m_editorToProperty.end()) {
m_propertyToEditor.remove(it.value());
m_editorToProperty.erase(it);
}
if (m_editedWidget == w) {
m_editedWidget = 0;
m_editedItem = 0;
}
}
}
void QtPropertyEditorDelegate::closeEditor(QtProperty *property)
{
if (QWidget *w = m_propertyToEditor.value(property, 0))
w->deleteLater();
}
QWidget *QtPropertyEditorDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &, const QModelIndex &index) const
{
if (index.column() == 1 && m_editorPrivate) {
QtProperty *property = m_editorPrivate->indexToProperty(index);
QTreeWidgetItem *item = m_editorPrivate->indexToItem(index);
if (property && item && (item->flags() & Qt::ItemIsEnabled)) {
QWidget *editor = m_editorPrivate->createEditor(property, parent);
if (editor) {
editor->setAutoFillBackground(true);
editor->installEventFilter(const_cast<QtPropertyEditorDelegate *>(this));
connect(editor, SIGNAL(destroyed(QObject *)), this, SLOT(slotEditorDestroyed(QObject *)));
m_propertyToEditor[property] = editor;
m_editorToProperty[editor] = property;
m_editedItem = item;
m_editedWidget = editor;
}
return editor;
}
}
return 0;
}
void QtPropertyEditorDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
Q_UNUSED(index)
editor->setGeometry(option.rect.adjusted(0, 0, 0, -1));
}
void QtPropertyEditorDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
bool hasValue = true;
if (m_editorPrivate) {
QtProperty *property = m_editorPrivate->indexToProperty(index);
if (property)
hasValue = property->hasValue();
}
QStyleOptionViewItem opt = option;
if ((m_editorPrivate && index.column() == 0) || !hasValue) {
QtProperty *property = m_editorPrivate->indexToProperty(index);
if (property && property->isModified()) {
opt.font.setBold(true);
opt.fontMetrics = QFontMetrics(opt.font);
}
}
QColor c;
if (!hasValue && m_editorPrivate->markPropertiesWithoutValue()) {
c = opt.palette.color(QPalette::Dark);
opt.palette.setColor(QPalette::Text, opt.palette.color(QPalette::BrightText));
} else {
c = m_editorPrivate->calculatedBackgroundColor(m_editorPrivate->indexToBrowserItem(index));
if (c.isValid() && (opt.features & QStyleOptionViewItem::Alternate))
c = c.lighter(112);
}
if (c.isValid())
painter->fillRect(option.rect, c);
opt.state &= ~QStyle::State_HasFocus;
if (index.column() == 1) {
QTreeWidgetItem *item = m_editorPrivate->indexToItem(index);
if (m_editedItem && m_editedItem == item)
m_disablePainting = true;
}
QItemDelegate::paint(painter, opt, index);
m_disablePainting = false;
opt.palette.setCurrentColorGroup(QPalette::Active);
QColor color = static_cast<QRgb>(QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor, &opt));
painter->save();
painter->setPen(QPen(color));
if (!m_editorPrivate || (!m_editorPrivate->lastColumn(index.column()) && hasValue)) {
int right = (option.direction == Qt::LeftToRight) ? option.rect.right() : option.rect.left();
painter->drawLine(right, option.rect.y(), right, option.rect.bottom());
}
painter->restore();
}
void QtPropertyEditorDelegate::drawDecoration(QPainter *painter, const QStyleOptionViewItem &option,
const QRect &rect, const QPixmap &pixmap) const
{
if (m_disablePainting)
return;
QItemDelegate::drawDecoration(painter, option, rect, pixmap);
}
void QtPropertyEditorDelegate::drawDisplay(QPainter *painter, const QStyleOptionViewItem &option,
const QRect &rect, const QString &text) const
{
if (m_disablePainting)
return;
QItemDelegate::drawDisplay(painter, option, rect, text);
}
QSize QtPropertyEditorDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
return QItemDelegate::sizeHint(option, index) + QSize(3, 4);
}
bool QtPropertyEditorDelegate::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::FocusOut) {
QFocusEvent *fe = static_cast<QFocusEvent *>(event);
if (fe->reason() == Qt::ActiveWindowFocusReason)
return false;
}
return QItemDelegate::eventFilter(object, event);
}
// -------- QtTreePropertyBrowserPrivate implementation
QtTreePropertyBrowserPrivate::QtTreePropertyBrowserPrivate() :
m_treeWidget(0),
m_headerVisible(true),
m_resizeMode(QtTreePropertyBrowser::Stretch),
m_delegate(0),
m_markPropertiesWithoutValue(false),
m_browserChangedBlocked(false)
{
}
// Draw an icon indicating opened/closing branches
static QIcon drawIndicatorIcon(const QPalette &palette, QStyle *style)
{
QPixmap pix(14, 14);
pix.fill(Qt::transparent);
QStyleOption branchOption;
QRect r(QPoint(0, 0), pix.size());
branchOption.rect = QRect(2, 2, 9, 9); // ### hardcoded in qcommonstyle.cpp
branchOption.palette = palette;
branchOption.state = QStyle::State_Children;
QPainter p;
// Draw closed state
p.begin(&pix);
style->drawPrimitive(QStyle::PE_IndicatorBranch, &branchOption, &p);
p.end();
QIcon rc = pix;
rc.addPixmap(pix, QIcon::Selected, QIcon::Off);
// Draw opened state
branchOption.state |= QStyle::State_Open;
pix.fill(Qt::transparent);
p.begin(&pix);
style->drawPrimitive(QStyle::PE_IndicatorBranch, &branchOption, &p);
p.end();
rc.addPixmap(pix, QIcon::Normal, QIcon::On);
rc.addPixmap(pix, QIcon::Selected, QIcon::On);
return rc;
}
void QtTreePropertyBrowserPrivate::init(QWidget *parent)
{
QHBoxLayout *layout = new QHBoxLayout(parent);
layout->setMargin(0);
m_treeWidget = new QtPropertyEditorView(parent);
m_treeWidget->setEditorPrivate(this);
m_treeWidget->setIconSize(QSize(18, 18));
layout->addWidget(m_treeWidget);
m_treeWidget->setColumnCount(2);
QStringList labels;
labels.append(QApplication::translate("QtTreePropertyBrowser", "Property", 0));
labels.append(QApplication::translate("QtTreePropertyBrowser", "Value", 0));
m_treeWidget->setHeaderLabels(labels);
m_treeWidget->setAlternatingRowColors(true);
m_treeWidget->setEditTriggers(QAbstractItemView::EditKeyPressed);
m_delegate = new QtPropertyEditorDelegate(parent);
m_delegate->setEditorPrivate(this);
m_treeWidget->setItemDelegate(m_delegate);
m_treeWidget->header()->setSectionsMovable(false);
m_treeWidget->header()->setSectionResizeMode(QHeaderView::Stretch);
m_expandIcon = drawIndicatorIcon(q_ptr->palette(), q_ptr->style());
QObject::connect(m_treeWidget, SIGNAL(collapsed(const QModelIndex &)), q_ptr, SLOT(slotCollapsed(const QModelIndex &)));
QObject::connect(m_treeWidget, SIGNAL(expanded(const QModelIndex &)), q_ptr, SLOT(slotExpanded(const QModelIndex &)));
QObject::connect(m_treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)), q_ptr, SLOT(slotCurrentTreeItemChanged(QTreeWidgetItem*,QTreeWidgetItem*)));
QObject::connect(m_treeWidget, SIGNAL(hoverPropertyChanged(QtBrowserItem *)), q_ptr, SLOT(onHoverPropertyChanged(QtBrowserItem *)));
}
QtBrowserItem *QtTreePropertyBrowserPrivate::currentItem() const
{
if (QTreeWidgetItem *treeItem = m_treeWidget->currentItem())
return m_itemToIndex.value(treeItem);
return 0;
}
void QtTreePropertyBrowserPrivate::setCurrentItem(QtBrowserItem *browserItem, bool block)
{
const bool blocked = block ? m_treeWidget->blockSignals(true) : false;
if (browserItem == 0)
m_treeWidget->setCurrentItem(0);
else
m_treeWidget->setCurrentItem(m_indexToItem.value(browserItem));
if (block)
m_treeWidget->blockSignals(blocked);
}
QtProperty *QtTreePropertyBrowserPrivate::indexToProperty(const QModelIndex &index) const
{
QTreeWidgetItem *item = m_treeWidget->indexToItem(index);
QtBrowserItem *idx = m_itemToIndex.value(item);
if (idx)
return idx->property();
return 0;
}
QtBrowserItem *QtTreePropertyBrowserPrivate::indexToBrowserItem(const QModelIndex &index) const
{
QTreeWidgetItem *item = m_treeWidget->indexToItem(index);
return m_itemToIndex.value(item);
}
QTreeWidgetItem *QtTreePropertyBrowserPrivate::indexToItem(const QModelIndex &index) const
{
return m_treeWidget->indexToItem(index);
}
bool QtTreePropertyBrowserPrivate::lastColumn(int column) const
{
return m_treeWidget->header()->visualIndex(column) == m_treeWidget->columnCount() - 1;
}
void QtTreePropertyBrowserPrivate::disableItem(QTreeWidgetItem *item) const
{
Qt::ItemFlags flags = item->flags();
if (flags & Qt::ItemIsEnabled) {
flags &= ~Qt::ItemIsEnabled;
item->setFlags(flags);
m_delegate->closeEditor(m_itemToIndex[item]->property());
const int childCount = item->childCount();
for (int i = 0; i < childCount; i++) {
QTreeWidgetItem *child = item->child(i);
disableItem(child);
}
}
}
void QtTreePropertyBrowserPrivate::enableItem(QTreeWidgetItem *item) const
{
Qt::ItemFlags flags = item->flags();
flags |= Qt::ItemIsEnabled;
item->setFlags(flags);
const int childCount = item->childCount();
for (int i = 0; i < childCount; i++) {
QTreeWidgetItem *child = item->child(i);
QtProperty *property = m_itemToIndex[child]->property();
if (property->isEnabled()) {
enableItem(child);
}
}
}
bool QtTreePropertyBrowserPrivate::hasValue(QTreeWidgetItem *item) const
{
QtBrowserItem *browserItem = m_itemToIndex.value(item);
if (browserItem)
return browserItem->property()->hasValue();
return false;
}
void QtTreePropertyBrowserPrivate::propertyInserted(QtBrowserItem *index, QtBrowserItem *afterIndex)
{
QTreeWidgetItem *afterItem = m_indexToItem.value(afterIndex);
QTreeWidgetItem *parentItem = m_indexToItem.value(index->parent());
QTreeWidgetItem *newItem = 0;
if (parentItem) {
newItem = new QTreeWidgetItem(parentItem, afterItem);
} else {
newItem = new QTreeWidgetItem(m_treeWidget, afterItem);
}
m_itemToIndex[newItem] = index;
m_indexToItem[index] = newItem;
newItem->setFlags(newItem->flags() | Qt::ItemIsEditable);
newItem->setExpanded(true);
updateItem(newItem);
}
void QtTreePropertyBrowserPrivate::propertyRemoved(QtBrowserItem *index)
{
QTreeWidgetItem *item = m_indexToItem.value(index);
if (m_treeWidget->currentItem() == item) {
m_treeWidget->setCurrentItem(0);
}
delete item;
m_indexToItem.remove(index);
m_itemToIndex.remove(item);
m_indexToBackgroundColor.remove(index);
}
void QtTreePropertyBrowserPrivate::propertyChanged(QtBrowserItem *index)
{
QTreeWidgetItem *item = m_indexToItem.value(index);
updateItem(item);
}
void QtTreePropertyBrowserPrivate::updateItem(QTreeWidgetItem *item)
{
QtProperty *property = m_itemToIndex[item]->property();
QIcon expandIcon;
if (property->hasValue()) {
QString toolTip = property->toolTip();
if (toolTip.isEmpty())
toolTip = property->valueText();
item->setToolTip(1, toolTip);
item->setIcon(1, property->valueIcon());
item->setText(1, property->valueText());
} else if (markPropertiesWithoutValue() && !m_treeWidget->rootIsDecorated()) {
expandIcon = m_expandIcon;
}
item->setIcon(0, expandIcon);
item->setFirstColumnSpanned(!property->hasValue());
item->setToolTip(0, property->propertyName());
item->setStatusTip(0, property->statusTip());
item->setWhatsThis(0, property->whatsThis());
item->setText(0, property->propertyName());
bool wasEnabled = item->flags() & Qt::ItemIsEnabled;
bool isEnabled = wasEnabled;
if (property->isEnabled()) {
QTreeWidgetItem *parent = item->parent();
if (!parent || (parent->flags() & Qt::ItemIsEnabled))
isEnabled = true;
else
isEnabled = false;
} else {
isEnabled = false;
}
if (wasEnabled != isEnabled) {
if (isEnabled)
enableItem(item);
else
disableItem(item);
}
if (property->isSelectable()) {
item->setFlags(item->flags() | Qt::ItemIsSelectable);
} else {
item->setFlags(item->flags() & ~Qt::ItemIsSelectable);
}
m_treeWidget->viewport()->update();
}
QColor QtTreePropertyBrowserPrivate::calculatedBackgroundColor(QtBrowserItem *item) const
{
QtBrowserItem *i = item;
const QMap<QtBrowserItem *, QColor>::const_iterator itEnd = m_indexToBackgroundColor.constEnd();
while (i) {
QMap<QtBrowserItem *, QColor>::const_iterator it = m_indexToBackgroundColor.constFind(i);
if (it != itEnd)
return it.value();
i = i->parent();
}
return QColor();
}
void QtTreePropertyBrowserPrivate::slotCollapsed(const QModelIndex &index)
{
QTreeWidgetItem *item = indexToItem(index);
QtBrowserItem *idx = m_itemToIndex.value(item);
if (item)
emit q_ptr->collapsed(idx);
}
void QtTreePropertyBrowserPrivate::slotExpanded(const QModelIndex &index)
{
QTreeWidgetItem *item = indexToItem(index);
QtBrowserItem *idx = m_itemToIndex.value(item);
if (item)
emit q_ptr->expanded(idx);
}
void QtTreePropertyBrowserPrivate::onHoverPropertyChanged(QtBrowserItem *item)
{
emit q_ptr->hoverPropertyChanged(item);
}
void QtTreePropertyBrowserPrivate::slotCurrentBrowserItemChanged(QtBrowserItem *item)
{
if (!m_browserChangedBlocked && item != currentItem())
setCurrentItem(item, true);
}
void QtTreePropertyBrowserPrivate::slotCurrentTreeItemChanged(QTreeWidgetItem *newItem, QTreeWidgetItem *)
{
QtBrowserItem *browserItem = newItem ? m_itemToIndex.value(newItem) : 0;
m_browserChangedBlocked = true;
q_ptr->setCurrentItem(browserItem);
m_browserChangedBlocked = false;
}
QTreeWidgetItem *QtTreePropertyBrowserPrivate::editedItem() const
{
return m_delegate->editedItem();
}
void QtTreePropertyBrowserPrivate::editItem(QtBrowserItem *browserItem)
{
if (QTreeWidgetItem *treeItem = m_indexToItem.value(browserItem, 0)) {
m_treeWidget->setCurrentItem (treeItem, 1);
m_treeWidget->editItem(treeItem, 1);
}
}
/*!
\class QtTreePropertyBrowser
\brief The QtTreePropertyBrowser class provides QTreeWidget based
property browser.
A property browser is a widget that enables the user to edit a
given set of properties. Each property is represented by a label
specifying the property's name, and an editing widget (e.g. a line
edit or a combobox) holding its value. A property can have zero or
more subproperties.
QtTreePropertyBrowser provides a tree based view for all nested
properties, i.e. properties that have subproperties can be in an
expanded (subproperties are visible) or collapsed (subproperties
are hidden) state. For example:
\image qttreepropertybrowser.png
Use the QtAbstractPropertyBrowser API to add, insert and remove
properties from an instance of the QtTreePropertyBrowser class.
The properties themselves are created and managed by
implementations of the QtAbstractPropertyManager class.
\sa QtGroupBoxPropertyBrowser, QtAbstractPropertyBrowser
*/
/*!
\fn void QtTreePropertyBrowser::collapsed(QtBrowserItem *item)
This signal is emitted when the \a item is collapsed.
\sa expanded(), setExpanded()
*/
/*!
\fn void QtTreePropertyBrowser::expanded(QtBrowserItem *item)
This signal is emitted when the \a item is expanded.
\sa collapsed(), setExpanded()
*/
/*!
Creates a property browser with the given \a parent.
*/
QtTreePropertyBrowser::QtTreePropertyBrowser(QWidget *parent)
: QtAbstractPropertyBrowser(parent)
{
d_ptr = new QtTreePropertyBrowserPrivate;
d_ptr->q_ptr = this;
d_ptr->init(this);
connect(this, SIGNAL(currentItemChanged(QtBrowserItem*)), this, SLOT(slotCurrentBrowserItemChanged(QtBrowserItem*)));
}
/*!
Destroys this property browser.
Note that the properties that were inserted into this browser are
\e not destroyed since they may still be used in other
browsers. The properties are owned by the manager that created
them.
\sa QtProperty, QtAbstractPropertyManager
*/
QtTreePropertyBrowser::~QtTreePropertyBrowser()
{
delete d_ptr;
}
/*!
\property QtTreePropertyBrowser::indentation
\brief indentation of the items in the tree view.
*/
int QtTreePropertyBrowser::indentation() const
{
return d_ptr->m_treeWidget->indentation();
}
void QtTreePropertyBrowser::setIndentation(int i)
{
d_ptr->m_treeWidget->setIndentation(i);
}
/*!
\property QtTreePropertyBrowser::rootIsDecorated
\brief whether to show controls for expanding and collapsing root items.
*/
bool QtTreePropertyBrowser::rootIsDecorated() const
{
return d_ptr->m_treeWidget->rootIsDecorated();
}
void QtTreePropertyBrowser::setRootIsDecorated(bool show)
{
d_ptr->m_treeWidget->setRootIsDecorated(show);
QMapIterator<QTreeWidgetItem *, QtBrowserItem *> it(d_ptr->m_itemToIndex);
while (it.hasNext()) {
QtProperty *property = it.next().value()->property();
if (!property->hasValue())
d_ptr->updateItem(it.key());
}
}
/*!
\property QtTreePropertyBrowser::alternatingRowColors
\brief whether to draw the background using alternating colors.
By default this property is set to true.
*/
bool QtTreePropertyBrowser::alternatingRowColors() const
{
return d_ptr->m_treeWidget->alternatingRowColors();
}
void QtTreePropertyBrowser::setAlternatingRowColors(bool enable)
{
d_ptr->m_treeWidget->setAlternatingRowColors(enable);
QMapIterator<QTreeWidgetItem *, QtBrowserItem *> it(d_ptr->m_itemToIndex);
}
/*!
\property QtTreePropertyBrowser::headerVisible
\brief whether to show the header.
*/
bool QtTreePropertyBrowser::isHeaderVisible() const
{
return d_ptr->m_headerVisible;
}
void QtTreePropertyBrowser::setHeaderVisible(bool visible)
{
if (d_ptr->m_headerVisible == visible)
return;
d_ptr->m_headerVisible = visible;
d_ptr->m_treeWidget->header()->setVisible(visible);
}
/*!
\enum QtTreePropertyBrowser::ResizeMode
The resize mode specifies the behavior of the header sections.
\value Interactive The user can resize the sections.
The sections can also be resized programmatically using setSplitterPosition().
\value Fixed The user cannot resize the section.
The section can only be resized programmatically using setSplitterPosition().
\value Stretch QHeaderView will automatically resize the section to fill the available space.
The size cannot be changed by the user or programmatically.
\value ResizeToContents QHeaderView will automatically resize the section to its optimal
size based on the contents of the entire column.
The size cannot be changed by the user or programmatically.
\sa setResizeMode()
*/
/*!
\property QtTreePropertyBrowser::resizeMode
\brief the resize mode of setions in the header.
*/
QtTreePropertyBrowser::ResizeMode QtTreePropertyBrowser::resizeMode() const
{
return d_ptr->m_resizeMode;
}
void QtTreePropertyBrowser::setResizeMode(QtTreePropertyBrowser::ResizeMode mode)
{
if (d_ptr->m_resizeMode == mode)
return;
d_ptr->m_resizeMode = mode;
QHeaderView::ResizeMode m = QHeaderView::Stretch;
switch (mode) {
case QtTreePropertyBrowser::Interactive: m = QHeaderView::Interactive; break;
case QtTreePropertyBrowser::Fixed: m = QHeaderView::Fixed; break;
case QtTreePropertyBrowser::ResizeToContents: m = QHeaderView::ResizeToContents; break;
case QtTreePropertyBrowser::Stretch:
default: m = QHeaderView::Stretch; break;
}
d_ptr->m_treeWidget->header()->setSectionResizeMode(m);
}
/*!
\property QtTreePropertyBrowser::splitterPosition
\brief the position of the splitter between the colunms.
*/
int QtTreePropertyBrowser::splitterPosition() const
{
return d_ptr->m_treeWidget->header()->sectionSize(0);
}
void QtTreePropertyBrowser::setSplitterPosition(int position)
{
d_ptr->m_treeWidget->header()->resizeSection(0, position);
}
/*!
Sets the \a item to either collapse or expanded, depending on the value of \a expanded.
\sa isExpanded(), expanded(), collapsed()
*/
void QtTreePropertyBrowser::setExpanded(QtBrowserItem *item, bool expanded)
{
QTreeWidgetItem *treeItem = d_ptr->m_indexToItem.value(item);
if (treeItem)
treeItem->setExpanded(expanded);
}
/*!
Returns true if the \a item is expanded; otherwise returns false.
\sa setExpanded()
*/
bool QtTreePropertyBrowser::isExpanded(QtBrowserItem *item) const
{
QTreeWidgetItem *treeItem = d_ptr->m_indexToItem.value(item);
if (treeItem)
return treeItem->isExpanded();
return false;
}
/*!
Returns true if the \a item is visible; otherwise returns false.
\sa setItemVisible()
\since 4.5
*/
bool QtTreePropertyBrowser::isItemVisible(QtBrowserItem *item) const
{
if (const QTreeWidgetItem *treeItem = d_ptr->m_indexToItem.value(item))
return !treeItem->isHidden();
return false;
}
/*!
Sets the \a item to be visible, depending on the value of \a visible.
\sa isItemVisible()
\since 4.5
*/
void QtTreePropertyBrowser::setItemVisible(QtBrowserItem *item, bool visible)
{
if (QTreeWidgetItem *treeItem = d_ptr->m_indexToItem.value(item))
treeItem->setHidden(!visible);
}
/*!
Sets the \a item's background color to \a color. Note that while item's background
is rendered every second row is being drawn with alternate color (which is a bit lighter than items \a color)
\sa backgroundColor(), calculatedBackgroundColor()
*/
void QtTreePropertyBrowser::setBackgroundColor(QtBrowserItem *item, const QColor &color)
{
if (!d_ptr->m_indexToItem.contains(item))
return;
if (color.isValid())
d_ptr->m_indexToBackgroundColor[item] = color;
else
d_ptr->m_indexToBackgroundColor.remove(item);
d_ptr->m_treeWidget->viewport()->update();
}
/*!
Returns the \a item's color. If there is no color set for item it returns invalid color.
\sa calculatedBackgroundColor(), setBackgroundColor()
*/
QColor QtTreePropertyBrowser::backgroundColor(QtBrowserItem *item) const
{
return d_ptr->m_indexToBackgroundColor.value(item);
}
/*!
Returns the \a item's color. If there is no color set for item it returns parent \a item's
color (if there is no color set for parent it returns grandparent's color and so on). In case
the color is not set for \a item and it's top level item it returns invalid color.
\sa backgroundColor(), setBackgroundColor()
*/
QColor QtTreePropertyBrowser::calculatedBackgroundColor(QtBrowserItem *item) const
{
return d_ptr->calculatedBackgroundColor(item);
}
/*!
\property QtTreePropertyBrowser::propertiesWithoutValueMarked
\brief whether to enable or disable marking properties without value.
When marking is enabled the item's background is rendered in dark color and item's
foreground is rendered with light color.
\sa propertiesWithoutValueMarked()
*/
void QtTreePropertyBrowser::setPropertiesWithoutValueMarked(bool mark)
{
if (d_ptr->m_markPropertiesWithoutValue == mark)
return;
d_ptr->m_markPropertiesWithoutValue = mark;
QMapIterator<QTreeWidgetItem *, QtBrowserItem *> it(d_ptr->m_itemToIndex);
while (it.hasNext()) {
QtProperty *property = it.next().value()->property();
if (!property->hasValue())
d_ptr->updateItem(it.key());
}
d_ptr->m_treeWidget->viewport()->update();
}
bool QtTreePropertyBrowser::propertiesWithoutValueMarked() const
{
return d_ptr->m_markPropertiesWithoutValue;
}
/*!
\reimp
*/
void QtTreePropertyBrowser::itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem)
{
d_ptr->propertyInserted(item, afterItem);
}
/*!
\reimp
*/
void QtTreePropertyBrowser::itemRemoved(QtBrowserItem *item)
{
d_ptr->propertyRemoved(item);
}
/*!
\reimp
*/
void QtTreePropertyBrowser::itemChanged(QtBrowserItem *item)
{
d_ptr->propertyChanged(item);
}
/*!
Sets the current item to \a item and opens the relevant editor for it.
*/
void QtTreePropertyBrowser::editItem(QtBrowserItem *item)
{
d_ptr->editItem(item);
}
QTreeWidget *QtTreePropertyBrowser::treeWidget() const
{
return d_ptr->treeWidget();
}
QtBrowserItem *QtTreePropertyBrowser::itemToBrowserItem(QTreeWidgetItem *item)
{
return d_ptr->itemToBrowserItem(item);
}
#if QT_VERSION >= 0x040400
QT_END_NAMESPACE
#endif
#include "moc_qttreepropertybrowser.cpp"
#include "qttreepropertybrowser.moc"