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(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { _inited = false; _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); QList<int> sizes = QList<int>(); sizes.append(590); ui->splitter->setSizes(sizes); ui->tabBar->setFocusPolicy(Qt::NoFocus); ui->tabBar->addTab("File"); ui->tabBar->addTab("Common"); ui->tabBar->addOptionsTab(); ui->tabBar->addHelpTab(); connect(ui->tabBar, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int))); connect(ui->tabBar, SIGNAL(helpToggled(bool)), this, SLOT(helpToggled(bool))); #ifdef __WIN32__ QFont font = ui->tabBar->font(); font.setPointSize(10); ui->tabBar->setFont(font); #endif ui->ribbonAnalysis->setEnabled(false); ui->ribbonSEM->setEnabled(false); ui->ribbonR11tLearn->setEnabled(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 // 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))); _tableModel = new DataSetTableModel(); ui->tableView->setModel(_tableModel); ui->tabBar->setCurrentIndex(1); 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(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(dataSetSelected(QString)), this, SLOT(dataSetSelected(QString))); connect(ui->backStage, SIGNAL(closeDataSetSelected()), this, SLOT(dataSetCloseRequested())); connect(ui->backStage, SIGNAL(exportSelected(QString)), this, SLOT(exportSelected(QString))); connect(ui->backStage, SIGNAL(saveSelected(QString)), this, SLOT(saveSelected(QString))); _alert = new ProgressWidget(ui->tableView); _alert->setAutoFillBackground(true); _alert->resize(400, 100); _alert->move(100, 80); _alert->hide(); connect(&_loader, SIGNAL(complete(const QString&, DataSetPackage*, const QString&)), this, SLOT(dataSetLoaded(const QString&, DataSetPackage*, const QString&))); connect(&_loader, SIGNAL(saveComplete(const QString&)), this, SLOT(saveComplete(const QString&))); connect(&_loader, SIGNAL(progress(QString,int)), _alert, SLOT(setStatus(QString,int))); connect(&_loader, SIGNAL(fail(QString)), this, SLOT(dataSetLoadFailed(QString))); connect(&_loader, SIGNAL(saveFail(QString)), this, SLOT(saveFailed(QString))); connect(this, SIGNAL(analysisSelected(int)), this, SLOT(analysisSelectedHandler(int))); connect(this, SIGNAL(analysisUnselected()), this, SLOT(analysisUnselectedHandler())); connect(this, SIGNAL(pushToClipboard(QString, QString)), this, SLOT(pushToClipboardHandler(QString, QString))); connect(this, SIGNAL(analysisChangedDownstream(int, QString)), this, SLOT(analysisChangedDownstreamHandler(int, QString))); _buttonPanel = new QWidget(ui->pageOptions); _buttonPanelLayout = new QVBoxLayout(_buttonPanel); _buttonPanelLayout->setSpacing(6); _buttonPanelLayout->setContentsMargins(0, 12, 24, 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->minimumWidth() - _buttonPanel->width(), 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))); updateUIFromOptions(); ui->panelMid->hide(); _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(); try { _log = new ActivityLog(); _log->log("Application Start"); ui->backStage->setLog(_log); _engineSync->setLog(_log); _log->flushLogToServer(); QTimer *timer = new QTimer(this); timer->setInterval(30000); connect(timer, SIGNAL(timeout()), _log, SLOT(flushLogToServer())); timer->start(); } catch (std::runtime_error &e) { _log = NULL; _fatalError = tq(e.what()); QTimer::singleShot(0, this, SLOT(fatalError())); } setAcceptDrops(true); }