7fd59977 |
1 | #include <qlayout.h> |
2 | #include <qlabel.h> |
3 | #include <qpushbutton.h> |
4 | |
5 | #include "Application.h" |
6 | #include "AutoTestDlg.h" |
7 | #include "global.h" |
8 | |
9 | AutoTestDlg::AutoTestDlg(QWidget* parent) |
10 | : QDialog(parent) |
c6c9371f |
11 | { |
7fd59977 |
12 | setModal( true ); |
13 | setWindowTitle(tr("DLG_AUTO_TEST")); |
14 | QString dir = Application::getResourceDir(); |
15 | QPixmap autoIcon( dir + tr( "ICON_AUTO_TEST" ) ); |
16 | setWindowIcon(autoIcon); |
17 | |
18 | QGridLayout* pMainLayout = new QGridLayout(this); |
19 | pMainLayout->setMargin(5); |
20 | pMainLayout->setSpacing(5); |
21 | |
22 | QLabel* lab = new QLabel(tr("LAB_START"), this); |
23 | pMainLayout->addWidget(lab, 0, 0); |
24 | |
25 | lab = new QLabel(tr("LAB_STOP"), this); |
26 | pMainLayout->addWidget(lab, 1, 0); |
27 | |
28 | lab = new QLabel(tr("LAB_STEP"), this); |
c6c9371f |
29 | pMainLayout->addWidget(lab, 2, 0); |
30 | |
31 | const int MinNbOfItems = 100000; // to see noticable effect |
32 | const int MaxNbOfItems = 1000000; // to avoid too long computations |
33 | const int ItemsStep = 100000; |
34 | const int MinStep = 50000; |
7fd59977 |
35 | const int StepStep = 50000; |
36 | |
c6c9371f |
37 | myStartSpin = new QSpinBox(this); |
38 | myStartSpin->setMinimum(MinNbOfItems); |
39 | myStartSpin->setMaximum(MaxNbOfItems); |
7fd59977 |
40 | myStartSpin->setSingleStep(ItemsStep); |
41 | pMainLayout->addWidget(myStartSpin, 0, 1); |
c6c9371f |
42 | verify(connect(myStartSpin, SIGNAL(valueChanged(int)), SLOT(checkStepSpinState()))); |
7fd59977 |
43 | |
44 | myStopSpin = new QSpinBox(this); |
c6c9371f |
45 | myStopSpin->setMinimum(MinNbOfItems); |
46 | myStopSpin->setMaximum(MaxNbOfItems); |
47 | myStartSpin->setSingleStep(ItemsStep); |
48 | pMainLayout->addWidget(myStopSpin, 1, 1); |
49 | verify(connect(myStopSpin, SIGNAL(valueChanged(int)), SLOT(setStartMaxValue(int)))); |
50 | verify(connect(myStopSpin, SIGNAL(valueChanged(int)), SLOT(checkStepSpinState()))); |
51 | |
52 | const int StopSpinDefaultValue = 2 * myStartSpin -> minimum(); |
53 | myStopSpin -> setValue(StopSpinDefaultValue); |
54 | myStartSpin -> setMaximum(myStopSpin -> value()); |
7fd59977 |
55 | |
56 | myStepSpin = new QSpinBox(this); |
c6c9371f |
57 | myStepSpin->setMinimum(MinStep); |
58 | myStepSpin->setMaximum(MaxNbOfItems - MinNbOfItems); |
59 | myStepSpin->setSingleStep(StepStep); |
7fd59977 |
60 | pMainLayout->addWidget(myStepSpin, 2, 1); |
61 | |
62 | lab = new QLabel(tr("LAB_ITEMS"), this); |
63 | pMainLayout->addWidget(lab, 0, 2); |
64 | |
65 | lab = new QLabel(tr("LAB_ITEMS"), this); |
66 | pMainLayout->addWidget(lab, 1, 2); |
67 | |
68 | lab = new QLabel(tr("LAB_ITEMS"), this); |
69 | pMainLayout->addWidget(lab, 2, 2); |
70 | |
c6c9371f |
71 | QFrame* separator = new QFrame(this); |
72 | separator->setFrameStyle(QFrame::HLine | QFrame::Sunken); |
73 | pMainLayout->addWidget(separator, 3, 0, 1, 3 ); |
74 | |
7fd59977 |
75 | QHBoxLayout* hcbox = new QHBoxLayout(); |
c6c9371f |
76 | hcbox->setSpacing(5); |
77 | |
78 | myTeCheck = new QCheckBox(tr( "MEN_BTN_TEXT" ), this); |
79 | hcbox->addWidget(myTeCheck); |
80 | verify(connect(myTeCheck, SIGNAL(clicked()), this, SLOT(onText()))); |
81 | |
82 | hcbox->addSpacing( 5 ); |
83 | |
84 | pMainLayout->addLayout(hcbox, 4, 0, 1, 3); |
85 | |
86 | QHBoxLayout* hbox = new QHBoxLayout(); |
87 | hbox->setSpacing(5); |
88 | |
7fd59977 |
89 | QPushButton* btn = new QPushButton(tr("BTN_START"), this); |
90 | // btn->setDefault(true); |
91 | verify(connect(btn, SIGNAL(clicked()), this, SLOT(onStart()))); |
92 | btn->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); |
93 | hbox->addWidget(btn); |
94 | btn = new QPushButton(tr("BTN_CANCEL"), this); |
95 | verify(connect(btn, SIGNAL(clicked()), this, SLOT(onCancel()))); |
96 | btn->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum)); |
97 | hbox->addWidget(btn); |
98 | hbox->addSpacing(5); |
c6c9371f |
99 | pMainLayout->addLayout(hbox, 5, 0, 1, 3); |
7fd59977 |
100 | } |
101 | |
102 | void AutoTestDlg::onStart() |
103 | { |
104 | accept(); |
105 | } |
106 | |
107 | void AutoTestDlg::onCancel() |
108 | { |
109 | reject(); |
c6c9371f |
110 | } |
111 | |
112 | void AutoTestDlg::setStartMaxValue(int i) |
113 | { |
114 | myStartSpin -> setMaximum(i); |
115 | if (myStartSpin -> value() > myStartSpin -> maximum()) |
116 | myStartSpin -> setValue(myStartSpin -> maximum()); |
117 | } |
118 | |
119 | void AutoTestDlg::checkStepSpinState() |
120 | { |
121 | if (isVisible()) |
122 | { |
123 | if (myStartSpin -> value() == myStopSpin -> value()) |
124 | myStepSpin -> setEnabled(false); |
125 | else |
126 | myStepSpin -> setEnabled(true); |
127 | } |
128 | } |
129 | |
130 | void AutoTestDlg::onText() |
131 | { |
132 | int MinNbOfItems, MaxNbOfItems, DefaultStartSpinVal, DefaultStopSpinVal, |
133 | ItemsStep, MinStep, StepStep; |
134 | |
135 | if (myTeCheck -> isChecked()) |
136 | { |
137 | MinNbOfItems = 1000; // to see noticeable effect |
138 | MaxNbOfItems = 100000; // to avoid too long computations |
139 | DefaultStartSpinVal = 10000; |
140 | DefaultStopSpinVal = 20000; |
141 | ItemsStep = 10000; |
142 | MinStep = 5000; |
143 | StepStep = 5000; |
144 | } |
145 | else |
146 | { |
147 | MinNbOfItems = 100000; // to see noticeable effect |
148 | MaxNbOfItems = 1000000; // to avoid too long computations |
149 | DefaultStartSpinVal = 100000; |
150 | DefaultStopSpinVal = 200000; |
151 | ItemsStep = 100000; |
152 | MinStep = 50000; |
153 | StepStep = 50000; |
154 | } |
155 | |
156 | myStartSpin -> setRange(MinNbOfItems, MaxNbOfItems); |
157 | myStartSpin -> setSingleStep(ItemsStep); |
158 | myStartSpin -> setValue(DefaultStartSpinVal); |
159 | |
160 | myStopSpin -> setRange(MinNbOfItems, MaxNbOfItems); |
161 | myStopSpin -> setSingleStep(ItemsStep); |
162 | |
163 | myStopSpin -> setValue(DefaultStopSpinVal); |
164 | myStartSpin -> setMaximum(myStopSpin -> value()); |
165 | |
166 | myStepSpin -> setRange(MinStep, MaxNbOfItems - MinNbOfItems); |
167 | myStepSpin -> setSingleStep(StepStep); |
168 | myStepSpin -> setValue(MinStep); |
7fd59977 |
169 | } |