~kst-plot/kst/debian-xenial

« back to all changes in this revision

Viewing changes to .pc/fix-qreal-vs-double-for-arm.diff/src/libkstapp/mainwindow.cpp

  • Committer: Steven Benton
  • Date: 2012-11-04 22:45:35 UTC
  • mfrom: (1.2.10)
  • Revision ID: stevebenton@rogers.com-20121104224535-mnnvrp4mhvuz0h2p
* New upstream release.
* Non-maintainer upload.
* Remove patches that have been resolved upstream:
  - desktop-entry-contains-encoding-key.diff
  - desktop-entry-lacks-main-category.diff
    - upstream uses Education category rather than Graphics
  - fix-qreal-vs-double-for-arm.diff
* kst package Replaces and Conflicts with kst2 -- for old PPA users only

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *                                                                         *
3
 
 *   copyright : (C) 2007 The University of Toronto                        *
4
 
 *                   netterfield@astro.utoronto.ca                         *
5
 
 *                                                                         *
6
 
 *   This program is free software; you can redistribute it and/or modify  *
7
 
 *   it under the terms of the GNU General Public License as published by  *
8
 
 *   the Free Software Foundation; either version 2 of the License, or     *
9
 
 *   (at your option) any later version.                                   *
10
 
 *                                                                         *
11
 
 ***************************************************************************/
12
 
 
13
 
#include "mainwindow.h"
14
 
#include "boxitem.h"
15
 
#include "datamanager.h"
16
 
#include "debugdialog.h"
17
 
#include "debugnotifier.h"
18
 
#include "document.h"
19
 
#include "ellipseitem.h"
20
 
#include "exportgraphicsdialog.h"
21
 
#include "exportvectorsdialog.h"
22
 
#include "logdialog.h"
23
 
#include "application.h"
24
 
#include "debug.h"
25
 
#include "labelitem.h"
26
 
#include "lineitem.h"
27
 
#include "circleitem.h"
28
 
#include "arrowitem.h"
29
 
#include "memorywidget.h"
30
 
#include "objectstore.h"
31
 
#include "pictureitem.h"
32
 
#include "plotitem.h"
33
 
#include "plotitemmanager.h"
34
 
#include "svgitem.h"
35
 
#include "tabwidget.h"
36
 
#include "sharedaxisboxitem.h"
37
 
#include "ui_aboutdialog.h"
38
 
#include "viewvectordialog.h"
39
 
#include "viewmatrixdialog.h"
40
 
#include "viewprimitivedialog.h"
41
 
#include "view.h"
42
 
#include "applicationsettings.h"
43
 
#include "updatemanager.h"
44
 
#include "datasourcepluginmanager.h"
45
 
#include "pluginmenuitemaction.h"
46
 
 
47
 
#include "applicationsettingsdialog.h"
48
 
#include "differentiatecurvesdialog.h"
49
 
#include "choosecolordialog.h"
50
 
#include "changedatasampledialog.h"
51
 
#include "changefiledialog.h"
52
 
#include "bugreportwizard.h"
53
 
#include "datawizard.h"
54
 
#include "aboutdialog.h"
55
 
#include "datavector.h"
56
 
#include "commandlineparser.h"
57
 
#include "dialogdefaults.h"
58
 
 
59
 
#include "dialoglauncher.h"
60
 
 
61
 
#include <QtGui>
62
 
 
63
 
 
64
 
namespace Kst {
65
 
 
66
 
MainWindow::MainWindow() :
67
 
    _dataManager(0),
68
 
    _exportGraphics(0),
69
 
    _exportVectors(0),
70
 
    _logDialog(0),
71
 
    _differentiateCurvesDialog(0),
72
 
    _chooseColorDialog(0),
73
 
    _changeDataSampleDialog(0),
74
 
    _changeFileDialog(0),
75
 
    _bugReportWizard(0),
76
 
    _applicationSettingsDialog(0),
77
 
    _aboutDialog(0),
78
 
