Bumping Qt-Color-Widgets (#2052)

* Bumping Qt-Color-Widgets

* changing Qt Color Widget CMAKE setup
This commit is contained in:
borgmanJeremy
2021-11-20 20:44:58 -06:00
committed by GitHub
parent 2283b3e783
commit 8ab1ac0eaa
135 changed files with 16061 additions and 712 deletions

View File

@@ -111,6 +111,11 @@ else()
add_subdirectory(external/spdlog)
endif()
option(BUILD_STATIC_LIBS ON)
option(BUILD_SHARED_LIBS OFF)
add_subdirectory(external/Qt-Color-Widgets EXCLUDE_FROM_ALL)
if (APPLE)
add_subdirectory(external/QHotkey)
endif()

174
external/Qt-Color-Widgets/CMakeLists.txt vendored Normal file
View File

@@ -0,0 +1,174 @@
#
# Copyright (C) 2013-2020 Mattia Basaglia
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
if ( ${CMAKE_VERSION} VERSION_GREATER "3.12.0")
cmake_policy(SET CMP0077 NEW)
endif()
set(COLORWIDGET_PROJECT_NAME QtColorWidgets)
project(${COLORWIDGET_PROJECT_NAME} CXX)
set (CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules
${CMAKE_CURRENT_LIST_DIR})
include (CheckCXXCompilerFlag)
include (cmake/install.cmake)
include (cmake/versioning.cmake)
SET (${COLORWIDGET_PROJECT_NAME}_VERSION_MAJOR 2)
SET (${COLORWIDGET_PROJECT_NAME}_VERSION_MINOR 2)
SET (${COLORWIDGET_PROJECT_NAME}_VERSION_PATCH 0)
SET (${COLORWIDGET_PROJECT_NAME}_VERSION "${${COLORWIDGET_PROJECT_NAME}_VERSION_MAJOR}.${${COLORWIDGET_PROJECT_NAME}_VERSION_MINOR}.${${COLORWIDGET_PROJECT_NAME}_VERSION_PATCH}")
set(QT_VERSION_MAJOR 5)
find_package(QT NAMES Qt5 Qt6 Qt4 COMPONENTS Core QUIET)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Widgets REQUIRED)
# Auto generate moc files
set(CMAKE_AUTOMOC ON)
# Auto generate moc files
set(CMAKE_AUTOUIC ON)
# Auto generate moc files
set(CMAKE_AUTORCC ON)
option(BUILD_SHARED_LIBS "Build the shared library" ON)
option(BUILD_STATIC_LIBS "Build the static library" OFF)
set (TARGET_NAME ${COLORWIDGET_PROJECT_NAME})
option(COLOR_WIDGETS_QT_SUFFIX "Append qt version to the target output files" OFF)
if ( COLOR_WIDGETS_QT_SUFFIX )
set (TARGET_OUTPUT_SUFFIX "-Qt${QT_VERSION}${${COLORWIDGET_PROJECT_NAME}_VERSION_MAJOR}")
else()
set (TARGET_OUTPUT_SUFFIX "")
endif()
set (INCLUDE_PREFIX "QtColorWidgets")
set (COLOR_WIDGETS_LIBRARY "${TARGET_NAME}")
if ( ${BUILD_STATIC_LIBS} )
add_definitions(-DQTCOLORWIDGETS_STATICALLY_LINKED)
endif()
add_library (${TARGET_NAME} "")
set_target_properties(${TARGET_NAME}
PROPERTIES
EXPORT_NAME "${TARGET_NAME}${TARGET_OUTPUT_SUFFIX}")
set_target_properties (${TARGET_NAME}
PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
VERSION ${${COLORWIDGET_PROJECT_NAME}_VERSION}
SOVERSION ${${COLORWIDGET_PROJECT_NAME}_VERSION_MAJOR}
"INTERFACE_${COLORWIDGET_PROJECT_NAME}_MAJOR_VERSION" ${${COLORWIDGET_PROJECT_NAME}_VERSION_MAJOR}
COMPATIBLE_INTERFACE_STRING "${COLORWIDGET_PROJECT_NAME}_MAJOR_VERSION"
COMPILE_DEFINITIONS QTCOLORWIDGETS_LIBRARY
OUTPUT_NAME "${TARGET_NAME}${TARGET_OUTPUT_SUFFIX}")
check_cxx_compiler_flag ("-Wall" Wall_FLAG_SUPPORTED)
if (Wall_FLAG_SUPPORTED)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
endif (Wall_FLAG_SUPPORTED)
check_cxx_compiler_flag ("-pedantic" pedantic_FLAG_SUPPORTED)
if (pedantic_FLAG_SUPPORTED)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pedantic")
endif (pedantic_FLAG_SUPPORTED)
check_cxx_compiler_flag ("-Wextra" Wextra_FLAG_SUPPORTED)
if (Wextra_FLAG_SUPPORTED)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wextra")
endif (Wextra_FLAG_SUPPORTED)
set (EXPORT_HEADER "${INCLUDE_PREFIX}/colorwidgets_global.hpp")
generate_versioning_information (
TARGET_NAME ${TARGET_NAME}
EXPORT_HEADER ${EXPORT_HEADER}
EXPORT_MACRO QCP_EXPORT
VERSIONED_ENTITY ${COLORWIDGET_PROJECT_NAME}
INCLUDE_PREFIX ${INCLUDE_PREFIX}
COMPANY_NAME "Mattia Basaglia"
COMPANY_COPYRIGHT "Mattia Basaglia Copyright (C) 2013-2020"
FILE_DESCRIPTION "Color wheel widget and dialog for Qt${QT_VERSION}"
)
target_include_directories(${TARGET_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
PUBLIC
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
)
add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR}/include/${INCLUDE_PREFIX})
add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR}/resources/${INCLUDE_PREFIX})
add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR}/src/${INCLUDE_PREFIX})
target_link_libraries (${TARGET_NAME} PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
install_project (
PROJECT_NAME ${COLORWIDGET_PROJECT_NAME}
TARGET_NAME ${TARGET_NAME}
TARGET_OUTPUT_SUFFIX "${TARGET_OUTPUT_SUFFIX}"
EXPORT_HEADER ${EXPORT_HEADER}
INCLUDE_PREFIX ${INCLUDE_PREFIX}
HEADER_MATCHING_REGEX "^.*\.h$|^.*\.hpp$|^.*$"
VERSION_HEADER ${CMAKE_CURRENT_BINARY_DIR}/${COLORWIDGET_PROJECT_NAME}_version.h
NAMESPACE "")
add_subdirectory (gallery)
option(QTCOLORWIDGETS_DESIGNER_PLUGIN "Build QtDesigner plugin" ON)
if (${QTCOLORWIDGETS_DESIGNER_PLUGIN})
find_package (Qt5Designer QUIET)
if (Qt5Designer_FOUND)
add_subdirectory (color_widgets_designer_plugin)
endif(Qt5Designer_FOUND)
endif()
configure_file(Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
add_custom_target(
${COLORWIDGET_PROJECT_NAME}_docs
COMMAND doxygen Doxyfile
COMMAND cp ${CMAKE_CURRENT_SOURCE_DIR}/gallery/*.png ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

2537
external/Qt-Color-Widgets/Doxyfile.in vendored Normal file

File diff suppressed because it is too large Load Diff

1
external/Qt-Color-Widgets/GITSHA vendored Normal file
View File

@@ -0,0 +1 @@
dca164702ef1481ecef9bd80b9d8c07c3a91c008

View File

@@ -0,0 +1,10 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
libdir=@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/include
Name: QtColorWidgets
Description: Color wheel widget and dialog for Qt
Version: @QtColorWidgets_VERSION@
Libs: -L${libdir} -l@i_target_name@@i_target_output_suffix@
Cflags: -I${includedir}/@i_project_name@ -I${includedir}

View File

@@ -17,6 +17,8 @@ The provided widgets are:
* ColorPaletteWidget, A widget to use and manage a list of palettes
* Color2DSlider, An analog widget used to select 2 color components
* ColorLineEdit, A widget to manipulate a string representing a color
* HarmonyColorWheel, A ColorWheel which allows defining multiple colors, separated by hue
* GradientListModel, A QAbstractListModel used to list gradients (useful for combo boxes, list views and the like)
they are all in the color_widgets namespace.
@@ -28,10 +30,16 @@ Using it in a project
For QMake-based projects, include color_widgets.pri in the QMake project file.
For CMake-based projects, add this as subdirectory, it will be compiled as a
library and you can link the required targets to ColorWidgets-qt5.
library and you can link the required targets to ColorWidgets.
All the required files are in ./src and ./include.
Documentation
-------------
See https://mattbas.gitlab.io/Qt-Color-Widgets/
Installing as a Qt Designer/Creator Plugin
------------------------------------------
@@ -41,7 +49,7 @@ Compile the library and install in
(Qt SDK)/Tools/QtCreator/bin/designer/
(Qt SDK)/(Qt Version)/(Toolchain)/plugins/designer
cd build && cmake .. && make ColorWidgetsPlugin && make install
mkdir build && cd build && cmake .. && make QtColorWidgetsPlugin && make install
Latest Version
@@ -49,8 +57,8 @@ Latest Version
The latest version of the sources can be found at the following locations:
* https://github.com/mbasaglia/Qt-Color-Widgets
* git://github.com/mbasaglia/Qt-Color-Widgets.git
* https://gitlab.com/mattbas/Qt-Color-Widgets
* git@gitlab.com:mattbas/Qt-Color-Widgets.git
License
@@ -61,4 +69,4 @@ As a special exception, this library can be included in any project under the
terms of any of the GNU liceses, distributing the whole project under a
different GNU license, see LICENSE-EXCEPTION for details.
Copyright (C) 2013-2017 Mattia Basaglia <mattia.basaglia@gmail.com>
Copyright (C) 2013-2020 Mattia Basaglia <dev@dragon.best>

View File

@@ -0,0 +1 @@
include("${CMAKE_CURRENT_LIST_DIR}/@CMAKE_BASE_FILE_NAME@@CMAKE_FILE_OUTPUT_SUFFIX@-targets.cmake")

View File

@@ -0,0 +1,88 @@
function (install_project
PROJECT_NAME i_project_name
TARGET_NAME i_target_name
TARGET_OUTPUT_SUFFIX i_target_output_suffix
EXPORT_HEADER i_export_header
INCLUDE_PREFIX i_include_prefix
HEADER_MATCHING_REGEX i_header_matching_regex
VERSION_HEADER i_version_header
NAMESPACE i_namespace)
install (TARGETS ${i_target_name}
EXPORT ${i_target_name}
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
install (DIRECTORY include/
DESTINATION include
FILES_MATCHING
REGEX ${i_header_matching_regex}
REGEX "CMakeLists\.txt" EXCLUDE)
install (FILES ${i_version_header}
DESTINATION include/${i_include_prefix}
COMPONENT Devel)
install (FILES include/${i_export_header}
DESTINATION include/${i_include_prefix}
COMPONENT Devel)
install(
EXPORT ${i_target_name}
DESTINATION lib/cmake/${i_target_name}${i_target_output_suffix}
FILE "${i_target_name}${i_target_output_suffix}.cmake"
COMPONENT Devel)
include(CMakePackageConfigHelpers)
string (TOLOWER ${i_target_name} CMAKE_BASE_FILE_NAME)
string (TOLOWER "${i_target_output_suffix}" CMAKE_FILE_OUTPUT_SUFFIX)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/${i_target_name}/${CMAKE_BASE_FILE_NAME}${CMAKE_FILE_OUTPUT_SUFFIX}-config-version.cmake"
VERSION ${${i_project_name}_VERSION}
COMPATIBILITY SameMajorVersion
)
export(EXPORT ${i_target_name}
FILE "${CMAKE_CURRENT_BINARY_DIR}/${i_target_name}/${CMAKE_BASE_FILE_NAME}${CMAKE_FILE_OUTPUT_SUFFIX}-targets.cmake"
)
configure_file("cmake/${i_project_name}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${i_target_name}/${CMAKE_BASE_FILE_NAME}${CMAKE_FILE_OUTPUT_SUFFIX}-config.cmake"
@ONLY
)
set(ConfigPackageLocation "lib/cmake/${i_target_name}${i_target_output_suffix}")
install(EXPORT ${i_target_name}
FILE
"${CMAKE_BASE_FILE_NAME}${CMAKE_FILE_OUTPUT_SUFFIX}-targets.cmake"
NAMESPACE
"${i_namespace}"
DESTINATION
${ConfigPackageLocation}
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/${i_target_name}/${CMAKE_BASE_FILE_NAME}${CMAKE_FILE_OUTPUT_SUFFIX}-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${i_target_name}/${CMAKE_BASE_FILE_NAME}${CMAKE_FILE_OUTPUT_SUFFIX}-config-version.cmake"
DESTINATION
${ConfigPackageLocation}
COMPONENT
Devel
)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/${i_project_name}.pc.in
${CMAKE_CURRENT_BINARY_DIR}/${i_target_name}${i_target_output_suffix}.pc
@ONLY
)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${i_target_name}${i_target_output_suffix}.pc
DESTINATION
lib/pkgconfig
)
endfunction (install_project)

View File

@@ -0,0 +1,80 @@
define_property (TARGET
PROPERTY GIT_DESCRIBE
BRIEF_DOCS "Advanced version info for developers"
FULL_DOCS "String with information that is important for developers during
development process. This information includes git commit hash, durty status
of repo, distance from the last tag.")
define_property (TARGET
PROPERTY GIT_UNTRACKED_FILES
BRIEF_DOCS "Information about presence of untracked files"
FULL_DOCS "Used in helper functions generation to add .with-untracked suffix
to version string. Suffix is only added if there are some untracked not
ignored files in repository.")
set(HERE_DIR ${CMAKE_CURRENT_LIST_DIR})
function (target_version_information
TARGET_NAME i_target_name
EXPORT_HEADER i_export_header
EXPORT_MACRO i_export_macro
VERSIONED_ENTITY i_versioned_entity)
find_file (
headerFileTemplate
"ProjectVersioning/version.h.in"
PATHS ${CMAKE_MODULE_PATH})
if ( NOT ${headerFileTemplate} )
set(headerFileTemplate "${HERE_DIR}/ProjectVersioning/version.h.in")
endif()
find_file (
sourceFileTemplate
"ProjectVersioning/version.c.in"
PATHS ${CMAKE_MODULE_PATH})
if ( NOT ${sourceFileTemplate} )
set(sourceFileTemplate "${HERE_DIR}/ProjectVersioning/version.c.in")
endif()
exec_program (
"git"
${CMAKE_SOURCE_DIR}
ARGS "describe --always --dirty --long --tags"
OUTPUT_VARIABLE gitDescribe)
exec_program (
"git"
${CMAKE_SOURCE_DIR}
ARGS "ls-files --others --exclude-standard"
OUTPUT_VARIABLE gitUntracked)
if (gitUntracked)
set (gitUntracked ".with-untracked")
endif (gitUntracked)
configure_file (
"${headerFileTemplate}"
"${CMAKE_CURRENT_BINARY_DIR}/${i_versioned_entity}_version.h")
configure_file(
"${sourceFileTemplate}"
"${CMAKE_BINARY_DIR}/${i_versioned_entity}_version.c")
target_sources ("${i_target_name}"
PRIVATE
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/${i_versioned_entity}_version.h>
$<INSTALL_INTERFACE:include/${i_include_prefix}/${i_versioned_entity}_version.h>
PRIVATE
"${CMAKE_BINARY_DIR}/${i_versioned_entity}_version.c")
set_target_properties (${i_target_name}
PROPERTIES
GIT_DESCRIBE "${gitDescribe}"
GIT_UNTRACKED_FILES "${gitUntracked}")
unset (headerFileTemplate PARENT_SCOPE)
unset (sourceFileTemplate PARENT_SCOPE)
endfunction (target_version_information)

View File

@@ -0,0 +1,34 @@
#include "${i_versioned_entity}_version.h"
unsigned int @i_versioned_entity@_versionMajor () {
return ${${i_versioned_entity}_VERSION_MAJOR};
}
unsigned int @i_versioned_entity@_versionMinor () {
return ${${i_versioned_entity}_VERSION_MINOR};
}
unsigned int @i_versioned_entity@_versionPatch () {
return ${${i_versioned_entity}_VERSION_PATCH};
}
const char* @i_versioned_entity@_versionGitInfo () {
return
"${gitDescribe}"
"${gitUntracked}";
}
const char* @i_versioned_entity@_versionFullString () {
return
"${${i_versioned_entity}_VERSION_MAJOR}."
"${${i_versioned_entity}_VERSION_MINOR}."
"${${i_versioned_entity}_VERSION_PATCH}"
"${${i_versioned_entity}_VERSION_PRE_RELEASE}"
"+${gitDescribe}"
"${gitUntracked}";
}

View File

@@ -0,0 +1,23 @@
#ifndef @CMAKE_PROJECT_NAME@_VERSION_H
#define @CMAKE_PROJECT_NAME@_VERSION_H
#include "@i_export_header@"
@i_export_macro@ unsigned int @i_versioned_entity@_versionMajor ();
@i_export_macro@ unsigned int @i_versioned_entity@_versionMinor ();
@i_export_macro@ unsigned int @i_versioned_entity@_versionPatch ();
@i_export_macro@ const char* @i_versioned_entity@_versionGitInfo ();
@i_export_macro@ const char* @i_versioned_entity@_versionFullString ();
#endif /* @CMAKE_PROJECT_NAME@_VERSION_H */

View File

@@ -0,0 +1,113 @@
/*
The MIT License (MIT)
Copyright (c) 2015, by [halex2005](mailto:akharlov@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#pragma once
#ifndef PRODUCT_VERSION_MAJOR
#define PRODUCT_VERSION_MAJOR @PRODUCT_VERSION_MAJOR@
#endif
#ifndef PRODUCT_VERSION_MINOR
#define PRODUCT_VERSION_MINOR @PRODUCT_VERSION_MINOR@
#endif
#ifndef PRODUCT_VERSION_PATCH
#define PRODUCT_VERSION_PATCH @PRODUCT_VERSION_PATCH@
#endif
#ifndef PRODUCT_VERSION_BUILD
#define PRODUCT_VERSION_BUILD @PRODUCT_VERSION_REVISION@
#endif
#ifndef FILE_VERSION_MAJOR
#define FILE_VERSION_MAJOR @PRODUCT_VERSION_MAJOR@
#endif
#ifndef FILE_VERSION_MINOR
#define FILE_VERSION_MINOR @PRODUCT_VERSION_MINOR@
#endif
#ifndef FILE_VERSION_PATCH
#define FILE_VERSION_PATCH @PRODUCT_VERSION_PATCH@
#endif
#ifndef FILE_VERSION_BUILD
#define FILE_VERSION_BUILD @PRODUCT_VERSION_REVISION@
#endif
#ifndef __TO_STRING
#define __TO_STRING_IMPL(x) #x
#define __TO_STRING(x) __TO_STRING_IMPL(x)
#endif
#define PRODUCT_VERSION_MAJOR_MINOR_STR __TO_STRING(PRODUCT_VERSION_MAJOR) "." __TO_STRING(PRODUCT_VERSION_MINOR)
#define PRODUCT_VERSION_MAJOR_MINOR_PATCH_STR PRODUCT_VERSION_MAJOR_MINOR_STR "." __TO_STRING(PRODUCT_VERSION_PATCH)
#define PRODUCT_VERSION_FULL_STR PRODUCT_VERSION_MAJOR_MINOR_PATCH_STR "." __TO_STRING(PRODUCT_VERSION_BUILD)
#define PRODUCT_VERSION_RESOURCE PRODUCT_VERSION_MAJOR,PRODUCT_VERSION_MINOR,PRODUCT_VERSION_PATCH,PRODUCT_VERSION_BUILD
#define PRODUCT_VERSION_RESOURCE_STR PRODUCT_VERSION_FULL_STR "\0"
#define FILE_VERSION_MAJOR_MINOR_STR __TO_STRING(FILE_VERSION_MAJOR) "." __TO_STRING(FILE_VERSION_MINOR)
#define FILE_VERSION_MAJOR_MINOR_PATCH_STR FILE_VERSION_MAJOR_MINOR_STR "." __TO_STRING(FILE_VERSION_PATCH)
#define FILE_VERSION_FULL_STR FILE_VERSION_MAJOR_MINOR_PATCH_STR "." __TO_STRING(FILE_VERSION_BUILD)
#define FILE_VERSION_RESOURCE FILE_VERSION_MAJOR,FILE_VERSION_MINOR,FILE_VERSION_PATCH,FILE_VERSION_BUILD
#define FILE_VERSION_RESOURCE_STR FILE_VERSION_FULL_STR "\0"
#ifndef USE_ICON
#define USE_ICON @USE_ICON@
#endif
#if USE_ICON
#ifndef PRODUCT_ICON
#define PRODUCT_ICON "@PRODUCT_ICON@"
#endif
#endif
#ifndef PRODUCT_COMMENTS
#define PRODUCT_COMMENTS "@PRODUCT_COMMENTS@\0"
#endif
#ifndef PRODUCT_COMPANY_NAME
#define PRODUCT_COMPANY_NAME "@PRODUCT_COMPANY_NAME@\0"
#endif
#ifndef PRODUCT_COMPANY_COPYRIGHT
#define PRODUCT_COMPANY_COPYRIGHT "@PRODUCT_COMPANY_COPYRIGHT@\0"
#endif
#ifndef PRODUCT_FILE_DESCRIPTION
#define PRODUCT_FILE_DESCRIPTION "@PRODUCT_FILE_DESCRIPTION@\0"
#endif
#ifndef PRODUCT_INTERNAL_NAME
#define PRODUCT_INTERNAL_NAME "@PRODUCT_NAME@\0"
#endif
#ifndef PRODUCT_ORIGINAL_FILENAME
#define PRODUCT_ORIGINAL_FILENAME "@PRODUCT_ORIGINAL_FILENAME@\0"
#endif
#ifndef PRODUCT_BUNDLE
#define PRODUCT_BUNDLE "@PRODUCT_BUNDLE@\0"
#endif

View File

@@ -0,0 +1,66 @@
/*
The MIT License (MIT)
Copyright (c) 2015, by [halex2005](mailto:akharlov@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "VersionInfo.h"
#include "winresrc.h"
#if USE_ICON
IDI_ICON1 ICON PRODUCT_ICON
#endif
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
VS_VERSION_INFO VERSIONINFO
FILEVERSION FILE_VERSION_RESOURCE
PRODUCTVERSION PRODUCT_VERSION_RESOURCE
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "041904b0"
BEGIN
VALUE "Comments", PRODUCT_COMMENTS
VALUE "CompanyName", PRODUCT_COMPANY_NAME
VALUE "FileDescription", PRODUCT_FILE_DESCRIPTION
VALUE "FileVersion", FILE_VERSION_RESOURCE_STR
VALUE "InternalName", PRODUCT_INTERNAL_NAME
VALUE "LegalCopyright", PRODUCT_COMPANY_COPYRIGHT
VALUE "OriginalFilename", PRODUCT_ORIGINAL_FILENAME
VALUE "ProductName", PRODUCT_BUNDLE
VALUE "ProductVersion", PRODUCT_VERSION_RESOURCE_STR
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x419, 1200
END
END

View File

@@ -0,0 +1,136 @@
# The MIT License (MIT)
# Copyright (c) 2015, by [halex2005](mailto:akharlov@gmail.com)
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
include (CMakeParseArguments)
set (GenerateProductVersionCurrentDir ${CMAKE_CURRENT_LIST_DIR})
# generate_product_version() function
#
# This function uses VersionInfo.in template file and VersionResource.rc file
# to generate WIN32 resource with version information and general resource strings.
#
# Usage:
# generate_product_version(
# SomeOutputResourceVariable
# NAME MyGreatProject
# ICON ${PATH_TO_APP_ICON}
# VERSION_MAJOR 2
# VERSION_MINOR 3
# VERSION_PATH ${BUILD_COUNTER}
# VERSION_REVISION ${BUILD_REVISION}
# )
# where BUILD_COUNTER and BUILD_REVISION could be values from your CI server.
#
# You can use generated resource for your executable targets:
# add_executable(target-name ${target-files} ${SomeOutputResourceVariable})
#
# You can specify resource strings in arguments:
# NAME - name of executable (no defaults, ex: Microsoft Word)
# BUNDLE - bundle (${NAME} is default, ex: Microsoft Office)
# USE_ICON - flag that shows whether icon is used or not
# ICON - path to application icon (${CMAKE_SOURCE_DIR}/product.ico by default)
# VERSION_MAJOR - 1 is default
# VERSION_MINOR - 0 is default
# VERSION_PATCH - 0 is default
# VERSION_REVISION - 0 is default
# COMPANY_NAME - your company name (no defaults)
# COMPANY_COPYRIGHT - ${COMPANY_NAME} (C) Copyright ${CURRENT_YEAR} is default
# COMMENTS - ${NAME} v${VERSION_MAJOR}.${VERSION_MINOR} is default
# ORIGINAL_FILENAME - ${NAME} is default
# INTERNAL_NAME - ${NAME} is default
# FILE_DESCRIPTION - ${NAME} is default
function(generate_product_version outfiles)
set (options)
set (oneValueArgs
NAME
BUNDLE
USE_ICON
ICON
VERSION_MAJOR
VERSION_MINOR
VERSION_PATCH
VERSION_REVISION
COMPANY_NAME
COMPANY_COPYRIGHT
COMMENTS
ORIGINAL_FILENAME
INTERNAL_NAME
FILE_DESCRIPTION)
set (multiValueArgs)
cmake_parse_arguments(PRODUCT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if (NOT PRODUCT_BUNDLE OR "${PRODUCT_BUNDLE}" STREQUAL "")
set(PRODUCT_BUNDLE "${PRODUCT_NAME}")
endif()
if (USE_ICON)
if (NOT PRODUCT_ICON OR "${PRODUCT_ICON}" STREQUAL "")
set(PRODUCT_ICON "${CMAKE_SOURCE_DIR}/product.ico")
endif()
else ()
set (USE_ICON 0)
endif ()
if (NOT PRODUCT_VERSION_MAJOR EQUAL 0 AND (NOT PRODUCT_VERSION_MAJOR OR "${PRODUCT_VERSION_MAJOR}" STREQUAL ""))
set(PRODUCT_VERSION_MAJOR 1)
endif()
if (NOT PRODUCT_VERSION_MINOR EQUAL 0 AND (NOT PRODUCT_VERSION_MINOR OR "${PRODUCT_VERSION_MINOR}" STREQUAL ""))
set(PRODUCT_VERSION_MINOR 0)
endif()
if (NOT PRODUCT_VERSION_PATCH EQUAL 0 AND (NOT PRODUCT_VERSION_PATCH OR "${PRODUCT_VERSION_PATCH}" STREQUAL ""))
set(PRODUCT_VERSION_PATCH 0)
endif()
if (NOT PRODUCT_VERSION_REVISION EQUAL 0 AND (NOT PRODUCT_VERSION_REVISION OR "${PRODUCT_VERSION_REVISION}" STREQUAL ""))
set(PRODUCT_VERSION_REVISION 0)
endif()
if (NOT PRODUCT_COMPANY_COPYRIGHT OR "${PRODUCT_COMPANY_COPYRIGHT}" STREQUAL "")
string(TIMESTAMP PRODUCT_CURRENT_YEAR "%Y")
set(PRODUCT_COMPANY_COPYRIGHT "${PRODUCT_COMPANY_NAME} (C) Copyright ${PRODUCT_CURRENT_YEAR}")
endif()
if (NOT PRODUCT_COMMENTS OR "${PRODUCT_COMMENTS}" STREQUAL "")
set(PRODUCT_COMMENTS "${PRODUCT_NAME} v${PRODUCT_VERSION_MAJOR}.${PRODUCT_VERSION_MINOR}")
endif()
if (NOT PRODUCT_ORIGINAL_FILENAME OR "${PRODUCT_ORIGINAL_FILENAME}" STREQUAL "")
set(PRODUCT_ORIGINAL_FILENAME "${PRODUCT_NAME}")
endif()
if (NOT PRODUCT_INTERNAL_NAME OR "${PRODUCT_INTERNAL_NAME}" STREQUAL "")
set(PRODUCT_INTERNAL_NAME "${PRODUCT_NAME}")
endif()
if (NOT PRODUCT_FILE_DESCRIPTION OR "${PRODUCT_FILE_DESCRIPTION}" STREQUAL "")
set(PRODUCT_FILE_DESCRIPTION "${PRODUCT_NAME}")
endif()
set (_VersionInfoFile ${CMAKE_CURRENT_BINARY_DIR}/VersionInfo.h)
set (_VersionResourceFile ${CMAKE_CURRENT_BINARY_DIR}/VersionResource.rc)
configure_file(
${GenerateProductVersionCurrentDir}/VersionInfo.in
${_VersionInfoFile}
@ONLY)
configure_file(
${GenerateProductVersionCurrentDir}/VersionResource.rc
${_VersionResourceFile}
COPYONLY)
list(APPEND ${outfiles} ${_VersionInfoFile} ${_VersionResourceFile})
set (${outfiles} ${${outfiles}} PARENT_SCOPE)
endfunction()

View File

@@ -0,0 +1,43 @@
include (ProjectVersioning)
function (generate_versioning_information
TARGET_NAME i_target_name
EXPORT_HEADER i_export_header
EXPORT_MACRO i_export_macro
VERSIONED_ENTITY i_versioned_entity
INCLUDE_PREFIX i_include_prefix
COMPANY_NAME i_company_name
COMPANY_COPYRIGHT i_company_copyright
FILE_DESCRIPTION i_file_description
)
target_version_information (
TARGET_NAME ${i_target_name}
EXPORT_HEADER ${i_export_header}
EXPORT_MACRO ${i_export_macro}
VERSIONED_ENTITY ${i_versioned_entity}
)
if (WIN32)
include (generate_product_version)
get_target_property (gitDescribe
${i_target_name} GIT_DESCRIBE)
get_target_property (gitUntracked
${i_target_name} GIT_UNTRACKED_FILES)
generate_product_version (
win32VersionInfoFiles
NAME ${i_versioned_entity}
VERSION_MAJOR ${${i_versioned_entity}_VERSION_MAJOR}
VERSION_MINOR ${${i_versioned_entity}_VERSION_MINOR}
VERSION_PATCH ${${i_versioned_entity}_VERSION_PATCH}
COMPANY_NAME ${i_company_name}
COMPANY_COPYRIGHT ${i_company_copyright}
COMMENTS "${gitDescribe}${gitUntracked}"
FILE_DESCRIPTION ${i_file_description}
)
target_sources (${i_target_name} PRIVATE ${win32VersionInfoFiles})
endif (WIN32)
endfunction (generate_versioning_information)

View File

@@ -1,4 +1,4 @@
# Copyright (C) 2013-2017 Mattia Basaglia
# Copyright (C) 2013-2019 Mattia Basaglia
#
#
# This software is free software: you can redistribute it and/or modify
@@ -19,13 +19,59 @@ CONFIG += c++11
INCLUDEPATH += $$PWD/src $$PWD/include
SOURCES += \
$$PWD/src/color_wheel.cpp \
$$PWD/src/color_utils.cpp
$$PWD/src/QtColorWidgets/abstract_widget_list.cpp \
$$PWD/src/QtColorWidgets/bound_color_selector.cpp \
$$PWD/src/QtColorWidgets/color_2d_slider.cpp \
$$PWD/src/QtColorWidgets/color_delegate.cpp \
$$PWD/src/QtColorWidgets/color_dialog.cpp \
$$PWD/src/QtColorWidgets/color_line_edit.cpp \
$$PWD/src/QtColorWidgets/color_list_widget.cpp \
$$PWD/src/QtColorWidgets/color_names.cpp \
$$PWD/src/QtColorWidgets/color_palette.cpp \
$$PWD/src/QtColorWidgets/color_palette_model.cpp \
$$PWD/src/QtColorWidgets/color_palette_widget.cpp \
$$PWD/src/QtColorWidgets/color_preview.cpp \
$$PWD/src/QtColorWidgets/color_selector.cpp \
$$PWD/src/QtColorWidgets/color_utils.cpp \
$$PWD/src/QtColorWidgets/color_wheel.cpp \
$$PWD/src/QtColorWidgets/gradient_editor.cpp \
$$PWD/src/QtColorWidgets/gradient_list_model.cpp \
$$PWD/src/QtColorWidgets/gradient_slider.cpp \
$$PWD/src/QtColorWidgets/harmony_color_wheel.cpp \
$$PWD/src/QtColorWidgets/hue_slider.cpp \
$$PWD/src/QtColorWidgets/swatch.cpp
HEADERS += \
$$PWD/include/color_wheel.hpp \
$$PWD/src/color_utils.hpp
$$PWD/include/QtColorWidgets/abstract_widget_list.hpp \
$$PWD/include/QtColorWidgets/bound_color_selector.hpp \
$$PWD/include/QtColorWidgets/color_2d_slider.hpp \
$$PWD/include/QtColorWidgets/color_delegate.hpp \
$$PWD/include/QtColorWidgets/color_dialog.hpp \
$$PWD/include/QtColorWidgets/color_line_edit.hpp \
$$PWD/include/QtColorWidgets/color_list_widget.hpp \
$$PWD/include/QtColorWidgets/color_names.hpp \
$$PWD/include/QtColorWidgets/color_palette.hpp \
$$PWD/include/QtColorWidgets/color_palette_model.hpp \
$$PWD/include/QtColorWidgets/color_palette_widget.hpp \
$$PWD/include/QtColorWidgets/color_preview.hpp \
$$PWD/include/QtColorWidgets/color_selector.hpp \
$$PWD/include/QtColorWidgets/color_utils.hpp \
$$PWD/include/QtColorWidgets/color_wheel.hpp \
$$PWD/include/QtColorWidgets/color_wheel_private.hpp \
$$PWD/include/QtColorWidgets/colorwidgets_global.hpp \
$$PWD/include/QtColorWidgets/gradient_delegate.hpp \
$$PWD/include/QtColorWidgets/gradient_editor.hpp \
$$PWD/include/QtColorWidgets/gradient_helper.hpp \
$$PWD/include/QtColorWidgets/gradient_list_model.hpp \
$$PWD/include/QtColorWidgets/gradient_slider.hpp \
$$PWD/include/QtColorWidgets/harmony_color_wheel.hpp \
$$PWD/include/QtColorWidgets/hue_slider.hpp \
$$PWD/include/QtColorWidgets/swatch.hpp
FORMS += \
$$PWD/src/QtColorWidgets/color_dialog.ui \
$$PWD/src/QtColorWidgets/color_palette_widget.ui
RESOURCES += \
$$PWD/src/color_widgets.qrc
$$PWD/resources/QtColorWidgets/color_widgets.qrc

View File

@@ -1,5 +1,5 @@
#
# Copyright (C) 2013-2017 Mattia Basaglia
# Copyright (C) 2013-2020 Mattia Basaglia
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
@@ -15,13 +15,15 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
TEMPLATE=lib
CONFIG += dll
#CONFIG += dll
QT += core gui widgets
DEFINES += QTCOLORWIDGETS_LIBRARY
TARGET=ColorWidgets-qt5
INCLUDEPATH += $$PWD/include
VERSION=1.0.0
TARGET=QtColorWidgets
VERSION=2.2.0
OBJECTS_DIR = out/obj
MOC_DIR = out/generated
@@ -41,7 +43,12 @@ unix {
win32 {
LIB_TARGET = $${TARGET}.dll
}
android {
OBJECTS_DIR = $$ANDROID_TARGET_ARCH/out/obj
MOC_DIR = $$ANDROID_TARGET_ARCH/out/generated
UI_DIR = $$ANDROID_TARGET_ARCH/out/generated
RCC_DIR = $$ANDROID_TARGET_ARCH/out/generated
}
isEmpty(PREFIX) {
PREFIX = /usr/local
}

View File

@@ -0,0 +1,161 @@
# Copyright (C) 2013-2020 Mattia Basaglia
#
#
# This software is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Color Widgets. If not, see <http://www.gnu.org/licenses/>.
cmake_minimum_required (VERSION 3.1 FATAL_ERROR)
project(QtColorWidgetsPlugin CXX)
set (CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${CMAKE_SOURCE_DIR}/cmake/modules
${CMAKE_CURRENT_LIST_DIR}/..)
include (CheckCXXCompilerFlag)
include (../cmake/versioning.cmake)
SET (${PROJECT_NAME}_VERSION_MAJOR 2)
SET (${PROJECT_NAME}_VERSION_MINOR 2)
SET (${PROJECT_NAME}_VERSION_PATCH 0)
SET (${PROJECT_NAME}_VERSION "${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}.${${PROJECT_NAME}_VERSION_PATCH}")
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Designer REQUIRED)
# Auto generate moc files
set(CMAKE_AUTOMOC ON)
# Auto generate moc files
set(CMAKE_AUTOUIC ON)
# Auto generate moc files
set(CMAKE_AUTORCC ON)
check_cxx_compiler_flag ("-Wall" Wall_FLAG_SUPPORTED)
if (Wall_FLAG_SUPPORTED)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
endif (Wall_FLAG_SUPPORTED)
check_cxx_compiler_flag ("-pedantic" pedantic_FLAG_SUPPORTED)
if (pedantic_FLAG_SUPPORTED)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pedantic")
endif (pedantic_FLAG_SUPPORTED)
check_cxx_compiler_flag ("-Wextra" Wextra_FLAG_SUPPORTED)
if (Wextra_FLAG_SUPPORTED)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wextra")
endif (Wextra_FLAG_SUPPORTED)
# Library
set (TARGET_NAME ${PROJECT_NAME})
set (TARGET_OUTPUT_SUFFIX "-Qt${QT_VERSION}${${PROJECT_NAME}_VERSION_MAJOR}")
add_library (${TARGET_NAME} SHARED "")
set_target_properties(${TARGET_NAME}
PROPERTIES
EXPORT_NAME "${TARGET_NAME}${TARGET_OUTPUT_SUFFIX}")
set_target_properties (${TARGET_NAME}
PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
VERSION ${${PROJECT_NAME}_VERSION}
SOVERSION ${${PROJECT_NAME}_VERSION_MAJOR}
"INTERFACE_${PROJECT_NAME}_MAJOR_VERSION" ${${PROJECT_NAME}_VERSION_MAJOR}
COMPATIBLE_INTERFACE_STRING "${PROJECT_NAME}_MAJOR_VERSION"
OUTPUT_NAME "${TARGET_NAME}${TARGET_OUTPUT_SUFFIX}")
target_link_libraries(${TARGET_NAME}
PRIVATE
${COLOR_WIDGETS_LIBRARY}
Qt${QT_VERSION_MAJOR}::Designer
)
# Sources
set(SOURCES
color_preview_plugin.cpp
color_wheel_plugin.cpp
color_widget_plugin_collection.cpp
gradient_slider_plugin.cpp
hue_slider_plugin.cpp
color_selector_plugin.cpp
color_list_plugin.cpp
swatch_plugin.cpp
color_palette_widget_plugin.cpp
color_2d_slider_plugin.cpp
color_line_edit_plugin.cpp
gradient_editor_plugin.cpp
# add new sources above this line
)
foreach (SOURCE IN LISTS SOURCES)
target_sources (${TARGET_NAME}
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${SOURCE}>)
endforeach (SOURCE IN SOURCES)
set(HEADERS
color_preview_plugin.hpp
color_wheel_plugin.hpp
color_widget_plugin_collection.hpp
gradient_slider_plugin.hpp
hue_slider_plugin.hpp
color_selector_plugin.hpp
color_list_plugin.hpp
swatch_plugin.hpp
color_palette_widget_plugin.hpp
color_2d_slider_plugin.hpp
color_line_edit_plugin.hpp
gradient_editor_plugin.hpp
# add new headers above this line
)
foreach (HEADER IN LISTS HEADERS)
target_sources (${TARGET_NAME}
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${HEADER}>)
endforeach (HEADER IN HEADERS)
# install
get_target_property (QT_QMAKE_EXECUTABLE
Qt${QT_VERSION_MAJOR}::qmake LOCATION)
execute_process (
COMMAND ${QT_QMAKE_EXECUTABLE} -query QT_INSTALL_PLUGINS
OUTPUT_VARIABLE QT_INSTALL_PLUGINS
OUTPUT_STRIP_TRAILING_WHITESPACE)
# install(TARGETS ${COLOR_WIDGETS_PLUGIN} DESTINATION ${QT_INSTALL_PLUGINS}/designer OPTIONAL)
execute_process (
COMMAND ${QT_QMAKE_EXECUTABLE} -query QT_INSTALL_LIBS
OUTPUT_VARIABLE QT_INSTALL_LIBS
OUTPUT_STRIP_TRAILING_WHITESPACE)
# install(TARGETS ${COLOR_WIDGETS_PLUGIN} DESTINATION ${QT_INSTALL_LIBS}/qtcreator/plugins OPTIONAL)
add_custom_target(${TARGET_NAME}_install
COMMAND cp $<TARGET_FILE:${TARGET_NAME}> ${QT_INSTALL_PLUGINS}/designer
COMMAND cp $<TARGET_FILE:${TARGET_NAME}> ${QT_INSTALL_LIBS}/qtcreator/plugins
DEPENDS ${TARGET_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

View File

@@ -0,0 +1,90 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "color_2d_slider_plugin.hpp"
#include "QtColorWidgets/color_2d_slider.hpp"
Color2DSlider_Plugin::Color2DSlider_Plugin(QObject *parent) :
QObject(parent), initialized(false)
{
}
void Color2DSlider_Plugin::initialize(QDesignerFormEditorInterface *)
{
initialized = true;
}
bool Color2DSlider_Plugin::isInitialized() const
{
return initialized;
}
QWidget *Color2DSlider_Plugin::createWidget(QWidget *parent)
{
return new color_widgets::Color2DSlider(parent);
}
QString Color2DSlider_Plugin::name() const
{
return "color_widgets::Color2DSlider";
}
QString Color2DSlider_Plugin::group() const
{
return "Color Widgets";
}
QIcon Color2DSlider_Plugin::icon() const
{
color_widgets::Color2DSlider w;
w.resize(64,64);
QPixmap pix(64,64);
w.render(&pix);
return QIcon(pix);
}
QString Color2DSlider_Plugin::toolTip() const
{
return "An analog widget to select 2 color components at the same time";
}
QString Color2DSlider_Plugin::whatsThis() const
{
return toolTip();
}
bool Color2DSlider_Plugin::isContainer() const
{
return false;
}
QString Color2DSlider_Plugin::domXml() const
{
return "<ui language=\"c++\">\n"
" <widget class=\"color_widgets::Color2DSlider\" name=\"color2DSlider\">\n"
" </widget>\n"
"</ui>\n";
}
QString Color2DSlider_Plugin::includeFile() const
{
return "QtColorWidgets/color_2d_slider.hpp";
}

View File

@@ -0,0 +1,57 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_WIDGETS_COLOR_2D_SLIDER_PLUGIN_HPP
#define COLOR_WIDGETS_COLOR_2D_SLIDER_PLUGIN_HPP
#include <QObject>
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
class Color2DSlider_Plugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
Color2DSlider_Plugin(QObject *parent = 0);
void initialize(QDesignerFormEditorInterface *core);
bool isInitialized() const;
QWidget *createWidget(QWidget *parent);
QString name() const;
QString group() const;
QIcon icon() const;
QString toolTip() const;
QString whatsThis() const;
bool isContainer() const;
QString domXml() const;
QString includeFile() const;
private:
bool initialized;
};
#endif // COLOR_WIDGETS_COLOR_2D_SLIDER_PLUGIN_HPP

View File

@@ -0,0 +1,87 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "color_line_edit_plugin.hpp"
#include "QtColorWidgets/color_line_edit.hpp"
QWidget* ColorLineEdit_Plugin::createWidget(QWidget *parent)
{
color_widgets::ColorLineEdit *widget = new color_widgets::ColorLineEdit(parent);
return widget;
}
QIcon ColorLineEdit_Plugin::icon() const
{
return QIcon::fromTheme("edit-rename");
}
QString ColorLineEdit_Plugin::domXml() const
{
return "<ui language=\"c++\">\n"
" <widget class=\"color_widgets::ColorLineEdit\" name=\"color_line_edit\">\n"
" </widget>\n"
"</ui>\n";
}
bool ColorLineEdit_Plugin::isContainer() const
{
return false;
}
ColorLineEdit_Plugin::ColorLineEdit_Plugin(QObject *parent) :
QObject(parent), initialized(false)
{
}
void ColorLineEdit_Plugin::initialize(QDesignerFormEditorInterface *)
{
initialized = true;
}
bool ColorLineEdit_Plugin::isInitialized() const
{
return initialized;
}
QString ColorLineEdit_Plugin::name() const
{
return "color_widgets::ColorLineEdit";
}
QString ColorLineEdit_Plugin::group() const
{
return "Color Widgets";
}
QString ColorLineEdit_Plugin::toolTip() const
{
return "A widget to manipulate a string representing a color";
}
QString ColorLineEdit_Plugin::whatsThis() const
{
return toolTip();
}
QString ColorLineEdit_Plugin::includeFile() const
{
return "QtColorWidgets/color_line_edit.hpp";
}

View File

@@ -0,0 +1,58 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_WIDGETS_COLOR_LINE_EDIT_PLUGIN_HPP
#define COLOR_WIDGETS_COLOR_LINE_EDIT_PLUGIN_HPP
#include <QObject>
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
class ColorLineEdit_Plugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
explicit ColorLineEdit_Plugin(QObject *parent = nullptr);
void initialize(QDesignerFormEditorInterface *core) Q_DECL_OVERRIDE;
bool isInitialized() const Q_DECL_OVERRIDE;
QWidget *createWidget(QWidget *parent) Q_DECL_OVERRIDE;
QString name() const Q_DECL_OVERRIDE;
QString group() const Q_DECL_OVERRIDE;
QIcon icon() const Q_DECL_OVERRIDE;
QString toolTip() const Q_DECL_OVERRIDE;
QString whatsThis() const Q_DECL_OVERRIDE;
bool isContainer() const Q_DECL_OVERRIDE;
QString domXml() const Q_DECL_OVERRIDE;
QString includeFile() const Q_DECL_OVERRIDE;
private:
bool initialized;
};
#endif // COLOR_WIDGETS_COLOR_LINE_EDIT_PLUGIN_HPP

View File

@@ -0,0 +1,88 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "color_list_plugin.hpp"
#include "QtColorWidgets/color_list_widget.hpp"
ColorListWidget_Plugin::ColorListWidget_Plugin(QObject *parent) :
QObject(parent)
{
}
void ColorListWidget_Plugin::initialize(QDesignerFormEditorInterface *)
{
initialized = true;
}
bool ColorListWidget_Plugin::isInitialized() const
{
return initialized;
}
QWidget *ColorListWidget_Plugin::createWidget(QWidget *parent)
{
return new color_widgets::ColorListWidget(parent);
}
QString ColorListWidget_Plugin::name() const
{
return "color_widgets::ColorListWidget";
}
QString ColorListWidget_Plugin::group() const
{
return "Color Widgets";
}
QIcon ColorListWidget_Plugin::icon() const
{
return QIcon::fromTheme("format-stroke-color");
}
QString ColorListWidget_Plugin::toolTip() const
{
return "An editable list of colors";
}
QString ColorListWidget_Plugin::whatsThis() const
{
return toolTip();
}
bool ColorListWidget_Plugin::isContainer() const
{
return false;
}
QString ColorListWidget_Plugin::domXml() const
{
return "<ui language=\"c++\">\n"
" <widget class=\"color_widgets::ColorListWidget\" name=\"ColorListWidget\">\n"
" </widget>\n"
"</ui>\n";
}
QString ColorListWidget_Plugin::includeFile() const
{
return "QtColorWidgets/color_list_widget.hpp";
}

View File

@@ -0,0 +1,56 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_LIST_PLUGIN_HPP
#define COLOR_LIST_PLUGIN_HPP
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
class ColorListWidget_Plugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
explicit ColorListWidget_Plugin(QObject *parent = 0);
void initialize(QDesignerFormEditorInterface *core);
bool isInitialized() const;
QWidget *createWidget(QWidget *parent);
QString name() const;
QString group() const;
QIcon icon() const;
QString toolTip() const;
QString whatsThis() const;
bool isContainer() const;
QString domXml() const;
QString includeFile() const;
private:
bool initialized;
};
#endif // COLOR_LIST_PLUGIN_HPP

View File

@@ -0,0 +1,120 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "color_palette_widget_plugin.hpp"
#include "QtColorWidgets/color_palette_widget.hpp"
ColorPaletteWidget_Plugin::ColorPaletteWidget_Plugin(QObject *parent) :
QObject(parent), initialized(false)
{
}
void ColorPaletteWidget_Plugin::initialize(QDesignerFormEditorInterface *)
{
initialized = true;
}
bool ColorPaletteWidget_Plugin::isInitialized() const
{
return initialized;
}
QWidget* ColorPaletteWidget_Plugin::createWidget(QWidget *parent)
{
color_widgets::ColorPaletteWidget *wid = new color_widgets::ColorPaletteWidget(parent);
color_widgets::ColorPalette palette1;
color_widgets::ColorPalette palette2;
int columns = 12;
palette1.setName("Palette 1");
palette2.setName("Palette 2");
palette1.setColumns(columns);
palette2.setColumns(columns);
for ( int i = 0; i < 6; i++ )
{
for ( int j = 0; j < columns; j++ )
{
float f = float(j)/columns;
palette1.appendColor(QColor::fromHsvF(i/8.0,1-f,0.5+f/2));
palette2.appendColor(QColor::fromHsvF(i/8.0,1-f,1-f));
}
}
color_widgets::ColorPaletteModel *model = new color_widgets::ColorPaletteModel;
model->setParent(wid);
model->addPalette(palette1, false);
model->addPalette(palette2, false);
wid->setModel(model);
return wid;
}
QString ColorPaletteWidget_Plugin::name() const
{
return "color_widgets::ColorPaletteWidget";
}
QString ColorPaletteWidget_Plugin::group() const
{
return "Color Widgets";
}
QIcon ColorPaletteWidget_Plugin::icon() const
{
color_widgets::ColorPalette w;
w.setColumns(6);
for ( int i = 0; i < 4; i++ )
{
for ( int j = 0; j < w.columns(); j++ )
{
float f = float(j)/w.columns();
w.appendColor(QColor::fromHsvF(i/5.0,1-f,0.5+f/2));
}
}
return QIcon(w.preview(QSize(64,64)));
}
QString ColorPaletteWidget_Plugin::toolTip() const
{
return "A widget that displays a color palette";
}
QString ColorPaletteWidget_Plugin::whatsThis() const
{
return toolTip();
}
bool ColorPaletteWidget_Plugin::isContainer() const
{
return false;
}
QString ColorPaletteWidget_Plugin::domXml() const
{
return "<ui language=\"c++\">\n"
" <widget class=\"color_widgets::ColorPaletteWidget\" name=\"palette_widget\">\n"
" </widget>\n"
"</ui>\n";
}
QString ColorPaletteWidget_Plugin::includeFile() const
{
return "QtColorWidgets/color_palette_widget.hpp";
}

View File

@@ -0,0 +1,57 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_WIDGETS_COLOR_PALETTE_WIDGET_PLUGIN_HPP
#define COLOR_WIDGETS_COLOR_PALETTE_WIDGET_PLUGIN_HPP
#include <QObject>
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
class ColorPaletteWidget_Plugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
ColorPaletteWidget_Plugin(QObject *parent = 0);
void initialize(QDesignerFormEditorInterface *core);
bool isInitialized() const;
QWidget *createWidget(QWidget *parent);
QString name() const;
QString group() const;
QIcon icon() const;
QString toolTip() const;
QString whatsThis() const;
bool isContainer() const;
QString domXml() const;
QString includeFile() const;
private:
bool initialized;
};
#endif // COLOR_WIDGETS_COLOR_PALETTE_WIDGET_PLUGIN_HPP

View File

@@ -0,0 +1,95 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "color_preview_plugin.hpp"
#include "QtColorWidgets/color_preview.hpp"
#include <QtPlugin>
ColorPreview_Plugin::ColorPreview_Plugin(QObject *parent)
: QObject(parent), initialized(false)
{
}
void ColorPreview_Plugin::initialize(QDesignerFormEditorInterface *)
{
if (initialized)
return;
initialized = true;
}
bool ColorPreview_Plugin::isInitialized() const
{
return initialized;
}
QWidget *ColorPreview_Plugin::createWidget(QWidget *parent)
{
return new color_widgets::ColorPreview(parent);
}
QString ColorPreview_Plugin::name() const
{
return "color_widgets::ColorPreview";
}
QString ColorPreview_Plugin::group() const
{
return "Color Widgets";
}
QIcon ColorPreview_Plugin::icon() const
{
return QIcon();
}
QString ColorPreview_Plugin::toolTip() const
{
return "Display a color";
}
QString ColorPreview_Plugin::whatsThis() const
{
return toolTip();
}
bool ColorPreview_Plugin::isContainer() const
{
return false;
}
QString ColorPreview_Plugin::domXml() const
{
return "<ui language=\"c++\">\n"
" <widget class=\"color_widgets::ColorPreview\" name=\"colorPreview\">\n"
" </widget>\n"
"</ui>\n";
}
QString ColorPreview_Plugin::includeFile() const
{
return "QtColorWidgets/color_preview.hpp";
}
//Q_EXPORT_PLUGIN2(color_widgets, ColorPreview_Plugin);

View File

@@ -0,0 +1,55 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_PREVIEW_PLUGIN_HPP
#define COLOR_PREVIEW_PLUGIN_HPP
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
class ColorPreview_Plugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
ColorPreview_Plugin(QObject *parent = 0);
void initialize(QDesignerFormEditorInterface *core);
bool isInitialized() const;
QWidget *createWidget(QWidget *parent);
QString name() const;
QString group() const;
QIcon icon() const;
QString toolTip() const;
QString whatsThis() const;
bool isContainer() const;
QString domXml() const;
QString includeFile() const;
private:
bool initialized;
};
#endif // COLOR_PREVIEW_PLUGIN_HPP

View File

@@ -0,0 +1,92 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "color_selector_plugin.hpp"
#include "QtColorWidgets/color_selector.hpp"
#include <QtPlugin>
ColorSelector_Plugin::ColorSelector_Plugin(QObject *parent)
: QObject(parent), initialized(false)
{
}
void ColorSelector_Plugin::initialize(QDesignerFormEditorInterface *)
{
if (initialized)
return;
initialized = true;
}
bool ColorSelector_Plugin::isInitialized() const
{
return initialized;
}
QWidget *ColorSelector_Plugin::createWidget(QWidget *parent)
{
return new color_widgets::ColorSelector(parent);
}
QString ColorSelector_Plugin::name() const
{
return "color_widgets::ColorSelector";
}
QString ColorSelector_Plugin::group() const
{
return "Color Widgets";
}
QIcon ColorSelector_Plugin::icon() const
{
return QIcon();
}
QString ColorSelector_Plugin::toolTip() const
{
return "Display a color and opens a color dialog on click";
}
QString ColorSelector_Plugin::whatsThis() const
{
return toolTip();
}
bool ColorSelector_Plugin::isContainer() const
{
return false;
}
QString ColorSelector_Plugin::domXml() const
{
return "<ui language=\"c++\">\n"
" <widget class=\"color_widgets::ColorSelector\" name=\"ColorSelector\">\n"
" </widget>\n"
"</ui>\n";
}
QString ColorSelector_Plugin::includeFile() const
{
return "QtColorWidgets/color_selector.hpp";
}

View File

@@ -0,0 +1,55 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_SELECTOR_PLUGIN_HPP
#define COLOR_SELECTOR_PLUGIN_HPP
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
class ColorSelector_Plugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
ColorSelector_Plugin(QObject *parent = 0);
void initialize(QDesignerFormEditorInterface *core);
bool isInitialized() const;
QWidget *createWidget(QWidget *parent);
QString name() const;
QString group() const;
QIcon icon() const;
QString toolTip() const;
QString whatsThis() const;
bool isContainer() const;
QString domXml() const;
QString includeFile() const;
private:
bool initialized;
};
#endif // COLOR_SELECTOR_PLUGIN_HPP

View File

@@ -0,0 +1,97 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "color_wheel_plugin.hpp"
#include "QtColorWidgets/color_wheel.hpp"
ColorWheel_Plugin::ColorWheel_Plugin(QObject *parent) :
QObject(parent), initialized(false)
{
}
void ColorWheel_Plugin::initialize(QDesignerFormEditorInterface *)
{
initialized = true;
}
bool ColorWheel_Plugin::isInitialized() const
{
return initialized;
}
QWidget *ColorWheel_Plugin::createWidget(QWidget *parent)
{
return new color_widgets::ColorWheel(parent);
}
QString ColorWheel_Plugin::name() const
{
return "color_widgets::ColorWheel";
}
QString ColorWheel_Plugin::group() const
{
return "Color Widgets";
}
QIcon ColorWheel_Plugin::icon() const
{
color_widgets::ColorWheel w;
w.resize(64,64);
w.setWheelWidth(8);
QPixmap pix(64,64);
w.render(&pix);
return QIcon(pix);
}
QString ColorWheel_Plugin::toolTip() const
{
return "A widget that allows an intuitive selection of HSL parameters for a QColor";
}
QString ColorWheel_Plugin::whatsThis() const
{
return toolTip();
}
bool ColorWheel_Plugin::isContainer() const
{
return false;
}
QString ColorWheel_Plugin::domXml() const
{
return "<ui language=\"c++\">\n"
" <widget class=\"color_widgets::ColorWheel\" name=\"colorWheel\">\n"
" <property name=\"sizePolicy\">\n"
" <sizepolicy hsizetype=\"Minimum\" vsizetype=\"Minimum\">\n"
" <horstretch>0</horstretch>\n"
" <verstretch>0</verstretch>\n"
" </sizepolicy>\n"
" </property>\n"
" </widget>\n"
"</ui>\n";
}
QString ColorWheel_Plugin::includeFile() const
{
return "QtColorWidgets/color_wheel.hpp";
}

View File

@@ -0,0 +1,57 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_WHEEL_PLUGIN_HPP
#define COLOR_WHEEL_PLUGIN_HPP
#include <QObject>
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
class ColorWheel_Plugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
ColorWheel_Plugin(QObject *parent = 0);
void initialize(QDesignerFormEditorInterface *core);
bool isInitialized() const;
QWidget *createWidget(QWidget *parent);
QString name() const;
QString group() const;
QIcon icon() const;
QString toolTip() const;
QString whatsThis() const;
bool isContainer() const;
QString domXml() const;
QString includeFile() const;
private:
bool initialized;
};
#endif // COLOR_WHEEL_PLUGIN_HPP

View File

@@ -0,0 +1,56 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "color_widget_plugin_collection.hpp"
#include "color_preview_plugin.hpp"
#include "color_wheel_plugin.hpp"
#include "gradient_slider_plugin.hpp"
#include "hue_slider_plugin.hpp"
#include "color_selector_plugin.hpp"
#include "color_list_plugin.hpp"
#include "swatch_plugin.hpp"
#include "color_palette_widget_plugin.hpp"
#include "color_2d_slider_plugin.hpp"
#include "color_line_edit_plugin.hpp"
#include "gradient_editor_plugin.hpp"
// add new plugin headers above this line
ColorWidgets_PluginCollection::ColorWidgets_PluginCollection(QObject *parent) :
QObject(parent)
{
widgets.push_back(new ColorPreview_Plugin(this));
widgets.push_back(new ColorWheel_Plugin(this));
widgets.push_back(new GradientSlider_Plugin(this));
widgets.push_back(new HueSlider_Plugin(this));
widgets.push_back(new ColorSelector_Plugin(this));
widgets.push_back(new ColorListWidget_Plugin(this));
widgets.push_back(new Swatch_Plugin(this));
widgets.push_back(new ColorPaletteWidget_Plugin(this));
widgets.push_back(new Color2DSlider_Plugin(this));
widgets.push_back(new ColorLineEdit_Plugin(this));
widgets.push_back(new GradientEditor_Plugin(this));
// add new plugins above this line
}
QList<QDesignerCustomWidgetInterface *> ColorWidgets_PluginCollection::customWidgets() const
{
return widgets;
}

View File

@@ -0,0 +1,43 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_WIDGET_PLUGIN_COLLECTION_HPP
#define COLOR_WIDGET_PLUGIN_COLLECTION_HPP
#include <QtUiPlugin/QDesignerCustomWidgetCollectionInterface>
class ColorWidgets_PluginCollection : public QObject, public QDesignerCustomWidgetCollectionInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "mattia.basaglia.ColorWidgetsPlugin")
Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
public:
explicit ColorWidgets_PluginCollection(QObject *parent = 0);
QList<QDesignerCustomWidgetInterface*> customWidgets() const;
private:
QList<QDesignerCustomWidgetInterface*> widgets;
};
#endif // COLOR_WIDGET_PLUGIN_COLLECTION_HPP

View File

@@ -0,0 +1,98 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "gradient_editor_plugin.hpp"
#include "QtColorWidgets/gradient_editor.hpp"
QWidget* GradientEditor_Plugin::createWidget(QWidget *parent)
{
color_widgets::GradientEditor *widget = new color_widgets::GradientEditor(parent);
return widget;
}
QIcon GradientEditor_Plugin::icon() const
{
color_widgets::GradientEditor w;
w.resize(64,16);
QGradientStops cols;
cols.push_back({0.2, Qt::green});
cols.push_back({0.5, Qt::yellow});
cols.push_back({0.8, Qt::red});
w.setStops(cols);
QPixmap pix(64,64);
pix.fill(Qt::transparent);
w.render(&pix, QPoint(0,16));
return QIcon(pix);
}
QString GradientEditor_Plugin::domXml() const
{
return "<ui language=\"c++\">\n"
" <widget class=\"color_widgets::GradientEditor\" name=\"gradient_editor\">\n"
" </widget>\n"
"</ui>\n";
}
bool GradientEditor_Plugin::isContainer() const
{
return false;
}
GradientEditor_Plugin::GradientEditor_Plugin(QObject *parent) :
QObject(parent), initialized(false)
{
}
void GradientEditor_Plugin::initialize(QDesignerFormEditorInterface *)
{
initialized = true;
}
bool GradientEditor_Plugin::isInitialized() const
{
return initialized;
}
QString GradientEditor_Plugin::name() const
{
return "color_widgets::GradientEditor";
}
QString GradientEditor_Plugin::group() const
{
return "Color Widgets";
}
QString GradientEditor_Plugin::toolTip() const
{
return "Widget to edit gradient stops";
}
QString GradientEditor_Plugin::whatsThis() const
{
return toolTip();
}
QString GradientEditor_Plugin::includeFile() const
{
return "QtColorWidgets/gradient_editor.hpp";
}

View File

@@ -0,0 +1,58 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_WIDGETS_GRADIENT_EDITOR_PLUGIN_HPP
#define COLOR_WIDGETS_GRADIENT_EDITOR_PLUGIN_HPP
#include <QObject>
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
class GradientEditor_Plugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
explicit GradientEditor_Plugin(QObject *parent = nullptr);
void initialize(QDesignerFormEditorInterface *core) Q_DECL_OVERRIDE;
bool isInitialized() const Q_DECL_OVERRIDE;
QWidget *createWidget(QWidget *parent) Q_DECL_OVERRIDE;
QString name() const Q_DECL_OVERRIDE;
QString group() const Q_DECL_OVERRIDE;
QIcon icon() const Q_DECL_OVERRIDE;
QString toolTip() const Q_DECL_OVERRIDE;
QString whatsThis() const Q_DECL_OVERRIDE;
bool isContainer() const Q_DECL_OVERRIDE;
QString domXml() const Q_DECL_OVERRIDE;
QString includeFile() const Q_DECL_OVERRIDE;
private:
bool initialized;
};
#endif // COLOR_WIDGETS_GRADIENT_EDITOR_PLUGIN_HPP

View File

@@ -0,0 +1,102 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "gradient_slider_plugin.hpp"
#include "QtColorWidgets/gradient_slider.hpp"
#include <QtPlugin>
GradientSlider_Plugin::GradientSlider_Plugin(QObject *parent)
: QObject(parent), initialized(false)
{
}
void GradientSlider_Plugin::initialize(QDesignerFormEditorInterface *)
{
if (initialized)
return;
initialized = true;
}
bool GradientSlider_Plugin::isInitialized() const
{
return initialized;
}
QWidget *GradientSlider_Plugin::createWidget(QWidget *parent)
{
return new color_widgets::GradientSlider(parent);
}
QString GradientSlider_Plugin::name() const
{
return "color_widgets::GradientSlider";
}
QString GradientSlider_Plugin::group() const
{
return "Color Widgets";
}
QIcon GradientSlider_Plugin::icon() const
{
color_widgets::GradientSlider w;
w.resize(64,16);
QVector<QColor> cols;
cols.push_back(Qt::green);
cols.push_back(Qt::yellow);
cols.push_back(Qt::red);
w.setColors(cols);
QPixmap pix(64,64);
pix.fill(Qt::transparent);
w.render(&pix,QPoint(0,16));
return QIcon(pix);
}
QString GradientSlider_Plugin::toolTip() const
{
return "Slider over a gradient";
}
QString GradientSlider_Plugin::whatsThis() const
{
return toolTip();
}
bool GradientSlider_Plugin::isContainer() const
{
return false;
}
QString GradientSlider_Plugin::domXml() const
{
return "<ui language=\"c++\">\n"
" <widget class=\"color_widgets::GradientSlider\" name=\"GradientSlider\">\n"
" </widget>\n"
"</ui>\n";
}
QString GradientSlider_Plugin::includeFile() const
{
return "QtColorWidgets/gradient_slider.hpp";
}

View File

@@ -0,0 +1,34 @@
#ifndef GRADIENT_SLIDER_PLUGIN_HPP
#define GRADIENT_SLIDER_PLUGIN_HPP
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
class GradientSlider_Plugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
GradientSlider_Plugin(QObject *parent = 0);
void initialize(QDesignerFormEditorInterface *core);
bool isInitialized() const;
QWidget *createWidget(QWidget *parent);
QString name() const;
QString group() const;
QIcon icon() const;
QString toolTip() const;
QString whatsThis() const;
bool isContainer() const;
QString domXml() const;
QString includeFile() const;
private:
bool initialized;
};
#endif // GRADIENT_SLIDER_PLUGIN_HPP

View File

@@ -0,0 +1,98 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
* \copyright Copyright (C) 2014 Calle Laakkonen
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "hue_slider_plugin.hpp"
#include "QtColorWidgets/hue_slider.hpp"
#include <QtPlugin>
HueSlider_Plugin::HueSlider_Plugin(QObject *parent)
: QObject(parent), initialized(false)
{
}
void HueSlider_Plugin::initialize(QDesignerFormEditorInterface *)
{
if (initialized)
return;
initialized = true;
}
bool HueSlider_Plugin::isInitialized() const
{
return initialized;
}
QWidget *HueSlider_Plugin::createWidget(QWidget *parent)
{
return new color_widgets::HueSlider(parent);
}
QString HueSlider_Plugin::name() const
{
return "color_widgets::HueSlider";
}
QString HueSlider_Plugin::group() const
{
return "Color Widgets";
}
QIcon HueSlider_Plugin::icon() const
{
color_widgets::HueSlider w;
w.resize(64,16);
QPixmap pix(64,64);
pix.fill(Qt::transparent);
w.render(&pix,QPoint(0,16));
return QIcon(pix);
}
QString HueSlider_Plugin::toolTip() const
{
return "Slider over a hue gradient";
}
QString HueSlider_Plugin::whatsThis() const
{
return toolTip();
}
bool HueSlider_Plugin::isContainer() const
{
return false;
}
QString HueSlider_Plugin::domXml() const
{
return "<ui language=\"c++\">\n"
" <widget class=\"color_widgets::HueSlider\" name=\"HueSlider\">\n"
" </widget>\n"
"</ui>\n";
}
QString HueSlider_Plugin::includeFile() const
{
return "QtColorWidgets/hue_slider.hpp";
}

View File

@@ -0,0 +1,34 @@
#ifndef HUE_SLIDER_PLUGIN_HPP
#define HUE_SLIDER_PLUGIN_HPP
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
class HueSlider_Plugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
HueSlider_Plugin(QObject *parent = 0);
void initialize(QDesignerFormEditorInterface *core);
bool isInitialized() const;
QWidget *createWidget(QWidget *parent);
QString name() const;
QString group() const;
QIcon icon() const;
QString toolTip() const;
QString whatsThis() const;
bool isContainer() const;
QString domXml() const;
QString includeFile() const;
private:
bool initialized;
};
#endif // HUE_SLIDER_PLUGIN_HPP

View File

@@ -0,0 +1,236 @@
#!/bin/bash
#
# Copyright (C) 2013-2020 Mattia Basaglia
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
SELFDIR=$(dirname $(readlink -se "${BASH_SOURCE[0]}"))
function class_to_underscore()
{
echo "$1" | sed -r -e 's/([a-z])([A-Z])/\1_\L\2/g' -e 's/[A-Z]/\L\0/g'
}
function class_to_header()
{
echo "$(class_to_underscore "$1").hpp"
}
function header_to_source()
{
echo "$1" | sed -r -e 's/\.h(pp)?$/.cpp/i'
}
function read_arg()
{
varname=$1
prompt="$2"
default="$3"
[ "$default" ] && prompt="${prompt} [$default]"
read -p "$prompt: " -i "$default" $varname
[ -z "${!varname}" ] && eval "$varname=\"$default\""
}
function header_to_guard()
{
echo "$1" | tr [:lower:] [:upper:] | tr /. _
}
read_arg class "Class name"
[ -z "$class" ] && exit 1
read_arg description "Description"
read_arg header "Header" "$(class_to_header "$class")"
read_arg plugin "Plugin Class" "${class}_Plugin"
read_arg plugin_header "Plugin Header" "$(class_to_header "$plugin")"
read_arg plugin_source "Plugin Source" "$(header_to_source "$plugin_header")"
read_arg plugin_path "Plugin Path" "$SELFDIR"
read_arg plugin_author "Author" "$(git config user.name)"
read_arg plugin_copyright "Copyright" "2013-$(date +%Y) $plugin_author"
echo "Summary:"
echo " Class: $class"
echo " Description: $description"
echo " Header: $header"
echo " Plugin Class: $plugin"
echo " Plugin Header: $plugin_header"
echo " Plugin Source: $plugin_source"
echo " Plugin Path: $plugin_path"
echo " Author: $plugin_author"
echo " Copyright: $plugin_copyright"
object_name="$(class_to_underscore $class)"
cat >"$plugin_path/$plugin_source" <<PLUGIN
/**
* \file
*
* \author $plugin_author
*
* \copyright Copyright (C) $plugin_copyright
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "$plugin_header"
#include "QtColorWidgets/$header"
QWidget* $plugin::createWidget(QWidget *parent)
{
color_widgets::$class *widget = new color_widgets::$class(parent);
return widget;
}
QIcon $plugin::icon() const
{
return QIcon();
}
QString $plugin::domXml() const
{
return "<ui language=\"c++\">\n"
" <widget class=\"color_widgets::$class\" name=\"$object_name\">\n"
" </widget>\n"
"</ui>\n";
}
bool $plugin::isContainer() const
{
return false;
}
$plugin::$plugin(QObject *parent) :
QObject(parent), initialized(false)
{
}
void $plugin::initialize(QDesignerFormEditorInterface *)
{
initialized = true;
}
bool $plugin::isInitialized() const
{
return initialized;
}
QString $plugin::name() const
{
return "color_widgets::$class";
}
QString $plugin::group() const
{
return "Color Widgets";
}
QString $plugin::toolTip() const
{
return "$description";
}
QString $plugin::whatsThis() const
{
return toolTip();
}
QString $plugin::includeFile() const
{
return "QtColorWidgets/$header";
}
PLUGIN
header_guard="COLOR_WIDGETS_$(header_to_guard "$plugin_header")"
cat >"$plugin_path/$plugin_header" <<PLUGIN
/**
* \file
*
* \author $plugin_author
*
* \copyright Copyright (C) $plugin_copyright
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef $header_guard
#define $header_guard
#include <QObject>
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
class $plugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
explicit $plugin(QObject *parent = nullptr);
void initialize(QDesignerFormEditorInterface *core) Q_DECL_OVERRIDE;
bool isInitialized() const Q_DECL_OVERRIDE;
QWidget *createWidget(QWidget *parent) Q_DECL_OVERRIDE;
QString name() const Q_DECL_OVERRIDE;
QString group() const Q_DECL_OVERRIDE;
QIcon icon() const Q_DECL_OVERRIDE;
QString toolTip() const Q_DECL_OVERRIDE;
QString whatsThis() const Q_DECL_OVERRIDE;
bool isContainer() const Q_DECL_OVERRIDE;
QString domXml() const Q_DECL_OVERRIDE;
QString includeFile() const Q_DECL_OVERRIDE;
private:
bool initialized;
};
#endif // $header_guard
PLUGIN
sed -i -r \
-e "\\~# add new sources above this line~i\\$plugin_source" \
-e "\\~# add new headers above this line~i\\$plugin_header" \
"$plugin_path/CMakeLists.txt"
sed -i -r \
-e "\\~// add new plugin headers above this line~i#include \"$plugin_header\"" \
-e "\\~// add new plugins above this line~i\ widgets.push_back(new $plugin(this));" \
"$plugin_path/color_widget_plugin_collection.cpp"

View File

@@ -0,0 +1,106 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "swatch_plugin.hpp"
#include "QtColorWidgets/swatch.hpp"
Swatch_Plugin::Swatch_Plugin(QObject *parent) :
QObject(parent), initialized(false)
{
}
void Swatch_Plugin::initialize(QDesignerFormEditorInterface *)
{
initialized = true;
}
bool Swatch_Plugin::isInitialized() const
{
return initialized;
}
QWidget* Swatch_Plugin::createWidget(QWidget *parent)
{
color_widgets::Swatch *wid = new color_widgets::Swatch(parent);
wid->palette().setColumns(12);
for ( int i = 0; i < 6; i++ )
{
for ( int j = 0; j < wid->palette().columns(); j++ )
{
float f = float(j)/wid->palette().columns();
wid->palette().appendColor(QColor::fromHsvF(i/8.0,1-f,0.5+f/2));
}
}
return wid;
}
QString Swatch_Plugin::name() const
{
return "color_widgets::Swatch";
}
QString Swatch_Plugin::group() const
{
return "Color Widgets";
}
QIcon Swatch_Plugin::icon() const
{
color_widgets::ColorPalette w;
w.setColumns(6);
for ( int i = 0; i < 4; i++ )
{
for ( int j = 0; j < w.columns(); j++ )
{
float f = float(j)/w.columns();
w.appendColor(QColor::fromHsvF(i/5.0,1-f,0.5+f/2));
}
}
return QIcon(w.preview(QSize(64,64)));
}
QString Swatch_Plugin::toolTip() const
{
return "A widget that displays a color palette";
}
QString Swatch_Plugin::whatsThis() const
{
return toolTip();
}
bool Swatch_Plugin::isContainer() const
{
return false;
}
QString Swatch_Plugin::domXml() const
{
return "<ui language=\"c++\">\n"
" <widget class=\"color_widgets::Swatch\" name=\"swatch\">\n"
" </widget>\n"
"</ui>\n";
}
QString Swatch_Plugin::includeFile() const
{
return "QtColorWidgets/swatch.hpp";
}

View File

@@ -0,0 +1,57 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_WIDGETS_SWATCH_PLUGIN_HPP
#define COLOR_WIDGETS_SWATCH_PLUGIN_HPP
#include <QObject>
#include <QtUiPlugin/QDesignerCustomWidgetInterface>
class Swatch_Plugin : public QObject, public QDesignerCustomWidgetInterface
{
Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
Swatch_Plugin(QObject *parent = 0);
void initialize(QDesignerFormEditorInterface *core);
bool isInitialized() const;
QWidget *createWidget(QWidget *parent);
QString name() const;
QString group() const;
QIcon icon() const;
QString toolTip() const;
QString whatsThis() const;
bool isContainer() const;
QString domXml() const;
QString includeFile() const;
private:
bool initialized;
};
#endif // COLOR_WIDGETS_SWATCH_PLUGIN_HPP

View File

@@ -0,0 +1,35 @@
#
# Copyright (C) 2013-2020 Mattia Basaglia
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
set (QT_SUPPORTED_VERSIONS 5)
set(SCREENSHOT_SOURCES screenshot.cpp)
set(SCREENSHOT_BINARY screenshot_bin)
add_executable(${SCREENSHOT_BINARY} EXCLUDE_FROM_ALL ${SCREENSHOT_SOURCES})
target_link_libraries(
${SCREENSHOT_BINARY}
PRIVATE
${COLOR_WIDGETS_LIBRARY}
Qt${QT_VERSION_MAJOR}::Widgets
)
add_custom_target(gallery
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SCREENSHOT_BINARY}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${SCREENSHOT_BINARY}
)

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 243 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 249 B

View File

@@ -0,0 +1,91 @@
Color Widgets Gallery
=====================
Color2DSlider
-------------
![Color2DSlider](Color2DSlider.png)
This widget allow the user to select 2 HSV color components at the same time,
by default that is Saturation and Value but they can be changed.
ColorDialog
-----------
![ColorDialog](ColorDialog.png)
This is a dialog analogous to <tt>QColorDialog</tt> but with a much nicer and friendlier
user interface. It uses several of the other widgets.
ColorLineEdit
-------------
![ColorLineEdit](ColorLineEdit.png)
![ColorLineEdit with color preview](ColorLineEdit_with_color.png)
This is a <tt>QLineEdit</tt> intended to be used to edit and display color names.
It accepts several string formats:
* <tt>#f00</tt> (3 hexadecimal rgb digits)
* <tt>#ff0000</tt> (6 hexadecimal rgb digits)
* <tt>rgb(255,0,0)</tt> (function-like)
* <tt>red</tt> (color name)
It can optionally display the color it represents on its background.
ColorListWidget
---------------
![ColorListWidget](ColorListWidget.png)
It allows to display and edit a list of colors.
ColorPaletteWidget and Swatch
-----------------------------
These widgets handle color palettes.
![Swatch](Swatch.png)
**Swatch** only handles a single palette, can be used to just select colors from the
palette or to modify the palette via drag and drop operations.
**ColorPaletteModel** is a list model that represents palettes with can be used
with the Qt item view widgets, it provides a name and a preview icon for
each of the stored palettes.
It also has functionality to load and save palettes from the filesystem.
![Read-only ColorPaletteWidget](ColorPaletteWidget_readonly.png)
![ColorPaletteWidget](ColorPaletteWidget.png)
**ColorPaletteWidget** manages a list of palettes (via **ColorPaletteModel**).
Has two modes: read-only only allows to select palettes and colors,
otherwise it can be used to modify the list of palettes and the palette itself.
ColorPreview and ColorSelector
------------------------------
![ColorPreview](ColorPreview.png)
**ColorPreview** is a widget that displays a color or compares two colors.
**ColorSelector** is like **ColorPreview** but when clicked it shows a ColorDialog.
GradientSlider and HueSlider
----------------------------
![HueSlider](HueSlider.png)
**GradientSlider** is a <tt>QSlider</tt> which uses a gradient as its background.
**HueSlider** is specifically made to select a hue and has more information
about the represented color.
GradientEditor
--------------
![GradientEditor](GradientEditor.png)
**GradientEditor** is similar in appearance to **GradientSlider** but it's for editing the gradient.
GradientListModel and GradientDelegate
--------------------------------------
![GradientListModel](GradientListModel_combo.png)
![GradientListModel](GradientListModel_view.png)
**GradientListModel** is a <tt>QAbstractListModel</tt> used to list gradients (useful for combo boxes, item views and the like).
**GradientDelegate** is an item delegate to edit gradients in an item view.

Binary file not shown.

After

Width:  |  Height:  |  Size: 951 B

View File

@@ -0,0 +1,222 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <cstring>
#include <algorithm>
#include <QApplication>
#include <QCommandLineParser>
#include <QComboBox>
#include <QListView>
#include <QTableWidget>
#include "QtColorWidgets/color_2d_slider.hpp"
#include "QtColorWidgets/color_delegate.hpp" /// \todo show it
#include "QtColorWidgets/color_dialog.hpp"
#include "QtColorWidgets/color_line_edit.hpp"
#include "QtColorWidgets/color_list_widget.hpp"
#include "QtColorWidgets/color_palette_widget.hpp"
#include "QtColorWidgets/color_preview.hpp"
#include "QtColorWidgets/color_wheel.hpp"
#include "QtColorWidgets/harmony_color_wheel.hpp"
#include "QtColorWidgets/hue_slider.hpp"
#include "QtColorWidgets/gradient_editor.hpp"
#include "QtColorWidgets/gradient_list_model.hpp"
#include "QtColorWidgets/gradient_delegate.hpp"
bool run = false;
QStringList just_these;
void screenshot(QWidget& widget, QString name = QString())
{
if ( name.isEmpty() )
{
name = widget.metaObject()->className();
name.remove("color_widgets::");
}
if ( !just_these.isEmpty() && !just_these.contains(name) )
return;
widget.setWindowTitle(name);
QPixmap pic(widget.size());
widget.render(&pic);
name += ".png";
pic.save(name);
if ( run )
widget.show();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QCommandLineParser parser;
parser.addHelpOption();
parser.addPositionalArgument("just_these", "Only these widgets");
QCommandLineOption run_option("run", "Show widgets instead of saving to file");
parser.addOption(run_option);
parser.process(a);
run = parser.isSet(run_option);
just_these = parser.positionalArguments();
QColor demo_color(64,172,143,128);
color_widgets::ColorPalette palette1;
color_widgets::ColorPalette palette2;
color_widgets::ColorPalette palette3;
int palette_columns = 12;
palette1.setName("Palette 1");
palette2.setName("Palette 2");
palette3.setName("Palette 3");
palette1.setColumns(palette_columns);
palette2.setColumns(palette_columns);
for ( int i = 0; i < 6; i++ )
{
for ( int j = 0; j < palette_columns; j++ )
{
float f = float(j)/palette_columns;
palette1.appendColor(QColor::fromHsvF(i/8.0,1-f,0.5+f/2));
palette2.appendColor(QColor::fromHsvF(i/8.0,1-f,1-f));
}
palette3.appendColor(QColor::fromHsvF(i/8.0, 0.8, 1));
}
color_widgets::ColorPaletteModel palette_model;
palette_model.addPalette(palette1, false);
palette_model.addPalette(palette2, false);
palette_model.addPalette(palette3, false);
color_widgets::ColorPreview preview;
preview.setColor(demo_color);
preview.setDisplayMode(color_widgets::ColorPreview::SplitAlpha);
preview.resize(128,32);
screenshot(preview);
color_widgets::ColorDialog dialog;
dialog.setColorSpace(color_widgets::ColorWheel::ColorLCH);
dialog.setColor(demo_color);
screenshot(dialog);
color_widgets::Color2DSlider slider2d;
slider2d.setColor(demo_color);
slider2d.resize(128,192);
screenshot(slider2d);
color_widgets::ColorLineEdit line_edit;
line_edit.setColor(demo_color);
line_edit.resize(line_edit.sizeHint());
screenshot(line_edit);
line_edit.setPreviewColor(true);
screenshot(line_edit, "ColorLineEdit_with_color");
color_widgets::ColorWheel wheel;
wheel.resize(256, 256);
wheel.setColor(demo_color);
screenshot(wheel);
color_widgets::HarmonyColorWheel harwheel;
harwheel.resize(256, 256);
harwheel.setColor(demo_color);
harwheel.addHarmony(.333, true);
harwheel.addHarmony(.667, true);
screenshot(harwheel);
color_widgets::Swatch swatch;
swatch.setPalette(palette1);
swatch.resize(swatch.sizeHint());
screenshot(swatch);
color_widgets::ColorPaletteWidget palette_widget;
palette_widget.setModel(&palette_model);
screenshot(palette_widget);
color_widgets::ColorPaletteWidget palette_widget1;
palette_widget1.setModel(&palette_model);
palette_widget1.setReadOnly(true);
screenshot(palette_widget1, "ColorPaletteWidget_readonly");
color_widgets::HueSlider hue_slider;
hue_slider.setColor(demo_color);
hue_slider.resize(192, hue_slider.sizeHint().height());
// hue_slider.setInvertedAppearance(true);
// hue_slider.setOrientation(Qt::Vertical);
screenshot(hue_slider);
color_widgets::ColorListWidget list_widget;
list_widget.setColors({
demo_color,
palette1.colorAt(palette_columns*0),
palette1.colorAt(palette_columns*1),
palette1.colorAt(palette_columns*3),
palette1.colorAt(palette_columns*5),
});
list_widget.resize(list_widget.sizeHint());
screenshot(list_widget);
color_widgets::GradientEditor editor;
QGradientStops gradient_colors;
float n_colors = 4;
for ( int i = 0; i <= n_colors; ++i )
gradient_colors.append(QGradientStop(i/n_colors, QColor::fromHsvF(i/n_colors, 0.5, 1)));
editor.setStops(gradient_colors);
screenshot(editor);
QComboBox gradient_list;
color_widgets::GradientListModel gradient_model;
gradient_model.setGradient("Rainbow", gradient_colors);
gradient_model.setGradient("Black to Transparent", QGradientStops{{0, Qt::black}, {1, QColor(0, 0, 0, 0)}});
gradient_list.setModel(&gradient_model);
gradient_model.setIconSize(QSize(128, 24));
gradient_list.setIconSize(gradient_model.iconSize());
QObject::connect(&editor, &color_widgets::GradientEditor::stopsChanged, &gradient_model,
[&gradient_model](const QGradientStops& stops){ gradient_model.setGradient("Rainbow", stops); });
gradient_list.resize(gradient_list.sizeHint());
screenshot(gradient_list, "GradientListModel_combo");
QListView gradient_view;
color_widgets::GradientDelegate gradient_delegate;
gradient_view.setItemDelegate(&gradient_delegate);
gradient_view.setModel(&gradient_model);
// gradient_model.setEditMode(color_widgets::GradientListModel::EditName);
gradient_model.setEditMode(color_widgets::GradientListModel::EditGradient);
gradient_view.resize(QSize(gradient_view.sizeHintForColumn(0) + 4, gradient_view.sizeHint().height()));
screenshot(gradient_view, "GradientListModel_view");
QTableWidget gradient_table;
gradient_table.setItemDelegate(&gradient_delegate);
gradient_table.setRowCount(2);
gradient_table.setColumnCount(2);
gradient_table.setItem(0, 0, new QTableWidgetItem());
gradient_table.item(0, 0)->setData(Qt::EditRole, QVariant::fromValue(gradient_model.gradientBrush(0)));
gradient_table.setItem(0, 1, new QTableWidgetItem(gradient_model.nameFromIndex(0)));
gradient_table.setItem(1, 0, new QTableWidgetItem());
gradient_table.item(1, 0)->setData(Qt::EditRole, QVariant::fromValue(gradient_model.gradientBrush(1)));
gradient_table.setItem(1, 1, new QTableWidgetItem(gradient_model.nameFromIndex(1)));
screenshot(gradient_table, "GradientDelegate_table");
if ( run )
return a.exec();
return 0;
}

View File

@@ -0,0 +1 @@
#include "abstract_widget_list.hpp"

View File

@@ -0,0 +1 @@
#include "bound_color_selector.hpp"

View File

@@ -0,0 +1,37 @@
set (HEADERS
abstract_widget_list.hpp
bound_color_selector.hpp
color_2d_slider.hpp
color_delegate.hpp
color_dialog.hpp
color_line_edit.hpp
color_list_widget.hpp
color_names.hpp
color_palette.hpp
color_palette_model.hpp
color_palette_widget.hpp
color_preview.hpp
color_selector.hpp
color_wheel.hpp
colorwidgets_global.hpp
gradient_slider.hpp
hue_slider.hpp
swatch.hpp
gradient_editor.hpp
harmony_color_wheel.hpp
gradient_list_model.hpp
gradient_delegate.hpp
)
file(RELATIVE_PATH
PREFIX
${PROJECT_SOURCE_DIR}
${CMAKE_CURRENT_LIST_DIR})
foreach (HEADER IN LISTS HEADERS)
target_sources (${TARGET_NAME}
PRIVATE
$<INSTALL_INTERFACE:${PREFIX}/${HEADER}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/${HEADER}>)
endforeach (HEADER IN HEADERS)

View File

@@ -0,0 +1 @@
#include "color_delegate.hpp"

View File

@@ -0,0 +1 @@
#include "color_dialog.hpp"

View File

@@ -0,0 +1 @@
#include "color_list_widget.hpp"

View File

@@ -0,0 +1 @@
#include "color_preview.hpp"

View File

@@ -0,0 +1 @@
#include "color_selector.hpp"

View File

@@ -0,0 +1 @@
#include "gradient_editor.hpp"

View File

@@ -0,0 +1 @@
#include "gradient_list_model.hpp"

View File

@@ -0,0 +1 @@
#include "gradient_slider.hpp"

View File

@@ -0,0 +1 @@
#include "harmony_color_wheel.hpp"

View File

@@ -0,0 +1 @@
#include "hue_slider.hpp"

View File

@@ -0,0 +1,110 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef ABSTRACT_WIDGET_LIST_HPP
#define ABSTRACT_WIDGET_LIST_HPP
#include "colorwidgets_global.hpp"
#include <QSignalMapper>
#include <QTableWidget>
class QCP_EXPORT AbstractWidgetList : public QWidget
{
Q_OBJECT
public:
explicit AbstractWidgetList(QWidget *parent = 0);
~AbstractWidgetList();
/**
* \brief Get the number of items
*/
int count() const;
/**
* \brief Swap row a and row b
*/
virtual void swap(int a, int b) = 0;
/// Whether the given row index is valid
bool isValidRow(int i) const { return i >= 0 && i < count(); }
void setRowHeight(int row, int height);
public Q_SLOTS:
/**
* \brief Remove row i
*/
void remove(int i);
/**
* \brief append a default row
*/
virtual void append() = 0;
Q_SIGNALS:
void removed(int i);
protected:
/**
* \brief Create a new row with the given widget
*
* Must be caled by implementations of append()
*/
void appendWidget(QWidget* w);
/**
* \brief get the widget found at the given row
*/
QWidget* widget(int i);
/**
* \brief get the widget found at the given row
*/
template<class T>
T* widget_cast(int i) { return qobject_cast<T*>(widget(i)); }
/**
* \brief clear all rows without emitting signals
*
* May be useful when implementation want to set all values at once
*/
void clear();
private Q_SLOTS:
void remove_clicked(QWidget* w);
void up_clicked(QWidget* w);
void down_clicked(QWidget* w);
private:
class Private;
Private * const p;
QWidget* create_button(QWidget* data, QSignalMapper*mapper,
QString icon_name, QString text,
QString tooltip = QString()) const;
};
#endif // ABSTRACT_WIDGET_LIST_HPP

View File

@@ -0,0 +1,44 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef BOUND_COLOR_SELECTOR_HPP
#define BOUND_COLOR_SELECTOR_HPP
#include "color_selector.hpp"
namespace color_widgets {
/**
* \brief A color selector bound to a color reference
* \todo Maybe this can be removed
*/
class QCP_EXPORT BoundColorSelector : public ColorSelector
{
Q_OBJECT
private:
QColor* ref;
public:
explicit BoundColorSelector(QColor* reference, QWidget *parent = 0);
private Q_SLOTS:
void update_reference(QColor);
};
} // namespace color_widgets
#endif // BOUND_COLOR_SELECTOR_HPP

View File

@@ -0,0 +1,128 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_WIDGETS_COLOR_2D_SLIDER_HPP
#define COLOR_WIDGETS_COLOR_2D_SLIDER_HPP
#include "colorwidgets_global.hpp"
#include <QWidget>
namespace color_widgets {
/**
* \brief A 2D slider that edits 2 color components
*/
class QCP_EXPORT Color2DSlider : public QWidget
{
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged DESIGNABLE true STORED false )
Q_PROPERTY(qreal hue READ hue WRITE setHue DESIGNABLE false )
Q_PROPERTY(qreal saturation READ saturation WRITE setSaturation DESIGNABLE false )
Q_PROPERTY(qreal value READ value WRITE setValue DESIGNABLE false )
/**
* \brief Which color component is used on the x axis
*/
Q_PROPERTY(Component componentX READ componentX WRITE setComponentX NOTIFY componentXChanged)
/**
* \brief Which color component is used on the y axis
*/
Q_PROPERTY(Component componentY READ componentY WRITE setComponentY NOTIFY componentYChanged)
public:
enum Component {
Hue, Saturation, Value
};
Q_ENUMS(Component)
explicit Color2DSlider(QWidget *parent = nullptr);
~Color2DSlider();
/// Get current color
QColor color() const;
QSize sizeHint() const Q_DECL_OVERRIDE;
/// Get current hue in the range [0-1]
qreal hue() const;
/// Get current saturation in the range [0-1]
qreal saturation() const;
/// Get current value in the range [0-1]
qreal value() const;
Component componentX() const;
Component componentY() const;
public Q_SLOTS:
/// Set current color
void setColor(const QColor& c);
/**
* @param h Hue [0-1]
*/
void setHue(qreal h);
/**
* @param s Saturation [0-1]
*/
void setSaturation(qreal s);
/**
* @param v Value [0-1]
*/
void setValue(qreal v);
void setComponentX(Component componentX);
void setComponentY(Component componentY);
Q_SIGNALS:
/**
* Emitted when the user selects a color or setColor is called
*/
void colorChanged(QColor);
/**
* Emitted when the user selects a color
*/
void colorSelected(QColor);
void componentXChanged(Component componentX);
void componentYChanged(Component componentY);
protected:
void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE;
void mousePressEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent* event) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent* event) Q_DECL_OVERRIDE;
private:
class Private;
Private * const p;
};
} // namespace color_widgets
#endif // COLOR_WIDGETS_COLOR_2D_SLIDER_HPP

