justified text and small improvements

This commit is contained in:
Stefan Kögl 2014-04-29 09:54:58 +02:00
parent 0d2372df12
commit ca1d492198
6 changed files with 66 additions and 191 deletions

View File

@ -1,2 +1,2 @@
pyuic4 -o texter_ui.py texter3.ui pyuic4 -o texter_ui.py texter3.ui
# pykdeuic4-python2.7 -o text_sorter_ui.py texter4.ui pyuic4 -o text_sorter_ui.py texter4.ui

View File

@ -71,6 +71,10 @@ class TextSorterDialog(QtGui.QWidget, Ui_TextSorterDialog):
def fill_list(self): def fill_list(self):
self.model = self.parent().parent().model self.model = self.parent().parent().model
self.text_list.setModel(self.model) self.text_list.setModel(self.model)
ix = self.parent().parent().current_index
index = self.model.index(ix, 0)
self.text_list.setCurrentIndex(index)
def slot_text_up(self): def slot_text_up(self):
row = self.text_list.currentIndex().row() row = self.text_list.currentIndex().row()
@ -81,6 +85,7 @@ class TextSorterDialog(QtGui.QWidget, Ui_TextSorterDialog):
text_db[row-1], text_db[row] = text_db[row], text_db[row-1] text_db[row-1], text_db[row] = text_db[row], text_db[row-1]
self.text_list.setCurrentIndex(self.model.index(row - 1, 0)) self.text_list.setCurrentIndex(self.model.index(row - 1, 0))
self.text_list.clicked.emit(self.model.index(row - 1, 0)) self.text_list.clicked.emit(self.model.index(row - 1, 0))
self.parent().parent().db_dirty = True
return True return True
def slot_text_down(self): def slot_text_down(self):
@ -93,6 +98,7 @@ class TextSorterDialog(QtGui.QWidget, Ui_TextSorterDialog):
index = self.model.index(row + 1, 0) index = self.model.index(row + 1, 0)
self.text_list.setCurrentIndex(index) self.text_list.setCurrentIndex(index)
self.text_list.clicked.emit(index) self.text_list.clicked.emit(index)
self.parent().parent().db_dirty = True
return True return True
def slot_show_text(self, model_index): def slot_show_text(self, model_index):
@ -108,6 +114,7 @@ class TextSorterDialog(QtGui.QWidget, Ui_TextSorterDialog):
index = self.model.index(0, 0) index = self.model.index(0, 0)
self.text_list.setCurrentIndex(index) self.text_list.setCurrentIndex(index)
self.text_list.clicked.emit(index) self.text_list.clicked.emit(index)
self.parent().parent().db_dirty = True
class FadeAnimation(QtCore.QObject): class FadeAnimation(QtCore.QObject):
animation_started = QtCore.pyqtSignal() animation_started = QtCore.pyqtSignal()
@ -120,8 +127,8 @@ class FadeAnimation(QtCore.QObject):
self.fade_steps = fade_steps self.fade_steps = fade_steps
self.current_alpha = 255 self.current_alpha = 255
self.timer = None self.timer = None
def start_animation(self): def start_animation(self):
print "start_animation" print "start_animation"
self.animation_started.emit() self.animation_started.emit()
@ -165,7 +172,6 @@ class FadeAnimation(QtCore.QObject):
self.animation_finished.emit() self.animation_finished.emit()
print "animation_finished" print "animation_finished"
class TextAnimation(QtCore.QObject): class TextAnimation(QtCore.QObject):
animation_started = QtCore.pyqtSignal() animation_started = QtCore.pyqtSignal()
@ -245,6 +251,7 @@ class TextAnimation(QtCore.QObject):
try: try:
char = self.text.next() char = self.text.next()
self.dst_cursor.insertText(char) self.dst_cursor.insertText(char)
self.dst_text_edit.ensureCursorVisible()
except StopIteration: except StopIteration:
self.fragment_iter += 1 self.fragment_iter += 1
self.text = None self.text = None
@ -287,11 +294,14 @@ class MainWindow(KMainWindow, Ui_MainWindow):
self.db_dirty = False self.db_dirty = False
self.is_animate = False self.is_animate = False
self.fade_animation = None self.fade_animation = None
self.dialog = None
self.current_object = None
self.current_index = -1
self.is_auto_publish = False self.is_auto_publish = False
self.setupUi(self) self.setupUi(self)
self.fade_animation = FadeAnimation(self.live_text, 6, self) self.fade_animation = FadeAnimation(self.live_text, 6, self)
self.font = QtGui.QFont("monospace", self.default_size) self.font = QtGui.QFont("monospace", self.default_size)
@ -333,7 +343,7 @@ class MainWindow(KMainWindow, Ui_MainWindow):
self.preview_size_action.triggered[QtGui.QAction].connect(self.slot_preview_font_size) self.preview_size_action.triggered[QtGui.QAction].connect(self.slot_preview_font_size)
self.live_size_action.triggered[QtGui.QAction].connect(self.slot_live_font_size) self.live_size_action.triggered[QtGui.QAction].connect(self.slot_live_font_size)
self.fade_action.triggered.connect(self.slot_fade) #self.fade_action.triggered.connect(self.slot_fade)
self.next_action.triggered.connect(self.slot_next_item) self.next_action.triggered.connect(self.slot_next_item)
self.previous_action.triggered.connect(self.slot_previous_item) self.previous_action.triggered.connect(self.slot_previous_item)
@ -364,6 +374,7 @@ class MainWindow(KMainWindow, Ui_MainWindow):
"format_font_family", "format_font_family",
#"format_font_size", #"format_font_size",
"format_text_background_color", "format_text_background_color",
"format_list_style",
"format_list_indent_more", "format_list_indent_more",
"format_list_indent_less", "format_list_indent_less",
"format_text_bold", "format_text_bold",
@ -371,7 +382,7 @@ class MainWindow(KMainWindow, Ui_MainWindow):
"format_text_strikeout", "format_text_strikeout",
"format_text_italic", "format_text_italic",
"format_align_right", "format_align_right",
"format_align_justify", #"format_align_justify",
"manage_link", "manage_link",
"format_text_subscript", "format_text_subscript",
"format_text_superscript", "format_text_superscript",
@ -380,6 +391,7 @@ class MainWindow(KMainWindow, Ui_MainWindow):
for action in self.live_editor_collection.actions(): for action in self.live_editor_collection.actions():
text = str(action.objectName()) text = str(action.objectName())
print "text", text
if text in disabled_action_names: if text in disabled_action_names:
action.setVisible(False) action.setVisible(False)
@ -493,12 +505,12 @@ class MainWindow(KMainWindow, Ui_MainWindow):
spacer = KToolBarSpacerAction(self.action_collection) spacer = KToolBarSpacerAction(self.action_collection)
self.action_collection.addAction("1_spacer", spacer) self.action_collection.addAction("1_spacer", spacer)
self.fade_action = self.action_collection.addAction("fade_action") #self.fade_action = self.action_collection.addAction("fade_action")
#icon = QtGui.QIcon.fromTheme(_fromUtf8("go-previous-view-page")) ##icon = QtGui.QIcon.fromTheme(_fromUtf8("go-previous-view-page"))
#self.fade_action.setIcon(icon) ##self.fade_action.setIcon(icon)
self.fade_action.setIconText("fade") #self.fade_action.setIconText("fade")
self.fade_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_F)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut)) #self.fade_action.setShortcut(KShortcut(QtGui.QKeySequence(QtCore.Qt.ALT + QtCore.Qt.Key_F)), KAction.ShortcutTypes(KAction.ActiveShortcut | KAction.DefaultShortcut))
self.previous_action = self.action_collection.addAction("previous_action") self.previous_action = self.action_collection.addAction("previous_action")
icon = QtGui.QIcon.fromTheme(_fromUtf8("go-previous-view-page")) icon = QtGui.QIcon.fromTheme(_fromUtf8("go-previous-view-page"))
@ -637,7 +649,6 @@ class MainWindow(KMainWindow, Ui_MainWindow):
self.preview_size_action.setFontSize(self.default_size) self.preview_size_action.setFontSize(self.default_size)
self.preview_text.document().setDefaultFont(self.font) self.preview_text.document().setDefaultFont(self.font)
def slot_set_live_defaults(self): def slot_set_live_defaults(self):
self.live_center_action.setChecked(True) self.live_center_action.setChecked(True)
self.live_text.alignCenter() self.live_text.alignCenter()
@ -645,29 +656,35 @@ class MainWindow(KMainWindow, Ui_MainWindow):
self.live_size_action.setFontSize(self.default_size) self.live_size_action.setFontSize(self.default_size)
self.live_text.document().setDefaultFont(self.font) self.live_text.document().setDefaultFont(self.font)
def slot_clear_live(self): def slot_clear_live(self):
self.live_text.clear() self.live_text.clear()
self.slot_set_live_defaults() self.slot_set_live_defaults()
def slot_clear_preview(self): def slot_clear_preview(self):
self.preview_text.clear() self.preview_text.clear()
self.slot_set_preview_defaults() self.slot_set_preview_defaults()
def slot_fade(self): def slot_fade(self):
if self.fade_animation.timer is None: if self.fade_animation.timer is None:
self.fade_animation.start_animation() self.fade_animation.start_animation()
def fill_combo_box(self): def fill_combo_box(self):
if self.dialog is not None:
self.dialog.deleteLater()
self.dialog = None
self.text_combo.clear() self.text_combo.clear()
for preview, text in self.model.text_db: current_row = -1
for ix, list_obj in enumerate(self.model.text_db):
preview, text = list_obj
self.text_combo.addAction(preview) self.text_combo.addAction(preview)
if list_obj == self.current_object:
current_row = ix
self.text_combo.setCurrentItem(0) if current_row == -1:
self.slot_load_preview_text(0) current_row = self.current_index
self.slot_load_preview_text(current_row)
self.text_combo.setCurrentItem(current_row)
def slot_load_preview_text(self, index): def slot_load_preview_text(self, index):
try: try:
@ -678,7 +695,6 @@ class MainWindow(KMainWindow, Ui_MainWindow):
if self.is_auto_publish: if self.is_auto_publish:
self.slot_publish() self.slot_publish()
def slot_save_live_text(self): def slot_save_live_text(self):
text = self.live_text.toHtml() text = self.live_text.toHtml()
preview = self.get_preview_text(unicode(self.live_text.toPlainText())) preview = self.get_preview_text(unicode(self.live_text.toPlainText()))
@ -733,6 +749,12 @@ class MainWindow(KMainWindow, Ui_MainWindow):
def slot_open_dialog(self): def slot_open_dialog(self):
self.current_index = self.text_combo.currentItem()
self.current_object = self.model.text_db[self.current_index]
if self.dialog is not None:
self.dialog.deleteLater()
self.dialog = None
self.dialog = KDialog(self) self.dialog = KDialog(self)
self.dialog_widget = TextSorterDialog(self.dialog) self.dialog_widget = TextSorterDialog(self.dialog)
self.dialog.setMainWidget(self.dialog_widget) self.dialog.setMainWidget(self.dialog_widget)
@ -745,8 +767,6 @@ class MainWindow(KMainWindow, Ui_MainWindow):
#self.dialog.setFixedSize(x, global_height-40) #self.dialog.setFixedSize(x, global_height-40)
self.dialog.okClicked.connect(self.fill_combo_box) self.dialog.okClicked.connect(self.fill_combo_box)
self.dialog.exec_() self.dialog.exec_()
self.dialog.deleteLater()
self.dialog = None
def slot_load(self): def slot_load(self):
path = os.path.expanduser("~/.texter") path = os.path.expanduser("~/.texter")

