(→Writing a KPart) |
(→Writing a KPart) |
||
| Line 35: | Line 35: | ||
TARGET_LINK_LIBRARIES(kdepart ${KDE4_KDEUI_LIBS} ${KDE4_KPARTS_LIBS}) | TARGET_LINK_LIBRARIES(kdepart ${KDE4_KDEUI_LIBS} ${KDE4_KPARTS_LIBS}) | ||
</pre> | </pre> | ||
| + | '''main.cpp''' | ||
| + | <code cpp> | ||
| + | #include <QString> | ||
| + | #include <kapplication.h> | ||
| + | #include <kaboutdata.h> | ||
| + | #include <kmessagebox.h> | ||
| + | #include <klistwidget.h> | ||
| + | #include <kparts/mainwindow.h> | ||
| + | #include <kparts/part.h> | ||
| + | #include <ktextedit.h> | ||
| + | #include <kcmdlineargs.h> | ||
| + | #include <KMainWindow> | ||
| + | #include <KPushButton> | ||
| + | #include "mypart.h" | ||
| + | |||
| + | int main (int argc, char *argv[]) | ||
| + | { | ||
| + | const QByteArray& ba=QByteArray("test"); | ||
| + | const KLocalizedString name=ki18n("myName"); | ||
| + | KAboutData aboutData( ba, ba, name, ba, name); | ||
| + | KCmdLineArgs::init( argc, argv, &aboutData ); | ||
| + | KApplication khello; | ||
| + | mypartmainwindow* mw=new mypartmainwindow(); | ||
| + | //mypart* mypart1=new mypart(mw); | ||
| + | //KPushButton* button=new KPushButton("ha"); | ||
| + | //mypart1->setMainWidget(button); | ||
| + | //mypart1->embed(mw); | ||
| + | //KListWidget* klv=new KListWidget(mywidget); | ||
| + | mw->show(); | ||
| + | khello.exec(); | ||
| + | } | ||
| + | </code> | ||
| + | '''mypart.h''' | ||
| + | <code cpp> | ||
| + | #include <KParts/Part> | ||
| + | #include <KParts/MainWindow> | ||
| + | |||
| + | class mypart:public KParts::Part | ||
| + | { | ||
| + | Q_OBJECT | ||
| + | public: | ||
| + | mypart(QObject *parent=0); | ||
| + | }; | ||
| + | |||
| + | class mypartmainwindow:public KParts::MainWindow | ||
| + | { | ||
| + | Q_OBJECT | ||
| + | public: | ||
| + | mypartmainwindow(QWidget* parent = 0, Qt::WindowFlags f = KDE_DEFAULT_WINDOWFLAGS); | ||
| + | }; | ||
| + | </code> | ||
'''mypart.cpp''' | '''mypart.cpp''' | ||
<code cpp> | <code cpp> | ||
Kontact plugins are KParts that get loaded at runtime. To integrate your KPart into kontact, you will need to have a .desktop file like this:
ls /home/kde-devel/kde/share/kde4/services/kontact/ akregatorplugin.desktop knotesplugin.desktop akregatorplugin3.2.desktop korganizerplugin.desktop journalplugin.desktop newstickerplugin.desktop kaddressbookplugin.desktop plannerplugin.desktop karmplugin.desktop specialdatesplugin.desktop kmailplugin.desktop summaryplugin.desktop kmobiletools.desktop todoplugin.desktop knodeplugin.desktop weatherplugin.desktop
The following is what you do
CMakeLists.txt
PROJECT( kdepart )
FIND_PACKAGE(KDE4 REQUIRED)
INCLUDE_DIRECTORIES(${KDE4_INCLUDES} .)
SET(kdepartSources main.cpp mypart.cpp)
KDE4_ADD_EXECUTABLE(kdepart ${kdepartSources})
TARGET_LINK_LIBRARIES(kdepart ${KDE4_KDEUI_LIBS} ${KDE4_KPARTS_LIBS})
main.cpp
int main (int argc, char *argv[]) {
const QByteArray& ba=QByteArray("test");
const KLocalizedString name=ki18n("myName");
KAboutData aboutData( ba, ba, name, ba, name);
KCmdLineArgs::init( argc, argv, &aboutData );
KApplication khello;
mypartmainwindow* mw=new mypartmainwindow();
//mypart* mypart1=new mypart(mw);
//KPushButton* button=new KPushButton("ha");
//mypart1->setMainWidget(button);
//mypart1->embed(mw);
//KListWidget* klv=new KListWidget(mywidget);
mw->show();
khello.exec();
}
mypart.h
class mypart:public KParts::Part {
Q_OBJECT
public:
mypart(QObject *parent=0);
};
class mypartmainwindow:public KParts::MainWindow {
Q_OBJECT
public:
mypartmainwindow(QWidget* parent = 0, Qt::WindowFlags f = KDE_DEFAULT_WINDOWFLAGS);
};
mypart.cpp
mypart::mypart(QObject* parent) {
kDebug() << "Entering mypart";
QWidget* mywidget=new QWidget();
KPushButton* button=new KPushButton("ho",mywidget);
setWidget(mywidget);
}
mypartmainwindow::mypartmainwindow(QWidget* parent, Qt::WindowFlags f) {
kDebug() << "Entering mypartmainwindow"; mypart* mypart1=new mypart(this); mypart1->embed(this);
}
You can use konqueror to display your kpart: konqueror -> Settings -> Configure Konqueror -> Web browsing -> Plugins