示例#1
0
qavimator::qavimator(yarp::os::ResourceFinder &config, QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::qavimator)
{
    ui->setupUi(this);
    setupToolBar();
    ui->animationView->init(config);
    nFPS=10;

    width=850;
    height=600;


    readSettings();
    // default size

    if (config.check("name")) {
        GUI_NAME=std::string(config.find("name").asString().c_str());
    }
    if (GUI_NAME[0]!='/') {
        GUI_NAME=std::string("/")+GUI_NAME;
    }
    if (config.check("width")) {
        width=config.find("width").asInt();
    }
    if (config.check("height")) {
        height=config.find("height").asInt();
    }

    //sanity check
    if(width<100) {
        width=100;
    }
    if(height<100) {
        height=100;
    }

    this->resize(width, height);

    int xpos=32,ypos=32;
    if (config.check("xpos")) {
        xpos=config.find("xpos").asInt();
    }
    if (config.check("ypos")) {
        ypos=config.find("ypos").asInt();
    }
    this->move(xpos,ypos);

    setWindowTitle(GUI_NAME.c_str());

    connect(ui->animationView,SIGNAL(backgroundClicked()),this,SLOT(backgroundClicked()));
    connect(this,SIGNAL(resetCamera()),ui->animationView,SLOT(resetCamera()));

    ui->animationView->startTimer(1000/nFPS);


}
示例#2
0
void DualColorButton::mouseReleaseEvent(QMouseEvent *event)
{
	if(event->button() != Qt::LeftButton)
		return;
	QRectF fgr = foregroundRect();
	QRectF bgr = backgroundRect();
	if(fgr.contains(event->pos()))
		emit foregroundClicked(foreground_);
	else if(bgr.contains(event->pos()))
		emit backgroundClicked(background_);
	else if(event->pos().x() > fgr.right() && event->pos().y() < bgr.top())
		swapColors();
	else if(event->pos().x() < bgr.left() && event->pos().y() > fgr.bottom()) {
		foreground_ = Qt::black;
		background_ = Qt::white;
		emit foregroundChanged(foreground_);
		emit backgroundChanged(background_);
		update();
	}
}
ToolSettings::ToolSettings(QWidget *parent)
	: QDockWidget(parent), _currentQuickslot(0), _eraserOverride(0)
{
	// Initialize tool slots
	_toolprops.reserve(QUICK_SLOTS);
	for(int i=0;i<QUICK_SLOTS;++i)
		_toolprops.append(tools::ToolsetProperties());

	// Initialize UI
	QWidget *w = new QWidget(this);
	setWidget(w);

	auto *layout = new QVBoxLayout(w);
	layout->setMargin(3);

	auto *hlayout = new QHBoxLayout;
	hlayout->setContentsMargins(3, 3, 3, 0);
	layout->addLayout(hlayout);

	// Create quick toolchange slot buttons
	QButtonGroup *quickbuttons = new QButtonGroup(this);
	quickbuttons->setExclusive(true);
	for(int i=0;i<QUICK_SLOTS;++i) {
		auto *b = new widgets::ToolSlotButton(w);

		b->setCheckable(true);
		b->setText(QString::number(i+1));
		b->setMinimumSize(32, 32);
		b->setAutoRaise(true);

		hlayout->addWidget(b);
		quickbuttons->addButton(b, i);
		_quickslot[i] = b;
	}

	connect(quickbuttons, SIGNAL(buttonClicked(int)), this, SLOT(setToolSlot(int)));

	hlayout->addSpacerItem(new QSpacerItem(10, 1, QSizePolicy::Expanding));

	// Create foreground/background color changing widget
	_fgbgcolor = new widgets::DualColorButton(w);
	_fgbgcolor->setMinimumSize(32,32);
	hlayout->addWidget(_fgbgcolor);

	connect(_fgbgcolor, &widgets::DualColorButton::foregroundChanged, [this](const QColor &c){
		_currenttool->setForeground(c);
		_toolprops[_currentQuickslot].setForegroundColor(c);
		updateToolSlot(_currentQuickslot, false);
		emit foregroundColorChanged(c);
	});
	connect(_fgbgcolor, &widgets::DualColorButton::backgroundChanged, [this](const QColor &c){
		_currenttool->setBackground(c);
		_toolprops[_currentQuickslot].setBackgroundColor(c);
		updateToolSlot(_currentQuickslot, false);
		emit backgroundColorChanged(c);
	});

	// Create a widget stack
	_widgets = new QStackedWidget(this);
	layout->addWidget(_widgets, 1);

	_pensettings = new tools::PenSettings("pen", tr("Pen"));
	_widgets->addWidget(_pensettings->createUi(this));

	_brushsettings = new tools::BrushSettings("brush", tr("Brush"));
	_widgets->addWidget(_brushsettings->createUi(this));
	_currenttool = _brushsettings;

	_erasersettings = new tools::EraserSettings("eraser", tr("Eraser"));
	_widgets->addWidget(_erasersettings->createUi(this));

	_pickersettings = new tools::ColorPickerSettings("picker", tr("Color picker"));
	_widgets->addWidget(_pickersettings->createUi(this));

	_linesettings = new tools::SimpleSettings("line", tr("Line"), icon::fromTheme("draw-line"), tools::SimpleSettings::Line, true);
	_widgets->addWidget(_linesettings->createUi(this));

	_rectsettings = new tools::SimpleSettings("rectangle", tr("Rectangle"), icon::fromTheme("draw-rectangle"), tools::SimpleSettings::Rectangle, false);
	_widgets->addWidget(_rectsettings->createUi(this));

	_ellipsesettings = new tools::SimpleSettings("ellipse", tr("Ellipse"), icon::fromTheme("draw-ellipse"), tools::SimpleSettings::Ellipse, true);
	_widgets->addWidget(_ellipsesettings->createUi(this));

	_fillsettings = new tools::FillSettings("fill", tr("Flood fill"));
	_widgets->addWidget(_fillsettings->createUi(this));

	_textsettings = new tools::AnnotationSettings("annotation", tr("Annotation"));
	_widgets->addWidget(_textsettings->createUi(this));

	_selectionsettings = new tools::SelectionSettings("selection", tr("Selection"));
	_widgets->addWidget(_selectionsettings->createUi(this));

	_lasersettings = new tools::LaserPointerSettings("laser", tr("Laser pointer"));
	_widgets->addWidget(_lasersettings->createUi(this));

	connect(_pickersettings, SIGNAL(colorSelected(QColor)), _fgbgcolor, SLOT(setForeground(QColor)));

	// Create color changer dialogs
	auto dlg_fgcolor = new Color_Dialog(this);
	dlg_fgcolor->setAlphaEnabled(false);
	dlg_fgcolor->setWindowTitle(tr("Foreground color"));
	connect(dlg_fgcolor, SIGNAL(colorSelected(QColor)), this, SLOT(setForegroundColor(QColor)));
	connect(_fgbgcolor, SIGNAL(foregroundClicked(QColor)), dlg_fgcolor, SLOT(showColor(QColor)));

	auto dlg_bgcolor = new Color_Dialog(this);
	dlg_bgcolor->setWindowTitle(tr("Background color"));
	dlg_bgcolor->setAlphaEnabled(false);
	connect(dlg_bgcolor, SIGNAL(colorSelected(QColor)), this, SLOT(setBackgroundColor(QColor)));
	connect(_fgbgcolor, SIGNAL(backgroundClicked(QColor)), dlg_bgcolor, SLOT(showColor(QColor)));
}