1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 #include "SalomeStyle.h"
28 #include <qlineedit.h>
29 #include <qlistview.h>
30 #include <qdrawutil.h>
31 #include <qpopupmenu.h>
32 #include <qpushbutton.h>
33 #include <qobjectlist.h>
34 #include <qtoolbutton.h>
35 #include <qapplication.h>
37 static const char* const hole_xpm[] = {
47 static const char* const cross_xpm[] = {
67 static const char* const maximize_xpm[] = {
87 static const char* const normal_xpm[] = {
107 static const char* const minimize_xpm[] = {
128 Class: SalomeStyle [Public]
129 Descr: Style for SALOME platform
132 SalomeStyle::SalomeStyle()
135 qApp->installEventFilter( this );
138 SalomeStyle::~SalomeStyle()
142 void SalomeStyle::polish( QWidget* w )
147 if ( w->inherits( "QLineEdit" ) )
149 QLineEdit* fr = (QLineEdit*)w;
150 if ( w->parentWidget() && w->parentWidget()->inherits( "QSpinWidget" ) )
151 fr->setFrameStyle( QFrame::Plain );
154 fr->setFrameStyle( QFrame::Plain | QFrame::Box );
155 fr->setLineWidth( 1 );
156 fr->setMidLineWidth( 0 );
161 if ( w->inherits( "QToolBar" ) )
163 QToolBar* tb = (QToolBar*)w;
164 tb->setFrameStyle( QFrame::ToolBarPanel | QFrame::Plain );
165 tb->setLineWidth( 1 );
166 tb->setMidLineWidth( 1 );
169 if ( w->inherits( "QDockWindow" ) )
171 QDockWindow* dw = (QDockWindow*)w;
172 dw->setFrameStyle( QFrame::ToolBarPanel | QFrame::Raised );
175 else if ( w->inherits( "QListView" ) )
177 QListView* lv = (QListView*)w;
178 lv->setFrameStyle( QFrame::Box | QFrame::Plain );
182 PARENT_STYLE::polish( w );
185 bool SalomeStyle::eventFilter( QObject* o, QEvent* e )
187 if ( e->type() == QEvent::FocusIn || e->type() == QEvent::FocusOut )
189 QDockWindow* wnd = NULL;
191 if( o->inherits( "QDockWindow" ) )
192 wnd = ( QDockWindow* )o;
198 const QObjectList* objList = o->children();
199 for( QObjectListIterator anIt( *objList ); anIt.current(); ++anIt )
200 if( anIt.current()->inherits( "QDockWindowHandle" ) )
202 QWidget* ww = ( QWidget* )anIt.current();
203 ww->repaint( ww->rect() );
204 const QObjectList* wc = ww->children();
205 for( QObjectListIterator anIt2( *wc ); anIt2.current(); ++anIt2 )
206 if( anIt2.current()->inherits( "QToolButton" ) )
208 QWidget* tb = ( QWidget* )anIt2.current();
209 tb->repaint( tb->rect() );
215 if ( o && o->inherits( "QPushButton" ) && ( e->type() == QEvent::Enter || e->type() == QEvent::Leave ) )
216 ((QWidget*)o)->update();
221 double linear( double x )
226 void SalomeStyle::mix( const double t, const QColor& c1, const QColor& c2, QColor& res )
231 int r = int( c1.red() * (1-t) + c2.red() * t ),
232 g = int( c1.green() * (1-t) + c2.green() * t ),
233 b = int( c1.blue() * (1-t) + c2.blue() * t );
234 res.setRgb( r, g, b );
237 void SalomeStyle::mix( const double t, QRgb& rgb1, const QRgb& rgb2 )
242 int c[2][4] = { qRed( rgb1 ), qGreen( rgb1 ), qBlue( rgb1 ), qAlpha( rgb1 ),
243 qRed( rgb2 ), qGreen( rgb2 ), qBlue( rgb2 ), qAlpha( rgb2 ) };
244 for( int i=0; i<4; i++ )
245 c[0][i] = (int)( c[0][i] * (1-t) + c[1][i] * t );
247 rgb1 = qRgba( c[0][0], c[0][1], c[0][2], qAlpha( rgb1 ) );
250 void SalomeStyle::mix( const double t, QPixmap& pix, const QColor& col )
255 QImage anImage = pix.convertToImage();
256 if( anImage.isNull() )
259 if( anImage.depth()!=32 )
260 anImage = anImage.convertDepth( 32 );
262 int w = anImage.width(),
263 h = anImage.height();
265 QRgb colrgb = col.rgb(), cur;
266 for( int y=0; y<h; y++ )
268 uchar* line = anImage.scanLine( y );
269 QRgb* colorline = ( QRgb* ) line;
270 for( int x=0; x<w; x++ )
272 cur = colorline[ x ];
273 mix( t, cur, colrgb );
274 colorline[ x ] = cur;
280 void SalomeStyle::toGrayscale( QPixmap& pix, double k )
282 QImage anImage = pix.convertToImage();
283 if( anImage.isNull() )
286 if( anImage.depth()!=32 )
287 anImage = anImage.convertDepth( 32 );
289 int w = anImage.width(),
290 h = anImage.height();
292 for( int y=0; y<h; y++ )
294 uchar* line = anImage.scanLine( y );
295 QRgb* colorline = ( QRgb* ) line;
296 for( int x=0; x<w; x++ )
298 int gray = (int)( k * qGray( colorline[ x ] ) );
303 colorline[ x ] = qRgba( gray, gray, gray, qAlpha( colorline[x] ) );
309 void SalomeStyle::drawGradient( QPainter* p, const QRect& r,
310 const QColor& c1, const QColor& c2,
311 const Direction d, gradient_func f ) const
314 p->translate( r.x(), r.y() );
317 if( d==LeftToRight || d==RightToLeft )
318 for( int xmax = r.width(), x = d==LeftToRight ? 0 : xmax;
319 d==LeftToRight ? x<=xmax : x>=0;
320 d==LeftToRight ? x++ : x-- )
322 double t = double( x ) / double( xmax );
323 mix( d==LeftToRight ? f(t) : 1-f(t), c1, c2, mid );
325 p->drawLine( x, 0, x, r.height() );
328 for( int ymax = r.height(), y = d==UpToDown ? 0 : ymax;
329 d==UpToDown ? y<=ymax : y>=0;
330 d==UpToDown ? y++ : y-- )
332 double t = double( y ) / double( ymax );
333 mix( d==UpToDown ? f(t) : 1-f(t), c1, c2, mid );
335 p->drawLine( 0, y, r.width(), y );
341 void SalomeStyle::drawPrimitive( PrimitiveElement pe, QPainter* p, const QRect& r,
342 const QColorGroup& cg, SFlags flags, const QStyleOption& opt ) const
347 if ( !myTitleParent )
348 PARENT_STYLE::drawPrimitive( pe, p, r, cg, flags, opt );
351 case PE_DockWindowResizeHandle:
352 p->fillRect( r.x(), r.y(), r.width(), r.height(), cg.dark() );
353 if ( flags & Style_Horizontal )
354 p->fillRect( r.x(), r.y() + 1, r.width(), r.height() - 2, cg.midlight() );
356 p->fillRect( r.x() + 1, r.y(), r.width() - 2, r.height(), cg.midlight() );
359 case PE_DockWindowHandle:
361 QPaintDevice* pd = p->device();
365 QWidget* w = (QWidget*)pd;
367 if ( !w || !w->inherits( "QDockWindowHandle" ) )
370 QDockWindow* wnd = ( QDockWindow* ) w->parent();
374 QObject* activeWidget = qApp->focusWidget();
375 QDockWindow* activeWnd = 0;
376 while ( !activeWnd && activeWidget )
378 if ( activeWidget->inherits( "QDockWindow" ) )
379 activeWnd = (QDockWindow*)activeWidget;
381 activeWidget = activeWidget->parent();
384 bool act = wnd == activeWnd, horiz = flags & Style_Horizontal;
386 QPixmap hole( (const char**)hole_xpm );
388 if ( wnd->inherits( "QToolBar" ) )
390 drawGradient( p, r, cg.light(), cg.background(), horiz ? UpToDown : LeftToRight, linear );
392 int c = 4, i; double d = ( horiz ? r.height() : r.width() ) / ( c + 1 );
393 QBrush fill = cg.brush( QColorGroup::Dark );
394 p->setPen( Qt::red );
395 for ( i = 0; i < c; i++ )
398 p->drawPixmap( r.x() + r.width() / 2 - 1, (int)( r.y() + ( i + 1 ) * d - 1 ), hole );
400 p->drawPixmap( (int) ( r.x() + ( i + 1 ) * d - 1 ), r.y() + r.height() / 2 - 1, hole );
403 int dd = (int(d)/2) + (int(d)%2);
404 for ( i = 0; i < c - 1; i++ )
407 p->drawPixmap( r.x() + r.width() / 2 + 2, (int)( r.y() + dd + ( i + 1 ) * d - 1 ), hole );
409 p->drawPixmap( (int)( r.x() + dd + ( i + 1 ) * d - 1 ), r.y() + r.height() / 2 + 2, hole );
415 QRect rr( r.x()+d, r.y()+d, r.width()-2*d, r.height()-2*d );
419 mix( 0.5, cg.highlight(), Qt::white, col );
421 col = cg.background();
423 drawGradient( p, rr, act ? cg.highlight() : cg.dark(), col,
424 horiz ? LeftToRight : UpToDown, linear );
427 if ( flags & Style_Horizontal )
428 rt.addCoords( 0, 20, 0, 0 );
430 rt.addCoords( 0, 0, -20, 0 );
432 int textW = flags & Style_Horizontal ? rt.height() : rt.width();
433 int textH = flags & Style_Horizontal ? rt.width() : rt.height();
435 QString title = titleText( wnd->caption(), textW, p->fontMetrics() );
439 QColorGroup cgroup = wnd->isActiveWindow() ? wnd->palette().active() : wnd->palette().inactive();
440 p->setPen( cgroup.highlightedText() );
442 if ( flags & Style_Horizontal )
445 p->translate( -(rt.height()+rt.y()), (rt.width()-rt.x()) );
446 p->drawText( 0, 0, title );
449 p->drawText( 2, 2, textW, textH, AlignLeft, title );
455 case PE_DockWindowSeparator:
457 bool horiz = ( flags & Style_Horizontal );
458 QWidget* w = ( QWidget* )p->device();
459 if( w->inherits( "QToolBarSeparator" ) )
461 drawGradient( p, r, cg.light(), cg.background(), horiz ? UpToDown : LeftToRight, linear );
462 int w = r.width(), h = r.height();
465 p->setPen( cg.dark() );
467 p->drawLine( r.x() + w/2, r.y() + h/part, r.x() + w/2, r.y() + (part-1)*h/part );
469 p->drawLine( r.x() + w/part, r.y() + h/2, r.x() + (part-1)*w/part, r.y() + h/2 );
471 p->setPen( cg.light() );
473 p->drawLine( r.x() + w/2 + 1, r.y() + h/part + 1, r.x() + w/2 + 1, r.y() + (part-1)*h/part + 1 );
475 p->drawLine( r.x() + w/part + 1, r.y() + h/2 + 1, r.x() + (part-1)*w/part + 1, r.y() + h/2 + 1 );
478 PARENT_STYLE::drawPrimitive( pe, p, r, cg, flags, opt );
482 case PE_PanelDockWindow:
484 QWidget* w = ( QWidget* )p->device();
486 int offset = pixelMetric( PM_DockWindowHandleExtent, w );
487 if ( w->inherits( "QToolBar" ) )
489 bool vert = ( ( QToolBar* )w )->orientation() == Qt::Vertical;
491 drawGradient( p, QRect( r.x(), r.y()+offset, r.x()+r.width(), r.y()+offset ),
492 cg.light(), cg.background(), LeftToRight, linear );
494 drawGradient( p, QRect( r.x()+offset, r.y(), r.x()+offset, r.y()+r.height() ),
495 cg.light(), cg.background(), UpToDown, linear );
497 p->setPen( QPen( cg.light(), 1 ) );
502 p->setPen( QPen( cg.dark(), 1 ) );
503 p->setBrush( cg.light() );
511 p->setPen( QPen( cg.dark(), 1 ) );
512 p->setBrush( cg.light() );
516 case PE_HeaderSection:
518 QColor col; mix( 0.2, cg.light(), Qt::black, col );
519 drawGradient( p, r, cg.light(), col, DownToUp, linear );
520 drawGradient( p, QRect( r.x(), r.y(), 1, r.height() ), cg.light(), cg.dark(), DownToUp, linear );
521 p->setPen( cg.dark() );
522 p->drawLine( r.x(), r.y()+r.height()-1, r.x()+r.width(), r.y()+r.height()-1 );
527 p->fillRect( r.x() + 1, r.y() + 1, r.width() - 2, r.height() - 2, cg.dark() );
528 p->fillRect( r.x() + 2, r.y() + 2, r.width() - 4, r.height() - 4, cg.midlight() );
532 PARENT_STYLE::drawPrimitive( PE_ButtonDropDown, p, r, cg, flags, opt );
535 case PE_ButtonCommand:
537 QColorGroup cGrp( cg );
538 if ( flags & Style_MouseOver )
539 cGrp.setColor( QColorGroup::Button, cGrp.midlight() );
541 if ( flags & Style_MouseOver )
542 PARENT_STYLE::drawPrimitive( PE_ButtonDropDown, p, r, cGrp, flags, opt );
544 PARENT_STYLE::drawPrimitive( flags & Style_Raised ? PE_ButtonDropDown : pe, p, r, cGrp, flags, opt );
549 PARENT_STYLE::drawPrimitive( pe, p, r, cg, flags, opt );
554 void SalomeStyle::drawControl( ControlElement element, QPainter* p, const QWidget* widget, const QRect& r,
555 const QColorGroup& cg, SFlags flags, const QStyleOption& opt ) const
559 case CE_PopupMenuItem:
561 if(! widget || opt.isDefault())
564 const QPopupMenu *popupmenu = (const QPopupMenu *) widget;
565 QMenuItem *mi = opt.menuItem();
569 int tab = opt.tabWidth();
570 int maxpmw = opt.maxIconWidth();
571 bool dis = !( flags & Style_Enabled );
572 bool checkable = popupmenu->isCheckable();
573 bool act = flags & Style_Active;
574 bool use2000style = true;
577 int windowsItemFrame = 2,
578 windowsItemHMargin = 5,
579 windowsItemVMargin = 1,
580 windowsRightBorder = 2,
581 windowsArrowHMargin = 2;
583 r.rect(&x, &y, &w, &h);
587 // space for the checkmarks
589 maxpmw = QMAX( maxpmw, 20 );
591 maxpmw = QMAX( maxpmw, 12 );
594 int checkcol = maxpmw;
596 if ( mi && mi->isSeparator() )
598 p->setPen( cg.dark() );
599 p->drawLine( x+3*checkcol/2, y, x+w, y );
600 //p->setPen( cg.light() );
601 //p->drawLine( x, y+1, x+w, y+1 );
605 QBrush fill = ( act && !dis ?
606 cg.brush( QColorGroup::Highlight ) :
607 cg.brush( QColorGroup::Light ) );
608 p->fillRect( x, y, w, h, fill );
614 QRect vrect = visualRect( QRect( xpos, y, checkcol, h ), r );
615 int xvis = vrect.x();
617 if( mi->isChecked() )
620 qDrawShadePanel( p, xvis, y, checkcol, h,
621 cg, TRUE, 1, &cg.brush( QColorGroup::Button ) );
624 QBrush fill( cg.light(), Dense4Pattern );
625 // set the brush origin for the hash pattern to the x/y coordinate
626 // of the menu item's checkmark... this way, the check marks have
628 QPoint origin = p->brushOrigin();
629 p->setBrushOrigin( xvis, y );
630 qDrawShadePanel( p, xvis, y, checkcol, h, cg, TRUE, 1, &fill );
631 // restore the previous brush origin
632 p->setBrushOrigin( origin );
636 p->fillRect(x+checkcol, y, w-checkcol , h, cg.brush( QColorGroup::Light ));
638 if( !( act && !dis ) && !mi->isChecked() )
640 QColor col; mix( 0.5, cg.mid(), Qt::white, col );
641 drawGradient( p, QRect( xvis, y, checkcol, h+1 ), cg.light(), col, LeftToRight, linear );
646 QIconSet::Mode mode = dis ? QIconSet::Active : QIconSet::Normal;
648 mode = QIconSet::Active;
650 if( checkable && mi->isChecked() )
651 pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode, QIconSet::On );
653 pixmap = mi->iconSet()->pixmap( QIconSet::Small, mode );
654 int pixw = pixmap.width();
655 int pixh = pixmap.height();
658 toGrayscale( pixmap, 1.1 );
660 //if( act && !dis && !mi->isChecked() )
661 // qDrawShadePanel( p, xvis, y, checkcol, h, cg, FALSE, 1, &cg.brush( QColorGroup::Button ) );
663 QRect pmr( 0, 0, pixw, pixh );
664 pmr.moveCenter( vrect.center() );
665 p->setPen( cg.text() );
666 p->drawPixmap( pmr.topLeft(), pixmap );
668 QBrush fill = ( act ? cg.brush( QColorGroup::Highlight ) : cg.brush( QColorGroup::Light ));
669 int xp = xpos + checkcol + 1;
671 p->fillRect( visualRect( QRect( xp, y, w - checkcol - 1, h ), r ), fill);
674 { // just "checking"...
675 if( mi->isChecked() )
677 int xp = xpos + windowsItemFrame;
679 SFlags cflags = Style_Default;
681 cflags |= Style_Enabled;
685 drawPrimitive( PE_CheckMark, p,
686 visualRect( QRect( xp, y + windowsItemFrame,
687 checkcol - 2*windowsItemFrame,
688 h - 2*windowsItemFrame), r ), cg, cflags, opt );
692 p->setPen( act ? cg.highlightedText() : cg.buttonText() );
701 int xm = windowsItemFrame + checkcol + windowsItemHMargin;
704 vrect = visualRect( QRect( xpos, y+windowsItemVMargin, w-xm-tab+1, h-2*windowsItemVMargin ), r );
711 p->setPen( cg.light() );
712 mi->custom()->paint( p, cg, act, !dis,
713 xvis+1, y+windowsItemVMargin+1,
714 w-xm-tab+1, h-2*windowsItemVMargin );
717 mi->custom()->paint( p, cg, act, !dis, xvis, y+windowsItemVMargin,
718 w-xm-tab+1, h-2*windowsItemVMargin );
721 QString s = mi->text();
724 int t = s.find( '\t' );
725 int text_flags = AlignVCenter | ShowPrefix | DontClip | SingleLine;
726 if( !styleHint( SH_UnderlineAccelerator, widget ) )
727 text_flags |= NoAccel;
728 text_flags |= (QApplication::reverseLayout() ? AlignRight : AlignLeft );
731 int xp = x + w - tab - windowsItemHMargin - windowsItemFrame + 1;
735 xp -= windowsRightBorder;
736 int xoff = visualRect( QRect( xp, y+windowsItemVMargin, tab, h-2*windowsItemVMargin ), r ).x();
739 p->setPen( cg.light() );
740 p->drawText( xoff+1, y+windowsItemVMargin+1, tab, h-2*windowsItemVMargin, text_flags, s.mid( t+1 ));
743 p->drawText( xoff, y+windowsItemVMargin, tab, h-2*windowsItemVMargin, text_flags, s.mid( t+1 ) );
748 p->setPen( cg.light() );
749 p->drawText( xvis+1, y+windowsItemVMargin+1, w-xm-tab+1, h-2*windowsItemVMargin, text_flags, s, t );
752 p->drawText( xvis, y+windowsItemVMargin, w-xm-tab+1, h-2*windowsItemVMargin, text_flags, s, t );
754 else if( mi->pixmap() )
756 QPixmap *pixmap = mi->pixmap();
757 if( pixmap->depth() == 1 )
758 p->setBackgroundMode( OpaqueMode );
759 p->drawPixmap( xvis, y+windowsItemFrame, *pixmap );
760 if( pixmap->depth() == 1 )
761 p->setBackgroundMode( TransparentMode );
764 { // draw sub menu arrow
765 int dim = (h-2*windowsItemFrame) / 2;
766 PrimitiveElement arrow;
767 arrow = ( QApplication::reverseLayout() ? PE_ArrowLeft : PE_ArrowRight );
768 xpos = x+w - windowsArrowHMargin - windowsItemFrame - dim;
769 vrect = visualRect( QRect(xpos, y + h / 2 - dim / 2, dim, dim), r );
773 g2.setColor( QColorGroup::ButtonText, g2.highlightedText() );
774 drawPrimitive( arrow, p, vrect, g2, dis ? Style_Default : Style_Enabled, opt );
778 drawPrimitive( arrow, p, vrect, cg, dis ? Style_Default : Style_Enabled, opt );
784 p->setPen( cg.dark() );
792 bool active = flags & Style_Active;
793 bool down = flags & Style_Down;
799 //QColor col; mix( 0.5, cg.mid(), Qt::white, col );
800 //drawGradient( p, r, col, cg.light(), UpToDown, linear );
801 p->setPen( cg.light() );
802 p->setBrush( cg.light() );
805 p->setPen( cg.dark() );
806 int w = r.width()-1, h = r.height();
807 p->drawLine( r.x(), r.y(), r.x()+w, r.y() );
808 p->drawLine( r.x(), r.y(), r.x(), r.y()+h );
809 p->drawLine( r.x()+w, r.y(), r.x()+w, r.y()+h );
811 p->translate( 1, 1 );
814 drawGradient( p, r, cg.light(), cg.background(), active ? DownToUp : UpToDown, linear );
816 QCommonStyle::drawControl(element, p, widget, pr, cg, flags, opt);
821 case CE_MenuBarEmptyArea:
823 drawGradient( p, r, cg.light(), cg.background(), UpToDown, linear );
827 case CE_ToolButtonLabel:
829 const QToolButton *toolbutton = (const QToolButton *) widget;
830 QObject* parent = toolbutton->parent();
834 if( parent->inherits( "QToolBar" ) )
836 tb = ( QToolBar* )parent;
840 parent = parent->parent();
841 parent = toolbutton->parent();
846 if( tb->orientation()==Qt::Horizontal )
850 drawGradient( p, r, cg.light(), cg.background(), horiz ? UpToDown : LeftToRight, linear );
852 else if( parent->inherits( "QDockWindowHandle" ) )
854 QWidget* w = ( QWidget* ) parent;
855 QDockWindow* wnd = ( QDockWindow* )w->parent();
856 if( !wnd->orientation()==Qt::Horizontal )
861 QPoint pp( r.x(), r.y() ),
862 qq = toolbutton->mapToParent( pp );
864 bitBlt( p->device(), r.x(), r.y(), w, horiz ? qq.x()-r.width() : qq.x(),
865 horiz ? qq.y() : qq.y()+r.height(),
866 r.width(), r.height(), Qt::CopyROP, true );
869 bool highlight = ( flags & Style_MouseOver ),
870 down = ( flags & ( Style_Down | Style_On ) ),
871 en = toolbutton->isEnabled();
876 drawGradient( p, r, cg.light(), cg.background(), horiz==1 ? DownToUp : RightToLeft, linear );
877 p->setPen( cg.background() );
882 p->setPen( cg.dark() );
883 p->setBrush( cg.light() );
888 p->setPen( cg.dark() );
889 QColor col; mix( 0.05, cg.background(), Qt::black, col );
896 Qt::ArrowType arrowType = opt.isDefault() ? Qt::DownArrow : opt.arrowType();
898 int shiftX = 0, shiftY = 0;
899 if( flags & ( Style_Down | Style_On ) )
901 shiftX = pixelMetric(PM_ButtonShiftHorizontal, widget);
902 shiftY = pixelMetric(PM_ButtonShiftVertical, widget);
905 if (!opt.isDefault())
910 case Qt::LeftArrow: pe = PE_ArrowLeft; break;
911 case Qt::RightArrow: pe = PE_ArrowRight; break;
912 case Qt::UpArrow: pe = PE_ArrowUp; break;
914 case Qt::DownArrow: pe = PE_ArrowDown; break;
917 rect.moveBy(shiftX, shiftY);
918 drawPrimitive(pe, p, rect, cg, flags, opt);
922 QColor btext = toolbutton->paletteForegroundColor();
924 if (toolbutton->iconSet().isNull() &&
925 ! toolbutton->text().isNull() &&
926 ! toolbutton->usesTextLabel())
928 int alignment = AlignCenter | ShowPrefix;
929 if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
930 alignment |= NoAccel;
932 rect.moveBy(shiftX, shiftY);
933 drawItem( p, rect, alignment, cg, flags & Style_Enabled, 0, toolbutton->text(),
934 toolbutton->text().length(), &btext);
939 QIconSet::Size size =
940 toolbutton->usesBigPixmap() ? QIconSet::Large : QIconSet::Small;
941 QIconSet::State state = toolbutton->isOn() ? QIconSet::On : QIconSet::Off;
943 if( !toolbutton->isEnabled() )
944 mode = QIconSet::Active; //QIconSet::Disabled;
945 else if( flags & (Style_Down | Style_On ) || ( flags & Style_Raised ) && (flags & Style_AutoRaise))
946 mode = QIconSet::Active;
948 mode = QIconSet::Normal;
949 pm = toolbutton->iconSet().pixmap( size, mode, state );
951 if( toolbutton->usesTextLabel() )
953 p->setFont( toolbutton->font() );
954 QRect pr = rect, tr = rect;
955 int alignment = ShowPrefix;
956 if (!styleHint(SH_UnderlineAccelerator, widget, QStyleOption::Default, 0))
957 alignment |= NoAccel;
959 if( toolbutton->textPosition() == QToolButton::Under )
961 int fh = p->fontMetrics().height();
962 pr.addCoords( 0, 1, 0, -fh-3 );
963 tr.addCoords( 0, pr.bottom(), 0, -3 );
964 pr.moveBy(shiftX, shiftY);
965 drawItem( p, pr, AlignCenter, cg, TRUE, &pm, QString::null );
966 alignment |= AlignCenter;
970 pr.setWidth( pm.width() + 8 );
971 tr.addCoords( pr.right(), 0, 0, 0 );
972 pr.moveBy(shiftX, shiftY);
974 drawItem( p, pr, AlignCenter, cg, TRUE, &pm, QString::null );
975 alignment |= AlignLeft | AlignVCenter;
978 tr.moveBy(shiftX, shiftY);
979 drawItem( p, tr, alignment, cg, flags & Style_Enabled, 0, toolbutton->textLabel(),
980 toolbutton->textLabel().length(), &btext);
984 /*if( en && !highlight )
985 mix( 0.6, pm, cg.background() );
988 toGrayscale( pm, 1.1 );
989 mix( 0.8, pm, cg.background() );
992 rect.moveBy(shiftX, shiftY);
993 drawItem( p, rect, AlignCenter, cg, true, &pm, QString::null );
1002 QPen oldPen = p->pen();
1005 bool selected = flags & Style_Selected;
1007 p->setPen( cg.midlight() );
1008 p->drawLine( r2.left(), r2.bottom(), r2.right(), r2.bottom() );
1011 r2.setRect( r2.left(), r2.top() + 1, r2.width(), r2.height() - 1 );
1013 r2.setRect( r2.left(), r2.top(), r2.width() - 2, r2.height() - 1 );
1015 p->setPen( cg.foreground() );
1016 drawGradient( p, QRect( r2.left(), r2.top(), r2.width(), r2.height() - 1 ),
1017 selected ? cg.highlight() : cg.dark(), cg.background(), UpToDown, linear );
1019 // p->fillRect( r2.left(), r2.top(), r2.width(), r2.height() - 1, selected ? cg.highlight() : cg.background() );
1020 p->drawRect( r2.left(), r2.top(), r2.width(), r2.height() - 1 );
1024 p->setPen( cg.shadow() );
1025 p->drawLine( r2.left() + 1, r2.bottom(), r2.right() + 1, r2.bottom() );
1026 p->drawLine( r2.right() + 1, r2.top() + 1, r2.right() + 1, r2.bottom() );
1032 case CE_TabBarLabel:
1034 QColorGroup tmp( cg );
1035 if ( flags & Style_Selected )
1036 tmp.setColor( QColorGroup::Foreground, tmp.highlightedText() );
1037 PARENT_STYLE::drawControl( element, p, widget, r, tmp, flags, opt );
1043 if ( flags & Style_Enabled && !( flags & Style_Down || flags & Style_On ) )
1045 const QPushButton* button = (const QPushButton*)widget;
1046 QRect br = QRect( button->mapToGlobal( button->rect().topLeft() ), button->rect().size() );
1047 if ( br.contains( QCursor::pos() ) )
1048 flags |= Style_MouseOver;
1051 PARENT_STYLE::drawControl( element, p, widget, r, cg, flags, opt );
1056 PARENT_STYLE::drawControl( element, p, widget, r, cg, flags, opt );
1061 QRect SalomeStyle::subRect( SubRect subrect, const QWidget* w ) const
1063 QRect r = PARENT_STYLE::subRect( subrect, w );
1064 if ( subrect==SR_DockWindowHandleRect && w->inherits( "QDockWindowHandle" ) )
1066 QDockWindow* wnd = ( QDockWindow* ) w->parent();
1067 if( wnd->orientation()==Qt::Vertical )
1068 r.setWidth( w->width() );
1071 r.setY( r.y()+r.height()-w->height() );
1072 r.setHeight( w->height() );
1079 void SalomeStyle::drawComplexControl( ComplexControl control, QPainter* p, const QWidget* widget,
1080 const QRect& r, const QColorGroup& cg, SFlags flags,
1081 SCFlags controls, SCFlags active, const QStyleOption& opt ) const
1087 ((SalomeStyle*)this)->myTitleParent = 0;
1092 if ( controls & SC_ComboBoxArrow )
1094 SFlags flags = Style_Default;
1096 qDrawShadeRect( p, r, cg, true, pixelMetric( PM_DefaultFrameWidth, widget ),
1097 0, widget->isEnabled() ? &cg.brush( QColorGroup::Base ) : &cg.brush( QColorGroup::Background ) );
1099 QRect ar = QStyle::visualRect( querySubControlMetrics( CC_ComboBox, widget, SC_ComboBoxArrow ), widget );
1100 if ( active == SC_ComboBoxArrow )
1102 p->setPen( cg.dark() );
1103 p->setBrush( cg.brush( QColorGroup::Button ) );
1107 qDrawWinPanel( p, ar, cg, FALSE, &cg.brush( QColorGroup::Button ) );
1109 ar.addCoords( 2, 2, -2, -2 );
1110 if ( widget->isEnabled() )
1111 flags |= Style_Enabled;
1113 if ( active == SC_ComboBoxArrow )
1114 flags |= Style_Sunken;
1115 drawPrimitive( PE_ArrowDown, p, ar, cg, flags );
1117 PARENT_STYLE::drawComplexControl( control, p, widget, r, cg, flags, controls & ~SC_ComboBoxArrow, active, opt );
1121 if( widget->inherits( "QTitleBar" ) )
1122 ( ( SalomeStyle* )this )->myTitleParent = ( QWidget* )widget->parent();
1125 PARENT_STYLE::drawComplexControl( control, p, widget, r, cg, flags, controls, active, opt );
1130 QPixmap SalomeStyle::stylePixmap( StylePixmap st, const QWidget* w, const QStyleOption& opt ) const
1134 case SP_DockWindowCloseButton:
1135 case SP_TitleBarCloseButton:
1136 return QPixmap( cross_xpm );
1137 case SP_TitleBarMaxButton:
1138 return QPixmap( maximize_xpm );
1139 case SP_TitleBarNormalButton:
1140 return QPixmap( normal_xpm );
1141 case SP_TitleBarMinButton:
1142 return QPixmap( minimize_xpm );
1144 return PARENT_STYLE::stylePixmap( st, w, opt );
1148 int SalomeStyle::pixelMetric( PixelMetric pm, const QWidget* widget ) const
1154 case PM_ButtonMargin:
1157 case PM_DockWindowFrameWidth:
1160 case PM_TabBarTabOverlap:
1163 case PM_TabBarTabHSpace:
1166 case PM_TabBarTabShiftHorizontal:
1167 case PM_TabBarTabShiftVertical:
1170 case PM_TabBarTabVSpace:
1173 case PM_DefaultFrameWidth:
1176 case PM_SpinBoxFrameWidth:
1179 case PM_ProgressBarChunkWidth:
1183 ret = PARENT_STYLE::pixelMetric( pm, widget );
1189 QString SalomeStyle::titleText( const QString& txt, const int W, const QFontMetrics& fm ) const
1191 QString res = txt.stripWhiteSpace();
1193 if ( fm.width( res ) > W )
1195 QString end( "..." );
1196 while ( !res.isEmpty() && fm.width( res + end ) > W )
1197 res.remove( res.length() - 1, 1 );
1199 if ( !res.isEmpty() )
1207 Class: SalomeStylePlugin [Internal]
1208 Descr: Plugin for Qt style mechanism
1211 SalomeStylePlugin::SalomeStylePlugin()
1215 SalomeStylePlugin::~SalomeStylePlugin()
1219 QStringList SalomeStylePlugin::keys() const
1221 return QStringList() << "salome";
1224 QStyle* SalomeStylePlugin::create( const QString& str )
1226 if ( str == "salome" )
1227 return new SalomeStyle();
1232 Q_EXPORT_PLUGIN( SalomeStylePlugin )