Commit 35299cfeb4efc9277795f8330244a05253a59d0c
1 parent
ecc9e1d7
Saving positions of docking windows and toolbars now and made it possible to set…
… their visibility via the View menu
Showing
4 changed files
with
280 additions
and
29 deletions
openhantek/src/openhantek.cpp
| @@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
| 3 | // OpenHantek | 3 | // OpenHantek |
| 4 | // openhantek.cpp | 4 | // openhantek.cpp |
| 5 | // | 5 | // |
| 6 | -// Copyright (C) 2010 Oliver Haag | 6 | +// Copyright (C) 2010, 2011 Oliver Haag |
| 7 | // oliver.haag@gmail.com | 7 | // oliver.haag@gmail.com |
| 8 | // | 8 | // |
| 9 | // This program is free software: you can redistribute it and/or modify it | 9 | // This program is free software: you can redistribute it and/or modify it |
| @@ -68,7 +68,6 @@ OpenHantekMainWindow::OpenHantekMainWindow(QWidget *parent, Qt::WindowFlags flag | @@ -68,7 +68,6 @@ OpenHantekMainWindow::OpenHantekMainWindow(QWidget *parent, Qt::WindowFlags flag | ||
| 68 | this->settings = new DsoSettings(); | 68 | this->settings = new DsoSettings(); |
| 69 | this->settings->setChannelCount(this->dsoControl->getChannelCount()); | 69 | this->settings->setChannelCount(this->dsoControl->getChannelCount()); |
| 70 | this->readSettings(); | 70 | this->readSettings(); |
| 71 | - this->applySettings(); | ||
| 72 | 71 | ||
| 73 | // Create dock windows before the dso widget, they fix messed up settings | 72 | // Create dock windows before the dso widget, they fix messed up settings |
| 74 | this->createDockWindows(); | 73 | this->createDockWindows(); |
| @@ -82,10 +81,17 @@ OpenHantekMainWindow::OpenHantekMainWindow(QWidget *parent, Qt::WindowFlags flag | @@ -82,10 +81,17 @@ OpenHantekMainWindow::OpenHantekMainWindow(QWidget *parent, Qt::WindowFlags flag | ||
| 82 | 81 | ||
| 83 | // Subroutines for window elements | 82 | // Subroutines for window elements |
| 84 | this->createActions(); | 83 | this->createActions(); |
| 85 | - this->createMenus(); | ||
| 86 | this->createToolBars(); | 84 | this->createToolBars(); |
| 85 | + this->createMenus(); | ||
| 87 | this->createStatusBar(); | 86 | this->createStatusBar(); |
| 88 | 87 | ||
| 88 | + // Apply the settings after the gui is initialized | ||
| 89 | + this->applySettings(); | ||
| 90 | + | ||
| 91 | + // Update stored window size and position | ||
| 92 | + this->settings->options.window.position = this->pos(); | ||
| 93 | + this->settings->options.window.size = this->size(); | ||
| 94 | + | ||
| 89 | // Connect general signals | 95 | // Connect general signals |
| 90 | connect(this, SIGNAL(settingsChanged()), this, SLOT(applySettings())); | 96 | connect(this, SIGNAL(settingsChanged()), this, SLOT(applySettings())); |
| 91 | //connect(this->dsoWidget, SIGNAL(stopped()), this, SLOT(stopped())); | 97 | //connect(this->dsoWidget, SIGNAL(stopped()), this, SLOT(stopped())); |
| @@ -254,6 +260,16 @@ void OpenHantekMainWindow::createMenus() { | @@ -254,6 +260,16 @@ void OpenHantekMainWindow::createMenus() { | ||
| 254 | this->viewMenu = this->menuBar()->addMenu(tr("&View")); | 260 | this->viewMenu = this->menuBar()->addMenu(tr("&View")); |
| 255 | this->viewMenu->addAction(this->digitalPhosphorAction); | 261 | this->viewMenu->addAction(this->digitalPhosphorAction); |
| 256 | this->viewMenu->addAction(this->zoomAction); | 262 | this->viewMenu->addAction(this->zoomAction); |
| 263 | + this->viewMenu->addSeparator(); | ||
| 264 | + this->dockMenu = this->viewMenu->addMenu(tr("&Docking windows")); | ||
| 265 | + this->dockMenu->addAction(this->horizontalDock->toggleViewAction()); | ||
| 266 | + this->dockMenu->addAction(this->spectrumDock->toggleViewAction()); | ||
| 267 | + this->dockMenu->addAction(this->triggerDock->toggleViewAction()); | ||
| 268 | + this->dockMenu->addAction(this->voltageDock->toggleViewAction()); | ||
| 269 | + this->toolbarMenu = this->viewMenu->addMenu(tr("&Toolbars")); | ||
| 270 | + this->toolbarMenu->addAction(this->fileToolBar->toggleViewAction()); | ||
| 271 | + this->toolbarMenu->addAction(this->oscilloscopeToolBar->toggleViewAction()); | ||
| 272 | + this->toolbarMenu->addAction(this->viewToolBar->toggleViewAction()); | ||
| 257 | 273 | ||
| 258 | this->oscilloscopeMenu = this->menuBar()->addMenu(tr("&Oscilloscope")); | 274 | this->oscilloscopeMenu = this->menuBar()->addMenu(tr("&Oscilloscope")); |
| 259 | this->oscilloscopeMenu->addAction(this->configAction); | 275 | this->oscilloscopeMenu->addAction(this->configAction); |
| @@ -318,13 +334,6 @@ void OpenHantekMainWindow::createDockWindows() | @@ -318,13 +334,6 @@ void OpenHantekMainWindow::createDockWindows() | ||
| 318 | this->triggerDock = new TriggerDock(this->settings, this->dsoControl->getSpecialTriggerSources()); | 334 | this->triggerDock = new TriggerDock(this->settings, this->dsoControl->getSpecialTriggerSources()); |
| 319 | this->spectrumDock = new SpectrumDock(this->settings); | 335 | this->spectrumDock = new SpectrumDock(this->settings); |
| 320 | this->voltageDock = new VoltageDock(this->settings); | 336 | this->voltageDock = new VoltageDock(this->settings); |
| 321 | - | ||
| 322 | - this->addDockWidget(Qt::RightDockWidgetArea, this->horizontalDock); | ||
| 323 | - this->addDockWidget(Qt::RightDockWidgetArea, this->triggerDock); | ||
| 324 | - this->addDockWidget(Qt::RightDockWidgetArea, this->voltageDock); | ||
| 325 | - this->addDockWidget(Qt::RightDockWidgetArea, this->spectrumDock); | ||
| 326 | - | ||
| 327 | - //viewMenu->addAction(this->horizontalDock->toggleViewAction()); | ||
| 328 | } | 337 | } |
| 329 | 338 | ||
| 330 | /// \brief Read the settings from an ini file. | 339 | /// \brief Read the settings from an ini file. |
| @@ -343,6 +352,8 @@ int OpenHantekMainWindow::readSettings(const QString &fileName) { | @@ -343,6 +352,8 @@ int OpenHantekMainWindow::readSettings(const QString &fileName) { | ||
| 343 | /// \param fileName Optional filename to read the settings from an ini file. | 352 | /// \param fileName Optional filename to read the settings from an ini file. |
| 344 | /// \return 0 on success, negative on error. | 353 | /// \return 0 on success, negative on error. |
| 345 | int OpenHantekMainWindow::writeSettings(const QString &fileName) { | 354 | int OpenHantekMainWindow::writeSettings(const QString &fileName) { |
| 355 | + this->updateSettings(); | ||
| 356 | + | ||
| 346 | return this->settings->save(fileName); | 357 | return this->settings->save(fileName); |
| 347 | } | 358 | } |
| 348 | 359 | ||
| @@ -351,7 +362,7 @@ int OpenHantekMainWindow::writeSettings(const QString &fileName) { | @@ -351,7 +362,7 @@ int OpenHantekMainWindow::writeSettings(const QString &fileName) { | ||
| 351 | void OpenHantekMainWindow::moveEvent(QMoveEvent *event) { | 362 | void OpenHantekMainWindow::moveEvent(QMoveEvent *event) { |
| 352 | Q_UNUSED(event); | 363 | Q_UNUSED(event); |
| 353 | 364 | ||
| 354 | - this->settings->options.windowPosition = this->pos(); | 365 | + this->settings->options.window.position = this->pos(); |
| 355 | } | 366 | } |
| 356 | 367 | ||
| 357 | /// \brief Called everytime the window is resized. | 368 | /// \brief Called everytime the window is resized. |
| @@ -359,7 +370,7 @@ void OpenHantekMainWindow::moveEvent(QMoveEvent *event) { | @@ -359,7 +370,7 @@ void OpenHantekMainWindow::moveEvent(QMoveEvent *event) { | ||
| 359 | void OpenHantekMainWindow::resizeEvent(QResizeEvent *event) { | 370 | void OpenHantekMainWindow::resizeEvent(QResizeEvent *event) { |
| 360 | Q_UNUSED(event); | 371 | Q_UNUSED(event); |
| 361 | 372 | ||
| 362 | - this->settings->options.windowSize = this->size(); | 373 | + this->settings->options.window.size = this->size(); |
| 363 | } | 374 | } |
| 364 | 375 | ||
| 365 | /// \brief Open a configuration file. | 376 | /// \brief Open a configuration file. |
| @@ -419,6 +430,8 @@ void OpenHantekMainWindow::stopped() { | @@ -419,6 +430,8 @@ void OpenHantekMainWindow::stopped() { | ||
| 419 | 430 | ||
| 420 | /// \brief Configure the oscilloscope. | 431 | /// \brief Configure the oscilloscope. |
| 421 | void OpenHantekMainWindow::config() { | 432 | void OpenHantekMainWindow::config() { |
| 433 | + this->updateSettings(); | ||
| 434 | + | ||
| 422 | DsoConfigDialog configDialog(this->settings, this); | 435 | DsoConfigDialog configDialog(this->settings, this); |
| 423 | if(configDialog.exec() == QDialog::Accepted) | 436 | if(configDialog.exec() == QDialog::Accepted) |
| 424 | this->settingsChanged(); | 437 | this->settingsChanged(); |
| @@ -448,14 +461,121 @@ void OpenHantekMainWindow::zoom(bool enabled) { | @@ -448,14 +461,121 @@ void OpenHantekMainWindow::zoom(bool enabled) { | ||
| 448 | void OpenHantekMainWindow::about() { | 461 | void OpenHantekMainWindow::about() { |
| 449 | QMessageBox::about(this, tr("About OpenHantek %1").arg(VERSION), tr( | 462 | QMessageBox::about(this, tr("About OpenHantek %1").arg(VERSION), tr( |
| 450 | "<p>This is a open source software for Hantek USB oscilloscopes.</p>" | 463 | "<p>This is a open source software for Hantek USB oscilloscopes.</p>" |
| 451 | - "<p>Copyright © 2010 Oliver Haag <oliver.haag@gmail.com></p>" | 464 | + "<p>Copyright © 2010, 2011 Oliver Haag <oliver.haag@gmail.com></p>" |
| 452 | )); | 465 | )); |
| 453 | } | 466 | } |
| 454 | 467 | ||
| 455 | /// \brief The settings have changed. | 468 | /// \brief The settings have changed. |
| 456 | void OpenHantekMainWindow::applySettings() { | 469 | void OpenHantekMainWindow::applySettings() { |
| 457 | - this->move(this->settings->options.windowPosition); | ||
| 458 | - this->resize(this->settings->options.windowSize); | 470 | + // Main window |
| 471 | + if(!this->settings->options.window.position.isNull()) | ||
| 472 | + this->move(this->settings->options.window.position); | ||
| 473 | + if(!this->settings->options.window.size.isNull()) | ||
| 474 | + this->resize(this->settings->options.window.size); | ||
| 475 | + | ||
| 476 | + // Docking windows | ||
| 477 | + QList<QDockWidget *> docks; | ||
| 478 | + docks.append(this->horizontalDock); | ||
| 479 | + docks.append(this->spectrumDock); | ||
| 480 | + docks.append(this->triggerDock); | ||
| 481 | + docks.append(this->voltageDock); | ||
| 482 | + | ||
| 483 | + QList<DsoSettingsOptionsWindowPanel *> dockSettings; | ||
| 484 | + dockSettings.append(&(this->settings->options.window.dock.horizontal)); | ||
| 485 | + dockSettings.append(&(this->settings->options.window.dock.spectrum)); | ||
| 486 | + dockSettings.append(&(this->settings->options.window.dock.trigger)); | ||
| 487 | + dockSettings.append(&(this->settings->options.window.dock.voltage)); | ||
| 488 | + | ||
| 489 | + QList<int> docked[2]; // Docks docked on the sides of the main window | ||
| 490 | + | ||
| 491 | + for(int dockId = 0; dockId < docks.size(); dockId++) { | ||
| 492 | + docks[dockId]->setVisible(dockSettings[dockId]->visible); | ||
| 493 | + docks[dockId]->setFloating(dockSettings[dockId]->floating); | ||
| 494 | + if(!dockSettings[dockId]->position.isNull()) { | ||
| 495 | + if(dockSettings[dockId]->floating) { | ||
| 496 | + docks[dockId]->move(dockSettings[dockId]->position); | ||
| 497 | + } | ||
| 498 | + else { | ||
| 499 | + // Check in which order the docking windows where placed | ||
| 500 | + int side = (dockSettings[dockId]->position.x() == 0) ? 0 : 1; | ||
| 501 | + int index = 0; | ||
| 502 | + while(index < docked[side].size() && dockSettings[docked[side][index]]->position.y() < dockSettings[dockId]->position.y()) | ||
| 503 | + index++; | ||
| 504 | + docked[side].insert(index, dockId); | ||
| 505 | + //docks[dockId]->setVisible(false); | ||
| 506 | + } | ||
| 507 | + } | ||
| 508 | + else { | ||
| 509 | + this->addDockWidget(Qt::RightDockWidgetArea, docks[dockId]); | ||
| 510 | + } | ||
| 511 | + } | ||
| 512 | + | ||
| 513 | + // Put the docked docking windows into the main window | ||
| 514 | + for(int position = 0; position < docked[0].size(); position++) | ||
| 515 | + this->addDockWidget(Qt::LeftDockWidgetArea, docks[docked[0][position]]); | ||
| 516 | + for(int position = 0; position < docked[1].size(); position++) | ||
| 517 | + this->addDockWidget(Qt::RightDockWidgetArea, docks[docked[1][position]]); | ||
| 518 | + | ||
| 519 | + // Toolbars | ||
| 520 | + QList<QToolBar *> toolbars; | ||
| 521 | + toolbars.append(this->fileToolBar); | ||
| 522 | + toolbars.append(this->oscilloscopeToolBar); | ||
| 523 | + toolbars.append(this->viewToolBar); | ||
| 524 | + | ||
| 525 | + QList<DsoSettingsOptionsWindowPanel *> toolbarSettings; | ||
| 526 | + toolbarSettings.append(&(this->settings->options.window.toolbar.file)); | ||
| 527 | + toolbarSettings.append(&(this->settings->options.window.toolbar.oscilloscope)); | ||
| 528 | + toolbarSettings.append(&(this->settings->options.window.toolbar.view)); | ||
| 529 | + | ||
| 530 | + for(int toolbarId = 0; toolbarId < toolbars.size(); toolbarId++) { | ||
| 531 | + toolbars[toolbarId]->setVisible(toolbarSettings[toolbarId]->visible); | ||
| 532 | + //toolbars[toolbarId]->setFloating(toolbarSettings[toolbarId]->floating); // setFloating missing, a bug in Qt? | ||
| 533 | + if(!toolbarSettings[toolbarId]->position.isNull()) | ||
| 534 | + toolbars[toolbarId]->move(toolbarSettings[toolbarId]->position); | ||
| 535 | + } | ||
| 536 | +} | ||
| 537 | + | ||
| 538 | +/// \brief Update the window layout in the settings. | ||
| 539 | +void OpenHantekMainWindow::updateSettings() { | ||
| 540 | + // Main window | ||
| 541 | + this->settings->options.window.position = this->pos(); | ||
| 542 | + this->settings->options.window.size = this->size(); | ||
| 543 | + | ||
| 544 | + // Docking windows | ||
| 545 | + QList<QDockWidget *> docks; | ||
| 546 | + docks.append(this->horizontalDock); | ||
| 547 | + docks.append(this->spectrumDock); | ||
| 548 | + docks.append(this->triggerDock); | ||
| 549 | + docks.append(this->voltageDock); | ||
| 550 | + | ||
| 551 | + QList<DsoSettingsOptionsWindowPanel *> dockSettings; | ||
| 552 | + dockSettings.append(&(this->settings->options.window.dock.horizontal)); | ||
| 553 | + dockSettings.append(&(this->settings->options.window.dock.spectrum)); | ||
| 554 | + dockSettings.append(&(this->settings->options.window.dock.trigger)); | ||
| 555 | + dockSettings.append(&(this->settings->options.window.dock.voltage)); | ||
| 556 | + | ||
| 557 | + for(int dockId = 0; dockId < docks.size(); dockId++) { | ||
| 558 | + dockSettings[dockId]->floating = docks[dockId]->isFloating(); | ||
| 559 | + dockSettings[dockId]->position = docks[dockId]->pos(); | ||
| 560 | + dockSettings[dockId]->visible = docks[dockId]->isVisible(); | ||
| 561 | + } | ||
| 562 | + | ||
| 563 | + // Toolbars | ||
| 564 | + QList<QToolBar *> toolbars; | ||
| 565 | + toolbars.append(this->fileToolBar); | ||
| 566 | + toolbars.append(this->oscilloscopeToolBar); | ||
| 567 | + toolbars.append(this->viewToolBar); | ||
| 568 | + | ||
| 569 | + QList<DsoSettingsOptionsWindowPanel *> toolbarSettings; | ||
| 570 | + toolbarSettings.append(&(this->settings->options.window.toolbar.file)); | ||
| 571 | + toolbarSettings.append(&(this->settings->options.window.toolbar.oscilloscope)); | ||
| 572 | + toolbarSettings.append(&(this->settings->options.window.toolbar.view)); | ||
| 573 | + | ||
| 574 | + for(int toolbarId = 0; toolbarId < toolbars.size(); toolbarId++) { | ||
| 575 | + toolbarSettings[toolbarId]->floating = toolbars[toolbarId]->isFloating(); | ||
| 576 | + toolbarSettings[toolbarId]->position = toolbars[toolbarId]->pos(); | ||
| 577 | + toolbarSettings[toolbarId]->visible = toolbars[toolbarId]->isVisible(); | ||
| 578 | + } | ||
| 459 | } | 579 | } |
| 460 | 580 | ||
| 461 | /// \brief Apply new buffer size to settings. | 581 | /// \brief Apply new buffer size to settings. |
openhantek/src/openhantek.h
| @@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
| 4 | /// \file openhantek.h | 4 | /// \file openhantek.h |
| 5 | /// \brief Declares the HantekDsoMainWindow class. | 5 | /// \brief Declares the HantekDsoMainWindow class. |
| 6 | // | 6 | // |
| 7 | -// Copyright (C) 2010 Oliver Haag | 7 | +// Copyright (C) 2010, 2011 Oliver Haag |
| 8 | // oliver.haag@gmail.com | 8 | // oliver.haag@gmail.com |
| 9 | // | 9 | // |
| 10 | // This program is free software: you can redistribute it and/or modify it | 10 | // This program is free software: you can redistribute it and/or modify it |
| @@ -93,7 +93,7 @@ class OpenHantekMainWindow : public QMainWindow { | @@ -93,7 +93,7 @@ class OpenHantekMainWindow : public QMainWindow { | ||
| 93 | 93 | ||
| 94 | // Menus | 94 | // Menus |
| 95 | QMenu *fileMenu; | 95 | QMenu *fileMenu; |
| 96 | - QMenu *viewMenu; | 96 | + QMenu *viewMenu, *dockMenu, *toolbarMenu; |
| 97 | QMenu *oscilloscopeMenu, *bufferSizeMenu; | 97 | QMenu *oscilloscopeMenu, *bufferSizeMenu; |
| 98 | QMenu *helpMenu; | 98 | QMenu *helpMenu; |
| 99 | 99 | ||
| @@ -139,7 +139,9 @@ class OpenHantekMainWindow : public QMainWindow { | @@ -139,7 +139,9 @@ class OpenHantekMainWindow : public QMainWindow { | ||
| 139 | void config(); | 139 | void config(); |
| 140 | void about(); | 140 | void about(); |
| 141 | 141 | ||
| 142 | + // Settings management | ||
| 142 | void applySettings(); | 143 | void applySettings(); |
| 144 | + void updateSettings(); | ||
| 143 | 145 | ||
| 144 | void bufferSizeSelected(QAction *action); | 146 | void bufferSizeSelected(QAction *action); |
| 145 | void updateOffset(unsigned int channel); | 147 | void updateOffset(unsigned int channel); |
openhantek/src/settings.cpp
| @@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
| 3 | // OpenHantek | 3 | // OpenHantek |
| 4 | // settings.cpp | 4 | // settings.cpp |
| 5 | // | 5 | // |
| 6 | -// Copyright (C) 2010 Oliver Haag | 6 | +// Copyright (C) 2010, 2011 Oliver Haag |
| 7 | // oliver.haag@gmail.com | 7 | // oliver.haag@gmail.com |
| 8 | // | 8 | // |
| 9 | // This program is free software: you can redistribute it and/or modify it | 9 | // This program is free software: you can redistribute it and/or modify it |
| @@ -39,8 +39,23 @@ DsoSettings::DsoSettings(QWidget *parent) : QObject(parent) { | @@ -39,8 +39,23 @@ DsoSettings::DsoSettings(QWidget *parent) : QObject(parent) { | ||
| 39 | // Options | 39 | // Options |
| 40 | this->options.alwaysSave = true; | 40 | this->options.alwaysSave = true; |
| 41 | this->options.imageSize = QSize(640, 480); | 41 | this->options.imageSize = QSize(640, 480); |
| 42 | - this->options.windowPosition = QPoint(0, 0); | ||
| 43 | - this->options.windowSize = QSize(800, 560); | 42 | + // Main window |
| 43 | + this->options.window.position = QPoint(); | ||
| 44 | + this->options.window.size = QSize(); | ||
| 45 | + // Docking windows and toolbars | ||
| 46 | + QList<DsoSettingsOptionsWindowPanel *> panels; | ||
| 47 | + panels.append(&(this->options.window.dock.horizontal)); | ||
| 48 | + panels.append(&(this->options.window.dock.spectrum)); | ||
| 49 | + panels.append(&(this->options.window.dock.trigger)); | ||
| 50 | + panels.append(&(this->options.window.dock.voltage)); | ||
| 51 | + panels.append(&(this->options.window.toolbar.file)); | ||
| 52 | + panels.append(&(this->options.window.toolbar.oscilloscope)); | ||
| 53 | + panels.append(&(this->options.window.toolbar.view)); | ||
| 54 | + for(int panelId = 0; panelId < panels.size(); panelId++) { | ||
| 55 | + panels[panelId]->floating = false; | ||
| 56 | + panels[panelId]->position = QPoint(); | ||
| 57 | + panels[panelId]->visible = true; | ||
| 58 | + } | ||
| 44 | 59 | ||
| 45 | // Oscilloscope settings | 60 | // Oscilloscope settings |
| 46 | // Horizontal axis | 61 | // Horizontal axis |
| @@ -191,12 +206,54 @@ int DsoSettings::load(const QString &fileName) { | @@ -191,12 +206,54 @@ int DsoSettings::load(const QString &fileName) { | ||
| 191 | if(settingsLoader->status() != QSettings::NoError) | 206 | if(settingsLoader->status() != QSettings::NoError) |
| 192 | return -settingsLoader->status(); | 207 | return -settingsLoader->status(); |
| 193 | 208 | ||
| 194 | - // Window size and position and other general options | 209 | + // Main window layout and other general options |
| 195 | settingsLoader->beginGroup("options"); | 210 | settingsLoader->beginGroup("options"); |
| 211 | + settingsLoader->beginGroup("window"); | ||
| 212 | + // Docking windows and toolbars | ||
| 213 | + settingsLoader->beginGroup("docks"); | ||
| 214 | + QList<DsoSettingsOptionsWindowPanel *> docks; | ||
| 215 | + docks.append(&(this->options.window.dock.horizontal)); | ||
| 216 | + docks.append(&(this->options.window.dock.spectrum)); | ||
| 217 | + docks.append(&(this->options.window.dock.trigger)); | ||
| 218 | + docks.append(&(this->options.window.dock.voltage)); | ||
| 219 | + QStringList dockNames; | ||
| 220 | + dockNames << "horizontal" << "spectrum" << "trigger" << "voltage"; | ||
| 221 | + for(int dockId = 0; dockId < docks.size(); dockId++) { | ||
| 222 | + settingsLoader->beginGroup(dockNames[dockId]); | ||
| 223 | + if(settingsLoader->contains("floating")) | ||
| 224 | + docks[dockId]->floating = settingsLoader->value("floating").toBool(); | ||
| 225 | + if(settingsLoader->contains("position")) | ||
| 226 | + docks[dockId]->position = settingsLoader->value("position").toPoint(); | ||
| 227 | + if(settingsLoader->contains("visible")) | ||
| 228 | + docks[dockId]->visible = settingsLoader->value("visible").toBool(); | ||
| 229 | + settingsLoader->endGroup(); | ||
| 230 | + } | ||
| 231 | + settingsLoader->endGroup(); | ||
| 232 | + settingsLoader->beginGroup("toolbars"); | ||
| 233 | + QList<DsoSettingsOptionsWindowPanel *> toolbars; | ||
| 234 | + toolbars.append(&(this->options.window.toolbar.file)); | ||
| 235 | + toolbars.append(&(this->options.window.toolbar.oscilloscope)); | ||
| 236 | + toolbars.append(&(this->options.window.toolbar.view)); | ||
| 237 | + QStringList toolbarNames; | ||
| 238 | + toolbarNames << "file" << "oscilloscope" << "view"; | ||
| 239 | + for(int toolbarId = 0; toolbarId < toolbars.size(); toolbarId++) { | ||
| 240 | + settingsLoader->beginGroup(toolbarNames[toolbarId]); | ||
| 241 | + if(settingsLoader->contains("floating")) | ||
| 242 | + toolbars[toolbarId]->floating = settingsLoader->value("floating").toBool(); | ||
| 243 | + if(settingsLoader->contains("position")) | ||
| 244 | + toolbars[toolbarId]->position = settingsLoader->value("position").toPoint(); | ||
| 245 | + if(settingsLoader->contains("visible")) | ||
| 246 | + toolbars[toolbarId]->visible = settingsLoader->value("visible").toBool(); | ||
| 247 | + settingsLoader->endGroup(); | ||
| 248 | + } | ||
| 249 | + settingsLoader->endGroup(); | ||
| 250 | + // Main window | ||
| 196 | if(settingsLoader->contains("pos")) | 251 | if(settingsLoader->contains("pos")) |
| 197 | - this->options.windowPosition = settingsLoader->value("pos").toPoint(); | 252 | + this->options.window.position = settingsLoader->value("pos").toPoint(); |
| 198 | if(settingsLoader->contains("size")) | 253 | if(settingsLoader->contains("size")) |
| 199 | - this->options.windowSize = settingsLoader->value("size").toSize(); | 254 | + this->options.window.size = settingsLoader->value("size").toSize(); |
| 255 | + settingsLoader->endGroup(); | ||
| 256 | + // General options | ||
| 200 | if(settingsLoader->contains("alwaysSave")) | 257 | if(settingsLoader->contains("alwaysSave")) |
| 201 | this->options.alwaysSave = settingsLoader->value("alwaysSave").toBool(); | 258 | this->options.alwaysSave = settingsLoader->value("alwaysSave").toBool(); |
| 202 | if(settingsLoader->contains("imageSize")) | 259 | if(settingsLoader->contains("imageSize")) |
| @@ -340,10 +397,45 @@ int DsoSettings::save(const QString &fileName) { | @@ -340,10 +397,45 @@ int DsoSettings::save(const QString &fileName) { | ||
| 340 | return -settingsSaver->status(); | 397 | return -settingsSaver->status(); |
| 341 | 398 | ||
| 342 | if(complete) { | 399 | if(complete) { |
| 343 | - // Window size and position | 400 | + // Main window layout and other general options |
| 344 | settingsSaver->beginGroup("options"); | 401 | settingsSaver->beginGroup("options"); |
| 345 | - settingsSaver->setValue("pos", this->options.windowPosition); | ||
| 346 | - settingsSaver->setValue("size", this->options.windowSize); | 402 | + settingsSaver->beginGroup("window"); |
| 403 | + // Docking windows and toolbars | ||
| 404 | + settingsSaver->beginGroup("docks"); | ||
| 405 | + QList<DsoSettingsOptionsWindowPanel *> docks; | ||
| 406 | + docks.append(&(this->options.window.dock.horizontal)); | ||
| 407 | + docks.append(&(this->options.window.dock.spectrum)); | ||
| 408 | + docks.append(&(this->options.window.dock.trigger)); | ||
| 409 | + docks.append(&(this->options.window.dock.voltage)); | ||
| 410 | + QStringList dockNames; | ||
| 411 | + dockNames << "horizontal" << "spectrum" << "trigger" << "voltage"; | ||
| 412 | + for(int dockId = 0; dockId < docks.size(); dockId++) { | ||
| 413 | + settingsSaver->beginGroup(dockNames[dockId]); | ||
| 414 | + settingsSaver->setValue("floating", docks[dockId]->floating); | ||
| 415 | + settingsSaver->setValue("position", docks[dockId]->position); | ||
| 416 | + settingsSaver->setValue("visible", docks[dockId]->visible); | ||
| 417 | + settingsSaver->endGroup(); | ||
| 418 | + } | ||
| 419 | + settingsSaver->endGroup(); | ||
| 420 | + settingsSaver->beginGroup("toolbars"); | ||
| 421 | + QList<DsoSettingsOptionsWindowPanel *> toolbars; | ||
| 422 | + toolbars.append(&(this->options.window.toolbar.file)); | ||
| 423 | + toolbars.append(&(this->options.window.toolbar.oscilloscope)); | ||
| 424 | + toolbars.append(&(this->options.window.toolbar.view)); | ||
| 425 | + QStringList toolbarNames; | ||
| 426 | + toolbarNames << "file" << "oscilloscope" << "view"; | ||
| 427 | + for(int toolbarId = 0; toolbarId < toolbars.size(); toolbarId++) { | ||
| 428 | + settingsSaver->beginGroup(toolbarNames[toolbarId]); | ||
| 429 | + settingsSaver->setValue("floating", toolbars[toolbarId]->floating); | ||
| 430 | + settingsSaver->setValue("position", toolbars[toolbarId]->position); | ||
| 431 | + settingsSaver->setValue("visible", toolbars[toolbarId]->visible); | ||
| 432 | + settingsSaver->endGroup(); | ||
| 433 | + } | ||
| 434 | + settingsSaver->endGroup(); | ||
| 435 | + // Main window | ||
| 436 | + settingsSaver->setValue("pos", this->options.window.position); | ||
| 437 | + settingsSaver->setValue("size", this->options.window.size); | ||
| 438 | + settingsSaver->endGroup(); | ||
| 347 | settingsSaver->setValue("alwaysSave", this->options.alwaysSave); | 439 | settingsSaver->setValue("alwaysSave", this->options.alwaysSave); |
| 348 | settingsSaver->setValue("imageSize", this->options.imageSize); | 440 | settingsSaver->setValue("imageSize", this->options.imageSize); |
| 349 | settingsSaver->endGroup(); | 441 | settingsSaver->endGroup(); |
openhantek/src/settings.h
| @@ -4,7 +4,7 @@ | @@ -4,7 +4,7 @@ | ||
| 4 | /// \file settings.h | 4 | /// \file settings.h |
| 5 | /// \brief Declares the DsoSettings class. | 5 | /// \brief Declares the DsoSettings class. |
| 6 | // | 6 | // |
| 7 | -// Copyright (C) 2010 Oliver Haag | 7 | +// Copyright (C) 2010, 2011 Oliver Haag |
| 8 | // oliver.haag@gmail.com | 8 | // oliver.haag@gmail.com |
| 9 | // | 9 | // |
| 10 | // This program is free software: you can redistribute it and/or modify it | 10 | // This program is free software: you can redistribute it and/or modify it |
| @@ -39,13 +39,50 @@ | @@ -39,13 +39,50 @@ | ||
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | //////////////////////////////////////////////////////////////////////////////// | 41 | //////////////////////////////////////////////////////////////////////////////// |
| 42 | +/// \struct DsoSettingsOptionsWindowPanel settings.h | ||
| 43 | +/// \brief Holds the position and state of a docking window or toolbar. | ||
| 44 | +struct DsoSettingsOptionsWindowPanel { | ||
| 45 | + bool floating; ///< true, if the panel is floating | ||
| 46 | + QPoint position; ///< Position of the panel | ||
| 47 | + bool visible; ///< true, if the panel is shown | ||
| 48 | +}; | ||
| 49 | + | ||
| 50 | +//////////////////////////////////////////////////////////////////////////////// | ||
| 51 | +/// \struct DsoSettingsOptionsWindowDock settings.h | ||
| 52 | +/// \brief Holds the layout of the docking windows. | ||
| 53 | +struct DsoSettingsOptionsWindowDock { | ||
| 54 | + DsoSettingsOptionsWindowPanel horizontal; ///< "Horizontal" docking window | ||
| 55 | + DsoSettingsOptionsWindowPanel spectrum; ///< "Spectrum" docking window | ||
| 56 | + DsoSettingsOptionsWindowPanel trigger; ///< "Trigger" docking window | ||
| 57 | + DsoSettingsOptionsWindowPanel voltage; ///< "Voltage" docking window | ||
| 58 | +}; | ||
| 59 | + | ||
| 60 | +//////////////////////////////////////////////////////////////////////////////// | ||
| 61 | +/// \struct DsoSettingsOptionsWindowToolbar settings.h | ||
| 62 | +/// \brief Holds the layout of the toolbars. | ||
| 63 | +struct DsoSettingsOptionsWindowToolbar { | ||
| 64 | + DsoSettingsOptionsWindowPanel file; ///< "File" toolbar | ||
| 65 | + DsoSettingsOptionsWindowPanel oscilloscope; ///< "Oscilloscope" toolbar | ||
| 66 | + DsoSettingsOptionsWindowPanel view; ///< The "View" toolbar | ||
| 67 | +}; | ||
| 68 | + | ||
| 69 | +//////////////////////////////////////////////////////////////////////////////// | ||
| 70 | +/// \struct DsoSettingsOptionsWindow settings.h | ||
| 71 | +/// \brief Holds the layout of the main window. | ||
| 72 | +struct DsoSettingsOptionsWindow { | ||
| 73 | + QPoint position; ///< Position of the main window | ||
| 74 | + QSize size; ///< Size of the main window | ||
| 75 | + DsoSettingsOptionsWindowDock dock; ///< Docking windows | ||
| 76 | + DsoSettingsOptionsWindowToolbar toolbar; ///< Toolbars | ||
| 77 | +}; | ||
| 78 | + | ||
| 79 | +//////////////////////////////////////////////////////////////////////////////// | ||
| 42 | /// \struct DsoSettingsOptions settings.h | 80 | /// \struct DsoSettingsOptions settings.h |
| 43 | /// \brief Holds the general options of the program. | 81 | /// \brief Holds the general options of the program. |
| 44 | struct DsoSettingsOptions { | 82 | struct DsoSettingsOptions { |
| 45 | bool alwaysSave; ///< Always save the settings on exit | 83 | bool alwaysSave; ///< Always save the settings on exit |
| 46 | QSize imageSize; ///< Size of exported images in pixels | 84 | QSize imageSize; ///< Size of exported images in pixels |
| 47 | - QPoint windowPosition; ///< Position of the main window | ||
| 48 | - QSize windowSize; ///< Size of the main window | 85 | + DsoSettingsOptionsWindow window; ///< Window layout |
| 49 | }; | 86 | }; |
| 50 | 87 | ||
| 51 | //////////////////////////////////////////////////////////////////////////////// | 88 | //////////////////////////////////////////////////////////////////////////////// |