! fills the ComboBox \c combobox with the six possible Qt::PenStyles, the color \c color is used. */
| 54 | fills the ComboBox \c combobox with the six possible Qt::PenStyles, the color \c color is used. |
| 55 | */ |
| 56 | void GuiTools::updatePenStyles(QComboBox* comboBox, const QColor& color) { |
| 57 | int index = comboBox->currentIndex(); |
| 58 | comboBox->clear(); |
| 59 | |
| 60 | QPainter pa; |
| 61 | int offset = 2; |
| 62 | int w = 50; |
| 63 | int h = 10; |
| 64 | QPixmap pm(w, h); |
| 65 | comboBox->setIconSize(QSize(w, h)); |
| 66 | |
| 67 | // loop over six possible Qt-PenStyles, draw on the pixmap and insert it |
| 68 | // TODO: avoid copy-paste in all finctions! |
| 69 | static std::array<QString, 6> list = |
| 70 | {i18n("No Line"), i18n("Solid Line"), i18n("Dash Line"), i18n("Dot Line"), i18n("Dash-dot Line"), i18n("Dash-dot-dot Line")}; |
| 71 | for (int i = 0; i < 6; i++) { |
| 72 | pm.fill(Qt::transparent); |
| 73 | pa.begin(&pm); |
| 74 | pa.setPen(QPen(color, 1, (Qt::PenStyle)i)); |
| 75 | pa.drawLine(offset, h / 2, w - offset, h / 2); |
| 76 | pa.end(); |
| 77 | comboBox->addItem(QIcon(pm), list[i]); |
| 78 | } |
| 79 | comboBox->setCurrentIndex(index); |
| 80 | } |
| 81 | |
| 82 | /*! |
| 83 | fills the QMenu \c menu with the six possible Qt::PenStyles, the color \c color is used. |
nothing calls this directly
no test coverage detected