summaryrefslogtreecommitdiff
authorzecke <zecke>2005-02-19 17:26:15 (UTC)
committer zecke <zecke>2005-02-19 17:26:15 (UTC)
commit112337f13c70f1266430f154d486b6f23ec18488 (patch) (unidiff)
tree6869bbf5f7763b2a56ef690526275cae081dae83
parentb02c537198dad1e53f8c4004a4c08578e431b411 (diff)
downloadopie-112337f13c70f1266430f154d486b6f23ec18488.zip
opie-112337f13c70f1266430f154d486b6f23ec18488.tar.gz
opie-112337f13c70f1266430f154d486b6f23ec18488.tar.bz2
Make use of the platform
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-gutenbrowser/helpwindow.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/noncore/apps/opie-gutenbrowser/helpwindow.cpp b/noncore/apps/opie-gutenbrowser/helpwindow.cpp
index 57b1e74..4bdac02 100644
--- a/noncore/apps/opie-gutenbrowser/helpwindow.cpp
+++ b/noncore/apps/opie-gutenbrowser/helpwindow.cpp
@@ -1,286 +1,289 @@
1/**************************************************************************** 1/****************************************************************************
2** $Id$ 2** $Id$
3** 3**
4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. 4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
5** 5**
6** This file is part of an example program for Qt. This example 6** This file is part of an example program for Qt. This example
7** program may be used, distributed and modified without limitation. 7** program may be used, distributed and modified without limitation.
8** 8**
9 copyright : (C) 2000 -2004 by llornkcor 9 copyright : (C) 2000 -2004 by llornkcor
10 email : ljp@llornkcor.com 10 email : ljp@llornkcor.com
11*****************************************************************************/ 11*****************************************************************************/
12 12
13#include "helpwindow.h" 13#include "helpwindow.h"
14
15#include <qpe/global.h>
16
14#include <qstatusbar.h> 17#include <qstatusbar.h>
15 18
16#include <qmenubar.h> 19#include <qmenubar.h>
17#include <qtoolbar.h> 20#include <qtoolbar.h>
18#include <qtoolbutton.h> 21#include <qtoolbutton.h>
19#include <qcombobox.h> 22#include <qcombobox.h>
20 23
21#ifndef QT_NO_FILEDIALOG 24#ifndef QT_NO_FILEDIALOG
22#include <qfiledialog.h> 25#include <qfiledialog.h>
23#endif 26#endif
24 27
25#include <ctype.h> 28#include <ctype.h>
26 29
27HelpWindow::HelpWindow( const QString& home_, const QString&, QWidget* parent, const char *name ) 30HelpWindow::HelpWindow( const QString& home_, const QString&, QWidget* parent, const char *name )
28 : QMainWindow( parent, name, WDestructiveClose ), pathCombo( 0 ), selectedURL() 31 : QMainWindow( parent, name, WDestructiveClose ), pathCombo( 0 ), selectedURL()
29{ 32{
30 QString local_library = (QDir::homeDirPath ()) +"/Applications/gutenbrowser/"; 33 QString local_library = Global::applicationFileName("gutenbrowser", QString::null);
31// readHistory(); 34// readHistory();
32// readBookmarks(); 35// readBookmarks();
33 36
34 browser = new QTextBrowser( this ); 37 browser = new QTextBrowser( this );
35 QStringList Strlist; 38 QStringList Strlist;
36 Strlist.append( home_); 39 Strlist.append( home_);
37 browser->mimeSourceFactory()->setFilePath( Strlist ); 40 browser->mimeSourceFactory()->setFilePath( Strlist );
38 41
39 browser->setFrameStyle( QFrame::Panel | QFrame::Sunken ); 42 browser->setFrameStyle( QFrame::Panel | QFrame::Sunken );
40 43
41 connect(browser,SIGNAL(textChanged()),this,SLOT(textChanged())); 44 connect(browser,SIGNAL(textChanged()),this,SLOT(textChanged()));
42 45
43 setCentralWidget( browser ); 46 setCentralWidget( browser );
44 47
45 if ( !home_.isEmpty() ) 48 if ( !home_.isEmpty() )
46 49
47//////////////////////////////// 50////////////////////////////////
48 browser->setSource( home_ ); 51 browser->setSource( home_ );
49 52
50//////////////////////////////// 53////////////////////////////////
51 connect( browser, SIGNAL( highlighted( const QString&) ), 54 connect( browser, SIGNAL( highlighted( const QString&) ),
52 statusBar(), SLOT( message( const QString&)) ); 55 statusBar(), SLOT( message( const QString&)) );
53 56
54// resize( 640,600 ); 57// resize( 640,600 );
55#ifdef Q_WS_QWS 58#ifdef Q_WS_QWS
56 setGeometry( 0,0,236,280); 59 setGeometry( 0,0,236,280);
57#else 60#else
58 setGeometry( 10,30,520,420 ); 61 setGeometry( 10,30,520,420 );
59// resize(520,420); 62// resize(520,420);
60#endif 63#endif
61 64
62 QPopupMenu* file = new QPopupMenu( this ); 65 QPopupMenu* file = new QPopupMenu( this );
63// file->insertItem( tr("&New Window"), this, SLOT( newWindow() ), ALT | Key_N ); 66// file->insertItem( tr("&New Window"), this, SLOT( newWindow() ), ALT | Key_N );
64 file->insertItem( tr("&Open File"), this, SLOT( openFile() ), ALT | Key_O ); 67 file->insertItem( tr("&Open File"), this, SLOT( openFile() ), ALT | Key_O );
65// file->insertItem( tr("&Print"), this, SLOT( print() ), ALT | Key_P ); 68// file->insertItem( tr("&Print"), this, SLOT( print() ), ALT | Key_P );
66 file->insertSeparator(); 69 file->insertSeparator();
67 file->insertItem( tr("&Close"), this, SLOT( close() ), ALT | Key_Q ); 70 file->insertItem( tr("&Close"), this, SLOT( close() ), ALT | Key_Q );
68// file->insertItem( tr("E&xit"), qApp, SLOT( closeAllWindows() ), ALT | Key_X ); 71// file->insertItem( tr("E&xit"), qApp, SLOT( closeAllWindows() ), ALT | Key_X );
69 72
70 // The same three icons are used twice each. 73 // The same three icons are used twice each.
71////F FIXME 74////F FIXME
72 QString pixs=(QDir::homeDirPath ()) +"/Applications/gutenbrowser/pix/"; 75 QString pixs=(QDir::homeDirPath ()) +"/Applications/gutenbrowser/pix/";
73 QIconSet icon_back( QPixmap(pixs+"back.png") ); 76 QIconSet icon_back( QPixmap(pixs+"back.png") );
74 QIconSet icon_forward( QPixmap(pixs+"forward.png") ); 77 QIconSet icon_forward( QPixmap(pixs+"forward.png") );
75 QIconSet icon_home( QPixmap(pixs+"home.png") ); 78 QIconSet icon_home( QPixmap(pixs+"home.png") );
76 79
77 QPopupMenu* go = new QPopupMenu( this ); 80 QPopupMenu* go = new QPopupMenu( this );
78 backwardId = go->insertItem( icon_back, tr("&Backward"), browser, SLOT( backward() ), ALT | Key_Left ); 81 backwardId = go->insertItem( icon_back, tr("&Backward"), browser, SLOT( backward() ), ALT | Key_Left );
79 forwardId = go->insertItem( icon_forward, tr("&Forward"), browser, SLOT( forward() ), ALT | Key_Right ); 82 forwardId = go->insertItem( icon_forward, tr("&Forward"), browser, SLOT( forward() ), ALT | Key_Right );
80 go->insertItem( icon_home, tr("&Home"), browser, SLOT( home() ) ); 83 go->insertItem( icon_home, tr("&Home"), browser, SLOT( home() ) );
81 84
82// QPopupMenu* help = new QPopupMenu( this ); 85// QPopupMenu* help = new QPopupMenu( this );
83// help->insertItem( tr("&About ..."), this, SLOT( about() ) ); 86// help->insertItem( tr("&About ..."), this, SLOT( about() ) );
84// help->insertItem( tr("About &Qt ..."), this, SLOT( aboutQt() ) ); 87// help->insertItem( tr("About &Qt ..."), this, SLOT( aboutQt() ) );
85 88
86 89
87 hist = new QPopupMenu( this ); 90 hist = new QPopupMenu( this );
88 QStringList::Iterator it = history.begin(); 91 QStringList::Iterator it = history.begin();
89 for ( ; it != history.end(); ++it ) 92 for ( ; it != history.end(); ++it )
90 mHistory[ hist->insertItem( *it ) ] = *it; 93 mHistory[ hist->insertItem( *it ) ] = *it;
91 connect( hist, SIGNAL( activated( int ) ), this, SLOT( histChosen( int ) ) ); 94 connect( hist, SIGNAL( activated( int ) ), this, SLOT( histChosen( int ) ) );
92 95
93 bookm = new QPopupMenu( this ); 96 bookm = new QPopupMenu( this );
94 bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) ); 97 bookm->insertItem( tr( "Add Bookmark" ), this, SLOT( addBookmark() ) );
95 bookm->insertSeparator(); 98 bookm->insertSeparator();
96 99
97 QStringList::Iterator it2 = bookmarks.begin(); 100 QStringList::Iterator it2 = bookmarks.begin();
98 for ( ; it2 != bookmarks.end(); ++it2 ) 101 for ( ; it2 != bookmarks.end(); ++it2 )
99 mBookmarks[ bookm->insertItem( *it2 ) ] = *it2; 102 mBookmarks[ bookm->insertItem( *it2 ) ] = *it2;
100 connect( bookm, SIGNAL( activated( int ) ), 103 connect( bookm, SIGNAL( activated( int ) ),
101 this, SLOT( bookmChosen( int ) ) ); 104 this, SLOT( bookmChosen( int ) ) );
102 105
103 menuBar()->insertItem( tr("&File"), file ); 106 menuBar()->insertItem( tr("&File"), file );
104 menuBar()->insertItem( tr("&Go"), go ); 107 menuBar()->insertItem( tr("&Go"), go );
105 menuBar()->insertItem( tr( "History" ), hist ); 108 menuBar()->insertItem( tr( "History" ), hist );
106 menuBar()->insertItem( tr( "Bookmarks" ), bookm ); 109 menuBar()->insertItem( tr( "Bookmarks" ), bookm );
107// menuBar()->insertSeparator(); 110// menuBar()->insertSeparator();
108// menuBar()->insertItem( tr("&Help"), help ); 111// menuBar()->insertItem( tr("&Help"), help );
109 112
110 menuBar()->setItemEnabled( forwardId, FALSE); 113 menuBar()->setItemEnabled( forwardId, FALSE);
111 menuBar()->setItemEnabled( backwardId, FALSE); 114 menuBar()->setItemEnabled( backwardId, FALSE);
112 connect( browser, SIGNAL( backwardAvailable( bool ) ), this, SLOT( setBackwardAvailable( bool ) ) ); 115 connect( browser, SIGNAL( backwardAvailable( bool ) ), this, SLOT( setBackwardAvailable( bool ) ) );
113 connect( browser, SIGNAL( forwardAvailable( bool ) ), this, SLOT( setForwardAvailable( bool ) ) ); 116 connect( browser, SIGNAL( forwardAvailable( bool ) ), this, SLOT( setForwardAvailable( bool ) ) );
114 117
115 118
116 QToolBar* toolbar = new QToolBar( this ); 119 QToolBar* toolbar = new QToolBar( this );
117 addToolBar( toolbar, "Toolbar"); 120 addToolBar( toolbar, "Toolbar");
118 QToolButton* button; 121 QToolButton* button;
119 122
120 button = new QToolButton( icon_back, tr("Backward"), "", browser, SLOT(backward()), toolbar ); 123 button = new QToolButton( icon_back, tr("Backward"), "", browser, SLOT(backward()), toolbar );
121 connect( browser, SIGNAL( backwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) ); 124 connect( browser, SIGNAL( backwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) );
122 button->setEnabled( FALSE ); 125 button->setEnabled( FALSE );
123 button = new QToolButton( icon_forward, tr("Forward"), "", browser, SLOT(forward()), toolbar ); 126 button = new QToolButton( icon_forward, tr("Forward"), "", browser, SLOT(forward()), toolbar );
124 connect( browser, SIGNAL( forwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) ); 127 connect( browser, SIGNAL( forwardAvailable(bool) ), button, SLOT( setEnabled(bool) ) );
125 button->setEnabled( FALSE ); 128 button->setEnabled( FALSE );
126 button = new QToolButton( icon_home, tr("Home"), "", browser, SLOT(home()), toolbar ); 129 button = new QToolButton( icon_home, tr("Home"), "", browser, SLOT(home()), toolbar );
127 130
128 toolbar->addSeparator(); 131 toolbar->addSeparator();
129 132
130 pathCombo = new QComboBox( TRUE, toolbar ); 133 pathCombo = new QComboBox( TRUE, toolbar );
131 connect( pathCombo, SIGNAL( activated( const QString & ) ), this, SLOT( pathSelected( const QString & ) ) ); 134 connect( pathCombo, SIGNAL( activated( const QString & ) ), this, SLOT( pathSelected( const QString & ) ) );
132 toolbar->setStretchableWidget( pathCombo ); 135 toolbar->setStretchableWidget( pathCombo );
133 136
134// pathCombo->setMaximumWidth(190); 137// pathCombo->setMaximumWidth(190);
135// setRightJustification( TRUE ); 138// setRightJustification( TRUE );
136// setDockEnabled( Left, FALSE ); 139// setDockEnabled( Left, FALSE );
137// setDockEnabled( Right, FALSE ); 140// setDockEnabled( Right, FALSE );
138 141
139 pathCombo->insertItem( home_ ); 142 pathCombo->insertItem( home_ );
140 143
141 browser->setFocus(); 144 browser->setFocus();
142 145
143 146
144} 147}
145 148
146 149
147void HelpWindow::setBackwardAvailable( bool b) 150void HelpWindow::setBackwardAvailable( bool b)
148{ 151{
149 menuBar()->setItemEnabled( backwardId, b); 152 menuBar()->setItemEnabled( backwardId, b);
150} 153}
151 154
152void HelpWindow::setForwardAvailable( bool b) 155void HelpWindow::setForwardAvailable( bool b)
153{ 156{
154 menuBar()->setItemEnabled( forwardId, b); 157 menuBar()->setItemEnabled( forwardId, b);
155} 158}
156 159
157 160
158void HelpWindow::textChanged() 161void HelpWindow::textChanged()
159{ 162{
160 if ( browser->documentTitle().isNull() ) { 163 if ( browser->documentTitle().isNull() ) {
161 setCaption( "Gutenbrowser - Helpviewer - " + browser->context() ); 164 setCaption( "Gutenbrowser - Helpviewer - " + browser->context() );
162 selectedURL = browser->context(); 165 selectedURL = browser->context();
163 } 166 }
164 else { 167 else {
165 setCaption( "Gutenbrowser - Helpviewer - " + browser->documentTitle() ) ; 168 setCaption( "Gutenbrowser - Helpviewer - " + browser->documentTitle() ) ;
166 selectedURL = browser->documentTitle(); 169 selectedURL = browser->documentTitle();
167 } 170 }
168 171
169 if ( !selectedURL.isEmpty() && pathCombo ) { 172 if ( !selectedURL.isEmpty() && pathCombo ) {
170 bool exists = FALSE; 173 bool exists = FALSE;
171 int i; 174 int i;
172 for ( i = 0; i < pathCombo->count(); ++i ) { 175 for ( i = 0; i < pathCombo->count(); ++i ) {
173 if ( pathCombo->text( i ) == selectedURL ) { 176 if ( pathCombo->text( i ) == selectedURL ) {
174 exists = TRUE; 177 exists = TRUE;
175 break; 178 break;
176 } 179 }
177 } 180 }
178 if ( !exists ) { 181 if ( !exists ) {
179 pathCombo->insertItem( selectedURL, 0 ); 182 pathCombo->insertItem( selectedURL, 0 );
180 pathCombo->setCurrentItem( 0 ); 183 pathCombo->setCurrentItem( 0 );
181 mHistory[ hist->insertItem( selectedURL ) ] = selectedURL; 184 mHistory[ hist->insertItem( selectedURL ) ] = selectedURL;
182 } else 185 } else
183 pathCombo->setCurrentItem( i ); 186 pathCombo->setCurrentItem( i );
184 selectedURL = QString::null; 187 selectedURL = QString::null;
185 } 188 }
186} 189}
187 190
188HelpWindow::~HelpWindow() 191HelpWindow::~HelpWindow()
189{ 192{
190 history.clear(); 193 history.clear();
191 QMap<int, QString>::Iterator it = mHistory.begin(); 194 QMap<int, QString>::Iterator it = mHistory.begin();
192 for ( ; it != mHistory.end(); ++it ) 195 for ( ; it != mHistory.end(); ++it )
193 history.append( *it ); 196 history.append( *it );
194 197
195 QFile f( QDir::currentDirPath() + "/.history" ); 198 QFile f( QDir::currentDirPath() + "/.history" );
196 f.open( IO_WriteOnly ); 199 f.open( IO_WriteOnly );
197 QDataStream s( &f ); 200 QDataStream s( &f );
198 s << history; 201 s << history;
199 f.close(); 202 f.close();
200 203
201 bookmarks.clear(); 204 bookmarks.clear();
202 QMap<int, QString>::Iterator it2 = mBookmarks.begin(); 205 QMap<int, QString>::Iterator it2 = mBookmarks.begin();
203 for ( ; it2 != mBookmarks.end(); ++it2 ) 206 for ( ; it2 != mBookmarks.end(); ++it2 )
204 bookmarks.append( *it2 ); 207 bookmarks.append( *it2 );
205 208
206 QFile f2( QDir::currentDirPath() + "/.bookmarks" ); 209 QFile f2( QDir::currentDirPath() + "/.bookmarks" );
207 f2.open( IO_WriteOnly ); 210 f2.open( IO_WriteOnly );
208 QDataStream s2( &f2 ); 211 QDataStream s2( &f2 );
209 s2 << bookmarks; 212 s2 << bookmarks;
210 f2.close(); 213 f2.close();
211} 214}
212 215
213// void HelpWindow::about() 216// void HelpWindow::about()
214// { 217// {
215// QMessageBox::about( this, "Gutenbrowser", "<p>Thanks to Trolltech for this</p>" ); 218// QMessageBox::about( this, "Gutenbrowser", "<p>Thanks to Trolltech for this</p>" );
216// } 219// }
217 220
218// void HelpWindow::aboutQt() 221// void HelpWindow::aboutQt()
219// { 222// {
220// QMessageBox::aboutQt( this, "QBrowser" ); 223// QMessageBox::aboutQt( this, "QBrowser" );
221// } 224// }
222 225
223void HelpWindow::openFile() 226void HelpWindow::openFile()
224{ 227{
225#ifndef QT_NO_FILEDIALOG 228#ifndef QT_NO_FILEDIALOG
226 QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this ); 229 QString fn = QFileDialog::getOpenFileName( QString::null, QString::null, this );
227 if ( !fn.isEmpty() ) 230 if ( !fn.isEmpty() )
228 browser->setSource( fn ); 231 browser->setSource( fn );
229#endif 232#endif
230} 233}
231 234
232void HelpWindow::newWindow() 235void HelpWindow::newWindow()
233{ 236{
234 ( new HelpWindow(browser->source(), "qbrowser") )->show(); 237 ( new HelpWindow(browser->source(), "qbrowser") )->show();
235} 238}
236 239
237void HelpWindow::print() 240void HelpWindow::print()
238{ 241{
239#ifndef QT_NO_PRINTER 242#ifndef QT_NO_PRINTER
240 QPrinter printer; 243 QPrinter printer;
241 printer.setFullPage(TRUE); 244 printer.setFullPage(TRUE);
242 if ( printer.setup() ) { 245 if ( printer.setup() ) {
243 QPainter p( &printer ); 246 QPainter p( &printer );
244 QPaintDeviceMetrics metrics(p.device()); 247 QPaintDeviceMetrics metrics(p.device());
245 int dpix = metrics.logicalDpiX(); 248 int dpix = metrics.logicalDpiX();
246 int dpiy = metrics.logicalDpiY(); 249 int dpiy = metrics.logicalDpiY();
247 const int margin = 72; // pt 250 const int margin = 72; // pt
248 QRect body(margin*dpix/72, margin*dpiy/72, 251 QRect body(margin*dpix/72, margin*dpiy/72,
249 metrics.width()-margin*dpix/72*2, 252 metrics.width()-margin*dpix/72*2,
250 metrics.height()-margin*dpiy/72*2 ); 253 metrics.height()-margin*dpiy/72*2 );
251 QFont font("times", 10); 254 QFont font("times", 10);
252 QSimpleRichText richText( browser->text(), font, browser->context(), browser->styleSheet(), 255 QSimpleRichText richText( browser->text(), font, browser->context(), browser->styleSheet(),
253 browser->mimeSourceFactory(), body.height() ); 256 browser->mimeSourceFactory(), body.height() );
254 richText.setWidth( &p, body.width() ); 257 richText.setWidth( &p, body.width() );
255 QRect view( body ); 258 QRect view( body );
256 int page = 1; 259 int page = 1;
257 do { 260 do {
258 p.setClipRect( body ); 261 p.setClipRect( body );
259 richText.draw( &p, body.left(), body.top(), view, colorGroup() ); 262 richText.draw( &p, body.left(), body.top(), view, colorGroup() );
260 p.setClipping( FALSE ); 263 p.setClipping( FALSE );
261 view.moveBy( 0, body.height() ); 264 view.moveBy( 0, body.height() );
262 p.translate( 0 , -body.height() ); 265 p.translate( 0 , -body.height() );
263 p.setFont( font ); 266 p.setFont( font );
264 p.drawText( view.right() - p.fontMetrics().width( QString::number(page) ), 267 p.drawText( view.right() - p.fontMetrics().width( QString::number(page) ),
265 view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page) ); 268 view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page) );
266 if ( view.top() >= richText.height() ) 269 if ( view.top() >= richText.height() )
267 break; 270 break;
268 printer.newPage(); 271 printer.newPage();
269 page++; 272 page++;
270 } while (TRUE); 273 } while (TRUE);
271 } 274 }
272#endif 275#endif
273} 276}
274 277
275void HelpWindow::pathSelected( const QString &_path ) 278void HelpWindow::pathSelected( const QString &_path )
276{ 279{
277 browser->setSource( _path ); 280 browser->setSource( _path );
278 QMap<int, QString>::Iterator it = mHistory.begin(); 281 QMap<int, QString>::Iterator it = mHistory.begin();
279 bool exists = FALSE; 282 bool exists = FALSE;
280 for ( ; it != mHistory.end(); ++it ) { 283 for ( ; it != mHistory.end(); ++it ) {
281 if ( *it == _path ) { 284 if ( *it == _path ) {
282 exists = TRUE; 285 exists = TRUE;
283 break; 286 break;
284 } 287 }
285 } 288 }
286 if ( !exists ) 289 if ( !exists )