Ticket #3334: importicons-libmyth-04102007.diff

File importicons-libmyth-04102007.diff, 6.0 KB (added by Matthew Wire <devel@…>, 19 years ago)

Update to set focus to cancel button

  • libs/libmyth/mythdialogs.cpp

     
    624624    return popup.ExecPopup();
    625625}
    626626
    627 MythProgressDialog::MythProgressDialog(const QString &message, int totalSteps)
     627MythProgressDialog::MythProgressDialog(const QString &message, int totalSteps,
     628                                         bool cancelButton, const QObject *target, const char *slot)
    628629                  : MythDialog(gContext->GetMainWindow(), "progress", false)
    629630{
    630631    int screenwidth, screenheight;
     
    652653    vbox->setFrameShadow(QFrame::Raised);
    653654    vbox->setMargin((int)(15 * wmult));
    654655
    655     QLabel *msglabel = new QLabel(vbox);
     656    msglabel = new QLabel(vbox);
    656657    msglabel->setBackgroundOrigin(ParentOrigin);
    657658    msglabel->setText(message);
     659    vbox->setStretchFactor(msglabel, 5);
    658660
    659     progress = new QProgressBar(totalSteps, vbox);
     661    QHBox *hbox = new QHBox(vbox);
     662    hbox->setSpacing(5);
     663   
     664    progress = new QProgressBar(totalSteps, hbox);
    660665    progress->setBackgroundOrigin(ParentOrigin);
    661     progress->setProgress(0);
    662666
     667    if (cancelButton && slot && target)
     668    {
     669        MythPushButton *button = new MythPushButton("Cancel", hbox, 0);
     670        button->setFocus();
     671        connect(button, SIGNAL(pressed()), target, slot);
     672    }
     673
    663674    setTotalSteps(totalSteps);
    664675
    665676    if (class LCD * lcddev = LCD::Get())
     
    707718    }
    708719}
    709720
     721void MythProgressDialog::setLabel(QString newlabel)
     722{
     723    msglabel->setText(newlabel);
     724}
     725
    710726void MythProgressDialog::keyPressEvent(QKeyEvent *e)
    711727{
    712728    bool handled = false;
     
    728744void MythProgressDialog::setTotalSteps(int totalSteps)
    729745{
    730746    m_totalSteps = totalSteps;
     747    progress->setTotalSteps(totalSteps);
    731748    steps = totalSteps / 1000;
    732749    if (steps == 0)
    733750        steps = 1;
    734751}
    735752
    736 MythBusyDialog::MythBusyDialog(const QString &title)
    737     : MythProgressDialog(title, 0), timer(NULL)
     753MythProgressDialog::~MythProgressDialog()
    738754{
     755    if (LCD *lcddev = LCD::Get())
     756        lcddev->switchToTime();
    739757}
    740758
     759
     760MythBusyDialog::MythBusyDialog(const QString &title,
     761                               bool cancelButton, const QObject *target, const char *slot)
     762    : MythProgressDialog(title, 0,
     763                         cancelButton, target, slot),
     764                         timer(NULL)
     765{
     766}
     767
    741768MythBusyDialog::~MythBusyDialog()
    742769{
    743770    if (timer)
  • libs/libmyth/settings.h

     
    409409    void setSelectionMode(MythListBox::SelectionMode mode);
    410410    void setCurrentItem(int i) { if (widget) widget->setCurrentItem(i); }
    411411    void setCurrentItem(const QString& str)  { if (widget) widget->setCurrentItem(str); }
     412    int currentItem() { if (widget) return widget->currentItem();
     413                         else return -1; }
    412414
    413415    virtual void setEnabled(bool b);
    414416
     
    668670                       allow_single_step, special_value_text) { }
    669671};
    670672
     673class MPUBLIC TransListBoxSetting :
     674    public ListBoxSetting, public TransientStorage
     675{
     676  public:
     677    TransListBoxSetting() : ListBoxSetting(this), TransientStorage() { }
     678};
     679
     680
    671681///////////////////////////////////////////////////////////////////////////////
    672682
    673683class MPUBLIC HostSlider : public SliderSetting, public HostDBStorage
  • libs/libmyth/mythdialogs.h

     
    189189*/
    190190class MPUBLIC MythProgressDialog: public MythDialog
    191191{
     192    Q_OBJECT   
    192193  public:
    193194    /** Create a progress bar dialog.
    194195       
    195196        \param message the title string to appear in the progress dialog.
    196197        \param totalSteps the total number of steps
     198        \param cancelButton display cancel button
     199        \param target target for pressed signal
     200        \param slot slot for pressed signal
    197201     */
    198     MythProgressDialog(const QString& message, int totalSteps);
     202    MythProgressDialog(const QString& message, int totalSteps = 0,
     203                       bool cancelButton = false,
     204                       const QObject * target = NULL,
     205                       const char * slot = NULL);
     206   
     207    ~MythProgressDialog();
    199208
     209
    200210    /* \brief Close the dialog.
    201211
    202212        This will close the dialog and return the LCD to the Time screen
    203213    */
    204214    void Close(void);
     215
     216    void keyPressEvent(QKeyEvent *);
     217   
     218  public slots:
    205219    /* \brief Update the progress bar. 
    206220
    207221       This will move the progress bar the percentage-completed as
     
    211225       The LCD is updated as well.
    212226    */
    213227    void setProgress(int curprogress);
     228    void setLabel(QString newlabel);
     229   
     230  signals:
     231    void pressed();
    214232
    215     void keyPressEvent(QKeyEvent *);
    216 
    217233  protected:
    218234    QProgressBar *progress;
     235    QLabel *msglabel;
    219236
    220237  private:
    221238    void setTotalSteps(int totalSteps);
     
    240257        the widget to indicate progress every 100msec;
    241258
    242259        \param title the title to appear in the progress bar dialog
     260        \cancelButton display cancel button
     261        \param target target for pressed signal
     262        \param slot slot for pressed signal
    243263    */
    244     MythBusyDialog(const QString &title);
     264    MythBusyDialog(const QString &title,
     265                   bool cancelButton = false,
     266                   const QObject * target = NULL,
     267                   const char * slot = NULL);
    245268
    246269    ~MythBusyDialog();
    247270
  • libs/libmyth/mythwidgets.h

     
    375375    virtual void keyPressEvent(QKeyEvent* e);
    376376
    377377    void setHelpText(QString help) { helptext = help; }
     378   
     379    int currentItem() { return QListBox::currentItem(); }
    378380
    379381  protected:
    380382    void focusInEvent(QFocusEvent *e);