kscribble.h

KDE Anwendungs Tutorials: Der KDE Anwendungs-Tutorial Leitfaden für die Integrierte Entwicklungsumgebung KDevelop
Zurück | Anhang A. KScribble-1.0 Beispiel Quellcode | Vor

# A.3. kscribble.h

       1 /***************************************************************************
       2                           kscribble.h  -  description
       3                              -------------------
       4     begin                : Mon Jan 31 11:05:05 CET 2000
       5     copyright            : (C) 2000 by Ralf Nolden
       6     email                : Ralf.Nolden@post.rwth-aachen.de
       7  ***************************************************************************/
       8
       9 /***************************************************************************
      10  *                                                                         *
      11  *   This program is free software; you can redistribute it and/or modify  *
      12  *   it under the terms of the GNU General Public License as published by  *
      13  *   the Free Software Foundation; either version 2 of the License, or     *
      14  *   (at your option) any later version.                                   *
      15  *                                                                         *
      16  ***************************************************************************/
      17
      18 #ifndef KSCRIBBLE_H
      19 #define KSCRIBBLE_H
      20
      21
      22 #ifdef HAVE_CONFIG_H
      23 #include <config.h>
      24 #endif
      25
      26 // include files for Qt
      27 #include <qstrlist.h>
      28 #include <qworkspace.h>
      29
      30 // include files for KDE
      31 #include <kapp.h>
      32 #include <ktmainwindow.h>
      33 #include <kaccel.h>
      34 #include <kimgio.h>
      35
      36 // forward declaration of the KScribble classes
      37 class KScribbleDoc;
      38 class KScribbleView;
      39
      40 /**
      41   * The base class for KScribble application windows. It sets up the main
      42   * window and reads the config file as well as providing a menubar, toolbar
      43   * and statusbar. In initView(), your main view is created as the MDI child window manager.
      44   * Child windows are created in createClient(), which gets a document instance as it's document to
      45   * display whereby one document can have several views.The MDI child is an instance of KScribbleView,
      46   * the document an instance of KScribbleDoc.
      47   * KScribbleApp reimplements the methods that KTMainWindow provides for main window handling and supports
      48   * full session management as well as keyboard accelerator configuration by using KAccel.
      49   * @see KTMainWindow
      50   * @see KApplication
      51   * @see KConfig
      52   * @see KAccel
      53   *
      54   * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team.
      55   * @version KDevelop version 1.1 code generation
      56   */
      57 class KScribbleApp : public KTMainWindow
      58 {
      59   Q_OBJECT
      60
      61   public:
      62     /** construtor of KScribbleApp, calls all init functions to create the application.
      63      *  @see initMenuBar initToolBar
      64      */
      65     KScribbleApp();
      66     ~KScribbleApp();
      67     /** enables menuentries/toolbar items
      68      */
      69     void enableCommand(int id_);
      70     /** disables menuentries/toolbar items
      71      */
      72     void disableCommand(int id_);
      73     /** opens a file specified by commandline option
      74      */
      75     void openDocumentFile(const char *file=0);
      76
      77   protected:
      78     /** queryClose is called by KTMainWindow on each closeEvent of a window. Against the
      79      *  default implementation (only returns true), this overridden function retrieves all modified documents
      80      *  from the open document list and asks the user to select which files to save before exiting the application.
      81      *  @see KTMainWindow#queryClose
      82      *  @see KTMainWindow#closeEvent
      83      */
      84     virtual bool queryClose();
      85     /** queryExit is called by KTMainWindow when the last window of the application is going to be closed
      86      *  during the closeEvent().
      87      *  Against the default implementation that just returns true, this calls saveOptions() to save the
      88      *  settings of the last window's properties.
      89      *  @see KTMainWindow#queryExit
      90      *  @see KTMainWindow#closeEvent
      91      */
      92     virtual bool queryExit();
      93     /** saves the window properties for each open window during session end to the session config file,
      94      *  including saving the currently opened file by a temporary filename provided by KApplication.
      95      *  @see KTMainWindow#saveProperties
      96      */
      97     virtual void saveProperties(KConfig *_cfg);
      98     /** reads the session config file and restores the application's state including the last
      99      *  opened files and documents by reading the temporary files saved by saveProperties()
     100      *  @see KTMainWindow#readProperties
     101      */
     102     virtual void readProperties(KConfig *_cfg);
     103     /** event filter to catch close events for MDI child windows and is installed in createClient() on every
     104       * child window. Closing a window calls the eventFilter first which removes the view from the connected
     105       * documents' view list. If the last view is going to be closed, the eventFilter() tests if the document
     106       * is modified; if yes, it asks the user to save the document. If the document title contains "Untitled",
     107       * slotFileSaveAs() gets called to get a save name and path.
     108       */
     109     virtual bool eventFilter(QObject* object, QEvent* event);
     110     /** creates a new child window. The document that will be connected to it
     111      *  has to be created before and the instances filled, with e.g. openDocument().
     112      *  Then call createClient() to get a new MDI child window.
     113      *  @see KScribbleDoc#addView
     114      *  @see KScribbleDoc#openDocument
     115      *  @param doc pointer to the document instance that the view will
     116      *  be connected to.
     117      */
     118     void createClient(KScribbleDoc* doc);
     119     /** accepts drag events for images */
     120     virtual void dragEnterEvent( QDragEnterEvent* );
     121     /** accepts drops and opens a new document
     122      *  for each drop */
     123     virtual void dropEvent( QDropEvent* );
     124
     125   private slots:
     126     /** sets the main application window title each time the active MDI child window changes. */
     127     void setWndTitle(QWidget*);
     128     /** switch argument for slot selection by menu or toolbar ID */
     129     void commandCallback(int id_);
     130     /** switch argument for Statusbar help entries on slot selection. Add your ID's help
     131      *  here for toolbars and menubar entries. */
     132     void statusCallback(int id_);
     133     /** add a opened file to the recent file list and update recent file menu*/
     134     void addRecentFile(const QString &&;file);
     135     /** clears the document in the actual view to reuse it as the new document */
     136     void slotFileNew();
     137     /** open a file and load it into the document*/
     138     void slotFileOpen();
     139     /** opens a file from the recent files menu */
     140     void slotFileOpenRecent(int id_);
     141     /** save a document */
     142     void slotFileSave();
     143     /** save a document by a new filename*/
     144     void slotFileSaveAs();
     145     /** asks for saving if the file is modified, then closes the actual file and window*/
     146     void slotFileClose();
     147     /** print the actual file */
     148     void slotFilePrint();
     149     /** closes all documents and quits the application.*/
     150     void slotFileQuit();
     151     /** reverts the last user action for the active window */
     152     void slotEditUndo();
     153     /** put the marked text/object into the clipboard and remove
     154      *  it from the document
     155      */
     156     void slotEditCut();
     157     /** put the marked text/object into the clipboard
     158      */
     159     void slotEditCopy();
     160     /** paste the clipboard into the document
     161      */
     162     void slotEditPaste();
     163     /** clears the current document */
     164     void slotEditClearAll();
     165     /** sets the pen width */
     166     void slotPenBrush();
     167     /** sets the pen color */
     168     void slotPenColor();
     169     /** toggles the toolbar
     170      */
     171     void slotViewToolBar();
     172     /** toggles the statusbar
     173      */
     174     void slotViewStatusBar();
     175     /** creates a new view for the document in the active child window and adds the new view to the
     176      * list of views the document maintains.
     177      */
     178     void slotWindowNewWindow();
     179     /** changes the statusbar contents for the standard label permanently, used to indicate current actions.
     180      * @param text the text that is displayed in the statusbar
     181      */
     182     void slotStatusMsg(const QString &&;text);
     183     /** changes the status message of the whole statusbar for two seconds, then restores the last status.
     184      * This is used to display statusbar messages that give information about actions for
     185      * toolbar icons and menuentries.
     186      * @param text the text that is displayed in the statusbar
     187      */
     188     void slotStatusHelpMsg(const QString &&;text);
     189     /** gets called when the window menu is activated; recreates the window menu with all opened window titles. */
     190     void windowMenuAboutToShow();
     191     /** activates the MDI child widget when it gets selected from the window menu. */
     192     void windowMenuActivated( int id );
     193
     194   private:
     195     /** save general Options like all bar positions and status as well as the geometry and
     196      * the recent file list to the configuration file
     197      */
     198     void saveOptions();
     199     /** read general Options again and initialize all variables like the recent file list
     200      */
     201     void readOptions();
     202     /** initKeyAccel creates the keyboard accelerator items for the available slots and changes the menu accelerators.
     203      * @see KAccel
     204      */
     205     void initKeyAccel();
     206     /** initMenuBar creates the menubar and inserts the menupopups as well as creating the helpMenu.
     207      */
     208     void initMenuBar();
     209     /** this creates the toolbars.
     210      */
     211     void initToolBar();
     212     /** sets up the statusbar for the main window by initialzing a statuslabel.
     213      */
     214     void initStatusBar();
     215
     216     /** Creates the main view of the KTMainWindow instance and initializes the MDI view area including any needed
     217      *  connections.
     218      */
     219     void initView();
     220
     221     /** contains the recently used filenames */
     222     QStrList recentFiles;
     223
     224     /** the configuration object of the application */
     225     KConfig *config;
     226     /** the key accelerator container */
     227     KAccel *keyAccel;
     228     /** the recent file menu containing the last five opened files */
     229     QPopupMenu *pRecentFileMenu;
     230     /** the file menu */
     231     QPopupMenu* pFileMenu;
     232     /** the edit menu */
     233     QPopupMenu* pEditMenu;
     234     /** the pen menu */
     235     QPopupMenu* pPenMenu;
     236     /** the view menu */
     237     QPopupMenu* pViewMenu;
     238     /** the window menu */
     239     QPopupMenu *pWindowMenu;
     240     /** pWorkspace is the MDI frame widget that handles MDI child widgets. Inititalized in
     241      * initView()
     242      */
     243     QWorkspace *pWorkspace;
     244     /** the printer instance */
     245     QPrinter *printer;
     246     /** a counter that gets increased each time the user creates a new document with "File"->"New" */
     247     int untitledCount;
     248     /** a list of all open documents. If the last window of a document gets closed, the installed eventFilter
     249      * removes this document from the list. The document list is checked for modified documents when the user
     250      * is about to close the application. */
     251     QList<KScribbleDoc> *pDocList;
     252
     253 };
     254
     255 #endif // KSCRIBBLE_H

Zurück | Anfang | Vor
main.cpp | Hoch | kscribble.cpp