Put ShapeWidget in a neat GroupBox with the shape's name in the caption.

This commit is contained in:
David Vierra 2015-09-17 15:54:21 -10:00
parent 4758e6f7dd
commit 83cf434426
3 changed files with 60 additions and 73 deletions

View File

@ -93,6 +93,10 @@ class Round(BrushShape):
ID = "Round"
icon = "shapes/round.png"
def __init__(self):
super(Round, self).__init__()
self.displayName = self.tr("Round")
def shapeFunc(self, blockPositions, shape):
# For spheres: x^2 + y^2 + z^2 <= r^2
# For ovoids: x^2/rx^2 + y^2/ry^2 + z^2/rz^2 <= 1
@ -125,6 +129,7 @@ class Square(BrushShape):
def __init__(self):
super(Square, self).__init__()
self.displayName = self.tr("Square")
self.optionsWidget = QtGui.QWidget()
self.hollowCheckbox = QtGui.QCheckBox()
@ -148,6 +153,10 @@ class Diamond(BrushShape):
ID = "Diamond"
icon = "shapes/diamond.png"
def __init__(self):
super(Diamond, self).__init__()
self.displayName = self.tr("Diamond")
def shapeFunc(self, blockPositions, selectionSize):
# This is an octahedron.
@ -174,6 +183,10 @@ class Cylinder(BrushShape):
ID = "Cylinder"
icon = "shapes/cylinder.png"
def __init__(self):
super(Cylinder, self).__init__()
self.displayName = self.tr("Cylinder")
def shapeFunc(self, blockPositions, selectionSize):
# axis = y
#
@ -207,6 +220,10 @@ class ChunkShape(BrushShape):
ID = "Chunk"
icon = "shapes/chunk.png"
def __init__(self):
super(ChunkShape, self).__init__()
self.displayName = self.tr("Chunk")
def createShapedSelection(self, box, dimension):
return box.chunkBox(dimension)
@ -215,6 +232,10 @@ class ParabolicDome(BrushShape):
ID = "ParabolicDome"
icon = "shapes/parabolic_dome.png"
def __init__(self):
super(ParabolicDome, self).__init__()
self.displayName = self.tr("Parabolic Dome")
def shapeFunc(self, blockPositions, selectionSize):
# In 2D:
@ -261,5 +282,6 @@ class ParabolicDome(BrushShape):
# xxx what is responsible for "owning" the instances of BrushShape??
# Currently the ShapeWidget seems to own them.
def getShapes():
return Square(), Round(), Diamond(), Cylinder(), ParabolicDome()

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>469</width>
<width>517</width>
<height>711</height>
</rect>
</property>
@ -15,8 +15,8 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,0,0,0,0">
<item row="7" column="1" colspan="2">
<layout class="QGridLayout" name="gridLayout" rowstretch="0,0,0,0,0,0,0">
<item row="6" column="1" colspan="2">
<widget class="SpinSlider" name="hoverSpinSlider" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
@ -26,7 +26,7 @@
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<item row="3" column="1" colspan="2">
<widget class="SpinSlider" name="xSpinSlider" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
@ -36,28 +36,21 @@
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="label">
<property name="text">
<string>Shape:</string>
</property>
</widget>
</item>
<item row="6" column="0">
<item row="5" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Length:</string>
</property>
</widget>
</item>
<item row="7" column="0">
<item row="6" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Hover:</string>
</property>
</widget>
</item>
<item row="2" column="1" colspan="2">
<item row="1" column="1" colspan="2">
<widget class="BrushModeWidget" name="brushModeInput" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
@ -67,81 +60,28 @@
</property>
</widget>
</item>
<item row="2" column="0">
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Mode:</string>
</property>
</widget>
</item>
<item row="5" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Height:</string>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Width:</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QScrollArea" name="scrollArea">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>447</width>
<height>69</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="margin">
<number>0</number>
</property>
<item>
<widget class="ShapeWidget" name="brushShapeInput" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item row="5" column="1" colspan="2">
<item row="4" column="1" colspan="2">
<widget class="SpinSlider" name="ySpinSlider" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
@ -151,7 +91,7 @@
</property>
</widget>
</item>
<item row="6" column="1" colspan="2">
<item row="5" column="1" colspan="2">
<widget class="SpinSlider" name="zSpinSlider" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
@ -161,6 +101,22 @@
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="ShapeWidget" name="brushShapeInput" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>40</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>

View File

@ -21,6 +21,8 @@ class ShapeWidget(QtGui.QWidget):
addShapes = kwargs.pop('addShapes', None)
super(ShapeWidget, self).__init__(*args, **kwargs)
buttons = self.buttons = []
self.groupBox = QtGui.QGroupBox("Shape:")
flowLayout = flowlayout.FlowLayout()
actionGroup = QtGui.QActionGroup(self)
actionGroup.setExclusive(True)
@ -29,6 +31,7 @@ class ShapeWidget(QtGui.QWidget):
shapes = list(getShapes())
if addShapes:
shapes.extend(addShapes)
for shape in shapes:
if shape.icon is not None:
filename = os.path.join(iconBase, shape.icon)
@ -61,7 +64,8 @@ class ShapeWidget(QtGui.QWidget):
self.optionsHolder = QtGui.QStackedWidget()
layout = Column(flowLayout, (self.optionsHolder, 1))
self.setLayout(layout)
self.groupBox.setLayout(layout)
self.setLayout(Column(self.groupBox, margin=0))
currentID = BrushShapeSetting.value(shapes[0].ID)
shapesByID = {shape.ID: shape for shape in shapes}
@ -77,7 +81,12 @@ class ShapeWidget(QtGui.QWidget):
shapeChanged = QtCore.Signal(object)
shapeOptionsChanged = QtCore.Signal()
def groupBoxTitle(self, shape):
return self.tr("Shape: ") + shape.displayName
def shapeDidChange(self, newShape):
self.groupBox.setTitle(self.groupBoxTitle(newShape))
while self.optionsHolder.count():
self.optionsHolder.removeWidget(self.optionsHolder.widget(0))