1 /*
2 	Actiona
3 	Copyright (C) 2005 Jonathan Mercier-Ganady
4 
5 	Actiona is free software: you can redistribute it and/or modify
6 	it under the terms of the GNU General Public License as published by
7 	the Free Software Foundation, either version 3 of the License, or
8 	(at your option) any later version.
9 
10 	Actiona is distributed in the hope that it will be useful,
11 	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 	GNU General Public License for more details.
14 
15 	You should have received a copy of the GNU General Public License
16 	along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 	Contact : jmgr@jmgr.info
19 */
20 
21 #include "progressdialog.h"
22 
23 #include <QScriptValueIterator>
24 #include <QProgressDialog>
25 
26 namespace Code
27 {
constructor(QScriptContext * context,QScriptEngine * engine)28 	QScriptValue ProgressDialog::constructor(QScriptContext *context, QScriptEngine *engine)
29 	{
30 		auto progressDialog = new ProgressDialog;
31 		progressDialog->setupConstructorParameters(context, engine, context->argument(0));
32 
33 		QScriptValueIterator it(context->argument(0));
34 
35 		while(it.hasNext())
36 		{
37 			it.next();
38 
39 			if(it.name() == QLatin1String("value"))
40 				progressDialog->mProgressDialog->setValue(it.value().toInt32());
41 			else if(it.name() == QLatin1String("labelText"))
42 				progressDialog->mProgressDialog->setLabelText(it.value().toString());
43 			else if(it.name() == QLatin1String("minimum"))
44 				progressDialog->mProgressDialog->setMinimum(it.value().toInt32());
45 			else if(it.name() == QLatin1String("maximum"))
46 				progressDialog->mProgressDialog->setMaximum(it.value().toInt32());
47 			else if(it.name() == QLatin1String("range"))
48 			{
49 				progressDialog->mProgressDialog->setMinimum(it.value().property(QStringLiteral("minimum")).toInt32());
50 				progressDialog->mProgressDialog->setMaximum(it.value().property(QStringLiteral("maximum")).toInt32());
51 			}
52 			else if(it.name() == QLatin1String("onCanceled"))
53 				progressDialog->mOnCanceled = it.value();
54 		}
55 
56 		return CodeClass::constructor(progressDialog, context, engine);
57 	}
58 
ProgressDialog()59 	ProgressDialog::ProgressDialog()
60 		: BaseWindow(),
61 		mProgressDialog(new QProgressDialog)
62 	{
63         mProgressDialog->setWindowFlags(mProgressDialog->windowFlags() | Qt::WindowContextHelpButtonHint);
64 
65 		setWidget(mProgressDialog);
66 
67         connect(mProgressDialog, &QProgressDialog::canceled, this, &ProgressDialog::canceled);
68 	}
69 
~ProgressDialog()70 	ProgressDialog::~ProgressDialog()
71 	{
72 		delete mProgressDialog;
73 	}
74 
value() const75 	int ProgressDialog::value() const
76 	{
77 		return mProgressDialog->value();
78 	}
79 
setValue(int value)80 	QScriptValue ProgressDialog::setValue(int value)
81 	{
82 		mProgressDialog->setValue(value);
83 
84 		return thisObject();
85 	}
86 
setLabelText(const QString & labelText)87 	QScriptValue ProgressDialog::setLabelText(const QString &labelText)
88 	{
89 		mProgressDialog->setLabelText(labelText);
90 
91 		return thisObject();
92 	}
93 
setMinimum(int minimum)94 	QScriptValue ProgressDialog::setMinimum(int minimum)
95 	{
96 		mProgressDialog->setMinimum(minimum);
97 
98 		return thisObject();
99 	}
100 
setMaximum(int maximum)101 	QScriptValue ProgressDialog::setMaximum(int maximum)
102 	{
103 		mProgressDialog->setMaximum(maximum);
104 
105 		return thisObject();
106 	}
107 
setRange(int minimum,int maximum)108 	QScriptValue ProgressDialog::setRange(int minimum, int maximum)
109 	{
110 		mProgressDialog->setMinimum(minimum);
111 		mProgressDialog->setMaximum(maximum);
112 
113 		return thisObject();
114 	}
115 
show()116 	QScriptValue ProgressDialog::show()
117 	{
118 		mProgressDialog->open();
119 
120         return thisObject();
121     }
122 
showModal()123 	int ProgressDialog::showModal()
124 	{
125 		return mProgressDialog->exec();
126 	}
127 
canceled()128 	void ProgressDialog::canceled()
129 	{
130 		if(mProgressDialog->isVisible() && mOnCanceled.isValid())
131 			mOnCanceled.call(thisObject());
132 	}
133 }
134