summaryrefslogtreecommitdiffstats
path: root/qt-ui/maintab.cpp
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-16 14:36:23 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-16 14:36:23 -0300
commitc917b29701470398b51aa5ad9541275825d912fd (patch)
treef73fc97ab5d0bc7654d793af31b7d7b99237e43c /qt-ui/maintab.cpp
parentc809b5a35bfee158f83a2c4467e9ad9c9b9b2350 (diff)
downloadsubsurface-c917b29701470398b51aa5ad9541275825d912fd.tar.gz
Save / Restore the sizes of the columns in Cylinders / Weigth widgets
This patch saves / restores the sizes of the columns in the cylinders and weigth table widgets, so everything is now properly behaved. There 's still other things to do - but I'm tired. i's sunday and there's a protest against the brazilian government to go. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui/maintab.cpp')
-rw-r--r--qt-ui/maintab.cpp48
1 files changed, 44 insertions, 4 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index bee94fb4b..c6b49da39 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -16,6 +16,7 @@
#include <QLabel>
#include <QDebug>
#include <QSet>
+#include <QSettings>
MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
ui(new Ui::MainTab()),
@@ -82,17 +83,14 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
QFontMetrics metrics(defaultModelFont());
QFontMetrics metrics2(font());
- ui->cylinders->setColumnWidth(CylindersModel::REMOVE, 24);
- ui->cylinders->setColumnWidth(CylindersModel::TYPE, metrics2.width(TankInfoModel::instance()->biggerString()) + 20);
ui->cylinders->horizontalHeader()->setResizeMode(CylindersModel::REMOVE, QHeaderView::Fixed);
ui->cylinders->verticalHeader()->setDefaultSectionSize( metrics.height() +8 );
ui->cylinders->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate());
- ui->weights->setColumnWidth(WeightModel::REMOVE, 24);
- ui->weights->setColumnWidth(WeightModel::TYPE, metrics2.width(WSInfoModel::instance()->biggerString()) + 20);
ui->weights->horizontalHeader()->setResizeMode (WeightModel::REMOVE , QHeaderView::Fixed);
ui->weights->verticalHeader()->setDefaultSectionSize( metrics.height() +8 );
ui->weights->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate());
+ initialUiSetup();
}
// We need to manually position the 'plus' on cylinder and weight.
@@ -481,3 +479,45 @@ void MainTab::on_visibility_valueChanged(int value)
return;
currentDive->visibility = value;
}
+
+void MainTab::hideEvent(QHideEvent* event)
+{
+ QSettings s;
+ s.beginGroup("MainTab");
+ s.beginGroup("Cylinders");
+ for (int i = 0; i < CylindersModel::COLUMNS; i++) {
+ s.setValue(QString("colwidth%1").arg(i), ui->cylinders->columnWidth(i));
+ }
+ s.endGroup();
+ s.beginGroup("Weights");
+ for (int i = 0; i < WeightModel::COLUMNS; i++) {
+ s.setValue(QString("colwidth%1").arg(i), ui->weights->columnWidth(i));
+ }
+ s.endGroup();
+ s.sync();
+}
+
+void MainTab::initialUiSetup()
+{
+ QSettings s;
+ s.beginGroup("MainTab");
+ s.beginGroup("Cylinders");
+ for (int i = 0; i < CylindersModel::COLUMNS; i++) {
+ QVariant width = s.value(QString("colwidth%1").arg(i));
+ if (width.isValid())
+ ui->cylinders->setColumnWidth(i, width.toInt());
+ else
+ ui->cylinders->resizeColumnToContents(i);
+ }
+ s.endGroup();
+ s.beginGroup("Weights");
+ for (int i = 0; i < WeightModel::COLUMNS; i++) {
+ QVariant width = s.value(QString("colwidth%1").arg(i));
+ if (width.isValid())
+ ui->weights->setColumnWidth(i, width.toInt());
+ else
+ ui->weights->resizeColumnToContents(i);
+ }
+ s.endGroup();
+
+}