[Kommander-devel] branches/work/kommander/editor

Andras Mantia amantia at kde.org
Thu Aug 10 18:16:16 EDT 2006


SVN commit 571780 by amantia:

Use KTextEditor for editing associated text. 

CCMAIL: kommander-devel at kdewebdev.org

 M  +1 -1      Makefile.am  
 M  +20 -14    assoctexteditor.ui  
 M  +24 -5     assoctexteditorimpl.cpp  
 M  +10 -0     assoctexteditorimpl.h  


--- branches/work/kommander/editor/Makefile.am #571779:571780
@@ -13,7 +13,7 @@
 kmdr_editor_LDADD = $(top_builddir)/factory/libkommanderfactory.la \
 	$(top_builddir)/widget/libkommanderwidget.la \
 	$(top_builddir)/widgets/libkommanderwidgets.la \
-	$(top_builddir)/plugin/libkommanderplugin.la
+	$(top_builddir)/plugin/libkommanderplugin.la -lktexteditor
 
 # which sources should be compiled for kmdr_editor
 kmdr_editor_SOURCES = actiondnd.cpp actioneditorimpl.cpp \
--- branches/work/kommander/editor/assoctexteditor.ui #571779:571780
@@ -1,4 +1,4 @@
-<!DOCTYPE UI><UI version="3.2" stdsetdef="1">
+<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
 <class>AssocTextEditorBase</class>
 <widget class="QDialog">
     <property name="name">
@@ -85,14 +85,6 @@
                 </widget>
             </hbox>
         </widget>
-        <widget class="KTextEdit" row="1" column="0">
-            <property name="name">
-                <cstring>associatedTextEdit</cstring>
-            </property>
-            <property name="autoFormatting">
-                <set>AutoAll</set>
-            </property>
-        </widget>
         <widget class="QGroupBox" row="2" column="0">
             <property name="name">
                 <cstring>groupBox1</cstring>
@@ -194,10 +186,27 @@
                 </widget>
             </hbox>
         </widget>
+        <widget class="QFrame" row="1" column="0">
+            <property name="name">
+                <cstring>editorFrame</cstring>
+            </property>
+            <property name="sizePolicy">
+                <sizepolicy>
+                    <hsizetype>1</hsizetype>
+                    <vsizetype>3</vsizetype>
+                    <horstretch>0</horstretch>
+                    <verstretch>0</verstretch>
+                </sizepolicy>
+            </property>
+            <property name="frameShape">
+                <enum>Box</enum>
+            </property>
+            <property name="frameShadow">
+                <enum>Plain</enum>
+            </property>
+        </widget>
     </grid>
 </widget>
-<customwidgets>
-</customwidgets>
 <connections>
     <connection>
         <sender>AssocTextEditorBase</sender>
@@ -210,7 +219,4 @@
     <slot>AssocTextEditorBase_destroyed(QObject*)</slot>
 </slots>
 <layoutdefaults spacing="6" margin="11"/>
-<includehints>
-    <includehint>ktextedit.h</includehint>
-</includehints>
 </UI>
--- branches/work/kommander/editor/assoctexteditorimpl.cpp #571779:571780
@@ -22,7 +22,13 @@
 #include <kiconloader.h>
 #include <kpushbutton.h>
 #include <ktextedit.h>
+#include <kdebug.h>
 
+#include <ktexteditor/view.h>
+#include <ktexteditor/editorchooser.h>
+#include <ktexteditor/editinterface.h>
+#include <ktexteditor/viewcursorinterface.h>
+
 /* QT INCLUDES */
 #include <qstringlist.h>
 #include <qmetaobject.h>
@@ -31,7 +37,9 @@
 #include <qfile.h>
 #include <qobject.h>
 #include <qobjectlist.h>
+#include <qtimer.h>
 
+
 /* OTHER INCLUDES */
 #include <cstdio>
 #include "assoctexteditorimpl.h"
@@ -48,9 +56,9 @@
     : AssocTextEditorBase(a_parent, a_name, a_modal)
 {
   // text editor
-  associatedTextEdit->setFont(KGlobalSettings::fixedFont());
+/*  associatedTextEdit->setFont(KGlobalSettings::fixedFont());
   associatedTextEdit->setTabStopWidth(associatedTextEdit->fontMetrics().maxWidth() * 3);
-  associatedTextEdit->setTextFormat(Qt::PlainText);
+  associatedTextEdit->setTextFormat(Qt::PlainText);*/
   
   // icon for non-empty scripts
   scriptPixmap = KGlobal::iconLoader()->loadIcon("source", KIcon::Small);
@@ -68,9 +76,16 @@
       widgetsComboBox->setCurrentItem(i);
       break;
     }
+
+  doc = KTextEditor::createDocument ("libkatepart", this, "KTextEditor::Document");
+  QGridLayout *layout = new QGridLayout(editorFrame, 1, 1);
+  view = doc->createView(editorFrame);
+  layout->addWidget(view, 1,1);
+  
+  associatedTextEdit = dynamic_cast<KTextEditor::EditInterface*>(doc);
   setWidget(a_widget);
 
-  connect(associatedTextEdit, SIGNAL(textChanged()), SLOT(textEditChanged()));
+  connect(doc, SIGNAL(textChanged()), SLOT(textEditChanged()));
   connect(widgetsComboBox, SIGNAL(activated(int)), SLOT(widgetChanged(int)));
   connect(stateComboBox, SIGNAL(activated(int)), SLOT(stateChanged(int)));
   connect(filePushButton, SIGNAL(clicked()), SLOT(insertFile()));
@@ -78,12 +93,13 @@
   connect(widgetComboBox, SIGNAL(activated(int)), SLOT(insertWidgetName(int)));
   connect(treeWidgetButton, SIGNAL(clicked()), SLOT(selectWidget()));
   
-  associatedTextEdit->setFocus();
+  view->setFocus();
 }
 
 AssocTextEditor::~AssocTextEditor()
 {
   save();
+  delete doc;
 }
 
 void AssocTextEditor::setWidget(QWidget *a_widget)
@@ -261,7 +277,10 @@
 
 void AssocTextEditor::insertAssociatedText(const QString& a_text)
 {
-    associatedTextEdit->insert(a_text);
+  uint line, col;
+  KTextEditor::ViewCursorInterface *viewCursorIf = dynamic_cast<KTextEditor::ViewCursorInterface*>(view);
+  viewCursorIf->cursorPositionReal(&line, &col);
+  associatedTextEdit->insertText(line, col, a_text);
 }
 
 void AssocTextEditor::insertFile()
--- branches/work/kommander/editor/assoctexteditorimpl.h #571779:571780
@@ -32,6 +32,12 @@
 class FormWindow;
 class PropertyEditor;
 
+namespace KTextEditor {
+  class EditInterface;
+  class Document;
+  class View;
+}
+
 class AssocTextEditor : public AssocTextEditorBase
 {
   Q_OBJECT
@@ -99,6 +105,10 @@
   QString widgetToString(QWidget* widget, bool formatted = true);
   // Conver combo string to widget
   QWidget* widgetFromString(const QString& name);
+
+  KTextEditor::EditInterface *associatedTextEdit;
+  KTextEditor::Document *doc;
+  KTextEditor::View *view;
 };
 
 #endif


More information about the Kommander-devel mailing list