-#include "SalomeStyle.h"\r
-\r
-#include <qimage.h>\r
-#include <qcursor.h>\r
-#include <qtabbar.h>\r
-#include <qpalette.h>\r
-#include <qtoolbar.h>\r
-#include <qspinbox.h>\r
-#include <qpainter.h>\r
-#include <qlineedit.h>\r
-#include <qlistview.h>\r
-#include <qdrawutil.h>\r
-#include <qpopupmenu.h>\r
-#include <qpushbutton.h>\r
-#include <qobjectlist.h>\r
-#include <qtoolbutton.h>\r
-#include <qapplication.h>\r
-\r
-static const char* const hole_xpm[] = {\r
-"3 3 3 1",\r
-". c None",\r
-"a c #999999",\r
-"b c #FFFFFF",\r
-"aa.",\r
-"aab",\r
-".bb"\r
-};\r
-\r
-static const char* const cross_xpm[] = {\r
-"12 12 4 1",\r
-". c None",\r
-"a c #000000",\r
-"b c #FFFFFF",\r
-"c c #666666",\r
-"............",\r
-"............",\r
-"............",\r
-".aaaa..aaaa.",\r
-"..abbaabba..",\r
-"...abbbba...",\r
-"....abba....",\r
-"...abbbba...",\r
-"..abbaabba..",\r
-".aaaa..aaaa.",\r
-"............",\r
-"............"\r
-};\r
-\r
-static const char* const maximize_xpm[] = {\r
-"12 12 4 1",\r
-". c None",\r
-"a c #000000",\r
-"b c #FFFFFF",\r
-"c c #666666",\r
-"............",\r
-".aaaaaaaaaa.",\r
-".acccccccca.",\r
-".acccccccca.",\r
-".abbbbbbbba.",\r
-".abbbbbbbba.",\r
-".abbbbbbbba.",\r
-".abbbbbbbba.",\r
-".abbbbbbbba.",\r
-".abbbbbbbba.",\r
-".aaaaaaaaaa.",\r
-"............"\r
-};\r
-\r
-static const char* const normal_xpm[] = {\r
-"12 12 4 1",\r
-". c None",\r
-"a c #000000",\r
-"b c #FFFFFF",\r
-"c c #666666",\r
-"............",\r
-"...aaaaaaaa.",\r
-"...acccccca.",\r
-"...abbbbbba.",\r
-"...aaaaaaba.",\r
-".aaaaaaaaba.",\r
-".accccccaba.",\r
-".abbbbbbaaa.",\r
-".abbbbbba...",\r
-".abbbbbba...",\r
-".aaaaaaaa...",\r
-"............"\r
-};\r
-\r
-static const char* const minimize_xpm[] = {\r
-"12 12 4 1",\r
-". c None",\r
-"a c #000000",\r
-"b c #FFFFFF",\r
-"c c #666666",\r
-"............",\r
-"............",\r
-"............",\r
-"............",\r
-"............",\r
-"............",\r
-"............",\r
-"............",\r
-"aaaaaaaaaaaa",\r
-"abbbbbbbbbba",\r
-"aaaaaaaaaaaa",\r
-"............"\r
-};\r
-\r
-/*!\r
- Class: SalomeStyle [Public]\r
- Descr: Style for SALOME platform\r
-*/\r
-\r
-SalomeStyle::SalomeStyle()\r
-: myTitleParent( 0 )\r
-{\r
- qApp->installEventFilter( this ); \r
-}\r
-\r
-SalomeStyle::~SalomeStyle()\r
-{\r
-}\r
-\r
-void SalomeStyle::polish( QWidget* w )\r
-{\r
- if ( !w )\r
- return;\r
-/*\r
- if ( w->inherits( "QLineEdit" ) )\r
- {\r
- QLineEdit* fr = (QLineEdit*)w;\r
- if ( w->parentWidget() && w->parentWidget()->inherits( "QSpinWidget" ) )\r
- fr->setFrameStyle( QFrame::Plain );\r
- else\r
- {\r
- fr->setFrameStyle( QFrame::Plain | QFrame::Box );\r
- fr->setLineWidth( 1 );\r
- fr->setMidLineWidth( 0 );\r
- }\r
- }\r
- else\r
-*/\r
- if ( w->inherits( "QToolBar" ) )\r
- {\r
- QToolBar* tb = (QToolBar*)w;\r
- tb->setFrameStyle( QFrame::ToolBarPanel | QFrame::Plain );\r
- tb->setLineWidth( 1 );\r
- tb->setMidLineWidth( 1 );\r
- }\r
- else\r
- if ( w->inherits( "QDockWindow" ) )\r
- {\r
- QDockWindow* dw = (QDockWindow*)w;\r
- dw->setFrameStyle( QFrame::ToolBarPanel | QFrame::Raised );\r
- }\r
-/*\r
- else if ( w->inherits( "QListView" ) )\r
- {\r
- QListView* lv = (QListView*)w;\r
- lv->setFrameStyle( QFrame::Box | QFrame::Plain );\r
- }\r
-*/\r
- else\r
- PARENT_STYLE::polish( w );\r
-}\r
-\r
-bool SalomeStyle::eventFilter( QObject* o, QEvent* e )\r
-{\r
- if ( e->type() == QEvent::FocusIn || e->type() == QEvent::FocusOut )\r
- {\r
- QDockWindow* wnd = NULL;\r
- while( o && !wnd )\r
- if( o->inherits( "QDockWindow" ) )\r
- wnd = ( QDockWindow* )o;\r
- else\r
- o = o->parent();\r
-\r
- if ( wnd )\r
- {\r
- const QObjectList* objList = o->children();\r
- for( QObjectListIterator anIt( *objList ); anIt.current(); ++anIt )\r
- if( anIt.current()->inherits( "QDockWindowHandle" ) )\r
- {\r
- QWidget* ww = ( QWidget* )anIt.current();\r
- ww->repaint( ww->rect() );\r
- const QObjectList* wc = ww->children();\r
- for( QObjectListIterator anIt2( *wc ); anIt2.current(); ++anIt2 )\r
- if( anIt2.current()->inherits( "QToolButton" ) )\r
- {\r
- QWidget* tb = ( QWidget* )anIt2.current();\r
- tb->repaint( tb->rect() );\r
- }\r
- } \r
- }\r
- }\r
-\r
- if ( o && o->inherits( "QPushButton" ) && ( e->type() == QEvent::Enter || e->type() == QEvent::Leave ) )\r
- ((QWidget*)o)->update();\r
-\r
- return false;\r
-}\r
-\r
-double linear( double x )\r
-{\r
- return x;\r
-}\r
-\r
-void SalomeStyle::mix( const double t, const QColor& c1, const QColor& c2, QColor& res )\r
-{\r
- if( t<0.0 || t>1.0 )\r
- return;\r
-\r
- int r = int( c1.red() * (1-t) + c2.red() * t ),\r
- g = int( c1.green() * (1-t) + c2.green() * t ),\r
- b = int( c1.blue() * (1-t) + c2.blue() * t );\r
- res.setRgb( r, g, b );\r
-}\r
-\r
-void SalomeStyle::mix( const double t, QRgb& rgb1, const QRgb& rgb2 )\r
-{\r
- if( t<0.0 || t>1.0 )\r
- return;\r
-\r
- int c[2][4] = { qRed( rgb1 ), qGreen( rgb1 ), qBlue( rgb1 ), qAlpha( rgb1 ),\r
- qRed( rgb2 ), qGreen( rgb2 ), qBlue( rgb2 ), qAlpha( rgb2 ) };\r
- for( int i=0; i<4; i++ )\r
- c[0][i] = (int)( c[0][i] * (1-t) + c[1][i] * t );\r
-\r
- rgb1 = qRgba( c[0][0], c[0][1], c[0][2], qAlpha( rgb1 ) );\r
-}\r
-\r
-void SalomeStyle::mix( const double t, QPixmap& pix, const QColor& col )\r
-{\r
- if( t<0.0 || t>1.0 )\r
- return;\r
-\r
- QImage anImage = pix.convertToImage();\r
- if( anImage.isNull() )\r
- return;\r
-\r
- if( anImage.depth()!=32 )\r
- anImage = anImage.convertDepth( 32 );\r
-\r
- int w = anImage.width(),\r
- h = anImage.height();\r
-\r
- QRgb colrgb = col.rgb(), cur;\r
- for( int y=0; y<h; y++ )\r
- {\r
- uchar* line = anImage.scanLine( y );\r
- QRgb* colorline = ( QRgb* ) line;\r
- for( int x=0; x<w; x++ )\r
- {\r
- cur = colorline[ x ];\r
- mix( t, cur, colrgb );\r
- colorline[ x ] = cur;\r
- }\r
- }\r
- pix = anImage;\r
-}\r
-\r
-void SalomeStyle::toGrayscale( QPixmap& pix, double k )\r
-{\r
- QImage anImage = pix.convertToImage();\r
- if( anImage.isNull() )\r
- return;\r
-\r
- if( anImage.depth()!=32 )\r
- anImage = anImage.convertDepth( 32 );\r
-\r
- int w = anImage.width(),\r
- h = anImage.height();\r
-\r
- for( int y=0; y<h; y++ )\r
- {\r
- uchar* line = anImage.scanLine( y );\r
- QRgb* colorline = ( QRgb* ) line;\r
- for( int x=0; x<w; x++ )\r
- {\r
- int gray = (int)( k * qGray( colorline[ x ] ) );\r
- if ( gray>255 )\r
- gray = 255;\r
- else if( gray<0 )\r
- gray = 0;\r
- colorline[ x ] = qRgba( gray, gray, gray, qAlpha( colorline[x] ) );\r
- }\r
- }\r
- pix = anImage;\r
-}\r
-\r
-void SalomeStyle::drawGradient( QPainter* p, const QRect& r,\r
- const QColor& c1, const QColor& c2,\r
- const Direction d, gradient_func f ) const \r
-{\r
- p->save();\r
- p->translate( r.x(), r.y() );\r
-\r
- QColor mid;\r
- if( d==LeftToRight || d==RightToLeft )\r
- for( int xmax = r.width(), x = d==LeftToRight ? 0 : xmax;\r
- d==LeftToRight ? x<=xmax : x>=0;\r
- d==LeftToRight ? x++ : x-- )\r
- {\r
- double t = double( x ) / double( xmax );\r
- mix( d==LeftToRight ? f(t) : 1-f(t), c1, c2, mid );\r
- p->setPen( mid );\r
- p->drawLine( x, 0, x, r.height() );\r
- }\r
- else\r
- for( int ymax = r.height(), y = d==UpToDown ? 0 : ymax;\r
- d==UpToDown ? y<=ymax : y>=0;\r
- d==UpToDown ? y++ : y-- )\r
- {\r
- double t = double( y ) / double( ymax );\r
- mix( d==UpToDown ? f(t) : 1-f(t), c1, c2, mid );\r
- p->setPen( mid );\r
- p->drawLine( 0, y, r.width(), y );\r
- }\r
-\r
- p->restore();\r
-}\r
-\r
-void SalomeStyle::drawPrimitive( PrimitiveElement pe, QPainter* p, const QRect& r,\r
- const QColorGroup& cg, SFlags flags, const QStyleOption& opt ) const\r
-{\r
- switch ( pe )\r
- {\r
- case PE_ButtonTool:\r
- if ( !myTitleParent )\r
- PARENT_STYLE::drawPrimitive( pe, p, r, cg, flags, opt );\r
- break;\r
-\r
- case PE_DockWindowResizeHandle:\r
- p->fillRect( r.x(), r.y(), r.width(), r.height(), cg.dark() );\r
- if ( flags & Style_Horizontal )\r
- p->fillRect( r.x(), r.y() + 1, r.width(), r.height() - 2, cg.midlight() );\r
- else\r
- p->fillRect( r.x() + 1, r.y(), r.width() - 2, r.height(), cg.midlight() );\r
- break;\r
-\r
- case PE_DockWindowHandle:\r
- {\r
- QPaintDevice* pd = p->device();\r
- if ( !pd )\r
- break;\r
-\r
- QWidget* w = (QWidget*)pd;\r
-\r
- if ( !w || !w->inherits( "QDockWindowHandle" ) )\r
- break;\r
-\r
- QDockWindow* wnd = ( QDockWindow* ) w->parent();\r
- if ( !wnd )\r
- return;\r
-\r
- QObject* activeWidget = qApp->focusWidget();\r
- QDockWindow* activeWnd = 0;\r
- while ( !activeWnd && activeWidget )\r
- {\r
- if ( activeWidget->inherits( "QDockWindow" ) )\r
- activeWnd = (QDockWindow*)activeWidget;\r
- else\r
- activeWidget = activeWidget->parent();\r
- }\r
-\r
- bool act = wnd == activeWnd, horiz = flags & Style_Horizontal;\r
-\r
- QPixmap hole( (const char**)hole_xpm );\r
-\r
- if ( wnd->inherits( "QToolBar" ) )\r
- {\r
- drawGradient( p, r, cg.light(), cg.background(), horiz ? UpToDown : LeftToRight, linear );\r
-\r
- int c = 4, i; double d = ( horiz ? r.height() : r.width() ) / ( c + 1 );\r
- QBrush fill = cg.brush( QColorGroup::Dark );\r
- p->setPen( Qt::red );\r
- for ( i = 0; i < c; i++ )\r
- {\r
- if ( horiz )\r
- p->drawPixmap( r.x() + r.width() / 2 - 1, (int)( r.y() + ( i + 1 ) * d - 1 ), hole );\r
- else\r
- p->drawPixmap( (int) ( r.x() + ( i + 1 ) * d - 1 ), r.y() + r.height() / 2 - 1, hole );\r
- }\r
-\r
- int dd = (int(d)/2) + (int(d)%2);\r
- for ( i = 0; i < c - 1; i++ )\r
- {\r
- if ( horiz )\r
- p->drawPixmap( r.x() + r.width() / 2 + 2, (int)( r.y() + dd + ( i + 1 ) * d - 1 ), hole );\r
- else\r
- p->drawPixmap( (int)( r.x() + dd + ( i + 1 ) * d - 1 ), r.y() + r.height() / 2 + 2, hole );\r
- }\r
- }\r
- else\r
- {\r
- int d = 1;\r
- QRect rr( r.x()+d, r.y()+d, r.width()-2*d, r.height()-2*d );\r
-\r
- QColor col; \r
- if ( act )\r
- mix( 0.5, cg.highlight(), Qt::white, col );\r
- else\r
- col = cg.background();\r
-\r
- drawGradient( p, rr, act ? cg.highlight() : cg.dark(), col,\r
- horiz ? LeftToRight : UpToDown, linear );\r
-\r
- int txtW = flags & Style_Horizontal ? r.height() : r.width();\r
- int txtH = flags & Style_Horizontal ? r.width() : r.height();\r
-\r
- QString title = titleText( wnd->caption(), txtW, p->fontMetrics() );\r
-\r
- p->save();\r
- if ( flags & Style_Horizontal )\r
- {\r
- p->rotate( 270 );\r
- p->translate( -r.height() - r.y(), r.width() - r.x() );\r
- p->drawText( 0, 0, txtW, txtH, Qt::AlignCenter, title );\r
- }\r
- else\r
- p->drawText( r, Qt::AlignCenter, title );\r
- p->restore();\r
- }\r
- break;\r
- }\r
-\r
- case PE_DockWindowSeparator:\r
- {\r
- bool horiz = ( flags & Style_Horizontal );\r
- QWidget* w = ( QWidget* )p->device();\r
- if( w->inherits( "QToolBarSeparator" ) )\r
- {\r
- drawGradient( p, r, cg.light(), cg.background(), horiz ? UpToDown : LeftToRight, linear );\r
- int w = r.width(), h = r.height();\r
- int part = 8;\r
-\r
- p->setPen( cg.dark() );\r
- if( horiz )\r
- p->drawLine( r.x() + w/2, r.y() + h/part, r.x() + w/2, r.y() + (part-1)*h/part );\r
- else\r
- p->drawLine( r.x() + w/part, r.y() + h/2, r.x() + (part-1)*w/part, r.y() + h/2 );\r
-\r
- p->setPen( cg.light() );\r
- if( horiz )\r
- p->drawLine( r.x() + w/2 + 1, r.y() + h/part + 1, r.x() + w/2 + 1, r.y() + (part-1)*h/part + 1 );\r
- else\r
- p->drawLine( r.x() + w/part + 1, r.y() + h/2 + 1, r.x() + (part-1)*w/part + 1, r.y() + h/2 + 1 );\r
- }\r
- else\r
- PARENT_STYLE::drawPrimitive( pe, p, r, cg, flags, opt );\r
- break;\r
- }\r
- \r
- case PE_PanelDockWindow:\r
- {\r
- QWidget* w = ( QWidget* )p->device();\r
-\r
- int offset = pixelMetric( PM_DockWindowHandleExtent, w );\r
- if ( w->inherits( "QToolBar" ) )\r
- {\r
- bool vert = ( ( QToolBar* )w )->orientation() == Qt::Vertical;\r
- if ( vert )\r
- drawGradient( p, QRect( r.x(), r.y()+offset, r.x()+r.width(), r.y()+offset ),\r
- cg.light(), cg.background(), LeftToRight, linear );\r
- else\r
- drawGradient( p, QRect( r.x()+offset, r.y(), r.x()+offset, r.y()+r.height() ),\r
- cg.light(), cg.background(), UpToDown, linear );\r
-\r
- p->setPen( QPen( cg.light(), 1 ) );\r
- p->drawRect( r );\r
- }\r
- else\r
- {\r
- p->setPen( QPen( cg.dark(), 1 ) );\r
- p->setBrush( cg.light() );\r
- p->drawRect( r );\r
- }\r
-\r
- break;\r
- }\r
-\r
- case PE_PanelPopup:\r
- p->setPen( QPen( cg.dark(), 1 ) );\r
- p->setBrush( cg.light() );\r
- p->drawRect( r );\r
- break;\r
-\r
- case PE_HeaderSection:\r
- {\r
- QColor col; mix( 0.2, cg.light(), Qt::black, col );\r
- drawGradient( p, r, cg.light(), col, DownToUp, linear );\r
- drawGradient( p, QRect( r.x(), r.y(), 1, r.height() ), cg.light(), cg.dark(), DownToUp, linear );\r
- p->setPen( cg.dark() );\r
- p->drawLine( r.x(), r.y()+r.height()-1, r.x()+r.width(), r.y()+r.height()-1 );\r
- break;\r
- }\r
-\r
- case PE_Splitter:\r
- p->fillRect( r.x() + 1, r.y() + 1, r.width() - 2, r.height() - 2, cg.dark() );\r
- p->fillRect( r.x() + 2, r.y() + 2, r.width() - 4, r.height() - 4, cg.midlight() );\r
- break;\r
-\r
- case PE_ButtonBevel:\r
- PARENT_STYLE::drawPrimitive( PE_ButtonDropDown, p, r, cg, flags, opt );\r
- break;\r
-\r
- case PE_ButtonCommand:\r
- {\r
- QColorGroup cGrp( cg );\r
- if ( flags & Style_MouseOver )\r
- cGrp.setColor( QColorGroup::Button, cGrp.midlight() );\r
-\r
- if ( flags & Style_MouseOver )\r
- PARENT_STYLE::drawPrimitive( PE_ButtonDropDown, p, r, cGrp, flags, opt );\r
- else\r
- PARENT_STYLE::drawPrimitive( flags & Style_Raised ? PE_ButtonDropDown : pe, p, r, cGrp, flags, opt );\r
- }\r
- break;\r
-\r
- default:\r
- PARENT_STYLE::drawPrimitive( pe, p, r, cg, flags, opt );\r
- break;\r
- }\r
-}\r
-\r
-void SalomeStyle::drawControl( ControlElement element, QPainter* p, const QWidget* widget, const QRect& r,\r
- const QColorGroup& cg, SFlags flags, const QStyleOption& opt ) const \r
-{\r
- switch( element )\r
- {\r
- case CE_PopupMenuItem:\r
- {\r
- if(! widget || opt.isDefault())\r
- break;\r
-\r
- const QPopupMenu *popupmenu = (const QPopupMenu *) widget;\r
- QMenuItem *mi = opt.menuItem();\r
- if( !mi )\r
- break;\r
-\r
- int tab = opt.tabWidth();\r
- int maxpmw = opt.maxIconWidth();\r
- bool dis = !( flags & Style_Enabled );\r
- bool checkable = popupmenu->isCheckable();\r
- bool act = flags & Style_Active;\r
- bool use2000style = true;\r
- int x, y, w, h;\r
-\r
- int windowsItemFrame = 2,\r
- windowsItemHMargin = 5,\r
- windowsItemVMargin = 1,\r
- windowsRightBorder = 2,\r
- windowsArrowHMargin = 2;\r
-\r
- r.rect(&x, &y, &w, &h);\r
-\r
- if ( checkable )\r
- {\r
- // space for the checkmarks\r
- if (use2000style)\r
- maxpmw = QMAX( maxpmw, 20 );\r
- else\r
- maxpmw = QMAX( maxpmw, 12 );\r
- }\r
-\r
- int checkcol = maxpmw;\r
-\r
- if ( mi && mi->isSeparator() )\r
- {\r
- p->setPen( cg.dark() );\r
- p->drawLine( x+3*checkcol/2, y, x+w, y );\r
- //p->setPen( cg.light() );\r
- //p->drawLine( x, y+1, x+w, y+1 );\r
- return;\r
- }\r
-\r
- QBrush fill = ( act && !dis ?\r
- cg.brush( QColorGroup::Highlight ) :\r
- cg.brush( QColorGroup::Light ) );\r
- p->fillRect( x, y, w, h, fill );\r
-\r
- if( !mi )\r
- return;\r
-\r
- int xpos = x;\r
- QRect vrect = visualRect( QRect( xpos, y, checkcol, h ), r );\r
- int xvis = vrect.x();\r
-\r
- if( mi->isChecked() )\r
- {\r
- if( act && !dis )\r
- qDrawShadePanel( p, xvis, y, checkcol, h,\r
- cg, TRUE, 1, &cg.brush( QColorGroup::Button ) );\r
- else\r
- {\r
- QBrush fill( cg.light(), Dense4Pattern );\r
- // set the brush origin for the hash pattern to the x/y coordinate\r
- // of the menu item's checkmark... this way, the check marks have\r
- // a consistent look\r
- QPoint origin = p->brushOrigin();\r
- p->setBrushOrigin( xvis, y );\r
- qDrawShadePanel( p, xvis, y, checkcol, h, cg, TRUE, 1, &fill );\r
- // restore the previous brush origin\r
- p->setBrushOrigin( origin );\r
- }\r
- }\r
- else if( !act )\r
- p->fillRect(x+checkcol, y, w-checkcol , h, cg.brush( QColorGroup::Light ));\r
-\r
- if( !( act && !dis ) && !mi->isChecked() )\r
- {\r
- QColor col; mix( 0.5, cg.mid(), Qt::white, col );\r
- drawGradient( p, QRect( xvis, y, checkcol, h+1 ), cg.light(), col, LeftToRight, linear );\r
- }\r
-\r
- if( mi->iconSet() )\r
- { // draw iconset\r
- QIconSet::Mode mode = dis ? QIconSet::Active : QIconSet::Normal;\r
- if(act && !dis )\r
- mode = QIconSet::Active;\r
- QPixmap pixmap;\r
- if( checkable && mi->isChecked() )\r
- pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode, QIconSet::On );\r
- else\r
- pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );\r
- int pixw = pixmap.width();\r
- int pixh = pixmap.height();\r
-\r
- if( dis )\r
- toGrayscale( pixmap, 1.1 );\r
-\r
- //if( act && !dis && !mi->isChecked() )\r
- // qDrawShadePanel( p, xvis, y, checkcol, h, cg, FALSE, 1, &cg.brush( QColorGroup::Button ) );\r
-\r
- QRect pmr( 0, 0, pixw, pixh );\r
- pmr.moveCenter( vrect.center() );\r
- p->setPen( cg.text() );\r
- p->drawPixmap( pmr.topLeft(), pixmap );\r
-\r
- QBrush fill = ( act ? cg.brush( QColorGroup::Highlight ) : cg.brush( QColorGroup::Light ));\r
- int xp = xpos + checkcol + 1;\r
- if( !dis )\r
- p->fillRect( visualRect( QRect( xp, y, w - checkcol - 1, h ), r ), fill);\r
- }\r
- else if( checkable )\r
- { // just "checking"...\r
- if( mi->isChecked() )\r
- {\r
- int xp = xpos + windowsItemFrame;\r
-\r
- SFlags cflags = Style_Default;\r
- if( !dis )\r
- cflags |= Style_Enabled;\r
- if( act )\r
- cflags |= Style_On;\r
-\r
- drawPrimitive( PE_CheckMark, p,\r
- visualRect( QRect( xp, y + windowsItemFrame,\r
- checkcol - 2*windowsItemFrame,\r
- h - 2*windowsItemFrame), r ), cg, cflags, opt );\r
- }\r
- }\r
-\r
- p->setPen( act ? cg.highlightedText() : cg.buttonText() );\r
-\r
- QColor discol;\r
- if( dis )\r
- {\r
- discol = cg.text();\r
- p->setPen( discol );\r
- }\r
-\r
- int xm = windowsItemFrame + checkcol + windowsItemHMargin;\r
- xpos += xm;\r
-\r
- vrect = visualRect( QRect( xpos, y+windowsItemVMargin, w-xm-tab+1, h-2*windowsItemVMargin ), r );\r
- xvis = vrect.x();\r
- if( mi->custom() )\r
- {\r
- p->save();\r
- if ( dis && !act )\r
- {\r
- p->setPen( cg.light() );\r
- mi->custom()->paint( p, cg, act, !dis,\r
- xvis+1, y+windowsItemVMargin+1,\r
- w-xm-tab+1, h-2*windowsItemVMargin );\r
- p->setPen( discol );\r
- }\r
- mi->custom()->paint( p, cg, act, !dis, xvis, y+windowsItemVMargin,\r
- w-xm-tab+1, h-2*windowsItemVMargin );\r
- p->restore();\r
- }\r
- QString s = mi->text();\r
- if( !s.isNull() )\r
- { // draw text\r
- int t = s.find( '\t' );\r
- int text_flags = AlignVCenter | ShowPrefix | DontClip | SingleLine;\r
- if( !styleHint( SH_UnderlineAccelerator, widget ) )\r
- text_flags |= NoAccel;\r
- text_flags |= (QApplication::reverseLayout() ? AlignRight : AlignLeft );\r
- if( t >= 0 )\r
- { // draw tab text\r
- int xp = x + w - tab - windowsItemHMargin - windowsItemFrame + 1;\r
- if( use2000style )\r
- xp -= 20;\r
- else\r
- xp -= windowsRightBorder;\r
- int xoff = visualRect( QRect( xp, y+windowsItemVMargin, tab, h-2*windowsItemVMargin ), r ).x();\r
- if( dis && !act )\r
- {\r
- p->setPen( cg.light() );\r
- p->drawText( xoff+1, y+windowsItemVMargin+1, tab, h-2*windowsItemVMargin, text_flags, s.mid( t+1 ));\r
- p->setPen( discol );\r
- }\r
- p->drawText( xoff, y+windowsItemVMargin, tab, h-2*windowsItemVMargin, text_flags, s.mid( t+1 ) );\r
- s = s.left( t );\r
- }\r
- if( dis && !act )\r
- {\r
- p->setPen( cg.light() );\r
- p->drawText( xvis+1, y+windowsItemVMargin+1, w-xm-tab+1, h-2*windowsItemVMargin, text_flags, s, t );\r
- p->setPen( discol );\r
- }\r
- p->drawText( xvis, y+windowsItemVMargin, w-xm-tab+1, h-2*windowsItemVMargin, text_flags, s, t );\r
- }\r
- else if( mi->pixmap() )\r
- { // draw pixmap\r
- QPixmap *pixmap = mi->pixmap();\r
- if( pixmap->depth() == 1 )\r
- p->setBackgroundMode( OpaqueMode );\r
- p->drawPixmap( xvis, y+windowsItemFrame, *pixmap );\r
- if( pixmap->depth() == 1 )\r
- p->setBackgroundMode( TransparentMode );\r
- }\r
- if( mi->popup() )\r
- { // draw sub menu arrow\r
- int dim = (h-2*windowsItemFrame) / 2;\r
- PrimitiveElement arrow;\r
- arrow = ( QApplication::reverseLayout() ? PE_ArrowLeft : PE_ArrowRight );\r
- xpos = x+w - windowsArrowHMargin - windowsItemFrame - dim;\r
- vrect = visualRect( QRect(xpos, y + h / 2 - dim / 2, dim, dim), r );\r
- if( act )\r
- {\r
- QColorGroup g2 = cg;\r
- g2.setColor( QColorGroup::ButtonText, g2.highlightedText() );\r
- drawPrimitive( arrow, p, vrect, g2, dis ? Style_Default : Style_Enabled, opt );\r
- }\r
- else\r
- {\r
- drawPrimitive( arrow, p, vrect, cg, dis ? Style_Default : Style_Enabled, opt );\r
- }\r
- }\r
-\r
- if( act && !dis )\r
- {\r
- p->setPen( cg.dark() );\r
- p->drawRect( r );\r
- }\r
- break;\r
- }\r
-\r
- case CE_MenuBarItem:\r
- {\r
- bool active = flags & Style_Active;\r
- bool down = flags & Style_Down;\r
- QRect pr = r;\r
-\r
- p->save();\r
- if( active && down )\r
- {\r
- //QColor col; mix( 0.5, cg.mid(), Qt::white, col );\r
- //drawGradient( p, r, col, cg.light(), UpToDown, linear );\r
- p->setPen( cg.light() );\r
- p->setBrush( cg.light() );\r
- p->drawRect( r );\r
- \r
- p->setPen( cg.dark() );\r
- int w = r.width()-1, h = r.height();\r
- p->drawLine( r.x(), r.y(), r.x()+w, r.y() );\r
- p->drawLine( r.x(), r.y(), r.x(), r.y()+h );\r
- p->drawLine( r.x()+w, r.y(), r.x()+w, r.y()+h );\r
-\r
- p->translate( 1, 1 );\r
- }\r
- else\r
- drawGradient( p, r, cg.light(), cg.background(), active ? DownToUp : UpToDown, linear );\r
-\r
- QCommonStyle::drawControl(element, p, widget, pr, cg, flags, opt);\r
- p->restore();\r
- break;\r
- }\r
-\r
- case CE_MenuBarEmptyArea:\r
- {\r
- drawGradient( p, r, cg.light(), cg.background(), UpToDown, linear );\r
- break;\r
- }\r
-\r
- case CE_ToolButtonLabel:\r
- {\r
- const QToolButton *toolbutton = (const QToolButton *) widget;\r
- QObject* parent = toolbutton->parent();\r
-\r
- QToolBar* tb = NULL;\r
- while( parent )\r
- if( parent->inherits( "QToolBar" ) )\r
- {\r
- tb = ( QToolBar* )parent;\r
- break;\r
- }\r
- else\r
- parent = parent->parent();\r
- parent = toolbutton->parent();\r
-\r
- int horiz = -1;\r
- if( tb )\r
- {\r
- if( tb->orientation()==Qt::Horizontal )\r
- horiz = 1;\r
- else\r
- horiz = 0;\r
- drawGradient( p, r, cg.light(), cg.background(), horiz ? UpToDown : LeftToRight, linear );\r
- }\r
- else if( parent->inherits( "QDockWindowHandle" ) )\r
- {\r
- QWidget* w = ( QWidget* ) parent;\r
- QDockWindow* wnd = ( QDockWindow* )w->parent();\r
- if( !wnd->orientation()==Qt::Horizontal )\r
- horiz=1;\r
- else\r
- horiz=0;\r
-\r
- QPoint pp( r.x(), r.y() ),\r
- qq = toolbutton->mapToParent( pp );\r
- \r
- bitBlt( p->device(), r.x(), r.y(), w, horiz ? qq.x()-r.width() : qq.x(),\r
- horiz ? qq.y() : qq.y()+r.height(),\r
- r.width(), r.height(), Qt::CopyROP, true );\r
- }\r
-\r
- bool highlight = ( flags & Style_MouseOver ),\r
- down = ( flags & ( Style_Down | Style_On ) ),\r
- en = toolbutton->isEnabled();\r
-\r
- if( down )\r
- if( horiz>=0 )\r
- {\r
- drawGradient( p, r, cg.light(), cg.background(), horiz==1 ? DownToUp : RightToLeft, linear );\r
- p->setPen( cg.background() );\r
- p->drawRect( r );\r
- }\r
- else\r
- {\r
- p->setPen( cg.dark() );\r
- p->setBrush( cg.light() );\r
- p->drawRect( r );\r
- }\r
- if( highlight )\r
- {\r
- p->setPen( cg.dark() );\r
- QColor col; mix( 0.05, cg.background(), Qt::black, col );\r
- p->setBrush( col );\r
- p->drawRect( r );\r
- }\r
-\r
-\r
- QRect rect = r;\r
- Qt::ArrowType arrowType = opt.isDefault() ? Qt::DownArrow : opt.arrowType();\r
-\r
- int shiftX = 0, shiftY = 0;\r
- if( flags & ( Style_Down | Style_On ) )\r
- {\r
- shiftX = pixelMetric(PM_ButtonShiftHorizontal, widget);\r
- shiftY = pixelMetric(PM_ButtonShiftVertical, widget);\r
- }\r
-\r
- if (!opt.isDefault())\r
- {\r
- PrimitiveElement pe;\r
- switch (arrowType)\r
- {\r
- case Qt::LeftArrow: pe = PE_ArrowLeft; break;\r
- case Qt::RightArrow: pe = PE_ArrowRight; break;\r
- case Qt::UpArrow: pe = PE_ArrowUp; break;\r
- default:\r
- case Qt::DownArrow: pe = PE_ArrowDown; break;\r
- }\r
-\r
- rect.moveBy(shiftX, shiftY);\r
- drawPrimitive(pe, p, rect, cg, flags, opt);\r
- }\r
- else\r
- {\r
- QColor btext = toolbutton->paletteForegroundColor();\r
-\r
- if (toolbutton->iconSet().isNull() &&\r
- ! toolbutton->text().isNull() &&\r
- ! toolbutton->usesTextLabel())\r
- {\r
- int alignment = AlignCenter | ShowPrefix;\r
- if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))\r
- alignment |= NoAccel;\r
-\r
- rect.moveBy(shiftX, shiftY);\r
- drawItem( p, rect, alignment, cg, flags & Style_Enabled, 0, toolbutton->text(),\r
- toolbutton->text().length(), &btext);\r
- }\r
- else\r
- {\r
- QPixmap pm;\r
- QIconSet::Size size =\r
- toolbutton->usesBigPixmap() ? QIconSet::Large : QIconSet::Small;\r
- QIconSet::State state = toolbutton->isOn() ? QIconSet::On : QIconSet::Off;\r
- QIconSet::Mode mode;\r
- if( !toolbutton->isEnabled() )\r
- mode = QIconSet::Active; //QIconSet::Disabled;\r
- else if( flags & (Style_Down | Style_On ) || ( flags & Style_Raised ) && (flags & Style_AutoRaise))\r
- mode = QIconSet::Active;\r
- else\r
- mode = QIconSet::Normal;\r
- pm = toolbutton->iconSet().pixmap( size, mode, state );\r
-\r
- if( toolbutton->usesTextLabel() )\r
- {\r
- p->setFont( toolbutton->font() );\r
- QRect pr = rect, tr = rect;\r
- int alignment = ShowPrefix;\r
- if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))\r
- alignment |= NoAccel;\r
-\r
- if( toolbutton->textPosition() == QToolButton::Under )\r
- {\r
- int fh = p->fontMetrics().height();\r
- pr.addCoords( 0, 1, 0, -fh-3 );\r
- tr.addCoords( 0, pr.bottom(), 0, -3 );\r
- pr.moveBy(shiftX, shiftY);\r
- drawItem( p, pr, AlignCenter, cg, TRUE, &pm, QString::null );\r
- alignment |= AlignCenter;\r
- }\r
- else\r
- {\r
- pr.setWidth( pm.width() + 8 );\r
- tr.addCoords( pr.right(), 0, 0, 0 );\r
- pr.moveBy(shiftX, shiftY);\r
- \r
- drawItem( p, pr, AlignCenter, cg, TRUE, &pm, QString::null );\r
- alignment |= AlignLeft | AlignVCenter;\r
- }\r
-\r
- tr.moveBy(shiftX, shiftY);\r
- drawItem( p, tr, alignment, cg, flags & Style_Enabled, 0, toolbutton->textLabel(),\r
- toolbutton->textLabel().length(), &btext);\r
- }\r
- else\r
- {\r
- /*if( en && !highlight )\r
- mix( 0.6, pm, cg.background() );\r
- else*/ if( !en )\r
- {\r
- toGrayscale( pm, 1.1 );\r
- mix( 0.8, pm, cg.background() );\r
- }\r
-\r
- rect.moveBy(shiftX, shiftY);\r
- drawItem( p, rect, AlignCenter, cg, true, &pm, QString::null );\r
- }\r
- }\r
- }\r
- }\r
- break;\r
-\r
- case CE_TabBarTab:\r
- {\r
- QPen oldPen = p->pen();\r
-\r
- QRect r2( r );\r
- bool selected = flags & Style_Selected;\r
-\r
- p->setPen( cg.midlight() );\r
- p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );\r
-\r
- if ( !selected )\r
- r2.setRect( r2.left(), r2.top() + 1, r2.width(), r2.height() - 1 );\r
- else\r
- r2.setRect( r2.left(), r2.top(), r2.width() - 2, r2.height() - 1 );\r
-\r
- p->setPen( cg.foreground() );\r
- QBrush brsh = cg.brush( selected ? QColorGroup::Base : QColorGroup::Background );\r
- p->fillRect( r2.left(), r2.top(), r2.width(), r2.height() - 1, brsh );\r
- p->drawRect( r2.left(), r2.top(), r2.width(), r2.height() - 1 );\r
-\r
- if ( selected )\r
- {\r
- p->setPen( cg.shadow() );\r
- p->drawLine( r2.left() + 1, r2.bottom(), r2.right() + 1, r2.bottom() );\r
- p->drawLine( r2.right() + 1, r2.top() + 1, r2.right() + 1, r2.bottom() );\r
- }\r
-\r
- break;\r
- }\r
-\r
- case CE_PushButton:\r
- {\r
- if ( flags & Style_Enabled && !( flags & Style_Down || flags & Style_On ) )\r
- {\r
- const QPushButton* button = (const QPushButton*)widget;\r
- QRect br = QRect( button->mapToGlobal( button->rect().topLeft() ), button->rect().size() );\r
- if ( br.contains( QCursor::pos() ) )\r
- flags |= Style_MouseOver;\r
- }\r
-\r
- PARENT_STYLE::drawControl( element, p, widget, r, cg, flags, opt );\r
- break;\r
- }\r
-\r
- default:\r
- PARENT_STYLE::drawControl( element, p, widget, r, cg, flags, opt );\r
- break;\r
- }\r
-}\r
-\r
-QRect SalomeStyle::subRect( SubRect subrect, const QWidget* w ) const\r
-{\r
- QRect r = PARENT_STYLE::subRect( subrect, w );\r
- if ( subrect==SR_DockWindowHandleRect && w->inherits( "QDockWindowHandle" ) )\r
- {\r
- QDockWindow* wnd = ( QDockWindow* ) w->parent();\r
- if( wnd->orientation()==Qt::Vertical )\r
- r.setWidth( w->width() );\r
- else\r
- {\r
- r.setY( r.y()+r.height()-w->height() );\r
- r.setHeight( w->height() );\r
- }\r
- }\r
-\r
- return r;\r
-}\r
-\r
-void SalomeStyle::drawComplexControl( ComplexControl control, QPainter* p, const QWidget* widget,\r
- const QRect& r, const QColorGroup& cg, SFlags flags,\r
- SCFlags controls, SCFlags active, const QStyleOption& opt ) const\r
-{\r
-\r
-\r
-\r
-\r
- ((SalomeStyle*)this)->myTitleParent = 0;\r
-\r
- switch ( control )\r
- {\r
- case CC_ComboBox:\r
- if ( controls & SC_ComboBoxArrow )\r
- {\r
- SFlags flags = Style_Default;\r
-\r
- qDrawShadeRect( p, r, cg, true, pixelMetric( PM_DefaultFrameWidth, widget ),\r
- 0, widget->isEnabled() ? &cg.brush( QColorGroup::Base ) : &cg.brush( QColorGroup::Background ) );\r
-\r
- QRect ar = QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget, SC_ComboBoxArrow ), widget );\r
- if ( active == SC_ComboBoxArrow )\r
- {\r
- p->setPen( cg.dark() );\r
- p->setBrush( cg.brush( QColorGroup::Button ) );\r
- p->drawRect( ar );\r
- }\r
- else\r
- qDrawWinPanel( p, ar, cg, FALSE, &cg.brush( QColorGroup::Button ) );\r
-\r
- ar.addCoords( 2, 2, -2, -2 );\r
- if ( widget->isEnabled() )\r
- flags |= Style_Enabled;\r
-\r
- if ( active == SC_ComboBoxArrow )\r
- flags |= Style_Sunken;\r
- drawPrimitive( PE_ArrowDown, p, ar, cg, flags );\r
- }\r
- PARENT_STYLE::drawComplexControl( control, p, widget, r, cg, flags, controls & ~SC_ComboBoxArrow, active, opt );\r
- break;\r
-\r
- case CC_TitleBar:\r
- if( widget->inherits( "QTitleBar" ) )\r
- ( ( SalomeStyle* )this )->myTitleParent = ( QWidget* )widget->parent();\r
-\r
- default:\r
- PARENT_STYLE::drawComplexControl( control, p, widget, r, cg, flags, controls, active, opt );\r
- break;\r
- }\r
-}\r
-\r
-QPixmap SalomeStyle::stylePixmap( StylePixmap st, const QWidget* w, const QStyleOption& opt ) const\r
-{\r
- switch ( st )\r
- {\r
- case SP_DockWindowCloseButton:\r
- case SP_TitleBarCloseButton:\r
- return QPixmap( cross_xpm );\r
- case SP_TitleBarMaxButton:\r
- return QPixmap( maximize_xpm );\r
- case SP_TitleBarNormalButton:\r
- return QPixmap( normal_xpm );\r
- case SP_TitleBarMinButton:\r
- return QPixmap( minimize_xpm );\r
- default:\r
- return PARENT_STYLE::stylePixmap( st, w, opt );\r
- }\r
-}\r
-\r
-int SalomeStyle::pixelMetric( PixelMetric pm, const QWidget* widget ) const\r
-{\r
- int ret = 0;\r
-\r
- switch ( pm )\r
- {\r
- case PM_ButtonMargin:\r
- ret = 5;\r
- break;\r
- case PM_DockWindowFrameWidth:\r
- ret = 0;\r
- break;\r
- case PM_TabBarTabOverlap:\r
- ret = 2;\r
- break;\r
- case PM_TabBarTabHSpace:\r
- ret = 20;\r
- break;\r
- case PM_TabBarTabShiftHorizontal:\r
- case PM_TabBarTabShiftVertical:\r
- ret = 0;\r
- break;\r
- case PM_TabBarTabVSpace:\r
- ret = 5;\r
- break;\r
- case PM_DefaultFrameWidth:\r
- ret = 1;\r
- break;\r
- case PM_SpinBoxFrameWidth:\r
- ret = 1;\r
- break;\r
- case PM_ProgressBarChunkWidth:\r
- ret = 1;\r
- break;\r
- default:\r
- ret = PARENT_STYLE::pixelMetric( pm, widget );\r
- break;\r
- }\r
- return ret;\r
-}\r
-\r
-QString SalomeStyle::titleText( const QString& txt, const int W, const QFontMetrics& fm ) const\r
-{\r
- QString res = txt.stripWhiteSpace();\r
-\r
- if ( fm.width( res ) > W )\r
- {\r
- QString end( "..." );\r
- while ( !res.isEmpty() && fm.width( res + end ) > W )\r
- res.remove( res.length() - 1, 1 );\r
-\r
- if ( !res.isEmpty() )\r
- res += end;\r
- }\r
-\r
- return res;\r
-}\r
-\r
-/*!\r
- Class: SalomeStylePlugin [Internal]\r
- Descr: Plugin for Qt style mechanism\r
-*/\r
-\r
-SalomeStylePlugin::SalomeStylePlugin()\r
-{\r
-}\r
-\r
-SalomeStylePlugin::~SalomeStylePlugin()\r
-{\r
-}\r
-\r
-QStringList SalomeStylePlugin::keys() const\r
-{\r
- return QStringList() << "salome";\r
-}\r
-\r
-QStyle* SalomeStylePlugin::create( const QString& str )\r
-{\r
- if ( str == "salome" )\r
- return new SalomeStyle();\r
- else\r
- return 0;\r
-}\r
-\r
-Q_EXPORT_PLUGIN( SalomeStylePlugin )\r
+#include "SalomeStyle.h"
+
+#include <qimage.h>
+#include <qcursor.h>
+#include <qtabbar.h>
+#include <qpalette.h>
+#include <qtoolbar.h>
+#include <qspinbox.h>
+#include <qpainter.h>
+#include <qlineedit.h>
+#include <qlistview.h>
+#include <qdrawutil.h>
+#include <qpopupmenu.h>
+#include <qpushbutton.h>
+#include <qobjectlist.h>
+#include <qtoolbutton.h>
+#include <qapplication.h>
+
+static const char* const hole_xpm[] = {
+"3 3 3 1",
+". c None",
+"a c #999999",
+"b c #FFFFFF",
+"aa.",
+"aab",
+".bb"
+};
+
+static const char* const cross_xpm[] = {
+"12 12 4 1",
+". c None",
+"a c #000000",
+"b c #FFFFFF",
+"c c #666666",
+"............",
+"............",
+"............",
+".aaaa..aaaa.",
+"..abbaabba..",
+"...abbbba...",
+"....abba....",
+"...abbbba...",
+"..abbaabba..",
+".aaaa..aaaa.",
+"............",
+"............"
+};
+
+static const char* const maximize_xpm[] = {
+"12 12 4 1",
+". c None",
+"a c #000000",
+"b c #FFFFFF",
+"c c #666666",
+"............",
+".aaaaaaaaaa.",
+".acccccccca.",
+".acccccccca.",
+".abbbbbbbba.",
+".abbbbbbbba.",
+".abbbbbbbba.",
+".abbbbbbbba.",
+".abbbbbbbba.",
+".abbbbbbbba.",
+".aaaaaaaaaa.",
+"............"
+};
+
+static const char* const normal_xpm[] = {
+"12 12 4 1",
+". c None",
+"a c #000000",
+"b c #FFFFFF",
+"c c #666666",
+"............",
+"...aaaaaaaa.",
+"...acccccca.",
+"...abbbbbba.",
+"...aaaaaaba.",
+".aaaaaaaaba.",
+".accccccaba.",
+".abbbbbbaaa.",
+".abbbbbba...",
+".abbbbbba...",
+".aaaaaaaa...",
+"............"
+};
+
+static const char* const minimize_xpm[] = {
+"12 12 4 1",
+". c None",
+"a c #000000",
+"b c #FFFFFF",
+"c c #666666",
+"............",
+"............",
+"............",
+"............",
+"............",
+"............",
+"............",
+"............",
+"aaaaaaaaaaaa",
+"abbbbbbbbbba",
+"aaaaaaaaaaaa",
+"............"
+};
+
+/*!
+ Class: SalomeStyle [Public]
+ Descr: Style for SALOME platform
+*/
+
+SalomeStyle::SalomeStyle()
+: myTitleParent( 0 )
+{
+ qApp->installEventFilter( this );
+}
+
+SalomeStyle::~SalomeStyle()
+{
+}
+
+void SalomeStyle::polish( QWidget* w )
+{
+ if ( !w )
+ return;
+/*
+ if ( w->inherits( "QLineEdit" ) )
+ {
+ QLineEdit* fr = (QLineEdit*)w;
+ if ( w->parentWidget() && w->parentWidget()->inherits( "QSpinWidget" ) )
+ fr->setFrameStyle( QFrame::Plain );
+ else
+ {
+ fr->setFrameStyle( QFrame::Plain | QFrame::Box );
+ fr->setLineWidth( 1 );
+ fr->setMidLineWidth( 0 );
+ }
+ }
+ else
+*/
+ if ( w->inherits( "QToolBar" ) )
+ {
+ QToolBar* tb = (QToolBar*)w;
+ tb->setFrameStyle( QFrame::ToolBarPanel | QFrame::Plain );
+ tb->setLineWidth( 1 );
+ tb->setMidLineWidth( 1 );
+ }
+ else
+ if ( w->inherits( "QDockWindow" ) )
+ {
+ QDockWindow* dw = (QDockWindow*)w;
+ dw->setFrameStyle( QFrame::ToolBarPanel | QFrame::Raised );
+ }
+/*
+ else if ( w->inherits( "QListView" ) )
+ {
+ QListView* lv = (QListView*)w;
+ lv->setFrameStyle( QFrame::Box | QFrame::Plain );
+ }
+*/
+ else
+ PARENT_STYLE::polish( w );
+}
+
+bool SalomeStyle::eventFilter( QObject* o, QEvent* e )
+{
+ if ( e->type() == QEvent::FocusIn || e->type() == QEvent::FocusOut )
+ {
+ QDockWindow* wnd = NULL;
+ while( o && !wnd )
+ if( o->inherits( "QDockWindow" ) )
+ wnd = ( QDockWindow* )o;
+ else
+ o = o->parent();
+
+ if ( wnd )
+ {
+ const QObjectList* objList = o->children();
+ for( QObjectListIterator anIt( *objList ); anIt.current(); ++anIt )
+ if( anIt.current()->inherits( "QDockWindowHandle" ) )
+ {
+ QWidget* ww = ( QWidget* )anIt.current();
+ ww->repaint( ww->rect() );
+ const QObjectList* wc = ww->children();
+ for( QObjectListIterator anIt2( *wc ); anIt2.current(); ++anIt2 )
+ if( anIt2.current()->inherits( "QToolButton" ) )
+ {
+ QWidget* tb = ( QWidget* )anIt2.current();
+ tb->repaint( tb->rect() );
+ }
+ }
+ }
+ }
+
+ if ( o && o->inherits( "QPushButton" ) && ( e->type() == QEvent::Enter || e->type() == QEvent::Leave ) )
+ ((QWidget*)o)->update();
+
+ return false;
+}
+
+double linear( double x )
+{
+ return x;
+}
+
+void SalomeStyle::mix( const double t, const QColor& c1, const QColor& c2, QColor& res )
+{
+ if( t<0.0 || t>1.0 )
+ return;
+
+ int r = int( c1.red() * (1-t) + c2.red() * t ),
+ g = int( c1.green() * (1-t) + c2.green() * t ),
+ b = int( c1.blue() * (1-t) + c2.blue() * t );
+ res.setRgb( r, g, b );
+}
+
+void SalomeStyle::mix( const double t, QRgb& rgb1, const QRgb& rgb2 )
+{
+ if( t<0.0 || t>1.0 )
+ return;
+
+ int c[2][4] = { qRed( rgb1 ), qGreen( rgb1 ), qBlue( rgb1 ), qAlpha( rgb1 ),
+ qRed( rgb2 ), qGreen( rgb2 ), qBlue( rgb2 ), qAlpha( rgb2 ) };
+ for( int i=0; i<4; i++ )
+ c[0][i] = (int)( c[0][i] * (1-t) + c[1][i] * t );
+
+ rgb1 = qRgba( c[0][0], c[0][1], c[0][2], qAlpha( rgb1 ) );
+}
+
+void SalomeStyle::mix( const double t, QPixmap& pix, const QColor& col )
+{
+ if( t<0.0 || t>1.0 )
+ return;
+
+ QImage anImage = pix.convertToImage();
+ if( anImage.isNull() )
+ return;
+
+ if( anImage.depth()!=32 )
+ anImage = anImage.convertDepth( 32 );
+
+ int w = anImage.width(),
+ h = anImage.height();
+
+ QRgb colrgb = col.rgb(), cur;
+ for( int y=0; y<h; y++ )
+ {
+ uchar* line = anImage.scanLine( y );
+ QRgb* colorline = ( QRgb* ) line;
+ for( int x=0; x<w; x++ )
+ {
+ cur = colorline[ x ];
+ mix( t, cur, colrgb );
+ colorline[ x ] = cur;
+ }
+ }
+ pix = anImage;
+}
+
+void SalomeStyle::toGrayscale( QPixmap& pix, double k )
+{
+ QImage anImage = pix.convertToImage();
+ if( anImage.isNull() )
+ return;
+
+ if( anImage.depth()!=32 )
+ anImage = anImage.convertDepth( 32 );
+
+ int w = anImage.width(),
+ h = anImage.height();
+
+ for( int y=0; y<h; y++ )
+ {
+ uchar* line = anImage.scanLine( y );
+ QRgb* colorline = ( QRgb* ) line;
+ for( int x=0; x<w; x++ )
+ {
+ int gray = (int)( k * qGray( colorline[ x ] ) );
+ if ( gray>255 )
+ gray = 255;
+ else if( gray<0 )
+ gray = 0;
+ colorline[ x ] = qRgba( gray, gray, gray, qAlpha( colorline[x] ) );
+ }
+ }
+ pix = anImage;
+}
+
+void SalomeStyle::drawGradient( QPainter* p, const QRect& r,
+ const QColor& c1, const QColor& c2,
+ const Direction d, gradient_func f ) const
+{
+ p->save();
+ p->translate( r.x(), r.y() );
+
+ QColor mid;
+ if( d==LeftToRight || d==RightToLeft )
+ for( int xmax = r.width(), x = d==LeftToRight ? 0 : xmax;
+ d==LeftToRight ? x<=xmax : x>=0;
+ d==LeftToRight ? x++ : x-- )
+ {
+ double t = double( x ) / double( xmax );
+ mix( d==LeftToRight ? f(t) : 1-f(t), c1, c2, mid );
+ p->setPen( mid );
+ p->drawLine( x, 0, x, r.height() );
+ }
+ else
+ for( int ymax = r.height(), y = d==UpToDown ? 0 : ymax;
+ d==UpToDown ? y<=ymax : y>=0;
+ d==UpToDown ? y++ : y-- )
+ {
+ double t = double( y ) / double( ymax );
+ mix( d==UpToDown ? f(t) : 1-f(t), c1, c2, mid );
+ p->setPen( mid );
+ p->drawLine( 0, y, r.width(), y );
+ }
+
+ p->restore();
+}
+
+void SalomeStyle::drawPrimitive( PrimitiveElement pe, QPainter* p, const QRect& r,
+ const QColorGroup& cg, SFlags flags, const QStyleOption& opt ) const
+{
+ switch ( pe )
+ {
+ case PE_ButtonTool:
+ if ( !myTitleParent )
+ PARENT_STYLE::drawPrimitive( pe, p, r, cg, flags, opt );
+ break;
+
+ case PE_DockWindowResizeHandle:
+ p->fillRect( r.x(), r.y(), r.width(), r.height(), cg.dark() );
+ if ( flags & Style_Horizontal )
+ p->fillRect( r.x(), r.y() + 1, r.width(), r.height() - 2, cg.midlight() );
+ else
+ p->fillRect( r.x() + 1, r.y(), r.width() - 2, r.height(), cg.midlight() );
+ break;
+
+ case PE_DockWindowHandle:
+ {
+ QPaintDevice* pd = p->device();
+ if ( !pd )
+ break;
+
+ QWidget* w = (QWidget*)pd;
+
+ if ( !w || !w->inherits( "QDockWindowHandle" ) )
+ break;
+
+ QDockWindow* wnd = ( QDockWindow* ) w->parent();
+ if ( !wnd )
+ return;
+
+ QObject* activeWidget = qApp->focusWidget();
+ QDockWindow* activeWnd = 0;
+ while ( !activeWnd && activeWidget )
+ {
+ if ( activeWidget->inherits( "QDockWindow" ) )
+ activeWnd = (QDockWindow*)activeWidget;
+ else
+ activeWidget = activeWidget->parent();
+ }
+
+ bool act = wnd == activeWnd, horiz = flags & Style_Horizontal;
+
+ QPixmap hole( (const char**)hole_xpm );
+
+ if ( wnd->inherits( "QToolBar" ) )
+ {
+ drawGradient( p, r, cg.light(), cg.background(), horiz ? UpToDown : LeftToRight, linear );
+
+ int c = 4, i; double d = ( horiz ? r.height() : r.width() ) / ( c + 1 );
+ QBrush fill = cg.brush( QColorGroup::Dark );
+ p->setPen( Qt::red );
+ for ( i = 0; i < c; i++ )
+ {
+ if ( horiz )
+ p->drawPixmap( r.x() + r.width() / 2 - 1, (int)( r.y() + ( i + 1 ) * d - 1 ), hole );
+ else
+ p->drawPixmap( (int) ( r.x() + ( i + 1 ) * d - 1 ), r.y() + r.height() / 2 - 1, hole );
+ }
+
+ int dd = (int(d)/2) + (int(d)%2);
+ for ( i = 0; i < c - 1; i++ )
+ {
+ if ( horiz )
+ p->drawPixmap( r.x() + r.width() / 2 + 2, (int)( r.y() + dd + ( i + 1 ) * d - 1 ), hole );
+ else
+ p->drawPixmap( (int)( r.x() + dd + ( i + 1 ) * d - 1 ), r.y() + r.height() / 2 + 2, hole );
+ }
+ }
+ else
+ {
+ int d = 1;
+ QRect rr( r.x()+d, r.y()+d, r.width()-2*d, r.height()-2*d );
+
+ QColor col;
+ if ( act )
+ mix( 0.5, cg.highlight(), Qt::white, col );
+ else
+ col = cg.background();
+
+ drawGradient( p, rr, act ? cg.highlight() : cg.dark(), col,
+ horiz ? LeftToRight : UpToDown, linear );
+
+ QRect rt = rr;
+ if ( flags & Style_Horizontal )
+ rt.addCoords( 0, 20, 0, 0 );
+ else
+ rt.addCoords( 0, 0, -20, 0 );
+
+ int textW = flags & Style_Horizontal ? rt.height() : rt.width();
+ int textH = flags & Style_Horizontal ? rt.width() : rt.height();
+
+ QString title = titleText( wnd->caption(), textW, p->fontMetrics() );
+
+ if ( wnd )
+ {
+ QColorGroup cgroup = wnd->isActiveWindow() ? wnd->palette().active() : wnd->palette().inactive();
+ p->setPen( cgroup.highlightedText() );
+
+ if ( flags & Style_Horizontal )
+ {
+ p->rotate( 270.0 );
+ p->translate( -(rt.height()+rt.y()), (rt.width()-rt.x()) );
+ p->drawText( 0, 0, title );
+ }
+ else
+ p->drawText( 2, 2, textW, textH, AlignLeft, title );
+ }
+ }
+ break;
+ }
+
+ case PE_DockWindowSeparator:
+ {
+ bool horiz = ( flags & Style_Horizontal );
+ QWidget* w = ( QWidget* )p->device();
+ if( w->inherits( "QToolBarSeparator" ) )
+ {
+ drawGradient( p, r, cg.light(), cg.background(), horiz ? UpToDown : LeftToRight, linear );
+ int w = r.width(), h = r.height();
+ int part = 8;
+
+ p->setPen( cg.dark() );
+ if( horiz )
+ p->drawLine( r.x() + w/2, r.y() + h/part, r.x() + w/2, r.y() + (part-1)*h/part );
+ else
+ p->drawLine( r.x() + w/part, r.y() + h/2, r.x() + (part-1)*w/part, r.y() + h/2 );
+
+ p->setPen( cg.light() );
+ if( horiz )
+ p->drawLine( r.x() + w/2 + 1, r.y() + h/part + 1, r.x() + w/2 + 1, r.y() + (part-1)*h/part + 1 );
+ else
+ p->drawLine( r.x() + w/part + 1, r.y() + h/2 + 1, r.x() + (part-1)*w/part + 1, r.y() + h/2 + 1 );
+ }
+ else
+ PARENT_STYLE::drawPrimitive( pe, p, r, cg, flags, opt );
+ break;
+ }
+
+ case PE_PanelDockWindow:
+ {
+ QWidget* w = ( QWidget* )p->device();
+
+ int offset = pixelMetric( PM_DockWindowHandleExtent, w );
+ if ( w->inherits( "QToolBar" ) )
+ {
+ bool vert = ( ( QToolBar* )w )->orientation() == Qt::Vertical;
+ if ( vert )
+ drawGradient( p, QRect( r.x(), r.y()+offset, r.x()+r.width(), r.y()+offset ),
+ cg.light(), cg.background(), LeftToRight, linear );
+ else
+ drawGradient( p, QRect( r.x()+offset, r.y(), r.x()+offset, r.y()+r.height() ),
+ cg.light(), cg.background(), UpToDown, linear );
+
+ p->setPen( QPen( cg.light(), 1 ) );
+ p->drawRect( r );
+ }
+ else
+ {
+ p->setPen( QPen( cg.dark(), 1 ) );
+ p->setBrush( cg.light() );
+ p->drawRect( r );
+ }
+
+ break;
+ }
+
+ case PE_PanelPopup:
+ p->setPen( QPen( cg.dark(), 1 ) );
+ p->setBrush( cg.light() );
+ p->drawRect( r );
+ break;
+
+ case PE_HeaderSection:
+ {
+ QColor col; mix( 0.2, cg.light(), Qt::black, col );
+ drawGradient( p, r, cg.light(), col, DownToUp, linear );
+ drawGradient( p, QRect( r.x(), r.y(), 1, r.height() ), cg.light(), cg.dark(), DownToUp, linear );
+ p->setPen( cg.dark() );
+ p->drawLine( r.x(), r.y()+r.height()-1, r.x()+r.width(), r.y()+r.height()-1 );
+ break;
+ }
+
+ case PE_Splitter:
+ p->fillRect( r.x() + 1, r.y() + 1, r.width() - 2, r.height() - 2, cg.dark() );
+ p->fillRect( r.x() + 2, r.y() + 2, r.width() - 4, r.height() - 4, cg.midlight() );
+ break;
+
+ case PE_ButtonBevel:
+ PARENT_STYLE::drawPrimitive( PE_ButtonDropDown, p, r, cg, flags, opt );
+ break;
+
+ case PE_ButtonCommand:
+ {
+ QColorGroup cGrp( cg );
+ if ( flags & Style_MouseOver )
+ cGrp.setColor( QColorGroup::Button, cGrp.midlight() );
+
+ if ( flags & Style_MouseOver )
+ PARENT_STYLE::drawPrimitive( PE_ButtonDropDown, p, r, cGrp, flags, opt );
+ else
+ PARENT_STYLE::drawPrimitive( flags & Style_Raised ? PE_ButtonDropDown : pe, p, r, cGrp, flags, opt );
+ }
+ break;
+
+ default:
+ PARENT_STYLE::drawPrimitive( pe, p, r, cg, flags, opt );
+ break;
+ }
+}
+
+void SalomeStyle::drawControl( ControlElement element, QPainter* p, const QWidget* widget, const QRect& r,
+ const QColorGroup& cg, SFlags flags, const QStyleOption& opt ) const
+{
+ switch( element )
+ {
+ case CE_PopupMenuItem:
+ {
+ if(! widget || opt.isDefault())
+ break;
+
+ const QPopupMenu *popupmenu = (const QPopupMenu *) widget;
+ QMenuItem *mi = opt.menuItem();
+ if( !mi )
+ break;
+
+ int tab = opt.tabWidth();
+ int maxpmw = opt.maxIconWidth();
+ bool dis = !( flags & Style_Enabled );
+ bool checkable = popupmenu->isCheckable();
+ bool act = flags & Style_Active;
+ bool use2000style = true;
+ int x, y, w, h;
+
+ int windowsItemFrame = 2,
+ windowsItemHMargin = 5,
+ windowsItemVMargin = 1,
+ windowsRightBorder = 2,
+ windowsArrowHMargin = 2;
+
+ r.rect(&x, &y, &w, &h);
+
+ if ( checkable )
+ {
+ // space for the checkmarks
+ if (use2000style)
+ maxpmw = QMAX( maxpmw, 20 );
+ else
+ maxpmw = QMAX( maxpmw, 12 );
+ }
+
+ int checkcol = maxpmw;
+
+ if ( mi && mi->isSeparator() )
+ {
+ p->setPen( cg.dark() );
+ p->drawLine( x+3*checkcol/2, y, x+w, y );
+ //p->setPen( cg.light() );
+ //p->drawLine( x, y+1, x+w, y+1 );
+ return;
+ }
+
+ QBrush fill = ( act && !dis ?
+ cg.brush( QColorGroup::Highlight ) :
+ cg.brush( QColorGroup::Light ) );
+ p->fillRect( x, y, w, h, fill );
+
+ if( !mi )
+ return;
+
+ int xpos = x;
+ QRect vrect = visualRect( QRect( xpos, y, checkcol, h ), r );
+ int xvis = vrect.x();
+
+ if( mi->isChecked() )
+ {
+ if( act && !dis )
+ qDrawShadePanel( p, xvis, y, checkcol, h,
+ cg, TRUE, 1, &cg.brush( QColorGroup::Button ) );
+ else
+ {
+ QBrush fill( cg.light(), Dense4Pattern );
+ // set the brush origin for the hash pattern to the x/y coordinate
+ // of the menu item's checkmark... this way, the check marks have
+ // a consistent look
+ QPoint origin = p->brushOrigin();
+ p->setBrushOrigin( xvis, y );
+ qDrawShadePanel( p, xvis, y, checkcol, h, cg, TRUE, 1, &fill );
+ // restore the previous brush origin
+ p->setBrushOrigin( origin );
+ }
+ }
+ else if( !act )
+ p->fillRect(x+checkcol, y, w-checkcol , h, cg.brush( QColorGroup::Light ));
+
+ if( !( act && !dis ) && !mi->isChecked() )
+ {
+ QColor col; mix( 0.5, cg.mid(), Qt::white, col );
+ drawGradient( p, QRect( xvis, y, checkcol, h+1 ), cg.light(), col, LeftToRight, linear );
+ }
+
+ if( mi->iconSet() )
+ { // draw iconset
+ QIconSet::Mode mode = dis ? QIconSet::Active : QIconSet::Normal;
+ if(act && !dis )
+ mode = QIconSet::Active;
+ QPixmap pixmap;
+ if( checkable && mi->isChecked() )
+ pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode, QIconSet::On );
+ else
+ pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
+ int pixw = pixmap.width();
+ int pixh = pixmap.height();
+
+ if( dis )
+ toGrayscale( pixmap, 1.1 );
+
+ //if( act && !dis && !mi->isChecked() )
+ // qDrawShadePanel( p, xvis, y, checkcol, h, cg, FALSE, 1, &cg.brush( QColorGroup::Button ) );
+
+ QRect pmr( 0, 0, pixw, pixh );
+ pmr.moveCenter( vrect.center() );
+ p->setPen( cg.text() );
+ p->drawPixmap( pmr.topLeft(), pixmap );
+
+ QBrush fill = ( act ? cg.brush( QColorGroup::Highlight ) : cg.brush( QColorGroup::Light ));
+ int xp = xpos + checkcol + 1;
+ if( !dis )
+ p->fillRect( visualRect( QRect( xp, y, w - checkcol - 1, h ), r ), fill);
+ }
+ else if( checkable )
+ { // just "checking"...
+ if( mi->isChecked() )
+ {
+ int xp = xpos + windowsItemFrame;
+
+ SFlags cflags = Style_Default;
+ if( !dis )
+ cflags |= Style_Enabled;
+ if( act )
+ cflags |= Style_On;
+
+ drawPrimitive( PE_CheckMark, p,
+ visualRect( QRect( xp, y + windowsItemFrame,
+ checkcol - 2*windowsItemFrame,
+ h - 2*windowsItemFrame), r ), cg, cflags, opt );
+ }
+ }
+
+ p->setPen( act ? cg.highlightedText() : cg.buttonText() );
+
+ QColor discol;
+ if( dis )
+ {
+ discol = cg.text();
+ p->setPen( discol );
+ }
+
+ int xm = windowsItemFrame + checkcol + windowsItemHMargin;
+ xpos += xm;
+
+ vrect = visualRect( QRect( xpos, y+windowsItemVMargin, w-xm-tab+1, h-2*windowsItemVMargin ), r );
+ xvis = vrect.x();
+ if( mi->custom() )
+ {
+ p->save();
+ if ( dis && !act )
+ {
+ p->setPen( cg.light() );
+ mi->custom()->paint( p, cg, act, !dis,
+ xvis+1, y+windowsItemVMargin+1,
+ w-xm-tab+1, h-2*windowsItemVMargin );
+ p->setPen( discol );
+ }
+ mi->custom()->paint( p, cg, act, !dis, xvis, y+windowsItemVMargin,
+ w-xm-tab+1, h-2*windowsItemVMargin );
+ p->restore();
+ }
+ QString s = mi->text();
+ if( !s.isNull() )
+ { // draw text
+ int t = s.find( '\t' );
+ int text_flags = AlignVCenter | ShowPrefix | DontClip | SingleLine;
+ if( !styleHint( SH_UnderlineAccelerator, widget ) )
+ text_flags |= NoAccel;
+ text_flags |= (QApplication::reverseLayout() ? AlignRight : AlignLeft );
+ if( t >= 0 )
+ { // draw tab text
+ int xp = x + w - tab - windowsItemHMargin - windowsItemFrame + 1;
+ if( use2000style )
+ xp -= 20;
+ else
+ xp -= windowsRightBorder;
+ int xoff = visualRect( QRect( xp, y+windowsItemVMargin, tab, h-2*windowsItemVMargin ), r ).x();
+ if( dis && !act )
+ {
+ p->setPen( cg.light() );
+ p->drawText( xoff+1, y+windowsItemVMargin+1, tab, h-2*windowsItemVMargin, text_flags, s.mid( t+1 ));
+ p->setPen( discol );
+ }
+ p->drawText( xoff, y+windowsItemVMargin, tab, h-2*windowsItemVMargin, text_flags, s.mid( t+1 ) );
+ s = s.left( t );
+ }
+ if( dis && !act )
+ {
+ p->setPen( cg.light() );
+ p->drawText( xvis+1, y+windowsItemVMargin+1, w-xm-tab+1, h-2*windowsItemVMargin, text_flags, s, t );
+ p->setPen( discol );
+ }
+ p->drawText( xvis, y+windowsItemVMargin, w-xm-tab+1, h-2*windowsItemVMargin, text_flags, s, t );
+ }
+ else if( mi->pixmap() )
+ { // draw pixmap
+ QPixmap *pixmap = mi->pixmap();
+ if( pixmap->depth() == 1 )
+ p->setBackgroundMode( OpaqueMode );
+ p->drawPixmap( xvis, y+windowsItemFrame, *pixmap );
+ if( pixmap->depth() == 1 )
+ p->setBackgroundMode( TransparentMode );
+ }
+ if( mi->popup() )
+ { // draw sub menu arrow
+ int dim = (h-2*windowsItemFrame) / 2;
+ PrimitiveElement arrow;
+ arrow = ( QApplication::reverseLayout() ? PE_ArrowLeft : PE_ArrowRight );
+ xpos = x+w - windowsArrowHMargin - windowsItemFrame - dim;
+ vrect = visualRect( QRect(xpos, y + h / 2 - dim / 2, dim, dim), r );
+ if( act )
+ {
+ QColorGroup g2 = cg;
+ g2.setColor( QColorGroup::ButtonText, g2.highlightedText() );
+ drawPrimitive( arrow, p, vrect, g2, dis ? Style_Default : Style_Enabled, opt );
+ }
+ else
+ {
+ drawPrimitive( arrow, p, vrect, cg, dis ? Style_Default : Style_Enabled, opt );
+ }
+ }
+
+ if( act && !dis )
+ {
+ p->setPen( cg.dark() );
+ p->drawRect( r );
+ }
+ break;
+ }
+
+ case CE_MenuBarItem:
+ {
+ bool active = flags & Style_Active;
+ bool down = flags & Style_Down;
+ QRect pr = r;
+
+ p->save();
+ if( active && down )
+ {
+ //QColor col; mix( 0.5, cg.mid(), Qt::white, col );
+ //drawGradient( p, r, col, cg.light(), UpToDown, linear );
+ p->setPen( cg.light() );
+ p->setBrush( cg.light() );
+ p->drawRect( r );
+
+ p->setPen( cg.dark() );
+ int w = r.width()-1, h = r.height();
+ p->drawLine( r.x(), r.y(), r.x()+w, r.y() );
+ p->drawLine( r.x(), r.y(), r.x(), r.y()+h );
+ p->drawLine( r.x()+w, r.y(), r.x()+w, r.y()+h );
+
+ p->translate( 1, 1 );
+ }
+ else
+ drawGradient( p, r, cg.light(), cg.background(), active ? DownToUp : UpToDown, linear );
+
+ QCommonStyle::drawControl(element, p, widget, pr, cg, flags, opt);
+ p->restore();
+ break;
+ }
+
+ case CE_MenuBarEmptyArea:
+ {
+ drawGradient( p, r, cg.light(), cg.background(), UpToDown, linear );
+ break;
+ }
+
+ case CE_ToolButtonLabel:
+ {
+ const QToolButton *toolbutton = (const QToolButton *) widget;
+ QObject* parent = toolbutton->parent();
+
+ QToolBar* tb = NULL;
+ while( parent )
+ if( parent->inherits( "QToolBar" ) )
+ {
+ tb = ( QToolBar* )parent;
+ break;
+ }
+ else
+ parent = parent->parent();
+ parent = toolbutton->parent();
+
+ int horiz = -1;
+ if( tb )
+ {
+ if( tb->orientation()==Qt::Horizontal )
+ horiz = 1;
+ else
+ horiz = 0;
+ drawGradient( p, r, cg.light(), cg.background(), horiz ? UpToDown : LeftToRight, linear );
+ }
+ else if( parent->inherits( "QDockWindowHandle" ) )
+ {
+ QWidget* w = ( QWidget* ) parent;
+ QDockWindow* wnd = ( QDockWindow* )w->parent();
+ if( !wnd->orientation()==Qt::Horizontal )
+ horiz=1;
+ else
+ horiz=0;
+
+ QPoint pp( r.x(), r.y() ),
+ qq = toolbutton->mapToParent( pp );
+
+ bitBlt( p->device(), r.x(), r.y(), w, horiz ? qq.x()-r.width() : qq.x(),
+ horiz ? qq.y() : qq.y()+r.height(),
+ r.width(), r.height(), Qt::CopyROP, true );
+ }
+
+ bool highlight = ( flags & Style_MouseOver ),
+ down = ( flags & ( Style_Down | Style_On ) ),
+ en = toolbutton->isEnabled();
+
+ if( down )
+ if( horiz>=0 )
+ {
+ drawGradient( p, r, cg.light(), cg.background(), horiz==1 ? DownToUp : RightToLeft, linear );
+ p->setPen( cg.background() );
+ p->drawRect( r );
+ }
+ else
+ {
+ p->setPen( cg.dark() );
+ p->setBrush( cg.light() );
+ p->drawRect( r );
+ }
+ if( highlight )
+ {
+ p->setPen( cg.dark() );
+ QColor col; mix( 0.05, cg.background(), Qt::black, col );
+ p->setBrush( col );
+ p->drawRect( r );
+ }
+
+
+ QRect rect = r;
+ Qt::ArrowType arrowType = opt.isDefault() ? Qt::DownArrow : opt.arrowType();
+
+ int shiftX = 0, shiftY = 0;
+ if( flags & ( Style_Down | Style_On ) )
+ {
+ shiftX = pixelMetric(PM_ButtonShiftHorizontal, widget);
+ shiftY = pixelMetric(PM_ButtonShiftVertical, widget);
+ }
+
+ if (!opt.isDefault())
+ {
+ PrimitiveElement pe;
+ switch (arrowType)
+ {
+ case Qt::LeftArrow: pe = PE_ArrowLeft; break;
+ case Qt::RightArrow: pe = PE_ArrowRight; break;
+ case Qt::UpArrow: pe = PE_ArrowUp; break;
+ default:
+ case Qt::DownArrow: pe = PE_ArrowDown; break;
+ }
+
+ rect.moveBy(shiftX, shiftY);
+ drawPrimitive(pe, p, rect, cg, flags, opt);
+ }
+ else
+ {
+ QColor btext = toolbutton->paletteForegroundColor();
+
+ if (toolbutton->iconSet().isNull() &&
+ ! toolbutton->text().isNull() &&
+ ! toolbutton->usesTextLabel())
+ {
+ int alignment = AlignCenter | ShowPrefix;
+ if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
+ alignment |= NoAccel;
+
+ rect.moveBy(shiftX, shiftY);
+ drawItem( p, rect, alignment, cg, flags & Style_Enabled, 0, toolbutton->text(),
+ toolbutton->text().length(), &btext);
+ }
+ else
+ {
+ QPixmap pm;
+ QIconSet::Size size =
+ toolbutton->usesBigPixmap() ? QIconSet::Large : QIconSet::Small;
+ QIconSet::State state = toolbutton->isOn() ? QIconSet::On : QIconSet::Off;
+ QIconSet::Mode mode;
+ if( !toolbutton->isEnabled() )
+ mode = QIconSet::Active; //QIconSet::Disabled;
+ else if( flags & (Style_Down | Style_On ) || ( flags & Style_Raised ) && (flags & Style_AutoRaise))
+ mode = QIconSet::Active;
+ else
+ mode = QIconSet::Normal;
+ pm = toolbutton->iconSet().pixmap( size, mode, state );
+
+ if( toolbutton->usesTextLabel() )
+ {
+ p->setFont( toolbutton->font() );
+ QRect pr = rect, tr = rect;
+ int alignment = ShowPrefix;
+ if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
+ alignment |= NoAccel;
+
+ if( toolbutton->textPosition() == QToolButton::Under )
+ {
+ int fh = p->fontMetrics().height();
+ pr.addCoords( 0, 1, 0, -fh-3 );
+ tr.addCoords( 0, pr.bottom(), 0, -3 );
+ pr.moveBy(shiftX, shiftY);
+ drawItem( p, pr, AlignCenter, cg, TRUE, &pm, QString::null );
+ alignment |= AlignCenter;
+ }
+ else
+ {
+ pr.setWidth( pm.width() + 8 );
+ tr.addCoords( pr.right(), 0, 0, 0 );
+ pr.moveBy(shiftX, shiftY);
+
+ drawItem( p, pr, AlignCenter, cg, TRUE, &pm, QString::null );
+ alignment |= AlignLeft | AlignVCenter;
+ }
+
+ tr.moveBy(shiftX, shiftY);
+ drawItem( p, tr, alignment, cg, flags & Style_Enabled, 0, toolbutton->textLabel(),
+ toolbutton->textLabel().length(), &btext);
+ }
+ else
+ {
+ /*if( en && !highlight )
+ mix( 0.6, pm, cg.background() );
+ else*/ if( !en )
+ {
+ toGrayscale( pm, 1.1 );
+ mix( 0.8, pm, cg.background() );
+ }
+
+ rect.moveBy(shiftX, shiftY);
+ drawItem( p, rect, AlignCenter, cg, true, &pm, QString::null );
+ }
+ }
+ }
+ }
+ break;
+
+ case CE_TabBarTab:
+ {
+ QPen oldPen = p->pen();
+
+ QRect r2( r );
+ bool selected = flags & Style_Selected;
+
+ p->setPen( cg.midlight() );
+ p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );
+
+ if ( !selected )
+ r2.setRect( r2.left(), r2.top() + 1, r2.width(), r2.height() - 1 );
+ else
+ r2.setRect( r2.left(), r2.top(), r2.width() - 2, r2.height() - 1 );
+
+ p->setPen( cg.foreground() );
+ QBrush brsh = cg.brush( selected ? QColorGroup::Base : QColorGroup::Background );
+ p->fillRect( r2.left(), r2.top(), r2.width(), r2.height() - 1, brsh );
+ p->drawRect( r2.left(), r2.top(), r2.width(), r2.height() - 1 );
+
+ if ( selected )
+ {
+ p->setPen( cg.shadow() );
+ p->drawLine( r2.left() + 1, r2.bottom(), r2.right() + 1, r2.bottom() );
+ p->drawLine( r2.right() + 1, r2.top() + 1, r2.right() + 1, r2.bottom() );
+ }
+
+ break;
+ }
+
+ case CE_PushButton:
+ {
+ if ( flags & Style_Enabled && !( flags & Style_Down || flags & Style_On ) )
+ {
+ const QPushButton* button = (const QPushButton*)widget;
+ QRect br = QRect( button->mapToGlobal( button->rect().topLeft() ), button->rect().size() );
+ if ( br.contains( QCursor::pos() ) )
+ flags |= Style_MouseOver;
+ }
+
+ PARENT_STYLE::drawControl( element, p, widget, r, cg, flags, opt );
+ break;
+ }
+
+ default:
+ PARENT_STYLE::drawControl( element, p, widget, r, cg, flags, opt );
+ break;
+ }
+}
+
+QRect SalomeStyle::subRect( SubRect subrect, const QWidget* w ) const
+{
+ QRect r = PARENT_STYLE::subRect( subrect, w );
+ if ( subrect==SR_DockWindowHandleRect && w->inherits( "QDockWindowHandle" ) )
+ {
+ QDockWindow* wnd = ( QDockWindow* ) w->parent();
+ if( wnd->orientation()==Qt::Vertical )
+ r.setWidth( w->width() );
+ else
+ {
+ r.setY( r.y()+r.height()-w->height() );
+ r.setHeight( w->height() );
+ }
+ }
+
+ return r;
+}
+
+void SalomeStyle::drawComplexControl( ComplexControl control, QPainter* p, const QWidget* widget,
+ const QRect& r, const QColorGroup& cg, SFlags flags,
+ SCFlags controls, SCFlags active, const QStyleOption& opt ) const
+{
+
+
+
+
+ ((SalomeStyle*)this)->myTitleParent = 0;
+
+ switch ( control )
+ {
+ case CC_ComboBox:
+ if ( controls & SC_ComboBoxArrow )
+ {
+ SFlags flags = Style_Default;
+
+ qDrawShadeRect( p, r, cg, true, pixelMetric( PM_DefaultFrameWidth, widget ),
+ 0, widget->isEnabled() ? &cg.brush( QColorGroup::Base ) : &cg.brush( QColorGroup::Background ) );
+
+ QRect ar = QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget, SC_ComboBoxArrow ), widget );
+ if ( active == SC_ComboBoxArrow )
+ {
+ p->setPen( cg.dark() );
+ p->setBrush( cg.brush( QColorGroup::Button ) );
+ p->drawRect( ar );
+ }
+ else
+ qDrawWinPanel( p, ar, cg, FALSE, &cg.brush( QColorGroup::Button ) );
+
+ ar.addCoords( 2, 2, -2, -2 );
+ if ( widget->isEnabled() )
+ flags |= Style_Enabled;
+
+ if ( active == SC_ComboBoxArrow )
+ flags |= Style_Sunken;
+ drawPrimitive( PE_ArrowDown, p, ar, cg, flags );
+ }
+ PARENT_STYLE::drawComplexControl( control, p, widget, r, cg, flags, controls & ~SC_ComboBoxArrow, active, opt );
+ break;
+
+ case CC_TitleBar:
+ if( widget->inherits( "QTitleBar" ) )
+ ( ( SalomeStyle* )this )->myTitleParent = ( QWidget* )widget->parent();
+
+ default:
+ PARENT_STYLE::drawComplexControl( control, p, widget, r, cg, flags, controls, active, opt );
+ break;
+ }
+}
+
+QPixmap SalomeStyle::stylePixmap( StylePixmap st, const QWidget* w, const QStyleOption& opt ) const
+{
+ switch ( st )
+ {
+ case SP_DockWindowCloseButton:
+ case SP_TitleBarCloseButton:
+ return QPixmap( cross_xpm );
+ case SP_TitleBarMaxButton:
+ return QPixmap( maximize_xpm );
+ case SP_TitleBarNormalButton:
+ return QPixmap( normal_xpm );
+ case SP_TitleBarMinButton:
+ return QPixmap( minimize_xpm );
+ default:
+ return PARENT_STYLE::stylePixmap( st, w, opt );
+ }
+}
+
+int SalomeStyle::pixelMetric( PixelMetric pm, const QWidget* widget ) const
+{
+ int ret = 0;
+
+ switch ( pm )
+ {
+ case PM_ButtonMargin:
+ ret = 5;
+ break;
+ case PM_DockWindowFrameWidth:
+ ret = 0;
+ break;
+ case PM_TabBarTabOverlap:
+ ret = 2;
+ break;
+ case PM_TabBarTabHSpace:
+ ret = 20;
+ break;
+ case PM_TabBarTabShiftHorizontal:
+ case PM_TabBarTabShiftVertical:
+ ret = 0;
+ break;
+ case PM_TabBarTabVSpace:
+ ret = 5;
+ break;
+ case PM_DefaultFrameWidth:
+ ret = 1;
+ break;
+ case PM_SpinBoxFrameWidth:
+ ret = 1;
+ break;
+ case PM_ProgressBarChunkWidth:
+ ret = 1;
+ break;
+ default:
+ ret = PARENT_STYLE::pixelMetric( pm, widget );
+ break;
+ }
+ return ret;
+}
+
+QString SalomeStyle::titleText( const QString& txt, const int W, const QFontMetrics& fm ) const
+{
+ QString res = txt.stripWhiteSpace();
+
+ if ( fm.width( res ) > W )
+ {
+ QString end( "..." );
+ while ( !res.isEmpty() && fm.width( res + end ) > W )
+ res.remove( res.length() - 1, 1 );
+
+ if ( !res.isEmpty() )
+ res += end;
+ }
+
+ return res;
+}
+
+/*!
+ Class: SalomeStylePlugin [Internal]
+ Descr: Plugin for Qt style mechanism
+*/
+
+SalomeStylePlugin::SalomeStylePlugin()
+{
+}
+
+SalomeStylePlugin::~SalomeStylePlugin()
+{
+}
+
+QStringList SalomeStylePlugin::keys() const
+{
+ return QStringList() << "salome";
+}
+
+QStyle* SalomeStylePlugin::create( const QString& str )
+{
+ if ( str == "salome" )
+ return new SalomeStyle();
+ else
+ return 0;
+}
+
+Q_EXPORT_PLUGIN( SalomeStylePlugin )