Hello KDE...

Kostas Lialiambis admin at edessa.topo.auth.gr
Sat Aug 29 21:17:53 EEST 1998


To oti oi kairoi einai xalepoi, den eisxwrei oydemia amfibolia mia kai
apaitoyn polla: Ena aplo "Hello, World!" den arkei. Prepei h application poy
8a to leei na exei kai menu bar, kai toolbal, kai Help section me ta
aparaithta abouts alla kai ikanothtes drag-and-drop.

Apo to Linux Journal sas para8etw to paradeigma toy Hello World - a - la -
KDE toy David Sweet.

Apoteleitai apo 4 arxeia. Pisteyw na kataferete na ta 3exwrisete kai na ta
kanete compiling. Xreiasthke na kanw 2-3 allages sta sources giati htan
grammena gia thn mh-telikh version toy KDE me apotelesma 2-3 functions na
symperiferontai diaforetika ap' o,ti  eprepe. Krathsa ta palia remarks (kai
ebala 1-2 dika moy).

Mh 3exanete oti h app ayth oxi mono typwnei Hello, World alla an kanete
drag-and-drom ena object apo ton filemanager sas panw s' aythn tote sas
typwnei to URL ths (p.x. file:/vmlinuz).

---------------------khellotw.cpp-----------------------

#include <qkeycode.h>
#include <kmsgbox.h>
#include <kstdaccel.h>
#include "khellotw.moc"

KHelloTW::KHelloTW(void)
{
    /**
    We'll get the standard KDE accelerator key
    combinations from this.
    */
    KStdAccel *kkeys=new KStdAccel(kapp->getConfig());
    /**
    Create the pulldown menus for the menubar.
    */
    file=new QPopupMenu();
    file->insertItem("&Quit", this, SLOT(slotQuit()),
 kkeys->quit());
    help=kapp->getHelpMenu(TRUE,
"Err... I had to modify this\napp a little in order\
to be\nable to compile it with the\nlatest version\
of KDE.\n\nK. Lialiambis.");
    help->insertSeparator();
    help->insertItem("&Original About-KHello...", this,
 SLOT(slotAbout()));
    /**
    Set up the menubar.
    */
    menubar=new KMenuBar(this);
    menubar->insertItem("File",file);
    menubar->insertSeparator(); //This
 //pushes the Help menu to far
 //right when KDE is in Motif widget mode
    menubar->insertItem("Help",help);
    /**
    Set up the toolbar.
    */
    toolbar=new KToolBar(this);
    QString buttonpicture;
    /*
    The original following statement was:
    buttonpicture=kapp->kdedir()+
       "/share/toolbar/exclamation.xpm";
    But kdedir() became a protected function in
    the later versions of KDE and could not be used
    that way.
    */
    buttonpicture=kapp->kde_toolbardir()+
       "/exclamation.xpm";
    toolbar->insertButton(QPixmap(buttonpicture.data()),
        0,SIGNAL(released()), this, SLOT(slotHello()),
        TRUE, "Press this to say hello");
    /**
    This label will fill the rest of our window
    (the part not occupied by the menubar or
    toolbar).
    */
    label=new QLabel(this);
    label->setFont(QFont("Helvetica", 24));
    label->setAlignment(AlignCenter);
    /**
    Tell KTopWidget about our menubar, toolbar
    and label.
    */
    setMenu(menubar);
    addToolBar(toolbar);
    setView(label);
    /**
    Drag and Drop. URL's can be dragged from KFM
    and dropped onto our QLabel. The URL will be
    displayed.
    */
    dropzone=new KDNDDropZone(label, DndURL);
 connect (dropzone,
 SIGNAL(dropAction(KDNDDropZone *)),
 this, SLOT(slotDropped(KDNDDropZone *)));
}

void KHelloTW::slotQuit()
{
    close();
}

void KHelloTW::slotAbout()
{
    KMsgBox::message (this, "The Original About-KHello",
"KHello\nCopyright (C) 1997\nBy David Sweet\n\
dsweet at physics.umd.edu");
}

void KHelloTW::slotHello()
{
    label->setText("Hello world!\n");
}

void KHelloTW::slotDropped(KDNDDropZone *dz)
{
    QString url;
    url=dz->getURLList().first();
    label->setText(url.data());
}

void KHelloTW::closeEvent(QCloseEvent *)
{
    kapp->quit();
}





----------------------kwhello.h-------------------------

#include <kapp.h>
#include <ktopwidget.h>
#include <ktoolbar.h>
#include <kmenubar.h>
#include <drag.h>
class KHelloTW : public KTopLevelWidget
{
    Q_OBJECT;
public:
    KHelloTW(void);
    void closeEvent(QCloseEvent *);
private:
    QPopupMenu *file, *help;
    KToolBar *toolbar;
    KMenuBar *menubar;
    QLabel *label;
    KDNDDropZone *dropzone;
public slots:
    void slotQuit();
    void slotAbout();
    void slotHello();
    void slotDropped(KDNDDropZone *);
};





-----------------------main.cpp-------------------------

#include "khellotw.h"

int main(int argc, char *argv[])
{
    KApplication app(argc, argv, "khello");
    KHelloTW hello;
    hello.show();
    return app.exec();
}





-----------------------Makefile-------------------------

QINC = -I/usr/lib/qt/include
KINC = -I/opt/kde/include
INCS = $(QINC) $(KINC)
LIBPATHS = -L/usr/X11R6/lib -L/opt/kde/lib
QLIB = -lqt
KLIB = -lkdecore -lkdeui -lkfm
XLIB = -lX11 -lXext
LIBS = $(LIBPATHS) $(KLIB) $(QLIB) $(XLIB)
CC = c++ -DSTDC_HEADERS -DHAVE_UNISTD_H $(LIBS)
CCo = c++ -c -DSTDC_HEADERS -DHAVE_UNISTD_H $(INCS)
khello : main.o khellotw.o
 $(CC) -o khello main.o khellotw.o
main.o : main.cpp khellotw.h
 $(CCo) main.cpp
khellotw.o : khellotw.cpp khellotw.moc
 $(CCo) khellotw.cpp
%.moc : %.h
 moc $< -o $@
clean:
 rm *.o *.moc

--------------------------------------------------------


Kor.






--
====================================================================
Gia boithia (h na diagrafhte) e-mail sto majordomo at argos.hol.gr
Ta archives tis listas einai sto http://www.argos.hol.gr/lists :
prin steilete kapoia erothsh psakte mipos exei hdh apanththei.
Gia opoiodipote problima stilte e-mail ston owner-linux-greek-users
====================================================================



More information about the Linux-greek-users mailing list