diff --git a/src/HomeWindow.cpp b/src/HomeWindow.cpp index 14a185c89..403866eca 100644 --- a/src/HomeWindow.cpp +++ b/src/HomeWindow.cpp @@ -575,22 +575,24 @@ HomeWindow::addChart(GcWindow* newone) } bool -HomeWindow::removeChart(int num) +HomeWindow::removeChart(int num, bool confirm) { if (num >= charts.count()) return false; // out of bounds (!) // better let the user confirm since this // is undoable etc - code swiped from delete // ride in MainWindow, seems to work ok ;) - QMessageBox msgBox; - msgBox.setText(tr("Are you sure you want to remove the chart?")); - QPushButton *deleteButton = msgBox.addButton(tr("Remove"),QMessageBox::YesRole); - msgBox.setStandardButtons(QMessageBox::Cancel); - msgBox.setDefaultButton(QMessageBox::Cancel); - msgBox.setIcon(QMessageBox::Critical); - msgBox.exec(); - if(msgBox.clickedButton() != deleteButton) return false; - + if(confirm == true) + { + QMessageBox msgBox; + msgBox.setText(tr("Are you sure you want to remove the chart?")); + QPushButton *deleteButton = msgBox.addButton(tr("Remove"),QMessageBox::YesRole); + msgBox.setStandardButtons(QMessageBox::Cancel); + msgBox.setDefaultButton(QMessageBox::Cancel); + msgBox.setIcon(QMessageBox::Critical); + msgBox.exec(); + if(msgBox.clickedButton() != deleteButton) return false; + } charts[num]->hide(); // just in case its currently selected @@ -627,6 +629,24 @@ HomeWindow::removeChart(int num) return true; } +void +HomeWindow::resetLayout() +{ + setUpdatesEnabled(false); + int numCharts = charts.count(); + for(int i = numCharts - 1; i >= 0; i--) // need to remove the charts from the end to the front + { + removeChart(i,false); + } + restoreState(true); + for(int i = 0; i < charts.count(); i++) + { + charts[i]->show(); + } + setUpdatesEnabled(true); + update(); +} + void HomeWindow::showEvent(QShowEvent *) { @@ -1278,12 +1298,17 @@ HomeWindow::saveState() } void -HomeWindow::restoreState() +HomeWindow::restoreState(bool useDefault) { // restore window state QString filename = mainWindow->home.absolutePath() + "/" + name + "-layout.xml"; QFileInfo finfo(filename); + if(useDefault) + { + QFile::remove(filename); + } + // use a default if not there if (!finfo.exists()) filename = QString(":xml/%1-layout.xml").arg(name); diff --git a/src/HomeWindow.h b/src/HomeWindow.h index 03e427136..6c4808afb 100644 --- a/src/HomeWindow.h +++ b/src/HomeWindow.h @@ -45,6 +45,8 @@ class HomeWindow : public GcWindow //int view() const { return viewMode->currentIndex(); } //void setView(int x) { viewMode->setCurrentIndex(x); } + void resetLayout(); + public slots: // GC signals @@ -63,12 +65,12 @@ class HomeWindow : public GcWindow // My widget signals and events void styleChanged(int); void addChart(GcWindow* newone); - bool removeChart(int); + bool removeChart(int, bool confirm = true); void titleChanged(); // save / restore window state void saveState(); - void restoreState(); + void restoreState(bool useDefault = false); //notifiction that been made visible void selected(); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index dd9d5e263..153797371 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -475,6 +475,7 @@ MainWindow::MainWindow(const QDir &home) : optionsMenu->addAction(tr("&Options..."), this, SLOT(showOptions()), tr("Ctrl+O")); optionsMenu->addAction(tr("Critical Power Calculator..."), this, SLOT(showTools())); optionsMenu->addAction(tr("Workout Wizard"), this, SLOT(showWorkoutWizard())); + optionsMenu->addAction(tr("Reset Window Layout"), this, SLOT(resetWindowLayout())); #ifdef GC_HAVE_ICAL optionsMenu->addSeparator(); @@ -816,6 +817,11 @@ void MainWindow::showWorkoutWizard() ww->show(); } +void MainWindow::resetWindowLayout() +{ + currentWindow->resetLayout(); +} + void MainWindow::dateChanged(const QDate &date) { for (int i = 0; i < allRides->childCount(); i++) @@ -877,6 +883,7 @@ MainWindow::selectAnalysis() masterControls->setCurrentIndex(0); views->setCurrentIndex(0); analWindow->selected(); // tell it! + currentWindow = analWindow; } void @@ -885,6 +892,7 @@ MainWindow::selectTrain() masterControls->setCurrentIndex(1); views->setCurrentIndex(1); trainWindow->selected(); // tell it! + currentWindow = trainWindow; } void @@ -893,6 +901,7 @@ MainWindow::selectDiary() masterControls->setCurrentIndex(2); views->setCurrentIndex(2); diaryWindow->selected(); // tell it! + currentWindow = diaryWindow; } void @@ -901,6 +910,7 @@ MainWindow::selectHome() masterControls->setCurrentIndex(3); views->setCurrentIndex(3); homeWindow->selected(); // tell it! + currentWindow = homeWindow; } void MainWindow::selectAthlete() diff --git a/src/MainWindow.h b/src/MainWindow.h index 0f4c76551..fdccce4e9 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -209,6 +209,7 @@ class MainWindow : public QMainWindow void showSidebar(bool want); void showToolbar(bool want); void showWorkoutWizard(); + void resetWindowLayout(); void dateChanged(const QDate &); void showTreeContextMenuPopup(const QPoint &); void showContextMenuPopup(const QPoint &); @@ -279,6 +280,7 @@ class MainWindow : public QMainWindow HomeWindow *diaryWindow; HomeWindow *trainWindow; HomeWindow *analWindow; + HomeWindow *currentWindow; // tracks the curerntly showing window // sidebar QTreeWidgetItem *allRides;