Ejemplo n.º 1
0
QString FileDialog::getFilePath(QWidget *parent, const QString &title, Mode mode, const QList<QPair<QString, QStringList>> &filterTextAndSuffixesList)
{
	QString lastDialogPath = appController()->settingsManager()->lastFileDialogPath();
	PAINTFIELD_DEBUG << lastDialogPath;
	
	QStringList filters;

	for (const auto &textAndSuffixes : filterTextAndSuffixesList)
	{
		QString filter = textAndSuffixes.first;

		if (textAndSuffixes.second.size())
		{
			filter += " (";
			for (auto suffix : textAndSuffixes.second)
			{
				filter = filter + "*." + suffix + " ";
			}
			filter.chop(1);
			filter += ")";
		}

		filters << filter;
	}
	
	QFileDialog fileDialog(parent);
	
	fileDialog.setDirectory(lastDialogPath);
	//fileDialog.setOption(QFileDialog::DontUseNativeDialog, true);
	fileDialog.setWindowTitle(title);
	fileDialog.setNameFilters(filters);
	
	switch (mode)
	{
		default:
		case OpenFile:
			fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
			fileDialog.setFileMode(QFileDialog::ExistingFile);
			break;
		case SaveFile:
			fileDialog.setAcceptMode(QFileDialog::AcceptSave);
			fileDialog.setConfirmOverwrite(true);
			fileDialog.setFileMode(QFileDialog::AnyFile);
			fileDialog.setDefaultSuffix(filterTextAndSuffixesList.first().second.first());
			break;
	}
	
	if (!fileDialog.exec())
		return QString();
	
	if (fileDialog.selectedFiles().size() == 0)
		return QString();
	
	appController()->settingsManager()->setLastFileDialogPath(fileDialog.directory().path());
	return fileDialog.selectedFiles().first();
}
Ejemplo n.º 2
0
ToolManager::ToolManager(QObject *parent) :
    QObject(parent),
	_actionGroup(new QActionGroup(this))
{
	createActions(appController()->settingsManager()->toolInfoHash());
	connect(_actionGroup, SIGNAL(triggered(QAction*)), this, SLOT(onActionTriggered(QAction*)));
}
Ejemplo n.º 3
0
void CanvasTabWidget::addCanvasesFromUrls(const QList<QUrl> &urls)
{
	for (const QUrl &url : urls)
	{
		auto filepath = url.toLocalFile();
		auto existingCanvas = appController()->findCanvasWithFilepath(filepath);
		
		Canvas *canvas = nullptr;
		
		if (existingCanvas)
		{
			canvas = new Canvas(existingCanvas, workspace());
		}
		else
		{
			auto document = DocumentController::createFromFile(url.toLocalFile());
			
			if (document)
				canvas = new Canvas(document, workspace());
			else
				return;
		}
		
		addCanvas(canvas);
	}
}
Ejemplo n.º 4
0
bool DocumentController::save(Document *document)
{
	if (!document->isModified())
		return true;
	
	if (document->filePath().isEmpty())	// first save
		return saveAs(document);
	
	auto result = FormatSupport::exportToFile(
			document->filePath(),
			appController()->formatSupportManager()->paintFieldFormatSupport(),
			document->layerScene()->topLevelLayers(),
			document->size()
	);
	
	if (!result)
	{
		MessageBox::show(QMessageBox::Warning, tr("Failed to save file."), QString());
		return false;
	}
	
	document->setModified(false);
	
	return true;
}
Ejemplo n.º 5
0
void CanvasNavigator::beginDragScaling(const QPoint &pos)
{
	appController()->cursorStack()->add(navigatingCursorId, Qt::SizeVerCursor);
	
	d->navigationMode = Scaling;
	d->navigationOrigin = pos;
	d->backupTransforms();
}
Ejemplo n.º 6
0
void CanvasNavigator::beginDragRotation(const QPoint &pos)
{
	appController()->cursorStack()->add(navigatingCursorId, Qt::ClosedHandCursor);
	
	d->navigationMode = Rotating;
	d->navigationOrigin = pos;
	d->backupTransforms();
}
Ejemplo n.º 7
0
			void FontManager::load(const BaseClass::IndexType &index, void *data, u32 size)
			{
				if (!exists(index)) {
					drivers::render::Font *driverFont(appController()->driver()->currentWindow()->newFont());
					driverFont->loadFromMemory(data, size);
					set(index, driverFont);
				}
			}
