diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-06-27 16:45:58 -0300 |
---|---|---|
committer | Tomaz Canabrava <tcanabrava@kde.org> | 2013-06-27 16:45:58 -0300 |
commit | c7c5ca7c3e1f4f9fb3d6a49a4b6eb2bcfdf2fb24 (patch) | |
tree | f78fd8be2b1e72b1db9b4552aa4ce8c58dd2587b /qt-ui | |
parent | 1244438b017f71be466ace7df9cad9462287fd30 (diff) | |
download | subsurface-c7c5ca7c3e1f4f9fb3d6a49a4b6eb2bcfdf2fb24.tar.gz |
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>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/diveplanner.cpp | 62 | ||||
-rw-r--r-- | qt-ui/diveplanner.h | 13 |
2 files changed, 71 insertions, 4 deletions
diff --git a/qt-ui/diveplanner.cpp b/qt-ui/diveplanner.cpp index e8cca8280..a8f45d91f 100644 --- a/qt-ui/diveplanner.cpp +++ b/qt-ui/diveplanner.cpp @@ -3,7 +3,12 @@ #include <cmath> #include <QMouseEvent> #include <QDebug> +#include <QGraphicsWidget> +#include <QGraphicsProxyWidget> +#include <QPushButton> + #include "ui_diveplanner.h" +#include "mainwindow.h" #define TIME_INITIAL_MAX 30 @@ -49,14 +54,39 @@ DivePlannerGraphics::DivePlannerGraphics(QWidget* parent): QGraphicsView(parent) scene()->addItem(depthString); plusDepth = new Button(); + plusDepth->setPixmap(QPixmap(":plus")); plusDepth->setPos(15, 1); scene()->addItem(plusDepth); connect(plusDepth, SIGNAL(clicked()), this, SLOT(increaseDepth())); plusTime = new Button(); + plusTime->setPixmap(QPixmap(":plus")); plusTime->setPos(95, 90); scene()->addItem(plusTime); 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() @@ -359,10 +389,38 @@ double Ruler::minimum() const 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); + 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) diff --git a/qt-ui/diveplanner.h b/qt-ui/diveplanner.h index 4029a6875..f2073515d 100644 --- a/qt-ui/diveplanner.h +++ b/qt-ui/diveplanner.h @@ -5,14 +5,20 @@ #include <QGraphicsPathItem> #include <QDialog> -class Button : public QObject, public QGraphicsPixmapItem { +class Button : public QObject, public QGraphicsRectItem { Q_OBJECT public: explicit Button(QObject* parent = 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 DiveHandler : public QGraphicsEllipseItem{ @@ -66,6 +72,8 @@ protected: private slots: void increaseTime(); void increaseDepth(); + void okClicked(); + void cancelClicked(); private: @@ -86,7 +94,8 @@ private: Button *plusDepth; Button *lessTime; Button *lessDepth; - + Button *okBtn; + Button *cancelBtn; QPointF lastValidPos; }; |