Back to index

lightning-sunbird  0.9+nobinonly
mainwindow.cpp
Go to the documentation of this file.
00001 #include "mainwindow.h"
00002 
00003 #include <qlineedit.h>
00004 #include <qaction.h>
00005 #include <qmenubar.h>
00006 #include <qtoolbar.h>
00007 #include <qfiledialog.h>
00008 #include <qstatusbar.h>
00009 #include <qvbox.h>
00010 #include <qlayout.h>
00011 
00012 #include "qgeckoembed.h"
00013 
00014 
00015 MyMainWindow::MyMainWindow()
00016 {
00017     QVBox *box = new QVBox(this);
00018     qecko = new QGeckoEmbed(box, "qgecko");
00019     box->setFrameStyle(QFrame::Panel | QFrame::Sunken);
00020     setCentralWidget( box );
00021 
00022     QToolBar *toolbar = new QToolBar(this);
00023     toolbar->setLabel("Location:");
00024 
00025     QAction *action = new QAction(QPixmap::fromMimeSource( "back.png" ), tr( "Go Back"), CTRL + Key_B,
00026                          toolbar, "goback");
00027     connect(action, SIGNAL(activated()), this, SLOT(goBack()));
00028     action->addTo(toolbar);
00029 
00030     action = new QAction(QPixmap::fromMimeSource( "forward.png" ), tr( "Go Forward"), CTRL + Key_F,
00031                          toolbar, "goforward");
00032     connect(action, SIGNAL(activated()), this, SLOT(goForward()));
00033     action->addTo(toolbar);
00034 
00035     action = new QAction(QPixmap::fromMimeSource( "stop.png" ), tr("Stop"), CTRL + Key_S,
00036                          toolbar, "stop");
00037     connect(action, SIGNAL(activated()), this, SLOT(stop()));
00038     action->addTo(toolbar);
00039 
00040     location = new QLineEdit(toolbar);
00041     toolbar->setStretchableWidget(location);
00042 
00043     QPopupMenu *menu = new QPopupMenu(this);
00044     menuBar()->insertItem( tr( "&File" ), menu );
00045 
00046     QAction *a = new QAction( QPixmap::fromMimeSource( "fileopen.png" ), tr( "&Open..." ), CTRL + Key_O,
00047                               toolbar, "fileOpen" );
00048     connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
00049     //a->addTo( toolbar );
00050     a->addTo( menu );
00051 
00052 
00053     connect( qecko, SIGNAL(linkMessage(const QString &)),
00054              statusBar(), SLOT(message(const QString &)) );
00055     connect( qecko, SIGNAL(jsStatusMessage(const QString &)),
00056              statusBar(), SLOT(message(const QString &)) );
00057     connect( qecko, SIGNAL(windowTitleChanged(const QString &)),
00058              SLOT(setCaption(const QString &)) );
00059     connect( qecko, SIGNAL(startURIOpen(const QString &, bool &)),
00060              SLOT(startURIOpen(const QString &, bool &)) );
00061     connect(qecko, SIGNAL(locationChanged(const QString&)),
00062             location, SLOT(setText(const QString&)));
00063     connect(qecko, SIGNAL(progress(int, int)),
00064             SLOT(slotProgress(int, int)));
00065     connect(qecko, SIGNAL(progressAll(const QString&, int, int)),
00066             SLOT(slotProgress(const QString&, int, int)));
00067 
00068 
00069     connect( location, SIGNAL(returnPressed()), SLOT(changeLocation()));
00070 
00071 }
00072 
00073 void MyMainWindow::fileOpen()
00074 {
00075     QString fn = QFileDialog::getOpenFileName( QString::null, tr( "HTML-Files (*.htm *.html);;All Files (*)" ), this );
00076     if ( !fn.isEmpty() )
00077        qecko->loadURL( fn );
00078 }
00079 
00080 void MyMainWindow::startURIOpen(const QString &, bool &)
00081 {
00082     qDebug("XX in the signal");
00083 }
00084 
00085 void MyMainWindow::changeLocation()
00086 {
00087     qecko->loadURL( location->text() );
00088 }
00089 
00090 void MyMainWindow::goBack()
00091 {
00092     qecko->goBack();
00093 }
00094 
00095 void MyMainWindow::goForward()
00096 {
00097     qecko->goForward();
00098 }
00099 
00100 void MyMainWindow::stop()
00101 {
00102     qecko->stopLoad();
00103 }
00104 
00105 void MyMainWindow::slotProgress(const QString &url, int current, int max)
00106 {
00107     qDebug("progress %d / %d (%s)",  current, max, url.latin1());
00108 }
00109 
00110 void MyMainWindow::slotProgress(int current, int max)
00111 {
00112     qDebug("progress %d / %d ", current, max);
00113 }