| 678 | ///////////////////////////////////////////////////////////////// |
| 679 | |
| 680 | MythSpinBoxDialog::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 | |
| 692 | bool 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 | */ |
| 727 | void MythSpinBoxDialog::SetRange (int low, int high, int step, uint pageMultiple) |
| 728 | { |
| 729 | m_spinBox->SetRange(low, high, step, pageMultiple); |
| 730 | } |
| 731 | |
| 732 | /** |
| 733 | * |
| 734 | */ |
| 735 | void 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 | */ |
| 744 | void 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 | */ |
| 752 | void MythSpinBoxDialog::SetValue (int value) |
| 753 | { |
| 754 | m_spinBox->SetValue(value); |
| 755 | } |
| 756 | |
| 757 | void MythSpinBoxDialog::SetReturnEvent(QObject *retobject, |
| 758 | const QString &resultid) |
| 759 | { |
| 760 | m_retObject = retobject; |
| 761 | m_id = resultid; |
| 762 | } |
| 763 | |
| 764 | void 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 | |