    _highlightPoint(false) 
79
 
{
80
 
  _doc = new Document(this);
81
 
  _tabWidget = new TabWidget(this);
82
 
  _undoGroup = new QUndoGroup(this);
83
 
  _debugDialog = new DebugDialog(this);
84
 
  Debug::self()->setHandler(_debugDialog);
85
 
 
86
 
  setWindowTitle("Kst");
87
 
 
88
 
  createActions();
89
 
  createMenus();
90
 
  createToolBars();
91
 
  createStatusBar();
92
 
 
93
 
  _tabWidget->createView();
94
 
 
95
 
  setCentralWidget(_tabWidget);
96
 
  connect(_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(currentViewChanged()));
97
 
  connect(_tabWidget, SIGNAL(currentViewModeChanged()), this, SLOT(currentViewModeChanged()));
98
 
  connect(PlotItemManager::self(), SIGNAL(tiedZoomRemoved()), this, SLOT(tiedZoomRemoved()));
99
 
  connect(PlotItemManager::self(), SIGNAL(allPlotsTiedZoom()), this, SLOT(allPlotsTiedZoom()));
100
 
 
101
 
  readSettings();
102
 
  connect(UpdateManager::self(), SIGNAL(objectsUpdated(qint64)), this, SLOT(updateViewItems(qint64)));
103
 
 
104
 
  QTimer::singleShot(0, this, SLOT(performHeavyStartupActions()));
105
 
 
106
 
  updateRecentKstFiles();
107
 
}
108
 
 
109
 
 
110
 
MainWindow::~MainWindow() {
111
 
  delete _dataManager;
112
 
  _dataManager = 0;
113
 
  delete _doc;
114
 
  _doc = 0;
115
 
}
116
 
 
117
 
 
118
 
void MainWindow::performHeavyStartupActions() {
119
 
  // Set the timer for the UpdateManager.
120
 
  UpdateManager::self()->setMinimumUpdatePeriod(ApplicationSettings::self()->minimumUpdatePeriod());
121
 
  DataObject::init();
122
 
  DataSourcePluginManager::init();
123
 
}
124
 
 
125
 
 
126
 
void MainWindow::cleanup() {
127
 
  if (document() && document()->objectStore()) {
128
 
    document()->objectStore()->clear();
129
 
  }
130
 
}
131
 
 
132
 
 
133
 
void MainWindow::setLayoutMode(bool layoutMode) {
134
 
  View *v = tabWidget()->currentView();
135
 
  Q_ASSERT(v);
136
 
 
137
 
  if (layoutMode) {
138
 
    v->setViewMode(View::Layout);
139
 
    _highlightPointAct->setEnabled(false);
140
 
    _tiedZoomAct->setEnabled(false);
141
 
  } else {
142
 
    v->setViewMode(View::Data);    
143
 
    _highlightPointAct->setEnabled(true);
144
 
    _tiedZoomAct->setEnabled(true);
145
 
  }
146
 
}
147
 
 
148
 
void MainWindow::setHighlightPoint(bool highlight) {
149
 
  _highlightPoint = highlight;
150
 
}
151
 
 
152
 
void MainWindow::changeZoomOnlyMode(QAction* act) {
153
 
  if (act == _layoutModeAct && act->isChecked()) {
154
 
    setLayoutMode(true);
155
 
  } else {
156
 
    setLayoutMode(false);
157
 
  }
158
 
  tabWidget()->currentView()->setZoomOnly((View::ZoomOnlyMode)act->data().toInt());
159
 
}
160
 
 
161
 
void MainWindow::toggleTiedZoom() {
162
 
  PlotItemManager::self()->toggleAllTiedZoom(tabWidget()->currentView());
163
 
}
164
 
 
165
 
 
166
 
void MainWindow::tiedZoomRemoved() {
167
 
  _tiedZoomAct->setChecked(false);
168
 
}
169
 
 
170
 
 
171
 
void MainWindow::allPlotsTiedZoom() {
172
 
  _tiedZoomAct->setChecked(true);
173
 
}
174
 
 
175
 
 
176
 
bool MainWindow::promptSave() {
177
 
  int rc = QMessageBox::warning(this, tr("Kst"), tr("Your document has been modified.\nSave changes?"), QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel, QMessageBox::Save);
178
 
  if (rc == QMessageBox::Save) {
179
 
    save();
180
 
  } else if (rc == QMessageBox::Cancel) {
181
 
    return false;
182
 
  }
183
 
  return true;
184
 
}
185
 
 
186
 
 
187
 
void MainWindow::closeEvent(QCloseEvent *e) {
188
 
  if (_doc->isChanged() && !promptSave()) {
189
 
    e->ignore();
190
 
    return;
191
 
  }
192
 
  //cleanup();
193
 
  QMainWindow::closeEvent(e);
194
 
}
195
 
 
196
 
 
197
 
Document *MainWindow::document() const {
198
 
  return _doc;
199
 
}
200
 
 
201
 
 
202
 
QUndoGroup *MainWindow::undoGroup() const {
203
 
  return _undoGroup;
204
 
}
205
 
 
206
 
 
207
 
TabWidget *MainWindow::tabWidget() const {
208
 
  return _tabWidget;
209
 
}
210
 
 
211
 
 
212
 
void MainWindow::save() {
213
 
  if (_doc->isOpen()) {
214
 
    _doc->save();
215
 
  } else {
216
 
    saveAs();
217
 
  }
218
 
}
219
 
 
220
 
 
221
 
void MainWindow::saveAs() {
222
 
  QString fn = QFileDialog::getSaveFileName(this, tr("Kst: Save File"), _doc->fileName(), tr("Kst Sessions (*.kst)"));
223
 
  if (fn.isEmpty()) {
224
 
    return;
225
 
  }
226
 
  QString restorePath = QDir::currentPath();
227
 
  QString kstfiledir = fn.left(fn.lastIndexOf('/')) + '/';
228
 
  QDir::setCurrent(kstfiledir);
229
 
  QString currentP = QDir::currentPath();
230
 
  _doc->save(fn);
231
 
  QDir::setCurrent(restorePath);
232
 
  setWindowTitle("Kst - " + fn);
233
 
  updateRecentKstFiles(fn);
234
 
}
235
 
 
236
 
 
237
 
void MainWindow::newDoc() {
238
 
  bool clearApproved = false;
239
 
  if (_doc->isChanged()) {
240
 
    clearApproved = promptSave();
241
 
  } else {
242
 
    int rc = QMessageBox::warning(this, tr("Kst"), tr("Delete everything?"), QMessageBox::Ok, QMessageBox::Cancel);
243
 
    clearApproved = (rc == QMessageBox::Ok);
244
 
  }
245
 
 
246
 
  if (clearApproved) {
247
 
    delete _dataManager;
248
 
    _dataManager = 0;
249
 
    delete _doc;
250
 
    _doc = new Document(this);
251
 
  } else {
252
 
    return;
253
 
  }
254
 
 
255
 
  tabWidget()->clear();
256
 
  tabWidget()->createView();
257
 
}
258
 
 
259
 
void MainWindow::open() {
260
 
  if (_doc->isChanged() && !promptSave()) {
261
 
    return;
262
 
  }
263
 
  QSettings settings("Kst2");
264
 
  const QString lastKey = "lastOpenedKstFile";
265
 
  QString fn = settings.value(lastKey).toString();
266
 
  if (fn.isEmpty()) {
267
 
      fn = _doc->fileName();
268
 
  }
269
 
  fn = QFileDialog::getOpenFileName(this, tr("Kst: Open File"), fn, tr("Kst Sessions (*.kst)"));
270
 
  if (fn.isEmpty()) {
271
 
    return;
272
 
  }
273
 
  settings.setValue(lastKey, fn);
274
 
  openFile(fn);
275
 
}
276
 
 
277
 
 
278
 
 
279
 
QAction* MainWindow::createRecentFileAction(const QString& filename, int idx, const QString& name, const char* openslot)
280
 
{
281
 
  QAction* action = new QAction(this);
282
 
  QString text = tr("&%1 %2").arg(idx).arg(name);
283
 
  action->setText(text);
284
 
  action->setData(filename);
285
 
  action->setStatusTip(filename);
286
 
  action->setVisible(true);
287
 
  connect(action, SIGNAL(triggered()), this, openslot);
288
 
  return action;
289
 
}
290
 
 
291
 
 
292
 
void MainWindow::updateRecentKstFiles(const QString& filename)
293
 
{
294
 
  updateRecentFiles("recentKstFileList", _fileMenu, _bottomRecentKstActions, _recentKstFilesMenu, filename, SLOT(openRecentKstFile()));
295
 
}
296
 
 
297
 
 
298
 
void MainWindow::updateRecentDataFiles(const QString& filename)
299
 
{
300
 
  updateRecentFiles("recentDataFileList", _toolsMenu, _bottomRecentDataActions, _recentDataFilesMenu, filename, SLOT(openRecentDataFile()));
301
 
  if (!filename.isEmpty()) {
302
 
    _dialogDefaults->setValue("vector/datasource", filename);
303
 
  }
304
 
}
305
 
 
306
 
 
307
 
void MainWindow::updateRecentFiles(const QString& key, QMenu* menu, QList<QAction*>& actions, QMenu* submenu, const QString& newfilename, const char* openslot)
308
 
{
309
 
  foreach(QAction* it, actions) {
310
 
    menu->removeAction(it);
311
 
    delete it;
312
 
  }
313
 
  actions.clear();
314
 
  QSettings settings("Kst2");
315
 
  QStringList recentFiles = settings.value(key).toStringList();
316
 
  if (recentFiles.removeDuplicates() > 0) {
317
 
    settings.setValue(key, recentFiles);
318
 
  }
319
 
  if (!newfilename.isEmpty()) {
320
 
    recentFiles.removeOne(newfilename);
321
 
    recentFiles.push_front(newfilename);
322
 
    recentFiles = recentFiles.mid(0, 30);
323
 
    settings.setValue(key, recentFiles);
324
 
  }
325
 
  
326
 
  submenu->clear();
327
 
  QAction* check = new QAction(this);
328
 
  check->setText("&Cleanup Non-Existent Files");
329
 
  check->setData(key);
330
 
  check->setVisible(true);
331
 
  connect(check, SIGNAL(triggered()), this, SLOT(checkRecentFilesOnExistence()));
332
 
  submenu->addAction(check);
333
 
  submenu->addSeparator();
334
 
  int i = 0;
335
 
  foreach(const QString& it, recentFiles) {
336
 
    i++;
337
 
    if (i <= 5) {
338
 
      // don't make file menu to wide, show complete path in statusbar
339
 
      QAction* action = createRecentFileAction(it, i, QFileInfo(it).fileName(), openslot);
340
 
      actions << action;
341
 
      menu->addAction(action);
342
 
    }
343
 
    submenu->addAction(createRecentFileAction(it, i, it, openslot));
344
 
  }
345
 
}
346
 
 
347
 
 
348
 
void MainWindow::openRecentKstFile()
349
 
{
350
 
  QAction *action = qobject_cast<QAction *>(sender());
351
 
  if (action) {
352
 
    openFile(action->data().toString());
353
 
  }
354
 
}
355
 
 
356
 
 
357
 
void MainWindow::checkRecentFilesOnExistence()
358
 
{
359
 
  QAction *action = qobject_cast<QAction *>(sender());
360
 
  if (action) {
361
 
    QSettings settings("Kst2");
362
 
    QStringList recentFiles = settings.value(action->data().toString()).toStringList();
363
 
    recentFiles.removeDuplicates();
364
 
    foreach(const QString& it, recentFiles) {
365
 
      if (!QFileInfo(it).exists()) {
366
 
        recentFiles.removeOne(it);
367
 
      }
368
 
    }
369
 
    settings.setValue(action->data().toString(), recentFiles);
370
 
    updateRecentKstFiles();
371
 
    updateRecentDataFiles();
372
 
  }
373
 
}
374
 
 
375
 
 
376
 
 
377
 
bool MainWindow::initFromCommandLine() {
378
 
  delete _doc;
379
 
  _doc = new Document(this);
380
 
 
381
 
  CommandLineParser P(_doc, this);
382
 
 
383
 
  bool ok = _doc->initFromCommandLine(&P);
384
 
  if (!P.pngFile().isEmpty()) {
385
 
    exportGraphicsFile(P.pngFile(), "png", 1280, 1024,0);
386
 
    ok = false;
387
 
  }
388
 
  if (!P.printFile().isEmpty()) {
389
 
    printFromCommandLine(P.printFile());
390
 
    ok = false;
391
 
  }
392
 
  if (!P.kstFileName().isEmpty()) {
393
 
    setWindowTitle("Kst - " + P.kstFileName());
394
 
  }
395
 
  _doc->setChanged(false);
396
 
  return ok;
397
 
}
398
 
 
399
 
void MainWindow::openFile(const QString &file) {
400
 
  QDir::setCurrent(file.left(file.lastIndexOf('/')) + '/');
401
 
  QDir::setCurrent(file.left(file.lastIndexOf('/')));
402
 
 
403
 
  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
404
 
  delete _dataManager;
405
 
  _dataManager = 0;
406
 
  delete _doc;
407
 
  _doc = new Document(this);
408
 
 
409
 
  bool ok = _doc->open(file);
410
 
  QApplication::restoreOverrideCursor();
411
 
 
412
 
  if (!ok) {
413
 
    QMessageBox::critical(this, tr("Kst"),
414
 
        tr("Error opening document '%1':\n%2\n"
415
 
           "Maybe it is a Kst 1 file which could not be read by Kst 2.").arg(file, _doc->lastError()));
416
 
    delete _doc;
417
 
    _doc = new Document(this);
418
 
  }
419
 
 
420
 
  setWindowTitle("Kst - " + file);
421
 
  updateRecentKstFiles(file);
422
 
}
423
 
 
424
 
 
425
 
void MainWindow::exportGraphicsFile(
426
 
    const QString &filename, const QString &format, int width, int height, int display) {
427
 
  int viewCount = 0;
428
 
  int n_views = _tabWidget->views().size();
429
 
  foreach (View *view, _tabWidget->views()) {
430
 
    QSize size;
431
 
    if (display == 0) {
432
 
      size.setWidth(width);
433
 
      size.setHeight(height);
434
 
    } else if (display == 1) {
435
 
      size.setWidth(width);
436
 
      size.setHeight(width);
437
 
    } else if (display == 2) {
438
 
      QSize sizeWindow(view->geometry().size());
439
 
 
440
 
      size.setWidth(width);
441
 
      size.setHeight((int)((double)width * (double)sizeWindow.height() / (double)sizeWindow.width()));
442
 
    } else {
443
 
      QSize sizeWindow(view->geometry().size());
444
 
 
445
 
      size.setHeight(height);
446
 
      size.setWidth((int)((double)height * (double)sizeWindow.width() / (double)sizeWindow.height()));
447
 
    }
448
 
 
449
 
    QImage image(size, QImage::Format_ARGB32);
450
 
 
451
 
    QPainter painter(&image);
452
 
    QSize currentSize(view->size());
453
 
    view->resize(size);
454
 
    view->processResize(size);
455
 
    view->setPrinting(true);
456
 
    view->render(&painter);
457
 
    view->setPrinting(false);
458
 
    view->resize(currentSize);
459
 
    view->processResize(currentSize);
460
 
 
461
 
    QString file = filename;
462
 
    if (n_views != 1) {
463
 
      QFileInfo QFI(filename);
464
 
      file = QFI.completeBaseName() +
465
 
             '_' +
466
 
             QString::number(viewCount+1) + '.' +
467
 
             QFI.suffix();
468
 
    }
469
 
 
470
 
    QImageWriter imageWriter(file, format.toLatin1());
471
 
    imageWriter.write(image);
472
 
    viewCount++;
473
 
  }
474
 
}
475
 
 
476
 
void MainWindow::exportLog(const QString &imagename, QString &msgfilename, const QString &format, int x_size, int y_size,
477
 
                           int size_option_index, const QString &message) {
478
 
  View *view = _tabWidget->currentView();
479
 
 
480
 
  QSize size;
481
 
  if (size_option_index == 0) {
482
 
    size.setWidth(x_size);
483
 
    size.setHeight(y_size);
484
 
  } else if (size_option_index == 1) {
485
 
    size.setWidth(x_size);
486
 
    size.setHeight(y_size);
487
 
  } else if (size_option_index == 2) {
488
 
    QSize sizeWindow(view->geometry().size());
489
 
 
490
 
    size.setWidth(x_size);
491
 
    size.setHeight((int)((double)x_size * (double)sizeWindow.height() / (double)sizeWindow.width()));
492
 
  } else {
493
 
    QSize sizeWindow(view->geometry().size());
494
 
 
495
 
    size.setHeight(y_size);
496
 
    size.setWidth((int)((double)y_size * (double)sizeWindow.width() / (double)sizeWindow.height()));
497
 
  }
498
 
 
499
 
  QImage image(size, QImage::Format_ARGB32);
500
 
 
501
 
  QPainter painter(&image);
502
 
  QSize currentSize(view->size());
503
 
  view->resize(size);
504
 
  view->processResize(size);
505
 
  view->setPrinting(true);
506
 
  view->render(&painter);
507
 
  view->setPrinting(false);
508
 
  view->resize(currentSize);
509
 
  view->processResize(currentSize);
510
 
 
511
 
  QImageWriter imageWriter(imagename, format.toLatin1());
512
 
  imageWriter.write(image);
513
 
 
514
 
  QFile file(msgfilename);
515
 
 
516
 
  if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
517
 
    QTextStream out(&file);
518
 
    out << message;
519
 
    file.close();
520
 
  }
521
 
 
522
 
}
523
 
 
524
 
void MainWindow::printToPrinter(QPrinter *printer) {
525
 
 
526
 
  QPainter painter(printer);
527
 
  QList<View*> pages;
528
 
 
529
 
  switch (printer->printRange()) {
530
 
   case QPrinter::PageRange:
531
 
    if (printer->fromPage()>0) {
532
 
      for (int i_page = printer->fromPage(); i_page<=printer->toPage(); i_page++) {
533
 
        pages.append(_tabWidget->views().at(i_page-1));
534
 
      }
535
 
    }
536
 
    break;
537
 
   case QPrinter::AllPages:
538
 
    foreach (View *view, _tabWidget->views()) {
539
 
      pages.append(view);
540
 
    }
541
 
    break;
542
 
   case QPrinter::Selection:
543
 
   default:
544
 
    pages.append(_tabWidget->currentView());
545
 
    break;
546
 
  }
547
 
 
548
 
  QSize printerPageSize = printer->pageRect().size();
549
 
  for (int i = 0; i < printer->numCopies(); ++i) {
550
 
    for (int i_page = 0; i_page<pages.count(); i_page++) {
551
 
      View *view = pages.at(i_page);
552
 
      QSize currentSize(view->size());
553
 
      view->resize(printerPageSize);
554
 
      view->processResize(printerPageSize);
555
 
      view->setPrinting(true);
556
 
      view->render(&painter);
557
 
      view->setPrinting(false);
558
 
      view->resize(currentSize);
559
 
      view->processResize(currentSize);
560
 
      if (i_page<pages.count()-1)
561
 
        printer->newPage();
562
 
 
563
 
    }
564
 
  }
565
 
}
566
 
 
567
 
