Debian Codegraph @

HercPrinter/PaperDialog.cpp

raw symbols SCIP
1 #include "PaperDialog.h"
2 #include "ui_PaperDialog.h"
3 #include "HerculesStudio.h"
4
5 #include <QSpinBox>
6
7 #include <sstream>
8
9 class InchesSpinBox : public QSpinBox
10 {
11 public:
12 InchesSpinBox(QWidget * parent=0);
13 protected:
14 virtual int valueFromText(const QString &text) const;
15 virtual QString textFromValue(int val) const;
16 private:
17 mutable int mNumerator; // deniminator is always 16
18 };
19
20 InchesSpinBox::InchesSpinBox(QWidget *parent) : QSpinBox(parent)
21 {
22 mNumerator = 8;
23 setRange(1,32);
24 setSingleStep(1);
25 setValue(mNumerator);
26 }
27
28 int InchesSpinBox::valueFromText(const QString &text) const
29 {
30 int slashPos = text.indexOf('/');
31 bool ok;
32
33 int numerator = text.left(slashPos).toInt(&ok);
34 hOutDebug(0, "den=" << numerator << " OK=" << (ok? "Y" : "N"));
35 if (!ok) return 8;
36
37 int denominator = text.mid(slashPos+1).toInt(&ok);
38 hOutDebug(0, "den=" << denominator << " OK=" << (ok? "Y" : "N"));
39 if (!ok) return 8;
40
41 if (denominator%2) return mNumerator;
42 if (denominator == 2) mNumerator = numerator * 8;
43 else if (denominator == 4) mNumerator = numerator * 4;
44 else if (denominator == 8) mNumerator = numerator * 2;
45 else mNumerator = numerator;
46 return mNumerator;
47 }
48
49 QString InchesSpinBox::textFromValue(int val) const
50 {
51 std::stringstream ss;
52 hOutDebug(0, "Value=" << val);
53
54 if ((val%16) == 0)
55 {
56 ss << (val/16) ;
57 }
58 else if ((val%8) == 0)
59 {
60 ss << (val/8) << "/" << "2";
61 }
62 else if ((val%4) == 0)
63 {
64 ss << (val/4) << "/" << "4";
65 }
66 else if ((val%2) == 0)
67 {
68 ss << (val/2) << "/" << "8";
69 }
70 else\
71 {
72 ss << val << "/" << "16";
73 }
74 //ss << " (" << val << "/16)";
75
76 hOutDebug(0, "text=" << ss.str());
77 return ss.str().c_str();
78 }
79
80
81 PaperDialog::PaperDialog(QWidget *parent) :
82 QDialog(parent),
83 ui(new Ui::PaperDialog)
84 {
85 ui->setupUi(this);
86
87 InchesSpinBox* topMarginSpinBox;
88 topMarginSpinBox = new InchesSpinBox(this);
89 topMarginSpinBox->setObjectName(QStringLiteral("topMarginSpinBox"));
90 topMarginSpinBox->setGeometry(QRect(160, 250, 120, 31));
91 topMarginSpinBox->setSingleStep(1);
92 }
93
94 PaperDialog::~PaperDialog()
95 {
96 delete ui;
97 }
98