This forum has been archived. All content is frozen. Please use KDE Discuss instead.

integrate kword in myapp

Tags: None
(comma "," separated)
xyfix
Registered Member
Posts
110
Karma
0

Re: integrate kword in myapp

Tue Jan 05, 2010 10:45 am
bcooksley,

since KParts::MainWindow is derived from KXMLGUIWindow I don't need my MainWindow to derive from KXMLGUIWindow just from KParts::MainWindow would be enough.....right??
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: integrate kword in myapp

Tue Jan 05, 2010 10:21 pm
Correct. I thought you were using KMainWindow which doesn't support XMLGUI.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
xyfix
Registered Member
Posts
110
Karma
0

Re: integrate kword in myapp

Wed Jan 06, 2010 9:06 am
sorry, that was a mistake from my side.
xyfix
Registered Member
Posts
110
Karma
0

Re: integrate kword in myapp

Wed Jan 06, 2010 1:40 pm
I've derived my MainWindow application from KParts::MainWindow, but how do I proceed further when I want each of the QTabWidgets of my app to show a KWord part. Do I need to derive the object(currently a derivation of QTextEdit) that was shown on the tabs from KParts::ReadWritePart?
I've read that if I want multiple kparts in my MainWindow I should connect the KParts::MainWindow::CreateGui slot to the KPartManager::activePartChanged signal, this sounds pretty sane but how do I fit this manager in my app?
xyfix
Registered Member
Posts
110
Karma
0

Re: integrate kword in myapp

Tue Jan 12, 2010 10:06 am
OK, now that my application is kpart-aware and I have the XMLGUI up and running (some action's have been moved to the new XMLGUI structure) but now I want to integrate kword as a kpart in my application. In my application I have these QTabWidgets where I currently put derived QTextEdit objects in. Now I replaced this and in the constructor of this object I do this:

Code: Select all
KLibFactory *factory = KLibLoader::self()->factory("katepart");
if (factory)
{
  KParts::ReadWritePart *m_part = static_cast<KParts::ReadWritePart *>
                     (factory->create(this,"KatePart" ));
  if(m_part)
  {
     layout2->addWidget( m_part->widget()):
  }
}
else
{
  //should send out a error message box
  return;
}


I put kate in the code above because that seem to work, because I get a text edit area where I can enter text ( which I already had with the QTextEdit object so not sure if this actually works). But when I put something else instead of katepart like kwordpart the edit area dissapears. So how can I use kword as a kpart?
xyfix
Registered Member
Posts
110
Karma
0

Re: integrate kword in myapp

Wed Jan 13, 2010 10:32 am
anyone an idea how to merge the gui of the kpart (for now kate later kword ) with my app, this is XMLGUI based ?
xyfix
Registered Member
Posts
110
Karma
0

Re: integrate kword in myapp

Wed Jan 13, 2010 4:27 pm
it seems like I've been using some deprecated classes (e.g. KLibLoader)
but when I use the right one (I assume) "KPluginLoader loader("kwordpart");"
I get an error "KPluginLoader::KPluginLoader: Could not find plugin "kwordpart"" . The libkwordpart.so is located in $HOME/koffice/src/lib/ this directory is in my LD_LIBRARY_PATH but how do I make it clear to the plugin loader. Environment variables KDEDIR & KDEDIRS don't have this directory.
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: integrate kword in myapp

Thu Jan 14, 2010 12:36 am
The following KParts guide may help
http://techbase.kde.org/Development/Tut ... ing_KParts


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
xyfix
Registered Member
Posts
110
Karma
0

Re: integrate kword in myapp

Thu Jan 14, 2010 7:52 am
bcooksley,

Unfortunately that tutorial won't help me, because I've already read it (was mentioned by cyrille). Judging on what I got (katepart is working but kwordpart is not found) I think one of you experts should have a look at it. :) Nevertheless I will read it again perhaps I overread something. I've also tried to find the solution on the internet, but the information on this is pretty scarce (it's only on the internet and no google groups ).
Another unfortunate point is that the link is outdated according to this http://api.kde.org/4.x-api/kdelibs-apid ... oader.html where it's mentioned that KLibLoader is depricated.
User avatar
zander
KDE Developer
Posts
87
Karma
1

Re: integrate kword in myapp

Thu Jan 14, 2010 8:25 am
Maybe you can put your app on gitorious or some hosting so people can see the code you have.

Right now its very hard to guess why it would fail.

There are plenty more tutorials on techbase and loads of info on kparts and parts discovery on api.kde.org that may be helpful


