Changeset View
Changeset View
Standalone View
Standalone View
testclient/widgets/axiscontrol.cpp
Show First 20 Lines • Show All 144 Lines • ▼ Show 20 Line(s) | |||||
145 | void AxisControl::resizeEvent(QResizeEvent *) | 145 | void AxisControl::resizeEvent(QResizeEvent *) | ||
146 | { | 146 | { | ||
147 | fitInView(sceneRect(), Qt::KeepAspectRatio); | 147 | fitInView(sceneRect(), Qt::KeepAspectRatio); | ||
148 | } | 148 | } | ||
149 | 149 | | |||
150 | void AxisControl::setLabels(QGraphicsItem *item, QLatin1Char axis, int value) | 150 | void AxisControl::setLabels(QGraphicsItem *item, QLatin1Char axis, int value) | ||
151 | { | 151 | { | ||
152 | auto *lb = new QGraphicsSimpleTextItem(); | 152 | auto *lb = new QGraphicsSimpleTextItem(); | ||
153 | | ||||
154 | lb->setBrush(palette().buttonText()); | 153 | lb->setBrush(palette().buttonText()); | ||
155 | 154 | | |||
156 | if (this->logicalDpiX() <= 96) { | 155 | if (this->logicalDpiX() <= 96) { | ||
157 | lb->setText((value < 0) ? QStringLiteral(" -") + axis : QStringLiteral(" ") + axis); | 156 | lb->setText((value < 0) ? QStringLiteral(" -") + axis : QStringLiteral(" ") + axis); | ||
158 | } else { | 157 | } else { | ||
159 | lb->setText((value < 0) ? QStringLiteral("-") + axis : QStringLiteral(" ") + axis); | 158 | lb->setText((value < 0) ? QStringLiteral("-") + axis : QStringLiteral(" ") + axis); | ||
160 | } | 159 | } | ||
161 | 160 | | |||
162 | if (axis.toLatin1() == 'X') { | 161 | if (axis.toLatin1() == 'X') { | ||
163 | lb->setY(item->y() - lb->boundingRect().width()); | 162 | lb->setY(item->y() - lb->boundingRect().width()); | ||
164 | if (value < 0) { | 163 | if (value < 0) { | ||
165 | lb->setX(item->x() - item->boundingRect().width() / 1.2 - lb->boundingRect().width() / 2); | 164 | lb->setX(item->x() - item->boundingRect().width() / 1.2 - lb->boundingRect().width() / 2); | ||
166 | } else { | 165 | } else { | ||
167 | lb->setX(item->x() + item->boundingRect().width() / 1.2 - lb->boundingRect().width() / 2); | 166 | lb->setX(item->x() + item->boundingRect().width() / 1.2 - lb->boundingRect().width() / 2); | ||
168 | } | 167 | } | ||
169 | } else if (axis.toLatin1() == 'Y') { | 168 | } else if (axis.toLatin1() == 'Y') { | ||
170 | lb->setX(item->x() - lb->boundingRect().width() / 2); | 169 | lb->setX(item->x() - lb->boundingRect().width() / 2); | ||
171 | if (value < 0) { | 170 | if (value < 0) { | ||
172 | lb->setY(item->y() + item->boundingRect().height() / 1.5); | 171 | lb->setY(item->y() + item->boundingRect().height() / 1.5); | ||
173 | } else { | 172 | } else { | ||
174 | lb->setY(item->y() - item->boundingRect().height()); | 173 | lb->setY(item->y() - item->boundingRect().height()); | ||
175 | } | 174 | } | ||
176 | } else { | 175 | } else { | ||
177 | 176 | #ifndef Q_OS_WIN | |||
178 | if (value < 0) { | 177 | if (value < 0) { | ||
179 | lb->setX(item->x() + lb->boundingRect().width() / fontMetrics().width(lb->text())); | 178 | lb->setX(item->x() + lb->boundingRect().width() / fontMetrics().width(lb->text())); | ||
180 | lb->setY(item->y() - lb->boundingRect().height() / fontMetrics().xHeight()); | 179 | lb->setY(item->y() - lb->boundingRect().height() / fontMetrics().xHeight()); | ||
181 | } else { | 180 | } else { | ||
182 | lb->setX(item->x() + lb->boundingRect().width() / fontMetrics().width(lb->text())); | 181 | lb->setX(item->x() + lb->boundingRect().width() / fontMetrics().width(lb->text())); | ||
183 | lb->setY(item->y() - lb->boundingRect().height() / fontMetrics().xHeight()); | 182 | lb->setY(item->y() - lb->boundingRect().height() / fontMetrics().xHeight()); | ||
184 | } | 183 | } | ||
184 | #else | ||||
185 | if (value < 0) { | ||||
186 | lb->setX(item->x() + lb->boundingRect().width() / fontMetrics().width(lb->text())); | ||||
187 | lb->setY(item->y() - lb->boundingRect().height() / fontMetrics().height()); | ||||
188 | } else { | ||||
189 | lb->setX(item->x() + lb->boundingRect().width() / fontMetrics().width(lb->text())); | ||||
190 | lb->setY(item->y() - lb->boundingRect().height() / fontMetrics().height()); | ||||
191 | } | ||||
192 | #endif | ||||
185 | } | 193 | } | ||
186 | scene()->addItem(lb); | 194 | scene()->addItem(lb); | ||
187 | } | 195 | } |