diff options
Diffstat (limited to 'qt-ui/maintab.cpp')
-rw-r--r-- | qt-ui/maintab.cpp | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 10645c12f..a52058816 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -61,8 +61,50 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), if (label) label->setAlignment(Qt::AlignHCenter); } + + /*Thid couldn't be done on the ui file because element + is floating, instead of being fixed on the layout. */ + QIcon plusIcon(":plus"); + addCylinder = new QPushButton(plusIcon, QString(), ui->cylindersGroup); + addCylinder->setFlat(true); + addCylinder->setToolTip(tr("Add Cylinder")); + connect(addCylinder, SIGNAL(clicked(bool)), this, SLOT(addCylinder_clicked())); + addCylinder->setEnabled(false); + addWeight = new QPushButton(plusIcon, QString(), ui->weightGroup); + addWeight->setFlat(true); + addWeight->setToolTip(tr("Add Weight System")); + connect(addWeight, SIGNAL(clicked(bool)), this, SLOT(addWeight_clicked())); + addWeight->setEnabled(false); + + connect(ui->cylinders, SIGNAL(clicked(QModelIndex)), ui->cylinders->model(), SLOT(remove(QModelIndex))); + connect(ui->weights, SIGNAL(clicked(QModelIndex)), ui->weights->model(), SLOT(remove(QModelIndex))); + + ui->cylinders->setColumnWidth( CylindersModel::REMOVE, 24); + ui->cylinders->horizontalHeader()->setResizeMode (CylindersModel::REMOVE , QHeaderView::Fixed); + ui->weights->setColumnWidth( WeightModel::REMOVE, 24); + ui->cylinders->horizontalHeader()->setResizeMode (WeightModel::REMOVE , QHeaderView::Fixed); +} + +// We need to manually position the 'plus' on cylinder and weight. +void MainTab::resizeEvent(QResizeEvent* event) +{ + if (ui->cylindersGroup->isVisible()) + addCylinder->setGeometry( ui->cylindersGroup->contentsRect().width() - 30, 2, 24,24); + + if (ui->weightGroup->isVisible()) + addWeight->setGeometry( ui->weightGroup->contentsRect().width() - 30, 2, 24,24); + + QTabWidget::resizeEvent(event); } +void MainTab::showEvent(QShowEvent* event) +{ + QTabWidget::showEvent(event); + addCylinder->setGeometry( ui->cylindersGroup->contentsRect().width() - 30, 2, 24,24); + addWeight->setGeometry( ui->weightGroup->contentsRect().width() - 30, 2, 24,24); +} + + bool MainTab::eventFilter(QObject* object, QEvent* event) { if (event->type() == QEvent::FocusIn) { @@ -204,6 +246,8 @@ void MainTab::updateDiveInfo(int dive) ui->shortestAllText->setText(get_time_string(stats_selection.shortest_time.seconds, 0)); cylindersModel->setDive(d); weightModel->setDive(d); + addCylinder->setEnabled(true); + addWeight->setEnabled(true); } else { /* make the fields read-only */ ui->location->setReadOnly(true); @@ -230,6 +274,8 @@ void MainTab::updateDiveInfo(int dive) ui->airPressureText->clear(); cylindersModel->clear(); weightModel->clear(); + addCylinder->setEnabled(false); + addWeight->setEnabled(false); } /* statisticsTab*/ /* we can access the stats_selection struct, but how do we ensure the relevant dives are selected @@ -240,7 +286,7 @@ void MainTab::updateDiveInfo(int dive) // qDebug("min temp %u",stats_selection.min_temp); } -void MainTab::on_addCylinder_clicked() +void MainTab::addCylinder_clicked() { if (cylindersModel->rowCount() >= MAX_CYLINDERS) return; @@ -267,7 +313,7 @@ void MainTab::on_delCylinder_clicked() { } -void MainTab::on_addWeight_clicked() +void MainTab::addWeight_clicked() { if (weightModel->rowCount() >= MAX_WEIGHTSYSTEMS) return; |