#include "mainwindow.h" #include "ui_mainwindow.h" #include "clientkitapi.h" #include <QApplication> #include <QWebView> #include <QWebPage> #include <QWebFrame> #include <QWebSettings> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { //init the UI as defined in 'mainwindow.ui' (edit using Qt Designer) ui->setupUi(this); setAttribute(Qt::WA_TranslucentBackground, true); // setAttribute(Qt::WA_OpaquePaintEvent); // setAttribute(Qt::WA_NoSystemBackground); ui->centralWidget->setAttribute(Qt::WA_TranslucentBackground, true); // ui->centralWidget->setAttribute(Qt::WA_OpaquePaintEvent); // ui->centralWidget->setAttribute(Qt::WA_NoSystemBackground); ui->webView->setAttribute(Qt::WA_TranslucentBackground, true); // ui->webView->setAttribute(Qt::WA_OpaquePaintEvent); // ui->webView->setAttribute(Qt::WA_NoSystemBackground); //init the ClientKitApi m_ClientKitApi = new ClientKitApi(this); // QFile jsMethodSource (":/js/ClientKitMethods.js"); // jsMethodSource.open(QIODevice::ReadOnly); // m_JsMethods = jsMethodSource.readAll(); // jsMethodSource.close(); //create addressbar widget and set up actions initAddressBar(); //create status bar and set up actions initStatusBar(); //populate the menus populateMenus(); //connect remaining SIGNALs and SLOTs connectSignalsAndSlots(); //create some Actions createActions(); //set up the webView QWebSettings* webSettings = ui->webView->page()->settings()->globalSettings(); webSettings->setAttribute(QWebSettings::JavaEnabled,true); webSettings->setAttribute(QWebSettings::JavascriptEnabled, true); webSettings->setAttribute(QWebSettings::JavascriptCanOpenWindows, true); webSettings->setAttribute(QWebSettings::JavascriptCanCloseWindows, true); webSettings->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); webSettings->setAttribute(QWebSettings::LocalStorageEnabled, true); webSettings->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true); webSettings->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true); webSettings->setAttribute(QWebSettings::LocalContentCanAccessRemoteUrls, true); webSettings->setAttribute(QWebSettings::LocalContentCanAccessFileUrls, true); webSettings->setAttribute(QWebSettings::SpatialNavigationEnabled, true); webSettings->setOfflineWebApplicationCacheQuota(1024*1024); webSettings->enablePersistentStorage(QCoreApplication::applicationDirPath()+"/../_appDataCache/"); ui->webView->load(QUrl("qrc:/index.html")); // setCentralWidget(ui->webView); } MainWindow::~MainWindow() { delete ui; } void MainWindow::addJSObject() { // Add ClientKitApi to JavaScript window object (global context). ui->webView->page()->mainFrame()->addToJavaScriptWindowObject(QString("ClientKit"), m_ClientKitApi); //add additional methods in js // ui->webView->page()->mainFrame()->evaluateJavaScript(m_JsMethods); } void MainWindow::on_actionClientKit_Help_Page_triggered() { ui->webView->load(QUrl("qrc:/help.html")); } void MainWindow::on_actionClientKit_Main_Page_triggered() { ui->webView->load(QUrl("qrc:/index.html")); } void MainWindow::setViewUrl() { QUrl url = QUrl(locationEdit->text()); ui->webView->setUrl(url); ui->webView->setFocus(); } void MainWindow::startLoading() { ui->mainToolBar->removeAction(addressBarText); ui->mainToolBar->removeAction(ui->webView->pageAction(QWebPage::Reload)); ui->mainToolBar->addAction(ui->webView->pageAction(QWebPage::Stop)); ui->mainToolBar->addAction(addressBarText); } void MainWindow::adjustLocation() { locationEdit->setText(ui->webView->url().toString()); } void MainWindow::adjustTitle() { QString windowTitle = "ClientKit - "; if (ui->webView->title().length()==0) windowTitle += "(Untitled Page)"; else windowTitle += ui->webView->title(); if (loadProgress <= 0 || loadProgress >= 100) setWindowTitle(windowTitle); else setWindowTitle(QString("%1 - [%2%]").arg(windowTitle).arg(loadProgress)); } void MainWindow::setProgress(int p) { loadProgress = p; adjustTitle(); } void MainWindow::finishLoading(bool) { loadProgress = 100; adjustTitle(); ui->mainToolBar->removeAction(addressBarText); ui->mainToolBar->removeAction(ui->webView->pageAction(QWebPage::Stop)); ui->mainToolBar->addAction(ui->webView->pageAction(QWebPage::Reload)); ui->mainToolBar->addAction(addressBarText); } void MainWindow::initAddressBar() { locationEdit = new QLineEdit(this); locationEdit->setSizePolicy(QSizePolicy::Expanding, locationEdit->sizePolicy().verticalPolicy()); connect(locationEdit, SIGNAL(returnPressed()), SLOT(setViewUrl())); ui->mainToolBar->addAction(ui->webView->pageAction(QWebPage::Back)); ui->mainToolBar->addAction(ui->webView->pageAction(QWebPage::Forward)); ui->mainToolBar->addAction(ui->webView->pageAction(QWebPage::Reload)); addressBarText = ui->mainToolBar->addWidget(locationEdit); } void MainWindow::initStatusBar() { //hides status bar since it's shown by default (since it doesn't do anything yet anyway) ui->actionStatus_Bar->trigger(); } void MainWindow::populateMenus() { ui->menuGo_To->addAction(ui->webView->pageAction(QWebPage::Back)); ui->menuGo_To->addAction(ui->webView->pageAction(QWebPage::Forward)); ui->menuGo_To->addAction(ui->webView->pageAction(QWebPage::Reload)); ui->menu_Edit->addAction(ui->webView->pageAction(QWebPage::Undo)); ui->menu_Edit->addAction(ui->webView->pageAction(QWebPage::Redo)); ui->menu_Edit->addSeparator(); ui->menu_Edit->addAction(ui->webView->pageAction(QWebPage::Cut)); ui->menu_Edit->addAction(ui->webView->pageAction(QWebPage::Copy)); ui->menu_Edit->addAction(ui->webView->pageAction(QWebPage::Paste)); ui->menu_Edit->addAction(ui->webView->pageAction(QWebPage::SelectAll)); } void MainWindow::createActions() { } void MainWindow::connectSignalsAndSlots() { //set up webView actions connect(ui->webView, SIGNAL(loadStarted()), SLOT(startLoading())); connect(ui->webView, SIGNAL(loadFinished(bool)), SLOT(adjustLocation())); connect(ui->webView, SIGNAL(titleChanged(QString)), SLOT(adjustTitle())); connect(ui->webView, SIGNAL(loadProgress(int)), SLOT(setProgress(int))); connect(ui->webView, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool))); connect(ui->webView->page()->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJSObject())); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#7 | 8115 | David George |
a bunch of changes to the GuiApi - probably bound to change, though, so use at your own risk! beginnings of migrating to an "all windows are created equal" model. (as opposed to a MainWindow) removing the unreliable Qt execution of the .js methods - please include in your HTML (<script type="text/javascript" src="qrc:/js/ClientKitMethods.js"></script>) |
||
#6 | 8109 | David George | same as last | ||
#5 | 8104 | David George |
merged .runAsync and .run into one method that runs sync/async depending on the presence of a callback function argument. restored some storage-related QWebSettings |
||
#4 | 8101 | David George |
beginning of _massive_ re-factoring your current build settings will fail create a new project from newly added .pro file (but change its p4api paths to match your old one) look for updated README as soon as Dave agrees that changes are _indeed_ for the best (Changes by Jaimen) |
||
#3 | 8099 | David George | Added deleteClientKitApi method. | ||
#2 | 8086 | David George | A slew of changes initially done on the internal Perforce server, including async and native file/folder launching. | ||
#1 | 8083 | David George |
Merging //guest/james_creasy/ClientKit/... to //guest/david_george/ClientKit/... This merge also includes changes grabbed from the internal Perforce depot. |
||
//guest/james_creasy/ClientKit/mainwindow.cpp | |||||
#1 | 8060 | james_creasy | Client Kit for Perforce |