Use proper font in GlyphEdit.
This commit is contained in:
parent
4dcbdddf4c
commit
0f5a46ce6f
2 changed files with 36 additions and 3 deletions
|
|
@ -20,8 +20,10 @@ from PyQt4.QtCore import (
|
|||
)
|
||||
|
||||
from PyQt4.QtGui import (
|
||||
QFont,
|
||||
QHBoxLayout,
|
||||
QLineEdit,
|
||||
QPalette,
|
||||
QToolButton,
|
||||
QWidget,
|
||||
)
|
||||
|
|
@ -44,24 +46,34 @@ class GlyphEdit(QWidget):
|
|||
def __init__(self, parent, document):
|
||||
super().__init__(parent)
|
||||
self.document = document
|
||||
config = document.config
|
||||
|
||||
self.layout = QHBoxLayout(self)
|
||||
self.layout.setSpacing(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.setText('B')
|
||||
self.bold.setShortcut('Ctrl+b')
|
||||
self.bold.toggled.connect(self.setBold)
|
||||
|
||||
self.italic = StyleButton(self)
|
||||
self.italic.setText('I')
|
||||
self.italic.setShortcut('Ctrl+i')
|
||||
self.italic.toggled.connect(self.setItalic)
|
||||
|
||||
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.italic)
|
||||
self.layout.addWidget(self.text)
|
||||
|
|
@ -69,6 +81,7 @@ class GlyphEdit(QWidget):
|
|||
def requestGlyph(self, glyph, bold, italic):
|
||||
self.bold.setChecked(bold)
|
||||
self.italic.setChecked(italic)
|
||||
self.setColor(glyph.qcolor)
|
||||
self.setEnabled(True)
|
||||
self.text.clear()
|
||||
self.text.setFocus()
|
||||
|
|
@ -76,6 +89,21 @@ class GlyphEdit(QWidget):
|
|||
def sendGlyph(self):
|
||||
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):
|
||||
if not allow and self.allowBoldItalic:
|
||||
self.italic.pressed.connect(self.bold.release)
|
||||
|
|
|
|||
|
|
@ -86,6 +86,11 @@ class PageObject(object):
|
|||
def color(self):
|
||||
return self.image.color
|
||||
|
||||
@property
|
||||
def qcolor(self):
|
||||
from PyQt4.QtGui import QColor
|
||||
return QColor(*self.color)
|
||||
|
||||
def fits(self, left, top, right, bottom):
|
||||
"""Return True if the glyph fits into the given bounding box."""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue