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