[PATCH 1/3] Better positioning of the plus sign icons in the Equip. tab

Lubomir I. Ivanov neolit123 at gmail.com
Thu Jun 27 05:33:43 PDT 2013


From: "Lubomir I. Ivanov" <neolit123 at gmail.com>

There are a couple of problems with said icons:
- When the Equip. tab is first seen, no relative event is monitored
so that the correct position is updated and the icons are positioned.

To solve that we connect the signal MainTab::currentChanged(int)
and call MainTab::equipmentPlusUpdate().

- When the info-profile QSplitter resizes with a snap towards/from
the edges of the main window, no resize handler is called such as
MainTab::resizeEvent().

A solution is to monitor the resize of the info-profile splitter
with MainWindow::on_infoProfileSplitter_splitterMoved() and again
call MainTab::equipmentPlusUpdate()

Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---

i wonder if there is a better solution with a per QGroupBox layout,
of sorts..
---
 qt-ui/maintab.cpp    | 27 +++++++++++++++++++--------
 qt-ui/maintab.h      |  2 ++
 qt-ui/mainwindow.cpp |  6 ++++++
 qt-ui/mainwindow.h   |  3 +++
 4 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index c6b49da..8437243 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -90,28 +90,39 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
 	ui->weights->horizontalHeader()->setResizeMode (WeightModel::REMOVE , QHeaderView::Fixed);
 	ui->weights->verticalHeader()->setDefaultSectionSize( metrics.height() +8 );
 	ui->weights->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate());
+
+	connect(this, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int)));
 	initialUiSetup();
 }
 
 // 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);
-
+	equipmentPlusUpdate();
 	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);
+	equipmentPlusUpdate();
+}
+
+void MainTab::tabChanged(int idx)
+{
+	/* if the current tab has become of index 1 (i.e. the equipment tab) call update
+	 * for the plus signs */
+	if (idx == 1)
+		equipmentPlusUpdate();
 }
 
+void MainTab::equipmentPlusUpdate()
+{
+	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);
+}
 
 bool MainTab::eventFilter(QObject* object, QEvent* event)
 {
diff --git a/qt-ui/maintab.h b/qt-ui/maintab.h
index 739c089..764ed23 100644
--- a/qt-ui/maintab.h
+++ b/qt-ui/maintab.h
@@ -43,6 +43,7 @@ public:
     virtual void hideEvent(QHideEvent* );
 
 	void initialUiSetup();
+	void equipmentPlusUpdate();
 
 
 public slots:
@@ -58,6 +59,7 @@ public slots:
 	void on_notes_textChanged();
 	void on_rating_valueChanged(int value);
 	void on_visibility_valueChanged(int value);
+	void tabChanged(int idx);
 
 private:
 	Ui::MainTab *ui;
diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 0655e7a..43376f9 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -299,6 +299,12 @@ void MainWindow::on_actionYearlyStatistics_triggered()
 	view->show();
 }
 
+void MainWindow::on_infoProfileSplitter_splitterMoved(int pos, int idx)
+{
+	/* always update the floating plus sign icons in the equipment tab */
+	ui->InfoWidget->equipmentPlusUpdate();
+}
+
 /**
  * So, here's the deal.
  * We have a few QSplitters that takes care of helping us with the
diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h
index bac7468..4890cb2 100644
--- a/qt-ui/mainwindow.h
+++ b/qt-ui/mainwindow.h
@@ -88,6 +88,9 @@ private slots:
 	void on_actionUserManual_triggered();
 	void on_actionDivePlanner_triggered();
 
+	/* monitor resize of the info-profile splitter */
+	void on_infoProfileSplitter_splitterMoved(int pos, int idx);
+
 	void current_dive_changed(int divenr);
 	void initialUiSetup();
 
-- 
1.7.11.msysgit.0



More information about the subsurface mailing list