void TColourScaleEditor::mouseDoubleClickEvent(QMouseEvent* event)
{
	// Store mouse position
	lastPos_ = event->pos();

	// Check mouse position
	if (gradientBarRegion_.contains(lastPos_))
	{
		// Gradient bar was double-clicked, so add a new point at this position
		double clickedValue = gradientBarValue(lastPos_);
		QColor clickedColour = colourScale_.colourAsQColor(clickedValue);
		colourScale_.addPoint(clickedValue, clickedColour);

		updateGradient();
		repaint();

		emit(colourScaleChanged());
	}
	else if (handleRegion_.contains(lastPos_))
	{
		currentColourScalePoint_ = handleUnderMouse(lastPos_);
		
		if (currentColourScalePoint_)
		{
			ColourDialog colourDialog(this);
			if (colourDialog.execute(currentColourScalePoint_->colourAsQColor()))
			{
				colourScale_.setColour(currentColourScalePoint_, colourDialog.selectedColour());

				updateGradient();
				repaint();

				emit(colourScaleChanged());
			}
		}
	}
	else if (labelRegion_.contains(lastPos_))
	{
		currentColourScalePoint_ = labelUnderMouse(lastPos_);

		if (currentColourScalePoint_)
		{
			bool ok;
			double newValue = QInputDialog::getDouble(this, "Set point value", "New value: ", currentColourScalePoint_->value(), -1.0e7, 1.0e7, 6, &ok);
			if (ok)
			{
				colourScale_.setValue(currentColourScalePoint_, newValue);

				updateGradient();
				repaint();

				emit(colourScaleChanged());
			}
		}
	}

	currentColourScalePoint_ = NULL;
}
void TColourScaleEditor::contextMenuRequested(const QPoint& point)
{
	// Get handle at clicked point
	ColourScalePoint* clickedPoint = handleUnderMouse(point);
	if (!clickedPoint) return;

	// Build the context menu to display
	QMenu contextMenu;
	QAction* valueAction = contextMenu.addAction("&Set value...");
	QAction* deleteAction = contextMenu.addAction("&Delete");
	QAction* spaceAction = contextMenu.addAction("&Set to midpoint");
	if ((!clickedPoint->prev) || (!clickedPoint->next)) spaceAction->setEnabled(false);

	// Show it
	QPoint menuPosition = mapToGlobal(point);
	QAction* menuResult = contextMenu.exec(menuPosition);

	// What was clicked?
	if (menuResult == valueAction)
	{
		bool ok;
		double newValue = QInputDialog::getDouble(this, "Set point value", "New value: ", clickedPoint->value(), -1.0e7, 1.0e7, 6, &ok);
		if (ok)
		{
			colourScale_.setValue(clickedPoint, newValue);

			updateGradient();
			repaint();

			emit(colourScaleChanged());
		}
	}
	else if (menuResult == deleteAction)
	{
		colourScale_.removePoint(clickedPoint);
		
		updateGradient();
		repaint();

		emit(colourScaleChanged());
	}
	else if (menuResult == spaceAction)
	{
		// Get average values of next and previous points
		double averageValue = (clickedPoint->next->value() + clickedPoint->prev->value()) * 0.5;

		colourScale_.setValue(clickedPoint, averageValue);

		updateGradient();
		repaint();

		emit(colourScaleChanged());
	}
}
Beispiel #3
0
Plot::Plot(QWidget *parent):
    QwtPlot( parent )
{
    // panning with the left mouse button
    (void) new QwtPlotPanner( canvas() );

    // zoom in/out with the wheel
    (void) new QwtPlotMagnifier( canvas() );

    setAutoFillBackground( true );
    setPalette( QPalette( QColor( 165, 193, 228 ) ) );
    updateGradient();

    setTitle("A Simple QwtPlot Demonstration");
    insertLegend(new QwtLegend(), QwtPlot::RightLegend);

    // axes 
    setAxisTitle(xBottom, "x -->" );
    setAxisScale(xBottom, 0.0, 10.0);

    setAxisTitle(yLeft, "y -->");
    setAxisScale(yLeft, -1.0, 1.0);

    // canvas
    canvas()->setLineWidth( 1 );
    canvas()->setFrameStyle( QFrame::Box | QFrame::Plain );
    canvas()->setBorderRadius( 15 );

    QPalette canvasPalette( Qt::white );
    canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) );
    canvas()->setPalette( canvasPalette );

    populate();
}
Beispiel #4
0
void Plot::resizeEvent( QResizeEvent *event )
{
    QwtPlot::resizeEvent( event );
#ifdef Q_WS_X11
    updateGradient();
#endif
}
// Set local colourscale
void TColourScaleEditor::setColourScale(const ColourScale& colourScale)
{
	// If the source colourscale uses deltaHSV_, we must construct an interpolated gradient manually since QGradient doesn't support HSV interpolation
// 	if (colourScale.useHSV())
// 	{
// 		colourScale_.clear();
// 		colourScale_.setUseHSV(false);
// 		if (colourScale.nPoints() > 0)
// 		{
// 			const int nPoints = 101;
// 			double value = colourScale.firstPoint()->value();
// 			double delta = (colourScale.lastPoint()->value() - value) / nPoints;
// 			for (int n=0; n<nPoints; ++n)
// 			{
// 				colourScale_.addPoint(value, colourScale.colour(value));
// 				value += delta;
// 			}
// 		}
// 	}
// 	else colourScale_ = colourScale;
	colourScale_ = colourScale;

	updateGradient();

	repaint();
}
Beispiel #6
0
void Plot::resizeEvent( QResizeEvent *event )
{
    QwtPlot::resizeEvent( event );

    // Qt 4.7.1: QGradient::StretchToDeviceMode is buggy on X11
    updateGradient();
}
Beispiel #7
0
void DkGradient::changeColor(DkColorSlider*) {

    updateGradient();
    update();

    emit gradientChanged();
}
Beispiel #8
0
void KNMainWindowStatusBar::changeBackgroundColor(int frame)
{
    //Save the opacity.
    m_opacity=frame;
    //Update the gradient.
    updateGradient();
}
Beispiel #9
0
void Dialog::colorChanged(int const index, QColor const& color)
{
   if (0 <= index && index < m_colors.size()) {
      m_colors[index] = color;
      setCustom();
      updateGradient();
   }
}
Beispiel #10
0
void KNMainWindowStatusBar::onPaletteChanged()
{
    //Save the color.
    m_backgroundColor=
            knTheme->getPalette("MainWindowStatusBar").color(QPalette::Window);
    //Update the gradient.
    updateGradient();
}
void ValueSlider::setHue(int h)
{
    if (m_hue != h) {
        m_hue = h;

        updateGradient();
        update();
    }
}
Beispiel #12
0
 Private(HueSlider *widget)
     : w(widget)
 {
     w->setRange(0, 359);
     connect(w, &QSlider::valueChanged, [this]{
         emit w->colorHueChanged(percent());
     });
     updateGradient();
 }
