2019-05-30 04:40:02 +08:00
/*
2022-07-19 19:40:43 +08:00
Copyright ( c ) 2008 - 2022 Jan W . Krieger ( < jan @ jkrieger . de > )
2019-05-30 04:40:02 +08:00
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 < http : //www.gnu.org/licenses/>.
*/
# ifndef JKQTPIMAGETOOLS_H
# define JKQTPIMAGETOOLS_H
# include <QIcon>
# include <QDebug>
# include <QImage>
# include <QStringList>
2019-06-22 20:21:32 +08:00
# include "jkqtplotter/jkqtplotter_imexport.h"
2019-05-30 04:40:02 +08:00
# include "jkqtcommon/jkqtpbasicimagetools.h"
2022-07-19 16:24:52 +08:00
# include "jkqtplotter/jkqtplotter_configmacros.h"
2019-05-30 04:40:02 +08:00
# include <cmath>
# include <cfloat>
# include <stdint.h>
# include <QColor>
# include "jkqtplotter/jkqtptools.h"
class JKQTPVerticalIndependentAxis ; // forward
class JKQTPHorizontalIndependentAxis ; // forward
class JKQTBasePlotter ; // forward
2019-08-01 04:10:26 +08:00
2019-05-30 04:40:02 +08:00
/*! \brief if a class is derived from this class, it may use color bars
\ ingroup jkqtplotter_imagelots_tools
*/
2019-06-22 20:21:32 +08:00
class JKQTPLOTTER_LIB_EXPORT JKQTPColorPaletteStyleAndToolsMixin {
2022-07-19 19:40:43 +08:00
# ifndef JKQTPLOTTER_WORKAROUND_QGADGET_BUG
2022-07-19 16:24:52 +08:00
Q_GADGET
# endif
2019-05-30 04:40:02 +08:00
public :
JKQTPColorPaletteStyleAndToolsMixin ( JKQTBasePlotter * parent ) ;
virtual ~ JKQTPColorPaletteStyleAndToolsMixin ( ) ;
2020-09-21 19:47:54 +08:00
/** \brief get list with all available palettes */
2019-05-30 04:40:02 +08:00
static QStringList getPalettes ( ) ;
2020-09-21 19:47:54 +08:00
/** \brief get list with all available palettes */
2019-05-30 04:40:02 +08:00
static int getPalettesCount ( ) ;
2020-09-21 19:47:54 +08:00
/** \brief get QIcon representing the given palette */
2019-05-30 04:40:02 +08:00
static QIcon getPaletteIcon ( int i ) ;
2020-09-21 19:47:54 +08:00
/** \brief get QIcon representing the given palette */
2019-05-30 04:40:02 +08:00
static QIcon getPaletteIcon ( JKQTPMathImageColorPalette palette ) ;
2020-09-21 19:47:54 +08:00
/** \brief get QIcon representing the given palette */
2019-08-01 04:10:26 +08:00
static QImage getPaletteImage ( int i , size_t width ) ;
2020-09-21 19:47:54 +08:00
/** \brief get QIcon representing the given palette */
2019-08-01 04:10:26 +08:00
static QImage getPaletteImage ( JKQTPMathImageColorPalette palette , size_t width ) ;
2019-05-30 04:40:02 +08:00
2020-09-21 19:47:54 +08:00
/** \brief get QIcon representing the given palette */
2019-05-30 04:40:02 +08:00
static QIcon getPaletteKeyIcon ( int i ) ;
2020-09-21 19:47:54 +08:00
/** \brief get QIcon representing the given palette */
2019-05-30 04:40:02 +08:00
static QIcon getPaletteKeyIcon ( JKQTPMathImageColorPalette palette ) ;
2020-09-21 19:47:54 +08:00
/** \brief get QIcon representing the given palette */
2019-08-01 04:10:26 +08:00
static QImage getPaletteKeyImage ( int i , size_t width , size_t height ) ;
2020-09-21 19:47:54 +08:00
/** \brief get QIcon representing the given palette */
2019-08-01 04:10:26 +08:00
static QImage getPaletteKeyImage ( JKQTPMathImageColorPalette palette , size_t width , size_t height ) ;
2019-05-30 04:40:02 +08:00
/*! \brief if the graph plots outside the actual plot field of view (e.g. color bars, scale bars, ...)
\ note If you want to draw outside , then you ' ll also have to implement drawOutside ( )
*/
2019-08-01 04:10:26 +08:00
virtual void cbGetOutsideSize ( JKQTPEnhancedPainter & painter , int & leftSpace , int & rightSpace , int & topSpace , int & bottomSpace ) ;
2019-05-30 04:40:02 +08:00
/*! \brief plots outside the actual plot field of view (e.g. color bars, scale bars, ...)
\ note If you want to draw outside , then you ' ll also have to implement getOutsideSize ( ) , so enough space is reserved
The four value supplied tell the method where to draw ( inside one of the rectangles ) .
*/
2019-08-01 04:10:26 +08:00
virtual void cbDrawOutside ( JKQTPEnhancedPainter & painter , QRect leftSpace , QRect rightSpace , QRect topSpace , QRect bottomSpace ) ;
2019-05-30 04:40:02 +08:00
/** \brief set the parent class for internal objects (e.g. color bars) */
2019-08-01 04:10:26 +08:00
virtual void cbSetParent ( JKQTBasePlotter * parent ) ;
2019-05-30 04:40:02 +08:00
/** \brief determine min/max data value of the image */
virtual void cbGetDataMinMax ( double & imin , double & imax ) = 0 ;
2020-09-21 19:47:54 +08:00
/** \copydoc palette */
2020-09-11 18:14:51 +08:00
void setColorPalette ( int pal ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc palette */
2020-09-11 18:14:51 +08:00
void setColorPalette ( const JKQTPMathImageColorPalette & __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc palette */
2020-09-11 18:14:51 +08:00
JKQTPMathImageColorPalette getColorPalette ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc rangeMinFailAction */
2019-05-30 04:40:02 +08:00
void setRangeMinFailAction ( const JKQTPMathImageColorRangeFailAction & __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc rangeMinFailAction */
2019-05-30 04:40:02 +08:00
JKQTPMathImageColorRangeFailAction getActionRangeMinFail ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc rangeMaxFailAction */
2019-05-30 04:40:02 +08:00
void setRangeMaxFailAction ( const JKQTPMathImageColorRangeFailAction & __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc rangeMaxFailAction */
2019-05-30 04:40:02 +08:00
JKQTPMathImageColorRangeFailAction getActionRangeMaxFail ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc rangeMinFailColor */
2019-05-30 04:40:02 +08:00
void setRangeMinFailColor ( const QColor & __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc rangeMinFailColor */
2019-05-30 04:40:02 +08:00
QColor getRangeMinFailColor ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc rangeMaxFailColor */
2019-05-30 04:40:02 +08:00
void setRangeMaxFailColor ( const QColor & __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc rangeMaxFailColor */
2019-05-30 04:40:02 +08:00
QColor getRangeMaxFailColor ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc nanColor */
2019-05-30 04:40:02 +08:00
void setNanColor ( const QColor & __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc nanColor */
2019-05-30 04:40:02 +08:00
QColor getNanColor ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc infColor */
2019-05-30 04:40:02 +08:00
void setInfColor ( const QColor & __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc infColor */
2019-05-30 04:40:02 +08:00
QColor getInfColor ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc showColorBar */
2019-05-30 04:40:02 +08:00
void setShowColorBar ( bool __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc showColorBar */
2019-05-30 04:40:02 +08:00
bool getShowColorBar ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc colorBarWidth */
2019-05-30 04:40:02 +08:00
void setColorBarWidth ( int __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc colorBarWidth */
2019-05-30 04:40:02 +08:00
int getColorBarWidth ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc colorBarOffset */
2019-05-30 04:40:02 +08:00
void setColorBarOffset ( int __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc colorBarOffset */
2019-05-30 04:40:02 +08:00
int getColorBarOffset ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc colorBarRelativeHeight */
2019-05-30 04:40:02 +08:00
void setColorBarRelativeHeight ( double __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc colorBarRelativeHeight */
2019-05-30 04:40:02 +08:00
double getColorBarRelativeHeight ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc imageMin */
2019-05-30 04:40:02 +08:00
void setImageMin ( double __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc imageMin */
2019-05-30 04:40:02 +08:00
double getImageMin ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc imageMax */
2019-05-30 04:40:02 +08:00
void setImageMax ( double __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc imageMax */
2019-05-30 04:40:02 +08:00
double getImageMax ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc autoImageRange */
2019-05-30 04:40:02 +08:00
void setAutoImageRange ( bool __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc autoImageRange */
2019-05-30 04:40:02 +08:00
bool getAutoImageRange ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc imageName */
2019-05-30 04:40:02 +08:00
void setImageName ( const QString & __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc imageName */
2019-05-30 04:40:02 +08:00
QString getImageName ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc imageNameFontName */
2019-05-30 04:40:02 +08:00
void setImageNameFontName ( const QString & __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc imageNameFontName */
2019-05-30 04:40:02 +08:00
QString getImageNameFontName ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc imageNameFontSize */
2019-05-30 04:40:02 +08:00
void setImageNameFontSize ( double __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc imageNameFontSize */
2019-05-30 04:40:02 +08:00
double getImageNameFontSize ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc colorBarRightAxis */
2019-05-30 04:40:02 +08:00
JKQTPVerticalIndependentAxis * getColorBarRightAxis ( ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc colorBarTopAxis */
2019-05-30 04:40:02 +08:00
JKQTPHorizontalIndependentAxis * getColorBarTopAxis ( ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc colorBarRightAxis */
2019-05-30 04:40:02 +08:00
const JKQTPVerticalIndependentAxis * getColorBarRightAxis ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc colorBarTopAxis */
2019-05-30 04:40:02 +08:00
const JKQTPHorizontalIndependentAxis * getColorBarTopAxis ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc colorBarTopVisible */
2019-05-30 04:40:02 +08:00
void setColorBarTopVisible ( bool __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc colorBarTopVisible */
2019-05-30 04:40:02 +08:00
bool getColorBarTopVisible ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc colorBarRightVisible */
2019-05-30 04:40:02 +08:00
void setColorBarRightVisible ( bool __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc colorBarRightVisible */
2019-05-30 04:40:02 +08:00
bool getColorBarRightVisible ( ) const ;
protected :
JKQTBasePlotter * cbParent ;
/** \brief top color bar visible */
bool colorBarTopVisible ;
/** \brief right color bar visible */
bool colorBarRightVisible ;
/** \brief name of the image displayed above color bar (may contain LaTeX markup!) */
QString imageName ;
/** \brief font name when displaying imageName */
QString imageNameFontName ;
/** \brief font size in points when displaying imageName */
double imageNameFontSize ;
/** \brief palette for plotting an image */
JKQTPMathImageColorPalette palette ;
/** \brief indicate whether to display a color bar */
bool showColorBar ;
/** \brief width of the color bar */
int colorBarWidth ;
/** \brief height of the color bar, as multiple of plotHeight */
double colorBarRelativeHeight ;
/** \brief indicates whether to estimate min/max of the image automatically */
bool autoImageRange ;
/** \brief image value range minimum */
double imageMin ;
/** \brief image value range maximum */
double imageMax ;
/** \brief offset between outside space border and color bar */
int colorBarOffset ;
/** \brief which action to take if a color is below \a imageMin and \a autoImageRange \c ==false */
JKQTPMathImageColorRangeFailAction rangeMinFailAction ;
/** \brief which action to take if a color is above \a imageMax and \a autoImageRange \c ==false */
JKQTPMathImageColorRangeFailAction rangeMaxFailAction ;
/** \brief color to use for some settings of \a rangeMinFailAction */
QColor rangeMinFailColor ;
/** \brief color to use for some settings of \a rangeMaxFailAction */
QColor rangeMaxFailColor ;
/** \brief color to use for a not-a-number value */
QColor nanColor ;
/** \brief color to use for an infinity value */
QColor infColor ;
2019-08-01 04:10:26 +08:00
/** \brief object used for color bar axes at the right
2019-05-30 04:40:02 +08:00
*
* \ note this axis has some kind of a special role . It is used to format color bar axes
*/
JKQTPVerticalIndependentAxis * colorBarRightAxis ;
2019-08-01 04:10:26 +08:00
/** \brief object used for color bar axes at the top
*
* \ note this axis has some kind of a special role . It is used to format color bar axes
*/
2019-05-30 04:40:02 +08:00
JKQTPHorizontalIndependentAxis * colorBarTopAxis ;
} ;
2019-08-01 04:10:26 +08:00
/*! \brief if a class is derived from this class, it may use color bars that have 2 axes (one "data"/color axis and one "modifier" axis)
\ ingroup jkqtplotter_imagelots_tools
*/
class JKQTPLOTTER_LIB_EXPORT JKQTPColorPaletteWithModifierStyleAndToolsMixin : public JKQTPColorPaletteStyleAndToolsMixin {
2022-07-19 19:40:43 +08:00
# ifndef JKQTPLOTTER_WORKAROUND_QGADGET_BUG
2022-07-19 16:24:52 +08:00
Q_GADGET
# endif
2019-08-01 04:10:26 +08:00
public :
JKQTPColorPaletteWithModifierStyleAndToolsMixin ( JKQTBasePlotter * parent ) ;
virtual ~ JKQTPColorPaletteWithModifierStyleAndToolsMixin ( ) = default ;
/*! \brief if the graph plots outside the actual plot field of view (e.g. color bars, scale bars, ...)
\ note If you want to draw outside , then you ' ll also have to implement drawOutside ( )
*/
virtual void cbGetOutsideSize ( JKQTPEnhancedPainter & painter , int & leftSpace , int & rightSpace , int & topSpace , int & bottomSpace ) override ;
/*! \brief plots outside the actual plot field of view (e.g. color bars, scale bars, ...)
\ note If you want to draw outside , then you ' ll also have to implement getOutsideSize ( ) , so enough space is reserved
The four value supplied tell the method where to draw ( inside one of the rectangles ) .
*/
virtual void cbDrawOutside ( JKQTPEnhancedPainter & painter , QRect leftSpace , QRect rightSpace , QRect topSpace , QRect bottomSpace ) override ;
/** \brief set the parent class for internal objects (e.g. color bars) */
virtual void cbSetParent ( JKQTBasePlotter * parent ) override ;
/** \brief determine min/max data value of the modifier image */
virtual void cbGetModifierDataMinMax ( double & imin , double & imax ) = 0 ;
2020-09-21 19:47:54 +08:00
/** \copydoc modifierMode */
2019-08-01 04:10:26 +08:00
void setModifierMode ( const JKQTPMathImageModifierMode & __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc modifierMode */
2019-08-01 04:10:26 +08:00
JKQTPMathImageModifierMode getModifierMode ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc colorBarModifiedWidth */
2019-08-01 04:10:26 +08:00
void setColorBarModifiedWidth ( double __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc colorBarModifiedWidth */
2019-08-01 04:10:26 +08:00
double getColorBarModifiedWidth ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc modifierColorBarTopAxis */
2019-08-01 04:10:26 +08:00
JKQTPVerticalIndependentAxis * getModifierColorBarTopAxis ( ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc modifierColorBarRightAxis */
2019-08-01 04:10:26 +08:00
JKQTPHorizontalIndependentAxis * getModifierColorBarRightAxis ( ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc modifierColorBarTopAxis */
2019-08-01 04:10:26 +08:00
const JKQTPVerticalIndependentAxis * getModifierColorBarTopAxis ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc modifierColorBarRightAxis */
2019-08-01 04:10:26 +08:00
const JKQTPHorizontalIndependentAxis * getModifierColorBarRightAxis ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc autoModifierRange */
2019-08-01 04:10:26 +08:00
void setAutoModifierRange ( bool __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc autoModifierRange */
2019-08-01 04:10:26 +08:00
bool getAutoModifierRange ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc modifierMin */
2019-08-01 04:10:26 +08:00
void setModifierMin ( double __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc modifierMin */
2019-08-01 04:10:26 +08:00
double getModifierMin ( ) const ;
2020-09-21 19:47:54 +08:00
/** \copydoc modifierMax */
2019-08-01 04:10:26 +08:00
void setModifierMax ( double __value ) ;
2020-09-21 19:47:54 +08:00
/** \copydoc modifierMax */
2019-08-01 04:10:26 +08:00
double getModifierMax ( ) const ;
/** \brief modify the given image \a img, using modifier image \a dataModifier (of type \a datatypeModifier and size \a Nx * \a Ny), using values in the range \a internalModifierMin ... \a internalModifierMax
*/
2020-09-29 01:24:17 +08:00
void modifyImage ( QImage & img , const void * dataModifier , JKQTPMathImageDataType datatypeModifier , int Nx , int Ny , double internalModifierMin , double internalModifierMax ) ;
2019-08-01 04:10:26 +08:00
protected :
/** \brief indicates whether to estimate min/max of the modifier automatically */
bool autoModifierRange ;
/** \brief modifier value range minimum */
double modifierMin ;
/** \brief modifier value range maximum */
double modifierMax ;
/** \brief width of the color bar when modifier is on */
double colorBarModifiedWidth ;
/** \brief how to apply the modifier column dataModifier
* \ see ModifierMode
*/
JKQTPMathImageModifierMode modifierMode ;
/** \brief object used for color bar axes (right border, modifier image data)
*
* \ note this axis has some kind of a special role . It is used to format color bar axes
*/
JKQTPVerticalIndependentAxis * modifierColorBarTopAxis ;
/** \brief object used for color bar axes (top border, modifier image data)
*
* \ note this axis has some kind of a special role . It is used to format color bar axes
*/
JKQTPHorizontalIndependentAxis * modifierColorBarRightAxis ;
} ;
2019-05-30 04:40:02 +08:00
# endif // JKQTPIMAGETOOLS_H