View File

@@ -0,0 +1,83 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_DELEGATE_HPP
#define COLOR_DELEGATE_HPP
#include "colorwidgets_global.hpp"
#include <QStyledItemDelegate>
namespace color_widgets {
class QCP_EXPORT ReadOnlyColorDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
using QStyledItemDelegate::QStyledItemDelegate;
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const Q_DECL_OVERRIDE;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE;
void setSizeHintForColor(const QSize& size_hint);
const QSize& sizeHintForColor() const;
protected:
void paintItem(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index, const QBrush& brush) const;
private:
QSize size_hint{24, 16};
};
/**
Delegate to use a ColorSelector in a color list
*/
class QCP_EXPORT ColorDelegate : public ReadOnlyColorDelegate
{
Q_OBJECT
public:
using ReadOnlyColorDelegate::ReadOnlyColorDelegate;
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const Q_DECL_OVERRIDE;
void setEditorData(QWidget *editor, const QModelIndex &index) const Q_DECL_OVERRIDE;
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const Q_DECL_OVERRIDE;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
const QModelIndex &index) const Q_DECL_OVERRIDE;
protected:
bool eventFilter(QObject * watched, QEvent * event) Q_DECL_OVERRIDE;
private slots:
void close_editor();
void color_changed();
};
} // namespace color_widgets
#endif // COLOR_DELEGATE_HPP

