(→See also) |
(→Writing a KPart) |
||
| Line 22: | Line 22: | ||
* write main.cpp | * write main.cpp | ||
** use new mypart(mw) to get your part into your main window | ** use new mypart(mw) to get your part into your main window | ||
| + | |||
| + | '''CMakeLists.txt''' | ||
| + | <pre> | ||
| + | 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}) | ||
| + | </pre> | ||
| + | '''mypart.cpp''' | ||
| + | <code cpp> | ||
| + | #include <kdebug.h> | ||
| + | #include <KPushButton> | ||
| + | #include "mypart.h" | ||
| + | #include <QWidget> | ||
| + | |||
| + | 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); | ||
| + | } | ||
| + | </code> | ||
= Using your kPart = | = Using your kPart = | ||
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})
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