! Checks whether the size is one of the QPageSize::PageSizeId and updates Size and Orientation checkbox when width/height changes. */
| 206 | updates Size and Orientation checkbox when width/height changes. |
| 207 | */ |
| 208 | void WorksheetDock::updatePaperSize() { |
| 209 | if (m_worksheet->useViewSize()) { |
| 210 | ui.cbSizeType->setCurrentIndex(ui.cbSizeType->findData((int)SizeType::ViewSize)); |
| 211 | return; |
| 212 | } |
| 213 | |
| 214 | double w = ui.sbWidth->value(); |
| 215 | double h = ui.sbHeight->value(); |
| 216 | if (m_units == Units::Metric) { |
| 217 | // In UI we use cm, so we need to convert to mm first before we check with QPageSize |
| 218 | w *= 10; |
| 219 | h *= 10; |
| 220 | } |
| 221 | |
| 222 | const QSizeF s = QSizeF(w, h); |
| 223 | const QSizeF st = s.transposed(); |
| 224 | |
| 225 | // determine the position of the QPageSize::PageSizeId in the combobox |
| 226 | bool found = false; |
| 227 | for (int i = 0; i < ui.cbPage->count(); ++i) { |
| 228 | const QVariant v = ui.cbPage->itemData(i); |
| 229 | if (!v.isValid()) |
| 230 | continue; |
| 231 | |
| 232 | const auto id = v.value<QPageSize::PageSizeId>(); |
| 233 | QPageSize::Unit pageUnit = (m_units == Units::Metric) ? QPageSize::Millimeter : QPageSize::Inch; |
| 234 | const QSizeF ps = QPageSize::size(id, pageUnit); |
| 235 | if (s == ps) { // check the portrait-orientation first |
| 236 | ui.cbPage->setCurrentIndex(i); |
| 237 | ui.cbOrientation->setCurrentIndex(0); // a QPageSize::PaperSize in portrait-orientation was found |
| 238 | found = true; |
| 239 | break; |
| 240 | } else if (st == ps) { // check for the landscape-orientation |
| 241 | ui.cbPage->setCurrentIndex(i); |
| 242 | ui.cbOrientation->setCurrentIndex(1); // a QPageSize::PaperSize in landscape-orientation was found |
| 243 | found = true; |
| 244 | break; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | if (!found) |
| 249 | ui.cbSizeType->setCurrentIndex(ui.cbSizeType->findData((int)SizeType::Custom)); |
| 250 | else |
| 251 | ui.cbSizeType->setCurrentIndex(ui.cbSizeType->findData((int)SizeType::StandardPage)); |
| 252 | } |
| 253 | |
| 254 | void WorksheetDock::retranslateUi() { |
| 255 | CONDITIONAL_LOCK_RETURN; |
nothing calls this directly
no test coverage detected