View File

@@ -0,0 +1,165 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_DIALOG_HPP
#define COLOR_DIALOG_HPP
#include "colorwidgets_global.hpp"
#include "color_preview.hpp"
#include "color_wheel.hpp"
#include <QDialog>
class QAbstractButton;
namespace color_widgets {
class QCP_EXPORT ColorDialog : public QDialog
{
Q_OBJECT
Q_ENUMS(ButtonMode)
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged DESIGNABLE true)
Q_PROPERTY(ColorWheel::ShapeEnum wheelShape READ wheelShape WRITE setWheelShape NOTIFY wheelShapeChanged)
Q_PROPERTY(ColorWheel::ColorSpaceEnum colorSpace READ colorSpace WRITE setColorSpace NOTIFY colorSpaceChanged)
Q_PROPERTY(bool wheelRotating READ wheelRotating WRITE setWheelRotating NOTIFY wheelRotatingChanged)
/**
* \brief whether the color alpha channel can be edited.
*
* If alpha is disabled, the selected color's alpha will always be 255.
*/
Q_PROPERTY(bool alphaEnabled READ alphaEnabled WRITE setAlphaEnabled NOTIFY alphaEnabledChanged)
public:
enum ButtonMode {
OkCancel,
OkApplyCancel,
Close
};
explicit ColorDialog(QWidget *parent = 0, Qt::WindowFlags f = {});
~ColorDialog();
/**
* Get currently selected color
*/
QColor color() const;
/**
* Set the display mode for the color preview
*/
void setPreviewDisplayMode(ColorPreview::DisplayMode mode);
/**
* Get the color preview diplay mode
*/
ColorPreview::DisplayMode previewDisplayMode() const;
bool alphaEnabled() const;
/**
* Select which dialog buttons to show
*
* There are three predefined modes:
* OkCancel - this is useful when the dialog is modal and we just want to return a color
* OkCancelApply - this is for non-modal dialogs
* Close - for non-modal dialogs with direct color updates via colorChanged signal
*/
void setButtonMode(ButtonMode mode);
ButtonMode buttonMode() const;
QSize sizeHint() const Q_DECL_OVERRIDE;
ColorWheel::ShapeEnum wheelShape() const;
ColorWheel::ColorSpaceEnum colorSpace() const;
bool wheelRotating() const;
int exec() Q_DECL_OVERRIDE;
public Q_SLOTS:
/**
* Change color
*/
void setColor(const QColor &c);
/**
* Set the current color and show the dialog
*/
void showColor(const QColor &oldcolor);
void setWheelShape(ColorWheel::ShapeEnum shape);
void setColorSpace(ColorWheel::ColorSpaceEnum space);
void setWheelRotating(bool rotating);
/**
* Set whether the color alpha channel can be edited.
* If alpha is disabled, the selected color's alpha will always be 255.
*/
void setAlphaEnabled(bool a);
Q_SIGNALS:
/**
* The current color was changed
*/
void colorChanged(QColor);
/**
* The user selected the new color by pressing Ok/Apply
*/
void colorSelected(QColor);
void wheelShapeChanged(ColorWheel::ShapeEnum shape);
void colorSpaceChanged(ColorWheel::ColorSpaceEnum space);
void wheelRotatingChanged(bool rotating);
void alphaEnabledChanged(bool alphaEnabled);
private Q_SLOTS:
/// Update all the Ui elements to match the selected color
void setColorInternal(const QColor &color);
/// Update from HSV sliders
void set_hsv();
/// Update from RGB sliders
void set_rgb();
/// Update from Alpha slider
void set_alpha();
void on_edit_hex_colorChanged(const QColor& color);
void on_edit_hex_colorEditingFinished(const QColor& color);
void on_buttonBox_clicked(QAbstractButton*);
protected:
void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
void dropEvent(QDropEvent * event) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void keyReleaseEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
private:
class Private;
Private * const p;
};
} // namespace color_widgets
#endif // COLOR_DIALOG_HPP