void MainWindow::printFromCommandLine(const QString &printFileName) {
568
 
  QPrinter printer(QPrinter::ScreenResolution);
569
 
  printer.setOutputFileName(printFileName);
570
 
  setPrinterDefaults(&printer);
571
 
 
572
 
  printer.setPrintRange(QPrinter::AllPages);
573
 
  printToPrinter(&printer);
574
 
}
575
 
 
576
 
void MainWindow::setPrinterDefaults(QPrinter *printer) {
577
 
  if (_dialogDefaults->value("print/landscape",true).toBool()) {
578
 
    printer->setOrientation(QPrinter::Landscape);
579
 
  } else {
580
 
    printer->setOrientation(QPrinter::Portrait);
581
 
  }
582
 
 
583
 
  printer->setPaperSize(QPrinter::PaperSize(_dialogDefaults->value("print/paperSize", QPrinter::Letter).toInt()));
584
 
 
585
 
  QPointF topLeft =_dialogDefaults->value("print/topLeftMargin", QPointF(15.0,15.0)).toPointF();
586
 
  QPointF bottomRight =_dialogDefaults->value("print/bottomRightMargin", QPointF(15.0,15.0)).toPointF();
587
 
 
588
 
  printer->setPageMargins(topLeft.x(), topLeft.y(), bottomRight.x(), bottomRight.y(), QPrinter::Millimeter);
589
 
  // Apparent Qt bug: setting the page margins here doesn't set the correspoding values in the print
590
 
  // dialog->printer-options sub-dialog under linux.  If you don't open the printer-options sub-dialog,
591
 
  // the values here are honored.
592
 
}
593
 
 
594
 
void MainWindow::savePrinterDefaults(QPrinter *printer) {
595
 
  _dialogDefaults->setValue("print/landscape", printer->orientation() == QPrinter::Landscape);
596
 
  _dialogDefaults->setValue("print/paperSize", int(printer->paperSize()));
597
 
 
598
 
  double left, top, right, bottom;
599
 
  printer->getPageMargins(&left, &top, &right, &bottom, QPrinter::Millimeter);
600
 
  _dialogDefaults->setValue("print/topLeftMargin", QPointF(left, top));
601
 
  _dialogDefaults->setValue("print/bottomRightMargin", QPointF(right, bottom));
602
 
 
603
 
}
604
 
 
605
 
void MainWindow::print() {
606
 
  // line widths in pixels make sense when using ScreenResolution
607
 
  // FIXME: come up with a better definition of line width!
608
 
  QPrinter printer(QPrinter::ScreenResolution);
609
 
  //QPrinter printer(QPrinter::HighResolution);
610
 
 
611
 
  setPrinterDefaults(&printer);
612
 
 
613
 
  QPointer<QPrintDialog> pd = new QPrintDialog(&printer, this);
614
 
#if QT_VERSION >= 0x040500
615
 
  pd->setOption(QPrintDialog::PrintToFile);
616
 
  pd->setOption(QPrintDialog::PrintPageRange, true);
617
 
  pd->setOption(QAbstractPrintDialog::PrintShowPageSize,true);
618
 
#endif
619
 
 
620
 
  if (pd->exec() == QDialog::Accepted) {
621
 
    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
622
 
    printToPrinter(&printer);
623
 
    QApplication::restoreOverrideCursor();
624
 
    savePrinterDefaults(&printer);
625
 
  }
626
 
  delete pd;
627
 
}
628
 
 
629
 
void MainWindow::currentViewChanged() {
630
 
  if(!_tabWidget->currentView())
631
 
    return;
632
 
  _undoGroup->setActiveStack(_tabWidget->currentView()->undoStack());
633
 
  currentViewModeChanged();
634
 
}
635
 
 
636
 
 
637
 
void MainWindow::currentViewModeChanged() {
638
 
  if(!_tabWidget->currentView())
639
 
    return;
640
 
  _layoutModeAct->setChecked(_tabWidget->currentView()->viewMode() == View::Layout);
641
 
}
642
 
 
643
 
void MainWindow::aboutToQuit() {
644
 
  writeSettings();
645
 
}
646
 
 
647
 
 
648
 
void MainWindow::about() {
649
 
  if (!_aboutDialog) {
650
 
    _aboutDialog = new AboutDialog(this);
651
 
  }
652
 
  if (_aboutDialog->isVisible()) {
653
 
    _aboutDialog->raise();
654
 
    _aboutDialog->activateWindow();
655
 
  }
656
 
  _aboutDialog->show();
657
 
}
658
 
 
659
 
 
660
 
void MainWindow::clearDrawingMarker() {
661
 
  _createBoxAct->setChecked(false);
662
 
  _createSharedAxisBoxAct->setChecked(false);
663
 
  _createCircleAct->setChecked(false);
664
 
  _createEllipseAct->setChecked(false);
665
 
  _createLabelAct->setChecked(false);
666
 
  _createLineAct->setChecked(false);
667
 
  _createArrowAct->setChecked(false);
668
 
  _createPictureAct->setChecked(false);
669
 
  _createPlotAct->setChecked(false);
670
 
  _createSvgAct->setChecked(false);
671
 
}
672
 
 
673
 
 
674
 
void MainWindow::createBox() {
675
 
  if (_createBoxAct->isChecked()) {
676
 
    clearDrawingMarker();
677
 
    _createBoxAct->setChecked(true);
678
 
    CreateBoxCommand *cmd = new CreateBoxCommand;
679
 
    cmd->createItem();
680
 
  } else {
681
 
    _tabWidget->currentView()->setMouseMode(View::Default);
682
 
  }
683
 
}
684
 
 
685
 
 
686
 
 
687
 
void MainWindow::createSharedAxisBox() {
688
 
  if (_createSharedAxisBoxAct->isChecked()) {
689
 
    clearDrawingMarker();
690
 
    _createSharedAxisBoxAct->setChecked(true);
691
 
    CreateSharedAxisBoxCommand *cmd = new CreateSharedAxisBoxCommand;
692
 
    cmd->createItem();
693
 
  } else {
694
 
    _tabWidget->currentView()->setMouseMode(View::Default);
695
 
  }
696
 
}
697
 
 
698
 
void MainWindow::createVector() {
699
 
  QString tmp;
700
 
  DialogLauncher::self()->showVectorDialog(tmp);
701
 
}
702
 
 
703
 
 
704
 
void MainWindow::createMatrix() {
705
 
  QString tmp;
706
 
  DialogLauncher::self()->showMatrixDialog(tmp);
707
 
}
708
 
 
709
 
 
710
 
void MainWindow::createScalar() {
711
 
  QString scalarName;
712
 
  DialogLauncher::self()->showScalarDialog(scalarName);
713
 
}
714
 
 
715
 
 
716
 
void MainWindow::createString() {
717
 
  QString stringName;
718
 
  DialogLauncher::self()->showStringDialog(stringName);
719
 
}
720
 
 
721
 
 
722
 
void MainWindow::createCircle() {
723
 
  if (_createCircleAct->isChecked()) {
724
 
    clearDrawingMarker();
725
 
    _createCircleAct->setChecked(true);
726
 
    CreateCircleCommand *cmd = new CreateCircleCommand;
727
 
    cmd->createItem();
728
 
  } else {
729
 
    _tabWidget->currentView()->setMouseMode(View::Default);
730
 
  }
731
 
}
732
 
 
733
 
 
734
 
void MainWindow::createEllipse() {
735
 
  if (_createEllipseAct->isChecked()) {
736
 
    clearDrawingMarker();
737
 
    _createEllipseAct->setChecked(true);
738
 
    CreateEllipseCommand *cmd = new CreateEllipseCommand;
739
 
    cmd->createItem();
740
 
  } else {
741
 
    _tabWidget->currentView()->setMouseMode(View::Default);
742
 
  }
743
 
}
744
 
 
745
 
 
746
 
void MainWindow::createLabel() {
747
 
  if (_createLabelAct->isChecked()) {
748
 
    clearDrawingMarker();
749
 
    _createLabelAct->setChecked(true);
750
 
    CreateLabelCommand *cmd = new CreateLabelCommand;
751
 
    cmd->createItem();
752
 
  } else {
753
 
    _tabWidget->currentView()->setMouseMode(View::Default);
754
 
  }
755
 
}
756
 
 
757
 
 
758
 
void MainWindow::createLine() {
759
 
  if (_createLineAct->isChecked()) {
760
 
    clearDrawingMarker();
761
 
    _createLineAct->setChecked(true);
762
 
    CreateLineCommand *cmd = new CreateLineCommand;
763
 
    cmd->createItem();
764
 
  } else {
765
 
    _tabWidget->currentView()->setMouseMode(View::Default);
766
 
  }
767
 
}
768
 
 
769
 
 
770
 
void MainWindow::createArrow() {
771
 
  if (_createArrowAct->isChecked()) {
772
 
    clearDrawingMarker();
773
 
    _createArrowAct->setChecked(true);
774
 
    CreateArrowCommand *cmd = new CreateArrowCommand;
775
 
    cmd->createItem();
776
 
  } else {
777
 
    _tabWidget->currentView()->setMouseMode(View::Default);
778
 
  }
779
 
}
780
 
 
781
 
 
782
 
void MainWindow::createPicture() {
783
 
  if (_createPictureAct->isChecked()) {
784
 
    clearDrawingMarker();
785
 
    _createPictureAct->setChecked(true);
786
 
    CreatePictureCommand *cmd = new CreatePictureCommand;
787
 
    cmd->createItem();
788
 
  } else {
789
 
    _tabWidget->currentView()->setMouseMode(View::Default);
790
 
  }
791
 
}
792
 
 
793
 
 
794
 
void MainWindow::createPlot() {
795
 
  if (_createPlotAct->isChecked()) {
796
 
    clearDrawingMarker();
797
 
    _createPlotAct->setChecked(true);
798
 
    CreatePlotCommand *cmd = new CreatePlotCommand;
799
 
    cmd->createItem();
800
 
  } else {
801
 
    _tabWidget->currentView()->setMouseMode(View::Default);
802
 
  }
803
 
}
804
 
 
805
 
 
806
 
void MainWindow::createSvg() {
807
 
  if (_createSvgAct->isChecked()) {
808
 
    clearDrawingMarker();
809
 
    _createSvgAct->setChecked(true);
810
 
    CreateSvgCommand *cmd = new CreateSvgCommand;
811
 
    cmd->createItem();
812
 
  } else {
813
 
    _tabWidget->currentView()->setMouseMode(View::Default);
814
 
  }
815
 
}
816
 
 
817
 
