21 #include <QMouseEvent> 23 #include <QWheelEvent> 31 m_colorMapper(colorMapper)
33 setAutoFillBackground(
false);
34 setAttribute(Qt::WA_OpaquePaintEvent,
true);
35 setAttribute(Qt::WA_NoSystemBackground,
true);
36 setMouseTracking(
true);
37 setFocusPolicy(Qt::StrongFocus);
41 m_background.setCoordinateMode(QGradient::ObjectBoundingMode);
46 for (; cmit != cmitEnd; ++cmit) {
64 const QLocale &cLocale = QLocale::c();
73 QWidget::setFont(font);
75 QFontMetrics fm(font);
99 for (; cmit != cmitEnd; ++cmit) {
150 for (
int i = 0;
i < d;
i++) {
161 if (c == QChar(
'0')) {
164 return QChar::fromLatin1(c.toLatin1() - 1);
169 if (c == QChar(
'9')) {
172 return QChar::fromLatin1(c.toLatin1() + 1);
179 QString str = QString(
"%1").arg(value,
m_numDigits, 10, QChar(
'0'));
187 const QLocale &cLocale = QLocale::c();
188 str.insert(ipoint, cLocale.groupSeparator());
197 QPainter painter(
this);
199 painter.setPen(Qt::black);
202 painter.drawRect(0, 0, width() - 1, height() - 1);
205 painter.setBrush(Qt::NoBrush);
210 painter.drawLine(1 +
i *
m_digitWidth, 1, 1 +
i * m_digitWidth, height() - 1);
212 painter.drawLine(0 +
i * m_digitWidth, 1, 0 +
i * m_digitWidth, height() - 1);
213 painter.drawLine(2 +
i * m_digitWidth, 1, 2 +
i * m_digitWidth, height() - 1);
217 painter.drawLine(1, 1, 1, height() - 1);
218 painter.drawLine(width() - 2, 1, width() - 2, height() - 1);
222 painter.drawLine(0, 0, width() - 2, 0);
223 painter.drawLine(0, height() - 1, 0, 0);
225 painter.drawLine(1, height() - 1, width() - 1, height() - 1);
226 painter.drawLine(width() - 1, height() - 1, width() - 1, 0);
230 painter.setPen(Qt::NoPen);
237 for (
int i = 0;
i <
m_text.length();
i++)
251 painter.setClipping(
false);
255 painter.setPen(Qt::NoPen);
262 for (
int i = 0;
i <
m_text.length();
i++)
282 painter.drawText(QRect(1 + i * m_digitWidth, h, m_digitWidth,
m_digitHeight), Qt::AlignCenter,
m_text.mid(i, 1));
310 Qt::MouseButton mouseButton =
event->button();
312 if (mouseButton == Qt::RightButton)
327 else if (mouseButton == Qt::LeftButton)
375 if (event->delta() < 0)
377 if (event->modifiers() & Qt::ShiftModifier) {
379 }
else if (event->modifiers() & Qt::ControlModifier) {
391 if (event->modifiers() & Qt::ShiftModifier) {
393 }
else if (event->modifiers() & Qt::ControlModifier) {
423 if ((value->key() == Qt::Key_Return) || (value->key() == Qt::Key_Enter) || (value->key() == Qt::Key_Escape))
454 if ((value->key() == Qt::Key_Left) || (value->key() == Qt::Key_Backspace))
473 else if (value->key() == Qt::Key_Right)
492 else if (value->key() == Qt::Key_Up)
496 if (value->modifiers() & Qt::ShiftModifier) {
498 }
else if (value->modifiers() & Qt::ControlModifier) {
515 else if (value->key() == Qt::Key_Down)
519 if (value->modifiers() & Qt::ShiftModifier) {
521 }
else if (value->modifiers() & Qt::ControlModifier) {
539 if (value->text().length() != 1) {
543 QChar c = value->text()[0];
545 if (c >= QChar(
'0') && (c <= QChar(
'9')))
547 int d = c.toLatin1() -
'0';
549 quint64 v = (
m_value / e) % 10;
const QColor & getBoundaryColor() const
const QColor & getForegroundColor() const
void wheelEvent(QWheelEvent *)
const QColor & getHighlightColor() const
QString formatText(quint64 value)
Fixed< IntType, IntBits > abs(Fixed< IntType, IntBits > const &x)
ColorMapper m_colorMapper
void setValue(quint64 value)
void setValueRange(uint numDigits, quint64 min, quint64 max)
const colormap & getDialBackgroundColorMap() const
void keyPressEvent(QKeyEvent *)
void focusInEvent(QFocusEvent *)
const QColor & getBoundaryAlphaColor() const
ValueDial(QWidget *parent=NULL, ColorMapper colorMapper=ColorMapper(ColorMapper::Normal))
QChar digitNeigh(QChar c, bool dir)
void paintEvent(QPaintEvent *)
void mouseMoveEvent(QMouseEvent *)
const QColor & getDarkBorderColor() const
void setColorMapper(ColorMapper colorMapper)
void leaveEvent(QEvent *)
const QColor & getLightBorderColor() const
void setFont(const QFont &font)
QLinearGradient m_background
void focusOutEvent(QFocusEvent *)
void changed(quint64 value)
void mousePressEvent(QMouseEvent *)
const QColor & getSecondaryForegroundColor() const
T max(const T &x, const T &y)
quint64 findExponent(int digit)
T min(const T &x, const T &y)