Use proper font in GlyphEdit.

This commit is contained in:
Andrey Golovizin 2014-09-19 23:56:12 +02:00
parent 4dcbdddf4c
commit 0f5a46ce6f
2 changed files with 36 additions and 3 deletions

View file

@ -20,8 +20,10 @@ from PyQt4.QtCore import (
) )
from PyQt4.QtGui import ( from PyQt4.QtGui import (
QFont,
QHBoxLayout, QHBoxLayout,
QLineEdit, QLineEdit,
QPalette,
QToolButton, QToolButton,
QWidget, QWidget,
) )
@ -44,24 +46,34 @@ class GlyphEdit(QWidget):
def __init__(self, parent, document): def __init__(self, parent, document):
super().__init__(parent) super().__init__(parent)
self.document = document self.document = document
config = document.config
self.layout = QHBoxLayout(self) self.layout = QHBoxLayout(self)
self.layout.setSpacing(0) self.layout.setSpacing(0)
self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setContentsMargins(0, 0, 0, 0)
self.text = QLineEdit(self)
self.text.returnPressed.connect(self.sendGlyph)
font = QFont()
if config.glyph_font_family:
font.setFamily(config.glyph_font_family)
if config.glyph_font_size:
font.setPixelSize(config.glyph_font_size)
self.text.setFont(font)
self.bold = StyleButton(self) self.bold = StyleButton(self)
self.bold.setText('B') self.bold.setText('B')
self.bold.setShortcut('Ctrl+b') self.bold.setShortcut('Ctrl+b')
self.bold.toggled.connect(self.setBold)
self.italic = StyleButton(self) self.italic = StyleButton(self)
self.italic.setText('I') self.italic.setText('I')
self.italic.setShortcut('Ctrl+i') self.italic.setShortcut('Ctrl+i')
self.italic.toggled.connect(self.setItalic)
self.setAllowBoldItalic(self.document.config.allow_bold_italic) self.setAllowBoldItalic(self.document.config.allow_bold_italic)
self.text = QLineEdit(self)
self.text.returnPressed.connect(self.sendGlyph)
self.layout.addWidget(self.bold) self.layout.addWidget(self.bold)
self.layout.addWidget(self.italic) self.layout.addWidget(self.italic)
self.layout.addWidget(self.text) self.layout.addWidget(self.text)
@ -69,6 +81,7 @@ class GlyphEdit(QWidget):
def requestGlyph(self, glyph, bold, italic): def requestGlyph(self, glyph, bold, italic):
self.bold.setChecked(bold) self.bold.setChecked(bold)
self.italic.setChecked(italic) self.italic.setChecked(italic)
self.setColor(glyph.qcolor)
self.setEnabled(True) self.setEnabled(True)
self.text.clear() self.text.clear()
self.text.setFocus() self.text.setFocus()
@ -76,6 +89,21 @@ class GlyphEdit(QWidget):
def sendGlyph(self): def sendGlyph(self):
self.glyphEntered.emit(self.text.text(), self.bold.isChecked(), self.italic.isChecked()) self.glyphEntered.emit(self.text.text(), self.bold.isChecked(), self.italic.isChecked())
def setBold(self, enable):
font = self.text.font()
font.setBold(enable)
self.text.setFont(font)
def setItalic(self, enable):
font = self.text.font()
font.setItalic(enable)
self.text.setFont(font)
def setColor(self, color):
palette = self.text.palette()
palette.setColor(QPalette.Text, color)
self.text.setPalette(palette)
def setAllowBoldItalic(self, allow=True): def setAllowBoldItalic(self, allow=True):
if not allow and self.allowBoldItalic: if not allow and self.allowBoldItalic:
self.italic.pressed.connect(self.bold.release) self.italic.pressed.connect(self.bold.release)

View file

@ -86,6 +86,11 @@ class PageObject(object):
def color(self): def color(self):
return self.image.color return self.image.color
@property
def qcolor(self):
from PyQt4.QtGui import QColor
return QColor(*self.color)
def fits(self, left, top, right, bottom): def fits(self, left, top, right, bottom):
"""Return True if the glyph fits into the given bounding box.""" """Return True if the glyph fits into the given bounding box."""