File: PaperDialog.cpp

package info (click to toggle)
herculesstudio 1.5.0-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,376 kB
  • sloc: cpp: 17,077; xml: 21; makefile: 13
file content (98 lines) | stat: -rw-r--r-- 2,234 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "PaperDialog.h"
#include "ui_PaperDialog.h"
#include "HerculesStudio.h"

#include <QSpinBox>

#include <sstream>

class InchesSpinBox : public QSpinBox
{
public:
    InchesSpinBox(QWidget * parent=0);
protected:
    virtual int valueFromText(const QString &text) const;
    virtual QString textFromValue(int val) const;
private:
    mutable int mNumerator; // deniminator is always 16
};

InchesSpinBox::InchesSpinBox(QWidget *parent) : QSpinBox(parent)
{
    mNumerator = 8;
    setRange(1,32);
    setSingleStep(1);
    setValue(mNumerator);
}

int InchesSpinBox::valueFromText(const QString &text) const
{
    int slashPos = text.indexOf('/');
    bool ok;

    int numerator = text.left(slashPos).toInt(&ok);
    hOutDebug(0, "den=" << numerator << " OK=" << (ok? "Y" : "N"));
    if (!ok) return 8;

    int denominator = text.mid(slashPos+1).toInt(&ok);
    hOutDebug(0, "den=" << denominator << " OK=" << (ok? "Y" : "N"));
    if (!ok) return 8;

    if (denominator%2) return mNumerator;
    if (denominator == 2) mNumerator = numerator * 8;
    else if (denominator == 4) mNumerator = numerator * 4;
    else if (denominator == 8) mNumerator = numerator * 2;
    else mNumerator = numerator;
    return mNumerator;
}

QString InchesSpinBox::textFromValue(int val) const
{
    std::stringstream ss;
    hOutDebug(0, "Value=" << val);

    if ((val%16) == 0)
    {
        ss << (val/16) ;
    }
    else if ((val%8) == 0)
    {
        ss << (val/8) << "/" << "2";
    }
    else if ((val%4) == 0)
    {
        ss << (val/4) << "/" << "4";
    }
    else if ((val%2) == 0)
    {
        ss << (val/2) << "/" << "8";
    }
    else\
    {
        ss << val << "/" << "16";
    }
    //ss << "  (" << val << "/16)";

    hOutDebug(0, "text=" << ss.str());
    return ss.str().c_str();
}


PaperDialog::PaperDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::PaperDialog)
{
    ui->setupUi(this);

    InchesSpinBox* topMarginSpinBox;
    topMarginSpinBox = new InchesSpinBox(this);
    topMarginSpinBox->setObjectName(QStringLiteral("topMarginSpinBox"));
    topMarginSpinBox->setGeometry(QRect(160, 250, 120, 31));
    topMarginSpinBox->setSingleStep(1);
}

PaperDialog::~PaperDialog()
{
    delete ui;
}