void MainWindow::createCurve() {
818
 
  DialogLauncher::self()->showCurveDialog();
819
 
}
820
 
 
821
 
void MainWindow::createPSD() {
822
 
  DialogLauncher::self()->showPowerSpectrumDialog();
823
 
}
824
 
 
825
 
void MainWindow::createEquation() {
826
 
  DialogLauncher::self()->showEquationDialog();
827
 
}
828
 
 
829
 
void MainWindow::createHistogram() {
830
 
  DialogLauncher::self()->showHistogramDialog();
831
 
}
832
 
 
833
 
void MainWindow::createImage() {
834
 
  DialogLauncher::self()->showImageDialog();
835
 
}
836
 
 
837
 
void MainWindow::createSpectogram() {
838
 
  DialogLauncher::self()->showCSDDialog();
839
 
}
840
 
 
841
 
void MainWindow::createEventMonitor() {
842
 
  DialogLauncher::self()->showEventMonitorDialog();
843
 
}
844
 
 
845
 
void MainWindow::createActions() {
846
 
  // ***************************** File actions ******************************** //
847
 
  _openAct = new QAction(tr("&Open..."), this);
848
 
  _openAct->setStatusTip(tr("Open a new session"));
849
 
  _openAct->setShortcut(tr("Ctrl+O"));
850
 
  _openAct->setIcon(QPixmap(":document-open.png"));
851
 
  connect(_openAct, SIGNAL(triggered()), this, SLOT(open()));
852
 
 
853
 
  _saveAct = new QAction(tr("&Save"), this);
854
 
  _saveAct->setStatusTip(tr("Save the current session"));
855
 
  _saveAct->setShortcut(tr("Ctrl+S"));
856
 
  _saveAct->setIcon(QPixmap(":document-save.png"));
857
 
  connect(_saveAct, SIGNAL(triggered()), this, SLOT(save()));
858
 
 
859
 
  _saveAsAct = new QAction(tr("Save &as..."), this);
860
 
  _saveAsAct->setStatusTip(tr("Save the current session"));
861
 
  _saveAsAct->setIcon(QPixmap(":document-save-as.png"));
862
 
  connect(_saveAsAct, SIGNAL(triggered()), this, SLOT(saveAs()));
863
 
 
864
 
  _closeAct = new QAction(tr("C&lose"), this);
865
 
  _closeAct->setStatusTip(tr("Close current session"));
866
 
  _closeAct->setIcon(QPixmap(":document-close.png"));
867
 
  connect(_closeAct, SIGNAL(triggered()), this, SLOT(newDoc()));
868
 
 
869
 
  _reloadAct = new QAction(tr("Reload All &Data Sources"), this);
870
 
  _reloadAct->setStatusTip(tr("Reload all data sources"));
871
 
  _reloadAct->setIcon(QPixmap(":kst_reload.png"));
872
 
  connect(_reloadAct, SIGNAL(triggered()), this, SLOT(reload()));
873
 
 
874
 
  _printAct = new QAction(tr("&Print..."), this);
875
 
  _printAct->setStatusTip(tr("Print the current view"));
876
 
  _printAct->setIcon(QPixmap(":document-print.png"));
877
 
  connect(_printAct, SIGNAL(triggered()), this, SLOT(print()));
878
 
 
879
 
  _exportGraphicsAct = new QAction(tr("&Export as Image..."), this);
880
 
  _exportGraphicsAct->setStatusTip(tr("Export graphics to disk"));
881
 
  _exportGraphicsAct->setIcon(QPixmap(":image-x-generic.png"));
882
 
  connect(_exportGraphicsAct, SIGNAL(triggered()), this, SLOT(showExportGraphicsDialog()));
883
 
 
884
 
  _exportVectorsAct = new QAction(tr("Save &Vectors to Disk..."), this);
885
 
  _exportVectorsAct->setStatusTip(tr("Export vectors to ascii file"));
886
 
  _exportVectorsAct->setIcon(QPixmap(":save-vectors.png"));
887
 
  connect(_exportVectorsAct, SIGNAL(triggered()), this, SLOT(showExportVectorsDialog()));
888
 
 
889
 
  _logAct = new QAction(tr("&Log Entry..."), this);
890
 
  _logAct->setStatusTip(tr("Commit a log entry"));
891
 
  _logAct->setIcon(QPixmap(":new-log-event.png"));
892
 
  connect(_logAct, SIGNAL(triggered()), this, SLOT(showLogDialog()));
893
 
 
894
 
  _newTabAct = new QAction(tr("&New Tab"), this);
895
 
  _newTabAct->setStatusTip(tr("Create a new tab"));
896
 
  _newTabAct->setIcon(QPixmap(":tab-new.png"));
897
 
  connect(_newTabAct, SIGNAL(triggered()), tabWidget(), SLOT(createView()));
898
 
 
899
 
  _closeTabAct = new QAction(tr("&Close Tab"), this);
900
 
  _closeTabAct->setStatusTip(tr("Close the current tab"));
901
 
  _closeTabAct->setIcon(QPixmap(":tab-close.png"));
902
 
  connect(_closeTabAct, SIGNAL(triggered()), tabWidget(), SLOT(closeCurrentView()));
903
 
 
904
 
  _exitAct = new QAction(tr("E&xit"), this);
905
 
  _exitAct->setShortcut(tr("Ctrl+Q"));
906
 
  _exitAct->setStatusTip(tr("Exit the application"));
907
 
  _exitAct->setIcon(QPixmap(":application-exit.png"));
908
 
  connect(_exitAct, SIGNAL(triggered()), this, SLOT(close()));
909
 
 
910
 
  // ************************** Edit Actions ******************************* //
911
 
  _undoAct = _undoGroup->createUndoAction(this);
912
 
  _undoAct->setShortcut(tr("Ctrl+Z"));
913
 
  _undoAct->setIcon(QPixmap(":edit-undo.png"));
914
 
  _redoAct = _undoGroup->createRedoAction(this);
915
 
  _redoAct->setShortcut(tr("Ctrl+Shift+Z"));
916
 
  _redoAct->setIcon(QPixmap(":edit-redo.png"));
917
 
 
918
 
  // ********************* View Actions ********************************** //
919
 
  _vectorEditorAct = new QAction(tr("&Vectors"), this);
920
 
  _vectorEditorAct->setStatusTip(tr("Show all vectors in a spreadsheet"));
921
 
  connect(_vectorEditorAct, SIGNAL(triggered()), this, SLOT(showVectorEditor()));
922
 
 
923
 
  _scalarEditorAct = new QAction(tr("&Scalars"), this);
924
 
  _scalarEditorAct->setStatusTip(tr("Show all scalars in a spreadsheet"));
925
 
  connect(_scalarEditorAct, SIGNAL(triggered()), this, SLOT(showScalarEditor()));
926
 
 
927
 
  _matrixEditorAct = new QAction(tr("&Matrices"), this);
928
 
  _matrixEditorAct->setStatusTip(tr("Show all matrices in a spreadsheet"));
929
 
  connect(_matrixEditorAct, SIGNAL(triggered()), this, SLOT(showMatrixEditor()));
930
 
 
931
 
  _stringEditorAct = new QAction(tr("S&trings"), this);
932
 
  _stringEditorAct->setStatusTip(tr("Show all strings in a spreadsheet"));
933
 
  connect(_stringEditorAct, SIGNAL(triggered()), this, SLOT(showStringEditor()));
934
 
 
935
 
  // ************************ Data Range 1 click Actions ************************** //
936
 
  _backAct = new QAction(tr("&Back One Screen"), this);
937
 
  _backAct->setStatusTip(tr("Back one screen"));
938
 
  _backAct->setIcon(QPixmap(":page-previous.png"));
939
 
  connect(_backAct, SIGNAL(triggered()), this, SLOT(back()));
940
 
 
941
 
  _forwardAct = new QAction(tr("&Forward One Screen"), this);
942
 
  _forwardAct->setStatusTip(tr("Forward one screen"));
943
 
  _forwardAct->setIcon(QPixmap(":page-next.png"));
944
 
  connect(_forwardAct, SIGNAL(triggered()), this, SLOT(forward()));
945
 
 
946
 
  _readFromEndAct = new QAction(tr("&Count from End"), this);
947
 
  _readFromEndAct->setStatusTip(tr("Set all data vectors to count from end mode"));
948
 
  _readFromEndAct->setIcon(QPixmap(":count-from-end.png"));
949
 
  connect(_readFromEndAct, SIGNAL(triggered()), this, SLOT(readFromEnd()));
950
 
 
951
 
  _readToEndAct = new QAction(tr("&Read to End"), this);
952
 
  _readToEndAct->setStatusTip(tr("Set all data vectors to read to end mode"));
953
 
  _readToEndAct->setIcon(QPixmap(":read-to-end.png"));
954
 
  connect(_readToEndAct, SIGNAL(triggered()), this, SLOT(readToEnd()));
955
 
 
956
 
  _pauseAct = new QAction(tr("&Pause"), this);
957
 
  _pauseAct->setStatusTip(tr("Toggle pause updates of data sources"));
958
 
  _pauseAct->setIcon(QPixmap(":pause.png"));
959
 
  _pauseAct->setCheckable(true);
960
 
  _pauseAct->setShortcut(QString("p"));
961
 
  connect(_pauseAct, SIGNAL(toggled(bool)), this, SLOT(pause(bool)));
962
 
 
963
 
  _changeDataSampleDialogAct = new QAction(tr("Change Data &Sample Range..."), this);
964
 
  _changeDataSampleDialogAct->setStatusTip(tr("Show Kst's Change Data Sample Range Dialog"));
965
 
  _changeDataSampleDialogAct->setIcon(QPixmap(":kst_changenpts.png"));
966
 
  connect(_changeDataSampleDialogAct, SIGNAL(triggered()), this, SLOT(showChangeDataSampleDialog()));
967
 
 
968
 
  // ************************ Create Actions ************************** //
969
 
  _createPlotAct = new QAction(tr("&Plot"), this);
970
 
  _createPlotAct->setStatusTip(tr("Create a plot for the current view"));
971
 
  _createPlotAct->setIcon(QPixmap(":office-chart-area-stacked.png"));
972
 
  _createPlotAct->setShortcut(QString("F11"));
973
 
  _createPlotAct->setCheckable(true);
974
 
  connect(_createPlotAct, SIGNAL(triggered()), this, SLOT(createPlot()));
975
 
 
976
 
  _newScalarAct = new QAction(tr("&Scalar"), this);
977
 
  connect(_newScalarAct, SIGNAL(triggered()), this, SLOT(createScalar()));
978
 
 
979
 
  _newVectorAct = new QAction(tr("&Vector"), this);
980
 
  connect(_newVectorAct, SIGNAL(triggered()), this, SLOT(createVector()));
981
 
 
982
 
  _newMatrixAct = new QAction(tr("&Matrix"), this);
983
 
  connect(_newMatrixAct, SIGNAL(triggered()), this, SLOT(createMatrix()));
984
 
 
985
 
  _newStringAct = new QAction(tr("Strin&g"), this);
986
 
  connect(_newStringAct, SIGNAL(triggered()), this, SLOT(createString()));
987
 
 
988
 
  _newCurveAct = new QAction(tr("&Curve"), this);
989
 
  connect(_newCurveAct, SIGNAL(triggered()), this, SLOT(createCurve()));
990
 
 
991
 
  _newEquationAct = new QAction(tr("&Equation"), this);
992
 
  connect(_newEquationAct, SIGNAL(triggered()), this, SLOT(createEquation()));
993
 
 
994
 
  _newPSDAct = new QAction(tr("Po&wer Spectrum"), this);
995
 
  connect(_newPSDAct, SIGNAL(triggered()), this, SLOT(createPSD()));
996
 
 
997
 
  _newHistogramAct = new QAction(tr("&Histogram"), this);
998
 
  connect(_newHistogramAct, SIGNAL(triggered()), this, SLOT(createHistogram()));
999
 
 
1000
 
  _newImageAct = new QAction(tr("&Image"), this);
1001
 
  connect(_newImageAct, SIGNAL(triggered()), this, SLOT(createImage()));
1002
 
 
1003
 
  _newSpectrogramAct = new QAction(tr("Spectr&ogram"), this);
1004
 
  connect(_newSpectrogramAct, SIGNAL(triggered()), this, SLOT(createSpectogram()));
1005
 
 
1006
 
  _newEventMonitorAct = new QAction(tr("Eve&nt Monitor"), this);
1007
 
  connect(_newEventMonitorAct, SIGNAL(triggered()), this, SLOT(createEventMonitor()));
1008
 
 
1009
 
  // Advanced layout
1010
 
  _createLabelAct = new QAction(tr("&Label"), this);
1011
 
  _createLabelAct->setStatusTip(tr("Create a label for the current view"));
1012
 
  _createLabelAct->setIcon(QPixmap(":kst_gfx_label.png"));
1013
 
  _createLabelAct->setShortcut(QString("F3"));
1014
 
  _createLabelAct->setCheckable(true);
1015
 
  connect(_createLabelAct, SIGNAL(triggered()), this, SLOT(createLabel()));
1016
 
 
1017
 
  _createBoxAct = new QAction(tr("&Box"), this);
1018
 
  _createBoxAct->setStatusTip(tr("Create a box for the current view"));
1019
 
  _createBoxAct->setIcon(QPixmap(":kst_gfx_rectangle.png"));
1020
 
  _createBoxAct->setShortcut(QString("F4"));
1021
 
  _createBoxAct->setCheckable(true);
1022
 
  connect(_createBoxAct, SIGNAL(triggered()), this, SLOT(createBox()));
1023
 
 
1024
 
  _createCircleAct = new QAction(tr("&Circle"), this);
1025
 
  _createCircleAct->setStatusTip(tr("Create a circle for the current view"));
1026
 
  _createCircleAct->setIcon(QPixmap(":kst_gfx_circle.png"));
1027
 
  _createCircleAct->setShortcut(QString("F5"));
1028
 
  _createCircleAct->setCheckable(true);
1029
 
  connect(_createCircleAct, SIGNAL(triggered()), this, SLOT(createCircle()));
1030
 
 
1031
 
  _createEllipseAct = new QAction(tr("&Ellipse"), this);
1032
 
  _createEllipseAct->setStatusTip(tr("Create an ellipse for the current view"));
1033
 
  _createEllipseAct->setIcon(QPixmap(":kst_gfx_ellipse.png"));
1034
 
  _createEllipseAct->setShortcut(QString("F6"));
1035
 
  _createEllipseAct->setCheckable(true);
1036
 
  connect(_createEllipseAct, SIGNAL(triggered()), this, SLOT(createEllipse()));
1037
 
 
1038
 
  _createLineAct = new QAction(tr("&Line"), this);
1039
 
  _createLineAct->setStatusTip(tr("Create a line for the current view"));
1040
 
  _createLineAct->setIcon(QPixmap(":kst_gfx_line.png"));
1041
 
  _createLineAct->setShortcut(QString("F7"));
1042
 
  _createLineAct->setCheckable(true);
1043
 
  connect(_createLineAct, SIGNAL(triggered()), this, SLOT(createLine()));
1044
 
 
1045
 
  _createArrowAct = new QAction(tr("&Arrow"), this);
1046
 
  _createArrowAct->setStatusTip(tr("Create a arrow for the current view"));
1047
 
  _createArrowAct->setIcon(QPixmap(":kst_gfx_arrow.png"));
1048
 
  _createArrowAct->setShortcut(QString("F8"));
1049
 
  _createArrowAct->setCheckable(true);
1050
 
  connect(_createArrowAct, SIGNAL(triggered()), this, SLOT(createArrow()));
1051
 
 
1052
 
  _createPictureAct = new QAction(tr("&Picture"), this);
1053
 
  _createPictureAct->setStatusTip(tr("Create a picture for the current view"));
1054
 
  _createPictureAct->setIcon(QPixmap(":image-x-generic.png"));
1055
 
  _createPictureAct->setShortcut(QString("F9"));
1056
 
  _createPictureAct->setCheckable(true);
1057
 
  connect(_createPictureAct, SIGNAL(triggered()), this, SLOT(createPicture()));
1058
 
 
1059
 
  _createSvgAct = new QAction(tr("&Svg"), this);
1060
 
  _createSvgAct->setStatusTip(tr("Create a svg for the current view"));
1061
 
  _createSvgAct->setIcon(QPixmap(":draw-bezier-curves.png"));
1062
 
  _createSvgAct->setShortcut(QString("F10"));
1063
 
  _createSvgAct->setCheckable(true);
1064
 
  connect(_createSvgAct, SIGNAL(triggered()), this, SLOT(createSvg()));
1065
 
 
1066
 
  _createSharedAxisBoxAct = new QAction(tr("Shared Axis &Box"), this);
1067
 
  _createSharedAxisBoxAct->setStatusTip(tr("Create a shared axis box for the current item"));
1068
 
  _createSharedAxisBoxAct->setIcon(QPixmap(":kst_gfx_sharedaxisbox.png"));
1069
 
  _createSharedAxisBoxAct->setCheckable(true);
1070
 
  //_createSharedAxisBoxAct->setEnabled(false);
1071
 
  connect(_createSharedAxisBoxAct, SIGNAL(triggered()), this, SLOT(createSharedAxisBox()));
1072
 
 
1073
 
  // ************************** Mode Actions ******************************* //
1074
 
  // First, general options
1075
 
  _tiedZoomAct = new QAction(tr("&Toggle Tied Zoom"), this);
1076
 
  _tiedZoomAct->setStatusTip(tr("Toggle the current view's tied zoom"));
1077
 
  _tiedZoomAct->setIcon(QPixmap(":tied-zoom.png"));
1078
 
  _tiedZoomAct->setCheckable(false);
1079
 
  _tiedZoomAct->setShortcut(QString("t"));
1080
 
  connect(_tiedZoomAct, SIGNAL(triggered()), this, SLOT(toggleTiedZoom()));
1081
 
 
1082
 
  _tabTiedAct = new QAction(tr("Tie &Across All Tabs"), this);
1083
 
  _tabTiedAct->setStatusTip(tr("Tied zoom applies between tabs"));
1084
 
  //_tiedZoomAct->setIcon(QPixmap(":tied-zoom.png"));
1085
 
  _tabTiedAct->setCheckable(true);
1086
 
  //connect(_tiedZoomAct, SIGNAL(triggered()), this, SLOT(toggleTiedZoom()));
1087
 
 
1088
 
  
1089
 
  _highlightPointAct = new QAction(tr("&Highlight Data Points"), this);
1090
 
  _highlightPointAct->setStatusTip(tr("Highlight closest data point"));
1091
 
  _highlightPointAct->setIcon(QPixmap(":kst_datamode.png"));
1092
 
  _highlightPointAct->setCheckable(true);
1093
 
  connect(_highlightPointAct, SIGNAL(toggled(bool)), this, SLOT(setHighlightPoint(bool)));
1094
 
  
1095
 
 
1096
 
  // Then, exclusive interaction modes
1097
 
  QActionGroup* _interactionModeGroup = new QActionGroup(this);
1098
 
 
1099
 
  _standardZoomAct = _interactionModeGroup->addAction(tr("X-Y &Zoom/Scroll"));
1100
 
  _standardZoomAct->setStatusTip(tr("Zoom arbitrarily in X- or Y-direction"));
1101
 
  //TODO _standardZoomAct->setShortcut(QString("a"));
1102
 
  _standardZoomAct->setCheckable(true);
1103
 
  _standardZoomAct->setData(View::ZoomOnlyDisabled);
1104
 
  _standardZoomAct->setIcon(QPixmap(":xy-zoom.png"));
1105
 
 
1106
 
  _xOnlyZoomAct = _interactionModeGroup->addAction(tr("&X-only Zoom"));
1107
 
  _xOnlyZoomAct->setStatusTip(tr("Zoom only in X direction"));
1108
 
  //TODO _xOnlyZoomAct->setShortcut(QString("x"));
1109
 
  _xOnlyZoomAct->setCheckable(true);
1110
 
  _xOnlyZoomAct->setData(View::ZoomOnlyX);
1111
 
  _xOnlyZoomAct->setIcon(QPixmap(":x-zoom.png"));
1112
 
 
1113
 
  _yOnlyZoomAct = _interactionModeGroup->addAction(tr("&Y-only Zoom"));
1114
 
  _yOnlyZoomAct->setStatusTip(tr("Zoom only in X direction"));
1115
 
  //TODO _yOnlyZoomAct->setShortcut(QString("y"));
1116
 
  _yOnlyZoomAct->setData(View::ZoomOnlyY);
1117
 
  _yOnlyZoomAct->setCheckable(true);
1118
 
  _yOnlyZoomAct->setIcon(QPixmap(":y-zoom.png"));
1119
 
 
1120
 
  _layoutModeAct = _interactionModeGroup->addAction(tr("&Layout Mode"));
1121
 
  _layoutModeAct->setStatusTip(tr("Toggle the current view's layout mode"));
1122
 
  _layoutModeAct->setIcon(QPixmap(":transform-move.png"));
1123
 
  _layoutModeAct->setCheckable(true);
1124
 
  _layoutModeAct->setShortcut(QString("F2"));
1125
 
  connect(_layoutModeAct, SIGNAL(toggled(bool)), this, SLOT(setLayoutMode(bool)));
1126
 
 
1127
 
  _interactionModeGroup->setExclusive(true);
1128
 
  connect(_interactionModeGroup, SIGNAL(triggered(QAction*)), this, SLOT(changeZoomOnlyMode(QAction*)));
1129
 
 
1130
 
  // *********************** Tools actions ************************************** //
1131
 
  _dataManagerAct = new QAction(tr("Data &Manager"), this);
1132
 
  _dataManagerAct->setStatusTip(tr("Show Kst's data manager window"));
1133
 
  _dataManagerAct->setIcon(QPixmap(":data-manager.png"));
1134
 
  _dataManagerAct->setShortcut(QString("d"));
1135
 
  connect(_dataManagerAct, SIGNAL(triggered()), this, SLOT(showDataManager()));
1136
 
 
1137
 
  _dataWizardAct = new QAction(tr("&Data Wizard"), this);
1138
 
  _dataWizardAct->setStatusTip(tr("Show Kst's Data Wizard"));
1139
 
  _dataWizardAct->setIcon(QPixmap(":tools-wizard.png"));
1140
 
  _dataWizardAct->setShortcut(QString("w"));
1141
 
  connect(_dataWizardAct, SIGNAL(triggered()), this, SLOT(showDataWizard()));
1142
 
 
1143
 
  _changeFileDialogAct = new QAction(tr("Change Data &File"), this);
1144
 
  _changeFileDialogAct->setStatusTip(tr("Show Kst's Change Data File Dialog"));
1145
 
  _changeFileDialogAct->setIcon(QPixmap(":change-data-file.png"));
1146
 
  _changeFileDialogAct->setShortcut(QString("f"));
1147
 
  connect(_changeFileDialogAct, SIGNAL(triggered()), this, SLOT(showChangeFileDialog()));
1148
 
 
1149
 
  _chooseColorDialogAct = new QAction(tr("Assign Curve &Color per File"), this);
1150
 
  _chooseColorDialogAct->setStatusTip(tr("Show Kst's Choose Color Dialog"));
1151
 
  _chooseColorDialogAct->setIcon(QPixmap(":code-class.png"));
1152
 
  connect(_chooseColorDialogAct, SIGNAL(triggered()), this, SLOT(showChooseColorDialog()));
1153
 
 
1154
 
  _differentiateCurvesDialogAct = new QAction(tr("D&ifferentiate Curves"), this);
1155
 
  _differentiateCurvesDialogAct->setStatusTip(tr("Show Kst's Differentiate Curves Dialog"));
1156
 
  _differentiateCurvesDialogAct->setIcon(QPixmap(":kst_differentiatecurves.png"));
1157
 
  connect(_differentiateCurvesDialogAct, SIGNAL(triggered()), this, SLOT(showDifferentiateCurvesDialog()));
1158
 
 
1159
 
  // *********************** Settings actions ************************************** //
1160
 
  _settingsDialogAct = new QAction(tr("&Configure Kst"), this);
1161
 
  _settingsDialogAct->setStatusTip(tr("Show Kst's Configuration Dialog"));
1162
 
  _settingsDialogAct->setIcon(QPixmap(":configure.png"));
1163
 
  connect(_settingsDialogAct, SIGNAL(triggered()), this, SLOT(showSettingsDialog()));
1164
 
 
1165
 
  // *********************** Help actions ************************************** //
1166
 
  _debugDialogAct = new QAction(tr("&Debug Dialog"), this);
1167
 
  _debugDialogAct->setStatusTip(tr("Show the Kst debugging dialog"));
1168
 
  _debugDialogAct->setIcon(QPixmap(":text-x-log.png"));
1169
 
  connect(_debugDialogAct, SIGNAL(triggered()), this, SLOT(showDebugDialog()));
1170
 
 
1171
 
  _bugReportWizardAct = new QAction(tr("&Bug Report Wizard"), this);
1172
 
  _bugReportWizardAct->setStatusTip(tr("Show Kst's Bug Report Wizard"));
1173
 
  _bugReportWizardAct->setIcon(QPixmap(":kbugbuster.png"));
1174
 
  connect(_bugReportWizardAct, SIGNAL(triggered()), this, SLOT(showBugReportWizard()));
1175
 
 
1176
 
  _aboutAct = new QAction(tr("&About"), this);
1177
 
  _aboutAct->setStatusTip(tr("Show Kst's About box"));
1178
 
  _aboutAct->setIcon(QPixmap(":dialog-information.png"));
1179
 
  connect(_aboutAct, SIGNAL(triggered()), this, SLOT(about()));
1180
 
}
1181
 
 
1182
 
 
1183
 
