-rw-r--r-- | noncore/apps/opie-write/mainwindow.cpp | 222 |
1 files changed, 113 insertions, 109 deletions
diff --git a/noncore/apps/opie-write/mainwindow.cpp b/noncore/apps/opie-write/mainwindow.cpp index ed95e83..bcafd16 100644 --- a/noncore/apps/opie-write/mainwindow.cpp +++ b/noncore/apps/opie-write/mainwindow.cpp | |||
@@ -23,6 +23,8 @@ | |||
23 | #include <qpe/fileselector.h> | 23 | #include <qpe/fileselector.h> |
24 | #include <qpe/applnk.h> | 24 | #include <qpe/applnk.h> |
25 | #include <qpe/resource.h> | 25 | #include <qpe/resource.h> |
26 | #include <qpe/fontdatabase.h> | ||
27 | |||
26 | //#include "qspellchecker.h" | 28 | //#include "qspellchecker.h" |
27 | #include "qtextedit.h" | 29 | #include "qtextedit.h" |
28 | #include <qaction.h> | 30 | #include <qaction.h> |
@@ -49,30 +51,30 @@ class ButtonMenu : public QToolButton | |||
49 | Q_OBJECT | 51 | Q_OBJECT |
50 | public: | 52 | public: |
51 | ButtonMenu( QWidget *parent, const char *name=0 ) | 53 | ButtonMenu( QWidget *parent, const char *name=0 ) |
52 | : QToolButton( parent, name ), current(0) | 54 | : QToolButton( parent, name ), current(0) |
53 | { | 55 | { |
54 | setPopup( new QPopupMenu( this ) ); | 56 | setPopup( new QPopupMenu( this ) ); |
55 | setPopupDelay( 1 ); | 57 | setPopupDelay( 1 ); |
56 | connect( popup(), SIGNAL(activated(int)), this, SLOT(selected(int)) ); | 58 | connect( popup(), SIGNAL(activated(int)), this, SLOT(selected(int)) ); |
57 | } | 59 | } |
58 | 60 | ||
59 | int insertItem(const QIconSet &icon, const QString &text, int id ) { | 61 | int insertItem(const QIconSet &icon, const QString &text, int id ) { |
60 | if ( !popup()->count() ) { | 62 | if ( !popup()->count() ) { |
61 | setIconSet( icon ); | 63 | setIconSet( icon ); |
62 | current = id; | 64 | current = id; |
63 | } | 65 | } |
64 | return popup()->insertItem( icon, text, id ); | 66 | return popup()->insertItem( icon, text, id ); |
65 | } | 67 | } |
66 | 68 | ||
67 | void setCurrentItem( int id ) { | 69 | void setCurrentItem( int id ) { |
68 | if ( id != current ) { | 70 | if ( id != current ) { |
69 | current = id; | 71 | current = id; |
70 | setIconSet( *popup()->iconSet( id ) ); | 72 | setIconSet( *popup()->iconSet( id ) ); |
71 | } | 73 | } |
72 | } | 74 | } |
73 | 75 | ||
74 | virtual QSize sizeHint() const { | 76 | virtual QSize sizeHint() const { |
75 | return QToolButton::sizeHint() + QSize( 4, 0 ); | 77 | return QToolButton::sizeHint() + QSize( 4, 0 ); |
76 | } | 78 | } |
77 | 79 | ||
78 | signals: | 80 | signals: |
@@ -80,16 +82,16 @@ signals: | |||
80 | 82 | ||
81 | protected slots: | 83 | protected slots: |
82 | void selected( int id ) { | 84 | void selected( int id ) { |
83 | current = id; | 85 | current = id; |
84 | setIconSet( *popup()->iconSet( id ) ); | 86 | setIconSet( *popup()->iconSet( id ) ); |
85 | emit activated( id ); | 87 | emit activated( id ); |
86 | } | 88 | } |
87 | 89 | ||
88 | protected: | 90 | protected: |
89 | virtual void drawButtonLabel( QPainter *p ) { | 91 | virtual void drawButtonLabel( QPainter *p ) { |
90 | p->translate( -4, 0 ); | 92 | p->translate( -4, 0 ); |
91 | QToolButton::drawButtonLabel( p ); | 93 | QToolButton::drawButtonLabel( p ); |
92 | p->translate( 4, 0 ); | 94 | p->translate( 4, 0 ); |
93 | } | 95 | } |
94 | 96 | ||
95 | private: | 97 | private: |
@@ -107,7 +109,7 @@ MainWindow::MainWindow( QWidget *parent, const char *name ) | |||
107 | editorStack = new QWidgetStack( this ); | 109 | editorStack = new QWidgetStack( this ); |
108 | 110 | ||
109 | fileSelector = new FileSelector( "text/html", | 111 | fileSelector = new FileSelector( "text/html", |
110 | editorStack, "fileselector" ); | 112 | editorStack, "fileselector" ); |
111 | 113 | ||
112 | 114 | ||
113 | fileSelector->setCloseVisible( FALSE ); | 115 | fileSelector->setCloseVisible( FALSE ); |
@@ -120,16 +122,16 @@ MainWindow::MainWindow( QWidget *parent, const char *name ) | |||
120 | setupActions(); | 122 | setupActions(); |
121 | 123 | ||
122 | QObject::connect( fileSelector, SIGNAL(closeMe()), | 124 | QObject::connect( fileSelector, SIGNAL(closeMe()), |
123 | this, SLOT(showEditTools()) ); | 125 | this, SLOT(showEditTools()) ); |
124 | QObject::connect( fileSelector, SIGNAL(fileSelected(const DocLnk &)), | 126 | QObject::connect( fileSelector, SIGNAL(fileSelected(const DocLnk &)), |
125 | this, SLOT(openFile(const DocLnk &)) ); | 127 | this, SLOT(openFile(const DocLnk &)) ); |
126 | QObject::connect( fileSelector, SIGNAL(newSelected(const DocLnk&)), | 128 | QObject::connect( fileSelector, SIGNAL(newSelected(const DocLnk&)), |
127 | this, SLOT(newFile(const DocLnk&)) ); | 129 | this, SLOT(newFile(const DocLnk&)) ); |
128 | 130 | ||
129 | if ( fileSelector->fileCount() < 1 ) | 131 | if ( fileSelector->fileCount() < 1 ) |
130 | fileNew(); | 132 | fileNew(); |
131 | else { | 133 | else { |
132 | fileOpen(); | 134 | fileOpen(); |
133 | } | 135 | } |
134 | doConnections( editor ); | 136 | doConnections( editor ); |
135 | 137 | ||
@@ -171,13 +173,13 @@ void MainWindow::setupActions() | |||
171 | a->addTo( file ); | 173 | a->addTo( file ); |
172 | 174 | ||
173 | a = new QAction( tr( "Undo" ), Resource::loadIconSet("opie-write/undo"), | 175 | a = new QAction( tr( "Undo" ), Resource::loadIconSet("opie-write/undo"), |
174 | QString::null, 0, this, "editUndo" ); | 176 | QString::null, 0, this, "editUndo" ); |
175 | connect( a, SIGNAL( activated() ), this, SLOT( editUndo() ) ); | 177 | connect( a, SIGNAL( activated() ), this, SLOT( editUndo() ) ); |
176 | connect( editor, SIGNAL(undoAvailable(bool)), a, SLOT(setEnabled(bool)) ); | 178 | connect( editor, SIGNAL(undoAvailable(bool)), a, SLOT(setEnabled(bool)) ); |
177 | a->addTo( tbEdit ); | 179 | a->addTo( tbEdit ); |
178 | a->addTo( edit ); | 180 | a->addTo( edit ); |
179 | a = new QAction( tr( "Redo" ), Resource::loadIconSet("opie-write/redo"), | 181 | a = new QAction( tr( "Redo" ), Resource::loadIconSet("opie-write/redo"), |
180 | QString::null, 0, this, "editRedo" ); | 182 | QString::null, 0, this, "editRedo" ); |
181 | connect( a, SIGNAL( activated() ), this, SLOT( editRedo() ) ); | 183 | connect( a, SIGNAL( activated() ), this, SLOT( editRedo() ) ); |
182 | connect( editor, SIGNAL(redoAvailable(bool)), a, SLOT(setEnabled(bool)) ); | 184 | connect( editor, SIGNAL(redoAvailable(bool)), a, SLOT(setEnabled(bool)) ); |
183 | a->addTo( tbEdit ); | 185 | a->addTo( tbEdit ); |
@@ -186,19 +188,19 @@ void MainWindow::setupActions() | |||
186 | edit->insertSeparator(); | 188 | edit->insertSeparator(); |
187 | 189 | ||
188 | a = new QAction( tr( "Copy" ), Resource::loadIconSet("copy"), | 190 | a = new QAction( tr( "Copy" ), Resource::loadIconSet("copy"), |
189 | QString::null, 0, this, "editCopy" ); | 191 | QString::null, 0, this, "editCopy" ); |
190 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); | 192 | connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); |
191 | connect( editor, SIGNAL(copyAvailable(bool)), a, SLOT(setEnabled(bool)) ); | 193 | connect( editor, SIGNAL(copyAvailable(bool)), a, SLOT(setEnabled(bool)) ); |
192 | a->addTo( tbEdit ); | 194 | a->addTo( tbEdit ); |
193 | a->addTo( edit ); | 195 | a->addTo( edit ); |
194 | a = new QAction( tr( "Cut" ), Resource::loadIconSet("cut"), | 196 | a = new QAction( tr( "Cut" ), Resource::loadIconSet("cut"), |
195 | QString::null, 0, this, "editCut" ); | 197 | QString::null, 0, this, "editCut" ); |
196 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); | 198 | connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); |
197 | connect( editor, SIGNAL(copyAvailable(bool)), a, SLOT(setEnabled(bool)) ); | 199 | connect( editor, SIGNAL(copyAvailable(bool)), a, SLOT(setEnabled(bool)) ); |
198 | a->addTo( tbEdit ); | 200 | a->addTo( tbEdit ); |
199 | a->addTo( edit ); | 201 | a->addTo( edit ); |
200 | a = new QAction( tr( "Paste" ), Resource::loadPixmap("paste"), | 202 | a = new QAction( tr( "Paste" ), Resource::loadPixmap("paste"), |
201 | QString::null, 0, this, "editPaste" ); | 203 | QString::null, 0, this, "editPaste" ); |
202 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); | 204 | connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); |
203 | a->addTo( tbEdit ); | 205 | a->addTo( tbEdit ); |
204 | a->addTo( edit ); | 206 | a->addTo( edit ); |
@@ -208,19 +210,21 @@ void MainWindow::setupActions() | |||
208 | tbFont->setHorizontalStretchable(TRUE); | 210 | tbFont->setHorizontalStretchable(TRUE); |
209 | 211 | ||
210 | comboFont = new QComboBox( FALSE, tbFont ); | 212 | comboFont = new QComboBox( FALSE, tbFont ); |
211 | QFontDatabase db; | 213 | FontDatabase db; |
214 | QStringList f= db.families(); | ||
212 | comboFont->insertStringList( db.families() ); | 215 | comboFont->insertStringList( db.families() ); |
213 | connect( comboFont, SIGNAL( activated( const QString & ) ), | 216 | connect( comboFont, SIGNAL( activated( const QString & ) ), |
214 | this, SLOT( textFamily( const QString & ) ) ); | 217 | this, SLOT( textFamily( const QString & ) ) ); |
215 | 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); | ||
216 | 220 | ||
217 | comboSize = new QComboBox( TRUE, tbFont ); | 221 | comboSize = new QComboBox( TRUE, tbFont ); |
218 | QValueList<int> sizes = db.standardSizes(); | 222 | QValueList<int> sizes = db.standardSizes(); |
219 | QValueList<int>::Iterator it = sizes.begin(); | 223 | QValueList<int>::Iterator it = sizes.begin(); |
220 | for ( ; it != sizes.end(); ++it ) | 224 | for ( ; it != sizes.end(); ++it ) |
221 | comboSize->insertItem( QString::number( *it ) ); | 225 | comboSize->insertItem( QString::number( *it ) ); |
222 | connect( comboSize, SIGNAL( activated( const QString & ) ), | 226 | connect( comboSize, SIGNAL( activated( const QString & ) ), |
223 | this, SLOT( textSize( const QString & ) ) ); | 227 | this, SLOT( textSize( const QString & ) ) ); |
224 | comboSize->lineEdit()->setText( QString::number( QApplication::font().pointSize() ) ); | 228 | comboSize->lineEdit()->setText( QString::number( QApplication::font().pointSize() ) ); |
225 | comboSize->setFixedWidth( 38 ); | 229 | comboSize->setFixedWidth( 38 ); |
226 | 230 | ||
@@ -228,26 +232,26 @@ void MainWindow::setupActions() | |||
228 | tbStyle->setLabel( "Style Actions" ); | 232 | tbStyle->setLabel( "Style Actions" ); |
229 | 233 | ||
230 | actionTextBold = new QAction( tr( "Bold" ), | 234 | actionTextBold = new QAction( tr( "Bold" ), |
231 | Resource::loadPixmap("bold"), | 235 | Resource::loadPixmap("bold"), |
232 | QString::null, CTRL + Key_B, | 236 | QString::null, CTRL + Key_B, |
233 | this, "textBold" ); | 237 | this, "textBold" ); |
234 | connect( actionTextBold, SIGNAL( activated() ), this, SLOT( textBold() ) ); | 238 | connect( actionTextBold, SIGNAL( activated() ), this, SLOT( textBold() ) ); |
235 | actionTextBold->addTo( tbStyle ); | 239 | actionTextBold->addTo( tbStyle ); |
236 | actionTextBold->setToggleAction( TRUE ); | 240 | actionTextBold->setToggleAction( TRUE ); |
237 | actionTextItalic = new QAction( tr( "Italic" ), | 241 | actionTextItalic = new QAction( tr( "Italic" ), |
238 | Resource::loadPixmap("italic"), | 242 | Resource::loadPixmap("italic"), |
239 | tr( "&Italic" ), CTRL + Key_I, | 243 | tr( "&Italic" ), CTRL + Key_I, |
240 | this, "textItalic" ); | 244 | this, "textItalic" ); |
241 | connect( actionTextItalic, SIGNAL( activated() ), this, | 245 | connect( actionTextItalic, SIGNAL( activated() ), this, |
242 | SLOT( textItalic() ) ); | 246 | SLOT( textItalic() ) ); |
243 | actionTextItalic->addTo( tbStyle ); | 247 | actionTextItalic->addTo( tbStyle ); |
244 | actionTextItalic->setToggleAction( TRUE ); | 248 | actionTextItalic->setToggleAction( TRUE ); |
245 | actionTextUnderline = new QAction( tr( "Underline" ), | 249 | actionTextUnderline = new QAction( tr( "Underline" ), |
246 | Resource::loadPixmap("underline"), | 250 | Resource::loadPixmap("underline"), |
247 | tr( "&Underline" ), CTRL + Key_U, | 251 | tr( "&Underline" ), CTRL + Key_U, |
248 | this, "textUnderline" ); | 252 | this, "textUnderline" ); |
249 | connect( actionTextUnderline, SIGNAL( activated() ), | 253 | connect( actionTextUnderline, SIGNAL( activated() ), |
250 | this, SLOT( textUnderline() ) ); | 254 | this, SLOT( textUnderline() ) ); |
251 | actionTextUnderline->addTo( tbStyle ); | 255 | actionTextUnderline->addTo( tbStyle ); |
252 | actionTextUnderline->setToggleAction( TRUE ); | 256 | actionTextUnderline->setToggleAction( TRUE ); |
253 | 257 | ||
@@ -261,89 +265,89 @@ void MainWindow::setupActions() | |||
261 | 265 | ||
262 | Qt3::QTextEdit *MainWindow::currentEditor() const | 266 | Qt3::QTextEdit *MainWindow::currentEditor() const |
263 | { | 267 | { |
264 | return editor; | 268 | return editor; |
265 | } | 269 | } |
266 | 270 | ||
267 | void MainWindow::doConnections( Qt3::QTextEdit *e ) | 271 | void MainWindow::doConnections( Qt3::QTextEdit *e ) |
268 | { | 272 | { |
269 | connect( e, SIGNAL( currentFontChanged( const QFont & ) ), | 273 | connect( e, SIGNAL( currentFontChanged( const QFont & ) ), |
270 | this, SLOT( fontChanged( const QFont & ) ) ); | 274 | this, SLOT( fontChanged( const QFont & ) ) ); |
271 | connect( e, SIGNAL( currentColorChanged( const QColor & ) ), | 275 | connect( e, SIGNAL( currentColorChanged( const QColor & ) ), |
272 | this, SLOT( colorChanged( const QColor & ) ) ); | 276 | this, SLOT( colorChanged( const QColor & ) ) ); |
273 | connect( e, SIGNAL( currentAlignmentChanged( int ) ), | 277 | connect( e, SIGNAL( currentAlignmentChanged( int ) ), |
274 | this, SLOT( alignmentChanged( int ) ) ); | 278 | this, SLOT( alignmentChanged( int ) ) ); |
275 | } | 279 | } |
276 | 280 | ||
277 | void MainWindow::updateFontSizeCombo( const QFont &f ) | 281 | void MainWindow::updateFontSizeCombo( const QFont &f ) |
278 | { | 282 | { |
279 | comboSize->clear(); | 283 | comboSize->clear(); |
280 | QFontDatabase fdb; | 284 | FontDatabase fdb; |
281 | QValueList<int> sizes = fdb.pointSizes( f.family() ); | 285 | QValueList<int> sizes = fdb.pointSizes( f.family() ); |
282 | QValueList<int>::Iterator it = sizes.begin(); | 286 | QValueList<int>::Iterator it = sizes.begin(); |
283 | for ( ; it != sizes.end(); ++it ) | 287 | for ( ; it != sizes.end(); ++it ) |
284 | comboSize->insertItem( QString::number( *it ) ); | 288 | comboSize->insertItem( QString::number( *it ) ); |
285 | } | 289 | } |
286 | 290 | ||
287 | void MainWindow::editUndo() | 291 | void MainWindow::editUndo() |
288 | { | 292 | { |
289 | if ( !currentEditor() ) | 293 | if ( !currentEditor() ) |
290 | return; | 294 | return; |
291 | currentEditor()->undo(); | 295 | currentEditor()->undo(); |
292 | } | 296 | } |
293 | 297 | ||
294 | void MainWindow::editRedo() | 298 | void MainWindow::editRedo() |
295 | { | 299 | { |
296 | if ( !currentEditor() ) | 300 | if ( !currentEditor() ) |
297 | return; | 301 | return; |
298 | currentEditor()->redo(); | 302 | currentEditor()->redo(); |
299 | } | 303 | } |
300 | 304 | ||
301 | void MainWindow::editCut() | 305 | void MainWindow::editCut() |
302 | { | 306 | { |
303 | if ( !currentEditor() ) | 307 | if ( !currentEditor() ) |
304 | return; | 308 | return; |
305 | currentEditor()->cut(); | 309 | currentEditor()->cut(); |
306 | } | 310 | } |
307 | 311 | ||
308 | void MainWindow::editCopy() | 312 | void MainWindow::editCopy() |
309 | { | 313 | { |
310 | if ( !currentEditor() ) | 314 | if ( !currentEditor() ) |
311 | return; | 315 | return; |
312 | currentEditor()->copy(); | 316 | currentEditor()->copy(); |
313 | } | 317 | } |
314 | 318 | ||
315 | void MainWindow::editPaste() | 319 | void MainWindow::editPaste() |
316 | { | 320 | { |
317 | if ( !currentEditor() ) | 321 | if ( !currentEditor() ) |
318 | return; | 322 | return; |
319 | currentEditor()->paste(); | 323 | currentEditor()->paste(); |
320 | } | 324 | } |
321 | 325 | ||
322 | void MainWindow::textBold() | 326 | void MainWindow::textBold() |
323 | { | 327 | { |
324 | if ( !currentEditor() ) | 328 | if ( !currentEditor() ) |
325 | return; | 329 | return; |
326 | currentEditor()->setBold( actionTextBold->isOn() ); | 330 | currentEditor()->setBold( actionTextBold->isOn() ); |
327 | } | 331 | } |
328 | 332 | ||
329 | void MainWindow::textUnderline() | 333 | void MainWindow::textUnderline() |
330 | { | 334 | { |
331 | if ( !currentEditor() ) | 335 | if ( !currentEditor() ) |
332 | return; | 336 | return; |
333 | currentEditor()->setUnderline( actionTextUnderline->isOn() ); | 337 | currentEditor()->setUnderline( actionTextUnderline->isOn() ); |
334 | } | 338 | } |
335 | 339 | ||
336 | void MainWindow::textItalic() | 340 | void MainWindow::textItalic() |
337 | { | 341 | { |
338 | if ( !currentEditor() ) | 342 | if ( !currentEditor() ) |
339 | return; | 343 | return; |
340 | currentEditor()->setItalic( actionTextItalic->isOn() ); | 344 | currentEditor()->setItalic( actionTextItalic->isOn() ); |
341 | } | 345 | } |
342 | 346 | ||
343 | void MainWindow::textFamily( const QString &f ) | 347 | void MainWindow::textFamily( const QString &f ) |
344 | { | 348 | { |
345 | if ( !currentEditor() ) | 349 | if ( !currentEditor() ) |
346 | return; | 350 | return; |
347 | currentEditor()->setFamily( f ); | 351 | currentEditor()->setFamily( f ); |
348 | currentEditor()->viewport()->setFocus(); | 352 | currentEditor()->viewport()->setFocus(); |
349 | } | 353 | } |
@@ -351,7 +355,7 @@ void MainWindow::textFamily( const QString &f ) | |||
351 | void MainWindow::textSize( const QString &p ) | 355 | void MainWindow::textSize( const QString &p ) |
352 | { | 356 | { |
353 | if ( !currentEditor() ) | 357 | if ( !currentEditor() ) |
354 | return; | 358 | return; |
355 | currentEditor()->setPointSize( p.toInt() ); | 359 | currentEditor()->setPointSize( p.toInt() ); |
356 | currentEditor()->viewport()->setFocus(); | 360 | currentEditor()->viewport()->setFocus(); |
357 | } | 361 | } |
@@ -359,35 +363,35 @@ void MainWindow::textSize( const QString &p ) | |||
359 | void MainWindow::textStyle( int i ) | 363 | void MainWindow::textStyle( int i ) |
360 | { | 364 | { |
361 | if ( !currentEditor() ) | 365 | if ( !currentEditor() ) |
362 | return; | 366 | return; |
363 | if ( i == 0 ) | 367 | if ( i == 0 ) |
364 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayBlock, | 368 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayBlock, |
365 | Qt3::QStyleSheetItem::ListDisc ); | 369 | Qt3::QStyleSheetItem::ListDisc ); |
366 | else if ( i == 1 ) | 370 | else if ( i == 1 ) |
367 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, | 371 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, |
368 | Qt3::QStyleSheetItem::ListDisc ); | 372 | Qt3::QStyleSheetItem::ListDisc ); |
369 | else if ( i == 2 ) | 373 | else if ( i == 2 ) |
370 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, | 374 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, |
371 | Qt3::QStyleSheetItem::ListCircle ); | 375 | Qt3::QStyleSheetItem::ListCircle ); |
372 | else if ( i == 3 ) | 376 | else if ( i == 3 ) |
373 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, | 377 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, |
374 | Qt3::QStyleSheetItem::ListSquare ); | 378 | Qt3::QStyleSheetItem::ListSquare ); |
375 | else if ( i == 4 ) | 379 | else if ( i == 4 ) |
376 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, | 380 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, |
377 | Qt3::QStyleSheetItem::ListDecimal ); | 381 | Qt3::QStyleSheetItem::ListDecimal ); |
378 | else if ( i == 5 ) | 382 | else if ( i == 5 ) |
379 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, | 383 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, |
380 | Qt3::QStyleSheetItem::ListLowerAlpha ); | 384 | Qt3::QStyleSheetItem::ListLowerAlpha ); |
381 | else if ( i == 6 ) | 385 | else if ( i == 6 ) |
382 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, | 386 | currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, |
383 | Qt3::QStyleSheetItem::ListUpperAlpha ); | 387 | Qt3::QStyleSheetItem::ListUpperAlpha ); |
384 | currentEditor()->viewport()->setFocus(); | 388 | currentEditor()->viewport()->setFocus(); |
385 | } | 389 | } |
386 | 390 | ||
387 | void MainWindow::textAlign( int a ) | 391 | void MainWindow::textAlign( int a ) |
388 | { | 392 | { |
389 | if ( !currentEditor() ) | 393 | if ( !currentEditor() ) |
390 | return; | 394 | return; |
391 | editor->setAlignment( a ); | 395 | editor->setAlignment( a ); |
392 | } | 396 | } |
393 | 397 | ||
@@ -408,20 +412,20 @@ void MainWindow::colorChanged( const QColor & ) | |||
408 | void MainWindow::alignmentChanged( int a ) | 412 | void MainWindow::alignmentChanged( int a ) |
409 | { | 413 | { |
410 | if ( ( a == Qt3::AlignAuto ) || ( a & AlignLeft )) { | 414 | if ( ( a == Qt3::AlignAuto ) || ( a & AlignLeft )) { |
411 | alignMenu->setCurrentItem(AlignLeft); | 415 | alignMenu->setCurrentItem(AlignLeft); |
412 | } else if ( ( a & AlignCenter ) ) { | 416 | } else if ( ( a & AlignCenter ) ) { |
413 | alignMenu->setCurrentItem(AlignCenter); | 417 | alignMenu->setCurrentItem(AlignCenter); |
414 | } else if ( ( a & AlignRight ) ) { | 418 | } else if ( ( a & AlignRight ) ) { |
415 | alignMenu->setCurrentItem(AlignRight); | 419 | alignMenu->setCurrentItem(AlignRight); |
416 | } else if ( ( a & Qt3::AlignJustify ) ) { | 420 | } else if ( ( a & Qt3::AlignJustify ) ) { |
417 | alignMenu->setCurrentItem(Qt3::AlignJustify); | 421 | alignMenu->setCurrentItem(Qt3::AlignJustify); |
418 | } | 422 | } |
419 | } | 423 | } |
420 | 424 | ||
421 | void MainWindow::editorChanged( QWidget * ) | 425 | void MainWindow::editorChanged( QWidget * ) |
422 | { | 426 | { |
423 | if ( !currentEditor() ) | 427 | if ( !currentEditor() ) |
424 | return; | 428 | return; |
425 | fontChanged( currentEditor()->font() ); | 429 | fontChanged( currentEditor()->font() ); |
426 | colorChanged( currentEditor()->color() ); | 430 | colorChanged( currentEditor()->color() ); |
427 | alignmentChanged( currentEditor()->alignment() ); | 431 | alignmentChanged( currentEditor()->alignment() ); |
@@ -471,7 +475,7 @@ void MainWindow::openFile( const DocLnk &dl ) | |||
471 | FileManager fm; | 475 | FileManager fm; |
472 | QString txt; | 476 | QString txt; |
473 | if ( !fm.loadFile( dl, txt ) ) | 477 | if ( !fm.loadFile( dl, txt ) ) |
474 | qDebug( "couldn't open file" ); | 478 | qDebug( "couldn't open file" ); |
475 | clear(); | 479 | clear(); |
476 | editorStack->raiseWidget( editor ); | 480 | editorStack->raiseWidget( editor ); |
477 | editor->viewport()->setFocus(); | 481 | editor->viewport()->setFocus(); |
@@ -503,13 +507,13 @@ void MainWindow::hideEditTools( void ) | |||
503 | tbStyle->hide(); | 507 | tbStyle->hide(); |
504 | } | 508 | } |
505 | 509 | ||
506 | 510 | ||
507 | void MainWindow::save() | 511 | void MainWindow::save() |
508 | { | 512 | { |
509 | if ( !doc ) | 513 | if ( !doc ) |
510 | return; | 514 | return; |
511 | if ( !editor->isModified() ) | 515 | if ( !editor->isModified() ) |
512 | return; | 516 | return; |
513 | 517 | ||
514 | QString rt = editor->text(); | 518 | QString rt = editor->text(); |
515 | 519 | ||
@@ -519,19 +523,19 @@ void MainWindow::save() | |||
519 | editor->setTextFormat( Qt::RichText ); | 523 | editor->setTextFormat( Qt::RichText ); |
520 | 524 | ||
521 | if ( doc->name().isEmpty() ) { | 525 | if ( doc->name().isEmpty() ) { |
522 | unsigned ispace = pt.find( ' ' ); | 526 | unsigned ispace = pt.find( ' ' ); |
523 | unsigned ienter = pt.find( '\n' ); | 527 | unsigned ienter = pt.find( '\n' ); |
524 | int i = (ispace < ienter) ? ispace : ienter; | 528 | int i = (ispace < ienter) ? ispace : ienter; |
525 | QString docname; | 529 | QString docname; |
526 | if ( i == -1 ) { | 530 | if ( i == -1 ) { |
527 | if ( pt.isEmpty() ) | 531 | if ( pt.isEmpty() ) |
528 | docname = "Empty Text"; | 532 | docname = "Empty Text"; |
529 | else | 533 | else |
530 | docname = pt; | 534 | docname = pt; |
531 | } else { | 535 | } else { |
532 | docname = pt.left( i ); | 536 | docname = pt.left( i ); |
533 | } | 537 | } |
534 | doc->setName(docname); | 538 | doc->setName(docname); |
535 | } | 539 | } |
536 | FileManager fm; | 540 | FileManager fm; |
537 | fm.saveFile( *doc, rt ); | 541 | fm.saveFile( *doc, rt ); |
@@ -547,23 +551,23 @@ void MainWindow::clear() | |||
547 | void MainWindow::updateCaption() | 551 | void MainWindow::updateCaption() |
548 | { | 552 | { |
549 | if ( !doc ) | 553 | if ( !doc ) |
550 | setCaption( tr("Rich Text Editor") ); | 554 | setCaption( tr("Rich Text Editor") ); |
551 | else { | 555 | else { |
552 | QString s = doc->name(); | 556 | QString s = doc->name(); |
553 | if ( s.isEmpty() ) | 557 | if ( s.isEmpty() ) |
554 | s = tr( "Unnamed" ); | 558 | s = tr( "Unnamed" ); |
555 | setCaption( s + " - " + tr("Rich Text Editor") ); | 559 | setCaption( s + " - " + tr("Rich Text Editor") ); |
556 | } | 560 | } |
557 | } | 561 | } |
558 | 562 | ||
559 | void MainWindow::closeEvent( QCloseEvent *e ) | 563 | void MainWindow::closeEvent( QCloseEvent *e ) |
560 | { | 564 | { |
561 | if ( editorStack->visibleWidget() == editor ) { | 565 | if ( editorStack->visibleWidget() == editor ) { |
562 | // call fileOpen instead, don't close it | 566 | // call fileOpen instead, don't close it |
563 | fileOpen(); | 567 | fileOpen(); |
564 | e->ignore(); | 568 | e->ignore(); |
565 | } else { | 569 | } else { |
566 | e->accept(); | 570 | e->accept(); |
567 | } | 571 | } |
568 | } | 572 | } |
569 | 573 | ||