summaryrefslogtreecommitdiff
path: root/src/ui.py
blob: 95ced0c1b050a24ff91497043f443526effa2c77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from common import *
from editorui import *


class KPLayerList(QtGui.QWidget):
	class LayerModel(QtCore.QAbstractListModel):
		def headerData(self, section, orientation, role = Qt.DisplayRole):
			return 'Layer'

		def rowCount(self, parent):
			return len(KP.map.layers)

		def data(self, index, role = Qt.DisplayRole):
			try:
				if (role == Qt.DisplayRole or role == Qt.EditRole) and index.isValid():
					return KP.map.layers[index.row()].name
			except IndexError:
				pass

			return QtCore.QVariant()

		def flags(self, index):
			if not index.isValid():
				return Qt.ItemIsEnabled
			
			return Qt.ItemIsEditable \
					| QtCore.QAbstractListModel.flags(self, index)

		def setData(self, index, value, role = Qt.EditRole):
			if index.isValid() and role == Qt.EditRole:
				value = str(value.toString())
				if len(value) > 0:
					KP.map.layers[index.row()].name = value
					self.dataChanged.emit(index, index)
					return True

			return False
	

	def __init__(self):
		QtGui.QWidget.__init__(self)

		self.layout = QtGui.QVBoxLayout()
		self.layout.setSpacing(0)

		self.model = KPLayerList.LayerModel()

		self.listView = QtGui.QListView()
		self.listView.setModel(self.model)
		self.layout.addWidget(self.listView)

		self.toolbar = QtGui.QToolBar()
		self.layout.addWidget(self.toolbar)

		self.setupToolbar(self.toolbar)

		self.setLayout(self.layout)
	

	def setupToolbar(self, tb):
		tb.addAction(QtGui.QIcon(), 'Add', self.addLayer)
		tb.addAction(QtGui.QIcon(), 'Remove', self.removeLayer)
		tb.addAction(QtGui.QIcon(), 'Move Up', self.moveUp)
		tb.addAction(QtGui.QIcon(), 'Move Down', self.moveDown)
	

	def addLayer(self):
		pass
	def removeLayer(self):
		pass
	def moveUp(self):
		pass
	def moveDown(self):
		pass


class KPMainWindow(QtGui.QMainWindow):
	def __init__(self):
		QtGui.QMainWindow.__init__(self)

		self.editor = KPEditorWidget()
		self.setCentralWidget(self.editor)

		self.setupMenuBar()

		self.setupDocks()
	

	def setupMenuBar(self):
		mb = self.menuBar()

		m = mb.addMenu('&File')
		# ...
	

	def setupDocks(self):
		self.layerList = KPLayerList()
		self.layerListDock = QtGui.QDockWidget('Layers')
		self.layerListDock.setWidget(self.layerList)

		self.addDockWidget(Qt.RightDockWidgetArea, self.layerListDock)