Author: coolo Date: Thu Dec 20 20:22:42 2007 New Revision: 43208 URL: http://svn.opensuse.org/viewcvs/yast?rev=43208&view=rev Log: support `CurrentItem in timezone selector to set a zone without zooming into it (for default value) Modified: trunk/core/libyui/doc/examples/TimezoneSelector.ycp trunk/core/libyui/src/YTimezoneSelector.cc trunk/core/libyui/src/YTimezoneSelector.h trunk/qt/src/YQTimezoneSelector.cc trunk/qt/src/YQTimezoneSelector.h Modified: trunk/core/libyui/doc/examples/TimezoneSelector.ycp URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/doc/examples/TimezoneSelector.ycp?rev=43208&r1=43207&r2=43208&view=diff ============================================================================== --- trunk/core/libyui/doc/examples/TimezoneSelector.ycp (original) +++ trunk/core/libyui/doc/examples/TimezoneSelector.ycp Thu Dec 20 20:22:42 2007 @@ -43,43 +43,51 @@ "US/Samoa" : "Samoa", "US/Eastern" : "Eastern", "Europe/London" : "United Kingdom", - "America/New_York" : "Eastern" - + "America/New_York" : "Eastern", + "Australia/Darwin" : "Northern Territory--Darwin", + "Australia/Brisbane" : "Queensland--Brisbane", + "Australia/South" : "South Australia--Adelaide", + "Australia/Sydney" : "New South Wales--Sydney", + "Australia/ACT" : "Australian Capital Territory--Canberra", + "Australia/Hobart" : "Tasmania--Hobart", + "Australia/Melbourne" : "Victoria--Melbourne", + "Australia/Perth" : "Western Australia--Perth" ]; // Ask the UI whether or not it supports this widget. - + if ( UI::HasSpecialWidget(`TimezoneSelector) ) { // Only create a dialog with this kind of widget if it is supported UI::OpenDialog( - `VBox( + `VBox( `TimezoneSelector(`id(`timezone), `opt(`notify), Directory::themedir + "/current/worldmap/GLOBALeb10colshade.jpg", examples), `PushButton(`id(`ok), `opt(`default), "&Close"), - `ComboBox(`id(`combozone), `opt(`notify), + `ComboBox(`id(`combozone), `opt(`notify), "", [ - `item("Please select your timezone"), `item(`id(`london), "Europe/London" ), `item(`id(`prag), "Europe/Prague" ), `item(`id(`ny), "America/New_York" ) ] ) ) ); + // preselect something + UI::ChangeWidget(`id(`timezone), `CurrentItem, "Europe/London"); } else { // Always provide a fallback: Either try to create a simpler dialog // without the special widget, or terminate with an error message. UI::OpenDialog( - `VBox( + `VBox( `Label("Timezone Selector not supported!"), `PushButton(`opt(`default), "&Oops!") ) ); } - + while( true ) { symbol button = (symbol)UI::UserInput(); @@ -102,7 +110,7 @@ string zone=(string)UI::QueryWidget(`id(`timezone), `Value); UI::ChangeWidget(`id(`combozone), `Value, zone); } - } + } UI::CloseDialog(); } Modified: trunk/core/libyui/src/YTimezoneSelector.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YTimezoneSelector.cc?rev=43208&r1=43207&r2=43208&view=diff ============================================================================== --- trunk/core/libyui/src/YTimezoneSelector.cc (original) +++ trunk/core/libyui/src/YTimezoneSelector.cc Thu Dec 20 20:22:42 2007 @@ -23,7 +23,7 @@ #include "YUISymbols.h" #include "YTimezoneSelector.h" -class YTimezoneSelectorPrivate +class YTimezoneSelectorPrivate { bool dummy; }; @@ -51,6 +51,7 @@ if ( propSet.isEmpty() ) { propSet.add( YProperty( YUIProperty_Value, YStringProperty ) ); + propSet.add( YProperty( YUIProperty_CurrentItem, YStringProperty ) ); propSet.add( YWidget::propertySet() ); } @@ -65,13 +66,15 @@ if ( propertyName == YUIProperty_Value ) { - setCurrentZone( val.stringVal() ); + setCurrentZone( val.stringVal(), true ); return true; // success -- no special handling necessary } - else + if ( propertyName == YUIProperty_CurrentItem ) { - return YWidget::setProperty( propertyName, val ); + setCurrentZone( val.stringVal(), false ); + return true; // success -- no special handling necessary } + return YWidget::setProperty( propertyName, val ); } @@ -81,9 +84,7 @@ propertySet().check( propertyName ); // throws exceptions if not found if ( propertyName == YUIProperty_Value ) return YPropertyValue( currentZone() ); - else - { - return YWidget::getProperty( propertyName ); - } + if ( propertyName == YUIProperty_CurrentItem ) return YPropertyValue( currentZone() ); + return YWidget::getProperty( propertyName ); } Modified: trunk/core/libyui/src/YTimezoneSelector.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/core/libyui/src/YTimezoneSelector.h?rev=43208&r1=43207&r2=43208&view=diff ============================================================================== --- trunk/core/libyui/src/YTimezoneSelector.h (original) +++ trunk/core/libyui/src/YTimezoneSelector.h Thu Dec 20 20:22:42 2007 @@ -87,7 +87,7 @@ /** * subclasses have to implement this to set value */ - virtual void setCurrentZone( const std::string &zone ) = 0; + virtual void setCurrentZone( const std::string &zone, bool zoom ) = 0; private: ImplPtr<YTimezoneSelectorPrivate> priv; Modified: trunk/qt/src/YQTimezoneSelector.cc URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt/src/YQTimezoneSelector.cc?rev=43208&r1=43207&r2=43208&view=diff ============================================================================== --- trunk/qt/src/YQTimezoneSelector.cc (original) +++ trunk/qt/src/YQTimezoneSelector.cc Thu Dec 20 20:22:42 2007 @@ -45,6 +45,7 @@ YQTimezoneSelectorPrivate( QWidget *p ) { parent = p; blink = 0; + highlight = 0; } QImage _pix; QPoint _zoom; @@ -166,13 +167,13 @@ int YQTimezoneSelector::preferredWidth() { - return 400; + return 600; } int YQTimezoneSelector::preferredHeight() { - return 200; + return 300; } @@ -192,7 +193,6 @@ if ( event->button() == Qt::RightButton ) { d->_zoom = QPoint(); - d->_best = YQTimezoneSelectorPrivate::Location(); d->cachePix = QPixmap(); } else if ( event->button() == Qt::LeftButton ) @@ -246,28 +246,50 @@ p.drawPixmap( 0, 0, d->cachePix ); - if ( d->highlight > 0 ) - { - QPoint pos = d->pixPosition( d->_best ); - static const QColor blinks[] = { QColor( "#00ff00" ), QColor( "#22dd00" ), QColor( "#44bb00" ), - QColor( "#669900" ), QColor( "#887700" ), QColor( "#aa5500" ), - QColor( "#887700" ), QColor( "#669900" ), QColor( "#44bb00" ), - QColor( "#22dd00" ) }; - int index = d->highlight - 1; - p.setPen( blinks[ index ] ); - p.setBrush( blinks[ index ] ); - - p.drawEllipse( QRect( d->pixToWindow( d->_best.pix_pos ) - QPoint( 2,2 ), QSize( 5, 5 ) ) ); - } setCursor( Qt::CrossCursor ); } - p.setBrush( Qt::green ); - p.setPen( Qt::green ); + p.setBrush( QColor( "#D8DF57" ) ); + p.setPen( QColor( "#B9DFD6" ) ); for ( QListYQTimezoneSelectorPrivate::Location::const_iterator it = d->locations.begin(); it != d->locations.end(); ++it ) { if ( !d->highlight || ( *it ).zone != d->_best.zone ) - p.drawEllipse( QRect( d->pixToWindow( ( *it ).pix_pos ) - QPoint( 2,2 ), QSize( 5, 5 ) ) ); + { + if ( d->_zoom.isNull() ) + p.drawEllipse( QRect( d->pixToWindow( ( *it ).pix_pos ) - QPoint( 1,1 ), QSize( 3, 3 ) ) ); + else + p.drawEllipse( QRect( d->pixToWindow( ( *it ).pix_pos ) - QPoint( 2,2 ), QSize( 5, 5 ) ) ); + } + } + if ( d->highlight > 0 ) + { + QPoint pos = d->pixPosition( d->_best ); + static const QColor blinks[] = { QColor( "#00ff00" ), QColor( "#22dd00" ), QColor( "#44bb00" ), + QColor( "#669900" ), QColor( "#887700" ), QColor( "#aa5500" ), + QColor( "#887700" ), QColor( "#669900" ), QColor( "#44bb00" ), + QColor( "#22dd00" ) }; + int index = d->highlight - 1; + p.setPen( blinks[ index ] ); + p.setBrush( blinks[ index ] ); + + p.drawEllipse( QRect( d->pixToWindow( d->_best.pix_pos ) - QPoint( 2,2 ), QSize( 5, 5 ) ) ); + + QFont f( font() ); + f.setBold( true ); + p.setFont( f ); + QFontMetrics fm( f ); + + QPoint off = d->pixToWindow( d->_best.pix_pos ) + QPoint( 11, 4 ); + int tw = fm.width( d->_best.tip ); + if ( tw + off.x() > width() ) + off.rx() = d->pixToWindow( d->_best.pix_pos ).x() - tw - 10; + + p.setPen( Qt::black ); + p.drawText( off, d->_best.tip ); + + p.setPen( Qt::white ); + p.drawText( off - QPoint( 1, 1 ), d->_best.tip ); + } } @@ -307,13 +329,18 @@ QPoint YQTimezoneSelectorPrivate::pixToWindow( const QPoint &pos ) const { + if ( _zoom.isNull() ) + { + return QPoint( double( pos.x() ) * parent->width() / _pix.width(), + double( pos.y() ) * parent->height() / _pix.height() ); + } int left = qMin( qMax( _zoom.x() - parent->width() / 2, 0 ), _pix.width() - parent->width() ); int top = qMin( qMax( _zoom.y() - parent->height() / 2, 0 ), _pix.height() - parent->height() ); return QPoint( pos.x() - left, pos.y() - top ); } -void YQTimezoneSelector::setCurrentZone( const std::string &_zone ) +void YQTimezoneSelector::setCurrentZone( const std::string &_zone, bool zoom ) { QString zone = QString::fromStdString( _zone ); @@ -328,8 +355,10 @@ d->_best = *it; } - d->_zoom = d->_best.pix_pos; + if ( zoom ) + d->_zoom = d->_best.pix_pos; d->cachePix = QPixmap(); + d->highlight = 1; d->blink->start(); update(); Modified: trunk/qt/src/YQTimezoneSelector.h URL: http://svn.opensuse.org/viewcvs/yast/trunk/qt/src/YQTimezoneSelector.h?rev=43208&r1=43207&r2=43208&view=diff ============================================================================== --- trunk/qt/src/YQTimezoneSelector.h (original) +++ trunk/qt/src/YQTimezoneSelector.h Thu Dec 20 20:22:42 2007 @@ -77,7 +77,7 @@ /** * subclasses have to implement this to set value */ - virtual void setCurrentZone( const std::string &zone ); + virtual void setCurrentZone( const std::string &zone, bool zoom ); protected: YQTimezoneSelectorPrivate *d; -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org