summaryrefslogtreecommitdiff
authorharlekin <harlekin>2003-03-22 18:18:46 (UTC)
committer harlekin <harlekin>2003-03-22 18:18:46 (UTC)
commit916e4d83eb69676e527d7b0cce5fdc0a400a8255 (patch) (unidiff)
tree15c3d829a943cd8902ab44a9b027967fb28c091f
parent5fa24d5c7e5ebf45917b8632bfb2fb99cf545381 (diff)
downloadopie-916e4d83eb69676e527d7b0cce5fdc0a400a8255.zip
opie-916e4d83eb69676e527d7b0cce5fdc0a400a8255.tar.gz
opie-916e4d83eb69676e527d7b0cce5fdc0a400a8255.tar.bz2
use icons from inline
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-write/mainwindow.cpp10
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
@@ -1,574 +1,574 @@
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#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> 26#include <qpe/fontdatabase.h>
27 27
28//#include "qspellchecker.h" 28//#include "qspellchecker.h"
29#include "qtextedit.h" 29#include "qtextedit.h"
30#include <qaction.h> 30#include <qaction.h>
31#include <qtoolbar.h> 31#include <qtoolbar.h>
32#include <qtoolbutton.h> 32#include <qtoolbutton.h>
33#include <qtabwidget.h> 33#include <qtabwidget.h>
34#include <qapplication.h> 34#include <qapplication.h>
35#include <qfontdatabase.h> 35#include <qfontdatabase.h>
36#include <qcombobox.h> 36#include <qcombobox.h>
37#include <qlineedit.h> 37#include <qlineedit.h>
38#include <qfileinfo.h> 38#include <qfileinfo.h>
39#include <qfile.h> 39#include <qfile.h>
40#include <qfiledialog.h> 40#include <qfiledialog.h>
41#include <qprinter.h> 41#include <qprinter.h>
42#include <qpaintdevicemetrics.h> 42#include <qpaintdevicemetrics.h>
43#include <qmenubar.h> 43#include <qmenubar.h>
44#include <qpopupmenu.h> 44#include <qpopupmenu.h>
45#include <qcolordialog.h> 45#include <qcolordialog.h>
46#include <qpainter.h> 46#include <qpainter.h>
47#include <qstyle.h> 47#include <qstyle.h>
48 48
49class ButtonMenu : public QToolButton 49class ButtonMenu : public QToolButton
50{ 50{
51 Q_OBJECT 51 Q_OBJECT
52public: 52public:
53 ButtonMenu( QWidget *parent, const char *name=0 ) 53 ButtonMenu( QWidget *parent, const char *name=0 )
54 : QToolButton( parent, name ), current(0) 54 : QToolButton( parent, name ), current(0)
55 { 55 {
56 setPopup( new QPopupMenu( this ) ); 56 setPopup( new QPopupMenu( this ) );
57 setPopupDelay( 1 ); 57 setPopupDelay( 1 );
58 connect( popup(), SIGNAL(activated(int)), this, SLOT(selected(int)) ); 58 connect( popup(), SIGNAL(activated(int)), this, SLOT(selected(int)) );
59 } 59 }
60 60
61 int insertItem(const QIconSet &icon, const QString &text, int id ) { 61 int insertItem(const QIconSet &icon, const QString &text, int id ) {
62 if ( !popup()->count() ) { 62 if ( !popup()->count() ) {
63 setIconSet( icon ); 63 setIconSet( icon );
64 current = id; 64 current = id;
65 } 65 }
66 return popup()->insertItem( icon, text, id ); 66 return popup()->insertItem( icon, text, id );
67 } 67 }
68 68
69 void setCurrentItem( int id ) { 69 void setCurrentItem( int id ) {
70 if ( id != current ) { 70 if ( id != current ) {
71 current = id; 71 current = id;
72 setIconSet( *popup()->iconSet( id ) ); 72 setIconSet( *popup()->iconSet( id ) );
73 } 73 }
74 } 74 }
75 75
76 virtual QSize sizeHint() const { 76 virtual QSize sizeHint() const {
77 return QToolButton::sizeHint() + QSize( 4, 0 ); 77 return QToolButton::sizeHint() + QSize( 4, 0 );
78 } 78 }
79 79
80signals: 80signals:
81 void activated( int id ); 81 void activated( int id );
82 82
83protected slots: 83protected slots:
84 void selected( int id ) { 84 void selected( int id ) {
85 current = id; 85 current = id;
86 setIconSet( *popup()->iconSet( id ) ); 86 setIconSet( *popup()->iconSet( id ) );
87 emit activated( id ); 87 emit activated( id );
88 } 88 }
89 89
90protected: 90protected:
91 virtual void drawButtonLabel( QPainter *p ) { 91 virtual void drawButtonLabel( QPainter *p ) {
92 p->translate( -4, 0 ); 92 p->translate( -4, 0 );
93 QToolButton::drawButtonLabel( p ); 93 QToolButton::drawButtonLabel( p );
94 p->translate( 4, 0 ); 94 p->translate( 4, 0 );
95 } 95 }
96 96
97private: 97private:
98 int current; 98 int current;
99}; 99};
100 100
101//=========================================================================== 101//===========================================================================
102 102
103MainWindow::MainWindow( QWidget *parent, const char *name ) 103MainWindow::MainWindow( QWidget *parent, const char *name )
104 : QMainWindow( parent, name ), 104 : QMainWindow( parent, name ),
105 doc( 0 ) 105 doc( 0 )
106{ 106{
107 setRightJustification(TRUE); 107 setRightJustification(TRUE);
108 108
109 editorStack = new QWidgetStack( this ); 109 editorStack = new QWidgetStack( this );
110 110
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
141MainWindow::~MainWindow() 141MainWindow::~MainWindow()
142{ 142{
143 save(); 143 save();
144} 144}
145 145
146void MainWindow::setupActions() 146void 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
266Qt3::QTextEdit *MainWindow::currentEditor() const 266Qt3::QTextEdit *MainWindow::currentEditor() const
267{ 267{
268 return editor; 268 return editor;
269} 269}
270 270
271void MainWindow::doConnections( Qt3::QTextEdit *e ) 271void 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
281void MainWindow::updateFontSizeCombo( const QFont &f ) 281void 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
291void MainWindow::editUndo() 291void MainWindow::editUndo()
292{ 292{
293 if ( !currentEditor() ) 293 if ( !currentEditor() )
294 return; 294 return;
295 currentEditor()->undo(); 295 currentEditor()->undo();
296} 296}
297 297
298void MainWindow::editRedo() 298void MainWindow::editRedo()
299{ 299{
300 if ( !currentEditor() ) 300 if ( !currentEditor() )
301 return; 301 return;
302 currentEditor()->redo(); 302 currentEditor()->redo();
303} 303}
304 304
305void MainWindow::editCut() 305void MainWindow::editCut()
306{ 306{
307 if ( !currentEditor() ) 307 if ( !currentEditor() )
308 return; 308 return;
309 currentEditor()->cut(); 309 currentEditor()->cut();
310} 310}
311 311
312void MainWindow::editCopy() 312void MainWindow::editCopy()
313{ 313{
314 if ( !currentEditor() ) 314 if ( !currentEditor() )
315 return; 315 return;
316 currentEditor()->copy(); 316 currentEditor()->copy();
317} 317}
318 318
319void MainWindow::editPaste() 319void MainWindow::editPaste()
320{ 320{
321 if ( !currentEditor() ) 321 if ( !currentEditor() )
322 return; 322 return;
323 currentEditor()->paste(); 323 currentEditor()->paste();
324} 324}
325 325
326void MainWindow::textBold() 326void 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
333void MainWindow::textUnderline() 333void MainWindow::textUnderline()
334{ 334{
335 if ( !currentEditor() ) 335 if ( !currentEditor() )
336 return; 336 return;
337 currentEditor()->setUnderline( actionTextUnderline->isOn() ); 337 currentEditor()->setUnderline( actionTextUnderline->isOn() );
338} 338}
339 339
340void MainWindow::textItalic() 340void MainWindow::textItalic()
341{ 341{
342 if ( !currentEditor() ) 342 if ( !currentEditor() )
343 return; 343 return;
344 currentEditor()->setItalic( actionTextItalic->isOn() ); 344 currentEditor()->setItalic( actionTextItalic->isOn() );
345} 345}
346 346
347void MainWindow::textFamily( const QString &f ) 347void MainWindow::textFamily( const QString &f )
348{ 348{
349 if ( !currentEditor() ) 349 if ( !currentEditor() )
350 return; 350 return;
351 currentEditor()->setFamily( f ); 351 currentEditor()->setFamily( f );
352 currentEditor()->viewport()->setFocus(); 352 currentEditor()->viewport()->setFocus();
353} 353}
354 354
355void MainWindow::textSize( const QString &p ) 355void MainWindow::textSize( const QString &p )
356{ 356{
357 if ( !currentEditor() ) 357 if ( !currentEditor() )
358 return; 358 return;
359 currentEditor()->setPointSize( p.toInt() ); 359 currentEditor()->setPointSize( p.toInt() );
360 currentEditor()->viewport()->setFocus(); 360 currentEditor()->viewport()->setFocus();
361} 361}
362 362
363void MainWindow::textStyle( int i ) 363void MainWindow::textStyle( int i )
364{ 364{
365 if ( !currentEditor() ) 365 if ( !currentEditor() )
366 return; 366 return;
367 if ( i == 0 ) 367 if ( i == 0 )
368 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayBlock, 368 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayBlock,
369 Qt3::QStyleSheetItem::ListDisc ); 369 Qt3::QStyleSheetItem::ListDisc );
370 else if ( i == 1 ) 370 else if ( i == 1 )
371 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, 371 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem,
372 Qt3::QStyleSheetItem::ListDisc ); 372 Qt3::QStyleSheetItem::ListDisc );
373 else if ( i == 2 ) 373 else if ( i == 2 )
374 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, 374 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem,
375 Qt3::QStyleSheetItem::ListCircle ); 375 Qt3::QStyleSheetItem::ListCircle );
376 else if ( i == 3 ) 376 else if ( i == 3 )
377 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, 377 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem,
378 Qt3::QStyleSheetItem::ListSquare ); 378 Qt3::QStyleSheetItem::ListSquare );
379 else if ( i == 4 ) 379 else if ( i == 4 )
380 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, 380 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem,
381 Qt3::QStyleSheetItem::ListDecimal ); 381 Qt3::QStyleSheetItem::ListDecimal );
382 else if ( i == 5 ) 382 else if ( i == 5 )
383 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, 383 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem,
384 Qt3::QStyleSheetItem::ListLowerAlpha ); 384 Qt3::QStyleSheetItem::ListLowerAlpha );
385 else if ( i == 6 ) 385 else if ( i == 6 )
386 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem, 386 currentEditor()->setParagType( Qt3::QStyleSheetItem::DisplayListItem,
387 Qt3::QStyleSheetItem::ListUpperAlpha ); 387 Qt3::QStyleSheetItem::ListUpperAlpha );
388 currentEditor()->viewport()->setFocus(); 388 currentEditor()->viewport()->setFocus();
389} 389}
390 390
391void MainWindow::textAlign( int a ) 391void MainWindow::textAlign( int a )
392{ 392{
393 if ( !currentEditor() ) 393 if ( !currentEditor() )
394 return; 394 return;
395 editor->setAlignment( a ); 395 editor->setAlignment( a );
396} 396}
397 397
398void MainWindow::fontChanged( const QFont &f ) 398void MainWindow::fontChanged( const QFont &f )
399{ 399{
400 comboFont->setCurrentItem( comboFont->listBox()->index( comboFont->listBox()->findItem( f.family() ) ) ); 400 comboFont->setCurrentItem( comboFont->listBox()->index( comboFont->listBox()->findItem( f.family() ) ) );
401 updateFontSizeCombo( f ); 401 updateFontSizeCombo( f );
402 comboSize->lineEdit()->setText( QString::number( f.pointSize() ) ); 402 comboSize->lineEdit()->setText( QString::number( f.pointSize() ) );
403 actionTextBold->setOn( f.bold() ); 403 actionTextBold->setOn( f.bold() );
404 actionTextItalic->setOn( f.italic() ); 404 actionTextItalic->setOn( f.italic() );
405 actionTextUnderline->setOn( f.underline() ); 405 actionTextUnderline->setOn( f.underline() );
406} 406}
407 407
408void MainWindow::colorChanged( const QColor & ) 408void MainWindow::colorChanged( const QColor & )
409{ 409{
410} 410}
411 411
412void MainWindow::alignmentChanged( int a ) 412void MainWindow::alignmentChanged( int a )
413{ 413{
414 if ( ( a == Qt3::AlignAuto ) || ( a & AlignLeft )) { 414 if ( ( a == Qt3::AlignAuto ) || ( a & AlignLeft )) {
415 alignMenu->setCurrentItem(AlignLeft); 415 alignMenu->setCurrentItem(AlignLeft);
416 } else if ( ( a & AlignCenter ) ) { 416 } else if ( ( a & AlignCenter ) ) {
417 alignMenu->setCurrentItem(AlignCenter); 417 alignMenu->setCurrentItem(AlignCenter);
418 } else if ( ( a & AlignRight ) ) { 418 } else if ( ( a & AlignRight ) ) {
419 alignMenu->setCurrentItem(AlignRight); 419 alignMenu->setCurrentItem(AlignRight);
420 } else if ( ( a & Qt3::AlignJustify ) ) { 420 } else if ( ( a & Qt3::AlignJustify ) ) {
421 alignMenu->setCurrentItem(Qt3::AlignJustify); 421 alignMenu->setCurrentItem(Qt3::AlignJustify);
422 } 422 }
423} 423}
424 424
425void MainWindow::editorChanged( QWidget * ) 425void MainWindow::editorChanged( QWidget * )
426{ 426{
427 if ( !currentEditor() ) 427 if ( !currentEditor() )
428 return; 428 return;
429 fontChanged( currentEditor()->font() ); 429 fontChanged( currentEditor()->font() );
430 colorChanged( currentEditor()->color() ); 430 colorChanged( currentEditor()->color() );
431 alignmentChanged( currentEditor()->alignment() ); 431 alignmentChanged( currentEditor()->alignment() );
432} 432}
433 433
434void MainWindow::fileOpen() 434void MainWindow::fileOpen()
435{ 435{
436 save(); 436 save();
437 editorStack->raiseWidget( fileSelector ); 437 editorStack->raiseWidget( fileSelector );
438 fileSelector->reread(); 438 fileSelector->reread();
439 hideEditTools(); 439 hideEditTools();
440 fileSelector->setNewVisible( TRUE ); 440 fileSelector->setNewVisible( TRUE );
441 clear(); 441 clear();
442 updateCaption(); 442 updateCaption();
443} 443}
444 444
445void MainWindow::fileRevert() 445void MainWindow::fileRevert()
446{ 446{
447 qDebug( "QMainWindow::fileRevert needs to be done" ); 447 qDebug( "QMainWindow::fileRevert needs to be done" );
448} 448}
449 449
450void MainWindow::fileNew() 450void 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
457void MainWindow::insertTable() 457void MainWindow::insertTable()
458{ 458{
459 qDebug( "MainWindow::insertTable() needs to be done" ); 459 qDebug( "MainWindow::insertTable() needs to be done" );
460} 460}
461 461
462void MainWindow::newFile( const DocLnk &dl ) 462void 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
473void MainWindow::openFile( const DocLnk &dl ) 473void 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
488void MainWindow::showEditTools( void ) 488void 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
496void MainWindow::hideEditTools( void ) 496void 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
511void MainWindow::save() 511void 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
544void MainWindow::clear() 544void 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
551void MainWindow::updateCaption() 551void 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
563void MainWindow::closeEvent( QCloseEvent *e ) 563void 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"