1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 /**************************************************************************
8 *   Copyright (C) 2009 by Franz Schmid                                    *
9 *   franz.schmid@altmuehlnet.de                                           *
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 *   This program is distributed in the hope that it will be useful,       *
17 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
18 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
19 *   GNU General Public License for more details.                          *
20 *                                                                         *
21 *   You should have received a copy of the GNU General Public License     *
22 *   along with this program; if not, write to the                         *
23 *   Free Software Foundation, Inc.,                                       *
24 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
25 ***************************************************************************/
26 
27 #include "gradientaddedit.h"
28 #include "ui/scmessagebox.h"
29 #include <QMessageBox>
30 
gradientEditDialog(QWidget * parent,const QString & name,const VGradient & gradient,ColorList doco,ScribusDoc * doc,QHash<QString,VGradient> * gradients,bool newFlag)31 gradientEditDialog::gradientEditDialog(QWidget* parent, const QString& name, const VGradient& gradient, ColorList doco, ScribusDoc *doc, QHash<QString, VGradient> *gradients, bool newFlag) : QDialog(parent)
32 {
33 	setupUi(this);
34 	setModal(true);
35 	editor->setColors(doco);
36 	editor->setGradient(gradient);
37 	gradientName->setText(name);
38 	m_doc = doc;
39 	m_name = name;
40 	m_gradients = gradients;
41 	isNew = newFlag;
42 	connect(buttonBox, SIGNAL(accepted()), this, SLOT(quitDialog()));
43 }
44 
name()45 QString gradientEditDialog::name()
46 {
47 	return gradientName->text();
48 }
49 
gradient()50 VGradient gradientEditDialog::gradient()
51 {
52 	return editor->gradient();
53 }
54 
quitDialog()55 void gradientEditDialog::quitDialog()
56 {
57 	if (gradientName->text().isEmpty())
58 	{
59 		ScMessageBox::information(this, CommonStrings::trWarning, tr("You cannot create a gradient without a name\nPlease give it a name"));
60 		gradientName->setFocus();
61 		gradientName->selectAll();
62 		return;
63 	}
64 	if ((m_name != gradientName->text()) || (isNew))
65 	{
66 		if (m_gradients->contains(gradientName->text()))
67 		{
68 			ScMessageBox::information(this, CommonStrings::trWarning, tr("The name of the gradient already exists,\nplease choose another one."));
69 			gradientName->selectAll();
70 			gradientName->setFocus();
71 			return;
72 		}
73 	}
74 	accept();
75 }
76