Thomas Zander
KWord maintainer
xyfix
Registered Member
Posts
110
Karma
0

Re: integrate kword in myapp

Thu Jan 14, 2010 1:34 pm
Thomas, bcooksley ,

please understand that a lot of the code is protected( legal issue) . I'll supply you all the information you guys need to help me out. I know that it is very hard (some think it's impossible) but since you're professionals that shouldn't hold you back, so please bear with me. I'll put the short-short version of the code here.

MainWindow.h:
Code: Select all
class MainWindow : public KParts::MainWindow
{
  Q_OBJECT
 
public:
  MainWindow();
 
private:
  void initialiseActions();

private slots:
  void slotAddReport();
 
private:
  KAction *m_addReport;   
  ViewMode *m_viewMode;
}


MainWindow.cpp:
Code: Select all
MainWindow::MainWindow ()
{
  initialiseActions();
}

void MainWindow::initialiseActions()
{
  m_addReport = actionCollection()->("m_addReport");
  m_addReport->setText(tr("&Add"));
  connect (m_addReport, SIGNAL (triggered ()), SLOT (slotAddReport ()));
}

void MainWindow::slotAddReport()
{
  m_viewMode->addReport();
}


ViewMode.h:
Code: Select all
class ViewMode : publid QTabWidget
{
  Q_OBJECT
 
public:
  ViewMode();
  void addReport();
}


ViewMode.cpp:
Code: Select all
ViewMode::ViewMode()
{....}

ViewMode::addReport()
{
  ReportEditor *editor = dynamic_cast< ReportEditor* >(currentWidget());
 
  if (editor)
  {
     editor->addReport();
  }
}


ReportEditor.h:
Code: Select all
class ReportEditor : public QWidget
{
  Q_OBJECT

public:
  ReportEditor();
  void initialiseReportArea( QWidget *parent );
 
public slots:
  void addReport();
 
private:
  QSplitter *m_splitter;
}


ReportEditor.cpp:
Code: Select all
ReportEditor::ReportEditor()
{
  m_splitter =  new QSplitter(this);
  initialiseReportArea(m_splitter);
}

ReportEditor::addReport()
{}

ReportEditor::initialiseReportArea( QWidget *parent)
{
  QWidget *layoutWidget = new QWidget( parent );
 
  QVBoxLayout layout = new QVBoxLayout( layoutWidget );
 
  KPluginFactory *factory = KPluginLoader("katepart").factory();
 
  if (factory)
  {
    KParts::ReadWritePart *part =  static_cast<KParts::ReadWirtePart *>
                          (factory->create(this, "katepart" );

    if (part)
    {
      layout->addWidget( part->widget());
    }
  }
  else
  {
    return;
  }
}



The kate part works I get an editor, but since the gui isn't merged yet no actions or buttons from kate is available ( only key shortcuts). But when katepart is replaced with kwordpart I get an error
KPluginLoader::KPluginLoader: Could not find plugin "kwordpart"

And can anybody tell me what's the way to run the createGUI in order to get the actions and buttons merged?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: integrate kword in myapp

Fri Jan 15, 2010 12:49 am
Just after you add the part to the layout, you need to call

Code: Select all
(pointer to your main window)->createGUI( part )


Where part is the KParts::ReadWritePart or KParts::ReadOnlyPart you have just created.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]
xyfix
Registered Member
Posts
110
Karma
0

Re: integrate kword in myapp

Fri Jan 15, 2010 8:30 am
Thank you bcooksley,

Any idea about the KPluginLoader not finding the plugin? I've built koffice 2.1 without any errors and saw that the plugin resides in $HOME/koffice-2.1/src/lib .
xyfix
Registered Member
Posts
110
Karma
0

Re: integrate kword in myapp

Fri Jan 15, 2010 9:23 am
bcooksley,

is it wise to pass a mainwindow object pointer via the function addReport(ViewMode) and the constructor of ReportEditor , just to have a pointer to the mainwindow object available in ReportEditor?
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS

Re: integrate kword in myapp

Fri Jan 15, 2010 9:55 am
An alternate way to do it would be to create a static function in your K(Unique)Application class which returns it.

Code: Select all
MyApplication * mApp = qobject_cast<MyApplication*>( kapp );
return mApp->m_mainWindow;


kapp is a global static provided by KApplication. QApplication also has one, qApp.
m_mainWindow is a pointer, stored by your Application subclass.


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]


Bookmarks



Who is online

Registered users: bancha, Bing [Bot], Evergrowing, Google [Bot], lockheed, mesutakcan