mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Added the Ok / Cancel buttons on the dive planner canvas.
Added the ok / cancel buttons on the dive planner canvas. I still need to hook the esc button to cancel it too, but since I removed the 'floating dialog' option and merged it into the mainwindow, it's necessary. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
This commit is contained in:
parent
1244438b01
commit
c7c5ca7c3e
2 changed files with 71 additions and 4 deletions
|
@ -3,7 +3,12 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QGraphicsWidget>
|
||||||
|
#include <QGraphicsProxyWidget>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
#include "ui_diveplanner.h"
|
#include "ui_diveplanner.h"
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
#define TIME_INITIAL_MAX 30
|
#define TIME_INITIAL_MAX 30
|
||||||
|
|
||||||
|
@ -49,14 +54,39 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent)
|
||||||
scene()->addItem(depthString);
|
scene()->addItem(depthString);
|
||||||
|
|
||||||
plusDepth = new Button();
|
plusDepth = new Button();
|
||||||
|
plusDepth->setPixmap(QPixmap(":plus"));
|
||||||
plusDepth->setPos(15, 1);
|
plusDepth->setPos(15, 1);
|
||||||
scene()->addItem(plusDepth);
|
scene()->addItem(plusDepth);
|
||||||
connect(plusDepth, SIGNAL(clicked()), this, SLOT(increaseDepth()));
|
connect(plusDepth, SIGNAL(clicked()), this, SLOT(increaseDepth()));
|
||||||
|
|
||||||
plusTime = new Button();
|
plusTime = new Button();
|
||||||
|
plusTime->setPixmap(QPixmap(":plus"));
|
||||||
plusTime->setPos(95, 90);
|
plusTime->setPos(95, 90);
|
||||||
scene()->addItem(plusTime);
|
scene()->addItem(plusTime);
|
||||||
connect(plusTime, SIGNAL(clicked()), this, SLOT(increaseTime()));
|
connect(plusTime, SIGNAL(clicked()), this, SLOT(increaseTime()));
|
||||||
|
|
||||||
|
okBtn = new Button();
|
||||||
|
okBtn->setText(tr("Ok"));
|
||||||
|
okBtn->setPos(1, 95);
|
||||||
|
scene()->addItem(okBtn);
|
||||||
|
connect(okBtn, SIGNAL(clicked()), this, SLOT(okClicked()));
|
||||||
|
|
||||||
|
cancelBtn = new Button();
|
||||||
|
cancelBtn->setText(tr("Cancel"));
|
||||||
|
cancelBtn->setPos(10,95);
|
||||||
|
scene()->addItem(cancelBtn);
|
||||||
|
connect(cancelBtn, SIGNAL(clicked()), this, SLOT(cancelClicked()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void DivePlannerGraphics::cancelClicked()
|
||||||
|
{
|
||||||
|
qDebug() << "clicked";
|
||||||
|
mainWindow()->showProfile();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DivePlannerGraphics::okClicked()
|
||||||
|
{
|
||||||
|
// todo.
|
||||||
}
|
}
|
||||||
|
|
||||||
void DivePlannerGraphics::increaseDepth()
|
void DivePlannerGraphics::increaseDepth()
|
||||||
|
@ -359,10 +389,38 @@ double Ruler::minimum() const
|
||||||
return min;
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
Button::Button(QObject* parent): QObject(parent), QGraphicsPixmapItem()
|
Button::Button(QObject* parent): QObject(parent), QGraphicsRectItem()
|
||||||
{
|
{
|
||||||
setPixmap(QPixmap(":plus").scaled(20,20));
|
icon = new QGraphicsPixmapItem(this);
|
||||||
|
text = new QGraphicsSimpleTextItem(this);
|
||||||
|
icon->setPos(0,0);
|
||||||
|
text->setPos(0,0);
|
||||||
setFlag(ItemIgnoresTransformations);
|
setFlag(ItemIgnoresTransformations);
|
||||||
|
setPen(QPen(QBrush(Qt::white), 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Button::setPixmap(const QPixmap& pixmap)
|
||||||
|
{
|
||||||
|
icon->setPixmap(pixmap.scaled(20,20));
|
||||||
|
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)
|
void Button::mousePressEvent(QGraphicsSceneMouseEvent* event)
|
||||||
|
|
|
@ -5,14 +5,20 @@
|
||||||
#include <QGraphicsPathItem>
|
#include <QGraphicsPathItem>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
|
||||||
class Button : public QObject, public QGraphicsPixmapItem {
|
class Button : public QObject, public QGraphicsRectItem {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Button(QObject* parent = 0);
|
explicit Button(QObject* parent = 0);
|
||||||
|
void setText(const QString& text);
|
||||||
|
void setPixmap(const QPixmap& pixmap);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
|
virtual void mousePressEvent(QGraphicsSceneMouseEvent* event);
|
||||||
signals:
|
signals:
|
||||||
void clicked();
|
void clicked();
|
||||||
|
private:
|
||||||
|
QGraphicsPixmapItem *icon;
|
||||||
|
QGraphicsSimpleTextItem *text;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DiveHandler : public QGraphicsEllipseItem{
|
class DiveHandler : public QGraphicsEllipseItem{
|
||||||
|
@ -66,6 +72,8 @@ protected:
|
||||||
private slots:
|
private slots:
|
||||||
void increaseTime();
|
void increaseTime();
|
||||||
void increaseDepth();
|
void increaseDepth();
|
||||||
|
void okClicked();
|
||||||
|
void cancelClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -86,7 +94,8 @@ private:
|
||||||
Button *plusDepth;
|
Button *plusDepth;
|
||||||
Button *lessTime;
|
Button *lessTime;
|
||||||
Button *lessDepth;
|
Button *lessDepth;
|
||||||
|
Button *okBtn;
|
||||||
|
Button *cancelBtn;
|
||||||
QPointF lastValidPos;
|
QPointF lastValidPos;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue