ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent), currentState(INVALID), dataModel(new DivePlotDataModel(this)), zoomLevel(0), zoomFactor(1.15), background(new DivePixmapItem()), backgroundFile(":poster"), toolTipItem(new ToolTipItem()), isPlotZoomed(prefs.zoomed_plot), forceReplot(false), profileYAxis(new DepthAxis()), gasYAxis(new PartialGasPressureAxis()), temperatureAxis(new TemperatureAxis()), timeAxis(new TimeAxis()), diveProfileItem(new DiveProfileItem()), temperatureItem(new DiveTemperatureItem()), cylinderPressureAxis(new DiveCartesianAxis()), gasPressureItem(new DiveGasPressureItem()), meanDepth(new MeanDepthLine()), diveComputerText(new DiveTextItem()), diveCeiling(new DiveCalculatedCeiling()), reportedCeiling(new DiveReportedCeiling()), pn2GasItem(new PartialPressureGasItem()), pheGasItem(new PartialPressureGasItem()), po2GasItem(new PartialPressureGasItem()), heartBeatAxis(new DiveCartesianAxis()), heartBeatItem(new DiveHeartrateItem()), rulerItem(new RulerItem2()), isGrayscale(false), printMode(false), shouldCalculateMaxTime(true) { memset(&plotInfo, 0, sizeof(plotInfo)); setupSceneAndFlags(); setupItemSizes(); setupItemOnScene(); addItemsToScene(); scene()->installEventFilter(this); setEmptyState(); connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged())); QAction *action = NULL; #define ADD_ACTION(SHORTCUT, Slot) \ action = new QAction(this); \ action->setShortcut(SHORTCUT); \ action->setShortcutContext(Qt::WindowShortcut); \ addAction(action); \ connect(action, SIGNAL(triggered(bool)), this, SLOT(Slot)); \ actionsForKeys[SHORTCUT] = action; ADD_ACTION(Qt::Key_Escape, keyEscAction()); ADD_ACTION(Qt::Key_Delete, keyDeleteAction()); ADD_ACTION(Qt::Key_Up, keyUpAction()); ADD_ACTION(Qt::Key_Down, keyDownAction()); ADD_ACTION(Qt::Key_Left, keyLeftAction()); ADD_ACTION(Qt::Key_Right, keyRightAction()); #undef ADD_ACTION #ifndef QT_NO_DEBUG QTableView *diveDepthTableView = new QTableView(); diveDepthTableView->setModel(dataModel); diveDepthTableView->show(); #endif }
DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0) { fill_profile_color(); setBackgroundBrush(profile_color[BACKGROUND].at(0)); setMouseTracking(true); setScene(new QGraphicsScene()); scene()->setSceneRect(0,0,1920,1080); verticalLine = new QGraphicsLineItem( fromPercent(0, Qt::Horizontal), fromPercent(0, Qt::Vertical), fromPercent(0, Qt::Horizontal), fromPercent(100, Qt::Vertical) ); verticalLine->setPen(QPen(Qt::DotLine)); scene()->addItem(verticalLine); horizontalLine = new QGraphicsLineItem( fromPercent(0, Qt::Horizontal), fromPercent(0, Qt::Vertical), fromPercent(100, Qt::Horizontal), fromPercent(0, Qt::Vertical) ); horizontalLine->setPen(QPen(Qt::DotLine)); scene()->addItem(horizontalLine); timeLine = new Ruler(); timeLine->setMinimum(0); timeLine->setMaximum(TIME_INITIAL_MAX); timeLine->setTickInterval(10); timeLine->setColor(getColor(TIME_GRID)); timeLine->setLine( fromPercent(10, Qt::Horizontal), fromPercent(85, Qt::Vertical), fromPercent(90, Qt::Horizontal), fromPercent(85, Qt::Vertical) ); timeLine->setOrientation(Qt::Horizontal); timeLine->setTickSize(fromPercent(1, Qt::Vertical)); timeLine->setTextColor(getColor(TIME_TEXT)); timeLine->updateTicks(); scene()->addItem(timeLine); depthLine = new Ruler(); depthLine->setMinimum(0); depthLine->setMaximum(M_OR_FT(40,120)); depthLine->setTickInterval(M_OR_FT(10,30)); depthLine->setLine( fromPercent(10, Qt::Horizontal), fromPercent(10, Qt::Vertical), fromPercent(10, Qt::Horizontal), fromPercent(85, Qt::Vertical) ); depthLine->setOrientation(Qt::Vertical); depthLine->setTickSize(fromPercent(1, Qt::Horizontal)); depthLine->setColor(getColor(DEPTH_GRID)); depthLine->setTextColor(getColor(SAMPLE_DEEP)); depthLine->updateTicks(); scene()->addItem(depthLine); timeString = new QGraphicsSimpleTextItem(); timeString->setFlag(QGraphicsItem::ItemIgnoresTransformations); timeString->setBrush(profile_color[TIME_TEXT].at(0)); scene()->addItem(timeString); depthString = new QGraphicsSimpleTextItem(); depthString->setFlag(QGraphicsItem::ItemIgnoresTransformations); depthString->setBrush(profile_color[SAMPLE_DEEP].at(0)); scene()->addItem(depthString); diveBg = new QGraphicsPolygonItem(); diveBg->setPen(QPen(QBrush(),0)); scene()->addItem(diveBg); QString incrText; if (prefs.units.length == units::METERS) incrText = tr("10m"); else incrText = tr("30ft"); timeHandler = new ExpanderGraphics(); timeHandler->increaseBtn->setPixmap(QString(":plan_plus")); timeHandler->decreaseBtn->setPixmap(QString(":plan_minus")); timeHandler->icon->setPixmap(QString(":icon_time")); connect(timeHandler->increaseBtn, SIGNAL(clicked()), this, SLOT(increaseTime())); connect(timeHandler->decreaseBtn, SIGNAL(clicked()), this, SLOT(decreaseTime())); timeHandler->setPos(fromPercent(83, Qt::Horizontal), fromPercent(100, Qt::Vertical)); timeHandler->setZValue(-2); scene()->addItem(timeHandler); depthHandler = new ExpanderGraphics(); depthHandler->increaseBtn->setPixmap(QString(":arrow_up")); depthHandler->decreaseBtn->setPixmap(QString(":arrow_down")); depthHandler->icon->setPixmap(QString(":icon_depth")); // Inverted here in the slots because the 'up' graphi should increase the depness, // and the down should decrease. connect(depthHandler->increaseBtn, SIGNAL(clicked()), this, SLOT(decreaseDepth())); connect(depthHandler->decreaseBtn, SIGNAL(clicked()), this, SLOT(increaseDepth())); depthHandler->setPos(fromPercent(0, Qt::Horizontal), fromPercent(100, Qt::Vertical)); depthHandler->setZValue(-2); scene()->addItem(depthHandler); minMinutes = TIME_INITIAL_MAX; QAction *action = NULL; #define ADD_ACTION( SHORTCUT, Slot ) \ action = new QAction(this); \ action->setShortcut( SHORTCUT ); \ action->setShortcutContext(Qt::WindowShortcut); \ addAction(action); \ connect(action, SIGNAL(triggered(bool)), this, SLOT( Slot )) ADD_ACTION(Qt::Key_Escape, keyEscAction()); ADD_ACTION(Qt::Key_Delete, keyDeleteAction()); ADD_ACTION(Qt::Key_Up, keyUpAction()); ADD_ACTION(Qt::Key_Down, keyDownAction()); ADD_ACTION(Qt::Key_Left, keyLeftAction()); ADD_ACTION(Qt::Key_Right, keyRightAction()); #undef ADD_ACTION connect(plannerModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(drawProfile())); connect(plannerModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(pointInserted(const QModelIndex&, int, int))); connect(plannerModel, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), this, SLOT(pointsRemoved(const QModelIndex&, int, int))); setRenderHint(QPainter::Antialiasing); }
DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent), activeDraggedHandler(0) { fill_profile_color(); setBackgroundBrush(profile_color[BACKGROUND].at(0)); setMouseTracking(true); setScene(new QGraphicsScene()); scene()->setSceneRect(0,0,1920,1080); verticalLine = new QGraphicsLineItem( fromPercent(0, Qt::Horizontal), fromPercent(0, Qt::Vertical), fromPercent(0, Qt::Horizontal), fromPercent(100, Qt::Vertical) ); verticalLine->setPen(QPen(Qt::DotLine)); scene()->addItem(verticalLine); horizontalLine = new QGraphicsLineItem( fromPercent(0, Qt::Horizontal), fromPercent(0, Qt::Vertical), fromPercent(100, Qt::Horizontal), fromPercent(0, Qt::Vertical) ); horizontalLine->setPen(QPen(Qt::DotLine)); scene()->addItem(horizontalLine); timeLine = new Ruler(); timeLine->setMinimum(0); timeLine->setMaximum(TIME_INITIAL_MAX); timeLine->setTickInterval(10); timeLine->setColor(getColor(TIME_GRID)); timeLine->setLine( fromPercent(10, Qt::Horizontal), fromPercent(90, Qt::Vertical), fromPercent(90, Qt::Horizontal), fromPercent(90, Qt::Vertical) ); timeLine->setOrientation(Qt::Horizontal); timeLine->setTickSize(fromPercent(1, Qt::Vertical)); timeLine->setTextColor(getColor(TIME_TEXT)); timeLine->updateTicks(); scene()->addItem(timeLine); depthLine = new Ruler(); depthLine->setMinimum(0); depthLine->setMaximum(M_OR_FT(40,120)); depthLine->setTickInterval(M_OR_FT(10,30)); depthLine->setLine( fromPercent(10, Qt::Horizontal), fromPercent(10, Qt::Vertical), fromPercent(10, Qt::Horizontal), fromPercent(90, Qt::Vertical) ); depthLine->setOrientation(Qt::Vertical); depthLine->setTickSize(fromPercent(1, Qt::Horizontal)); depthLine->setColor(getColor(DEPTH_GRID)); depthLine->setTextColor(getColor(SAMPLE_DEEP)); depthLine->updateTicks(); scene()->addItem(depthLine); timeString = new QGraphicsSimpleTextItem(); timeString->setFlag(QGraphicsItem::ItemIgnoresTransformations); timeString->setBrush(profile_color[TIME_TEXT].at(0)); scene()->addItem(timeString); depthString = new QGraphicsSimpleTextItem(); depthString->setFlag(QGraphicsItem::ItemIgnoresTransformations); depthString->setBrush(profile_color[SAMPLE_DEEP].at(0)); scene()->addItem(depthString); diveBg = new QGraphicsPolygonItem(); diveBg->setPen(QPen(QBrush(),0)); scene()->addItem(diveBg); #define ADDBTN(obj, icon, text, horizontal, vertical, tooltip, value, slot) \ obj = new Button(); \ obj->setPixmap(QPixmap(icon)); \ obj->setPos(fromPercent(horizontal, Qt::Horizontal), fromPercent(vertical, Qt::Vertical)); \ obj->setToolTip(QString(tooltip.arg(value))); \ scene()->addItem(obj); \ connect(obj, SIGNAL(clicked()), this, SLOT(slot)); QString incrText; if (prefs.units.length == units::METERS) incrText = tr("10m"); else incrText = tr("30ft"); ADDBTN(plusDepth, ":plus", "" , 5, 5, tr("Increase maximum depth by %1"), incrText, increaseDepth()); ADDBTN(lessDepth, ":minimum","" , 2, 5, tr("Decreases maximum depth by %1"), incrText, decreaseDepth()); ADDBTN(plusTime, ":plus", "" , 95, 95, tr("Increase minimum time by %1"), tr("10min"), increaseTime()); ADDBTN(lessTime, ":minimum","" , 92, 95, tr("Decreases minimum time by %1"), tr("10min"), decreaseTime()); #undef ADDBTN minMinutes = TIME_INITIAL_MAX; QAction *action = NULL; #define ADD_ACTION( SHORTCUT, Slot ) \ action = new QAction(this); \ action->setShortcut( SHORTCUT ); \ action->setShortcutContext(Qt::WindowShortcut); \ addAction(action); \ connect(action, SIGNAL(triggered(bool)), this, SLOT( Slot )) ADD_ACTION(Qt::Key_Escape, keyEscAction()); ADD_ACTION(Qt::Key_Delete, keyDeleteAction()); ADD_ACTION(Qt::Key_Up, keyUpAction()); ADD_ACTION(Qt::Key_Down, keyDownAction()); ADD_ACTION(Qt::Key_Left, keyLeftAction()); ADD_ACTION(Qt::Key_Right, keyRightAction()); #undef ADD_ACTION // Prepare the stuff for the gas-choices. gasListView = new QListView(); gasListView->setWindowFlags(Qt::Popup); gasListView->setModel(GasSelectionModel::instance()); gasListView->hide(); gasListView->installEventFilter(this); connect(gasListView, SIGNAL(activated(QModelIndex)), this, SLOT(selectGas(QModelIndex))); connect(plannerModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(drawProfile())); connect(plannerModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), this, SLOT(pointInserted(const QModelIndex&, int, int))); connect(plannerModel, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), this, SLOT(pointsRemoved(const QModelIndex&, int, int))); setRenderHint(QPainter::Antialiasing); }