[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    [PATCH] KPlato embedding
From:       Raphael Langerhorst <raphael.langerhorst () kdemail ! net>
Date:       2006-01-16 14:01:35
Message-ID: 200601161501.35743.raphael.langerhorst () kdemail ! net
[Download RAW message or body]

Hello,

The attached patch(es) enable KPlato embedding. The patch still has known 
limitations, it is work-in-progress.

The patch for kdgantt is necessary to avoid event processing while 
transitioning the view from an embedded component to the parent component. 
The gantt view looks ok with this patch, but I don't know if there is any 
impact on kdgantt functionality. At least it shouldn't do event processing 
right there - koffice is crashing if it does.

Known limitations of the kplato patch:

* RMB context menu on tasks in the gantt view doesn't work anymore (due to 
ganttview - view decoupling), this can be amended, just needs some work.
* zooming is not yet working correctly.
* the task list (left part of the gantt view) is not yet drawing correctly 
when embedded. In fact I have no idea why and didn't look into it enough yet 
to find out what needs to be done.
* crashes on (auto-)save; it should be possible to fix this, but haven't 
looked into this yet.


I'm now again away (no internet) until Wednesday but wanted to post the 
current status to the list. If possible I would like to commit the patch 
before the beta 1 release, there are no i18n string changes.
Comments welcome.

Best wishes,
-- 
Raphael Langerhorst
http://raphael.g-system.at/blog/

["kdgantt_no_events.patch" (text/x-diff)]

Index: kdgantt/KDGanttViewSubwidgets.cpp
===================================================================
--- kdgantt/KDGanttViewSubwidgets.cpp	(Revision 498186)
+++ kdgantt/KDGanttViewSubwidgets.cpp	(Arbeitskopie)
@@ -3072,7 +3072,7 @@
 void KDGanttCanvasView::setMyContentsHeight( int hei )
 {
     mySignalSender->closingBlocked = true;
-    qApp->processEvents();
+//     qApp->processEvents();
     mySignalSender->closingBlocked = false;
     //qDebug("setMyContentsHeight %d %d ", hei,  myMyContentsHeight);
     if ( hei > 0 )

["kplato_embedding.patch" (text/x-diff)]

Index: kplato/kpttaskappointmentsview.h
===================================================================
--- kplato/kpttaskappointmentsview.h	(Revision 498178)
+++ kplato/kpttaskappointmentsview.h	(Arbeitskopie)
@@ -39,7 +39,6 @@
 namespace KPlato
 {
 
-class View;
 class Project;
 class Resource;
 class Task;
@@ -53,15 +52,15 @@
     Q_OBJECT
 public:
 
-    TaskAppointmentsView(View *view, QWidget *parent);
+    TaskAppointmentsView(QWidget *parent);
 
     //~TaskAppointmentsView();
 
     void zoom(double zoom);
 
-    View *mainView() { return m_mainview; }
     void draw();
     void draw(Task *task);
+    virtual void drawContents(QPainter* painter);
     void print(KPrinter &printer);
     void clear();
     
@@ -85,7 +84,6 @@
     };
     
 private:
-    View *m_mainview;
     
     int m_defaultFontSize;
     Task *m_task;
Index: kplato/kptganttview.h
===================================================================
--- kplato/kptganttview.h	(Revision 498178)
+++ kplato/kptganttview.h	(Arbeitskopie)
@@ -46,7 +46,6 @@
 
 class TaskAppointmentsView;
 
-class View;
 class Node;
 class Task;
 class Project;
@@ -58,15 +57,19 @@
 
  public:
 
-    GanttView(View *view, QWidget *parent, bool readWrite=true, const char* name = 0 \
); +    GanttView(QWidget *parent, bool readWrite=true, const char* name = 0  );
 
     //~GanttView();
 
-    void zoom(double zoom);
+    void setZoom(double zoom);
 
     void draw(Project &project);
     void drawChanges(Project &project);
-    View *mainView();
+    
+    /**
+     * Call draw() or drawChanges() before calling this.
+     */
+    void drawOnPainter(QPainter* painter);
 
     Node *currentNode() const;
 
@@ -89,6 +92,7 @@
     void modifyRelation(Relation *rel, int linkType) ;
     void addRelation(Node *par, Node *child, int linkType);
     void itemDoubleClicked();
+    void itemRenamed(Node*, const QString&);
     
 public slots:
     void popupMenuRequested(KDGanttViewItem * item, const QPoint & pos, int);
@@ -163,7 +167,6 @@
     void getContextClosedNodes(Context::Ganttview &context, KDGanttViewItem *item) \
const;  
 private:
-    View *m_mainview;
     bool m_readWrite;
     int m_defaultFontSize;
     KDGanttViewItem *m_currentItem;
Index: kplato/kptpertview.h
===================================================================
--- kplato/kptpertview.h	(Revision 498178)
+++ kplato/kptpertview.h	(Arbeitskopie)
@@ -47,7 +47,7 @@
 
     ~PertView();
     
-    void zoom(double /*zoom*/) {}
+    void setZoom(double /*zoom*/) {}
 
     void draw();
     View *mainView() const { return m_mainview; } 
Index: kplato/kptview.h
===================================================================
--- kplato/kptview.h	(Revision 498178)
+++ kplato/kptview.h	(Arbeitskopie)
@@ -76,8 +76,6 @@
     void projectCalculate();
 
     virtual DCOPObject* dcopObject();
-    
-    void renameNode(Node *node, QString name);
    
     virtual bool setContext(Context &context);
     virtual void getContext(Context &context) const;
@@ -119,6 +117,8 @@
     
     void slotExportGantt(); // testing
     
+    void slotRenameNode(Node *node, const QString& name);
+    
 protected slots:
     void slotProjectCalendar();
     void slotProjectWorktime();
Index: kplato/kpttaskappointmentsview.cc
===================================================================
--- kplato/kpttaskappointmentsview.cc	(Revision 498178)
+++ kplato/kpttaskappointmentsview.cc	(Arbeitskopie)
@@ -21,7 +21,6 @@
 
 #include "kptappointment.h"
 #include "kpttask.h"
-#include "kptview.h"
 
 #include <kcalendarsystem.h>
 #include <kglobal.h>
@@ -56,9 +55,8 @@
 }
 
 //-------------------------------------------
