1 #include "SalomeStyle.h"
10 #include <qlineedit.h>
11 #include <qlistview.h>
12 #include <qdrawutil.h>
13 #include <qpopupmenu.h>
14 #include <qpushbutton.h>
15 #include <qobjectlist.h>
16 #include <qtoolbutton.h>
17 #include <qapplication.h>
19 static const char* const hole_xpm[] = {
29 static const char* const cross_xpm[] = {
49 static const char* const maximize_xpm[] = {
69 static const char* const normal_xpm[] = {
89 static const char* const minimize_xpm[] = {
110 Class: SalomeStyle [Public]
111 Descr: Style for SALOME platform
114 SalomeStyle::SalomeStyle()
117 qApp->installEventFilter( this );
120 SalomeStyle::~SalomeStyle()
124 void SalomeStyle::polish( QWidget* w )
129 if ( w->inherits( "QLineEdit" ) )
131 QLineEdit* fr = (QLineEdit*)w;
132 if ( w->parentWidget() && w->parentWidget()->inherits( "QSpinWidget" ) )
133 fr->setFrameStyle( QFrame::Plain );
136 fr->setFrameStyle( QFrame::Plain | QFrame::Box );
137 fr->setLineWidth( 1 );
138 fr->setMidLineWidth( 0 );
143 if ( w->inherits( "QToolBar" ) )
145 QToolBar* tb = (QToolBar*)w;
146 tb->setFrameStyle( QFrame::ToolBarPanel | QFrame::Plain );
147 tb->setLineWidth( 1 );
148 tb->setMidLineWidth( 1 );
151 if ( w->inherits( "QDockWindow" ) )
153 QDockWindow* dw = (QDockWindow*)w;
154 dw->setFrameStyle( QFrame::ToolBarPanel | QFrame::Raised );
157 else if ( w->inherits( "QListView" ) )
159 QListView* lv = (QListView*)w;
160 lv->setFrameStyle( QFrame::Box | QFrame::Plain );
164 PARENT_STYLE::polish( w );
167 bool SalomeStyle::eventFilter( QObject* o, QEvent* e )
169 if ( e->type() == QEvent::FocusIn || e->type() == QEvent::FocusOut )
171 QDockWindow* wnd = NULL;
173 if( o->inherits( "QDockWindow" ) )
174 wnd = ( QDockWindow* )o;
180 const QObjectList* objList = o->children();
181 for( QObjectListIterator anIt( *objList ); anIt.current(); ++anIt )
182 if( anIt.current()->inherits( "QDockWindowHandle" ) )
184 QWidget* ww = ( QWidget* )anIt.current();
185 ww->repaint( ww->rect() );
186 const QObjectList* wc = ww->children();
187 for( QObjectListIterator anIt2( *wc ); anIt2.current(); ++anIt2 )
188 if( anIt2.current()->inherits( "QToolButton" ) )
190 QWidget* tb = ( QWidget* )anIt2.current();
191 tb->repaint( tb->rect() );
197 if ( o && o->inherits( "QPushButton" ) && ( e->type() == QEvent::Enter || e->type() == QEvent::Leave ) )
198 ((QWidget*)o)->update();
203 double linear( double x )
208 void SalomeStyle::mix( const double t, const QColor& c1, const QColor& c2, QColor& res )
213 int r = int( c1.red() * (1-t) + c2.red() * t ),
214 g = int( c1.green() * (1-t) + c2.green() * t ),
215 b = int( c1.blue() * (1-t) + c2.blue() * t );
216 res.setRgb( r, g, b );
219 void SalomeStyle::mix( const double t, QRgb& rgb1, const QRgb& rgb2 )
224 int c[2][4] = { qRed( rgb1 ), qGreen( rgb1 ), qBlue( rgb1 ), qAlpha( rgb1 ),
225 qRed( rgb2 ), qGreen( rgb2 ), qBlue( rgb2 ), qAlpha( rgb2 ) };
226 for( int i=0; i<4; i++ )
227 c[0][i] = (int)( c[0][i] * (1-t) + c[1][i] * t );
229 rgb1 = qRgba( c[0][0], c[0][1], c[0][2], qAlpha( rgb1 ) );
232 void SalomeStyle::mix( const double t, QPixmap& pix, const QColor& col )
237 QImage anImage = pix.convertToImage();
238 if( anImage.isNull() )
241 if( anImage.depth()!=32 )
242 anImage = anImage.convertDepth( 32 );
244 int w = anImage.width(),
245 h = anImage.height();
247 QRgb colrgb = col.rgb(), cur;
248 for( int y=0; y<h; y++ )
250 uchar* line = anImage.scanLine( y );
251 QRgb* colorline = ( QRgb* ) line;
252 for( int x=0; x<w; x++ )
254 cur = colorline[ x ];
255 mix( t, cur, colrgb );
256 colorline[ x ] = cur;
262 void SalomeStyle::toGrayscale( QPixmap& pix, double k )
264 QImage anImage = pix.convertToImage();
265 if( anImage.isNull() )
268 if( anImage.depth()!=32 )
269 anImage = anImage.convertDepth( 32 );
271 int w = anImage.width(),
272 h = anImage.height();
274 for( int y=0; y<h; y++ )
276 uchar* line = anImage.scanLine( y );
277 QRgb* colorline = ( QRgb* ) line;
278 for( int x=0; x<w; x++ )
280 int gray = (int)( k * qGray( colorline[ x ] ) );
285 colorline[ x ] = qRgba( gray, gray, gray, qAlpha( colorline[x] ) );
291 void SalomeStyle::drawGradient( QPainter* p, const QRect& r,
292 const QColor& c1, const QColor& c2,
293 const Direction d, gradient_func f ) const
296 p->translate( r.x(), r.y() );
299 if( d==LeftToRight || d==RightToLeft )
300 for( int xmax = r.width(), x = d==LeftToRight ? 0 : xmax;
301 d==LeftToRight ? x<=xmax : x>=0;
302 d==LeftToRight ? x++ : x-- )
304 double t = double( x ) / double( xmax );
305 mix( d==LeftToRight ? f(t) : 1-f(t), c1, c2, mid );
307 p->drawLine( x, 0, x, r.height() );
310 for( int ymax = r.height(), y = d==UpToDown ? 0 : ymax;
311 d==UpToDown ? y<=ymax : y>=0;
312 d==UpToDown ? y++ : y-- )
314 double t = double( y ) / double( ymax );
315 mix( d==UpToDown ? f(t) : 1-f(t), c1, c2, mid );
317 p->drawLine( 0, y, r.width(), y );
323 void SalomeStyle::drawPrimitive( PrimitiveElement pe, QPainter* p, const QRect& r,
324 const QColorGroup& cg, SFlags flags, const QStyleOption& opt ) const
329 if ( !myTitleParent )
330 PARENT_STYLE::drawPrimitive( pe, p, r, cg, flags, opt );
333 case PE_DockWindowResizeHandle:
334 p->fillRect( r.x(), r.y(), r.width(), r.height(), cg.dark() );
335 if ( flags & Style_Horizontal )
336 p->fillRect( r.x(), r.y() + 1, r.width(), r.height() - 2, cg.midlight() );
338 p->fillRect( r.x() + 1, r.y(), r.width() - 2, r.height(), cg.midlight() );
341 case PE_DockWindowHandle:
343 QPaintDevice* pd = p->device();
347 QWidget* w = (QWidget*)pd;
349 if ( !w || !w->inherits( "QDockWindowHandle" ) )
352 QDockWindow* wnd = ( QDockWindow* ) w->parent();
356 QObject* activeWidget = qApp->focusWidget();
357 QDockWindow* activeWnd = 0;
358 while ( !activeWnd && activeWidget )
360 if ( activeWidget->inherits( "QDockWindow" ) )
361 activeWnd = (QDockWindow*)activeWidget;
363 activeWidget = activeWidget->parent();
366 bool act = wnd == activeWnd, horiz = flags & Style_Horizontal;
368 QPixmap hole( (const char**)hole_xpm );
370 if ( wnd->inherits( "QToolBar" ) )
372 drawGradient( p, r, cg.light(), cg.background(), horiz ? UpToDown : LeftToRight, linear );
374 int c = 4, i; double d = ( horiz ? r.height() : r.width() ) / ( c + 1 );
375 QBrush fill = cg.brush( QColorGroup::Dark );
376 p->setPen( Qt::red );
377 for ( i = 0; i < c; i++ )
380 p->drawPixmap( r.x() + r.width() / 2 - 1, (int)( r.y() + ( i + 1 ) * d - 1 ), hole );
382 p->drawPixmap( (int) ( r.x() + ( i + 1 ) * d - 1 ), r.y() + r.height() / 2 - 1, hole );
385 int dd = (int(d)/2) + (int(d)%2);
386 for ( i = 0; i < c - 1; i++ )
389 p->drawPixmap( r.x() + r.width() / 2 + 2, (int)( r.y() + dd + ( i + 1 ) * d - 1 ), hole );
391 p->drawPixmap( (int)( r.x() + dd + ( i + 1 ) * d - 1 ), r.y() + r.height() / 2 + 2, hole );
397 QRect rr( r.x()+d, r.y()+d, r.width()-2*d, r.height()-2*d );
401 mix( 0.5, cg.highlight(), Qt::white, col );
403 col = cg.background();
405 drawGradient( p, rr, act ? cg.highlight() : cg.dark(), col,
406 horiz ? LeftToRight : UpToDown, linear );
409 if ( flags & Style_Horizontal )
410 rt.addCoords( 0, 20, 0, 0 );
412 rt.addCoords( 0, 0, -20, 0 );
414 int textW = flags & Style_Horizontal ? rt.height() : rt.width();
415 int textH = flags & Style_Horizontal ? rt.width() : rt.height();
417 QString title = titleText( wnd->caption(), textW, p->fontMetrics() );
421 p->setPen( act ? cg.highlightedText() : cg.text() );
423 if ( flags & Style_Horizontal )
426 p->translate( -(rt.height()+rt.y()), (rt.width()-rt.x()) );
427 p->drawText( 0, 0, title );
430 p->drawText( 2, 2, textW, textH, AlignLeft, title );
436 case PE_DockWindowSeparator:
438 bool horiz = ( flags & Style_Horizontal );
439 QWidget* w = ( QWidget* )p->device();
440 if( w->inherits( "QToolBarSeparator" ) )
442 drawGradient( p, r, cg.light(), cg.background(), horiz ? UpToDown : LeftToRight, linear );
443 int w = r.width(), h = r.height();
446 p->setPen( cg.dark() );
448 p->drawLine( r.x() + w/2, r.y() + h/part, r.x() + w/2, r.y() + (part-1)*h/part );
450 p->drawLine( r.x() + w/part, r.y() + h/2, r.x() + (part-1)*w/part, r.y() + h/2 );
452 p->setPen( cg.light() );
454 p->drawLine( r.x() + w/2 + 1, r.y() + h/part + 1, r.x() + w/2 + 1, r.y() + (part-1)*h/part + 1 );
456 p->drawLine( r.x() + w/part + 1, r.y() + h/2 + 1, r.x() + (part-1)*w/part + 1, r.y() + h/2 + 1 );
459 PARENT_STYLE::drawPrimitive( pe, p, r, cg, flags, opt );
463 case PE_PanelDockWindow:
465 QWidget* w = ( QWidget* )p->device();
467 int offset = pixelMetric( PM_DockWindowHandleExtent, w );
468 if ( w->inherits( "QToolBar" ) )
470 bool vert = ( ( QToolBar* )w )->orientation() == Qt::Vertical;
472 drawGradient( p, QRect( r.x(), r.y()+offset, r.x()+r.width(), r.y()+offset ),
473 cg.light(), cg.background(), LeftToRight, linear );
475 drawGradient( p, QRect( r.x()+offset, r.y(), r.x()+offset, r.y()+r.height() ),
476 cg.light(), cg.background(), UpToDown, linear );
478 p->setPen( QPen( cg.light(), 1 ) );
483 p->setPen( QPen( cg.dark(), 1 ) );
484 p->setBrush( cg.light() );
492 p->setPen( QPen( cg.dark(), 1 ) );
493 p->setBrush( cg.light() );
497 case PE_HeaderSection:
499 QColor col; mix( 0.2, cg.light(), Qt::black, col );
500 drawGradient( p, r, cg.light(), col, DownToUp, linear );
501 drawGradient( p, QRect( r.x(), r.y(), 1, r.height() ), cg.light(), cg.dark(), DownToUp, linear );
502 p->setPen( cg.dark() );
503 p->drawLine( r.x(), r.y()+r.height()-1, r.x()+r.width(), r.y()+r.height()-1 );
508 p->fillRect( r.x() + 1, r.y() + 1, r.width() - 2, r.height() - 2, cg.dark() );
509 p->fillRect( r.x() + 2, r.y() + 2, r.width() - 4, r.height() - 4, cg.midlight() );
513 PARENT_STYLE::drawPrimitive( PE_ButtonDropDown, p, r, cg, flags, opt );
516 case PE_ButtonCommand:
518 QColorGroup cGrp( cg );
519 if ( flags & Style_MouseOver )
520 cGrp.setColor( QColorGroup::Button, cGrp.midlight() );
522 if ( flags & Style_MouseOver )
523 PARENT_STYLE::drawPrimitive( PE_ButtonDropDown, p, r, cGrp, flags, opt );
525 PARENT_STYLE::drawPrimitive( flags & Style_Raised ? PE_ButtonDropDown : pe, p, r, cGrp, flags, opt );
530 PARENT_STYLE::drawPrimitive( pe, p, r, cg, flags, opt );
535 void SalomeStyle::drawControl( ControlElement element, QPainter* p, const QWidget* widget, const QRect& r,
536 const QColorGroup& cg, SFlags flags, const QStyleOption& opt ) const
540 case CE_PopupMenuItem:
542 if(! widget || opt.isDefault())
545 const QPopupMenu *popupmenu = (const QPopupMenu *) widget;
546 QMenuItem *mi = opt.menuItem();
550 int tab = opt.tabWidth();
551 int maxpmw = opt.maxIconWidth();
552 bool dis = !( flags & Style_Enabled );
553 bool checkable = popupmenu->isCheckable();
554 bool act = flags & Style_Active;
555 bool use2000style = true;
558 int windowsItemFrame = 2,
559 windowsItemHMargin = 5,
560 windowsItemVMargin = 1,
561 windowsRightBorder = 2,
562 windowsArrowHMargin = 2;
564 r.rect(&x, &y, &w, &h);
568 // space for the checkmarks
570 maxpmw = QMAX( maxpmw, 20 );
572 maxpmw = QMAX( maxpmw, 12 );
575 int checkcol = maxpmw;
577 if ( mi && mi->isSeparator() )
579 p->setPen( cg.dark() );
580 p->drawLine( x+3*checkcol/2, y, x+w, y );
581 //p->setPen( cg.light() );
582 //p->drawLine( x, y+1, x+w, y+1 );
586 QBrush fill = ( act && !dis ?
587 cg.brush( QColorGroup::Highlight ) :
588 cg.brush( QColorGroup::Light ) );
589 p->fillRect( x, y, w, h, fill );
595 QRect vrect = visualRect( QRect( xpos, y, checkcol, h ), r );
596 int xvis = vrect.x();
598 if( mi->isChecked() )
601 qDrawShadePanel( p, xvis, y, checkcol, h,
602 cg, TRUE, 1, &cg.brush( QColorGroup::Button ) );
605 QBrush fill( cg.light(), Dense4Pattern );
606 // set the brush origin for the hash pattern to the x/y coordinate
607 // of the menu item's checkmark... this way, the check marks have
609 QPoint origin = p->brushOrigin();
610 p->setBrushOrigin( xvis, y );
611 qDrawShadePanel( p, xvis, y, checkcol, h, cg, TRUE, 1, &fill );
612 // restore the previous brush origin
613 p->setBrushOrigin( origin );
617 p->fillRect(x+checkcol, y, w-checkcol , h, cg.brush( QColorGroup::Light ));
619 if( !( act && !dis ) && !mi->isChecked() )
621 QColor col; mix( 0.5, cg.mid(), Qt::white, col );
622 drawGradient( p, QRect( xvis, y, checkcol, h+1 ), cg.light(), col, LeftToRight, linear );
627 QIconSet::Mode mode = dis ? QIconSet::Active : QIconSet::Normal;
629 mode = QIconSet::Active;
631 if( checkable && mi->isChecked() )
632 pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode, QIconSet::On );
634 pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
635 int pixw = pixmap.width();
636 int pixh = pixmap.height();
639 toGrayscale( pixmap, 1.1 );
641 //if( act && !dis && !mi->isChecked() )
642 // qDrawShadePanel( p, xvis, y, checkcol, h, cg, FALSE, 1, &cg.brush( QColorGroup::Button ) );
644 QRect pmr( 0, 0, pixw, pixh );
645 pmr.moveCenter( vrect.center() );
646 p->setPen( cg.text() );
647 p->drawPixmap( pmr.topLeft(), pixmap );
649 QBrush fill = ( act ? cg.brush( QColorGroup::Highlight ) : cg.brush( QColorGroup::Light ));
650 int xp = xpos + checkcol + 1;
652 p->fillRect( visualRect( QRect( xp, y, w - checkcol - 1, h ), r ), fill);
655 { // just "checking"...
656 if( mi->isChecked() )
658 int xp = xpos + windowsItemFrame;
660 SFlags cflags = Style_Default;
662 cflags |= Style_Enabled;
666 drawPrimitive( PE_CheckMark, p,
667 visualRect( QRect( xp, y + windowsItemFrame,
668 checkcol - 2*windowsItemFrame,
669 h - 2*windowsItemFrame), r ), cg, cflags, opt );
673 p->setPen( act ? cg.highlightedText() : cg.buttonText() );
682 int xm = windowsItemFrame + checkcol + windowsItemHMargin;
685 vrect = visualRect( QRect( xpos, y+windowsItemVMargin, w-xm-tab+1, h-2*windowsItemVMargin ), r );
692 p->setPen( cg.light() );
693 mi->custom()->paint( p, cg, act, !dis,
694 xvis+1, y+windowsItemVMargin+1,
695 w-xm-tab+1, h-2*windowsItemVMargin );
698 mi->custom()->paint( p, cg, act, !dis, xvis, y+windowsItemVMargin,
699 w-xm-tab+1, h-2*windowsItemVMargin );
702 QString s = mi->text();
705 int t = s.find( '\t' );
706 int text_flags = AlignVCenter | ShowPrefix | DontClip | SingleLine;
707 if( !styleHint( SH_UnderlineAccelerator, widget ) )
708 text_flags |= NoAccel;
709 text_flags |= (QApplication::reverseLayout() ? AlignRight : AlignLeft );
712 int xp = x + w - tab - windowsItemHMargin - windowsItemFrame + 1;
716 xp -= windowsRightBorder;
717 int xoff = visualRect( QRect( xp, y+windowsItemVMargin, tab, h-2*windowsItemVMargin ), r ).x();
720 p->setPen( cg.light() );
721 p->drawText( xoff+1, y+windowsItemVMargin+1, tab, h-2*windowsItemVMargin, text_flags, s.mid( t+1 ));
724 p->drawText( xoff, y+windowsItemVMargin, tab, h-2*windowsItemVMargin, text_flags, s.mid( t+1 ) );
729 p->setPen( cg.light() );
730 p->drawText( xvis+1, y+windowsItemVMargin+1, w-xm-tab+1, h-2*windowsItemVMargin, text_flags, s, t );
733 p->drawText( xvis, y+windowsItemVMargin, w-xm-tab+1, h-2*windowsItemVMargin, text_flags, s, t );
735 else if( mi->pixmap() )
737 QPixmap *pixmap = mi->pixmap();
738 if( pixmap->depth() == 1 )
739 p->setBackgroundMode( OpaqueMode );
740 p->drawPixmap( xvis, y+windowsItemFrame, *pixmap );
741 if( pixmap->depth() == 1 )
742 p->setBackgroundMode( TransparentMode );
745 { // draw sub menu arrow
746 int dim = (h-2*windowsItemFrame) / 2;
747 PrimitiveElement arrow;
748 arrow = ( QApplication::reverseLayout() ? PE_ArrowLeft : PE_ArrowRight );
749 xpos = x+w - windowsArrowHMargin - windowsItemFrame - dim;
750 vrect = visualRect( QRect(xpos, y + h / 2 - dim / 2, dim, dim), r );
754 g2.setColor( QColorGroup::ButtonText, g2.highlightedText() );
755 drawPrimitive( arrow, p, vrect, g2, dis ? Style_Default : Style_Enabled, opt );
759 drawPrimitive( arrow, p, vrect, cg, dis ? Style_Default : Style_Enabled, opt );
765 p->setPen( cg.dark() );
773 bool active = flags & Style_Active;
774 bool down = flags & Style_Down;
780 //QColor col; mix( 0.5, cg.mid(), Qt::white, col );
781 //drawGradient( p, r, col, cg.light(), UpToDown, linear );
782 p->setPen( cg.light() );
783 p->setBrush( cg.light() );
786 p->setPen( cg.dark() );
787 int w = r.width()-1, h = r.height();
788 p->drawLine( r.x(), r.y(), r.x()+w, r.y() );
789 p->drawLine( r.x(), r.y(), r.x(), r.y()+h );
790 p->drawLine( r.x()+w, r.y(), r.x()+w, r.y()+h );
792 p->translate( 1, 1 );
795 drawGradient( p, r, cg.light(), cg.background(), active ? DownToUp : UpToDown, linear );
797 QCommonStyle::drawControl(element, p, widget, pr, cg, flags, opt);
802 case CE_MenuBarEmptyArea:
804 drawGradient( p, r, cg.light(), cg.background(), UpToDown, linear );
808 case CE_ToolButtonLabel:
810 const QToolButton *toolbutton = (const QToolButton *) widget;
811 QObject* parent = toolbutton->parent();
815 if( parent->inherits( "QToolBar" ) )
817 tb = ( QToolBar* )parent;
821 parent = parent->parent();
822 parent = toolbutton->parent();
827 if( tb->orientation()==Qt::Horizontal )
831 drawGradient( p, r, cg.light(), cg.background(), horiz ? UpToDown : LeftToRight, linear );
833 else if( parent->inherits( "QDockWindowHandle" ) )
835 QWidget* w = ( QWidget* ) parent;
836 QDockWindow* wnd = ( QDockWindow* )w->parent();
837 if( !wnd->orientation()==Qt::Horizontal )
842 QPoint pp( r.x(), r.y() ),
843 qq = toolbutton->mapToParent( pp );
845 bitBlt( p->device(), r.x(), r.y(), w, horiz ? qq.x()-r.width() : qq.x(),
846 horiz ? qq.y() : qq.y()+r.height(),
847 r.width(), r.height(), Qt::CopyROP, true );
850 bool highlight = ( flags & Style_MouseOver ),
851 down = ( flags & ( Style_Down | Style_On ) ),
852 en = toolbutton->isEnabled();
857 drawGradient( p, r, cg.light(), cg.background(), horiz==1 ? DownToUp : RightToLeft, linear );
858 p->setPen( cg.background() );
863 p->setPen( cg.dark() );
864 p->setBrush( cg.light() );
869 p->setPen( cg.dark() );
870 QColor col; mix( 0.05, cg.background(), Qt::black, col );
877 Qt::ArrowType arrowType = opt.isDefault() ? Qt::DownArrow : opt.arrowType();
879 int shiftX = 0, shiftY = 0;
880 if( flags & ( Style_Down | Style_On ) )
882 shiftX = pixelMetric(PM_ButtonShiftHorizontal, widget);
883 shiftY = pixelMetric(PM_ButtonShiftVertical, widget);
886 if (!opt.isDefault())
891 case Qt::LeftArrow: pe = PE_ArrowLeft; break;
892 case Qt::RightArrow: pe = PE_ArrowRight; break;
893 case Qt::UpArrow: pe = PE_ArrowUp; break;
895 case Qt::DownArrow: pe = PE_ArrowDown; break;
898 rect.moveBy(shiftX, shiftY);
899 drawPrimitive(pe, p, rect, cg, flags, opt);
903 QColor btext = toolbutton->paletteForegroundColor();
905 if (toolbutton->iconSet().isNull() &&
906 ! toolbutton->text().isNull() &&
907 ! toolbutton->usesTextLabel())
909 int alignment = AlignCenter | ShowPrefix;
910 if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
911 alignment |= NoAccel;
913 rect.moveBy(shiftX, shiftY);
914 drawItem( p, rect, alignment, cg, flags & Style_Enabled, 0, toolbutton->text(),
915 toolbutton->text().length(), &btext);
920 QIconSet::Size size =
921 toolbutton->usesBigPixmap() ? QIconSet::Large : QIconSet::Small;
922 QIconSet::State state = toolbutton->isOn() ? QIconSet::On : QIconSet::Off;
924 if( !toolbutton->isEnabled() )
925 mode = QIconSet::Active; //QIconSet::Disabled;
926 else if( flags & (Style_Down | Style_On ) || ( flags & Style_Raised ) && (flags & Style_AutoRaise))
927 mode = QIconSet::Active;
929 mode = QIconSet::Normal;
930 pm = toolbutton->iconSet().pixmap( size, mode, state );
932 if( toolbutton->usesTextLabel() )
934 p->setFont( toolbutton->font() );
935 QRect pr = rect, tr = rect;
936 int alignment = ShowPrefix;
937 if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
938 alignment |= NoAccel;
940 if( toolbutton->textPosition() == QToolButton::Under )
942 int fh = p->fontMetrics().height();
943 pr.addCoords( 0, 1, 0, -fh-3 );
944 tr.addCoords( 0, pr.bottom(), 0, -3 );
945 pr.moveBy(shiftX, shiftY);
946 drawItem( p, pr, AlignCenter, cg, TRUE, &pm, QString::null );
947 alignment |= AlignCenter;
951 pr.setWidth( pm.width() + 8 );
952 tr.addCoords( pr.right(), 0, 0, 0 );
953 pr.moveBy(shiftX, shiftY);
955 drawItem( p, pr, AlignCenter, cg, TRUE, &pm, QString::null );
956 alignment |= AlignLeft | AlignVCenter;
959 tr.moveBy(shiftX, shiftY);
960 drawItem( p, tr, alignment, cg, flags & Style_Enabled, 0, toolbutton->textLabel(),
961 toolbutton->textLabel().length(), &btext);
965 /*if( en && !highlight )
966 mix( 0.6, pm, cg.background() );
969 toGrayscale( pm, 1.1 );
970 mix( 0.8, pm, cg.background() );
973 rect.moveBy(shiftX, shiftY);
974 drawItem( p, rect, AlignCenter, cg, true, &pm, QString::null );
983 QPen oldPen = p->pen();
986 bool selected = flags & Style_Selected;
988 p->setPen( cg.midlight() );
989 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );
992 r2.setRect( r2.left(), r2.top() + 1, r2.width(), r2.height() - 1 );
994 r2.setRect( r2.left(), r2.top(), r2.width() - 2, r2.height() - 1 );
996 p->setPen( cg.foreground() );
997 QBrush brsh = cg.brush( selected ? QColorGroup::Base : QColorGroup::Background );
998 p->fillRect( r2.left(), r2.top(), r2.width(), r2.height() - 1, brsh );
999 p->drawRect( r2.left(), r2.top(), r2.width(), r2.height() - 1 );
1003 p->setPen( cg.shadow() );
1004 p->drawLine( r2.left() + 1, r2.bottom(), r2.right() + 1, r2.bottom() );
1005 p->drawLine( r2.right() + 1, r2.top() + 1, r2.right() + 1, r2.bottom() );
1013 if ( flags & Style_Enabled && !( flags & Style_Down || flags & Style_On ) )
1015 const QPushButton* button = (const QPushButton*)widget;
1016 QRect br = QRect( button->mapToGlobal( button->rect().topLeft() ), button->rect().size() );
1017 if ( br.contains( QCursor::pos() ) )
1018 flags |= Style_MouseOver;
1021 PARENT_STYLE::drawControl( element, p, widget, r, cg, flags, opt );
1026 PARENT_STYLE::drawControl( element, p, widget, r, cg, flags, opt );
1031 QRect SalomeStyle::subRect( SubRect subrect, const QWidget* w ) const
1033 QRect r = PARENT_STYLE::subRect( subrect, w );
1034 if ( subrect==SR_DockWindowHandleRect && w->inherits( "QDockWindowHandle" ) )
1036 QDockWindow* wnd = ( QDockWindow* ) w->parent();
1037 if( wnd->orientation()==Qt::Vertical )
1038 r.setWidth( w->width() );
1041 r.setY( r.y()+r.height()-w->height() );
1042 r.setHeight( w->height() );
1049 void SalomeStyle::drawComplexControl( ComplexControl control, QPainter* p, const QWidget* widget,
1050 const QRect& r, const QColorGroup& cg, SFlags flags,
1051 SCFlags controls, SCFlags active, const QStyleOption& opt ) const
1057 ((SalomeStyle*)this)->myTitleParent = 0;
1062 if ( controls & SC_ComboBoxArrow )
1064 SFlags flags = Style_Default;
1066 qDrawShadeRect( p, r, cg, true, pixelMetric( PM_DefaultFrameWidth, widget ),
1067 0, widget->isEnabled() ? &cg.brush( QColorGroup::Base ) : &cg.brush( QColorGroup::Background ) );
1069 QRect ar = QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget, SC_ComboBoxArrow ), widget );
1070 if ( active == SC_ComboBoxArrow )
1072 p->setPen( cg.dark() );
1073 p->setBrush( cg.brush( QColorGroup::Button ) );
1077 qDrawWinPanel( p, ar, cg, FALSE, &cg.brush( QColorGroup::Button ) );
1079 ar.addCoords( 2, 2, -2, -2 );
1080 if ( widget->isEnabled() )
1081 flags |= Style_Enabled;
1083 if ( active == SC_ComboBoxArrow )
1084 flags |= Style_Sunken;
1085 drawPrimitive( PE_ArrowDown, p, ar, cg, flags );
1087 PARENT_STYLE::drawComplexControl( control, p, widget, r, cg, flags, controls & ~SC_ComboBoxArrow, active, opt );
1091 if( widget->inherits( "QTitleBar" ) )
1092 ( ( SalomeStyle* )this )->myTitleParent = ( QWidget* )widget->parent();
1095 PARENT_STYLE::drawComplexControl( control, p, widget, r, cg, flags, controls, active, opt );
1100 QPixmap SalomeStyle::stylePixmap( StylePixmap st, const QWidget* w, const QStyleOption& opt ) const
1104 case SP_DockWindowCloseButton:
1105 case SP_TitleBarCloseButton:
1106 return QPixmap( cross_xpm );
1107 case SP_TitleBarMaxButton:
1108 return QPixmap( maximize_xpm );
1109 case SP_TitleBarNormalButton:
1110 return QPixmap( normal_xpm );
1111 case SP_TitleBarMinButton:
1112 return QPixmap( minimize_xpm );
1114 return PARENT_STYLE::stylePixmap( st, w, opt );
1118 int SalomeStyle::pixelMetric( PixelMetric pm, const QWidget* widget ) const
1124 case PM_ButtonMargin:
1127 case PM_DockWindowFrameWidth:
1130 case PM_TabBarTabOverlap:
1133 case PM_TabBarTabHSpace:
1136 case PM_TabBarTabShiftHorizontal:
1137 case PM_TabBarTabShiftVertical:
1140 case PM_TabBarTabVSpace:
1143 case PM_DefaultFrameWidth:
1146 case PM_SpinBoxFrameWidth:
1149 case PM_ProgressBarChunkWidth:
1153 ret = PARENT_STYLE::pixelMetric( pm, widget );
1159 QString SalomeStyle::titleText( const QString& txt, const int W, const QFontMetrics& fm ) const
1161 QString res = txt.stripWhiteSpace();
1163 if ( fm.width( res ) > W )
1165 QString end( "..." );
1166 while ( !res.isEmpty() && fm.width( res + end ) > W )
1167 res.remove( res.length() - 1, 1 );
1169 if ( !res.isEmpty() )
1177 Class: SalomeStylePlugin [Internal]
1178 Descr: Plugin for Qt style mechanism
1181 SalomeStylePlugin::SalomeStylePlugin()
1185 SalomeStylePlugin::~SalomeStylePlugin()
1189 QStringList SalomeStylePlugin::keys() const
1191 return QStringList() << "salome";
1194 QStyle* SalomeStylePlugin::create( const QString& str )
1196 if ( str == "salome" )
1197 return new SalomeStyle();
1202 Q_EXPORT_PLUGIN( SalomeStylePlugin )