From 5bb0235b3388a99e568de7a12bcd396548fd039b Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Thu, 2 Jun 2022 21:21:51 +0200 Subject: [PATCH] added QIcon-generating functions to jkqtcommon --- lib/jkqtcommon/CMakeLists.txt | 3 + lib/jkqtcommon/jkqtpicons.cpp | 112 ++++++++++++++++++++++++++++++++++ lib/jkqtcommon/jkqtpicons.h | 60 ++++++++++++++++++ 3 files changed, 175 insertions(+) create mode 100644 lib/jkqtcommon/jkqtpicons.cpp create mode 100644 lib/jkqtcommon/jkqtpicons.h diff --git a/lib/jkqtcommon/CMakeLists.txt b/lib/jkqtcommon/CMakeLists.txt index acdc3044e2..7187532fb5 100644 --- a/lib/jkqtcommon/CMakeLists.txt +++ b/lib/jkqtcommon/CMakeLists.txt @@ -41,6 +41,7 @@ set(SOURCES ${CMAKE_CURRENT_LIST_DIR}/jkqtpstatregression.cpp ${CMAKE_CURRENT_LIST_DIR}/jkqtpstatpoly.cpp ${CMAKE_CURRENT_LIST_DIR}/jkqtpstatgrouped.cpp + ${CMAKE_CURRENT_LIST_DIR}/jkqtpicons.cpp ) set(HEADERS @@ -88,6 +89,8 @@ set(HEADERS $ $ $ + $ + $ ) include(CMakePackageConfigHelpers) diff --git a/lib/jkqtcommon/jkqtpicons.cpp b/lib/jkqtcommon/jkqtpicons.cpp new file mode 100644 index 0000000000..074951e01f --- /dev/null +++ b/lib/jkqtcommon/jkqtpicons.cpp @@ -0,0 +1,112 @@ +/* + Copyright (c) 2008-2022 Jan W. Krieger () + + last modification: $LastChangedDate$ (revision $Rev$) + + This software is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License (LGPL) as published by + the Free Software Foundation, either version 2.1 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 (LGPL) for more details. + + You should have received a copy of the GNU Lesser General Public License (LGPL) + along with this program. If not, see . +*/ + + +#include "jkqtpicons.h" + +#include +#include +#include +#include + +QIcon jkqtp_makeQBrushStyleIcon(Qt::BrushStyle style) { + QPixmap icon(22,22); + icon.fill(Qt::lightGray); + { + QPainter p; + p.begin(&icon); + p.setRenderHint(QPainter::Antialiasing); + p.setRenderHint(QPainter::TextAntialiasing); + p.fillRect(0,0,icon.width(),icon.height(),QBrush(Qt::darkGray, style)); + p.end(); + + } + return QIcon(icon); +} + +QIcon jkqtp_makeQColorIcon(QColor style) { + QPixmap icon(22,22); + icon.fill(Qt::white); + { + QPainter p; + p.begin(&icon); + p.setRenderHint(QPainter::Antialiasing); + p.setRenderHint(QPainter::TextAntialiasing); + p.fillRect(0,0,icon.width()/2,icon.height()/2,QBrush(QColor("black"), Qt::SolidPattern)); + p.fillRect(icon.width()/2+1,icon.height()/2+1,icon.width(),icon.height(),QBrush(QColor("black"), Qt::SolidPattern)); + p.setPen(QPen(Qt::NoPen)); + p.setBrush(QBrush(style, Qt::SolidPattern)); + p.drawEllipse(QRectF(1,1,icon.width()-2,icon.height()-2)); + p.end(); + + } + return QIcon(icon); +} + +QIcon jkqtp_makeQPenStyleIcon(Qt::PenStyle style) { + QPixmap icon(22,22); + icon.fill(Qt::white); + { + QPainter p; + p.begin(&icon); + p.setRenderHint(QPainter::Antialiasing); + p.setRenderHint(QPainter::TextAntialiasing); + p.setPen(QPen(QColor(Qt::black), 1, style)); + p.drawLine(0,icon.height()/2,icon.width(),icon.height()/2); + p.end(); + + } + return QIcon(icon); +} + +QIcon JKQTPLineDecoratorStyle2Icon(JKQTPLineDecoratorStyle style) +{ + QPixmap icon(22,22); + icon.fill(Qt::white); + { + QPainter p; + p.begin(&icon); + p.setRenderHint(QPainter::Antialiasing); + p.setRenderHint(QPainter::TextAntialiasing); + p.setPen(QPen(QColor(Qt::black), 1, Qt::SolidLine)); + p.setBrush(QBrush(QColor("silver"), Qt::SolidPattern)); + p.drawLine(2,icon.height()/2,icon.width(),icon.height()/2); + JKQTPPlotLineDecorator(p, 2, icon.height()/2, 0, style, 12); + p.end(); + + } + return QIcon(icon); +} + +QIcon JKQTPGraphSymbols2Icon(JKQTPGraphSymbols style) +{ + QPixmap icon(22,22); + icon.fill(Qt::white); + { + QPainter p; + p.begin(&icon); + p.setRenderHint(QPainter::Antialiasing); + p.setRenderHint(QPainter::TextAntialiasing); + p.setPen(QPen(QColor(Qt::black), 1, Qt::SolidLine)); + JKQTPPlotSymbol(p, icon.width()/2, icon.height()/2, style, 15, 1, QColor("black"), QColor("silver")); + p.end(); + + } + return QIcon(icon); +} diff --git a/lib/jkqtcommon/jkqtpicons.h b/lib/jkqtcommon/jkqtpicons.h new file mode 100644 index 0000000000..7dadf0fbfb --- /dev/null +++ b/lib/jkqtcommon/jkqtpicons.h @@ -0,0 +1,60 @@ +/* + Copyright (c) 2008-2022 Jan W. Krieger () + + last modification: $LastChangedDate$ (revision $Rev$) + + This software is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License (LGPL) as published by + the Free Software Foundation, either version 2.1 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 (LGPL) for more details. + + You should have received a copy of the GNU Lesser General Public License (LGPL) + along with this program. If not, see . +*/ + + + + + +#ifndef JKQTPICONS_H +#define JKQTPICONS_H + +#include "jkqtcommon/jkqtcommon_imexport.h" +#include +#include +#include +#include +#include "jkqtcommon/jkqtpdrawingtools.h" + +/** \brief make a QIcon representing a QColor + * \ingroup tools + */ +JKQTCOMMON_LIB_EXPORT QIcon jkqtp_makeQColorIcon(QColor style); + +/** \brief make a QIcon representing a Qt::BrushStyle + * \ingroup tools + */ +JKQTCOMMON_LIB_EXPORT QIcon jkqtp_makeQBrushStyleIcon(Qt::BrushStyle style); + + +/** \brief make a QIcon representing a Qt::PenStyle + * \ingroup tools + */ +JKQTCOMMON_LIB_EXPORT QIcon jkqtp_makeQPenStyleIcon(Qt::PenStyle style); + +/** \brief make a QIcon representing a JKQTPLineDecoratorStyle + * \ingroup tools + */ +JKQTCOMMON_LIB_EXPORT QIcon JKQTPLineDecoratorStyle2Icon(JKQTPLineDecoratorStyle style); + +/** \brief make a QIcon representing a JKQTPGraphSymbols + * \ingroup tools + */ +JKQTCOMMON_LIB_EXPORT QIcon JKQTPGraphSymbols2Icon(JKQTPGraphSymbols style); + +#endif // JKQTPICONS_H