| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qtgradientviewdialog_p.h" |
| 5 | #include "qtgradientmanager_p.h" |
| 6 | #include <QtWidgets/QPushButton> |
| 7 | |
| 8 | QT_BEGIN_NAMESPACE |
| 9 | |
| 10 | QtGradientViewDialog::QtGradientViewDialog(QWidget *parent) |
| 11 | : QDialog(parent) |
| 12 | { |
| 13 | m_ui.setupUi(this); |
| 14 | m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); |
| 15 | connect(m_ui.gradientView, &QtGradientView::currentGradientChanged, |
| 16 | this, &QtGradientViewDialog::slotGradientSelected); |
| 17 | connect(m_ui.gradientView, &QtGradientView::gradientActivated, |
| 18 | this, &QtGradientViewDialog::slotGradientActivated); |
| 19 | } |
| 20 | |
| 21 | void QtGradientViewDialog::setGradientManager(QtGradientManager *manager) |
| 22 | { |
| 23 | m_ui.gradientView->setGradientManager(manager); |
| 24 | } |
| 25 | |
| 26 | QGradient QtGradientViewDialog::getGradient(bool *ok, QtGradientManager *manager, QWidget *parent, const QString &caption) |
| 27 | { |
| 28 | QtGradientViewDialog dlg(parent); |
| 29 | dlg.setGradientManager(manager); |
| 30 | dlg.setWindowTitle(caption); |
| 31 | QGradient grad = QLinearGradient(); |
| 32 | const int res = dlg.exec(); |
| 33 | if (res == QDialog::Accepted) |
| 34 | grad = dlg.m_ui.gradientView->gradientManager()->gradients().value(dlg.m_ui.gradientView->currentGradient()); |
| 35 | if (ok) |
| 36 | *ok = res == QDialog::Accepted; |
| 37 | return grad; |
| 38 | } |
| 39 | |
| 40 | void QtGradientViewDialog::slotGradientSelected(const QString &id) |
| 41 | { |
| 42 | m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!id.isEmpty()); |
| 43 | } |
| 44 | |
| 45 | void QtGradientViewDialog::slotGradientActivated(const QString &id) |
| 46 | { |
| 47 | Q_UNUSED(id); |
| 48 | accept(); |
| 49 | } |
| 50 | |
| 51 | QT_END_NAMESPACE |
| 52 |
