1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 // File: QtxColorScale.cxx
20 // Author: Sergey TELKOV
22 #include "QtxColorScale.h"
30 #include <qmainwindow.h>
31 #include <qstringlist.h>
32 #include <qstylesheet.h>
33 #include <qsimplerichtext.h>
37 /*********************************************************************
38 ** Class: QtxColorScale
39 ** Descr: Color Scale widget.
41 *********************************************************************/
43 QtxColorScale::QtxColorScale( QWidget* parent, const char* name, WFlags f )
44 : QFrame( parent, name, f | WResizeNoErase | WRepaintNoErase ),
57 myFlags( AtBorder | WrapTitle )
59 setCaption( tr ( "Color scale" ) );
62 QtxColorScale::QtxColorScale( const int num, QWidget* parent, const char* name, WFlags f )
63 : QFrame( parent, name, f | WResizeNoErase | WRepaintNoErase ),
76 myFlags( AtBorder | WrapTitle )
78 setCaption( tr ( "Color scale" ) );
83 QtxColorScale::QtxColorScale( Dock* dock, const char* name, WFlags f )
84 : QFrame( dock, name, f | WResizeNoErase | WRepaintNoErase ),
97 myFlags( AtBorder | WrapTitle )
99 setCaption( tr ( "Color scale" ) );
104 QtxColorScale::~QtxColorScale()
108 //================================================================
109 // Function : minimum
110 // Purpose : Returns minimal limit of scale.
111 //================================================================
113 double QtxColorScale::minimum() const
118 //================================================================
119 // Function : maximum
120 // Purpose : Returns maximal limit of scale.
121 //================================================================
123 double QtxColorScale::maximum() const
128 //================================================================
130 // Purpose : Returns range (minimal and maximal limits) of scale.
131 //================================================================
133 void QtxColorScale::range( double& min, double& max ) const
139 //================================================================
141 // Purpose : Returns the current title string.
142 //================================================================
144 QString QtxColorScale::title() const
149 //================================================================
151 // Purpose : Returns the current format of number presentation in
152 // labels for Auto label mode (sprintf specification).
153 //================================================================
155 QString QtxColorScale::format() const
160 //================================================================
161 // Function : dumpMode
162 // Purpose : Returns dump mode.
163 //================================================================
165 int QtxColorScale::dumpMode() const
170 //================================================================
171 // Function : labelMode
172 // Purpose : Returns label mode.
173 //================================================================
175 int QtxColorScale::labelMode() const
180 //================================================================
181 // Function : colorMode
182 // Purpose : Returns color mode.
183 //================================================================
185 int QtxColorScale::colorMode() const
190 //================================================================
191 // Function : intervalsNumber
192 // Purpose : Returns intervals number of color scale.
193 //================================================================
195 int QtxColorScale::intervalsNumber() const
200 //================================================================
202 // Purpose : Returns the user label of specified interval.
203 //================================================================
205 QString QtxColorScale::label( const int idx ) const
208 if ( idx >= 0 && idx < (int)myLabels.count() )
209 res = *myLabels.at( idx );
213 //================================================================
215 // Purpose : Returns the user color of specified interval.
216 //================================================================
218 QColor QtxColorScale::color( const int idx ) const
221 if ( idx >= 0 && idx < (int)myColors.count() )
222 res = *myColors.at( idx );
226 //================================================================
228 // Purpose : Returns the user labels.
229 //================================================================
231 void QtxColorScale::labels( QStringList& list ) const
236 //================================================================
238 // Purpose : Returns the user color.
239 //================================================================
241 void QtxColorScale::colors( QValueList<QColor>& list ) const
246 //================================================================
247 // Function : labelPosition
248 // Purpose : Returns the label position.
249 //================================================================
251 int QtxColorScale::labelPosition() const
256 //================================================================
257 // Function : titlePosition
258 // Purpose : Returns the title position.
259 //================================================================
261 int QtxColorScale::titlePosition() const
266 //================================================================
267 // Function : setMinimum
268 // Purpose : Sets the minimum limit.
269 //================================================================
271 void QtxColorScale::setMinimum( const double val )
273 setRange( val, maximum() );
276 //================================================================
277 // Function : setMaximum
278 // Purpose : Sets the maximum limit.
279 //================================================================
281 void QtxColorScale::setMaximum( const double val )
283 setRange( minimum(), val );
286 //================================================================
287 // Function : setRange
288 // Purpose : Sets the minimum and maximum limits.
289 //================================================================
291 void QtxColorScale::setRange( const double min, const double max )
293 if ( myMin == min && myMax == max )
299 myPrecise = QString::null;
301 if ( colorMode() == Auto || labelMode() == Auto )
305 //================================================================
306 // Function : setTitle
307 // Purpose : Sets the title string.
308 //================================================================
310 void QtxColorScale::setTitle( const QString& str )
312 if ( myTitle == str )
319 //================================================================
320 // Function : setFormat
321 // Purpose : Sets the format of number presentation in labels for
322 // Auto label mode (sprintf specification).
323 //================================================================
325 void QtxColorScale::setFormat( const QString& format )
327 if ( myFormat == format )
331 myPrecise = QString::null;
332 if ( colorMode() == Auto )
336 //================================================================
337 // Function : setIntervalsNumber
338 // Purpose : Sets the number of intervals.
339 //================================================================
341 void QtxColorScale::setIntervalsNumber( const int num )
343 if ( myInterval == num || num < 1 )
347 myPrecise = QString::null;
352 //================================================================
353 // Function : setLabel
354 // Purpose : Sets the user label for specified interval. If number
355 // of interval is negative then user label will be added
356 // as new at the end of list.
357 //================================================================
359 void QtxColorScale::setLabel( const QString& txt, const int idx )
361 bool changed = false;
362 uint i = idx < 0 ? myLabels.count() : idx;
363 if ( i < myLabels.count() )
365 changed = *myLabels.at( i ) != txt;
371 while ( i >= myLabels.count() )
372 myLabels.append( "" );
379 //================================================================
380 // Function : setColor
381 // Purpose : Sets the user color for specified interval. If number
382 // of interval is negative then user color will be added
383 // as new at the end of list.
384 //================================================================
386 void QtxColorScale::setColor( const QColor& clr, const int idx )
388 bool changed = false;
389 uint i = idx < 0 ? myColors.count() : idx;
390 if ( i < myColors.count() )
392 changed = *myColors.at( i ) != clr;
398 while ( i >= myColors.count() )
399 myColors.append( QColor() );
406 //================================================================
407 // Function : setLabels
408 // Purpose : Replace the all user label with specified list.
409 //================================================================
411 void QtxColorScale::setLabels( const QStringList& list )
413 if ( list.isEmpty() )
420 //================================================================
421 // Function : setColors
422 // Purpose : Replace the all user colors with specified list.
423 //================================================================
425 void QtxColorScale::setColors( const QValueList<QColor>& list )
427 if ( list.isEmpty() )
434 //================================================================
435 // Function : setColorMode
436 // Purpose : Sets the color mode (Auto or User).
437 //================================================================
439 void QtxColorScale::setColorMode( const int mode )
441 if ( myColorMode == mode )
448 //================================================================
449 // Function : setDumpMode
450 // Purpose : Sets the dump mode.
451 //================================================================
453 void QtxColorScale::setDumpMode( const int mode )
458 //================================================================
459 // Function : setLabelMode
460 // Purpose : Sets the label mode (Auto or User).
461 //================================================================
463 void QtxColorScale::setLabelMode( const int mode )
465 if ( myLabelMode != mode )
472 //================================================================
473 // Function : setLabelPosition
474 // Purpose : Sets the label position.
475 //================================================================
477 void QtxColorScale::setLabelPosition( const int pos )
479 if ( myLabelPos != pos && pos >= None && pos <= Center )
486 //================================================================
487 // Function : setTitlePosition
488 // Purpose : Sets the title position.
489 //================================================================
491 void QtxColorScale::setTitlePosition( const int pos )
493 if ( myTitlePos != pos && pos >= None && pos <= Center )
500 //================================================================
501 // Function : setFlags
502 // Purpose : Set the specified flags.
503 //================================================================
505 void QtxColorScale::setFlags( const int flags )
509 if ( prev != myFlags )
513 //================================================================
514 // Function : testFlags
515 // Purpose : Returns true if specified flags are setted.
516 //================================================================
518 bool QtxColorScale::testFlags( const int flags ) const
520 return ( myFlags & flags ) == flags;
523 //================================================================
524 // Function : clearFlags
525 // Purpose : Clear (reset) the specified flags.
526 //================================================================
528 void QtxColorScale::clearFlags( const int flags )
532 if ( prev != myFlags )
536 //================================================================
537 // Function : minimumSizeHint
539 //================================================================
541 QSize QtxColorScale::minimumSizeHint() const
543 QSize sz = calculateSize( true, myFlags, titlePosition() != None, labelPosition() != None, true );
544 return sz + QSize( frameWidth(), frameWidth() );
547 //================================================================
548 // Function : sizeHint
550 //================================================================
552 QSize QtxColorScale::sizeHint() const
554 QSize sz = calculateSize( false, myFlags, titlePosition() != None, labelPosition() != None, true );
555 return sz + QSize( frameWidth(), frameWidth() );
558 //================================================================
559 // Function : calculateSize
560 // Purpose : Dump color scale into pixmap with current size.
561 //================================================================
563 QSize QtxColorScale::calculateSize( const bool min, const int flags, const bool title,
564 const bool labels, const bool colors ) const
566 int num = intervalsNumber();
570 int textHeight = fontMetrics().height();
573 if ( labels && colors )
575 QtxColorScale* that = (QtxColorScale*)this;
576 QString fmt = that->myFormat;
578 for ( int idx = 0; idx < num; idx++ )
579 textWidth = QMAX( textWidth, fontMetrics().width( getLabel( idx ) ) );
582 that->myFormat = that->myFormat.replace( QRegExp( "g" ), "f" );
584 for ( int index = 0; index < num; index++ )
585 textWidth = QMAX( textWidth, fontMetrics().width( getLabel( index ) ) );
587 that->myFormat = fmt;
596 if ( flags & AtBorder )
599 if ( min && title && !myTitle.isEmpty() )
605 scaleWidth = colorWidth + textWidth + ( textWidth ? 3 : 2 ) * spacer;
607 scaleHeight = QMAX( 2 * num, 3 * textHeight );
609 scaleHeight = (int)( 1.5 * ( num + 1 ) * textHeight );
614 QSimpleRichText* srt = simpleRichText( flags );
619 srt->setWidth( &p, scaleWidth );
621 titleHeight = srt->height() + spacer;
622 titleWidth = srt->widthUsed() + 10;
628 int W = QMAX( titleWidth, scaleWidth ) + width() - contentsRect().width();
629 int H = scaleHeight + titleHeight + height() - contentsRect().height();
631 return QSize( W, H );
634 //================================================================
636 // Purpose : Dump color scale into pixmap with current size.
637 //================================================================
639 QPixmap QtxColorScale::dump() const
643 if ( dumpMode() != NoDump )
645 aPix = QPixmap( size() );
646 if ( !aPix.isNull() )
648 bool scale = ( myDumpMode == ScaleDump || myDumpMode == FullDump );
649 bool label = ( myDumpMode == ScaleDump || myDumpMode == FullDump ) &&
650 labelPosition() != None;
651 bool title = ( myDumpMode == TitleDump || myDumpMode == FullDump ) &&
652 titlePosition() != None;
655 QColor bgc = backgroundColor();
657 QColor bgc = paletteBackgroundColor();
661 p.fillRect( 0, 0, aPix.width(), aPix.height(), bgc );
662 drawScale( &p, bgc, false, 0, 0, aPix.width(), aPix.height(), title, label, scale );
670 //================================================================
672 // Purpose : Dump color scale into pixmap with specified size.
673 //================================================================
675 QPixmap QtxColorScale::dump( const int w, const int h ) const
678 return dump( backgroundColor(), w, h );
680 return dump( paletteBackgroundColor(), w, h );
684 //================================================================
686 // Purpose : Dump color scale into pixmap with specified size
687 // and background color.
688 //================================================================
690 QPixmap QtxColorScale::dump( const QColor& bg, const int w, const int h ) const
693 if ( dumpMode() != NoDump )
695 bool scale = ( myDumpMode == ScaleDump || myDumpMode == FullDump );
696 bool label = ( myDumpMode == ScaleDump || myDumpMode == FullDump ) &&
697 labelPosition() != None;
698 bool title = ( myDumpMode == TitleDump || myDumpMode == FullDump ) &&
699 titlePosition() != None;
703 if ( W < 0 || H < 0 )
705 QSize sz = calculateSize( false, myFlags & ~WrapTitle, title, label, scale );
713 aPix = QPixmap( W, H );
714 if ( !aPix.isNull() )
718 p.fillRect( 0, 0, aPix.width(), aPix.height(), bg );
719 drawScale( &p, bg, false, 0, 0, aPix.width(), aPix.height(), title, label, scale );
727 //================================================================
729 // Purpose : Show the color scale. [Reimplemented]
730 //================================================================
732 void QtxColorScale::show()
742 //================================================================
744 // Purpose : Hides the color scale. [Reimplemented]
745 //================================================================
747 void QtxColorScale::hide()
751 myDock->deactivate();
757 //================================================================
758 // Function : drawContents
759 // Purpose : Draw color scale contents. [Reimplemented]
760 //================================================================
762 void QtxColorScale::drawContents( QPainter* p )
764 if ( !isUpdatesEnabled() )
767 QRect aDrawRect = contentsRect();
769 drawScale( p, false/*testFlags( Transparent )*/, aDrawRect.x(),
770 aDrawRect.y(), aDrawRect.width(), aDrawRect.height(),
771 titlePosition() != None, labelPosition() != None, true );
774 //================================================================
775 // Function : drawScale
776 // Purpose : Draw color scale contents.
777 //================================================================
779 void QtxColorScale::drawScale( QPainter* p, const bool transp, const int X, const int Y,
780 const int W, const int H, const bool title,
781 const bool label, const bool scale ) const
783 QPixmap cache( W, H );
784 QPainter cp( &cache );
787 drawScale( &cp, backgroundColor(), transp, 0, 0, W, H, title, label, scale );
789 drawScale( &cp, paletteBackgroundColor(), transp, 0, 0, W, H, title, label, scale );
793 p->drawPixmap( X, Y, cache );
796 //================================================================
797 // Function : drawScale
798 // Purpose : Draw color scale contents.
799 //================================================================
801 void QtxColorScale::drawScale( QPainter* p, const QColor& bg, const bool transp,
802 const int X, const int Y, const int W, const int H,
803 const bool drawTitle, const bool drawLabel, const bool drawColors ) const
806 p->fillRect( X, Y, W, H, bg );
808 int num = intervalsNumber();
810 int labPos = labelPosition();
814 int textHeight = p->fontMetrics().height();
816 QString aTitle = title();
821 if ( qGray( bg.rgb() ) < 128 )
822 p->setPen( QColor( 255, 255, 255 ) );
824 p->setPen( QColor( 0, 0, 0 ) );
829 QSimpleRichText* srt = simpleRichText( myFlags );
832 srt->setWidth( p, W - 10 );
833 titleHeight = srt->height() + spacer;
834 titleWidth = srt->widthUsed();
835 QColorGroup cg = colorGroup();
836 cg.setColor( QColorGroup::Text, p->pen().color() );
837 srt->draw( p, X + 5, Y, QRect( 0, 0, srt->width(), srt->height() ), cg );
843 bool reverse = testFlags( Reverse );
845 QValueList<QColor> colors;
846 QValueList<QString> labels;
847 for ( int idx = 0; idx < num; idx++ )
851 colors.append( getColor( idx ) );
852 labels.append( getLabel( idx ) );
856 colors.prepend( getColor( idx ) );
857 labels.prepend( getLabel( idx ) );
861 if ( testFlags( AtBorder ) )
864 labels.append( getLabel( num ) );
866 labels.prepend( getLabel( num ) );
868 textWidth = QMAX( textWidth, p->fontMetrics().width( labels.last() ) );
873 const QFontMetrics& fm = p->fontMetrics();
874 for ( QStringList::ConstIterator it = labels.begin(); it != labels.end(); ++it )
875 textWidth = QMAX( textWidth, fm.width( *it) );
878 int lab = labels.count();
880 double spc = ( H - ( ( QMIN( lab, 2 ) + QABS( lab - num - 1 ) ) * textHeight ) - titleHeight );
881 double val = spc != 0 ? 1.0 * ( lab - QMIN( lab, 2 ) ) * textHeight / spc : 0;
883 double fPart = modf( val, &iPart );
884 int filter = (int)iPart + ( fPart != 0 ? 1 : 0 );
885 filter = QMAX( filter, 1 );
887 double step = 1.0 * ( H - ( lab - num + QABS( lab - num - 1 ) ) * textHeight - titleHeight ) / num;
889 int ascent = p->fontMetrics().ascent();
890 int colorWidth = QMAX( 5, QMIN( 20, W - textWidth - 3 * spacer ) );
891 if ( labPos == Center || !drawLabel )
892 colorWidth = W - 2 * spacer;
899 x += textWidth + ( textWidth ? 1 : 0 ) * spacer;
903 double offset = 1.0 * textHeight / 2 * ( lab - num + QABS( lab - num - 1 ) ) + titleHeight;
904 QValueList<QColor>::Iterator cit = colors.begin();
906 for ( ci = 0; cit != colors.end() && drawColors; ++cit, ci++ )
908 int y = (int)( Y + ci * step + offset );
909 int h = (int)( Y + ( ci + 1 ) * step + offset ) - y;
910 p->fillRect( x, y, colorWidth, h, *cit );
914 p->drawRect( int( x - 1 ), int( Y + offset - 1 ), int( colorWidth + 2 ), int( ci * step + 2 ) );
917 offset = 1.0 * QABS( lab - num - 1 ) * ( step - textHeight ) / 2 +
918 1.0 * QABS( lab - num - 1 ) * textHeight / 2;
919 offset += titleHeight;
920 if ( drawLabel && !labels.isEmpty() )
924 int last1( i1 ), last2( i2 );
929 x += ( colorWidth - textWidth ) / 2;
932 x += colorWidth + spacer;
935 while ( i2 - i1 >= filter || ( i2 == 0 && i1 == 0 ) )
938 int pos2 = lab - 1 - i2;
939 if ( filter && !( pos1 % filter ) )
941 p->drawText( x, (int)( Y + i1 * step + ascent + offset ), *labels.at( i1 ) );
944 if ( filter && !( pos2 % filter ) )
946 p->drawText( x, (int)( Y + i2 * step + ascent + offset ), *labels.at( i2 ) );
954 while ( pos <= i2 && i0 == -1 )
956 if ( filter && !( pos % filter ) &&
957 QABS( pos - last1 ) >= filter && QABS( pos - last2 ) >= filter )
963 p->drawText( x, (int)( Y + i0 * step + ascent + offset ), *labels.at( i0 ) );
967 //================================================================
968 // Function : getFormat
969 // Purpose : Returns the format for number labels.
970 //================================================================
972 QString QtxColorScale::getFormat() const
974 QString aFormat = format();
976 if ( !testFlags( PreciseFormat ) || testFlags( Integer ) )
979 if ( !myPrecise.isEmpty() )
982 if ( aFormat.find( QRegExp( "^(%[0-9]*.?[0-9]*[fegFEG])$" ) ) != 0 )
985 int pos1 = aFormat.find( '.' );
986 int pos2 = aFormat.find( QRegExp( "[fegFEG]") );
992 aLocFormat = aFormat.mid( 0, pos1 + 1 );
993 precision = aFormat.mid( pos1 + 1, pos2 - pos1 - 1 ).toInt();
1000 QtxColorScale* that = (QtxColorScale*)this;
1002 // calculate format, maximum precision limited
1003 // to 7 digits after the decimal point.
1004 while ( myPrecise.isEmpty() && precision < 7 )
1006 QString aTmpFormat = aLocFormat;
1007 aTmpFormat += QString( "%1" ).arg( precision );
1008 aTmpFormat += aFormat.mid( pos2 );
1010 QMap<QString, int> map;
1011 bool isHasTwinz = false;
1013 for ( int idx = 0; idx < intervalsNumber() && !isHasTwinz; idx++ )
1015 double val = getNumber( idx );
1016 QString tmpname = QString().sprintf( aTmpFormat, val );
1017 isHasTwinz = map.contains( tmpname );
1018 map.insert( tmpname, 1 );
1022 that->myPrecise = aTmpFormat;
1026 if ( !myPrecise.isEmpty() )
1027 aFormat = myPrecise;
1032 //================================================================
1033 // Function : getNumber
1034 // Purpose : Returns the number for specified interval.
1035 //================================================================
1037 double QtxColorScale::getNumber( const int idx ) const
1040 if ( intervalsNumber() > 0 )
1041 val = minimum() + idx * ( QABS( maximum() - minimum() ) / intervalsNumber() );
1045 //================================================================
1046 // Function : getLabel
1047 // Purpose : Returns the label for specified interval according
1048 // to the current label mode.
1049 //================================================================
1051 QString QtxColorScale::getLabel( const int idx ) const
1054 if ( labelMode() == User )
1058 double val = getNumber( idx );
1059 res = QString().sprintf( getFormat(), testFlags( Integer ) ? (int)val : val );
1064 //================================================================
1065 // Function : getColor
1066 // Purpose : Returns the color for specified interval according
1067 // to the current color mode.
1068 //================================================================
1070 QColor QtxColorScale::getColor( const int idx ) const
1073 if ( colorMode() == User )
1076 res = Qtx::scaleColor( idx, 0, intervalsNumber() - 1 );
1080 //================================================================
1081 // Function : updateScale
1082 // Purpose : Update color scale if it required.
1083 //================================================================
1085 void QtxColorScale::updateScale()
1091 //================================================================
1092 // Function : simpleRichText
1093 // Purpose : Return QSimpleRichText object for title. If title
1094 // not defined (empty string) then return null pointer.
1095 // Object should be deleted by caller function.
1096 //================================================================
1098 QSimpleRichText* QtxColorScale::simpleRichText( const int flags ) const
1100 QSimpleRichText* srt = 0;
1103 switch ( titlePosition() )
1106 aTitle = QString( "<p align=\"left\">%1</p>" );
1109 aTitle = QString( "<p align=\"right\">%1</p>" );
1112 aTitle = QString( "<p align=\"center\">%1</p>" );
1119 if ( !aTitle.isEmpty() && !title().isEmpty() )
1121 if ( !myStyleSheet )
1123 QtxColorScale* that = (QtxColorScale*)this;
1124 that->myStyleSheet = new QStyleSheet( that );
1129 QStyleSheetItem* item = myStyleSheet->item( "p" );
1131 item->setWhiteSpaceMode( flags & WrapTitle ? QStyleSheetItem::WhiteSpaceNormal :
1132 QStyleSheetItem::WhiteSpaceNoWrap );
1135 aTitle = aTitle.arg( title() );
1136 srt = new QSimpleRichText( aTitle, font(), QString::null, myStyleSheet );
1144 /*********************************************************************
1145 ** Class: QtxColorScale::Dock
1146 ** Descr: Dockable window contains the color scale.
1148 *********************************************************************/
1150 //================================================================
1152 // Purpose : Constructor.
1153 //================================================================
1155 QtxColorScale::Dock::Dock( Place p, QWidget* parent, const char* name, WFlags f )
1156 : QDockWindow( p, parent, name, f ),
1157 myBlockShow( false ),
1158 myBlockResize( false )
1160 myScale = new QtxColorScale( this );
1162 setWidget( myScale );
1164 setCloseMode( Always );
1165 setMovingEnabled( true );
1166 setResizeEnabled( true );
1167 setHorizontalStretchable( false );
1169 setCaption( tr ( "Color scale" ) );
1172 //================================================================
1174 // Purpose : Destructor.
1175 //================================================================
1177 QtxColorScale::Dock::~Dock()
1181 //================================================================
1182 // Function : colorScale
1183 // Purpose : Returns color scale widget.
1184 //================================================================
1186 QtxColorScale* QtxColorScale::Dock::colorScale() const
1191 //================================================================
1192 // Function : activate
1193 // Purpose : Set the dockable window is visible for main window.
1194 //================================================================
1196 void QtxColorScale::Dock::activate()
1201 QMainWindow* mw = 0;
1202 QWidget* p = parentWidget();
1205 if ( p->inherits( "QMainWindow" ) )
1206 mw = (QMainWindow*)p;
1207 p = p->parentWidget();
1210 mw->setAppropriate( this, true );
1213 //================================================================
1214 // Function : deactivate
1215 // Purpose : Set the dockable window is hidden for main window.
1216 //================================================================
1218 void QtxColorScale::Dock::deactivate()
1223 QMainWindow* mw = 0;
1224 QWidget* p = parentWidget();
1227 if ( p->inherits( "QMainWindow" ) )
1228 mw = (QMainWindow*)p;
1229 p = p->parentWidget();
1232 mw->setAppropriate( this, false );
1235 //================================================================
1236 // Function : isActive
1237 // Purpose : Returns true if the dockable window is visible.
1238 //================================================================
1240 bool QtxColorScale::Dock::isActive() const
1242 QMainWindow* mw = 0;
1243 QWidget* p = parentWidget();
1246 if ( p->inherits( "QMainWindow" ) )
1247 mw = (QMainWindow*)p;
1248 p = p->parentWidget();
1251 return mw->appropriate( (QDockWindow*)this );
1256 //================================================================
1258 // Purpose : Reimplemented for internal reasons.
1259 //================================================================
1261 void QtxColorScale::Dock::show()
1263 bool f = myBlockShow;
1265 QDockWindow::show();
1269 //================================================================
1271 // Purpose : Reimplemented for internal reasons.
1272 //================================================================
1274 void QtxColorScale::Dock::hide()
1276 bool f = myBlockShow;
1277 myBlockShow = false;
1278 QDockWindow::hide();
1282 //================================================================
1283 // Function : resize
1284 // Purpose : Make extent width as maximum value of widget width.
1285 //================================================================
1287 void QtxColorScale::Dock::resize( int w, int h )
1289 QDockWindow::resize( w, h );
1291 if ( myBlockResize )
1294 if ( orientation() == Qt::Vertical )
1295 setFixedExtentWidth( QMAX( fixedExtent().width(), w ) );
1296 else if ( orientation() == Qt::Horizontal )
1297 setFixedExtentHeight( QMAX( fixedExtent().height(), h ) );
1300 //================================================================
1301 // Function : setOrientation
1303 //================================================================
1305 void QtxColorScale::Dock::setOrientation( Orientation o )
1307 bool b = myBlockResize;
1308 myBlockResize = true;
1309 QDockWindow::setOrientation( o );