View File

@@ -0,0 +1,98 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_WIDGETS_COLOR_LINE_EDIT_HPP
#define COLOR_WIDGETS_COLOR_LINE_EDIT_HPP
#include "colorwidgets_global.hpp"
#include <QLineEdit>
#include <QColor>
namespace color_widgets {
/**
* \brief A line edit used to define a color name
*
* Supported string formats:
* * Short hex strings #f00
* * Long hex strings #ff0000
* * Color names red
* * Function-like rgb(255,0,0)
*
* Additional string formats supported when showAlpha is true:
* * Long hex strings #ff0000ff
* * Function like rgba(255,0,0,255)
*/
class QCP_EXPORT ColorLineEdit : public QLineEdit
{
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
/**
* \brief Whether the widget displays and edits the alpha channel
*/
Q_PROPERTY(bool showAlpha READ showAlpha WRITE setShowAlpha NOTIFY showAlphaChanged)
/**
* \brief If \b true, the background of the widget is changed to show the color
*/
Q_PROPERTY(bool previewColor READ previewColor WRITE setPreviewColor NOTIFY previewColorChanged)
public:
explicit ColorLineEdit(QWidget* parent = nullptr);
~ColorLineEdit();
QColor color() const;
bool showAlpha() const;
bool previewColor() const;
public Q_SLOTS:
void setColor(const QColor& color);
void setShowAlpha(bool showAlpha);
void setPreviewColor(bool previewColor);
Q_SIGNALS:
/**
* \brief Emitted when the color is changed by any means
*/
void colorChanged(const QColor& color);
/**
* \brief Emitted when the user is typing a color but has not finished yet
*/
void colorEdited(const QColor& color);
/**
* \brief Emitted when the user finished to edit a string
*/
void colorEditingFinished(const QColor& color);
void showAlphaChanged(bool showAlpha);
void previewColorChanged(bool previewColor);
protected:
void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
void dropEvent(QDropEvent * event) Q_DECL_OVERRIDE;
void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE;
private:
class Private;
Private* p;
};
} // namespace color_widgets
#endif // COLOR_WIDGETS_COLOR_LINE_EDIT_HPP

