summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-11-10 03:13:39 (UTC)
committer llornkcor <llornkcor>2002-11-10 03:13:39 (UTC)
commitea3334042e9625c0f67c9a7293a482849f60e4e2 (patch) (unidiff)
treed9c36920818ed681a4a80d3e7af14524e66fa942
parent7601c75b529d9ff205403a32206b9431845cfc91 (diff)
downloadopie-ea3334042e9625c0f67c9a7293a482849f60e4e2.zip
opie-ea3334042e9625c0f67c9a7293a482849f60e4e2.tar.gz
opie-ea3334042e9625c0f67c9a7293a482849f60e4e2.tar.bz2
use opie's FontDatabase so to be able to use freetype
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-write/mainwindow.cpp222
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
@@ -25,2 +25,4 @@
25#include <qpe/resource.h> 25#include <qpe/resource.h>
26#include <qpe/fontdatabase.h>
27
26//#include "qspellchecker.h" 28//#include "qspellchecker.h"
@@ -51,7 +53,7 @@ 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 }
@@ -59,7 +61,7 @@ public:
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 }
@@ -67,6 +69,6 @@ public:
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 }
@@ -74,3 +76,3 @@ public:
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 }
@@ -82,5 +84,5 @@ 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 }
@@ -89,5 +91,5 @@ 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 }
@@ -109,3 +111,3 @@ MainWindow::MainWindow( QWidget *parent, const char *name )
109 fileSelector = new FileSelector( "text/html", 111 fileSelector = new FileSelector( "text/html",
110 editorStack, "fileselector" ); 112 editorStack, "fileselector" );
111 113
@@ -122,12 +124,12 @@ MainWindow::MainWindow( QWidget *parent, const char *name )
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 }
@@ -173,3 +175,3 @@ void MainWindow::setupActions()
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() ) );
@@ -179,3 +181,3 @@ void MainWindow::setupActions()
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() ) );
@@ -188,3 +190,3 @@ void MainWindow::setupActions()
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() ) );
@@ -194,3 +196,3 @@ void MainWindow::setupActions()
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() ) );
@@ -200,3 +202,3 @@ void MainWindow::setupActions()
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() ) );
@@ -210,7 +212,9 @@ void MainWindow::setupActions()
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
@@ -220,5 +224,5 @@ void MainWindow::setupActions()
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() ) );
@@ -230,5 +234,5 @@ void MainWindow::setupActions()
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() ) );
@@ -237,7 +241,7 @@ void MainWindow::setupActions()
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 );
@@ -245,7 +249,7 @@ void MainWindow::setupActions()
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 );
@@ -263,3 +267,3 @@ Qt3::QTextEdit *MainWindow::currentEditor() const
263{ 267{
264 return editor; 268 return editor;
265} 269}
@@ -269,7 +273,7 @@ void MainWindow::doConnections( Qt3::QTextEdit *e )
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}
@@ -279,3 +283,3 @@ void MainWindow::updateFontSizeCombo( const QFont &f )
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() );
@@ -283,3 +287,3 @@ void MainWindow::updateFontSizeCombo( const QFont &f )
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}
@@ -289,3 +293,3 @@ void MainWindow::editUndo()
289 if ( !currentEditor() ) 293 if ( !currentEditor() )
290 return; 294 return;
291 currentEditor()->undo(); 295 currentEditor()->undo();
@@ -296,3 +300,3 @@ void MainWindow::editRedo()
296 if ( !currentEditor() ) 300 if ( !currentEditor() )
297 return; 301 return;
298 currentEditor()->redo(); 302 currentEditor()->redo();
@@ -303,3 +307,3 @@ void MainWindow::editCut()
303 if ( !currentEditor() ) 307 if ( !currentEditor() )
304 return; 308 return;
305 currentEditor()->cut(); 309 currentEditor()->cut();
@@ -310,3 +314,3 @@ void MainWindow::editCopy()
310 if ( !currentEditor() ) 314 if ( !currentEditor() )
311 return; 315 return;
312 currentEditor()->copy(); 316 currentEditor()->copy();
@@ -317,3 +321,3 @@ void MainWindow::editPaste()
317 if ( !currentEditor() ) 321 if ( !currentEditor() )
318 return; 322 return;
319 currentEditor()->paste(); 323 currentEditor()->paste();
@@ -324,3 +328,3 @@ void MainWindow::textBold()
324 if ( !currentEditor() ) 328 if ( !currentEditor() )
325 return; 329 return;
326 currentEditor()->setBold( actionTextBold->isOn() ); 330 currentEditor()->setBold( actionTextBold->isOn() );
@@ -331,3 +335,3 @@ void MainWindow::textUnderline()
331 if ( !currentEditor() ) 335 if ( !currentEditor() )
332 return; 336 return;
333 currentEditor()->setUnderline( actionTextUnderline->isOn() ); 337 currentEditor()->setUnderline( actionTextUnderline->isOn() );
@@ -338,3 +342,3 @@ void MainWindow::textItalic()
338 if ( !currentEditor() ) 342 if ( !currentEditor() )
339 return; 343 return;
340 currentEditor()->setItalic( actionTextItalic->isOn() ); 344 currentEditor()->setItalic( actionTextItalic->isOn() );
@@ -345,3 +349,3 @@ void MainWindow::textFamily( const QString &f )
345 if ( !currentEditor() ) 349 if ( !currentEditor() )
346 return; 350 return;
347 currentEditor()->setFamily( f ); 351 currentEditor()->setFamily( f );
@@ -353,3 +357,3 @@ void MainWindow::textSize( const QString &p )
353 if ( !currentEditor() ) 357 if ( !currentEditor() )
354 return; 358 return;
355 currentEditor()->setPointSize( p.toInt() ); 359 currentEditor()->setPointSize( p.toInt() );
@@ -361,24 +365,24 @@ void MainWindow::textStyle( int i )
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();
@@ -389,3 +393,3 @@ void MainWindow::textAlign( int a )
389 if ( !currentEditor() ) 393 if ( !currentEditor() )
390 return; 394 return;
391 editor->setAlignment( a ); 395 editor->setAlignment( a );
@@ -410,9 +414,9 @@ void MainWindow::alignmentChanged( int a )
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 }
@@ -423,3 +427,3 @@ void MainWindow::editorChanged( QWidget * )
423 if ( !currentEditor() ) 427 if ( !currentEditor() )
424 return; 428 return;
425 fontChanged( currentEditor()->font() ); 429 fontChanged( currentEditor()->font() );
@@ -473,3 +477,3 @@ void MainWindow::openFile( const DocLnk &dl )
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();
@@ -505,3 +509,3 @@ void MainWindow::hideEditTools( void )
505 509
506 510
507void MainWindow::save() 511void MainWindow::save()
@@ -509,5 +513,5 @@ void MainWindow::save()
509 if ( !doc ) 513 if ( !doc )
510 return; 514 return;
511 if ( !editor->isModified() ) 515 if ( !editor->isModified() )
512 return; 516 return;
513 517
@@ -521,15 +525,15 @@ void MainWindow::save()
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 }
@@ -549,8 +553,8 @@ void MainWindow::updateCaption()
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 }
@@ -561,7 +565,7 @@ void MainWindow::closeEvent( QCloseEvent *e )
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 }