src/hbwidgets/popups/hbinputdialog.cpp
changeset 6 c3690ec91ef8
parent 3 11d3954df52a
child 7 923ff622b8b9
equal deleted inserted replaced
5:627c4a0fd0e7 6:c3690ec91ef8
    20 **
    20 **
    21 ** If you have questions regarding the use of this file, please contact
    21 ** If you have questions regarding the use of this file, please contact
    22 ** Nokia at developer.feedback@nokia.com.
    22 ** Nokia at developer.feedback@nokia.com.
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 
    25 #include "hbinputdialog_p.h"
    26 #include <hbinputdialog.h>
    26 #include <hbinputdialog.h>
    27 #include "hbinputdialog_p.h"
       
    28 #include "hbglobal_p.h"
    27 #include "hbglobal_p.h"
    29 #include <hblineedit.h>
    28 #include <hblineedit.h>
    30 #include <hbaction.h>
    29 #include <hbaction.h>
    31 #include "hbinputdialogcontent_p.h"
    30 #include "hbinputdialogcontent_p.h"
    32 #include <hbstyleoptioninputdialog_p.h>
    31 #include <hbstyleoptioninputdialog_p.h>
    56     HbInputDialog *object = new HbInputDialog();
    55     HbInputDialog *object = new HbInputDialog();
    57     \endcode
    56     \endcode
    58 
    57 
    59     The HbDialog::open( QObject* receiver, const char* member ) method  from the HbDialog is used to show the HbInputDialog. 
    58     The HbDialog::open( QObject* receiver, const char* member ) method  from the HbDialog is used to show the HbInputDialog. 
    60 
    59 
    61     The open method can be attached with a SLOT of the format finished(HbAction*). When the open is used with a slot then the slot 
    60     The open method can be attached with a SLOT of the format finished(HbAction*) or finished(int). When the open is used with a slot then the slot 
    62     will be invoked once the user does any action such as accept or reject (The Ok or Cancel press).
    61     will be invoked once the user does any action such as accept or reject (The Ok or Cancel press).
    63 
    62 
    64     
    63     
    65     below is the declaration of the slot.
    64     below is the declaration of the slot.
    66     \code
    65     \code
    67     public slots : 
    66     public slots : 
    68     void dialogClosed(HbAction *action);
    67     void dialogClosed(int);
    69     \endcode
    68     \endcode
    70 
    69 
    71     below code shows how the open method can be called using this slot.
    70     below code shows how the open method can be called using this slot.
    72 
    71     \snipped{ultimatecodesnipped/ultimatecodesnippet.cpp,56}    
    73     \code
    72 
    74     HbInputDialog *object = new HbInputDialog(parent);
    73     A sample slot definition is shown below    
    75     object->open(this,SLOT(dialogClosed(HbAction*)));
    74     \snipped{ultimatecodesnipped/ultimatecodesnippet.cpp,55}    
    76     \endcode
    75 
    77 
    76     In HbInputDialog four static convenience API's are provided: queryText(), queryInteger(), queryDouble(), and queryIp()
    78     A sample slot definition is shown below
       
    79     
       
    80     \code
       
    81     void dialogClosed(HbAction *action)
       
    82     {
       
    83           HbInputDialog *dlg=static_cast<HbInputDialog*>(sender());
       
    84           if(dlg->actions().first() == action) { // user is clicked OK
       
    85               //Get the string enter by user
       
    86                QString myString = dlg->value().toString();
       
    87               //Do the action here
       
    88            }
       
    89            else if(dlg->actions().at(1) == action) {
       
    90               // user is clicked CANCEL
       
    91            }    
       
    92     }
       
    93     \endcode
       
    94 
       
    95 
       
    96     In HbInputDialog four static convenience API's are provided: getText(), getInteger(), getDouble(), and getIp()
       
    97     static API's can be used to quickly get an input from user.
    77     static API's can be used to quickly get an input from user.
    98 
    78 
    99     \enum HbInputDialog::InputMode
    79     \enum HbInputDialog::InputMode
   100 
    80 
   101     \value \b TextInput When this value is set as Input mode, Input Dialog accepts text input in its 
    81     \value \b TextInput When this value is set as Input mode, Input Dialog accepts text input in its 
   397     if (d->mContentWidget->mLabel2 && d->mContentWidget->mAdditionalRowVisible) {
   377     if (d->mContentWidget->mLabel2 && d->mContentWidget->mAdditionalRowVisible) {
   398         style()->updatePrimitive(d->mContentWidget->mLabel2, HbStyle::P_InputDialog_additionaltext, &option);
   378         style()->updatePrimitive(d->mContentWidget->mLabel2, HbStyle::P_InputDialog_additionaltext, &option);
   399     }
   379     }
   400 }
   380 }
   401 
   381 
       
   382 void HbInputDialog::done(int code)
       
   383 {
       
   384     Q_D(HbInputDialog);
       
   385     if(code==Accepted) {
       
   386         QString text;
       
   387         if(d->mContentWidget && d->mContentWidget->mEdit1) {
       
   388             text = d->mContentWidget->mEdit1->text();
       
   389         }
       
   390         switch(d->mPrimaryMode) {
       
   391             case HbInputDialog::TextInput:
       
   392             case HbInputDialog::IpInput: {
       
   393                 emit textValueSelected(text);
       
   394                 break;
       
   395             }        
       
   396             case HbInputDialog::IntInput: {
       
   397                 emit intValueSelected(text.toInt(0,10));       
       
   398                 break;
       
   399             }
       
   400             case HbInputDialog::RealInput: {
       
   401                 emit doubleValueSelected(text.toDouble());       
       
   402                 break;
       
   403             }
       
   404             default:
       
   405                 break;
       
   406         }
       
   407     }
       
   408     HbDialog::done(code);
       
   409 }
       
   410 
   402 /*!
   411 /*!
   403     Returns the echoMode of the user input field.It returns HbLineEdit::EchoMode.
   412     Returns the echoMode of the user input field.It returns HbLineEdit::EchoMode.
   404 
   413 
   405     \param row This parameter indicates which row of the user field.0  means the 
   414     \param row This parameter indicates which row of the user field.0  means the 
   406     the first user input field and 1 means second user input field
   415     the first user input field and 1 means second user input field
   417     }
   426     }
   418     return HbLineEdit::EchoMode(-1);//
   427     return HbLineEdit::EchoMode(-1);//
   419 }
   428 }
   420 
   429 
   421 /*!
   430 /*!
       
   431     \deprecated HbInputDialog::getText(const QString&,QObject*,const char*,const QString&,QGraphicsScene*,QGraphicsItem*)
       
   432         is deprecated.
       
   433     
   422     This is a static convenience function for creating an Input Dialog and to get a string data from the the user. The Application can use this 
   434     This is a static convenience function for creating an Input Dialog and to get a string data from the the user. The Application can use this 
   423     function in order to get any text data from user like username,search data etc. This API allows a slot to be passed as a param. This slot will 
   435     function in order to get any text data from user like username,search data etc. This API allows a slot to be passed as a param. This slot will 
   424     be invoked when the user does the action like OK press or CANCEL press.  
   436     be invoked when the user does the action like OK press or CANCEL press.  
   425     
   437     
   426     HbInputDialog::getText(iTitle,this,SLOT(dialogClosed(HbAction*)),iText);  iTitle is the prompt text.dialogClosed will be invoked when the user does the action.
   438     HbInputDialog::getText(iTitle,this,SLOT(dialogClosed(HbAction*)),iText);  iTitle is the prompt text.dialogClosed will be invoked when the user does the action.
   453     dlg->open(receiver,member);
   465     dlg->open(receiver,member);
   454 }
   466 }
   455 
   467 
   456 
   468 
   457 /*!
   469 /*!
   458     This is a static convenience function for creating an Input Dialog and to get an integer data from the the user. The Application can use this 
   470     \deprecated HbInputDialog::getInteger(const QString&,QObject*,const char*,int,QGraphicsScene*,QGraphicsItem*)
   459     function in order to get any integer data from user like year , any number etc. This API allows a slot to be passed as a param. This slot will 
   471         is deprecated.
   460     be invoked when the user does the action like OK press or CANCEL press.  
   472 
   461     
   473     \sa queryInteger(), queryDouble(), queryIp()
   462     HbInputDialog::getInt(iTitle,this,SLOT(dialogClosed(HbAction*)),iText);  iTitle is the prompt text.dialogClosed will be invoked when the user does the action.
       
   463     Please refer the class documentation to know how to handle the slot.
       
   464    
       
   465     \param label The prompt text which gives information on user input field.
       
   466     \param receiver The instance where the slot is declared.
       
   467     \param member The slot which has dialogClosed(HbAction*) signature. 
       
   468     \param value The default value that should be presented to the user.
       
   469     \param scene The scene parameter.
       
   470     \param parent The parent widget for the dialog.
       
   471    
       
   472     \sa getText(), getDouble(), getIp()
       
   473 */
   474 */
   474 void HbInputDialog::getInteger(const QString &label, 
   475 void HbInputDialog::getInteger(const QString &label, 
   475                                 QObject *receiver,
   476                                 QObject *receiver,
   476                                 const char *member,
   477                                 const char *member,
   477                                 int value,
   478                                 int value,
   487     dlg->setValue(QString::number(value));
   488     dlg->setValue(QString::number(value));
   488     dlg->setAttribute(Qt::WA_DeleteOnClose);
   489     dlg->setAttribute(Qt::WA_DeleteOnClose);
   489     dlg->open(receiver,member);
   490     dlg->open(receiver,member);
   490 }
   491 }
   491 /*!
   492 /*!
   492     This is a static convenience function for creating an Input Dialog and to get a double data from the the user. The Application can use this 
   493     \deprecated HbInputDialog::getDouble(const QString&,QObject*,const char*,double,QGraphicsScene*,QGraphicsItem*)
   493     function in order to get any double data from user. This API allows a slot to be passed as a param. This slot will 
   494         is deprecated.
   494     be invoked when the user does the action like OK press or CANCEL press.  
   495    
   495     
   496     \sa queryInteger(), queryDouble(), queryIp()
   496     HbInputDialog::getDouble(iTitle,this,SLOT(dialogClosed(HbAction*)),iText);  iTitle is the prompt text.dialogClosed will be invoked when the user does the action.
       
   497     Please refer the class documentation to know how to handle the slot.
       
   498    
       
   499     \param label The prompt text which gives information on user input field.
       
   500     \param receiver the instance where the slot is declared.
       
   501     \param member the slot which has dialogClosed(HbAction*) signature. 
       
   502     \param value the default value that should be presented to the user.
       
   503     \param scene the scene parameter.
       
   504     \param parent the parent widget for the dialog.
       
   505    
       
   506     \sa getText(), getInteger(), getIp()
       
   507 */
   497 */
   508 void HbInputDialog::getDouble(const QString &label, 
   498 void HbInputDialog::getDouble(const QString &label, 
   509                                 QObject *receiver,
   499                                 QObject *receiver,
   510                                 const char *member,
   500                                 const char *member,
   511                                 double value, 
   501                                 double value, 
   520     dlg->setInputMode(RealInput);
   510     dlg->setInputMode(RealInput);
   521     dlg->setValue(QString::number(value));
   511     dlg->setValue(QString::number(value));
   522     dlg->open(receiver,member);
   512     dlg->open(receiver,member);
   523 }
   513 }
   524 
   514 
   525 
   515 /*!
   526 /*!
   516     \deprecated HbInputDialog::getIp(const QString &,QObject*,const char*,const QString&,QGraphicsScene*,QGraphicsItem*)
   527     This is a static convenience function for creating an Input Dialog and to get an IP information from the the user. This API allows a slot to be passed as a param. This slot will 
   517         is deprecated.
   528     be invoked when the user does the action like OK press or CANCEL press.  
   518 
   529     
   519     \sa queryInteger(), queryDouble(), queryIp()
   530     HbInputDialog::getIp(iTitle,this,SLOT(dialogClosed(HbAction*)),iText);  iTitle is the prompt text.dialogClosed will be invoked when the user does the action.
       
   531     Please refer the class documentation to know how to handle the slot.
       
   532    
       
   533     \param label The prompt text which gives information on user input field.
       
   534     \param receiver the instance where the slot is declared.
       
   535     \param member the slot which has dialogClosed(HbAction*) signature. 
       
   536     \param ipaddress the default value that should be presented to the user.
       
   537     \param scene the scene parameter.
       
   538     \param parent the parent widget for the dialog.
       
   539    
       
   540     \sa getText(), getInteger(), getDouble()
       
   541 */
   520 */
   542 
   521 
   543 void HbInputDialog::getIp(const QString &label, 
   522 void HbInputDialog::getIp(const QString &label, 
   544                             QObject *receiver,
   523                             QObject *receiver,
   545                             const char *member,
   524                             const char *member,
   554     dlg->setPromptText(label);
   533     dlg->setPromptText(label);
   555     dlg->setValue(ipaddress);
   534     dlg->setValue(ipaddress);
   556     dlg->setInputMode(IpInput);    
   535     dlg->setInputMode(IpInput);    
   557     dlg->open(receiver,member);
   536     dlg->open(receiver,member);
   558 }
   537 }
       
   538 
       
   539 /*!
       
   540     This is a static convenience function for creating an Input Dialog and to get a string data from the the user. The Application can use this 
       
   541     function in order to get any text data from user like username,search data etc. This API allows a slot to be passed as a param. This slot will 
       
   542     be invoked when the user does the action like OK press or CANCEL press.  
       
   543     
       
   544     HbInputDialog::queryText(iTitle,this,SLOT(dialogClosed(int)),iText);  iTitle is the prompt text.dialogClosed will be invoked when the user does the action.
       
   545     Please refer the class documentation to know how to handle the slot.
       
   546    
       
   547     \param promptText The prompt text which gives information on user input field.
       
   548     \param receiver The instance where the slot is declared.
       
   549     \param member The slot which has dialogClosed(HbAction*) or dialogClosed(int) signature. 
       
   550     \param defaultText The default text that should be presented to the user.
       
   551     \param scene The scene parameter.
       
   552     \param parent The parent item for the dialog.
       
   553    
       
   554     \sa queryInteger(), queryDouble(), queryIp()
       
   555 */
       
   556 void HbInputDialog::queryText(const QString &promptText,
       
   557                                 QObject *receiver,
       
   558                                 const char* member,
       
   559                                 const QString &defaultText,
       
   560                                 QGraphicsScene *scene, 
       
   561                                 QGraphicsItem *parent)
       
   562 {
       
   563     HbInputDialog *dlg = new HbInputDialog(parent);
       
   564     if (scene && !parent) {
       
   565         scene->addItem(dlg);
       
   566     }
       
   567     dlg->setPromptText(promptText);
       
   568     dlg->setInputMode(TextInput);
       
   569     dlg->setValue(defaultText);    
       
   570     dlg->setAttribute(Qt::WA_DeleteOnClose);
       
   571     dlg->open(receiver,member);
       
   572 }
       
   573 
       
   574 
       
   575 /*!
       
   576     This is a static convenience function for creating an Input Dialog and to get an integer data from the the user. The Application can use this 
       
   577     function in order to get any integer data from user like year , any number etc. This API allows a slot to be passed as a param. This slot will 
       
   578     be invoked when the user does the action like OK press or CANCEL press.  
       
   579     
       
   580     HbInputDialog::queryInt(iTitle,this,SLOT(dialogClosed(int)),iText);  iTitle is the prompt text.dialogClosed will be invoked when the user does the action.
       
   581     Please refer the class documentation to know how to handle the slot.
       
   582    
       
   583     \param promptText The prompt text which gives information on user input field.
       
   584     \param receiver The instance where the slot is declared.
       
   585     \param member The slot which has dialogClosed(HbAction*) or dialogClosed(int) signature. 
       
   586     \param defaultInt The default value that should be presented to the user.
       
   587     \param scene The scene parameter.
       
   588     \param parent The parent widget for the dialog.
       
   589    
       
   590     \sa queryText(), queryDouble(), queryIp()
       
   591 */
       
   592 void HbInputDialog::queryInt(const QString &promptText, 
       
   593                                 QObject *receiver,
       
   594                                 const char *member,
       
   595                                 int defaultInt,
       
   596                                 QGraphicsScene *scene,
       
   597                                 QGraphicsItem *parent)
       
   598 {
       
   599     HbInputDialog *dlg = new HbInputDialog(parent);
       
   600     if(scene && !parent) {
       
   601         scene->addItem(dlg);
       
   602     }
       
   603     dlg->setPromptText(promptText);
       
   604     dlg->setInputMode(IntInput);
       
   605     dlg->setValue(QString::number(defaultInt));
       
   606     dlg->setAttribute(Qt::WA_DeleteOnClose);
       
   607     dlg->open(receiver,member);
       
   608 }
       
   609 /*!
       
   610     This is a static convenience function for creating an Input Dialog and to get a double data from the the user. The Application can use this 
       
   611     function in order to get any double data from user. This API allows a slot to be passed as a param. This slot will 
       
   612     be invoked when the user does the action like OK press or CANCEL press.  
       
   613     
       
   614     HbInputDialog::queryDouble(iTitle,this,SLOT(dialogClosed(int)),iText);  iTitle is the prompt text.dialogClosed will be invoked when the user does the action.
       
   615     Please refer the class documentation to know how to handle the slot.
       
   616    
       
   617     \param promptText The prompt text which gives information on user input field.
       
   618     \param receiver the instance where the slot is declared.
       
   619     \param member the slot which has dialogClosed(HbAction*) or dialogClosed(int) signature. 
       
   620     \param defaultDouble the default value that should be presented to the user.
       
   621     \param scene the scene parameter.
       
   622     \param parent the parent widget for the dialog.
       
   623    
       
   624     \sa queryText(), queryInteger(), queryIp()
       
   625 */
       
   626 void HbInputDialog::queryDouble(const QString &promptText, 
       
   627                                 QObject *receiver,
       
   628                                 const char *member,
       
   629                                 double defaultDouble, 
       
   630                                 QGraphicsScene *scene, 
       
   631                                 QGraphicsItem *parent)
       
   632 {
       
   633     HbInputDialog *dlg = new HbInputDialog(parent);
       
   634     if(scene && !parent) {
       
   635         scene->addItem(dlg);    
       
   636     }
       
   637     dlg->setPromptText(promptText);
       
   638     dlg->setInputMode(RealInput);
       
   639     dlg->setValue(QString::number(defaultDouble));
       
   640     dlg->open(receiver,member);
       
   641 }
       
   642 
       
   643 
       
   644 /*!
       
   645     This is a static convenience function for creating an Input Dialog and to get an IP information from the the user. This API allows a slot to be passed as a param. This slot will 
       
   646     be invoked when the user does the action like OK press or CANCEL press.  
       
   647     
       
   648     HbInputDialog::queryIp(iTitle,this,SLOT(dialogClosed(int)),iText);  iTitle is the prompt text.dialogClosed will be invoked when the user does the action.
       
   649     Please refer the class documentation to know how to handle the slot.
       
   650    
       
   651     \param promptText The prompt text which gives information on user input field.
       
   652     \param receiver the instance where the slot is declared.
       
   653     \param member the slot which has dialogClosed(HbAction*) or dialogClosed(int) signature. 
       
   654     \param defaultIp the default value that should be presented to the user.
       
   655     \param scene the scene parameter.
       
   656     \param parent the parent widget for the dialog.
       
   657    
       
   658     \sa queryText(), queryInteger(), queryDouble()
       
   659 */
       
   660 
       
   661 void HbInputDialog::queryIp(const QString &promptText, 
       
   662                             QObject *receiver,
       
   663                             const char *member,
       
   664                             const QString &defaultIp, 
       
   665                             QGraphicsScene *scene, 
       
   666                             QGraphicsItem *parent)
       
   667 {
       
   668     HbInputDialog *dlg = new HbInputDialog(parent);
       
   669     if(scene && !parent) {
       
   670         scene->addItem(dlg);    
       
   671     }
       
   672     dlg->setPromptText(promptText);
       
   673     dlg->setValue(defaultIp);
       
   674     dlg->setInputMode(IpInput);    
       
   675     dlg->open(receiver,member);
       
   676 }
   559 #include "moc_hbinputdialog.cpp"
   677 #include "moc_hbinputdialog.cpp"
   560 
   678