Beispiel #1
0
void GuiScroll::set_value(int value) {
    int old_value = current_value;
    current_value = value;
    recalc();
    if (current_value != old_value) {
        if (on_value_changed) {
            on_value_changed(this, on_value_changed_data, current_value);
        }
    }
}
Beispiel #2
0
/*!
 */
KScrollBar::KScrollBar(QGraphicsItem *parent)
    : KWidget(parent)
	, m_value(0)
	, m_minimum(0)
	, m_maximum(1)
	, m_deltaFactor(1.0)
	, m_singleStep(1)
	, m_pageStep(1)
	, m_orientation(Qt::Horizontal)
	, m_pressedValue(0)
	, m_hoveredControl(QStyle::SC_None)
	, m_pressedControl(QStyle::SC_None)
	, m_initialDelay(250)
	, m_repeatFrequency(50)
	, m_buttonHeight(14)
	, m_frameThickness(15)
	, m_sliderMinimumHeight(16)
	, m_ptThumbIconOffset(0,0)
	, m_bShowFullOnHover(false)
{
    setAcceptHoverEvents(true);
	setAcceptedMouseButtons(Qt::LeftButton);

	m_lineAddButton = new KPushButton(this);
	m_lineAddButton->setZValue(1);
	QObject::connect(m_lineAddButton, SIGNAL(clicked()), this, SLOT(on_linebutton_clicked()));
	addChild(m_lineAddButton);
	m_lineSubButton = new KPushButton(this);
	m_lineSubButton->setZValue(1);
	QObject::connect(m_lineSubButton, SIGNAL(clicked()), this, SLOT(on_linebutton_clicked()));
	addChild(m_lineSubButton);
	m_thumb = new KFrameItem(this);
	m_thumb->setFrameType(KFrameItem::GridFour);
	m_thumb->setZValue(1000);
	addChild(m_thumb);
	m_thumbIcon = new KIcon(this);
	m_thumbIcon->setZValue(2000);
	addChild(m_thumbIcon);
	m_background = new KFrameItem(this);
	m_background->setFrameType(KFrameItem::GridFour);
	m_background->setZValue(0);
	addChild(m_background);

	QObject::connect(this, SIGNAL(valueChanged(qreal)), this, SLOT(on_value_changed(qreal)));

	setOrientation(Qt::Vertical);

	displayFullOnHover(m_bShowFullOnHover ? false : true);
}
Beispiel #3
0
bool Widget::refresh_meter_level(float new_level) {

    static const float falloff = 87 * 60 * 0.001;

    // Note: removed RMS calculation, we will only focus on max peaks
    static float old_peak_db = -INFINITY;

    // calculate peak dB and translate into meter
	float peak_db = -INFINITY;
	if (new_level > 0) {
	    peak_db = power2db(new_level);
	}
	// retrieve old meter value and consider falloff
	if (peak_db < old_peak_db) {
	    peak_db = max(peak_db, old_peak_db - falloff);
	}
	fastmeter.set(log_meter(peak_db));
	old_peak_db = peak_db;
    
    // reset the maxlevel buffer in the vumeter thread
    reset *= -1;
    on_value_changed(RESET);
    return true;
}
Beispiel #4
0
	void Slider::handle_event(gui::EventArgs &args)
	{
		if (args.type == gui::Event_CursorDrag || args.type == gui::Event_CursorButtonPressed)
		{
			// To find the 'current_value' of the slider, we work backwards by
			// taking the input at args.local.x and computing the desired position
			// for the drag handle.

			// calculate usable width
			Point left_edge = get_left_edge();
			Point right_edge = get_right_edge();
			float usable_width = (right_edge.x - left_edge.x);

			// user clicked or dragged at input
			float input = args.local.x;

			// translate it back by half the handle width
			float slider_origin = (input - (drag_handle_width / 2.0f));

			// cache the previous value
			float old_value = current_value;

			// compute the new value as it should be in our usable_width
			current_value = glm::clamp(((slider_origin - kLeftMargin) / usable_width), 0.0f, 1.0f);

			// set pressed color
			drag_handle->set_background_color(gemini::Color::from_rgba(255, 128, 0, 255));

			if ((old_value != current_value) && on_value_changed.is_valid())
			{
				on_value_changed(current_value);
			}

			args.compositor->set_focus(this);
			args.handled = true;
		}
		else if (args.type == gui::Event_KeyButtonReleased)
		{
			// TODO: handle home/end + various other keys
			args.handled = true;
		}
		else if (args.type == gui::Event_CursorMove)
		{
			Point pt = args.local - drag_handle->get_origin();
			if (drag_handle->hit_test_local(pt))
			{
				drag_handle->set_background_color(gemini::Color::from_rgba(255, 128, 128, 255));
			}
			else
			{
				drag_handle->set_background_color(gemini::Color::from_rgba(0, 255, 0, 255));
			}

			args.handled = true;
		}
		else if (args.type == gui::Event_CursorExit)
		{
			drag_handle->set_background_color(gemini::Color::from_rgba(0, 255, 0, 255));
			args.handled = true;
		}
	}