void SaturationSlider::setHue(int h)
{
    if (m_hue != h) {
        m_hue = h;

        updateGradient();
        update();
    }
}
Beispiel #14
0
void Dialog::on_stopsSpin_valueChanged(int n)
{
   if (n != m_colors.size()) {
      Function f(m_colors);
      f.resample(n);
      m_colors = f.colors();
      setCustom();
      updateGradient();
   }
}
Beispiel #15
0
void GradientLine::mouseReleaseEvent(QMouseEvent *event)
{
    if (event->button() == Qt::LeftButton) {
        event->accept();

        if (m_dragActive) {
            m_yOffset += event->pos().y() - 14;
            if (m_yOffset > 0) {
                m_yOffset = 0;
            } else if ((m_yOffset < - 8) && (currentColorIndex()) != 0 && (currentColorIndex() < m_stops.size() - 1)) {
                m_yOffset = 0;
                m_dragActive = false;
                m_stops.removeAt(currentColorIndex());
                m_colorList.removeAt(currentColorIndex());
                updateGradient();
                emit gradientChanged();
                setCurrentIndex(0);
                //delete item
            }
        }

        if (m_dragActive == false && m_create) {
            qreal stopPos = qreal(event->pos().x() - 9) / qreal((width() - 15));
            int index = -1;
            for (int i =0; i < m_stops.size() - 1; i++) {
                if ((stopPos > m_stops.at(i)) && (index == -1))
                    index = i +1;
            }
            if (index != -1 && (m_useGradient) && abs(m_dragStart.x() - event->pos().x()) < 10) { //creating of items only in base state
                m_stops.insert(index, stopPos);
                m_colorList.insert(index, QColor(Qt::white));
                setCurrentIndex(index);
            }
        }
    }
    m_dragActive = false;
    m_yOffset = 0;
    updateGradient();
    emit gradientChanged();
    update();
    setFocus(Qt::MouseFocusReason);
}
Beispiel #16
0
void DkGradient::init() {

	clearAllSliders();

	addSlider(0, Qt::black);
	addSlider(1, Qt::white);
	
	updateGradient();


};
Beispiel #17
0
void GradientLine::setActiveColor(const QColor &newColor)
{
    if (newColor.name() == m_activeColor.name() && newColor.alpha() == m_activeColor.alpha())
        return;

    m_activeColor = newColor;
    m_colorList.removeAt(currentColorIndex());
    m_colorList.insert(currentColorIndex(), m_activeColor);
    updateGradient();
    update();
}
Beispiel #18
0
void GradientLine::readGradient()
{
    if (m_useGradient) {
        m_colorList.clear();
        m_stops.clear();
        foreach (const QGradientStop &stop, m_gradient.stops()) {
            m_stops << stop.first;
            m_colorList << stop.second;
        }
    }
    updateGradient();
}
Beispiel #19
0
// --------------- Dialog ----------------
Dialog::Dialog(ColorList const& colors, QWidget* parent) : QDialog(parent),  m_colors(colors)
{
   m_dialog.setupUi(this);
   if (m_colors == Preferences::DefaultGradientColors()) {
      m_dialog.gradientCombo->setCurrentIndex(Default);
   }else if (m_colors == Preferences::SpectrumGradientColors()) {
      m_dialog.gradientCombo->setCurrentIndex(Spectrum);
   }else {
      m_dialog.gradientCombo->setCurrentIndex(Custom);
   }
   updateGradient();
}
void CImplicitGradient::setGradient(double x1, double x2, double y1, double y2, double z1, double z2,
    double w1, double w2, double u1, double u2, double v1, double v2)
{
    m_gx1=x1; m_gx2=x2;
    m_gy1=y1; m_gy2=y2;
    m_gz1=z1; m_gz2=z2;
    m_gw1=w1; m_gw2=w2;
    m_gu1=u1; m_gu2=u2;
    m_gv1=v1; m_gv2=v2;

    updateGradient();
}
Beispiel #21
0
void DkGradient::init() {

    isActiveSliderExisting = false;

    clearAllSliders();

    addSlider(0, Qt::black);
    addSlider(1, Qt::white);

    updateGradient();


};
Beispiel #22
0
void DkGradient::moveSlider(DkColorSlider* sender, int dragDistX, int yPos) {


    // Delete the actual slider:
    if (yPos > deleteSliderDist) {
        int idx = sliders.lastIndexOf(sender);
        if (idx != -1) {
            sliders.remove(idx);
            delete sender;
            isActiveSliderExisting = false;
        }
    }

    // Insert a new slider:
    else {

        int newPos = sender->pos().x() + dragDistX;

        if (newPos < 0)
            newPos = 0;
        else if (newPos > width() - sliderWidth - 1)
            newPos = width() - sliderWidth - 1;

        qreal normedSliderPos = getNormedPos(newPos);

        if (normedSliderPos > 1)
            normedSliderPos = 1;
        if (normedSliderPos < 0)
            normedSliderPos = 0;

        DkColorSlider *slider;
        // Check if the position is already assigned to another slider:
        for (int i = 0; i < sliders.size(); i++) {
            slider = sliders.at(i);
            if (slider != sender) {
                if (slider->getNormedPos() == normedSliderPos)
                    return;
            }
        }

        sender->setNormedPos(normedSliderPos);
        sender->move(newPos, sender->pos().y());

    }

    updateGradient();
    update();

    emit gradientChanged();

}
Beispiel #23
0
void GradientLine::keyPressEvent(QKeyEvent * event)
{
    if (event->matches(QKeySequence::Delete)) {
        if ((currentColorIndex()) != 0 && (currentColorIndex() < m_stops.size() - 1)) {
            m_dragActive = false;
            m_stops.removeAt(currentColorIndex());
            m_colorList.removeAt(currentColorIndex());
            updateGradient();
            setCurrentIndex(0);
            //delete item
        }
    } else {
        QWidget::keyPressEvent(event);
    }
}
Beispiel #24
0
// Take a step for the initialization optimization procedure.
double GPCMBackConstraintMLP::initializationStep(
    const double *x,                        // Current parameter offset.
    double *g                               // Returned gradient
    )
{
    double value;

    // Pull out parameters.
    int cnt = 0;
    memcpy(W1.data(),&x[cnt],sizeof(double)*W1.rows()*W1.cols());
    cnt += W1.rows()*W1.cols();
    memcpy(b1.data(),&x[cnt],sizeof(double)*b1.rows()*b1.cols());
    cnt += b1.rows()*b1.cols();
    memcpy(W2.data(),&x[cnt],sizeof(double)*W2.rows()*W2.cols());
    cnt += W2.rows()*W2.cols();
    memcpy(b2.data(),&x[cnt],sizeof(double)*b2.rows()*b2.cols());

    // Update coordinates.
    updateLatentCoords();

    // Compute value and gradient.
    Xerror = X-Xtarget;
    value = 0.5*Xerror.array().square().sum();
    
    // Compute gradients with respect to variables.
    updateGradient(Xerror,true);

    // Pack the gradient.
    if (g)
    {
        cnt = 0;
        memcpy(&g[cnt],W1grad.data(),sizeof(double)*W1.rows()*W1.cols());
        cnt += W1.rows()*W1.cols();
        memcpy(&g[cnt],b1grad.data(),sizeof(double)*b1.rows()*b1.cols());
        cnt += b1.rows()*b1.cols();
        memcpy(&g[cnt],W2grad.data(),sizeof(double)*W2.rows()*W2.cols());
        cnt += W2.rows()*W2.cols();
        memcpy(&g[cnt],b2grad.data(),sizeof(double)*b2.rows()*b2.cols());
        for (int i = 0; i < cnt+b2.rows()*b2.cols(); i++)
            g[i] = -g[i];
    }

    // Return result.
    //DBPRINTLN("Initialization error: " << value);
    return -value;
}
Beispiel #25
0
void Dialog::on_gradientCombo_currentIndexChanged(int n)
{
   switch (n) {
      case Default:
         m_colors = Preferences::DefaultGradientColors();
         break;
      case Spectrum:
         m_colors = Preferences::SpectrumGradientColors();
         break;
      case Custom:
         m_colors = Preferences::CustomGradientColors();
         break;
      default:
         break;
   }

   updateGradient();
}
Beispiel #26
0
void DkGradient::resizeEvent( QResizeEvent * event ) {

    if (event->size() == event->oldSize())
        return;

    DkColorSlider *slider;

    for (int i = 0; i < sliders.size(); i++) {
        slider = sliders.at(i);
        slider->updatePos(this->width());
    }

    //qDebug() << "resize gradient: " << event->size();

    updateGradient();

    QWidget::resizeEvent(event);
}
Beispiel #27
0
void DkGradient::setGradient(const QLinearGradient& gradient) {

    reset();
    clearAllSliders();	// reset adds a slider at the start and end

    this->gradient.setStops(gradient.stops());

    QVector<QGradientStop> stops = gradient.stops();

    for (int idx = 0; idx < stops.size(); idx++) {
        addSlider(stops.at(idx).first, stops.at(idx).second);
    }

    updateGradient();
    update();
    emit gradientChanged();

}
SpectrumWarsRxGuiWidget::SpectrumWarsRxGuiWidget(SWRxGuiParams params,
                                                 SWRxGuiCallback* callback,
                                                 QWidget *parent)
  :QWidget(parent)
{
  params_ = params;
  callback_ = callback;
  knob1_ = new KnobSpin("Frequency (MHz)", params_.minFreq, params_.maxFreq,
                        0.1, this);
  QShortcut* s11_ = new QShortcut(QKeySequence("Q"), this);
  connect(s11_, SIGNAL(activated()), knob1_->spin(), SLOT(stepUp()));
  QShortcut* s12_ = new QShortcut(QKeySequence("A"), this);
  connect(s12_, SIGNAL(activated()), knob1_->spin(), SLOT(stepDown()));

  knob2_ = new KnobSpin("Bandwidth (MHz)", params_.minBW, params_.maxBW,
                        0.25, this);
  QShortcut* s21_ = new QShortcut(QKeySequence("W"), this);
  connect(s21_, SIGNAL(activated()), knob2_->spin(), SLOT(stepUp()));
  QShortcut* s22_ = new QShortcut(QKeySequence("S"), this);
  connect(s22_, SIGNAL(activated()), knob2_->spin(), SLOT(stepDown()));

  knob3_ = new KnobSpin("Gain", params_.minGain, params_.maxGain,
                        1.0, this);
  QShortcut* s31_ = new QShortcut(QKeySequence("E"), this);
  connect(s31_, SIGNAL(activated()), knob3_->spin(), SLOT(stepUp()));
  QShortcut* s32_ = new QShortcut(QKeySequence("D"), this);
  connect(s32_, SIGNAL(activated()), knob3_->spin(), SLOT(stepDown()));

  connect(knob1_, SIGNAL(valueChanged(double)),
          this, SLOT(setFrequency(double)));
  connect(knob2_, SIGNAL(valueChanged(double)),
          this, SLOT(setBandwidth(double)));
  connect(knob3_, SIGNAL(valueChanged(double)),
          this, SLOT(setGain(double)));

  QHBoxLayout* hLayout1 = new QHBoxLayout(this);
  hLayout1->addWidget(knob1_);
  hLayout1->addWidget(knob2_);
  hLayout1->addWidget(knob3_);

  setPalette( QPalette( QColor( 192, 192, 192 ) ) );
  updateGradient();
}
Beispiel #29
0
Plot::Plot(QWidget *parent):
    QwtPlot( parent )
{
    setAutoFillBackground( true );
    setPalette( QPalette( QColor( 165, 193, 228 ) ) );
    updateGradient();

    setTitle( "График аппроксимации" );
    insertLegend( new QwtLegend(), QwtPlot::RightLegend );

    // axes
    setAxisTitle( xBottom, "" );
    setAxisScale( xBottom, 0.0, 60.0 );

    setAxisTitle( yLeft, "Функция принадлежности -->" );
    setAxisScale( yLeft, -0.1, 1.1 );

    // canvas
    QwtPlotCanvas *canvas = new QwtPlotCanvas();
    canvas->setLineWidth( 1 );
    canvas->setFrameStyle( QFrame::Box | QFrame::Plain );
    canvas->setBorderRadius( 15 );

    QPalette canvasPalette( Qt::white );
    canvasPalette.setColor( QPalette::Foreground, QColor( 133, 190, 232 ) );
    canvas->setPalette( canvasPalette );

    setCanvas( canvas );

    // panning with the left mouse button
    //( void ) new QwtPlotPanner( canvas );

    // zoom in/out with the wheel
    ( void ) new QwtPlotMagnifier( canvas );

    zoom = new QwtPlotZoomer(canvas);
    zoom->setRubberBandPen(QPen(Qt::red));

    clear();

    //  ...a horizontal line at y = 0...

<<<<<<< HEAD
Beispiel #30
0
Dialog::Dialog(StandardGradient const grad, QWidget* parent) : QDialog(parent)
{
   m_dialog.setupUi(this);
   switch (grad) {
      case Default:
         m_colors = Preferences::DefaultGradientColors();      
         m_dialog.gradientCombo->setCurrentIndex(Default);
         break;
      case Spectrum:
         m_colors = Preferences::SpectrumGradientColors();      
         m_dialog.gradientCombo->setCurrentIndex(Spectrum);
         break;
      case Custom:
         m_colors = Preferences::CustomGradientColors();      
         m_dialog.gradientCombo->setCurrentIndex(Custom);
         break;
   }
   updateGradient();
}