void MainWindow::createMenus() {
1184
 
  _fileMenu = menuBar()->addMenu(tr("&File"));
1185
 
  // Session operations
1186
 
  _fileMenu->addAction(_openAct);
1187
 
  _fileMenu->addAction(_saveAct);
1188
 
  _fileMenu->addAction(_saveAsAct);
1189
 
  _fileMenu->addAction(_closeAct);
1190
 
  _fileMenu->addSeparator();
1191
 
  _recentKstFilesMenu = _fileMenu->addMenu(tr("&Recent Sessions"));
1192
 
  _recentDataFilesMenu = _fileMenu->addMenu("Recent Data &Files");
1193
 
  _fileMenu->addSeparator();
1194
 
  // Reload, isolate it a bit from the other entries to avoid inadvertent triggering
1195
 
  _fileMenu->addAction(_reloadAct);
1196
 
  _fileMenu->addSeparator();
1197
 
  // Print/export
1198
 
  _fileMenu->addAction(_printAct);
1199
 
  _fileMenu->addAction(_exportGraphicsAct);
1200
 
  _fileMenu->addAction(_exportVectorsAct);
1201
 
  _fileMenu->addAction(_logAct);
1202
 
  _fileMenu->addSeparator();
1203
 
  // Tabs
1204
 
  _fileMenu->addAction(_newTabAct);
1205
 
  _fileMenu->addAction(_closeTabAct);
1206
 
  _fileMenu->addSeparator();
1207
 
  // exit  
1208
 
  _fileMenu->addAction(_exitAct);
1209
 
  // recent files
1210
 
  _fileMenu->addSeparator();
1211
 
  updateRecentKstFiles();
1212
 
 
1213
 
 
1214
 
  _editMenu = menuBar()->addMenu(tr("&Edit"));
1215
 
  _editMenu->addAction(_undoAct);
1216
 
  _editMenu->addAction(_redoAct);
1217
 
  // Cut/Copy/Paste will come here
1218
 
 
1219
 
  _viewMenu = menuBar()->addMenu(tr("&View"));
1220
 
  _viewMenu->addAction(_vectorEditorAct);
1221
 
  _viewMenu->addAction(_scalarEditorAct);
1222
 
  _viewMenu->addAction(_matrixEditorAct);
1223
 
  _viewMenu->addAction(_stringEditorAct);
1224
 
 
1225
 
  _rangeMenu = menuBar()->addMenu(tr("&Range"));
1226
 
  _rangeMenu->addAction(_backAct);
1227
 
  _rangeMenu->addAction(_forwardAct);
1228
 
  _rangeMenu->addSeparator();
1229
 
  _rangeMenu->addAction(_readFromEndAct);
1230
 
  _rangeMenu->addAction(_readToEndAct);
1231
 
  _rangeMenu->addAction(_pauseAct);
1232
 
  _rangeMenu->addSeparator();
1233
 
  _rangeMenu->addAction(_changeDataSampleDialogAct);
1234
 
 
1235
 
  _createMenu = menuBar()->addMenu(tr("&Create"));
1236
 
  // Containers
1237
 
  _createMenu->addAction(_createPlotAct);
1238
 
  _createMenu->addAction(_createSharedAxisBoxAct);
1239
 
  _createMenu->addSeparator();
1240
 
  // Primitives
1241
 
  _createMenu->addAction(_newScalarAct);
1242
 
  _createMenu->addAction(_newVectorAct);
1243
 
  _createMenu->addAction(_newMatrixAct);
1244
 
  _createMenu->addAction(_newStringAct);
1245
 
  _createMenu->addSeparator();
1246
 
  // Data objects
1247
 
  _createMenu->addAction(_newCurveAct);
1248
 
  _createMenu->addAction(_newEquationAct);
1249
 
  _createMenu->addAction(_newPSDAct);
1250
 
  _createMenu->addAction(_newHistogramAct);
1251
 
  _createMenu->addAction(_newImageAct);
1252
 
  _createMenu->addAction(_newSpectrogramAct);
1253
 
  _createMenu->addAction(_newEventMonitorAct);
1254
 
  _createMenu->addSeparator();
1255
 
  // Now, create the dynamic plugin menus
1256
 
  QMenu* _pluginsMenu = _createMenu->addMenu(tr("Standard P&lugin"));
1257
 
  QMenu* _fitPluginsMenu = _createMenu->addMenu(tr("Fit Pl&ugin"));
1258
 
  QMenu* _filterPluginsMenu = _createMenu->addMenu(tr("Fil&ter Plugin"));
1259
 
  PluginMenuItemAction* action;
1260
 
  foreach (QString pluginName, DataObject::dataObjectPluginList()) {
1261
 
    action = new PluginMenuItemAction(pluginName, this);
1262
 
    connect(action, SIGNAL(triggered(QString&)), this, SLOT(showPluginDialog(QString&)));
1263
 
    _pluginsMenu->addAction(action);
1264
 
  }
1265
 
  foreach (QString pluginName, DataObject::fitsPluginList()) {
1266
 
    action = new PluginMenuItemAction(pluginName, this);
1267
 
    connect(action, SIGNAL(triggered(QString&)), this, SLOT(showPluginDialog(QString&)));
1268
 
    _fitPluginsMenu->addAction(action);
1269
 
  }
1270
 
  foreach (QString pluginName, DataObject::filterPluginList()) {
1271
 
    action = new PluginMenuItemAction(pluginName, this);
1272
 
    connect(action, SIGNAL(triggered(QString&)), this, SLOT(showPluginDialog(QString&)));
1273
 
    _filterPluginsMenu->addAction(action);
1274
 
  }
1275
 
  _createMenu->addSeparator();
1276
 
  // Annotation objects
1277
 
  QMenu* annotations = _createMenu->addMenu(tr("&Annotation"));
1278
 
  annotations->addAction(_createLabelAct);
1279
 
  annotations->addAction(_createBoxAct);
1280
 
  annotations->addAction(_createCircleAct);
1281
 
  annotations->addAction(_createEllipseAct);
1282
 
  annotations->addAction(_createLineAct);
1283
 
  annotations->addAction(_createArrowAct);
1284
 
  annotations->addAction(_createPictureAct);
1285
 
  annotations->addAction(_createSvgAct);
1286
 
 
1287
 
  _modeMenu = menuBar()->addMenu(tr("&Mode"));
1288
 
  // Interaction mode
1289
 
  _modeMenu->addSeparator()->setText(tr("Interaction mode"));
1290
 
  _modeMenu->addAction(_standardZoomAct);
1291
 
  _modeMenu->addAction(_xOnlyZoomAct);
1292
 
  _modeMenu->addAction(_yOnlyZoomAct);
1293
 
  _modeMenu->addAction(_layoutModeAct);
1294
 
  _standardZoomAct->setChecked(true);
1295
 
  _modeMenu->addSeparator();
1296
 
  // Tied zoom options
1297
 
  _modeMenu->addAction(_tiedZoomAct);
1298
 
  _modeMenu->addAction(_tabTiedAct);
1299
 
  _modeMenu->addSeparator();
1300
 
  // Data mode
1301
 
  _modeMenu->addAction(_highlightPointAct);
1302
 
 
1303
 
  _toolsMenu = menuBar()->addMenu(tr("&Tools"));
1304
 
  _toolsMenu->addAction(_dataManagerAct);
1305
 
  _toolsMenu->addAction(_dataWizardAct);
1306
 
  _toolsMenu->addAction(_changeFileDialogAct);
1307
 
  _toolsMenu->addAction(_chooseColorDialogAct);
1308
 
  _toolsMenu->addAction(_differentiateCurvesDialogAct);
1309
 
  _toolsMenu->addSeparator();
1310
 
  updateRecentDataFiles();
1311
 
 
1312
 
  _settingsMenu = menuBar()->addMenu(tr("&Settings"));
1313
 
  _settingsMenu->addAction(_settingsDialogAct);
1314
 
 
1315
 
  menuBar()->addSeparator();
1316
 
 
1317
 
  _helpMenu = menuBar()->addMenu(tr("&Help"));
1318
 
  _helpMenu->addAction(_debugDialogAct);
1319
 
  _helpMenu->addAction(_bugReportWizardAct);
1320
 
  _helpMenu->addSeparator();
1321
 
  _helpMenu->addAction(_aboutAct);
1322
 
 
1323
 
}
1324
 
 
1325
 
 
1326
 
