vymview.cpp
author insilmaril
Tue May 26 11:24:51 2009 +0000 (2009-05-26)
changeset 774 2f002657dada
parent 769 a6931cd6309a
child 775 6e4b586aa88a
permissions -rw-r--r--
added missing new files
     1 #include "vymview.h"
     2 
     3 #include <iostream>
     4 using namespace std;
     5 
     6 #include "mainwindow.h"
     7 #include "mapeditor.h"
     8 #include "treeeditor.h"
     9 
    10 extern Main *mainWindow;
    11 
    12 
    13 VymView::VymView(VymModel *m)
    14 {
    15 	model=m;
    16 
    17 	// Create TreeView
    18 	treeEditor=new TreeEditor (model);
    19 	treeEditor->setModel ((QAbstractItemModel*)model);
    20 	//treeEditor->setMinimumWidth (50);
    21 
    22 	treeEditor->setColumnWidth (0,350);
    23 
    24 	selModel=treeEditor->selectionModel();
    25 	model->setSelectionModel (selModel);
    26 	connect (
    27 		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    28 		this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
    29 
    30 	// Create good old MapEditor
    31 	mapEditor=model->getMapEditor();
    32 	if (!mapEditor) mapEditor=new MapEditor (model);
    33 	connect (
    34 		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    35 		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    36 
    37 	connect (
    38 		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
    39 		mapEditor,SLOT (updateData(const QModelIndex &) ) );
    40 
    41 	// VymModel may want to update selection or other data, e.g. during animation
    42 	connect (
    43 		model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    44 		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    45 
    46 	connect (
    47 		model, SIGNAL (noteHasChanged(QModelIndex) ),
    48 		mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
    49 		
    50 	connect (
    51 		model, SIGNAL (expandAll() ),
    52 		this, SLOT (expandAll () ) );
    53 		
    54 	connect (
    55 		model, SIGNAL (showSelection() ),
    56 		this, SLOT (showSelection() ) );
    57 		
    58 
    59 	mapEditor->setAntiAlias (mainWindow->isAliased());
    60 	mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
    61 
    62 	addWidget (treeEditor);
    63 	addWidget (mapEditor);
    64 
    65 	// Set geometry
    66 	QList <int> widths;
    67 	widths<<120;
    68 	widths<<600;
    69 	setSizes(widths);
    70 }
    71 
    72 VymView::~VymView()
    73 {
    74 	//cout << "Destructor VymView\n";
    75 }
    76 
    77 VymModel* VymView::getModel()
    78 {
    79 	return model;
    80 }
    81 
    82 MapEditor* VymView::getMapEditor()
    83 {
    84 	return mapEditor;
    85 }
    86 
    87 void VymView::initFocus()
    88 {
    89 	mapEditor->setFocus();
    90 }
    91 
    92 QItemSelectionModel* VymView::selectionModel() 
    93 {
    94 	if (treeEditor) 
    95 		return selModel;
    96 	else 
    97 		std::cout <<"VymView::selectionModel: hey, no treeEditor so far???\n";
    98 	return NULL;
    99 }
   100 
   101 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
   102 {
   103 	// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
   104 	mainWindow->changeSelection (model,newsel,oldsel);	// FIXME-3 maybe connect VymModel <-> MainWindow directly?
   105 	showSelection();
   106 }
   107 
   108 void VymView::expandAll()
   109 {
   110 	treeEditor->expandAll();
   111 }
   112 
   113 void VymView::showSelection()
   114 {
   115 	QModelIndex ix=model->getSelectedIndex();
   116 	treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
   117 	mapEditor->scrollTo ( ix);
   118 }
   119