Ticket #10342: MythSpinBoxDialog.diff

File MythSpinBoxDialog.diff, 6.5 KB (added by Xavier Hervy <xavier.hervy@…>, 14 years ago)
  • mythtv/libs/libmythui/mythdialogbox.cpp

    diff --git a/mythtv/libs/libmythui/mythdialogbox.cpp b/mythtv/libs/libmythui/mythdialogbox.cpp
    index a0f921f..ded8c2d 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 * Can be called only after MythSpinBoxDialog::Create() return successfully
     734 * The range need to be set before we can set the value
     735 */
     736void MythSpinBoxDialog::SetValue (const QString & value)
     737{
     738    m_spinBox->SetValue(value);
     739}
     740
     741/**
     742 * Can be called only after MythSpinBoxDialog::Create() return successfully
     743 */
     744void MythSpinBoxDialog::SetValue (int value)
     745{
     746    m_spinBox->SetValue(value);
     747}
     748
     749void MythSpinBoxDialog::SetReturnEvent(QObject *retobject,
     750                                         const QString &resultid)
     751{
     752    m_retObject = retobject;
     753    m_id = resultid;
     754}
     755
     756void MythSpinBoxDialog::sendResult()
     757{
     758    QString inputString = m_spinBox->GetValue();
     759    emit haveResult(inputString);
     760
     761    if (m_retObject)
     762    {
     763        DialogCompletionEvent *dce = new DialogCompletionEvent(m_id, 0,
     764                                                            inputString, "");
     765        QCoreApplication::postEvent(m_retObject, dce);
     766    }
     767
     768    Close();
     769}
     770
    677771/////////////////////////////////////////////////////////////////////
    678772
    679773
  • mythtv/libs/libmythui/mythdialogbox.h

    diff --git a/mythtv/libs/libmythui/mythdialogbox.h b/mythtv/libs/libmythui/mythdialogbox.h
    index da8c320..6d3068c 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 SetValue (const QString & value);
     268    void SetValue (int value);
     269
     270  signals:
     271     void haveResult(QString);
     272
     273  protected:
     274    MythUISpinBox *m_spinBox;
     275    QString m_message;
     276    QString m_defaultValue;
     277    QObject *m_retObject;
     278    QString m_id;
     279
     280  protected slots:
     281    void sendResult();
     282};
     283
     284
     285/**
    248286 * \class MythUISearchDialog
    249287 * \brief Provide a dialog to quickly find an entry in a list
    250288 *
  • mythtv/themes/default-wide/base.xml

    diff --git a/mythtv/themes/default-wide/base.xml b/mythtv/themes/default-wide/base.xml
    index ae44d1c..156be62 100644
    a b  
    817817        </button>
    818818    </window>
    819819
     820    <window name="MythSpinBoxDialog">
     821        <area>-1,-1,580,165</area>
     822
     823        <imagetype name="backimg">
     824            <filename>mythprogressdialog-background.png</filename>
     825        </imagetype>
     826
     827        <textarea name="message" from="basetextarea">
     828            <area>20,20,540,30</area>
     829            <align>allcenter</align>
     830        </textarea>
     831
     832        <spinbox name="input" from="basespinbox">
     833            <position>245,50</position>
     834        </spinbox>
     835
     836        <button name="ok" from="basebutton">
     837            <position>109,110</position>
     838            <value>OK</value>
     839        </button>
     840    </window>
     841
    820842    <window name="MythSearchDialog">
    821843        <area>-1,-1,500,500</area>
    822844        <imagetype name="backimg">
  • mythtv/themes/default/base.xml

    diff --git a/mythtv/themes/default/base.xml b/mythtv/themes/default/base.xml
    index 5d36b3c..d2b55ae 100644
    a b  
    900900        </button>
    901901    </window>
    902902
     903    <window name="MythSpinBoxDialog">
     904        <area>-1,-1,580,165</area>
     905
     906        <imagetype name="backimg">
     907            <filename>mythprogressdialog-background.png</filename>
     908        </imagetype>
     909
     910        <textarea name="message" from="basetextarea">
     911            <area>20,20,540,30</area>
     912            <align>allcenter</align>
     913        </textarea>
     914
     915        <spinbox name="input" from="basespinbox">
     916            <position>245,50</position>
     917        </spinbox>
     918
     919        <button name="ok" from="basebutton">
     920            <position>109,110</position>
     921            <value>OK</value>
     922        </button>
     923    </window>
     924
    903925    <window name="MythSearchDialog">
    904926        <area>-1,-1,500,500</area>
    905927        <imagetype name="backimg">