void MainWindow::createToolBars() {
1327
 
  setToolButtonStyle(Qt::ToolButtonIconOnly);
1328
 
 
1329
 
  _fileToolBar = addToolBar(tr("File"));
1330
 
  _fileToolBar->setObjectName("File Toolbar");
1331
 
  _fileToolBar->addAction(_openAct);
1332
 
  _fileToolBar->addAction(_saveAct);
1333
 
  _fileToolBar->addAction(_reloadAct);
1334
 
  _fileToolBar->addAction(_printAct);
1335
 
  _fileToolBar->addAction(_logAct);
1336
 
 
1337
 
  _editToolBar = addToolBar(tr("Edit"));
1338
 
  _editToolBar->setObjectName("Edit Toolbar");
1339
 
  _editToolBar->addAction(_undoAct);
1340
 
  _editToolBar->addAction(_redoAct);
1341
 
 
1342
 
  _toolsToolBar = addToolBar(tr("Tools"));
1343
 
  _toolsToolBar->setObjectName("Tools Toolbar");
1344
 
  _toolsToolBar->addAction(_dataManagerAct);
1345
 
  _toolsToolBar->addAction(_dataWizardAct);
1346
 
  _toolsToolBar->addAction(_changeDataSampleDialogAct);
1347
 
  _toolsToolBar->addAction(_changeFileDialogAct);
1348
 
 
1349
 
  _rangeToolBar = addToolBar(tr("Data Range"));
1350
 
  _rangeToolBar->setObjectName("Data Range Toolbar");
1351
 
  _rangeToolBar->addAction(_backAct);
1352
 
  _rangeToolBar->addAction(_forwardAct);
1353
 
  _rangeToolBar->addAction(_readFromEndAct);
1354
 
  _rangeToolBar->addAction(_readToEndAct);
1355
 
  _rangeToolBar->addAction(_pauseAct);
1356
 
 
1357
 
  _modeToolBar = addToolBar(tr("Mode"));
1358
 
  _modeToolBar->setObjectName("Mode Toolbar");
1359
 
  _modeToolBar->addAction(_tiedZoomAct);
1360
 
  _modeToolBar->addAction(_highlightPointAct);
1361
 
  _modeToolBar->addSeparator();
1362
 
  _modeToolBar->addAction(_standardZoomAct);
1363
 
  _modeToolBar->addAction(_xOnlyZoomAct);
1364
 
  _modeToolBar->addAction(_yOnlyZoomAct);
1365
 
  _modeToolBar->addAction(_layoutModeAct);
1366
 
 
1367
 
  _annotationToolBar = addToolBar(tr("Advanced Layout"));
1368
 
  _annotationToolBar->setObjectName("Advanced Layout Toolbar");
1369
 
  _annotationToolBar->addAction(_createSharedAxisBoxAct);
1370
 
  _annotationToolBar->addSeparator();
1371
 
  _annotationToolBar->addAction(_createLabelAct);
1372
 
  _annotationToolBar->addAction(_createBoxAct);
1373
 
  _annotationToolBar->addAction(_createCircleAct);
1374
 
  _annotationToolBar->addAction(_createEllipseAct);
1375
 
  _annotationToolBar->addAction(_createLineAct);
1376
 
  _annotationToolBar->addAction(_createArrowAct);
1377
 
  _annotationToolBar->addAction(_createPictureAct);
1378
 
  _annotationToolBar->addAction(_createSvgAct);
1379
 
 
1380
 
}
1381
 
 
1382
 
 
1383
 
