pax_global_header00006660000000000000000000000064142236456120014517gustar00rootroot0000000000000052 comment=15e16374e51153006d3400cb88066d5272698743 kColorPicker-0.2.0/000077500000000000000000000000001422364561200141055ustar00rootroot00000000000000kColorPicker-0.2.0/.github/000077500000000000000000000000001422364561200154455ustar00rootroot00000000000000kColorPicker-0.2.0/.github/FUNDING.yml000066400000000000000000000002401422364561200172560ustar00rootroot00000000000000# These are supported funding model platforms github: DamirPorobic liberapay: dporobic patreon: dporobic open_collective: ksnip custom: paypal.me/damirporobic kColorPicker-0.2.0/.github/workflows/000077500000000000000000000000001422364561200175025ustar00rootroot00000000000000kColorPicker-0.2.0/.github/workflows/build.yml000066400000000000000000000012061422364561200213230ustar00rootroot00000000000000name: Build on: push: branches: [ master ] pull_request: branches: [ master ] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Install Qt uses: jurplel/install-qt-action@v2 with: version: '5.15.2' host: 'linux' install-deps: 'true' - name: Install dependencies run: sudo apt-get install xvfb - name: Build run: | mkdir build && cd build cmake .. -DBUILD_TESTS=ON && make VERBOSE=1 - name: Test working-directory: ${{github.workspace}}/build run: xvfb-run make test CTEST_OUTPUT_ON_FAILURE=1 kColorPicker-0.2.0/.gitignore000066400000000000000000000012061422364561200160740ustar00rootroot00000000000000# C++ objects and libs *.slo *.lo *.o *.a *.la *.lai *.so *.dll *.dylib # Qt-es /.qmake.cache /.qmake.stash *.pro.user *.pro.user.* *.qbs.user *.qbs.user.* *.moc moc_*.cpp qrc_*.cpp ui_*.h Makefile* *build-* # QtCreator *.autosave # QtCtreator Qml *.qmlproject.user *.qmlproject.user.* # QtCtreator CMake CMakeLists.txt.user # kdevelop apidocs .kdev4 build *~ *.kdev4 *.bak *.orig *.rej doxygen.log Doxyfile *.kdevelop *.kdevelop.filelist *.kdevelop.pcs *.kdevses .*kate-swp build/ mem.log.* massif.* callgrind.* perf.data* # from kdiff3 *.BACKUP.* *.BASE.* *.LOCAL.* *.REMOTE.* # visual studio code *.vscode/ *.vs # clion *.idea *.idea/kColorPicker-0.2.0/CMakeLists.txt000066400000000000000000000066561422364561200166620ustar00rootroot00000000000000cmake_minimum_required(VERSION 3.5) project(kColorPicker LANGUAGES CXX VERSION 0.2.0) set(QT_MIN_VERSION "5.9.4") set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) option(BUILD_TESTS "Build Unit Tests" OFF) option(BUILD_EXAMPLE "Build Example Application" ON) find_package(Qt5 ${QT_MIN_VERSION} REQUIRED Widgets) include(GNUInstallDirs) include(FeatureSummary) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory(src) if (BUILD_EXAMPLE) add_subdirectory(example) endif (BUILD_EXAMPLE) if (BUILD_TESTS) find_package(Qt5 ${QT_MIN_VERSION} REQUIRED Test) enable_testing() add_subdirectory(tests) endif (BUILD_TESTS) include(CMakePackageConfigHelpers) add_library(kColorPicker ${KCOLORPICKER_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/include/kColorPicker/KColorPicker.h ${CMAKE_CURRENT_SOURCE_DIR}/icons/kColorPicker_icons.qrc ) add_library(kColorPicker::kColorPicker ALIAS kColorPicker) target_include_directories(kColorPicker PUBLIC $ $ $ ) target_link_libraries(kColorPicker PUBLIC Qt5::Widgets) target_compile_definitions(kColorPicker PRIVATE KIMAGEANNOTATOR_LIB) set_target_properties(kColorPicker PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin VERSION ${PROJECT_VERSION} SOVERSION 0 ) install(TARGETS kColorPicker EXPORT kColorPicker-targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/kColorPicker DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/kColorPickerConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/cmake/kColorPickerConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kColorPicker ) write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/cmake/kColorPickerConfig-version.cmake VERSION ${PROJECT_VERSION} COMPATIBILITY AnyNewerVersion ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/kColorPickerConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/cmake/kColorPickerConfig-version.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kColorPicker ) export(EXPORT kColorPicker-targets FILE ${CMAKE_CURRENT_BINARY_DIR}/cmake/kColorPicker-targets.cmake NAMESPACE kColorPicker:: ) install(EXPORT kColorPicker-targets FILE kColorPicker-targets.cmake NAMESPACE kColorPicker:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/kColorPicker ) # uninstall target if(NOT TARGET uninstall) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) endif() kColorPicker-0.2.0/LICENSE000066400000000000000000000167441422364561200151260ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. kColorPicker-0.2.0/README.md000066400000000000000000000030251422364561200153640ustar00rootroot00000000000000# kColorPicker [![Build Status][github-badge]][github-url] QToolButton with color popup menu with lets you select a color. The popup features a color dialog button which can be used to add custom colors to the popup menu. Version 0.2.0 ![kColorPicker](https://i.imgur.com/VkhUvFa.png "kColorPicker") ### Building from source 1. Get the latest release from GitHub by cloning the repo: `$ git clone https://github.com/ksnip/kColorPicker` 2. Change to repo directory: `$ cd kColorPicker` 3. Make new build directory and enter it: `$ mkdir build && cd build` 4. Create the makefile and build the project: `$ cmake .. && make` 5. Install shared library (not required when only using the example): `$ sudo make install` 6. Run the example application: `$ ./example/kColorPicker-example` ### Shared vs Static You can either build the project as shared library by providing the flag `-DBUILD_SHARED_LIBS=ON` to cmake or `-DBUILD_SHARED_LIBS=OFF` to build as static library. On Windows we currently can only build as static library. ### Integrate library in project 1. Let cmake find the shared library, optionally with version `set(KCOLORPICKER_MIN_VERSION "0.x.x")` `find_package(kColorPicker ${KCOLORPICKER_MIN_VERSION} REQUIRED)` 2. Link the library with your application `target_link_libraries(myApp kColorPicker)` [github-badge]: https://github.com/ksnip/kColorPicker/actions/workflows/build.yml/badge.svg [github-url]: https://github.com/ksnip/kColorPicker/actionskColorPicker-0.2.0/cmake/000077500000000000000000000000001422364561200151655ustar00rootroot00000000000000kColorPicker-0.2.0/cmake/cmake_uninstall.cmake.in000066400000000000000000000017551422364561200217550ustar00rootroot00000000000000if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt") endif(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) string(REGEX REPLACE "\n" ";" files "${files}") foreach(file ${files}) message(STATUS "Uninstalling $ENV{DESTDIR}${file}") if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") exec_program( "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" OUTPUT_VARIABLE rm_out RETURN_VALUE rm_retval ) if(NOT "${rm_retval}" STREQUAL 0) message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") endif(NOT "${rm_retval}" STREQUAL 0) else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") message(STATUS "File $ENV{DESTDIR}${file} does not exist.") endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") endforeach(file) kColorPicker-0.2.0/cmake/kColorPickerConfig.cmake.in000066400000000000000000000003401422364561200223060ustar00rootroot00000000000000include(CMakeFindDependencyMacro) @PACKAGE_INIT@ find_dependency(Qt5 @QT_MIN_VERSION@ COMPONENTS Widgets) if(NOT TARGET kColorPicker::kColorPicker) include("${CMAKE_CURRENT_LIST_DIR}/kColorPicker-targets.cmake") endif()kColorPicker-0.2.0/example/000077500000000000000000000000001422364561200155405ustar00rootroot00000000000000kColorPicker-0.2.0/example/CMakeLists.txt000066400000000000000000000001471422364561200203020ustar00rootroot00000000000000add_executable(kColorPicker-example main.cpp) target_link_libraries(kColorPicker-example kColorPicker)kColorPicker-0.2.0/example/main.cpp000066400000000000000000000024661422364561200172000ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * 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 2 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 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include #include #include using kColorPicker::KColorPicker; int main(int argc, char **argv) { QApplication app(argc, argv); auto widget = new QWidget(); widget->setFixedWidth(200); widget->setFixedHeight(200); auto layout = new QVBoxLayout(); auto colorPicker = new KColorPicker(true); colorPicker->setColor(QColor(Qt::red)); layout->addWidget(colorPicker); widget->setLayout(layout); widget->show(); return app.exec(); }kColorPicker-0.2.0/icons/000077500000000000000000000000001422364561200152205ustar00rootroot00000000000000kColorPicker-0.2.0/icons/ellipsis.64.png000066400000000000000000000017571422364561200200140ustar00rootroot00000000000000PNG  IHDR@@iq pHYs u N{MIDATxMoTsϕ=%2fE!*7P.ؠ""h{*?Ю,/"H0ĤcmՕz3Ws{g2\\f4, n e] nMefYfErw2(@1>sQo\jpA9  f̥jA5 @0@7c.5W sA ZG l(nFUHc`Z{/(Tb76667}&w1?ƘE$S$iWiFccJȍ14MӨkOg"2 q^gaU39l6NTQ[ׁ_s`6|E_' rx/O.7/3`eۄρ\U+>٢z6ޙÁ N& _jGfwW>i ?LFQzYUaeǦMfkf٦cȣ(zXcsPg}9'IY7ZƘ Zꋞf_6tjOB۩-yiMWu>Wսzi߫ c{=Tө ellipsis.64.png kColorPicker-0.2.0/include/000077500000000000000000000000001422364561200155305ustar00rootroot00000000000000kColorPicker-0.2.0/include/kColorPicker/000077500000000000000000000000001422364561200201175ustar00rootroot00000000000000kColorPicker-0.2.0/include/kColorPicker/KColorPicker.h000066400000000000000000000033541422364561200226240ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * 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 2 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 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KCOLORPICKER_KCOLORPICKER_H #define KCOLORPICKER_KCOLORPICKER_H #include #include #include #include namespace kColorPicker { class KColorPickerPrivate; class KCOLORPICKER_EXPORT KColorPicker : public QToolButton { Q_OBJECT Q_DECLARE_PRIVATE(KColorPicker) public: explicit KColorPicker(bool showAlphaChannel = false, QWidget *parent = nullptr); ~KColorPicker() override; void setFixedSize(const QSize &size); void setFixedSize(int width, int height); QColor color() const; void resetColors(bool showAlphaChannel = false); public Q_SLOTS: void setColor(const QColor &color); Q_SIGNALS: void colorChanged(const QColor &color) const; private: QScopedPointer const d_ptr; private Q_SLOTS: void setColorIcon(const QColor &color); void setIconSize(const QSize &size); void colorSelected(const QColor &color); }; } #endif //KCOLORPICKER_KCOLORPICKER_H kColorPicker-0.2.0/include/kColorPicker/KColorPickerExport.h000066400000000000000000000022201422364561200240150ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * 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 2 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 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KCOLORPICKER_KCOLORPICKEREXPORT_H #define KCOLORPICKER_KCOLORPICKEREXPORT_H #include #if defined(_WIN32) # define KCOLORPICKER_EXPORT #else #if defined(KCOLORPICKER_LIB) # define KCOLORPICKER_EXPORT Q_DECL_EXPORT #else # define KCOLORPICKER_EXPORT Q_DECL_IMPORT #endif #endif #endif //KCOLORPICKER_KCOLORPICKEREXPORT_H kColorPicker-0.2.0/src/000077500000000000000000000000001422364561200146745ustar00rootroot00000000000000kColorPicker-0.2.0/src/CMakeLists.txt000066400000000000000000000007761422364561200174460ustar00rootroot00000000000000set(KCOLORPICKER_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/KColorPicker.cpp ${CMAKE_CURRENT_SOURCE_DIR}/PopupMenu.cpp ${CMAKE_CURRENT_SOURCE_DIR}/IconCreator.cpp ${CMAKE_CURRENT_SOURCE_DIR}/buttons/AbstractPopupMenuButton.cpp ${CMAKE_CURRENT_SOURCE_DIR}/buttons/ColorButton.cpp ${CMAKE_CURRENT_SOURCE_DIR}/buttons/ColorDialogButton.cpp ${CMAKE_CURRENT_SOURCE_DIR}/common/ScaledSizeProvider.cpp ) set(KCOLORPICKER_SRCS ${KCOLORPICKER_SRCS} PARENT_SCOPE) kColorPicker-0.2.0/src/IconCreator.cpp000066400000000000000000000036441422364561200176170ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * 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 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "IconCreator.h" namespace kColorPicker { QIcon IconCreator::createIcon(const QColor &color, const QSize &size) { auto background = getBackgroundBrush(size); QPixmap pixmap(size); QPainter painter(&pixmap); // Paint background painter.setPen(Qt::NoPen); painter.setBrush(background); painter.drawRect(0, 0, size.width(), size.height()); // Paint color painter.setBrush(color); painter.drawRect(0, 0, size.width(), size.height()); // Paint border auto penWidth = painter.pen().width(); painter.setPen(QColor(Qt::gray)); painter.drawRect(0, 0, size.width() - penWidth, size.height() - penWidth); return { pixmap }; } QImage IconCreator::getBackgroundBrush(const QSize &size) { auto halfWidth = size.width() / 2; auto halfHeight = size.height() / 2; auto background = QImage(size, QImage::Format_ARGB32_Premultiplied); background.fill(Qt::white); QPainter painter(&background); painter.setPen(Qt::NoPen); painter.setBrush(Qt::gray); painter.drawRect(0, 0, halfWidth, halfHeight); painter.drawRect(halfWidth, halfHeight, size.width(), size.height()); return background; } } // namespace kColorPickerkColorPicker-0.2.0/src/IconCreator.h000066400000000000000000000023461422364561200172620ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * 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 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KCOLORPICKER_ICONCREATOR_H #define KCOLORPICKER_ICONCREATOR_H #include #include #include #include namespace kColorPicker { class IconCreator { public: explicit IconCreator() = delete; ~IconCreator() = delete; static QIcon createIcon(const QColor &color, const QSize &size); static QImage getBackgroundBrush(const QSize &size); }; } // namespace kColorPicker #endif //KCOLORPICKER_ICONCREATOR_H kColorPicker-0.2.0/src/KColorPicker.cpp000066400000000000000000000074431422364561200177370ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * 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 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include #include "IconCreator.h" #include "PopupMenu.h" inline void initResource() { Q_INIT_RESOURCE(kColorPicker_icons); } namespace kColorPicker { class KColorPickerPrivate { Q_DISABLE_COPY(KColorPickerPrivate) Q_DECLARE_PUBLIC(KColorPicker) explicit KColorPickerPrivate(KColorPicker *kColorPicker, bool showAlphaChannel = false, QWidget *parent = nullptr); KColorPicker *const q_ptr; QSize mIconSize; PopupMenu *mPopupMenu; QColor mSelectedColor; }; KColorPicker::KColorPicker(bool showAlphaChannel, QWidget *parent) : d_ptr(new KColorPickerPrivate(this, showAlphaChannel, parent)) { // Default Colors resetColors(showAlphaChannel); } KColorPicker::~KColorPicker() {} void KColorPicker::setColor(const QColor &color) { Q_D(KColorPicker); d->mSelectedColor = color; setColorIcon(color); d->mPopupMenu->selectColor(color); } void KColorPicker::colorSelected(const QColor &color) { Q_D(KColorPicker); d->mSelectedColor = color; setColorIcon(color); emit colorChanged(color); } void KColorPicker::setFixedSize(const QSize &size) { Q_D(const KColorPicker); QToolButton::setFixedSize(size); setIconSize(size); setColorIcon(d->mSelectedColor); } void KColorPicker::setFixedSize(int width, int height) { Q_D(const KColorPicker); QToolButton::setFixedSize(width, height); setIconSize(QSize(width, height)); setColorIcon(d->mSelectedColor); } QColor KColorPicker::color() const { Q_D(const KColorPicker); return d->mSelectedColor; } void KColorPicker::resetColors(bool showAlphaChannel) { Q_D(const KColorPicker); d->mPopupMenu->removeColors(); d->mPopupMenu->addColor(QColor(Qt::red)); d->mPopupMenu->addColor(QColor(Qt::green)); d->mPopupMenu->addColor(QColor(Qt::blue)); d->mPopupMenu->addColor(QColor(Qt::yellow)); d->mPopupMenu->addColor(QColor(Qt::magenta)); d->mPopupMenu->addColor(QColor(Qt::cyan)); d->mPopupMenu->addColor(QColor(Qt::white)); d->mPopupMenu->addColor(QColor(Qt::black)); if(showAlphaChannel) { d->mPopupMenu->addColor(QColor(0, 255, 255, 100)); d->mPopupMenu->addColor(QColor(255, 0, 255, 100)); d->mPopupMenu->addColor(QColor(255, 255, 0, 100)); d->mPopupMenu->addColor(QColor(255, 255, 255, 100)); } } void KColorPicker::setIconSize(const QSize &size) { Q_D(KColorPicker); auto scaleFactor = 0.6; d->mIconSize = size * scaleFactor; QToolButton::setIconSize(d->mIconSize); } void KColorPicker::setColorIcon(const QColor &color) { Q_D(KColorPicker); auto icon = IconCreator::createIcon(color, d->mIconSize); setIcon(icon); setToolTip(color.name()); } // // KColorPickerPrivate // KColorPickerPrivate::KColorPickerPrivate(KColorPicker *kColorPicker, bool showAlphaChannel, QWidget *parent) : q_ptr(kColorPicker), mPopupMenu(new PopupMenu(showAlphaChannel, parent)) { initResource(); mIconSize = QSize(25, 25); kColorPicker->setPopupMode(QToolButton::InstantPopup); kColorPicker->setMenu(mPopupMenu); kColorPicker->connect(mPopupMenu, &PopupMenu::colorChanged, kColorPicker, &KColorPicker::colorSelected); } } // namespace kColorPicker kColorPicker-0.2.0/src/PopupMenu.cpp000066400000000000000000000062411422364561200173330ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * 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 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "PopupMenu.h" namespace kColorPicker { PopupMenu::PopupMenu(bool showAlphaChannel, QWidget *parent) : QMenu(parent), mButtonGroup(new QButtonGroup(this)), mLayout(new QGridLayout(this)), mColorDialogButton(new ColorDialogButton(QIcon(QLatin1String(":/icons/ellipsis")), showAlphaChannel)) { mLayout->setSpacing(0); mLayout->setMargin(5); setLayout(mLayout); connect(mColorDialogButton, &AbstractPopupMenuButton::colorSelected, this, &PopupMenu::colorSelected); } PopupMenu::~PopupMenu() { qDeleteAll(mColorButtons); delete mColorDialogButton; } void PopupMenu::addColor(const QColor &color) { if (!isColorInGrid(color)) { addColorButton(color); } } void PopupMenu::removeColors() { for (auto button : mColorButtons) { mButtonGroup->removeButton(button); mLayout->removeWidget(button); disconnect(button, &AbstractPopupMenuButton::colorSelected, this, &PopupMenu::colorSelected); } qDeleteAll(mColorButtons); mColorButtons.clear(); generateGrid(); } void PopupMenu::selectColor(const QColor &color) { addColor(color); for (auto button : mColorButtons) { if (button->color() == color) { button->setChecked(true); return; } } } void PopupMenu::generateGrid() { auto row = 0; auto column = 0; clearGrid(); for (auto button : mColorButtons) { mLayout->addWidget(button, row, column % 4); column++; if (column % 4 == 0) { row++; } } mLayout->addWidget(mColorDialogButton, row, column % 4); } ColorButton *PopupMenu::createButton(const QColor &color) { auto icon = IconCreator::createIcon(color, ScaledSizeProvider::scaledSize(QSize(25, 25))); auto button = new ColorButton(icon, color); return button; } void PopupMenu::addColorButton(const QColor &color) { auto button = createButton(color); mButtonGroup->addButton(button); mColorButtons.append(button); connect(button, &AbstractPopupMenuButton::colorSelected, this, &PopupMenu::colorSelected); generateGrid(); } void PopupMenu::clearGrid() { for (auto button : mColorButtons) { mLayout->removeWidget(button); } } bool PopupMenu::isColorInGrid(const QColor &color) { for (auto button : mColorButtons) { if (button->color() == color) { return true; } } return false; } void PopupMenu::colorSelected(const QColor &color) { emit colorChanged(color); selectColor(color); hide(); } QSize PopupMenu::sizeHint() const { return mLayout->sizeHint(); } } // namespace kColorPickerkColorPicker-0.2.0/src/PopupMenu.h000066400000000000000000000034301422364561200167750ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * 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 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KCOLORPICKER_POPUPMENU_H #define KCOLORPICKER_POPUPMENU_H #include #include #include #include "IconCreator.h" #include "buttons/ColorButton.h" #include "buttons/ColorDialogButton.h" namespace kColorPicker { class PopupMenu : public QMenu { Q_OBJECT public: PopupMenu(bool showAlphaChannel, QWidget *parent); ~PopupMenu() override; void addColor(const QColor &color); void removeColors(); void selectColor(const QColor &color); QSize sizeHint() const; signals: void colorChanged(const QColor &color) const; private: QButtonGroup *mButtonGroup; QGridLayout *mLayout; QList mColorButtons; ColorDialogButton *mColorDialogButton; void generateGrid(); static ColorButton *createButton(const QColor &color); void addColorButton(const QColor &color); void clearGrid(); bool isColorInGrid(const QColor &color); private slots: void colorSelected(const QColor &color); }; } // namespace kColorPicker #endif //KCOLORPICKER_POPUPMENU_H kColorPicker-0.2.0/src/buttons/000077500000000000000000000000001422364561200163725ustar00rootroot00000000000000kColorPicker-0.2.0/src/buttons/AbstractPopupMenuButton.cpp000066400000000000000000000036171422364561200237150ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * 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 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "AbstractPopupMenuButton.h" namespace kColorPicker { AbstractPopupMenuButton::AbstractPopupMenuButton(const QIcon &icon) : mHoverColor(QColor(QLatin1String("#add8e6"))) { setIcon(icon); setFixedSize(iconSize() + QSize(8, 8)); connect(this, &QToolButton::clicked, this, &AbstractPopupMenuButton::buttonClicked); } void AbstractPopupMenuButton::paintEvent(QPaintEvent *event) { QPainter painter(this); QStyleOption styleOption; styleOption.initFrom(this); auto rect = event->rect(); auto scaleRatio = devicePixelRatioF(); auto buttonRect = QRectF(rect.x() + (2 / scaleRatio), rect.y() + (2 / scaleRatio), rect.width() - 5, rect.height() - 5); if(styleOption.state & QStyle::State_MouseOver) { auto defaultPen = painter.pen(); auto defaultBrush = painter.brush(); painter.setPen(mHoverColor); painter.setBrush(mHoverColor); painter.drawRect(buttonRect); painter.setPen(defaultPen); painter.setBrush(defaultBrush); } painter.drawPixmap(buttonRect.topLeft() + QPointF(2, 2), icon().pixmap(iconSize())); if(isChecked()) { painter.drawRect(buttonRect); } } } // namespace kColorPicker kColorPicker-0.2.0/src/buttons/AbstractPopupMenuButton.h000066400000000000000000000026601422364561200233570ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * 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 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KCOLORPICKER_ABSTRACTPOPUPMENUBUTTON_H #define KCOLORPICKER_ABSTRACTPOPUPMENUBUTTON_H #include #include #include #include #include "src/common/ScaledSizeProvider.h" namespace kColorPicker { class AbstractPopupMenuButton : public QToolButton { Q_OBJECT public: explicit AbstractPopupMenuButton(const QIcon &icon); signals: void colorSelected(const QColor &color) const; protected slots: void paintEvent(QPaintEvent *event) override; virtual void buttonClicked() = 0; private: QColor mHoverColor; }; } // namespace kColorPicker #endif //KCOLORPICKER_ABSTRACTPOPUPMENUBUTTON_H kColorPicker-0.2.0/src/buttons/ColorButton.cpp000066400000000000000000000025151422364561200213530ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * 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 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ColorButton.h" namespace kColorPicker { ColorButton::ColorButton(const QIcon &icon, const QColor &color) : AbstractPopupMenuButton(icon) { setCheckable(true); setToolTip(getColorName(color)); mColor = color; } QColor ColorButton::color() const { return mColor; } void ColorButton::buttonClicked() { emit colorSelected(mColor); } QString ColorButton::getColorName(const QColor &color) { auto format = color.alpha() < 255 ? QColor::HexArgb : QColor::HexRgb; return color.name(format); } } // namespace kColorPickerkColorPicker-0.2.0/src/buttons/ColorButton.h000066400000000000000000000023771422364561200210260ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * 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 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KCOLORPICKER_COLORBUTTON_H #define KCOLORPICKER_COLORBUTTON_H #include "AbstractPopupMenuButton.h" namespace kColorPicker { class ColorButton : public AbstractPopupMenuButton { Q_OBJECT public: ColorButton(const QIcon &icon, const QColor &color); QColor color() const; protected: void buttonClicked() override; private: QColor mColor; static QString getColorName(const QColor &color); }; } // namespace kColorPicker #endif //KCOLORPICKER_COLORBUTTON_H kColorPicker-0.2.0/src/buttons/ColorDialogButton.cpp000066400000000000000000000026371422364561200225000ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * 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 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ColorDialogButton.h" namespace kColorPicker { ColorDialogButton::ColorDialogButton(const QIcon &icon, bool showAlphaChannel) : AbstractPopupMenuButton(icon), mShowAlphaChannel(showAlphaChannel) { setCheckable(false); } void ColorDialogButton::buttonClicked() { auto color = QColorDialog::getColor(Qt::white, this, QString(), getColorDialogOptions()); emit colorSelected(color); } QFlags ColorDialogButton::getColorDialogOptions() const { return mShowAlphaChannel ? QColorDialog::ShowAlphaChannel : QFlags(); } } // namespace kColorPickerkColorPicker-0.2.0/src/buttons/ColorDialogButton.h000066400000000000000000000025071422364561200221410ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * 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 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KCOLORPICKER_COLORDIALOGBUTTON_H #define KCOLORPICKER_COLORDIALOGBUTTON_H #include #include "AbstractPopupMenuButton.h" namespace kColorPicker { class ColorDialogButton : public AbstractPopupMenuButton { Q_OBJECT public: explicit ColorDialogButton(const QIcon &icon, bool showAlphaChannel); protected: void buttonClicked() override; private: bool mShowAlphaChannel; QFlags getColorDialogOptions() const; }; } // namespace kColorPicker #endif //KCOLORPICKER_COLORDIALOGBUTTON_H kColorPicker-0.2.0/src/common/000077500000000000000000000000001422364561200161645ustar00rootroot00000000000000kColorPicker-0.2.0/src/common/ScaledSizeProvider.cpp000066400000000000000000000033351422364561200224350ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * 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 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ScaledSizeProvider.h" namespace kColorPicker { QSize ScaledSizeProvider::scaledSize(const QSize &size) { return size * scaleFactor(); } qreal ScaledSizeProvider::scaleFactor() { static auto scaleFactor = getScaleFactor(); return scaleFactor; } qreal ScaledSizeProvider::getScaleFactor() { #if defined(__linux__) if(isGnomeEnvironment()) { auto screen = QApplication::primaryScreen(); auto logicalDotsPerInch = (int) screen->logicalDotsPerInch(); auto physicalDotsPerInch = (int) screen->physicalDotsPerInch(); return (qreal)logicalDotsPerInch / (qreal)physicalDotsPerInch; } #endif return 1; } #if defined(__linux__) bool ScaledSizeProvider::isGnomeEnvironment() { auto currentDesktop = QString(qgetenv("XDG_CURRENT_DESKTOP")); return currentDesktop.contains(QLatin1String("gnome"), Qt::CaseInsensitive) || currentDesktop.contains(QLatin1String("unity"), Qt::CaseInsensitive); } #endif } // namespace kColorPickerkColorPicker-0.2.0/src/common/ScaledSizeProvider.h000066400000000000000000000025321422364561200221000ustar00rootroot00000000000000/* * Copyright (C) 2021 Damir Porobic * * 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 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KCOLORPICKER_SCALEDSIZEPROVIDER_H #define KCOLORPICKER_SCALEDSIZEPROVIDER_H #include #if defined(__linux__) #include #include #endif namespace kColorPicker { class ScaledSizeProvider { public: static QSize scaledSize(const QSize &size); private: static qreal scaleFactor(); static qreal getScaleFactor(); #if defined(__linux__) static bool isGnomeEnvironment(); #endif ScaledSizeProvider() = default; ~ScaledSizeProvider() = default; }; } // namespace kColorPicker #endif //KCOLORPICKER_SCALEDSIZEPROVIDER_H kColorPicker-0.2.0/tests/000077500000000000000000000000001422364561200152475ustar00rootroot00000000000000kColorPicker-0.2.0/tests/CMakeLists.txt000066400000000000000000000007401422364561200200100ustar00rootroot00000000000000set(UNITTEST_SRC buttons/ColorButtonTest.cpp ) add_library(KCOLORPICKER_STATIC STATIC ${KCOLORPICKER_SRCS}) target_link_libraries(KCOLORPICKER_STATIC Qt5::Widgets kColorPicker) foreach (UnitTest ${UNITTEST_SRC}) get_filename_component(UnitTestName ${UnitTest} NAME_WE) add_executable(${UnitTestName} ${UnitTest}) target_link_libraries(${UnitTestName} KCOLORPICKER_STATIC Qt5::Test) add_test(${UnitTestName} ${UnitTestName}) endforeach (UnitTest)kColorPicker-0.2.0/tests/buttons/000077500000000000000000000000001422364561200167455ustar00rootroot00000000000000kColorPicker-0.2.0/tests/buttons/ColorButtonTest.cpp000066400000000000000000000023151422364561200225640ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * 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 2 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 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "ColorButtonTest.h" void ColorButtonTest::Clicked_Should_EmitColorSelected() { auto color = QColor(Qt::blue); ColorButton colorButton(QIcon(), color); QSignalSpy spy(&colorButton, &ColorButton::colorSelected); colorButton.click(); QCOMPARE(spy.count(), 1); auto selectedColor = qvariant_cast(spy.at(0).at(0)); QCOMPARE(selectedColor, color); } QTEST_MAIN(ColorButtonTest); kColorPicker-0.2.0/tests/buttons/ColorButtonTest.h000066400000000000000000000022771422364561200222400ustar00rootroot00000000000000/* * Copyright (C) 2018 Damir Porobic * * 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 2 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 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, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef KCOLORPICKER_COLORBUTTONTEST_H #define KCOLORPICKER_COLORBUTTONTEST_H #include #include "src/buttons/ColorButton.h" #include "src/common/ScaledSizeProvider.h" using kColorPicker::ColorButton; using kColorPicker::ScaledSizeProvider; class ColorButtonTest : public QObject { Q_OBJECT private slots: void Clicked_Should_EmitColorSelected(); }; #endif // KCOLORPICKER_COLORBUTTONTEST_H