• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

kapptemplate

  • sources
  • kde-4.12
  • kdesdk
  • kapptemplate
  • templates
  • C++
  • kpartapp
  • src
kpartapp/src/%{APPNAMELC}.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) %{CURRENT_YEAR} by %{AUTHOR} <%{EMAIL}> *
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  * This program is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12  * GNU General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU General Public License *
15  * along with this program; if not, write to the *
16  * Free Software Foundation, Inc., *
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18  ***************************************************************************/
19 
20 #include "%{APPNAMELC}.h"
21 #include "%{APPNAMELC}.moc"
22 
23 #include <kaction.h>
24 #include <kactioncollection.h>
25 #include <kconfig.h>
26 #include <kedittoolbar.h>
27 #include <kfiledialog.h>
28 #include <kshortcutsdialog.h>
29 #include <klibloader.h>
30 #include <kmessagebox.h>
31 #include <kstandardaction.h>
32 #include <kstatusbar.h>
33 #include <kurl.h>
34 #include <klocale.h>
35 
36 #include <QApplication>
37 
38 %{APPNAME}::%{APPNAME}()
39  : KParts::MainWindow( )
40 {
41  // set the shell's ui resource file
42  setXMLFile("%{APPNAMELC}_shell.rc");
43 
44  // then, setup our actions
45  setupActions();
46 
47  // this routine will find and load our Part. it finds the Part by
48  // name which is a bad idea usually.. but it's alright in this
49  // case since our Part is made for this Shell
50  KLibFactory *factory = KLibLoader::self()->factory("lib%{APPNAMELC}part");
51  if (factory)
52  {
53  // now that the Part is loaded, we cast it to a Part to get
54  // our hands on it
55  m_part = static_cast<KParts::ReadWritePart *>(factory->create(this,
56  "%{APPNAME}Part" ));
57 
58  if (m_part)
59  {
60  // tell the KParts::MainWindow that this is indeed the main widget
61  setCentralWidget(m_part->widget());
62 
63  // and integrate the part's GUI with the shell's
64  setupGUI();
65  }
66  }
67  else
68  {
69  // if we couldn't find our Part, we exit since the Shell by
70  // itself can't do anything useful
71  KMessageBox::error(this, i18n("Could not find our Part!"));
72  qApp->quit();
73  // we return here, cause qApp->quit() only means "exit the
74  // next time we enter the event loop...
75  return;
76  }
77 
78  // apply the saved mainwindow settings, if any, and ask the mainwindow
79  // to automatically save settings if changed: window size, toolbar
80  // position, icon size, etc.
81  setAutoSaveSettings();
82 }
83 
84 %{APPNAME}::~%{APPNAME}()
85 {
86 }
87 
88 void %{APPNAME}::load(const KUrl& url)
89 {
90  m_part->openUrl( url );
91 }
92 
93 void %{APPNAME}::setupActions()
94 {
95  KStandardAction::openNew(this, SLOT(fileNew()), actionCollection());
96  KStandardAction::open(this, SLOT(fileOpen()), actionCollection());
97 
98  KStandardAction::quit(qApp, SLOT(closeAllWindows()), actionCollection());
99 
100  createStandardStatusBarAction();
101  setStandardToolBarMenuEnabled(true);
102 
103  //KStandardAction::keyBindings(this, SLOT(optionsConfigureKeys()), actionCollection());
104  //KStandardAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection());
105 }
106 
107 void %{APPNAME}::saveProperties(KConfigGroup & /*config*/)
108 {
109  // the 'config' object points to the session managed
110  // config file. anything you write here will be available
111  // later when this app is restored
112 }
113 
114 void %{APPNAME}::readProperties(const KConfigGroup & /*config*/)
115 {
116  // the 'config' object points to the session managed
117  // config file. this function is automatically called whenever
118  // the app is being restored. read in here whatever you wrote
119  // in 'saveProperties'
120 }
121 
122 void %{APPNAME}::fileNew()
123 {
124  // this slot is called whenever the File->New menu is selected,
125  // the New shortcut is pressed (usually CTRL+N) or the New toolbar
126  // button is clicked
127 
128  // About this function, the style guide (
129  // http://developer.kde.org/documentation/standards/kde/style/basics/index.html )
130  // says that it should open a new window if the document is _not_
131  // in its initial state. This is what we do here..
132  if ( ! m_part->url().isEmpty() || m_part->isModified() )
133  {
134  (new %{APPNAME})->show();
135  };
136 }
137 
138 void %{APPNAME}::optionsConfigureKeys()
139 {
140  /*KShortcutsDialog dlg( KKeyChooser::AllActions, KKeyChooser::LetterShortcutsDisallowed, this );
141  dlg.insert( actionCollection(), "%{APPNAMELC}_shell.rc" );
142  dlg.insert( m_part->actionCollection(), "%{APPNAMELC}_part.rc" );
143  (void) dlg.configure( true );*/
144 }
145 
146 void %{APPNAME}::optionsConfigureToolbars()
147 {
148  //saveMainWindowSettings(KGlobal::config(), autoSaveGroup());
149 
150  // use the standard toolbar editor
151  /*KEditToolBar dlg(factory());
152  connect(&dlg, SIGNAL(newToolbarConfig()),
153  this, SLOT(applyNewToolbarConfig()));
154  dlg.exec();*/
155 }
156 
157 void %{APPNAME}::applyNewToolbarConfig()
158 {
159  //applyMainWindowSettings(KGlobal::config(), autoSaveGroup());
160 }
161 
162 void %{APPNAME}::fileOpen()
163 {
164  // this slot is called whenever the File->Open menu is selected,
165  // the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
166  // button is clicked
167  KUrl url =
168  KFileDialog::getOpenUrl( KUrl(), QString(), this );
169 
170  if (url.isEmpty() == false)
171  {
172  // About this function, the style guide (
173  // http://developer.kde.org/documentation/standards/kde/style/basics/index.html )
174  // says that it should open a new window if the document is _not_
175  // in its initial state. This is what we do here..
176  if ( m_part->url().isEmpty() && ! m_part->isModified() )
177  {
178  // we open the file in this window...
179  load( url );
180  }
181  else
182  {
183  // we open the file in a new window...
184  %{APPNAME}* newWin = new %{APPNAME};
185  newWin->load( url );
186  newWin->show();
187  }
188  }
189 }
%{APPNAMELC}.h
APPNAME
main APPNAME
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:03:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kapptemplate

Skip menu "kapptemplate"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal