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 QColorGroup cgroup = wnd->isActiveWindow() ? wnd->palette().active() : wnd->palette().inactive();
422 p->setPen( cgroup.highlightedText() );
424 if ( flags & Style_Horizontal )
427 p->translate( -(rt.height()+rt.y()), (rt.width()-rt.x()) );
428 p->drawText( 0, 0, title );
431 p->drawText( 2, 2, textW, textH, AlignLeft, title );
437 case PE_DockWindowSeparator:
439 bool horiz = ( flags & Style_Horizontal );
440 QWidget* w = ( QWidget* )p->device();
441 if( w->inherits( "QToolBarSeparator" ) )
443 drawGradient( p, r, cg.light(), cg.background(), horiz ? UpToDown : LeftToRight, linear );
444 int w = r.width(), h = r.height();
447 p->setPen( cg.dark() );
449 p->drawLine( r.x() + w/2, r.y() + h/part, r.x() + w/2, r.y() + (part-1)*h/part );
451 p->drawLine( r.x() + w/part, r.y() + h/2, r.x() + (part-1)*w/part, r.y() + h/2 );
453 p->setPen( cg.light() );
455 p->drawLine( r.x() + w/2 + 1, r.y() + h/part + 1, r.x() + w/2 + 1, r.y() + (part-1)*h/part + 1 );
457 p->drawLine( r.x() + w/part + 1, r.y() + h/2 + 1, r.x() + (part-1)*w/part + 1, r.y() + h/2 + 1 );
460 PARENT_STYLE::drawPrimitive( pe, p, r, cg, flags, opt );
464 case PE_PanelDockWindow:
466 QWidget* w = ( QWidget* )p->device();
468 int offset = pixelMetric( PM_DockWindowHandleExtent, w );
469 if ( w->inherits( "QToolBar" ) )
471 bool vert = ( ( QToolBar* )w )->orientation() == Qt::Vertical;
473 drawGradient( p, QRect( r.x(), r.y()+offset, r.x()+r.width(), r.y()+offset ),
474 cg.light(), cg.background(), LeftToRight, linear );
476 drawGradient( p, QRect( r.x()+offset, r.y(), r.x()+offset, r.y()+r.height() ),
477 cg.light(), cg.background(), UpToDown, linear );
479 p->setPen( QPen( cg.light(), 1 ) );
484 p->setPen( QPen( cg.dark(), 1 ) );
485 p->setBrush( cg.light() );
493 p->setPen( QPen( cg.dark(), 1 ) );
494 p->setBrush( cg.light() );
498 case PE_HeaderSection:
500 QColor col; mix( 0.2, cg.light(), Qt::black, col );
501 drawGradient( p, r, cg.light(), col, DownToUp, linear );
502 drawGradient( p, QRect( r.x(), r.y(), 1, r.height() ), cg.light(), cg.dark(), DownToUp, linear );
503 p->setPen( cg.dark() );
504 p->drawLine( r.x(), r.y()+r.height()-1, r.x()+r.width(), r.y()+r.height()-1 );
509 p->fillRect( r.x() + 1, r.y() + 1, r.width() - 2, r.height() - 2, cg.dark() );
510 p->fillRect( r.x() + 2, r.y() + 2, r.width() - 4, r.height() - 4, cg.midlight() );
514 PARENT_STYLE::drawPrimitive( PE_ButtonDropDown, p, r, cg, flags, opt );
517 case PE_ButtonCommand:
519 QColorGroup cGrp( cg );
520 if ( flags & Style_MouseOver )
521 cGrp.setColor( QColorGroup::Button, cGrp.midlight() );
523 if ( flags & Style_MouseOver )
524 PARENT_STYLE::drawPrimitive( PE_ButtonDropDown, p, r, cGrp, flags, opt );
526 PARENT_STYLE::drawPrimitive( flags & Style_Raised ? PE_ButtonDropDown : pe, p, r, cGrp, flags, opt );
531 PARENT_STYLE::drawPrimitive( pe, p, r, cg, flags, opt );
536 void SalomeStyle::drawControl( ControlElement element, QPainter* p, const QWidget* widget, const QRect& r,
537 const QColorGroup& cg, SFlags flags, const QStyleOption& opt ) const
541 case CE_PopupMenuItem:
543 if(! widget || opt.isDefault())
546 const QPopupMenu *popupmenu = (const QPopupMenu *) widget;
547 QMenuItem *mi = opt.menuItem();
551 int tab = opt.tabWidth();
552 int maxpmw = opt.maxIconWidth();
553 bool dis = !( flags & Style_Enabled );
554 bool checkable = popupmenu->isCheckable();
555 bool act = flags & Style_Active;
556 bool use2000style = true;
559 int windowsItemFrame = 2,
560 windowsItemHMargin = 5,
561 windowsItemVMargin = 1,
562 windowsRightBorder = 2,
563 windowsArrowHMargin = 2;
565 r.rect(&x, &y, &w, &h);
569 // space for the checkmarks
571 maxpmw = QMAX( maxpmw, 20 );
573 maxpmw = QMAX( maxpmw, 12 );
576 int checkcol = maxpmw;
578 if ( mi && mi->isSeparator() )
580 p->setPen( cg.dark() );
581 p->drawLine( x+3*checkcol/2, y, x+w, y );
582 //p->setPen( cg.light() );
583 //p->drawLine( x, y+1, x+w, y+1 );
587 QBrush fill = ( act && !dis ?
588 cg.brush( QColorGroup::Highlight ) :
589 cg.brush( QColorGroup::Light ) );
590 p->fillRect( x, y, w, h, fill );
596 QRect vrect = visualRect( QRect( xpos, y, checkcol, h ), r );
597 int xvis = vrect.x();
599 if( mi->isChecked() )
602 qDrawShadePanel( p, xvis, y, checkcol, h,
603 cg, TRUE, 1, &cg.brush( QColorGroup::Button ) );
606 QBrush fill( cg.light(), Dense4Pattern );
607 // set the brush origin for the hash pattern to the x/y coordinate
608 // of the menu item's checkmark... this way, the check marks have
610 QPoint origin = p->brushOrigin();
611 p->setBrushOrigin( xvis, y );
612 qDrawShadePanel( p, xvis, y, checkcol, h, cg, TRUE, 1, &fill );
613 // restore the previous brush origin
614 p->setBrushOrigin( origin );
618 p->fillRect(x+checkcol, y, w-checkcol , h, cg.brush( QColorGroup::Light ));
620 if( !( act && !dis ) && !mi->isChecked() )
622 QColor col; mix( 0.5, cg.mid(), Qt::white, col );
623 drawGradient( p, QRect( xvis, y, checkcol, h+1 ), cg.light(), col, LeftToRight, linear );
628 QIconSet::Mode mode = dis ? QIconSet::Active : QIconSet::Normal;
630 mode = QIconSet::Active;
632 if( checkable && mi->isChecked() )
633 pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode, QIconSet::On );
635 pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
636 int pixw = pixmap.width();
637 int pixh = pixmap.height();
640 toGrayscale( pixmap, 1.1 );
642 //if( act && !dis && !mi->isChecked() )
643 // qDrawShadePanel( p, xvis, y, checkcol, h, cg, FALSE, 1, &cg.brush( QColorGroup::Button ) );
645 QRect pmr( 0, 0, pixw, pixh );
646 pmr.moveCenter( vrect.center() );
647 p->setPen( cg.text() );
648 p->drawPixmap( pmr.topLeft(), pixmap );
650 QBrush fill = ( act ? cg.brush( QColorGroup::Highlight ) : cg.brush( QColorGroup::Light ));
651 int xp = xpos + checkcol + 1;
653 p->fillRect( visualRect( QRect( xp, y, w - checkcol - 1, h ), r ), fill);
656 { // just "checking"...
657 if( mi->isChecked() )
659 int xp = xpos + windowsItemFrame;
661 SFlags cflags = Style_Default;
663 cflags |= Style_Enabled;
667 drawPrimitive( PE_CheckMark, p,
668 visualRect( QRect( xp, y + windowsItemFrame,
669 checkcol - 2*windowsItemFrame,
670 h - 2*windowsItemFrame), r ), cg, cflags, opt );
674 p->setPen( act ? cg.highlightedText() : cg.buttonText() );
683 int xm = windowsItemFrame + checkcol + windowsItemHMargin;
686 vrect = visualRect( QRect( xpos, y+windowsItemVMargin, w-xm-tab+1, h-2*windowsItemVMargin ), r );
693 p->setPen( cg.light() );
694 mi->custom()->paint( p, cg, act, !dis,
695 xvis+1, y+windowsItemVMargin+1,
696 w-xm-tab+1, h-2*windowsItemVMargin );
699 mi->custom()->paint( p, cg, act, !dis, xvis, y+windowsItemVMargin,
700 w-xm-tab+1, h-2*windowsItemVMargin );
703 QString s = mi->text();
706 int t = s.find( '\t' );
707 int text_flags = AlignVCenter | ShowPrefix | DontClip | SingleLine;
708 if( !styleHint( SH_UnderlineAccelerator, widget ) )
709 text_flags |= NoAccel;
710 text_flags |= (QApplication::reverseLayout() ? AlignRight : AlignLeft );
713 int xp = x + w - tab - windowsItemHMargin - windowsItemFrame + 1;
717 xp -= windowsRightBorder;
718 int xoff = visualRect( QRect( xp, y+windowsItemVMargin, tab, h-2*windowsItemVMargin ), r ).x();
721 p->setPen( cg.light() );
722 p->drawText( xoff+1, y+windowsItemVMargin+1, tab, h-2*windowsItemVMargin, text_flags, s.mid( t+1 ));
725 p->drawText( xoff, y+windowsItemVMargin, tab, h-2*windowsItemVMargin, text_flags, s.mid( t+1 ) );
730 p->setPen( cg.light() );
731 p->drawText( xvis+1, y+windowsItemVMargin+1, w-xm-tab+1, h-2*windowsItemVMargin, text_flags, s, t );
734 p->drawText( xvis, y+windowsItemVMargin, w-xm-tab+1, h-2*windowsItemVMargin, text_flags, s, t );
736 else if( mi->pixmap() )
738 QPixmap *pixmap = mi->pixmap();
739 if( pixmap->depth() == 1 )
740 p->setBackgroundMode( OpaqueMode );
741 p->drawPixmap( xvis, y+windowsItemFrame, *pixmap );
742 if( pixmap->depth() == 1 )
743 p->setBackgroundMode( TransparentMode );
746 { // draw sub menu arrow
747 int dim = (h-2*windowsItemFrame) / 2;
748 PrimitiveElement arrow;
749 arrow = ( QApplication::reverseLayout() ? PE_ArrowLeft : PE_ArrowRight );
750 xpos = x+w - windowsArrowHMargin - windowsItemFrame - dim;
751 vrect = visualRect( QRect(xpos, y + h / 2 - dim / 2, dim, dim), r );
755 g2.setColor( QColorGroup::ButtonText, g2.highlightedText() );
756 drawPrimitive( arrow, p, vrect, g2, dis ? Style_Default : Style_Enabled, opt );
760 drawPrimitive( arrow, p, vrect, cg, dis ? Style_Default : Style_Enabled, opt );
766 p->setPen( cg.dark() );
774 bool active = flags & Style_Active;
775 bool down = flags & Style_Down;
781 //QColor col; mix( 0.5, cg.mid(), Qt::white, col );
782 //drawGradient( p, r, col, cg.light(), UpToDown, linear );
783 p->setPen( cg.light() );
784 p->setBrush( cg.light() );
787 p->setPen( cg.dark() );
788 int w = r.width()-1, h = r.height();
789 p->drawLine( r.x(), r.y(), r.x()+w, r.y() );
790 p->drawLine( r.x(), r.y(), r.x(), r.y()+h );
791 p->drawLine( r.x()+w, r.y(), r.x()+w, r.y()+h );
793 p->translate( 1, 1 );
796 drawGradient( p, r, cg.light(), cg.background(), active ? DownToUp : UpToDown, linear );
798 QCommonStyle::drawControl(element, p, widget, pr, cg, flags, opt);
803 case CE_MenuBarEmptyArea:
805 drawGradient( p, r, cg.light(), cg.background(), UpToDown, linear );
809 case CE_ToolButtonLabel:
811 const QToolButton *toolbutton = (const QToolButton *) widget;
812 QObject* parent = toolbutton->parent();
816 if( parent->inherits( "QToolBar" ) )
818 tb = ( QToolBar* )parent;
822 parent = parent->parent();
823 parent = toolbutton->parent();
828 if( tb->orientation()==Qt::Horizontal )
832 drawGradient( p, r, cg.light(), cg.background(), horiz ? UpToDown : LeftToRight, linear );
834 else if( parent->inherits( "QDockWindowHandle" ) )
836 QWidget* w = ( QWidget* ) parent;
837 QDockWindow* wnd = ( QDockWindow* )w->parent();
838 if( !wnd->orientation()==Qt::Horizontal )
843 QPoint pp( r.x(), r.y() ),
844 qq = toolbutton->mapToParent( pp );
846 bitBlt( p->device(), r.x(), r.y(), w, horiz ? qq.x()-r.width() : qq.x(),
847 horiz ? qq.y() : qq.y()+r.height(),
848 r.width(), r.height(), Qt::CopyROP, true );
851 bool highlight = ( flags & Style_MouseOver ),
852 down = ( flags & ( Style_Down | Style_On ) ),
853 en = toolbutton->isEnabled();
858 drawGradient( p, r, cg.light(), cg.background(), horiz==1 ? DownToUp : RightToLeft, linear );
859 p->setPen( cg.background() );
864 p->setPen( cg.dark() );
865 p->setBrush( cg.light() );
870 p->setPen( cg.dark() );
871 QColor col; mix( 0.05, cg.background(), Qt::black, col );
878 Qt::ArrowType arrowType = opt.isDefault() ? Qt::DownArrow : opt.arrowType();
880 int shiftX = 0, shiftY = 0;
881 if( flags & ( Style_Down | Style_On ) )
883 shiftX = pixelMetric(PM_ButtonShiftHorizontal, widget);
884 shiftY = pixelMetric(PM_ButtonShiftVertical, widget);
887 if (!opt.isDefault())
892 case Qt::LeftArrow: pe = PE_ArrowLeft; break;
893 case Qt::RightArrow: pe = PE_ArrowRight; break;
894 case Qt::UpArrow: pe = PE_ArrowUp; break;
896 case Qt::DownArrow: pe = PE_ArrowDown; break;
899 rect.moveBy(shiftX, shiftY);
900 drawPrimitive(pe, p, rect, cg, flags, opt);
904 QColor btext = toolbutton->paletteForegroundColor();
906 if (toolbutton->iconSet().isNull() &&
907 ! toolbutton->text().isNull() &&
908 ! toolbutton->usesTextLabel())
910 int alignment = AlignCenter | ShowPrefix;
911 if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
912 alignment |= NoAccel;
914 rect.moveBy(shiftX, shiftY);
915 drawItem( p, rect, alignment, cg, flags & Style_Enabled, 0, toolbutton->text(),
916 toolbutton->text().length(), &btext);
921 QIconSet::Size size =
922 toolbutton->usesBigPixmap() ? QIconSet::Large : QIconSet::Small;
923 QIconSet::State state = toolbutton->isOn() ? QIconSet::On : QIconSet::Off;
925 if( !toolbutton->isEnabled() )
926 mode = QIconSet::Active; //QIconSet::Disabled;
927 else if( flags & (Style_Down | Style_On ) || ( flags & Style_Raised ) && (flags & Style_AutoRaise))
928 mode = QIconSet::Active;
930 mode = QIconSet::Normal;
931 pm = toolbutton->iconSet().pixmap( size, mode, state );
933 if( toolbutton->usesTextLabel() )
935 p->setFont( toolbutton->font() );
936 QRect pr = rect, tr = rect;
937 int alignment = ShowPrefix;
938 if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
939 alignment |= NoAccel;
941 if( toolbutton->textPosition() == QToolButton::Under )
943 int fh = p->fontMetrics().height();
944 pr.addCoords( 0, 1, 0, -fh-3 );
945 tr.addCoords( 0, pr.bottom(), 0, -3 );
946 pr.moveBy(shiftX, shiftY);
947 drawItem( p, pr, AlignCenter, cg, TRUE, &pm, QString::null );
948 alignment |= AlignCenter;
952 pr.setWidth( pm.width() + 8 );
953 tr.addCoords( pr.right(), 0, 0, 0 );
954 pr.moveBy(shiftX, shiftY);
956 drawItem( p, pr, AlignCenter, cg, TRUE, &pm, QString::null );
957 alignment |= AlignLeft | AlignVCenter;
960 tr.moveBy(shiftX, shiftY);
961 drawItem( p, tr, alignment, cg, flags & Style_Enabled, 0, toolbutton->textLabel(),
962 toolbutton->textLabel().length(), &btext);
966 /*if( en && !highlight )
967 mix( 0.6, pm, cg.background() );
970 toGrayscale( pm, 1.1 );
971 mix( 0.8, pm, cg.background() );
974 rect.moveBy(shiftX, shiftY);
975 drawItem( p, rect, AlignCenter, cg, true, &pm, QString::null );
984 QPen oldPen = p->pen();
987 bool selected = flags & Style_Selected;
989 p->setPen( cg.midlight() );
990 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );
993 r2.setRect( r2.left(), r2.top() + 1, r2.width(), r2.height() - 1 );
995 r2.setRect( r2.left(), r2.top(), r2.width() - 2, r2.height() - 1 );
997 p->setPen( cg.foreground() );
998 QBrush brsh = cg.brush( selected ? QColorGroup::Base : QColorGroup::Background );
999 p->fillRect( r2.left(), r2.top(), r2.width(), r2.height() - 1, brsh );
1000 p->drawRect( r2.left(), r2.top(), r2.width(), r2.height() - 1 );
1004 p->setPen( cg.shadow() );
1005 p->drawLine( r2.left() + 1, r2.bottom(), r2.right() + 1, r2.bottom() );
1006 p->drawLine( r2.right() + 1, r2.top() + 1, r2.right() + 1, r2.bottom() );
1014 if ( flags & Style_Enabled && !( flags & Style_Down || flags & Style_On ) )
1016 const QPushButton* button = (const QPushButton*)widget;
1017 QRect br = QRect( button->mapToGlobal( button->rect().topLeft() ), button->rect().size() );
1018 if ( br.contains( QCursor::pos() ) )
1019 flags |= Style_MouseOver;
1022 PARENT_STYLE::drawControl( element, p, widget, r, cg, flags, opt );
1027 PARENT_STYLE::drawControl( element, p, widget, r, cg, flags, opt );
1032 QRect SalomeStyle::subRect( SubRect subrect, const QWidget* w ) const
1034 QRect r = PARENT_STYLE::subRect( subrect, w );
1035 if ( subrect==SR_DockWindowHandleRect && w->inherits( "QDockWindowHandle" ) )
1037 QDockWindow* wnd = ( QDockWindow* ) w->parent();
1038 if( wnd->orientation()==Qt::Vertical )
1039 r.setWidth( w->width() );
1042 r.setY( r.y()+r.height()-w->height() );
1043 r.setHeight( w->height() );
1050 void SalomeStyle::drawComplexControl( ComplexControl control, QPainter* p, const QWidget* widget,
1051 const QRect& r, const QColorGroup& cg, SFlags flags,
1052 SCFlags controls, SCFlags active, const QStyleOption& opt ) const
1058 ((SalomeStyle*)this)->myTitleParent = 0;
1063 if ( controls & SC_ComboBoxArrow )
1065 SFlags flags = Style_Default;
1067 qDrawShadeRect( p, r, cg, true, pixelMetric( PM_DefaultFrameWidth, widget ),
1068 0, widget->isEnabled() ? &cg.brush( QColorGroup::Base ) : &cg.brush( QColorGroup::Background ) );
1070 QRect ar = QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget, SC_ComboBoxArrow ), widget );
1071 if ( active == SC_ComboBoxArrow )
1073 p->setPen( cg.dark() );
1074 p->setBrush( cg.brush( QColorGroup::Button ) );
1078 qDrawWinPanel( p, ar, cg, FALSE, &cg.brush( QColorGroup::Button ) );
1080 ar.addCoords( 2, 2, -2, -2 );
1081 if ( widget->isEnabled() )
1082 flags |= Style_Enabled;
1084 if ( active == SC_ComboBoxArrow )
1085 flags |= Style_Sunken;
1086 drawPrimitive( PE_ArrowDown, p, ar, cg, flags );
1088 PARENT_STYLE::drawComplexControl( control, p, widget, r, cg, flags, controls & ~SC_ComboBoxArrow, active, opt );
1092 if( widget->inherits( "QTitleBar" ) )
1093 ( ( SalomeStyle* )this )->myTitleParent = ( QWidget* )widget->parent();
1096 PARENT_STYLE::drawComplexControl( control, p, widget, r, cg, flags, controls, active, opt );
1101 QPixmap SalomeStyle::stylePixmap( StylePixmap st, const QWidget* w, const QStyleOption& opt ) const
1105 case SP_DockWindowCloseButton:
1106 case SP_TitleBarCloseButton:
1107 return QPixmap( cross_xpm );
1108 case SP_TitleBarMaxButton:
1109 return QPixmap( maximize_xpm );
1110 case SP_TitleBarNormalButton:
1111 return QPixmap( normal_xpm );
1112 case SP_TitleBarMinButton:
1113 return QPixmap( minimize_xpm );
1115 return PARENT_STYLE::stylePixmap( st, w, opt );
1119 int SalomeStyle::pixelMetric( PixelMetric pm, const QWidget* widget ) const
1125 case PM_ButtonMargin:
1128 case PM_DockWindowFrameWidth:
1131 case PM_TabBarTabOverlap:
1134 case PM_TabBarTabHSpace:
1137 case PM_TabBarTabShiftHorizontal:
1138 case PM_TabBarTabShiftVertical:
1141 case PM_TabBarTabVSpace:
1144 case PM_DefaultFrameWidth:
1147 case PM_SpinBoxFrameWidth:
1150 case PM_ProgressBarChunkWidth:
1154 ret = PARENT_STYLE::pixelMetric( pm, widget );
1160 QString SalomeStyle::titleText( const QString& txt, const int W, const QFontMetrics& fm ) const
1162 QString res = txt.stripWhiteSpace();
1164 if ( fm.width( res ) > W )
1166 QString end( "..." );
1167 while ( !res.isEmpty() && fm.width( res + end ) > W )
1168 res.remove( res.length() - 1, 1 );
1170 if ( !res.isEmpty() )
1178 Class: SalomeStylePlugin [Internal]
1179 Descr: Plugin for Qt style mechanism
1182 SalomeStylePlugin::SalomeStylePlugin()
1186 SalomeStylePlugin::~SalomeStylePlugin()
1190 QStringList SalomeStylePlugin::keys() const
1192 return QStringList() << "salome";
1195 QStyle* SalomeStylePlugin::create( const QString& str )
1197 if ( str == "salome" )
1198 return new SalomeStyle();
1203 Q_EXPORT_PLUGIN( SalomeStylePlugin )