ksimpleeditor.h

ksimpleeditor.h

#ifndef __KSIMPLEEDITOR_H__
#define __KSIMPLEEDITOR_H__
・・・
#endif /* __KSIMPLEEDITOR_H__ */

ヘッダーファイルのお決まりの宣言です。

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

configureスクリプトによって得られるconfig.hを読み込みます。(使う予定はない)

#include <kmainwindow.h>
#include <kmenubar.h>
#include <ktextedit.h>

各ウィジットのヘッダーファイルを読み込みます。

class KSimpleEditor : public KMainWindow
{
    KSimpleEditor();
    ~KSimpleEditor();
    ・・・
};

KMainWindowクラスを継承してKSimpleEditorクラスを定義します。

    Q_OBJECT

スロットを定義するので書いておきます。

public:
    KTextEdit* txtEdit;
    KToolBar* tlbFile;
    KToolBar* tlbEdit;

メインのエディタとファイル用、編集用メニューのポインタです。

    void setupMenuBar();
    void setupToolBar();
    void setupStatusBar();

メニューバー、ツールバー、ステータスバーを実際に作ります。

public slots:
    void slotFileNew();
    void slotFileOpen();
    void slotFileSave();
    void slotFileSaveAs();

それぞれファイルメニューに関連づけられるスロットの定義です。

private:
    QString GfileName;

編集中のファイル名です。新規のときは空文字列""にします。

    bool CheckChangedAndSaved();

ファイルに変更があれば保存するか聞いて保存する場合は保存します。

    void fileNew();
    void fileOpen();
    bool fileSave();
    bool fileSaveAs();

それぞれ実際にファイルの新規作成、開く、保存、名前を付けて保存の作業をします。

protected:
    virtual bool queryClose();

×ボタンが押されたときの処理です。

Linux Life
プログラミング > C++ > KDE > KDEプログラミング入門 > KSimpleEditor > ksimpleeditor.h