| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| using namespace DVGui; |
| |
| QString DialogTitle = QObject::tr("OpenToonz 1.0"); |
| |
| |
| namespace |
| { |
| QPixmap getMsgBoxPixmap(MsgType type) |
| { |
| int iconSize = QApplication::style()->pixelMetric(QStyle::PM_MessageBoxIconSize); |
| QIcon msgBoxIcon; |
| |
| switch (type) { |
| case DVGui::INFORMATION: |
| msgBoxIcon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxInformation); |
| break; |
| case DVGui::WARNING: |
| msgBoxIcon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning); |
| break; |
| case DVGui::CRITICAL: |
| msgBoxIcon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxCritical); |
| break; |
| case DVGui::QUESTION: |
| msgBoxIcon = QApplication::style()->standardIcon(QStyle::SP_MessageBoxQuestion); |
| break; |
| default: |
| break; |
| } |
| |
| if (!msgBoxIcon.isNull()) |
| return msgBoxIcon.pixmap(iconSize, iconSize); |
| return QPixmap(); |
| } |
| |
| |
| |
| QString getMsgBoxTitle(MsgType type) |
| { |
| QString title = DialogTitle + " - "; |
| |
| switch (type) { |
| case DVGui::INFORMATION: |
| title.append(QObject::tr("Information")); |
| break; |
| case DVGui::WARNING: |
| title.append(QObject::tr("Warning")); |
| break; |
| case DVGui::CRITICAL: |
| title.append(QObject::tr("Critical")); |
| break; |
| case DVGui::QUESTION: |
| title.append(QObject::tr("Question")); |
| break; |
| default: |
| break; |
| } |
| return title; |
| } |
| |
| |
| } |
| |
| |
| |
| |
| |
| |
| Separator::Separator(QString name, QWidget *parent) |
| : QFrame(parent), m_name(name), m_isHorizontal(true) |
| { |
| |
| |
| |
| setMinimumSize(1, 15); |
| } |
| |
| |
| |
| Separator::~Separator() |
| { |
| } |
| |
| |
| |
| void Separator::paintEvent(QPaintEvent *) |
| { |
| QPainter p(this); |
| ParamsPage *page = dynamic_cast<ParamsPage *>(parentWidget()); |
| if (!page) |
| p.setPen(Qt::black); |
| else |
| p.setPen(page->getTextColor()); |
| |
| QRect contents(contentsRect()); |
| |
| int textWidth = p.fontMetrics().width(m_name); |
| |
| p.drawText(contents.left(), 10, m_name); |
| p.setPen(palette().alternateBase().color()); |
| int h = contents.height(); |
| if (m_isHorizontal) { |
| int y = contents.center().y(); |
| int space = (textWidth == 0) ? 0 : 8; |
| p.drawLine(textWidth + space, y, contents.width(), y); |
| } else { |
| double w = width(); |
| int space = (textWidth == 0) ? 0 : 2; |
| int x0 = (w > textWidth) ? w * 0.5 : (double)textWidth * 0.5; |
| int textHeghit = (space == 0) ? 0 : p.fontMetrics().height(); |
| p.drawLine(x0, textHeghit + space, x0, contents.bottom()); |
| } |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| QSettings *Dialog::m_settings = 0; |
| |
| Dialog::Dialog(QWidget *parent, bool hasButton, bool hasFixedSize, const QString &name) |
| : QDialog(parent, Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint), m_hasButton(hasButton), m_mainHLayout(0), m_leftVLayout(0), m_rightVLayout(0), m_isMainVLayout(false), m_isMainHLayout(false), m_layoutSpacing(5), m_layoutMargin(0), m_labelWidth(100), m_name() |
| { |
| QVBoxLayout *mainLayout = new QVBoxLayout; |
| mainLayout->setMargin(0); |
| mainLayout->setSpacing(0); |
| m_mainFrame = new QFrame(this); |
| m_mainFrame->setObjectName("dialogMainFrame"); |
| m_mainFrame->setMinimumHeight(41); |
| m_mainFrame->setFrameStyle(QFrame::StyledPanel); |
| m_topLayout = new QVBoxLayout; |
| m_topLayout->setMargin(12); |
| m_topLayout->setSpacing(m_layoutSpacing); |
| m_topLayout->setAlignment(Qt::AlignCenter); |
| m_mainFrame->setLayout(m_topLayout); |
| |
| mainLayout->addWidget(m_mainFrame); |
| |
| if (m_hasButton) { |
| |
| setModal(true); |
| |
| m_buttonFrame = new QFrame(this); |
| m_buttonFrame->setObjectName("dialogButtonFrame"); |
| m_buttonFrame->setFrameStyle(QFrame::StyledPanel); |
| m_buttonFrame->setFixedHeight(45); |
| |
| m_buttonLayout = new QHBoxLayout; |
| m_buttonLayout->setMargin(0); |
| m_buttonLayout->setSpacing(20); |
| m_buttonLayout->setAlignment(Qt::AlignHCenter); |
| |
| QVBoxLayout *buttonFrameLayout = new QVBoxLayout; |
| buttonFrameLayout->setAlignment(Qt::AlignVCenter); |
| buttonFrameLayout->addLayout(m_buttonLayout); |
| m_buttonFrame->setLayout(buttonFrameLayout); |
| |
| mainLayout->addWidget(m_buttonFrame); |
| } |
| |
| if (hasFixedSize) |
| mainLayout->setSizeConstraint(QLayout::SetFixedSize); |
| else |
| mainLayout->setSizeConstraint(QLayout::SetMinimumSize); |
| |
| setLayout(mainLayout); |
| |
| |
| setWindowFlags(Qt::Tool); |
| |
| |
| if (!m_settings) { |
| TFilePath layoutDir = ToonzFolder::getMyModuleDir(); |
| TFilePath savePath = layoutDir + TFilePath("popups.ini"); |
| m_settings = new QSettings(QString::fromStdWString(savePath.getWideString()), QSettings::IniFormat); |
| } |
| |
| if (name == QString()) |
| return; |
| m_name = name + "DialogGeometry"; |
| QString geo = m_settings->value(m_name).toString(); |
| if (geo != QString()) { |
| QStringList values = geo.split(" "); |
| assert(values.size() == 4); |
| setGeometry(values.at(0).toInt(), std::max(30, values.at(1).toInt()), values.at(2).toInt(), values.at(3).toInt()); |
| } |
| } |
| |
| |
| |
| Dialog::~Dialog() |
| { |
| } |
| |
| |
| void Dialog::moveEvent(QMoveEvent *e) |
| { |
| if (m_name == QString()) |
| return; |
| |
| QRect r = geometry(); |
| m_settings->setValue(m_name, QString::number(r.left()) + " " + QString::number(r.top()) + " " + QString::number(r.width()) + " " + QString::number(r.height())); |
| } |
| |
| |
| |
| void Dialog::resizeEvent(QResizeEvent *e) |
| { |
| if (Preferences::instance()->getCurrentLanguage() != "English") { |
| QSize t = this->size(); |
| QLabel *s; |
| foreach (s, m_labelList) |
| s->setFixedWidth(t.width() * .35); |
| } |
| |
| if (m_name == QString()) |
| return; |
| |
| QRect r = geometry(); |
| m_settings->setValue(m_name, QString::number(r.left()) + " " + QString::number(r.top()) + " " + QString::number(r.width()) + " " + QString::number(r.height())); |
| } |
| |
| |
| |
| |
| |
| |
| void Dialog::hideEvent(QHideEvent *event) |
| { |
| move(pos()); |
| resize(size()); |
| emit dialogClosed(); |
| } |
| |
| |
| |
| |
| void Dialog::beginVLayout() |
| { |
| m_isMainVLayout = true; |
| |
| m_leftVLayout = new QVBoxLayout; |
| m_leftVLayout->setMargin(m_layoutMargin); |
| m_leftVLayout->setSpacing(m_layoutSpacing); |
| |
| m_rightVLayout = new QVBoxLayout; |
| m_rightVLayout->setMargin(m_layoutMargin); |
| m_rightVLayout->setSpacing(m_layoutSpacing); |
| } |
| |
| |
| |
| |
| |
| void Dialog::endVLayout() |
| { |
| if (!m_leftVLayout || !m_rightVLayout) |
| return; |
| m_isMainVLayout = false; |
| |
| QHBoxLayout *layout = new QHBoxLayout; |
| layout->setMargin(m_layoutMargin); |
| layout->setSpacing(m_layoutSpacing); |
| layout->setSizeConstraint(QLayout::SetFixedSize); |
| |
| layout->addLayout(m_leftVLayout); |
| layout->setAlignment(m_leftVLayout, Qt::AlignLeft); |
| layout->addLayout(m_rightVLayout); |
| layout->setAlignment(m_rightVLayout, Qt::AlignLeft); |
| |
| addLayout(layout); |
| |
| m_leftVLayout = 0; |
| m_rightVLayout = 0; |
| } |
| |
| |
| |
| |
| void Dialog::beginHLayout() |
| { |
| m_isMainHLayout = true; |
| m_mainHLayout = new QHBoxLayout; |
| m_mainHLayout->setMargin(m_layoutMargin); |
| m_mainHLayout->setSpacing(m_layoutSpacing); |
| } |
| |
| |
| |
| |
| void Dialog::endHLayout() |
| { |
| m_isMainHLayout = false; |
| if (!m_mainHLayout) |
| return; |
| addLayout(m_mainHLayout); |
| m_mainHLayout = 0; |
| } |
| |
| |
| |
| |
| |
| |
| void Dialog::addWidget(QWidget *widget, bool isRight) |
| { |
| if (m_isMainVLayout) { |
| assert(m_leftVLayout && m_rightVLayout); |
| QWidget *w = new QWidget(); |
| int h = widget->height() + m_layoutSpacing; |
| if (isRight) { |
| m_leftVLayout->addSpacing(h); |
| m_rightVLayout->addWidget(widget); |
| } else { |
| m_leftVLayout->addWidget(widget, 1, Qt::AlignRight); |
| m_rightVLayout->addSpacing(h); |
| } |
| return; |
| } else if (m_isMainHLayout) { |
| assert(m_mainHLayout); |
| m_mainHLayout->addWidget(widget); |
| return; |
| } |
| m_topLayout->addWidget(widget); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void Dialog::addWidgets(QWidget *firstW, QWidget *secondW) |
| { |
| if (m_isMainVLayout) { |
| assert(m_leftVLayout && m_rightVLayout); |
| m_leftVLayout->addWidget(firstW); |
| m_rightVLayout->addWidget(secondW); |
| return; |
| } |
| QHBoxLayout *pairLayout = new QHBoxLayout; |
| pairLayout->setMargin(m_layoutMargin); |
| pairLayout->setSpacing(m_layoutSpacing); |
| pairLayout->addWidget(firstW); |
| pairLayout->addWidget(secondW); |
| |
| if (m_isMainHLayout) { |
| assert(m_mainHLayout); |
| m_mainHLayout->addLayout(pairLayout); |
| return; |
| } |
| addLayout(pairLayout); |
| } |
| |
| |
| |
| |
| |
| |
| void Dialog::addWidget(QString labelName, QWidget *widget) |
| { |
| QLabel *label = new QLabel(labelName); |
| m_labelList.push_back(label); |
| label->setAlignment(Qt::AlignRight | Qt::AlignVCenter); |
| label->setFixedSize(m_labelWidth, widget->height()); |
| addWidgets(label, widget); |
| } |
| |
| |
| |
| |
| |
| |
| void Dialog::addLayout(QLayout *layout, bool isRight) |
| { |
| if (m_isMainVLayout) { |
| assert(m_leftVLayout && m_rightVLayout); |
| int h = layout->itemAt(0)->widget()->height() + m_layoutSpacing; |
| if (isRight) { |
| m_leftVLayout->addSpacing(h); |
| m_rightVLayout->addLayout(layout); |
| } else { |
| m_leftVLayout->addLayout(layout); |
| m_rightVLayout->addSpacing(h); |
| } |
| return; |
| } else if (m_isMainHLayout) { |
| assert(m_mainHLayout); |
| m_mainHLayout->addLayout(layout); |
| return; |
| } |
| m_topLayout->addLayout(layout); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void Dialog::addWidgetLayout(QWidget *widget, QLayout *layout) |
| { |
| layout->setMargin(m_layoutMargin); |
| layout->setSpacing(m_layoutSpacing); |
| |
| if (m_isMainVLayout) { |
| assert(m_leftVLayout && m_rightVLayout); |
| m_leftVLayout->addWidget(widget); |
| m_rightVLayout->addLayout(layout); |
| return; |
| } |
| |
| QHBoxLayout *pairLayout = new QHBoxLayout; |
| pairLayout->setMargin(m_layoutMargin); |
| pairLayout->setSpacing(m_layoutSpacing); |
| pairLayout->addWidget(widget); |
| pairLayout->addLayout(layout); |
| |
| if (m_isMainHLayout) { |
| assert(m_mainHLayout); |
| m_mainHLayout->addLayout(pairLayout); |
| return; |
| } |
| |
| addLayout(pairLayout); |
| } |
| |
| |
| |
| |
| |
| |
| void Dialog::addLayout(QString labelName, QLayout *layout) |
| { |
| QLabel *label = new QLabel(labelName); |
| m_labelList.push_back(label); |
| label->setFixedWidth(m_labelWidth); |
| label->setAlignment(Qt::AlignRight | Qt::AlignVCenter); |
| addWidgetLayout(label, layout); |
| } |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| void Dialog::addLayouts(QLayout *firstL, QLayout *secondL) |
| { |
| firstL->setMargin(m_layoutMargin); |
| firstL->setSpacing(m_layoutSpacing); |
| secondL->setMargin(m_layoutMargin); |
| secondL->setSpacing(m_layoutSpacing); |
| |
| if (m_isMainVLayout) { |
| assert(m_leftVLayout && m_rightVLayout); |
| m_leftVLayout->addLayout(firstL); |
| m_rightVLayout->addLayout(secondL); |
| return; |
| } |
| |
| QHBoxLayout *pairLayout = new QHBoxLayout; |
| pairLayout->setMargin(m_layoutMargin); |
| pairLayout->setSpacing(m_layoutSpacing); |
| pairLayout->addLayout(firstL); |
| pairLayout->addLayout(secondL); |
| |
| if (m_isMainHLayout) { |
| assert(m_mainHLayout); |
| m_mainHLayout->addLayout(pairLayout); |
| return; |
| } |
| |
| addLayout(pairLayout); |
| } |
| |
| |
| |
| |
| void Dialog::addSpacing(int spacing) |
| { |
| if (m_isMainVLayout) { |
| assert(m_leftVLayout && m_rightVLayout); |
| m_leftVLayout->addSpacing(spacing); |
| m_rightVLayout->addSpacing(spacing); |
| return; |
| } else if (m_isMainHLayout) { |
| assert(m_mainHLayout); |
| m_mainHLayout->addSpacing(spacing); |
| return; |
| } |
| m_topLayout->addSpacing(spacing); |
| } |
| |
| |
| |
| |
| |
| |
| void Dialog::addSeparator(QString name) |
| { |
| Separator *separator = new Separator(name); |
| if (m_isMainVLayout) { |
| assert(m_leftVLayout && m_rightVLayout); |
| endVLayout(); |
| addWidget(separator); |
| beginVLayout(); |
| return; |
| } else if (m_isMainHLayout) { |
| assert(m_mainHLayout); |
| separator->setOrientation(false); |
| m_mainHLayout->addWidget(separator); |
| return; |
| } |
| addWidget(separator); |
| } |
| |
| |
| |
| |
| void Dialog::setAlignment(Qt::Alignment alignment) |
| { |
| m_mainFrame->layout()->setAlignment(alignment); |
| } |
| |
| |
| |
| |
| void Dialog::setTopSpacing(int spacing) |
| { |
| m_layoutSpacing = spacing; |
| m_topLayout->setSpacing(spacing); |
| } |
| |
| |
| void Dialog::setLabelWidth(int labelWidth) |
| { |
| m_labelWidth = labelWidth; |
| } |
| |
| |
| |
| |
| |
| void Dialog::setLayoutInsertedSpacing(int spacing) |
| { |
| m_layoutSpacing = spacing; |
| } |
| |
| |
| |
| |
| |
| int Dialog::getLayoutInsertedSpacing() |
| { |
| return m_layoutSpacing; |
| } |
| |
| |
| |
| |
| void Dialog::setTopMargin(int margin) |
| { |
| m_topLayout->setMargin(margin); |
| } |
| |
| |
| |
| |
| void Dialog::setButtonBarMargin(int margin) |
| { |
| m_buttonLayout->setMargin(margin); |
| } |
| |
| |
| |
| |
| void Dialog::setButtonBarSpacing(int spacing) |
| { |
| m_buttonLayout->setSpacing(spacing); |
| } |
| |
| |
| |
| |
| void Dialog::addButtonBarWidget(QWidget *widget) |
| { |
| widget->setMinimumSize(65, 25); |
| assert(m_hasButton); |
| if (m_hasButton) { |
| m_buttonLayout->addWidget(widget); |
| m_buttonBarWidgets.push_back(widget); |
| } |
| } |
| |
| |
| |
| |
| void Dialog::clearButtonBar() |
| { |
| for (int i = 0; i < (int)m_buttonBarWidgets.size(); i++) { |
| m_buttonLayout->removeWidget(m_buttonBarWidgets[i]); |
| } |
| m_buttonBarWidgets.clear(); |
| } |
| |
| |
| |
| |
| void Dialog::addButtonBarWidget(QWidget *first, QWidget *second) |
| { |
| first->setMinimumSize(65, 25); |
| second->setMinimumSize(65, 25); |
| assert(m_hasButton); |
| if (m_hasButton) { |
| m_buttonLayout->addWidget(first); |
| m_buttonLayout->addWidget(second); |
| } |
| } |
| |
| |
| |
| |
| void Dialog::addButtonBarWidget(QWidget *first, QWidget *second, QWidget *third) |
| { |
| first->setMinimumSize(65, 25); |
| second->setMinimumSize(65, 25); |
| third->setMinimumSize(65, 25); |
| assert(m_hasButton); |
| if (m_hasButton) { |
| m_buttonLayout->addWidget(first); |
| m_buttonLayout->addWidget(second); |
| m_buttonLayout->addWidget(third); |
| } |
| } |
| |
| |
| |
| RadioButtonDialog::RadioButtonDialog(const QString &labelText, const QList<QString> &radioButtonList, |
| QWidget *parent, Qt::WindowFlags f) |
| : Dialog(parent, true, true), m_result(1) |
| { |
| setWindowTitle(tr("Toonz")); |
| |
| setMinimumSize(20, 20); |
| |
| beginVLayout(); |
| |
| QLabel *label = new QLabel(labelText); |
| label->setAlignment(Qt::AlignLeft); |
| label->setFixedHeight(2 * WidgetHeight); |
| addWidget(label); |
| |
| QButtonGroup *buttonGroup = new QButtonGroup(this); |
| int i; |
| for (i = 0; i < radioButtonList.count(); i++) { |
| QRadioButton *radioButton = new QRadioButton(radioButtonList.at(i)); |
| if (i == m_result - 1) |
| radioButton->setChecked(true); |
| radioButton->setFixedHeight(WidgetHeight); |
| buttonGroup->addButton(radioButton); |
| buttonGroup->setId(radioButton, i); |
| addWidget(radioButton); |
| } |
| |
| bool ret = connect(buttonGroup, SIGNAL(buttonClicked(int)), SLOT(onButtonClicked(int))); |
| |
| endVLayout(); |
| |
| QPushButton *applyButton = new QPushButton(QObject::tr("Apply")); |
| ret = ret && connect(applyButton, SIGNAL(pressed()), this, SLOT(onApply())); |
| QPushButton *cancelButton = new QPushButton(QObject::tr("Cancel")); |
| ret = ret && connect(cancelButton, SIGNAL(pressed()), this, SLOT(onCancel())); |
| |
| addButtonBarWidget(applyButton, cancelButton); |
| |
| assert(ret); |
| } |
| |
| |
| |
| void RadioButtonDialog::onButtonClicked(int id) |
| { |
| |
| m_result = id + 1; |
| } |
| |
| |
| |
| void RadioButtonDialog::onCancel() |
| { |
| done(0); |
| } |
| |
| |
| |
| void RadioButtonDialog::onApply() |
| { |
| done(m_result); |
| } |
| |
| |
| |
| int DVGui::RadioButtonMsgBox(MsgType type, const QString &labelText, |
| const QList<QString> &radioButtonList, QWidget *parent) |
| { |
| RadioButtonDialog *dialog = new RadioButtonDialog(labelText, radioButtonList, parent); |
| QString msgBoxTitle = getMsgBoxTitle(DVGui::WARNING); |
| dialog->setWindowTitle(msgBoxTitle); |
| return dialog->exec(); |
| } |
| |
| |
| |
| ProgressDialog::ProgressDialog(const QString &labelText, const QString &cancelButtonText, |
| int minimum, int maximum, QWidget *parent, Qt::WindowFlags f) |
| : Dialog(parent, true, true), m_isCanceled(false) |
| { |
| setWindowTitle(tr("Toonz")); |
| |
| setMinimumSize(20, 20); |
| |
| beginVLayout(); |
| |
| m_label = new QLabel(this); |
| m_label->setText(labelText); |
| addWidget(m_label); |
| |
| m_progressBar = new QProgressBar(this); |
| m_progressBar->setRange(minimum, maximum); |
| m_progressBar->setMinimumWidth(250); |
| addWidget(m_progressBar); |
| |
| endVLayout(); |
| |
| if (!cancelButtonText.isEmpty()) |
| setCancelButton(new QPushButton(cancelButtonText)); |
| } |
| |
| |
| |
| void ProgressDialog::setLabelText(const QString &text) |
| { |
| m_label->setText(text); |
| } |
| |
| |
| |
| void ProgressDialog::setCancelButton(QPushButton *cancelButton) |
| { |
| m_cancelButton = cancelButton; |
| bool ret = connect(cancelButton, SIGNAL(pressed()), this, SLOT(onCancel())); |
| ret = ret && connect(cancelButton, SIGNAL(pressed()), this, SIGNAL(canceled())); |
| assert(ret); |
| addButtonBarWidget(m_cancelButton); |
| } |
| |
| |
| |
| int ProgressDialog::maximum() |
| { |
| return m_progressBar->maximum(); |
| } |
| |
| |
| void ProgressDialog::setMaximum(int maximum) |
| { |
| m_progressBar->setMaximum(maximum); |
| } |
| |
| |
| |
| int ProgressDialog::minimum() |
| { |
| return m_progressBar->minimum(); |
| } |
| |
| |
| void ProgressDialog::setMinimum(int minimum) |
| { |
| m_progressBar->setMinimum(minimum); |
| } |
| |
| |
| |
| int ProgressDialog::value() |
| { |
| return m_progressBar->value(); |
| } |
| |
| |
| |
| void ProgressDialog::setValue(int progress) |
| { |
| m_progressBar->setValue(progress); |
| if (isModal()) |
| qApp->processEvents(); |
| } |
| |
| |
| |
| void ProgressDialog::reset() |
| { |
| m_progressBar->reset(); |
| } |
| |
| |
| |
| bool ProgressDialog::wasCanceled() const |
| { |
| return m_isCanceled; |
| } |
| |
| |
| |
| void ProgressDialog::onCancel() |
| { |
| m_isCanceled = true; |
| reset(); |
| hide(); |
| } |
| |
| |
| |
| int DVGui::MsgBox(MsgType type, |
| const QString &text, |
| const std::vector<QString> &buttons, |
| int defaultButtonIndex, |
| QWidget *parent) |
| { |
| Dialog dialog(parent, true); |
| dialog.setWindowFlags(dialog.windowFlags() | Qt::WindowStaysOnTopHint); |
| dialog.setAlignment(Qt::AlignLeft); |
| QString msgBoxTitle = getMsgBoxTitle(type); |
| |
| dialog.setWindowTitle(msgBoxTitle); |
| |
| QLabel *mainTextLabel = new QLabel(text, &dialog); |
| QPixmap iconPixmap = getMsgBoxPixmap(type); |
| if (!iconPixmap.isNull()) { |
| QLabel *iconLabel = new QLabel(&dialog); |
| iconLabel->setPixmap(iconPixmap); |
| |
| QHBoxLayout *mainLayout = new QHBoxLayout; |
| mainLayout->addWidget(iconLabel); |
| mainLayout->addSpacing(16); |
| mainLayout->addWidget(mainTextLabel); |
| dialog.addLayout(mainLayout); |
| } else |
| dialog.addWidget(mainTextLabel); |
| |
| |
| QButtonGroup *buttonGroup = new QButtonGroup(&dialog); |
| |
| for (int i = 0; i < (int)buttons.size(); i++) { |
| QPushButton *button = new QPushButton(buttons[i], &dialog); |
| if (defaultButtonIndex == i) |
| button->setDefault(true); |
| else |
| button->setDefault(false); |
| dialog.addButtonBarWidget(button); |
| |
| buttonGroup->addButton(button, i + 1); |
| } |
| |
| QObject::connect(buttonGroup, SIGNAL(buttonPressed(int)), &dialog, SLOT(done(int))); |
| |
| dialog.raise(); |
| |
| return dialog.exec(); |
| } |
| |
| |
| |
| void DVGui::MsgBoxInPopup(MsgType type, const QString &text) |
| { |
| |
| |
| |
| |
| Q_ASSERT(QApplication::instance()->thread() == QThread::currentThread()); |
| |
| |
| |
| |
| static QList<QPair<MsgType, QString>> messageQueue; |
| static bool popupIsOpen = false; |
| |
| messageQueue.append(qMakePair(type, text)); |
| if (popupIsOpen) |
| return; |
| popupIsOpen = true; |
| |
| Dialog dialog(0, true); |
| |
| dialog.setWindowFlags(dialog.windowFlags() | Qt::WindowStaysOnTopHint); |
| dialog.setAlignment(Qt::AlignLeft); |
| QLabel *mainTextLabel = new QLabel("", &dialog); |
| mainTextLabel->setMinimumWidth(400); |
| QLabel *iconLabel = new QLabel(&dialog); |
| |
| QHBoxLayout *mainLayout = new QHBoxLayout; |
| mainLayout->addWidget(iconLabel); |
| mainLayout->addStretch(); |
| mainLayout->addWidget(mainTextLabel); |
| mainLayout->addStretch(); |
| dialog.addLayout(mainLayout); |
| |
| |
| QButtonGroup *buttonGroup = new QButtonGroup(&dialog); |
| QPushButton *button = new QPushButton(QPushButton::tr("OK"), &dialog); |
| button->setDefault(true); |
| dialog.addButtonBarWidget(button); |
| buttonGroup->addButton(button, 1); |
| QObject::connect(buttonGroup, SIGNAL(buttonPressed(int)), &dialog, SLOT(done(int))); |
| |
| while (!messageQueue.empty()) { |
| MsgType type1 = messageQueue.first().first; |
| QString text1 = messageQueue.first().second; |
| messageQueue.pop_front(); |
| |
| mainTextLabel->setText(text1); |
| |
| QString msgBoxTitle = getMsgBoxTitle(type1); |
| dialog.setWindowTitle(msgBoxTitle); |
| |
| QPixmap iconPixmap = getMsgBoxPixmap(type1); |
| if (!iconPixmap.isNull()) { |
| iconLabel->setPixmap(iconPixmap); |
| iconLabel->setVisible(true); |
| } else { |
| iconLabel->setVisible(false); |
| } |
| |
| dialog.raise(); |
| dialog.exec(); |
| |
| } |
| popupIsOpen = false; |
| } |
| |
| |
| |
| int DVGui::MsgBox(const QString &text, |
| const QString &button1Text, |
| const QString &button2Text, |
| const QString &button3Text, |
| int defaultButtonIndex, |
| QWidget *parent) |
| { |
| Dialog dialog(parent, true); |
| dialog.setWindowFlags(dialog.windowFlags() | Qt::WindowStaysOnTopHint); |
| dialog.setAlignment(Qt::AlignLeft); |
| QString msgBoxTitle = getMsgBoxTitle(QUESTION); |
| dialog.setWindowTitle(msgBoxTitle); |
| |
| QLabel *mainTextLabel = new QLabel(text, &dialog); |
| QPixmap iconPixmap = getMsgBoxPixmap(QUESTION); |
| if (!iconPixmap.isNull()) { |
| QLabel *iconLabel = new QLabel(&dialog); |
| iconLabel->setPixmap(iconPixmap); |
| |
| QHBoxLayout *mainLayout = new QHBoxLayout; |
| mainLayout->addWidget(iconLabel); |
| mainLayout->addSpacing(16); |
| mainLayout->addWidget(mainTextLabel); |
| dialog.addLayout(mainLayout); |
| } else |
| dialog.addWidget(mainTextLabel); |
| |
| |
| QButtonGroup *buttonGroup = new QButtonGroup(&dialog); |
| |
| QPushButton *button1 = new QPushButton(button1Text, &dialog); |
| button1->setDefault(false); |
| if (defaultButtonIndex == 0) |
| button1->setDefault(true); |
| dialog.addButtonBarWidget(button1); |
| buttonGroup->addButton(button1, 1); |
| |
| QPushButton *button2 = new QPushButton(button2Text, &dialog); |
| button2->setDefault(false); |
| if (defaultButtonIndex == 1) |
| button2->setDefault(true); |
| dialog.addButtonBarWidget(button2); |
| buttonGroup->addButton(button2, 2); |
| |
| QPushButton *button3 = new QPushButton(button3Text, &dialog); |
| button3->setDefault(false); |
| if (defaultButtonIndex == 2) |
| button3->setDefault(true); |
| dialog.addButtonBarWidget(button3); |
| buttonGroup->addButton(button3, 3); |
| |
| QObject::connect(buttonGroup, SIGNAL(buttonPressed(int)), &dialog, SLOT(done(int))); |
| dialog.raise(); |
| return dialog.exec(); |
| } |
| |
| |
| |
| int DVGui::MsgBox(const QString &text, |
| const QString &button1, |
| const QString &button2, |
| int defaultButtonIndex, |
| QWidget *parent) |
| { |
| Dialog dialog(parent, true); |
| dialog.setWindowFlags(dialog.windowFlags() | Qt::WindowStaysOnTopHint); |
| std::vector<QString> buttons; |
| buttons.push_back(button1); |
| buttons.push_back(button2); |
| return DVGui::MsgBox(DVGui::QUESTION, text, buttons, defaultButtonIndex, parent); |
| } |
| |
| |
| |
| Dialog *DVGui::createMsgBox(MsgType type, |
| const QString &text, |
| const QStringList &buttons, |
| int defaultButtonIndex, |
| QWidget *parent) |
| { |
| Dialog *dialog = new Dialog(parent, true); |
| dialog->setWindowFlags(dialog->windowFlags() | Qt::WindowStaysOnTopHint); |
| dialog->setAlignment(Qt::AlignLeft); |
| QString msgBoxTitle = getMsgBoxTitle(type); |
| |
| dialog->setWindowTitle(msgBoxTitle); |
| |
| QLabel *mainTextLabel = new QLabel(text, dialog); |
| mainTextLabel->setObjectName("Label"); |
| QPixmap iconPixmap = getMsgBoxPixmap(type); |
| if (!iconPixmap.isNull()) { |
| QLabel *iconLabel = new QLabel(dialog); |
| iconLabel->setPixmap(iconPixmap); |
| |
| QHBoxLayout *mainLayout = new QHBoxLayout; |
| mainLayout->addWidget(iconLabel); |
| mainLayout->addSpacing(16); |
| mainLayout->addWidget(mainTextLabel); |
| dialog->addLayout(mainLayout); |
| } else |
| dialog->addWidget(mainTextLabel); |
| |
| |
| QButtonGroup *buttonGroup = new QButtonGroup(dialog); |
| |
| for (int i = 0; i < (int)buttons.size(); i++) { |
| QPushButton *button = new QPushButton(buttons[i], dialog); |
| if (defaultButtonIndex == i) |
| button->setDefault(true); |
| else |
| button->setDefault(false); |
| dialog->addButtonBarWidget(button); |
| |
| buttonGroup->addButton(button, i + 1); |
| } |
| |
| QObject::connect(buttonGroup, SIGNAL(buttonPressed(int)), dialog, SLOT(done(int))); |
| |
| return dialog; |
| } |
| |
| |
| |
| QString DVGui::getText(const QString &title, const QString &labelText, |
| const QString &text, bool *ok) |
| { |
| Dialog dialog(0, true); |
| |
| dialog.setWindowTitle(title); |
| dialog.setWindowFlags(Qt::WindowStaysOnTopHint | |
| Qt::WindowTitleHint | |
| Qt::CustomizeWindowHint); |
| |
| QVBoxLayout *layout = new QVBoxLayout(&dialog); |
| dialog.addLayout(layout); |
| |
| QLabel *label = new QLabel(labelText, &dialog); |
| layout->addWidget(label); |
| |
| LineEdit *nameFld = new LineEdit(text, &dialog); |
| layout->addWidget(nameFld); |
| |
| QPushButton *okBtn = new QPushButton(dialog.tr("OK"), &dialog); |
| okBtn->setDefault(true); |
| QPushButton *cancelBtn = new QPushButton(dialog.tr("Cancel"), &dialog); |
| QObject::connect(okBtn, SIGNAL(clicked()), &dialog, SLOT(accept())); |
| QObject::connect(cancelBtn, SIGNAL(clicked()), &dialog, SLOT(reject())); |
| |
| dialog.addButtonBarWidget(okBtn, cancelBtn); |
| |
| int ret = dialog.exec(); |
| if (ok) |
| *ok = (ret == QDialog::Accepted); |
| |
| return nameFld->text(); |
| } |
| |
| |
| |
| namespace |
| { |
| bool isStyleIdInPalette(int styleId, const TPalette *palette) |
| { |
| if (palette->getStyleCount() == 0) |
| return false; |
| int i; |
| for (i = 0; i < palette->getPageCount(); i++) { |
| const TPalette::Page *page = palette->getPage(i); |
| if (!page) |
| return false; |
| int j; |
| for (j = 0; j < page->getStyleCount(); j++) |
| if (page->getStyleId(j) == styleId) |
| return true; |
| } |
| return false; |
| } |
| } |
| |
| |
| |
| int DVGui::eraseStylesInDemand(TPalette *palette, const TXsheetHandle *xsheetHandle, TPalette *newPalette) |
| { |
| |
| std::vector<int> styleIds; |
| int h; |
| for (h = 0; h < palette->getPageCount(); h++) { |
| TPalette::Page *page = palette->getPage(h); |
| if (!page) |
| continue; |
| int k; |
| for (k = 0; k < page->getStyleCount(); k++) { |
| int styleId = page->getStyleId(k); |
| bool isStyleIdInNewPalette = (!newPalette) ? false : isStyleIdInPalette(styleId, newPalette); |
| if (styleId > 0 && !isStyleIdInNewPalette) |
| styleIds.push_back(styleId); |
| } |
| } |
| |
| return eraseStylesInDemand(palette, styleIds, xsheetHandle); |
| } |
| |
| |
| |
| int DVGui::eraseStylesInDemand(TPalette *palette, std::vector<int> styleIds, |
| const TXsheetHandle *xsheetHandle) |
| { |
| struct locals { |
| static bool isRasterLevel(const TXshSimpleLevel *level) |
| { |
| return level->getType() == TZP_XSHLEVEL || level->getType() == OVL_XSHLEVEL; |
| } |
| }; |
| |
| |
| std::set<TXshSimpleLevel *> levels; |
| int row, column; |
| findPaletteLevels(levels, row, column, palette, xsheetHandle->getXsheet()); |
| |
| bool someStyleIsUsed = !levels.empty() || styleIds.empty(); |
| if (someStyleIsUsed) |
| someStyleIsUsed = areStylesUsed(levels, styleIds); |
| |
| if (!someStyleIsUsed) |
| return 1; |
| |
| |
| |
| |
| QString question = QObject::tr("Styles you are going to delete are used to paint lines and areas in the animation level.\n") + QObject::tr("How do you want to proceed?"); |
| |
| int ret = DVGui::MsgBox(question, QObject::tr("Delete Styles Only"), |
| QObject::tr("Delete Styles, Lines and Areas"), |
| QObject::tr("Cancel"), 0); |
| if (ret != 2) |
| return (ret == 0 || ret == 3) ? 0 : 1; |
| |
| |
| if (boost::algorithm::any_of(levels, locals::isRasterLevel)) { |
| std::vector<QString> buttons(2); |
| buttons[0] = QObject::tr("Ok"), buttons[1] = QObject::tr("Cancel"); |
| |
| if (DVGui::MsgBox(DVGui::WARNING, |
| QObject::tr("Deletion of Lines and Areas from raster-based levels is not undoable.\n""Are you sure?"), |
| buttons) != 1) |
| return 0; |
| } |
| |
| QApplication::setOverrideCursor(Qt::WaitCursor); |
| PaletteCmd::eraseStyles(levels, styleIds); |
| QApplication::restoreOverrideCursor(); |
| |
| return (assert(ret == 2), ret); |
| } |
| |
| |
| |
| void DVGui::setDialogTitle(const QString &dialogTitle) |
| { |
| DialogTitle = dialogTitle; |
| } |
| |
| |
| |
| |