[191] | 1 | /**********************************************************************
|
---|
| 2 | ** Copyright (C) 2000-2007 Trolltech ASA. All rights reserved.
|
---|
| 3 | **
|
---|
| 4 | ** This file is part of the Qt Assistant.
|
---|
| 5 | **
|
---|
| 6 | ** This file may be distributed and/or modified under the terms of the
|
---|
| 7 | ** GNU General Public License version 2 as published by the Free Software
|
---|
| 8 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 9 | ** packaging of this file.
|
---|
| 10 | **
|
---|
| 11 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
| 12 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
| 13 | ** Agreement provided with the Software.
|
---|
| 14 | **
|
---|
| 15 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
| 16 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
| 17 | **
|
---|
| 18 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
| 19 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
| 20 | ** information about Qt Commercial License Agreements.
|
---|
| 21 | **
|
---|
| 22 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
| 23 | ** not clear to you.
|
---|
| 24 | **
|
---|
| 25 | **********************************************************************/
|
---|
| 26 |
|
---|
| 27 | #include "config.h"
|
---|
| 28 |
|
---|
| 29 | #include <qtabwidget.h>
|
---|
| 30 | #include <qfileinfo.h>
|
---|
| 31 | #include <qaccel.h>
|
---|
| 32 | #include <qobjectlist.h>
|
---|
| 33 | #include <qtimer.h>
|
---|
| 34 | #include <qdragobject.h>
|
---|
| 35 | #include <qfontinfo.h>
|
---|
| 36 | #include <qaccel.h>
|
---|
| 37 | #include <qmetaobject.h>
|
---|
| 38 | #include <qeventloop.h>
|
---|
| 39 |
|
---|
| 40 | QPtrList<MainWindow> *MainWindow::windows = 0;
|
---|
| 41 |
|
---|
| 42 | #if defined(Q_WS_WIN)
|
---|
| 43 | extern Q_EXPORT int qt_ntfs_permission_lookup;
|
---|
| 44 | #endif
|
---|
| 45 |
|
---|
| 46 | void MainWindow::init()
|
---|
| 47 | {
|
---|
| 48 | #if defined(Q_WS_WIN)
|
---|
| 49 | // Workaround for QMimeSourceFactory failing in QFileInfo::isReadable() for
|
---|
| 50 | // certain user configs. See task: 34372
|
---|
| 51 | qt_ntfs_permission_lookup = 0;
|
---|
| 52 | #endif
|
---|
| 53 | setupCompleted = FALSE;
|
---|
| 54 |
|
---|
| 55 | goActions = new QPtrList<QAction>;
|
---|
| 56 | goActionDocFiles = new QMap<QAction*,QString>;
|
---|
| 57 | goActions->setAutoDelete( TRUE );
|
---|
| 58 |
|
---|
| 59 | if ( !windows )
|
---|
| 60 | windows = new QPtrList<MainWindow>;
|
---|
| 61 | windows->append( this );
|
---|
| 62 | tabs = new TabbedBrowser( this, "qt_assistant_tabbedbrowser" );
|
---|
| 63 | setCentralWidget( tabs );
|
---|
| 64 | settingsDia = 0;
|
---|
| 65 |
|
---|
| 66 | Config *config = Config::configuration();
|
---|
| 67 |
|
---|
| 68 | updateProfileSettings();
|
---|
| 69 |
|
---|
| 70 | dw = new QDockWindow( QDockWindow::InDock, this );
|
---|
| 71 | helpDock = new HelpDialog( dw, this );
|
---|
| 72 | dw->setResizeEnabled( TRUE );
|
---|
| 73 | dw->setCloseMode( QDockWindow::Always );
|
---|
| 74 | addDockWindow( dw, DockLeft );
|
---|
| 75 | dw->setWidget( helpDock );
|
---|
| 76 | dw->setCaption( "Sidebar" );
|
---|
| 77 | dw->setFixedExtentWidth( 320 );
|
---|
| 78 |
|
---|
| 79 | // read geometry configuration
|
---|
| 80 | setupGoActions();
|
---|
| 81 |
|
---|
| 82 | if ( !config->isMaximized() ) {
|
---|
| 83 | QRect geom = config->geometry();
|
---|
| 84 | if( geom.isValid() ) {
|
---|
| 85 | resize(geom.size());
|
---|
| 86 | move(geom.topLeft());
|
---|
| 87 | }
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | QString mainWindowLayout = config->mainWindowLayout();
|
---|
| 91 |
|
---|
| 92 | QTextStream ts( &mainWindowLayout, IO_ReadOnly );
|
---|
| 93 | ts >> *this;
|
---|
| 94 |
|
---|
| 95 | if ( config->sideBarHidden() )
|
---|
| 96 | dw->hide();
|
---|
| 97 |
|
---|
| 98 | tabs->setup();
|
---|
| 99 | QTimer::singleShot( 0, this, SLOT( setup() ) );
|
---|
| 100 | #if defined(Q_OS_MACX)
|
---|
| 101 | // Use the same forward and backward browser shortcuts as Safari and Internet Explorer do
|
---|
| 102 | // on the Mac. This means that if you have access to one of those cool Intellimice, the thing
|
---|
| 103 | // works just fine, since that's how Microsoft hacked it.
|
---|
| 104 | actionGoPrevious->setAccel(QKeySequence(Qt::CTRL|Qt::Key_Left));
|
---|
| 105 | actionGoNext->setAccel(QKeySequence(Qt::CTRL|Qt::Key_Right));
|
---|
| 106 | #endif
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | void MainWindow::setup()
|
---|
| 110 | {
|
---|
| 111 | if( setupCompleted )
|
---|
| 112 | return;
|
---|
| 113 |
|
---|
| 114 | qApp->setOverrideCursor( QCursor( Qt::WaitCursor ) );
|
---|
| 115 | statusBar()->message( tr( "Initializing Qt Assistant..." ) );
|
---|
| 116 | setupCompleted = TRUE;
|
---|
| 117 | helpDock->initialize();
|
---|
| 118 | connect( actionGoPrevious, SIGNAL( activated() ), tabs, SLOT( backward() ) );
|
---|
| 119 | connect( actionGoNext, SIGNAL( activated() ), tabs, SLOT( forward() ) );
|
---|
| 120 | connect( actionEditCopy, SIGNAL( activated() ), tabs, SLOT( copy() ) );
|
---|
| 121 | connect( actionFileExit, SIGNAL( activated() ), qApp, SLOT( closeAllWindows() ) );
|
---|
| 122 | connect( actionAddBookmark, SIGNAL( activated() ),
|
---|
| 123 | helpDock, SLOT( addBookmark() ) );
|
---|
| 124 | connect( helpDock, SIGNAL( showLink( const QString& ) ),
|
---|
| 125 | this, SLOT( showLink( const QString& ) ) );
|
---|
| 126 | connect( helpDock, SIGNAL( showSearchLink( const QString&, const QStringList& ) ),
|
---|
| 127 | this, SLOT( showSearchLink( const QString&, const QStringList&) ) );
|
---|
| 128 |
|
---|
| 129 | connect( bookmarkMenu, SIGNAL( activated( int ) ),
|
---|
| 130 | this, SLOT( showBookmark( int ) ) );
|
---|
| 131 | connect( actionZoomIn, SIGNAL( activated() ), tabs, SLOT( zoomIn() ) );
|
---|
| 132 | connect( actionZoomOut, SIGNAL( activated() ), tabs, SLOT( zoomOut() ) );
|
---|
| 133 |
|
---|
| 134 | connect( actionOpenPage, SIGNAL( activated() ), tabs, SLOT( newTab() ) );
|
---|
| 135 | connect( actionClosePage, SIGNAL( activated() ), tabs, SLOT( closeTab() ) );
|
---|
| 136 | connect( actionNextPage, SIGNAL( activated() ), tabs, SLOT( nextTab() ) );
|
---|
| 137 | connect( actionPrevPage, SIGNAL( activated() ), tabs, SLOT( previousTab() ) );
|
---|
| 138 |
|
---|
| 139 |
|
---|
| 140 |
|
---|
| 141 | #if defined(Q_OS_WIN32) || defined(Q_OS_WIN64)
|
---|
| 142 | QAccel *acc = new QAccel( this );
|
---|
| 143 | // acc->connectItem( acc->insertItem( Key_F5 ), browser, SLOT( reload() ) );
|
---|
| 144 | acc->connectItem( acc->insertItem( QKeySequence("SHIFT+CTRL+=") ), actionZoomIn, SIGNAL(activated()) );
|
---|
| 145 | #endif
|
---|
| 146 |
|
---|
| 147 | QAccel *a = new QAccel( this, dw );
|
---|
| 148 | a->connectItem( a->insertItem( QAccel::stringToKey( tr("Ctrl+T") ) ),
|
---|
| 149 | helpDock, SLOT( toggleContents() ) );
|
---|
| 150 | a->connectItem( a->insertItem( QAccel::stringToKey( tr("Ctrl+I") ) ),
|
---|
| 151 | helpDock, SLOT( toggleIndex() ) );
|
---|
| 152 | a->connectItem( a->insertItem( QAccel::stringToKey( tr("Ctrl+B") ) ),
|
---|
| 153 | helpDock, SLOT( toggleBookmarks() ) );
|
---|
| 154 | a->connectItem( a->insertItem( QAccel::stringToKey( tr("Ctrl+S") ) ),
|
---|
| 155 | helpDock, SLOT( toggleSearch() ) );
|
---|
| 156 |
|
---|
| 157 | Config *config = Config::configuration();
|
---|
| 158 |
|
---|
| 159 | setupBookmarkMenu();
|
---|
| 160 | PopupMenu->insertItem( tr( "Vie&ws" ), createDockWindowMenu() );
|
---|
| 161 | helpDock->tabWidget->setCurrentPage( config->sideBarPage() );
|
---|
| 162 |
|
---|
| 163 | qApp->restoreOverrideCursor();
|
---|
| 164 | actionGoPrevious->setEnabled( FALSE );
|
---|
| 165 | actionGoNext->setEnabled( FALSE );
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | void MainWindow::setupGoActions()
|
---|
| 169 | {
|
---|
| 170 | Config *config = Config::configuration();
|
---|
| 171 | QStringList titles = config->docTitles();
|
---|
| 172 | QAction *action = 0;
|
---|
| 173 |
|
---|
| 174 | static bool separatorInserted = FALSE;
|
---|
| 175 |
|
---|
| 176 | QAction *cur = goActions->first();
|
---|
| 177 | while( cur ) {
|
---|
| 178 | cur->removeFrom( goMenu );
|
---|
| 179 | cur->removeFrom( goActionToolbar );
|
---|
| 180 | cur = goActions->next();
|
---|
| 181 | }
|
---|
| 182 | goActions->clear();
|
---|
| 183 | goActionDocFiles->clear();
|
---|
| 184 |
|
---|
| 185 | int addCount = 0;
|
---|
| 186 |
|
---|
| 187 | QStringList::ConstIterator it = titles.begin();
|
---|
| 188 | for ( ; it != titles.end(); ++it ) {
|
---|
| 189 | QString title = *it;
|
---|
| 190 | QPixmap pix = config->docIcon( title );
|
---|
| 191 | if( !pix.isNull() ) {
|
---|
| 192 | if( !separatorInserted ) {
|
---|
| 193 | goMenu->insertSeparator();
|
---|
| 194 | separatorInserted = TRUE;
|
---|
| 195 | }
|
---|
| 196 | action = new QAction( title, QIconSet( pix ), title, 0, 0 );
|
---|
| 197 | action->addTo( goMenu );
|
---|
| 198 | action->addTo( goActionToolbar );
|
---|
| 199 | goActions->append( action );
|
---|
| 200 | goActionDocFiles->insert( action, config->indexPage( title ) );
|
---|
| 201 | connect( action, SIGNAL( activated() ),
|
---|
| 202 | this, SLOT( showGoActionLink() ) );
|
---|
| 203 | ++addCount;
|
---|
| 204 | }
|
---|
| 205 | }
|
---|
| 206 | if( !addCount )
|
---|
| 207 | goActionToolbar->hide();
|
---|
| 208 | else
|
---|
| 209 | goActionToolbar->show();
|
---|
| 210 |
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | void MainWindow::browserTabChanged()
|
---|
| 214 | {
|
---|
| 215 | if (tabs->currentBrowser()) {
|
---|
| 216 | actionGoPrevious->setEnabled(tabs->currentBrowser()->isBackwardAvailable());
|
---|
| 217 | actionGoNext->setEnabled(tabs->currentBrowser()->isForwardAvailable());
|
---|
| 218 | }
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | bool MainWindow::insertActionSeparator()
|
---|
| 222 | {
|
---|
| 223 | goMenu->insertSeparator();
|
---|
| 224 | Toolbar->addSeparator();
|
---|
| 225 | return TRUE;
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | bool MainWindow::close( bool alsoDelete )
|
---|
| 229 | {
|
---|
| 230 | saveSettings();
|
---|
| 231 | return QMainWindow::close( alsoDelete );
|
---|
| 232 | }
|
---|
| 233 |
|
---|
| 234 | void MainWindow::destroy()
|
---|
| 235 | {
|
---|
| 236 | windows->removeRef( this );
|
---|
| 237 | if ( windows->isEmpty() ) {
|
---|
| 238 | delete windows;
|
---|
| 239 | windows = 0;
|
---|
| 240 | }
|
---|
| 241 | delete goActions;
|
---|
| 242 | delete goActionDocFiles;
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | void MainWindow::about()
|
---|
| 246 | {
|
---|
| 247 | QMessageBox box( this );
|
---|
| 248 | box.setText( "<center><img src=\"splash.png\">"
|
---|
| 249 | "<p>Version " + QString(QT_VERSION_STR) + "</p>"
|
---|
| 250 | "<p>Copyright (C) 2000-2007 Trolltech ASA. All rights reserved."
|
---|
| 251 | "</p></center><p></p>"
|
---|
| 252 | "<p>Qt Commercial Edition license holders: This program is"
|
---|
| 253 | " licensed to you under the terms of the Qt Commercial License"
|
---|
| 254 | " Agreement. For details, see the file LICENSE that came with"
|
---|
| 255 | " this software distribution.</p><p></p>"
|
---|
| 256 | "<p>Qt Open Source Edition users: This program is licensed to you"
|
---|
| 257 | " under the terms of the GNU General Public License Version 2."
|
---|
| 258 | " For details, see the file LICENSE.GPL that came with this"
|
---|
| 259 | " software distribution.</p><p>The program is provided AS IS"
|
---|
| 260 | " with NO WARRANTY OF ANY KIND, INCLUDING THE WARRANTY OF"
|
---|
| 261 | " DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE."
|
---|
| 262 | "</p>" );
|
---|
| 263 | box.setCaption( tr( "Qt Assistant" ) );
|
---|
| 264 | box.setIcon( QMessageBox::NoIcon );
|
---|
| 265 | box.exec();
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | void MainWindow::aboutApplication()
|
---|
| 269 | {
|
---|
| 270 | QString url = Config::configuration()->aboutURL();
|
---|
| 271 | if ( url == "about_qt" ) {
|
---|
| 272 | QMessageBox::aboutQt( this, "Qt Assistant" );
|
---|
| 273 | return;
|
---|
| 274 | }
|
---|
| 275 | QString text;
|
---|
| 276 | QFile file( url );
|
---|
| 277 | if( file.exists() && file.open( IO_ReadOnly ) )
|
---|
| 278 | text = QString( file.readAll() );
|
---|
| 279 | if( text.isNull() )
|
---|
| 280 | text = tr( "Failed to open about application contents in file: '%1'" ).arg( url );
|
---|
| 281 |
|
---|
| 282 | QMessageBox box( this );
|
---|
| 283 | box.setText( text );
|
---|
| 284 | box.setCaption( Config::configuration()->aboutApplicationMenuText() );
|
---|
| 285 | box.setIcon( QMessageBox::NoIcon );
|
---|
| 286 | box.exec();
|
---|
| 287 | }
|
---|
| 288 |
|
---|
| 289 | void MainWindow::find()
|
---|
| 290 | {
|
---|
| 291 | if ( !findDialog )
|
---|
| 292 | findDialog = new FindDialog( this );
|
---|
| 293 | findDialog->comboFind->setFocus();
|
---|
| 294 | findDialog->comboFind->lineEdit()->setSelection(
|
---|
| 295 | 0, findDialog->comboFind->lineEdit()->text().length() );
|
---|
| 296 | findDialog->show();
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 | void MainWindow::findAgain()
|
---|
| 300 | {
|
---|
| 301 | if (!findDialog || !findDialog->hasFindExpression()) {
|
---|
| 302 | find();
|
---|
| 303 | return;
|
---|
| 304 | }
|
---|
| 305 | findDialog->doFind(TRUE);
|
---|
| 306 | }
|
---|
| 307 |
|
---|
| 308 | void MainWindow::findAgainPrev()
|
---|
| 309 | {
|
---|
| 310 | if (!findDialog || !findDialog->hasFindExpression()) {
|
---|
| 311 | find();
|
---|
| 312 | return;
|
---|
| 313 | }
|
---|
| 314 | findDialog->doFind(FALSE);
|
---|
| 315 | }
|
---|
| 316 |
|
---|
| 317 | void MainWindow::goHome()
|
---|
| 318 | {
|
---|
| 319 | showLink( Config::configuration()->homePage() );
|
---|
| 320 | }
|
---|
| 321 |
|
---|
| 322 | void MainWindow::print()
|
---|
| 323 | {
|
---|
| 324 | #ifndef QT_NO_PRINTER
|
---|
| 325 | QPrinter printer( QPrinter::HighResolution );
|
---|
| 326 | printer.setFullPage( TRUE );
|
---|
| 327 | if ( printer.setup( this ) ) {
|
---|
| 328 | QPainter p;
|
---|
| 329 | if ( !p.begin( &printer ) )
|
---|
| 330 | return;
|
---|
| 331 |
|
---|
| 332 | qApp->setOverrideCursor( QCursor( Qt::WaitCursor ) );
|
---|
| 333 | qApp->eventLoop()->processEvents( QEventLoop::ExcludeUserInput );
|
---|
| 334 |
|
---|
| 335 | QPaintDeviceMetrics metrics(p.device());
|
---|
| 336 | QTextBrowser *browser = tabs->currentBrowser();
|
---|
| 337 | int dpiy = metrics.logicalDpiY();
|
---|
| 338 | int margin = (int) ( (2/2.54)*dpiy );
|
---|
| 339 | QRect view( margin,
|
---|
| 340 | margin,
|
---|
| 341 | metrics.width() - 2 * margin,
|
---|
| 342 | metrics.height() - 2 * margin );
|
---|
| 343 | QSimpleRichText richText( browser->text(), browser->QWidget::font(), browser->context(),
|
---|
| 344 | browser->styleSheet(), browser->mimeSourceFactory(),
|
---|
| 345 | view.height(), Qt::black, FALSE );
|
---|
| 346 | richText.setWidth( &p, view.width() );
|
---|
| 347 | int page = 1;
|
---|
| 348 | do {
|
---|
| 349 | qApp->eventLoop()->processEvents( QEventLoop::ExcludeUserInput );
|
---|
| 350 |
|
---|
| 351 | richText.draw( &p, margin, margin, view, palette().active() );
|
---|
| 352 | view.moveBy( 0, view.height() );
|
---|
| 353 | p.translate( 0 , -view.height() );
|
---|
| 354 | p.drawText( view.right() - p.fontMetrics().width( QString::number(page) ),
|
---|
| 355 | view.bottom() + p.fontMetrics().ascent() + 5, QString::number(page) );
|
---|
| 356 | if ( view.top() - margin >= richText.height() )
|
---|
| 357 | break;
|
---|
| 358 | printer.newPage();
|
---|
| 359 | page++;
|
---|
| 360 | } while (TRUE);
|
---|
| 361 |
|
---|
| 362 | qApp->eventLoop()->processEvents( QEventLoop::ExcludeUserInput );
|
---|
| 363 | qApp->restoreOverrideCursor();
|
---|
| 364 | }
|
---|
| 365 | #endif
|
---|
| 366 | }
|
---|
| 367 |
|
---|
| 368 | void MainWindow::updateBookmarkMenu()
|
---|
| 369 | {
|
---|
| 370 | for ( MainWindow *mw = windows->first(); mw; mw = windows->next() )
|
---|
| 371 | mw->setupBookmarkMenu();
|
---|
| 372 | }
|
---|
| 373 |
|
---|
| 374 | void MainWindow::setupBookmarkMenu()
|
---|
| 375 | {
|
---|
| 376 | bookmarkMenu->clear();
|
---|
| 377 | bookmarks.clear();
|
---|
| 378 | actionAddBookmark->addTo( bookmarkMenu );
|
---|
| 379 |
|
---|
| 380 | QFile f( QDir::homeDirPath() + "/.assistant/bookmarks." +
|
---|
| 381 | Config::configuration()->profileName() );
|
---|
| 382 | if ( !f.open( IO_ReadOnly ) )
|
---|
| 383 | return;
|
---|
| 384 | QTextStream ts( &f );
|
---|
| 385 | bookmarkMenu->insertSeparator();
|
---|
| 386 | while ( !ts.atEnd() ) {
|
---|
| 387 | QString title = ts.readLine();
|
---|
| 388 | QString link = ts.readLine();
|
---|
| 389 | bookmarks.insert( bookmarkMenu->insertItem( title ), link );
|
---|
| 390 | }
|
---|
| 391 | }
|
---|
| 392 |
|
---|
| 393 | void MainWindow::showBookmark( int id )
|
---|
| 394 | {
|
---|
| 395 | if ( bookmarks.find( id ) != bookmarks.end() )
|
---|
| 396 | showLink( *bookmarks.find( id ) );
|
---|
| 397 | }
|
---|
| 398 |
|
---|
| 399 | void MainWindow::showLinkFromClient( const QString &link )
|
---|
| 400 | {
|
---|
| 401 | setWindowState(windowState() & ~WindowMinimized);
|
---|
| 402 | raise();
|
---|
| 403 | setActiveWindow();
|
---|
| 404 | showLink( link );
|
---|
| 405 | }
|
---|
| 406 |
|
---|
| 407 | void MainWindow::showLink( const QString &link )
|
---|
| 408 | {
|
---|
| 409 | if( link.isEmpty() ) {
|
---|
| 410 | qWarning( "The link is empty!" );
|
---|
| 411 | }
|
---|
| 412 |
|
---|
| 413 | int find = link.find( '#' );
|
---|
| 414 | QString name = find >= 0 ? link.left( find ) : link;
|
---|
| 415 |
|
---|
| 416 | QString absLink = link;
|
---|
| 417 | QFileInfo fi( name );
|
---|
| 418 | if ( fi.isRelative() ) {
|
---|
| 419 | if ( find >= 0 )
|
---|
| 420 | absLink = fi.absFilePath() + link.right( link.length() - find );
|
---|
| 421 | else
|
---|
| 422 | absLink = fi.absFilePath();
|
---|
| 423 | }
|
---|
| 424 | if( fi.exists() ) {
|
---|
| 425 | tabs->setSource( absLink );
|
---|
| 426 | tabs->currentBrowser()->setFocus();
|
---|
| 427 | } else {
|
---|
| 428 | // ### Default 404 site!
|
---|
| 429 | statusBar()->message( tr( "Failed to open link: '%1'" ).arg( link ), 5000 );
|
---|
| 430 | tabs->currentBrowser()->setText( tr( "<div align=\"center\"><h1>The page could not be found!</h1><br>"
|
---|
| 431 | "<h3>'%1'</h3></div>").arg( link ) );
|
---|
| 432 | tabs->updateTitle( tr( "Error..." ) );
|
---|
| 433 | }
|
---|
| 434 | }
|
---|
| 435 |
|
---|
| 436 | void MainWindow::showLinks( const QStringList &links )
|
---|
| 437 | {
|
---|
| 438 | if ( links.size() == 0 ) {
|
---|
| 439 | qWarning( "MainWindow::showLinks() - Empty link" );
|
---|
| 440 | return;
|
---|
| 441 | }
|
---|
| 442 |
|
---|
| 443 | if ( links.size() == 1 ) {
|
---|
| 444 | showLink( links.first() );
|
---|
| 445 | return;
|
---|
| 446 | }
|
---|
| 447 |
|
---|
| 448 | pendingLinks = links;
|
---|
| 449 |
|
---|
| 450 | QStringList::ConstIterator it = pendingLinks.begin();
|
---|
| 451 | // Initial showing, The tab is empty so update that without creating it first
|
---|
| 452 | if ( tabs->currentBrowser()->source().isEmpty() ) {
|
---|
| 453 | pendingBrowsers.append(tabs->currentBrowser());
|
---|
| 454 | tabs->setTitle(tabs->currentBrowser(), pendingLinks.first());
|
---|
| 455 | }
|
---|
| 456 | ++it;
|
---|
| 457 |
|
---|
| 458 | while( it != pendingLinks.end() ) {
|
---|
| 459 | pendingBrowsers.append( tabs->newBackgroundTab(*it) );
|
---|
| 460 | ++it;
|
---|
| 461 | }
|
---|
| 462 |
|
---|
| 463 | startTimer(50);
|
---|
| 464 | return;
|
---|
| 465 | }
|
---|
| 466 |
|
---|
| 467 | void MainWindow::timerEvent(QTimerEvent *e)
|
---|
| 468 | {
|
---|
| 469 | QString link = pendingLinks.first();
|
---|
| 470 | HelpWindow *win = pendingBrowsers.first();
|
---|
| 471 | pendingLinks.pop_front();
|
---|
| 472 | pendingBrowsers.removeFirst();
|
---|
| 473 | if (pendingLinks.size() == 0)
|
---|
| 474 | killTimer(e->timerId());
|
---|
| 475 | win->setSource(link);
|
---|
| 476 | }
|
---|
| 477 |
|
---|
| 478 | void MainWindow::showQtHelp()
|
---|
| 479 | {
|
---|
| 480 | showLink( QString( qInstallPathDocs() ) + "/html/index.html" );
|
---|
| 481 | }
|
---|
| 482 |
|
---|
| 483 | void MainWindow::showSettingsDialog()
|
---|
| 484 | {
|
---|
| 485 | showSettingsDialog( -1 );
|
---|
| 486 | }
|
---|
| 487 |
|
---|
| 488 | void MainWindow::showWebBrowserSettings()
|
---|
| 489 | {
|
---|
| 490 | showSettingsDialog( 1 );
|
---|
| 491 | }
|
---|
| 492 |
|
---|
| 493 | void MainWindow::showSettingsDialog( int page )
|
---|
| 494 | {
|
---|
| 495 | if ( !settingsDia ){
|
---|
| 496 | settingsDia = new SettingsDialog( this );
|
---|
| 497 | }
|
---|
| 498 | QFontDatabase fonts;
|
---|
| 499 | settingsDia->fontCombo->clear();
|
---|
| 500 | settingsDia->fontCombo->insertStringList( fonts.families() );
|
---|
| 501 | settingsDia->fontCombo->lineEdit()->setText( tabs->browserFont().family() );
|
---|
| 502 | settingsDia->fixedfontCombo->clear();
|
---|
| 503 | settingsDia->fixedfontCombo->insertStringList( fonts.families() );
|
---|
| 504 | settingsDia->fixedfontCombo->lineEdit()->setText( tabs->styleSheet()->item( "pre" )->fontFamily() );
|
---|
| 505 | settingsDia->linkUnderlineCB->setChecked( tabs->linkUnderline() );
|
---|
| 506 | settingsDia->colorButton->setPaletteBackgroundColor( tabs->palette().color( QPalette::Active, QColorGroup::Link ) );
|
---|
| 507 | if ( page != -1 )
|
---|
| 508 | settingsDia->settingsTab->setCurrentPage( page );
|
---|
| 509 |
|
---|
| 510 | int ret = settingsDia->exec();
|
---|
| 511 |
|
---|
| 512 | if ( ret != QDialog::Accepted )
|
---|
| 513 | return;
|
---|
| 514 |
|
---|
| 515 | QObjectList *lst = (QObjectList*)Toolbar->children();
|
---|
| 516 | QObject *obj;
|
---|
| 517 | for ( obj = lst->last(); obj; obj = lst->prev() ) {
|
---|
| 518 | if ( obj->isA( "QToolBarSeparator" ) ) {
|
---|
| 519 | delete obj;
|
---|
| 520 | obj = 0;
|
---|
| 521 | break;
|
---|
| 522 | }
|
---|
| 523 | }
|
---|
| 524 |
|
---|
| 525 | setupGoActions();
|
---|
| 526 |
|
---|
| 527 | QFont fnt( tabs->browserFont() );
|
---|
| 528 | fnt.setFamily( settingsDia->fontCombo->currentText() );
|
---|
| 529 | tabs->setBrowserFont( fnt );
|
---|
| 530 | tabs->setLinkUnderline( settingsDia->linkUnderlineCB->isChecked() );
|
---|
| 531 |
|
---|
| 532 | QPalette pal = tabs->palette();
|
---|
| 533 | QColor lc = settingsDia->colorButton->paletteBackgroundColor();
|
---|
| 534 | pal.setColor( QPalette::Active, QColorGroup::Link, lc );
|
---|
| 535 | pal.setColor( QPalette::Inactive, QColorGroup::Link, lc );
|
---|
| 536 | pal.setColor( QPalette::Disabled, QColorGroup::Link, lc );
|
---|
| 537 | tabs->setPalette( pal );
|
---|
| 538 |
|
---|
| 539 | QString family = settingsDia->fixedfontCombo->currentText();
|
---|
| 540 |
|
---|
| 541 | QStyleSheet *sh = tabs->styleSheet();
|
---|
| 542 | sh->item( "pre" )->setFontFamily( family );
|
---|
| 543 | sh->item( "code" )->setFontFamily( family );
|
---|
| 544 | sh->item( "tt" )->setFontFamily( family );
|
---|
| 545 | tabs->currentBrowser()->setText( tabs->currentBrowser()->text() );
|
---|
| 546 | showLink( tabs->currentBrowser()->source() );
|
---|
| 547 | }
|
---|
| 548 |
|
---|
| 549 | void MainWindow::hide()
|
---|
| 550 | {
|
---|
| 551 | saveToolbarSettings();
|
---|
| 552 | QMainWindow::hide();
|
---|
| 553 | }
|
---|
| 554 |
|
---|
| 555 | MainWindow* MainWindow::newWindow()
|
---|
| 556 | {
|
---|
| 557 | saveSettings();
|
---|
| 558 | saveToolbarSettings();
|
---|
| 559 | MainWindow *mw = new MainWindow;
|
---|
| 560 | mw->move( geometry().topLeft() );
|
---|
| 561 | if ( isMaximized() )
|
---|
| 562 | mw->showMaximized();
|
---|
| 563 | else
|
---|
| 564 | mw->show();
|
---|
| 565 | mw->goHome();
|
---|
| 566 | return mw;
|
---|
| 567 | }
|
---|
| 568 |
|
---|
| 569 | void MainWindow::saveSettings()
|
---|
| 570 | {
|
---|
| 571 | Config *config = Config::configuration();
|
---|
| 572 | config->setFontFamily( tabs->browserFont().family() );
|
---|
| 573 | config->setFontSize( tabs->currentBrowser()->font().pointSize() );
|
---|
| 574 | config->setFontFixedFamily( tabs->styleSheet()->item( "pre" )->fontFamily() );
|
---|
| 575 | config->setLinkUnderline( tabs->linkUnderline() );
|
---|
| 576 | config->setLinkColor( tabs->palette().color( QPalette::Active, QColorGroup::Link ).name() );
|
---|
| 577 | config->setSideBarPage( helpDock->tabWidget->currentPageIndex() );
|
---|
| 578 | config->setGeometry( QRect( x(), y(), width(), height() ) );
|
---|
| 579 | config->setMaximized( isMaximized() );
|
---|
| 580 |
|
---|
| 581 | // Create list of the tab urls
|
---|
| 582 | QStringList lst;
|
---|
| 583 | QPtrList<HelpWindow> browsers = tabs->browsers();
|
---|
| 584 | HelpWindow *browser = browsers.first();
|
---|
| 585 | while (browser) {
|
---|
| 586 | lst << browser->source();
|
---|
| 587 | browser = browsers.next();
|
---|
| 588 | }
|
---|
| 589 | config->setSource(lst);
|
---|
| 590 | config->save();
|
---|
| 591 | }
|
---|
| 592 |
|
---|
| 593 | void MainWindow::saveToolbarSettings()
|
---|
| 594 | {
|
---|
| 595 | QString mainWindowLayout;
|
---|
| 596 | QTextStream ts( &mainWindowLayout, IO_WriteOnly );
|
---|
| 597 | ts << *this;
|
---|
| 598 | Config::configuration()->setMainWindowLayout( mainWindowLayout );
|
---|
| 599 | }
|
---|
| 600 |
|
---|
| 601 | TabbedBrowser* MainWindow::browsers()
|
---|
| 602 | {
|
---|
| 603 | return tabs;
|
---|
| 604 | }
|
---|
| 605 |
|
---|
| 606 | void MainWindow::showSearchLink( const QString &link, const QStringList &terms )
|
---|
| 607 | {
|
---|
| 608 | HelpWindow * hw = tabs->currentBrowser();
|
---|
| 609 | hw->blockScrolling( TRUE );
|
---|
| 610 | hw->setCursor( waitCursor );
|
---|
| 611 | if ( hw->source() == link )
|
---|
| 612 | hw->reload();
|
---|
| 613 | else
|
---|
| 614 | showLink( link );
|
---|
| 615 | hw->sync();
|
---|
| 616 | hw->setCursor( arrowCursor );
|
---|
| 617 |
|
---|
| 618 | hw->viewport()->setUpdatesEnabled( FALSE );
|
---|
| 619 | int minPar = INT_MAX;
|
---|
| 620 | int minIndex = INT_MAX;
|
---|
| 621 | QStringList::ConstIterator it = terms.begin();
|
---|
| 622 | for ( ; it != terms.end(); ++it ) {
|
---|
| 623 | int para = 0;
|
---|
| 624 | int index = 0;
|
---|
| 625 | bool found = hw->find( *it, FALSE, TRUE, TRUE, ¶, &index );
|
---|
| 626 | while ( found ) {
|
---|
| 627 | if ( para < minPar ) {
|
---|
| 628 | minPar = para;
|
---|
| 629 | minIndex = index;
|
---|
| 630 | }
|
---|
| 631 | hw->setColor( red );
|
---|
| 632 | found = hw->find( *it, FALSE, TRUE, TRUE );
|
---|
| 633 | }
|
---|
| 634 | }
|
---|
| 635 | hw->blockScrolling( FALSE );
|
---|
| 636 | hw->viewport()->setUpdatesEnabled( TRUE );
|
---|
| 637 | hw->setCursorPosition( minPar, minIndex );
|
---|
| 638 | hw->updateContents();
|
---|
| 639 | }
|
---|
| 640 |
|
---|
| 641 |
|
---|
| 642 | void MainWindow::showGoActionLink()
|
---|
| 643 | {
|
---|
| 644 | const QObject *origin = sender();
|
---|
| 645 | if( !origin ||
|
---|
| 646 | origin->metaObject()->className() != QString( "QAction" ) )
|
---|
| 647 | return;
|
---|
| 648 |
|
---|
| 649 | QAction *action = (QAction*) origin;
|
---|
| 650 | QString docfile = *( goActionDocFiles->find( action ) );
|
---|
| 651 | showLink( docfile );
|
---|
| 652 | }
|
---|
| 653 |
|
---|
| 654 | void MainWindow::showAssistantHelp()
|
---|
| 655 | {
|
---|
| 656 | showLink( Config::configuration()->assistantDocPath() + "/assistant.html" );
|
---|
| 657 | }
|
---|
| 658 |
|
---|
| 659 | HelpDialog* MainWindow::helpDialog()
|
---|
| 660 | {
|
---|
| 661 | return helpDock;
|
---|
| 662 | }
|
---|
| 663 |
|
---|
| 664 | void MainWindow::backwardAvailable( bool enable )
|
---|
| 665 | {
|
---|
| 666 | actionGoPrevious->setEnabled( enable );
|
---|
| 667 | }
|
---|
| 668 |
|
---|
| 669 | void MainWindow::forwardAvailable( bool enable )
|
---|
| 670 | {
|
---|
| 671 | actionGoNext->setEnabled( enable );
|
---|
| 672 | }
|
---|
| 673 |
|
---|
| 674 | void MainWindow::updateProfileSettings()
|
---|
| 675 | {
|
---|
| 676 | Config *config = Config::configuration();
|
---|
| 677 | #ifndef Q_WS_MACX
|
---|
| 678 | setIcon( config->applicationIcon() );
|
---|
| 679 | #endif
|
---|
| 680 | helpMenu->clear();
|
---|
| 681 | actionHelpAssistant->addTo( helpMenu );
|
---|
| 682 | helpMenu->insertSeparator();
|
---|
| 683 | helpAbout_Qt_AssistantAction->addTo( helpMenu );
|
---|
| 684 | if ( !config->aboutApplicationMenuText().isEmpty() )
|
---|
| 685 | actionAboutApplication->addTo( helpMenu );
|
---|
| 686 | helpMenu->insertSeparator();
|
---|
| 687 | actionHelpWhatsThis->addTo( helpMenu );
|
---|
| 688 |
|
---|
| 689 | actionAboutApplication->setMenuText( config->aboutApplicationMenuText() );
|
---|
| 690 |
|
---|
| 691 | if( !config->title().isNull() )
|
---|
| 692 | setCaption( config->title() );
|
---|
| 693 | }
|
---|