• 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
  • scripting
newscriptwizard.cc
Go to the documentation of this file.
1 // Copyright (C) 2003 Dominique Devriese <devriese@kde.org>
2 // Copyright (C) 2005-2006 Pino Toscano <toscano.pino@tiscali.it>
3 
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License
6 // as published by the Free Software Foundation; either version 2
7 // of the License, or (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 Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 // 02110-1301, USA.
18 
19 #include "newscriptwizard.h"
20 #include "newscriptwizard.moc"
21 
22 #include "script_mode.h"
23 
24 #include <qlabel.h>
25 #include <qlayout.h>
26 #include <qmenu.h>
27 
28 #include <kaction.h>
29 #include <kactioncollection.h>
30 #include <kdialog.h>
31 #include <kglobalsettings.h>
32 #include <kiconloader.h>
33 #include <klocale.h>
34 #include <ktextedit.h>
35 #include <ktexteditor/document.h>
36 #include <ktexteditor/editor.h>
37 #include <ktexteditor/editorchooser.h>
38 #include <ktexteditor/view.h>
39 #include <ktoolinvocation.h>
40 
41 #include <assert.h>
42 
43 static const int IntroPageId = 1;
44 static const int CodePageId = 2;
45 
46 NewScriptWizard::~NewScriptWizard()
47 {
48  if ( !document )
49  {
50  delete textedit;
51  }
52  else
53  {
54  delete document;
55  }
56 }
57 
58 NewScriptWizard::NewScriptWizard( QWidget* parent, ScriptModeBase* mode, KIconLoader* il )
59  : QWizard( parent ),
60  mmode( mode ), textedit( 0 ), document( 0 ), docview( 0 ), mIconLoader( il )
61 {
62  setObjectName( QLatin1String( "New Script Wizard" ) );
63  setWindowTitle( KDialog::makeStandardCaption( i18n( "New Script" ) ) );
64  setOption( HaveHelpButton );
65 
66  QWizardPage* firstPage = new QWizardPage( this );
67  firstPage->setTitle( i18n( "Select Arguments" ) );
68  firstPage->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
69  QVBoxLayout* lay1 = new QVBoxLayout( firstPage );
70  lay1->setMargin( 0 );
71  QLabel* infoText = new QLabel( firstPage );
72  lay1->addWidget( infoText );
73  infoText->setText( i18n( "Select the argument objects (if any)\n"
74  "in the Kig window and press \"Next\"." ) );
75  infoText->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter );
76  setPage( IntroPageId, firstPage );
77 
78  QWizardPage* secondPage = new QWizardPage( this );
79  secondPage->setTitle( i18n( "Enter Code" ) );
80  secondPage->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
81  secondPage->setFinalPage( true );
82  QVBoxLayout* lay2 = new QVBoxLayout( secondPage );
83  lay2->setMargin( 0 );
84  mLabelFillCode = new QLabel( secondPage );
85  lay2->addWidget( mLabelFillCode );
86  setPage( CodePageId, secondPage );
87 
88  KTextEditor::Editor* editor = KTextEditor::EditorChooser::editor();
89 // KTextEditor::Editor* editor = 0;
90  kDebug() << "EDITOR: " << editor;
91 
92  if ( !editor )
93  {
94  // there is no KDE textditor component installed, so we'll use a
95  // simplier KTextEdit
96  textedit = new KTextEdit( secondPage );
97  textedit->setObjectName( "textedit" );
98  textedit->setFont( KGlobalSettings::fixedFont() );
99  textedit->setAcceptRichText( false );
100  lay2->addWidget( textedit );
101  }
102  else
103  {
104  document = editor->createDocument( 0 );
105  // creating the 'view', that is what the user see and interact with
106  (void)document->createView( secondPage );
107  docview = document->activeView();
108 
109  lay2->addWidget( docview );
110 
111  // displaying the left border with line numbers
112  QAction *a = docview->actionCollection()->action( "view_line_numbers" );
113  if ( a )
114  {
115  a->trigger();
116  }
117 
118  // creating the popup menu
119  QMenu* menu = docview->defaultContextMenu();
120 
121  // finally, we install the popup menu
122  docview->setContextMenu( menu );
123  }
124 
125  connect( this, SIGNAL( currentIdChanged( int ) ), this, SLOT( currentIdChanged( int ) ) );
126  connect( this, SIGNAL( helpRequested() ), this, SLOT( slotHelpClicked() ) );
127 }
128 
129 void NewScriptWizard::currentIdChanged( int id )
130 {
131  switch ( id )
132  {
133  case IntroPageId:
134  mmode->argsPageEntered();
135  break;
136  case CodePageId:
137  mmode->codePageEntered();
138  if ( !document )
139  {
140  textedit->setFocus();
141  }
142  else
143  {
144  docview->setFocus();
145  }
146  break;
147  case -1: // no id - skip it
148  break;
149  default:
150  assert( false );
151  }
152 }
153 
154 void NewScriptWizard::reject()
155 {
156  if ( mmode->queryCancel() )
157  QWizard::reject();
158 }
159 
160 void NewScriptWizard::accept()
161 {
162  if ( mmode->queryFinish() )
163  QWizard::accept();
164 }
165 
166 void NewScriptWizard::slotHelpClicked()
167 {
168  KToolInvocation::invokeHelp( "scripting", "kig" );
169 }
170 
171 void NewScriptWizard::setText( const QString& text )
172 {
173  if ( !document )
174  {
175  textedit->setPlainText( text );
176  }
177  else
178  {
179  document->setText( text );
180  }
181 }
182 
183 QString NewScriptWizard::text() const
184 {
185  if ( !document )
186  {
187  return textedit->toPlainText();
188  }
189  else
190  {
191  return document->text();
192  }
193 }
194 
195 void NewScriptWizard::setType( ScriptType::Type type )
196 {
197  mLabelFillCode->setText( ScriptType::fillCodeStatement( type ) );
198  KIcon scriptIcon( ScriptType::icon( type ), mIconLoader );
199  if ( type != ScriptType::Unknown )
200  {
201  setWindowIcon( scriptIcon );
202  }
203  setPixmap( LogoPixmap, scriptIcon.pixmap( 64, 64 ) );
204 
205  if ( document )
206  {
207  // setting the highlight mode
208  document->setMode( ScriptType::highlightStyle( type ) );
209  }
210 }
NewScriptWizard::slotHelpClicked
void slotHelpClicked()
Definition: newscriptwizard.cc:166
NewScriptWizard::text
QString text() const
Definition: newscriptwizard.cc:183
NewScriptWizard::mLabelFillCode
QLabel * mLabelFillCode
Definition: newscriptwizard.h:58
ScriptModeBase
Base mode to interact with a script.
Definition: script_mode.h:32
ScriptModeBase::queryCancel
virtual bool queryCancel()=0
CodePageId
static const int CodePageId
Definition: newscriptwizard.cc:44
newscriptwizard.h
ScriptType::icon
static const char * icon(ScriptType::Type type)
Returns the icon's name for a script language.
Definition: script-common.cc:107
NewScriptWizard::mIconLoader
KIconLoader * mIconLoader
Definition: newscriptwizard.h:62
QWidget
ScriptType::Type
Type
This enum represents all the script language types actually in Kig.
Definition: script-common.h:36
script_mode.h
ScriptModeBase::queryFinish
virtual bool queryFinish()=0
ScriptType::fillCodeStatement
static QString fillCodeStatement(ScriptType::Type type)
Returns an i18n'ed statement like 'Now fill in the code:' with the name of the script language...
Definition: script-common.cc:39
NewScriptWizard::accept
void accept()
Definition: newscriptwizard.cc:160
NewScriptWizard::setType
void setType(ScriptType::Type type)
Definition: newscriptwizard.cc:195
NewScriptWizard::NewScriptWizard
NewScriptWizard(QWidget *parent, ScriptModeBase *mode, KIconLoader *il)
Definition: newscriptwizard.cc:58
NewScriptWizard::setText
void setText(const QString &text)
Definition: newscriptwizard.cc:171
NewScriptWizard::reject
void reject()
Definition: newscriptwizard.cc:154
NewScriptWizard::document
KTextEditor::Document * document
Definition: newscriptwizard.h:60
ScriptModeBase::codePageEntered
void codePageEntered()
Definition: script_mode.cc:160
NewScriptWizard::currentIdChanged
void currentIdChanged(int id)
Definition: newscriptwizard.cc:129
NewScriptWizard::docview
KTextEditor::View * docview
Definition: newscriptwizard.h:61
ScriptModeBase::argsPageEntered
void argsPageEntered()
Definition: script_mode.cc:148
NewScriptWizard::textedit
KTextEdit * textedit
Definition: newscriptwizard.h:59
NewScriptWizard::~NewScriptWizard
~NewScriptWizard()
Definition: newscriptwizard.cc:46
ScriptType::highlightStyle
static QString highlightStyle(ScriptType::Type type)
Returns the Kate highlight stytle name for a script language.
Definition: script-common.cc:112
ScriptType::Unknown
Definition: script-common.h:36
IntroPageId
static const int IntroPageId
Definition: newscriptwizard.cc:43
QWizard
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