Author: coolo
Date: Mon Dec 17 20:49:56 2007
New Revision: 43149
URL: http://svn.opensuse.org/viewcvs/yast?rev=43149&view=rev
Log:
extending the example - I'm getting better in ycp :)
BUT: it's horribly slow and I wonder if it's my fault
Modified:
branches/tmp/coolo/zone/core/libyui/doc/examples/TimezoneSelector.ycp
branches/tmp/coolo/zone/core/libyui/src/YTimezoneSelector.cc
branches/tmp/coolo/zone/core/libyui/src/YTimezoneSelector.h
branches/tmp/coolo/zone/qt/src/YQTimezoneSelector.cc
branches/tmp/coolo/zone/qt/src/YQTimezoneSelector.h
Modified: branches/tmp/coolo/zone/core/libyui/doc/examples/TimezoneSelector.ycp
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/coolo/zone/core/libyui/doc/examples/TimezoneSelector.ycp?rev=43149&r1=43148&r2=43149&view=diff
==============================================================================
--- branches/tmp/coolo/zone/core/libyui/doc/examples/TimezoneSelector.ycp (original)
+++ branches/tmp/coolo/zone/core/libyui/doc/examples/TimezoneSelector.ycp Mon Dec 17 20:49:56 2007
@@ -8,11 +8,18 @@
if ( UI::HasSpecialWidget(`TimezoneSelector) )
{
// Only create a dialog with this kind of widget if it is supported
-
UI::OpenDialog(
`VBox(
- `TimezoneSelector("/home/col/prod/yast2/core/libyui/doc/examples/caida_1280.jpg"),
- `PushButton(`opt(`default), "&OK")
+ `TimezoneSelector(`id(`timezone), `opt(`notify), "/home/col/prod/yast2/core/libyui/doc/examples/caida_1280.jpg"),
+ `PushButton(`id(`ok), `opt(`default), "&Close"),
+ `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" )
+ ] )
)
);
}
@@ -20,7 +27,6 @@
{
// Always provide a fallback: Either try to create a simpler dialog
// without the special widget, or terminate with an error message.
-
UI::OpenDialog(
`VBox(
`Label("Timezone Selector not supported!"),
@@ -29,6 +35,29 @@
);
}
- UI::UserInput();
+ while( true )
+ {
+ symbol button = (symbol)UI::UserInput();
+ if ( button == `ok || button == `cancel )
+ break;
+
+ if ( button == `combozone )
+ {
+ any zone=UI::QueryWidget(`id(`combozone), `Value);
+ if (zone == `london)
+ UI::ChangeWidget(`id(`timezone), `Value, "Europe/London" );
+ if (zone == `prag)
+ UI::ChangeWidget(`id(`timezone), `Value, "Europe/Prague" );
+ if (zone == `ny)
+ UI::ChangeWidget(`id(`timezone), `Value, "America/New_York" );
+ }
+
+ if ( button == `timezone )
+ {
+ string zone=(string)UI::QueryWidget(`id(`timezone), `Value);
+ UI::ChangeWidget(`id(`combozone), `Value, zone);
+ }
+ }
+
UI::CloseDialog();
}
Modified: branches/tmp/coolo/zone/core/libyui/src/YTimezoneSelector.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/coolo/zone/core/libyui/src/YTimezoneSelector.cc?rev=43149&r1=43148&r2=43149&view=diff
==============================================================================
--- branches/tmp/coolo/zone/core/libyui/src/YTimezoneSelector.cc (original)
+++ branches/tmp/coolo/zone/core/libyui/src/YTimezoneSelector.cc Mon Dec 17 20:49:56 2007
@@ -45,6 +45,7 @@
if ( propSet.isEmpty() )
{
+ propSet.add( YProperty( YUIProperty_Value, YStringProperty ) );
propSet.add( YWidget::propertySet() );
}
@@ -57,13 +58,15 @@
{
propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
- if ( propertyName == YUIProperty_Values ) return false; // need special processing
+ if ( propertyName == YUIProperty_Value )
+ {
+ setCurrentZone( val.stringVal() );
+ return true; // success -- no special handling necessary
+ }
else
{
- YWidget::setProperty( propertyName, val );
+ return YWidget::setProperty( propertyName, val );
}
-
- return true; // success -- no special handling necessary
}
@@ -72,7 +75,7 @@
{
propertySet().check( propertyName ); // throws exceptions if not found
- if ( propertyName == YUIProperty_Values ) return YPropertyValue( YOtherProperty );
+ if ( propertyName == YUIProperty_Value ) return YPropertyValue( currentZone() );
else
{
return YWidget::getProperty( propertyName );
Modified: branches/tmp/coolo/zone/core/libyui/src/YTimezoneSelector.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/coolo/zone/core/libyui/src/YTimezoneSelector.h?rev=43149&r1=43148&r2=43149&view=diff
==============================================================================
--- branches/tmp/coolo/zone/core/libyui/src/YTimezoneSelector.h (original)
+++ branches/tmp/coolo/zone/core/libyui/src/YTimezoneSelector.h Mon Dec 17 20:49:56 2007
@@ -71,6 +71,16 @@
**/
virtual const YPropertySet & propertySet();
+ /**
+ * subclasses have to implement this to return value
+ */
+ virtual std::string currentZone() const = 0;
+
+ /**
+ * subclasses have to implement this to set value
+ */
+ virtual void setCurrentZone( const std::string &zone ) = 0;
+
};
Modified: branches/tmp/coolo/zone/qt/src/YQTimezoneSelector.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/coolo/zone/qt/src/YQTimezoneSelector.cc?rev=43149&r1=43148&r2=43149&view=diff
==============================================================================
--- branches/tmp/coolo/zone/qt/src/YQTimezoneSelector.cc (original)
+++ branches/tmp/coolo/zone/qt/src/YQTimezoneSelector.cc Mon Dec 17 20:49:56 2007
@@ -27,6 +27,7 @@
#include "YQUI.h"
#include "YQTimezoneSelector.h"
#include "YQWidgetCaption.h"
+#include "YEvent.h"
#include <QVBoxLayout>
#include <QPainter>
#include <QMouseEvent>
@@ -44,14 +45,10 @@
float t1 = whole.toFloat();
float t2 = fraction.toFloat();
- if (t1 >= 0.0) {
- //qDebug() << pos << t1 << t2 << t1 + t2/pow (10.0, fraction.length() );
+ if (t1 >= 0.0)
return t1 + t2/pow (10.0, fraction.length() );
- }
- else {
- //qDebug() << pos << t1 << t2 << t1 - t2/pow (10.0, fraction.length());
+ else
return t1 - t2/pow (10.0, fraction.length());
- }
}
bool YQTimezoneSelector::Location::operator<(const Location& l1 ) const
@@ -91,8 +88,7 @@
loc.latitude = convert_pos ( arr[1].left( split_index ), 2);
loc.longitude = convert_pos ( arr[1].mid( split_index ), 3);
- loc.x = _pix.width() / 2 + _pix.width() / 2 * loc.longitude / 180;
- loc.y = _pix.height() / 2 - _pix.height() / 2 * loc.latitude / 90;
+ loc.pix_pos = pixPosition( loc );
locations.push_back( loc );
}
@@ -103,13 +99,14 @@
QPainter p( &_pix );
for ( QList<Location>::const_iterator it = locations.begin(); it != locations.end(); ++it )
- {
- p.drawRect( ( *it ).x - 1, ( *it ).y - 1, 3, 3 );
- qDebug() << "loc" << ( *it ).latitude << ( *it ).longitude << ( *it ).zone << ( *it ).x;
- }
+ p.drawRect( ( *it ).pix_pos.x() - 1, ( *it ).pix_pos.y() - 1, 3, 3 );
-}
+ blink = new QTimer( this );
+ blink->setInterval( 200 );
+ connect( blink, SIGNAL( timeout() ), SLOT( slotBlink() ) );
+ highlight = false;
+}
YQTimezoneSelector::~YQTimezoneSelector()
{
@@ -134,16 +131,35 @@
resize( newWidth, newHeight );
}
+QPoint YQTimezoneSelector::pixPosition( const Location &pos ) const
+{
+ return QPoint( _pix.width() / 2 + _pix.width() / 2 * pos.longitude / 180,
+ _pix.height() / 2 - _pix.height() / 2 * pos.latitude / 90 );
+}
+
void YQTimezoneSelector::mousePressEvent ( QMouseEvent * event )
{
if ( event->button() == Qt::RightButton )
+ {
_zoom = QPoint();
- else if ( event->button() == Qt::LeftButton && _zoom.isNull() )
+ _best = Location();
+ }
+ else if ( event->button() == Qt::LeftButton )
{
- QPoint click = event->pos();
- /* keep the zoom point in unscaled math */
- _zoom.rx() = double( click.x() ) * _pix.width() / width();
- _zoom.ry() = double( click.y() ) * _pix.height() / height();
+ if ( _zoom.isNull() )
+ {
+ QPoint click = event->pos();
+ /* keep the zoom point in unscaled math */
+ _zoom.rx() = double( click.x() ) * _pix.width() / width();
+ _zoom.ry() = double( click.y() ) * _pix.height() / height();
+ } else {
+ _best = findBest( event->pos() );
+
+ if ( notify() )
+ YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
+
+ blink->start();
+ }
} else
return;
@@ -165,34 +181,87 @@
int top = qMin( qMax( _zoom.y() - height() / 2, 0 ), _pix.height() - height() );
p.drawPixmap( QPoint( 0, 0 ), _pix, QRect( QPoint( left, top ), size() ) );
+ if ( highlight )
+ {
+ QPoint pos = pixPosition( _best );
+ p.setPen( Qt::red );
+ p.drawRect( pos.x() - left - 1, pos.y() - top - 1, 3, 3 );
+ }
setCursor( Qt::CrossCursor );
}
}
+YQTimezoneSelector::Location YQTimezoneSelector::findBest( const QPoint &pos ) const
+{
+ int left = qMin( qMax( _zoom.x() - width() / 2, 0 ), _pix.width() - width() );
+ int top = qMin( qMax( _zoom.y() - height() / 2, 0 ), _pix.height() - height() );
+
+ double min_dist = 2000;
+ Location best;
+ for ( QList<Location>::const_iterator it = locations.begin(); it != locations.end(); ++it )
+ {
+ double dist = QPoint( QPoint( ( *it ).pix_pos.x() - left,
+ ( *it ).pix_pos.y() - top ) - pos ).manhattanLength ();
+ if ( dist < min_dist )
+ {
+ min_dist = dist;
+ best = *it;
+ }
+ }
+ return best;
+}
+
bool YQTimezoneSelector::event(QEvent *event)
{
if (event->type() == QEvent::ToolTip)
{
QHelpEvent *helpEvent = static_cast