PicMosaic::PicMosaic(QWidget *parent) : QWidget(parent), ui(new Ui::PicMosaic) { this->pixmap = new QPixmap; this->thread = new mosaicThread(this); ui->setupUi(this); this->ui->label->setPixmap(*this->pixmap); this->connect(this->thread,SIGNAL(throwBlock(Block)),this,SLOT(handleBlock(Block))); this->connect(this->thread,SIGNAL(finished()),this,SLOT(finishSlot())); this->ui->reset->setEnabled(false); this->ui->stop->setEnabled(false); this->connect(this->ui->stop,SIGNAL(clicked()),this->thread,SLOT(stop())); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), settings(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QDir::separator() + "settings.ini", QSettings::IniFormat), first(true), started(true) { srand(QDateTime::currentDateTime().toTime_t()); ui->setupUi(this); ui->customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectAxes | QCP::iSelectLegend | QCP::iSelectPlottables); // Axes ui->customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime); ui->customPlot->xAxis->setDateTimeFormat("hh:mm:ss"); ui->customPlot->xAxis->setAutoTickStep(false); ui->customPlot->xAxis->setTickStep(2); ui->customPlot->xAxis->setLabel("Time"); ui->customPlot->xAxis->setLabelPadding(0); ui->customPlot->xAxis->setSelectableParts(QCPAxis::spAxis); ui->customPlot->yAxis->setRange(-20, 20); ui->customPlot->yAxis->setLabel("Acceleration (m/s^2)"); ui->customPlot->yAxis->setLabelPadding(0); ui->customPlot->yAxis->setSelectableParts(QCPAxis::spAxis); ui->customPlot->axisRect()->setupFullAxesBox(); // Legend ui->customPlot->legend->setVisible(true); QFont legendFont = font(); legendFont.setPointSize(10); ui->customPlot->legend->setFont(legendFont); ui->customPlot->legend->setSelectedFont(legendFont); ui->customPlot->legend->setSelectableParts(QCPLegend::spNone); // X, Y, Z reading graphs ui->customPlot->addGraph(); // blue line ui->customPlot->graph(0)->setPen(QPen(Qt::blue)); ui->customPlot->graph(0)->setName("X"); ui->customPlot->graph(0)->setSelectable(false); ui->customPlot->addGraph(); // red line ui->customPlot->graph(1)->setPen(QPen(Qt::red)); ui->customPlot->graph(1)->setName("Y"); ui->customPlot->graph(1)->setSelectable(false); ui->customPlot->addGraph(); // green line ui->customPlot->graph(2)->setPen(QPen(Qt::green)); ui->customPlot->graph(2)->setName("Z"); ui->customPlot->graph(2)->setSelectable(false); // Scale in a particular direction when an axis is selected connect(ui->customPlot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(mousePress())); connect(ui->customPlot, SIGNAL(mouseWheel(QWheelEvent*)), this, SLOT(mouseWheel())); // Make bottom and left axes transfer their ranges to top and right axes: connect(ui->customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->xAxis2, SLOT(setRange(QCPRange))); connect(ui->customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->yAxis2, SLOT(setRange(QCPRange))); // Adjust the tick marks on x-axis scale connect(ui->customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(xAxisChanged(QCPRange))); // Context menu popup ui->customPlot->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->customPlot, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequest(QPoint))); // Buttons connect(ui->buttonStartStop, SIGNAL(released()), this, SLOT(pressedStartStop())); connect(ui->buttonAnalyze, SIGNAL(released()), this, SLOT(pressedAnalyze())); connect(ui->buttonSave, SIGNAL(released()), this, SLOT(pressedSave())); // Setup accelerometer accelerometer = new QAccelerometer(this); accelerometer->setAccelerationMode(QAccelerometer::Combined); accelerometer->setDataRate(30); accelerometer->addFilter(&filter); // We'll always keep it running since on the phone apparently calling // stop makes the whole application freeze. Thus, we'll just start/stop // recording data not actually requesting data from the accelerometer accelerometer->start(); // Button enabled/disabled coloring button_enabled = ui->buttonStartStop->palette(); button_disabled = ui->buttonStartStop->palette(); button_enabled.setColor(QPalette::Button, QColor(Qt::white)); button_disabled.setColor(QPalette::Button, QColor(Qt::lightGray)); // Load previous settings bool timed = settings.value("timed").toBool(); ui->checkBoxTimed->setChecked(timed); // When we start the application, either start it automatically if we're // not using a fixed period of time or set it up so we can press Start to // start it if we are using a fixed period of time if (timed) stop(); else start(); // Setup a timer that repeatedly calls MainWindow::realtimeDataSlot connect(&dataTimer, SIGNAL(timeout()), this, SLOT(realtimeDataSlot())); // Stop it after a certain period of time connect(&finishTimer, SIGNAL(timeout()), this, SLOT(finishSlot())); // Start with delay to reduce effect of touching the "Start" // button when recording for set amount of time connect(&startTimer, SIGNAL(timeout()), this, SLOT(startSlot())); }