#include "QtxColorScale.h"
-#include <qmap.h>
-#include <qimage.h>
-#include <qregexp.h>
-#include <qpixmap.h>
-#include <qbitmap.h>
-#include <qpainter.h>
-#include <qmainwindow.h>
-#include <qstringlist.h>
-#include <qstylesheet.h>
-#include <qsimplerichtext.h>
+#include <QtCore/qmap.h>
+#include <QtCore/qregexp.h>
+#include <QtCore/qstringlist.h>
+
+#include <QtGui/qimage.h>
+#include <QtGui/qpixmap.h>
+#include <QtGui/qbitmap.h>
+#include <QtGui/qpainter.h>
+#include <QtGui/qtextdocument.h>
#include <math.h>
/*!
- Constructor
+ \class QtxColorScale
+ \brief Color Scale widget.
*/
-QtxColorScale::QtxColorScale( QWidget* parent, const char* name, WFlags f )
-: QFrame( parent, name, f | WResizeNoErase | WRepaintNoErase ),
-myDock( 0 ),
-myMin( 0.0 ),
-myMax( 1.0 ),
-myTitle( "" ),
-myInterval( 10 ),
-myStyleSheet( 0 ),
-myFormat( "%.4g" ),
-myColorMode( Auto ),
-myLabelMode( Auto ),
-myLabelPos( Right ),
-myTitlePos( Center ),
-myDumpMode( NoDump ),
-myFlags( AtBorder | WrapTitle )
-{
- setCaption( tr ( "Color scale" ) );
-}
/*!
- Constructor
+ \brief Constructor.
+ \param parent parent widget
+ \param f widget flags
*/
-QtxColorScale::QtxColorScale( const int num, QWidget* parent, const char* name, WFlags f )
-: QFrame( parent, name, f | WResizeNoErase | WRepaintNoErase ),
-myDock( 0 ),
-myMin( 0.0 ),
-myMax( 1.0 ),
-myTitle( "" ),
-myInterval( num ),
-myStyleSheet( 0 ),
-myFormat( "%.4g" ),
-myColorMode( Auto ),
-myLabelMode( Auto ),
-myLabelPos( Right ),
-myTitlePos( Center ),
-myDumpMode( NoDump ),
-myFlags( AtBorder | WrapTitle )
+QtxColorScale::QtxColorScale( QWidget* parent, Qt::WindowFlags f )
+: QFrame( parent, f ),
+ myMin( 0.0 ),
+ myMax( 1.0 ),
+ myTitle( "" ),
+ myFormat( "%.4g" ),
+ myInterval( 10 ),
+ myDumpMode( NoDump ),
+ myColorMode( Auto ),
+ myLabelMode( Auto ),
+ myFlags( AtBorder | WrapTitle ),
+ myLabelPos( Right ),
+ myTitlePos( Center )
{
- setCaption( tr ( "Color scale" ) );
+ setWindowTitle( tr ( "Color scale" ) );
}
-#if QT_VER == 3
-
/*!
- Constructor
+ \brief Constructor.
+ \param num number of color scale intervals
+ \param parent parent widget
+ \param f widget flags
*/
-QtxColorScale::QtxColorScale( Dock* dock, const char* name, WFlags f )
-: QFrame( dock, name, f | WResizeNoErase | WRepaintNoErase ),
-myMin( 0.0 ),
-myMax( 1.0 ),
-myTitle( "" ),
-myDock( dock ),
-myInterval( 10 ),
-myStyleSheet( 0 ),
-myFormat( "%.4g" ),
-myColorMode( Auto ),
-myLabelMode( Auto ),
-myLabelPos( Right ),
-myTitlePos( Center ),
-myDumpMode( NoDump ),
-myFlags( AtBorder | WrapTitle )
+QtxColorScale::QtxColorScale( const int num, QWidget* parent, Qt::WindowFlags f )
+: QFrame( parent, f ),
+ myMin( 0.0 ),
+ myMax( 1.0 ),
+ myTitle( "" ),
+ myFormat( "%.4g" ),
+ myInterval( num ),
+ myDumpMode( NoDump ),
+ myColorMode( Auto ),
+ myLabelMode( Auto ),
+ myFlags( AtBorder | WrapTitle ),
+ myLabelPos( Right ),
+ myTitlePos( Center )
{
- setCaption( tr ( "Color scale" ) );
+ setWindowTitle( tr ( "Color scale" ) );
}
-#endif
-
/*!
- Destructor
+ \brief Destructor.
+
+ Does nothing for the moment.
*/
QtxColorScale::~QtxColorScale()
{
}
/*!
- \returns minimal limit of scale.
+ \brief Get color scale minimum value.
+ \return lower limit of the color scale
*/
double QtxColorScale::minimum() const
{
- return myMin;
+ return myMin;
}
/*!
- \return maximal limit of scale.
+ \brief Get color scale maximum value.
+ \return upper limit of the color scale
*/
double QtxColorScale::maximum() const
{
- return myMax;
+ return myMax;
}
/*!
- \return range (minimal and maximal limits) of scale.
+ \brief Get color scale range.
+ \param min returning lower limit of the color scale
+ \param max returning upper limit of the color scale
*/
void QtxColorScale::range( double& min, double& max ) const
{
- min = myMin;
- max = myMax;
+ min = myMin;
+ max = myMax;
}
/*!
- \return the current title string.
+ \brief Get color scale title.
+ \return current title
*/
QString QtxColorScale::title() const
{
- return myTitle;
+ return myTitle;
}
/*!
- \returns the current format of number presentation in labels for Auto label mode (sprintf specification).
+ \brief Get current format of the number presentation.
+
+ This format is used to output values in the color scale labels
+ in "Auto" label mode. The format uses sprintf specification.
+
+ \return current format
*/
QString QtxColorScale::format() const
{
- return myFormat;
+ return myFormat;
}
/*!
- \return dump mode.
+ \brief Get Color scale dump mode.
+ \return current dump mode (QtxColorScale::DumpMode)
*/
int QtxColorScale::dumpMode() const
{
- return myDumpMode;
+ return myDumpMode;
}
/*!
- \return label mode.
+ \brief Get label mode.
+ \return current label mode (QtxColorScale::Mode)
*/
int QtxColorScale::labelMode() const
{
- return myLabelMode;
+ return myLabelMode;
}
/*!
- \return color mode.
+ \brief Get color mode.
+ \return current color mode (QtxColorScale::Mode)
*/
int QtxColorScale::colorMode() const
{
- return myColorMode;
+ return myColorMode;
}
/*!
- \return intervals number of color scale.
+ \brief Get number of color scale intervals.
+ \return number of intervals
*/
int QtxColorScale::intervalsNumber() const
{
- return myInterval;
+ return myInterval;
}
/*!
- \return the user label of specified interval.
+ \brief Get user label for the specified color scale interval.
+ \param idx interval index
+ \return user label for specified interval
*/
QString QtxColorScale::label( const int idx ) const
{
- QString res;
- if ( idx >= 0 && idx < (int)myLabels.count() )
- res = *myLabels.at( idx );
- return res;
+ QString res;
+ if ( idx >= 0 && idx < (int)myLabels.count() )
+ res = myLabels[idx];
+ return res;
}
/*!
- \return the user color of specified interval.
+ \brief Get user color for the specified color scale interval.
+ \param idx interval index
+ \return user color for specified interval
*/
QColor QtxColorScale::color( const int idx ) const
{
- QColor res;
- if ( idx >= 0 && idx < (int)myColors.count() )
- res = *myColors.at( idx );
- return res;
+ QColor res;
+ if ( idx >= 0 && idx < (int)myColors.count() )
+ res = myColors[idx];
+ return res;
}
/*!
- \return the user labels.
+ \brief Get user labels for all color scale intervals.
+ \param list returning labels list
*/
void QtxColorScale::labels( QStringList& list ) const
{
- list = myLabels;
+ list = myLabels;
}
/*!
- \return the user color.
+ \brief Get user colors for all color scale intervals.
+ \param list returning colors list
*/
-void QtxColorScale::colors( QValueList<QColor>& list ) const
+void QtxColorScale::colors( QList<QColor>& list ) const
{
- list = myColors;
+ list = myColors;
}
/*!
- \return the label position.
+ \brief Get label position.
+ \return label position (QtxColorScale::Position)
*/
int QtxColorScale::labelPosition() const
{
- return myLabelPos;
+ return myLabelPos;
}
/*!
- \return the title position.
+ \brief Get title position.
+ \return title position (QtxColorScale::Position)
*/
int QtxColorScale::titlePosition() const
{
- return myTitlePos;
+ return myTitlePos;
}
/*!
- Sets the minimum limit.
+ \brief Set color scale minimum value.
+ \param val lower limit of the color scale
*/
void QtxColorScale::setMinimum( const double val )
{
- setRange( val, maximum() );
+ setRange( val, maximum() );
}
/*!
- Sets the maximum limit.
+ \brief Set color scale maximum value.
+ \param val upper limit of the color scale
*/
void QtxColorScale::setMaximum( const double val )
{
- setRange( minimum(), val );
+ setRange( minimum(), val );
}
/*!
- Sets the minimum and maximum limits.
+ \brief Set color scale range.
+ \param min lower limit of the color scale
+ \param max upper limit of the color scale
*/
void QtxColorScale::setRange( const double min, const double max )
{
- if ( myMin == min && myMax == max )
- return;
-
- myMin = min;
- myMax = max;
-
- myPrecise = QString::null;
+ if ( myMin == min && myMax == max )
+ return;
+
+ myMin = min;
+ myMax = max;
+
+ myPrecise = QString::null;
- if ( colorMode() == Auto || labelMode() == Auto )
- updateScale();
+ if ( colorMode() == Auto || labelMode() == Auto )
+ updateScale();
}
/*!
- Sets the title string.
+ \brief Set color scale title.
+ \param str new title
*/
void QtxColorScale::setTitle( const QString& str )
{
- if ( myTitle == str )
- return;
-
- myTitle = str;
- updateScale();
+ if ( myTitle == str )
+ return;
+
+ myTitle = str;
+ updateScale();
}
/*!
- Sets the format of number presentation in labels for
- Auto label mode (sprintf specification).
+ \brief Set current format of the number presentation.
+ \sa format()
+ \param format new number presentation format
*/
void QtxColorScale::setFormat( const QString& format )
{
- if ( myFormat == format )
- return;
+ if ( myFormat == format )
+ return;
- myFormat = format;
- myPrecise = QString::null;
- if ( colorMode() == Auto )
- updateScale();
+ myFormat = format;
+ myPrecise = QString::null;
+ if ( colorMode() == Auto )
+ updateScale();
}
/*!
- Sets the number of intervals.
+ \brief Set number of color scale intervals.
+ \param num number of intervals
*/
void QtxColorScale::setIntervalsNumber( const int num )
{
- if ( myInterval == num || num < 1 )
- return;
-
- myInterval = num;
- myPrecise = QString::null;
-
- updateScale();
+ if ( myInterval == num || num < 1 )
+ return;
+
+ myInterval = num;
+ myPrecise = QString::null;
+
+ updateScale();
}
/*!
- Sets the user label for specified interval. If number
- of interval is negative then user label will be added
- as new at the end of list.
+ \brief Set user label for the specified color scale interval.
+
+ If number of interval is negative then user label will be added
+ as new to the end of list.
+
+ \param txt user label
+ \param idx interval index
*/
void QtxColorScale::setLabel( const QString& txt, const int idx )
{
- bool changed = false;
- uint i = idx < 0 ? myLabels.count() : idx;
- if ( i < myLabels.count() )
- {
- changed = *myLabels.at( i ) != txt;
- myLabels[i] = txt;
- }
- else
- {
- changed = true;
- while ( i >= myLabels.count() )
- myLabels.append( "" );
- myLabels[i] = txt;
- }
- if ( changed )
- updateScale();
+ bool changed = false;
+ int i = idx < 0 ? myLabels.count() : idx;
+ if ( i < myLabels.count() )
+ {
+ changed = myLabels[i] != txt;
+ myLabels[i] = txt;
+ }
+ else
+ {
+ changed = true;
+ while ( i >= myLabels.count() )
+ myLabels.append( "" );
+ myLabels[i] = txt;
+ }
+ if ( changed )
+ updateScale();
}
/*!
- Sets the user color for specified interval. If number
- of interval is negative then user color will be added
- as new at the end of list.
+ \brief Set user color for the specified color scale interval.
+
+ If number of interval is negative then user color will be added
+ as new to the end of list.
+
+ \param clr user color
+ \param idx interval index
*/
void QtxColorScale::setColor( const QColor& clr, const int idx )
{
- bool changed = false;
- uint i = idx < 0 ? myColors.count() : idx;
- if ( i < myColors.count() )
- {
- changed = *myColors.at( i ) != clr;
- myColors[i] = clr;
- }
- else
- {
- changed = true;
- while ( i >= myColors.count() )
- myColors.append( QColor() );
- myColors[i] = clr;
- }
- if ( changed )
- updateScale();
+ bool changed = false;
+ int i = idx < 0 ? myColors.count() : idx;
+ if ( i < myColors.count() )
+ {
+ changed = myColors[i] != clr;
+ myColors[i] = clr;
+ }
+ else
+ {
+ changed = true;
+ while ( i >= myColors.count() )
+ myColors.append( QColor() );
+ myColors[i] = clr;
+ }
+ if ( changed )
+ updateScale();
}
/*!
- Replace the all user label with specified list.
+ \brief Set user labels for all color scale intervals.
+ \param list new labels list
*/
void QtxColorScale::setLabels( const QStringList& list )
{
- if ( list.isEmpty() )
- return;
+ if ( list.isEmpty() )
+ return;
- myLabels = list;
- updateScale();
+ myLabels = list;
+ updateScale();
}
/*!
- Replace the all user colors with specified list.
+ \brief Set user colors for all color scale intervals.
+ \param list new colors list
*/
-void QtxColorScale::setColors( const QValueList<QColor>& list )
+void QtxColorScale::setColors( const QList<QColor>& list )
{
- if ( list.isEmpty() )
- return;
+ if ( list.isEmpty() )
+ return;
- myColors = list;
- updateScale();
+ myColors = list;
+ updateScale();
}
/*!
- Sets the color mode (Auto or User).
+ \brief Set color scale color mode.
+ \param mode new color mode (QtxColorScale::Mode)
*/
void QtxColorScale::setColorMode( const int mode )
{
- if ( myColorMode == mode )
- return;
-
- myColorMode = mode;
- updateScale();
+ if ( myColorMode == mode )
+ return;
+
+ myColorMode = mode;
+ updateScale();
}
/*!
- Sets the dump mode.
+ \brief Set color scale dump mode.
+ \param mode new dump mode (QtxColorScale::DumpMode)
*/
void QtxColorScale::setDumpMode( const int mode )
{
- myDumpMode = mode;
+ myDumpMode = mode;
}
/*!
- Sets the label mode (Auto or User).
+ \brief Set color scale label mode.
+ \param mode new label mode (QtxColorScale::Mode)
*/
void QtxColorScale::setLabelMode( const int mode )
{
- if ( myLabelMode != mode )
- {
- myLabelMode = mode;
- updateScale();
- }
+ if ( myLabelMode != mode )
+ {
+ myLabelMode = mode;
+ updateScale();
+ }
}
/*!
- Sets the label position.
+ \brief Set label position.
+ \param pos new label position (QtxColorScale::Position)
*/
void QtxColorScale::setLabelPosition( const int pos )
{
- if ( myLabelPos != pos && pos >= None && pos <= Center )
- {
- myLabelPos = pos;
- updateScale();
- }
+ if ( myLabelPos != pos && pos >= None && pos <= Center )
+ {
+ myLabelPos = pos;
+ updateScale();
+ }
}
/*!
- Sets the title position.
+ \brief Set title position.
+ \param pos new title position (QtxColorScale::Position)
*/
void QtxColorScale::setTitlePosition( const int pos )
{
- if ( myTitlePos != pos && pos >= None && pos <= Center )
- {
- myTitlePos = pos;
- updateScale();
- }
+ if ( myTitlePos != pos && pos >= None && pos <= Center )
+ {
+ myTitlePos = pos;
+ updateScale();
+ }
}
/*!
- Set the specified flags.
+ \brief Set color scale flags.
+ \param flags new flags
*/
void QtxColorScale::setFlags( const int flags )
{
- int prev = myFlags;
- myFlags |= flags;
- if ( prev != myFlags )
- updateScale();
+ int prev = myFlags;
+ myFlags |= flags;
+ if ( prev != myFlags )
+ updateScale();
}
/*!
- \return true if specified flags are setted.
+ \brief Test color scale flags.
+ \return \c true if specified flags are set
*/
bool QtxColorScale::testFlags( const int flags ) const
{
- return ( myFlags & flags ) == flags;
+ return ( myFlags & flags ) == flags;
}
/*!
- Clear (reset) the specified flags.
+ \brief Clear (reset) color scale flags.
+ \param flags color scale flags to be cleared
*/
void QtxColorScale::clearFlags( const int flags )
{
- int prev = myFlags;
- myFlags &= ~flags;
- if ( prev != myFlags )
- updateScale();
+ int prev = myFlags;
+ myFlags &= ~flags;
+ if ( prev != myFlags )
+ updateScale();
}
/*!
+ \brief Get widget's minumum size hint.
\return minimum size hint
*/
QSize QtxColorScale::minimumSizeHint() const
{
QSize sz = calculateSize( true, myFlags, titlePosition() != None, labelPosition() != None, true );
- return sz + QSize( frameWidth(), frameWidth() );
+ return sz + QSize( frameWidth(), frameWidth() );
}
/*!
+ \brief Get widget's default size hint.
\return size hint
*/
QSize QtxColorScale::sizeHint() const
{
QSize sz = calculateSize( false, myFlags, titlePosition() != None, labelPosition() != None, true );
- return sz + QSize( frameWidth(), frameWidth() );
+ return sz + QSize( frameWidth(), frameWidth() );
}
/*!
- Dump color scale into pixmap with current size.
+ \brief Calculate color scale size.
+ \param min if \c true, color scale size is calculated to be as smallest as possible
+ \param flags color scale flags
+ \param title color scale title
+ \param labels if \c true take into account labels
+ \param colors if \c true take into account colors
+ \return color scale size
*/
QSize QtxColorScale::calculateSize( const bool min, const int flags, const bool title,
- const bool labels, const bool colors ) const
+ const bool labels, const bool colors ) const
{
- int num = intervalsNumber();
-
- int spacer = 5;
- int textWidth = 0;
- int textHeight = fontMetrics().height();
- int colorWidth = 20;
-
- if ( labels && colors )
+ int num = intervalsNumber();
+
+ int spacer = 5;
+ int textWidth = 0;
+ int textHeight = fontMetrics().height();
+ int colorWidth = 20;
+
+ if ( labels && colors )
{
QtxColorScale* that = (QtxColorScale*)this;
QString fmt = that->myFormat;
- for ( int idx = 0; idx < num; idx++ )
- textWidth = QMAX( textWidth, fontMetrics().width( getLabel( idx ) ) );
-
+ for ( int idx = 0; idx < num; idx++ )
+ textWidth = qMax( textWidth, fontMetrics().width( getLabel( idx ) ) );
+
if ( !min )
that->myFormat = that->myFormat.replace( QRegExp( "g" ), "f" );
-
- for ( int index = 0; index < num; index++ )
- textWidth = QMAX( textWidth, fontMetrics().width( getLabel( index ) ) );
-
+
+ for ( int index = 0; index < num; index++ )
+ textWidth = qMax( textWidth, fontMetrics().width( getLabel( index ) ) );
+
that->myFormat = fmt;
}
+
+ int scaleWidth = 0;
+ int scaleHeight = 0;
+
+ int titleWidth = 0;
+ int titleHeight = 0;
+
+ if ( flags & AtBorder )
+ {
+ num++;
+ if ( min && title && !myTitle.isEmpty() )
+ titleHeight += 10;
+ }
+
+ if ( colors )
+ {
+ scaleWidth = colorWidth + textWidth + ( textWidth ? 3 : 2 ) * spacer;
+ if ( min )
+ scaleHeight = qMax( 2 * num, 3 * textHeight );
+ else
+ scaleHeight = (int)( 1.5 * ( num + 1 ) * textHeight );
+ }
+
+ if ( title )
+ {
+ QTextDocument* srt = textDocument( flags );
+ if ( srt )
+ {
+ QPainter p( (QtxColorScale*)this );
+ if ( scaleWidth )
+ srt->setTextWidth( scaleWidth );
+
+ titleHeight = (int)srt->size().height() + spacer;
+ titleWidth = (int)srt->size().width() + 10;
+
+ }
+ delete srt;
+ }
- int scaleWidth = 0;
- int scaleHeight = 0;
-
- int titleWidth = 0;
- int titleHeight = 0;
-
- if ( flags & AtBorder )
- {
- num++;
- if ( min && title && !myTitle.isEmpty() )
- titleHeight += 10;
- }
-
- if ( colors )
- {
- scaleWidth = colorWidth + textWidth + ( textWidth ? 3 : 2 ) * spacer;
- if ( min )
- scaleHeight = QMAX( 2 * num, 3 * textHeight );
- else
- scaleHeight = (int)( 1.5 * ( num + 1 ) * textHeight );
- }
-
- if ( title )
- {
- QSimpleRichText* srt = simpleRichText( flags );
- if ( srt )
- {
- QPainter p( this );
- if ( scaleWidth )
- srt->setWidth( &p, scaleWidth );
-
- titleHeight = srt->height() + spacer;
- titleWidth = srt->widthUsed() + 10;
-
- delete srt;
- }
- }
-
- int W = QMAX( titleWidth, scaleWidth ) + width() - contentsRect().width();
- int H = scaleHeight + titleHeight + height() - contentsRect().height();
-
- return QSize( W, H );
+ int W = qMax( titleWidth, scaleWidth ) + width() - contentsRect().width();
+ int H = scaleHeight + titleHeight + height() - contentsRect().height();
+
+ return QSize( W, H );
}
/*!
- Dump color scale into pixmap with current size.
+ \brief Dump color scale into pixmap with current size.
+ \return generated pixmap
*/
QPixmap QtxColorScale::dump() const
{
- QPixmap aPix;
+ QPixmap aPix;
- if ( dumpMode() != NoDump )
- {
- aPix = QPixmap( size() );
- if ( !aPix.isNull() )
- {
- bool scale = ( myDumpMode == ScaleDump || myDumpMode == FullDump );
- bool label = ( myDumpMode == ScaleDump || myDumpMode == FullDump ) &&
- labelPosition() != None;
- bool title = ( myDumpMode == TitleDump || myDumpMode == FullDump ) &&
- titlePosition() != None;
-
-#if QT_VER < 3
- QColor bgc = backgroundColor();
-#else
- QColor bgc = paletteBackgroundColor();
-#endif
- QPainter p;
- p.begin( &aPix );
- p.fillRect( 0, 0, aPix.width(), aPix.height(), bgc );
- drawScale( &p, bgc, false, 0, 0, aPix.width(), aPix.height(), title, label, scale );
- p.end();
- }
- }
-
- return aPix;
+ if ( dumpMode() != NoDump )
+ {
+ aPix = QPixmap( size() );
+ if ( !aPix.isNull() )
+ {
+ bool scale = ( myDumpMode == ScaleDump || myDumpMode == FullDump );
+ bool label = ( myDumpMode == ScaleDump || myDumpMode == FullDump ) &&
+ labelPosition() != None;
+ bool title = ( myDumpMode == TitleDump || myDumpMode == FullDump ) &&
+ titlePosition() != None;
+ QColor bgc = palette().color( backgroundRole() );
+ QPainter p;
+ p.begin( &aPix );
+ p.fillRect( 0, 0, aPix.width(), aPix.height(), bgc );
+ drawScale( &p, bgc, false, 0, 0, aPix.width(), aPix.height(), title, label, scale );
+ p.end();
+ }
+ }
+
+ return aPix;
}
/*!
- Dump color scale into pixmap with specified size.
+ \brief Dump color scale into pixmap with the specified size.
+ \param w pixmap width
+ \param h pixmap height
+ \return generated pixmap
*/
QPixmap QtxColorScale::dump( const int w, const int h ) const
{
-#if QT_VER < 3
- return dump( backgroundColor(), w, h );
-#else
- return dump( paletteBackgroundColor(), w, h );
-#endif
+ return dump( palette().color( backgroundRole() ), w, h );
}
/*!
- Dump color scale into pixmap with specified size and background color.
+ \brief Dump color scale into pixmap with the specified size and background color.
+ \param bg pixmap background color
+ \param w pixmap width
+ \param h pixmap height
+ \return generated pixmap
*/
QPixmap QtxColorScale::dump( const QColor& bg, const int w, const int h ) const
{
- QPixmap aPix;
- if ( dumpMode() != NoDump )
- {
- bool scale = ( myDumpMode == ScaleDump || myDumpMode == FullDump );
- bool label = ( myDumpMode == ScaleDump || myDumpMode == FullDump ) &&
- labelPosition() != None;
- bool title = ( myDumpMode == TitleDump || myDumpMode == FullDump ) &&
- titlePosition() != None;
-
- int W = w;
- int H = h;
- if ( W < 0 || H < 0 )
- {
- QSize sz = calculateSize( false, myFlags & ~WrapTitle, title, label, scale );
-
- if ( W < 0 )
- W = sz.width();
- if ( H < 0 )
- H = sz.height();
- }
-
- aPix = QPixmap( W, H );
- if ( !aPix.isNull() )
- {
- QPainter p;
- p.begin( &aPix );
- p.fillRect( 0, 0, aPix.width(), aPix.height(), bg );
- drawScale( &p, bg, false, 0, 0, aPix.width(), aPix.height(), title, label, scale );
- p.end();
- }
- }
-
- return aPix;
+ QPixmap aPix;
+ if ( dumpMode() != NoDump )
+ {
+ bool scale = ( myDumpMode == ScaleDump || myDumpMode == FullDump );
+ bool label = ( myDumpMode == ScaleDump || myDumpMode == FullDump ) &&
+ labelPosition() != None;
+ bool title = ( myDumpMode == TitleDump || myDumpMode == FullDump ) &&
+ titlePosition() != None;
+
+ int W = w;
+ int H = h;
+ if ( W < 0 || H < 0 )
+ {
+ QSize sz = calculateSize( false, myFlags & ~WrapTitle, title, label, scale );
+
+ if ( W < 0 )
+ W = sz.width();
+ if ( H < 0 )
+ H = sz.height();
+ }
+
+ aPix = QPixmap( W, H );
+ if ( !aPix.isNull() )
+ {
+ QPainter p;
+ p.begin( &aPix );
+ p.fillRect( 0, 0, aPix.width(), aPix.height(), bg );
+ drawScale( &p, bg, false, 0, 0, aPix.width(), aPix.height(), title, label, scale );
+ p.end();
+ }
+ }
+
+ return aPix;
}
/*!
- Show the color scale. [Reimplemented]
+ \brief Show color scale (reimplemented from QFrame).
*/
void QtxColorScale::show()
{
-#if QT_VER == 3
- if ( myDock )
- myDock->activate();
- else
-#endif
- QFrame::show();
+ QFrame::show();
}
/*!
- Hides the color scale. [Reimplemented]
+ \brief Hide color scale (reimplemented from QFrame).
*/
void QtxColorScale::hide()
{
-#if QT_VER == 3
- if ( myDock )
- myDock->deactivate();
- else
-#endif
- QFrame::hide();
+ QFrame::hide();
}
/*!
- Draw color scale contents. [Reimplemented]
+ \brief Draw color scale (reimplemented from QFrame).
+ \param p painter
*/
void QtxColorScale::drawContents( QPainter* p )
{
- if ( !isUpdatesEnabled() )
- return;
-
- QRect aDrawRect = contentsRect();
-
- drawScale( p, false/*testFlags( Transparent )*/, aDrawRect.x(),
- aDrawRect.y(), aDrawRect.width(), aDrawRect.height(),
- titlePosition() != None, labelPosition() != None, true );
+ if ( !updatesEnabled() )
+ return;
+
+ QRect aDrawRect = contentsRect();
+
+ drawScale( p, false/*testFlags( Transparent )*/, aDrawRect.x(),
+ aDrawRect.y(), aDrawRect.width(), aDrawRect.height(),
+ titlePosition() != None, labelPosition() != None, true );
}
/*!
- Draw color scale contents.
+ \brief Draw color scale contents.
+ \param p painter
+ \param transp if \c true color scale is drawn on transparent background
+ \param X color scale x coordinate
+ \param Y color scale y coordinate
+ \param W color scale width
+ \param H color scale height
+ \param drawTitle if \c true, draw title
+ \param drawLabel if \c true, draw labels
+ \param drawColors if \c true, draw colors
*/
void QtxColorScale::drawScale( QPainter* p, const bool transp, const int X, const int Y,
- const int W, const int H, const bool title,
- const bool label, const bool scale ) const
+ const int W, const int H, const bool drawTitle,
+ const bool drawLabel, const bool drawColors ) const
{
- QPixmap cache( W, H );
- QPainter cp( &cache );
-
-#if QT_VER < 3
- drawScale( &cp, backgroundColor(), transp, 0, 0, W, H, title, label, scale );
-#else
- drawScale( &cp, paletteBackgroundColor(), transp, 0, 0, W, H, title, label, scale );
-#endif
- cp.end();
-
- p->drawPixmap( X, Y, cache );
+ QPixmap cache( W, H );
+ QPainter cp( &cache );
+
+ drawScale( &cp, palette().color( backgroundRole() ), transp, 0, 0, W, H, drawTitle, drawLabel, drawColors );
+ cp.end();
+
+ p->drawPixmap( X, Y, cache );
}
/*!
- Draw color scale contents.
+ \brief Draw color scale contents.
+ \param p painter
+ \param bg background color
+ \param transp if \c true color scale is drawn on transparent background
+ \param X color scale x coordinate
+ \param Y color scale y coordinate
+ \param W color scale width
+ \param H color scale height
+ \param drawTitle if \c true, draw title
+ \param drawLabel if \c true, draw labels
+ \param drawColors if \c true, draw colors
*/
void QtxColorScale::drawScale( QPainter* p, const QColor& bg, const bool transp,
const int X, const int Y, const int W, const int H,
const bool drawTitle, const bool drawLabel, const bool drawColors ) const
{
- if ( !transp )
- p->fillRect( X, Y, W, H, bg );
-
- int num = intervalsNumber();
-
- int labPos = labelPosition();
-
- int spacer = 5;
- int textWidth = 0;
- int textHeight = p->fontMetrics().height();
-
- QString aTitle = title();
-
- int titleWidth = 0;
- int titleHeight = 0;
-
- if ( qGray( bg.rgb() ) < 128 )
- p->setPen( QColor( 255, 255, 255 ) );
- else
- p->setPen( QColor( 0, 0, 0 ) );
-
- // Draw title
- if ( drawTitle )
- {
- QSimpleRichText* srt = simpleRichText( myFlags );
- if ( srt )
- {
- srt->setWidth( p, W - 10 );
- titleHeight = srt->height() + spacer;
- titleWidth = srt->widthUsed();
- QColorGroup cg = colorGroup();
- cg.setColor( QColorGroup::Text, p->pen().color() );
- srt->draw( p, X + 5, Y, QRect( 0, 0, srt->width(), srt->height() ), cg );
-
- delete srt;
- }
- }
-
- bool reverse = testFlags( Reverse );
-
- QValueList<QColor> colors;
- QValueList<QString> labels;
- for ( int idx = 0; idx < num; idx++ )
- {
- if ( reverse )
- {
- colors.append( getColor( idx ) );
- labels.append( getLabel( idx ) );
- }
- else
- {
- colors.prepend( getColor( idx ) );
- labels.prepend( getLabel( idx ) );
- }
- }
-
- if ( testFlags( AtBorder ) )
- {
- if ( reverse )
- labels.append( getLabel( num ) );
- else
- labels.prepend( getLabel( num ) );
- if ( drawLabel )
- textWidth = QMAX( textWidth, p->fontMetrics().width( labels.last() ) );
- }
-
- if ( drawLabel )
- {
- const QFontMetrics& fm = p->fontMetrics();
- for ( QStringList::ConstIterator it = labels.begin(); it != labels.end(); ++it )
- textWidth = QMAX( textWidth, fm.width( *it) );
- }
-
- int lab = labels.count();
-
- double spc = ( H - ( ( QMIN( lab, 2 ) + QABS( lab - num - 1 ) ) * textHeight ) - titleHeight );
- double val = spc != 0 ? 1.0 * ( lab - QMIN( lab, 2 ) ) * textHeight / spc : 0;
- double iPart;
- double fPart = modf( val, &iPart );
- int filter = (int)iPart + ( fPart != 0 ? 1 : 0 );
- filter = QMAX( filter, 1 );
-
- double step = 1.0 * ( H - ( lab - num + QABS( lab - num - 1 ) ) * textHeight - titleHeight ) / num;
-
- int ascent = p->fontMetrics().ascent();
- int colorWidth = QMAX( 5, QMIN( 20, W - textWidth - 3 * spacer ) );
- if ( labPos == Center || !drawLabel )
- colorWidth = W - 2 * spacer;
-
- // Draw colors
- int x = X + spacer;
- switch ( labPos )
- {
- case Left:
- x += textWidth + ( textWidth ? 1 : 0 ) * spacer;
- break;
- }
-
- double offset = 1.0 * textHeight / 2 * ( lab - num + QABS( lab - num - 1 ) ) + titleHeight;
- QValueList<QColor>::Iterator cit = colors.begin();
+ if ( !transp )
+ p->fillRect( X, Y, W, H, bg );
+
+ int num = intervalsNumber();
+
+ int labPos = labelPosition();
+
+ int spacer = 5;
+ int textWidth = 0;
+ int textHeight = p->fontMetrics().height();
+
+ QString aTitle = title();
+
+ int titleWidth = 0;
+ int titleHeight = 0;
+
+ if ( qGray( bg.rgb() ) < 128 )
+ p->setPen( QColor( 255, 255, 255 ) );
+ else
+ p->setPen( QColor( 0, 0, 0 ) );
+
+ // Draw title
+ if ( drawTitle )
+ {
+ QTextDocument* srt = textDocument( myFlags );
+ if ( srt )
+ {
+ srt->setTextWidth( W - 10 );
+ titleHeight = (int)srt->size().height() + spacer;
+ titleWidth = (int)srt->size().width();
+ p->save();
+ p->translate( X + 5, Y );
+ srt->drawContents( p );
+ p->restore();
+ }
+ delete srt;
+ }
+
+ bool reverse = testFlags( Reverse );
+
+ QList<QColor> colors;
+ QList<QString> labels;
+ for ( int idx = 0; idx < num; idx++ )
+ {
+ if ( reverse )
+ {
+ colors.append( getColor( idx ) );
+ labels.append( getLabel( idx ) );
+ }
+ else
+ {
+ colors.prepend( getColor( idx ) );
+ labels.prepend( getLabel( idx ) );
+ }
+ }
+
+ if ( testFlags( AtBorder ) )
+ {
+ if ( reverse )
+ labels.append( getLabel( num ) );
+ else
+ labels.prepend( getLabel( num ) );
+ if ( drawLabel )
+ textWidth = qMax( textWidth, p->fontMetrics().width( labels.last() ) );
+ }
+
+ if ( drawLabel )
+ {
+ const QFontMetrics& fm = p->fontMetrics();
+ for ( QStringList::ConstIterator it = labels.begin(); it != labels.end(); ++it )
+ textWidth = qMax( textWidth, fm.width( *it) );
+ }
+
+ int lab = labels.count();
+
+ double spc = ( H - ( ( qMin( lab, 2 ) + qAbs( lab - num - 1 ) ) * textHeight ) - titleHeight );
+ double val = spc != 0 ? 1.0 * ( lab - qMin( lab, 2 ) ) * textHeight / spc : 0;
+ double iPart;
+ double fPart = modf( val, &iPart );
+ int filter = (int)iPart + ( fPart != 0 ? 1 : 0 );
+ filter = qMax( filter, 1 );
+
+ double step = 1.0 * ( H - ( lab - num + qAbs( lab - num - 1 ) ) * textHeight - titleHeight ) / num;
+
+ int ascent = p->fontMetrics().ascent();
+ int colorWidth = qMax( 5, qMin( 20, W - textWidth - 3 * spacer ) );
+ if ( labPos == Center || !drawLabel )
+ colorWidth = W - 2 * spacer;
+
+ // Draw colors
+ int x = X + spacer;
+ switch ( labPos )
+ {
+ case Left:
+ x += textWidth + ( textWidth ? 1 : 0 ) * spacer;
+ break;
+ }
+
+ double offset = 1.0 * textHeight / 2 * ( lab - num + qAbs( lab - num - 1 ) ) + titleHeight;
+ QList<QColor>::Iterator cit = colors.begin();
uint ci = 0;
- for ( ci = 0; cit != colors.end() && drawColors; ++cit, ci++ )
- {
- int y = (int)( Y + ci * step + offset );
- int h = (int)( Y + ( ci + 1 ) * step + offset ) - y;
- p->fillRect( x, y, colorWidth, h, *cit );
- }
-
- if ( drawColors )
- p->drawRect( int( x - 1 ), int( Y + offset - 1 ), int( colorWidth + 2 ), int( ci * step + 2 ) );
-
- // Draw labels
- offset = 1.0 * QABS( lab - num - 1 ) * ( step - textHeight ) / 2 +
- 1.0 * QABS( lab - num - 1 ) * textHeight / 2;
- offset += titleHeight;
- if ( drawLabel && !labels.isEmpty() )
- {
- int i1 = 0;
- int i2 = lab - 1;
- int last1( i1 ), last2( i2 );
- int x = X + spacer;
- switch ( labPos )
- {
- case Center:
- x += ( colorWidth - textWidth ) / 2;
- break;
- case Right:
- x += colorWidth + spacer;
- break;
- }
- while ( i2 - i1 >= filter || ( i2 == 0 && i1 == 0 ) )
- {
- int pos1 = i1;
- int pos2 = lab - 1 - i2;
- if ( filter && !( pos1 % filter ) )
- {
- p->drawText( x, (int)( Y + i1 * step + ascent + offset ), *labels.at( i1 ) );
- last1 = i1;
- }
- if ( filter && !( pos2 % filter ) )
- {
- p->drawText( x, (int)( Y + i2 * step + ascent + offset ), *labels.at( i2 ) );
- last2 = i2;
- }
- i1++;
- i2--;
- }
- int pos = i1;
- int i0 = -1;
- while ( pos <= i2 && i0 == -1 )
- {
- if ( filter && !( pos % filter ) &&
- QABS( pos - last1 ) >= filter && QABS( pos - last2 ) >= filter )
- i0 = pos;
- pos++;
- }
-
- if ( i0 != -1 )
- p->drawText( x, (int)( Y + i0 * step + ascent + offset ), *labels.at( i0 ) );
- }
+ for ( ci = 0; cit != colors.end() && drawColors; ++cit, ci++ )
+ {
+ int y = (int)( Y + ci * step + offset );
+ int h = (int)( Y + ( ci + 1 ) * step + offset ) - y;
+ p->fillRect( x, y, colorWidth, h, *cit );
+ }
+
+ if ( drawColors )
+ p->drawRect( int( x - 1 ), int( Y + offset - 1 ), int( colorWidth + 2 ), int( ci * step + 2 ) );
+
+ // Draw labels
+ offset = 1.0 * qAbs( lab - num - 1 ) * ( step - textHeight ) / 2 +
+ 1.0 * qAbs( lab - num - 1 ) * textHeight / 2;
+ offset += titleHeight;
+ if ( drawLabel && !labels.isEmpty() )
+ {
+ int i1 = 0;
+ int i2 = lab - 1;
+ int last1( i1 ), last2( i2 );
+ int x = X + spacer;
+ switch ( labPos )
+ {
+ case Center:
+ x += ( colorWidth - textWidth ) / 2;
+ break;
+ case Right:
+ x += colorWidth + spacer;
+ break;
+ }
+ while ( i2 - i1 >= filter || ( i2 == 0 && i1 == 0 ) )
+ {
+ int pos1 = i1;
+ int pos2 = lab - 1 - i2;
+ if ( filter && !( pos1 % filter ) )
+ {
+ p->drawText( x, (int)( Y + i1 * step + ascent + offset ), labels[i1] );
+ last1 = i1;
+ }
+ if ( filter && !( pos2 % filter ) )
+ {
+ p->drawText( x, (int)( Y + i2 * step + ascent + offset ), labels[i2] );
+ last2 = i2;
+ }
+ i1++;
+ i2--;
+ }
+ int pos = i1;
+ int i0 = -1;
+ while ( pos <= i2 && i0 == -1 )
+ {
+ if ( filter && !( pos % filter ) &&
+ qAbs( pos - last1 ) >= filter && qAbs( pos - last2 ) >= filter )
+ i0 = pos;
+ pos++;
+ }
+
+ if ( i0 != -1 )
+ p->drawText( x, (int)( Y + i0 * step + ascent + offset ), labels[i0] );
+ }
}
/*!
- \return the format for number labels.
+ \brief Generate number presentation format.
+ \return format for number labels
*/
QString QtxColorScale::getFormat() const
{
- QString aFormat = format();
-
- if ( !testFlags( PreciseFormat ) || testFlags( Integer ) )
- return aFormat;
-
- if ( !myPrecise.isEmpty() )
- return myPrecise;
-
- if ( aFormat.find( QRegExp( "^(%[0-9]*.?[0-9]*[fegFEG])$" ) ) != 0 )
- return aFormat;
-
- int pos1 = aFormat.find( '.' );
- int pos2 = aFormat.find( QRegExp( "[fegFEG]") );
-
- QString aLocFormat;
- int precision = 1;
- if ( pos1 > 0 )
- {
- aLocFormat = aFormat.mid( 0, pos1 + 1 );
- precision = aFormat.mid( pos1 + 1, pos2 - pos1 - 1 ).toInt();
- if ( precision < 1 )
- precision = 1;
- }
- else
- return aFormat;
+ QString aFormat = format();
+
+ if ( !testFlags( PreciseFormat ) || testFlags( Integer ) )
+ return aFormat;
+
+ if ( !myPrecise.isEmpty() )
+ return myPrecise;
+
+ if ( !aFormat.contains( QRegExp( "^(%[0-9]*.?[0-9]*[fegFEG])$" ) ) )
+ return aFormat;
+
+ int pos1 = aFormat.indexOf( '.' );
+ int pos2 = aFormat.indexOf( QRegExp( "[fegFEG]") );
- QtxColorScale* that = (QtxColorScale*)this;
-
- // calculate format, maximum precision limited
- // to 7 digits after the decimal point.
- while ( myPrecise.isEmpty() && precision < 7 )
- {
- QString aTmpFormat = aLocFormat;
- aTmpFormat += QString( "%1" ).arg( precision );
- aTmpFormat += aFormat.mid( pos2 );
-
- QMap<QString, int> map;
- bool isHasTwinz = false;
-
- for ( int idx = 0; idx < intervalsNumber() && !isHasTwinz; idx++ )
- {
- double val = getNumber( idx );
- QString tmpname = QString().sprintf( aTmpFormat, val );
- isHasTwinz = map.contains( tmpname );
- map.insert( tmpname, 1 );
- }
-
- if ( !isHasTwinz )
- that->myPrecise = aTmpFormat;
- precision++;
- }
-
- if ( !myPrecise.isEmpty() )
- aFormat = myPrecise;
-
- return aFormat;
+ QString aLocFormat;
+ int precision = 1;
+ if ( pos1 > 0 )
+ {
+ aLocFormat = aFormat.mid( 0, pos1 + 1 );
+ precision = aFormat.mid( pos1 + 1, pos2 - pos1 - 1 ).toInt();
+ if ( precision < 1 )
+ precision = 1;
+ }
+ else
+ return aFormat;
+
+ QtxColorScale* that = (QtxColorScale*)this;
+
+ // calculate format, maximum precision limited
+ // to 7 digits after the decimal point.
+ while ( myPrecise.isEmpty() && precision < 7 )
+ {
+ QString aTmpFormat = aLocFormat;
+ aTmpFormat += QString( "%1" ).arg( precision );
+ aTmpFormat += aFormat.mid( pos2 );
+
+ QMap<QString, int> map;
+ bool isHasTwinz = false;
+
+ for ( int idx = 0; idx < intervalsNumber() && !isHasTwinz; idx++ )
+ {
+ double val = getNumber( idx );
+ QString tmpname = QString().sprintf( aTmpFormat.toLatin1(), val );
+ isHasTwinz = map.contains( tmpname );
+ map.insert( tmpname, 1 );
+ }
+
+ if ( !isHasTwinz )
+ that->myPrecise = aTmpFormat;
+ precision++;
+ }
+
+ if ( !myPrecise.isEmpty() )
+ aFormat = myPrecise;
+
+ return aFormat;
}
/*!
- \return the number for specified interval.
+ \brief Get color scale value corresponding to the specified interval.
+ \param idx interval index
+ \return color scale value
*/
double QtxColorScale::getNumber( const int idx ) const
{
- double val = 0;
- if ( intervalsNumber() > 0 )
- val = minimum() + idx * ( QABS( maximum() - minimum() ) / intervalsNumber() );
- return val;
+ double val = 0;
+ if ( intervalsNumber() > 0 )
+ val = minimum() + idx * ( qAbs( maximum() - minimum() ) / intervalsNumber() );
+ return val;
}
/*!
- \return the label for specified interval according to the current label mode.
+ \brief Get color scale label text corresponding to the specified interval.
+ \param idx interval index
+ \return color scale label text
*/
QString QtxColorScale::getLabel( const int idx ) const
{
- QString res;
- if ( labelMode() == User )
- res = label( idx );
- else
- {
- double val = getNumber( idx );
- res = QString().sprintf( getFormat(), testFlags( Integer ) ? (int)val : val );
- }
- return res;
+ QString res;
+ if ( labelMode() == User )
+ res = label( idx );
+ else
+ {
+ double val = getNumber( idx );
+ res = QString().sprintf( getFormat().toLatin1(), testFlags( Integer ) ? (int)val : val );
+ }
+ return res;
}
/*!
- \return the color for specified interval according to the current color mode.
+ \brief Get color scale color corresponding to the specified interval.
+ \param idx interval index
+ \return color scale color
*/
QColor QtxColorScale::getColor( const int idx ) const
{
- QColor res;
- if ( colorMode() == User )
- res = color( idx );
- else
+ QColor res;
+ if ( colorMode() == User )
+ res = color( idx );
+ else
res = Qtx::scaleColor( idx, 0, intervalsNumber() - 1 );
- return res;
+ return res;
}
/*!
- Update color scale if it required.
+ \brief Update color scale.
*/
void QtxColorScale::updateScale()
{
update();
- updateGeometry();
+ updateGeometry();
}
/*!
- \return QSimpleRichText object for title. If title
- not defined (empty string) then return null pointer.
- Object should be deleted by caller function.
-*/
-QSimpleRichText* QtxColorScale::simpleRichText( const int flags ) const
-{
- QSimpleRichText* srt = 0;
-
- QString aTitle;
- switch ( titlePosition() )
- {
- case Left:
- aTitle = QString( "<p align=\"left\">%1</p>" );
- break;
- case Right:
- aTitle = QString( "<p align=\"right\">%1</p>" );
- break;
- case Center:
- aTitle = QString( "<p align=\"center\">%1</p>" );
- break;
- case None:
- default:
- break;
- }
-
- if ( !aTitle.isEmpty() && !title().isEmpty() )
- {
- if ( !myStyleSheet )
- {
- QtxColorScale* that = (QtxColorScale*)this;
- that->myStyleSheet = new QStyleSheet( that );
- }
-
- if ( myStyleSheet )
- {
- QStyleSheetItem* item = myStyleSheet->item( "p" );
- if ( item )
- item->setWhiteSpaceMode( flags & WrapTitle ? QStyleSheetItem::WhiteSpaceNormal :
- QStyleSheetItem::WhiteSpaceNoWrap );
- }
-
- aTitle = aTitle.arg( title() );
- srt = new QSimpleRichText( aTitle, font(), QString::null, myStyleSheet );
- }
-
- return srt;
-}
-
-#if QT_VER == 3
-
-/*!
- \class QtxColorScale::Dock
- Dockable window contains the color scale.
-*/
-
-/*!
- Constructor
-*/
-QtxColorScale::Dock::Dock( Place p, QWidget* parent, const char* name, WFlags f )
-: QDockWindow( p, parent, name, f ),
-myBlockShow( false ),
-myBlockResize( false )
-{
- myScale = new QtxColorScale( this );
-
- setWidget( myScale );
+ \brief Get text document (rich text) for the color scale title representation.
- setCloseMode( Always );
- setMovingEnabled( true );
- setResizeEnabled( true );
- setHorizontalStretchable( false );
+ If title is not defined (empty string) then null pointer is returned.
+ The calling function is responsible for the returning object deleting.
- setCaption( tr ( "Color scale" ) );
-}
-
-/*!
- Destructor.
+ \param flags color scale flags (not used)
+ \return text document or 0 if title is not set
*/
-QtxColorScale::Dock::~Dock()
+QTextDocument* QtxColorScale::textDocument( const int /*flags*/ ) const
{
-}
+ QTextDocument* doc = 0;
-/*!
- \return color scale widget.
-*/
-QtxColorScale* QtxColorScale::Dock::colorScale() const
-{
- return myScale;
-}
-
-/*!
- Set the dockable window is visible for main window.
-*/
-void QtxColorScale::Dock::activate()
-{
- if ( myBlockShow )
- return;
-
- QMainWindow* mw = 0;
- QWidget* p = parentWidget();
- while ( !mw && p )
- {
- if ( p->inherits( "QMainWindow" ) )
- mw = (QMainWindow*)p;
- p = p->parentWidget();
- }
- if ( mw )
- mw->setAppropriate( this, true );
-}
-
-/*!
- Set the dockable window is hidden for main window.
-*/
-void QtxColorScale::Dock::deactivate()
-{
- if ( myBlockShow )
- return;
-
- QMainWindow* mw = 0;
- QWidget* p = parentWidget();
- while ( !mw && p )
- {
- if ( p->inherits( "QMainWindow" ) )
- mw = (QMainWindow*)p;
- p = p->parentWidget();
- }
- if ( mw )
- mw->setAppropriate( this, false );
-}
-
-/*!
- \return true if the dockable window is visible.
-*/
-bool QtxColorScale::Dock::isActive() const
-{
- QMainWindow* mw = 0;
- QWidget* p = parentWidget();
- while ( !mw && p )
- {
- if ( p->inherits( "QMainWindow" ) )
- mw = (QMainWindow*)p;
- p = p->parentWidget();
- }
- if ( mw )
- return mw->appropriate( (QDockWindow*)this );
- else
- return false;
-}
-
-/*!
- Redefined show
-*/
-void QtxColorScale::Dock::show()
-{
- bool f = myBlockShow;
- myBlockShow = true;
- QDockWindow::show();
- myBlockShow = f;
-}
-
-/*!
- Redefined hide
-*/
-void QtxColorScale::Dock::hide()
-{
- bool f = myBlockShow;
- myBlockShow = false;
- QDockWindow::hide();
- myBlockShow = f;
-}
-
-/*!
- Make extent width as maximum value of widget width.
-*/
-void QtxColorScale::Dock::resize( int w, int h )
-{
- QDockWindow::resize( w, h );
-
- if ( myBlockResize )
- return;
-
- if ( orientation() == Qt::Vertical )
- setFixedExtentWidth( QMAX( fixedExtent().width(), w ) );
- else if ( orientation() == Qt::Horizontal )
- setFixedExtentHeight( QMAX( fixedExtent().height(), h ) );
-}
+ QString aTitle;
+ switch ( titlePosition() )
+ {
+ case Left:
+ aTitle = QString( "<p align=\"left\">%1</p>" );
+ break;
+ case Right:
+ aTitle = QString( "<p align=\"right\">%1</p>" );
+ break;
+ case Center:
+ aTitle = QString( "<p align=\"center\">%1</p>" );
+ break;
+ case None:
+ default:
+ break;
+ }
+
+ if ( !aTitle.isEmpty() && !title().isEmpty() )
+ {
+ /*
+ if ( !myStyleSheet )
+ {
+ QtxColorScale* that = (QtxColorScale*)this;
+ that->myStyleSheet = new QStyleSheet( that );
+ }
+
+ if ( myStyleSheet )
+ {
+ QStyleSheetItem* item = myStyleSheet->item( "p" );
+ if ( item )
+ item->setWhiteSpaceMode( flags & WrapTitle ? QStyleSheetItem::WhiteSpaceNormal :
+ QStyleSheetItem::WhiteSpaceNoWrap );
+ }
+ */
+ aTitle = aTitle.arg( title() );
+ doc = new QTextDocument( aTitle );
+ }
-/*!
- Set orientation
- \param o - new orientation
-*/
-void QtxColorScale::Dock::setOrientation( Orientation o )
-{
- bool b = myBlockResize;
- myBlockResize = true;
- QDockWindow::setOrientation( o );
- myBlockResize = b;
+ return doc;
}
-
-#endif
#include "Qtx.h"
-#include <qframe.h>
-#include <qvaluelist.h>
+#include <QtGui/qframe.h>
+#include <QtCore/qlist.h>
-#if QT_VER == 3
-#include <qdockwindow.h>
-#endif
-
-class QStyleSheet;
-class QSimpleRichText;
+class QTextDocument;
#ifdef WIN32
#pragma warning( disable:4251 )
#endif
-/*!
- \class QtxColorScale
- Color Scale widget.
-*/
class QTX_EXPORT QtxColorScale : public QFrame
{
- Q_OBJECT
+ Q_OBJECT
public:
- typedef enum { Auto, User } Mode;
- typedef enum { None, Left, Right, Center } Position;
- typedef enum { NoDump, TitleDump, ScaleDump, FullDump } DumpMode;
- typedef enum { AtBorder = 0x001, Reverse = 0x002, Integer = 0x004,
- WrapTitle = 0x008, PreciseFormat = 0x010, Transparent = 0x020 } Flags;
-
-#if QT_VER == 3
- class Dock : public QDockWindow
- {
- public:
- Dock( Place = InDock, QWidget* = 0, const char* = 0, WFlags = 0 );
- virtual ~Dock();
-
- QtxColorScale* colorScale() const;
-
- void activate();
- void deactivate();
-
- bool isActive() const;
-
- virtual void show();
- virtual void hide();
-
- virtual void resize( int, int );
- virtual void setOrientation( Orientation );
-
- private:
- QtxColorScale* myScale;
- bool myBlockShow;
- bool myBlockResize;
- };
-
-private:
- QtxColorScale( Dock*, const char* = 0, WFlags = 0 );
-#endif
+ //! Color scale color/label mode.
+ typedef enum {
+ Auto, //!< auto
+ User //!< user defined
+ } Mode;
+ //! Color scale title, label position.
+ typedef enum {
+ None, //!< do not draw
+ Left, //!< draw at the left
+ Right, //!< draw at the right
+ Center //!< draw at the center
+ } Position;
+ //! Dump mode.
+ typedef enum {
+ NoDump, //!< do not dump
+ TitleDump, //!< dump title
+ ScaleDump, //!< dump scale
+ FullDump //!< dump all
+ } DumpMode;
+ //! Color scale flags (bitwise).
+ typedef enum {
+ AtBorder = 0x001,
+ Reverse = 0x002,
+ Integer = 0x004,
+ WrapTitle = 0x008,
+ PreciseFormat = 0x010,
+ Transparent = 0x020
+ } Flags;
public:
- QtxColorScale( QWidget* = 0, const char* = 0, WFlags = 0 );
- QtxColorScale( const int, QWidget* = 0, const char* = 0, WFlags = 0 );
- virtual ~QtxColorScale();
-
- double minimum() const;
- double maximum() const;
- void range( double&, double& ) const;
- int dumpMode() const;
- int labelMode() const;
- int colorMode() const;
- int intervalsNumber() const;
-
- QString title() const;
- QString format() const;
- QString label( const int ) const;
- QColor color( const int ) const;
- void labels( QStringList& ) const;
- void colors( QValueList<QColor>& ) const;
-
- int labelPosition() const;
- int titlePosition() const;
-
- void setMinimum( const double );
- void setMaximum( const double );
- void setRange( const double, const double );
- void setDumpMode( const int );
- void setColorMode( const int );
- void setLabelMode( const int );
- void setIntervalsNumber( const int );
-
- void setTitle( const QString& );
- void setFormat( const QString& );
- void setLabel( const QString&, const int = -1 );
- void setColor( const QColor&, const int = -1 );
- void setLabels( const QStringList& );
- void setColors( const QValueList<QColor>& );
-
- void setLabelPosition( const int );
- void setTitlePosition( const int );
-
- void setFlags( const int );
- bool testFlags( const int ) const;
- void clearFlags( const int );
-
- QPixmap dump() const;
- QPixmap dump( const int = -1, const int = -1 ) const;
- QPixmap dump( const QColor&, const int = -1, const int = -1 ) const;
-
- virtual QSize minimumSizeHint() const;
- virtual QSize sizeHint() const;
-
- virtual void show();
- virtual void hide();
+ QtxColorScale( QWidget* = 0, Qt::WindowFlags = 0 );
+ QtxColorScale( const int, QWidget* = 0, Qt::WindowFlags = 0 );
+ virtual ~QtxColorScale();
+
+ double minimum() const;
+ double maximum() const;
+ void range( double&, double& ) const;
+ int dumpMode() const;
+ int labelMode() const;
+ int colorMode() const;
+ int intervalsNumber() const;
+
+ QString title() const;
+ QString format() const;
+ QString label( const int ) const;
+ QColor color( const int ) const;
+ void labels( QStringList& ) const;
+ void colors( QList<QColor>& ) const;
+
+ int labelPosition() const;
+ int titlePosition() const;
+
+ void setMinimum( const double );
+ void setMaximum( const double );
+ void setRange( const double, const double );
+ void setDumpMode( const int );
+ void setColorMode( const int );
+ void setLabelMode( const int );
+ void setIntervalsNumber( const int );
+
+ void setTitle( const QString& );
+ void setFormat( const QString& );
+ void setLabel( const QString&, const int = -1 );
+ void setColor( const QColor&, const int = -1 );
+ void setLabels( const QStringList& );
+ void setColors( const QList<QColor>& );
+
+ void setLabelPosition( const int );
+ void setTitlePosition( const int );
+
+ void setFlags( const int );
+ bool testFlags( const int ) const;
+ void clearFlags( const int );
+
+ QPixmap dump() const;
+ QPixmap dump( const int = -1, const int = -1 ) const;
+ QPixmap dump( const QColor&, const int = -1, const int = -1 ) const;
+
+ virtual QSize minimumSizeHint() const;
+ virtual QSize sizeHint() const;
+
+ virtual void show();
+ virtual void hide();
protected:
- virtual void drawContents( QPainter* );
+ virtual void drawContents( QPainter* );
private:
- void updateScale();
- QString getFormat() const;
- QString getLabel( const int ) const;
- QColor getColor( const int ) const;
- double getNumber( const int ) const;
- QSimpleRichText* simpleRichText( const int ) const;
- void drawScale( QPainter*, const bool, const int, const int,
- const int, const int, const bool, const bool, const bool ) const;
- void drawScale( QPainter*, const QColor&, const bool,
- const int, const int, const int, const int,
- const bool, const bool, const bool ) const;
- QSize calculateSize( const bool, const int,
- const bool, const bool, const bool ) const;
-
-#if QT_VER == 3
- friend class QtxColorScale::Dock;
-#endif
+ void updateScale();
+ QString getFormat() const;
+ QString getLabel( const int ) const;
+ QColor getColor( const int ) const;
+ double getNumber( const int ) const;
+ QTextDocument* textDocument( const int ) const;
+ void drawScale( QPainter*, const bool, const int, const int,
+ const int, const int, const bool, const bool, const bool ) const;
+ void drawScale( QPainter*, const QColor&, const bool,
+ const int, const int, const int, const int,
+ const bool, const bool, const bool ) const;
+ QSize calculateSize( const bool, const int,
+ const bool, const bool, const bool ) const;
private:
- double myMin;
- double myMax;
- QString myTitle;
- QString myFormat;
- QString myPrecise;
- int myInterval;
- int myDumpMode;
- int myColorMode;
- int myLabelMode;
-
- QValueList<QColor> myColors;
- QValueList<QString> myLabels;
-
- Dock* myDock;
- int myFlags;
- int myLabelPos;
- int myTitlePos;
- QStyleSheet* myStyleSheet;
+ double myMin; //!< lower limit
+ double myMax; //!< upper limit
+ QString myTitle; //!< title
+ QString myFormat; //!< number presentation format
+ QString myPrecise; //!< double values precision format
+ int myInterval; //!< number of color scale intervals
+ int myDumpMode; //!< dump mode (QtxColorScale::DumpMode)
+ int myColorMode; //!< color mode (QtxColorScale::Mode)
+ int myLabelMode; //!< label mode (QtxColorScale::Mode)
+
+ QList<QColor> myColors; //!< list of colors
+ QList<QString> myLabels; //!< list of labels
+
+ int myFlags; //!< color scale flags (QtxColorScale::Flags)
+ int myLabelPos; //!< label position (QtxColorScale::Position)
+ int myTitlePos; //!< title position (QtxColorScale::Position)
};
#ifdef WIN32
#pragma warning( default:4251 )
#endif
-#endif
+#endif // QTXCOLORSCALE_H