1 // File: QtxColorScale.cxx
2 // Author: Sergey TELKOV
4 #include "QtxColorScale.h"
12 #include <qmainwindow.h>
13 #include <qstringlist.h>
14 #include <qstylesheet.h>
15 #include <qsimplerichtext.h>
19 /*********************************************************************
20 ** Class: QtxColorScale
21 ** Descr: Color Scale widget.
23 *********************************************************************/
25 QtxColorScale::QtxColorScale( QWidget* parent, const char* name, WFlags f )
26 : QFrame( parent, name, f | WResizeNoErase | WRepaintNoErase ),
39 myFlags( AtBorder | WrapTitle )
41 setCaption( tr ( "Color scale" ) );
44 QtxColorScale::QtxColorScale( const int num, QWidget* parent, const char* name, WFlags f )
45 : QFrame( parent, name, f | WResizeNoErase | WRepaintNoErase ),
58 myFlags( AtBorder | WrapTitle )
60 setCaption( tr ( "Color scale" ) );
65 QtxColorScale::QtxColorScale( Dock* dock, const char* name, WFlags f )
66 : QFrame( dock, name, f | WResizeNoErase | WRepaintNoErase ),
79 myFlags( AtBorder | WrapTitle )
81 setCaption( tr ( "Color scale" ) );
86 QtxColorScale::~QtxColorScale()
90 //================================================================
92 // Purpose : Returns minimal limit of scale.
93 //================================================================
95 double QtxColorScale::minimum() const
100 //================================================================
101 // Function : maximum
102 // Purpose : Returns maximal limit of scale.
103 //================================================================
105 double QtxColorScale::maximum() const
110 //================================================================
112 // Purpose : Returns range (minimal and maximal limits) of scale.
113 //================================================================
115 void QtxColorScale::range( double& min, double& max ) const
121 //================================================================
123 // Purpose : Returns the current title string.
124 //================================================================
126 QString QtxColorScale::title() const
131 //================================================================
133 // Purpose : Returns the current format of number presentation in
134 // labels for Auto label mode (sprintf specification).
135 //================================================================
137 QString QtxColorScale::format() const
142 //================================================================
143 // Function : dumpMode
144 // Purpose : Returns dump mode.
145 //================================================================
147 int QtxColorScale::dumpMode() const
152 //================================================================
153 // Function : labelMode
154 // Purpose : Returns label mode.
155 //================================================================
157 int QtxColorScale::labelMode() const
162 //================================================================
163 // Function : colorMode
164 // Purpose : Returns color mode.
165 //================================================================
167 int QtxColorScale::colorMode() const
172 //================================================================
173 // Function : intervalsNumber
174 // Purpose : Returns intervals number of color scale.
175 //================================================================
177 int QtxColorScale::intervalsNumber() const
182 //================================================================
184 // Purpose : Returns the user label of specified interval.
185 //================================================================
187 QString QtxColorScale::label( const int idx ) const
190 if ( idx >= 0 && idx < (int)myLabels.count() )
191 res = *myLabels.at( idx );
195 //================================================================
197 // Purpose : Returns the user color of specified interval.
198 //================================================================
200 QColor QtxColorScale::color( const int idx ) const
203 if ( idx >= 0 && idx < (int)myColors.count() )
204 res = *myColors.at( idx );
208 //================================================================
210 // Purpose : Returns the user labels.
211 //================================================================
213 void QtxColorScale::labels( QStringList& list ) const
218 //================================================================
220 // Purpose : Returns the user color.
221 //================================================================
223 void QtxColorScale::colors( QValueList<QColor>& list ) const
228 //================================================================
229 // Function : labelPosition
230 // Purpose : Returns the label position.
231 //================================================================
233 int QtxColorScale::labelPosition() const
238 //================================================================
239 // Function : titlePosition
240 // Purpose : Returns the title position.
241 //================================================================
243 int QtxColorScale::titlePosition() const
248 //================================================================
249 // Function : setMinimum
250 // Purpose : Sets the minimum limit.
251 //================================================================
253 void QtxColorScale::setMinimum( const double val )
255 setRange( val, maximum() );
258 //================================================================
259 // Function : setMaximum
260 // Purpose : Sets the maximum limit.
261 //================================================================
263 void QtxColorScale::setMaximum( const double val )
265 setRange( minimum(), val );
268 //================================================================
269 // Function : setRange
270 // Purpose : Sets the minimum and maximum limits.
271 //================================================================
273 void QtxColorScale::setRange( const double min, const double max )
275 if ( myMin == min && myMax == max )
281 myPrecise = QString::null;
283 if ( colorMode() == Auto || labelMode() == Auto )
287 //================================================================
288 // Function : setTitle
289 // Purpose : Sets the title string.
290 //================================================================
292 void QtxColorScale::setTitle( const QString& str )
294 if ( myTitle == str )
301 //================================================================
302 // Function : setFormat
303 // Purpose : Sets the format of number presentation in labels for
304 // Auto label mode (sprintf specification).
305 //================================================================
307 void QtxColorScale::setFormat( const QString& format )
309 if ( myFormat == format )
313 myPrecise = QString::null;
314 if ( colorMode() == Auto )
318 //================================================================
319 // Function : setIntervalsNumber
320 // Purpose : Sets the number of intervals.
321 //================================================================
323 void QtxColorScale::setIntervalsNumber( const int num )
325 if ( myInterval == num || num < 1 )
329 myPrecise = QString::null;
334 //================================================================
335 // Function : setLabel
336 // Purpose : Sets the user label for specified interval. If number
337 // of interval is negative then user label will be added
338 // as new at the end of list.
339 //================================================================
341 void QtxColorScale::setLabel( const QString& txt, const int idx )
343 bool changed = false;
344 uint i = idx < 0 ? myLabels.count() : idx;
345 if ( i < myLabels.count() )
347 changed = *myLabels.at( i ) != txt;
353 while ( i >= myLabels.count() )
354 myLabels.append( "" );
361 //================================================================
362 // Function : setColor
363 // Purpose : Sets the user color for specified interval. If number
364 // of interval is negative then user color will be added
365 // as new at the end of list.
366 //================================================================
368 void QtxColorScale::setColor( const QColor& clr, const int idx )
370 bool changed = false;
371 uint i = idx < 0 ? myColors.count() : idx;
372 if ( i < myColors.count() )
374 changed = *myColors.at( i ) != clr;
380 while ( i >= myColors.count() )
381 myColors.append( QColor() );
388 //================================================================
389 // Function : setLabels
390 // Purpose : Replace the all user label with specified list.
391 //================================================================
393 void QtxColorScale::setLabels( const QStringList& list )
395 if ( list.isEmpty() )
402 //================================================================
403 // Function : setColors
404 // Purpose : Replace the all user colors with specified list.
405 //================================================================
407 void QtxColorScale::setColors( const QValueList<QColor>& list )
409 if ( list.isEmpty() )
416 //================================================================
417 // Function : setColorMode
418 // Purpose : Sets the color mode (Auto or User).
419 //================================================================
421 void QtxColorScale::setColorMode( const int mode )
423 if ( myColorMode == mode )
430 //================================================================
431 // Function : setDumpMode
432 // Purpose : Sets the dump mode.
433 //================================================================
435 void QtxColorScale::setDumpMode( const int mode )
440 //================================================================
441 // Function : setLabelMode
442 // Purpose : Sets the label mode (Auto or User).
443 //================================================================
445 void QtxColorScale::setLabelMode( const int mode )
447 if ( myLabelMode != mode )
454 //================================================================
455 // Function : setLabelPosition
456 // Purpose : Sets the label position.
457 //================================================================
459 void QtxColorScale::setLabelPosition( const int pos )
461 if ( myLabelPos != pos && pos >= None && pos <= Center )
468 //================================================================
469 // Function : setTitlePosition
470 // Purpose : Sets the title position.
471 //================================================================
473 void QtxColorScale::setTitlePosition( const int pos )
475 if ( myTitlePos != pos && pos >= None && pos <= Center )
482 //================================================================
483 // Function : setFlags
484 // Purpose : Set the specified flags.
485 //================================================================
487 void QtxColorScale::setFlags( const int flags )
491 if ( prev != myFlags )
495 //================================================================
496 // Function : testFlags
497 // Purpose : Returns true if specified flags are setted.
498 //================================================================
500 bool QtxColorScale::testFlags( const int flags ) const
502 return ( myFlags & flags ) == flags;
505 //================================================================
506 // Function : clearFlags
507 // Purpose : Clear (reset) the specified flags.
508 //================================================================
510 void QtxColorScale::clearFlags( const int flags )
514 if ( prev != myFlags )
518 //================================================================
519 // Function : minimumSizeHint
521 //================================================================
523 QSize QtxColorScale::minimumSizeHint() const
525 QSize sz = calculateSize( true, myFlags, titlePosition() != None, labelPosition() != None, true );
526 return sz + QSize( frameWidth(), frameWidth() );
529 //================================================================
530 // Function : sizeHint
532 //================================================================
534 QSize QtxColorScale::sizeHint() const
536 QSize sz = calculateSize( false, myFlags, titlePosition() != None, labelPosition() != None, true );
537 return sz + QSize( frameWidth(), frameWidth() );
540 //================================================================
541 // Function : calculateSize
542 // Purpose : Dump color scale into pixmap with current size.
543 //================================================================
545 QSize QtxColorScale::calculateSize( const bool min, const int flags, const bool title,
546 const bool labels, const bool colors ) const
548 int num = intervalsNumber();
552 int textHeight = fontMetrics().height();
555 if ( labels && colors )
557 QtxColorScale* that = (QtxColorScale*)this;
558 QString fmt = that->myFormat;
560 for ( int idx = 0; idx < num; idx++ )
561 textWidth = QMAX( textWidth, fontMetrics().width( getLabel( idx ) ) );
564 that->myFormat = that->myFormat.replace( QRegExp( "g" ), "f" );
566 for ( int index = 0; index < num; index++ )
567 textWidth = QMAX( textWidth, fontMetrics().width( getLabel( index ) ) );
569 that->myFormat = fmt;
578 if ( flags & AtBorder )
581 if ( min && title && !myTitle.isEmpty() )
587 scaleWidth = colorWidth + textWidth + ( textWidth ? 3 : 2 ) * spacer;
589 scaleHeight = QMAX( 2 * num, 3 * textHeight );
591 scaleHeight = (int)( 1.5 * ( num + 1 ) * textHeight );
596 QSimpleRichText* srt = simpleRichText( flags );
601 srt->setWidth( &p, scaleWidth );
603 titleHeight = srt->height() + spacer;
604 titleWidth = srt->widthUsed() + 10;
610 int W = QMAX( titleWidth, scaleWidth ) + width() - contentsRect().width();
611 int H = scaleHeight + titleHeight + height() - contentsRect().height();
613 return QSize( W, H );
616 //================================================================
618 // Purpose : Dump color scale into pixmap with current size.
619 //================================================================
621 QPixmap QtxColorScale::dump() const
625 if ( dumpMode() != NoDump )
627 aPix = QPixmap( size() );
628 if ( !aPix.isNull() )
630 bool scale = ( myDumpMode == ScaleDump || myDumpMode == FullDump );
631 bool label = ( myDumpMode == ScaleDump || myDumpMode == FullDump ) &&
632 labelPosition() != None;
633 bool title = ( myDumpMode == TitleDump || myDumpMode == FullDump ) &&
634 titlePosition() != None;
637 QColor bgc = backgroundColor();
639 QColor bgc = paletteBackgroundColor();
643 p.fillRect( 0, 0, aPix.width(), aPix.height(), bgc );
644 drawScale( &p, bgc, false, 0, 0, aPix.width(), aPix.height(), title, label, scale );
652 //================================================================
654 // Purpose : Dump color scale into pixmap with specified size.
655 //================================================================
657 QPixmap QtxColorScale::dump( const int w, const int h ) const
660 return dump( backgroundColor(), w, h );
662 return dump( paletteBackgroundColor(), w, h );
666 //================================================================
668 // Purpose : Dump color scale into pixmap with specified size
669 // and background color.
670 //================================================================
672 QPixmap QtxColorScale::dump( const QColor& bg, const int w, const int h ) const
675 if ( dumpMode() != NoDump )
677 bool scale = ( myDumpMode == ScaleDump || myDumpMode == FullDump );
678 bool label = ( myDumpMode == ScaleDump || myDumpMode == FullDump ) &&
679 labelPosition() != None;
680 bool title = ( myDumpMode == TitleDump || myDumpMode == FullDump ) &&
681 titlePosition() != None;
685 if ( W < 0 || H < 0 )
687 QSize sz = calculateSize( false, myFlags & ~WrapTitle, title, label, scale );
695 aPix = QPixmap( W, H );
696 if ( !aPix.isNull() )
700 p.fillRect( 0, 0, aPix.width(), aPix.height(), bg );
701 drawScale( &p, bg, false, 0, 0, aPix.width(), aPix.height(), title, label, scale );
709 //================================================================
711 // Purpose : Show the color scale. [Reimplemented]
712 //================================================================
714 void QtxColorScale::show()
724 //================================================================
726 // Purpose : Hides the color scale. [Reimplemented]
727 //================================================================
729 void QtxColorScale::hide()
733 myDock->deactivate();
739 //================================================================
740 // Function : drawContents
741 // Purpose : Draw color scale contents. [Reimplemented]
742 //================================================================
744 void QtxColorScale::drawContents( QPainter* p )
746 if ( !isUpdatesEnabled() )
749 QRect aDrawRect = contentsRect();
751 drawScale( p, false/*testFlags( Transparent )*/, aDrawRect.x(),
752 aDrawRect.y(), aDrawRect.width(), aDrawRect.height(),
753 titlePosition() != None, labelPosition() != None, true );
756 //================================================================
757 // Function : drawScale
758 // Purpose : Draw color scale contents.
759 //================================================================
761 void QtxColorScale::drawScale( QPainter* p, const bool transp, const int X, const int Y,
762 const int W, const int H, const bool title,
763 const bool label, const bool scale ) const
765 QPixmap cache( W, H );
766 QPainter cp( &cache );
769 drawScale( &cp, backgroundColor(), transp, 0, 0, W, H, title, label, scale );
771 drawScale( &cp, paletteBackgroundColor(), transp, 0, 0, W, H, title, label, scale );
775 p->drawPixmap( X, Y, cache );
778 //================================================================
779 // Function : drawScale
780 // Purpose : Draw color scale contents.
781 //================================================================
783 void QtxColorScale::drawScale( QPainter* p, const QColor& bg, const bool transp,
784 const int X, const int Y, const int W, const int H,
785 const bool drawTitle, const bool drawLabel, const bool drawColors ) const
788 p->fillRect( X, Y, W, H, bg );
790 int num = intervalsNumber();
792 int labPos = labelPosition();
796 int textHeight = p->fontMetrics().height();
798 QString aTitle = title();
803 if ( qGray( bg.rgb() ) < 128 )
804 p->setPen( QColor( 255, 255, 255 ) );
806 p->setPen( QColor( 0, 0, 0 ) );
811 QSimpleRichText* srt = simpleRichText( myFlags );
814 srt->setWidth( p, W - 10 );
815 titleHeight = srt->height() + spacer;
816 titleWidth = srt->widthUsed();
817 QColorGroup cg = colorGroup();
818 cg.setColor( QColorGroup::Text, p->pen().color() );
819 srt->draw( p, X + 5, Y, QRect( 0, 0, srt->width(), srt->height() ), cg );
825 bool reverse = testFlags( Reverse );
827 QValueList<QColor> colors;
828 QValueList<QString> labels;
829 for ( int idx = 0; idx < num; idx++ )
833 colors.append( getColor( idx ) );
834 labels.append( getLabel( idx ) );
838 colors.prepend( getColor( idx ) );
839 labels.prepend( getLabel( idx ) );
843 if ( testFlags( AtBorder ) )
846 labels.append( getLabel( num ) );
848 labels.prepend( getLabel( num ) );
850 textWidth = QMAX( textWidth, p->fontMetrics().width( labels.last() ) );
855 const QFontMetrics& fm = p->fontMetrics();
856 for ( QStringList::ConstIterator it = labels.begin(); it != labels.end(); ++it )
857 textWidth = QMAX( textWidth, fm.width( *it) );
860 int lab = labels.count();
862 double spc = ( H - ( ( QMIN( lab, 2 ) + QABS( lab - num - 1 ) ) * textHeight ) - titleHeight );
863 double val = spc != 0 ? 1.0 * ( lab - QMIN( lab, 2 ) ) * textHeight / spc : 0;
865 double fPart = modf( val, &iPart );
866 int filter = (int)iPart + ( fPart != 0 ? 1 : 0 );
867 filter = QMAX( filter, 1 );
869 double step = 1.0 * ( H - ( lab - num + QABS( lab - num - 1 ) ) * textHeight - titleHeight ) / num;
871 int ascent = p->fontMetrics().ascent();
872 int colorWidth = QMAX( 5, QMIN( 20, W - textWidth - 3 * spacer ) );
873 if ( labPos == Center || !drawLabel )
874 colorWidth = W - 2 * spacer;
881 x += textWidth + ( textWidth ? 1 : 0 ) * spacer;
885 double offset = 1.0 * textHeight / 2 * ( lab - num + QABS( lab - num - 1 ) ) + titleHeight;
886 QValueList<QColor>::Iterator cit = colors.begin();
888 for ( ci = 0; cit != colors.end() && drawColors; ++cit, ci++ )
890 int y = (int)( Y + ci * step + offset );
891 int h = (int)( Y + ( ci + 1 ) * step + offset ) - y;
892 p->fillRect( x, y, colorWidth, h, *cit );
896 p->drawRect( int( x - 1 ), int( Y + offset - 1 ), int( colorWidth + 2 ), int( ci * step + 2 ) );
899 offset = 1.0 * QABS( lab - num - 1 ) * ( step - textHeight ) / 2 +
900 1.0 * QABS( lab - num - 1 ) * textHeight / 2;
901 offset += titleHeight;
902 if ( drawLabel && !labels.isEmpty() )
906 int last1( i1 ), last2( i2 );
911 x += ( colorWidth - textWidth ) / 2;
914 x += colorWidth + spacer;
917 while ( i2 - i1 >= filter || ( i2 == 0 && i1 == 0 ) )
920 int pos2 = lab - 1 - i2;
921 if ( filter && !( pos1 % filter ) )
923 p->drawText( x, (int)( Y + i1 * step + ascent + offset ), *labels.at( i1 ) );
926 if ( filter && !( pos2 % filter ) )
928 p->drawText( x, (int)( Y + i2 * step + ascent + offset ), *labels.at( i2 ) );
936 while ( pos <= i2 && i0 == -1 )
938 if ( filter && !( pos % filter ) &&
939 QABS( pos - last1 ) >= filter && QABS( pos - last2 ) >= filter )
945 p->drawText( x, (int)( Y + i0 * step + ascent + offset ), *labels.at( i0 ) );
949 //================================================================
950 // Function : getFormat
951 // Purpose : Returns the format for number labels.
952 //================================================================
954 QString QtxColorScale::getFormat() const
956 QString aFormat = format();
958 if ( !testFlags( PreciseFormat ) || testFlags( Integer ) )
961 if ( !myPrecise.isEmpty() )
964 if ( aFormat.find( QRegExp( "^(%[0-9]*.?[0-9]*[fegFEG])$" ) ) != 0 )
967 int pos1 = aFormat.find( '.' );
968 int pos2 = aFormat.find( QRegExp( "[fegFEG]") );
974 aLocFormat = aFormat.mid( 0, pos1 + 1 );
975 precision = aFormat.mid( pos1 + 1, pos2 - pos1 - 1 ).toInt();
982 QtxColorScale* that = (QtxColorScale*)this;
984 // calculate format, maximum precision limited
985 // to 7 digits after the decimal point.
986 while ( myPrecise.isEmpty() && precision < 7 )
988 QString aTmpFormat = aLocFormat;
989 aTmpFormat += QString( "%1" ).arg( precision );
990 aTmpFormat += aFormat.mid( pos2 );
992 QMap<QString, int> map;
993 bool isHasTwinz = false;
995 for ( int idx = 0; idx < intervalsNumber() && !isHasTwinz; idx++ )
997 double val = getNumber( idx );
998 QString tmpname = QString().sprintf( aTmpFormat, val );
999 isHasTwinz = map.contains( tmpname );
1000 map.insert( tmpname, 1 );
1004 that->myPrecise = aTmpFormat;
1008 if ( !myPrecise.isEmpty() )
1009 aFormat = myPrecise;
1014 //================================================================
1015 // Function : getNumber
1016 // Purpose : Returns the number for specified interval.
1017 //================================================================
1019 double QtxColorScale::getNumber( const int idx ) const
1022 if ( intervalsNumber() > 0 )
1023 val = minimum() + idx * ( QABS( maximum() - minimum() ) / intervalsNumber() );
1027 //================================================================
1028 // Function : getLabel
1029 // Purpose : Returns the label for specified interval according
1030 // to the current label mode.
1031 //================================================================
1033 QString QtxColorScale::getLabel( const int idx ) const
1036 if ( labelMode() == User )
1040 double val = getNumber( idx );
1041 res = QString().sprintf( getFormat(), testFlags( Integer ) ? (int)val : val );
1046 //================================================================
1047 // Function : getColor
1048 // Purpose : Returns the color for specified interval according
1049 // to the current color mode.
1050 //================================================================
1052 QColor QtxColorScale::getColor( const int idx ) const
1055 if ( colorMode() == User )
1058 res = Qtx::scaleColor( idx, 0, intervalsNumber() - 1 );
1062 //================================================================
1063 // Function : updateScale
1064 // Purpose : Update color scale if it required.
1065 //================================================================
1067 void QtxColorScale::updateScale()
1073 //================================================================
1074 // Function : simpleRichText
1075 // Purpose : Return QSimpleRichText object for title. If title
1076 // not defined (empty string) then return null pointer.
1077 // Object should be deleted by caller function.
1078 //================================================================
1080 QSimpleRichText* QtxColorScale::simpleRichText( const int flags ) const
1082 QSimpleRichText* srt = 0;
1085 switch ( titlePosition() )
1088 aTitle = QString( "<p align=\"left\">%1</p>" );
1091 aTitle = QString( "<p align=\"right\">%1</p>" );
1094 aTitle = QString( "<p align=\"center\">%1</p>" );
1101 if ( !aTitle.isEmpty() && !title().isEmpty() )
1103 if ( !myStyleSheet )
1105 QtxColorScale* that = (QtxColorScale*)this;
1106 that->myStyleSheet = new QStyleSheet( that );
1111 QStyleSheetItem* item = myStyleSheet->item( "p" );
1113 item->setWhiteSpaceMode( flags & WrapTitle ? QStyleSheetItem::WhiteSpaceNormal :
1114 QStyleSheetItem::WhiteSpaceNoWrap );
1117 aTitle = aTitle.arg( title() );
1118 srt = new QSimpleRichText( aTitle, font(), QString::null, myStyleSheet );
1126 /*********************************************************************
1127 ** Class: QtxColorScale::Dock
1128 ** Descr: Dockable window contains the color scale.
1130 *********************************************************************/
1132 //================================================================
1134 // Purpose : Constructor.
1135 //================================================================
1137 QtxColorScale::Dock::Dock( Place p, QWidget* parent, const char* name, WFlags f )
1138 : QDockWindow( p, parent, name, f ),
1139 myBlockShow( false ),
1140 myBlockResize( false )
1142 myScale = new QtxColorScale( this );
1144 setWidget( myScale );
1146 setCloseMode( Always );
1147 setMovingEnabled( true );
1148 setResizeEnabled( true );
1149 setHorizontalStretchable( false );
1151 setCaption( tr ( "Color scale" ) );
1154 //================================================================
1156 // Purpose : Destructor.
1157 //================================================================
1159 QtxColorScale::Dock::~Dock()
1163 //================================================================
1164 // Function : colorScale
1165 // Purpose : Returns color scale widget.
1166 //================================================================
1168 QtxColorScale* QtxColorScale::Dock::colorScale() const
1173 //================================================================
1174 // Function : activate
1175 // Purpose : Set the dockable window is visible for main window.
1176 //================================================================
1178 void QtxColorScale::Dock::activate()
1183 QMainWindow* mw = 0;
1184 QWidget* p = parentWidget();
1187 if ( p->inherits( "QMainWindow" ) )
1188 mw = (QMainWindow*)p;
1189 p = p->parentWidget();
1192 mw->setAppropriate( this, true );
1195 //================================================================
1196 // Function : deactivate
1197 // Purpose : Set the dockable window is hidden for main window.
1198 //================================================================
1200 void QtxColorScale::Dock::deactivate()
1205 QMainWindow* mw = 0;
1206 QWidget* p = parentWidget();
1209 if ( p->inherits( "QMainWindow" ) )
1210 mw = (QMainWindow*)p;
1211 p = p->parentWidget();
1214 mw->setAppropriate( this, false );
1217 //================================================================
1218 // Function : isActive
1219 // Purpose : Returns true if the dockable window is visible.
1220 //================================================================
1222 bool QtxColorScale::Dock::isActive() const
1224 QMainWindow* mw = 0;
1225 QWidget* p = parentWidget();
1228 if ( p->inherits( "QMainWindow" ) )
1229 mw = (QMainWindow*)p;
1230 p = p->parentWidget();
1233 return mw->appropriate( (QDockWindow*)this );
1238 //================================================================
1240 // Purpose : Reimplemented for internal reasons.
1241 //================================================================
1243 void QtxColorScale::Dock::show()
1245 bool f = myBlockShow;
1247 QDockWindow::show();
1251 //================================================================
1253 // Purpose : Reimplemented for internal reasons.
1254 //================================================================
1256 void QtxColorScale::Dock::hide()
1258 bool f = myBlockShow;
1259 myBlockShow = false;
1260 QDockWindow::hide();
1264 //================================================================
1265 // Function : resize
1266 // Purpose : Make extent width as maximum value of widget width.
1267 //================================================================
1269 void QtxColorScale::Dock::resize( int w, int h )
1271 QDockWindow::resize( w, h );
1273 if ( myBlockResize )
1276 if ( orientation() == Qt::Vertical )
1277 setFixedExtentWidth( QMAX( fixedExtent().width(), w ) );
1278 else if ( orientation() == Qt::Horizontal )
1279 setFixedExtentHeight( QMAX( fixedExtent().height(), h ) );
1282 //================================================================
1283 // Function : setOrientation
1285 //================================================================
1287 void QtxColorScale::Dock::setOrientation( Orientation o )
1289 bool b = myBlockResize;
1290 myBlockResize = true;
1291 QDockWindow::setOrientation( o );