View File

@@ -0,0 +1,78 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_LIST_WIDGET_HPP
#define COLOR_LIST_WIDGET_HPP
#include "abstract_widget_list.hpp"
#include "color_wheel.hpp"
namespace color_widgets {
class QCP_EXPORT ColorListWidget : public AbstractWidgetList
{
Q_OBJECT
Q_PROPERTY(QList<QColor> colors READ colors WRITE setColors NOTIFY colorsChanged )
Q_PROPERTY(ColorWheel::ShapeEnum wheelShape READ wheelShape WRITE setWheelShape NOTIFY wheelShapeChanged)
Q_PROPERTY(ColorWheel::ColorSpaceEnum colorSpace READ colorSpace WRITE setColorSpace NOTIFY colorSpaceChanged)
Q_PROPERTY(bool wheelRotating READ wheelRotating WRITE setWheelRotating NOTIFY wheelRotatingChanged)
public:
explicit ColorListWidget(QWidget *parent = 0);
~ColorListWidget();
QList<QColor> colors() const;
void setColors(const QList<QColor>& colors);
void swap(int a, int b);
void append();
ColorWheel::ShapeEnum wheelShape() const;
ColorWheel::ColorSpaceEnum colorSpace() const;
bool wheelRotating() const;
Q_SIGNALS:
void colorsChanged(const QList<QColor>&);
void wheelShapeChanged(ColorWheel::ShapeEnum shape);
void colorSpaceChanged(ColorWheel::ColorSpaceEnum space);
void wheelRotatingChanged(bool rotating);
public Q_SLOTS:
void setWheelShape(ColorWheel::ShapeEnum shape);
void setColorSpace(ColorWheel::ColorSpaceEnum space);
void setWheelRotating(bool rotating);
private Q_SLOTS:
void emit_changed();
void handle_removed(int);
void color_changed(int row);
private:
class Private;
Private * const p;
void append_widget(int col);
};
} // namespace color_widgets
#endif // COLOR_LIST_WIDGET_HPP

