Ticket #10342: mythspinboxdialog-2012-03-01.diff

File mythspinboxdialog-2012-03-01.diff, 4.7 KB (added by Xavier Hervy <xavier.hervy@…>, 12 years ago)

Make use of new MythUISpinBox::AddSelection? form #10393

  • mythtv/libs/libmythui/mythdialogbox.cpp

    diff --git a/mythtv/libs/libmythui/mythdialogbox.cpp b/mythtv/libs/libmythui/mythdialogbox.cpp
    index a0f921f..6aa420d 100644
    a b  
    1717#include "mythuibuttonlist.h"
    1818#include "mythuibutton.h"
    1919#include "mythuistatetype.h"
     20#include "mythuispinbox.h"
    2021
    2122QEvent::Type DialogCompletionEvent::kEventType =
    2223    (QEvent::Type) QEvent::registerEventType();
    void MythTextInputDialog::sendResult() 
    674675    Close();
    675676}
    676677
     678/////////////////////////////////////////////////////////////////
     679
     680MythSpinBoxDialog::MythSpinBoxDialog(MythScreenStack *parent,
     681            const QString &message)
     682           : MythScreenType(parent, "mythspinboxpopup")
     683{
     684    LOG(VB_GENERAL, LOG_ERR, "MythSpinBoxDialog::MythSpinBoxDialog()");
     685    m_message = message;
     686    m_spinBox = NULL;
     687
     688    m_id = "";
     689    m_retObject = NULL;
     690}
     691
     692bool MythSpinBoxDialog::Create(void)
     693{
     694    if (!CopyWindowFromBase("MythSpinBoxDialog", this))
     695        return false;
     696
     697    MythUIText *messageText = NULL;
     698    MythUIButton *okButton = NULL;
     699    MythUIButton *cancelButton = NULL;
     700
     701    bool err = false;
     702    UIUtilE::Assign(this, m_spinBox, "input", &err);
     703    UIUtilE::Assign(this, messageText, "message", &err);
     704    UIUtilE::Assign(this, okButton, "ok", &err);
     705    UIUtilW::Assign(this, cancelButton, "cancel");
     706
     707    if (err)
     708    {
     709        LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'MythSpinBoxDialog'");
     710        return false;
     711    }
     712
     713    if (cancelButton)
     714        connect(cancelButton, SIGNAL(Clicked()), SLOT(Close()));
     715    connect(okButton, SIGNAL(Clicked()), SLOT(sendResult()));
     716
     717    messageText->SetText(m_message);
     718    BuildFocusList();
     719
     720    return true;
     721}
     722
     723/**
     724 *  \copydoc MythUISpinBox::SetRange()
     725 * Can be called only after MythSpinBoxDialog::Create() return successfully
     726 */
     727void MythSpinBoxDialog::SetRange (int low, int high, int step, uint pageMultiple)
     728{
     729    m_spinBox->SetRange(low, high, step, pageMultiple);
     730}
     731
     732/**
     733 *
     734 */
     735void MythSpinBoxDialog::AddSelection (QString label, int value)
     736{
     737    m_spinBox->AddSelection(label, value);
     738}
     739
     740/**
     741 * Can be called only after MythSpinBoxDialog::Create() return successfully
     742 * The range need to be set before we can set the value
     743 */
     744void MythSpinBoxDialog::SetValue (const QString & value)
     745{
     746    m_spinBox->SetValue(value);
     747}
     748
     749/**
     750 * Can be called only after MythSpinBoxDialog::Create() return successfully
     751 */
     752void MythSpinBoxDialog::SetValue (int value)
     753{
     754    m_spinBox->SetValue(value);
     755}
     756
     757void MythSpinBoxDialog::SetReturnEvent(QObject *retobject,
     758                                         const QString &resultid)
     759{
     760    m_retObject = retobject;
     761    m_id = resultid;
     762}
     763
     764void MythSpinBoxDialog::sendResult()
     765{
     766    QString inputString = m_spinBox->GetValue();
     767    emit haveResult(inputString);
     768
     769    if (m_retObject)
     770    {
     771        DialogCompletionEvent *dce = new DialogCompletionEvent(m_id, 0,
     772                                                            inputString, "");
     773        QCoreApplication::postEvent(m_retObject, dce);
     774    }
     775
     776    Close();
     777}
     778
    677779/////////////////////////////////////////////////////////////////////
    678780
    679781
  • mythtv/libs/libmythui/mythdialogbox.h

    diff --git a/mythtv/libs/libmythui/mythdialogbox.h b/mythtv/libs/libmythui/mythdialogbox.h
    index da8c320..699c788 100644
    a b class MythUIButtonListItem; 
    1515class MythUIButtonList;
    1616class MythUIButton;
    1717class MythUITextEdit;
     18class MythUISpinBox;
    1819class MythUIImage;
    1920class MythUIStateType;
    2021class MythMenu;
    class MUI_PUBLIC MythTextInputDialog : public MythScreenType 
    245246
    246247
    247248/**
     249 *  \class MythSpinBoxDialog
     250 *
     251 *  \brief Dialog prompting the user to enter a number using a spin box
     252 *
     253 *  Sends out a DialogCompletionEvent event and the haveResult() signal
     254 *  containing the result when the user selects the Ok button.
     255 */
     256class MUI_PUBLIC MythSpinBoxDialog : public MythScreenType
     257{
     258    Q_OBJECT
     259
     260  public:
     261    MythSpinBoxDialog(MythScreenStack *parent, const QString &message);
     262
     263    bool Create(void);
     264    void SetReturnEvent(QObject *retobject, const QString &resultid);
     265
     266    void SetRange (int low, int high, int step, uint pageMultiple=5);
     267    void AddSelection (QString label, int value);
     268    void SetValue (const QString & value);
     269    void SetValue (int value);
     270
     271  signals:
     272     void haveResult(QString);
     273
     274  protected:
     275    MythUISpinBox *m_spinBox;
     276    QString m_message;
     277    QString m_defaultValue;
     278    QObject *m_retObject;
     279    QString m_id;
     280
     281  protected slots:
     282    void sendResult();
     283};
     284
     285
     286/**
    248287 * \class MythUISearchDialog
    249288 * \brief Provide a dialog to quickly find an entry in a list
    250289 *