]> Shamusworld >> Repos - architektonas/blob - src/forms/dlgimageoptions.cpp
391d30cd7c351a09184d9e0ad1e5593e0d5ce66e
[architektonas] / src / forms / dlgimageoptions.cpp
1 // dlgimageoptions.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  05/12/2010  Created this file. :-)
13 //
14
15 #include "dlgimageoptions.h"
16
17 #include "rs_math.h"
18 #include "settings.h"
19
20 ImageOptionsDialog::ImageOptionsDialog(QWidget * parent/*= NULL*/, Qt::WindowFlags flags/*= 0*/):
21         QDialog(parent, flags)
22 {
23         ui.setupUi(this);
24
25         graphicSize = Vector(0.0, 0.0);
26         updateEnabled = true;
27
28         settings.beginGroup("ExportImage");
29         ui.leWidth->setText(settings.value("Width", "640").toString());
30         ui.leHeight->setText(settings.value("Height", "480").toString());
31         ui.rbBlack->setChecked(settings.value("BlackBackground", false).toBool());
32         settings.endGroup();
33 }
34
35 ImageOptionsDialog::~ImageOptionsDialog()
36 {
37 }
38
39 void ImageOptionsDialog::setGraphicSize(const Vector & s)
40 {
41         graphicSize = s;
42 }
43
44 void ImageOptionsDialog::ok()
45 {
46         settings.beginGroup("ExportImage");
47         settings.setValue("Width", ui.leWidth->text());
48         settings.setValue("Height", ui.leHeight->text());
49         settings.setValue("BlackBackground", ui.rbBlack->isChecked());
50         //RS_SETTINGS->writeEntry("/Blackwhite", (int)rbBlackwhite->isChecked());
51         settings.endGroup();
52
53         accept();
54 }
55
56 void ImageOptionsDialog::sizeChanged()
57 {
58         if (updateEnabled)
59         {
60                 updateEnabled = false;
61 //              ui.cbResolution->setCurrentText("auto");
62                 ui.cbResolution->setItemText(ui.cbResolution->currentIndex(), "auto");
63                 updateEnabled = true;
64         }
65 }
66
67 void  ImageOptionsDialog::resolutionChanged()
68 {
69         if (updateEnabled)
70         {
71                 updateEnabled = false;
72                 bool ok = false;
73                 double res = RS_Math::eval(ui.cbResolution->currentText(), &ok);
74
75                 if (!ok)
76                         res = 1.0;
77
78                 int w = RS_Math::round(res * graphicSize.x);
79                 int h = RS_Math::round(res * graphicSize.y);
80                 ui.leWidth->setText(QString("%1").arg(w));
81                 ui.leHeight->setText(QString("%1").arg(h));
82                 updateEnabled = true;
83         }
84 }
85
86 QSize ImageOptionsDialog::getSize()
87 {
88         return QSize(RS_Math::round(RS_Math::eval(ui.leWidth->text())),
89                 RS_Math::round(RS_Math::eval(ui.leHeight->text())));
90 }
91
92 bool ImageOptionsDialog::isBackgroundBlack()
93 {
94         return ui.rbBlack->isChecked();
95 }
96
97 /*bool ImageOptionsDialog::isBlackwhite() {
98         return rbBlackwhite->isChecked();
99 }*/