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

kig

  • sources
  • kde-4.14
  • 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 #include <KService>
47 
48 Kig::Kig()
49  : KParts::MainWindow(), m_part( 0 )
50 {
51  KService::Ptr kigpartService = KService::serviceByDesktopName("kig_part");
52 
53  setObjectName( QLatin1String( "Kig" ) );
54  // setting the configation file
55  config = new KConfig( "kigrc" );
56  // set the shell's ui resource file
57  setXMLFile("kigui.rc");
58  // then, setup our actions
59  setupActions();
60 
61  if ( kigpartService )
62  {
63  m_part = kigpartService->createInstance< KParts::ReadWritePart >( this );
64  m_mimeTypes = kigpartService->mimeTypes();
65  if (m_part)
66  {
67  // tell the KParts::MainWindow that this is indeed the main widget
68  setCentralWidget(m_part->widget());
69 
70  // and integrate the part's GUI with the shell's
71  createGUI(m_part);
72 
73  // finally show tip-of-day ( if the user wants it :) )
74  QTimer::singleShot( 0, this, SLOT( startupTipOfDay() ) );
75  }
76  }
77  else
78  {
79  // if we couldn't find our Part, we exit since the Shell by
80  // itself can't do anything useful
81  KMessageBox::error(this, i18n( "Could not find the necessary Kig library, check your installation." ) );
82  QApplication::exit();
83  return;
84  }
85 
86  // we have drag'n'drop
87  setAcceptDrops(true);
88 
89  // save the window settings on exit.
90  setAutoSaveSettings();
91 }
92 
93 Kig::~Kig()
94 {
95  m_recentFilesAction->saveEntries(config->group( QString() ));
96  delete config;
97 }
98 
99 void Kig::setupActions()
100 {
101  KStandardAction::openNew(this, SLOT(fileNew()), actionCollection());
102  KStandardAction::open(this, SLOT(fileOpen()), actionCollection());
103  KStandardAction::quit(this, SLOT(close()), actionCollection());
104 
105  createStandardStatusBarAction();
106  setStandardToolBarMenuEnabled(true);
107 
108  // FIXME: this (recent files) should be app-wide, not specific to each window...
109  m_recentFilesAction = KStandardAction::openRecent( this, SLOT( openUrl( const KUrl& ) ), actionCollection() );
110  m_recentFilesAction->loadEntries(config->group( QString() ) );
111 
112  KStandardAction::keyBindings( guiFactory(), SLOT( configureShortcuts() ), actionCollection() );
113  KStandardAction::configureToolbars(this, SLOT(optionsConfigureToolbars()), actionCollection());
114 
115  KStandardAction::tipOfDay( this, SLOT( tipOfDay() ), actionCollection() );
116 }
117 
118 void Kig::saveProperties(KConfigGroup &config)
119 {
120  // the 'config' object points to the session managed
121  // config file. anything you write here will be available
122  // later when this app is restored
123  config.writePathEntry("fileName", m_part->url().path());
124 }
125 
126 void Kig::readProperties(const KConfigGroup &config)
127 {
128  // the 'config' object points to the session managed
129  // config file. this function is automatically called whenever
130  // the app is being restored. read in here whatever you wrote
131  // in 'saveProperties'
132  load( KUrl( config.readPathEntry( "fileName", QString() ) ) );
133 }
134 
135 void Kig::load( const KUrl& url )
136 {
137  // we check for m_part not being 0, because in the case of us not
138  // finding our library, we would otherwise get a crash...
139  if ( m_part && m_part->openUrl( url ) ) m_recentFilesAction->addUrl( url );
140 }
141 
142 void Kig::fileNew()
143 {
144  // this slot is called whenever the File->New menu is selected,
145  // the New shortcut is pressed (usually CTRL+N) or the New toolbar
146  // button is clicked
147 
148  // create a new window if we aren't in the "initial state" ( see
149  // the KDE style guide on the file menu stuff...)
150  if ( ! m_part->url().isEmpty() || m_part->isModified() )
151  (new Kig)->show();
152 }
153 
154 void Kig::openUrl( const KUrl& url )
155 {
156  // Called for opening a file by either the KRecentFilesAction or our
157  // own fileOpen() method.
158  // if we are in the "initial state", we open the url in this window:
159  if ( m_part->url().isEmpty() && ! m_part->isModified() )
160  {
161  load( url );
162  }
163  else
164  {
165  // otherwise we open it in a new window...
166  Kig* widget = new Kig;
167  widget->load(url);
168  widget->show();
169  };
170 }
171 
172 void Kig::optionsConfigureToolbars()
173 {
174  saveMainWindowSettings(KGlobal::config()->group( "MainWindow") );
175 
176  // use the standard toolbar editor
177  KEditToolBar dlg(factory());
178  connect(&dlg, SIGNAL(newToolBarConfig()),
179  this, SLOT(applyNewToolbarConfig()));
180  dlg.exec();
181 }
182 
183 void Kig::applyNewToolbarConfig()
184 {
185  applyMainWindowSettings(KGlobal::config()->group( "MainWindow") );
186 }
187 
188 bool Kig::queryClose()
189 {
190  return m_part->queryClose();
191 }
192 
193 void Kig::dragEnterEvent(QDragEnterEvent* e)
194 {
195  e->setAccepted( KUrl::List::canDecode( e->mimeData() ) );
196 }
197 
198 void Kig::dropEvent(QDropEvent* e)
199 {
200  KUrl::List urls = KUrl::List::fromMimeData( e->mimeData() );
201  for ( KUrl::List::iterator u = urls.begin(); u != urls.end(); ++u )
202  {
203  Kig* k = new Kig();
204  k->show();
205  k->load( *u );
206  }
207 }
208 
209 void Kig::fileOpen()
210 {
211  // this slot is connected to the KStandardAction::open action...
212  QString file_name = KFileDialog::getOpenFileName( KUrl( "kfiledialog:///document" ), m_mimeTypes.join( " " ) );
213 
214  if (!file_name.isEmpty()) openUrl(file_name);
215 }
216 
217 void Kig::tipOfDay() {
218  KTipDialog::showTip(this, "kig/tips", true);
219 }
220 
221 void Kig::startupTipOfDay() {
222  KTipDialog::showTip(this, "kig/tips");
223 }
Kig::load
void load(const KUrl &file)
Open file in this window.
Definition: kig.cpp:135
QDropEvent::mimeData
const QMimeData * mimeData() const
Kig::dragEnterEvent
virtual void dragEnterEvent(QDragEnterEvent *e)
The user started dragging something onto us...
Definition: kig.cpp:193
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:188
QStringList::join
QString join(const QString &separator) const
Kig::~Kig
virtual ~Kig()
Default Destructor.
Definition: kig.cpp:93
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:118
QCoreApplication::exit
void exit(int returnCode)
QEvent::setAccepted
void setAccepted(bool accepted)
QDropEvent
QString::isEmpty
bool isEmpty() const
QString
Kig::dropEvent
virtual void dropEvent(QDropEvent *e)
The user dropped something onto us...
Definition: kig.cpp:198
kig.h
QDragEnterEvent
Kig::Kig
Kig()
Default Constructor.
Definition: kig.cpp:48
QLatin1String
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:126
QTimer::singleShot
singleShot
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:12:05 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
  • 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