1 /***************************************************************************
2                          qgsmodelgroupboxdefinitionwidget.cpp
3                          ------------------------------------------
4     begin                : March 2020
5     copyright            : (C) 2020 by Nyall Dawson
6     email                : nyall dot dawson at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 
19 #include "qgsmodelgroupboxdefinitionwidget.h"
20 
21 #include "qgscolorbutton.h"
22 #include "qgsgui.h"
23 #include <QVBoxLayout>
24 #include <QTextEdit>
25 #include <QDialogButtonBox>
26 #include <QLabel>
27 
QgsModelGroupBoxDefinitionDialog(const QgsProcessingModelGroupBox & box,QWidget * parent)28 QgsModelGroupBoxDefinitionDialog::QgsModelGroupBoxDefinitionDialog( const QgsProcessingModelGroupBox &box,
29     QWidget *parent )
30   : QDialog( parent )
31   , mBox( box )
32 {
33   QVBoxLayout *commentLayout = new QVBoxLayout();
34   commentLayout->addWidget( new QLabel( tr( "Title" ) ) );
35   mCommentEdit = new QTextEdit();
36   mCommentEdit->setAcceptRichText( false );
37   mCommentEdit->setText( box.description() );
38   commentLayout->addWidget( mCommentEdit, 1 );
39 
40   QHBoxLayout *hl = new QHBoxLayout();
41   hl->setContentsMargins( 0, 0, 0, 0 );
42   hl->addWidget( new QLabel( tr( "Color" ) ) );
43   mCommentColorButton = new QgsColorButton();
44   mCommentColorButton->setAllowOpacity( true );
45   mCommentColorButton->setWindowTitle( tr( "Comment Color" ) );
46   mCommentColorButton->setShowNull( true, tr( "Default" ) );
47 
48   if ( box.color().isValid() )
49     mCommentColorButton->setColor( box.color() );
50   else
51     mCommentColorButton->setToNull();
52 
53   hl->addWidget( mCommentColorButton );
54   commentLayout->addLayout( hl );
55 
56   QDialogButtonBox *bbox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Ok );
57   connect( bbox, &QDialogButtonBox::accepted, this, &QgsModelGroupBoxDefinitionDialog::accept );
58   connect( bbox, &QDialogButtonBox::rejected, this, &QgsModelGroupBoxDefinitionDialog::reject );
59 
60   commentLayout->addWidget( bbox );
61   setLayout( commentLayout );
62   setWindowTitle( tr( "Group Box Properties" ) );
63   setObjectName( QStringLiteral( "QgsModelGroupBoxDefinitionWidget" ) );
64   QgsGui::enableAutoGeometryRestore( this );
65 
66   mCommentEdit->setFocus();
67   mCommentEdit->selectAll();
68 }
69 
groupBox() const70 QgsProcessingModelGroupBox QgsModelGroupBoxDefinitionDialog::groupBox() const
71 {
72   QgsProcessingModelGroupBox box = mBox;
73   box.setColor( mCommentColorButton->isNull() ? QColor() : mCommentColorButton->color() );
74   box.setDescription( mCommentEdit->toPlainText() );
75   return box;
76 }
77 
78