• 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
  • modes
textlabelwizard.cc
Go to the documentation of this file.
1 // Copyright (C) 2002 Dominique Devriese <devriese@kde.org>
2 
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 // 02110-1301, USA.
17 
18 #include "textlabelwizard.h"
19 #include "textlabelwizard.moc"
20 
21 #include "label.h"
22 #include "linkslabel.h"
23 
24 #include <qcheckbox.h>
25 #include <qlabel.h>
26 #include <qlayout.h>
27 #include <qtextedit.h>
28 
29 #include <kdialog.h>
30 #include <ktoolinvocation.h>
31 #include <kdebug.h>
32 
33 // defined in label.cc
34 extern uint percentCount( const QString& s );
35 
36 class TextPage : public QWizardPage
37 {
38 public:
39  TextPage( QWidget* parent, TextLabelModeBase* mode );
40 
41  QTextEdit* mtext;
42 
43 private:
44  TextLabelModeBase* mmode;
45 };
46 
47 TextPage::TextPage( QWidget* parent, TextLabelModeBase* mode )
48  : QWizardPage( parent ), mmode( mode )
49 {
50  setTitle( i18n( "Enter Label Text" ) );
51  setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
52  setFinalPage( true );
53 
54  QVBoxLayout* lay = new QVBoxLayout( this );
55  lay->setMargin( 0 );
56  QLabel* label = new QLabel( this );
57  lay->addWidget( label );
58  label->setText(
59  i18n( "Enter the text for your label here and press \"Next\".\n"
60  "If you want to show variable parts, then put %1, %2, ... "
61  "at the appropriate places (e.g. \"This segment is %1 units "
62  "long.\").", QString( "%1" ), QString( "%2" ) ) ); // grrr i18n()
63  label->setAlignment( Qt::AlignTop );
64  label->setWordWrap( true );
65  mtext = new QTextEdit( this );
66  lay->addWidget( mtext );
67  QCheckBox* wantframe = new QCheckBox( this );
68  lay->addWidget( wantframe );
69  wantframe->setText( i18n( "Show text in a frame" ) );
70 
71  registerField( "wantframe", wantframe );
72 
73  connect( mtext, SIGNAL( textChanged() ), parent, SLOT( textChanged() ) );
74 }
75 
76 
77 class ArgsPage : public QWizardPage
78 {
79 public:
80  ArgsPage( QWidget* parent, TextLabelModeBase* mode );
81 
82  virtual bool validatePage();
83 
84  LinksLabel* mlinks;
85 
86 private:
87  TextLabelModeBase* mmode;
88 };
89 
90 ArgsPage::ArgsPage( QWidget* parent, TextLabelModeBase* mode )
91  : QWizardPage( parent ), mmode( mode )
92 {
93  setTitle( i18n( "Select Arguments" ) );
94  setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
95  setFinalPage( true );
96 
97  QVBoxLayout* lay = new QVBoxLayout( this );
98  lay->setMargin( 0 );
99  QLabel* label = new QLabel( this );
100  lay->addWidget( label );
101  label->setText(
102  i18n( "Now select the argument(s) you need. For every argument, "
103  "click on it, select an object and a property in the Kig "
104  "window, and click finish when you are done..." ) );
105  label->setWordWrap( true );
106  mlinks = new LinksLabel( this );
107  lay->addWidget( mlinks );
108 
109  connect( mlinks, SIGNAL( changed() ), this, SIGNAL( completeChanged() ) );
110 }
111 
112 bool ArgsPage::validatePage()
113 {
114  return mmode->canFinish();
115 }
116 
117 
118 TextLabelWizard::TextLabelWizard( QWidget* parent, TextLabelModeBase* mode )
119  : QWizard( parent ), mmode( mode )
120 {
121  setModal( false );
122  setObjectName( QLatin1String( "TextLabelWizard" ) );
123  setWindowTitle( KDialog::makeStandardCaption( i18n( "Construct Label" ) ) );
124  setOption( HaveHelpButton );
125  setOption( HaveFinishButtonOnEarlyPages );
126 
127  mtextPage = new TextPage( this, mmode );
128  setPage( TextPageId, mtextPage );
129  margsPage = new ArgsPage( this, mmode );
130  setPage( ArgsPageId, margsPage );
131 
132  connect( this, SIGNAL( helpRequested() ), this,
133  SLOT( slotHelpClicked() ) );
134  connect( linksLabel(), SIGNAL( linkClicked( int ) ),
135  SLOT( linkClicked( int ) ) );
136  connect( this, SIGNAL( currentIdChanged( int ) ),
137  this, SLOT( currentIdChanged( int ) ) );
138 
139  mtextPage->mtext->setFocus();
140 }
141 
142 TextLabelWizard::~TextLabelWizard()
143 {
144 }
145 
146 LinksLabel* TextLabelWizard::linksLabel()
147 {
148  return margsPage->mlinks;
149 }
150 
151 QString TextLabelWizard::text() const
152 {
153  return mtextPage->mtext->toPlainText();
154 }
155 
156 void TextLabelWizard::setText( const QString& newtext )
157 {
158  mtextPage->mtext->setPlainText( newtext );
159 }
160 
161 void TextLabelWizard::reject()
162 {
163  QWizard::reject();
164  mmode->cancelPressed();
165 }
166 
167 void TextLabelWizard::accept()
168 {
169  if( validateCurrentPage() )
170  {
171  QWizard::accept();
172  mmode->finishPressed();
173  }
174 }
175 
176 void TextLabelWizard::textChanged()
177 {
178  uint percentcount = percentCount( text() );
179  bool finish = mmode->percentCountChanged( percentcount );
180  (void)finish;
181  button( QWizard::FinishButton )->setEnabled( percentcount == 0 );
182  button( QWizard::NextButton )->setEnabled( percentcount > 0 );
183 }
184 
185 void TextLabelWizard::linkClicked( int which )
186 {
187  mmode->linkClicked( which );
188 }
189 
190 void TextLabelWizard::currentIdChanged( int id )
191 {
192  switch ( id )
193  {
194  case TextPageId:
195  mmode->enterTextPageEntered();
196  // simulate a text change
197  textChanged();
198  break;
199  case ArgsPageId:
200  mmode->selectArgumentsPageEntered();
201  break;
202  case -1: // no id - skip it
203  break;
204  default:
205  ;
206  }
207 }
208 
209 void TextLabelWizard::slotHelpClicked()
210 {
211  KToolInvocation::invokeHelp( "text-labels", "kig" );
212 }
213 
TextLabelWizard::setText
void setText(const QString &newtext)
Definition: textlabelwizard.cc:156
TextLabelModeBase::enterTextPageEntered
void enterTextPageEntered()
Definition: label.cc:285
TextLabelWizard::linksLabel
LinksLabel * linksLabel()
Definition: textlabelwizard.cc:146
TextLabelWizard::accept
void accept()
Definition: textlabelwizard.cc:167
QWidget
TextLabelWizard::text
QString text() const
Definition: textlabelwizard.cc:151
TextLabelModeBase::cancelPressed
void cancelPressed()
Definition: label.cc:294
TextLabelModeBase::linkClicked
void linkClicked(int)
Definition: label.cc:425
TextLabelWizard::TextLabelWizard
TextLabelWizard(QWidget *parent, TextLabelModeBase *mode)
Definition: textlabelwizard.cc:118
linkslabel.h
TextLabelWizard::~TextLabelWizard
~TextLabelWizard()
Definition: textlabelwizard.cc:142
TextLabelWizard::reject
void reject()
Definition: textlabelwizard.cc:161
TextLabelModeBase::selectArgumentsPageEntered
void selectArgumentsPageEntered()
Definition: label.cc:289
TextLabelWizard::TextPageId
static const int TextPageId
Definition: textlabelwizard.h:35
TextLabelModeBase::finishPressed
void finishPressed()
Definition: label.cc:336
label.h
textlabelwizard.h
TextLabelWizard::ArgsPageId
static const int ArgsPageId
Definition: textlabelwizard.h:36
percentCount
uint percentCount(const QString &s)
Definition: label.cc:300
LinksLabel
this widget shows a line of text, with some links underlined, and emits a signal if one of the links ...
Definition: linkslabel.h:30
TextLabelModeBase
this is the base class for TextLabelConstructionMode and TextLabelRedefineMode.
Definition: label.h:41
TextLabelModeBase::percentCountChanged
bool percentCountChanged(uint percentcount)
Definition: label.cc:345
uint
unsigned int uint
Definition: object_imp.h:87
QWizard
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:40 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