moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kturtle / src / dialogs.cpp
blob2d7b7ece1f48cbf45421f9077e0e69422af48584
1 /*
2 KTurtle, Copyright (C) 2003-04 Cies Breijs <cies # kde ! nl>
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of version 2 of the GNU General Public
6 License as published by the Free Software Foundation.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include <kapplication.h>
20 #include <kdebug.h>
21 #include <klocale.h>
23 #include "dialogs.h"
26 // BEGIN class ErrorMessage dialog
28 ErrorMessage::ErrorMessage (QWidget *parent)
29 : KDialogBase (parent, "errorDialog", false, 0, KDialogBase::Close | KDialogBase::Help | KDialogBase::User1, KDialogBase::Close, true, i18n("Help on &Error") )
31 connect( this, SIGNAL( user1Clicked() ), this, SLOT( showHelpOnError() ) );
32 connect( this, SIGNAL( helpClicked() ), this, SLOT( errorMessageHelp() ) );
33 setCaption( i18n("Error Dialog") );
34 setButtonWhatsThis( KDialogBase::Close, i18n("Closes this Error Dialog") );
35 setButtonWhatsThis( KDialogBase::Help, i18n("Click here to read more on this Error Dialog in KTurtle's Handbook.") );
36 setButtonTip( KDialogBase::Help, i18n("Click here for help using this Error Dialog") );
37 setButtonWhatsThis( KDialogBase::User1, i18n("Click here for help regarding the error you selected in the list. This button will not work when no error is selected.") );
38 setButtonTip( KDialogBase::User1, i18n("Click here for help regarding the error you selected.") );
40 QWidget *baseWidget = new QWidget(this);
41 setMainWidget(baseWidget);
42 baseLayout = new QVBoxLayout(baseWidget);
44 label = new QLabel(baseWidget);
45 label->setText( i18n("In this list you find the error(s) that resulted from running your Logo code. \nGood luck!") );
46 // \nYou can select an error and click the 'Help on Error' button for help.
47 label->setScaledContents(true);
48 baseLayout->addWidget(label);
50 spacer = new QSpacerItem( 10, 10, QSizePolicy::Minimum, QSizePolicy::Fixed );
51 baseLayout->addItem(spacer);
53 errTable = new QTable(0, 3, baseWidget);
54 errTable->setSelectionMode(QTable::SingleRow);
55 errTable->setReadOnly(true);
56 errTable->setShowGrid(false);
57 errTable->setFocusStyle(QTable::FollowStyle);
58 errTable->setLeftMargin(0);
60 errTable->horizontalHeader()->setLabel( 0, i18n("number") );
61 errTable->hideColumn(0); // needed to link with the errorData which stores the tokens, codes, etc.
63 errTable->horizontalHeader()->setLabel( 1, i18n("line") );
64 errTable->setColumnWidth(1, baseWidget->fontMetrics().width("88888") );
66 errTable->horizontalHeader()->setLabel( 2, i18n("description") );
67 errTable->setColumnStretchable(2, true);
69 baseLayout->addWidget(errTable);
71 // Since both help buttons are not working yet. Doc need a section on the Error Dialog!
72 enableButton(KDialogBase::Help, false);
73 enableButton(KDialogBase::User1, false);
75 errCount = 1;
79 void ErrorMessage::slotAddError(Token& t, const QString& s, uint c)
81 errorData err;
82 err.code = c;
83 err.tok = t;
84 err.msg = s;
85 errList.append(err);
87 Token currentToken = err.tok; kdDebug(0)<<"ErrorMessage::slotAddError(); >> "<<err.msg<<" <<, token: '"<<currentToken.look<<"', @ ("<<currentToken.start.row<<", "<<currentToken.start.col<<") - ("<<currentToken.end.row<<", "<<currentToken.end.col<<"), tok-number:"<<currentToken.type<<endl;
89 errTable->insertRows(0);
90 errTable->setText( 0, 0, QString::number(errCount) ); // put the count in a hidden field for reference
91 errTable->setText( 0, 1, QString::number(err.tok.start.row) );
92 errTable->setText( 0, 2, err.msg );
94 errCount++;
98 bool ErrorMessage::containsErrors()
100 if (errTable->numRows() != 0) return true;
101 return false;
104 void ErrorMessage::display()
106 errTable->clearSelection();
107 enableButton (KDialogBase::User1, false);
108 errTable->sortColumn(0, true, true);
109 show();
110 connect( errTable, SIGNAL( selectionChanged() ), this, SLOT( updateSelection() ) );
113 void ErrorMessage::updateSelection()
115 int i = errTable->text( errTable->currentRow(), 0 ).toInt(); // get the hidden errCount value
116 currentError = *errList.at(i - 1);
117 emit setSelection(currentError.tok.start.row, currentError.tok.start.col,
118 currentError.tok.end.row, currentError.tok.end.col);
119 // #if 0 // FIXME
120 // if ( tokenTypeNames[currentError.tok.type].isEmpty() ) enableButton(KDialogBase::User1, true);
121 // else enableButton(KDialogBase::User1, false);
122 // #endif
125 void ErrorMessage::showHelpOnError()
127 // #if 0 // FIXME
128 // kapp->invokeHelp(tokenTypeNames[currentError.tok.type], "", "");
129 // #endif
132 void ErrorMessage::errorMessageHelp()
134 kapp->invokeHelp("anchorname", "", "");
137 // END
141 // BEGIN class ColorPicker dialog
143 ColorPicker::ColorPicker(QWidget *parent)
144 : KDialogBase(parent, "colorpicker", false, i18n("Color Picker"), KDialogBase::Close | KDialogBase::Help | KDialogBase::User1, KDialogBase::Close, true )
146 // connect to help
147 connect( this, SIGNAL( helpClicked() ), SLOT( slotColorPickerHelp() ) );
149 // for toggling convenience
150 connect( this, SIGNAL( finished() ), SLOT( slotEmitVisibility() ) );
152 // Create the top level page and its layout
153 BaseWidget = new QWidget(this);
154 setMainWidget(BaseWidget);
156 // the User1 button:
157 setButtonText( KDialogBase::User1, i18n("Insert Color Code at Cursor") );
158 connect( this, SIGNAL( user1Clicked() ), SLOT( slotEmitColorCode() ) );
160 QVBoxLayout *vlayout = new QVBoxLayout(BaseWidget);
162 vlayout->addSpacing(5); // spacing on top
164 // the palette and value selector go into a H-box
165 QHBoxLayout *h1layout = new QHBoxLayout(BaseWidget);
166 vlayout->addLayout(h1layout);
168 h1layout->addSpacing(10); // space on the left border
170 hsSelector = new KHSSelector(BaseWidget); // the color (SH) selector
171 hsSelector->setMinimumSize(300, 150);
172 h1layout->addWidget(hsSelector);
173 connect( hsSelector, SIGNAL( valueChanged(int, int) ), SLOT( slotSelectorChanged(int, int) ) );
175 h1layout->addSpacing(5); // space in between
177 valuePal = new KValueSelector(BaseWidget); // the darkness (V) pal
178 valuePal->setFixedWidth(30);
179 h1layout->addWidget(valuePal);
180 connect( valuePal, SIGNAL( valueChanged(int) ), SLOT( slotPalChanged(int) ) );
182 vlayout->addSpacing(15); // space in between the top and the bottom widgets
184 // the patch and the codegenerator also go into a H-box
185 QHBoxLayout *h2layout = new QHBoxLayout(BaseWidget);
186 vlayout->addLayout(h2layout);
188 h2layout->addSpacing(10); // space on the left border
190 patch = new KColorPatch(BaseWidget); // the patch (color previewer)
191 patch->setFixedSize(50, 50);
192 h2layout->addWidget(patch);
194 h2layout->addSpacing(10); // space in between
196 // the label and the codegenerator go in a V-box
197 QVBoxLayout *v2layout = new QVBoxLayout(BaseWidget);
198 h2layout->addLayout(v2layout);
200 copyable = new QLabel(i18n("Color code:"), BaseWidget); // tha label
201 v2layout->addWidget(copyable);
203 colorcode = new QLineEdit(BaseWidget); // the code generator
204 colorcode->setReadOnly(true);
205 v2layout->addWidget(colorcode);
206 connect( colorcode, SIGNAL( selectionChanged() ), SLOT( slotReselect() ) );
208 h2layout->addSpacing(5); // spacing on the right border
210 vlayout->addSpacing(10); // spacing on the bottom
212 h = g = b = 0; // start with red
213 s = v = r = 255;
215 slotSelectorChanged(h, s); // update all at once
220 void ColorPicker::updateSelector()
222 hsSelector->setValues(h, s);
225 void ColorPicker::updatePal()
227 valuePal->setHue(h);
228 valuePal->setSaturation(s);
229 valuePal->setValue(v);
230 valuePal->updateContents();
231 valuePal->repaint(false);
234 void ColorPicker::updatePatch()
236 patch->setColor(color);
239 void ColorPicker::updateColorCode()
241 color.getRgb(&r, &g, &b);
242 colorcode->setText( QString("%1, %2, %3").arg(r).arg(g).arg(b) );
243 colorcode->selectAll();
246 void ColorPicker::slotSelectorChanged(int h_, int s_)
248 h = h_;
249 s = s_;
250 color.setHsv(h, s, v);
252 //updateSelector(); // updated it self allready
253 updatePal();
254 updatePatch();
255 updateColorCode();
258 void ColorPicker::slotPalChanged(int v_)
260 v = v_;
261 color.setHsv(h, s, v);
263 //updateSelector(); // only needed when H or S changes
264 //updatePal(); // updated it self allready
265 updatePatch();
266 updateColorCode();
269 void ColorPicker::slotReselect()
271 // reselect by selectAll(), but make sure no looping occurs
272 disconnect( colorcode, SIGNAL( selectionChanged() ), 0, 0 );
273 colorcode->selectAll();
274 connect( colorcode, SIGNAL( selectionChanged() ), SLOT( slotReselect() ) );
277 void ColorPicker::slotEmitVisibility()
279 // for toggling convenience
280 emit visible(false);
283 void ColorPicker::slotEmitColorCode()
285 // convenience
286 emit ColorCode( colorcode->text() );
289 void ColorPicker::slotColorPickerHelp()
291 kapp->invokeHelp("tools-color-picker", "", "");
294 // END
298 // BEGIN class RestartOrBack dialog
300 RestartOrBack::RestartOrBack (QWidget *parent)
301 : KDialogBase (parent, "rbDialog", true, 0, KDialogBase::User1 | KDialogBase::User2, KDialogBase::User2, false, i18n("&Restart"), i18n("&Back") )
303 setPlainCaption( i18n("Finished Execution") );
304 setButtonWhatsThis( KDialogBase::User1, i18n("Click here to restart the current logo program.") );
305 setButtonWhatsThis( KDialogBase::User2, i18n("Click here to switch back to the edit mode.") );
306 QWidget *baseWidget = new QWidget(this);
307 setMainWidget(baseWidget);
308 baseLayout = new QVBoxLayout(baseWidget);
310 label = new QLabel(baseWidget);
311 label->setText( i18n("Execution was finished without errors.\nWhat do you want to do next?") );
312 label->setScaledContents(true);
313 baseLayout->addWidget(label);
314 disableResize();
317 // END
320 #include "dialogs.moc"