1 /*
2 Drawpile - a collaborative drawing program.
3
4 Copyright (C) 2006-2014 Calle Laakkonen
5
6 Drawpile is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Drawpile is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Drawpile. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "newdialog.h"
21 #include "utils/images.h"
22
23 #include "ui_newdialog.h"
24
25 #include <QPushButton>
26 #include <QSettings>
27 #include <QMessageBox>
28
29 namespace dialogs {
30
NewDialog(QWidget * parent)31 NewDialog::NewDialog(QWidget *parent)
32 : QDialog(parent)
33 {
34 _ui = new Ui_NewDialog;
35 _ui->setupUi(this);
36 _ui->buttons->button(QDialogButtonBox::Ok)->setText(tr("Create"));
37
38 QSettings cfg;
39
40 QSize lastSize = cfg.value("history/newsize", QSize(800, 600)).toSize();
41 if(lastSize.isValid())
42 setSize(lastSize);
43
44 QColor lastColor = cfg.value("history/newcolor").value<QColor>();
45 if(lastColor.isValid())
46 setBackground(lastColor);
47 }
48
~NewDialog()49 NewDialog::~NewDialog()
50 {
51 delete _ui;
52 }
53
setSize(const QSize & size)54 void NewDialog::setSize(const QSize &size)
55 {
56 _ui->width->setValue(size.width());
57 _ui->height->setValue(size.height());
58
59 }
60
setBackground(const QColor & color)61 void NewDialog::setBackground(const QColor &color)
62 {
63 _ui->background->setColor(color);
64 }
65
done(int r)66 void NewDialog::done(int r)
67 {
68 if(r == QDialog::Accepted) {
69 QSize size(_ui->width->value(), _ui->height->value());
70
71 if(!utils::checkImageSize(size)) {
72 QMessageBox::information(this, tr("Error"), tr("Size is too large"));
73 return;
74
75 } else {
76
77 QSettings cfg;
78 cfg.setValue("history/newsize", size);
79 cfg.setValue("history/newcolor", _ui->background->color());
80 emit accepted(size, _ui->background->color());
81
82 }
83
84 }
85
86 QDialog::done(r);
87 }
88
89 }
90
91