[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8885 - trunk/gnue-forms/src/uidrivers/qt3/widgets
From: |
johannes |
Subject: |
[gnue] r8885 - trunk/gnue-forms/src/uidrivers/qt3/widgets |
Date: |
Fri, 20 Oct 2006 05:22:54 -0500 (CDT) |
Author: johannes
Date: 2006-10-20 05:22:53 -0500 (Fri, 20 Oct 2006)
New Revision: 8885
Modified:
trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py
Log:
Improved MultiLine text edits
Modified: trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py 2006-10-20 08:35:01 UTC
(rev 8884)
+++ trunk/gnue-forms/src/uidrivers/qt3/widgets/entry.py 2006-10-20 10:22:53 UTC
(rev 8885)
@@ -482,33 +482,93 @@
qt.QLineEdit.__init__(self, parent)
BaseEntry.__init__(self, ui_widget, qt.QTextEdit)
+ self.__last_para = 0
+ self.__last_pos = 0
+
self.setTextFormat(qt.Qt.PlainText)
+ self.connect(self, qt.SIGNAL('textChanged()'),
+ self.__on_text_changed)
+ self.connect(self, qt.SIGNAL('cursorPositionChanged(int, int)'),
+ self.__on_cursor_changed)
+
# -------------------------------------------------------------------------
# UI slots
# -------------------------------------------------------------------------
def _ui_set_value_(self, value):
- # TODO: check for newlines (and paragraph handling)
self.setText(value)
# -------------------------------------------------------------------------
def _ui_set_cursor_position_(self, position):
- # TODO: what about other paragraphs ?
- self.setCursorPosition(0, position)
+ (para, offset) = self.__position_to_qt(position)
+ self.setCursorPosition(para, offset)
# -------------------------------------------------------------------------
def _ui_set_selected_area_(self, selection1, selection2):
- self.setSelection(0, selection1, 0, selection2)
+ (para1, offs1) = self.__position_to_qt(selection1)
+ (para2, offs2) = self.__position_to_qt(selection2)
+ self.setSelection(para1, offs1, para2, offs2)
+ # -------------------------------------------------------------------------
+ # Qt-Signals
+ # -------------------------------------------------------------------------
+ def __on_text_changed(self):
+
+ # FIXME: This signal is fired twice when a selection get's replaced by
+ # a new text. By doing this and the lack of a working
+ # getCursorPosition() replacing selected text does not work properly.
+ if not self.ui_widget._block_change_:
+ self.ui_widget._request('REPLACEVALUE', text=unicode(self.text()),
+ position=self.__qt_to_position() + 1)
+
+ # -------------------------------------------------------------------------
+
+ def __on_cursor_changed(self, para, pos):
+
+ # pyQT has a broken getCursorPosition(), so we have no chance to find
+ # out where the cursor is currently located. That's the reason for
+ # doing it this way.
+ self.__last_para = para
+ self.__last_pos = pos
+
+
+ # -------------------------------------------------------------------------
+ # Map a QT position into a GF position
+ # -------------------------------------------------------------------------
+
+ def __qt_to_position(self):
+
+ result = self.__last_pos + self.__last_para
+ for i in range(self.__last_para):
+ result += self.paragraphLength(i)
+
+ return result
+
+
+ # -------------------------------------------------------------------------
+ # Map a GF position into a QT position
+ # -------------------------------------------------------------------------
+
+ def __position_to_qt(self, position):
+
+ val = unicode(self.text())[:position]
+ para = val.count('\n')
+ offset = position
+ if para > 0:
+ offset = len(val.split('\n')[-1])
+
+ return (para, offset)
+
+
# =============================================================================
# Checkbox (TriState)
# =============================================================================
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8885 - trunk/gnue-forms/src/uidrivers/qt3/widgets,
johannes <=