First commit
31
.gitignore
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# Compiled Object files
|
||||||
|
*.slo
|
||||||
|
*.lo
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
|
||||||
|
# Precompiled Headers
|
||||||
|
*.gch
|
||||||
|
*.pch
|
||||||
|
|
||||||
|
# Compiled Dynamic libraries
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
*.dll
|
||||||
|
|
||||||
|
# Fortran module files
|
||||||
|
*.mod
|
||||||
|
|
||||||
|
# Compiled Static libraries
|
||||||
|
*.lai
|
||||||
|
*.la
|
||||||
|
*.a
|
||||||
|
*.lib
|
||||||
|
|
||||||
|
# Executables
|
||||||
|
*.exe
|
||||||
|
*.out
|
||||||
|
*.app
|
||||||
|
|
||||||
|
# Ignores 'build' in any sub folder
|
||||||
|
build/
|
||||||
53
CMakeLists.txt
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
|
||||||
|
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
|
||||||
|
PROJECT(QtPropertyBrowser)
|
||||||
|
|
||||||
|
########################### Misc. Configs ##############################
|
||||||
|
# Add custom cmake files folder
|
||||||
|
SET (PROJECT_CMAKE_DIR ${PROJECT_SOURCE_DIR}/cmake)
|
||||||
|
SET (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${PROJECT_CMAKE_DIR}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
##################### Look for required libraries ######################
|
||||||
|
|
||||||
|
# Add QT dependencies
|
||||||
|
INCLUDE(AddQt)
|
||||||
|
IF (NOT QT_FOUND)
|
||||||
|
MESSAGE(FATAL "We Need some QT")
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
# Subdirectories
|
||||||
|
#
|
||||||
|
ADD_SUBDIRECTORY(src)
|
||||||
|
|
||||||
|
OPTION (BUILD_EXAMPLES "Build Examples" ON)
|
||||||
|
IF(BUILD_EXAMPLES)
|
||||||
|
ADD_SUBDIRECTORY(examples)
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
# Generate QtPropertyBrowserConfig file
|
||||||
|
#
|
||||||
|
CONFIGURE_FILE(UseQtPropertyBrowser.cmake.in
|
||||||
|
${QtPropertyBrowser_BINARY_DIR}/UseQtPropertyBrowser.cmake COPYONLY)
|
||||||
|
|
||||||
|
INCLUDE(GenerateQtPropertyBrowserConfig.cmake)
|
||||||
|
|
||||||
|
|
||||||
|
MESSAGE(STATUS "===============================================================")
|
||||||
|
MESSAGE(STATUS "================ Configuration Summary ======================")
|
||||||
|
MESSAGE(STATUS "Project Name: ${PROJECT_NAME}")
|
||||||
|
MESSAGE(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
|
||||||
|
MESSAGE(STATUS "Build type Flags: ${CMAKE_BUILD_TYPE_FLAGS}")
|
||||||
|
MESSAGE(STATUS "C++ compile flags: ${CMAKE_CXX_FLAGS}")
|
||||||
|
MESSAGE(STATUS "Install Path: ${CMAKE_INSTALL_PREFIX}")
|
||||||
|
MESSAGE(STATUS "Build Examples: ${BUILD_EXAMPLES}")
|
||||||
|
IF(QT_FOUND )
|
||||||
|
MESSAGE(STATUS "QT Version: ${QT_VERSION_STRING}")
|
||||||
|
MESSAGE(STATUS "QT_TARGETS: ${QT_TARGETS}")
|
||||||
|
MESSAGE(STATUS "QT_ALL_TARGETS: ${QT_ALL_TARGETS}")
|
||||||
|
MESSAGE(STATUS "QT_INCLUDE_DIRS: ${QT_INCLUDE_DIRS}")
|
||||||
|
MESSAGE(STATUS "QT_COMPILE_DEFS: ${QT_COMPILE_DEFS}")
|
||||||
|
ENDIF()
|
||||||
59
GenerateQtPropertyBrowserConfig.cmake
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
###########################################################################
|
||||||
|
#
|
||||||
|
# Library: CTK
|
||||||
|
#
|
||||||
|
# Copyright (c) Kitware Inc.
|
||||||
|
#
|
||||||
|
# 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.commontk.org/LICENSE
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
# Settings shared between the build tree and install tree.
|
||||||
|
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
# Settings specific to the build tree.
|
||||||
|
|
||||||
|
# The "use" file.
|
||||||
|
SET(QtPropertyBrowser_USE_FILE ${QtPropertyBrowser_BINARY_DIR}/UseQtPropertyBrowser.cmake)
|
||||||
|
|
||||||
|
# Determine the include directories needed.
|
||||||
|
SET(QtPropertyBrowser_INCLUDE_DIRS_CONFIG
|
||||||
|
${QtPropertyBrowser_SOURCE_DIR}/src
|
||||||
|
)
|
||||||
|
|
||||||
|
# Library directory.
|
||||||
|
SET(QtPropertyBrowser_LIBRARY_DIRS_CONFIG ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
|
||||||
|
|
||||||
|
# Runtime library directory.
|
||||||
|
SET(QtPropertyBrowser_RUNTIME_LIBRARY_DIRS_CONFIG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||||
|
|
||||||
|
# Build configuration information.
|
||||||
|
SET(QtPropertyBrowser_CONFIGURATION_TYPES_CONFIG ${CMAKE_CONFIGURATION_TYPES})
|
||||||
|
SET(QtPropertyBrowser_BUILD_TYPE_CONFIG ${CMAKE_BUILD_TYPE})
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
# Configure QtPropertyBrowserConfig.cmake for the build tree.
|
||||||
|
CONFIGURE_FILE(${QtPropertyBrowser_SOURCE_DIR}/QtPropertyBrowserConfig.cmake.in
|
||||||
|
${QtPropertyBrowser_BINARY_DIR}/QtPropertyBrowserConfig.cmake @ONLY IMMEDIATE)
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
# Settings specific to the install tree.
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------
|
||||||
|
# Configure QtPropertyBrowserConfig.cmake for the install tree.
|
||||||
|
|
||||||
|
# TODO
|
||||||
60
QtPropertyBrowserConfig.cmake.in
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
###########################################################################
|
||||||
|
#
|
||||||
|
# Library: CTK
|
||||||
|
#
|
||||||
|
# Copyright (c) Kitware Inc.
|
||||||
|
#
|
||||||
|
# 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.commontk.org/LICENSE
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
#
|
||||||
|
# QtPropertyBrowserConfig.cmake - QtPropertyBrowser CMake configuration file for external projects.
|
||||||
|
#
|
||||||
|
# This file is configured by QtPropertyBrowser and used by the
|
||||||
|
# UseQtPropertyBrowser.cmake module to load QtPropertyBrowser's settings
|
||||||
|
# for an external project.
|
||||||
|
|
||||||
|
# The QtPropertyBrowser include file directories.
|
||||||
|
SET(QtPropertyBrowser_INCLUDE_DIRS "@QtPropertyBrowser_INCLUDE_DIRS_CONFIG@")
|
||||||
|
|
||||||
|
# The QtPropertyBrowser library directories. Note that if
|
||||||
|
# QtPropertyBrowser_CONFIGURATION_TYPES is set (see below) then these directories
|
||||||
|
# will be the parent directories under which there will be a directory
|
||||||
|
# of runtime binaries for each configuration type.
|
||||||
|
SET(QtPropertyBrowser_LIBRARY_DIRS "@QtPropertyBrowser_LIBRARY_DIRS_CONFIG@")
|
||||||
|
|
||||||
|
# The QtPropertyBrowser runtime library directories. Note that if
|
||||||
|
# QtPropertyBrowser_CONFIGURATION_TYPES is set (see below) then these directories
|
||||||
|
# will be the parent directories under which there will be a directory
|
||||||
|
# of runtime libraries for each configuration type.
|
||||||
|
SET(QtPropertyBrowser_RUNTIME_LIBRARY_DIRS "@QtPropertyBrowser_RUNTIME_LIBRARY_DIRS_CONFIG@")
|
||||||
|
|
||||||
|
# The location of the UseQtPropertyBrowser.cmake file.
|
||||||
|
SET(QtPropertyBrowser_USE_FILE "@QtPropertyBrowser_USE_FILE@")
|
||||||
|
|
||||||
|
|
||||||
|
# A QtPropertyBrowser install tree always provides one build configuration.
|
||||||
|
# A QtPropertyBrowser build tree may provide either one or multiple build
|
||||||
|
# configurations depending on the CMake generator used.
|
||||||
|
# Since QtPropertyBrowser can be used either from a build tree or an install
|
||||||
|
# tree it is useful for outside projects to know the configurations available.
|
||||||
|
# If this QtPropertyBrowserConfig.cmake is in a QtPropertyBrowser install
|
||||||
|
# tree QtPropertyBrowser_CONFIGURATION_TYPES will be empty and
|
||||||
|
# QtPropertyBrowser_BUILD_TYPE will be set to the value of
|
||||||
|
# CMAKE_BUILD_TYPE used to build QtPropertyBrowser. If QtPropertyBrowserConfig.cmake
|
||||||
|
# is in a QtPropertyBrowser build tree then QtPropertyBrowser_CONFIGURATION_TYPES
|
||||||
|
# and QtPropertyBrowser_BUILD_TYPE will have values matching CMAKE_CONFIGURATION_TYPES
|
||||||
|
# and CMAKE_BUILD_TYPE for that build tree (only one will ever be set).
|
||||||
|
SET(QtPropertyBrowser_CONFIGURATION_TYPES @QtPropertyBrowser_CONFIGURATION_TYPES_CONFIG@)
|
||||||
|
SET(QtPropertyBrowser_BUILD_TYPE @QtPropertyBrowser_BUILD_TYPE_CONFIG@)
|
||||||
93
README.md
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
Qt Solutions Component: Property Browser
|
||||||
|
|
||||||
|
A property browser framework enabling the user to edit a set of
|
||||||
|
properties.
|
||||||
|
|
||||||
|
The framework provides a browser widget that displays the given
|
||||||
|
properties with labels and corresponding editing widgets (e.g.
|
||||||
|
line edits or comboboxes). The various types of editing widgets
|
||||||
|
are provided by the framework's editor factories: For each
|
||||||
|
property type, the framework provides a property manager (e.g.
|
||||||
|
QtIntPropertyManager and QtStringPropertyManager) which can be
|
||||||
|
associated with the preferred editor factory (e.g.
|
||||||
|
QtSpinBoxFactory and QtLineEditFactory). The framework also
|
||||||
|
provides a variant based property type with corresponding variant
|
||||||
|
manager and factory. Finally, the framework provides three
|
||||||
|
ready-made implementations of the browser widget:
|
||||||
|
QtTreePropertyBrowser, QtButtonPropertyBrowser and
|
||||||
|
QtGroupBoxPropertyBrowser.
|
||||||
|
|
||||||
|
Version history:
|
||||||
|
|
||||||
|
2.1: - QtTreePropertyBrowser - tooltip of property applied to
|
||||||
|
first column, while second column shows the value text of property
|
||||||
|
in its tooltip
|
||||||
|
- QtAbstractPropertyManager - initializeProperty() and
|
||||||
|
uninitializeProperty() without const modifier now
|
||||||
|
- QtTreePropertyBrowser and QtGroupBoxPropertyBrowser - internal
|
||||||
|
margin set to 0
|
||||||
|
- QtProperty - setEnabled() and isEnabled() methods added
|
||||||
|
- QtTreePropertyBrowser - "rootIsDecorated", "indentation" and
|
||||||
|
"headerVisible" properties added
|
||||||
|
- QtProperty - hasValue() method added, useful for group
|
||||||
|
properties
|
||||||
|
|
||||||
|
2.2: - FocusOut event now filtered out in case of
|
||||||
|
Qt::ActiveWindowFocusReason reason. In that case editor is not
|
||||||
|
closed when its sub dialog is executed
|
||||||
|
- Removed bug in color icon generation
|
||||||
|
- Decimals attribute added to "double" property type
|
||||||
|
- PointF, SizeF and RectF types supported
|
||||||
|
- Proper translation calls for tree property browser
|
||||||
|
- QtProperty - ensure inserted subproperty is different from
|
||||||
|
"this" property
|
||||||
|
- QtBrowserItem class introduced, useful for identifying browser's
|
||||||
|
gui elements
|
||||||
|
- Possibility to control expanded state of QtTreePropertyBrowser's
|
||||||
|
items from code
|
||||||
|
- QtTreePropertyBrowser - "resizeMode" and "splitterPosition"
|
||||||
|
properties added
|
||||||
|
- QtGroupBoxPropertyBrowser - fixed crash in case of deleting the
|
||||||
|
editor factory and then deleting the manager
|
||||||
|
- "Decoration" example added - it shows how to add new
|
||||||
|
responsibilities to the existing managers and editor factories
|
||||||
|
|
||||||
|
2.3: - Various bugfixes and improvements
|
||||||
|
- QtProperty - setModified() and isModified() methods added
|
||||||
|
- QtTreePropertyBrowser - disabling an item closes its editor
|
||||||
|
- KeySequence, Char, Locale and Cursor types supported
|
||||||
|
- Support for icons in enum type added
|
||||||
|
- Kerning subproperty exposed in Font type
|
||||||
|
- New property browser class added - QtButtonPropertyBrowser with
|
||||||
|
drop down button as a grouping element
|
||||||
|
|
||||||
|
2.4: - Fixed memory leak of QtProperty
|
||||||
|
- QtTreePropertyBrowser - group items are rendered better
|
||||||
|
- QtTreePropertyBrowser - propertiesWithoutValueMarked and
|
||||||
|
alternatingRowColors features added
|
||||||
|
- QtTreePropertyBrowser - possibility of coloring properties added
|
||||||
|
- QtTreePropertyBrowser - keyboard navigation improved
|
||||||
|
- New factories providing popup dialogs added:
|
||||||
|
QtColorEditorFactory and QtFontEditorFactory
|
||||||
|
- Single step attribute added to: QtIntPropertyManager and
|
||||||
|
QtDoublePropertyManager
|
||||||
|
|
||||||
|
2.5: - "Object Controller" example added. It implements a similar
|
||||||
|
widget to the property editor in QDesigner
|
||||||
|
- Compile with QT_NO_CURSOR
|
||||||
|
- Expand root item with single click on the '+' icon
|
||||||
|
- QtRectPropertyManager and QtRectFPropertyManager - by default
|
||||||
|
constraint is null rect meaning no constraint is applied
|
||||||
|
|
||||||
|
2.6: - QtGroupPropertyBrowser - don't force the layout to show the
|
||||||
|
whole labels' contents for read only properties, show tooltips for
|
||||||
|
them in addition.
|
||||||
|
- QtTreePropertyBrowser - fixed painting of the editor for color
|
||||||
|
property type when style sheet is used (QTSOLBUG-64).
|
||||||
|
- Make it possible to change the style of the checkboxes with a
|
||||||
|
stylesheet (QTSOLBUG-61).
|
||||||
|
- Change the minimum size of a combobox so that it can show at
|
||||||
|
least one character and an icon.
|
||||||
|
- Make it possible to properly style custom embedded editors (e.g.
|
||||||
|
the color editor provided with the solution).
|
||||||
|
|
||||||
36
UseQtPropertyBrowser.cmake.in
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
###########################################################################
|
||||||
|
#
|
||||||
|
# Library: CTK
|
||||||
|
#
|
||||||
|
# Copyright (c) Kitware Inc.
|
||||||
|
#
|
||||||
|
# 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.commontk.org/LICENSE
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
###########################################################################
|
||||||
|
|
||||||
|
#
|
||||||
|
# This module is provided as QtPropertyBrowser_USE_FILE by QtPropertyBrowserConfig.cmake.
|
||||||
|
# It can be INCLUDED in a project to load the needed compiler and linker
|
||||||
|
# settings to use QtPropertyBrowser.
|
||||||
|
#
|
||||||
|
|
||||||
|
IF(NOT QtPropertyBrowser_USE_FILE_INCLUDED)
|
||||||
|
SET(QtPropertyBrowser_USE_FILE_INCLUDED 1)
|
||||||
|
|
||||||
|
# Add include directories needed to use QtPropertyBrowser.
|
||||||
|
INCLUDE_DIRECTORIES(${QtPropertyBrowser_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
# Add link directories needed to use QtPropertyBrowser.
|
||||||
|
LINK_DIRECTORIES(${QtPropertyBrowser_LIBRARY_DIRS})
|
||||||
|
|
||||||
|
ENDIF()
|
||||||
55
cmake/AddQt.cmake
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
if(NOT QT_FOUND)
|
||||||
|
# --- QT5 ---
|
||||||
|
find_package(Qt5Core QUIET)
|
||||||
|
if(Qt5Core_FOUND)
|
||||||
|
find_package(Qt5Gui QUIET)
|
||||||
|
find_package(Qt5Widgets QUIET)
|
||||||
|
if(Qt5Gui_FOUND AND Qt5Widgets_FOUND)
|
||||||
|
set(QT5_FOUND ON)
|
||||||
|
set(QT_FOUND ON)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT QT_FOUND)
|
||||||
|
# --- QT4 ---
|
||||||
|
find_package(Qt4 QUIET)
|
||||||
|
if(QT4_FOUND)
|
||||||
|
set(QT_FOUND TRUE)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if(QT_FOUND)
|
||||||
|
if(NOT QT5_FOUND)
|
||||||
|
message ( STATUS "Using Qt4")
|
||||||
|
set( QT_VERSION_STRING "${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}")
|
||||||
|
set( QT_TARGETS "Qt4::QtGui")
|
||||||
|
else()
|
||||||
|
message ( STATUS "Using Qt5")
|
||||||
|
set( QT_VERSION_STRING ${Qt5Core_VERSION_STRING})
|
||||||
|
set( QT_TARGETS "Qt5::Gui;Qt5::Widgets")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
else()
|
||||||
|
message ( STATUS "Qt Not Found")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
#include some custom CMake util functions
|
||||||
|
INCLUDE(CommonCMakeUtils)
|
||||||
|
|
||||||
|
extract_target_properties(QT_TARGETS_DEPENDENCIES QT_TARGETS INTERFACE_LINK_LIBRARIES)
|
||||||
|
set (QT_ALL_TARGETS ${QT_TARGETS} ${QT_TARGETS_DEPENDENCIES})
|
||||||
|
list(REMOVE_DUPLICATES QT_ALL_TARGETS)
|
||||||
|
extract_target_properties(QT_INCLUDE_DIRS QT_ALL_TARGETS INTERFACE_INCLUDE_DIRECTORIES)
|
||||||
|
extract_target_properties(QT_COMPILE_DEFS QT_ALL_TARGETS INTERFACE_COMPILE_DEFINITIONS)
|
||||||
|
|
||||||
|
IF(QT_FOUND )
|
||||||
|
MESSAGE(STATUS "QT Version: ${QT_VERSION_STRING}")
|
||||||
|
MESSAGE(STATUS "QT_TARGETS: ${QT_TARGETS}")
|
||||||
|
MESSAGE(STATUS "QT_ALL_TARGETS: ${QT_ALL_TARGETS}")
|
||||||
|
MESSAGE(STATUS "QT_INCLUDE_DIRS: ${QT_INCLUDE_DIRS}")
|
||||||
|
MESSAGE(STATUS "QT_COMPILE_DEFS: ${QT_COMPILE_DEFS}")
|
||||||
|
ENDIF()
|
||||||
27
cmake/CommonCMakeUtils.cmake
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
# extract filename components of all items in src_list in dst_list
|
||||||
|
# example usage: extract_filename_components(ALL_LIBS_BASENAME ALL_LIBS NAME_WE)
|
||||||
|
macro(extract_filename_components dst_list src_list component)
|
||||||
|
set(list_var "${${src_list}}")
|
||||||
|
#message(STATUS "list_var: ${list_var}")
|
||||||
|
#message(STATUS "component: ${component}")
|
||||||
|
foreach(item ${list_var})
|
||||||
|
get_filename_component(BASENAME ${item} ${component})
|
||||||
|
list( APPEND ${dst_list} ${BASENAME})
|
||||||
|
endforeach()
|
||||||
|
#message(STATUS "dst_list: ${${dst_list}}")
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
|
||||||
|
# extract target properties of all items in src_list in dst_list
|
||||||
|
# example usage: extract_target_properties(QT_INCLUDES Qt5::Core INTERFACE_INCLUDE_DIR)
|
||||||
|
macro(extract_target_properties target_props target_list property)
|
||||||
|
set(list_var "${${target_list}}")
|
||||||
|
# message(STATUS "list_var: ${list_var}")
|
||||||
|
#message(STATUS "property: ${property}")
|
||||||
|
foreach(item ${list_var})
|
||||||
|
get_target_property(value ${item} ${property})
|
||||||
|
list( APPEND ${target_props} ${value})
|
||||||
|
endforeach()
|
||||||
|
#message(STATUS "target_props: ${${target_props}}")
|
||||||
|
list(REMOVE_DUPLICATES ${target_props})
|
||||||
|
endmacro()
|
||||||
BIN
doc/images/canvas_typed.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
doc/images/canvas_variant.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
doc/images/decoration.png
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
doc/images/demo.png
Normal file
|
After Width: | Height: | Size: 75 KiB |
BIN
doc/images/extension.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
BIN
doc/images/object_controller.png
Normal file
|
After Width: | Height: | Size: 39 KiB |
BIN
doc/images/qt-logo.png
Normal file
|
After Width: | Height: | Size: 4.0 KiB |
BIN
doc/images/qtbuttonpropertybrowser.png
Normal file
|
After Width: | Height: | Size: 7.0 KiB |
BIN
doc/images/qtgroupboxpropertybrowser.png
Normal file
|
After Width: | Height: | Size: 5.7 KiB |
BIN
doc/images/qtpropertybrowser-duplicate.png
Normal file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
doc/images/qtpropertybrowser.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
doc/images/qttreepropertybrowser.png
Normal file
|
After Width: | Height: | Size: 7.1 KiB |
BIN
doc/images/simple.png
Normal file
|
After Width: | Height: | Size: 9.3 KiB |
15
examples/CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
INCLUDE_DIRECTORIES(
|
||||||
|
${${PROJECT_NAME}_SOURCE_DIR}/src
|
||||||
|
)
|
||||||
|
|
||||||
|
# setting a common place to put all executable files
|
||||||
|
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||||
|
|
||||||
|
ADD_SUBDIRECTORY(canvas_typed)
|
||||||
|
ADD_SUBDIRECTORY(canvas_variant)
|
||||||
|
ADD_SUBDIRECTORY(decoration)
|
||||||
|
ADD_SUBDIRECTORY(demo)
|
||||||
|
ADD_SUBDIRECTORY(extension)
|
||||||
|
ADD_SUBDIRECTORY(object_controller)
|
||||||
|
ADD_SUBDIRECTORY(simple)
|
||||||
19
examples/canvas_typed/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Tell CMake to run moc when necessary:
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
|
||||||
|
# As moc files are generated in the binary dir, tell CMake
|
||||||
|
# to always look for includes there:
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
|
SET(example_name canvas_typed)
|
||||||
|
|
||||||
|
SET(KIT_SRCS
|
||||||
|
main.cpp
|
||||||
|
mainwindow.cpp
|
||||||
|
mainwindow.h
|
||||||
|
qtcanvas.cpp
|
||||||
|
qtcanvas.h
|
||||||
|
)
|
||||||
|
|
||||||
|
ADD_EXECUTABLE(${example_name} ${KIT_SRCS})
|
||||||
|
TARGET_LINK_LIBRARIES(${example_name} ${PROJECT_NAME} ${QT_TARGETS})
|
||||||
96
examples/canvas_typed/canvas_typed.qdoc
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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."
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\page qtpropertybrowser-example-canvas_typed.html
|
||||||
|
|
||||||
|
\title Type Based Canvas Example
|
||||||
|
|
||||||
|
This example demonstrates how to use different
|
||||||
|
QtAbstractPropertyManager subclasses for different property
|
||||||
|
types. Using this approach, the developer interfaces with a
|
||||||
|
type-safe API (since each manager has its own property-type
|
||||||
|
specific API).
|
||||||
|
|
||||||
|
\image canvas_typed.png
|
||||||
|
|
||||||
|
The example presents a canvas filled up with items of different
|
||||||
|
types, and a tree property browser which displays the currently
|
||||||
|
selected item's properties.
|
||||||
|
|
||||||
|
All item types has a few common properties like "Position X", "Position Y"
|
||||||
|
or "Position Z", but each type also adds its own type-specific
|
||||||
|
properties (e.g. the text items provide "Text" and "Font"
|
||||||
|
properties, and the line items provide a "Vector" property).
|
||||||
|
|
||||||
|
The source files can be found in examples/canvas_typed directory
|
||||||
|
of the package.
|
||||||
|
|
||||||
|
\section1 Third party copyright notice
|
||||||
|
|
||||||
|
The canvas class used in this example contains third party code
|
||||||
|
with the following copyright notice:
|
||||||
|
|
||||||
|
\legalese
|
||||||
|
\code
|
||||||
|
|
||||||
|
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
|
||||||
|
|
||||||
|
All Rights Reserved
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and distribute this software and its
|
||||||
|
documentation for any purpose and without fee is hereby granted,
|
||||||
|
provided that the above copyright notice appear in all copies and that
|
||||||
|
both that copyright notice and this permission notice appear in
|
||||||
|
supporting documentation, and that the name of Digital not be
|
||||||
|
used in advertising or publicity pertaining to distribution of the
|
||||||
|
software without specific, written prior permission.
|
||||||
|
|
||||||
|
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||||
|
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||||
|
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
||||||
|
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||||
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
\endcode
|
||||||
|
\endlegalese
|
||||||
|
|
||||||
|
*/
|
||||||
51
examples/canvas_typed/main.cpp
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 <QApplication>
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
|
MainWindow mw;
|
||||||
|
mw.show();
|
||||||
|
|
||||||
|
return app.exec();
|
||||||
|
}
|
||||||
521
examples/canvas_typed/mainwindow.cpp
Normal file
@@ -0,0 +1,521 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 "mainwindow.h"
|
||||||
|
#include "qtpropertymanager.h"
|
||||||
|
#include "qteditorfactory.h"
|
||||||
|
#include "qttreepropertybrowser.h"
|
||||||
|
#include <QMatrix>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <QMenuBar>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QAction>
|
||||||
|
#include <QDockWidget>
|
||||||
|
|
||||||
|
void CanvasView::contentsMousePressEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
handleMouseClickEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CanvasView::contentsMouseDoubleClickEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
handleMouseClickEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CanvasView::handleMouseClickEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
QPoint p = inverseWorldMatrix().map(event->pos());
|
||||||
|
QtCanvasItemList l = canvas()->collisions(p);
|
||||||
|
moving = 0;
|
||||||
|
if (!l.isEmpty())
|
||||||
|
moving = l.first();
|
||||||
|
moving_start = p;
|
||||||
|
emit itemClicked(moving);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CanvasView::contentsMouseMoveEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
if (moving) {
|
||||||
|
QPoint p = inverseWorldMatrix().map(event->pos());
|
||||||
|
moving->moveBy(p.x() - moving_start.x(), p.y() - moving_start.y());
|
||||||
|
moving_start = p;
|
||||||
|
canvas()->update();
|
||||||
|
emit itemMoved(moving);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
|
: QMainWindow(parent)
|
||||||
|
{
|
||||||
|
QMenu *editMenu = menuBar()->addMenu(tr("Edit"));
|
||||||
|
QMenu *newObjectMenu = editMenu->addMenu(tr("New Object"));
|
||||||
|
|
||||||
|
QAction *newRectangleAction = new QAction(tr("Rectangle"), this);
|
||||||
|
connect(newRectangleAction, SIGNAL(triggered(bool)), this, SLOT(newRectangle()));
|
||||||
|
newObjectMenu->addAction(newRectangleAction);
|
||||||
|
|
||||||
|
QAction *newLineAction = new QAction(tr("Line"), this);
|
||||||
|
connect(newLineAction, SIGNAL(triggered(bool)), this, SLOT(newLine()));
|
||||||
|
newObjectMenu->addAction(newLineAction);
|
||||||
|
|
||||||
|
QAction *newEllipseAction = new QAction(tr("Ellipse"), this);
|
||||||
|
connect(newEllipseAction, SIGNAL(triggered(bool)), this, SLOT(newEllipse()));
|
||||||
|
newObjectMenu->addAction(newEllipseAction);
|
||||||
|
|
||||||
|
QAction *newTextAction = new QAction(tr("Text"), this);
|
||||||
|
connect(newTextAction, SIGNAL(triggered(bool)), this, SLOT(newText()));
|
||||||
|
newObjectMenu->addAction(newTextAction);
|
||||||
|
|
||||||
|
deleteAction = new QAction(tr("Delete Object"), this);
|
||||||
|
connect(deleteAction, SIGNAL(triggered(bool)), this, SLOT(deleteObject()));
|
||||||
|
editMenu->addAction(deleteAction);
|
||||||
|
|
||||||
|
QAction *clearAction = new QAction(tr("Clear All"), this);
|
||||||
|
connect(clearAction, SIGNAL(triggered(bool)), this, SLOT(clearAll()));
|
||||||
|
editMenu->addAction(clearAction);
|
||||||
|
|
||||||
|
QAction *fillAction = new QAction(tr("Fill View"), this);
|
||||||
|
connect(fillAction, SIGNAL(triggered(bool)), this, SLOT(fillView()));
|
||||||
|
editMenu->addAction(fillAction);
|
||||||
|
|
||||||
|
doubleManager = new QtDoublePropertyManager(this);
|
||||||
|
stringManager = new QtStringPropertyManager(this);
|
||||||
|
colorManager = new QtColorPropertyManager(this);
|
||||||
|
fontManager = new QtFontPropertyManager(this);
|
||||||
|
pointManager = new QtPointPropertyManager(this);
|
||||||
|
sizeManager = new QtSizePropertyManager(this);
|
||||||
|
|
||||||
|
connect(doubleManager, SIGNAL(valueChanged(QtProperty *, double)),
|
||||||
|
this, SLOT(valueChanged(QtProperty *, double)));
|
||||||
|
connect(stringManager, SIGNAL(valueChanged(QtProperty *, const QString &)),
|
||||||
|
this, SLOT(valueChanged(QtProperty *, const QString &)));
|
||||||
|
connect(colorManager, SIGNAL(valueChanged(QtProperty *, const QColor &)),
|
||||||
|
this, SLOT(valueChanged(QtProperty *, const QColor &)));
|
||||||
|
connect(fontManager, SIGNAL(valueChanged(QtProperty *, const QFont &)),
|
||||||
|
this, SLOT(valueChanged(QtProperty *, const QFont &)));
|
||||||
|
connect(pointManager, SIGNAL(valueChanged(QtProperty *, const QPoint &)),
|
||||||
|
this, SLOT(valueChanged(QtProperty *, const QPoint &)));
|
||||||
|
connect(sizeManager, SIGNAL(valueChanged(QtProperty *, const QSize &)),
|
||||||
|
this, SLOT(valueChanged(QtProperty *, const QSize &)));
|
||||||
|
|
||||||
|
QtDoubleSpinBoxFactory *doubleSpinBoxFactory = new QtDoubleSpinBoxFactory(this);
|
||||||
|
QtCheckBoxFactory *checkBoxFactory = new QtCheckBoxFactory(this);
|
||||||
|
QtSpinBoxFactory *spinBoxFactory = new QtSpinBoxFactory(this);
|
||||||
|
QtLineEditFactory *lineEditFactory = new QtLineEditFactory(this);
|
||||||
|
QtEnumEditorFactory *comboBoxFactory = new QtEnumEditorFactory(this);
|
||||||
|
|
||||||
|
canvas = new QtCanvas(800, 600);
|
||||||
|
canvasView = new CanvasView(canvas, this);
|
||||||
|
setCentralWidget(canvasView);
|
||||||
|
|
||||||
|
QDockWidget *dock = new QDockWidget(this);
|
||||||
|
addDockWidget(Qt::RightDockWidgetArea, dock);
|
||||||
|
|
||||||
|
propertyEditor = new QtTreePropertyBrowser(dock);
|
||||||
|
propertyEditor->setFactoryForManager(doubleManager, doubleSpinBoxFactory);
|
||||||
|
propertyEditor->setFactoryForManager(stringManager, lineEditFactory);
|
||||||
|
propertyEditor->setFactoryForManager(colorManager->subIntPropertyManager(), spinBoxFactory);
|
||||||
|
propertyEditor->setFactoryForManager(fontManager->subIntPropertyManager(), spinBoxFactory);
|
||||||
|
propertyEditor->setFactoryForManager(fontManager->subBoolPropertyManager(), checkBoxFactory);
|
||||||
|
propertyEditor->setFactoryForManager(fontManager->subEnumPropertyManager(), comboBoxFactory);
|
||||||
|
propertyEditor->setFactoryForManager(pointManager->subIntPropertyManager(), spinBoxFactory);
|
||||||
|
propertyEditor->setFactoryForManager(sizeManager->subIntPropertyManager(), spinBoxFactory);
|
||||||
|
dock->setWidget(propertyEditor);
|
||||||
|
|
||||||
|
currentItem = 0;
|
||||||
|
|
||||||
|
connect(canvasView, SIGNAL(itemClicked(QtCanvasItem *)),
|
||||||
|
this, SLOT(itemClicked(QtCanvasItem *)));
|
||||||
|
connect(canvasView, SIGNAL(itemMoved(QtCanvasItem *)),
|
||||||
|
this, SLOT(itemMoved(QtCanvasItem *)));
|
||||||
|
|
||||||
|
fillView();
|
||||||
|
itemClicked(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::newRectangle()
|
||||||
|
{
|
||||||
|
QtCanvasItem *item = addRectangle();
|
||||||
|
canvas->update();
|
||||||
|
itemClicked(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::newEllipse()
|
||||||
|
{
|
||||||
|
QtCanvasItem *item = addEllipse();
|
||||||
|
canvas->update();
|
||||||
|
itemClicked(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::newLine()
|
||||||
|
{
|
||||||
|
QtCanvasItem *item = addLine();
|
||||||
|
canvas->update();
|
||||||
|
itemClicked(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::newText()
|
||||||
|
{
|
||||||
|
QtCanvasItem *item = addText();
|
||||||
|
canvas->update();
|
||||||
|
itemClicked(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::deleteObject()
|
||||||
|
{
|
||||||
|
if (!currentItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
delete currentItem;
|
||||||
|
itemClicked(0);
|
||||||
|
canvas->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::clearAll()
|
||||||
|
{
|
||||||
|
QtCanvasItemList list = canvas->allItems();
|
||||||
|
qDeleteAll(list);
|
||||||
|
itemClicked(0);
|
||||||
|
canvas->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::fillView()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
addRectangle();
|
||||||
|
addEllipse();
|
||||||
|
addLine();
|
||||||
|
addText();
|
||||||
|
}
|
||||||
|
canvas->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
QtCanvasItem *MainWindow::addRectangle()
|
||||||
|
{
|
||||||
|
QtCanvasPolygonalItem *item = new QtCanvasRectangle(rand() % canvas->width(),
|
||||||
|
rand() % canvas->height(), 50, 50, canvas);
|
||||||
|
int z = rand() % 256;
|
||||||
|
item->setBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
|
||||||
|
item->setPen(QPen(QColor(rand() % 32*8, rand() % 32*8, rand() % 32*8), 4));
|
||||||
|
item->setZ(z);
|
||||||
|
item->show();
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
QtCanvasItem *MainWindow::addEllipse()
|
||||||
|
{
|
||||||
|
QtCanvasPolygonalItem *item = new QtCanvasEllipse(50, 50, canvas);
|
||||||
|
item->setBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
|
||||||
|
item->move(rand() % canvas->width(), rand() % canvas->height());
|
||||||
|
item->setZ(rand() % 256);
|
||||||
|
item->show();
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
QtCanvasItem *MainWindow::addLine()
|
||||||
|
{
|
||||||
|
QtCanvasLine *item = new QtCanvasLine(canvas);
|
||||||
|
item->setPoints(0, 0, rand() % canvas->width() - canvas->width() / 2,
|
||||||
|
rand() % canvas->height() - canvas->height() / 2);
|
||||||
|
item->move(rand() % canvas->width(), rand() % canvas->height());
|
||||||
|
item->setPen(QPen(QColor(rand() % 32*8, rand() % 32*8, rand() % 32*8), 6));
|
||||||
|
item->setZ(rand() % 256);
|
||||||
|
item->show();
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
QtCanvasItem *MainWindow::addText()
|
||||||
|
{
|
||||||
|
QtCanvasText *item = new QtCanvasText(canvas);
|
||||||
|
item->setText(tr("Text"));
|
||||||
|
item->setColor(QColor(rand() % 32*8, rand() % 32*8, rand() % 32*8));
|
||||||
|
item->move(rand() % canvas->width(), rand() % canvas->height());
|
||||||
|
item->setZ(rand() % 256);
|
||||||
|
item->show();
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::itemMoved(QtCanvasItem *item)
|
||||||
|
{
|
||||||
|
if (item != currentItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
doubleManager->setValue(idToProperty[QLatin1String("xpos")], item->x());
|
||||||
|
doubleManager->setValue(idToProperty[QLatin1String("ypos")], item->y());
|
||||||
|
doubleManager->setValue(idToProperty[QLatin1String("zpos")], item->z());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::updateExpandState()
|
||||||
|
{
|
||||||
|
QList<QtBrowserItem *> list = propertyEditor->topLevelItems();
|
||||||
|
QListIterator<QtBrowserItem *> it(list);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
QtBrowserItem *item = it.next();
|
||||||
|
QtProperty *prop = item->property();
|
||||||
|
idToExpanded[propertyToId[prop]] = propertyEditor->isExpanded(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::itemClicked(QtCanvasItem *item)
|
||||||
|
{
|
||||||
|
updateExpandState();
|
||||||
|
|
||||||
|
QMap<QtProperty *, QString>::ConstIterator itProp = propertyToId.constBegin();
|
||||||
|
while (itProp != propertyToId.constEnd()) {
|
||||||
|
delete itProp.key();
|
||||||
|
itProp++;
|
||||||
|
}
|
||||||
|
propertyToId.clear();
|
||||||
|
idToProperty.clear();
|
||||||
|
|
||||||
|
currentItem = item;
|
||||||
|
if (!currentItem) {
|
||||||
|
deleteAction->setEnabled(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteAction->setEnabled(true);
|
||||||
|
|
||||||
|
QtProperty *property;
|
||||||
|
|
||||||
|
property = doubleManager->addProperty(tr("Position X"));
|
||||||
|
doubleManager->setRange(property, 0, canvas->width());
|
||||||
|
doubleManager->setValue(property, item->x());
|
||||||
|
addProperty(property, QLatin1String("xpos"));
|
||||||
|
|
||||||
|
property = doubleManager->addProperty(tr("Position Y"));
|
||||||
|
doubleManager->setRange(property, 0, canvas->height());
|
||||||
|
doubleManager->setValue(property, item->y());
|
||||||
|
addProperty(property, QLatin1String("ypos"));
|
||||||
|
|
||||||
|
property = doubleManager->addProperty(tr("Position Z"));
|
||||||
|
doubleManager->setRange(property, 0, 256);
|
||||||
|
doubleManager->setValue(property, item->z());
|
||||||
|
addProperty(property, QLatin1String("zpos"));
|
||||||
|
|
||||||
|
if (item->rtti() == QtCanvasItem::Rtti_Rectangle) {
|
||||||
|
QtCanvasRectangle *i = (QtCanvasRectangle *)item;
|
||||||
|
|
||||||
|
property = colorManager->addProperty(tr("Brush Color"));
|
||||||
|
colorManager->setValue(property, i->brush().color());
|
||||||
|
addProperty(property, QLatin1String("brush"));
|
||||||
|
|
||||||
|
property = colorManager->addProperty(tr("Pen Color"));
|
||||||
|
colorManager->setValue(property, i->pen().color());
|
||||||
|
addProperty(property, QLatin1String("pen"));
|
||||||
|
|
||||||
|
property = sizeManager->addProperty(tr("Size"));
|
||||||
|
sizeManager->setValue(property, i->size());
|
||||||
|
addProperty(property, QLatin1String("size"));
|
||||||
|
} else if (item->rtti() == QtCanvasItem::Rtti_Line) {
|
||||||
|
QtCanvasLine *i = (QtCanvasLine *)item;
|
||||||
|
|
||||||
|
property = colorManager->addProperty(tr("Pen Color"));
|
||||||
|
colorManager->setValue(property, i->pen().color());
|
||||||
|
addProperty(property, QLatin1String("pen"));
|
||||||
|
|
||||||
|
property = pointManager->addProperty(tr("Vector"));
|
||||||
|
pointManager->setValue(property, i->endPoint());
|
||||||
|
addProperty(property, QLatin1String("endpoint"));
|
||||||
|
} else if (item->rtti() == QtCanvasItem::Rtti_Ellipse) {
|
||||||
|
QtCanvasEllipse *i = (QtCanvasEllipse *)item;
|
||||||
|
|
||||||
|
property = colorManager->addProperty(tr("Brush Color"));
|
||||||
|
colorManager->setValue(property, i->brush().color());
|
||||||
|
addProperty(property, QLatin1String("brush"));
|
||||||
|
|
||||||
|
property = sizeManager->addProperty(tr("Size"));
|
||||||
|
sizeManager->setValue(property, QSize(i->width(), i->height()));
|
||||||
|
sizeManager->setRange(property, QSize(0, 0), QSize(1000, 1000));
|
||||||
|
addProperty(property, QLatin1String("size"));
|
||||||
|
} else if (item->rtti() == QtCanvasItem::Rtti_Text) {
|
||||||
|
QtCanvasText *i = (QtCanvasText *)item;
|
||||||
|
|
||||||
|
property = colorManager->addProperty(tr("Color"));
|
||||||
|
colorManager->setValue(property, i->color());
|
||||||
|
addProperty(property, QLatin1String("color"));
|
||||||
|
|
||||||
|
property = stringManager->addProperty(tr("Text"));
|
||||||
|
stringManager->setValue(property, i->text());
|
||||||
|
addProperty(property, QLatin1String("text"));
|
||||||
|
|
||||||
|
property = fontManager->addProperty(tr("Font"));
|
||||||
|
fontManager->setValue(property, i->font());
|
||||||
|
addProperty(property, QLatin1String("font"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::addProperty(QtProperty *property, const QString &id)
|
||||||
|
{
|
||||||
|
propertyToId[property] = id;
|
||||||
|
idToProperty[id] = property;
|
||||||
|
QtBrowserItem *item = propertyEditor->addProperty(property);
|
||||||
|
if (idToExpanded.contains(id))
|
||||||
|
propertyEditor->setExpanded(item, idToExpanded[id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::valueChanged(QtProperty *property, double value)
|
||||||
|
{
|
||||||
|
if (!propertyToId.contains(property))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!currentItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString id = propertyToId[property];
|
||||||
|
if (id == QLatin1String("xpos")) {
|
||||||
|
currentItem->setX(value);
|
||||||
|
} else if (id == QLatin1String("ypos")) {
|
||||||
|
currentItem->setY(value);
|
||||||
|
} else if (id == QLatin1String("zpos")) {
|
||||||
|
currentItem->setZ(value);
|
||||||
|
}
|
||||||
|
canvas->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::valueChanged(QtProperty *property, const QString &value)
|
||||||
|
{
|
||||||
|
if (!propertyToId.contains(property))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!currentItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString id = propertyToId[property];
|
||||||
|
if (id == QLatin1String("text")) {
|
||||||
|
if (currentItem->rtti() == QtCanvasItem::Rtti_Text) {
|
||||||
|
QtCanvasText *i = (QtCanvasText *)currentItem;
|
||||||
|
i->setText(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
canvas->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::valueChanged(QtProperty *property, const QColor &value)
|
||||||
|
{
|
||||||
|
if (!propertyToId.contains(property))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!currentItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString id = propertyToId[property];
|
||||||
|
if (id == QLatin1String("color")) {
|
||||||
|
if (currentItem->rtti() == QtCanvasItem::Rtti_Text) {
|
||||||
|
QtCanvasText *i = (QtCanvasText *)currentItem;
|
||||||
|
i->setColor(value);
|
||||||
|
}
|
||||||
|
} else if (id == QLatin1String("brush")) {
|
||||||
|
if (currentItem->rtti() == QtCanvasItem::Rtti_Rectangle ||
|
||||||
|
currentItem->rtti() == QtCanvasItem::Rtti_Ellipse) {
|
||||||
|
QtCanvasPolygonalItem *i = (QtCanvasPolygonalItem *)currentItem;
|
||||||
|
QBrush b = i->brush();
|
||||||
|
b.setColor(value);
|
||||||
|
i->setBrush(b);
|
||||||
|
}
|
||||||
|
} else if (id == QLatin1String("pen")) {
|
||||||
|
if (currentItem->rtti() == QtCanvasItem::Rtti_Rectangle ||
|
||||||
|
currentItem->rtti() == QtCanvasItem::Rtti_Line) {
|
||||||
|
QtCanvasPolygonalItem *i = (QtCanvasPolygonalItem *)currentItem;
|
||||||
|
QPen p = i->pen();
|
||||||
|
p.setColor(value);
|
||||||
|
i->setPen(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
canvas->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::valueChanged(QtProperty *property, const QFont &value)
|
||||||
|
{
|
||||||
|
if (!propertyToId.contains(property))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!currentItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString id = propertyToId[property];
|
||||||
|
if (id == QLatin1String("font")) {
|
||||||
|
if (currentItem->rtti() == QtCanvasItem::Rtti_Text) {
|
||||||
|
QtCanvasText *i = (QtCanvasText *)currentItem;
|
||||||
|
i->setFont(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
canvas->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::valueChanged(QtProperty *property, const QPoint &value)
|
||||||
|
{
|
||||||
|
if (!propertyToId.contains(property))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!currentItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString id = propertyToId[property];
|
||||||
|
if (currentItem->rtti() == QtCanvasItem::Rtti_Line) {
|
||||||
|
QtCanvasLine *i = (QtCanvasLine *)currentItem;
|
||||||
|
if (id == QLatin1String("endpoint")) {
|
||||||
|
i->setPoints(i->startPoint().x(), i->startPoint().y(), value.x(), value.y());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
canvas->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::valueChanged(QtProperty *property, const QSize &value)
|
||||||
|
{
|
||||||
|
if (!propertyToId.contains(property))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!currentItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString id = propertyToId[property];
|
||||||
|
if (id == QLatin1String("size")) {
|
||||||
|
if (currentItem->rtti() == QtCanvasItem::Rtti_Rectangle) {
|
||||||
|
QtCanvasRectangle *i = (QtCanvasRectangle *)currentItem;
|
||||||
|
i->setSize(value.width(), value.height());
|
||||||
|
} else if (currentItem->rtti() == QtCanvasItem::Rtti_Ellipse) {
|
||||||
|
QtCanvasEllipse *i = (QtCanvasEllipse *)currentItem;
|
||||||
|
i->setSize(value.width(), value.height());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
canvas->update();
|
||||||
|
}
|
||||||
|
|
||||||
120
examples/canvas_typed/mainwindow.h
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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."
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef MAINWINDOW_H
|
||||||
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QMap>
|
||||||
|
#include "qtcanvas.h"
|
||||||
|
|
||||||
|
class QtProperty;
|
||||||
|
|
||||||
|
class CanvasView : public QtCanvasView
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
CanvasView(QWidget *parent = 0)
|
||||||
|
: QtCanvasView(parent), moving(0) { }
|
||||||
|
CanvasView(QtCanvas *canvas, QWidget *parent = 0)
|
||||||
|
: QtCanvasView(canvas, parent), moving(0) { }
|
||||||
|
signals:
|
||||||
|
void itemClicked(QtCanvasItem *item);
|
||||||
|
void itemMoved(QtCanvasItem *item);
|
||||||
|
protected:
|
||||||
|
void contentsMousePressEvent(QMouseEvent *event);
|
||||||
|
void contentsMouseDoubleClickEvent(QMouseEvent *event);
|
||||||
|
void contentsMouseMoveEvent(QMouseEvent* event);
|
||||||
|
private:
|
||||||
|
void handleMouseClickEvent(QMouseEvent *event);
|
||||||
|
QPoint moving_start;
|
||||||
|
QtCanvasItem *moving;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MainWindow : public QMainWindow
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
MainWindow(QWidget *parent = 0);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void newRectangle();
|
||||||
|
void newEllipse();
|
||||||
|
void newLine();
|
||||||
|
void newText();
|
||||||
|
void deleteObject();
|
||||||
|
void clearAll();
|
||||||
|
void fillView();
|
||||||
|
|
||||||
|
void itemClicked(QtCanvasItem *item);
|
||||||
|
void itemMoved(QtCanvasItem *item);
|
||||||
|
void valueChanged(QtProperty *property, double value);
|
||||||
|
void valueChanged(QtProperty *property, const QString &value);
|
||||||
|
void valueChanged(QtProperty *property, const QColor &value);
|
||||||
|
void valueChanged(QtProperty *property, const QFont &value);
|
||||||
|
void valueChanged(QtProperty *property, const QPoint &value);
|
||||||
|
void valueChanged(QtProperty *property, const QSize &value);
|
||||||
|
private:
|
||||||
|
|
||||||
|
QtCanvasItem *addRectangle();
|
||||||
|
QtCanvasItem *addEllipse();
|
||||||
|
QtCanvasItem *addLine();
|
||||||
|
QtCanvasItem *addText();
|
||||||
|
void addProperty(QtProperty *property, const QString &id);
|
||||||
|
void updateExpandState();
|
||||||
|
|
||||||
|
QAction *deleteAction;
|
||||||
|
|
||||||
|
class QtDoublePropertyManager *doubleManager;
|
||||||
|
class QtStringPropertyManager *stringManager;
|
||||||
|
class QtColorPropertyManager *colorManager;
|
||||||
|
class QtFontPropertyManager *fontManager;
|
||||||
|
class QtPointPropertyManager *pointManager;
|
||||||
|
class QtSizePropertyManager *sizeManager;
|
||||||
|
|
||||||
|
class QtTreePropertyBrowser *propertyEditor;
|
||||||
|
CanvasView *canvasView;
|
||||||
|
QtCanvas *canvas;
|
||||||
|
QtCanvasItem *currentItem;
|
||||||
|
QMap<QtProperty *, QString> propertyToId;
|
||||||
|
QMap<QString, QtProperty *> idToProperty;
|
||||||
|
QMap<QString, bool> idToExpanded;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
5906
examples/canvas_typed/qtcanvas.cpp
Normal file
778
examples/canvas_typed/qtcanvas.h
Normal file
@@ -0,0 +1,778 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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."
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef QTCANVAS_H
|
||||||
|
#define QTCANVAS_H
|
||||||
|
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QBrush>
|
||||||
|
#include <QPen>
|
||||||
|
#include <QPolygon>
|
||||||
|
#include <QScrollArea>
|
||||||
|
|
||||||
|
class QtCanvasSprite;
|
||||||
|
class QtCanvasPolygonalItem;
|
||||||
|
class QtCanvasRectangle;
|
||||||
|
class QtCanvasPolygon;
|
||||||
|
class QtCanvasEllipse;
|
||||||
|
class QtCanvasText;
|
||||||
|
class QtCanvasLine;
|
||||||
|
class QtCanvasChunk;
|
||||||
|
class QtCanvas;
|
||||||
|
class QtCanvasItem;
|
||||||
|
class QtCanvasView;
|
||||||
|
class QtCanvasPixmap;
|
||||||
|
|
||||||
|
typedef QList<QtCanvasItem *> QtCanvasItemList;
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasItemExtra;
|
||||||
|
|
||||||
|
class QtCanvasItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtCanvasItem(QtCanvas* canvas);
|
||||||
|
virtual ~QtCanvasItem();
|
||||||
|
|
||||||
|
double x() const
|
||||||
|
{ return myx; }
|
||||||
|
double y() const
|
||||||
|
{ return myy; }
|
||||||
|
double z() const
|
||||||
|
{ return myz; } // (depth)
|
||||||
|
|
||||||
|
virtual void moveBy(double dx, double dy);
|
||||||
|
void move(double x, double y);
|
||||||
|
void setX(double a) { move(a,y()); }
|
||||||
|
void setY(double a) { move(x(),a); }
|
||||||
|
void setZ(double a) { myz=a; changeChunks(); }
|
||||||
|
|
||||||
|
bool animated() const;
|
||||||
|
virtual void setAnimated(bool y);
|
||||||
|
virtual void setVelocity(double vx, double vy);
|
||||||
|
void setXVelocity(double vx) { setVelocity(vx,yVelocity()); }
|
||||||
|
void setYVelocity(double vy) { setVelocity(xVelocity(),vy); }
|
||||||
|
double xVelocity() const;
|
||||||
|
double yVelocity() const;
|
||||||
|
virtual void advance(int stage);
|
||||||
|
|
||||||
|
virtual bool collidesWith(const QtCanvasItem*) const=0;
|
||||||
|
|
||||||
|
QtCanvasItemList collisions(bool exact /* NO DEFAULT */) const;
|
||||||
|
|
||||||
|
virtual void setCanvas(QtCanvas*);
|
||||||
|
|
||||||
|
virtual void draw(QPainter&)=0;
|
||||||
|
|
||||||
|
void show();
|
||||||
|
void hide();
|
||||||
|
|
||||||
|
virtual void setVisible(bool yes);
|
||||||
|
bool isVisible() const
|
||||||
|
{ return (bool)vis; }
|
||||||
|
virtual void setSelected(bool yes);
|
||||||
|
bool isSelected() const
|
||||||
|
{ return (bool)sel; }
|
||||||
|
virtual void setEnabled(bool yes);
|
||||||
|
bool isEnabled() const
|
||||||
|
{ return (bool)ena; }
|
||||||
|
virtual void setActive(bool yes);
|
||||||
|
bool isActive() const
|
||||||
|
{ return (bool)act; }
|
||||||
|
bool visible() const
|
||||||
|
{ return (bool)vis; }
|
||||||
|
bool selected() const
|
||||||
|
{ return (bool)sel; }
|
||||||
|
bool enabled() const
|
||||||
|
{ return (bool)ena; }
|
||||||
|
bool active() const
|
||||||
|
{ return (bool)act; }
|
||||||
|
|
||||||
|
enum RttiValues {
|
||||||
|
Rtti_Item = 0,
|
||||||
|
Rtti_Sprite = 1,
|
||||||
|
Rtti_PolygonalItem = 2,
|
||||||
|
Rtti_Text = 3,
|
||||||
|
Rtti_Polygon = 4,
|
||||||
|
Rtti_Rectangle = 5,
|
||||||
|
Rtti_Ellipse = 6,
|
||||||
|
Rtti_Line = 7,
|
||||||
|
Rtti_Spline = 8
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual int rtti() const;
|
||||||
|
static int RTTI;
|
||||||
|
|
||||||
|
virtual QRect boundingRect() const=0;
|
||||||
|
virtual QRect boundingRectAdvanced() const;
|
||||||
|
|
||||||
|
QtCanvas* canvas() const
|
||||||
|
{ return cnv; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void update() { changeChunks(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
// For friendly subclasses...
|
||||||
|
|
||||||
|
friend class QtCanvasPolygonalItem;
|
||||||
|
friend class QtCanvasSprite;
|
||||||
|
friend class QtCanvasRectangle;
|
||||||
|
friend class QtCanvasPolygon;
|
||||||
|
friend class QtCanvasEllipse;
|
||||||
|
friend class QtCanvasText;
|
||||||
|
friend class QtCanvasLine;
|
||||||
|
|
||||||
|
virtual QPolygon chunks() const;
|
||||||
|
virtual void addToChunks();
|
||||||
|
virtual void removeFromChunks();
|
||||||
|
virtual void changeChunks();
|
||||||
|
virtual bool collidesWith(const QtCanvasSprite*,
|
||||||
|
const QtCanvasPolygonalItem*,
|
||||||
|
const QtCanvasRectangle*,
|
||||||
|
const QtCanvasEllipse*,
|
||||||
|
const QtCanvasText*) const = 0;
|
||||||
|
// End of friend stuff
|
||||||
|
|
||||||
|
QtCanvas* cnv;
|
||||||
|
static QtCanvas* current_canvas;
|
||||||
|
double myx,myy,myz;
|
||||||
|
QtCanvasItemExtra *ext;
|
||||||
|
QtCanvasItemExtra& extra();
|
||||||
|
uint ani:1;
|
||||||
|
uint vis:1;
|
||||||
|
uint val:1;
|
||||||
|
uint sel:1;
|
||||||
|
uint ena:1;
|
||||||
|
uint act:1;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasData;
|
||||||
|
|
||||||
|
class QtCanvas : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
QtCanvas(QObject* parent = 0);
|
||||||
|
QtCanvas(int w, int h);
|
||||||
|
QtCanvas(QPixmap p, int h, int v, int tilewidth, int tileheight);
|
||||||
|
|
||||||
|
virtual ~QtCanvas();
|
||||||
|
|
||||||
|
virtual void setTiles(QPixmap tiles, int h, int v,
|
||||||
|
int tilewidth, int tileheight);
|
||||||
|
virtual void setBackgroundPixmap(const QPixmap& p);
|
||||||
|
QPixmap backgroundPixmap() const;
|
||||||
|
|
||||||
|
virtual void setBackgroundColor(const QColor& c);
|
||||||
|
QColor backgroundColor() const;
|
||||||
|
|
||||||
|
virtual void setTile(int x, int y, int tilenum);
|
||||||
|
int tile(int x, int y) const
|
||||||
|
{ return grid[x+y*htiles]; }
|
||||||
|
|
||||||
|
int tilesHorizontally() const
|
||||||
|
{ return htiles; }
|
||||||
|
int tilesVertically() const
|
||||||
|
{ return vtiles; }
|
||||||
|
|
||||||
|
int tileWidth() const
|
||||||
|
{ return tilew; }
|
||||||
|
int tileHeight() const
|
||||||
|
{ return tileh; }
|
||||||
|
|
||||||
|
virtual void resize(int width, int height);
|
||||||
|
int width() const
|
||||||
|
{ return awidth; }
|
||||||
|
int height() const
|
||||||
|
{ return aheight; }
|
||||||
|
QSize size() const
|
||||||
|
{ return QSize(awidth,aheight); }
|
||||||
|
QRect rect() const
|
||||||
|
{ return QRect(0, 0, awidth, aheight); }
|
||||||
|
bool onCanvas(int x, int y) const
|
||||||
|
{ return x>=0 && y>=0 && x<awidth && y<aheight; }
|
||||||
|
bool onCanvas(const QPoint& p) const
|
||||||
|
{ return onCanvas(p.x(),p.y()); }
|
||||||
|
bool validChunk(int x, int y) const
|
||||||
|
{ return x>=0 && y>=0 && x<chwidth && y<chheight; }
|
||||||
|
bool validChunk(const QPoint& p) const
|
||||||
|
{ return validChunk(p.x(),p.y()); }
|
||||||
|
|
||||||
|
int chunkSize() const
|
||||||
|
{ return chunksize; }
|
||||||
|
virtual void retune(int chunksize, int maxclusters=100);
|
||||||
|
|
||||||
|
bool sameChunk(int x1, int y1, int x2, int y2) const
|
||||||
|
{ return x1/chunksize==x2/chunksize && y1/chunksize==y2/chunksize; }
|
||||||
|
virtual void setChangedChunk(int i, int j);
|
||||||
|
virtual void setChangedChunkContaining(int x, int y);
|
||||||
|
virtual void setAllChanged();
|
||||||
|
virtual void setChanged(const QRect& area);
|
||||||
|
virtual void setUnchanged(const QRect& area);
|
||||||
|
|
||||||
|
// These call setChangedChunk.
|
||||||
|
void addItemToChunk(QtCanvasItem*, int i, int j);
|
||||||
|
void removeItemFromChunk(QtCanvasItem*, int i, int j);
|
||||||
|
void addItemToChunkContaining(QtCanvasItem*, int x, int y);
|
||||||
|
void removeItemFromChunkContaining(QtCanvasItem*, int x, int y);
|
||||||
|
|
||||||
|
QtCanvasItemList allItems();
|
||||||
|
QtCanvasItemList collisions(const QPoint&) const;
|
||||||
|
QtCanvasItemList collisions(const QRect&) const;
|
||||||
|
QtCanvasItemList collisions(const QPolygon& pa, const QtCanvasItem* item,
|
||||||
|
bool exact) const;
|
||||||
|
|
||||||
|
void drawArea(const QRect&, QPainter* p, bool double_buffer=false);
|
||||||
|
|
||||||
|
// These are for QtCanvasView to call
|
||||||
|
virtual void addView(QtCanvasView*);
|
||||||
|
virtual void removeView(QtCanvasView*);
|
||||||
|
|
||||||
|
void drawCanvasArea(const QRect&, QPainter* p=0, bool double_buffer=true);
|
||||||
|
void drawViewArea(QtCanvasView* view, QPainter* p, const QRect& r, bool dbuf);
|
||||||
|
|
||||||
|
// These are for QtCanvasItem to call
|
||||||
|
virtual void addItem(QtCanvasItem*);
|
||||||
|
virtual void addAnimation(QtCanvasItem*);
|
||||||
|
virtual void removeItem(QtCanvasItem*);
|
||||||
|
virtual void removeAnimation(QtCanvasItem*);
|
||||||
|
|
||||||
|
virtual void setAdvancePeriod(int ms);
|
||||||
|
virtual void setUpdatePeriod(int ms);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void resized();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual void advance();
|
||||||
|
virtual void update();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void drawBackground(QPainter&, const QRect& area);
|
||||||
|
virtual void drawForeground(QPainter&, const QRect& area);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void init(int w, int h, int chunksze=16, int maxclust=100);
|
||||||
|
|
||||||
|
QtCanvasChunk& chunk(int i, int j) const;
|
||||||
|
QtCanvasChunk& chunkContaining(int x, int y) const;
|
||||||
|
|
||||||
|
QRect changeBounds();
|
||||||
|
|
||||||
|
int awidth,aheight;
|
||||||
|
int chunksize;
|
||||||
|
int maxclusters;
|
||||||
|
int chwidth,chheight;
|
||||||
|
QtCanvasChunk* chunks;
|
||||||
|
|
||||||
|
QtCanvasData* d;
|
||||||
|
|
||||||
|
void initTiles(QPixmap p, int h, int v, int tilewidth, int tileheight);
|
||||||
|
ushort *grid;
|
||||||
|
ushort htiles;
|
||||||
|
ushort vtiles;
|
||||||
|
ushort tilew;
|
||||||
|
ushort tileh;
|
||||||
|
bool oneone;
|
||||||
|
QPixmap pm;
|
||||||
|
QTimer* update_timer;
|
||||||
|
QColor bgcolor;
|
||||||
|
bool debug_redraw_areas;
|
||||||
|
|
||||||
|
friend void qt_unview(QtCanvas* c);
|
||||||
|
|
||||||
|
Q_DISABLE_COPY(QtCanvas)
|
||||||
|
};
|
||||||
|
|
||||||
|
class QtCanvasViewData;
|
||||||
|
|
||||||
|
class QtCanvasView : public QScrollArea
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(bool highQualityRendering READ highQualityRendering WRITE setHighQualityRendering)
|
||||||
|
public:
|
||||||
|
|
||||||
|
QtCanvasView(QWidget* parent=0);
|
||||||
|
QtCanvasView(QtCanvas* viewing, QWidget* parent=0);
|
||||||
|
~QtCanvasView();
|
||||||
|
|
||||||
|
QtCanvas* canvas() const
|
||||||
|
{ return viewing; }
|
||||||
|
void setCanvas(QtCanvas* v);
|
||||||
|
|
||||||
|
const QMatrix &worldMatrix() const;
|
||||||
|
const QMatrix &inverseWorldMatrix() const;
|
||||||
|
bool setWorldMatrix(const QMatrix &);
|
||||||
|
|
||||||
|
virtual QSize sizeHint() const;
|
||||||
|
|
||||||
|
bool highQualityRendering() const;
|
||||||
|
public slots:
|
||||||
|
void setHighQualityRendering(bool enable);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
friend class QtCanvasWidget;
|
||||||
|
virtual void drawContents(QPainter *p, int cx, int cy, int cw, int ch);
|
||||||
|
|
||||||
|
virtual void contentsMousePressEvent( QMouseEvent* );
|
||||||
|
virtual void contentsMouseReleaseEvent( QMouseEvent* );
|
||||||
|
virtual void contentsMouseDoubleClickEvent( QMouseEvent* );
|
||||||
|
virtual void contentsMouseMoveEvent( QMouseEvent* );
|
||||||
|
virtual void contentsDragEnterEvent( QDragEnterEvent * );
|
||||||
|
virtual void contentsDragMoveEvent( QDragMoveEvent * );
|
||||||
|
virtual void contentsDragLeaveEvent( QDragLeaveEvent * );
|
||||||
|
virtual void contentsDropEvent( QDropEvent * );
|
||||||
|
virtual void contentsWheelEvent( QWheelEvent * );
|
||||||
|
virtual void contentsContextMenuEvent( QContextMenuEvent * );
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class QtCanvas;
|
||||||
|
void drawContents(QPainter*);
|
||||||
|
QtCanvas* viewing;
|
||||||
|
QtCanvasViewData* d;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void updateContentsSize();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(QtCanvasView)
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasPixmap : public QPixmap
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
#ifndef QT_NO_IMAGEIO
|
||||||
|
QtCanvasPixmap(const QString& datafilename);
|
||||||
|
#endif
|
||||||
|
QtCanvasPixmap(const QImage& image);
|
||||||
|
QtCanvasPixmap(const QPixmap&, const QPoint& hotspot);
|
||||||
|
~QtCanvasPixmap();
|
||||||
|
|
||||||
|
int offsetX() const
|
||||||
|
{ return hotx; }
|
||||||
|
int offsetY() const
|
||||||
|
{ return hoty; }
|
||||||
|
void setOffset(int x, int y) { hotx = x; hoty = y; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(QtCanvasPixmap)
|
||||||
|
|
||||||
|
void init(const QImage&);
|
||||||
|
void init(const QPixmap& pixmap, int hx, int hy);
|
||||||
|
|
||||||
|
friend class QtCanvasSprite;
|
||||||
|
friend class QtCanvasPixmapArray;
|
||||||
|
friend bool qt_testCollision(const QtCanvasSprite* s1, const QtCanvasSprite* s2);
|
||||||
|
|
||||||
|
int hotx,hoty;
|
||||||
|
|
||||||
|
QImage* collision_mask;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasPixmapArray
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtCanvasPixmapArray();
|
||||||
|
#ifndef QT_NO_IMAGEIO
|
||||||
|
QtCanvasPixmapArray(const QString& datafilenamepattern, int framecount=0);
|
||||||
|
#endif
|
||||||
|
QtCanvasPixmapArray(const QList<QPixmap> &pixmaps, const QPolygon &hotspots = QPolygon());
|
||||||
|
~QtCanvasPixmapArray();
|
||||||
|
|
||||||
|
#ifndef QT_NO_IMAGEIO
|
||||||
|
bool readPixmaps(const QString& datafilenamepattern, int framecount=0);
|
||||||
|
bool readCollisionMasks(const QString& filenamepattern);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// deprecated
|
||||||
|
bool operator!(); // Failure check.
|
||||||
|
bool isValid() const;
|
||||||
|
|
||||||
|
QtCanvasPixmap* image(int i) const
|
||||||
|
{ return img ? img[i] : 0; }
|
||||||
|
void setImage(int i, QtCanvasPixmap* p);
|
||||||
|
uint count() const
|
||||||
|
{ return (uint)framecount; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(QtCanvasPixmapArray)
|
||||||
|
|
||||||
|
#ifndef QT_NO_IMAGEIO
|
||||||
|
bool readPixmaps(const QString& datafilenamepattern, int framecount, bool maskonly);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
int framecount;
|
||||||
|
QtCanvasPixmap** img;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasSprite : public QtCanvasItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtCanvasSprite(QtCanvasPixmapArray* array, QtCanvas* canvas);
|
||||||
|
|
||||||
|
void setSequence(QtCanvasPixmapArray* seq);
|
||||||
|
|
||||||
|
virtual ~QtCanvasSprite();
|
||||||
|
|
||||||
|
void move(double x, double y);
|
||||||
|
virtual void move(double x, double y, int frame);
|
||||||
|
void setFrame(int);
|
||||||
|
enum FrameAnimationType { Cycle, Oscillate };
|
||||||
|
virtual void setFrameAnimation(FrameAnimationType=Cycle, int step=1, int state=0);
|
||||||
|
int frame() const
|
||||||
|
{ return frm; }
|
||||||
|
int frameCount() const
|
||||||
|
{ return images->count(); }
|
||||||
|
|
||||||
|
int rtti() const;
|
||||||
|
static int RTTI;
|
||||||
|
|
||||||
|
bool collidesWith(const QtCanvasItem*) const;
|
||||||
|
|
||||||
|
QRect boundingRect() const;
|
||||||
|
|
||||||
|
// is there a reason for these to be protected? Lars
|
||||||
|
//protected:
|
||||||
|
|
||||||
|
int width() const;
|
||||||
|
int height() const;
|
||||||
|
|
||||||
|
int leftEdge() const;
|
||||||
|
int topEdge() const;
|
||||||
|
int rightEdge() const;
|
||||||
|
int bottomEdge() const;
|
||||||
|
|
||||||
|
int leftEdge(int nx) const;
|
||||||
|
int topEdge(int ny) const;
|
||||||
|
int rightEdge(int nx) const;
|
||||||
|
int bottomEdge(int ny) const;
|
||||||
|
QtCanvasPixmap* image() const
|
||||||
|
{ return images->image(frm); }
|
||||||
|
virtual QtCanvasPixmap* imageAdvanced() const;
|
||||||
|
QtCanvasPixmap* image(int f) const
|
||||||
|
{ return images->image(f); }
|
||||||
|
virtual void advance(int stage);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void draw(QPainter& painter);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(QtCanvasSprite)
|
||||||
|
|
||||||
|
void addToChunks();
|
||||||
|
void removeFromChunks();
|
||||||
|
void changeChunks();
|
||||||
|
|
||||||
|
int frm;
|
||||||
|
ushort anim_val;
|
||||||
|
uint anim_state:2;
|
||||||
|
uint anim_type:14;
|
||||||
|
bool collidesWith(const QtCanvasSprite*,
|
||||||
|
const QtCanvasPolygonalItem*,
|
||||||
|
const QtCanvasRectangle*,
|
||||||
|
const QtCanvasEllipse*,
|
||||||
|
const QtCanvasText*) const;
|
||||||
|
|
||||||
|
friend bool qt_testCollision(const QtCanvasSprite* s1,
|
||||||
|
const QtCanvasSprite* s2);
|
||||||
|
|
||||||
|
QtCanvasPixmapArray* images;
|
||||||
|
};
|
||||||
|
|
||||||
|
class QPolygonalProcessor;
|
||||||
|
|
||||||
|
class QtCanvasPolygonalItem : public QtCanvasItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtCanvasPolygonalItem(QtCanvas* canvas);
|
||||||
|
virtual ~QtCanvasPolygonalItem();
|
||||||
|
|
||||||
|
bool collidesWith(const QtCanvasItem*) const;
|
||||||
|
|
||||||
|
virtual void setPen(QPen p);
|
||||||
|
virtual void setBrush(QBrush b);
|
||||||
|
|
||||||
|
QPen pen() const
|
||||||
|
{ return pn; }
|
||||||
|
QBrush brush() const
|
||||||
|
{ return br; }
|
||||||
|
|
||||||
|
virtual QPolygon areaPoints() const=0;
|
||||||
|
virtual QPolygon areaPointsAdvanced() const;
|
||||||
|
QRect boundingRect() const;
|
||||||
|
|
||||||
|
int rtti() const;
|
||||||
|
static int RTTI;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void draw(QPainter &);
|
||||||
|
virtual void drawShape(QPainter &) = 0;
|
||||||
|
|
||||||
|
bool winding() const;
|
||||||
|
void setWinding(bool);
|
||||||
|
|
||||||
|
void invalidate();
|
||||||
|
bool isValid() const
|
||||||
|
{ return (bool)val; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void scanPolygon(const QPolygon& pa, int winding,
|
||||||
|
QPolygonalProcessor& process) const;
|
||||||
|
QPolygon chunks() const;
|
||||||
|
|
||||||
|
bool collidesWith(const QtCanvasSprite*,
|
||||||
|
const QtCanvasPolygonalItem*,
|
||||||
|
const QtCanvasRectangle*,
|
||||||
|
const QtCanvasEllipse*,
|
||||||
|
const QtCanvasText*) const;
|
||||||
|
|
||||||
|
QBrush br;
|
||||||
|
QPen pn;
|
||||||
|
uint wind:1;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasRectangle : public QtCanvasPolygonalItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtCanvasRectangle(QtCanvas* canvas);
|
||||||
|
QtCanvasRectangle(const QRect&, QtCanvas* canvas);
|
||||||
|
QtCanvasRectangle(int x, int y, int width, int height, QtCanvas* canvas);
|
||||||
|
|
||||||
|
~QtCanvasRectangle();
|
||||||
|
|
||||||
|
int width() const;
|
||||||
|
int height() const;
|
||||||
|
void setSize(int w, int h);
|
||||||
|
QSize size() const
|
||||||
|
{ return QSize(w,h); }
|
||||||
|
QPolygon areaPoints() const;
|
||||||
|
QRect rect() const
|
||||||
|
{ return QRect(int(x()),int(y()),w,h); }
|
||||||
|
|
||||||
|
bool collidesWith(const QtCanvasItem*) const;
|
||||||
|
|
||||||
|
int rtti() const;
|
||||||
|
static int RTTI;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void drawShape(QPainter &);
|
||||||
|
QPolygon chunks() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool collidesWith( const QtCanvasSprite*,
|
||||||
|
const QtCanvasPolygonalItem*,
|
||||||
|
const QtCanvasRectangle*,
|
||||||
|
const QtCanvasEllipse*,
|
||||||
|
const QtCanvasText*) const;
|
||||||
|
|
||||||
|
int w, h;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasPolygon : public QtCanvasPolygonalItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtCanvasPolygon(QtCanvas* canvas);
|
||||||
|
~QtCanvasPolygon();
|
||||||
|
void setPoints(QPolygon);
|
||||||
|
QPolygon points() const;
|
||||||
|
void moveBy(double dx, double dy);
|
||||||
|
|
||||||
|
QPolygon areaPoints() const;
|
||||||
|
|
||||||
|
int rtti() const;
|
||||||
|
static int RTTI;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void drawShape(QPainter &);
|
||||||
|
QPolygon poly;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasSpline : public QtCanvasPolygon
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtCanvasSpline(QtCanvas* canvas);
|
||||||
|
~QtCanvasSpline();
|
||||||
|
|
||||||
|
void setControlPoints(QPolygon, bool closed=true);
|
||||||
|
QPolygon controlPoints() const;
|
||||||
|
bool closed() const;
|
||||||
|
|
||||||
|
int rtti() const;
|
||||||
|
static int RTTI;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void recalcPoly();
|
||||||
|
QPolygon bez;
|
||||||
|
bool cl;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasLine : public QtCanvasPolygonalItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtCanvasLine(QtCanvas* canvas);
|
||||||
|
~QtCanvasLine();
|
||||||
|
void setPoints(int x1, int y1, int x2, int y2);
|
||||||
|
|
||||||
|
QPoint startPoint() const
|
||||||
|
{ return QPoint(x1,y1); }
|
||||||
|
QPoint endPoint() const
|
||||||
|
{ return QPoint(x2,y2); }
|
||||||
|
|
||||||
|
int rtti() const;
|
||||||
|
static int RTTI;
|
||||||
|
|
||||||
|
void setPen(QPen p);
|
||||||
|
void moveBy(double dx, double dy);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void drawShape(QPainter &);
|
||||||
|
QPolygon areaPoints() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int x1,y1,x2,y2;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasEllipse : public QtCanvasPolygonalItem
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
QtCanvasEllipse(QtCanvas* canvas);
|
||||||
|
QtCanvasEllipse(int width, int height, QtCanvas* canvas);
|
||||||
|
QtCanvasEllipse(int width, int height, int startangle, int angle,
|
||||||
|
QtCanvas* canvas);
|
||||||
|
|
||||||
|
~QtCanvasEllipse();
|
||||||
|
|
||||||
|
int width() const;
|
||||||
|
int height() const;
|
||||||
|
void setSize(int w, int h);
|
||||||
|
void setAngles(int start, int length);
|
||||||
|
int angleStart() const
|
||||||
|
{ return a1; }
|
||||||
|
int angleLength() const
|
||||||
|
{ return a2; }
|
||||||
|
QPolygon areaPoints() const;
|
||||||
|
|
||||||
|
bool collidesWith(const QtCanvasItem*) const;
|
||||||
|
|
||||||
|
int rtti() const;
|
||||||
|
static int RTTI;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void drawShape(QPainter &);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool collidesWith(const QtCanvasSprite*,
|
||||||
|
const QtCanvasPolygonalItem*,
|
||||||
|
const QtCanvasRectangle*,
|
||||||
|
const QtCanvasEllipse*,
|
||||||
|
const QtCanvasText*) const;
|
||||||
|
int w, h;
|
||||||
|
int a1, a2;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasTextExtra;
|
||||||
|
|
||||||
|
class QtCanvasText : public QtCanvasItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtCanvasText(QtCanvas* canvas);
|
||||||
|
QtCanvasText(const QString&, QtCanvas* canvas);
|
||||||
|
QtCanvasText(const QString&, QFont, QtCanvas* canvas);
|
||||||
|
|
||||||
|
virtual ~QtCanvasText();
|
||||||
|
|
||||||
|
void setText(const QString&);
|
||||||
|
void setFont(const QFont&);
|
||||||
|
void setColor(const QColor&);
|
||||||
|
QString text() const;
|
||||||
|
QFont font() const;
|
||||||
|
QColor color() const;
|
||||||
|
|
||||||
|
void moveBy(double dx, double dy);
|
||||||
|
|
||||||
|
int textFlags() const
|
||||||
|
{ return flags; }
|
||||||
|
void setTextFlags(int);
|
||||||
|
|
||||||
|
QRect boundingRect() const;
|
||||||
|
|
||||||
|
bool collidesWith(const QtCanvasItem*) const;
|
||||||
|
|
||||||
|
int rtti() const;
|
||||||
|
static int RTTI;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void draw(QPainter&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(QtCanvasText)
|
||||||
|
|
||||||
|
void addToChunks();
|
||||||
|
void removeFromChunks();
|
||||||
|
void changeChunks();
|
||||||
|
|
||||||
|
void setRect();
|
||||||
|
QRect brect;
|
||||||
|
QString txt;
|
||||||
|
int flags;
|
||||||
|
QFont fnt;
|
||||||
|
QColor col;
|
||||||
|
QtCanvasTextExtra* extra;
|
||||||
|
|
||||||
|
bool collidesWith(const QtCanvasSprite*,
|
||||||
|
const QtCanvasPolygonalItem*,
|
||||||
|
const QtCanvasRectangle*,
|
||||||
|
const QtCanvasEllipse*,
|
||||||
|
const QtCanvasText*) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QTCANVAS_H
|
||||||
19
examples/canvas_variant/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# Tell CMake to run moc when necessary:
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
|
||||||
|
# As moc files are generated in the binary dir, tell CMake
|
||||||
|
# to always look for includes there:
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
|
SET(example_name canvas_variant)
|
||||||
|
|
||||||
|
SET(KIT_SRCS
|
||||||
|
main.cpp
|
||||||
|
mainwindow.cpp
|
||||||
|
mainwindow.h
|
||||||
|
qtcanvas.cpp
|
||||||
|
qtcanvas.h
|
||||||
|
)
|
||||||
|
|
||||||
|
ADD_EXECUTABLE(${example_name} ${KIT_SRCS})
|
||||||
|
TARGET_LINK_LIBRARIES(${example_name} ${PROJECT_NAME} ${QT_TARGETS})
|
||||||
94
examples/canvas_variant/canvas_variant.qdoc
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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."
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\page qtpropertybrowser-example-canvas_variant.html
|
||||||
|
\title Variant Based Canvas Example
|
||||||
|
|
||||||
|
This example demonstrates how to use the QtVariantPropertyManager
|
||||||
|
convenience class for all property types. In this approach only
|
||||||
|
one instance of the property manager class is used, and the
|
||||||
|
developer interfaces with a dynamic API based on QVariant.
|
||||||
|
|
||||||
|
\image canvas_variant.png
|
||||||
|
|
||||||
|
The example presents a canvas filled up with items of different
|
||||||
|
types, and a tree property browser which displays the currently
|
||||||
|
selected item's properties.
|
||||||
|
|
||||||
|
All item types has a few common properties like "Position X", "Position Y"
|
||||||
|
or "Position Z", but each type also adds its own type-specific
|
||||||
|
properties (e.g. the text items provide "Text" and "Font"
|
||||||
|
properties, and the line items provide a "Vector" property).
|
||||||
|
|
||||||
|
The source files can be found in examples/canvas_variant directory
|
||||||
|
of the package.
|
||||||
|
|
||||||
|
\section1 Third party copyright notice
|
||||||
|
|
||||||
|
The canvas class used in this example contains third party code
|
||||||
|
with the following copyright notice:
|
||||||
|
|
||||||
|
\legalese
|
||||||
|
\code
|
||||||
|
|
||||||
|
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
|
||||||
|
|
||||||
|
All Rights Reserved
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and distribute this software and its
|
||||||
|
documentation for any purpose and without fee is hereby granted,
|
||||||
|
provided that the above copyright notice appear in all copies and that
|
||||||
|
both that copyright notice and this permission notice appear in
|
||||||
|
supporting documentation, and that the name of Digital not be
|
||||||
|
used in advertising or publicity pertaining to distribution of the
|
||||||
|
software without specific, written prior permission.
|
||||||
|
|
||||||
|
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||||
|
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||||
|
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
||||||
|
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||||
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
\endcode
|
||||||
|
\endlegalese
|
||||||
|
|
||||||
|
*/
|
||||||
51
examples/canvas_variant/main.cpp
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 <QApplication>
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
|
MainWindow mw;
|
||||||
|
mw.show();
|
||||||
|
|
||||||
|
return app.exec();
|
||||||
|
}
|
||||||
434
examples/canvas_variant/mainwindow.cpp
Normal file
@@ -0,0 +1,434 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 "mainwindow.h"
|
||||||
|
#include "qtvariantproperty.h"
|
||||||
|
#include "qttreepropertybrowser.h"
|
||||||
|
#include <QMatrix>
|
||||||
|
#include <QMouseEvent>
|
||||||
|
#include <QMenuBar>
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QAction>
|
||||||
|
#include <QDockWidget>
|
||||||
|
|
||||||
|
void CanvasView::contentsMousePressEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
handleMouseClickEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CanvasView::contentsMouseDoubleClickEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
handleMouseClickEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CanvasView::handleMouseClickEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
QPoint p = inverseWorldMatrix().map(event->pos());
|
||||||
|
QtCanvasItemList l = canvas()->collisions(p);
|
||||||
|
moving = 0;
|
||||||
|
if (!l.isEmpty())
|
||||||
|
moving = l.first();
|
||||||
|
moving_start = p;
|
||||||
|
emit itemClicked(moving);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CanvasView::contentsMouseMoveEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
if (moving) {
|
||||||
|
QPoint p = inverseWorldMatrix().map(event->pos());
|
||||||
|
moving->moveBy(p.x() - moving_start.x(), p.y() - moving_start.y());
|
||||||
|
moving_start = p;
|
||||||
|
canvas()->update();
|
||||||
|
emit itemMoved(moving);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
|
: QMainWindow(parent)
|
||||||
|
{
|
||||||
|
QMenu *editMenu = menuBar()->addMenu(tr("Edit"));
|
||||||
|
QMenu *newObjectMenu = editMenu->addMenu(tr("New Object"));
|
||||||
|
|
||||||
|
QAction *newRectangleAction = new QAction(tr("Rectangle"), this);
|
||||||
|
connect(newRectangleAction, SIGNAL(triggered(bool)), this, SLOT(newRectangle()));
|
||||||
|
newObjectMenu->addAction(newRectangleAction);
|
||||||
|
|
||||||
|
QAction *newLineAction = new QAction(tr("Line"), this);
|
||||||
|
connect(newLineAction, SIGNAL(triggered(bool)), this, SLOT(newLine()));
|
||||||
|
newObjectMenu->addAction(newLineAction);
|
||||||
|
|
||||||
|
QAction *newEllipseAction = new QAction(tr("Ellipse"), this);
|
||||||
|
connect(newEllipseAction, SIGNAL(triggered(bool)), this, SLOT(newEllipse()));
|
||||||
|
newObjectMenu->addAction(newEllipseAction);
|
||||||
|
|
||||||
|
QAction *newTextAction = new QAction(tr("Text"), this);
|
||||||
|
connect(newTextAction, SIGNAL(triggered(bool)), this, SLOT(newText()));
|
||||||
|
newObjectMenu->addAction(newTextAction);
|
||||||
|
|
||||||
|
deleteAction = new QAction(tr("Delete Object"), this);
|
||||||
|
connect(deleteAction, SIGNAL(triggered(bool)), this, SLOT(deleteObject()));
|
||||||
|
editMenu->addAction(deleteAction);
|
||||||
|
|
||||||
|
QAction *clearAction = new QAction(tr("Clear All"), this);
|
||||||
|
connect(clearAction, SIGNAL(triggered(bool)), this, SLOT(clearAll()));
|
||||||
|
editMenu->addAction(clearAction);
|
||||||
|
|
||||||
|
QAction *fillAction = new QAction(tr("Fill View"), this);
|
||||||
|
connect(fillAction, SIGNAL(triggered(bool)), this, SLOT(fillView()));
|
||||||
|
editMenu->addAction(fillAction);
|
||||||
|
|
||||||
|
variantManager = new QtVariantPropertyManager(this);
|
||||||
|
|
||||||
|
connect(variantManager, SIGNAL(valueChanged(QtProperty *, const QVariant &)),
|
||||||
|
this, SLOT(valueChanged(QtProperty *, const QVariant &)));
|
||||||
|
|
||||||
|
QtVariantEditorFactory *variantFactory = new QtVariantEditorFactory(this);
|
||||||
|
|
||||||
|
canvas = new QtCanvas(800, 600);
|
||||||
|
canvasView = new CanvasView(canvas, this);
|
||||||
|
setCentralWidget(canvasView);
|
||||||
|
|
||||||
|
QDockWidget *dock = new QDockWidget(this);
|
||||||
|
addDockWidget(Qt::RightDockWidgetArea, dock);
|
||||||
|
|
||||||
|
propertyEditor = new QtTreePropertyBrowser(dock);
|
||||||
|
propertyEditor->setFactoryForManager(variantManager, variantFactory);
|
||||||
|
dock->setWidget(propertyEditor);
|
||||||
|
|
||||||
|
currentItem = 0;
|
||||||
|
|
||||||
|
connect(canvasView, SIGNAL(itemClicked(QtCanvasItem *)),
|
||||||
|
this, SLOT(itemClicked(QtCanvasItem *)));
|
||||||
|
connect(canvasView, SIGNAL(itemMoved(QtCanvasItem *)),
|
||||||
|
this, SLOT(itemMoved(QtCanvasItem *)));
|
||||||
|
|
||||||
|
fillView();
|
||||||
|
itemClicked(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::newRectangle()
|
||||||
|
{
|
||||||
|
QtCanvasItem *item = addRectangle();
|
||||||
|
canvas->update();
|
||||||
|
itemClicked(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::newEllipse()
|
||||||
|
{
|
||||||
|
QtCanvasItem *item = addEllipse();
|
||||||
|
canvas->update();
|
||||||
|
itemClicked(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::newLine()
|
||||||
|
{
|
||||||
|
QtCanvasItem *item = addLine();
|
||||||
|
canvas->update();
|
||||||
|
itemClicked(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::newText()
|
||||||
|
{
|
||||||
|
QtCanvasItem *item = addText();
|
||||||
|
canvas->update();
|
||||||
|
itemClicked(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::deleteObject()
|
||||||
|
{
|
||||||
|
if (!currentItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
delete currentItem;
|
||||||
|
itemClicked(0);
|
||||||
|
canvas->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::clearAll()
|
||||||
|
{
|
||||||
|
QtCanvasItemList list = canvas->allItems();
|
||||||
|
qDeleteAll(list);
|
||||||
|
itemClicked(0);
|
||||||
|
canvas->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::fillView()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
addRectangle();
|
||||||
|
addEllipse();
|
||||||
|
addLine();
|
||||||
|
addText();
|
||||||
|
}
|
||||||
|
canvas->update();
|
||||||
|
}
|
||||||
|
|
||||||
|
QtCanvasItem *MainWindow::addRectangle()
|
||||||
|
{
|
||||||
|
QtCanvasPolygonalItem *item = new QtCanvasRectangle(rand() % canvas->width(),
|
||||||
|
rand() % canvas->height(), 50, 50, canvas);
|
||||||
|
int z = rand() % 256;
|
||||||
|
item->setBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
|
||||||
|
item->setPen(QPen(QColor(rand() % 32*8, rand() % 32*8, rand() % 32*8), 4));
|
||||||
|
item->setZ(z);
|
||||||
|
item->show();
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
QtCanvasItem *MainWindow::addEllipse()
|
||||||
|
{
|
||||||
|
QtCanvasPolygonalItem *item = new QtCanvasEllipse(50, 50, canvas);
|
||||||
|
item->setBrush(QColor(rand() % 32 * 8, rand() % 32 * 8, rand() % 32 * 8));
|
||||||
|
item->move(rand() % canvas->width(), rand() % canvas->height());
|
||||||
|
item->setZ(rand() % 256);
|
||||||
|
item->show();
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
QtCanvasItem *MainWindow::addLine()
|
||||||
|
{
|
||||||
|
QtCanvasLine *item = new QtCanvasLine(canvas);
|
||||||
|
item->setPoints(0, 0, rand() % canvas->width() - canvas->width() / 2,
|
||||||
|
rand() % canvas->height() - canvas->height() / 2);
|
||||||
|
item->move(rand() % canvas->width(), rand() % canvas->height());
|
||||||
|
item->setPen(QPen(QColor(rand() % 32*8, rand() % 32*8, rand() % 32*8), 6));
|
||||||
|
item->setZ(rand() % 256);
|
||||||
|
item->show();
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
QtCanvasItem *MainWindow::addText()
|
||||||
|
{
|
||||||
|
QtCanvasText *item = new QtCanvasText(canvas);
|
||||||
|
item->setText(tr("Text"));
|
||||||
|
item->setColor(QColor(rand() % 32*8, rand() % 32*8, rand() % 32*8));
|
||||||
|
item->move(rand() % canvas->width(), rand() % canvas->height());
|
||||||
|
item->setZ(rand() % 256);
|
||||||
|
item->show();
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::itemMoved(QtCanvasItem *item)
|
||||||
|
{
|
||||||
|
if (item != currentItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
variantManager->setValue(idToProperty[QLatin1String("xpos")], item->x());
|
||||||
|
variantManager->setValue(idToProperty[QLatin1String("ypos")], item->y());
|
||||||
|
variantManager->setValue(idToProperty[QLatin1String("zpos")], item->z());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::updateExpandState()
|
||||||
|
{
|
||||||
|
QList<QtBrowserItem *> list = propertyEditor->topLevelItems();
|
||||||
|
QListIterator<QtBrowserItem *> it(list);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
QtBrowserItem *item = it.next();
|
||||||
|
QtProperty *prop = item->property();
|
||||||
|
idToExpanded[propertyToId[prop]] = propertyEditor->isExpanded(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::itemClicked(QtCanvasItem *item)
|
||||||
|
{
|
||||||
|
updateExpandState();
|
||||||
|
|
||||||
|
QMap<QtProperty *, QString>::ConstIterator itProp = propertyToId.constBegin();
|
||||||
|
while (itProp != propertyToId.constEnd()) {
|
||||||
|
delete itProp.key();
|
||||||
|
itProp++;
|
||||||
|
}
|
||||||
|
propertyToId.clear();
|
||||||
|
idToProperty.clear();
|
||||||
|
|
||||||
|
currentItem = item;
|
||||||
|
if (!currentItem) {
|
||||||
|
deleteAction->setEnabled(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteAction->setEnabled(true);
|
||||||
|
|
||||||
|
QtVariantProperty *property;
|
||||||
|
|
||||||
|
property = variantManager->addProperty(QVariant::Double, tr("Position X"));
|
||||||
|
property->setAttribute(QLatin1String("minimum"), 0);
|
||||||
|
property->setAttribute(QLatin1String("maximum"), canvas->width());
|
||||||
|
property->setValue(item->x());
|
||||||
|
addProperty(property, QLatin1String("xpos"));
|
||||||
|
|
||||||
|
property = variantManager->addProperty(QVariant::Double, tr("Position Y"));
|
||||||
|
property->setAttribute(QLatin1String("minimum"), 0);
|
||||||
|
property->setAttribute(QLatin1String("maximum"), canvas->height());
|
||||||
|
property->setValue(item->y());
|
||||||
|
addProperty(property, QLatin1String("ypos"));
|
||||||
|
|
||||||
|
property = variantManager->addProperty(QVariant::Double, tr("Position Z"));
|
||||||
|
property->setAttribute(QLatin1String("minimum"), 0);
|
||||||
|
property->setAttribute(QLatin1String("maximum"), 256);
|
||||||
|
property->setValue(item->z());
|
||||||
|
addProperty(property, QLatin1String("zpos"));
|
||||||
|
|
||||||
|
if (item->rtti() == QtCanvasItem::Rtti_Rectangle) {
|
||||||
|
QtCanvasRectangle *i = (QtCanvasRectangle *)item;
|
||||||
|
|
||||||
|
property = variantManager->addProperty(QVariant::Color, tr("Brush Color"));
|
||||||
|
property->setValue(i->brush().color());
|
||||||
|
addProperty(property, QLatin1String("brush"));
|
||||||
|
|
||||||
|
property = variantManager->addProperty(QVariant::Color, tr("Pen Color"));
|
||||||
|
property->setValue(i->pen().color());
|
||||||
|
addProperty(property, QLatin1String("pen"));
|
||||||
|
|
||||||
|
property = variantManager->addProperty(QVariant::Size, tr("Size"));
|
||||||
|
property->setValue(i->size());
|
||||||
|
addProperty(property, QLatin1String("size"));
|
||||||
|
} else if (item->rtti() == QtCanvasItem::Rtti_Line) {
|
||||||
|
QtCanvasLine *i = (QtCanvasLine *)item;
|
||||||
|
|
||||||
|
property = variantManager->addProperty(QVariant::Color, tr("Pen Color"));
|
||||||
|
property->setValue(i->pen().color());
|
||||||
|
addProperty(property, QLatin1String("pen"));
|
||||||
|
|
||||||
|
property = variantManager->addProperty(QVariant::Point, tr("Vector"));
|
||||||
|
property->setValue(i->endPoint());
|
||||||
|
addProperty(property, QLatin1String("endpoint"));
|
||||||
|
} else if (item->rtti() == QtCanvasItem::Rtti_Ellipse) {
|
||||||
|
QtCanvasEllipse *i = (QtCanvasEllipse *)item;
|
||||||
|
|
||||||
|
property = variantManager->addProperty(QVariant::Color, tr("Brush Color"));
|
||||||
|
property->setValue(i->brush().color());
|
||||||
|
addProperty(property, QLatin1String("brush"));
|
||||||
|
|
||||||
|
property = variantManager->addProperty(QVariant::Size, tr("Size"));
|
||||||
|
property->setValue(QSize(i->width(), i->height()));
|
||||||
|
addProperty(property, QLatin1String("size"));
|
||||||
|
} else if (item->rtti() == QtCanvasItem::Rtti_Text) {
|
||||||
|
QtCanvasText *i = (QtCanvasText *)item;
|
||||||
|
|
||||||
|
property = variantManager->addProperty(QVariant::Color, tr("Color"));
|
||||||
|
property->setValue(i->color());
|
||||||
|
addProperty(property, QLatin1String("color"));
|
||||||
|
|
||||||
|
property = variantManager->addProperty(QVariant::String, tr("Text"));
|
||||||
|
property->setValue(i->text());
|
||||||
|
addProperty(property, QLatin1String("text"));
|
||||||
|
|
||||||
|
property = variantManager->addProperty(QVariant::Font, tr("Font"));
|
||||||
|
property->setValue(i->font());
|
||||||
|
addProperty(property, QLatin1String("font"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::addProperty(QtVariantProperty *property, const QString &id)
|
||||||
|
{
|
||||||
|
propertyToId[property] = id;
|
||||||
|
idToProperty[id] = property;
|
||||||
|
QtBrowserItem *item = propertyEditor->addProperty(property);
|
||||||
|
if (idToExpanded.contains(id))
|
||||||
|
propertyEditor->setExpanded(item, idToExpanded[id]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::valueChanged(QtProperty *property, const QVariant &value)
|
||||||
|
{
|
||||||
|
if (!propertyToId.contains(property))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!currentItem)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString id = propertyToId[property];
|
||||||
|
if (id == QLatin1String("xpos")) {
|
||||||
|
currentItem->setX(value.toDouble());
|
||||||
|
} else if (id == QLatin1String("ypos")) {
|
||||||
|
currentItem->setY(value.toDouble());
|
||||||
|
} else if (id == QLatin1String("zpos")) {
|
||||||
|
currentItem->setZ(value.toDouble());
|
||||||
|
} else if (id == QLatin1String("text")) {
|
||||||
|
if (currentItem->rtti() == QtCanvasItem::Rtti_Text) {
|
||||||
|
QtCanvasText *i = (QtCanvasText *)currentItem;
|
||||||
|
i->setText(value.value<QString>());
|
||||||
|
}
|
||||||
|
} else if (id == QLatin1String("color")) {
|
||||||
|
if (currentItem->rtti() == QtCanvasItem::Rtti_Text) {
|
||||||
|
QtCanvasText *i = (QtCanvasText *)currentItem;
|
||||||
|
i->setColor(value.value<QColor>());
|
||||||
|
}
|
||||||
|
} else if (id == QLatin1String("brush")) {
|
||||||
|
if (currentItem->rtti() == QtCanvasItem::Rtti_Rectangle ||
|
||||||
|
currentItem->rtti() == QtCanvasItem::Rtti_Ellipse) {
|
||||||
|
QtCanvasPolygonalItem *i = (QtCanvasPolygonalItem *)currentItem;
|
||||||
|
QBrush b = i->brush();
|
||||||
|
b.setColor(value.value<QColor>());
|
||||||
|
i->setBrush(b);
|
||||||
|
}
|
||||||
|
} else if (id == QLatin1String("pen")) {
|
||||||
|
if (currentItem->rtti() == QtCanvasItem::Rtti_Rectangle ||
|
||||||
|
currentItem->rtti() == QtCanvasItem::Rtti_Line) {
|
||||||
|
QtCanvasPolygonalItem *i = (QtCanvasPolygonalItem *)currentItem;
|
||||||
|
QPen p = i->pen();
|
||||||
|
p.setColor(value.value<QColor>());
|
||||||
|
i->setPen(p);
|
||||||
|
}
|
||||||
|
} else if (id == QLatin1String("font")) {
|
||||||
|
if (currentItem->rtti() == QtCanvasItem::Rtti_Text) {
|
||||||
|
QtCanvasText *i = (QtCanvasText *)currentItem;
|
||||||
|
i->setFont(value.value<QFont>());
|
||||||
|
}
|
||||||
|
} else if (id == QLatin1String("endpoint")) {
|
||||||
|
if (currentItem->rtti() == QtCanvasItem::Rtti_Line) {
|
||||||
|
QtCanvasLine *i = (QtCanvasLine *)currentItem;
|
||||||
|
QPoint p = value.value<QPoint>();
|
||||||
|
i->setPoints(i->startPoint().x(), i->startPoint().y(), p.x(), p.y());
|
||||||
|
}
|
||||||
|
} else if (id == QLatin1String("size")) {
|
||||||
|
if (currentItem->rtti() == QtCanvasItem::Rtti_Rectangle) {
|
||||||
|
QtCanvasRectangle *i = (QtCanvasRectangle *)currentItem;
|
||||||
|
QSize s = value.value<QSize>();
|
||||||
|
i->setSize(s.width(), s.height());
|
||||||
|
} else if (currentItem->rtti() == QtCanvasItem::Rtti_Ellipse) {
|
||||||
|
QtCanvasEllipse *i = (QtCanvasEllipse *)currentItem;
|
||||||
|
QSize s = value.value<QSize>();
|
||||||
|
i->setSize(s.width(), s.height());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
canvas->update();
|
||||||
|
}
|
||||||
|
|
||||||
114
examples/canvas_variant/mainwindow.h
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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."
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef MAINWINDOW_H
|
||||||
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QMap>
|
||||||
|
#include "qtcanvas.h"
|
||||||
|
|
||||||
|
class QtVariantProperty;
|
||||||
|
class QtProperty;
|
||||||
|
|
||||||
|
class QtBrowserIndex;
|
||||||
|
|
||||||
|
class CanvasView : public QtCanvasView
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
CanvasView(QWidget *parent = 0)
|
||||||
|
: QtCanvasView(parent), moving(0) { }
|
||||||
|
CanvasView(QtCanvas *canvas, QWidget *parent = 0)
|
||||||
|
: QtCanvasView(canvas, parent), moving(0) { }
|
||||||
|
signals:
|
||||||
|
void itemClicked(QtCanvasItem *item);
|
||||||
|
void itemMoved(QtCanvasItem *item);
|
||||||
|
protected:
|
||||||
|
void contentsMousePressEvent(QMouseEvent *event);
|
||||||
|
void contentsMouseDoubleClickEvent(QMouseEvent *event);
|
||||||
|
void contentsMouseMoveEvent(QMouseEvent* event);
|
||||||
|
private:
|
||||||
|
void handleMouseClickEvent(QMouseEvent *event);
|
||||||
|
QPoint moving_start;
|
||||||
|
QtCanvasItem *moving;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MainWindow : public QMainWindow
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
MainWindow(QWidget *parent = 0);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void newRectangle();
|
||||||
|
void newEllipse();
|
||||||
|
void newLine();
|
||||||
|
void newText();
|
||||||
|
void deleteObject();
|
||||||
|
void clearAll();
|
||||||
|
void fillView();
|
||||||
|
|
||||||
|
|
||||||
|
void itemClicked(QtCanvasItem *item);
|
||||||
|
void itemMoved(QtCanvasItem *item);
|
||||||
|
void valueChanged(QtProperty *property, const QVariant &value);
|
||||||
|
private:
|
||||||
|
|
||||||
|
QtCanvasItem *addRectangle();
|
||||||
|
QtCanvasItem *addEllipse();
|
||||||
|
QtCanvasItem *addLine();
|
||||||
|
QtCanvasItem *addText();
|
||||||
|
void addProperty(QtVariantProperty *property, const QString &id);
|
||||||
|
void updateExpandState();
|
||||||
|
|
||||||
|
QAction *deleteAction;
|
||||||
|
|
||||||
|
class QtVariantPropertyManager *variantManager;
|
||||||
|
|
||||||
|
class QtTreePropertyBrowser *propertyEditor;
|
||||||
|
CanvasView *canvasView;
|
||||||
|
QtCanvas *canvas;
|
||||||
|
QtCanvasItem *currentItem;
|
||||||
|
QMap<QtProperty *, QString> propertyToId;
|
||||||
|
QMap<QString, QtVariantProperty *> idToProperty;
|
||||||
|
QMap<QString, bool> idToExpanded;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
5906
examples/canvas_variant/qtcanvas.cpp
Normal file
778
examples/canvas_variant/qtcanvas.h
Normal file
@@ -0,0 +1,778 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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."
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef QTCANVAS_H
|
||||||
|
#define QTCANVAS_H
|
||||||
|
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QBrush>
|
||||||
|
#include <QPen>
|
||||||
|
#include <QPolygon>
|
||||||
|
#include <QScrollArea>
|
||||||
|
|
||||||
|
class QtCanvasSprite;
|
||||||
|
class QtCanvasPolygonalItem;
|
||||||
|
class QtCanvasRectangle;
|
||||||
|
class QtCanvasPolygon;
|
||||||
|
class QtCanvasEllipse;
|
||||||
|
class QtCanvasText;
|
||||||
|
class QtCanvasLine;
|
||||||
|
class QtCanvasChunk;
|
||||||
|
class QtCanvas;
|
||||||
|
class QtCanvasItem;
|
||||||
|
class QtCanvasView;
|
||||||
|
class QtCanvasPixmap;
|
||||||
|
|
||||||
|
typedef QList<QtCanvasItem *> QtCanvasItemList;
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasItemExtra;
|
||||||
|
|
||||||
|
class QtCanvasItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtCanvasItem(QtCanvas* canvas);
|
||||||
|
virtual ~QtCanvasItem();
|
||||||
|
|
||||||
|
double x() const
|
||||||
|
{ return myx; }
|
||||||
|
double y() const
|
||||||
|
{ return myy; }
|
||||||
|
double z() const
|
||||||
|
{ return myz; } // (depth)
|
||||||
|
|
||||||
|
virtual void moveBy(double dx, double dy);
|
||||||
|
void move(double x, double y);
|
||||||
|
void setX(double a) { move(a,y()); }
|
||||||
|
void setY(double a) { move(x(),a); }
|
||||||
|
void setZ(double a) { myz=a; changeChunks(); }
|
||||||
|
|
||||||
|
bool animated() const;
|
||||||
|
virtual void setAnimated(bool y);
|
||||||
|
virtual void setVelocity(double vx, double vy);
|
||||||
|
void setXVelocity(double vx) { setVelocity(vx,yVelocity()); }
|
||||||
|
void setYVelocity(double vy) { setVelocity(xVelocity(),vy); }
|
||||||
|
double xVelocity() const;
|
||||||
|
double yVelocity() const;
|
||||||
|
virtual void advance(int stage);
|
||||||
|
|
||||||
|
virtual bool collidesWith(const QtCanvasItem*) const=0;
|
||||||
|
|
||||||
|
QtCanvasItemList collisions(bool exact /* NO DEFAULT */) const;
|
||||||
|
|
||||||
|
virtual void setCanvas(QtCanvas*);
|
||||||
|
|
||||||
|
virtual void draw(QPainter&)=0;
|
||||||
|
|
||||||
|
void show();
|
||||||
|
void hide();
|
||||||
|
|
||||||
|
virtual void setVisible(bool yes);
|
||||||
|
bool isVisible() const
|
||||||
|
{ return (bool)vis; }
|
||||||
|
virtual void setSelected(bool yes);
|
||||||
|
bool isSelected() const
|
||||||
|
{ return (bool)sel; }
|
||||||
|
virtual void setEnabled(bool yes);
|
||||||
|
bool isEnabled() const
|
||||||
|
{ return (bool)ena; }
|
||||||
|
virtual void setActive(bool yes);
|
||||||
|
bool isActive() const
|
||||||
|
{ return (bool)act; }
|
||||||
|
bool visible() const
|
||||||
|
{ return (bool)vis; }
|
||||||
|
bool selected() const
|
||||||
|
{ return (bool)sel; }
|
||||||
|
bool enabled() const
|
||||||
|
{ return (bool)ena; }
|
||||||
|
bool active() const
|
||||||
|
{ return (bool)act; }
|
||||||
|
|
||||||
|
enum RttiValues {
|
||||||
|
Rtti_Item = 0,
|
||||||
|
Rtti_Sprite = 1,
|
||||||
|
Rtti_PolygonalItem = 2,
|
||||||
|
Rtti_Text = 3,
|
||||||
|
Rtti_Polygon = 4,
|
||||||
|
Rtti_Rectangle = 5,
|
||||||
|
Rtti_Ellipse = 6,
|
||||||
|
Rtti_Line = 7,
|
||||||
|
Rtti_Spline = 8
|
||||||
|
};
|
||||||
|
|
||||||
|
virtual int rtti() const;
|
||||||
|
static int RTTI;
|
||||||
|
|
||||||
|
virtual QRect boundingRect() const=0;
|
||||||
|
virtual QRect boundingRectAdvanced() const;
|
||||||
|
|
||||||
|
QtCanvas* canvas() const
|
||||||
|
{ return cnv; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void update() { changeChunks(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
// For friendly subclasses...
|
||||||
|
|
||||||
|
friend class QtCanvasPolygonalItem;
|
||||||
|
friend class QtCanvasSprite;
|
||||||
|
friend class QtCanvasRectangle;
|
||||||
|
friend class QtCanvasPolygon;
|
||||||
|
friend class QtCanvasEllipse;
|
||||||
|
friend class QtCanvasText;
|
||||||
|
friend class QtCanvasLine;
|
||||||
|
|
||||||
|
virtual QPolygon chunks() const;
|
||||||
|
virtual void addToChunks();
|
||||||
|
virtual void removeFromChunks();
|
||||||
|
virtual void changeChunks();
|
||||||
|
virtual bool collidesWith(const QtCanvasSprite*,
|
||||||
|
const QtCanvasPolygonalItem*,
|
||||||
|
const QtCanvasRectangle*,
|
||||||
|
const QtCanvasEllipse*,
|
||||||
|
const QtCanvasText*) const = 0;
|
||||||
|
// End of friend stuff
|
||||||
|
|
||||||
|
QtCanvas* cnv;
|
||||||
|
static QtCanvas* current_canvas;
|
||||||
|
double myx,myy,myz;
|
||||||
|
QtCanvasItemExtra *ext;
|
||||||
|
QtCanvasItemExtra& extra();
|
||||||
|
uint ani:1;
|
||||||
|
uint vis:1;
|
||||||
|
uint val:1;
|
||||||
|
uint sel:1;
|
||||||
|
uint ena:1;
|
||||||
|
uint act:1;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasData;
|
||||||
|
|
||||||
|
class QtCanvas : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
QtCanvas(QObject* parent = 0);
|
||||||
|
QtCanvas(int w, int h);
|
||||||
|
QtCanvas(QPixmap p, int h, int v, int tilewidth, int tileheight);
|
||||||
|
|
||||||
|
virtual ~QtCanvas();
|
||||||
|
|
||||||
|
virtual void setTiles(QPixmap tiles, int h, int v,
|
||||||
|
int tilewidth, int tileheight);
|
||||||
|
virtual void setBackgroundPixmap(const QPixmap& p);
|
||||||
|
QPixmap backgroundPixmap() const;
|
||||||
|
|
||||||
|
virtual void setBackgroundColor(const QColor& c);
|
||||||
|
QColor backgroundColor() const;
|
||||||
|
|
||||||
|
virtual void setTile(int x, int y, int tilenum);
|
||||||
|
int tile(int x, int y) const
|
||||||
|
{ return grid[x+y*htiles]; }
|
||||||
|
|
||||||
|
int tilesHorizontally() const
|
||||||
|
{ return htiles; }
|
||||||
|
int tilesVertically() const
|
||||||
|
{ return vtiles; }
|
||||||
|
|
||||||
|
int tileWidth() const
|
||||||
|
{ return tilew; }
|
||||||
|
int tileHeight() const
|
||||||
|
{ return tileh; }
|
||||||
|
|
||||||
|
virtual void resize(int width, int height);
|
||||||
|
int width() const
|
||||||
|
{ return awidth; }
|
||||||
|
int height() const
|
||||||
|
{ return aheight; }
|
||||||
|
QSize size() const
|
||||||
|
{ return QSize(awidth,aheight); }
|
||||||
|
QRect rect() const
|
||||||
|
{ return QRect(0, 0, awidth, aheight); }
|
||||||
|
bool onCanvas(int x, int y) const
|
||||||
|
{ return x>=0 && y>=0 && x<awidth && y<aheight; }
|
||||||
|
bool onCanvas(const QPoint& p) const
|
||||||
|
{ return onCanvas(p.x(),p.y()); }
|
||||||
|
bool validChunk(int x, int y) const
|
||||||
|
{ return x>=0 && y>=0 && x<chwidth && y<chheight; }
|
||||||
|
bool validChunk(const QPoint& p) const
|
||||||
|
{ return validChunk(p.x(),p.y()); }
|
||||||
|
|
||||||
|
int chunkSize() const
|
||||||
|
{ return chunksize; }
|
||||||
|
virtual void retune(int chunksize, int maxclusters=100);
|
||||||
|
|
||||||
|
bool sameChunk(int x1, int y1, int x2, int y2) const
|
||||||
|
{ return x1/chunksize==x2/chunksize && y1/chunksize==y2/chunksize; }
|
||||||
|
virtual void setChangedChunk(int i, int j);
|
||||||
|
virtual void setChangedChunkContaining(int x, int y);
|
||||||
|
virtual void setAllChanged();
|
||||||
|
virtual void setChanged(const QRect& area);
|
||||||
|
virtual void setUnchanged(const QRect& area);
|
||||||
|
|
||||||
|
// These call setChangedChunk.
|
||||||
|
void addItemToChunk(QtCanvasItem*, int i, int j);
|
||||||
|
void removeItemFromChunk(QtCanvasItem*, int i, int j);
|
||||||
|
void addItemToChunkContaining(QtCanvasItem*, int x, int y);
|
||||||
|
void removeItemFromChunkContaining(QtCanvasItem*, int x, int y);
|
||||||
|
|
||||||
|
QtCanvasItemList allItems();
|
||||||
|
QtCanvasItemList collisions(const QPoint&) const;
|
||||||
|
QtCanvasItemList collisions(const QRect&) const;
|
||||||
|
QtCanvasItemList collisions(const QPolygon& pa, const QtCanvasItem* item,
|
||||||
|
bool exact) const;
|
||||||
|
|
||||||
|
void drawArea(const QRect&, QPainter* p, bool double_buffer=false);
|
||||||
|
|
||||||
|
// These are for QtCanvasView to call
|
||||||
|
virtual void addView(QtCanvasView*);
|
||||||
|
virtual void removeView(QtCanvasView*);
|
||||||
|
|
||||||
|
void drawCanvasArea(const QRect&, QPainter* p=0, bool double_buffer=true);
|
||||||
|
void drawViewArea(QtCanvasView* view, QPainter* p, const QRect& r, bool dbuf);
|
||||||
|
|
||||||
|
// These are for QtCanvasItem to call
|
||||||
|
virtual void addItem(QtCanvasItem*);
|
||||||
|
virtual void addAnimation(QtCanvasItem*);
|
||||||
|
virtual void removeItem(QtCanvasItem*);
|
||||||
|
virtual void removeAnimation(QtCanvasItem*);
|
||||||
|
|
||||||
|
virtual void setAdvancePeriod(int ms);
|
||||||
|
virtual void setUpdatePeriod(int ms);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void resized();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual void advance();
|
||||||
|
virtual void update();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void drawBackground(QPainter&, const QRect& area);
|
||||||
|
virtual void drawForeground(QPainter&, const QRect& area);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void init(int w, int h, int chunksze=16, int maxclust=100);
|
||||||
|
|
||||||
|
QtCanvasChunk& chunk(int i, int j) const;
|
||||||
|
QtCanvasChunk& chunkContaining(int x, int y) const;
|
||||||
|
|
||||||
|
QRect changeBounds();
|
||||||
|
|
||||||
|
int awidth,aheight;
|
||||||
|
int chunksize;
|
||||||
|
int maxclusters;
|
||||||
|
int chwidth,chheight;
|
||||||
|
QtCanvasChunk* chunks;
|
||||||
|
|
||||||
|
QtCanvasData* d;
|
||||||
|
|
||||||
|
void initTiles(QPixmap p, int h, int v, int tilewidth, int tileheight);
|
||||||
|
ushort *grid;
|
||||||
|
ushort htiles;
|
||||||
|
ushort vtiles;
|
||||||
|
ushort tilew;
|
||||||
|
ushort tileh;
|
||||||
|
bool oneone;
|
||||||
|
QPixmap pm;
|
||||||
|
QTimer* update_timer;
|
||||||
|
QColor bgcolor;
|
||||||
|
bool debug_redraw_areas;
|
||||||
|
|
||||||
|
friend void qt_unview(QtCanvas* c);
|
||||||
|
|
||||||
|
Q_DISABLE_COPY(QtCanvas)
|
||||||
|
};
|
||||||
|
|
||||||
|
class QtCanvasViewData;
|
||||||
|
|
||||||
|
class QtCanvasView : public QScrollArea
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(bool highQualityRendering READ highQualityRendering WRITE setHighQualityRendering)
|
||||||
|
public:
|
||||||
|
|
||||||
|
QtCanvasView(QWidget* parent=0);
|
||||||
|
QtCanvasView(QtCanvas* viewing, QWidget* parent=0);
|
||||||
|
~QtCanvasView();
|
||||||
|
|
||||||
|
QtCanvas* canvas() const
|
||||||
|
{ return viewing; }
|
||||||
|
void setCanvas(QtCanvas* v);
|
||||||
|
|
||||||
|
const QMatrix &worldMatrix() const;
|
||||||
|
const QMatrix &inverseWorldMatrix() const;
|
||||||
|
bool setWorldMatrix(const QMatrix &);
|
||||||
|
|
||||||
|
virtual QSize sizeHint() const;
|
||||||
|
|
||||||
|
bool highQualityRendering() const;
|
||||||
|
public slots:
|
||||||
|
void setHighQualityRendering(bool enable);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
friend class QtCanvasWidget;
|
||||||
|
virtual void drawContents(QPainter *p, int cx, int cy, int cw, int ch);
|
||||||
|
|
||||||
|
virtual void contentsMousePressEvent( QMouseEvent* );
|
||||||
|
virtual void contentsMouseReleaseEvent( QMouseEvent* );
|
||||||
|
virtual void contentsMouseDoubleClickEvent( QMouseEvent* );
|
||||||
|
virtual void contentsMouseMoveEvent( QMouseEvent* );
|
||||||
|
virtual void contentsDragEnterEvent( QDragEnterEvent * );
|
||||||
|
virtual void contentsDragMoveEvent( QDragMoveEvent * );
|
||||||
|
virtual void contentsDragLeaveEvent( QDragLeaveEvent * );
|
||||||
|
virtual void contentsDropEvent( QDropEvent * );
|
||||||
|
virtual void contentsWheelEvent( QWheelEvent * );
|
||||||
|
virtual void contentsContextMenuEvent( QContextMenuEvent * );
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class QtCanvas;
|
||||||
|
void drawContents(QPainter*);
|
||||||
|
QtCanvas* viewing;
|
||||||
|
QtCanvasViewData* d;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void updateContentsSize();
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(QtCanvasView)
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasPixmap : public QPixmap
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
#ifndef QT_NO_IMAGEIO
|
||||||
|
QtCanvasPixmap(const QString& datafilename);
|
||||||
|
#endif
|
||||||
|
QtCanvasPixmap(const QImage& image);
|
||||||
|
QtCanvasPixmap(const QPixmap&, const QPoint& hotspot);
|
||||||
|
~QtCanvasPixmap();
|
||||||
|
|
||||||
|
int offsetX() const
|
||||||
|
{ return hotx; }
|
||||||
|
int offsetY() const
|
||||||
|
{ return hoty; }
|
||||||
|
void setOffset(int x, int y) { hotx = x; hoty = y; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(QtCanvasPixmap)
|
||||||
|
|
||||||
|
void init(const QImage&);
|
||||||
|
void init(const QPixmap& pixmap, int hx, int hy);
|
||||||
|
|
||||||
|
friend class QtCanvasSprite;
|
||||||
|
friend class QtCanvasPixmapArray;
|
||||||
|
friend bool qt_testCollision(const QtCanvasSprite* s1, const QtCanvasSprite* s2);
|
||||||
|
|
||||||
|
int hotx,hoty;
|
||||||
|
|
||||||
|
QImage* collision_mask;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasPixmapArray
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtCanvasPixmapArray();
|
||||||
|
#ifndef QT_NO_IMAGEIO
|
||||||
|
QtCanvasPixmapArray(const QString& datafilenamepattern, int framecount=0);
|
||||||
|
#endif
|
||||||
|
QtCanvasPixmapArray(const QList<QPixmap> &pixmaps, const QPolygon &hotspots = QPolygon());
|
||||||
|
~QtCanvasPixmapArray();
|
||||||
|
|
||||||
|
#ifndef QT_NO_IMAGEIO
|
||||||
|
bool readPixmaps(const QString& datafilenamepattern, int framecount=0);
|
||||||
|
bool readCollisionMasks(const QString& filenamepattern);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// deprecated
|
||||||
|
bool operator!(); // Failure check.
|
||||||
|
bool isValid() const;
|
||||||
|
|
||||||
|
QtCanvasPixmap* image(int i) const
|
||||||
|
{ return img ? img[i] : 0; }
|
||||||
|
void setImage(int i, QtCanvasPixmap* p);
|
||||||
|
uint count() const
|
||||||
|
{ return (uint)framecount; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(QtCanvasPixmapArray)
|
||||||
|
|
||||||
|
#ifndef QT_NO_IMAGEIO
|
||||||
|
bool readPixmaps(const QString& datafilenamepattern, int framecount, bool maskonly);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void reset();
|
||||||
|
int framecount;
|
||||||
|
QtCanvasPixmap** img;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasSprite : public QtCanvasItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtCanvasSprite(QtCanvasPixmapArray* array, QtCanvas* canvas);
|
||||||
|
|
||||||
|
void setSequence(QtCanvasPixmapArray* seq);
|
||||||
|
|
||||||
|
virtual ~QtCanvasSprite();
|
||||||
|
|
||||||
|
void move(double x, double y);
|
||||||
|
virtual void move(double x, double y, int frame);
|
||||||
|
void setFrame(int);
|
||||||
|
enum FrameAnimationType { Cycle, Oscillate };
|
||||||
|
virtual void setFrameAnimation(FrameAnimationType=Cycle, int step=1, int state=0);
|
||||||
|
int frame() const
|
||||||
|
{ return frm; }
|
||||||
|
int frameCount() const
|
||||||
|
{ return images->count(); }
|
||||||
|
|
||||||
|
int rtti() const;
|
||||||
|
static int RTTI;
|
||||||
|
|
||||||
|
bool collidesWith(const QtCanvasItem*) const;
|
||||||
|
|
||||||
|
QRect boundingRect() const;
|
||||||
|
|
||||||
|
// is there a reason for these to be protected? Lars
|
||||||
|
//protected:
|
||||||
|
|
||||||
|
int width() const;
|
||||||
|
int height() const;
|
||||||
|
|
||||||
|
int leftEdge() const;
|
||||||
|
int topEdge() const;
|
||||||
|
int rightEdge() const;
|
||||||
|
int bottomEdge() const;
|
||||||
|
|
||||||
|
int leftEdge(int nx) const;
|
||||||
|
int topEdge(int ny) const;
|
||||||
|
int rightEdge(int nx) const;
|
||||||
|
int bottomEdge(int ny) const;
|
||||||
|
QtCanvasPixmap* image() const
|
||||||
|
{ return images->image(frm); }
|
||||||
|
virtual QtCanvasPixmap* imageAdvanced() const;
|
||||||
|
QtCanvasPixmap* image(int f) const
|
||||||
|
{ return images->image(f); }
|
||||||
|
virtual void advance(int stage);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void draw(QPainter& painter);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(QtCanvasSprite)
|
||||||
|
|
||||||
|
void addToChunks();
|
||||||
|
void removeFromChunks();
|
||||||
|
void changeChunks();
|
||||||
|
|
||||||
|
int frm;
|
||||||
|
ushort anim_val;
|
||||||
|
uint anim_state:2;
|
||||||
|
uint anim_type:14;
|
||||||
|
bool collidesWith(const QtCanvasSprite*,
|
||||||
|
const QtCanvasPolygonalItem*,
|
||||||
|
const QtCanvasRectangle*,
|
||||||
|
const QtCanvasEllipse*,
|
||||||
|
const QtCanvasText*) const;
|
||||||
|
|
||||||
|
friend bool qt_testCollision(const QtCanvasSprite* s1,
|
||||||
|
const QtCanvasSprite* s2);
|
||||||
|
|
||||||
|
QtCanvasPixmapArray* images;
|
||||||
|
};
|
||||||
|
|
||||||
|
class QPolygonalProcessor;
|
||||||
|
|
||||||
|
class QtCanvasPolygonalItem : public QtCanvasItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtCanvasPolygonalItem(QtCanvas* canvas);
|
||||||
|
virtual ~QtCanvasPolygonalItem();
|
||||||
|
|
||||||
|
bool collidesWith(const QtCanvasItem*) const;
|
||||||
|
|
||||||
|
virtual void setPen(QPen p);
|
||||||
|
virtual void setBrush(QBrush b);
|
||||||
|
|
||||||
|
QPen pen() const
|
||||||
|
{ return pn; }
|
||||||
|
QBrush brush() const
|
||||||
|
{ return br; }
|
||||||
|
|
||||||
|
virtual QPolygon areaPoints() const=0;
|
||||||
|
virtual QPolygon areaPointsAdvanced() const;
|
||||||
|
QRect boundingRect() const;
|
||||||
|
|
||||||
|
int rtti() const;
|
||||||
|
static int RTTI;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void draw(QPainter &);
|
||||||
|
virtual void drawShape(QPainter &) = 0;
|
||||||
|
|
||||||
|
bool winding() const;
|
||||||
|
void setWinding(bool);
|
||||||
|
|
||||||
|
void invalidate();
|
||||||
|
bool isValid() const
|
||||||
|
{ return (bool)val; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void scanPolygon(const QPolygon& pa, int winding,
|
||||||
|
QPolygonalProcessor& process) const;
|
||||||
|
QPolygon chunks() const;
|
||||||
|
|
||||||
|
bool collidesWith(const QtCanvasSprite*,
|
||||||
|
const QtCanvasPolygonalItem*,
|
||||||
|
const QtCanvasRectangle*,
|
||||||
|
const QtCanvasEllipse*,
|
||||||
|
const QtCanvasText*) const;
|
||||||
|
|
||||||
|
QBrush br;
|
||||||
|
QPen pn;
|
||||||
|
uint wind:1;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasRectangle : public QtCanvasPolygonalItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtCanvasRectangle(QtCanvas* canvas);
|
||||||
|
QtCanvasRectangle(const QRect&, QtCanvas* canvas);
|
||||||
|
QtCanvasRectangle(int x, int y, int width, int height, QtCanvas* canvas);
|
||||||
|
|
||||||
|
~QtCanvasRectangle();
|
||||||
|
|
||||||
|
int width() const;
|
||||||
|
int height() const;
|
||||||
|
void setSize(int w, int h);
|
||||||
|
QSize size() const
|
||||||
|
{ return QSize(w,h); }
|
||||||
|
QPolygon areaPoints() const;
|
||||||
|
QRect rect() const
|
||||||
|
{ return QRect(int(x()),int(y()),w,h); }
|
||||||
|
|
||||||
|
bool collidesWith(const QtCanvasItem*) const;
|
||||||
|
|
||||||
|
int rtti() const;
|
||||||
|
static int RTTI;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void drawShape(QPainter &);
|
||||||
|
QPolygon chunks() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool collidesWith( const QtCanvasSprite*,
|
||||||
|
const QtCanvasPolygonalItem*,
|
||||||
|
const QtCanvasRectangle*,
|
||||||
|
const QtCanvasEllipse*,
|
||||||
|
const QtCanvasText*) const;
|
||||||
|
|
||||||
|
int w, h;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasPolygon : public QtCanvasPolygonalItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtCanvasPolygon(QtCanvas* canvas);
|
||||||
|
~QtCanvasPolygon();
|
||||||
|
void setPoints(QPolygon);
|
||||||
|
QPolygon points() const;
|
||||||
|
void moveBy(double dx, double dy);
|
||||||
|
|
||||||
|
QPolygon areaPoints() const;
|
||||||
|
|
||||||
|
int rtti() const;
|
||||||
|
static int RTTI;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void drawShape(QPainter &);
|
||||||
|
QPolygon poly;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasSpline : public QtCanvasPolygon
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtCanvasSpline(QtCanvas* canvas);
|
||||||
|
~QtCanvasSpline();
|
||||||
|
|
||||||
|
void setControlPoints(QPolygon, bool closed=true);
|
||||||
|
QPolygon controlPoints() const;
|
||||||
|
bool closed() const;
|
||||||
|
|
||||||
|
int rtti() const;
|
||||||
|
static int RTTI;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void recalcPoly();
|
||||||
|
QPolygon bez;
|
||||||
|
bool cl;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasLine : public QtCanvasPolygonalItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtCanvasLine(QtCanvas* canvas);
|
||||||
|
~QtCanvasLine();
|
||||||
|
void setPoints(int x1, int y1, int x2, int y2);
|
||||||
|
|
||||||
|
QPoint startPoint() const
|
||||||
|
{ return QPoint(x1,y1); }
|
||||||
|
QPoint endPoint() const
|
||||||
|
{ return QPoint(x2,y2); }
|
||||||
|
|
||||||
|
int rtti() const;
|
||||||
|
static int RTTI;
|
||||||
|
|
||||||
|
void setPen(QPen p);
|
||||||
|
void moveBy(double dx, double dy);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void drawShape(QPainter &);
|
||||||
|
QPolygon areaPoints() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int x1,y1,x2,y2;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasEllipse : public QtCanvasPolygonalItem
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
QtCanvasEllipse(QtCanvas* canvas);
|
||||||
|
QtCanvasEllipse(int width, int height, QtCanvas* canvas);
|
||||||
|
QtCanvasEllipse(int width, int height, int startangle, int angle,
|
||||||
|
QtCanvas* canvas);
|
||||||
|
|
||||||
|
~QtCanvasEllipse();
|
||||||
|
|
||||||
|
int width() const;
|
||||||
|
int height() const;
|
||||||
|
void setSize(int w, int h);
|
||||||
|
void setAngles(int start, int length);
|
||||||
|
int angleStart() const
|
||||||
|
{ return a1; }
|
||||||
|
int angleLength() const
|
||||||
|
{ return a2; }
|
||||||
|
QPolygon areaPoints() const;
|
||||||
|
|
||||||
|
bool collidesWith(const QtCanvasItem*) const;
|
||||||
|
|
||||||
|
int rtti() const;
|
||||||
|
static int RTTI;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void drawShape(QPainter &);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool collidesWith(const QtCanvasSprite*,
|
||||||
|
const QtCanvasPolygonalItem*,
|
||||||
|
const QtCanvasRectangle*,
|
||||||
|
const QtCanvasEllipse*,
|
||||||
|
const QtCanvasText*) const;
|
||||||
|
int w, h;
|
||||||
|
int a1, a2;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class QtCanvasTextExtra;
|
||||||
|
|
||||||
|
class QtCanvasText : public QtCanvasItem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QtCanvasText(QtCanvas* canvas);
|
||||||
|
QtCanvasText(const QString&, QtCanvas* canvas);
|
||||||
|
QtCanvasText(const QString&, QFont, QtCanvas* canvas);
|
||||||
|
|
||||||
|
virtual ~QtCanvasText();
|
||||||
|
|
||||||
|
void setText(const QString&);
|
||||||
|
void setFont(const QFont&);
|
||||||
|
void setColor(const QColor&);
|
||||||
|
QString text() const;
|
||||||
|
QFont font() const;
|
||||||
|
QColor color() const;
|
||||||
|
|
||||||
|
void moveBy(double dx, double dy);
|
||||||
|
|
||||||
|
int textFlags() const
|
||||||
|
{ return flags; }
|
||||||
|
void setTextFlags(int);
|
||||||
|
|
||||||
|
QRect boundingRect() const;
|
||||||
|
|
||||||
|
bool collidesWith(const QtCanvasItem*) const;
|
||||||
|
|
||||||
|
int rtti() const;
|
||||||
|
static int RTTI;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void draw(QPainter&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Q_DISABLE_COPY(QtCanvasText)
|
||||||
|
|
||||||
|
void addToChunks();
|
||||||
|
void removeFromChunks();
|
||||||
|
void changeChunks();
|
||||||
|
|
||||||
|
void setRect();
|
||||||
|
QRect brect;
|
||||||
|
QString txt;
|
||||||
|
int flags;
|
||||||
|
QFont fnt;
|
||||||
|
QColor col;
|
||||||
|
QtCanvasTextExtra* extra;
|
||||||
|
|
||||||
|
bool collidesWith(const QtCanvasSprite*,
|
||||||
|
const QtCanvasPolygonalItem*,
|
||||||
|
const QtCanvasRectangle*,
|
||||||
|
const QtCanvasEllipse*,
|
||||||
|
const QtCanvasText*) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QTCANVAS_H
|
||||||
15
examples/decoration/CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# Tell CMake to run moc when necessary:
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
|
||||||
|
# As moc files are generated in the binary dir, tell CMake
|
||||||
|
# to always look for includes there:
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
|
SET(example_name decoration)
|
||||||
|
|
||||||
|
SET(KIT_SRCS
|
||||||
|
main.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
ADD_EXECUTABLE(${example_name} ${KIT_SRCS})
|
||||||
|
TARGET_LINK_LIBRARIES(${example_name} ${PROJECT_NAME} ${QT_TARGETS})
|
||||||
54
examples/decoration/decoration.qdoc
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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."
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\page qtpropertybrowser-example-decoration.html
|
||||||
|
\title Decoration Example
|
||||||
|
|
||||||
|
This example demonstrates how to decorate the existing
|
||||||
|
QtDoublePropertyManager class with additional responsibilities.
|
||||||
|
|
||||||
|
\image decoration.png
|
||||||
|
|
||||||
|
It also shows how to write respective editor factory for decorated manager
|
||||||
|
by delegating common responsibilities of undecorated base manager to the aggregated
|
||||||
|
QtDoubleSpinBoxFactory member.
|
||||||
|
|
||||||
|
The source files can be found in examples/decoration directory of the package.
|
||||||
|
*/
|
||||||
312
examples/decoration/main.cpp
Normal file
@@ -0,0 +1,312 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 <QApplication>
|
||||||
|
#include <QMap>
|
||||||
|
#include <QDoubleSpinBox>
|
||||||
|
#include "qtpropertybrowser.h"
|
||||||
|
#include "qteditorfactory.h"
|
||||||
|
#include "qttreepropertybrowser.h"
|
||||||
|
|
||||||
|
class DecoratedDoublePropertyManager : public QtDoublePropertyManager
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
DecoratedDoublePropertyManager(QObject *parent = 0);
|
||||||
|
~DecoratedDoublePropertyManager();
|
||||||
|
|
||||||
|
QString prefix(const QtProperty *property) const;
|
||||||
|
QString suffix(const QtProperty *property) const;
|
||||||
|
public Q_SLOTS:
|
||||||
|
void setPrefix(QtProperty *property, const QString &prefix);
|
||||||
|
void setSuffix(QtProperty *property, const QString &suffix);
|
||||||
|
Q_SIGNALS:
|
||||||
|
void prefixChanged(QtProperty *property, const QString &prefix);
|
||||||
|
void suffixChanged(QtProperty *property, const QString &suffix);
|
||||||
|
protected:
|
||||||
|
QString valueText(const QtProperty *property) const;
|
||||||
|
virtual void initializeProperty(QtProperty *property);
|
||||||
|
virtual void uninitializeProperty(QtProperty *property);
|
||||||
|
private:
|
||||||
|
struct Data {
|
||||||
|
QString prefix;
|
||||||
|
QString suffix;
|
||||||
|
};
|
||||||
|
QMap<const QtProperty *, Data> propertyToData;
|
||||||
|
};
|
||||||
|
|
||||||
|
DecoratedDoublePropertyManager::DecoratedDoublePropertyManager(QObject *parent)
|
||||||
|
: QtDoublePropertyManager(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
DecoratedDoublePropertyManager::~DecoratedDoublePropertyManager()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DecoratedDoublePropertyManager::prefix(const QtProperty *property) const
|
||||||
|
{
|
||||||
|
if (!propertyToData.contains(property))
|
||||||
|
return QString();
|
||||||
|
return propertyToData[property].prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DecoratedDoublePropertyManager::suffix(const QtProperty *property) const
|
||||||
|
{
|
||||||
|
if (!propertyToData.contains(property))
|
||||||
|
return QString();
|
||||||
|
return propertyToData[property].suffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DecoratedDoublePropertyManager::setPrefix(QtProperty *property, const QString &prefix)
|
||||||
|
{
|
||||||
|
if (!propertyToData.contains(property))
|
||||||
|
return;
|
||||||
|
|
||||||
|
DecoratedDoublePropertyManager::Data data = propertyToData[property];
|
||||||
|
if (data.prefix == prefix)
|
||||||
|
return;
|
||||||
|
|
||||||
|
data.prefix = prefix;
|
||||||
|
propertyToData[property] = data;
|
||||||
|
|
||||||
|
emit propertyChanged(property);
|
||||||
|
emit prefixChanged(property, prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DecoratedDoublePropertyManager::setSuffix(QtProperty *property, const QString &suffix)
|
||||||
|
{
|
||||||
|
if (!propertyToData.contains(property))
|
||||||
|
return;
|
||||||
|
|
||||||
|
DecoratedDoublePropertyManager::Data data = propertyToData[property];
|
||||||
|
if (data.suffix == suffix)
|
||||||
|
return;
|
||||||
|
|
||||||
|
data.suffix = suffix;
|
||||||
|
propertyToData[property] = data;
|
||||||
|
|
||||||
|
emit propertyChanged(property);
|
||||||
|
emit suffixChanged(property, suffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString DecoratedDoublePropertyManager::valueText(const QtProperty *property) const
|
||||||
|
{
|
||||||
|
QString text = QtDoublePropertyManager::valueText(property);
|
||||||
|
if (!propertyToData.contains(property))
|
||||||
|
return text;
|
||||||
|
|
||||||
|
DecoratedDoublePropertyManager::Data data = propertyToData[property];
|
||||||
|
text = data.prefix + text + data.suffix;
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DecoratedDoublePropertyManager::initializeProperty(QtProperty *property)
|
||||||
|
{
|
||||||
|
propertyToData[property] = DecoratedDoublePropertyManager::Data();
|
||||||
|
QtDoublePropertyManager::initializeProperty(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DecoratedDoublePropertyManager::uninitializeProperty(QtProperty *property)
|
||||||
|
{
|
||||||
|
propertyToData.remove(property);
|
||||||
|
QtDoublePropertyManager::uninitializeProperty(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class DecoratedDoubleSpinBoxFactory : public QtAbstractEditorFactory<DecoratedDoublePropertyManager>
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
DecoratedDoubleSpinBoxFactory(QObject *parent = 0);
|
||||||
|
~DecoratedDoubleSpinBoxFactory();
|
||||||
|
protected:
|
||||||
|
void connectPropertyManager(DecoratedDoublePropertyManager *manager);
|
||||||
|
QWidget *createEditor(DecoratedDoublePropertyManager *manager, QtProperty *property,
|
||||||
|
QWidget *parent);
|
||||||
|
void disconnectPropertyManager(DecoratedDoublePropertyManager *manager);
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void slotPrefixChanged(QtProperty *property, const QString &prefix);
|
||||||
|
void slotSuffixChanged(QtProperty *property, const QString &prefix);
|
||||||
|
void slotEditorDestroyed(QObject *object);
|
||||||
|
private:
|
||||||
|
/* We delegate responsibilities for QtDoublePropertyManager, which is a base class
|
||||||
|
of DecoratedDoublePropertyManager to appropriate QtDoubleSpinBoxFactory */
|
||||||
|
QtDoubleSpinBoxFactory *originalFactory;
|
||||||
|
QMap<QtProperty *, QList<QDoubleSpinBox *> > createdEditors;
|
||||||
|
QMap<QDoubleSpinBox *, QtProperty *> editorToProperty;
|
||||||
|
};
|
||||||
|
|
||||||
|
DecoratedDoubleSpinBoxFactory::DecoratedDoubleSpinBoxFactory(QObject *parent)
|
||||||
|
: QtAbstractEditorFactory<DecoratedDoublePropertyManager>(parent)
|
||||||
|
{
|
||||||
|
originalFactory = new QtDoubleSpinBoxFactory(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
DecoratedDoubleSpinBoxFactory::~DecoratedDoubleSpinBoxFactory()
|
||||||
|
{
|
||||||
|
// not need to delete editors because they will be deleted by originalFactory in its destructor
|
||||||
|
}
|
||||||
|
|
||||||
|
void DecoratedDoubleSpinBoxFactory::connectPropertyManager(DecoratedDoublePropertyManager *manager)
|
||||||
|
{
|
||||||
|
originalFactory->addPropertyManager(manager);
|
||||||
|
connect(manager, SIGNAL(prefixChanged(QtProperty *, const QString &)), this, SLOT(slotPrefixChanged(QtProperty *, const QString &)));
|
||||||
|
connect(manager, SIGNAL(suffixChanged(QtProperty *, const QString &)), this, SLOT(slotSuffixChanged(QtProperty *, const QString &)));
|
||||||
|
}
|
||||||
|
|
||||||
|
QWidget *DecoratedDoubleSpinBoxFactory::createEditor(DecoratedDoublePropertyManager *manager, QtProperty *property,
|
||||||
|
QWidget *parent)
|
||||||
|
{
|
||||||
|
QtAbstractEditorFactoryBase *base = originalFactory;
|
||||||
|
QWidget *w = base->createEditor(property, parent);
|
||||||
|
if (!w)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
QDoubleSpinBox *spinBox = qobject_cast<QDoubleSpinBox *>(w);
|
||||||
|
if (!spinBox)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
spinBox->setPrefix(manager->prefix(property));
|
||||||
|
spinBox->setSuffix(manager->suffix(property));
|
||||||
|
|
||||||
|
createdEditors[property].append(spinBox);
|
||||||
|
editorToProperty[spinBox] = property;
|
||||||
|
|
||||||
|
return spinBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DecoratedDoubleSpinBoxFactory::disconnectPropertyManager(DecoratedDoublePropertyManager *manager)
|
||||||
|
{
|
||||||
|
originalFactory->removePropertyManager(manager);
|
||||||
|
disconnect(manager, SIGNAL(prefixChanged(QtProperty *, const QString &)), this, SLOT(slotPrefixChanged(QtProperty *, const QString &)));
|
||||||
|
disconnect(manager, SIGNAL(suffixChanged(QtProperty *, const QString &)), this, SLOT(slotSuffixChanged(QtProperty *, const QString &)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DecoratedDoubleSpinBoxFactory::slotPrefixChanged(QtProperty *property, const QString &prefix)
|
||||||
|
{
|
||||||
|
if (!createdEditors.contains(property))
|
||||||
|
return;
|
||||||
|
|
||||||
|
DecoratedDoublePropertyManager *manager = propertyManager(property);
|
||||||
|
if (!manager)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QList<QDoubleSpinBox *> editors = createdEditors[property];
|
||||||
|
QListIterator<QDoubleSpinBox *> itEditor(editors);
|
||||||
|
while (itEditor.hasNext()) {
|
||||||
|
QDoubleSpinBox *editor = itEditor.next();
|
||||||
|
editor->setPrefix(prefix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DecoratedDoubleSpinBoxFactory::slotSuffixChanged(QtProperty *property, const QString &prefix)
|
||||||
|
{
|
||||||
|
if (!createdEditors.contains(property))
|
||||||
|
return;
|
||||||
|
|
||||||
|
DecoratedDoublePropertyManager *manager = propertyManager(property);
|
||||||
|
if (!manager)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QList<QDoubleSpinBox *> editors = createdEditors[property];
|
||||||
|
QListIterator<QDoubleSpinBox *> itEditor(editors);
|
||||||
|
while (itEditor.hasNext()) {
|
||||||
|
QDoubleSpinBox *editor = itEditor.next();
|
||||||
|
editor->setSuffix(prefix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DecoratedDoubleSpinBoxFactory::slotEditorDestroyed(QObject *object)
|
||||||
|
{
|
||||||
|
QMap<QDoubleSpinBox *, QtProperty *>::ConstIterator itEditor =
|
||||||
|
editorToProperty.constBegin();
|
||||||
|
while (itEditor != editorToProperty.constEnd()) {
|
||||||
|
if (itEditor.key() == object) {
|
||||||
|
QDoubleSpinBox *editor = itEditor.key();
|
||||||
|
QtProperty *property = itEditor.value();
|
||||||
|
editorToProperty.remove(editor);
|
||||||
|
createdEditors[property].removeAll(editor);
|
||||||
|
if (createdEditors[property].isEmpty())
|
||||||
|
createdEditors.remove(property);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
itEditor++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
|
QtDoublePropertyManager *undecoratedManager = new QtDoublePropertyManager();
|
||||||
|
QtProperty *undecoratedProperty = undecoratedManager->addProperty("Undecorated");
|
||||||
|
undecoratedManager->setValue(undecoratedProperty, 123.45);
|
||||||
|
|
||||||
|
DecoratedDoublePropertyManager *decoratedManager = new DecoratedDoublePropertyManager();
|
||||||
|
QtProperty *decoratedProperty = decoratedManager->addProperty("Decorated");
|
||||||
|
decoratedManager->setPrefix(decoratedProperty, "speed: ");
|
||||||
|
decoratedManager->setSuffix(decoratedProperty, " km/h");
|
||||||
|
decoratedManager->setValue(decoratedProperty, 123.45);
|
||||||
|
|
||||||
|
QtDoubleSpinBoxFactory *undecoratedFactory = new QtDoubleSpinBoxFactory();
|
||||||
|
DecoratedDoubleSpinBoxFactory *decoratedFactory = new DecoratedDoubleSpinBoxFactory();
|
||||||
|
|
||||||
|
QtTreePropertyBrowser *editor = new QtTreePropertyBrowser();
|
||||||
|
editor->setFactoryForManager(undecoratedManager, undecoratedFactory);
|
||||||
|
editor->setFactoryForManager(decoratedManager, decoratedFactory);
|
||||||
|
editor->addProperty(undecoratedProperty);
|
||||||
|
editor->addProperty(decoratedProperty);
|
||||||
|
editor->show();
|
||||||
|
|
||||||
|
int ret = app.exec();
|
||||||
|
|
||||||
|
delete decoratedFactory;
|
||||||
|
delete decoratedManager;
|
||||||
|
delete undecoratedFactory;
|
||||||
|
delete undecoratedManager;
|
||||||
|
delete editor;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "main.moc"
|
||||||
19
examples/demo/CMakeLists.txt
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
SET(example_name demo)
|
||||||
|
|
||||||
|
SET(KIT_SRCS
|
||||||
|
main.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
SET(KIT_resources
|
||||||
|
demo.qrc
|
||||||
|
)
|
||||||
|
|
||||||
|
IF(QT5_FOUND)
|
||||||
|
QT5_ADD_RESOURCES(KIT_QRC_SRCS ${KIT_resources})
|
||||||
|
ELSE()
|
||||||
|
QT4_ADD_RESOURCES(KIT_QRC_SRCS ${KIT_resources})
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
ADD_EXECUTABLE(${example_name} ${KIT_SRCS} ${KIT_QRC_SRCS})
|
||||||
|
TARGET_LINK_LIBRARIES(${example_name} ${PROJECT_NAME} ${QT_TARGETS})
|
||||||
8
examples/demo/demo.pro
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
TEMPLATE = app
|
||||||
|
DEPENDPATH += .
|
||||||
|
INCLUDEPATH += .
|
||||||
|
|
||||||
|
include(../../src/qtpropertybrowser.pri)
|
||||||
|
# Input
|
||||||
|
SOURCES += main.cpp
|
||||||
|
RESOURCES += demo.qrc
|
||||||
59
examples/demo/demo.qdoc
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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."
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\page qtpropertybrowser-example-demo.html
|
||||||
|
\title Demo Example
|
||||||
|
|
||||||
|
This example shows how to customize a property browser widget's
|
||||||
|
appearance and behavior.
|
||||||
|
|
||||||
|
\image demo.png
|
||||||
|
|
||||||
|
The various property browsers presented in this example display
|
||||||
|
the same set of properties, and are implementations of the
|
||||||
|
QtTreePropertyBrowser class and the QtGroupBoxPropertyBrowser
|
||||||
|
class, respectively.
|
||||||
|
|
||||||
|
The example shows how a property browser's appearance and behavior can
|
||||||
|
be varied using the QtPropertyBrowser framework's property
|
||||||
|
managers and editor factories.
|
||||||
|
|
||||||
|
The source files can be found in examples/demo directory of the package.
|
||||||
|
*/
|
||||||
8
examples/demo/demo.qrc
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<RCC version="1.0">
|
||||||
|
<qresource prefix="/demo">
|
||||||
|
<file>images/up.png</file>
|
||||||
|
<file>images/down.png</file>
|
||||||
|
<file>images/right.png</file>
|
||||||
|
<file>images/left.png</file>
|
||||||
|
</qresource>
|
||||||
|
</RCC>
|
||||||
BIN
examples/demo/images/down.png
Normal file
|
After Width: | Height: | Size: 594 B |
BIN
examples/demo/images/left.png
Normal file
|
After Width: | Height: | Size: 678 B |
BIN
examples/demo/images/right.png
Normal file
|
After Width: | Height: | Size: 655 B |
BIN
examples/demo/images/up.png
Normal file
|
After Width: | Height: | Size: 692 B |
215
examples/demo/main.cpp
Normal file
@@ -0,0 +1,215 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 <QApplication>
|
||||||
|
#include <QScrollArea>
|
||||||
|
#include <QGridLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QIcon>
|
||||||
|
#include <QMap>
|
||||||
|
#include "qtpropertymanager.h"
|
||||||
|
#include "qteditorfactory.h"
|
||||||
|
#include "qttreepropertybrowser.h"
|
||||||
|
#include "qtbuttonpropertybrowser.h"
|
||||||
|
#include "qtgroupboxpropertybrowser.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
|
QWidget *w = new QWidget();
|
||||||
|
|
||||||
|
QtBoolPropertyManager *boolManager = new QtBoolPropertyManager(w);
|
||||||
|
QtIntPropertyManager *intManager = new QtIntPropertyManager(w);
|
||||||
|
QtStringPropertyManager *stringManager = new QtStringPropertyManager(w);
|
||||||
|
QtSizePropertyManager *sizeManager = new QtSizePropertyManager(w);
|
||||||
|
QtRectPropertyManager *rectManager = new QtRectPropertyManager(w);
|
||||||
|
QtSizePolicyPropertyManager *sizePolicyManager = new QtSizePolicyPropertyManager(w);
|
||||||
|
QtEnumPropertyManager *enumManager = new QtEnumPropertyManager(w);
|
||||||
|
QtGroupPropertyManager *groupManager = new QtGroupPropertyManager(w);
|
||||||
|
|
||||||
|
QtProperty *item0 = groupManager->addProperty("QObject");
|
||||||
|
|
||||||
|
QtProperty *item1 = stringManager->addProperty("objectName");
|
||||||
|
item0->addSubProperty(item1);
|
||||||
|
|
||||||
|
QtProperty *item2 = boolManager->addProperty("enabled");
|
||||||
|
item0->addSubProperty(item2);
|
||||||
|
|
||||||
|
QtProperty *item3 = rectManager->addProperty("geometry");
|
||||||
|
item0->addSubProperty(item3);
|
||||||
|
|
||||||
|
QtProperty *item4 = sizePolicyManager->addProperty("sizePolicy");
|
||||||
|
item0->addSubProperty(item4);
|
||||||
|
|
||||||
|
QtProperty *item5 = sizeManager->addProperty("sizeIncrement");
|
||||||
|
item0->addSubProperty(item5);
|
||||||
|
|
||||||
|
QtProperty *item7 = boolManager->addProperty("mouseTracking");
|
||||||
|
item0->addSubProperty(item7);
|
||||||
|
|
||||||
|
QtProperty *item8 = enumManager->addProperty("direction");
|
||||||
|
QStringList enumNames;
|
||||||
|
enumNames << "Up" << "Right" << "Down" << "Left";
|
||||||
|
enumManager->setEnumNames(item8, enumNames);
|
||||||
|
QMap<int, QIcon> enumIcons;
|
||||||
|
enumIcons[0] = QIcon(":/demo/images/up.png");
|
||||||
|
enumIcons[1] = QIcon(":/demo/images/right.png");
|
||||||
|
enumIcons[2] = QIcon(":/demo/images/down.png");
|
||||||
|
enumIcons[3] = QIcon(":/demo/images/left.png");
|
||||||
|
enumManager->setEnumIcons(item8, enumIcons);
|
||||||
|
item0->addSubProperty(item8);
|
||||||
|
|
||||||
|
QtProperty *item9 = intManager->addProperty("value");
|
||||||
|
intManager->setRange(item9, -100, 100);
|
||||||
|
item0->addSubProperty(item9);
|
||||||
|
|
||||||
|
QtCheckBoxFactory *checkBoxFactory = new QtCheckBoxFactory(w);
|
||||||
|
QtSpinBoxFactory *spinBoxFactory = new QtSpinBoxFactory(w);
|
||||||
|
QtSliderFactory *sliderFactory = new QtSliderFactory(w);
|
||||||
|
QtScrollBarFactory *scrollBarFactory = new QtScrollBarFactory(w);
|
||||||
|
QtLineEditFactory *lineEditFactory = new QtLineEditFactory(w);
|
||||||
|
QtEnumEditorFactory *comboBoxFactory = new QtEnumEditorFactory(w);
|
||||||
|
|
||||||
|
QtAbstractPropertyBrowser *editor1 = new QtTreePropertyBrowser();
|
||||||
|
editor1->setFactoryForManager(boolManager, checkBoxFactory);
|
||||||
|
editor1->setFactoryForManager(intManager, spinBoxFactory);
|
||||||
|
editor1->setFactoryForManager(stringManager, lineEditFactory);
|
||||||
|
editor1->setFactoryForManager(sizeManager->subIntPropertyManager(), spinBoxFactory);
|
||||||
|
editor1->setFactoryForManager(rectManager->subIntPropertyManager(), spinBoxFactory);
|
||||||
|
editor1->setFactoryForManager(sizePolicyManager->subIntPropertyManager(), spinBoxFactory);
|
||||||
|
editor1->setFactoryForManager(sizePolicyManager->subEnumPropertyManager(), comboBoxFactory);
|
||||||
|
editor1->setFactoryForManager(enumManager, comboBoxFactory);
|
||||||
|
|
||||||
|
editor1->addProperty(item0);
|
||||||
|
|
||||||
|
QtAbstractPropertyBrowser *editor2 = new QtTreePropertyBrowser();
|
||||||
|
editor2->addProperty(item0);
|
||||||
|
|
||||||
|
QtAbstractPropertyBrowser *editor3 = new QtGroupBoxPropertyBrowser();
|
||||||
|
editor3->setFactoryForManager(boolManager, checkBoxFactory);
|
||||||
|
editor3->setFactoryForManager(intManager, spinBoxFactory);
|
||||||
|
editor3->setFactoryForManager(stringManager, lineEditFactory);
|
||||||
|
editor3->setFactoryForManager(sizeManager->subIntPropertyManager(), spinBoxFactory);
|
||||||
|
editor3->setFactoryForManager(rectManager->subIntPropertyManager(), spinBoxFactory);
|
||||||
|
editor3->setFactoryForManager(sizePolicyManager->subIntPropertyManager(), spinBoxFactory);
|
||||||
|
editor3->setFactoryForManager(sizePolicyManager->subEnumPropertyManager(), comboBoxFactory);
|
||||||
|
editor3->setFactoryForManager(enumManager, comboBoxFactory);
|
||||||
|
|
||||||
|
editor3->addProperty(item0);
|
||||||
|
|
||||||
|
QScrollArea *scroll3 = new QScrollArea();
|
||||||
|
scroll3->setWidgetResizable(true);
|
||||||
|
scroll3->setWidget(editor3);
|
||||||
|
|
||||||
|
QtAbstractPropertyBrowser *editor4 = new QtGroupBoxPropertyBrowser();
|
||||||
|
editor4->setFactoryForManager(boolManager, checkBoxFactory);
|
||||||
|
editor4->setFactoryForManager(intManager, scrollBarFactory);
|
||||||
|
editor4->setFactoryForManager(stringManager, lineEditFactory);
|
||||||
|
editor4->setFactoryForManager(sizeManager->subIntPropertyManager(), spinBoxFactory);
|
||||||
|
editor4->setFactoryForManager(rectManager->subIntPropertyManager(), spinBoxFactory);
|
||||||
|
editor4->setFactoryForManager(sizePolicyManager->subIntPropertyManager(), sliderFactory);
|
||||||
|
editor4->setFactoryForManager(sizePolicyManager->subEnumPropertyManager(), comboBoxFactory);
|
||||||
|
editor4->setFactoryForManager(enumManager, comboBoxFactory);
|
||||||
|
|
||||||
|
editor4->addProperty(item0);
|
||||||
|
|
||||||
|
QScrollArea *scroll4 = new QScrollArea();
|
||||||
|
scroll4->setWidgetResizable(true);
|
||||||
|
scroll4->setWidget(editor4);
|
||||||
|
|
||||||
|
QtAbstractPropertyBrowser *editor5 = new QtButtonPropertyBrowser();
|
||||||
|
editor5->setFactoryForManager(boolManager, checkBoxFactory);
|
||||||
|
editor5->setFactoryForManager(intManager, scrollBarFactory);
|
||||||
|
editor5->setFactoryForManager(stringManager, lineEditFactory);
|
||||||
|
editor5->setFactoryForManager(sizeManager->subIntPropertyManager(), spinBoxFactory);
|
||||||
|
editor5->setFactoryForManager(rectManager->subIntPropertyManager(), spinBoxFactory);
|
||||||
|
editor5->setFactoryForManager(sizePolicyManager->subIntPropertyManager(), sliderFactory);
|
||||||
|
editor5->setFactoryForManager(sizePolicyManager->subEnumPropertyManager(), comboBoxFactory);
|
||||||
|
editor5->setFactoryForManager(enumManager, comboBoxFactory);
|
||||||
|
|
||||||
|
editor5->addProperty(item0);
|
||||||
|
|
||||||
|
QScrollArea *scroll5 = new QScrollArea();
|
||||||
|
scroll5->setWidgetResizable(true);
|
||||||
|
scroll5->setWidget(editor5);
|
||||||
|
|
||||||
|
QGridLayout *layout = new QGridLayout(w);
|
||||||
|
QLabel *label1 = new QLabel("Editable Tree Property Browser");
|
||||||
|
QLabel *label2 = new QLabel("Read Only Tree Property Browser, editor factories are not set");
|
||||||
|
QLabel *label3 = new QLabel("Group Box Property Browser");
|
||||||
|
QLabel *label4 = new QLabel("Group Box Property Browser with different editor factories");
|
||||||
|
QLabel *label5 = new QLabel("Button Property Browser");
|
||||||
|
label1->setWordWrap(true);
|
||||||
|
label2->setWordWrap(true);
|
||||||
|
label3->setWordWrap(true);
|
||||||
|
label4->setWordWrap(true);
|
||||||
|
label5->setWordWrap(true);
|
||||||
|
label1->setFrameShadow(QFrame::Sunken);
|
||||||
|
label2->setFrameShadow(QFrame::Sunken);
|
||||||
|
label3->setFrameShadow(QFrame::Sunken);
|
||||||
|
label4->setFrameShadow(QFrame::Sunken);
|
||||||
|
label5->setFrameShadow(QFrame::Sunken);
|
||||||
|
label1->setFrameShape(QFrame::Panel);
|
||||||
|
label2->setFrameShape(QFrame::Panel);
|
||||||
|
label3->setFrameShape(QFrame::Panel);
|
||||||
|
label4->setFrameShape(QFrame::Panel);
|
||||||
|
label5->setFrameShape(QFrame::Panel);
|
||||||
|
label1->setAlignment(Qt::AlignCenter);
|
||||||
|
label2->setAlignment(Qt::AlignCenter);
|
||||||
|
label3->setAlignment(Qt::AlignCenter);
|
||||||
|
label4->setAlignment(Qt::AlignCenter);
|
||||||
|
label5->setAlignment(Qt::AlignCenter);
|
||||||
|
|
||||||
|
layout->addWidget(label1, 0, 0);
|
||||||
|
layout->addWidget(label2, 0, 1);
|
||||||
|
layout->addWidget(label3, 0, 2);
|
||||||
|
layout->addWidget(label4, 0, 3);
|
||||||
|
layout->addWidget(label5, 0, 4);
|
||||||
|
layout->addWidget(editor1, 1, 0);
|
||||||
|
layout->addWidget(editor2, 1, 1);
|
||||||
|
layout->addWidget(scroll3, 1, 2);
|
||||||
|
layout->addWidget(scroll4, 1, 3);
|
||||||
|
layout->addWidget(scroll5, 1, 4);
|
||||||
|
w->show();
|
||||||
|
|
||||||
|
int ret = app.exec();
|
||||||
|
delete w;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
7
examples/examples.pro
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
######################################################################
|
||||||
|
# Automatically generated by qmake (2.00a) Wed Jun 15 15:53:34 2005
|
||||||
|
######################################################################
|
||||||
|
|
||||||
|
TEMPLATE = subdirs
|
||||||
|
SUBDIRS = simple canvas_variant canvas_typed demo decoration extension object_controller
|
||||||
|
|
||||||
15
examples/extension/CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# Tell CMake to run moc when necessary:
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
|
||||||
|
# As moc files are generated in the binary dir, tell CMake
|
||||||
|
# to always look for includes there:
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
|
SET(example_name extension)
|
||||||
|
|
||||||
|
SET(KIT_SRCS
|
||||||
|
main.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
ADD_EXECUTABLE(${example_name} ${KIT_SRCS})
|
||||||
|
TARGET_LINK_LIBRARIES(${example_name} ${PROJECT_NAME} ${QT_TARGETS})
|
||||||
8
examples/extension/extension.pro
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
TEMPLATE = app
|
||||||
|
DEPENDPATH += .
|
||||||
|
INCLUDEPATH += .
|
||||||
|
|
||||||
|
include(../../src/qtpropertybrowser.pri)
|
||||||
|
# Input
|
||||||
|
SOURCES += main.cpp
|
||||||
|
|
||||||
53
examples/extension/extension.qdoc
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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."
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\page qtpropertybrowser-example-extension.html
|
||||||
|
\title Extension Example
|
||||||
|
|
||||||
|
This example demonstrates how to extend the
|
||||||
|
QtVariantPropertyManager class to handle additional property
|
||||||
|
types.
|
||||||
|
|
||||||
|
\image extension.png
|
||||||
|
|
||||||
|
The variant manager is extended to handle the QPointF type.
|
||||||
|
|
||||||
|
The source files can be found in examples/extension directory of the package.
|
||||||
|
*/
|
||||||
238
examples/extension/main.cpp
Normal file
@@ -0,0 +1,238 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 <QApplication>
|
||||||
|
#include "qtvariantproperty.h"
|
||||||
|
#include "qteditorfactory.h"
|
||||||
|
#include "qttreepropertybrowser.h"
|
||||||
|
|
||||||
|
class VariantManager : public QtVariantPropertyManager
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
VariantManager(QObject *parent = 0);
|
||||||
|
~VariantManager();
|
||||||
|
|
||||||
|
virtual QVariant value(const QtProperty *property) const;
|
||||||
|
virtual int valueType(int propertyType) const;
|
||||||
|
virtual bool isPropertyTypeSupported(int propertyType) const;
|
||||||
|
|
||||||
|
QString valueText(const QtProperty *property) const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual void setValue(QtProperty *property, const QVariant &val);
|
||||||
|
protected:
|
||||||
|
virtual void initializeProperty(QtProperty *property);
|
||||||
|
virtual void uninitializeProperty(QtProperty *property);
|
||||||
|
private slots:
|
||||||
|
void slotValueChanged(QtProperty *property, const QVariant &value);
|
||||||
|
void slotPropertyDestroyed(QtProperty *property);
|
||||||
|
private:
|
||||||
|
struct Data {
|
||||||
|
QVariant value;
|
||||||
|
QtVariantProperty *x;
|
||||||
|
QtVariantProperty *y;
|
||||||
|
};
|
||||||
|
QMap<const QtProperty *, Data> propertyToData;
|
||||||
|
QMap<const QtProperty *, QtProperty *> xToProperty;
|
||||||
|
QMap<const QtProperty *, QtProperty *> yToProperty;
|
||||||
|
};
|
||||||
|
|
||||||
|
VariantManager::VariantManager(QObject *parent)
|
||||||
|
: QtVariantPropertyManager(parent)
|
||||||
|
{
|
||||||
|
connect(this, SIGNAL(valueChanged(QtProperty *, const QVariant &)),
|
||||||
|
this, SLOT(slotValueChanged(QtProperty *, const QVariant &)));
|
||||||
|
connect(this, SIGNAL(propertyDestroyed(QtProperty *)),
|
||||||
|
this, SLOT(slotPropertyDestroyed(QtProperty *)));
|
||||||
|
}
|
||||||
|
|
||||||
|
VariantManager::~VariantManager()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void VariantManager::slotValueChanged(QtProperty *property, const QVariant &value)
|
||||||
|
{
|
||||||
|
if (xToProperty.contains(property)) {
|
||||||
|
QtProperty *pointProperty = xToProperty[property];
|
||||||
|
QVariant v = this->value(pointProperty);
|
||||||
|
QPointF p = v.value<QPointF>();
|
||||||
|
p.setX(value.value<double>());
|
||||||
|
setValue(pointProperty, p);
|
||||||
|
} else if (yToProperty.contains(property)) {
|
||||||
|
QtProperty *pointProperty = yToProperty[property];
|
||||||
|
QVariant v = this->value(pointProperty);
|
||||||
|
QPointF p = v.value<QPointF>();
|
||||||
|
p.setY(value.value<double>());
|
||||||
|
setValue(pointProperty, p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void VariantManager::slotPropertyDestroyed(QtProperty *property)
|
||||||
|
{
|
||||||
|
if (xToProperty.contains(property)) {
|
||||||
|
QtProperty *pointProperty = xToProperty[property];
|
||||||
|
propertyToData[pointProperty].x = 0;
|
||||||
|
xToProperty.remove(property);
|
||||||
|
} else if (yToProperty.contains(property)) {
|
||||||
|
QtProperty *pointProperty = yToProperty[property];
|
||||||
|
propertyToData[pointProperty].y = 0;
|
||||||
|
yToProperty.remove(property);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool VariantManager::isPropertyTypeSupported(int propertyType) const
|
||||||
|
{
|
||||||
|
if (propertyType == QVariant::PointF)
|
||||||
|
return true;
|
||||||
|
return QtVariantPropertyManager::isPropertyTypeSupported(propertyType);
|
||||||
|
}
|
||||||
|
|
||||||
|
int VariantManager::valueType(int propertyType) const
|
||||||
|
{
|
||||||
|
if (propertyType == QVariant::PointF)
|
||||||
|
return QVariant::PointF;
|
||||||
|
return QtVariantPropertyManager::valueType(propertyType);
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant VariantManager::value(const QtProperty *property) const
|
||||||
|
{
|
||||||
|
if (propertyToData.contains(property))
|
||||||
|
return propertyToData[property].value;
|
||||||
|
return QtVariantPropertyManager::value(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString VariantManager::valueText(const QtProperty *property) const
|
||||||
|
{
|
||||||
|
if (propertyToData.contains(property)) {
|
||||||
|
QVariant v = propertyToData[property].value;
|
||||||
|
QPointF p = v.value<QPointF>();
|
||||||
|
return QString(tr("(%1, %2)").arg(QString::number(p.x()))
|
||||||
|
.arg(QString::number(p.y())));
|
||||||
|
}
|
||||||
|
return QtVariantPropertyManager::valueText(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VariantManager::setValue(QtProperty *property, const QVariant &val)
|
||||||
|
{
|
||||||
|
if (propertyToData.contains(property)) {
|
||||||
|
if (val.type() != QVariant::PointF && !val.canConvert(QVariant::PointF))
|
||||||
|
return;
|
||||||
|
QPointF p = val.value<QPointF>();
|
||||||
|
Data d = propertyToData[property];
|
||||||
|
d.value = p;
|
||||||
|
if (d.x)
|
||||||
|
d.x->setValue(p.x());
|
||||||
|
if (d.y)
|
||||||
|
d.y->setValue(p.y());
|
||||||
|
propertyToData[property] = d;
|
||||||
|
emit propertyChanged(property);
|
||||||
|
emit valueChanged(property, p);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QtVariantPropertyManager::setValue(property, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VariantManager::initializeProperty(QtProperty *property)
|
||||||
|
{
|
||||||
|
if (propertyType(property) == QVariant::PointF) {
|
||||||
|
Data d;
|
||||||
|
|
||||||
|
d.value = QPointF(0, 0);
|
||||||
|
|
||||||
|
VariantManager *that = (VariantManager *)this;
|
||||||
|
|
||||||
|
d.x = that->addProperty(QVariant::Double);
|
||||||
|
d.x->setPropertyName(tr("Position X"));
|
||||||
|
property->addSubProperty(d.x);
|
||||||
|
xToProperty[d.x] = property;
|
||||||
|
|
||||||
|
d.y = that->addProperty(QVariant::Double);
|
||||||
|
d.y->setPropertyName(tr("Position Y"));
|
||||||
|
property->addSubProperty(d.y);
|
||||||
|
yToProperty[d.y] = property;
|
||||||
|
|
||||||
|
propertyToData[property] = d;
|
||||||
|
}
|
||||||
|
QtVariantPropertyManager::initializeProperty(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
void VariantManager::uninitializeProperty(QtProperty *property)
|
||||||
|
{
|
||||||
|
if (propertyToData.contains(property)) {
|
||||||
|
Data d = propertyToData[property];
|
||||||
|
if (d.x)
|
||||||
|
xToProperty.remove(d.x);
|
||||||
|
if (d.y)
|
||||||
|
yToProperty.remove(d.y);
|
||||||
|
propertyToData.remove(property);
|
||||||
|
}
|
||||||
|
QtVariantPropertyManager::uninitializeProperty(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
|
VariantManager *variantManager = new VariantManager();
|
||||||
|
|
||||||
|
QtVariantProperty *item = variantManager->addProperty(QVariant::PointF,
|
||||||
|
"PointF Property");
|
||||||
|
item->setValue(QPointF(2.5, 13.13));
|
||||||
|
|
||||||
|
QtVariantEditorFactory *variantFactory = new QtVariantEditorFactory();
|
||||||
|
|
||||||
|
QtTreePropertyBrowser ed1;
|
||||||
|
QtVariantPropertyManager *varMan = variantManager;
|
||||||
|
ed1.setFactoryForManager(varMan, variantFactory);
|
||||||
|
ed1.addProperty(item);
|
||||||
|
|
||||||
|
|
||||||
|
ed1.show();
|
||||||
|
|
||||||
|
int ret = app.exec();
|
||||||
|
|
||||||
|
delete variantFactory;
|
||||||
|
delete variantManager;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "main.moc"
|
||||||
16
examples/object_controller/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# Tell CMake to run moc when necessary:
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
|
||||||
|
# As moc files are generated in the binary dir, tell CMake
|
||||||
|
# to always look for includes there:
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
|
SET(example_name object_controller)
|
||||||
|
|
||||||
|
SET(KIT_SRCS
|
||||||
|
main.cpp
|
||||||
|
objectcontroller.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
ADD_EXECUTABLE(${example_name} ${KIT_SRCS})
|
||||||
|
TARGET_LINK_LIBRARIES(${example_name} ${PROJECT_NAME} ${QT_TARGETS})
|
||||||
167
examples/object_controller/main.cpp
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 <QApplication>
|
||||||
|
#include <QSpinBox>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
#include <QLineEdit>
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QToolButton>
|
||||||
|
#include <QPushButton>
|
||||||
|
#include <QBoxLayout>
|
||||||
|
#include <QTreeWidget>
|
||||||
|
#include <QAction>
|
||||||
|
#include <QDesktopWidget>
|
||||||
|
#include <QTextDocument>
|
||||||
|
#include <QCalendarWidget>
|
||||||
|
#include <QTimeLine>
|
||||||
|
#include "objectcontroller.h"
|
||||||
|
|
||||||
|
class MyController : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
MyController(QWidget *parent = 0);
|
||||||
|
~MyController();
|
||||||
|
private slots:
|
||||||
|
void createAndControl();
|
||||||
|
private:
|
||||||
|
QComboBox *theClassCombo;
|
||||||
|
ObjectController *theController;
|
||||||
|
QStringList theClassNames;
|
||||||
|
QObject *theControlledObject;
|
||||||
|
};
|
||||||
|
|
||||||
|
MyController::MyController(QWidget *parent)
|
||||||
|
: QDialog(parent), theControlledObject(0)
|
||||||
|
{
|
||||||
|
theClassCombo = new QComboBox(this);
|
||||||
|
QToolButton *button = new QToolButton(this);
|
||||||
|
theController = new ObjectController(this);
|
||||||
|
QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
|
||||||
|
|
||||||
|
connect(button, SIGNAL(clicked()), this, SLOT(createAndControl()));
|
||||||
|
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||||
|
|
||||||
|
button->setText(tr("Create And Control"));
|
||||||
|
buttonBox->setStandardButtons(QDialogButtonBox::Close);
|
||||||
|
|
||||||
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||||
|
QHBoxLayout *internalLayout = new QHBoxLayout();
|
||||||
|
internalLayout->addWidget(theClassCombo);
|
||||||
|
internalLayout->addWidget(button);
|
||||||
|
layout->addLayout(internalLayout);
|
||||||
|
layout->addWidget(theController);
|
||||||
|
layout->addWidget(buttonBox);
|
||||||
|
|
||||||
|
theClassNames.append(QLatin1String("QWidget"));
|
||||||
|
theClassNames.append(QLatin1String("QPushButton"));
|
||||||
|
theClassNames.append(QLatin1String("QDialogButtonBox"));
|
||||||
|
theClassNames.append(QLatin1String("QTreeWidget"));
|
||||||
|
theClassNames.append(QLatin1String("QCalendarWidget"));
|
||||||
|
theClassNames.append(QLatin1String("QAction"));
|
||||||
|
theClassNames.append(QLatin1String("QTimeLine"));
|
||||||
|
theClassNames.append(QLatin1String("QTextDocument"));
|
||||||
|
|
||||||
|
theClassCombo->addItems(theClassNames);
|
||||||
|
}
|
||||||
|
|
||||||
|
MyController::~MyController()
|
||||||
|
{
|
||||||
|
if (theControlledObject)
|
||||||
|
delete theControlledObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyController::createAndControl()
|
||||||
|
{
|
||||||
|
QObject *newObject = 0;
|
||||||
|
QString className = theClassNames.at(theClassCombo->currentIndex());
|
||||||
|
if (className == QLatin1String("QWidget"))
|
||||||
|
newObject = new QWidget();
|
||||||
|
else if (className == QLatin1String("QPushButton"))
|
||||||
|
newObject = new QPushButton();
|
||||||
|
else if (className == QLatin1String("QDialogButtonBox"))
|
||||||
|
newObject = new QDialogButtonBox();
|
||||||
|
else if (className == QLatin1String("QTreeWidget"))
|
||||||
|
newObject = new QTreeWidget();
|
||||||
|
else if (className == QLatin1String("QCalendarWidget"))
|
||||||
|
newObject = new QCalendarWidget();
|
||||||
|
else if (className == QLatin1String("QAction"))
|
||||||
|
newObject = new QAction(0);
|
||||||
|
else if (className == QLatin1String("QTimeLine"))
|
||||||
|
newObject = new QTimeLine();
|
||||||
|
else if (className == QLatin1String("QTextDocument"))
|
||||||
|
newObject = new QTextDocument();
|
||||||
|
|
||||||
|
if (!newObject)
|
||||||
|
return;
|
||||||
|
|
||||||
|
QWidget *newWidget = qobject_cast<QWidget *>(newObject);
|
||||||
|
if (newWidget) {
|
||||||
|
QRect r = newWidget->geometry();
|
||||||
|
r.setSize(newWidget->sizeHint());
|
||||||
|
r.setWidth(qMax(r.width(), 150));
|
||||||
|
r.setHeight(qMax(r.height(), 50));
|
||||||
|
r.moveCenter(QApplication::desktop()->geometry().center());
|
||||||
|
newWidget->setGeometry(r);
|
||||||
|
newWidget->setWindowTitle(tr("Controlled Object: %1").arg(className));
|
||||||
|
newWidget->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (theControlledObject)
|
||||||
|
delete theControlledObject;
|
||||||
|
|
||||||
|
theControlledObject = newObject;
|
||||||
|
theController->setObject(theControlledObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
|
MyController *controller = new MyController();
|
||||||
|
controller->show();
|
||||||
|
|
||||||
|
int ret = app.exec();
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "main.moc"
|
||||||
54
examples/object_controller/object_controller.qdoc
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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."
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\page qtpropertybrowser-example-object_controller.html
|
||||||
|
\title The Object Controller Example.
|
||||||
|
|
||||||
|
\image object_controller.png
|
||||||
|
|
||||||
|
This example implements a simple widget component which shows
|
||||||
|
QObject's and its subclasses' properties. The user can modify these properies interacively
|
||||||
|
and the object controller applies the changes to the controlled object.
|
||||||
|
The object controller is similar to the property editor used in QDesigner application.
|
||||||
|
To control the object just instantiate ObjectController, set controlled object (any QObject subclass) by
|
||||||
|
calling ObjectController::setObject() and show the controller.
|
||||||
|
|
||||||
|
The source files can be found in examples/object_controller directory of the package.
|
||||||
|
*/
|
||||||
391
examples/object_controller/objectcontroller.cpp
Normal file
@@ -0,0 +1,391 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 <QMetaObject>
|
||||||
|
#include <QMetaProperty>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
#include <QScrollArea>
|
||||||
|
#include "objectcontroller.h"
|
||||||
|
#include "qtvariantproperty.h"
|
||||||
|
#include "qtgroupboxpropertybrowser.h"
|
||||||
|
#include "qttreepropertybrowser.h"
|
||||||
|
#include "qtpropertybrowser.h"
|
||||||
|
|
||||||
|
class ObjectControllerPrivate
|
||||||
|
{
|
||||||
|
ObjectController *q_ptr;
|
||||||
|
Q_DECLARE_PUBLIC(ObjectController)
|
||||||
|
public:
|
||||||
|
|
||||||
|
void addClassProperties(const QMetaObject *metaObject);
|
||||||
|
void updateClassProperties(const QMetaObject *metaObject, bool recursive);
|
||||||
|
void saveExpandedState();
|
||||||
|
void restoreExpandedState();
|
||||||
|
void slotValueChanged(QtProperty *property, const QVariant &value);
|
||||||
|
int enumToInt(const QMetaEnum &metaEnum, int enumValue) const;
|
||||||
|
int intToEnum(const QMetaEnum &metaEnum, int intValue) const;
|
||||||
|
int flagToInt(const QMetaEnum &metaEnum, int flagValue) const;
|
||||||
|
int intToFlag(const QMetaEnum &metaEnum, int intValue) const;
|
||||||
|
bool isSubValue(int value, int subValue) const;
|
||||||
|
bool isPowerOf2(int value) const;
|
||||||
|
|
||||||
|
QObject *m_object;
|
||||||
|
|
||||||
|
QMap<const QMetaObject *, QtProperty *> m_classToProperty;
|
||||||
|
QMap<QtProperty *, const QMetaObject *> m_propertyToClass;
|
||||||
|
QMap<QtProperty *, int> m_propertyToIndex;
|
||||||
|
QMap<const QMetaObject *, QMap<int, QtVariantProperty *> > m_classToIndexToProperty;
|
||||||
|
|
||||||
|
QMap<QtProperty *, bool> m_propertyToExpanded;
|
||||||
|
|
||||||
|
QList<QtProperty *> m_topLevelProperties;
|
||||||
|
|
||||||
|
QtAbstractPropertyBrowser *m_browser;
|
||||||
|
QtVariantPropertyManager *m_manager;
|
||||||
|
QtVariantPropertyManager *m_readOnlyManager;
|
||||||
|
};
|
||||||
|
|
||||||
|
int ObjectControllerPrivate::enumToInt(const QMetaEnum &metaEnum, int enumValue) const
|
||||||
|
{
|
||||||
|
QMap<int, int> valueMap; // dont show multiple enum values which have the same values
|
||||||
|
int pos = 0;
|
||||||
|
for (int i = 0; i < metaEnum.keyCount(); i++) {
|
||||||
|
int value = metaEnum.value(i);
|
||||||
|
if (!valueMap.contains(value)) {
|
||||||
|
if (value == enumValue)
|
||||||
|
return pos;
|
||||||
|
valueMap[value] = pos++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ObjectControllerPrivate::intToEnum(const QMetaEnum &metaEnum, int intValue) const
|
||||||
|
{
|
||||||
|
QMap<int, bool> valueMap; // dont show multiple enum values which have the same values
|
||||||
|
QList<int> values;
|
||||||
|
for (int i = 0; i < metaEnum.keyCount(); i++) {
|
||||||
|
int value = metaEnum.value(i);
|
||||||
|
if (!valueMap.contains(value)) {
|
||||||
|
valueMap[value] = true;
|
||||||
|
values.append(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (intValue >= values.count())
|
||||||
|
return -1;
|
||||||
|
return values.at(intValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ObjectControllerPrivate::isSubValue(int value, int subValue) const
|
||||||
|
{
|
||||||
|
if (value == subValue)
|
||||||
|
return true;
|
||||||
|
int i = 0;
|
||||||
|
while (subValue) {
|
||||||
|
if (!(value & (1 << i))) {
|
||||||
|
if (subValue & 1)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
subValue = subValue >> 1;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ObjectControllerPrivate::isPowerOf2(int value) const
|
||||||
|
{
|
||||||
|
while (value) {
|
||||||
|
if (value & 1) {
|
||||||
|
return value == 1;
|
||||||
|
}
|
||||||
|
value = value >> 1;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ObjectControllerPrivate::flagToInt(const QMetaEnum &metaEnum, int flagValue) const
|
||||||
|
{
|
||||||
|
if (!flagValue)
|
||||||
|
return 0;
|
||||||
|
int intValue = 0;
|
||||||
|
QMap<int, int> valueMap; // dont show multiple enum values which have the same values
|
||||||
|
int pos = 0;
|
||||||
|
for (int i = 0; i < metaEnum.keyCount(); i++) {
|
||||||
|
int value = metaEnum.value(i);
|
||||||
|
if (!valueMap.contains(value) && isPowerOf2(value)) {
|
||||||
|
if (isSubValue(flagValue, value))
|
||||||
|
intValue |= (1 << pos);
|
||||||
|
valueMap[value] = pos++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return intValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ObjectControllerPrivate::intToFlag(const QMetaEnum &metaEnum, int intValue) const
|
||||||
|
{
|
||||||
|
QMap<int, bool> valueMap; // dont show multiple enum values which have the same values
|
||||||
|
QList<int> values;
|
||||||
|
for (int i = 0; i < metaEnum.keyCount(); i++) {
|
||||||
|
int value = metaEnum.value(i);
|
||||||
|
if (!valueMap.contains(value) && isPowerOf2(value)) {
|
||||||
|
valueMap[value] = true;
|
||||||
|
values.append(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int flagValue = 0;
|
||||||
|
int temp = intValue;
|
||||||
|
int i = 0;
|
||||||
|
while (temp) {
|
||||||
|
if (i >= values.count())
|
||||||
|
return -1;
|
||||||
|
if (temp & 1)
|
||||||
|
flagValue |= values.at(i);
|
||||||
|
i++;
|
||||||
|
temp = temp >> 1;
|
||||||
|
}
|
||||||
|
return flagValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectControllerPrivate::updateClassProperties(const QMetaObject *metaObject, bool recursive)
|
||||||
|
{
|
||||||
|
if (!metaObject)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (recursive)
|
||||||
|
updateClassProperties(metaObject->superClass(), recursive);
|
||||||
|
|
||||||
|
QtProperty *classProperty = m_classToProperty.value(metaObject);
|
||||||
|
if (!classProperty)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int idx = metaObject->propertyOffset(); idx < metaObject->propertyCount(); idx++) {
|
||||||
|
QMetaProperty metaProperty = metaObject->property(idx);
|
||||||
|
if (metaProperty.isReadable()) {
|
||||||
|
if (m_classToIndexToProperty.contains(metaObject) && m_classToIndexToProperty[metaObject].contains(idx)) {
|
||||||
|
QtVariantProperty *subProperty = m_classToIndexToProperty[metaObject][idx];
|
||||||
|
if (metaProperty.isEnumType()) {
|
||||||
|
if (metaProperty.isFlagType())
|
||||||
|
subProperty->setValue(flagToInt(metaProperty.enumerator(), metaProperty.read(m_object).toInt()));
|
||||||
|
else
|
||||||
|
subProperty->setValue(enumToInt(metaProperty.enumerator(), metaProperty.read(m_object).toInt()));
|
||||||
|
} else {
|
||||||
|
subProperty->setValue(metaProperty.read(m_object));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectControllerPrivate::addClassProperties(const QMetaObject *metaObject)
|
||||||
|
{
|
||||||
|
if (!metaObject)
|
||||||
|
return;
|
||||||
|
|
||||||
|
addClassProperties(metaObject->superClass());
|
||||||
|
|
||||||
|
QtProperty *classProperty = m_classToProperty.value(metaObject);
|
||||||
|
if (!classProperty) {
|
||||||
|
QString className = QLatin1String(metaObject->className());
|
||||||
|
classProperty = m_manager->addProperty(QtVariantPropertyManager::groupTypeId(), className);
|
||||||
|
m_classToProperty[metaObject] = classProperty;
|
||||||
|
m_propertyToClass[classProperty] = metaObject;
|
||||||
|
|
||||||
|
for (int idx = metaObject->propertyOffset(); idx < metaObject->propertyCount(); idx++) {
|
||||||
|
QMetaProperty metaProperty = metaObject->property(idx);
|
||||||
|
int type = metaProperty.userType();
|
||||||
|
QtVariantProperty *subProperty = 0;
|
||||||
|
if (!metaProperty.isReadable()) {
|
||||||
|
subProperty = m_readOnlyManager->addProperty(QVariant::String, QLatin1String(metaProperty.name()));
|
||||||
|
subProperty->setValue(QLatin1String("< Non Readable >"));
|
||||||
|
} else if (metaProperty.isEnumType()) {
|
||||||
|
if (metaProperty.isFlagType()) {
|
||||||
|
subProperty = m_manager->addProperty(QtVariantPropertyManager::flagTypeId(), QLatin1String(metaProperty.name()));
|
||||||
|
QMetaEnum metaEnum = metaProperty.enumerator();
|
||||||
|
QMap<int, bool> valueMap;
|
||||||
|
QStringList flagNames;
|
||||||
|
for (int i = 0; i < metaEnum.keyCount(); i++) {
|
||||||
|
int value = metaEnum.value(i);
|
||||||
|
if (!valueMap.contains(value) && isPowerOf2(value)) {
|
||||||
|
valueMap[value] = true;
|
||||||
|
flagNames.append(QLatin1String(metaEnum.key(i)));
|
||||||
|
}
|
||||||
|
subProperty->setAttribute(QLatin1String("flagNames"), flagNames);
|
||||||
|
subProperty->setValue(flagToInt(metaEnum, metaProperty.read(m_object).toInt()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
subProperty = m_manager->addProperty(QtVariantPropertyManager::enumTypeId(), QLatin1String(metaProperty.name()));
|
||||||
|
QMetaEnum metaEnum = metaProperty.enumerator();
|
||||||
|
QMap<int, bool> valueMap; // dont show multiple enum values which have the same values
|
||||||
|
QStringList enumNames;
|
||||||
|
for (int i = 0; i < metaEnum.keyCount(); i++) {
|
||||||
|
int value = metaEnum.value(i);
|
||||||
|
if (!valueMap.contains(value)) {
|
||||||
|
valueMap[value] = true;
|
||||||
|
enumNames.append(QLatin1String(metaEnum.key(i)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subProperty->setAttribute(QLatin1String("enumNames"), enumNames);
|
||||||
|
subProperty->setValue(enumToInt(metaEnum, metaProperty.read(m_object).toInt()));
|
||||||
|
}
|
||||||
|
} else if (m_manager->isPropertyTypeSupported(type)) {
|
||||||
|
if (!metaProperty.isWritable())
|
||||||
|
subProperty = m_readOnlyManager->addProperty(type, QLatin1String(metaProperty.name()) + QLatin1String(" (Non Writable)"));
|
||||||
|
if (!metaProperty.isDesignable())
|
||||||
|
subProperty = m_readOnlyManager->addProperty(type, QLatin1String(metaProperty.name()) + QLatin1String(" (Non Designable)"));
|
||||||
|
else
|
||||||
|
subProperty = m_manager->addProperty(type, QLatin1String(metaProperty.name()));
|
||||||
|
subProperty->setValue(metaProperty.read(m_object));
|
||||||
|
} else {
|
||||||
|
subProperty = m_readOnlyManager->addProperty(QVariant::String, QLatin1String(metaProperty.name()));
|
||||||
|
subProperty->setValue(QLatin1String("< Unknown Type >"));
|
||||||
|
subProperty->setEnabled(false);
|
||||||
|
}
|
||||||
|
classProperty->addSubProperty(subProperty);
|
||||||
|
m_propertyToIndex[subProperty] = idx;
|
||||||
|
m_classToIndexToProperty[metaObject][idx] = subProperty;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
updateClassProperties(metaObject, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_topLevelProperties.append(classProperty);
|
||||||
|
m_browser->addProperty(classProperty);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectControllerPrivate::saveExpandedState()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectControllerPrivate::restoreExpandedState()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectControllerPrivate::slotValueChanged(QtProperty *property, const QVariant &value)
|
||||||
|
{
|
||||||
|
if (!m_propertyToIndex.contains(property))
|
||||||
|
return;
|
||||||
|
|
||||||
|
int idx = m_propertyToIndex.value(property);
|
||||||
|
|
||||||
|
const QMetaObject *metaObject = m_object->metaObject();
|
||||||
|
QMetaProperty metaProperty = metaObject->property(idx);
|
||||||
|
if (metaProperty.isEnumType()) {
|
||||||
|
if (metaProperty.isFlagType())
|
||||||
|
metaProperty.write(m_object, intToFlag(metaProperty.enumerator(), value.toInt()));
|
||||||
|
else
|
||||||
|
metaProperty.write(m_object, intToEnum(metaProperty.enumerator(), value.toInt()));
|
||||||
|
} else {
|
||||||
|
metaProperty.write(m_object, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateClassProperties(metaObject, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////
|
||||||
|
|
||||||
|
ObjectController::ObjectController(QWidget *parent)
|
||||||
|
: QWidget(parent)
|
||||||
|
{
|
||||||
|
d_ptr = new ObjectControllerPrivate;
|
||||||
|
d_ptr->q_ptr = this;
|
||||||
|
|
||||||
|
d_ptr->m_object = 0;
|
||||||
|
/*
|
||||||
|
QScrollArea *scroll = new QScrollArea(this);
|
||||||
|
scroll->setWidgetResizable(true);
|
||||||
|
|
||||||
|
d_ptr->m_browser = new QtGroupBoxPropertyBrowser(this);
|
||||||
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||||
|
layout->setMargin(0);
|
||||||
|
layout->addWidget(scroll);
|
||||||
|
scroll->setWidget(d_ptr->m_browser);
|
||||||
|
*/
|
||||||
|
QtTreePropertyBrowser *browser = new QtTreePropertyBrowser(this);
|
||||||
|
browser->setRootIsDecorated(false);
|
||||||
|
d_ptr->m_browser = browser;
|
||||||
|
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||||
|
layout->setMargin(0);
|
||||||
|
layout->addWidget(d_ptr->m_browser);
|
||||||
|
|
||||||
|
d_ptr->m_readOnlyManager = new QtVariantPropertyManager(this);
|
||||||
|
d_ptr->m_manager = new QtVariantPropertyManager(this);
|
||||||
|
QtVariantEditorFactory *factory = new QtVariantEditorFactory(this);
|
||||||
|
d_ptr->m_browser->setFactoryForManager(d_ptr->m_manager, factory);
|
||||||
|
|
||||||
|
connect(d_ptr->m_manager, SIGNAL(valueChanged(QtProperty *, const QVariant &)),
|
||||||
|
this, SLOT(slotValueChanged(QtProperty *, const QVariant &)));
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectController::~ObjectController()
|
||||||
|
{
|
||||||
|
delete d_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectController::setObject(QObject *object)
|
||||||
|
{
|
||||||
|
if (d_ptr->m_object == object)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (d_ptr->m_object) {
|
||||||
|
d_ptr->saveExpandedState();
|
||||||
|
QListIterator<QtProperty *> it(d_ptr->m_topLevelProperties);
|
||||||
|
while (it.hasNext()) {
|
||||||
|
d_ptr->m_browser->removeProperty(it.next());
|
||||||
|
}
|
||||||
|
d_ptr->m_topLevelProperties.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
d_ptr->m_object = object;
|
||||||
|
|
||||||
|
if (!d_ptr->m_object)
|
||||||
|
return;
|
||||||
|
|
||||||
|
d_ptr->addClassProperties(d_ptr->m_object->metaObject());
|
||||||
|
|
||||||
|
d_ptr->restoreExpandedState();
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject *ObjectController::object() const
|
||||||
|
{
|
||||||
|
return d_ptr->m_object;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "moc_objectcontroller.cpp"
|
||||||
64
examples/object_controller/objectcontroller.h
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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."
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef OBJECTCONTROLLER_H
|
||||||
|
#define OBJECTCONTROLLER_H
|
||||||
|
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
|
class ObjectControllerPrivate;
|
||||||
|
|
||||||
|
class ObjectController : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
ObjectController(QWidget *parent = 0);
|
||||||
|
~ObjectController();
|
||||||
|
|
||||||
|
void setObject(QObject *object);
|
||||||
|
QObject *object() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ObjectControllerPrivate *d_ptr;
|
||||||
|
Q_DECLARE_PRIVATE(ObjectController)
|
||||||
|
Q_DISABLE_COPY(ObjectController)
|
||||||
|
Q_PRIVATE_SLOT(d_func(), void slotValueChanged(QtProperty *, const QVariant &))
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
9
examples/simple/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
SET(example_name simple)
|
||||||
|
|
||||||
|
SET(KIT_SRCS
|
||||||
|
main.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
ADD_EXECUTABLE(${example_name} ${KIT_SRCS})
|
||||||
|
TARGET_LINK_LIBRARIES(${example_name} ${PROJECT_NAME} ${QT_TARGETS})
|
||||||
180
examples/simple/main.cpp
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 <QApplication>
|
||||||
|
#include <QDate>
|
||||||
|
#include <QLocale>
|
||||||
|
#include "qtpropertymanager.h"
|
||||||
|
#include "qtvariantproperty.h"
|
||||||
|
#include "qttreepropertybrowser.h"
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
|
QtVariantPropertyManager *variantManager = new QtVariantPropertyManager();
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
QtProperty *topItem = variantManager->addProperty(QtVariantPropertyManager::groupTypeId(),
|
||||||
|
QString::number(i++) + QLatin1String(" Group Property"));
|
||||||
|
|
||||||
|
QtVariantProperty *item = variantManager->addProperty(QVariant::Bool, QString::number(i++) + QLatin1String(" Bool Property"));
|
||||||
|
item->setValue(true);
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::Int, QString::number(i++) + QLatin1String(" Int Property"));
|
||||||
|
item->setValue(20);
|
||||||
|
item->setAttribute(QLatin1String("minimum"), 0);
|
||||||
|
item->setAttribute(QLatin1String("maximum"), 100);
|
||||||
|
item->setAttribute(QLatin1String("singleStep"), 10);
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::Double, QString::number(i++) + QLatin1String(" Double Property"));
|
||||||
|
item->setValue(1.2345);
|
||||||
|
item->setAttribute(QLatin1String("singleStep"), 0.1);
|
||||||
|
item->setAttribute(QLatin1String("decimals"), 3);
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::String, QString::number(i++) + QLatin1String(" String Property"));
|
||||||
|
item->setValue("Value");
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::Date, QString::number(i++) + QLatin1String(" Date Property"));
|
||||||
|
item->setValue(QDate::currentDate().addDays(2));
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::Time, QString::number(i++) + QLatin1String(" Time Property"));
|
||||||
|
item->setValue(QTime::currentTime());
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::DateTime, QString::number(i++) + QLatin1String(" DateTime Property"));
|
||||||
|
item->setValue(QDateTime::currentDateTime());
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::KeySequence, QString::number(i++) + QLatin1String(" KeySequence Property"));
|
||||||
|
item->setValue(QKeySequence(Qt::ControlModifier | Qt::Key_Q));
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::Char, QString::number(i++) + QLatin1String(" Char Property"));
|
||||||
|
item->setValue(QChar(386));
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::Locale, QString::number(i++) + QLatin1String(" Locale Property"));
|
||||||
|
item->setValue(QLocale(QLocale::Polish, QLocale::Poland));
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::Point, QString::number(i++) + QLatin1String(" Point Property"));
|
||||||
|
item->setValue(QPoint(10, 10));
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::PointF, QString::number(i++) + QLatin1String(" PointF Property"));
|
||||||
|
item->setValue(QPointF(1.2345, -1.23451));
|
||||||
|
item->setAttribute(QLatin1String("decimals"), 3);
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::Size, QString::number(i++) + QLatin1String(" Size Property"));
|
||||||
|
item->setValue(QSize(20, 20));
|
||||||
|
item->setAttribute(QLatin1String("minimum"), QSize(10, 10));
|
||||||
|
item->setAttribute(QLatin1String("maximum"), QSize(30, 30));
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::SizeF, QString::number(i++) + QLatin1String(" SizeF Property"));
|
||||||
|
item->setValue(QSizeF(1.2345, 1.2345));
|
||||||
|
item->setAttribute(QLatin1String("decimals"), 3);
|
||||||
|
item->setAttribute(QLatin1String("minimum"), QSizeF(0.12, 0.34));
|
||||||
|
item->setAttribute(QLatin1String("maximum"), QSizeF(20.56, 20.78));
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::Rect, QString::number(i++) + QLatin1String(" Rect Property"));
|
||||||
|
item->setValue(QRect(10, 10, 20, 20));
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
item->setAttribute(QLatin1String("constraint"), QRect(0, 0, 50, 50));
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::RectF, QString::number(i++) + QLatin1String(" RectF Property"));
|
||||||
|
item->setValue(QRectF(1.2345, 1.2345, 1.2345, 1.2345));
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
item->setAttribute(QLatin1String("constraint"), QRectF(0, 0, 50, 50));
|
||||||
|
item->setAttribute(QLatin1String("decimals"), 3);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QtVariantPropertyManager::enumTypeId(),
|
||||||
|
QString::number(i++) + QLatin1String(" Enum Property"));
|
||||||
|
QStringList enumNames;
|
||||||
|
enumNames << "Enum0" << "Enum1" << "Enum2";
|
||||||
|
item->setAttribute(QLatin1String("enumNames"), enumNames);
|
||||||
|
item->setValue(1);
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QtVariantPropertyManager::flagTypeId(),
|
||||||
|
QString::number(i++) + QLatin1String(" Flag Property"));
|
||||||
|
QStringList flagNames;
|
||||||
|
flagNames << "Flag0" << "Flag1" << "Flag2";
|
||||||
|
item->setAttribute(QLatin1String("flagNames"), flagNames);
|
||||||
|
item->setValue(5);
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::SizePolicy, QString::number(i++) + QLatin1String(" SizePolicy Property"));
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::Font, QString::number(i++) + QLatin1String(" Font Property"));
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::Cursor, QString::number(i++) + QLatin1String(" Cursor Property"));
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
item = variantManager->addProperty(QVariant::Color, QString::number(i++) + QLatin1String(" Color Property"));
|
||||||
|
topItem->addSubProperty(item);
|
||||||
|
|
||||||
|
QtVariantEditorFactory *variantFactory = new QtVariantEditorFactory();
|
||||||
|
|
||||||
|
QtTreePropertyBrowser *variantEditor = new QtTreePropertyBrowser();
|
||||||
|
variantEditor->setFactoryForManager(variantManager, variantFactory);
|
||||||
|
variantEditor->addProperty(topItem);
|
||||||
|
variantEditor->setPropertiesWithoutValueMarked(true);
|
||||||
|
variantEditor->setRootIsDecorated(false);
|
||||||
|
|
||||||
|
variantEditor->show();
|
||||||
|
|
||||||
|
int ret = app.exec();
|
||||||
|
|
||||||
|
delete variantManager;
|
||||||
|
delete variantFactory;
|
||||||
|
delete variantEditor;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
51
examples/simple/simple.qdoc
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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."
|
||||||
|
**
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\page qtpropertybrowser-example-simple.html
|
||||||
|
\title Simple Tree Property Browser Example
|
||||||
|
|
||||||
|
\image simple.png
|
||||||
|
|
||||||
|
This example shows how to present various properties using a
|
||||||
|
simple tree property browser, i.e. an implementation of the
|
||||||
|
QtTreePropertyBrowser class.
|
||||||
|
|
||||||
|
The source files can be found in examples/simple directory of the package.
|
||||||
|
*/
|
||||||
116
src/CMakeLists.txt
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
# Tell CMake to run moc when necessary:
|
||||||
|
#set(CMAKE_AUTOMOC ON)
|
||||||
|
|
||||||
|
# As moc files are generated in the binary dir, tell CMake
|
||||||
|
# to always look for includes there:
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
|
SET(KIT_SRCS
|
||||||
|
qtbuttonpropertybrowser.cpp
|
||||||
|
qtbuttonpropertybrowser.h
|
||||||
|
qteditorfactory.cpp
|
||||||
|
qteditorfactory.h
|
||||||
|
qtgroupboxpropertybrowser.cpp
|
||||||
|
qtgroupboxpropertybrowser.h
|
||||||
|
qtpropertybrowser.cpp
|
||||||
|
qtpropertybrowser.h
|
||||||
|
qtpropertybrowserutils.cpp
|
||||||
|
qtpropertybrowserutils_p.h
|
||||||
|
qtpropertymanager.cpp
|
||||||
|
qtpropertymanager.h
|
||||||
|
qttreepropertybrowser.cpp
|
||||||
|
qttreepropertybrowser.h
|
||||||
|
qtvariantproperty.cpp
|
||||||
|
qtvariantproperty.h
|
||||||
|
)
|
||||||
|
|
||||||
|
SET(KIT_MOC_SRCS
|
||||||
|
qtpropertybrowserutils_p.h
|
||||||
|
)
|
||||||
|
|
||||||
|
SET(KIT_UI_FORMS
|
||||||
|
)
|
||||||
|
|
||||||
|
SET(KIT_resources
|
||||||
|
qtpropertybrowser.qrc
|
||||||
|
)
|
||||||
|
|
||||||
|
if(QT5_FOUND)
|
||||||
|
QT5_WRAP_UI(KIT_UI_CPP ${KIT_UI_FORMS})
|
||||||
|
QT5_WRAP_CPP(KIT_MOC_CPP ${KIT_MOC_SRCS})
|
||||||
|
QT5_ADD_RESOURCES(KIT_QRC_SRCS ${KIT_resources})
|
||||||
|
ELSE()
|
||||||
|
QT4_WRAP_UI(KIT_UI_CPP ${KIT_UI_FORMS})
|
||||||
|
QT4_WRAP_CPP(KIT_MOC_CPP ${KIT_MOC_SRCS})
|
||||||
|
QT4_ADD_RESOURCES(KIT_QRC_SRCS ${KIT_resources})
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
SET(libname ${PROJECT_NAME})
|
||||||
|
ADD_LIBRARY(${libname} STATIC
|
||||||
|
${KIT_SRCS}
|
||||||
|
${KIT_UI_CPP}
|
||||||
|
${KIT_MOC_CPP}
|
||||||
|
${KIT_QRC_SRCS}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(${libname} PRIVATE ${QT_INCLUDE_DIRS})
|
||||||
|
target_compile_definitions(${libname} PRIVATE ${QT_COMPILE_DEFS})
|
||||||
|
set_target_properties(${libname} PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||||
|
|
||||||
|
|
||||||
|
SET(${PROJECT_NAME}_LINK_LIBRARIES ${QT_LIBRARIES})
|
||||||
|
TARGET_LINK_LIBRARIES(
|
||||||
|
${libname}
|
||||||
|
${${PROJECT_NAME}_LINK_LIBRARIES}
|
||||||
|
)
|
||||||
|
|
||||||
|
# List of header that should go though moc
|
||||||
|
SET(KIT_HEADERS_MOC_SRCS
|
||||||
|
qtbuttonpropertybrowser.h
|
||||||
|
qteditorfactory.h
|
||||||
|
qtgroupboxpropertybrowser.h
|
||||||
|
qtpropertybrowser.h
|
||||||
|
qtpropertybrowserutils_p.h
|
||||||
|
qtpropertymanager.h
|
||||||
|
qttreepropertybrowser.h
|
||||||
|
qtvariantproperty.h
|
||||||
|
)
|
||||||
|
|
||||||
|
SET(KIT_MOC_CPP)
|
||||||
|
FOREACH(file ${KIT_HEADERS_MOC_SRCS})
|
||||||
|
get_filename_component(filename_we ${file} NAME_WE)
|
||||||
|
SET(output_file moc_${filename_we}.cpp)
|
||||||
|
|
||||||
|
IF(QT5_FOUND)
|
||||||
|
QT5_GENERATE_MOC(${file} ${output_file})
|
||||||
|
ELSE()
|
||||||
|
QT4_GENERATE_MOC(${file} ${output_file})
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
LIST(APPEND KIT_MOC_CPP ${output_file})
|
||||||
|
ENDFOREACH()
|
||||||
|
|
||||||
|
# List of cpp files that should go though moc
|
||||||
|
SET(KIT_CPP_MOC_SRCS
|
||||||
|
qteditorfactory.cpp
|
||||||
|
qtpropertymanager.cpp
|
||||||
|
qttreepropertybrowser.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
FOREACH(file ${KIT_CPP_MOC_SRCS})
|
||||||
|
get_filename_component(filename_we ${file} NAME_WE)
|
||||||
|
SET(output_file ${filename_we}.moc)
|
||||||
|
|
||||||
|
if(QT5_FOUND)
|
||||||
|
QT5_GENERATE_MOC(${file} ${output_file})
|
||||||
|
ELSE()
|
||||||
|
QT4_GENERATE_MOC(${file} ${output_file})
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
|
LIST(APPEND KIT_MOC_CPP ${output_file})
|
||||||
|
ENDFOREACH()
|
||||||
|
|
||||||
|
add_custom_target(${libname}GenerateMoc
|
||||||
|
DEPENDS ${KIT_MOC_CPP}
|
||||||
|
)
|
||||||
|
add_dependencies(${libname} ${libname}GenerateMoc)
|
||||||
1
src/QtAbstractEditorFactoryBase
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertybrowser.h"
|
||||||
1
src/QtAbstractPropertyBrowser
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertybrowser.h"
|
||||||
1
src/QtAbstractPropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertybrowser.h"
|
||||||
1
src/QtBoolPropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||
1
src/QtBrowserItem
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertybrowser.h"
|
||||||
1
src/QtButtonPropertyBrowser
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtbuttonpropertybrowser.h"
|
||||||
1
src/QtCharEditorFactory
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qteditorfactory.h"
|
||||||
1
src/QtCharPropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||
1
src/QtCheckBoxFactory
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qteditorfactory.h"
|
||||||
1
src/QtColorEditorFactory
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qteditorfactory.h"
|
||||||
1
src/QtColorPropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||
1
src/QtCursorEditorFactory
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qteditorfactory.h"
|
||||||
1
src/QtCursorPropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||
1
src/QtDateEditFactory
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qteditorfactory.h"
|
||||||
1
src/QtDatePropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||
1
src/QtDateTimeEditFactory
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qteditorfactory.h"
|
||||||
1
src/QtDateTimePropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||
1
src/QtDoublePropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||
1
src/QtDoubleSpinBoxFactory
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qteditorfactory.h"
|
||||||
1
src/QtEnumEditorFactory
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qteditorfactory.h"
|
||||||
1
src/QtEnumPropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||
1
src/QtFlagPropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||
1
src/QtFontEditorFactory
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qteditorfactory.h"
|
||||||
1
src/QtFontPropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||
1
src/QtGroupBoxPropertyBrowser
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtgroupboxpropertybrowser.h"
|
||||||
1
src/QtGroupPropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||
1
src/QtIntPropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||
1
src/QtKeySequenceEditorFactory
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qteditorfactory.h"
|
||||||
1
src/QtKeySequencePropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||
1
src/QtLineEditFactory
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qteditorfactory.h"
|
||||||
1
src/QtLocalePropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||
1
src/QtPointFPropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||
1
src/QtPointPropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||
1
src/QtProperty
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertybrowser.h"
|
||||||
1
src/QtRectFPropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||
1
src/QtRectPropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||
1
src/QtScrollBarFactory
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qteditorfactory.h"
|
||||||
1
src/QtSizeFPropertyManager
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "qtpropertymanager.h"
|
||||||