View File

@@ -0,0 +1,57 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_WIDGETS_COLOR_NAMES_HPP
#define COLOR_WIDGETS_COLOR_NAMES_HPP
#include <QColor>
#include <QString>
#include <QtColorWidgets/colorwidgets_global.hpp>
namespace color_widgets {
/**
* \brief Convert a string into a color
*
* Supported string formats:
* * Short hex strings #f00
* * Long hex strings #ff0000
* * Color names red
* * Function-like rgb(255,0,0)
*
* Additional string formats supported only when \p alpha is true:
* * Long hex strings #ff0000ff
* * Function like rgba(255,0,0,255)
*/
QCP_EXPORT QColor colorFromString(const QString& string, bool alpha = true);
/**
* \brief Convert a color into a string
*
* Format:
* * If the color has full alpha: #ff0000
* * If alpha is true and the color has non-full alpha: #ff000088
*/
QCP_EXPORT QString stringFromColor(const QColor& color, bool alpha = true);
} // namespace color_widgets
#endif // COLOR_WIDGETS_COLOR_NAMES_HPP

View File

@@ -0,0 +1,229 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_WIDGETS_COLOR_PALETTE_HPP
#define COLOR_WIDGETS_COLOR_PALETTE_HPP
#include <QColor>
#include <QString>
#include <QVector>
#include <QObject>
#include <QPair>
#include <QPixmap>
#include "colorwidgets_global.hpp"
namespace color_widgets {
class QCP_EXPORT ColorPalette : public QObject
{
Q_OBJECT
/**
* \brief The list of colors
*/
Q_PROPERTY(QVector<value_type> colors READ colors WRITE setColors NOTIFY colorsChanged)
/**
* \brief Name of the palette
*/
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
/**
* \brief Number of colors to display in a row, if 0 unspecified
*/
Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged)
/**
* \brief Number of colors
*/
Q_PROPERTY(int count READ count)
/**
* \brief Name of the file the palette has been read from
*/
Q_PROPERTY(QString fileName READ fileName WRITE setFileName NOTIFY fileNameChanged)
/**
* \brief Whether it has been modified and it might be advisable to save it
*/
Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged)
public:
typedef QPair<QColor,QString> value_type;
ColorPalette(const QVector<QColor>& colors, const QString& name = QString(), int columns = 0);
ColorPalette(const QVector<QPair<QColor,QString> >& colors, const QString& name = QString(), int columns = 0);
explicit ColorPalette(const QString& name = QString());
ColorPalette(const ColorPalette& other);
ColorPalette& operator=(const ColorPalette& other);
~ColorPalette();
ColorPalette(ColorPalette&& other);
ColorPalette& operator=(ColorPalette&& other);
/**
* \brief Color at the given index
*/
Q_INVOKABLE QColor colorAt(int index) const;
/**
* \brief Color name at the given index
*/
Q_INVOKABLE QString nameAt(int index) const;
QVector<QPair<QColor,QString> > colors() const;
QVector<QColor> onlyColors() const;
int count() const;
int columns();
QString name() const;
/**
* \brief Use a color table to set the colors
*/
Q_INVOKABLE void loadColorTable(const QVector<QRgb>& color_table);
/**
* \brief Convert to a color table
*/
Q_INVOKABLE QVector<QRgb> colorTable() const;
/**
* \brief Creates a ColorPalette from a color table
*/
static ColorPalette fromColorTable(const QVector<QRgb>& table);
/**
* \brief Use the pixels on an image to set the palette colors
*/
Q_INVOKABLE bool loadImage(const QImage& image);
/**
* \brief Creates a ColorPalette from a Gimp palette (gpl) file
*/
static ColorPalette fromImage(const QImage& image);
/**
* \brief Load contents from a Gimp palette (gpl) file
* \returns \b true On Success
* \note If this function returns \b false, the palette will become empty
*/
Q_INVOKABLE bool load(const QString& name);
/**
* \brief Creates a ColorPalette from a Gimp palette (gpl) file
*/
static ColorPalette fromFile(const QString& name);
QString fileName() const;
bool dirty() const;
/**
* \brief Returns a preview image of the colors in the palette
*/
QPixmap preview(const QSize& size, const QColor& background=Qt::transparent) const;
public Q_SLOTS:
void setColumns(int columns);
void setColors(const QVector<QColor>& colors);
void setColors(const QVector<QPair<QColor,QString> >& colors);
/**
* \brief Change the color at the given index
*/
void setColorAt(int index, const QColor& color);
/**
* \brief Change the color at the given index
*/
void setColorAt(int index, const QColor& color, const QString& name);
/**
* \brief Change the name of a color
*/
void setNameAt(int index, const QString& name = QString());
/**
* \brief Append a color at the end
*/
void appendColor(const QColor& color, const QString& name = QString());
/**
* \brief Insert a color in an arbitrary location
*/
void insertColor(int index, const QColor& color, const QString& name = QString());
/**
* \brief Remove the color at the given index
*/
void eraseColor(int index);
/**
* \brief Change file name and save
* \returns \b true on success
*/
bool save(const QString& filename);
/**
* \brief save to file, the filename is \c fileName or determined automatically
* \returns \b true on success
*/
bool save();
void setName(const QString& name);
void setFileName(const QString& name);
void setDirty(bool dirty);
Q_SIGNALS:
/**
* \brief Emitted when all the colors have changed
*/
void colorsChanged(const QVector<QPair<QColor,QString> >&);
void columnsChanged(int);
void nameChanged(const QString&);
void fileNameChanged(const QString&);
void dirtyChanged(bool);
/**
* \brief Emitted when the color or the name at the given index has been modified
*/
void colorChanged(int index);
/**
* \brief Emitted when the color at the given index has been removed
*/
void colorRemoved(int index);
/**
* \brief Emitted when a single color has been added
*/
void colorAdded(int index);
/**
* \brief Emitted when the colors have been modified with a simple operation (set, append etc.)
*/
void colorsUpdated(const QVector<QPair<QColor,QString>>&);
private:
/**
* \brief Returns \c name if it isn't null, otherwise a default value
*/
QString unnamed(const QString& name = QString()) const;
/**
* \brief Emit all the necessary signals when the palette has been completely overwritten
*/
void emitUpdate();
class Private;
Private *p;
};
} // namespace color_widgets
#endif // COLOR_WIDGETS_COLOR_PALETTE_HPP

View File

@@ -0,0 +1,140 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_WIDGETS_COLOR_PALETTE_MODEL_HPP
#define COLOR_WIDGETS_COLOR_PALETTE_MODEL_HPP
#include <QAbstractListModel>
#include "color_palette.hpp"
namespace color_widgets {
class QCP_EXPORT ColorPaletteModel : public QAbstractListModel
{
Q_OBJECT
/**
* \brief List of directories to be scanned for palette files
*/
Q_PROPERTY(QStringList searchPaths READ searchPaths WRITE setSearchPaths NOTIFY searchPathsChanged)
/**
* \brief Default directory to be used when saving a palette
*/
Q_PROPERTY(QString savePath READ savePath WRITE setSavePath NOTIFY savePathChanged)
/**
* \brief Size of the icon used for the palette previews
*/
Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged)
public:
ColorPaletteModel();
~ColorPaletteModel();
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex()) Q_DECL_OVERRIDE;
QString savePath() const;
QStringList searchPaths() const;
QSize iconSize() const;
/**
* \brief Number of palettes
*/
int count() const;
/**
* \brief Returns a reference to the first palette with the given name
* \pre hasPalette(name)
*/
const ColorPalette& palette(const QString& name) const;
/**
* \brief Whether a palette with the given name exists in the model
*/
bool hasPalette(const QString& name) const;
/**
* \brief Get the palette at the given index (row)
* \pre 0 <= index < count()
*/
const ColorPalette& palette(int index) const;
/**
* \brief Updates an existing palette
* \param index Palette index
* \param palette New palette
* \param save Whether to save the palette to the filesystem
*
* Saving will try: (in this order)
* * To overwrite the file pointed by the old palette
* * To write to the new palette file name
* * To create a file in the save path
* If all of the above fail, the palette will be replaced interally
* but not on the filesystem
*
* \returns \b true if the palette has been successfully updated (and saved)
*/
bool updatePalette(int index, const ColorPalette& palette, bool save = true);
/**
* \brief Remove a palette from the model and optionally from the filesystem
* \returns \b true if the palette has been successfully removed
*/
bool removePalette(int index, bool remove_file = true);
/**
* \brief Remove a palette to the model and optionally to the filesystem
* \returns \b true if the palette has been successfully added
*/
bool addPalette(const ColorPalette& palette, bool save = true);
/**
* \brief The index of the palette with the given file name
* \returns -1 if none is found
*/
int indexFromFile(const QString& filename) const;
public Q_SLOTS:
void setSavePath(const QString& savePath);
void setSearchPaths(const QStringList& searchPaths);
void addSearchPath(const QString& path);
void setIconSize(const QSize& iconSize);
/**
* \brief Load palettes files found in the search paths
*/
void load();
Q_SIGNALS:
void savePathChanged(const QString& savePath);
void searchPathsChanged(const QStringList& searchPaths);
void iconSizeChanged(const QSize& iconSize);
private:
class Private;
Private* p;
};
} // namespace color_widgets
#endif // COLOR_WIDGETS_COLOR_PALETTE_MODEL_HPP

View File

@@ -0,0 +1,204 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_WIDGETS_COLOR_PALETTE_WIDGET_HPP
#define COLOR_WIDGETS_COLOR_PALETTE_WIDGET_HPP
#include <memory>
#include <QWidget>
#include "color_palette_model.hpp"
#include "swatch.hpp"
namespace color_widgets {
/**
* \brief A widget to use and modify palettes
*/
class QCP_EXPORT ColorPaletteWidget : public QWidget
{
Q_OBJECT
/**
* \brief Model used to store the palettes
*/
Q_PROPERTY(ColorPaletteModel* model READ model WRITE setModel NOTIFY modelChanged)
/**
* \brief Size of a single color in the swatch widget
*/
Q_PROPERTY(QSize colorSize READ colorSize WRITE setColorSize NOTIFY colorSizeChanged)
/**
* \brief Policy for colorSize
**/
Q_PROPERTY(color_widgets::Swatch::ColorSizePolicy colorSizePolicy READ colorSizePolicy WRITE setColorSizePolicy NOTIFY colorSizePolicyChanged)
/**
* \brief Border around the colors
*/
Q_PROPERTY(QPen border READ border WRITE setBorder NOTIFY borderChanged)
/**
* \brief Forces the Swatch to display that many rows of colors
*
* If there are too few elements, the widget will display less than this
* many rows.
*
* A value of0 means that the number of rows is automatic.
*
* \note Conflicts with forcedColumns
*/
Q_PROPERTY(int forcedRows READ forcedRows WRITE setForcedRows NOTIFY forcedRowsChanged)
/**
* \brief Forces the Swatch to display that many columns of colors
*
* If there are too few elements, the widget will display less than this
* many columns.
*
* A value of 0 means that the number of columns is automatic.
*
* \note Conflicts with forcedRows
*/
Q_PROPERTY(int forcedColumns READ forcedColumns WRITE setForcedColumns NOTIFY forcedColumnsChanged)
/**
* \brief Whether the palettes can be modified via user interaction
*/
Q_PROPERTY(bool readOnly READ readOnly WRITE setReadOnly NOTIFY readOnlyChanged)
/**
* \brief Currently selected color
*/
Q_PROPERTY(QColor currentColor READ currentColor WRITE setCurrentColor NOTIFY currentColorChanged)
/**
* \brief Currently selected model row
*/
Q_PROPERTY(int currentRow READ currentRow WRITE setCurrentRow NOTIFY currentRowChanged)
/**
* \brief Palette shown by the widget
*/
Q_PROPERTY(const ColorPalette& currentPalette READ currentPalette NOTIFY currentPaletteChanged)
/**
* \brief If a valid color, it's used when adding new colors to palettes
*/
Q_PROPERTY(QColor defaultColor READ defaultColor WRITE setDefaultColor NOTIFY defaultColorChanged)
public:
ColorPaletteWidget(QWidget* parent = nullptr);
~ColorPaletteWidget();
ColorPaletteModel* model() const;
/**
* \brief Currently selected palette
* \pre model() != nullptr and there is a selected palette
*/
const ColorPalette& currentPalette() const;
QSize colorSize() const;
Swatch::ColorSizePolicy colorSizePolicy() const;
QPen border() const;
int forcedRows() const;
int forcedColumns() const;
bool readOnly() const;
QColor currentColor() const;
int currentRow() const;
/**
* \brief Default color when adding a color to the current palette
*/
QColor defaultColor() const;
public Q_SLOTS:
void setModel(ColorPaletteModel* model);
void setColorSize(const QSize& colorSize);
void setColorSizePolicy(Swatch::ColorSizePolicy colorSizePolicy);
void setBorder(const QPen& border);
void setForcedRows(int forcedRows);
void setForcedColumns(int forcedColumns);
void setReadOnly(bool readOnly);
/**
* \brief Clear the selected color
*/
void clearCurrentColor();
/**
* \brief Attempt to select a color
*
* If the given color is available in the current palete, it will be selected
* \return \b true on success
*/
bool setCurrentColor(const QColor& color);
/**
* \brief Attempt to select a color by name
*
* If the given color is available in the current palete, it will be selected
* \return \b true on success
*/
bool setCurrentColor(const QString& name);
/**
* \brief Attempt to select a color by index
*
* If the given color is available in the current palete, it will be selected
* \return \b true on success
*/
bool setCurrentColor(int index);
/**
* \brief Set the selected row in the model
*/
void setCurrentRow(int currentRow);
/**
* \brief Sets the default for new colors
* If invalid, it will show a dialog
*/
void setDefaultColor(const QColor& color);
Q_SIGNALS:
void modelChanged(ColorPaletteModel* model);
void colorSizeChanged(const QSize& colorSize);
void colorSizePolicyChanged(Swatch::ColorSizePolicy colorSizePolicy);
void forcedRowsChanged(int forcedRows);
void forcedColumnsChanged(int forcedColumns);
void readOnlyChanged(bool readOnly);
void currentColorChanged(const QColor& currentColor);
void currentColorChanged(int index);
void borderChanged(const QPen& border);
void currentRowChanged(int currentRow);
void currentPaletteChanged(const ColorPalette& palette);
void defaultColorChanged(const QColor& color);
private Q_SLOTS:
void on_palette_list_currentIndexChanged(int index);
void on_swatch_doubleClicked(int index);
private:
class Private;
std::unique_ptr<Private> p;
};
} // namespace color_widgets
#endif // COLOR_WIDGETS_COLOR_PALETTE_WIDGET_HPP

View File

@@ -0,0 +1,116 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
* \copyright Copyright (C) 2014 Calle Laakkonen
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_PREVIEW_HPP
#define COLOR_PREVIEW_HPP
#include "colorwidgets_global.hpp"
#include <QWidget>
namespace color_widgets {
/**
* Simple widget that shows a preview of a color
*/
class QCP_EXPORT ColorPreview : public QWidget
{
Q_OBJECT
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged DESIGNABLE true)
Q_PROPERTY(QColor comparisonColor READ comparisonColor WRITE setComparisonColor NOTIFY comparisonColorChanged DESIGNABLE true)
Q_PROPERTY(DisplayMode display_mode READ displayMode WRITE setDisplayMode NOTIFY displayModeChanged DESIGNABLE true)
Q_PROPERTY(QBrush background READ background WRITE setBackground NOTIFY backgroundChanged DESIGNABLE true)
Q_PROPERTY(bool drawFrame READ drawFrame WRITE setDrawFrame NOTIFY drawFrameChanged DESIGNABLE true)
Q_ENUMS(DisplayMode)
public:
enum DisplayMode
{
NoAlpha, ///< Show current color with no transparency
AllAlpha, ///< show current color with transparency
SplitAlpha, ///< Show both solid and transparent side by side
SplitColor, ///< Show current and comparison colors side by side
SplitColorReverse, ///< Like Split color but swapped
};
Q_ENUMS(DisplayMode)
explicit ColorPreview(QWidget *parent = 0);
~ColorPreview();
/// Get the background visible under transparent colors
QBrush background() const;
/// Change the background visible under transparent colors
void setBackground(const QBrush &bk);
/// Get color display mode
DisplayMode displayMode() const;
/// Set how transparent colors are handled
void setDisplayMode(DisplayMode dm);
/// Get current color
QColor color() const;
/// Get the comparison color
QColor comparisonColor() const;
QSize sizeHint () const Q_DECL_OVERRIDE;
void paint(QPainter &painter, QRect rect) const;
/// Whether to draw a frame around the color
bool drawFrame() const;
void setDrawFrame(bool);
public Q_SLOTS:
/// Set current color
void setColor(const QColor &c);
/// Set the comparison color
void setComparisonColor(const QColor &c);
Q_SIGNALS:
/// Emitted when the user clicks on the widget
void clicked();
/// Emitted on setColor
void colorChanged(QColor);
void comparisonColorChanged(QColor);
void displayModeChanged(DisplayMode);
void backgroundChanged(const QBrush&);
void drawFrameChanged(bool);
protected:
void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent *ev) Q_DECL_OVERRIDE;
private:
class Private;
Private * const p;
};
} // namespace color_widgets
Q_DECLARE_METATYPE(color_widgets::ColorPreview::DisplayMode)
#endif // COLOR_PREVIEW_HPP

View File

@@ -0,0 +1,99 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_SELECTOR_HPP
#define COLOR_SELECTOR_HPP
#include "color_preview.hpp"
#include "color_wheel.hpp"
namespace color_widgets {
/**
* Color preview that opens a color dialog
*/
class QCP_EXPORT ColorSelector : public ColorPreview
{
Q_OBJECT
Q_ENUMS(UpdateMode)
Q_PROPERTY(UpdateMode updateMode READ updateMode WRITE setUpdateMode NOTIFY updateModeChanged)
Q_PROPERTY(Qt::WindowModality dialogModality READ dialogModality WRITE setDialogModality NOTIFY dialogModalityChanged)
Q_PROPERTY(ColorWheel::ShapeEnum wheelShape READ wheelShape WRITE setWheelShape NOTIFY wheelShapeChanged)
Q_PROPERTY(ColorWheel::ColorSpaceEnum colorSpace READ colorSpace WRITE setColorSpace NOTIFY colorSpaceChanged)
Q_PROPERTY(bool wheelRotating READ wheelRotating WRITE setWheelRotating NOTIFY wheelRotatingChanged)
public:
enum UpdateMode {
Confirm, ///< Update color only after the dialog has been accepted
Continuous ///< Update color as it's being modified in the dialog
};
explicit ColorSelector(QWidget *parent = 0);
~ColorSelector();
void setUpdateMode(UpdateMode m);
UpdateMode updateMode() const;
Qt::WindowModality dialogModality() const;
void setDialogModality(Qt::WindowModality m);
ColorWheel::ShapeEnum wheelShape() const;
ColorWheel::ColorSpaceEnum colorSpace() const;
bool wheelRotating() const;
Q_SIGNALS:
void wheelShapeChanged(ColorWheel::ShapeEnum shape);
void colorSpaceChanged(ColorWheel::ColorSpaceEnum space);
void wheelRotatingChanged(bool rotating);
void updateModeChanged(UpdateMode);
void dialogModalityChanged(Qt::WindowModality);
/// Emitted when a color is selected by the user
void colorSelected(const QColor& c);
public Q_SLOTS:
void showDialog();
void setWheelShape(ColorWheel::ShapeEnum shape);
void setColorSpace(ColorWheel::ColorSpaceEnum space);
void setWheelRotating(bool rotating);
private Q_SLOTS:
void accept_dialog();
void reject_dialog();
void update_old_color(const QColor &c);
protected:
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent * event);
private:
/// Connect/Disconnect colorChanged based on UpdateMode
void connect_dialog();
/// Disconnect from dialog update
void disconnect_dialog();
class Private;
Private * const p;
};
} // namespace color_widgets
#endif // COLOR_SELECTOR_HPP

View File

