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

kig

  • sources
  • kde-4.12
  • kdeedu
  • kig
  • kig
kig.cpp
Go to the documentation of this file.
1 
21 #include "kig.h"
22 #include "kig.moc"
23 
24 #include <qevent.h>
25 #include <qtimer.h>
26 
27 #include <kaction.h>
28 #include <kconfig.h>
29 #include <kdebug.h>
30 #include <kedittoolbar.h>
31 #include <kfiledialog.h>
32 #include <kshortcutsdialog.h>
33 #include <klibloader.h>
34 #include <klocale.h>
35 #include <kactioncollection.h>
36 #include <kmessagebox.h>
37 #include <krecentfilesaction.h>
38 #include <kstatusbar.h>
39 #include <kstandardaction.h>
40 #include <ktip.h>
41 #include <kurl.h>
42 #include <kxmlguifactory.h>
43 #include <kapplication.h>
44 #include <assert.h>
45 
46 Kig::Kig()
47  : KParts::MainWindow(), m_part( 0 )
48 {
49  setObjectName( QLatin1String( "Kig" ) );
50  // setting the configation file
51  config = new KConfig( "kigrc" );
52  // set the shell's ui resource file
53  setXMLFile("kigui.rc");
54  // then, setup our actions
55  setupActions();
56 
57  // this routine will find and load our Part. it finds the Part by
58  // name which is a bad idea usually.. but it's alright in this
59  // case since our Part is made for this Shell
60  KPluginLoader libraryLoader( "kigpart" );
61 
62  libraryLoader.setLoadHints( QLibrary::ExportExternalSymbolsHint );
63 
64  if ( KPluginFactory* factory = libraryLoader.factory() )
65  {
66  // now that the Part is loaded, we cast it to a Part to get
67  // our hands on it
68  m_part = factory->create< KParts::ReadWritePart >( this );
69  if (m_part)
70  {
71  // tell the KParts::MainWindow that this is indeed the main widget
72  setCentralWidget(m_part->widget());
73 
74  // and integrate the part's GUI with the shell's
75  // FIXME!!! disabling for now as it seems to create a unending loop
76  createGUI(m_part);
77  // finally show tip-of-day ( if the user wants it :) )
78  QTimer::singleShot( 0, this, SLOT( startupTipOfDay() ) );
79  }
80  }
81  else
82  {
83  // if we couldn't find our Part, we exit since the Shell by
84  // itself can't do anything useful
85  KMessageBox::error(this, i18n( "Could not find the necessary Kig library, check your installation." ) );
86  KApplication::exit();
87  return;
88  }
89 
90  // we have drag'n'drop
91  setAcceptDrops(true);
92 
93  // save the window settings on exit.
94  setAutoSaveSettings();
95 }
96 
97 Kig::~Kig()
98 {
99  m_recentFilesAction->saveEntries(config->group( QString() ));
100  delete config;
101 }
102 
103 void Kig::setupActions()
104 {
105  KStandardAction::openNew(this, SLOT(fileNew()), actionCollection());
106  KStandardAction::open(this, SLOT(fileOpen()), actionCollection());
107  KStandardAction::quit(this, SLOT(close()), actionCollection());
108 
109  createStandardStatusBarAction();
110  setStandardToolBarMenuEnabled(true);
111 
112  // FIXME: this (recent files) should be app-wide, not specific to each window...
113  m_recentFilesAction = KStandardAction::openRecent( this, SLOT( openUrl( const KUrl& ) ), actionCollection() );
114  m_recentFilesAction->loadEntries(config->group( QString() ) );
115 
116  KStandardAction::keyBindings( guiFactory(), SLOT( configureShortcuts() ), actionCollection() );
117  KStandardAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection());
118 
119  KStandardAction::tipOfDay( this, SLOT( tipOfDay() ), actionCollection() );
120 }
121 
122 void Kig::saveProperties(KConfigGroup &config)
123 {
124  // the 'config' object points to the session managed
125  // config file. anything you write here will be available
126  // later when this app is restored
127  config.writePathEntry("fileName", m_part->url().path());
128 }
129 
130 void Kig::readProperties(const KConfigGroup &config)
131 {
132  // the 'config' object points to the session managed
133  // config file. this function is automatically called whenever
134  // the app is being restored. read in here whatever you wrote
135  // in 'saveProperties'
136  load( KUrl( config.readPathEntry( "fileName", QString() ) ) );
137 }
138 
139 void Kig::load( const KUrl& url )
140 {
141  // we check for m_part not being 0, because in the case of us not
142  // finding our library, we would otherwise get a crash...
143  if ( m_part && m_part->openUrl( url ) ) m_recentFilesAction->addUrl( url );
144 }
145 
146 void Kig::fileNew()
147 {
148  // this slot is called whenever the File->New menu is selected,
149  // the New shortcut is pressed (usually CTRL+N) or the New toolbar
150  // button is clicked
151 
152  // create a new window if we aren't in the "initial state" ( see
153  // the KDE style guide on the file menu stuff...)
154  if ( ! m_part->url().isEmpty() || m_part->isModified() )
155  (new Kig)->show();
156 }
157 
158 void Kig::openUrl( const KUrl& url )
159 {
160  // Called for opening a file by either the KRecentFilesAction or our
161  // own fileOpen() method.
162  // if we are in the "initial state", we open the url in this window:
163  if ( m_part->url().isEmpty() && ! m_part->isModified() )
164  {
165  load( url );
166  }
167  else
168  {
169  // otherwise we open it in a new window...
170  Kig* widget = new Kig;
171  widget->load(url);
172  widget->show();
173  };
174 }
175 
176 void Kig::optionsConfigureToolbars()
177 {
178  saveMainWindowSettings(KGlobal::config()->group( "MainWindow") );
179 
180  // use the standard toolbar editor
181  KEditToolBar dlg(factory());
182  connect(&dlg, SIGNAL(newToolBarConfig()),
183  this, SLOT(applyNewToolbarConfig()));
184  dlg.exec();
185 }
186 
187 void Kig::applyNewToolbarConfig()
188 {
189  applyMainWindowSettings(KGlobal::config()->group( "MainWindow") );
190 }
191 
192 bool Kig::queryClose()
193 {
194  return m_part->queryClose();
195 }
196 
197 void Kig::dragEnterEvent(QDragEnterEvent* e)
198 {
199  e->setAccepted( KUrl::List::canDecode( e->mimeData() ) );
200 }
201 
202 void Kig::dropEvent(QDropEvent* e)
203 {
204  KUrl::List urls = KUrl::List::fromMimeData( e->mimeData() );
205  for ( KUrl::List::iterator u = urls.begin(); u != urls.end(); ++u )
206  {
207  Kig* k = new Kig();
208  k->show();
209  k->load( *u );
210  }
211 }
212 
213 void Kig::fileOpen()
214 {
215  QString formats =
216  i18n( "*.kig *.kigz *.seg *.fgeo *.fig *.FIG|All Supported Files (*.kig *.kigz *.seg *.fgeo *.fig)\n"
217  "*.kig|Kig Documents (*.kig)\n"
218  "*.kigz|Compressed Kig Documents (*.kigz)\n"
219  "*.kgeo|KGeo Documents (*.kgeo)\n"
220  "*.seg|KSeg Documents (*.seg)\n"
221  "*.fgeo|Dr. Geo Documents (*.fgeo)\n"
222  "*.fig *.FIG|Cabri Documents (*.fig *.FIG)" );
223 
224  // this slot is connected to the KStandardAction::open action...
225  QString file_name = KFileDialog::getOpenFileName( KUrl( "kfiledialog:///document" ), formats );
226 
227  if (!file_name.isEmpty()) openUrl(file_name);
228 }
229 
230 void Kig::tipOfDay() {
231  KTipDialog::showTip(this, "kig/tips", true);
232 }
233 
234 void Kig::startupTipOfDay() {
235  KTipDialog::showTip(this, "kig/tips");
236 }
Kig::load
void load(const KUrl &file)
Open file in this window.
Definition: kig.cpp:139
Kig::dragEnterEvent
virtual void dragEnterEvent(QDragEnterEvent *e)
The user started dragging something onto us...
Definition: kig.cpp:197
Kig::queryClose
bool queryClose()
this is called by the framework before closing the window, to allow the user to save his changes...
Definition: kig.cpp:192
Kig::~Kig
virtual ~Kig()
Default Destructor.
Definition: kig.cpp:97
Kig::saveProperties
void saveProperties(KConfigGroup &)
This method is called when it is time for the app to save its properties for session management purpo...
Definition: kig.cpp:122
Kig::dropEvent
virtual void dropEvent(QDropEvent *e)
The user dropped something onto us...
Definition: kig.cpp:202
kig.h
Kig::Kig
Kig()
Default Constructor.
Definition: kig.cpp:46
Kig
This is the application "Shell".
Definition: kig.h:30
Kig::openUrl
virtual void openUrl(const QString &s)
this opens the file specified in s in a new window
Definition: kig.h:56
Kig::readProperties
void readProperties(const KConfigGroup &)
This method is called when this app is restored.
Definition: kig.cpp:130
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

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