View File

@ -19,6 +19,8 @@ class TextModel(QtCore.QAbstractTableModel):
return 2 return 2
def data(self, index, role): def data(self, index, role):
if role not in (1,3,4,5,6,7,8,9,10,13):
print "role", role
if not index.isValid() or \ if not index.isValid() or \
not 0 <= index.row() < self.rowCount(): not 0 <= index.row() < self.rowCount():
return QVariant() return QVariant()
@ -28,6 +30,10 @@ class TextModel(QtCore.QAbstractTableModel):
if role == QtCore.Qt.DisplayRole: if role == QtCore.Qt.DisplayRole:
return self.text_db[row][column] return self.text_db[row][column]
#return "foo bar" #return "foo bar"
elif role == QtCore.Qt.ForegroundRole:
return QtGui.QBrush(QtCore.Qt.black)
elif role == QtCore.Qt.BackgroundRole:
return QtGui.QBrush(QtCore.Qt.white)
return QtCore.QVariant() return QtCore.QVariant()
@ -43,7 +49,11 @@ class TextModel(QtCore.QAbstractTableModel):
def setData(self, index, value, role): def setData(self, index, value, role):
if role == QtCore.Qt.EditRole: if role == QtCore.Qt.EditRole:
self.text_db[index.row()][index.column()] = value.toString() text = value.toString()
if not text:
return False
else:
self.text_db[index.row()][index.column()] = text
return True return True

View File

@ -1,11 +1,12 @@
#!/usr/bin/env python # -*- coding: utf-8 -*-
# coding=UTF-8
# Form implementation generated from reading ui file 'texter4.ui'
# #
# Generated by pykdeuic4 from texter4.ui on Mon Apr 21 01:34:50 2014 # Created: Mon Apr 28 21:58:51 2014
# by: PyQt4 UI code generator 4.10.3
# #
# WARNING! All changes to this file will be lost. # WARNING! All changes made in this file will be lost!
from PyKDE4 import kdecore
from PyKDE4 import kdeui
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
try: try:
@ -39,44 +40,6 @@ class Ui_TextSorterDialog(object):
self.text_list.setSizePolicy(sizePolicy) self.text_list.setSizePolicy(sizePolicy)
self.text_list.setMinimumSize(QtCore.QSize(200, 576)) self.text_list.setMinimumSize(QtCore.QSize(200, 576))
self.text_list.setMaximumSize(QtCore.QSize(16777215, 576)) self.text_list.setMaximumSize(QtCore.QSize(16777215, 576))
palette = QtGui.QPalette()
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(255, 255, 255))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush)
brush = QtGui.QBrush(QtGui.QColor(128, 125, 123))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush)
brush = QtGui.QBrush(QtGui.QColor(128, 125, 123))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush)
brush = QtGui.QBrush(QtGui.QColor(0, 0, 0))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush)
self.text_list.setPalette(palette)
self.text_list.setObjectName(_fromUtf8("text_list")) self.text_list.setObjectName(_fromUtf8("text_list"))
self.text_preview = KRichTextWidget(self.splitter) self.text_preview = KRichTextWidget(self.splitter)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
@ -250,7 +213,7 @@ class Ui_TextSorterDialog(object):
QtCore.QMetaObject.connectSlotsByName(TextSorterDialog) QtCore.QMetaObject.connectSlotsByName(TextSorterDialog)
def retranslateUi(self, TextSorterDialog): def retranslateUi(self, TextSorterDialog):
TextSorterDialog.setWindowTitle(kdecore.i18n(_fromUtf8("Form"))) TextSorterDialog.setWindowTitle(_translate("TextSorterDialog", "Form", None))
self.remove_button.setText(kdecore.i18n(_fromUtf8("Remove"))) self.remove_button.setText(_translate("TextSorterDialog", "Remove", None))
from PyKDE4.kdeui import KButtonGroup, KArrowButton, KPushButton, KRichTextWidget from PyKDE4.kdeui import KButtonGroup, KArrowButton, KPushButton, KRichTextWidget

