Пример #1
0
    void thread () {
        while (!mKillThread) {
            auto nextTimePoint = std::chrono::steady_clock::now() + tickInterval();

            // If an octet is available from the write buffer, load it into the
            // intermediate buffer. Otherwise, push nothing to keep the pipe
            // flowing.
            uint8_t octet;
            //printf("%s moving an octet from write buffer to intermediate buffer\n", mDebugName.c_str());
            mMedium.push(mWriteQueue.try_pop(octet)
                    ? Quantum(octet)
                    : Quantum(boost::none));

            // Feed the deliver callback if there's an octet available.
            auto quantum = mMedium.front();
            mMedium.pop();
            if (quantum) {
                //printf("%s outputing an octet\n", mDebugName.c_str());
                output(*quantum);
            }

            //printf("%s cycle complete\n", mDebugName.c_str());
            if (nextTimePoint < std::chrono::steady_clock::now()) {
                //fprintf(stderr, "Process is too slow to simulate this baud rate.\n");
            }
            else {
                std::this_thread::sleep_until(nextTimePoint);
            }
        }
    }
Пример #2
0
// Function copied from qslider.cpp and modified to make it compile
void Slider::initStyleOption_Qt430( QStyleOptionSlider *option ) const
{
	if (!option)
		return;

	option->initFrom( this );
	option->subControls       = QStyle::SC_None;
	option->activeSubControls = QStyle::SC_None;
	option->orientation       = orientation();
	option->maximum           = maximum();
	option->minimum           = minimum();
	option->tickPosition      = (QSlider::TickPosition) tickPosition();
	option->tickInterval      = tickInterval();
	option->upsideDown        = (orientation() == Qt::Horizontal) ?
								   (invertedAppearance() != (option->direction == Qt::RightToLeft))
								 : (!invertedAppearance());
	option->direction         = Qt::LeftToRight; // we use the upsideDown option instead
	option->sliderPosition    = sliderPosition();
	option->sliderValue       = value();
	option->singleStep        = singleStep();
	option->pageStep          = pageStep();

	if (orientation() == Qt::Horizontal)
		option->state |= QStyle::State_Horizontal;
}
Пример #3
0
void TickSlider::addDefaultTickLabels()
{
    int interval = tickInterval();
    if (interval == 0) {
        interval = pageStep();
    }
    for (int i = minimum(); i <= maximum(); i += interval) {
        m_tick_labels[i] = QString::number(i);
    }
}
Пример #4
0
QSize TickSlider::sizeHint() const
{
    QSize size = QSlider::sizeHint();
    bool using_labels = tickLabelPosition() != NoTicks;
    QSize label = using_labels ? biggestLabel() : QSize();
    bool using_ticks = tickPosition() != NoTicks;
    int n_potential_labels = (maximum() - minimum()) / tickInterval();
    if (orientation() == Qt::Horizontal) {
        // Horizontal
        if (using_labels) {
            size.rheight() += 2 * label.height();
            size = size.expandedTo(QSize(
                                       n_potential_labels * label.width() +
                                       (n_potential_labels - 1) * m_min_interlabel_gap,
                                       0));
        }
        if (using_ticks) {
            size.rheight() += 2 * m_tick_length;
        }
        if (using_labels && using_ticks) {
            size.rheight() += 2 * m_tick_label_gap;
        }
        if (using_labels || using_ticks) {
            size.rheight() += 2 * m_gap_to_slider;
        }
    } else {
        // Vertical
        if (using_labels) {
            size.rwidth() += 2 * label.width();
            size = size.expandedTo(QSize(
                                       0,
                                       n_potential_labels * label.height() +
                                       (n_potential_labels - 1) * m_min_interlabel_gap));
        }
        if (using_ticks) {
            size.rwidth() += 2 * m_tick_length;
        }
        if (using_labels && using_ticks) {
            size.rwidth() += 2 * m_tick_label_gap;
        }
        if (using_labels || using_ticks) {
            size.rwidth() += 2 * m_gap_to_slider;
        }
    }
    return size;
}
Пример #5
0
int QSlider::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QAbstractSlider::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        if (_id < 2)
            qt_static_metacall(this, _c, _id, _a);
        _id -= 2;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< TickPosition*>(_v) = tickPosition(); break;
        case 1: *reinterpret_cast< int*>(_v) = tickInterval(); break;
        }
        _id -= 2;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setTickPosition(*reinterpret_cast< TickPosition*>(_v)); break;
        case 1: setTickInterval(*reinterpret_cast< int*>(_v)); break;
        }
        _id -= 2;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 2;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 2;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 2;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 2;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 2;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 2;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}