@@ -3,7 +3,7 @@
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2017 Mattia Basaglia
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@@ -19,43 +19,50 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_UTILS_HPP
#define COLOR_UTILS_HPP
#include <QColor>
#include <QPoint>
#include <qmath.h>
#include "QtColorWidgets/colorwidgets_global.hpp"
namespace color_widgets {
namespace detail {
namespace utils {
inline qreal color_chromaF(const QColor& c)
QCP_EXPORT inline qreal color_chromaF(const QColor& c)
{
qreal max = qMax(c.redF(), qMax(c.greenF(), c.blueF()));
qreal min = qMin(c.redF(), qMin(c.greenF(), c.blueF()));
return max - min;
}
inline qreal color_lumaF(const QColor& c)
QCP_EXPORT inline qreal color_lumaF(const QColor& c)
{
return 0.30 * c.redF() + 0.59 * c.greenF() + 0.11 * c.blueF();
}
QColor color_from_lch(qreal hue, qreal chroma, qreal luma, qreal alpha = 1 );
inline QColor rainbow_lch(qreal hue)
QCP_EXPORT QColor color_from_lch(qreal hue, qreal chroma, qreal luma, qreal alpha = 1 );
QCP_EXPORT inline QColor rainbow_lch(qreal hue)
{
return color_from_lch(hue,1,1);
}
inline QColor rainbow_hsv(qreal hue)
QCP_EXPORT inline QColor rainbow_hsv(qreal hue)
{
return QColor::fromHsvF(hue,1,1);
}
inline qreal color_lightnessF(const QColor& c)
QCP_EXPORT inline qreal color_lightnessF(const QColor& c)
{
return ( qMax(c.redF(),qMax(c.greenF(),c.blueF())) +
qMin(c.redF(),qMin(c.greenF(),c.blueF())) ) / 2;
}
inline qreal color_HSL_saturationF(const QColor& col)
QCP_EXPORT inline qreal color_HSL_saturationF(const QColor& col)
{
qreal c = color_chromaF(col);
qreal l = color_lightnessF(col);
@@ -64,7 +71,12 @@ inline qreal color_HSL_saturationF(const QColor& col)
return c / (1-qAbs(2*l-1));
}
QColor color_from_hsl(qreal hue, qreal sat, qreal lig, qreal alpha = 1 );
} // namespace detail
QCP_EXPORT QColor color_from_hsl(qreal hue, qreal sat, qreal lig, qreal alpha = 1 );
QCP_EXPORT QColor get_screen_color(const QPoint &global_pos);
} // namespace utils
} // namespace color_widgets
#endif // COLOR_UTILS_HPP

View File

@@ -3,7 +3,7 @@
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2017 Mattia Basaglia
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@@ -24,6 +24,9 @@
#include <QWidget>
#include "colorwidgets_global.hpp"
namespace color_widgets {
/**
@@ -32,7 +35,7 @@ namespace color_widgets {
* It has an outer wheel to select the Hue and an intenal square to select
* Saturation and Lightness.
*/
class ColorWheel : public QWidget
class QCP_EXPORT ColorWheel : public QWidget
{
Q_OBJECT
@@ -40,35 +43,36 @@ class ColorWheel : public QWidget
Q_PROPERTY(qreal hue READ hue WRITE setHue DESIGNABLE false )
Q_PROPERTY(qreal saturation READ saturation WRITE setSaturation DESIGNABLE false )
Q_PROPERTY(qreal value READ value WRITE setValue DESIGNABLE false )
Q_PROPERTY(unsigned wheelWidth READ wheelWidth WRITE setWheelWidth DESIGNABLE true )
Q_PROPERTY(DisplayFlags displayFlags READ displayFlags WRITE setDisplayFlags NOTIFY displayFlagsChanged DESIGNABLE true )
Q_PROPERTY(unsigned wheelWidth READ wheelWidth WRITE setWheelWidth NOTIFY wheelWidthChanged DESIGNABLE true )
Q_PROPERTY(ShapeEnum selectorShape READ selectorShape WRITE setSelectorShape NOTIFY selectorShapeChanged DESIGNABLE true )
Q_PROPERTY(bool rotatingSelector READ rotatingSelector WRITE setRotatingSelector NOTIFY rotatingSelectorChanged DESIGNABLE true )
Q_PROPERTY(ColorSpaceEnum colorSpace READ colorSpace WRITE setColorSpace NOTIFY colorSpaceChanged DESIGNABLE true )
public:
enum DisplayEnum
enum ShapeEnum
{
SHAPE_DEFAULT = 0x000, ///< Use the default shape
SHAPE_TRIANGLE = 0x001, ///< A triangle
SHAPE_SQUARE = 0x002, ///< A square
SHAPE_FLAGS = 0x00f, ///< Mask for the shape flags
ANGLE_DEFAULT = 0x000, ///< Use the default rotation style
ANGLE_FIXED = 0x010, ///< The inner part doesn't rotate
ANGLE_ROTATING = 0x020, ///< The inner part follows the hue selector
ANGLE_FLAGS = 0x0f0, ///< Mask for the angle flags
COLOR_DEFAULT = 0x000, ///< Use the default colorspace
COLOR_HSV = 0x100, ///< Use the HSV color space
COLOR_HSL = 0x200, ///< Use the HSL color space
COLOR_LCH = 0x400, ///< Use Luma Chroma Hue (Y_601')
COLOR_FLAGS = 0xf00, ///< Mask for the color space flags
FLAGS_DEFAULT = 0x000, ///< Use all defaults
FLAGS_ALL = 0xfff ///< Mask matching all flags
ShapeTriangle, ///< A triangle
ShapeSquare, ///< A square
};
Q_DECLARE_FLAGS(DisplayFlags, DisplayEnum)
Q_FLAGS(DisplayFlags)
explicit ColorWheel(QWidget *parent = nullptr);
enum AngleEnum
{
AngleFixed, ///< The inner part doesn't rotate
AngleRotating, ///< The inner part follows the hue selector
};
enum ColorSpaceEnum
{
ColorHSV, ///< Use the HSV color space
ColorHSL, ///< Use the HSL color space
ColorLCH, ///< Use Luma Chroma Hue (Y_601')
};
Q_ENUM(ShapeEnum);
Q_ENUM(AngleEnum);
Q_ENUM(ColorSpaceEnum);
explicit ColorWheel(QWidget *parent = 0);
~ColorWheel();
/// Get current color
@@ -91,21 +95,14 @@ public:
/// Set the width in pixels of the outer wheel
void setWheelWidth(unsigned int w);
/// Get display flags
DisplayFlags displayFlags(DisplayFlags mask = FLAGS_ALL) const;
/// Shape of the internal selector
ShapeEnum selectorShape() const;
/// Set the default display flags
static void setDefaultDisplayFlags(DisplayFlags flags);
/// Whether the internal selector should rotare in accordance with the hue
bool rotatingSelector() const;
/// Get default display flags
static DisplayFlags defaultDisplayFlags(DisplayFlags mask = FLAGS_ALL);
/**
* @brief Set a specific display flag
* @param flag Flag replacing the mask
* @param mask Mask to be cleared
*/
void setDisplayFlag(DisplayFlags flag, DisplayFlags mask);
/// Color space used to preview/edit the color
ColorSpaceEnum colorSpace() const;
public Q_SLOTS:
@@ -127,11 +124,14 @@ public Q_SLOTS:
*/
void setValue(qreal v);
/**
* @brief Set the display flags
* @param flags which will replace the current ones
*/
void setDisplayFlags(ColorWheel::DisplayFlags flags);
/// Sets the shape of the internal selector
void setSelectorShape(ShapeEnum shape);
/// Sets whether the internal selector should rotare in accordance with the hue
void setRotatingSelector(bool rotating);
/// Sets the color space used to preview/edit the color
void setColorSpace(ColorSpaceEnum space);
Q_SIGNALS:
/**
@@ -144,25 +144,37 @@ Q_SIGNALS:
*/
void colorSelected(QColor);
void displayFlagsChanged(ColorWheel::DisplayFlags flags);
void wheelWidthChanged(unsigned);
void mouseReleaseOnColor(QColor);
void selectorShapeChanged(ShapeEnum shape);
void rotatingSelectorChanged(bool rotating);
void colorSpaceChanged(ColorSpaceEnum space);
/**
* Emitted when the user releases from dragging
*/
void editingFinished();
protected:
void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;
void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
void dragEnterEvent(QDragEnterEvent* event) Q_DECL_OVERRIDE;
void dropEvent(QDropEvent* event) Q_DECL_OVERRIDE;
private:
protected:
class Private;
Private * const p;
};
ColorWheel(QWidget *parent, Private* data);
Private* data() const { return p; }
Q_DECLARE_OPERATORS_FOR_FLAGS(ColorWheel::DisplayFlags)
private:
Private * const p;
};
} // namespace color_widgets

View File

@@ -0,0 +1,291 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
* \copyright Copyright (C) 2017 caryoscelus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "QtColorWidgets/color_wheel.hpp"
#include "QtColorWidgets/color_utils.hpp"
#include <QPainter>
#include <QPainterPath>
#include <QMouseEvent>
namespace color_widgets {
enum MouseStatus
{
Nothing,
DragCircle,
DragSquare
};
class ColorWheel::Private
{
private:
ColorWheel * const w;
public:
qreal hue, sat, val;
bool backgroundIsDark;
unsigned int wheel_width;
MouseStatus mouse_status;
QPixmap hue_ring;
QImage inner_selector;
std::vector<uint32_t> inner_selector_buffer;
ColorSpaceEnum color_space = ColorHSV;
bool rotating_selector = true;
ShapeEnum selector_shape = ShapeTriangle;
QColor (*color_from)(qreal,qreal,qreal,qreal);
QColor (*rainbow_from_hue)(qreal);
int max_size = 128;
Private(ColorWheel *widget)
: w(widget), hue(0), sat(0), val(0),
wheel_width(20), mouse_status(Nothing),
color_from(&QColor::fromHsvF), rainbow_from_hue(&utils::rainbow_hsv)
{
}
void setup()
{
qreal backgroundValue = w->palette().window().color().valueF();
backgroundIsDark = backgroundValue < 0.5;
}
virtual ~Private(){}
/// Calculate outer wheel radius from idget center
qreal outer_radius() const
{
return qMin(w->geometry().width(), w->geometry().height())/2;
}
/// Calculate inner wheel radius from idget center
qreal inner_radius() const
{
return outer_radius()-wheel_width;
}
/// Calculate the edge length of the inner square
qreal square_size() const
{
return inner_radius()*qSqrt(2);
}
/// Calculate the height of the inner triangle
qreal triangle_height() const
{
return inner_radius()*3/2;
}
/// Calculate the side of the inner triangle
qreal triangle_side() const
{
return inner_radius()*qSqrt(3);
}
/// return line from center to given point
QLineF line_to_point(const QPoint &p) const
{
return QLineF (w->geometry().width()/2, w->geometry().height()/2, p.x(), p.y());
}
/**
* Ensures the internal image buffer is the correct size
* and that the QImage is associated to it
*/
void init_buffer(QSize size)
{
std::size_t linear_size = size.width() * size.height();
if ( inner_selector_buffer.size() == linear_size )
return;
inner_selector_buffer.resize(linear_size);
inner_selector = QImage(
reinterpret_cast<uchar*>(inner_selector_buffer.data()),
size.width(),
size.height(),
QImage::Format_RGB32
);
}
void render_square()
{
int width = qMin<int>(square_size(), max_size);
init_buffer(QSize(width, width));
for ( int y = 0; y < width; ++y )
{
for ( int x = 0; x < width; ++x )
{
QRgb color = color_from(hue,double(x)/width,double(y)/width,1).rgb();
inner_selector_buffer[width * y + x] = color;
}
}
}
/**
* \brief renders the selector as a triangle
* \note It's the same as a square with the edge with value=0 collapsed to a single point
*/
void render_triangle()
{
QSizeF size = selector_size();
if ( size.height() > max_size )
size *= max_size / size.height();
qreal ycenter = size.height()/2;
QSize isize = size.toSize();
init_buffer(isize);
for (int x = 0; x < isize.width(); x++ )
{
qreal pval = x / size.height();
qreal slice_h = size.height() * pval;
for (int y = 0; y < isize.height(); y++ )
{
qreal ymin = ycenter-slice_h/2;
qreal psat = qBound(0.0,(y-ymin)/slice_h,1.0);
QRgb color = color_from(hue,psat,pval,1).rgb();
inner_selector_buffer[isize.width() * y + x] = color;
}
}
}
/// Updates the inner image that displays the saturation-value selector
void render_inner_selector()
{
if ( selector_shape == ShapeTriangle )
render_triangle();
else
render_square();
}
/// Offset of the selector image
QPointF selector_image_offset()
{
if ( selector_shape == ShapeTriangle )
return QPointF(-inner_radius(),-triangle_side()/2);
return QPointF(-square_size()/2,-square_size()/2);
}
/**
* \brief Size of the selector when rendered to the screen
*/
QSizeF selector_size()
{
if ( selector_shape == ShapeTriangle )
return QSizeF(triangle_height(), triangle_side());
return QSizeF(square_size(), square_size());
}
/// Rotation of the selector image
qreal selector_image_angle()
{
if ( selector_shape == ShapeTriangle )
{
if ( rotating_selector )
return -hue*360-60;
return -150;
}
else
{
if ( rotating_selector )
return -hue*360-45;
else
return 180;
}
}
/// Updates the outer ring that displays the hue selector
void render_ring()
{
hue_ring = QPixmap(outer_radius()*2,outer_radius()*2);
hue_ring.fill(Qt::transparent);
QPainter painter(&hue_ring);
painter.setRenderHint(QPainter::Antialiasing);
painter.setCompositionMode(QPainter::CompositionMode_Source);
const int hue_stops = 24;
QConicalGradient gradient_hue(0, 0, 0);
if ( gradient_hue.stops().size() < hue_stops )
{
for ( double a = 0; a < 1.0; a+=1.0/(hue_stops-1) )
{
gradient_hue.setColorAt(a,rainbow_from_hue(a));
}
gradient_hue.setColorAt(1,rainbow_from_hue(0));
}
painter.translate(outer_radius(),outer_radius());
painter.setPen(Qt::NoPen);
painter.setBrush(QBrush(gradient_hue));
painter.drawEllipse(QPointF(0,0),outer_radius(),outer_radius());
painter.setBrush(Qt::transparent);//palette().background());
painter.drawEllipse(QPointF(0,0),inner_radius(),inner_radius());
}
void set_color(const QColor& c)
{
float nice_hue = c.hsvHueF();
if ( nice_hue < 0 )
nice_hue = c.hslHueF();
if ( nice_hue < 0 )
nice_hue = hue;
switch ( color_space )
{
case ColorHSV:
hue = nice_hue;
sat = c.hsvSaturationF();
val = c.valueF();
break;
case ColorHSL:
hue = nice_hue;
sat = utils::color_HSL_saturationF(c);
val = utils::color_lightnessF(c);
break;
case ColorLCH:
hue = nice_hue;
sat = utils::color_chromaF(c);
val = utils::color_lumaF(c);
break;
}
}
void draw_ring_editor(double editor_hue, QPainter& painter, QColor color) {
painter.setPen(QPen(color,3));
painter.setBrush(Qt::NoBrush);
QLineF ray(0, 0, outer_radius(), 0);
ray.setAngle(editor_hue*360);
QPointF h1 = ray.p2();
ray.setLength(inner_radius());
QPointF h2 = ray.p2();
painter.drawLine(h1,h2);
}
};
} // namespace color_widgets

View File

@@ -0,0 +1,14 @@
#ifndef QT_COLOR_WIDGETS_GLOBAL_H
#define QT_COLOR_WIDGETS_GLOBAL_H
#include <QtCore/QtGlobal>
#if defined(QTCOLORWIDGETS_STATICALLY_LINKED)
# define QCP_EXPORT
#elif defined(QTCOLORWIDGETS_LIBRARY)
# define QCP_EXPORT Q_DECL_EXPORT
#else
# define QCP_EXPORT Q_DECL_IMPORT
#endif
#endif // QT_COLOR_WIDGETS_GLOBAL_H

View File

@@ -0,0 +1,103 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_WIDGETS_GRADIENT_DELEGATE_HPP
#define COLOR_WIDGETS_GRADIENT_DELEGATE_HPP
#include <QStyledItemDelegate>
#include <QPainter>
#include "QtColorWidgets/gradient_editor.hpp"
namespace color_widgets {
/**
* \brief Item delegate to edits gradients
*
* In order to make it work, return as edit data from the model a QBrush with a gradient
*/
class QCP_EXPORT GradientDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const Q_DECL_OVERRIDE
{
QVariant data = index.data(Qt::EditRole);
if ( data.canConvert<QBrush>() )
{
QBrush brush = data.value<QBrush>();
if ( brush.gradient() )
{
GradientEditor* editor = new GradientEditor(parent);
editor->setStops(brush.gradient()->stops());
return editor;
}
}
return QStyledItemDelegate::createEditor(parent, option, index);
}
void setModelData(QWidget * widget, QAbstractItemModel * model, const QModelIndex & index) const Q_DECL_OVERRIDE
{
if ( GradientEditor* editor = qobject_cast<GradientEditor*>(widget) )
model->setData(index, QBrush(editor->gradient()), Qt::EditRole);
else
QStyledItemDelegate::setModelData(widget, model, index);
}
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const Q_DECL_OVERRIDE
{
QVariant display_data = index.data(Qt::DisplayRole);
QVariant gradient_data = display_data.isValid() ? display_data : index.data(Qt::EditRole);
if ( gradient_data.canConvert<QBrush>() )
{
QBrush brush = gradient_data.value<QBrush>();
if ( brush.gradient() )
{
QBrush background;
background.setTexture(QPixmap(QStringLiteral(":/color_widgets/alphaback.png")));
painter->fillRect(option.rect, background);
QLinearGradient g(option.rect.topLeft(), option.rect.topRight());
g.setStops(brush.gradient()->stops());
painter->fillRect(option.rect, g);
if ( option.state & QStyle::State_Selected )
{
int border = 2;
painter->setBrush(Qt::transparent);
painter->setPen(QPen(option.palette.highlight(), border));
painter->drawRect(option.rect.adjusted(border/2, border/2, -border/2, -border/2));
}
return;
}
}
QStyledItemDelegate::paint(painter, option, index);
}
};
} // namespace color_widgets
#endif // COLOR_WIDGETS_GRADIENT_DELEGATE_HPP

View File

@@ -0,0 +1,123 @@
/**
* \file gradient_editor.hpp
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef GRADIENT_EDITOR_HPP
#define GRADIENT_EDITOR_HPP
#include "colorwidgets_global.hpp"
#include <QWidget>
#include <QGradient>
namespace color_widgets {
class ColorDialog;
/**
* \brief A slider that moves on top of a gradient
*/
class QCP_EXPORT GradientEditor : public QWidget
{
Q_OBJECT
Q_PROPERTY(QBrush background READ background WRITE setBackground NOTIFY backgroundChanged)
Q_PROPERTY(QGradientStops stops READ stops WRITE setStops NOTIFY stopsChanged)
Q_PROPERTY(QLinearGradient gradient READ gradient WRITE setGradient)
Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
Q_PROPERTY(int selectedStop READ selectedStop WRITE setSelectedStop NOTIFY selectedStopChanged)
Q_PROPERTY(QColor selectedColor READ selectedColor WRITE setSelectedColor)
public:
explicit GradientEditor(QWidget *parent = 0);
explicit GradientEditor(Qt::Orientation orientation, QWidget *parent = 0);
~GradientEditor();
QSize sizeHint() const override;
/// Get the background, it's visible for transparent gradient stops
QBrush background() const;
/// Set the background, it's visible for transparent gradient stops
void setBackground(const QBrush &bg);
/// Get the colors that make up the gradient
QGradientStops stops() const;
/// Set the colors that make up the gradient
void setStops(const QGradientStops &colors);
/// Get the gradient
QLinearGradient gradient() const;
/// Set the gradient
void setGradient(const QLinearGradient &gradient);
Qt::Orientation orientation() const;
/**
* \brief Dialog shown when double clicking a stop
*/
ColorDialog* dialog() const;
/**
* \brief Index of the currently selected gradient stop (or -1 if there is no selection)
*/
int selectedStop() const;
/**
* \brief Color of the selected stop
*/
QColor selectedColor() const;
public Q_SLOTS:
void setOrientation(Qt::Orientation);
void setSelectedStop(int stop);
void setSelectedColor(const QColor& color);
void addStop();
void removeStop();
Q_SIGNALS:
void backgroundChanged(const QBrush&);
void stopsChanged(const QGradientStops&);
void selectedStopChanged(int);
protected:
void paintEvent(QPaintEvent *ev) override;
void mousePressEvent(QMouseEvent *ev) override;
void mouseMoveEvent(QMouseEvent *ev) override;
void mouseReleaseEvent(QMouseEvent *ev) override;
void leaveEvent(QEvent * event) override;
void mouseDoubleClickEvent(QMouseEvent *event) override;
void dragEnterEvent(QDragEnterEvent *event) override;
void dragMoveEvent(QDragMoveEvent* event) override;
void dragLeaveEvent(QDragLeaveEvent *event) override;
void dropEvent(QDropEvent* event) override;
private Q_SLOTS:
void dialogUpdate(const QColor& c);
private:
class Private;
Private * const p;
};
} // namespace color_widgets
#endif // GRADIENT_EDITOR_HPP