View File

@ -233,7 +233,7 @@
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set> <set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
</property> </property>
<property name="richTextSupport"> <property name="richTextSupport">
<set>KRichTextWidget::SupportAlignment|KRichTextWidget::SupportChangeListStyle|KRichTextWidget::SupportFontFamily|KRichTextWidget::SupportFontSize|KRichTextWidget::SupportIndentLists|KRichTextWidget::SupportTextForegroundColor</set> <set>KRichTextWidget::SupportAlignment|KRichTextWidget::SupportFontFamily|KRichTextWidget::SupportFontSize|KRichTextWidget::SupportTextForegroundColor</set>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -38,124 +38,6 @@
<height>576</height> <height>576</height>
</size> </size>
</property> </property>
<property name="palette">
<palette>
<active>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</active>
<inactive>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>255</red>
<green>255</green>
<blue>255</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</inactive>
<disabled>
<colorrole role="WindowText">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>128</red>
<green>125</green>
<blue>123</blue>
</color>
</brush>
</colorrole>
<colorrole role="Text">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>128</red>
<green>125</green>
<blue>123</blue>
</color>
</brush>
</colorrole>
<colorrole role="Base">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
<colorrole role="Window">
<brush brushstyle="SolidPattern">
<color alpha="255">
<red>0</red>
<green>0</green>
<blue>0</blue>
</color>
</brush>
</colorrole>
</disabled>
</palette>
</property>
</widget> </widget>
<widget class="KRichTextWidget" name="text_preview"> <widget class="KRichTextWidget" name="text_preview">
<property name="sizePolicy"> <property name="sizePolicy">