File indexing completed on 2024-05-26 04:30:24

0001 /*
0002  *  SPDX-FileCopyrightText: 2013 Sven Langkamp <sven.langkamp@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 
0008 
0009 #ifndef KIS_OPERATION_UI_WIDGET_FACTORY_H
0010 #define KIS_OPERATION_UI_WIDGET_FACTORY_H
0011 
0012 #include <KoDialog.h>
0013 #include <klocalizedstring.h>
0014 
0015 #include "kis_operation_ui_factory.h"
0016 #include "operations/kis_operation_ui_widget.h"
0017 #include "KisViewManager.h"
0018 
0019 
0020 /**
0021  *  Factory to get operation configurations from QWidget based operation widgets
0022  *  T has to be a KisOperationUIWidget
0023  */
0024 template <class T> class KisOperationUIWidgetFactory : public KisOperationUIFactory
0025 {
0026 
0027 public:
0028     KisOperationUIWidgetFactory(const QString &id)
0029         : KisOperationUIFactory(id)
0030         , m_configuration(nullptr)
0031     {
0032     }
0033     
0034     ~KisOperationUIWidgetFactory() override
0035     {
0036     }
0037 
0038     /**
0039     *  Reimplemented. Show a dialog the widget specify as T
0040     *  @param view the view
0041     *  @param configuration the configuration to the operation
0042     *  @returns true if the configuration could be constructed (not canceled)
0043     */
0044     bool fetchConfiguration(KisViewManager* view, KisOperationConfigurationSP configuration) override {
0045         KoDialog * dialog = new KoDialog(view->mainWindowAsQWidget());
0046         Q_CHECK_PTR(dialog);
0047 
0048         T* configWidget = new T(dialog, view, m_configuration ? m_configuration : configuration);
0049         dialog->setCaption(configWidget->caption());
0050         dialog->setMainWidget(configWidget);
0051         bool success = false;
0052         if (dialog->exec() == QDialog::Accepted) {
0053             configWidget->getConfiguration(configuration);
0054             m_configuration = configuration;
0055             success = true;
0056         }
0057         delete dialog;
0058 
0059         return success;
0060     }
0061 
0062 private:
0063     KisOperationConfigurationSP m_configuration;
0064 };
0065 
0066 #endif // KIS_OPERATION_UI_WIDGET_FACTORY_H