1 #pragma once 2 3 #ifndef DVDIALOG_INCLUDED 4 #define DVDIALOG_INCLUDED 5 6 // TnzCore includes 7 #include "tcommon.h" 8 #include "tmsgcore.h" 9 10 // Qt includes 11 #include <QDialog> 12 #include <QVBoxLayout> 13 #include <QString> 14 #include <QProgressBar> 15 #include <QFrame> 16 #include <QSettings> 17 18 #undef DVAPI 19 #undef DVVAR 20 #ifdef TOONZQT_EXPORTS 21 #define DVAPI DV_EXPORT_API 22 #define DVVAR DV_EXPORT_VAR 23 #else 24 #define DVAPI DV_IMPORT_API 25 #define DVVAR DV_IMPORT_VAR 26 #endif 27 28 // forward declaration 29 class QAbstractButton; 30 class QHBoxLayout; 31 class QVBoxLayout; 32 class QLayout; 33 class QLabel; 34 class TXsheetHandle; 35 class TPalette; 36 37 #ifdef _MSC_VER 38 #pragma warning(disable : 4251) 39 #endif 40 41 //============================================================================= 42 namespace DVGui { 43 //============================================================================= 44 45 const int WidgetHeight = 20; 46 47 class Dialog; 48 class MessageAndCheckboxDialog; 49 50 //============================================================================= 51 52 void DVAPI MsgBoxInPopup(MsgType type, const QString &text); 53 54 // ATTENZIONE: Valore di ritorno 55 // 0 = l'utente ha chiuso la finestra (dovrebbe corrispondere ad un cancel o ad 56 // un NO) - closed window 57 // 1 = primo bottone da sx premuto - first button selected 58 // 2 = secondo bottone da sx premuto - second button 59 // 3 = terzo bottone da sx premuto - third button 60 // 4 = fourth button 61 62 int DVAPI MsgBox(MsgType type, const QString &text, 63 const std::vector<QString> &buttons, 64 int defaultButtonIndex = 0, QWidget *parent = 0); 65 66 // QUESTION: due bottoni user defined 67 int DVAPI MsgBox(const QString &text, const QString &button1, 68 const QString &button2, int defaultButtonIndex = 0, 69 QWidget *parent = 0); 70 71 // QUESTION: tre bottoni user defined 72 int DVAPI MsgBox(const QString &text, const QString &button1, 73 const QString &button2, const QString &button3, 74 int defaultButtonIndex = 0, QWidget *parent = 0); 75 76 // QUESTION: four botton user defined 77 int DVAPI MsgBox(const QString &text, const QString &button1, 78 const QString &button2, const QString &button3, 79 const QString &button4, int defaultButtonIndex = 0, 80 QWidget *parent = 0); 81 82 Dialog DVAPI *createMsgBox(MsgType type, const QString &text, 83 const QStringList &buttons, int defaultButtonIndex, 84 QWidget *parent = 0); 85 86 MessageAndCheckboxDialog DVAPI *createMsgandCheckbox( 87 MsgType type, const QString &text, const QString &checkBoxText, 88 const QStringList &buttons, int defaultButtonIndex, 89 Qt::CheckState defaultCheckBoxState, QWidget *parent = 0); 90 91 // void DVAPI error(const QString &msg); 92 // void DVAPI info(const QString &msg); 93 94 //----------------------------------------------------------------------------- 95 96 QString DVAPI getText(const QString &title, const QString &label, 97 const QString &text = QString(), bool *ok = 0); 98 99 //============================================================================= 100 /*! \brief The Separator class provides a separator. 101 102 Inherits \b QWidget. 103 104 The separator can be text and line or only line. If QString \b 105 name, passed to 106 constructor, is not empty, separator is composed by text \b name 107 and line; 108 else separator is a line, this line width is DV dialog width, 109 clearly taking care 110 DV dialog margin. 111 The separator can be horizontal (by default) or vertical, 112 isVertical(), you can 113 set it using function \b setOrientation(). 114 115 To add a separator to DV dialog \b Dialog you must create a new 116 Separator 117 and recall \b Dialog::addWidget(), or recall \b 118 Dialog::addSeparator(). 119 120 \b Example: in a DV dialog \b Dialog 121 \code 122 Separator* exampleNameAndLine = new 123 Separator(QString("Example Name")); 124 addWidget(exampleNameAndLine); 125 Separator* exampleLine = new Separator(""); 126 addWidget(exampleLine); 127 \endcode 128 or: 129 \code 130 addSeparator(QString("Example Name")); 131 addSeparator(); 132 \endcode 133 \b Result 134 \image html DialogSeparator.jpg 135 */ 136 class DVAPI Separator final : public QFrame { 137 Q_OBJECT 138 139 QString m_name; 140 bool m_isHorizontal; 141 142 public: 143 Separator(QString name = "", QWidget *parent = 0, bool isHorizontal = true); 144 ~Separator(); 145 146 /*! Set dialog saparator \b name to name, if name is empty dialog separator 147 is a line. */ setName(const QString & name)148 void setName(const QString &name) { m_name = name; } getName()149 QString getName() { return m_name; } 150 151 /*! Set dialog saparator orientation to horizontal if \b isHorizontal is 152 true, 153 otherwise to vertical. */ setOrientation(bool isHorizontal)154 void setOrientation(bool isHorizontal) { m_isHorizontal = isHorizontal; } 155 156 /*! Return true if saparator orientation is horizontal, false otherwise. */ isHorizontal()157 bool isHorizontal() { return m_isHorizontal; } 158 159 protected: 160 void paintEvent(QPaintEvent *event) override; 161 }; 162 163 //----------------------------------------------------------------------------- 164 165 class DVAPI Dialog : public QDialog { 166 Q_OBJECT 167 // If the dialog has button then is modal too. 168 bool m_hasButton; 169 QString m_name; 170 int m_currentScreen = -1; 171 // gmt. rendo m_buttonLayout protected per ovviare ad un problema 172 // sull'addButtonBarWidget(). cfr filebrowserpopup.cpp. 173 // Dobbiamo discutere di Dialog. 174 175 protected: 176 QHBoxLayout *m_buttonLayout; 177 QList<QLabel *> m_labelList; 178 void resizeEvent(QResizeEvent *e) override; 179 180 public: 181 QVBoxLayout *m_topLayout; 182 QFrame *m_mainFrame, *m_buttonFrame; 183 184 QHBoxLayout *m_mainHLayout; 185 bool m_isMainHLayout; 186 187 QVBoxLayout *m_leftVLayout, *m_rightVLayout; 188 bool m_isMainVLayout; 189 190 int m_layoutSpacing; 191 int m_layoutMargin; 192 int m_labelWidth; 193 194 std::vector<QWidget *> m_buttonBarWidgets; 195 196 public: 197 // if 'name' is not empty, the dialog will remember its geometry between Toonz 198 // sessions 199 Dialog(QWidget *parent = 0, bool hasButton = false, bool hasFixedSize = true, 200 const QString &name = QString()); 201 ~Dialog(); 202 203 void beginVLayout(); 204 void endVLayout(); 205 206 void beginHLayout(); 207 void endHLayout(); 208 209 void addWidget(QWidget *widget, bool isRight = true); 210 void addWidgets(QWidget *firstW, QWidget *secondW); 211 void addWidget(QString labelName, QWidget *widget); 212 213 void addLayout(QLayout *layout, bool isRight = true); 214 void addWidgetLayout(QWidget *widget, QLayout *layout); 215 void addLayout(QString labelName, QLayout *layout); 216 void addLayouts(QLayout *firstL, QLayout *secondL); 217 218 void addSpacing(int spacing); 219 void addSeparator(QString name = QString()); 220 221 void setAlignment(Qt::Alignment alignment); 222 223 void setTopMargin(int margin); 224 void setTopSpacing(int spacing); 225 226 void setLabelWidth(int labelWidth); getLabelWidth()227 int getLabelWidth() const { return m_labelWidth; }; 228 229 void setLayoutInsertedSpacing(int spacing); 230 int getLayoutInsertedSpacing(); 231 232 void setButtonBarMargin(int margin); 233 void setButtonBarSpacing(int spacing); 234 235 void addButtonBarWidget(QWidget *widget); 236 void addButtonBarWidget(QWidget *first, QWidget *second); 237 void addButtonBarWidget(QWidget *first, QWidget *second, QWidget *third); 238 void addButtonBarWidget(QWidget *first, QWidget *second, QWidget *third, 239 QWidget *fourth); 240 241 void hideEvent(QHideEvent *event) override; 242 243 void clearButtonBar(); 244 signals: 245 void dialogClosed(); 246 }; 247 248 //----------------------------------------------------------------------------- 249 250 class DVAPI MessageAndCheckboxDialog final : public DVGui::Dialog { 251 Q_OBJECT 252 253 int m_checked = 0; 254 255 public: 256 MessageAndCheckboxDialog(QWidget *parent = 0, bool hasButton = false, 257 bool hasFixedSize = true, 258 const QString &name = QString(), 259 Qt::CheckState checkButtonState = Qt::Unchecked); getChecked()260 int getChecked() { return m_checked; } 261 262 public slots: 263 void onCheckboxChanged(int checked); 264 void onButtonPressed(int id); 265 }; 266 267 //----------------------------------------------------------------------------- 268 /*! Is a modal dialog with exclusive list of radio button. 269 Exec value depend to checked button. 270 0 -> Cancel or Close Popup, 271 1,2,3,... -> checkbox clicked. 272 */ 273 class DVAPI RadioButtonDialog final : public DVGui::Dialog { 274 Q_OBJECT 275 276 int m_result; 277 278 public: 279 RadioButtonDialog(const QString &labelText, 280 const QList<QString> &radioButtonList, QWidget *parent = 0, 281 Qt::WindowFlags f = 0); 282 283 public Q_SLOTS: 284 void onButtonClicked(int id); 285 void onCancel(); 286 void onApply(); 287 }; 288 289 //----------------------------------------------------------------------------- 290 291 int DVAPI RadioButtonMsgBox(MsgType type, const QString &labelText, 292 const QList<QString> &buttons, QWidget *parent = 0); 293 294 //----------------------------------------------------------------------------- 295 296 class DVAPI ProgressDialog : public DVGui::Dialog { 297 Q_OBJECT 298 299 QLabel *m_label; 300 QProgressBar *m_progressBar; 301 QPushButton *m_cancelButton; 302 303 protected: 304 bool m_isCanceled; 305 306 public: 307 ProgressDialog(const QString &labelText, const QString &cancelButtonText, 308 int minimum, int maximum, QWidget *parent = 0, 309 Qt::WindowFlags f = 0); 310 311 void setLabelText(const QString &text); 312 void setCancelButton(QPushButton *cancelButton); 313 314 int maximum(); 315 void setMaximum(int maximum); 316 317 int minimum(); 318 void setMinimum(int minimum); 319 320 void reset(); 321 int value(); 322 323 bool wasCanceled() const; 324 325 public Q_SLOTS: 326 void setValue(int progress); 327 virtual void onCancel(); 328 329 Q_SIGNALS: 330 void canceled(); 331 }; 332 333 //----------------------------------------------------------------------------- 334 /*! Return 2 if erase style, 335 1 if don't erase style, 336 0 if press cancel or close popup. 337 If newPalette != 0 verify if styles to erase are in new palette before 338 send question. 339 */ 340 int eraseStylesInDemand(TPalette *palette, const TXsheetHandle *xsheetHandle, 341 TPalette *newPalette = 0); 342 343 int eraseStylesInDemand(TPalette *palette, std::vector<int> styleIds, 344 const TXsheetHandle *xsheetHandle); 345 346 //----------------------------------------------------------------------------- 347 348 //----------------------------------------------------------------------------- 349 } // namespace DVGui 350 //----------------------------------------------------------------------------- 351 352 #endif // DVDIALOG_INCLUDED 353