[nostalgia/core/studio] Replace TileSheetEditor ScrollView scrolling with manual version
This commit is contained in:
		@@ -10,18 +10,10 @@ import QtQuick 2.0
 | 
			
		||||
import QtQuick.Controls 2.14
 | 
			
		||||
import 'qrc:/qml/'
 | 
			
		||||
 | 
			
		||||
ScrollView {
 | 
			
		||||
Rectangle {
 | 
			
		||||
	id: tileSheetEditor
 | 
			
		||||
	ScrollBar.horizontal.policy: ScrollBar.AsNeeded
 | 
			
		||||
	ScrollBar.vertical.policy: ScrollBar.AsNeeded
 | 
			
		||||
	contentWidth: tileGrid.width
 | 
			
		||||
	contentHeight: tileGrid.height
 | 
			
		||||
	clip: true
 | 
			
		||||
	focusPolicy: Qt.WheelFocus
 | 
			
		||||
 | 
			
		||||
	background: Rectangle {
 | 
			
		||||
		color: '#717d7e'
 | 
			
		||||
	}
 | 
			
		||||
	color: '#717d7e'
 | 
			
		||||
 | 
			
		||||
	MouseArea {
 | 
			
		||||
		id: mouseArea
 | 
			
		||||
@@ -45,10 +37,42 @@ ScrollView {
 | 
			
		||||
				} else if (tileGrid.scaleFactor > 0.9) {
 | 
			
		||||
					tileGrid.scaleFactor -= mod;
 | 
			
		||||
				}
 | 
			
		||||
				wheel.accepted = true;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
				if (tileGrid.width <= this.width) {
 | 
			
		||||
					tileGrid.x = this.width / 2 - tileGrid.width / 2;
 | 
			
		||||
				}
 | 
			
		||||
				if (tileGrid.height <= this.height) {
 | 
			
		||||
					tileGrid.y = this.height / 2 - tileGrid.height / 2;
 | 
			
		||||
				}
 | 
			
		||||
			} else {
 | 
			
		||||
				wheel.accepted = false;
 | 
			
		||||
				const mod = 15;
 | 
			
		||||
				if (tileGrid.width > this.width) {
 | 
			
		||||
					if (wheel.angleDelta.x > 0) {
 | 
			
		||||
						if (tileGrid.x < tileGrid.width / 2) {
 | 
			
		||||
							tileGrid.x += mod;
 | 
			
		||||
						}
 | 
			
		||||
					} else if (wheel.angleDelta.x < 0) {
 | 
			
		||||
						let x2 = tileGrid.x + tileGrid.width;
 | 
			
		||||
						if (x2 > this.width / 2) {
 | 
			
		||||
							tileGrid.x -= mod;
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
				if (tileGrid.height > this.height) {
 | 
			
		||||
					if (wheel.angleDelta.y > 0) {
 | 
			
		||||
						if (tileGrid.y < this.height / 2) {
 | 
			
		||||
							tileGrid.y += mod;
 | 
			
		||||
						}
 | 
			
		||||
					} else if (wheel.angleDelta.y < 0) {
 | 
			
		||||
						let y2 = tileGrid.y + tileGrid.height;
 | 
			
		||||
						if (y2 > this.height / 2) {
 | 
			
		||||
							tileGrid.y -= mod;
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			wheel.accepted = true;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		onPositionChanged: sheetData.updatePixel(pixelAt(mouseX, mouseY))
 | 
			
		||||
@@ -74,10 +98,10 @@ ScrollView {
 | 
			
		||||
		id: tileGrid
 | 
			
		||||
		property double scaleFactor: 0.9
 | 
			
		||||
		property int baseTileSize: Math.min(2000 / tileGrid.columns, 1000 / tileGrid.rows)
 | 
			
		||||
		x: tileSheetEditor.width / 2 - this.width / 2
 | 
			
		||||
		y: tileSheetEditor.height / 2 - this.height / 2
 | 
			
		||||
		width: tileGrid.columns * tileGrid.baseTileSize * tileGrid.scaleFactor
 | 
			
		||||
		height: tileGrid.rows * tileGrid.baseTileSize * tileGrid.scaleFactor
 | 
			
		||||
		//anchors.horizontalCenter: parent.horizontalCenter
 | 
			
		||||
		//anchors.verticalCenter: parent.verticalCenter
 | 
			
		||||
		rows: sheetData ? sheetData.rows : 1
 | 
			
		||||
		columns: sheetData ? sheetData.columns : 1
 | 
			
		||||
		Repeater {
 | 
			
		||||
 
 | 
			
		||||
@@ -224,17 +224,17 @@ TileSheetEditor::TileSheetEditor(QString path, const studio::Context *ctx, QWidg
 | 
			
		||||
	m_splitter = new QSplitter(this);
 | 
			
		||||
	auto canvasParent = new QWidget(m_splitter);
 | 
			
		||||
	auto canvasLyt = new QVBoxLayout(canvasParent);
 | 
			
		||||
	auto canvas = new QQuickWidget(canvasParent);
 | 
			
		||||
	canvasLyt->addWidget(canvas);
 | 
			
		||||
	m_canvas = new QQuickWidget(canvasParent);
 | 
			
		||||
	canvasLyt->addWidget(m_canvas);
 | 
			
		||||
	canvasLyt->setMenuBar(setupToolBar());
 | 
			
		||||
	lyt->addWidget(m_splitter);
 | 
			
		||||
	m_splitter->addWidget(canvasParent);
 | 
			
		||||
	m_splitter->addWidget(setupColorPicker(m_splitter));
 | 
			
		||||
	m_splitter->setStretchFactor(0, 1);
 | 
			
		||||
	m_sheetData.updatePixels(m_ctx, path);
 | 
			
		||||
	canvas->rootContext()->setContextProperty("sheetData", &m_sheetData);
 | 
			
		||||
	canvas->setSource(QUrl::fromLocalFile(":/qml/TileSheetEditor.qml"));
 | 
			
		||||
	canvas->setResizeMode(QQuickWidget::SizeRootObjectToView);
 | 
			
		||||
	m_canvas->rootContext()->setContextProperty("sheetData", &m_sheetData);
 | 
			
		||||
	m_canvas->setSource(QUrl::fromLocalFile(":/qml/TileSheetEditor.qml"));
 | 
			
		||||
	m_canvas->setResizeMode(QQuickWidget::SizeRootObjectToView);
 | 
			
		||||
	setColorTable(m_sheetData.palette());
 | 
			
		||||
	restoreState();
 | 
			
		||||
}
 | 
			
		||||
@@ -304,6 +304,7 @@ void TileSheetEditor::saveState() {
 | 
			
		||||
	settings.setValue("m_splitter/state", m_splitter->saveState());
 | 
			
		||||
	settings.setValue("m_sheetData/tileRows", m_sheetData.rows());
 | 
			
		||||
	settings.setValue("m_sheetData/tileColumns", m_sheetData.columns());
 | 
			
		||||
	settings.setValue("m_colorPicker.colorTable/geometry", m_colorPicker.colorTable->horizontalHeader()->saveState());
 | 
			
		||||
	settings.endGroup();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -313,6 +314,7 @@ void TileSheetEditor::restoreState() {
 | 
			
		||||
	m_splitter->restoreState(settings.value("m_splitter/state", m_splitter->saveState()).toByteArray());
 | 
			
		||||
	m_sheetData.setRows(settings.value("m_sheetData/tileRows", 1).toInt());
 | 
			
		||||
	m_sheetData.setColumns(settings.value("m_sheetData/tileColumns", 1).toInt());
 | 
			
		||||
	m_colorPicker.colorTable->horizontalHeader()->restoreState(settings.value("m_colorPicker.colorTable/geometry", m_colorPicker.colorTable->horizontalHeader()->saveState()).toByteArray());
 | 
			
		||||
	settings.endGroup();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -88,8 +88,9 @@ class TileSheetEditor: public studio::Editor {
 | 
			
		||||
		const studio::Context *m_ctx = nullptr;
 | 
			
		||||
		SheetData m_sheetData;
 | 
			
		||||
		QSplitter *m_splitter = nullptr;
 | 
			
		||||
		class LabeledSpinner *m_tilesX = nullptr;
 | 
			
		||||
		class LabeledSpinner *m_tilesY = nullptr;
 | 
			
		||||
		struct LabeledSpinner *m_tilesX = nullptr;
 | 
			
		||||
		struct LabeledSpinner *m_tilesY = nullptr;
 | 
			
		||||
		class QQuickWidget* m_canvas = nullptr;
 | 
			
		||||
		struct {
 | 
			
		||||
			QComboBox *palette = nullptr;
 | 
			
		||||
			QTableWidget *colorTable = nullptr;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user