FotoLab::FotoLab(QWidget *parent) : QMainWindow(parent), backend(), sigmaSpin(this), tlowSpin(this), thighSpin(this) { ui.setupUi(this); activateToolBar(); activateActions(); fileDialog = new QFileDialog(this); fileDialog->setFilter(tr("Images (*.png *.xpm *.jpg)")); fileDialog->setViewMode(QFileDialog::Detail); }
void MainWindow::openProject(QString filename, bool onNewMainWindow) { if(filename.isEmpty()) return; QFile file(filename); if(!file.exists()) { // error return; } if(!file.open(QIODevice::ReadOnly)) { // error return; } QXmlStreamReader reader(&file); reader.readNextStartElement(); if(reader.attributes().value("version").toString() != CHEMVP_VERSION) { error("Invalid Version Number!"); return; } DrawingCanvas* old_canvas = canvas; DrawingInfo* old_info = drawingInfo; QGraphicsView* old_view = view; FileParser* old_parser = parser; // Deserialize this->parser = FileParser::deserialize(&reader); this->drawingInfo = DrawingInfo::deserialize(&reader); this->canvas = DrawingCanvas::deserialize(&reader, drawingInfo, parser); setWindowTitle(tr("%1 - cheMVP").arg(filename)); this->view = new DrawingDisplay(canvas, drawingInfo); view->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); view->setGeometry(0, 0, static_cast<int>(DEFAULT_SCENE_SIZE_X), static_cast<int>(DEFAULT_SCENE_SIZE_Y)); view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate); QMap<QString, QString>* options = new QMap<QString, QString>(); // Appearance options->insert("FOGGING_ON", QString("%1").arg(drawingInfo->getUseFogging())); options->insert("FOGGING_SCALE", QString("%1").arg(drawingInfo->getFoggingScale())); options->insert("X_ROTATION", "0"); // Where are these stored? options->insert("Y_ROTATION", "0"); // They aren't. options->insert("Z_ROTATION", "0"); // Why not? // No idea. options->insert("BACKGROUND_OPACITY", QString("%1").arg(canvas->getBackgroundOpacity())); options->insert("ZOOM", QString("%1").arg(drawingInfo->getZoom())); // Bonds and Angles options->insert("BOND_LABEL_PRECISION", QString("%1").arg(drawingInfo->getBondPrecision())); options->insert("ANGLE_LABEL_PRECISION", QString("%1").arg(drawingInfo->getAnglePrecision())); // Atoms options->insert("ATOM_DRAWING_STYLE", QString("%1").arg(drawingInfo->getDrawingStyle())); options->insert("ATOM_LABEL_SIZE", QString("%1").arg(Atom::SmallLabel)); resetToolBox(options); animationSlider->blockSignals(true); // Update toolbox widgets if (parser->numMolecules() <= 1) animationWidget->setEnabled(false); else animationWidget->setEnabled(true); animationSlider->setRange(0, parser->numMolecules() - 1); animationSlider->setValue(parser->current()); animationSlider->blockSignals(false); // Refresh layout QHBoxLayout* layout = new QHBoxLayout; QByteArray state = splitter->saveState(); QSplitter* old_splitter = splitter; splitter = new QSplitter(Qt::Horizontal); splitter->addWidget(view); splitter->addWidget(toolBox); if(!onNewMainWindow) splitter->restoreState(state); layout->addWidget(splitter); QWidget *widget = new QWidget; widget->setLayout(layout); this->setCentralWidget(widget); resetSignalsOnFileLoad(); reader.readNextStartElement(); if(reader.hasError()) error("Reader: " + reader.errorString()); else if(reader.name() != "cheMVP") error("Full document not parsed!"); delete old_parser; delete old_info; delete old_view; delete old_splitter; delete old_canvas; activateToolBar(); }
void MainWindow::loadFile() { if (!parser->fileName().isEmpty()) { if(parser->fileName().endsWith(".chmvp")) { error("Project loading in MainWindow::loadFile()"); return; } parser->readFile(); canvas->clearAll(); DrawingCanvas* old_canvas = canvas; DrawingInfo* old_info = drawingInfo; QGraphicsView* old_view = view; drawingInfo = new DrawingInfo(); // Includes loading canvas from parser canvas = new DrawingCanvas(this->drawingInfo, this->parser); setWindowTitle(tr("%1 - cheMVP").arg(parser->fileName())); this->view = new DrawingDisplay(canvas, drawingInfo); view->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); view->setGeometry(0, 0, static_cast<int>(DEFAULT_SCENE_SIZE_X), static_cast<int>(DEFAULT_SCENE_SIZE_Y)); // view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // Causes display issues on load view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); view->setViewportUpdateMode(QGraphicsView::FullViewportUpdate); resetToolBox(NULL); resetSignalsOnFileLoad(); // Enable the widgets in the animation tab if there are multiple geometries if (parser->numMolecules() <= 1) animationWidget->setEnabled(false); else animationWidget->setEnabled(true); // Set the sliders range and current value. animationSlider->setRange(0, parser->numMolecules() - 1); animationSlider->setValue(parser->current()); QHBoxLayout* layout = new QHBoxLayout; QByteArray state = splitter->saveState(); QSplitter* old_splitter = splitter; splitter = new QSplitter(Qt::Horizontal); splitter->addWidget(view); splitter->addWidget(toolBox); splitter->restoreState(state); layout->addWidget(splitter); QWidget *widget = new QWidget; widget->setLayout(layout); this->setCentralWidget(widget); delete old_info; delete old_view; delete old_splitter; delete old_canvas; activateToolBar(); } }