Пример #6
0
void TickSlider::paintEvent(QPaintEvent *ev)
{
    Q_UNUSED(ev)
    QStylePainter p(this);
    QStyleOptionSlider opt;
    initStyleOption(&opt);

    QRect handle = style()->subControlRect(QStyle::CC_Slider, &opt,
                                           QStyle::SC_SliderHandle, this);

    // Draw the slider first
    opt.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle;
    opt.activeSubControls = getHoverControl();  // addition here
    p.drawComplexControl(QStyle::CC_Slider, opt);

    // draw tick marks
    // do this manually because they are very badly behaved with style sheets
    int interval = tickInterval();
    if (interval == 0) {
        interval = pageStep();
    }

    // see http://doc.qt.io/qt-5.7/coordsys.html
    // ... positive is right and down

    bool using_ticks = tickPosition() != NoTicks;
    bool using_labels = tickLabelPosition() != NoTicks;
    if (!using_ticks && !using_labels) {
        return;
    }
    QPen pen;
    pen.setColor(m_tick_colour);
    pen.setWidth(m_tick_thickness);
    p.setPen(pen);
    bool horizontal = orientation() == Qt::Horizontal;
    QSize biggest_label = biggestLabel();
    int max_label_height = using_labels ? biggest_label.height() : 0;
    int max_label_width = using_labels ? biggest_label.width() : 0;
    if (horizontal) {
        // --------------------------------------------------------------------
        // HORIZONTAL
        // --------------------------------------------------------------------
        int move_tick_vertically_by = (max_label_height > 0)
                                      ? (max_label_height + m_tick_label_gap)
                                      : 0;
        // Top
        int bounding_box_top = this->rect().top();
        int top_label_top = bounding_box_top;
        int top_tick_top = bounding_box_top + move_tick_vertically_by;
        int top_tick_bottom = top_tick_top + m_tick_length;
        // Bottom, working up
        int bounding_box_bottom = this->rect().bottom();
        int bottom_label_bottom = bounding_box_bottom;
        int bottom_tick_bottom = bounding_box_bottom - move_tick_vertically_by;
        int bottom_tick_top = bottom_tick_bottom - m_tick_length;
        // OK:
        for (int i = minimum(); i <= maximum(); i += interval) {
            Qt::Alignment halign = Qt::AlignHCenter;
            if (m_edge_in_extreme_labels) {
                bool leftmost = i == minimum();
                bool rightmost = i == maximum();
                if (leftmost) {
                    halign = Qt::AlignLeft;
                } else if (rightmost) {
                    halign = Qt::AlignRight;
                }
            }
            int q = m_reverse_horizontal_labels ? (maximum() - i) : i;
            int x = round(
                        (double)(
                            (double)(
                                (double)(q - this->minimum()) /
                                (double)(this->maximum() - this->minimum())
                            ) * (double)(this->width() - handle.width()) +
                            (double)(handle.width() / 2.0)
                        )
                    ) - 1;
            bool has_label = m_tick_labels.contains(i);
            QString label_text;
            if (has_label) {
                label_text = m_tick_labels[i];
            }
            if (tickPosition() == TicksBothSides ||
                    tickPosition() == TicksAbove) {
                p.drawLine(x, top_tick_top, x, top_tick_bottom);
            }
            if (has_label && (tickLabelPosition() == TicksBothSides ||
                              tickLabelPosition() == TicksAbove)) {
                UiFunc::drawText(p, x, top_label_top,
                                 halign | Qt::AlignTop, label_text);
            }
            if (tickPosition() == TicksBothSides ||
                    tickPosition() == TicksBelow) {
                p.drawLine(x, bottom_tick_top, x, bottom_tick_bottom);
            }
            if (has_label && (tickLabelPosition() == TicksBothSides ||
                              tickLabelPosition() == TicksBelow)) {
                UiFunc::drawText(p, x, bottom_label_bottom,
                                 halign | Qt::AlignBottom, label_text);
            }
        }
    } else {
        // --------------------------------------------------------------------
        // VERTICAL
        // --------------------------------------------------------------------
        int move_tick_horizontally_by = (max_label_width > 0)
                                        ? (max_label_width + m_tick_label_gap)
                                        : 0;
        // Left
        int bounding_box_left = this->rect().left();
        int left_label_right = bounding_box_left + max_label_width;
        int left_tick_left = bounding_box_left + move_tick_horizontally_by;
        int left_tick_right = left_tick_left + m_tick_length;
        // Right, working leftwards
        int bounding_box_right = this->rect().right();
        int right_label_left = bounding_box_right - max_label_width;
        int right_tick_right = bounding_box_right - move_tick_horizontally_by;
        int right_tick_left = right_tick_right - m_tick_length;
        // OK:
        for (int i = minimum(); i <= maximum(); i += interval) {
            Qt::Alignment valign = Qt::AlignVCenter;
            int q = m_reverse_vertical_labels ? (maximum() - i) : i;
            int y = round(
                        (double)(
                            (double)(
                                (double)(q - this->minimum()) /
                                (double)(this->maximum() - this->minimum())
                            ) * (double)(this->height() - handle.height()) +
                            (double)(handle.height() / 2.0)
                        )
                    ) - 1;
            bool has_label = m_tick_labels.contains(i);
            QString label_text;
            if (has_label) {
                label_text = m_tick_labels[i];
            }
            if (tickPosition() == TicksBothSides ||
                    tickPosition() == TicksLeft) {
                p.drawLine(left_tick_left, y, left_tick_right, y);
            }
            if (has_label && (tickLabelPosition() == TicksBothSides ||
                              tickLabelPosition() == TicksLeft)) {
                UiFunc::drawText(p, left_label_right, y,
                                 Qt::AlignRight | valign, label_text);
            }
            if (tickPosition() == TicksBothSides ||
                    tickPosition() == TicksRight) {
                p.drawLine(right_tick_left, y, right_tick_right, y);
            }
            if (has_label && (tickLabelPosition() == TicksBothSides ||
                              tickLabelPosition() == TicksRight)) {
                UiFunc::drawText(p, right_label_left, y,
                                 Qt::AlignLeft | valign, label_text);
            }
        }
    }
}