-TaskAppointmentsView::TaskAppointmentsView(View *view, QWidget *parent)
+TaskAppointmentsView::TaskAppointmentsView(QWidget *parent)
     : DoubleListViewBase(parent),
-      m_mainview(view),
       m_task(0) {
     
     setNameHeader(i18n("Resource"));
@@ -98,6 +96,11 @@
     slotUpdate();
 }
 
+void TaskAppointmentsView::drawContents(QPainter* painter)
+{
+  this->DoubleListViewBase::drawContents(painter);
+}
+
 void TaskAppointmentsView::slotUpdate() {
     //kdDebug()<<k_funcinfo<<endl;
     if (!m_task)
Index: kplato/kptpart.h
===================================================================
--- kplato/kptpart.h	(Revision 498178)
+++ kplato/kptpart.h	(Arbeitskopie)
@@ -39,6 +39,7 @@
 class ProjectDialog;
 class ResourceGroup;
 class Context;
+class GanttView;
 
 class Part : public KoDocument {
     Q_OBJECT
@@ -89,7 +90,15 @@
 private:
     Project *m_project;
     ProjectDialog *m_projectDialog;
+    QWidget* m_parentWidget;
     View *m_view;
+    
+    /**
+     * Used for drawing the project when embedded into another koffice app.
+     * @see paintContent()
+     */
+    GanttView* m_ganttView;
+    
     KoCommandHistory *m_commandHistory;
     bool m_update, m_calculate, m_baseline;
     
Index: kplato/kptganttview.cc
===================================================================
--- kplato/kptganttview.cc	(Revision 498178)
+++ kplato/kptganttview.cc	(Arbeitskopie)
@@ -66,15 +66,14 @@
 namespace KPlato
 {
 
-GanttView::GanttView(View *view, QWidget *parent, bool readWrite, const char* name)
+GanttView::GanttView(QWidget *parent, bool readWrite, const char* name)
     : QSplitter(parent, name),
-    m_mainview(view),
     m_readWrite(readWrite),
     m_currentItem(0),
     m_taskView(0),
     m_firstTime(true)
 {
-
+    kdDebug() << " ---------------- KPlato: Creating GanttView ----------------" << \
endl;  setOrientation(QSplitter::Vertical);
     
     m_gantt = new KDGanttView(this, "Gantt view");
@@ -99,13 +98,13 @@
     m_gantt->setScale(KDGanttView::Day);
     m_gantt->setShowLegendButton(false);
     m_gantt->setShowHeaderPopupMenu();
-    m_taskView = new TaskAppointmentsView(view, this);
+    m_taskView = new TaskAppointmentsView(this);
     // hide TaskAppointmentsView
     QValueList<int> list = sizes();
     list[0] += list[1];
     list[1] = 0;
     setSizes(list);
-    draw(view->getPart()->getProject());
+    
     setReadWriteMode(readWrite);
     
 	connect(m_gantt, SIGNAL(lvContextMenuRequested ( KDGanttViewItem *, const QPoint &, \
int )), @@ -124,8 +123,10 @@
     }
 }
 
-void GanttView::zoom(double /*zoom*/)
+void GanttView::setZoom(double zoom)
 {
+  kdDebug() << "setting gantt zoom: " << zoom << endl;
+  m_gantt->setZoomFactor(zoom,true);
 }
 
 void GanttView::clear()
@@ -192,6 +193,12 @@
     currentItemChanged(m_currentItem);
 }
 
+void GanttView::drawOnPainter(QPainter* painter)
+{
+  m_gantt->drawContents(painter);
+  m_taskView->drawContents(painter); //TODO doesn't seem to do very much
+}
+
 KDGanttViewItem *GanttView::findItem(Node *node)
 {
     return findItem(node, m_gantt->firstChild());
@@ -854,36 +861,38 @@
 
 void GanttView::popupMenuRequested(KDGanttViewItem * item, const QPoint & pos, int)
 {
-    //kdDebug()<<k_funcinfo<<(item?item->listViewText(0):"0")<<endl;
-    if (item == 0) {
-        kdDebug()<<"No item selected"<<endl;
-        return;
-    }
-    Node *n = getNode(item);
-    if (n == 0) {
-        kdDebug()<<"No node selected"<<endl;
-        return;
-    }
-    Task *t =  dynamic_cast<Task*>(n);
-    if (t && (t->type() == Node::Type_Task || t->type() == Node::Type_Milestone)) {
-        QPopupMenu *menu = m_mainview->popupMenu("task_popup");
-        if (menu)
-        {
-            /*int id =*/ menu->exec(pos);
-            //kdDebug()<<k_funcinfo<<"id="<<id<<endl;
-        }
-        return;
-    } 
-    if (t && t->type() == Node::Type_Summarytask) {
-        QPopupMenu *menu = m_mainview->popupMenu("summarytask_popup");
-        if (menu)
-        {
-            /*int id =*/ menu->exec(pos);
-            //kdDebug()<<k_funcinfo<<"id="<<id<<endl;
-        }
-        return;
-    }
-    //TODO: Other nodetypes
+//     if (m_mainview == NULL)
+//       return;
+//     //kdDebug()<<k_funcinfo<<(item?item->listViewText(0):"0")<<endl;
+//     if (item == 0) {
+//         kdDebug()<<"No item selected"<<endl;
+//         return;
+//     }
+//     Node *n = getNode(item);
+//     if (n == 0) {
+//         kdDebug()<<"No node selected"<<endl;
+//         return;
+//     }
+//     Task *t =  dynamic_cast<Task*>(n);
+//     if (t && (t->type() == Node::Type_Task || t->type() == Node::Type_Milestone)) \
{ +//         QPopupMenu *menu = m_mainview->popupMenu("task_popup");
+//         if (menu)
+//         {
+//             /*int id =*/ menu->exec(pos);
+//             //kdDebug()<<k_funcinfo<<"id="<<id<<endl;
+//         }
+//         return;
+//     } 
+//     if (t && t->type() == Node::Type_Summarytask) {
+//         QPopupMenu *menu = m_mainview->popupMenu("summarytask_popup");
+//         if (menu)
+//         {
+//             /*int id =*/ menu->exec(pos);
+//             //kdDebug()<<k_funcinfo<<"id="<<id<<endl;
+//         }
+//         return;
+//     }
+//     //TODO: Other nodetypes
 }
 
 void GanttView::slotItemDoubleClicked(QListViewItem* item) {
@@ -921,11 +930,16 @@
     
     // Make a simple header
     p.drawRect(0,0,metrics.width(),metrics.height());
-    QString text = i18n("Project: \
%1").arg(m_mainview->getPart()->getProject().name()); +    QString text;
+    int hei = 0;
     QRect r = p.boundingRect(1,0,0,0, Qt::AlignLeft, text );
-    p.drawText( r, Qt::AlignLeft, text );
-    int hei = r.height();
-    //kdDebug()<<"Project r="<<r.left()<<","<<r.top()<<" \
"<<r.width()<<"x"<<r.height()<<endl; +//     if (m_mainview)
+//     {
+//       text = i18n("Project: %1").arg(m_mainview->getPart()->getProject().name());
+//       p.drawText( r, Qt::AlignLeft, text );
+//       hei = r.height();
+//       //kdDebug()<<"Project r="<<r.left()<<","<<r.top()<<" \
"<<r.width()<<"x"<<r.height()<<endl; +//     }
     text = KGlobal::locale()->formatDateTime(QDateTime::currentDateTime());
     r = p.boundingRect(metrics.width()-1,0,0,0, Qt::AlignRight, text );
     p.drawText( r, Qt::AlignRight, text );
@@ -961,7 +975,7 @@
 void GanttView::slotItemRenamed(KDGanttViewItem* item, int col, const QString& str) \
                {
     //kdDebug()<<k_funcinfo<<(item ? item->listViewText(col) : "null")<<": \
"<<str<<endl;  if (col == 0) {
-        m_mainview->renameNode(getNode(item), QString(str));
+        emit itemRenamed(getNode(item), str);
     }
 }
 
@@ -1026,8 +1040,11 @@
     list[1] = context.taskviewsize;
     setSizes(list);    
 
-    Project &p = m_mainview->getProject();
-    currentItemChanged(findItem(p.findNode(context.currentNode)));
+//     if (m_mainview)
+//     {
+//       Project &p = m_mainview->getProject();
+//       currentItemChanged(findItem(p.findNode(context.currentNode)));
+//     }
     
     m_showResources = context.showResources ;
     m_showTaskName = context.showTaskName;
@@ -1037,13 +1054,17 @@
     m_showCriticalTasks = context.showCriticalTasks;
     m_showCriticalPath = context.showCriticalPath;
     
-    getContextClosedNodes(context, m_gantt->firstChild());
-    for (QStringList::ConstIterator it = context.closedNodes.begin(); it != \
                context.closedNodes.end(); ++it) {
-        KDGanttViewItem *item = findItem(p.findNode(*it));
-        if (item) {
-            item->setOpen(false);
-        }
-    }
+//     if (m_mainview)
+//     {
+//       Project &p = m_mainview->getProject();
+//       getContextClosedNodes(context, m_gantt->firstChild());
+//       for (QStringList::ConstIterator it = context.closedNodes.begin(); it != \
context.closedNodes.end(); ++it) { +//           KDGanttViewItem *item = \
findItem(p.findNode(*it)); +//           if (item) {
+//               item->setOpen(false);
+//           }
+//       }
+//     }
     return true;
 }
 
Index: kplato/kptpart.cc
===================================================================
--- kplato/kptpart.cc	(Revision 498178)
+++ kplato/kptpart.cc	(Arbeitskopie)
@@ -25,6 +25,7 @@
 #include "kptprojectdialog.h"
 #include "kptresource.h"
 #include "kptcontext.h"
+#include "kptganttview.h"
 
 #include <qpainter.h>
 #include <qfileinfo.h>
@@ -46,7 +47,8 @@
 Part::Part(QWidget *parentWidget, const char *widgetName,
 		 QObject *parent, const char *name, bool singleViewMode)
     : KoDocument(parentWidget, widgetName, parent, name, singleViewMode),
-      m_project(0), m_projectDialog(0), m_view(0),
+      m_project(0), m_projectDialog(0), m_parentWidget(parentWidget),
+      m_view(0),
       m_context(0)
 {
     m_update = m_calculate = false;
@@ -59,6 +61,8 @@
 
     delete m_project;
     m_project = new Project(); // after config is loaded
+    
+    m_ganttView = new GanttView(parentWidget);
 
     connect(m_commandHistory, SIGNAL(commandExecuted()), \
                SLOT(slotCommandExecuted()));
     connect(m_commandHistory, SIGNAL(documentRestored()), \
SLOT(slotDocumentRestored())); @@ -71,6 +75,8 @@
     delete m_project;
     delete m_projectDialog;
     delete m_commandHistory;
+    if (m_ganttView)
+      delete m_ganttView;
 }
 
 
@@ -145,9 +151,14 @@
 
 
 void Part::editProject() {
+
+    QWidget* parent = m_parentWidget;
+    if (m_view)
+      parent = m_view;
+      
     if (m_projectDialog == 0)
 	// Make the dialog
-	m_projectDialog = new ProjectDialog(*m_project, m_view);
+	m_projectDialog = new ProjectDialog(*m_project, parent);
 
     m_projectDialog->exec();
 }
@@ -268,10 +279,21 @@
 }
 
 
-void Part::paintContent(QPainter &/*painter*/, const QRect &/*rect*/,
+void Part::paintContent(QPainter &painter, const QRect &/*rect*/,
 			   bool /*transparent*/,
-			   double /*zoomX*/, double /*zoomY*/)
+			   double zoomX, double zoomY)
 {
+    kdDebug() << "----------- KPlato: Part::paintContent ------------" << endl;
+    if (isEmbedded() && m_ganttView && m_project)
+    {
+      double zoom = zoomX;
+      if (zoomY < zoomX)
+        zoom = zoomY;
+      m_ganttView->clear();
+      m_ganttView->setZoom(zoom);
+      m_ganttView->draw(*m_project);
+      m_ganttView->drawOnPainter(&painter);
+    }
     // ####### handle transparency
 
     // Need to draw only the document rectangle described in the parameter rect.
@@ -295,6 +317,10 @@
 void Part::slotCommandExecuted() {
     //kdDebug()<<k_funcinfo<<endl;
     setModified(true);
+    kdDebug() << "------- KPlato, is embedded: " << isEmbedded() << endl;
+    if (m_view == NULL)
+      return;
+      
     if (m_calculate)
         m_view->slotUpdate(config().behavior().calculationMode == \
Behavior::OnChange);  else if (m_update)
Index: kplato/kptview.cc
===================================================================
--- kplato/kptview.cc	(Revision 498178)
+++ kplato/kptview.cc	(Arbeitskopie)
@@ -118,14 +118,15 @@
     // build the DCOP object
     dcopObject();
 
-	m_tab = new QWidgetStack(this);
+    m_tab = new QWidgetStack(this);
     QVBoxLayout *layout = new QVBoxLayout(this);
-	layout->add(m_tab);
+    layout->add(m_tab);
 
-	m_ganttview = new GanttView(this, m_tab, part->isReadWrite());
-	m_tab->addWidget(m_ganttview);
+    m_ganttview = new GanttView(m_tab, part->isReadWrite());
+    m_tab->addWidget(m_ganttview);
+    m_ganttview->draw(getPart()->getProject());
 
-	m_pertview = new PertView( this, m_tab, layout );
+    m_pertview = new PertView( this, m_tab, layout );
     m_tab->addWidget(m_pertview);
 
     m_resourceview = new ResourceView( this, m_tab );
@@ -146,6 +147,7 @@
     connect(m_ganttview, SIGNAL(modifyRelation(Relation*, int)), \
                SLOT(slotModifyRelation(Relation*, int)));
     connect(m_ganttview, SIGNAL(modifyRelation(Relation*)), \
                SLOT(slotModifyRelation(Relation*)));
     connect(m_ganttview, SIGNAL(itemDoubleClicked()), SLOT(slotOpenNode()));
+    connect(m_ganttview, SIGNAL(itemRenamed(Node*, const \
                QString&)),this,SLOT(slotRenameNode(Node*, const QString&)));
     connect(m_resourceview, SIGNAL(itemDoubleClicked()), SLOT(slotEditResource()));
 
 	// The menu items
@@ -300,8 +302,8 @@
 }
 
 void View::setZoom(double zoom) {
-    m_ganttview->zoom(zoom);
-	m_pertview->zoom(zoom);
+    m_ganttview->setZoom(zoom);
+	m_pertview->setZoom(zoom);
 }
 
 void View::setupPrinter(KPrinter &printer) {
@@ -1038,7 +1040,7 @@
     }
 }
 
-void View::renameNode(Node *node, QString name) {
+void View::slotRenameNode(Node *node, const QString& name) {
     //kdDebug()<<k_funcinfo<<name<<endl;
     if (node) {
         NodeModifyNameCmd *cmd = new NodeModifyNameCmd(getPart(), *node, name, \
i18n("Modify Name"));



_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic