void MainWindow::htmlContentSizeChanged() { if (scrollBarPos > 0) { // restore previous scrollbar position scrollValueChanged(scrollBarPos); } }
void WebView::paintEvent(QPaintEvent * event) { QWebView::paintEvent(event); QWebFrame *frameff = page()->mainFrame(); int hValue = frameff->scrollBarValue(Qt::Horizontal); int vValue = frameff->scrollBarValue(Qt::Vertical); if (hValue != _lastHorizontalValue || vValue != _lastVerticalValue) { _lastHorizontalValue = hValue; _lastVerticalValue = vValue; emit scrollValueChanged(); } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { _log = NULL; _tableModel = NULL; _currentOptionsWidget = NULL; _currentAnalysis = NULL; _optionsForm = NULL; _package = new DataSetPackage(); _package->isModifiedChanged.connect(boost::bind(&MainWindow::packageChanged, this, _1)); QShortcut *saveShortcut = new QShortcut(QKeySequence("Ctrl+S"), this); QObject::connect(saveShortcut, SIGNAL(activated()), this, SLOT(saveKeysSelected())); QShortcut *openShortcut = new QShortcut(QKeySequence("Ctrl+O"), this); QObject::connect(openShortcut, SIGNAL(activated()), this, SLOT(openKeysSelected())); ui->setupUi(this); int initalTableWidth = 530; QList<int> sizes = QList<int>(); sizes.append(initalTableWidth); ui->splitter->setSizes(sizes); ui->tabBar->setFocusPolicy(Qt::NoFocus); ui->tabBar->addTab("File"); #ifdef QT_DEBUG ui->tabBar->addTab("Variables"); // variables view #endif ui->tabBar->addTab("Common"); #ifndef __linux__ ui->tabBar->addOptionsTab(); // no SEM under linux for now #endif ui->tabBar->addHelpTab(); connect(ui->tabBar, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int))); connect(ui->tabBar, SIGNAL(helpToggled(bool)), this, SLOT(helpToggled(bool))); ui->ribbonAnalysis->setDataSetLoaded(false); ui->ribbonSEM->setDataSetLoaded(false); ui->ribbonR11tLearn->setDataSetLoaded(false); #ifdef QT_DEBUG ui->webViewResults->page()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); ui->webViewHelp->page()->settings()->setAttribute(QWebSettings::DeveloperExtrasEnabled, true); #else ui->webViewResults->setContextMenuPolicy(Qt::NoContextMenu); ui->webViewHelp->setContextMenuPolicy(Qt::NoContextMenu); #endif tempfiles_init(ProcessInfo::currentPID()); // needed here so that the LRNAM can be passed the session directory _odm = new OnlineDataManager(this); QVariant osfUsernameV = _settings.value("OSFUsername"); QVariant osfPasswordV = _settings.value("OSFPassword", ""); if (osfUsernameV.canConvert(QMetaType::QString) && osfPasswordV.canConvert(QMetaType::QString)) { QString username = osfUsernameV.toString(); QString password = osfPasswordV.toString(); _odm->setAuthentication(OnlineDataManager::OSF, username, password); } _loader.setOnlineDataManager(_odm); ui->backStage->setOnlineDataManager(_odm); // the LRNAM adds mime types to local resources; important for SVGs ui->webViewResults->page()->setNetworkAccessManager(new LRNAM(tq(tempfiles_sessionDirName()), this)); ui->webViewResults->setUrl(QUrl(QString("qrc:///core/index.html"))); connect(ui->webViewResults, SIGNAL(loadFinished(bool)), this, SLOT(resultsPageLoaded(bool))); connect(ui->webViewResults, SIGNAL(scrollValueChanged()), this, SLOT(scrollValueChangedHandle())); _tableModel = new DataSetTableModel(); ui->tableView->setModel(_tableModel); #ifdef QT_DEBUG // variables view ui->tabBar->setCurrentIndex(2); #else ui->tabBar->setCurrentIndex(1); #endif ui->tableView->setVerticalScrollMode(QTableView::ScrollPerPixel); ui->tableView->setHorizontalScrollMode(QTableView::ScrollPerPixel); _analyses = new Analyses(); _engineSync = new EngineSync(_analyses, this); connect(_engineSync, SIGNAL(engineTerminated()), this, SLOT(fatalError())); connect(_analyses, SIGNAL(analysisResultsChanged(Analysis*)), this, SLOT(analysisResultsChangedHandler(Analysis*))); connect(_analyses, SIGNAL(analysisUserDataLoaded(Analysis*)), this, SLOT(analysisUserDataLoadedHandler(Analysis*))); connect(ui->ribbonAnalysis, SIGNAL(itemSelected(QString)), this, SLOT(itemSelected(QString))); connect(ui->ribbonSEM, SIGNAL(itemSelected(QString)), this, SLOT(itemSelected(QString))); connect(ui->ribbonR11tLearn, SIGNAL(itemSelected(QString)), this, SLOT(itemSelected(QString))); connect(ui->backStage, SIGNAL(dataSetIORequest(FileEvent*)), this, SLOT(dataSetIORequest(FileEvent*))); connect(ui->backStage, SIGNAL(exportSelected(QString)), this, SLOT(exportSelected(QString))); _progressIndicator = new ProgressWidget(ui->tableView); _progressIndicator->setAutoFillBackground(true); _progressIndicator->resize(400, 100); _progressIndicator->move(100, 80); _progressIndicator->hide(); connect(&_loader, SIGNAL(progress(QString,int)), _progressIndicator, SLOT(setStatus(QString,int))); connect(this, SIGNAL(analysisSelected(int)), this, SLOT(analysisSelectedHandler(int))); connect(this, SIGNAL(analysisUnselected()), this, SLOT(analysisUnselectedHandler())); connect(this, SIGNAL(saveTempImage(int, QString, QByteArray)), this, SLOT(saveTempImageHandler(int, QString, QByteArray))); connect(this, SIGNAL(displayMessageFromResults(QString)), this, SLOT(displayMessageFromResultsHandler(QString))); connect(this, SIGNAL(pushToClipboard(QString, QString, QString)), this, SLOT(pushToClipboardHandler(QString, QString, QString))); connect(this, SIGNAL(pushImageToClipboard(QByteArray, QString)), this, SLOT(pushImageToClipboardHandler(QByteArray, QString))); connect(this, SIGNAL(saveTextToFile(QString, QString)), this, SLOT(saveTextToFileHandler(QString, QString))); connect(this, SIGNAL(analysisChangedDownstream(int, QString)), this, SLOT(analysisChangedDownstreamHandler(int, QString))); connect(this, SIGNAL(showAnalysesMenu(QString)), this, SLOT(showAnalysesMenuHandler(QString))); connect(this, SIGNAL(removeAnalysisRequest(int)), this, SLOT(removeAnalysisRequestHandler(int))); connect(this, SIGNAL(updateUserData(int, QString)), this, SLOT(updateUserDataHandler(int, QString))); connect(this, SIGNAL(simulatedMouseClick(int, int, int)), this, SLOT(simulatedMouseClickHandler(int, int, int))); connect(this, SIGNAL(resultsDocumentChanged()), this, SLOT(resultsDocumentChangedHandler())); #ifdef __APPLE__ _scrollbarWidth = 3; #else _scrollbarWidth = qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent); #endif _buttonPanel = new QWidget(ui->panelMid); _buttonPanelLayout = new QVBoxLayout(_buttonPanel); _buttonPanelLayout->setSpacing(6); _buttonPanelLayout->setContentsMargins(0, _buttonPanelLayout->contentsMargins().top(), _buttonPanelLayout->contentsMargins().right(), 0); _buttonPanel->setLayout(_buttonPanelLayout); _okButton = new QPushButton(QString("OK"), _buttonPanel); _okButton->setDefault(true); _runButton = new QPushButton(QString("Run"), _buttonPanel); _menuButton = new QPushButton(QString("..."), _buttonPanel); QMenu *menu = new QMenu(_menuButton); menu->addAction("Remove Analysis", this, SLOT(analysisRemoved())); _menuButton->setMenu(menu); _buttonPanelLayout->addWidget(_okButton); _buttonPanelLayout->addWidget(_runButton); _buttonPanelLayout->addWidget(_menuButton); _buttonPanelLayout->addStretch(); _buttonPanel->resize(_buttonPanel->sizeHint()); _buttonPanel->move(ui->panelMid->width() - _buttonPanel->width() - _scrollbarWidth, 0); connect(_okButton, SIGNAL(clicked()), this, SLOT(analysisOKed())); connect(_runButton, SIGNAL(clicked()), this, SLOT(analysisRunned())); connect(ui->splitter, SIGNAL(splitterMoved(int,int)), this, SLOT(splitterMovedHandler(int,int))); _analysisMenu = new QMenu(this); connect(_analysisMenu, SIGNAL(aboutToHide()), this, SLOT(menuHidding())); updateUIFromOptions(); _tableViewWidthBeforeOptionsMadeVisible = -1; QUrl userGuide = QUrl::fromLocalFile(AppDirs::help() + "/index.html"); ui->webViewHelp->setUrl(userGuide); connect(ui->webViewHelp, SIGNAL(loadFinished(bool)), this, SLOT(helpFirstLoaded(bool))); ui->panelHelp->hide(); setAcceptDrops(true); #ifdef __WIN32__ QApplication::setFont(ui->tableView->font()); #endif setupOptionPanelSize(); ui->panelMid->hide(); }