10 #include "qwt_arrow_button.h" 
   15 #include <qstyleoption.h> 
   18 static const int MaxNum = 3;
 
   19 static const int Margin = 2;
 
   20 static const int Spacing = 1;
 
   22 class QwtArrowButton::PrivateData
 
   31     QStyleOptionButton option;
 
   32     option.initFrom( btn );
 
   33     option.features = QStyleOptionButton::None;
 
   35         option.features |= QStyleOptionButton::Flat;
 
   37         option.features |= QStyleOptionButton::HasMenu;
 
   38     if ( btn->autoDefault() || btn->isDefault() )
 
   39         option.features |= QStyleOptionButton::AutoDefaultButton;
 
   40     if ( btn->isDefault() )
 
   41         option.features |= QStyleOptionButton::DefaultButton;
 
   43         option.state |= QStyle::State_Sunken;
 
   44     if ( !btn->isFlat() && !btn->isDown() )
 
   45         option.state |= QStyle::State_Raised;
 
   56     : QPushButton( parent )
 
   58     m_data = 
new PrivateData;
 
   59     m_data->num = qBound( 1, 
num, MaxNum );
 
   62     setAutoRepeat( 
true );
 
   63     setAutoDefault( 
false );
 
   65     switch ( m_data->arrowType )
 
   69             setSizePolicy( QSizePolicy::Expanding,
 
   73             setSizePolicy( QSizePolicy::Fixed,
 
   74                 QSizePolicy::Expanding );
 
   90     return m_data->arrowType;
 
  106     const int m = Margin;
 
  109     r.setRect( r.x() + m, r.y() + m,
 
  110         r.width() - 2 * m, r.height() - 2 * m );
 
  114         QStyleOptionButton option = styleOpt( 
this );
 
  115         const int ph = style()->pixelMetric(
 
  116             QStyle::PM_ButtonShiftHorizontal, &option, 
this );
 
  117         const int pv = style()->pixelMetric(
 
  118             QStyle::PM_ButtonShiftVertical, &option, 
this );
 
  120         r.translate( ph, pv );
 
  132     QPushButton::paintEvent( event );
 
  133     QPainter painter( 
this );
 
  145     const bool isVertical = m_data->arrowType == Qt::UpArrow ||
 
  146         m_data->arrowType == Qt::DownArrow;
 
  151         boundingSize.transpose();
 
  154         ( boundingSize.width() - ( MaxNum - 1 ) * Spacing ) / MaxNum;
 
  157         QSize( w, boundingSize.height() ) );
 
  163     if ( m_data->arrowType == Qt::LeftArrow || m_data->arrowType == Qt::RightArrow )
 
  165         contentsSize.setWidth( m_data->num * arrow.width()
 
  166             + ( m_data->num - 1 ) * Spacing );
 
  167         contentsSize.setHeight( arrow.height() );
 
  171         contentsSize.setWidth( arrow.width() );
 
  172         contentsSize.setHeight( m_data->num * arrow.height()
 
  173             + ( m_data->num - 1 ) * Spacing );
 
  176     QRect arrowRect( contentsSize );
 
  177     arrowRect.moveCenter( r.center() );
 
  178     arrowRect.setSize( arrow );
 
  181     for ( 
int i = 0; i < m_data->num; i++ )
 
  183         drawArrow( painter, arrowRect, m_data->arrowType );
 
  189             dy = arrow.height() + Spacing;
 
  191             dx = arrow.width() + Spacing;
 
  193         arrowRect.translate( dx, dy );
 
  199         QStyleOptionFocusRect option;
 
  200         option.initFrom( 
this );
 
  201         option.backgroundColor = palette().color( QPalette::Window );
 
  203         style()->drawPrimitive( QStyle::PE_FrameFocusRect,
 
  204             &option, painter, 
this );
 
  216     const QRect& r, Qt::ArrowType arrowType )
 const 
  223             pa.setPoint( 0, r.bottomLeft() );
 
  224             pa.setPoint( 1, r.bottomRight() );
 
  225             pa.setPoint( 2, r.center().x(), r.top() );
 
  228             pa.setPoint( 0, r.topLeft() );
 
  229             pa.setPoint( 1, r.topRight() );
 
  230             pa.setPoint( 2, r.center().x(), r.bottom() );
 
  233             pa.setPoint( 0, r.topLeft() );
 
  234             pa.setPoint( 1, r.bottomLeft() );
 
  235             pa.setPoint( 2, r.right(), r.center().y() );
 
  238             pa.setPoint( 0, r.topRight() );
 
  239             pa.setPoint( 1, r.bottomRight() );
 
  240             pa.setPoint( 2, r.left(), r.center().y() );
 
  248     painter->setRenderHint( QPainter::Antialiasing, 
true );
 
  249     painter->setPen( Qt::NoPen );
 
  250     painter->setBrush( palette().brush( QPalette::ButtonText ) );
 
  251     painter->drawPolygon( pa );
 
  262     return qwtExpandedToGlobalStrut( hint );
 
  270     const QSize asz = 
arrowSize( Qt::RightArrow, QSize() );
 
  273         2 * Margin + ( MaxNum - 1 ) * Spacing + MaxNum * asz.width(),
 
  274         2 * Margin + asz.height()
 
  277     if ( m_data->arrowType == Qt::UpArrow || m_data->arrowType == Qt::DownArrow )
 
  280     QStyleOption styleOption;
 
  281     styleOption.initFrom( 
this );
 
  283     sz = style()->sizeFromContents( QStyle::CT_PushButton,
 
  284         &styleOption, sz, 
this );
 
  297     const QSize& boundingSize )
 const 
  299     QSize bs = boundingSize;
 
  303     const int MinLen = 2;
 
  304     const QSize sz = bs.expandedTo(
 
  305         QSize( MinLen, 2 * MinLen - 1 ) ); 
 
  310     if ( h > sz.height() )
 
  316     QSize arrSize( w, h );
 
  328     if ( event->isAutoRepeat() && event->key() == Qt::Key_Space )
 
  331     QPushButton::keyPressEvent( event );