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) |
11 | {\r |
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); |
29 | pMainLayout->addWidget(lab, 2, 0);\r |
30 | \r |
31 | const int MinNbOfItems = 100000; // to see noticable effect\r |
32 | const int MaxNbOfItems = 1000000; // to avoid too long computations\r |
33 | const int ItemsStep = 100000;\r |
34 | const int MinStep = 50000;\r |
35 | const int StepStep = 50000; |
36 | |
37 | myStartSpin = new QSpinBox(this);\r |
38 | myStartSpin->setMinimum(MinNbOfItems);\r |
39 | myStartSpin->setMaximum(MaxNbOfItems);\r |
40 | myStartSpin->setSingleStep(ItemsStep); |
41 | pMainLayout->addWidget(myStartSpin, 0, 1); |
42 | verify(connect(myStartSpin, SIGNAL(valueChanged(int)), SLOT(checkStepSpinState())));\r |
43 | |
44 | myStopSpin = new QSpinBox(this); |
45 | myStopSpin->setMinimum(MinNbOfItems);\r |
46 | myStopSpin->setMaximum(MaxNbOfItems);\r |
47 | myStartSpin->setSingleStep(ItemsStep);\r |
48 | pMainLayout->addWidget(myStopSpin, 1, 1);\r |
49 | verify(connect(myStopSpin, SIGNAL(valueChanged(int)), SLOT(setStartMaxValue(int))));\r |
50 | verify(connect(myStopSpin, SIGNAL(valueChanged(int)), SLOT(checkStepSpinState())));\r |
51 | \r |
52 | const int StopSpinDefaultValue = 2 * myStartSpin -> minimum();\r |
53 | myStopSpin -> setValue(StopSpinDefaultValue);\r |
54 | myStartSpin -> setMaximum(myStopSpin -> value());\r |
55 | |
56 | myStepSpin = new QSpinBox(this); |
57 | myStepSpin->setMinimum(MinStep);\r |
58 | myStepSpin->setMaximum(MaxNbOfItems - MinNbOfItems);\r |
59 | myStepSpin->setSingleStep(StepStep);\r |
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 | |
71 | QFrame* separator = new QFrame(this);\r |
72 | separator->setFrameStyle(QFrame::HLine | QFrame::Sunken);\r |
73 | pMainLayout->addWidget(separator, 3, 0, 1, 3 );\r |
74 | \r |
75 | QHBoxLayout* hcbox = new QHBoxLayout(); |
76 | hcbox->setSpacing(5);\r |
77 | \r |
78 | myTeCheck = new QCheckBox(tr( "MEN_BTN_TEXT" ), this);\r |
79 | hcbox->addWidget(myTeCheck);\r |
80 | verify(connect(myTeCheck, SIGNAL(clicked()), this, SLOT(onText())));\r |
81 | \r |
82 | hcbox->addSpacing( 5 );\r |
83 | \r |
84 | pMainLayout->addLayout(hcbox, 4, 0, 1, 3);\r |
85 | \r |
86 | QHBoxLayout* hbox = new QHBoxLayout();\r |
87 | hbox->setSpacing(5);\r |
88 | \r |
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); |
99 | pMainLayout->addLayout(hbox, 5, 0, 1, 3);\r |
100 | } |
101 | |
102 | void AutoTestDlg::onStart() |
103 | { |
104 | accept(); |
105 | } |
106 | |
107 | void AutoTestDlg::onCancel() |
108 | { |
109 | reject(); |
110 | }\r |
111 | \r |
112 | void AutoTestDlg::setStartMaxValue(int i)\r |
113 | {\r |
114 | myStartSpin -> setMaximum(i); \r |
115 | if (myStartSpin -> value() > myStartSpin -> maximum())\r |
116 | myStartSpin -> setValue(myStartSpin -> maximum());\r |
117 | }\r |
118 | \r |
119 | void AutoTestDlg::checkStepSpinState()\r |
120 | {\r |
121 | if (isVisible())\r |
122 | {\r |
123 | if (myStartSpin -> value() == myStopSpin -> value())\r |
124 | myStepSpin -> setEnabled(false);\r |
125 | else\r |
126 | myStepSpin -> setEnabled(true);\r |
127 | }\r |
128 | }\r |
129 | \r |
130 | void AutoTestDlg::onText()\r |
131 | {\r |
132 | int MinNbOfItems, MaxNbOfItems, DefaultStartSpinVal, DefaultStopSpinVal,\r |
133 | ItemsStep, MinStep, StepStep;\r |
134 | \r |
135 | if (myTeCheck -> isChecked())\r |
136 | {\r |
137 | MinNbOfItems = 1000; // to see noticeable effect\r |
138 | MaxNbOfItems = 100000; // to avoid too long computations\r |
139 | DefaultStartSpinVal = 10000;\r |
140 | DefaultStopSpinVal = 20000;\r |
141 | ItemsStep = 10000;\r |
142 | MinStep = 5000;\r |
143 | StepStep = 5000;\r |
144 | }\r |
145 | else\r |
146 | {\r |
147 | MinNbOfItems = 100000; // to see noticeable effect\r |
148 | MaxNbOfItems = 1000000; // to avoid too long computations\r |
149 | DefaultStartSpinVal = 100000;\r |
150 | DefaultStopSpinVal = 200000;\r |
151 | ItemsStep = 100000;\r |
152 | MinStep = 50000;\r |
153 | StepStep = 50000;\r |
154 | }\r |
155 | \r |
156 | myStartSpin -> setRange(MinNbOfItems, MaxNbOfItems);\r |
157 | myStartSpin -> setSingleStep(ItemsStep);\r |
158 | myStartSpin -> setValue(DefaultStartSpinVal);\r |
159 | \r |
160 | myStopSpin -> setRange(MinNbOfItems, MaxNbOfItems);\r |
161 | myStopSpin -> setSingleStep(ItemsStep);\r |
162 | \r |
163 | myStopSpin -> setValue(DefaultStopSpinVal);\r |
164 | myStartSpin -> setMaximum(myStopSpin -> value());\r |
165 | \r |
166 | myStepSpin -> setRange(MinStep, MaxNbOfItems - MinNbOfItems);\r |
167 | myStepSpin -> setSingleStep(StepStep);\r |
168 | myStepSpin -> setValue(MinStep);\r |
169 | } |