summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-write/mainwindow.cpp49
1 files changed, 27 insertions, 22 deletions
diff --git a/noncore/apps/opie-write/mainwindow.cpp b/noncore/apps/opie-write/mainwindow.cpp
index aa03060..296a1b0 100644
--- a/noncore/apps/opie-write/mainwindow.cpp
+++ b/noncore/apps/opie-write/mainwindow.cpp
@@ -1,522 +1,527 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** Licensees holding valid Qtopia Developer license may use this 6** Licensees holding valid Qtopia Developer license may use this
7** file in accordance with the Qtopia Developer License Agreement 7** file in accordance with the Qtopia Developer License Agreement
8** provided with the Software. 8** provided with the Software.
9** 9**
10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING 10** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
11** THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 11** THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
12** PURPOSE. 12** PURPOSE.
13** 13**
14** email sales@trolltech.com for information about Qtopia License 14** email sales@trolltech.com for information about Qtopia License
15** Agreements. 15** Agreements.
16** 16**
17** Contact info@trolltech.com if any conditions of this licensing are 17** Contact info@trolltech.com if any conditions of this licensing are
18** not clear to you. 18** not clear to you.
19** 19**
20**********************************************************************/ 20**********************************************************************/
21 21
22#include "mainwindow.h" 22#include "mainwindow.h"
23 23
24/* OPIE */ 24/* OPIE */
25#include <opie2/odebug.h> 25#include <opie2/odebug.h>
26#include <opie2/oresource.h>
26#include <qpe/fileselector.h> 27#include <qpe/fileselector.h>
27#include <qpe/applnk.h> 28#include <qpe/applnk.h>
28#include <qpe/resource.h>
29#include <qpe/fontdatabase.h> 29#include <qpe/fontdatabase.h>
30using namespace Opie::Core; 30using namespace Opie::Core;
31 31
32/* QT */ 32/* QT */
33#include "qtextedit.h" 33#include "qtextedit.h"
34#include <qaction.h> 34#include <qaction.h>
35#include <qtoolbar.h> 35#include <qtoolbar.h>
36#include <qtoolbutton.h> 36#include <qtoolbutton.h>
37#include <qtabwidget.h> 37#include <qtabwidget.h>
38#include <qapplication.h> 38#include <qapplication.h>
39#include <qfontdatabase.h> 39#include <qfontdatabase.h>
40#include <qcombobox.h> 40#include <qcombobox.h>
41#include <qlineedit.h> 41#include <qlineedit.h>
42#include <qfileinfo.h> 42#include <qfileinfo.h>
43#include <qfile.h> 43#include <qfile.h>
44#include <qfiledialog.h> 44#include <qfiledialog.h>
45#include <qprinter.h> 45#include <qprinter.h>
46#include <qpaintdevicemetrics.h> 46#include <qpaintdevicemetrics.h>
47#include <qmenubar.h> 47#include <qmenubar.h>
48#include <qpopupmenu.h> 48#include <qpopupmenu.h>
49#include <qcolordialog.h> 49#include <qcolordialog.h>
50#include <qpainter.h> 50#include <qpainter.h>
51#include <qstyle.h> 51#include <qstyle.h>
52 52
53class ButtonMenu : public QToolButton 53class ButtonMenu : public QToolButton
54{ 54{
55 Q_OBJECT 55 Q_OBJECT
56public: 56public:
57 ButtonMenu( QWidget *parent, const char *name=0 ) 57 ButtonMenu( QWidget *parent, const char *name=0 )
58 : QToolButton( parent, name ), current(0) 58 : QToolButton( parent, name ), current(0)
59 { 59 {
60 setPopup( new QPopupMenu( this ) ); 60 setPopup( new QPopupMenu( this ) );
61 setPopupDelay( 1 ); 61 setPopupDelay( 1 );
62 connect( popup(), SIGNAL(activated(int)), this, SLOT(selected(int)) ); 62 connect( popup(), SIGNAL(activated(int)), this, SLOT(selected(int)) );
63 } 63 }
64 64
65 int insertItem(const QIconSet &icon, const QString &text, int id ) { 65 int insertItem(const QIconSet &icon, const QString &text, int id ) {
66 if ( !popup()->count() ) { 66 if ( !popup()->count() ) {
67 setIconSet( icon ); 67 setIconSet( icon );
68 current = id; 68 current = id;
69 } 69 }
70 return popup()->insertItem( icon, text, id ); 70 return popup()->insertItem( icon, text, id );
71 } 71 }
72 72
73 void setCurrentItem( int id ) { 73 void setCurrentItem( int id ) {
74 if ( id != current ) { 74 if ( id != current ) {
75 current = id; 75 current = id;
76 setIconSet( *popup()->iconSet( id ) ); 76 setIconSet( *popup()->iconSet( id ) );
77 } 77 }
78 } 78 }
79 79
80 virtual QSize sizeHint() const { 80 virtual QSize sizeHint() const {
81 return QToolButton::sizeHint() + QSize( 4, 0 ); 81 return QToolButton::sizeHint() + QSize( 4, 0 );
82 } 82 }
83 83
84signals: 84signals:
85 void activated( int id ); 85 void activated( int id );
86 86
87protected slots: 87protected slots:
88 void selected( int id ) { 88 void selected( int id ) {
89 current = id; 89 current = id;
90 setIconSet( *popup()->iconSet( id ) ); 90 setIconSet( *popup()->iconSet( id ) );
91 emit activated( id ); 91 emit activated( id );
92 } 92 }
93 93
94protected: 94protected:
95 virtual void drawButtonLabel( QPainter *p ) { 95 virtual void drawButtonLabel( QPainter *p ) {
96 p->translate( -4, 0 ); 96 p->translate( -4, 0 );
97 QToolButton::drawButtonLabel( p ); 97 QToolButton::drawButtonLabel( p );
98 p->translate( 4, 0 ); 98 p->translate( 4, 0 );
99 } 99 }
100 100
101private: 101private:
102 int current; 102 int current;
103}; 103};
104 104
105//=========================================================================== 105//===========================================================================
106 106
107MainWindow::MainWindow( QWidget *parent, const char *name, WFlags fl ) 107MainWindow::MainWindow( QWidget *parent, const char *name, WFlags fl )
108 : QMainWindow( parent, name, fl ), 108 : QMainWindow( parent, name, fl ),
109 doc( 0 ) 109 doc( 0 )
110{ 110{
111 setRightJustification(TRUE); 111 setRightJustification(TRUE);
112 112
113 editorStack = new QWidgetStack( this ); 113 editorStack = new QWidgetStack( this );
114 114
115 fileSelector = new FileSelector( "text/html", 115 fileSelector = new FileSelector( "text/html",
116 editorStack, "fileselector" ); 116 editorStack, "fileselector" );
117 117
118 118
119 fileSelector->setCloseVisible( FALSE ); 119 fileSelector->setCloseVisible( FALSE );
120 editorStack->addWidget( fileSelector, 0 ); 120 editorStack->addWidget( fileSelector, 0 );
121 121
122 editor = new Qt3::QTextEdit( editorStack ); 122 editor = new Qt3::QTextEdit( editorStack );
123 editor->setTextFormat( Qt::RichText ); 123 editor->setTextFormat( Qt::RichText );
124 editorStack->addWidget( editor, 1 ); 124 editorStack->addWidget( editor, 1 );
125 125
126 setupActions(); 126 setupActions();
127 127
128 QObject::connect( fileSelector, SIGNAL(closeMe()), 128 QObject::connect( fileSelector, SIGNAL(closeMe()),
129 this, SLOT(showEditTools()) ); 129 this, SLOT(showEditTools()) );
130 QObject::connect( fileSelector, SIGNAL(fileSelected(const DocLnk&)), 130 QObject::connect( fileSelector, SIGNAL(fileSelected(const DocLnk&)),
131 this, SLOT(openFile(const DocLnk&)) ); 131 this, SLOT(openFile(const DocLnk&)) );
132 QObject::connect( fileSelector, SIGNAL(newSelected(const DocLnk&)), 132 QObject::connect( fileSelector, SIGNAL(newSelected(const DocLnk&)),
133 this, SLOT(newFile(const DocLnk&)) ); 133 this, SLOT(newFile(const DocLnk&)) );
134 134
135 if ( fileSelector->fileCount() < 1 ) 135 if ( fileSelector->fileCount() < 1 )
136 fileNew(); 136 fileNew();
137 else { 137 else {
138 fileOpen(); 138 fileOpen();
139 } 139 }
140 doConnections( editor ); 140 doConnections( editor );
141 141
142 setCentralWidget( editorStack ); 142 setCentralWidget( editorStack );
143} 143}
144 144
145MainWindow::~MainWindow() 145MainWindow::~MainWindow()
146{ 146{
147 save(); 147 save();
148} 148}
149 149
150void MainWindow::setupActions() 150void MainWindow::setupActions()
151{ 151{
152 setToolBarsMovable(false); 152 setToolBarsMovable(false);
153 153
154 tbMenu = new QToolBar( this ); 154 tbMenu = new QToolBar( this );
155 tbMenu->setHorizontalStretchable( TRUE ); 155 tbMenu->setHorizontalStretchable( TRUE );
156 156
157 QMenuBar *menu = new QMenuBar( tbMenu ); 157 QMenuBar *menu = new QMenuBar( tbMenu );
158 158
159 tbEdit = new QToolBar( this ); 159 tbEdit = new QToolBar( this );
160 160
161 QPopupMenu *file = new QPopupMenu( this ); 161 QPopupMenu *file = new QPopupMenu( this );
162 menu->insertItem( tr("File"), file ); 162 menu->insertItem( tr("File"), file );
163 163
164 QPopupMenu *edit = new QPopupMenu( this ); 164 QPopupMenu *edit = new QPopupMenu( this );
165 menu->insertItem( tr("Edit"), edit ); 165 menu->insertItem( tr("Edit"), edit );
166 166
167 // ### perhaps these shortcut keys should have some 167 // ### perhaps these shortcut keys should have some
168 // IPaq keys defined??? 168 // IPaq keys defined???
169 QAction *a; 169 QAction *a;
170 170
171 a = new QAction( tr( "New" ), Resource::loadPixmap("new"), QString::null, 0, this, 0 ); 171 a = new QAction( tr( "New" ), Opie::Core::OResource::loadPixmap("new", Opie::Core::OResource::SmallIcon),
172 QString::null, 0, this, 0 );
172 connect( a, SIGNAL(activated()), this, SLOT(fileNew()) ); 173 connect( a, SIGNAL(activated()), this, SLOT(fileNew()) );
173 a->addTo( file ); 174 a->addTo( file );
174 175
175 a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 ); 176 a = new QAction( tr( "Open" ), Opie::Core::OResource::loadPixmap( "fileopen", Opie::Core::OResource::SmallIcon ),
177 QString::null, 0, this, 0 );
176 connect( a, SIGNAL(activated()), this, SLOT(fileOpen()) ); 178 connect( a, SIGNAL(activated()), this, SLOT(fileOpen()) );
177 a->addTo( file ); 179 a->addTo( file );
178 180
179 a = new QAction( tr( "Undo" ), Resource::loadIconSet("undo"), 181 a = new QAction( tr( "Undo" ), Opie::Core::OResource::loadPixmap("undo", Opie::Core::OResource::SmallIcon),
180 QString::null, 0, this, "editUndo" ); 182 QString::null, 0, this, "editUndo" );
181 connect( a, SIGNAL( activated() ), this, SLOT( editUndo() ) ); 183 connect( a, SIGNAL( activated() ), this, SLOT( editUndo() ) );
182 connect( editor, SIGNAL(undoAvailable(bool)), a, SLOT(setEnabled(bool)) ); 184 connect( editor, SIGNAL(undoAvailable(bool)), a, SLOT(setEnabled(bool)) );
183 a->addTo( tbEdit ); 185 a->addTo( tbEdit );
184 a->addTo( edit ); 186 a->addTo( edit );
185 a = new QAction( tr( "Redo" ), Resource::loadIconSet("redo"), 187 a = new QAction( tr( "Redo" ), Opie::Core::OResource::loadPixmap("redo", Opie::Core::OResource::SmallIcon),
186 QString::null, 0, this, "editRedo" ); 188 QString::null, 0, this, "editRedo" );
187 connect( a, SIGNAL( activated() ), this, SLOT( editRedo() ) ); 189 connect( a, SIGNAL( activated() ), this, SLOT( editRedo() ) );
188 connect( editor, SIGNAL(redoAvailable(bool)), a, SLOT(setEnabled(bool)) ); 190 connect( editor, SIGNAL(redoAvailable(bool)), a, SLOT(setEnabled(bool)) );
189 a->addTo( tbEdit ); 191 a->addTo( tbEdit );
190 a->addTo( edit ); 192 a->addTo( edit );
191 193
192 edit->insertSeparator(); 194 edit->insertSeparator();
193 195
194 a = new QAction( tr( "Copy" ), Resource::loadIconSet("copy"), 196 a = new QAction( tr( "Copy" ), Opie::Core::OResource::loadPixmap("copy", Opie::Core::OResource::SmallIcon ),
195 QString::null, 0, this, "editCopy" ); 197 QString::null, 0, this, "editCopy" );
196 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) ); 198 connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
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( "Cut" ), Resource::loadIconSet("cut"), 202 a = new QAction( tr( "Cut" ), Opie::Core::OResource::loadPixmap("cut", Opie::Core::OResource::SmallIcon ),
201 QString::null, 0, this, "editCut" ); 203 QString::null, 0, this, "editCut" );
202 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) ); 204 connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
203 connect( editor, SIGNAL(copyAvailable(bool)), a, SLOT(setEnabled(bool)) ); 205 connect( editor, SIGNAL(copyAvailable(bool)), a, SLOT(setEnabled(bool)) );
204 a->addTo( tbEdit ); 206 a->addTo( tbEdit );
205 a->addTo( edit ); 207 a->addTo( edit );
206 a = new QAction( tr( "Paste" ), Resource::loadPixmap("paste"), 208 a = new QAction( tr( "Paste" ), Opie::Core::OResource::loadPixmap("paste", Opie::Core::OResource::SmallIcon ),
207 QString::null, 0, this, "editPaste" ); 209 QString::null, 0, this, "editPaste" );
208 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) ); 210 connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
209 a->addTo( tbEdit ); 211 a->addTo( tbEdit );
210 a->addTo( edit ); 212 a->addTo( edit );
211 213
212 tbFont = new QToolBar( this ); 214 tbFont = new QToolBar( this );
213 tbFont->setLabel( "Font Actions" ); 215 tbFont->setLabel( "Font Actions" );
214 tbFont->setHorizontalStretchable(TRUE); 216 tbFont->setHorizontalStretchable(TRUE);
215 217
216 comboFont = new QComboBox( FALSE, tbFont ); 218 comboFont = new QComboBox( FALSE, tbFont );
217 FontDatabase db; 219 FontDatabase db;
218 QStringList f= db.families(); 220 QStringList f= db.families();
219 comboFont->insertStringList( db.families() ); 221 comboFont->insertStringList( db.families() );
220 connect( comboFont, SIGNAL( activated(const QString&) ), 222 connect( comboFont, SIGNAL( activated(const QString&) ),
221 this, SLOT( textFamily(const QString&) ) ); 223 this, SLOT( textFamily(const QString&) ) );
222 comboFont->setCurrentItem( comboFont->listBox()->index( comboFont->listBox()->findItem( QApplication::font().family() ) ) ); 224 comboFont->setCurrentItem( comboFont->listBox()->index( comboFont->listBox()->findItem( QApplication::font().family() ) ) );
223 comboFont->setMaximumWidth(90); 225 comboFont->setMaximumWidth(90);
224 226
225 comboSize = new QComboBox( TRUE, tbFont ); 227 comboSize = new QComboBox( TRUE, tbFont );
226 QValueList<int> sizes = db.standardSizes(); 228 QValueList<int> sizes = db.standardSizes();
227 QValueList<int>::Iterator it = sizes.begin(); 229 QValueList<int>::Iterator it = sizes.begin();
228 for ( ; it != sizes.end(); ++it ) 230 for ( ; it != sizes.end(); ++it )
229 comboSize->insertItem( QString::number( *it ) ); 231 comboSize->insertItem( QString::number( *it ) );
230 connect( comboSize, SIGNAL( activated(const QString&) ), 232 connect( comboSize, SIGNAL( activated(const QString&) ),
231 this, SLOT( textSize(const QString&) ) ); 233 this, SLOT( textSize(const QString&) ) );
232 comboSize->lineEdit()->setText( QString::number( QApplication::font().pointSize() ) ); 234 comboSize->lineEdit()->setText( QString::number( QApplication::font().pointSize() ) );
233 comboSize->setFixedWidth( 38 ); 235 comboSize->setFixedWidth( 38 );
234 236
235 tbStyle = new QToolBar( this ); 237 tbStyle = new QToolBar( this );
236 tbStyle->setLabel( "Style Actions" ); 238 tbStyle->setLabel( "Style Actions" );
237 239
238 actionTextBold = new QAction( tr( "Bold" ), 240 actionTextBold = new QAction( tr( "Bold" ),
239 Resource::loadPixmap("bold"), 241 Opie::Core::OResource::loadPixmap("bold", Opie::Core::OResource::SmallIcon ),
240 QString::null, CTRL + Key_B, 242 QString::null, CTRL + Key_B,
241 this, "textBold" ); 243 this, "textBold" );
242 connect( actionTextBold, SIGNAL( activated() ), this, SLOT( textBold() ) ); 244 connect( actionTextBold, SIGNAL( activated() ), this, SLOT( textBold() ) );
243 actionTextBold->addTo( tbStyle ); 245 actionTextBold->addTo( tbStyle );
244 actionTextBold->setToggleAction( TRUE ); 246 actionTextBold->setToggleAction( TRUE );
245 actionTextItalic = new QAction( tr( "Italic" ), 247 actionTextItalic = new QAction( tr( "Italic" ),
246 Resource::loadPixmap("italic"), 248 Opie::Core::OResource::loadPixmap("italic", Opie::Core::OResource::SmallIcon ),
247 tr( "&Italic" ), CTRL + Key_I, 249 tr( "&Italic" ), CTRL + Key_I,
248 this, "textItalic" ); 250 this, "textItalic" );
249 connect( actionTextItalic, SIGNAL( activated() ), this, 251 connect( actionTextItalic, SIGNAL( activated() ), this,
250 SLOT( textItalic() ) ); 252 SLOT( textItalic() ) );
251 actionTextItalic->addTo( tbStyle ); 253 actionTextItalic->addTo( tbStyle );
252 actionTextItalic->setToggleAction( TRUE ); 254 actionTextItalic->setToggleAction( TRUE );
253 actionTextUnderline = new QAction( tr( "Underline" ), 255 actionTextUnderline = new QAction( tr( "Underline" ),
254 Resource::loadPixmap("underline"), 256 Opie::Core::OResource::loadPixmap("underline", Opie::Core::OResource::SmallIcon ),
255 tr( "&Underline" ), CTRL + Key_U, 257 tr( "&Underline" ), CTRL + Key_U,
256 this, "textUnderline" ); 258 this, "textUnderline" );
257 connect( actionTextUnderline, SIGNAL( activated() ), 259 connect( actionTextUnderline, SIGNAL( activated() ),
258 this, SLOT( textUnderline() ) ); 260 this, SLOT( textUnderline() ) );
259 actionTextUnderline->addTo( tbStyle ); 261 actionTextUnderline->addTo( tbStyle );
260 actionTextUnderline->setToggleAction( TRUE ); 262 actionTextUnderline->setToggleAction( TRUE );
261 263
262 alignMenu = new ButtonMenu( tbStyle ); 264 alignMenu = new ButtonMenu( tbStyle );
263 alignMenu->insertItem( Resource::loadPixmap("left"), tr("Left"), AlignLeft ); 265 alignMenu->insertItem( Opie::Core::OResource::loadPixmap("left", Opie::Core::OResource::SmallIcon), tr("Left"), AlignLeft );
264 alignMenu->insertItem( Resource::loadPixmap("center"), tr("Center"), AlignCenter ); 266 alignMenu->insertItem( Opie::Core::OResource::loadPixmap("center", Opie::Core::OResource::SmallIcon),
265 alignMenu->insertItem( Resource::loadPixmap("right"), tr("Right"), AlignRight ); 267 tr("Center"), AlignCenter );
266 alignMenu->insertItem( Resource::loadPixmap("opie-write/justify"), tr("Full"), Qt3::AlignJustify ); 268 alignMenu->insertItem( Opie::Core::OResource::loadPixmap("right", Opie::Core::OResource::SmallIcon),
269 tr("Right"), AlignRight );
270 alignMenu->insertItem( Opie::Core::OResource::loadPixmap("opie-write/justify", Opie::Core::OResource::SmallIcon),
271 tr("Full"), Qt3::AlignJustify );
267 connect( alignMenu, SIGNAL(activated(int)), this, SLOT(textAlign(int)) ); 272 connect( alignMenu, SIGNAL(activated(int)), this, SLOT(textAlign(int)) );
268} 273}
269 274
270Qt3::QTextEdit *MainWindow::currentEditor() const 275Qt3::QTextEdit *MainWindow::currentEditor() const
271{ 276{
272 return editor; 277 return editor;
273} 278}
274 279
275void MainWindow::doConnections( Qt3::QTextEdit *e ) 280void MainWindow::doConnections( Qt3::QTextEdit *e )
276{ 281{
277 connect( e, SIGNAL( currentFontChanged(const QFont&) ), 282 connect( e, SIGNAL( currentFontChanged(const QFont&) ),
278 this, SLOT( fontChanged(const QFont&) ) ); 283 this, SLOT( fontChanged(const QFont&) ) );
279 connect( e, SIGNAL( currentColorChanged(const QColor&) ), 284 connect( e, SIGNAL( currentColorChanged(const QColor&) ),
280 this, SLOT( colorChanged(const QColor&) ) ); 285 this, SLOT( colorChanged(const QColor&) ) );
281 connect( e, SIGNAL( currentAlignmentChanged(int) ), 286 connect( e, SIGNAL( currentAlignmentChanged(int) ),
282 this, SLOT( alignmentChanged(int) ) ); 287 this, SLOT( alignmentChanged(int) ) );
283} 288}
284 289
285void MainWindow::updateFontSizeCombo( const QFont &f ) 290void MainWindow::updateFontSizeCombo( const QFont &f )
286{ 291{
287 comboSize->clear(); 292 comboSize->clear();
288 FontDatabase fdb; 293 FontDatabase fdb;
289 QValueList<int> sizes = fdb.pointSizes( f.family() ); 294 QValueList<int> sizes = fdb.pointSizes( f.family() );
290 QValueList<int>::Iterator it = sizes.begin(); 295 QValueList<int>::Iterator it = sizes.begin();
291 for ( ; it != sizes.end(); ++it ) 296 for ( ; it != sizes.end(); ++it )
292 comboSize->insertItem( QString::number( *it ) ); 297 comboSize->insertItem( QString::number( *it ) );
293} 298}
294 299
295void MainWindow::editUndo() 300void MainWindow::editUndo()
296{ 301{
297 if ( !currentEditor() ) 302 if ( !currentEditor() )
298 return; 303 return;
299 currentEditor()->undo(); 304 currentEditor()->undo();
300} 305}
301 306
302void MainWindow::editRedo() 307void MainWindow::editRedo()
303{ 308{
304 if ( !currentEditor() ) 309 if ( !currentEditor() )
305 return; 310 return;
306 currentEditor()->redo(); 311 currentEditor()->redo();
307} 312}
308 313
309void MainWindow::editCut() 314void MainWindow::editCut()
310{ 315{
311 if ( !currentEditor() ) 316 if ( !currentEditor() )
312 return; 317 return;
313 currentEditor()->cut(); 318 currentEditor()->cut();
314} 319}
315 320
316void MainWindow::editCopy() 321void MainWindow::editCopy()
317{ 322{
318 if ( !currentEditor() ) 323 if ( !currentEditor() )
319 return; 324 return;
320 currentEditor()->copy(); 325 currentEditor()->copy();
321} 326}
322 327
323void MainWindow::editPaste() 328void MainWindow::editPaste()
324{ 329{
325 if ( !currentEditor() ) 330 if ( !currentEditor() )
326 return; 331 return;
327 currentEditor()->paste(); 332 currentEditor()->paste();
328} 333}
329 334
330void MainWindow::textBold() 335void MainWindow::textBold()
331{ 336{
332 if ( !currentEditor() ) 337 if ( !currentEditor() )
333 return; 338 return;
334 currentEditor()->setBold( actionTextBold->isOn() ); 339 currentEditor()->setBold( actionTextBold->isOn() );
335} 340}
336 341
337void MainWindow::textUnderline() 342void MainWindow::textUnderline()
338{ 343{
339 if ( !currentEditor() ) 344 if ( !currentEditor() )
340 return; 345 return;
341 currentEditor()->setUnderline( actionTextUnderline->isOn() ); 346 currentEditor()->setUnderline( actionTextUnderline->isOn() );
342} 347}
343 348
344void MainWindow::textItalic() 349void MainWindow::textItalic()
345{ 350{
346 if ( !currentEditor() ) 351 if ( !currentEditor() )
347 return; 352 return;
348 currentEditor()->setItalic( actionTextItalic->isOn() ); 353 currentEditor()->setItalic( actionTextItalic->isOn() );
349} 354}
350 355
351void MainWindow::textFamily( const QString &f ) 356void MainWindow::textFamily( const QString &f )
352{ 357{
353 if ( !currentEditor() ) 358 if ( !currentEditor() )
354 return; 359 return;
355 currentEditor()->setFamily( f ); 360 currentEditor()->setFamily( f );
356 currentEditor()->viewport()->setFocus(); 361 currentEditor()->viewport()->setFocus();
357} 362}
358 363
359void MainWindow::textSize( const QString &p ) 364void MainWindow::textSize( const QString &p )
360{ 365{
361 if ( !currentEditor() ) 366 if ( !currentEditor() )
362 return; 367 return;
363 currentEditor()->setPointSize( p.toInt() ); 368 currentEditor()->setPointSize( p.toInt() );
364 currentEditor()->viewport()->setFocus(); 369 currentEditor()->viewport()->setFocus();
365} 370}
366 371
367void MainWindow::textStyle( int i ) 372void MainWindow::textStyle( int i )
368{ 373{
369 if ( !currentEditor() ) 374 if ( !currentEditor() )
370 return; 375 return;
371 if ( i == 0 ) 376 if ( i == 0 )
372 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayBlock, 377 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayBlock,
373 Qt3::QStyleSheetItem::ListDisc ); 378 Qt3::QStyleSheetItem::ListDisc );
374 else if ( i == 1 ) 379 else if ( i == 1 )
375 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, 380 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem,
376 Qt3::QStyleSheetItem::ListDisc ); 381 Qt3::QStyleSheetItem::ListDisc );
377 else if ( i == 2 ) 382 else if ( i == 2 )
378 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, 383 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem,
379 Qt3::QStyleSheetItem::ListCircle ); 384 Qt3::QStyleSheetItem::ListCircle );
380 else if ( i == 3 ) 385 else if ( i == 3 )
381 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, 386 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem,
382 Qt3::QStyleSheetItem::ListSquare ); 387 Qt3::QStyleSheetItem::ListSquare );
383 else if ( i == 4 ) 388 else if ( i == 4 )
384 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, 389 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem,
385 Qt3::QStyleSheetItem::ListDecimal ); 390 Qt3::QStyleSheetItem::ListDecimal );
386 else if ( i == 5 ) 391 else if ( i == 5 )
387 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, 392 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem,
388 Qt3::QStyleSheetItem::ListLowerAlpha ); 393 Qt3::QStyleSheetItem::ListLowerAlpha );
389 else if ( i == 6 ) 394 else if ( i == 6 )
390 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, 395 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem,
391 Qt3::QStyleSheetItem::ListUpperAlpha ); 396 Qt3::QStyleSheetItem::ListUpperAlpha );
392 currentEditor()->viewport()->setFocus(); 397 currentEditor()->viewport()->setFocus();
393} 398}
394 399
395void MainWindow::textAlign( int a ) 400void MainWindow::textAlign( int a )
396{ 401{
397 if ( !currentEditor() ) 402 if ( !currentEditor() )
398 return; 403 return;
399 editor->setAlignment( a ); 404 editor->setAlignment( a );
400} 405}
401 406
402void MainWindow::fontChanged( const QFont &f ) 407void MainWindow::fontChanged( const QFont &f )
403{ 408{
404 comboFont->setCurrentItem( comboFont->listBox()->index( comboFont->listBox()->findItem( f.family() ) ) ); 409 comboFont->setCurrentItem( comboFont->listBox()->index( comboFont->listBox()->findItem( f.family() ) ) );
405 updateFontSizeCombo( f ); 410 updateFontSizeCombo( f );
406 comboSize->lineEdit()->setText( QString::number( f.pointSize() ) ); 411 comboSize->lineEdit()->setText( QString::number( f.pointSize() ) );
407 actionTextBold->setOn( f.bold() ); 412 actionTextBold->setOn( f.bold() );
408 actionTextItalic->setOn( f.italic() ); 413 actionTextItalic->setOn( f.italic() );
409 actionTextUnderline->setOn( f.underline() ); 414 actionTextUnderline->setOn( f.underline() );
410} 415}
411 416
412void MainWindow::colorChanged( const QColor & ) 417void MainWindow::colorChanged( const QColor & )
413{ 418{
414} 419}
415 420
416void MainWindow::alignmentChanged( int a ) 421void MainWindow::alignmentChanged( int a )
417{ 422{
418 if ( ( a == Qt3::AlignAuto ) || ( a & AlignLeft )) { 423 if ( ( a == Qt3::AlignAuto ) || ( a & AlignLeft )) {
419 alignMenu->setCurrentItem(AlignLeft); 424 alignMenu->setCurrentItem(AlignLeft);
420 } else if ( ( a & AlignCenter ) ) { 425 } else if ( ( a & AlignCenter ) ) {
421 alignMenu->setCurrentItem(AlignCenter); 426 alignMenu->setCurrentItem(AlignCenter);
422 } else if ( ( a & AlignRight ) ) { 427 } else if ( ( a & AlignRight ) ) {
423 alignMenu->setCurrentItem(AlignRight); 428 alignMenu->setCurrentItem(AlignRight);
424 } else if ( ( a & Qt3::AlignJustify ) ) { 429 } else if ( ( a & Qt3::AlignJustify ) ) {
425 alignMenu->setCurrentItem(Qt3::AlignJustify); 430 alignMenu->setCurrentItem(Qt3::AlignJustify);
426 } 431 }
427} 432}
428 433
429void MainWindow::editorChanged( QWidget * ) 434void MainWindow::editorChanged( QWidget * )
430{ 435{
431 if ( !currentEditor() ) 436 if ( !currentEditor() )
432 return; 437 return;
433 fontChanged( currentEditor()->font() ); 438 fontChanged( currentEditor()->font() );
434 colorChanged( currentEditor()->color() ); 439 colorChanged( currentEditor()->color() );
435 alignmentChanged( currentEditor()->alignment() ); 440 alignmentChanged( currentEditor()->alignment() );
436} 441}
437 442
438void MainWindow::fileOpen() 443void MainWindow::fileOpen()
439{ 444{
440 save(); 445 save();
441 editorStack->raiseWidget( fileSelector ); 446 editorStack->raiseWidget( fileSelector );
442 fileSelector->reread(); 447 fileSelector->reread();
443 hideEditTools(); 448 hideEditTools();
444 fileSelector->setNewVisible( TRUE ); 449 fileSelector->setNewVisible( TRUE );
445 clear(); 450 clear();
446 updateCaption(); 451 updateCaption();
447} 452}
448 453
449void MainWindow::fileRevert() 454void MainWindow::fileRevert()
450{ 455{
451 odebug << "QMainWindow::fileRevert needs to be done" << oendl; 456 odebug << "QMainWindow::fileRevert needs to be done" << oendl;
452} 457}
453 458
454void MainWindow::fileNew() 459void MainWindow::fileNew()
455{ 460{
456 editor->setTextFormat( Qt::RichText ); 461 editor->setTextFormat( Qt::RichText );
457 save(); 462 save();
458 newFile(DocLnk()); 463 newFile(DocLnk());
459} 464}
460 465
461void MainWindow::insertTable() 466void MainWindow::insertTable()
462{ 467{
463 odebug << "MainWindow::insertTable() needs to be done" << oendl; 468 odebug << "MainWindow::insertTable() needs to be done" << oendl;
464} 469}
465 470
466void MainWindow::newFile( const DocLnk &dl ) 471void MainWindow::newFile( const DocLnk &dl )
467{ 472{
468 DocLnk nf = dl; 473 DocLnk nf = dl;
469 nf.setType( "text/html" ); 474 nf.setType( "text/html" );
470 clear(); 475 clear();
471 editorStack->raiseWidget( editor ); 476 editorStack->raiseWidget( editor );
472 editor->viewport()->setFocus(); 477 editor->viewport()->setFocus();
473 doc = new DocLnk( nf ); 478 doc = new DocLnk( nf );
474 updateCaption(); 479 updateCaption();
475} 480}
476 481
477void MainWindow::openFile( const DocLnk &dl ) 482void MainWindow::openFile( const DocLnk &dl )
478{ 483{
479 FileManager fm; 484 FileManager fm;
480 QString txt; 485 QString txt;
481 if ( !fm.loadFile( dl, txt ) ) 486 if ( !fm.loadFile( dl, txt ) )
482 odebug << "couldn't open file" << oendl; 487 odebug << "couldn't open file" << oendl;
483 clear(); 488 clear();
484 editorStack->raiseWidget( editor ); 489 editorStack->raiseWidget( editor );
485 editor->viewport()->setFocus(); 490 editor->viewport()->setFocus();
486 doc = new DocLnk( dl ); 491 doc = new DocLnk( dl );
487 editor->setText( txt ); 492 editor->setText( txt );
488 editor->setModified( FALSE ); 493 editor->setModified( FALSE );
489 updateCaption(); 494 updateCaption();
490} 495}
491 496
492void MainWindow::showEditTools( void ) 497void MainWindow::showEditTools( void )
493{ 498{
494 tbMenu->show(); 499 tbMenu->show();
495 tbEdit->show(); 500 tbEdit->show();
496 tbFont->show(); 501 tbFont->show();
497 tbStyle->show(); 502 tbStyle->show();
498} 503}
499 504
500void MainWindow::hideEditTools( void ) 505void MainWindow::hideEditTools( void )
501{ 506{
502 // let's reset the buttons... 507 // let's reset the buttons...
503 actionTextBold->setOn( FALSE ); 508 actionTextBold->setOn( FALSE );
504 actionTextItalic->setOn( FALSE ); 509 actionTextItalic->setOn( FALSE );
505 actionTextUnderline->setOn( FALSE ); 510 actionTextUnderline->setOn( FALSE );
506 //comboFont->setCurrentText( QApplication::font().family() ); 511 //comboFont->setCurrentText( QApplication::font().family() );
507 comboSize->lineEdit()->setText( QString::number(QApplication::font().pointSize() ) ); 512 comboSize->lineEdit()->setText( QString::number(QApplication::font().pointSize() ) );
508 tbMenu->hide(); 513 tbMenu->hide();
509 tbEdit->hide(); 514 tbEdit->hide();
510 tbFont->hide(); 515 tbFont->hide();
511 tbStyle->hide(); 516 tbStyle->hide();
512} 517}
513 518
514 519
515void MainWindow::save() 520void MainWindow::save()
516{ 521{
517 if ( !doc ) 522 if ( !doc )
518 return; 523 return;
519 if ( !editor->isModified() ) 524 if ( !editor->isModified() )
520 return; 525 return;
521 526
522 QString rt = editor->text(); 527 QString rt = editor->text();