コード例 #1
0
ファイル: colorwidget.cpp プロジェクト: CGRU/cgru
void ColorWidget::mouseDoubleClickEvent( QMouseEvent * event)
{
//printf("ColorWidget::mouseDoubleClickEvent:\n");
   QColorDialog * dialog = new QColorDialog( clr->c, this);
   dialog->setModal( false);
   dialog->setOptions( QColorDialog::NoButtons);
   connect( dialog, SIGNAL( currentColorChanged( const QColor &)), this, SLOT( currentColorChanged( const QColor &)));
   connect( dialog, SIGNAL( finished(              int         )), this, SLOT( finished(              int         )));
   Watch::repaintStart();
   dialog->open();
//   dialog->open( this, "accepted");
}
コード例 #2
0
bool DynamicObjectItemDelegate::editorEvent(QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem&, const QModelIndex& index)
{
	if (event->type() == QEvent::MouseButtonRelease)
	{
		auto* node = (DynamicObjectModel::Node*)index.internalPointer();
		if (!node)
		{
			return false;
		}
		if (node->onClick && index.column() == 1)
		{
			QWidget* widget = qobject_cast<QWidget*>(parent());
			QPoint pos = widget->mapToGlobal(QPoint(static_cast<QMouseEvent*>(event)->x(), static_cast<QMouseEvent*>(event)->y()));
			node->onClick(widget, pos);
			return true;
		}
		if (index.data().type() == QMetaType::QColor)
		{
			QColorDialog* dialog = new QColorDialog(index.data().value<QColor>());
			dialog->setModal(true);
			auto old_color = index.data().value<QColor>();
			dialog->connect(dialog, &QColorDialog::rejected, [model, index, old_color]{
				model->setData(index, old_color);
			});
			dialog->connect(dialog, &QColorDialog::currentColorChanged, [model, index, dialog]()
			{
				QColor color = dialog->currentColor();
				Lumix::Vec3 value;
				value.x = color.redF();
				value.y = color.greenF();
				value.z = color.blueF();
				model->setData(index, color);
			});
			dialog->show();
		}
		else if (index.data().type() == QMetaType::Bool)
		{
			model->setData(index, !index.data().toBool());
			return true;
		}
	}
	return false;
}