Remove a ton of code.

The code removed was already ported to the New Profile.
We managed to clean quite a bit. huhhy

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-05-23 22:39:51 -03:00 committed by Dirk Hohndel
parent 93f35971c6
commit d2569c6688
4 changed files with 8 additions and 221 deletions

View file

@ -43,67 +43,9 @@ QString dpGasToStr(const divedatapoint &p)
static DivePlannerPointsModel *plannerModel = DivePlannerPointsModel::instance();
DivePlannerGraphics::DivePlannerGraphics(QWidget *parent) : QGraphicsView(parent),
verticalLine(new QGraphicsLineItem(fromPercent(0, Qt::Horizontal), fromPercent(0, Qt::Vertical), fromPercent(0, Qt::Horizontal), fromPercent(100, Qt::Vertical))),
horizontalLine(new QGraphicsLineItem(fromPercent(0, Qt::Horizontal), fromPercent(0, Qt::Vertical), fromPercent(100, Qt::Horizontal), fromPercent(0, Qt::Vertical))),
activeDraggedHandler(0),
diveBg(new QGraphicsPolygonItem()),
timeString(new QGraphicsSimpleTextItem()),
depthString(new QGraphicsSimpleTextItem()),
depthHandler(new ExpanderGraphics()),
timeHandler(new ExpanderGraphics()),
minMinutes(TIME_INITIAL_MAX),
minDepth(M_OR_FT(40, 120)),
dpMaxTime(0)
DivePlannerGraphics::DivePlannerGraphics(QWidget *parent) : QGraphicsView(parent)
{
setBackgroundBrush(profile_color[BACKGROUND].at(0));
setMouseTracking(true);
setScene(new QGraphicsScene());
scene()->setSceneRect(0, 0, 1920, 1080);
verticalLine->setPen(QPen(Qt::DotLine));
scene()->addItem(verticalLine);
horizontalLine->setPen(QPen(Qt::DotLine));
scene()->addItem(horizontalLine);
timeString->setFlag(QGraphicsItem::ItemIgnoresTransformations);
timeString->setBrush(profile_color[TIME_TEXT].at(0));
scene()->addItem(timeString);
depthString->setFlag(QGraphicsItem::ItemIgnoresTransformations);
depthString->setBrush(profile_color[SAMPLE_DEEP].at(0));
scene()->addItem(depthString);
diveBg->setPen(QPen(QBrush(), 0));
scene()->addItem(diveBg);
QString incrText;
if (prefs.units.length == units::METERS)
incrText = tr("10m");
else
incrText = tr("30ft");
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->increaseBtn->setPixmap(QString(":arrow_down"));
depthHandler->decreaseBtn->setPixmap(QString(":arrow_up"));
depthHandler->icon->setPixmap(QString(":icon_depth"));
connect(depthHandler->decreaseBtn, SIGNAL(clicked()), this, SLOT(decreaseDepth()));
connect(depthHandler->increaseBtn, SIGNAL(clicked()), this, SLOT(increaseDepth()));
depthHandler->setPos(fromPercent(0, Qt::Horizontal), fromPercent(100, Qt::Vertical));
depthHandler->setZValue(-2);
scene()->addItem(depthHandler);
QAction *action = NULL;
#define ADD_ACTION(SHORTCUT, Slot) \
action = new QAction(this); \
action->setShortcut(SHORTCUT); \
@ -118,8 +60,6 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget *parent) : QGraphicsView(parent
ADD_ACTION(Qt::Key_Left, keyLeftAction());
ADD_ACTION(Qt::Key_Right, keyRightAction());
#undef ADD_ACTION
setRenderHint(QPainter::Antialiasing);
}
void DivePlannerGraphics::keyDownAction()
@ -337,7 +277,7 @@ void DivePlannerPointsModel::removeDeco()
removeSelectedPoints(computedPoints);
setRecalc(oldrec);
}
#if 0
void DivePlannerGraphics::drawProfile()
{
// Code ported to the new profile is deleted. This part that I left here
@ -349,6 +289,7 @@ void DivePlannerGraphics::drawProfile()
plannerModel->setRecalc(oldRecalc);
plannerModel->deleteTemporaryPlan();
}
#endif
DiveHandler::DiveHandler() : QGraphicsEllipseItem()
{
@ -360,7 +301,7 @@ DiveHandler::DiveHandler() : QGraphicsEllipseItem()
int DiveHandler::parentIndex()
{
DivePlannerGraphics *view = qobject_cast<DivePlannerGraphics *>(scene()->views().first());
ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
return view->handles.indexOf(this);
}
@ -383,9 +324,11 @@ void DiveHandler::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
void DiveHandler::selfRemove()
{
#if 0
setSelected(true);
DivePlannerGraphics *view = qobject_cast<DivePlannerGraphics *>(scene()->views().first());
ProfileWidget2 *view = qobject_cast<ProfileWidget2 *>(scene()->views().first());
view->keyDeleteAction();
#endif
}
void DiveHandler::changeGas()
@ -404,47 +347,6 @@ void DiveHandler::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
emit moved();
}
Button::Button(QObject *parent, QGraphicsItem *itemParent) : QObject(parent),
QGraphicsRectItem(itemParent),
icon(new QGraphicsPixmapItem(this)),
text(new QGraphicsSimpleTextItem(this))
{
icon->setPos(0, 0);
text->setPos(0, 0);
setFlag(ItemIgnoresTransformations);
setPen(QPen(QBrush(), 0));
}
void Button::setPixmap(const QPixmap &pixmap)
{
icon->setPixmap(pixmap);
if (pixmap.isNull())
icon->hide();
else
icon->show();
setRect(childrenBoundingRect());
}
void Button::setText(const QString &t)
{
text->setText(t);
if (icon->pixmap().isNull()) {
icon->hide();
text->setPos(0, 0);
} else {
icon->show();
text->setPos(22, 0);
}
setRect(childrenBoundingRect());
}
void Button::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
event->ignore();
emit clicked();
}
DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
{
ui.setupUi(this);
@ -1099,39 +1001,3 @@ void DivePlannerPointsModel::createPlan()
CylindersModel::instance()->update();
plannerModel->setRecalc(oldRecalc);
}
ExpanderGraphics::ExpanderGraphics(QGraphicsItem *parent) : QGraphicsRectItem(parent),
icon(new QGraphicsPixmapItem(this)),
increaseBtn(new Button(0, this)),
decreaseBtn(new Button(0, this)),
bg(new QGraphicsPixmapItem(this)),
leftWing(new QGraphicsPixmapItem(this)),
rightWing(new QGraphicsPixmapItem(this))
{
icon->setPixmap(QPixmap(":icon_time"));
bg->setPixmap(QPixmap(":round_base"));
leftWing->setPixmap(QPixmap(":left_wing"));
rightWing->setPixmap(QPixmap(":right_wing"));
decreaseBtn->setPixmap(QPixmap(":arrow_down"));
increaseBtn->setPixmap(QPixmap(":arrow_up"));
setFlag(ItemIgnoresTransformations);
leftWing->setZValue(-2);
rightWing->setZValue(-2);
bg->setZValue(-1);
leftWing->setPos(0, 0);
bg->setPos(leftWing->pos().x() + leftWing->boundingRect().width() - 60, 5);
rightWing->setPos(leftWing->pos().x() + leftWing->boundingRect().width() - 20, 0);
decreaseBtn->setPos(leftWing->pos().x(), leftWing->pos().y());
increaseBtn->setPos(rightWing->pos().x(), rightWing->pos().y());
icon->setPos(bg->pos().x(), bg->pos().y() - 5);
//I need to bottom align the items, I need to make the 0,0 ( orgin ) to be
// the bottom of this item, so shift everything up.
QRectF r = childrenBoundingRect();
Q_FOREACH (QGraphicsItem *i, childItems()) {
i->setPos(i->pos().x(), i->pos().y() - r.height());
}
setScale(0.7);
}

