aboutsummaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAdrien Tétar2015-10-24 09:39:38 +0200
committerAdrien Tétar2015-10-24 09:39:38 +0200
commit96d82800eaa15eaec91db8489ef5dc2459a3c811 (patch)
tree7e8fe81ffdb226ecddf478849316327939c56698 /Lib
parent3754935c961939a19b25f4e1a1356e12500c59bf (diff)
downloadtrufont-96d82800eaa15eaec91db8489ef5dc2459a3c811.tar.bz2
meta: fix sizing mechanism, fix AllFonts()
Diffstat (limited to 'Lib')
-rw-r--r--Lib/defconQt/fontView.py13
-rw-r--r--Lib/defconQt/glyphCollectionView.py25
-rw-r--r--Lib/defconQt/groupsView.py9
-rw-r--r--Lib/defconQt/spaceCenter.py33
4 files changed, 29 insertions, 51 deletions
diff --git a/Lib/defconQt/fontView.py b/Lib/defconQt/fontView.py
index 02656f8..dfa2fe2 100644
--- a/Lib/defconQt/fontView.py
+++ b/Lib/defconQt/fontView.py
@@ -76,7 +76,7 @@ class Application(QApplication):
for window in QApplication.topLevelWidgets():
if isinstance(window, MainWindow):
fonts.append(window._font)
- return fonts
+ return fonts
def currentFont(self):
return self._currentMainWindow._font
@@ -1050,9 +1050,9 @@ class MainWindow(QMainWindow):
self.selectionLabel.setText(text)
def _squareSizeChanged(self):
- val = self.sqSizeSlider.value()
- self.collectionWidget._sizeEvent(self.width(), val)
- QToolTip.showText(QCursor.pos(), str(val), self)
+ squareSize = self.sqSizeSlider.value()
+ self.collectionWidget.squareSize = squareSize
+ QToolTip.showText(QCursor.pos(), str(squareSize), self)
def event(self, event):
if event.type() == QEvent.WindowActivate:
@@ -1063,11 +1063,6 @@ class MainWindow(QMainWindow):
app.setCurrentGlyph(lastSelectedGlyph)
return super(MainWindow, self).event(event)
- def resizeEvent(self, event):
- if self.isVisible():
- self.collectionWidget._sizeEvent(event.size().width())
- super(MainWindow, self).resizeEvent(event)
-
def setWindowTitle(self, title=None):
if title is None:
if self.font.path is not None:
diff --git a/Lib/defconQt/glyphCollectionView.py b/Lib/defconQt/glyphCollectionView.py
index 795ac08..1bbf5d2 100644
--- a/Lib/defconQt/glyphCollectionView.py
+++ b/Lib/defconQt/glyphCollectionView.py
@@ -50,7 +50,7 @@ class GlyphCollectionWidget(QWidget):
super(GlyphCollectionWidget, self).__init__(parent)
self.setAttribute(Qt.WA_KeyCompression)
self._glyphs = []
- self.squareSize = 56
+ self._squareSize = 56
self._columns = 10
self._selection = set()
self._oldSelection = None
@@ -70,6 +70,7 @@ class GlyphCollectionWidget(QWidget):
self._scrollArea.dragMoveEvent = self.pipeDragMoveEvent
self._scrollArea.dragLeaveEvent = self.pipeDragLeaveEvent
self._scrollArea.dropEvent = self.pipeDropEvent
+ self._scrollArea.resizeEvent = self.resizeEvent
self._scrollArea.setAcceptDrops(True)
self._scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self._scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
@@ -141,6 +142,15 @@ class GlyphCollectionWidget(QWidget):
currentDropIndex = property(_get_currentDropIndex, _set_currentDropIndex)
+ def _get_squareSize(self):
+ return self._squareSize
+
+ def _set_squareSize(self, squareSize):
+ self._squareSize = squareSize
+ self._rewindColumns()
+
+ squareSize = property(_get_squareSize, _set_squareSize)
+
def pipeDragEnterEvent(self, event):
# glyph reordering
if event.source() == self:
@@ -180,14 +190,11 @@ class GlyphCollectionWidget(QWidget):
self.glyphs = [glyph
for glyph in self._glyphs if glyph is not None]
- # TODO: break this down into set width/set square
- # TODO: see whether scrollArea gets resizeEvents
- def _sizeEvent(self, width, squareSize=None):
- sw = self._scrollArea.verticalScrollBar().width(
- ) + self._scrollArea.contentsMargins().right()
- if squareSize is not None:
- self.squareSize = squareSize
- columns = (width - sw) // self.squareSize
+ def resizeEvent(self, event):
+ self._rewindColumns()
+
+ def _rewindColumns(self):
+ columns = self._scrollArea.viewport().width() // self.squareSize
if not columns > 0:
return
self._columns = columns
diff --git a/Lib/defconQt/groupsView.py b/Lib/defconQt/groupsView.py
index 3a4f959..671116c 100644
--- a/Lib/defconQt/groupsView.py
+++ b/Lib/defconQt/groupsView.py
@@ -181,6 +181,7 @@ class GroupsWindow(QWidget):
# TODO: calib this more
layout.setColumnStretch(4, 1)
self.setLayout(layout)
+ self.adjustSize()
self.setWindowTitle("Groups window – %s %s" % (
self.font.info.familyName, self.font.info.styleName))
@@ -286,11 +287,3 @@ class GroupsWindow(QWidget):
def closeEvent(self, event):
self.font.removeObserver(self, "Groups.Changed")
event.accept()
-
- def resizeEvent(self, event):
- if self.isVisible():
- margins = self.layout().contentsMargins()
- width = event.size().width() - (margins.left() + margins.right())
- self.collectionWidget._sizeEvent(width)
- self.stackWidget.update()
- super(GroupsWindow, self).resizeEvent(event)
diff --git a/Lib/defconQt/spaceCenter.py b/Lib/defconQt/spaceCenter.py
index fa5d25b..0c9596b 100644
--- a/Lib/defconQt/spaceCenter.py
+++ b/Lib/defconQt/spaceCenter.py
@@ -197,11 +197,6 @@ class MainSpaceWindow(QWidget):
self.canvas.setGlyphs(self.glyphs)
self.table.setGlyphs(self.glyphs)
- def resizeEvent(self, event):
- if self.isVisible():
- self.canvas._sizeEvent(event)
- super(MainSpaceWindow, self).resizeEvent(event)
-
pointSizes = [50, 75, 100, 125, 150, 200, 250, 300, 350, 400, 450, 500]
@@ -337,6 +332,7 @@ class GlyphsCanvas(QWidget):
self._wrapLines = True
self._scrollArea = QScrollArea(self.parent())
+ self._scrollArea.resizeEvent = self.resizeEvent
self._scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self._scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self._scrollArea.setWidget(self)
@@ -372,18 +368,12 @@ class GlyphsCanvas(QWidget):
return
self._wrapLines = wrapLines
if self._wrapLines:
- sw = self._scrollArea.verticalScrollBar().width(
- ) + self._scrollArea.contentsMargins().right()
- self.resize(self.parent().parent().parent().width() -
- sw, self.height())
+ self.resize(self._scrollArea.viewport().width(), self.height())
self._scrollArea.setHorizontalScrollBarPolicy(
Qt.ScrollBarAlwaysOff)
self._scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
else:
- sh = self._scrollArea.horizontalScrollBar().height(
- ) + self._scrollArea.contentsMargins().bottom()
- self.resize(self.width(), self.parent(
- ).parent().parent().height() - sh)
+ self.resize(self.width(), self._scrollArea.viewport().height())
self._scrollArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self._scrollArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
self.update()
@@ -428,15 +418,11 @@ class GlyphsCanvas(QWidget):
.5 * self.ptSize * self._lineHeight + 20)
self.update()
- def _sizeEvent(self, event):
+ def resizeEvent(self, event):
if self._wrapLines:
- sw = self._scrollArea.verticalScrollBar().width(
- ) + self._scrollArea.contentsMargins().right()
- self.resize(event.size().width() - sw, self.height())
+ self.resize(self._scrollArea.viewport().width(), self.height())
else:
- sh = self._scrollArea.horizontalScrollBar().height(
- ) + self._scrollArea.contentsMargins().bottom()
- self.resize(self.width(), event.size().height() - sh)
+ self.resize(self.width(), self._scrollArea.viewport().height())
def wheelEvent(self, event):
if event.modifiers() & Qt.ControlModifier:
@@ -617,12 +603,9 @@ class GlyphsCanvas(QWidget):
painter.restore()
painter.translate(gWidth, 0)
- scrollMargins = self._scrollArea.contentsMargins()
- innerHeight = self._scrollArea.height() - scrollMargins.top() - \
- scrollMargins.bottom()
+ innerHeight = self._scrollArea.viewport().height()
if not self._wrapLines:
- innerWidth = self._scrollArea.width() - scrollMargins.left() - \
- scrollMargins.right()
+ innerWidth = self._scrollArea.viewport().width()
width = max(innerWidth, cur_width + self.padding * 2)
else:
width = self.width()