void MainWindow::createStatusBar() {
1384
 
  _messageLabel = new QLabel(statusBar());
1385
 
  statusBar()->addWidget(_messageLabel);
1386
 
  setStatusMessage(tr("Ready"));
1387
 
 
1388
 
  _progressBar = new QProgressBar(statusBar());
1389
 
  _progressBar->hide();
1390
 
  statusBar()->addPermanentWidget(_progressBar);
1391
 
  MemoryWidget *mw = new MemoryWidget(statusBar());
1392
 
  statusBar()->addPermanentWidget(mw);
1393
 
  DebugNotifier *dn = new DebugNotifier(statusBar());
1394
 
  connect(dn, SIGNAL(showDebugLog()), this, SLOT(showDebugDialog()));
1395
 
  connect(_debugDialog, SIGNAL(notifyOfError()), dn, SLOT(reanimate()));
1396
 
  connect(_debugDialog, SIGNAL(notifyAllClear()), dn, SLOT(close()));
1397
 
  statusBar()->addPermanentWidget(dn);
1398
 
}
1399
 
 
1400
 
void MainWindow::setStatusMessage(QString message) {
1401
 
  _messageLabel->setText(message);
1402
 
}
1403
 
 
1404
 
QProgressBar *MainWindow::progressBar() const {
1405
 
  return _progressBar;
1406
 
}
1407
 
 
1408
 
void MainWindow::readFromEnd() {
1409
 
  int nf = 0;
1410
 
  int skip;
1411
 
  bool do_skip;
1412
 
  bool do_filter;
1413
 
 
1414
 
  DataVectorList dataVectors = document()->objectStore()->getObjects<DataVector>();
1415
 
 
1416
 
  foreach (DataVectorPtr v, dataVectors) {
1417
 
    v->readLock();
1418
 
    nf = v->reqNumFrames();
1419
 
    if (nf <=0 ) {
1420
 
      nf = v->numFrames();
1421
 
    }
1422
 
    skip = v->skip();
1423
 
    do_skip = v->doSkip();
1424
 
    do_filter = v->doAve();
1425
 
    v->unlock();
1426
 
 
1427
 
    v->writeLock();
1428
 
    v->changeFrames(-1, nf, skip, do_skip, do_filter);
1429
 
    v->registerChange();
1430
 
    v->unlock();
1431
 
  }
1432
 
  UpdateManager::self()->doUpdates(true);
1433
 
  _dialogDefaults->setValue("vector/range", nf);
1434
 
  _dialogDefaults->setValue("vector/countFromEnd", true);
1435
 
  _dialogDefaults->setValue("vector/readToEnd", false);
1436
 
}
1437
 
 
1438
 
void MainWindow::readToEnd() {
1439
 
  int f0 = 0;
1440
 
  int skip;
1441
 
  bool do_skip;
1442
 
  bool do_filter;
1443
 
 
1444
 
  DataVectorList dataVectors = document()->objectStore()->getObjects<DataVector>();
1445
 
 
1446
 
  foreach (DataVectorPtr v, dataVectors) {
1447
 
    v->readLock();
1448
 
    f0 = v->startFrame();
1449
 
    skip = v->skip();
1450
 
    do_skip = v->doSkip();
1451
 
    do_filter = v->doAve();
1452
 
    v->unlock();
1453
 
 
1454
 
    v->writeLock();
1455
 
    v->changeFrames(f0, -1, skip, do_skip, do_filter);
1456
 
    v->registerChange();
1457
 
    v->unlock();
1458
 
  }
1459
 
  _dialogDefaults->setValue("vector/start", f0);
1460
 
  _dialogDefaults->setValue("vector/countFromEnd", false);
1461
 
  _dialogDefaults->setValue("vector/readToEnd", true);
1462
 
  UpdateManager::self()->doUpdates(true);
1463
 
}
1464
 
 
1465
 
void MainWindow::pause(bool pause) {
1466
 
  UpdateManager::self()->setPaused(pause);
1467
 
 
1468
 
  if (!pause) {
1469
 
     foreach (DataSourcePtr s, document()->objectStore()->dataSourceList()) {
1470
 
       s->checkUpdate();
1471
 
     }
1472
 
  }
1473
 
}
1474
 
 
1475
 
void MainWindow::forward() {
1476
 
  int f0 = 0;
1477
 
  int nf = 0;
1478
 
  int skip;
1479
 
  int filelength;
1480
 
  bool count_from_end;
1481
 
  bool read_to_end;
1482
 
  bool do_skip;
1483
 
  bool do_filter;
1484
 
 
1485
 
  DataVectorList dataVectors = document()->objectStore()->getObjects<DataVector>();
1486
 
 
1487
 
  foreach (DataVectorPtr v, dataVectors) {
1488
 
    v->readLock();
1489
 
    f0 = v->startFrame();
1490
 
    nf = v->numFrames();
1491
 
    count_from_end = v->countFromEOF();
1492
 
    read_to_end = v->readToEOF();
1493
 
    filelength = v->fileLength();
1494
 
 
1495
 
    skip = v->skip();
1496
 
    do_skip = v->doSkip();
1497
 
    do_filter = v->doAve();
1498
 
    v->unlock();
1499
 
 
1500
 
    if ((!count_from_end) && (!read_to_end)) {
1501
 
      f0 += nf;
1502
 
      if (f0+nf>=filelength) {
1503
 
        f0 = filelength - nf;
1504
 
      }
1505
 
 
1506
 
      v->writeLock();
1507
 
      v->changeFrames(f0, nf, skip, do_skip, do_filter);
1508
 
      v->registerChange();
1509
 
      v->unlock();
1510
 
    }
1511
 
  }
1512
 
  _dialogDefaults->setValue("vector/range", nf);
1513
 
  _dialogDefaults->setValue("vector/start", f0);
1514
 
  _dialogDefaults->setValue("vector/countFromEnd", false);
1515
 
  _dialogDefaults->setValue("vector/readToEnd", false);
1516
 
 
1517
 
  UpdateManager::self()->doUpdates(true);
1518
 
}
1519
 
 
1520
 
void MainWindow::back() {
1521
 
  int f0 = 0;
1522
 
  int nf = 0;
1523
 
  int skip;
1524
 
  int filelength;
1525
 
  bool count_from_end;
1526
 
  bool read_to_end;
1527
 
  bool do_skip;
1528
 
  bool do_filter;
1529
 
 
1530
 
  DataVectorList dataVectors = document()->objectStore()->getObjects<DataVector>();
1531
 
 
1532
 
  foreach (DataVectorPtr v, dataVectors) {
1533
 
    v->readLock();
1534
 
    f0 = v->startFrame();
1535
 
    nf = v->numFrames();
1536
 
    count_from_end = v->countFromEOF();
1537
 
    read_to_end = v->readToEOF();
1538
 
    filelength = v->fileLength();
1539
 
 
1540
 
    skip = v->skip();
1541
 
    do_skip = v->doSkip();
1542
 
    do_filter = v->doAve();
1543
 
    v->unlock();
1544
 
 
1545
 
    if (f0 != 0) {
1546
 
      if (count_from_end) {
1547
 
        f0 = filelength - nf;
1548
 
      }
1549
 
      if (read_to_end) {
1550
 
        nf = filelength - f0;
1551
 
      }
1552
 
 
1553
 
      f0 -= nf;
1554
 
      if (f0<0) {
1555
 
        f0 = 0;
1556
 
      }
1557
 
      v->writeLock();
1558
 
      v->changeFrames(f0, nf, skip, do_skip, do_filter);
1559
 
      v->registerChange();
1560
 
      v->unlock();
1561
 
    }
1562
 
  }
1563
 
  _dialogDefaults->setValue("vector/range", nf);
1564
 
  _dialogDefaults->setValue("vector/start", f0);
1565
 
  _dialogDefaults->setValue("vector/countFromEnd", false);
1566
 
  _dialogDefaults->setValue("vector/readToEnd", false);
1567
 
  UpdateManager::self()->doUpdates(true);
1568
 
}
1569
 
 
1570
 
