Author: coolo
Date: Mon Dec 17 10:00:07 2007
New Revision: 43112
URL: http://svn.opensuse.org/viewcvs/yast?rev=43112&view=rev
Log:
backup for my sunday evening hack
Added:
branches/tmp/coolo/zone/core/libyui/doc/examples/TimezoneSelector.ycp
branches/tmp/coolo/zone/core/libyui/doc/examples/caida_1280.jpg (with props)
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/src/Makefile.am
branches/tmp/coolo/zone/core/libyui/src/YCPDialogParser.cc
branches/tmp/coolo/zone/core/libyui/src/YCPDialogParser.h
branches/tmp/coolo/zone/core/libyui/src/YOptionalWidgetFactory.cc
branches/tmp/coolo/zone/core/libyui/src/YOptionalWidgetFactory.h
branches/tmp/coolo/zone/core/libyui/src/YUISymbols.h
branches/tmp/coolo/zone/core/libyui/src/YUI_builtins.cc
branches/tmp/coolo/zone/qt/src/CMakeLists.txt
branches/tmp/coolo/zone/qt/src/YQOptionalWidgetFactory.cc
branches/tmp/coolo/zone/qt/src/YQOptionalWidgetFactory.h
Added: 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=43112&view=auto
==============================================================================
--- branches/tmp/coolo/zone/core/libyui/doc/examples/TimezoneSelector.ycp (added)
+++ branches/tmp/coolo/zone/core/libyui/doc/examples/TimezoneSelector.ycp Mon Dec 17 10:00:07 2007
@@ -0,0 +1,34 @@
+{
+ // Build a dialog with a "special" widget - one that may not be supported
+ // by all UIs.
+
+
+ // 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(
+ `TimezoneSelector("/home/col/prod/yast2/core/libyui/doc/examples/caida_1280.jpg"),
+ `PushButton(`opt(`default), "&OK")
+ )
+ );
+ }
+ 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(
+ `Label("Timezone Selector not supported!"),
+ `PushButton(`opt(`default), "&Oops!")
+ )
+ );
+ }
+
+ UI::UserInput();
+ UI::CloseDialog();
+}
Added: branches/tmp/coolo/zone/core/libyui/doc/examples/caida_1280.jpg
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/coolo/zone/core/libyui/doc/examples/caida_1280.jpg?rev=43112&view=auto
==============================================================================
Binary file - no diff available.
Modified: branches/tmp/coolo/zone/core/libyui/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/coolo/zone/core/libyui/src/Makefile.am?rev=43112&r1=43111&r2=43112&view=diff
==============================================================================
--- branches/tmp/coolo/zone/core/libyui/src/Makefile.am (original)
+++ branches/tmp/coolo/zone/core/libyui/src/Makefile.am Mon Dec 17 10:00:07 2007
@@ -89,6 +89,7 @@
YTimeField.cc \
YTree.cc \
YWizard.cc \
+ YTimezoneSelector.cc \
\
YRpmGroupsTree.cc \
YStringTree.cc \
@@ -187,6 +188,7 @@
YSquash.h \
YTable.h \
YTimeField.h \
+ YTimezoneSelector.h \
YTree.h \
YWizard.h \
\
Modified: branches/tmp/coolo/zone/core/libyui/src/YCPDialogParser.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/coolo/zone/core/libyui/src/YCPDialogParser.cc?rev=43112&r1=43111&r2=43112&view=diff
==============================================================================
--- branches/tmp/coolo/zone/core/libyui/src/YCPDialogParser.cc (original)
+++ branches/tmp/coolo/zone/core/libyui/src/YCPDialogParser.cc Mon Dec 17 10:00:07 2007
@@ -79,6 +79,7 @@
#include "YTimeField.h"
#include "YTree.h"
#include "YWizard.h"
+#include "YTimezoneSelector.h"
using std::string;
@@ -280,6 +281,7 @@
else if ( s == YUISpecialWidget_Time ) w = parseTimeField ( p, opt, term, ol, n );
else if ( s == YUISpecialWidget_TimeField ) w = parseTimeField ( p, opt, term, ol, n );
else if ( s == YUISpecialWidget_Wizard ) w = parseWizard ( p, opt, term, ol, n );
+ else if ( s == YUISpecialWidget_TimezoneSelector ) w = parseTimezoneSelector ( p, opt, term, ol, n );
else
{
YUI_THROW( YUIException( string( "Unknown widget type " ) + s.c_str() ) );
@@ -3259,6 +3261,41 @@
return wizard;
}
+/**
+ * @widgets TimezoneSelector
+ * @short Timezone selector map
+ * @class YTimezoneSelector
+ * @arg string map
+ * @usage if ( HasSpecialWidget( `TimezoneSelector ) {...
+ * `TimezoneSelector( "world.jpg" )
+ *
+ * @description
+ * An graphical timezone selector map
+ *
+ * @note This is a "special" widget, i.e. not all UIs necessarily support it. Check
+ * for availability with <tt>HasSpecialWidget( `TimezoneSelector)</tt> before using it.
+ **/
+YWidget *
+YCPDialogParser::parseTimezoneSelector( YWidget * parent, YWidgetOpt & opt,
+ const YCPTerm & term, const YCPList & optList, int argnr )
+{
+
+ if ( term->size() - argnr < 1 || term->size() - argnr > 1
+ || !term->value(argnr)->isString() )
+ {
+ y2error( "Invalid arguments for the TimezoneSelector widget: %s",
+ term->toString().c_str() );
+ return 0;
+ }
+
+ rejectAllOptions( term, optList );
+
+ string map = term->value( argnr )->asString()->value();
+
+ YTimezoneSelector * selector = YUI::optionalWidgetFactory()->createTimezoneSelector( parent, map );
+
+ return selector;
+}
Modified: branches/tmp/coolo/zone/core/libyui/src/YCPDialogParser.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/coolo/zone/core/libyui/src/YCPDialogParser.h?rev=43112&r1=43111&r2=43112&view=diff
==============================================================================
--- branches/tmp/coolo/zone/core/libyui/src/YCPDialogParser.h (original)
+++ branches/tmp/coolo/zone/core/libyui/src/YCPDialogParser.h Mon Dec 17 10:00:07 2007
@@ -265,6 +265,9 @@
static YWidget * parseSimplePatchSelector( YWidget *parent, YWidgetOpt & opt, const YCPTerm & term,
const YCPList & optList, int argnr );
+ static YWidget * parseTimezoneSelector ( YWidget *parent, YWidgetOpt & opt, const YCPTerm & term,
+ const YCPList & optList, int argnr );
+
/**
* Look for a widget id in a widget term. If it finds one, returns
* it and sets argnr to 1, otherwise it creates a new unique widget
Modified: branches/tmp/coolo/zone/core/libyui/src/YOptionalWidgetFactory.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/coolo/zone/core/libyui/src/YOptionalWidgetFactory.cc?rev=43112&r1=43111&r2=43112&view=diff
==============================================================================
--- branches/tmp/coolo/zone/core/libyui/src/YOptionalWidgetFactory.cc (original)
+++ branches/tmp/coolo/zone/core/libyui/src/YOptionalWidgetFactory.cc Mon Dec 17 10:00:07 2007
@@ -228,3 +228,14 @@
return YUI::widgetFactory()->createOutputField( parent, "YDummySpecialWidget" );
}
+bool YOptionalWidgetFactory::hasTimezoneSelector()
+{
+ return false;
+}
+
+YTimezoneSelector *
+YOptionalWidgetFactory::createTimezoneSelector( YWidget * parent,
+ const string & map )
+{
+ THROW_UNSUPPORTED( "YTimezoneSelector" );
+}
Modified: branches/tmp/coolo/zone/core/libyui/src/YOptionalWidgetFactory.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/coolo/zone/core/libyui/src/YOptionalWidgetFactory.h?rev=43112&r1=43111&r2=43112&view=diff
==============================================================================
--- branches/tmp/coolo/zone/core/libyui/src/YOptionalWidgetFactory.h (original)
+++ branches/tmp/coolo/zone/core/libyui/src/YOptionalWidgetFactory.h Mon Dec 17 10:00:07 2007
@@ -38,7 +38,7 @@
class YSlider;
class YTimeField;
class YWidget;
-
+class YTimezoneSelector;
/**
* Abstract widget factory for optional ("special") widgets.
@@ -115,7 +115,9 @@
bool hasDummySpecialWidget();
YWidget * createDummySpecialWidget( YWidget * parent );
-
+ virtual bool hasTimezoneSelector();
+ virtual YTimezoneSelector * createTimezoneSelector( YWidget * parent,
+ const string & map );
protected:
Added: 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=43112&view=auto
==============================================================================
--- branches/tmp/coolo/zone/core/libyui/src/YTimezoneSelector.cc (added)
+++ branches/tmp/coolo/zone/core/libyui/src/YTimezoneSelector.cc Mon Dec 17 10:00:07 2007
@@ -0,0 +1,81 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YMultiProgressMeter.cc
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+
+#define y2log_component "ui"
+#include
+
+#include "YUISymbols.h"
+#include "YTimezoneSelector.h"
+
+
+
+YTimezoneSelector::YTimezoneSelector( YWidget * parent,
+ const string &label )
+ : YWidget( parent )
+{
+}
+
+
+YTimezoneSelector::~YTimezoneSelector()
+{
+ // NOP
+}
+
+
+const YPropertySet &
+YTimezoneSelector::propertySet()
+{
+ static YPropertySet propSet;
+
+ if ( propSet.isEmpty() )
+ {
+ propSet.add( YWidget::propertySet() );
+ }
+
+ return propSet;
+}
+
+
+bool
+YTimezoneSelector::setProperty( const string & propertyName, const YPropertyValue & val )
+{
+ propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
+
+ if ( propertyName == YUIProperty_Values ) return false; // need special processing
+ else
+ {
+ YWidget::setProperty( propertyName, val );
+ }
+
+ return true; // success -- no special handling necessary
+}
+
+
+YPropertyValue
+YTimezoneSelector::getProperty( const string & propertyName )
+{
+ propertySet().check( propertyName ); // throws exceptions if not found
+
+ if ( propertyName == YUIProperty_Values ) return YPropertyValue( YOtherProperty );
+ else
+ {
+ return YWidget::getProperty( propertyName );
+ }
+}
+
Added: 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=43112&view=auto
==============================================================================
--- branches/tmp/coolo/zone/core/libyui/src/YTimezoneSelector.h (added)
+++ branches/tmp/coolo/zone/core/libyui/src/YTimezoneSelector.h Mon Dec 17 10:00:07 2007
@@ -0,0 +1,77 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YTimezoneSelector.h
+
+ Author: Stephan Kulow
+
+/-*/
+
+#ifndef YTimezoneSelector_h
+#define YTimezoneSelector_h
+
+#include "YWidget.h"
+
+class YTimezoneSelector : public YWidget
+{
+protected:
+ /**
+ * Constructor
+ **/
+ YTimezoneSelector( YWidget * parent,
+ const string &map );
+
+public:
+ /**
+ * Destructor.
+ **/
+ virtual ~YTimezoneSelector();
+
+ /**
+ * Return a descriptive name of this widget class for logging,
+ * debugging etc.
+ **/
+ virtual const char * widgetClass() const { return "YTimezoneSelector"; }
+
+ /**
+ * Set a property.
+ * Reimplemented from YWidget.
+ *
+ * This function may throw YUIPropertyExceptions.
+ *
+ * This function returns 'true' if the value was successfully set and
+ * 'false' if that value requires special handling (not in error cases:
+ * those are covered by exceptions).
+ **/
+ virtual bool setProperty( const string & propertyName,
+ const YPropertyValue & val );
+
+ /**
+ * Get a property.
+ * Reimplemented from YWidget.
+ *
+ * This method may throw YUIPropertyExceptions.
+ **/
+ virtual YPropertyValue getProperty( const string & propertyName );
+
+ /**
+ * Return this class's property set.
+ * This also initializes the property upon the first call.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual const YPropertySet & propertySet();
+
+};
+
+
+#endif // YMultiProgressMeter_h
Modified: branches/tmp/coolo/zone/core/libyui/src/YUISymbols.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/coolo/zone/core/libyui/src/YUISymbols.h?rev=43112&r1=43111&r2=43112&view=diff
==============================================================================
--- branches/tmp/coolo/zone/core/libyui/src/YUISymbols.h (original)
+++ branches/tmp/coolo/zone/core/libyui/src/YUISymbols.h Mon Dec 17 10:00:07 2007
@@ -143,6 +143,7 @@
#define YUISpecialWidget_Time "Time"
#define YUISpecialWidget_TimeField "TimeField"
#define YUISpecialWidget_Wizard "Wizard"
+#define YUISpecialWidget_TimezoneSelector "TimezoneSelector"
// Widget properties
Modified: branches/tmp/coolo/zone/core/libyui/src/YUI_builtins.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/coolo/zone/core/libyui/src/YUI_builtins.cc?rev=43112&r1=43111&r2=43112&view=diff
==============================================================================
--- branches/tmp/coolo/zone/core/libyui/src/YUI_builtins.cc (original)
+++ branches/tmp/coolo/zone/core/libyui/src/YUI_builtins.cc Mon Dec 17 10:00:07 2007
@@ -98,6 +98,7 @@
else if ( symbol == YUISpecialWidget_Wizard ) hasWidget = fact->hasWizard();
else if ( symbol == YUISpecialWidget_Date ) hasWidget = fact->hasDateField();
else if ( symbol == YUISpecialWidget_Time ) hasWidget = fact->hasTimeField();
+ else if ( symbol == YUISpecialWidget_TimezoneSelector ) hasWidget = fact->hasTimezoneSelector();
else
{
y2error( "HasSpecialWidget(): Unknown special widget: %s", symbol.c_str() );
@@ -416,7 +417,7 @@
#if VERBOSE_EVENTS
y2debug( "UI::UserInput()" );
#endif
-
+
return doUserInput( YUIBuiltin_UserInput,
0, // timeout_millisec
true, // wait
@@ -444,7 +445,7 @@
#if VERBOSE_EVENTS
y2debug( "UI::PollInput()" );
#endif
-
+
return doUserInput( YUIBuiltin_PollInput,
0, // timeout_millisec
false, // wait
@@ -470,7 +471,7 @@
YCPValue YUI::evaluateTimeoutUserInput( const YCPInteger & timeout )
{
long timeout_millisec = timeout->value();
-
+
#if VERBOSE_EVENTS
y2debug( "UI::TimeoutUserInput( %d )", timeout_millisec );
#endif
@@ -495,12 +496,12 @@
YCPValue YUI::evaluateWaitForEvent( const YCPInteger & timeout )
{
long timeout_millisec = 0;
-
+
if ( ! timeout.isNull() )
{
timeout_millisec = timeout->value();
}
-
+
#if VERBOSE_EVENTS
y2debug( "UI::WaitForEvent( %d )", timeout_millisec );
#endif
@@ -579,7 +580,7 @@
if ( event )
{
-
+
if ( detailed )
input = event->ycpEvent(); // The event map
else
@@ -671,14 +672,14 @@
y2debug( "Expected: %p (widgetRep %p), received: %p (widgetRep %p)",
YDialog::currentDialog(),
YDialog::currentDialog()->widgetRep(),
- widgetEvent->widget()->findDialog(),
+ widgetEvent->widget()->findDialog(),
widgetEvent->widget()->findDialog()->widgetRep() );
y2debug( "Event widget: " );
widgetEvent->widget()->findDialog()->dumpWidgetTree();
y2debug( "Current dialog:" );
YDialog::currentDialog()->dumpWidgetTree();
#endif
-
+
delete widgetEvent;
return 0;
}
@@ -711,10 +712,10 @@
* distinct from the normal colors, but not as bright as warncolor.
*
* The <tt>`decorated</tt> option is now obsolete, but still accepted to keep
- * old code working.
+ * old code working.
*
* The <tt>`centered</tt> option is now obsolete, but still accepted to keep
- * old code working.
+ * old code working.
*
* @param term options
* @param term widget
@@ -727,7 +728,7 @@
{
YDialogType dialogType = YPopupDialog;
YDialogColorMode colorMode = YDialogNormalColor;
-
+
if ( ! opts.isNull() ) // evaluate `opt() contents
{
YCPList optList = opts->args();
@@ -751,7 +752,7 @@
blockEvents(); // Prevent self-generated events from UI built-ins.
bool ok = true;
-
+
try
{
YDialog * dialog = YUI::widgetFactory()->createDialog( dialogType, colorMode );
@@ -776,7 +777,7 @@
}
unblockEvents();
-
+
return YCPBoolean( ok );
}
@@ -838,11 +839,11 @@
YCPValue YUI::evaluateChangeWidget( const YCPValue & idValue, const YCPValue & property, const YCPValue & newValue )
{
YCPValue ret = YCPVoid();
-
+
try
{
blockEvents(); // We don't want self-generated events from UI::ChangeWidget().
-
+
if ( ! YCPDialogParser::isSymbolOrId( idValue ) )
{
YUI_THROW( YUISyntaxErrorException( string( "Expected `id(...) or `symbol, not " ) +
@@ -929,7 +930,7 @@
YCPValue YUI::evaluateQueryWidget( const YCPValue & idValue, const YCPValue & property )
{
YCPValue ret = YCPVoid();
-
+
try
{
if ( ! YCPDialogParser::isSymbolOrId( idValue ) )
@@ -1001,7 +1002,7 @@
YCPBoolean YUI::evaluateReplaceWidget( const YCPValue & idValue, const YCPTerm & newContentTerm )
{
bool success = true;
-
+
try
{
if ( ! YCPDialogParser::isSymbolOrId( idValue ) )
@@ -1043,11 +1044,11 @@
{
YUI_CAUGHT( exception );
success = false;
-
+
ycperror( "UI::ReplaceWidget() failed: UI::ReplaceWidget( %s, %s )",
idValue->toString().c_str(),
newContentTerm->toString().c_str() );
-
+
}
unblockEvents();
@@ -1062,7 +1063,7 @@
* @short Runs a wizard command
* @description
* Issues a command to a wizard widget with ID 'wizardId'.
- *
+ *
* <b>This builtin is not for general use. Use the Wizard.ycp module instead.</b>
*
* For available wizard commands see file YWizard.cc .
@@ -1684,7 +1685,7 @@
YUI::evaluateAskForExistingDirectory( const YCPString & startDir, const YCPString & headline )
{
string ret = app()->askForExistingDirectory( startDir->value(), headline->value() );
-
+
if ( ret.empty() )
return YCPVoid();
else
@@ -1709,7 +1710,7 @@
YCPValue YUI::evaluateAskForExistingFile( const YCPString & startWith, const YCPString & filter, const YCPString & headline )
{
string ret = app()->askForExistingFile( startWith->value(), filter->value(), headline->value() );
-
+
if ( ret.empty() )
return YCPVoid();
else
@@ -1734,7 +1735,7 @@
YCPValue YUI::evaluateAskForSaveFileName( const YCPString & startWith, const YCPString & filter, const YCPString & headline )
{
string ret = app()->askForSaveFileName( startWith->value(), filter->value(), headline->value() );
-
+
if ( ret.empty() )
return YCPVoid();
else
Modified: branches/tmp/coolo/zone/qt/src/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/coolo/zone/qt/src/CMakeLists.txt?rev=43112&r1=43111&r2=43112&view=diff
==============================================================================
--- branches/tmp/coolo/zone/qt/src/CMakeLists.txt (original)
+++ branches/tmp/coolo/zone/qt/src/CMakeLists.txt Mon Dec 17 10:00:07 2007
@@ -27,7 +27,7 @@
YQSpacing.cc YQSquash.cc YQTable.cc YQTimeField.cc YQTree.cc
YQUI_builtins.cc YQUI_core.cc YQUI_widgets.cc YQUI_x11.cc
YQWidgetCaption.cc YQWidgetFactory.cc YQWizardButton.cc
- YQWizard.cc QY2Styler.cc
+ YQWizard.cc QY2Styler.cc YQTimezoneSelector.cc
)
QT4_AUTOMOC(${qt_yast_plugin_SRCS})
Modified: branches/tmp/coolo/zone/qt/src/YQOptionalWidgetFactory.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/coolo/zone/qt/src/YQOptionalWidgetFactory.cc?rev=43112&r1=43111&r2=43112&view=diff
==============================================================================
--- branches/tmp/coolo/zone/qt/src/YQOptionalWidgetFactory.cc (original)
+++ branches/tmp/coolo/zone/qt/src/YQOptionalWidgetFactory.cc Mon Dec 17 10:00:07 2007
@@ -21,6 +21,7 @@
#include "YUIException.h"
#include "YQPackageSelectorPlugin.h"
#include "YQWizard.h"
+#include "YQTimezoneSelector.h"
#define THROW_UNSUPPORTED( WIDGET_TYPE ) \
YUI_THROW( YUIUnsupportedWidgetException( WIDGET_TYPE ) ); \
@@ -257,3 +258,16 @@
return downloadProgress;
}
+bool YQOptionalWidgetFactory::hasTimezoneSelector()
+{
+ return true;
+}
+
+YTimezoneSelector *
+YQOptionalWidgetFactory::createTimezoneSelector( YWidget * parent,
+ const string & map )
+{
+ return new YQTimezoneSelector( parent, map );
+}
+
+
Modified: branches/tmp/coolo/zone/qt/src/YQOptionalWidgetFactory.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/coolo/zone/qt/src/YQOptionalWidgetFactory.h?rev=43112&r1=43111&r2=43112&view=diff
==============================================================================
--- branches/tmp/coolo/zone/qt/src/YQOptionalWidgetFactory.h (original)
+++ branches/tmp/coolo/zone/qt/src/YQOptionalWidgetFactory.h Mon Dec 17 10:00:07 2007
@@ -110,6 +110,10 @@
const string & filename,
YFileSize_t expectedFileSize );
+ virtual bool hasTimezoneSelector();
+ virtual YTimezoneSelector * createTimezoneSelector( YWidget * parent,
+ const string & map );
+
protected:
friend class YQUI;
Added: branches/tmp/coolo/zone/qt/src/YQTimezoneSelector.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/coolo/zone/qt/src/YQTimezoneSelector.cc?rev=43112&view=auto
==============================================================================
--- branches/tmp/coolo/zone/qt/src/YQTimezoneSelector.cc (added)
+++ branches/tmp/coolo/zone/qt/src/YQTimezoneSelector.cc Mon Dec 17 10:00:07 2007
@@ -0,0 +1,198 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YQTimezoneSelector.cc
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+
+#define y2log_component "qt-ui"
+#include
+#include
+
+#include
+
+#include "utf8.h"
+#include "YQUI.h"
+#include "YQTimezoneSelector.h"
+#include "YQWidgetCaption.h"
+#include <QVBoxLayout>
+#include <QPainter>
+#include <QMouseEvent>
+#include <QDebug>
+#include <QToolTip>
+
+static float
+convert_pos (const QString &pos, int digits)
+{
+ if (pos.length() < 4 || digits > 9) return 0.0;
+
+ QString whole = pos.left( digits + 1 );
+ QString fraction = pos.mid( digits + 1 );
+
+ float t1 = whole.toFloat();
+ float t2 = fraction.toFloat();
+
+ if (t1 >= 0.0) {
+ //qDebug() << pos << t1 << t2 << t1 + t2/pow (10.0, fraction.length() );
+ return t1 + t2/pow (10.0, fraction.length() );
+ }
+ else {
+ //qDebug() << pos << t1 << t2 << t1 - t2/pow (10.0, fraction.length());
+ return t1 - t2/pow (10.0, fraction.length());
+ }
+}
+
+bool YQTimezoneSelector::Location::operator<(const Location& l1 ) const
+{
+ return l1.latitude < latitude;
+}
+
+YQTimezoneSelector::YQTimezoneSelector( YWidget * parent, const string & map )
+ : QFrame( (QWidget *) parent->widgetRep() )
+ , YTimezoneSelector( parent, map )
+{
+ setWidgetRep( this );
+ setMouseTracking(true);
+ _pix.load( QString::fromStdString( map ) );
+
+ setStretchable( YD_HORIZ, true );
+ setStretchable( YD_VERT, true );
+
+ char buf[4096];
+ FILE *tzfile = fopen ("/usr/share/zoneinfo/zone.tab", "r");
+ while (fgets (buf, sizeof(buf), tzfile))
+ {
+ if (*buf == '#') continue;
+
+ QString sbuf = buf;
+ QStringList arr = sbuf.trimmed().split( '\t' );
+
+ int split_index = 1;
+ while ( split_index < arr[1].length() && arr[1][split_index] != '-' && arr[1][split_index] != '+' )
+ split_index++;
+
+ Location loc;
+ loc.country = arr[0];
+ loc.zone = arr[2];
+ if ( arr.size() > 3 )
+ loc.comment = arr[3];
+ 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;
+
+ locations.push_back( loc );
+ }
+
+ fclose (tzfile);
+
+ qSort( locations.begin(), locations.end() );
+
+ 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;
+ }
+
+}
+
+
+YQTimezoneSelector::~YQTimezoneSelector()
+{
+ // NOP
+}
+
+
+int YQTimezoneSelector::preferredWidth()
+{
+ return _pix.width() / 2;
+}
+
+
+int YQTimezoneSelector::preferredHeight()
+{
+ return _pix.height() / 2;
+}
+
+
+void YQTimezoneSelector::setSize( int newWidth, int newHeight )
+{
+ resize( newWidth, newHeight );
+}
+
+void YQTimezoneSelector::mousePressEvent ( QMouseEvent * event )
+{
+ if ( event->button() == Qt::RightButton )
+ _zoom = QPoint();
+ else if ( event->button() == Qt::LeftButton && _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
+ return;
+
+ update();
+}
+
+void YQTimezoneSelector::paintEvent( QPaintEvent *event )
+{
+ QFrame::paintEvent( event );
+ QPainter p( this );
+ if ( _zoom.isNull() )
+ {
+ QImage t = _pix.toImage().scaled( width(), height() );
+ p.drawPixmap( 0, 0, QPixmap::fromImage( t ) );
+
+ setCursor( QCursor( QPixmap( "/home/col/prod/ubiquity/pixmaps/zoom-in.png" ) ) );
+ } else {
+ int left = qMin( qMax( _zoom.x() - width() / 2, 0 ), _pix.width() - width() );
+ int top = qMin( qMax( _zoom.y() - height() / 2, 0 ), _pix.height() - height() );
+ p.drawPixmap( QPoint( 0, 0 ), _pix, QRect( QPoint( left, top ), size() ) );
+
+ setCursor( Qt::CrossCursor );
+ }
+}
+
+bool YQTimezoneSelector::event(QEvent *event)
+{
+ if (event->type() == QEvent::ToolTip)
+ {
+ QHelpEvent *helpEvent = static_cast(event);
+
+ 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 ).x - left, ( *it ).y - top ) - helpEvent->pos() ).manhattanLength ();
+ if ( dist < min_dist )
+ {
+ min_dist = dist;
+ best = *it;
+ }
+ }
+
+ QToolTip::showText(helpEvent->globalPos(), best.zone );
+ }
+ return QWidget::event(event);
+}
+
+#include "YQTimezoneSelector.moc"
Added: branches/tmp/coolo/zone/qt/src/YQTimezoneSelector.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/coolo/zone/qt/src/YQTimezoneSelector.h?rev=43112&view=auto
==============================================================================
--- branches/tmp/coolo/zone/qt/src/YQTimezoneSelector.h (added)
+++ branches/tmp/coolo/zone/qt/src/YQTimezoneSelector.h Mon Dec 17 10:00:07 2007
@@ -0,0 +1,91 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YQTimezoneSelector.h
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+
+#ifndef YQTimezoneSelector_h
+#define YQTimezoneSelector_h
+
+#include <QFrame>
+#include "YTimezoneSelector.h"
+
+class YQTimezoneSelector : public QFrame, public YTimezoneSelector
+{
+ Q_OBJECT
+
+public:
+ /**
+ * Constructor.
+ **/
+ YQTimezoneSelector( YWidget * parent,
+ const string & label );
+
+ /**
+ * Destructor.
+ **/
+ virtual ~YQTimezoneSelector();
+
+ /**
+ * Preferred width of the widget.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual int preferredWidth();
+
+ /**
+ * Preferred height of the widget.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual int preferredHeight();
+
+ /**
+ * Set the new size of the widget.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual void setSize( int newWidth, int newHeight );
+
+ virtual void paintEvent( QPaintEvent *event );
+
+ virtual void mousePressEvent ( QMouseEvent * event );
+
+ virtual bool event(QEvent *event);
+
+protected:
+ QPixmap _pix;
+ QPoint _zoom;
+
+ struct Location
+ {
+ QString country;
+ double latitude;
+ double longitude;
+ QString zone;
+ QString comment;
+
+ uint x;
+ uint y;
+
+ bool operator<(const Location& l2) const;
+ };
+
+ QList<Location> locations;
+};
+
+
+#endif // YQTimeField_h
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org