View File

@@ -0,0 +1,98 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef GRADIENT_HELPER_HPP
#define GRADIENT_HELPER_HPP
#include "colorwidgets_global.hpp"
#include <QGradient>
namespace color_widgets {
inline QColor blendColors(const QColor& a, const QColor& b, qreal ratio)
{
return QColor::fromRgbF(
a.redF() * (1-ratio) + b.redF() * ratio,
a.greenF() * (1-ratio) + b.greenF() * ratio,
a.blueF() * (1-ratio) + b.blueF() * ratio,
a.alphaF() * (1-ratio) + b.alphaF() * ratio
);
}
/**
* \brief Get an insertion point in the gradient
* \param gradient Gradient stops to look into (must be properly set up)
* \param factor Value in [0, 1] to get the color for
* \return A pair whose first element is the index to insert the new value at, and a GradientStop
*/
inline QPair<int, QGradientStop> Q_DECL_EXPORT gradientBlendedColorInsert(const QGradientStops& gradient, qreal factor)
{
if ( gradient.empty() )
return {0, {0, QColor()}};
if ( gradient.size() == 1 || factor <= 0 )
return {0, gradient.front()};
int i = 0;
QGradientStop s1;
for ( auto s2 : gradient )
{
if ( factor < s2.first )
{
qreal ratio = (factor - s1.first) / (s2.first - s1.first);
return {i, {factor, blendColors(s1.second, s2.second, ratio)}};
}
s1 = s2;
++i;
}
return {gradient.size(), gradient.back()};
}
/**
* \brief Returns a color in the gradient
* \param gradient Gradient stops to look into (must be properly set up)
* \param factor Value in [0, 1] to get the color for
*/
inline QColor Q_DECL_EXPORT gradientBlendedColor(const QGradientStops& gradient, qreal factor)
{
return gradientBlendedColorInsert(gradient, factor).second.second;
}
/**
* \brief Returns a color in the gradient
* \param gradient Gradient to look into
* \param factor Value in [0, 1] to get the color for
*/
inline QColor Q_DECL_EXPORT gradientBlendedColor(const QGradient& gradient, qreal factor)
{
return gradientBlendedColor(gradient.stops(), factor);
}
} // namespace color_widgets
#endif // GRADIENT_HELPER_HPP

View File

@@ -0,0 +1,173 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_WIDGETS_GRADIENT_LIST_MODEL_HPP
#define COLOR_WIDGETS_GRADIENT_LIST_MODEL_HPP
#include "colorwidgets_global.hpp"
#include <memory>
#include <QAbstractListModel>
#include <QLinearGradient>
namespace color_widgets {
class QCP_EXPORT GradientListModel : public QAbstractListModel
{
Q_OBJECT
/**
* \brief Size of the icon used for the gradient previews
*/
Q_PROPERTY(QSize iconSize READ iconSize WRITE setIconSize NOTIFY iconSizeChanged)
Q_PROPERTY(ItemEditMode editMode READ editMode WRITE setEditMode NOTIFY editModeChanged)
public:
enum ItemEditMode
{
EditNone = 0,
EditName,
EditGradient,
};
Q_ENUM(ItemEditMode);
GradientListModel(QObject *parent = nullptr);
~GradientListModel();
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE;
Qt::ItemFlags flags(const QModelIndex & index) const Q_DECL_OVERRIDE;
bool setData(const QModelIndex & index, const QVariant & value, int role) Q_DECL_OVERRIDE;
QSize iconSize() const;
/**
* \brief Number of gradients
*/
int count() const;
/**
* \brief Remove all gradients
*/
void clear();
/**
* \brief Returns a reference to the first gradient with the given name
* \pre hasGradient(name)
*/
const QLinearGradient& gradient(const QString& name) const;
/**
* \brief Returns a reference to the first gradient with the given name
* \pre hasGradient(name)
*/
QGradientStops gradientStops(const QString& name) const;
/**
* \brief Whether a gradient with the given name exists in the model
*/
bool hasGradient(const QString& name) const;
/**
* \brief Get the gradient at the given index (row)
* \pre 0 <= index < count()
*/
const QLinearGradient& gradient(int index) const;
/**
* \brief Get the gradient stops at the given index (row)
* \pre 0 <= index < count()
*/
QGradientStops gradientStops(int index) const;
/**
* \brief Inserts or updates a gradient
* \returns The index for the new gradient
*/
int setGradient(const QString& name, const QGradient& gradient);
int setGradient(const QString& name, const QGradientStops& gradient);
/**
* \brief Updates the gradient at \p index
*/
bool setGradient(int index, const QGradient& gradient);
bool setGradient(int index, const QGradientStops& gradient);
/**
* \brief Renames the gradient at \p index
* \returns \b true on success
*/
bool rename(int index, const QString& new_name);
/**
* \brief Renames a gradient
* \returns \b true on success
*/
bool rename(const QString& old_name, const QString& new_name);
/**
* \brief Remove a gradient from the model
* \returns \b true if the gradient has been successfully removed
*/
bool removeGradient(const QString& name);
bool removeGradient(int index);
/**
* \brief The index of the gradient with the given name
* \returns -1 if none is found
*/
int indexFromName(const QString& name) const;
/**
* \brief Name of the gradient at index
*/
QString nameFromIndex(int index) const;
ItemEditMode editMode() const;
/**
* \brief Brush for a gradient
* \pre 0 <= \p index < count()
*/
QBrush gradientBrush(int index) const;
public Q_SLOTS:
void setIconSize(const QSize& iconSize);
void setEditMode(ItemEditMode mode);
Q_SIGNALS:
void iconSizeChanged(const QSize& iconSize);
void editModeChanged(ItemEditMode mode);
private:
class Private;
std::unique_ptr<Private> d;
};
} // namespace color_widgets
#endif // COLOR_WIDGETS_GRADIENT_LIST_MODEL_HPP

View File

@@ -0,0 +1,117 @@
/**
* \file gradient_slider.hpp
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
* \copyright Copyright (C) 2014 Calle Laakkonen
* \copyright Copyright (C) 2017 caryoscelus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef GRADIENT_SLIDER_HPP
#define GRADIENT_SLIDER_HPP
#include "colorwidgets_global.hpp"
#include <QSlider>
#include <QGradient>
namespace color_widgets {
/**
* \brief A slider that moves on top of a gradient
*/
class QCP_EXPORT GradientSlider : public QSlider
{
Q_OBJECT
Q_PROPERTY(QBrush background READ background WRITE setBackground NOTIFY backgroundChanged)
Q_PROPERTY(QGradientStops colors READ colors WRITE setColors DESIGNABLE false)
Q_PROPERTY(QColor firstColor READ firstColor WRITE setFirstColor STORED false)
Q_PROPERTY(QColor lastColor READ lastColor WRITE setLastColor STORED false)
Q_PROPERTY(QLinearGradient gradient READ gradient WRITE setGradient)
public:
explicit GradientSlider(QWidget *parent = 0);
explicit GradientSlider(Qt::Orientation orientation, QWidget *parent = 0);
~GradientSlider();
/// Get the background, it's visible for transparent gradient stops
QBrush background() const;
/// Set the background, it's visible for transparent gradient stops
void setBackground(const QBrush &bg);
/// Get the colors that make up the gradient
QGradientStops colors() const;
/// Set the colors that make up the gradient
void setColors(const QGradientStops &colors);
/// Get the gradient
QLinearGradient gradient() const;
/// Set the gradient
void setGradient(const QLinearGradient &gradient);
/**
* Overload: create an evenly distributed gradient of the given colors
*/
void setColors(const QVector<QColor> &colors);
/**
* \brief Set the first color of the gradient
*
* If the gradient is currently empty it will create a stop with the given color
*/
void setFirstColor(const QColor &c);
/**
* \brief Set the last color of the gradient
*
* If the gradient is has less than two colors,
* it will create a stop with the given color
*/
void setLastColor(const QColor &c);
/**
* \brief Get the first color
*
* \returns QColor() con empty gradient
*/
QColor firstColor() const;
/**
* \brief Get the last color
*
* \returns QColor() con empty gradient
*/
QColor lastColor() const;
Q_SIGNALS:
void backgroundChanged(const QBrush&);
protected:
void paintEvent(QPaintEvent *ev) override;
void mousePressEvent(QMouseEvent *ev) override;
void mouseMoveEvent(QMouseEvent *ev) override;
void mouseReleaseEvent(QMouseEvent *ev) override;
private:
class Private;
Private * const p;
};
} // namespace color_widgets
#endif // GRADIENT_SLIDER_HPP

View File

@@ -0,0 +1,95 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
* \copyright Copyright (C) 2017 caryoscelus
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef HARMONY_COLOR_WHEEL_HPP
#define HARMONY_COLOR_WHEEL_HPP
#include "color_wheel.hpp"
namespace color_widgets {
/**
* \brief ColorWheel with color harmonies
*/
class QCP_EXPORT HarmonyColorWheel : public ColorWheel
{
Q_OBJECT
public:
explicit HarmonyColorWheel(QWidget *parent = 0);
~HarmonyColorWheel();
/// Get all harmony colors (including main)
QList<QColor> harmonyColors() const;
/// Get number of harmony colors (including main)
unsigned int harmonyCount() const;
/// Clear harmony color scheme
void clearHarmonies();
/**
* @brief Add harmony color
* @param hue_diff Initial hue difference (in [0-1) range)
* @param editable Whether this harmony should be editable
* @returns Index of newly added harmony
*/
unsigned addHarmony(double hue_diff, bool editable);
/**
* @brief Add symmetric harmony color
* @param relative_to Index of other harmony that should be symmetric relative to main hue
* @returns Index of newly added harmony
* Editability is inherited from symmetric editor
*/
unsigned addSymmetricHarmony(unsigned relative_to);
/**
* @brief Add opposite harmony color
* @param relative_to Index of other harmony that should be opposite to this
* @returns Index of newly added harmony
* Editability is inherited from opposite editor
*/
unsigned addOppositeHarmony(unsigned relative_to);
Q_SIGNALS:
/**
* Emitted when harmony settings or harmony colors are changed (including due to main hue change)
*/
void harmonyChanged();
protected:
void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;
void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE;
private:
class Private;
Private * p;
};
} // namespace color_widgets
#endif // COLOR_WHEEL_HPP

View File

@@ -0,0 +1,100 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2014 Calle Laakkonen
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef HUE_SLIDER_HPP
#define HUE_SLIDER_HPP
#include "gradient_slider.hpp"
namespace color_widgets {
/**
* \brief A slider for selecting a hue value
*/
class QCP_EXPORT HueSlider : public GradientSlider
{
Q_OBJECT
/**
* \brief Saturation used in the rainbow gradient, as a [0-1] float
*/
Q_PROPERTY(qreal colorSaturation READ colorSaturation WRITE setColorSaturation NOTIFY colorSaturationChanged)
/**
* \brief Value used in the rainbow gradient, as a [0-1] float
*/
Q_PROPERTY(qreal colorValue READ colorValue WRITE setColorValue NOTIFY colorValueChanged)
/**
* \brief Alpha used in the rainbow gradient, as a [0-1] float
*/
Q_PROPERTY(qreal colorAlpha READ colorAlpha WRITE setColorAlpha NOTIFY colorAlphaChanged)
/**
* \brief Color with corresponding color* components
*/
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
/**
* \brief Normalized Hue, as indicated from the slider
*/
Q_PROPERTY(qreal colorHue READ colorHue WRITE setColorHue NOTIFY colorHueChanged)
public:
explicit HueSlider(QWidget *parent = nullptr);
explicit HueSlider(Qt::Orientation orientation, QWidget *parent = nullptr);
~HueSlider();
qreal colorSaturation() const;
qreal colorValue() const;
qreal colorAlpha() const;
QColor color() const;
qreal colorHue() const;
public Q_SLOTS:
void setColorValue(qreal value);
void setColorSaturation(qreal value);
void setColorAlpha(qreal alpha);
void setColorHue(qreal colorHue);
/**
* \brief Set Hue Saturation and ColorValue, ignoring alpha
*/
void setColor(const QColor& color);
/**
* \brief Set Hue Saturation, ColorValue and Alpha
*/
void setFullColor(const QColor& color);
Q_SIGNALS:
void colorHueChanged(qreal colorHue);
void colorChanged(QColor);
void colorAlphaChanged(qreal v);
void colorSaturationChanged(qreal v);
void colorValueChanged(qreal v);
private:
class Private;
Private * const p;
};
} // namespace color_widgets
#endif // HUE_SLIDER_HPP

View File

@@ -0,0 +1,214 @@
/**
* \file
*
* \author Mattia Basaglia
*
* \copyright Copyright (C) 2013-2020 Mattia Basaglia
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COLOR_WIDGETS_SWATCH_HPP
#define COLOR_WIDGETS_SWATCH_HPP
#include <QWidget>
#include <QPen>
#include "color_palette.hpp"
namespace color_widgets {
/**
* \brief A widget drawing a palette
*/
class QCP_EXPORT Swatch : public QWidget
{
Q_OBJECT
/**
* \brief Palette shown by the widget
*/
Q_PROPERTY(const ColorPalette& palette READ palette WRITE setPalette NOTIFY paletteChanged)
/**
* \brief Currently selected color (-1 if no color is selected)
*/
Q_PROPERTY(int selected READ selected WRITE setSelected NOTIFY selectedChanged)
/**
* \brief Preferred size for a color square
*/
Q_PROPERTY(QSize colorSize READ colorSize WRITE setColorSize NOTIFY colorSizeChanged)
Q_PROPERTY(ColorSizePolicy colorSizePolicy READ colorSizePolicy WRITE setColorSizePolicy NOTIFY colorSizePolicyChanged)
/**
* \brief Border around the colors
*/
Q_PROPERTY(QPen border READ border WRITE setBorder NOTIFY borderChanged)
/**
* \brief Forces the Swatch to display that many rows of colors
*
* If there are too few elements, the widget will display less than this
* many rows.
*
* A value of0 means that the number of rows is automatic.
*
* \note Conflicts with forcedColumns
*/
Q_PROPERTY(int forcedRows READ forcedRows WRITE setForcedRows NOTIFY forcedRowsChanged)
/**
* \brief Forces the Swatch to display that many columns of colors
*
* If there are too few elements, the widget will display less than this
* many columns.
*
* A value of 0 means that the number of columns is automatic.
*
* \note Conflicts with forcedRows
*/
Q_PROPERTY(int forcedColumns READ forcedColumns WRITE setForcedColumns NOTIFY forcedColumnsChanged)
/**
* \brief Whether the palette can be modified via user interaction
* \note Even when this is \b false, it can still be altered programmatically
*/
Q_PROPERTY(bool readOnly READ readOnly WRITE setReadOnly NOTIFY readOnlyChanged)
/**
* \brief Maximum size a color square can have
*/
Q_PROPERTY(QSize maxColorSize READ maxColorSize WRITE setMaxColorSize NOTIFY maxColorSizeChanged)
/**
* \brief Whether to show an extra color to perform a "clear" operation.
*
* Clicking on this extra pseudo-color will emit signals like clicked() etc with an index of -1.
*/
Q_PROPERTY(bool showClearColor READ showClearColor WRITE setShowClearColor NOTIFY showClearColorChanged)
public:
enum ColorSizePolicy
{
Hint, ///< The size is just a hint
Minimum, ///< Can expand but not contract
Fixed ///< Must be exactly as specified
};
Q_ENUMS(ColorSizePolicy)
Swatch(QWidget* parent = 0);
~Swatch();
QSize sizeHint() const Q_DECL_OVERRIDE;
QSize minimumSizeHint() const Q_DECL_OVERRIDE;
const ColorPalette& palette() const;
ColorPalette& palette();
int selected() const;
/**
* \brief Color at the currently selected index
*/
QColor selectedColor() const;
/**
* \brief Color index at the given position within the widget
* \param p Point in local coordinates
* \returns -1 if the position doesn't represent any color
*/
int indexAt(const QPoint& p);
/**
* \brief Color at the given position within the widget
* \param p Point in local coordinates
*/
QColor colorAt(const QPoint& p);
QSize colorSize() const;
QSize maxColorSize() const;
ColorSizePolicy colorSizePolicy() const;
QPen border() const;
int forcedRows() const;
int forcedColumns() const;
bool readOnly() const;
bool showClearColor() const;
public Q_SLOTS:
void setPalette(const ColorPalette& palette);
void setSelected(int selected);
void clearSelection();
void setColorSize(const QSize& colorSize);
void setMaxColorSize(const QSize& colorSize);
void setColorSizePolicy(ColorSizePolicy colorSizePolicy);
void setBorder(const QPen& border);
void setForcedRows(int forcedRows);
void setForcedColumns(int forcedColumns);
void setReadOnly(bool readOnly);
/**
* \brief Remove the currently seleceted color
**/
void removeSelected();
void setShowClearColor(bool show);
Q_SIGNALS:
void paletteChanged(const ColorPalette& palette);
void selectedChanged(int selected);
void colorSelected(const QColor& color);
void colorSizeChanged(const QSize& colorSize);
void maxColorSizeChanged(const QSize& colorSize);
void colorSizePolicyChanged(ColorSizePolicy colorSizePolicy);
void doubleClicked(int index, Qt::KeyboardModifiers modifiers);
void rightClicked(int index, Qt::KeyboardModifiers modifiers);
void clicked(int index, Qt::KeyboardModifiers modifiers);
void forcedRowsChanged(int forcedRows);
void forcedColumnsChanged(int forcedColumns);
void readOnlyChanged(bool readOnly);
void borderChanged(const QPen& border);
void showClearColorChanged(bool show);
protected:
bool event(QEvent* event) Q_DECL_OVERRIDE;
void paintEvent(QPaintEvent* event) Q_DECL_OVERRIDE;
void keyPressEvent(QKeyEvent* event) Q_DECL_OVERRIDE;
void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void mouseDoubleClickEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
void wheelEvent(QWheelEvent* event) Q_DECL_OVERRIDE;
void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
void dragMoveEvent(QDragMoveEvent* event) Q_DECL_OVERRIDE;
void dragLeaveEvent(QDragLeaveEvent *event) Q_DECL_OVERRIDE;
void dropEvent(QDropEvent* event) Q_DECL_OVERRIDE;
protected Q_SLOTS:
/**
* \brief Connected to the internal palette object to keep eveything consistent
*/
void paletteModified();
private:
class Private;
Private* p;
};
} // namespace color_widgets
#endif // COLOR_WIDGETS_SWATCH_HPP

99
external/Qt-Color-Widgets/refactor.sh vendored Executable file
View File

@@ -0,0 +1,99 @@
#!/bin/bash
#
# Copyright (C) 2013-2020 Mattia Basaglia
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
################################################################################
# This script is to refactor the old class names to the new ones #
# eg: occurrences of Color_Dialog become color_widgets::ColorDialog #
# This script does very simple text replacements and overwrites existing files #
# Use with care #
# Usage: #
# ./refactor.sh /path/to/sources #
# #
################################################################################
old_classes=(
Color_Delegate
Color_Dialog
Color_List_Widget
Color_Preview
Color_Selector
Color_Wheel
Gradient_Slider
Hue_Slider
)
old_enums=(
Button_Mode
Display_Mode
Update_Mode
Display_Enum
Display_Flags
)
file_extensions=(
ui
cpp
hpp
C
H
h
cxx
hxx
)
function new_class_name()
{
echo "$1" | sed -e 's/_//g' -r -e 's/^/color_widgets::/'
}
function new_enum_name()
{
echo "$1" | sed -e 's/_//g'
}
directory="$1"
if [ -z "$directory" ]
then
echo "Usage: $0 (directory)"
exit 1
fi
find_extensions=""
for ext in ${file_extensions[@]}
do
find_extensions="$find_extensions -o -name '*.$ext'"
done
find_extensions="$(echo "$find_extensions" | sed -r 's/ -o //')"
find_command="find \""$directory"\" -type f -a \( $find_extensions \) -print"
files="$(bash -c "$find_command")"
replacements=""
for class in ${old_classes[@]}
do
replacements="$replacements $class $(new_class_name $class)"
done
for enum in ${old_enums[@]}
do
replacements="$replacements $enum $(new_enum_name $enum)"
done
for file in $files
do
replace $replacements -- "$file"
done

Some files were not shown because too many files have changed in this diff Show More