View file

@ -101,38 +101,6 @@ private:
QVector<QPair<int, int> > oldGases;
};
class Button : public QObject, public QGraphicsRectItem {
Q_OBJECT
public:
Button(QObject *parent = 0, QGraphicsItem *itemParent = 0);
void setText(const QString &text);
void setPixmap(const QPixmap &pixmap);
protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
signals:
void clicked();
private:
QGraphicsPixmapItem *icon;
QGraphicsSimpleTextItem *text;
};
class ExpanderGraphics : public QGraphicsRectItem {
public:
ExpanderGraphics(QGraphicsItem *parent = 0);
QGraphicsPixmapItem *icon;
Button *increaseBtn;
Button *decreaseBtn;
private:
QGraphicsPixmapItem *bg;
QGraphicsPixmapItem *leftWing;
QGraphicsPixmapItem *rightWing;
};
class DiveHandler : public QObject, public QGraphicsEllipseItem {
Q_OBJECT
public:
@ -155,11 +123,6 @@ class DivePlannerGraphics : public QGraphicsView {
Q_OBJECT
public:
DivePlannerGraphics(QWidget *parent = 0);
protected:
virtual void showEvent(QShowEvent *event);
virtual void resizeEvent(QResizeEvent *event);
qreal fromPercent(qreal percent, Qt::Orientation orientation);
private
slots:
void keyEscAction();
@ -168,46 +131,6 @@ slots:
void keyDownAction();
void keyLeftAction();
void keyRightAction();
private:
void moveActiveHandler(const QPointF &MappedPos, const int pos);
/* This are the lines of the plotted dive. */
QList<QGraphicsLineItem *> lines;
/* This is the user-entered handles. */
QList<DiveHandler *> handles;
QList<QGraphicsSimpleTextItem *> gases;
/* those are the lines that follows the mouse. */
QGraphicsLineItem *verticalLine;
QGraphicsLineItem *horizontalLine;
/* This is the handler that's being dragged. */
DiveHandler *activeDraggedHandler;
// When we start to move the handler, this pos is saved.
// so we can revert it later.
QPointF originalHandlerPos;
/* this is the background of the dive, the blue-gradient. */
QGraphicsPolygonItem *diveBg;
/* This is the bottom ruler - the x axis, and it's associated text */
QGraphicsSimpleTextItem *timeString;
/* this is the left ruler, the y axis, and it's associated text. */
QGraphicsSimpleTextItem *depthString;
/* Buttons */
ExpanderGraphics *depthHandler;
ExpanderGraphics *timeHandler;
int minMinutes; // this holds the minimum requested window time
int minDepth; // this holds the minimum requested window depth
int dpMaxTime; // this is the time of the dive calculated by the deco.
friend class DiveHandler;
};
#include "ui_diveplanner.h"

View file

@ -68,7 +68,6 @@ MainWindow::MainWindow() : QMainWindow(),
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.ListWidget, SLOT(update()));
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.ListWidget, SLOT(reloadHeaderActions()));
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.InfoWidget, SLOT(updateDiveInfo()));
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.divePlanner, SLOT(settingsChanged()));
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), ui.divePlannerWidget, SLOT(settingsChanged()));
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), TankInfoModel::instance(), SLOT(update()));
connect(ui.actionRecent1, SIGNAL(triggered(bool)), this, SLOT(recentFileTriggered(bool)));
@ -86,10 +85,8 @@ MainWindow::MainWindow() : QMainWindow(),
ui.globe->reload();
ui.ListWidget->expand(ui.ListWidget->model()->index(0, 0));
ui.ListWidget->scrollTo(ui.ListWidget->model()->index(0, 0), QAbstractItemView::PositionAtCenter);
ui.divePlanner->settingsChanged();
ui.divePlannerWidget->settingsChanged();
#ifndef ENABLE_PLANNER
ui.menuLog->removeAction(ui.actionDivePlanner);
#endif

View file

@ -150,6 +150,7 @@ private:
QList<QGraphicsSimpleTextItem *> gases;
void repositionDiveHandlers();
int fixHandlerIndex(DiveHandler *activeHandler);
friend class DiveHandler;
};
#endif // PROFILEWIDGET2_H