Exemple #1
0
Editor::Editor(QWidget *parent)
  :  QWidget(parent)
  , _view(NULL)
  , _buttonBar(NULL)
  , _xmlPreview(NULL)
  , _assembly(NULL)
  , _viewController(NULL)
  , _editorController(NULL)
  , _buttonBarController(NULL)
{
  qRegisterMetaType<ItemMove>("ItemMove");
  qRegisterMetaType<ItemsMove>("ItemsMove");

  // Widgets
  _view = new GraphicsView;

  _buttonBar = new ButtonBar;
  _buttonBar->setEnabled(false);

  _xmlPreview = new QTextEdit;
  _xmlPreview->setReadOnly(true);

  QVBoxLayout* vLyt = new QVBoxLayout(this);
  vLyt->setMargin(0);
  vLyt->setSpacing(1);
  vLyt->addWidget(_view, 4);
  vLyt->addWidget(_buttonBar);
  vLyt->addWidget(_xmlPreview, 1);

  // Controllers
  _viewController = new ViewController(_view, this);

  _buttonBarController = new ButtonBarController(_buttonBar, this);
  connect(_viewController, SIGNAL(selectionChanged(int)),
          _buttonBarController, SLOT(onSelectionChanged(int)));

  _editorController = new EditorController(this);
  connect(_viewController, SIGNAL(elementsMoved(ItemsMove)),
          _editorController, SLOT(onElementsMoved(ItemsMove)));
  connect(_buttonBarController, SIGNAL(actionTriggered(int,Action)),
          _editorController, SLOT(onAction(int,Action)));
  connect(_buttonBarController, SIGNAL(actionValueTriggered(int,Action,qreal)),
          _editorController, SLOT(onActionValue(int,Action,qreal)));
  connect(_buttonBarController, SIGNAL(nameChanged(QString)),
          _editorController, SLOT(onNameEdited(QString)));

  QAction* redoAction = _editorController->undoStack()->createRedoAction(this);
  redoAction->setShortcut(QKeySequence::Redo);
  redoAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
  this->addAction(redoAction);

  QAction* undoAction = _editorController->undoStack()->createUndoAction(this);
  undoAction->setShortcut(QKeySequence::Undo);
  undoAction->setShortcutContext(Qt::WidgetWithChildrenShortcut);
  this->addAction(undoAction);
}
void AMSamplePlatePre2013Selector::startCreatingNewPlate() {
	// We're going to steal the name edit as the place for the user to enter the name of this new plate
	disconnect(nameEdit, SIGNAL(textEdited(QString)), this, SLOT(onNameEdited(QString)));
	disconnect(nameEdit, SIGNAL(editingFinished()), this, SLOT(onPlateEditingFinished()));
	nameEdit->setText("[New Sample Plate Name]");
	nameEdit->setFocus();
	nameEdit->selectAll();
	connect(nameEdit, SIGNAL(editingFinished()), this, SLOT(onFinishCreatingNewPlate()));

}
AMSamplePlatePre2013Selector::AMSamplePlatePre2013Selector(AMSamplePlatePre2013* sourcePlate, QWidget *parent)
	: QWidget(parent) {

	samplePlateTableName_ = AMDbObjectSupport::s()->tableNameForClass<AMSamplePlatePre2013>();
	// Either use an external plate (if specified in sourcePlate), or make an internal one.
	plate_ = sourcePlate ? sourcePlate : new AMSamplePlatePre2013(this);

	setupUi();
	notesEditor->setObjectName("notesEditor");
	notesEditor->setStyleSheet("#notesEditor { background-image: url(:/notepadBackground.png); font: bold 15px \"Marker Felt\";}");

	AMDetailedItemDelegate* del = new AMDetailedItemDelegate(this);
	// Setting a new view fixes a grayed-menu-background drawing bug on mac
	QListView* lview = new QListView(this);
	lview->setItemDelegate(del);
	lview->setAlternatingRowColors(true);
	plateComboBox->setView(lview);

	notesEditor->setMaximumHeight(80);
	this->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);

	connect(&plateRefreshScheduler_, SIGNAL(executed()), this, SLOT(populateSamplePlates()));
	plateRefreshScheduler_.schedule();

	onSamplePlateChanged(/*plate_->valid()*/);

	connect(AMDatabase::database("user"), SIGNAL(updated(QString,int)), this, SLOT(onDatabaseUpdated(QString,int)), Qt::QueuedConnection);
	connect(AMDatabase::database("user"), SIGNAL(created(QString,int)), this, SLOT(onDatabaseCreated(QString,int)), Qt::QueuedConnection);
	connect(AMDatabase::database("user"), SIGNAL(removed(QString,int)), this, SLOT(onDatabaseRemoved(QString,int)), Qt::QueuedConnection);

	// GUI event connections
	connect(plateComboBox, SIGNAL(activated(int)), this, SLOT(onComboBoxActivated(int)));
	connect(nameEdit, SIGNAL(textEdited(QString)), this, SLOT(onNameEdited(QString)));
	connect(nameEdit, SIGNAL(editingFinished()), this, SLOT(onPlateEditingFinished()));
	connect(notesEditor, SIGNAL(textChanged()), this, SLOT(onNotesEdited()));
	connect(notesEditor, SIGNAL(editingFinished(int)), this, SLOT(onPlateEditingFinished()));

	notesHeaderButton->setChecked(false);
	notesEditor->setVisible(false);
	connect(notesHeaderButton, SIGNAL(clicked(bool)), notesEditor, SLOT(setVisible(bool)));

	// when our current sample plate is re-loaded out of the database, respond to update the GUI values
	connect(plate_, SIGNAL(loadedFromDb()), this, SLOT(onSamplePlateChanged()), Qt::QueuedConnection);
}
void AMSamplePlatePre2013Selector::onFinishCreatingNewPlate() {

	// restore usual connections for the name edit box...
	disconnect(nameEdit, SIGNAL(editingFinished()), this, SLOT(onFinishCreatingNewPlate()));

	nameEdit->clearFocus();
	connect(nameEdit, SIGNAL(textEdited(QString)), this, SLOT(onNameEdited(QString)));
	connect(nameEdit, SIGNAL(editingFinished()), this, SLOT(onPlateEditingFinished()));

	QString newName = nameEdit->text();
	if(newName.isEmpty())
		return;

	AMSamplePlatePre2013 newPlate;
	newPlate.setName(nameEdit->text());
	if(newPlate.storeToDb(AMDatabase::database("user")))
		changeSamplePlate(newPlate.id());

	// this update will be picked up by our 'onDatabaseUpdated()' slot

}