2016-12-06 01:48:26 +01:00
|
|
|
#include <QPen>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QResizeEvent>
|
2022-11-04 09:03:36 +01:00
|
|
|
#include "common/util.h"
|
2016-12-06 01:48:26 +01:00
|
|
|
#include "stylecombobox.h"
|
|
|
|
|
2016-12-06 21:01:06 +01:00
|
|
|
|
2016-12-07 21:38:36 +01:00
|
|
|
#define MIN_LINE_LENGTH 60
|
2016-12-06 21:01:06 +01:00
|
|
|
#define LINE_WIDTH_RATIO 7
|
|
|
|
|
2019-01-24 00:45:22 +01:00
|
|
|
static Qt::PenStyle styles[] = {Qt::SolidLine, Qt::DashLine, Qt::DotLine,
|
|
|
|
Qt::DashDotLine, Qt::DashDotDotLine};
|
|
|
|
|
|
|
|
QIcon StyleComboBox::icon(Qt::PenStyle style)
|
2016-12-06 01:48:26 +01:00
|
|
|
{
|
2019-01-24 00:45:22 +01:00
|
|
|
QPixmap pm(iconSize());
|
|
|
|
pm.fill(Qt::transparent);
|
2016-12-06 01:48:26 +01:00
|
|
|
|
2019-01-24 00:45:22 +01:00
|
|
|
QBrush brush(QPalette().brush(QPalette::Active, QPalette::WindowText));
|
|
|
|
QPen pen(brush, pm.height() / LINE_WIDTH_RATIO, style);
|
2016-12-06 01:48:26 +01:00
|
|
|
|
2019-01-24 00:45:22 +01:00
|
|
|
QPainter painter(&pm);
|
|
|
|
painter.setPen(pen);
|
|
|
|
painter.drawLine(0, pm.height() / 2, pm.width(), pm.height() / 2);
|
2016-12-06 01:48:26 +01:00
|
|
|
|
2019-01-24 00:45:22 +01:00
|
|
|
return QIcon(pm);
|
|
|
|
}
|
2016-12-06 01:48:26 +01:00
|
|
|
|
2019-01-24 00:45:22 +01:00
|
|
|
StyleComboBox::StyleComboBox(QWidget *parent) : QComboBox(parent)
|
|
|
|
{
|
|
|
|
QSize is = iconSize();
|
|
|
|
setIconSize(QSize(MIN_LINE_LENGTH, is.height()));
|
2016-12-06 01:48:26 +01:00
|
|
|
|
2019-01-24 00:45:22 +01:00
|
|
|
for (size_t i = 0; i < ARRAY_SIZE(styles); i++)
|
|
|
|
addItem(icon(styles[i]), QString(), QVariant((int)styles[i]));
|
2016-12-06 01:48:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void StyleComboBox::setValue(Qt::PenStyle value)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < count(); i++) {
|
|
|
|
if ((Qt::PenStyle) itemData(i).toInt() == value) {
|
|
|
|
setCurrentIndex(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-24 00:45:22 +01:00
|
|
|
|
|
|
|
void StyleComboBox::changeEvent(QEvent *e)
|
|
|
|
{
|
|
|
|
if (e->type() == QEvent::PaletteChange)
|
|
|
|
for (int i = 0; i < count(); i++)
|
|
|
|
setItemIcon(i, icon(styles[i]));
|
|
|
|
|
|
|
|
QComboBox::changeEvent(e);
|
|
|
|
}
|