Ejemplo n.º 8
0
Document *DocumentController::createFromNewDialog(QWidget *dialogParent)
{
	NewDocumentDialog dialog(dialogParent);
	if (dialog.exec() != QDialog::Accepted)
		return 0;
	
	auto layer = std::make_shared<RasterLayer>(tr("New Layer"));
	return new Document(appController()->unduplicatedFileTempName(tr("Untitled")), dialog.documentSize(), {layer});
}
Ejemplo n.º 9
0
Document *DocumentController::createFromClipboard()
{
	auto pixmap = qApp->clipboard()->pixmap();
	if (pixmap.isNull())
		return 0;
	
	auto layer = RasterLayer::createFromImage(pixmap.toImage());
	layer->setName(tr("Clipboard"));
	return new Document(appController()->unduplicatedFileTempName(tr("Clipboard")), pixmap.size(), {layer});
}
Ejemplo n.º 10
0
Document *DocumentController::createFromImageFile(const QString &path)
{
	QList<LayerRef> layers;
	QSize size;
	QString name;
	
	bool result = FormatSupport::importFromFile(
			path,
			appController()->formatSupportManager()->formatSupports(),
			&layers,
			&size,
			&name
	);
	
	if (result)
		return new Document(appController()->unduplicatedFileTempName(name), size, layers);
	else
		return nullptr;
}
Ejemplo n.º 11
0
bool DocumentController::exportToImage(Document *document, QWidget *dialogParent)
{
	return FormatSupport::exportToFileDialog(
			dialogParent,
			tr("Export"),
			true,
			appController()->formatSupportManager()->formatSupports(),
			document->layerScene()->topLevelLayers(),
			document->size()
	);
}
Ejemplo n.º 12
0
bool DocumentController::saveAs(Document *document)
{
	return FormatSupport::exportToFileDialog(
			0,
			tr("Save As"),
			false,
			{appController()->formatSupportManager()->paintFieldFormatSupport()},
			document->layerScene()->topLevelLayers(),
			document->size()
	);
}
Ejemplo n.º 13
0
Document *DocumentController::createFromImportDialog()
{
	QList<LayerRef> layers;
	QSize size;
	QString name;
	
	bool result = FormatSupport::importFromFileDialog(
			0,
			tr("Import"),
			tr("Any files"),
			appController()->formatSupportManager()->formatSupports(),
			&layers,
			&size,
			&name
	);
	
	if (result)
		return new Document(appController()->unduplicatedFileTempName(name), size, layers);
	else
		return nullptr;
}
Ejemplo n.º 14
0
void CanvasNavigator::onPressedKeysChanged()
{
	PAINTFIELD_DEBUG;
	
	auto cursorStack = appController()->cursorStack();
	auto keyTracker = d->keyTracker;
	
	auto addOrRemove = [cursorStack, keyTracker](const QKeySequence &seq, const QString &id, const QCursor &cursor)
	{
		if (keyTracker->match(seq))
			cursorStack->add(id, cursor);
		else
			cursorStack->remove(id);
	};
	
	addOrRemove(d->translationKeys, readyToTranslateCursorId, Qt::OpenHandCursor);
	addOrRemove(d->scaleKeys, readyToScaleCursorId, Qt::SizeVerCursor);
	addOrRemove(d->rotationKeys, readyToRotateCursorId, Qt::OpenHandCursor);
}
Ejemplo n.º 15
0
CanvasNavigator::CanvasNavigator(KeyTracker *keyTracker, CanvasViewController *controller) :
	QObject(controller),
	d(new Data)
{
	d->canvas = controller->canvas();
	d->controller = controller;
	d->keyTracker = keyTracker;
	
	connect(d->keyTracker, SIGNAL(pressedKeysChanged(QSet<int>)), this, SLOT(onPressedKeysChanged()));
	
	// setup key bindings
	{
		auto keyBindingHash = appController()->settingsManager()->value({".key-bindings"}).toMap();
		
		d->translationKeys = keyBindingHash["paintfield.canvas.dragTranslation"].toString();
		d->scaleKeys = keyBindingHash["paintfield.canvas.dragScale"].toString();
		d->rotationKeys = keyBindingHash["paintfield.canvas.dragRotation"].toString();
	}
}
Ejemplo n.º 16
0
Document *DocumentController::createFromSavedFile(const QString &path)
{
	PAINTFIELD_DEBUG << path;
	
	QList<LayerRef> layers;
	QSize size;
	QString name;
	
	bool result = FormatSupport::importFromFile(
			path,
			{appController()->formatSupportManager()->paintFieldFormatSupport()},
			&layers,
			&size,
			&name
	);
	
	if (!result)
		return nullptr;
	
	auto document = new Document(name, size, layers, 0);
	document->setFilePath(path);
	
	return document;
}
Ejemplo n.º 17
0
void CanvasNavigator::endDragRotation()
{
	appController()->cursorStack()->remove(navigatingCursorId);
	d->navigationMode = NoNavigation;
}