void MainWindow::on_actionNew_triggered() { SetupDialog dialog; dialog.setModal(true); if(dialog.exec() != dialog.Accepted) return; int port = dialog.getPort(); int xSize = dialog.xSize(); int ySize = dialog.ySize(); Server *tmpState = new Server(port, xSize, ySize); line = new Line(tmpState); rect = new Rect(tmpState); freeHand = new FreeHand(tmpState); text = new Text(tmpState); ellips = new Ellips(tmpState); fill = new Fill(tmpState); erasor = new Eraser(tmpState); ui->canvas->setActiveState(tmpState); ui->canvas->setActiveTool(fill); text->setState(tmpState); delete state; state = tmpState; }
MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); SetupDialog dialog; dialog.setModal(true); if(dialog.exec() != dialog.Accepted) exit(0); int port = dialog.getPort(); if(dialog.isServer() && dialog.newFile()) { QString fileName = QFileDialog::getOpenFileName(this, "Save Image", // Caption "", // Default selection "Images (*.png *.jpg);;XML files (*.xml);;All files (*)"); // Filter QImage image; image.load(fileName); state = new Server(port, image.width(), image.height()); state->draw(&image); } else if(dialog.isServer()) { int xSize = dialog.xSize(); int ySize = dialog.ySize(); state = new Server(port, xSize, ySize); } else { QHostAddress host = QHostAddress(dialog.hostName()); cout << "We're a client with the host address: "; cout << dialog.hostName().toStdString() << endl; state = new Client(host, port); } ui->statusBar->showMessage(state->getStatus()); line = new Line(state); rect = new Rect(state); freeHand = new FreeHand(state); text = new Text(state); ellips = new Ellips(state); fill = new Fill(state); erasor = new Eraser(state); paste = new Paste(state); ui->canvas->setActiveState(state); ui->canvas->setActiveTool(freeHand); text->setState(state); connect(ui->colorPanel, SIGNAL(colorInPanelChanged(QColor)), this, SLOT(colorChanged(QColor))); // connect(ui->canvas, SIGNAL(mouseMovedTo(QString)), ui->statusBar, SLOT(showMessage(QString))); connect(state, SIGNAL(statusChanged()), this, SLOT(updateStatus())); ui->canvas->setMinimumSize(QSize(state->getImage()->width(), state->getImage()->height())); }