void MainWindow::reload() {
1571
 
  document()->objectStore()->rebuildDataSourceList();
1572
 
  UpdateManager::self()->doUpdates(true);
1573
 
  //document()->setChanged(true);
1574
 
}
1575
 
 
1576
 
void MainWindow::showDataManager() {
1577
 
  if (!_dataManager) {
1578
 
    _dataManager = new DataManager(this, _doc);
1579
 
  }
1580
 
  if (_dataManager->isVisible()) {
1581
 
    _dataManager->raise();
1582
 
    _dataManager->activateWindow();
1583
 
  }
1584
 
  _dataManager->show();
1585
 
}
1586
 
 
1587
 
 
1588
 
void MainWindow::updateViewItems(qint64 serial) {
1589
 
 
1590
 
  QList<PlotItem *> plots = ViewItem::getItems<PlotItem>();
1591
 
 
1592
 
  bool changed = false;
1593
 
  foreach (PlotItem *plot, plots) {
1594
 
    changed |= plot->handleChangedInputs(serial);
1595
 
  }
1596
 
 
1597
 
  if (changed) {
1598
 
    _tabWidget->currentView()->update();
1599
 
  }
1600
 
 
1601
 
  QTimer::singleShot(20, UpdateManager::self(), SLOT(viewItemUpdateFinished()));
1602
 
}
1603
 
 
1604
 
void MainWindow::showVectorEditor() {
1605
 
  ViewVectorDialog *viewVectorDialog = new ViewVectorDialog(this, _doc);
1606
 
  viewVectorDialog->show();
1607
 
}
1608
 
 
1609
 
 
1610
 
void MainWindow::showScalarEditor() {
1611
 
  ViewPrimitiveDialog *viewScalarDialog = new ViewScalarDialog(this, _doc);
1612
 
  viewScalarDialog->show();
1613
 
}
1614
 
 
1615
 
 
1616
 
void MainWindow::showStringEditor() {
1617
 
  ViewPrimitiveDialog *viewStringDialog = new ViewStringDialog(this, _doc);
1618
 
  viewStringDialog->show();
1619
 
}
1620
 
 
1621
 
void MainWindow::showMatrixEditor() {
1622
 
  ViewMatrixDialog *viewMatrixDialog = new ViewMatrixDialog(this, _doc);
1623
 
  viewMatrixDialog->show();
1624
 
}
1625
 
 
1626
 
 
1627
 
void MainWindow::showDebugDialog() {
1628
 
  if (!_debugDialog) {
1629
 
    _debugDialog = new DebugDialog(this);
1630
 
  }
1631
 
  _debugDialog->setObjectStore(document()->objectStore());
1632
 
  if (_debugDialog->isVisible()) {
1633
 
    _debugDialog->raise();
1634
 
    _debugDialog->activateWindow();
1635
 
  }
1636
 
  _debugDialog->show();
1637
 
}
1638
 
 
1639
 
 
1640
 
void MainWindow::showExportGraphicsDialog() {
1641
 
  if (!_exportGraphics) {
1642
 
    _exportGraphics = new ExportGraphicsDialog(this);
1643
 
    connect(_exportGraphics, SIGNAL(exportGraphics(const QString &, const QString &, int, int, int)),
1644
 
            this, SLOT(exportGraphicsFile(const QString &, const QString &, int, int, int)));
1645
 
  }
1646
 
  if (_exportGraphics->isVisible()) {
1647
 
    _exportGraphics->raise();
1648
 
    _exportGraphics->activateWindow();
1649
 
  }
1650
 
  _exportGraphics->show();
1651
 
}
1652
 
 
1653
 
 
1654
 
void MainWindow::showExportVectorsDialog() {
1655
 
  if (!_exportVectors) {
1656
 
    _exportVectors = new ExportVectorsDialog(this);
1657
 
    //connect(_exportVectors, SIGNAL(exportGraphics(const QString &, const QString &, int, int, int)),
1658
 
    //        this, SLOT(exportGraphicsFile(const QString &, const QString &, int, int, int)));
1659
 
  }
1660
 
  if (_exportVectors->isVisible()) {
1661
 
    _exportVectors->raise();
1662
 
    _exportVectors->activateWindow();
1663
 
  }
1664
 
  _exportVectors->show();
1665
 
}
1666
 
 
1667
 
 
1668
 
void MainWindow::showLogDialog() {
1669
 
  if (!_logDialog) {
1670
 
    _logDialog = new LogDialog(this);
1671
 
    //connect(_logDialog, SIGNAL(exportLog(const QString &, time_t, const QString &, int, int, int, const QString &)),
1672
 
    //        this, SLOT(exportLog(const QString &, time_t, const QString &, int, int, int, const QString &)));
1673
 
  }
1674
 
  if (_logDialog->isVisible()) {
1675
 
    _logDialog->raise();
1676
 
    _logDialog->activateWindow();
1677
 
  }
1678
 
  _logDialog->show();
1679
 
}
1680
 
 
1681
 
 
1682
 
void MainWindow::showSettingsDialog() {
1683
 
  if (!_applicationSettingsDialog) {
1684
 
    _applicationSettingsDialog = new ApplicationSettingsDialog(this);
1685
 
  }
1686
 
  if (_applicationSettingsDialog->isVisible()) {
1687
 
    _applicationSettingsDialog->raise();
1688
 
    _applicationSettingsDialog->activateWindow();
1689
 
  }
1690
 
  _applicationSettingsDialog->show();
1691
 
}
1692
 
 
1693
 
 
1694
 
void MainWindow::showDifferentiateCurvesDialog() {
1695
 
  if (!_differentiateCurvesDialog) {
1696
 
    _differentiateCurvesDialog = new DifferentiateCurvesDialog(this);
1697
 
  }
1698
 
  if (_differentiateCurvesDialog->isVisible()) {
1699
 
    _differentiateCurvesDialog->raise();
1700
 
    _differentiateCurvesDialog->activateWindow();
1701
 
  }
1702
 
  _differentiateCurvesDialog->show();
1703
 
}
1704
 
 
1705
 
 
1706
 
void MainWindow::showChooseColorDialog() {
1707
 
  if (!_chooseColorDialog) {
1708
 
    _chooseColorDialog = new ChooseColorDialog(this);
1709
 
  }
1710
 
  if (_chooseColorDialog->isVisible()) {
1711
 
    _chooseColorDialog->raise();
1712
 
    _chooseColorDialog->activateWindow();
1713
 
  }
1714
 
  _chooseColorDialog->show();
1715
 
}
1716
 
 
1717
 
 
1718
 
void MainWindow::showChangeDataSampleDialog() {
1719
 
  if (!_changeDataSampleDialog) {
1720
 
    _changeDataSampleDialog = new ChangeDataSampleDialog(this);
1721
 
  }
1722
 
  if (_changeDataSampleDialog->isVisible()) {
1723
 
    _changeDataSampleDialog->raise();
1724
 
    _changeDataSampleDialog->activateWindow();
1725
 
  }
1726
 
  _changeDataSampleDialog->show();
1727
 
}
1728
 
 
1729
 
 
1730
 
void MainWindow::showDataWizard() {
1731
 
  DataWizard *dataWizard = new DataWizard(this);
1732
 
  connect(dataWizard, SIGNAL(dataSourceLoaded(const QString&)), this, SLOT(updateRecentDataFiles(const QString&)));
1733
 
  dataWizard->show();
1734
 
}
1735
 
 
1736
 
 
1737
 
void MainWindow::openRecentDataFile()
1738
 
{
1739
 
  QAction *action = qobject_cast<QAction *>(sender());
1740
 
  if (action) {
1741
 
    DataWizard *dataWizard = new DataWizard(this, action->data().toString());
1742
 
    connect(dataWizard, SIGNAL(dataSourceLoaded(const QString&)), this, SLOT(updateRecentDataFiles(const QString&)));
1743
 
    dataWizard->show();
1744
 
  }
1745
 
}
1746
 
 
1747
 
 
1748
 
void MainWindow::showBugReportWizard() {
1749
 
  if (!_bugReportWizard) {
1750
 
    _bugReportWizard = new BugReportWizard(this);
1751
 
  }
1752
 
  if (_bugReportWizard->isVisible()) {
1753
 
    _bugReportWizard->raise();
1754
 
    _bugReportWizard->activateWindow();
1755
 
  }
1756
 
  _bugReportWizard->show();
1757
 
}
1758
 
 
1759
 
void MainWindow::showChangeFileDialog() {
1760
 
  if (!_changeFileDialog) {
1761
 
    _changeFileDialog = new ChangeFileDialog(this);
1762
 
  }
1763
 
  if (_changeFileDialog->isVisible()) {
1764
 
    _changeFileDialog->raise();
1765
 
    _changeFileDialog->activateWindow();
1766
 
  }
1767
 
  _changeFileDialog->show();
1768
 
}
1769
 
 
1770
 
void MainWindow::showPluginDialog(QString &pluginName) {
1771
 
  DialogLauncher::self()->showBasicPluginDialog(pluginName);
1772
 
}
1773
 
 
1774
 
bool MainWindow::isTiedTabs() {
1775
 
  return _tabTiedAct->isChecked();
1776
 
}
1777
 
 
1778
 
void MainWindow::readSettings() {
1779
 
  QSettings settings("Kst2");
1780
 
  QByteArray geo = settings.value("geometry").toByteArray();
1781
 
  if (!geo.isEmpty()) {
1782
 
      restoreGeometry(geo);
1783
 
  } else {
1784
 
      setGeometry(50, 50, 800, 600);
1785
 
  }
1786
 
  restoreState(settings.value("toolbarState").toByteArray());
1787
 
  _tabTiedAct->setChecked(settings.value("tieTabs").toBool());
1788
 
}
1789
 
 
1790
 
 
1791
 
void MainWindow::writeSettings() {
1792
 
  QSettings settings("Kst2");
1793
 
  settings.setValue("geometry", saveGeometry());
1794
 
  settings.setValue("toolbarState", saveState());
1795
 
  settings.setValue("tieTabs", _tabTiedAct->isChecked());
1796
 
}
1797
 
 
1798
 
void MainWindow::setWidgetFlags(QWidget* widget)
1799
 
{
1800
 
  if (widget) {
1801
 
    // Make sure the dialog gets maximize and minimize buttons under Windows
1802
 
    widget->QWidget::setWindowFlags((Qt::WindowFlags) Qt::Dialog |     Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint
1803
 
#if QT_VERSION >= 0x040500
1804
 
        | Qt::WindowCloseButtonHint
1805
 
#endif
1806
 
);
1807
 
  }
1808
 
}
1809
 
 
1810
 
}
1811
 
 
1812
 
// vim: ts=2 sw=2 et