tahoma2d/toonz/sources/toonzqt/validatedchoicedialog.cpp

115 lines
3.1 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
#include "toonzqt/validatedchoicedialog.h"
// Qt includes
#include <QLabel>
#include <QPushButton>
#include <QButtonGroup>
//************************************************************************
// ValidatedChoiceDialog implementation
//************************************************************************
2016-06-15 18:43:10 +12:00
DVGui::ValidatedChoiceDialog::ValidatedChoiceDialog(QWidget *parent,
Options opts)
: Dialog(parent, true, false) {
setModal(true);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_buttonGroup = new QButtonGroup(this);
m_buttonGroup->setExclusive(true);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool ret = true;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QPushButton *okBtn = new QPushButton(QString(tr("Apply")), this);
ret = ret && connect(okBtn, SIGNAL(clicked()), SLOT(accept()));
addButtonBarWidget(okBtn);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QPushButton *okToAllBtn = new QPushButton(QString(tr("Apply to All")), this);
ret = ret && connect(okToAllBtn, SIGNAL(clicked()), SLOT(onApplyToAll()));
addButtonBarWidget(okToAllBtn);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
QPushButton *cancelBtn = new QPushButton(QString(tr("Cancel")), this);
ret = ret && connect(cancelBtn, SIGNAL(clicked()), SLOT(reject()));
addButtonBarWidget(cancelBtn);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
assert(ret);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
reset();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Start layout
beginVLayout();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
m_label = new QLabel(this);
addWidget(m_label);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// enbVLayout() must be invoked by derived classes
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void DVGui::ValidatedChoiceDialog::reset() {
m_appliedToAllRes = NO_REQUIRED_RESOLUTION;
m_appliedToAll = false;
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------
QString validate(void *obj);
2016-06-15 18:43:10 +12:00
int DVGui::ValidatedChoiceDialog::execute(void *obj) {
struct Resol {
int m_res;
bool m_all;
Resol(int res, bool all) : m_res(res), m_all(all) {}
};
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
Resol curResolution(NO_REQUIRED_RESOLUTION, false),
newResolution(m_appliedToAll ? m_appliedToAllRes : NO_REQUIRED_RESOLUTION,
m_appliedToAll);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
bool initialize = true;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Loop until a resolution gets accepted
do {
QString err =
acceptResolution(obj, curResolution.m_res, curResolution.m_all);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (err.isEmpty()) break;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (newResolution.m_res == NO_REQUIRED_RESOLUTION) {
// No new resolution selected - prompt for user interaction
m_label->setText(err);
m_applyToAll = false;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (initialize) initializeUserInteraction(obj), initialize = false;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
if (exec() == QDialog::Rejected) {
curResolution.m_res = CANCEL;
break;
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
newResolution = Resol(m_buttonGroup->checkedId(), m_applyToAll);
assert(newResolution.m_res >= DEFAULT_RESOLUTIONS_COUNT);
}
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Substitute resolution and retry
curResolution = newResolution,
newResolution = Resol(NO_REQUIRED_RESOLUTION, false);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
} while (true);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
return curResolution.m_res;
2016-03-19 06:57:51 +13:00
}
//------------------------------------------------------------------------
2016-06-15 18:43:10 +12:00
void DVGui::ValidatedChoiceDialog::onApplyToAll() {
m_appliedToAllRes = m_buttonGroup->checkedId();
m_applyToAll = m_appliedToAll = true;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
assert(m_appliedToAllRes >= DEFAULT_RESOLUTIONS_COUNT);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
accept();
2016-03-19 06:57:51 +13:00
}