1 #pragma once
2 
3 #ifndef VALIDATEDCHOICEDIALOG_H
4 #define VALIDATEDCHOICEDIALOG_H
5 
6 // TnzCore includes
7 #include "tcommon.h"
8 
9 // TnzQt includes
10 #include "toonzqt/dvdialog.h"
11 
12 #undef DVAPI
13 #undef DVVAR
14 #ifdef TOONZQT_EXPORTS
15 #define DVAPI DV_EXPORT_API
16 #define DVVAR DV_EXPORT_VAR
17 #else
18 #define DVAPI DV_IMPORT_API
19 #define DVVAR DV_IMPORT_VAR
20 #endif
21 
22 //====================================================
23 
24 //    Forward declarations
25 
26 class QButtonGroup;
27 
28 //====================================================
29 
30 //************************************************************************
31 //    ValidatedChoiceDialog  declaration
32 //************************************************************************
33 
34 namespace DVGui {
35 
36 /*!
37   \brief    Base class for validated multi-choice user dialogs.
38 
39   \warning  For correct usage, observe the guidelines described in the
40             ValidatedChoiceDialog() constructor.
41 */
42 
43 class DVAPI ValidatedChoiceDialog : public DVGui::Dialog {
44   Q_OBJECT
45 
46 public:
47   enum Options         //!  Construction options
48   { NO_OPTIONS = 0x0,  //!< No special options.
49     APPLY_TO_ALL =
50         0x1  //!< Has the "Apply to All" button. An <I>applied to all</I>
51              //!  resolution persists as the default without-prompt resolution
52              //!  until the next call to reset().
53   };
54 
55   enum DefaultResolution  //!  Basic resolutions supported by the dialog.
56   { NO_REQUIRED_RESOLUTION =
57         0,       //!< An object supplied for validation turns out to be valid,
58                  //!  no need for any resolution.
59     CANCEL = 1,  //!< Resolution selection was canceled. Stop processing.
60 
61     DEFAULT_RESOLUTIONS_COUNT };
62 
63 public:
64   /*! \warning  Due to compatibility with DVGui::Dialog's interface, this class
65 reserves
66           invocation of \p Dialog::beginVLayout() during class construction -
67           however, <B>\p Dialog::endVLayout() invocation is responsibility of
68           derived classes</B> after resolution choices have been manually added
69           to the layout.
70 
71 \warning  Users are required to respect the default resolution ids when adding
72           buttons into \p m_buttonGroup. See the \p DefaultResolution enum for a
73           list of all default resolutions. */
74 
75   ValidatedChoiceDialog(QWidget *parent,
76                         Options opts = NO_OPTIONS);  //!< Constructs the dialog
77                                                      //! with no default
78   //! resolutions.
79   //!\param parent  Parent
80   //! top-level widget.
81   //!\param Opts
82   //! Construction options.
83 
84   /*! \param    obj  The object to resolve.
85 \return        The accepted resolution. */
86 
87   int execute(
88       void *obj);  //!< Prompts the dialog asking for user input, until a
89                    //!  valid resolution for the specified object is selected or
90                    //!  the action is canceled.
91   virtual void
92   reset();  //!< Clears accepted resolutions - should be used together
93             //!  with option \p APPLY_TO_ALL.
94 protected:
95   QButtonGroup *m_buttonGroup;  //!< Group of abstract buttons representing all
96                                 //!  available resolutions.
97 protected:
98   /*! \details  Resolution \p NO_REQUIRED_RESOLUTION is always tested before
99 other
100           proposed resolutions.
101 
102 \return   An error message upon failure. */
103 
104   virtual QString acceptResolution(
105       void *obj,  //!< The type-erased object to be resolved. May be modified.
106       int resolution,  //!< The <I>button id</I> associated to the selected
107                        //! resolution.
108       bool applyToAll  //!< Whether user selected the resolution for all
109                        //! successive prompts.
110       ) = 0;           //!< Attempts enforcement of the selected resolution.
111 
112   /*! \details  This function can be used to initialize the widget as soon as
113           user interaction is required. Use \p showEvent() in case the
114           initialization is needed at \a every interaction time. */
115 
initializeUserInteraction(const void * obj)116   virtual void initializeUserInteraction(const void *obj) {
117   }  //!< Invoked at max \a once per \p execute(), immediately
118      //!  before the dialog is shown.
appliedToAll()119   bool appliedToAll() const {
120     return m_appliedToAll;
121   }  //!< Returns whether the "Apply To All" button has been hit.
appliedToAllResolution()122   int appliedToAllResolution() const {
123     return m_appliedToAllRes;
124   }  //!< Returns the resolution associated to the "Apply To All"
125      //!  button.
126 private:
127   QLabel *m_label;  //!< Label showing a description of the validation problem.
128 
129   int m_appliedToAllRes;  //!< Resolution applied in the \p APPLY_TO_ALL case.
130   bool m_appliedToAll,    //!< Whether the \p APPLY_TO_ALL option has previously
131                           //! been selected.
132       m_applyToAll;  //!< Whether the \p APPLY_TO_ALL option has been selected
133                      //! in
134   //!  \a current user interaction.
135 private slots:
136 
137   void onApplyToAll();
138 };
139 
140 }  // namespace DVGui
141 
142 #endif  // VALIDATEDCHOICEDIALOG_H
143