-rw-r--r-- | noncore/apps/opie-write/mainwindow.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/noncore/apps/opie-write/mainwindow.cpp b/noncore/apps/opie-write/mainwindow.cpp index bcafd16..4a49abf 100644 --- a/noncore/apps/opie-write/mainwindow.cpp +++ b/noncore/apps/opie-write/mainwindow.cpp | |||
@@ -111,222 +111,222 @@ MainWindow::MainWindow( QWidget *parent, const char *name ) | |||
111 | fileSelector = new FileSelector( "text/html", | 111 | fileSelector = new FileSelector( "text/html", |
112 | editorStack, "fileselector" ); | 112 | editorStack, "fileselector" ); |
113 | 113 | ||
114 | 114 | ||
115 | fileSelector->setCloseVisible( FALSE ); | 115 | fileSelector->setCloseVisible( FALSE ); |
116 | editorStack->addWidget( fileSelector, 0 ); | 116 | editorStack->addWidget( fileSelector, 0 ); |
117 | 117 | ||
118 | editor = new Qt3::QTextEdit( editorStack ); | 118 | editor = new Qt3::QTextEdit( editorStack ); |
119 | editor->setTextFormat( Qt::RichText ); | 119 | editor->setTextFormat( Qt::RichText ); |
120 | editorStack->addWidget( editor, 1 ); | 120 | editorStack->addWidget( editor, 1 ); |
121 | 121 | ||
122 | setupActions(); | 122 | setupActions(); |
123 | 123 | ||
124 | QObject::connect( fileSelector, SIGNAL(closeMe()), | 124 | QObject::connect( fileSelector, SIGNAL(closeMe()), |
125 | this, SLOT(showEditTools()) ); | 125 | this, SLOT(showEditTools()) ); |
126 | QObject::connect( fileSelector, SIGNAL(fileSelected(const DocLnk &)), | 126 | QObject::connect( fileSelector, SIGNAL(fileSelected(const DocLnk &)), |
127 | this, SLOT(openFile(const DocLnk &)) ); | 127 | this, SLOT(openFile(const DocLnk &)) ); |
128 | QObject::connect( fileSelector, SIGNAL(newSelected(const DocLnk&)), | 128 | QObject::connect( fileSelector, SIGNAL(newSelected(const DocLnk&)), |
129 | this, SLOT(newFile(const DocLnk&)) ); | 129 | this, SLOT(newFile(const DocLnk&)) ); |
130 | 130 | ||
131 | if ( fileSelector->fileCount() < 1 ) | 131 | if ( fileSelector->fileCount() < 1 ) |
132 | fileNew(); | 132 | fileNew(); |
133 | else { | 133 | else { |
134 | fileOpen(); | 134 | fileOpen(); |
135 | } | 135 | } |
136 | doConnections( editor ); | 136 | doConnections( editor ); |
137 | 137 | ||
138 | setCentralWidget( editorStack ); | 138 | setCentralWidget( editorStack ); |
139 | } | 139 | } |
140 | 140 | ||
141 | MainWindow::~MainWindow() | 141 | MainWindow::~MainWindow() |
142 | { | 142 | { |
143 | save(); | 143 | save(); |
144 | } | 144 | } |
145 | 145 | ||
146 | void MainWindow::setupActions() | 146 | void MainWindow::setupActions() |
147 | { | 147 | { |
148 | setToolBarsMovable(false); | 148 | setToolBarsMovable(false); |
149 | 149 | ||
150 | tbMenu = new QToolBar( this ); | 150 | tbMenu = new QToolBar( this ); |
151 | tbMenu->setHorizontalStretchable( TRUE ); | 151 | tbMenu->setHorizontalStretchable( TRUE ); |
152 | 152 | ||
153 | QMenuBar *menu = new QMenuBar( tbMenu ); | 153 | QMenuBar *menu = new QMenuBar( tbMenu ); |
154 | 154 | ||
155 | tbEdit = new QToolBar( this ); | 155 | tbEdit = new QToolBar( this ); |
156 | 156 | ||
157 | QPopupMenu *file = new QPopupMenu( this ); | 157 | QPopupMenu *file = new QPopupMenu( this ); |
158 | menu->insertItem( tr("File"), file ); | 158 | menu->insertItem( tr("File"), file ); |
159 | 159 | ||
160 | QPopupMenu *edit = new QPopupMenu( this ); | 160 | QPopupMenu *edit = new QPopupMenu( this ); |
161 | menu->insertItem( tr("Edit"), edit ); | 161 | menu->insertItem( tr("Edit"), edit ); |
162 | 162 | ||
163 | // ### perhaps these shortcut keys should have some | 163 | // ### perhaps these shortcut keys should have some |
164 | // IPaq keys defined??? | 164 | // IPaq keys defined??? |
165 | QAction *a; | 165 | QAction *a; |
166 | 166 | ||
167 | a = new QAction( tr( "New" ), Resource::loadPixmap("new"), QString::null, 0, this, 0 ); | 167 | a = new QAction( tr( "New" ), Resource::loadPixmap("new"), QString::null, 0, this, 0 ); |
168 | connect( a, SIGNAL(activated()), this, SLOT(fileNew()) ); | 168 | connect( a, SIGNAL(activated()), this, SLOT(fileNew()) ); |
169 | a->addTo( file ); | 169 | a->addTo( file ); |
170 | 170 | ||
171 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); | 171 | a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); |
172 | connect( a, SIGNAL(activated()), this, SLOT(fileOpen()) ); | 172 | connect( a, SIGNAL(activated()), this, SLOT(fileOpen()) ); |
173 | a->addTo( file ); | 173 | a->addTo( file ); |
174 | 174 | ||
175 | a = new QAction( tr( "Undo" ), Resource::loadIconSet("opie-write/undo"), | 175 | a = new QAction( tr( "Undo" ), Resource::loadIconSet("undo"), |
176 | QString::null, 0, this, "editUndo" ); | 176 | QString::null, 0, this, "editUndo" ); |
177 | connect( a, SIGNAL( activated() ), this, SLOT( editUndo() ) ); | 177 | connect( a, SIGNAL( activated() ), this, SLOT( editUndo() ) ); |
178 | connect( editor, SIGNAL(undoAvailable(bool)), a, SLOT(setEnabled(bool)) ); | 178 | connect( editor, SIGNAL(undoAvailable(bool)), a, SLOT(setEnabled(bool)) ); |
179 | a->addTo( tbEdit ); | 179 | a->addTo( tbEdit ); |
180 | a->addTo( edit ); | 180 | a->addTo( edit ); |
181 | a = new QAction( tr( "Redo" ), Resource::loadIconSet("opie-write/redo"), | 181 | a = new QAction( tr( "Redo" ), Resource::loadIconSet("redo"), |
182 | QString::null, 0, this, "editRedo" ); | 182 | QString::null, 0, this, "editRedo" ); |
183 | connect( a, SIGNAL( activated() ), this, SLOT( editRedo() ) ); | 183 | connect( a, SIGNAL( activated() ), this, SLOT( editRedo() ) ); |
184 | connect( editor, SIGNAL(redoAvailable(bool)), a, SLOT(setEnabled(bool)) ); | 184 | connect( editor, SIGNAL(redoAvailable(bool)), a, SLOT(setEnabled(bool)) ); |
185 | a->addTo( tbEdit ); | 185 | a->addTo( tbEdit ); |
186 | a->addTo( edit ); | 186 | a->addTo( edit ); |
187 | 187 | ||
188 | edit->insertSeparator(); | 188 | edit->insertSeparator(); |
189 | 189 | ||
190 | a = new QAction( tr( "Copy" ), Resource::loadIconSet("copy"), | 190 | a = new QAction( tr( "Copy" ), Resource::loadIconSet("copy"), |
191 | QString::null, 0, this, "editCopy" ); | 191 | QString::null, 0, this, "editCopy" ); |
192 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 192 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); |
193 | connect( editor, SIGNAL(copyAvailable(bool)), a, SLOT(setEnabled(bool)) ); | 193 | connect( editor, SIGNAL(copyAvailable(bool)), a, SLOT(setEnabled(bool)) ); |
194 | a->addTo( tbEdit ); | 194 | a->addTo( tbEdit ); |
195 | a->addTo( edit ); | 195 | a->addTo( edit ); |
196 | a = new QAction( tr( "Cut" ), Resource::loadIconSet("cut"), | 196 | a = new QAction( tr( "Cut" ), Resource::loadIconSet("cut"), |
197 | QString::null, 0, this, "editCut" ); | 197 | QString::null, 0, this, "editCut" ); |
198 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 198 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
199 | connect( editor, SIGNAL(copyAvailable(bool)), a, SLOT(setEnabled(bool)) ); | 199 | connect( editor, SIGNAL(copyAvailable(bool)), a, SLOT(setEnabled(bool)) ); |
200 | a->addTo( tbEdit ); | 200 | a->addTo( tbEdit ); |
201 | a->addTo( edit ); | 201 | a->addTo( edit ); |
202 | a = new QAction( tr( "Paste" ), Resource::loadPixmap("paste"), | 202 | a = new QAction( tr( "Paste" ), Resource::loadPixmap("paste"), |
203 | QString::null, 0, this, "editPaste" ); | 203 | QString::null, 0, this, "editPaste" ); |
204 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | 204 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); |
205 | a->addTo( tbEdit ); | 205 | a->addTo( tbEdit ); |
206 | a->addTo( edit ); | 206 | a->addTo( edit ); |
207 | 207 | ||
208 | tbFont = new QToolBar( this ); | 208 | tbFont = new QToolBar( this ); |
209 | tbFont->setLabel( "Font Actions" ); | 209 | tbFont->setLabel( "Font Actions" ); |
210 | tbFont->setHorizontalStretchable(TRUE); | 210 | tbFont->setHorizontalStretchable(TRUE); |
211 | 211 | ||
212 | comboFont = new QComboBox( FALSE, tbFont ); | 212 | comboFont = new QComboBox( FALSE, tbFont ); |
213 | FontDatabase db; | 213 | FontDatabase db; |
214 | QStringList f= db.families(); | 214 | QStringList f= db.families(); |
215 | comboFont->insertStringList( db.families() ); | 215 | comboFont->insertStringList( db.families() ); |
216 | connect( comboFont, SIGNAL( activated( const QString & ) ), | 216 | connect( comboFont, SIGNAL( activated( const QString & ) ), |
217 | this, SLOT( textFamily( const QString & ) ) ); | 217 | this, SLOT( textFamily( const QString & ) ) ); |
218 | comboFont->setCurrentItem( comboFont->listBox()->index( comboFont->listBox()->findItem( QApplication::font().family() ) ) ); | 218 | comboFont->setCurrentItem( comboFont->listBox()->index( comboFont->listBox()->findItem( QApplication::font().family() ) ) ); |
219 | comboFont->setMaximumWidth(90); | 219 | comboFont->setMaximumWidth(90); |
220 | 220 | ||
221 | comboSize = new QComboBox( TRUE, tbFont ); | 221 | comboSize = new QComboBox( TRUE, tbFont ); |
222 | QValueList<int> sizes = db.standardSizes(); | 222 | QValueList<int> sizes = db.standardSizes(); |
223 | QValueList<int>::Iterator it = sizes.begin(); | 223 | QValueList<int>::Iterator it = sizes.begin(); |
224 | for ( ; it != sizes.end(); ++it ) | 224 | for ( ; it != sizes.end(); ++it ) |
225 | comboSize->insertItem( QString::number( *it ) ); | 225 | comboSize->insertItem( QString::number( *it ) ); |
226 | connect( comboSize, SIGNAL( activated( const QString & ) ), | 226 | connect( comboSize, SIGNAL( activated( const QString & ) ), |
227 | this, SLOT( textSize( const QString & ) ) ); | 227 | this, SLOT( textSize( const QString & ) ) ); |
228 | comboSize->lineEdit()->setText( QString::number( QApplication::font().pointSize() ) ); | 228 | comboSize->lineEdit()->setText( QString::number( QApplication::font().pointSize() ) ); |
229 | comboSize->setFixedWidth( 38 ); | 229 | comboSize->setFixedWidth( 38 ); |
230 | 230 | ||
231 | tbStyle = new QToolBar( this ); | 231 | tbStyle = new QToolBar( this ); |
232 | tbStyle->setLabel( "Style Actions" ); | 232 | tbStyle->setLabel( "Style Actions" ); |
233 | 233 | ||
234 | actionTextBold = new QAction( tr( "Bold" ), | 234 | actionTextBold = new QAction( tr( "Bold" ), |
235 | Resource::loadPixmap("bold"), | 235 | Resource::loadPixmap("bold"), |
236 | QString::null, CTRL + Key_B, | 236 | QString::null, CTRL + Key_B, |
237 | this, "textBold" ); | 237 | this, "textBold" ); |
238 | connect( actionTextBold, SIGNAL( activated() ), this, SLOT( textBold() ) ); | 238 | connect( actionTextBold, SIGNAL( activated() ), this, SLOT( textBold() ) ); |
239 | actionTextBold->addTo( tbStyle ); | 239 | actionTextBold->addTo( tbStyle ); |
240 | actionTextBold->setToggleAction( TRUE ); | 240 | actionTextBold->setToggleAction( TRUE ); |
241 | actionTextItalic = new QAction( tr( "Italic" ), | 241 | actionTextItalic = new QAction( tr( "Italic" ), |
242 | Resource::loadPixmap("italic"), | 242 | Resource::loadPixmap("italic"), |
243 | tr( "&Italic" ), CTRL + Key_I, | 243 | tr( "&Italic" ), CTRL + Key_I, |
244 | this, "textItalic" ); | 244 | this, "textItalic" ); |
245 | connect( actionTextItalic, SIGNAL( activated() ), this, | 245 | connect( actionTextItalic, SIGNAL( activated() ), this, |
246 | SLOT( textItalic() ) ); | 246 | SLOT( textItalic() ) ); |
247 | actionTextItalic->addTo( tbStyle ); | 247 | actionTextItalic->addTo( tbStyle ); |
248 | actionTextItalic->setToggleAction( TRUE ); | 248 | actionTextItalic->setToggleAction( TRUE ); |
249 | actionTextUnderline = new QAction( tr( "Underline" ), | 249 | actionTextUnderline = new QAction( tr( "Underline" ), |
250 | Resource::loadPixmap("underline"), | 250 | Resource::loadPixmap("underline"), |
251 | tr( "&Underline" ), CTRL + Key_U, | 251 | tr( "&Underline" ), CTRL + Key_U, |
252 | this, "textUnderline" ); | 252 | this, "textUnderline" ); |
253 | connect( actionTextUnderline, SIGNAL( activated() ), | 253 | connect( actionTextUnderline, SIGNAL( activated() ), |
254 | this, SLOT( textUnderline() ) ); | 254 | this, SLOT( textUnderline() ) ); |
255 | actionTextUnderline->addTo( tbStyle ); | 255 | actionTextUnderline->addTo( tbStyle ); |
256 | actionTextUnderline->setToggleAction( TRUE ); | 256 | actionTextUnderline->setToggleAction( TRUE ); |
257 | 257 | ||
258 | alignMenu = new ButtonMenu( tbStyle ); | 258 | alignMenu = new ButtonMenu( tbStyle ); |
259 | alignMenu->insertItem( Resource::loadPixmap("left"), tr("Left"), AlignLeft ); | 259 | alignMenu->insertItem( Resource::loadPixmap("left"), tr("Left"), AlignLeft ); |
260 | alignMenu->insertItem( Resource::loadPixmap("center"), tr("Center"), AlignCenter ); | 260 | alignMenu->insertItem( Resource::loadPixmap("center"), tr("Center"), AlignCenter ); |
261 | alignMenu->insertItem( Resource::loadPixmap("right"), tr("Right"), AlignRight ); | 261 | alignMenu->insertItem( Resource::loadPixmap("right"), tr("Right"), AlignRight ); |
262 | alignMenu->insertItem( Resource::loadPixmap("opie-write/justify"), tr("Full"), Qt3::AlignJustify ); | 262 | alignMenu->insertItem( Resource::loadPixmap("opie-write/justify"), tr("Full"), Qt3::AlignJustify ); |
263 | connect( alignMenu, SIGNAL(activated(int)), this, SLOT(textAlign(int)) ); | 263 | connect( alignMenu, SIGNAL(activated(int)), this, SLOT(textAlign(int)) ); |
264 | } | 264 | } |
265 | 265 | ||
266 | Qt3::QTextEdit *MainWindow::currentEditor() const | 266 | Qt3::QTextEdit *MainWindow::currentEditor() const |
267 | { | 267 | { |
268 | return editor; | 268 | return editor; |
269 | } | 269 | } |
270 | 270 | ||
271 | void MainWindow::doConnections( Qt3::QTextEdit *e ) | 271 | void MainWindow::doConnections( Qt3::QTextEdit *e ) |
272 | { | 272 | { |
273 | connect( e, SIGNAL( currentFontChanged( const QFont & ) ), | 273 | connect( e, SIGNAL( currentFontChanged( const QFont & ) ), |
274 | this, SLOT( fontChanged( const QFont & ) ) ); | 274 | this, SLOT( fontChanged( const QFont & ) ) ); |
275 | connect( e, SIGNAL( currentColorChanged( const QColor & ) ), | 275 | connect( e, SIGNAL( currentColorChanged( const QColor & ) ), |
276 | this, SLOT( colorChanged( const QColor & ) ) ); | 276 | this, SLOT( colorChanged( const QColor & ) ) ); |
277 | connect( e, SIGNAL( currentAlignmentChanged( int ) ), | 277 | connect( e, SIGNAL( currentAlignmentChanged( int ) ), |
278 | this, SLOT( alignmentChanged( int ) ) ); | 278 | this, SLOT( alignmentChanged( int ) ) ); |
279 | } | 279 | } |
280 | 280 | ||
281 | void MainWindow::updateFontSizeCombo( const QFont &f ) | 281 | void MainWindow::updateFontSizeCombo( const QFont &f ) |
282 | { | 282 | { |
283 | comboSize->clear(); | 283 | comboSize->clear(); |
284 | FontDatabase fdb; | 284 | FontDatabase fdb; |
285 | QValueList<int> sizes = fdb.pointSizes( f.family() ); | 285 | QValueList<int> sizes = fdb.pointSizes( f.family() ); |
286 | QValueList<int>::Iterator it = sizes.begin(); | 286 | QValueList<int>::Iterator it = sizes.begin(); |
287 | for ( ; it != sizes.end(); ++it ) | 287 | for ( ; it != sizes.end(); ++it ) |
288 | comboSize->insertItem( QString::number( *it ) ); | 288 | comboSize->insertItem( QString::number( *it ) ); |
289 | } | 289 | } |
290 | 290 | ||
291 | void MainWindow::editUndo() | 291 | void MainWindow::editUndo() |
292 | { | 292 | { |
293 | if ( !currentEditor() ) | 293 | if ( !currentEditor() ) |
294 | return; | 294 | return; |
295 | currentEditor()->undo(); | 295 | currentEditor()->undo(); |
296 | } | 296 | } |
297 | 297 | ||
298 | void MainWindow::editRedo() | 298 | void MainWindow::editRedo() |
299 | { | 299 | { |
300 | if ( !currentEditor() ) | 300 | if ( !currentEditor() ) |
301 | return; | 301 | return; |
302 | currentEditor()->redo(); | 302 | currentEditor()->redo(); |
303 | } | 303 | } |
304 | 304 | ||
305 | void MainWindow::editCut() | 305 | void MainWindow::editCut() |
306 | { | 306 | { |
307 | if ( !currentEditor() ) | 307 | if ( !currentEditor() ) |
308 | return; | 308 | return; |
309 | currentEditor()->cut(); | 309 | currentEditor()->cut(); |
310 | } | 310 | } |
311 | 311 | ||
312 | void MainWindow::editCopy() | 312 | void MainWindow::editCopy() |
313 | { | 313 | { |
314 | if ( !currentEditor() ) | 314 | if ( !currentEditor() ) |
315 | return; | 315 | return; |
316 | currentEditor()->copy(); | 316 | currentEditor()->copy(); |
317 | } | 317 | } |
318 | 318 | ||
319 | void MainWindow::editPaste() | 319 | void MainWindow::editPaste() |
320 | { | 320 | { |
321 | if ( !currentEditor() ) | 321 | if ( !currentEditor() ) |
322 | return; | 322 | return; |
323 | currentEditor()->paste(); | 323 | currentEditor()->paste(); |
324 | } | 324 | } |
325 | 325 | ||
326 | void MainWindow::textBold() | 326 | void MainWindow::textBold() |
327 | { | 327 | { |
328 | if ( !currentEditor() ) | 328 | if ( !currentEditor() ) |
329 | return; | 329 | return; |
330 | currentEditor()->setBold( actionTextBold->isOn() ); | 330 | currentEditor()->setBold( actionTextBold->isOn() ); |
331 | } | 331 | } |
332 | 332 | ||
@@ -446,129 +446,129 @@ void MainWindow::fileRevert() | |||
446 | { | 446 | { |
447 | qDebug( "QMainWindow::fileRevert needs to be done" ); | 447 | qDebug( "QMainWindow::fileRevert needs to be done" ); |
448 | } | 448 | } |
449 | 449 | ||
450 | void MainWindow::fileNew() | 450 | void MainWindow::fileNew() |
451 | { | 451 | { |
452 | editor->setTextFormat( Qt::RichText ); | 452 | editor->setTextFormat( Qt::RichText ); |
453 | save(); | 453 | save(); |
454 | newFile(DocLnk()); | 454 | newFile(DocLnk()); |
455 | } | 455 | } |
456 | 456 | ||
457 | void MainWindow::insertTable() | 457 | void MainWindow::insertTable() |
458 | { | 458 | { |
459 | qDebug( "MainWindow::insertTable() needs to be done" ); | 459 | qDebug( "MainWindow::insertTable() needs to be done" ); |
460 | } | 460 | } |
461 | 461 | ||
462 | void MainWindow::newFile( const DocLnk &dl ) | 462 | void MainWindow::newFile( const DocLnk &dl ) |
463 | { | 463 | { |
464 | DocLnk nf = dl; | 464 | DocLnk nf = dl; |
465 | nf.setType( "text/html" ); | 465 | nf.setType( "text/html" ); |
466 | clear(); | 466 | clear(); |
467 | editorStack->raiseWidget( editor ); | 467 | editorStack->raiseWidget( editor ); |
468 | editor->viewport()->setFocus(); | 468 | editor->viewport()->setFocus(); |
469 | doc = new DocLnk( nf ); | 469 | doc = new DocLnk( nf ); |
470 | updateCaption(); | 470 | updateCaption(); |
471 | } | 471 | } |
472 | 472 | ||
473 | void MainWindow::openFile( const DocLnk &dl ) | 473 | void MainWindow::openFile( const DocLnk &dl ) |
474 | { | 474 | { |
475 | FileManager fm; | 475 | FileManager fm; |
476 | QString txt; | 476 | QString txt; |
477 | if ( !fm.loadFile( dl, txt ) ) | 477 | if ( !fm.loadFile( dl, txt ) ) |
478 | qDebug( "couldn't open file" ); | 478 | qDebug( "couldn't open file" ); |
479 | clear(); | 479 | clear(); |
480 | editorStack->raiseWidget( editor ); | 480 | editorStack->raiseWidget( editor ); |
481 | editor->viewport()->setFocus(); | 481 | editor->viewport()->setFocus(); |
482 | doc = new DocLnk( dl ); | 482 | doc = new DocLnk( dl ); |
483 | editor->setText( txt ); | 483 | editor->setText( txt ); |
484 | editor->setModified( FALSE ); | 484 | editor->setModified( FALSE ); |
485 | updateCaption(); | 485 | updateCaption(); |
486 | } | 486 | } |
487 | 487 | ||
488 | void MainWindow::showEditTools( void ) | 488 | void MainWindow::showEditTools( void ) |
489 | { | 489 | { |
490 | tbMenu->show(); | 490 | tbMenu->show(); |
491 | tbEdit->show(); | 491 | tbEdit->show(); |
492 | tbFont->show(); | 492 | tbFont->show(); |
493 | tbStyle->show(); | 493 | tbStyle->show(); |
494 | } | 494 | } |
495 | 495 | ||
496 | void MainWindow::hideEditTools( void ) | 496 | void MainWindow::hideEditTools( void ) |
497 | { | 497 | { |
498 | // let's reset the buttons... | 498 | // let's reset the buttons... |
499 | actionTextBold->setOn( FALSE ); | 499 | actionTextBold->setOn( FALSE ); |
500 | actionTextItalic->setOn( FALSE ); | 500 | actionTextItalic->setOn( FALSE ); |
501 | actionTextUnderline->setOn( FALSE ); | 501 | actionTextUnderline->setOn( FALSE ); |
502 | //comboFont->setCurrentText( QApplication::font().family() ); | 502 | //comboFont->setCurrentText( QApplication::font().family() ); |
503 | comboSize->lineEdit()->setText( QString::number(QApplication::font().pointSize() ) ); | 503 | comboSize->lineEdit()->setText( QString::number(QApplication::font().pointSize() ) ); |
504 | tbMenu->hide(); | 504 | tbMenu->hide(); |
505 | tbEdit->hide(); | 505 | tbEdit->hide(); |
506 | tbFont->hide(); | 506 | tbFont->hide(); |
507 | tbStyle->hide(); | 507 | tbStyle->hide(); |
508 | } | 508 | } |
509 | 509 | ||
510 | 510 | ||
511 | void MainWindow::save() | 511 | void MainWindow::save() |
512 | { | 512 | { |
513 | if ( !doc ) | 513 | if ( !doc ) |
514 | return; | 514 | return; |
515 | if ( !editor->isModified() ) | 515 | if ( !editor->isModified() ) |
516 | return; | 516 | return; |
517 | 517 | ||
518 | QString rt = editor->text(); | 518 | QString rt = editor->text(); |
519 | 519 | ||
520 | // quick hack to get around formatting... | 520 | // quick hack to get around formatting... |
521 | editor->setTextFormat( Qt::PlainText ); | 521 | editor->setTextFormat( Qt::PlainText ); |
522 | QString pt = editor->text(); | 522 | QString pt = editor->text(); |
523 | editor->setTextFormat( Qt::RichText ); | 523 | editor->setTextFormat( Qt::RichText ); |
524 | 524 | ||
525 | if ( doc->name().isEmpty() ) { | 525 | if ( doc->name().isEmpty() ) { |
526 | unsigned ispace = pt.find( ' ' ); | 526 | unsigned ispace = pt.find( ' ' ); |
527 | unsigned ienter = pt.find( '\n' ); | 527 | unsigned ienter = pt.find( '\n' ); |
528 | int i = (ispace < ienter) ? ispace : ienter; | 528 | int i = (ispace < ienter) ? ispace : ienter; |
529 | QString docname; | 529 | QString docname; |
530 | if ( i == -1 ) { | 530 | if ( i == -1 ) { |
531 | if ( pt.isEmpty() ) | 531 | if ( pt.isEmpty() ) |
532 | docname = "Empty Text"; | 532 | docname = "Empty Text"; |
533 | else | 533 | else |
534 | docname = pt; | 534 | docname = pt; |
535 | } else { | 535 | } else { |
536 | docname = pt.left( i ); | 536 | docname = pt.left( i ); |
537 | } | 537 | } |
538 | doc->setName(docname); | 538 | doc->setName(docname); |
539 | } | 539 | } |
540 | FileManager fm; | 540 | FileManager fm; |
541 | fm.saveFile( *doc, rt ); | 541 | fm.saveFile( *doc, rt ); |
542 | } | 542 | } |
543 | 543 | ||
544 | void MainWindow::clear() | 544 | void MainWindow::clear() |
545 | { | 545 | { |
546 | delete doc; | 546 | delete doc; |
547 | doc = 0; | 547 | doc = 0; |
548 | editor->clear(); | 548 | editor->clear(); |
549 | } | 549 | } |
550 | 550 | ||
551 | void MainWindow::updateCaption() | 551 | void MainWindow::updateCaption() |
552 | { | 552 | { |
553 | if ( !doc ) | 553 | if ( !doc ) |
554 | setCaption( tr("Rich Text Editor") ); | 554 | setCaption( tr("Rich Text Editor") ); |
555 | else { | 555 | else { |
556 | QString s = doc->name(); | 556 | QString s = doc->name(); |
557 | if ( s.isEmpty() ) | 557 | if ( s.isEmpty() ) |
558 | s = tr( "Unnamed" ); | 558 | s = tr( "Unnamed" ); |
559 | setCaption( s + " - " + tr("Rich Text Editor") ); | 559 | setCaption( s + " - " + tr("Rich Text Editor") ); |
560 | } | 560 | } |
561 | } | 561 | } |
562 | 562 | ||
563 | void MainWindow::closeEvent( QCloseEvent *e ) | 563 | void MainWindow::closeEvent( QCloseEvent *e ) |
564 | { | 564 | { |
565 | if ( editorStack->visibleWidget() == editor ) { | 565 | if ( editorStack->visibleWidget() == editor ) { |
566 | // call fileOpen instead, don't close it | 566 | // call fileOpen instead, don't close it |
567 | fileOpen(); | 567 | fileOpen(); |
568 | e->ignore(); | 568 | e->ignore(); |
569 | } else { | 569 | } else { |
570 | e->accept(); | 570 | e->accept(); |
571 | } | 571 | } |
572 | } | 572 | } |
573 | 573 | ||
574 | #include "mainwindow.moc" | 574 | #include "mainwindow.moc" |