vymview.cpp
author insilmaril
Tue, 07 Jul 2009 11:21:27 +0000
changeset 780 fe839bdfd10c
parent 777 8acac4fade1b
child 788 78ba80b54bc4
permissions -rw-r--r--
vymLinks working again
     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 		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    39 		model,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    40 
    41 	connect (
    42 		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
    43 		mapEditor,SLOT (updateData(const QModelIndex &) ) );
    44 
    45 	// VymModel may want to update selection or other data, e.g. during animation
    46 	connect (
    47 		model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    48 		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    49 
    50 	connect (
    51 		model, SIGNAL (noteHasChanged(QModelIndex) ),
    52 		mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
    53 		
    54 	connect (
    55 		model, SIGNAL (expandAll() ),
    56 		this, SLOT (expandAll () ) );
    57 		
    58 	connect (
    59 		model, SIGNAL (showSelection() ),
    60 		this, SLOT (showSelection() ) );
    61 		
    62 
    63 	mapEditor->setAntiAlias (mainWindow->isAliased());
    64 	mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
    65 
    66 	addWidget (treeEditor);
    67 	addWidget (mapEditor);
    68 
    69 	// Set geometry
    70 	QList <int> widths;
    71 	widths<<120;
    72 	widths<<600;
    73 	setSizes(widths);
    74 }
    75 
    76 VymView::~VymView()
    77 {
    78 	//cout << "Destructor VymView\n";
    79 }
    80 
    81 VymModel* VymView::getModel()
    82 {
    83 	return model;
    84 }
    85 
    86 MapEditor* VymView::getMapEditor()
    87 {
    88 	return mapEditor;
    89 }
    90 
    91 void VymView::initFocus()
    92 {
    93 	mapEditor->setFocus();
    94 }
    95 
    96 QItemSelectionModel* VymView::selectionModel() 
    97 {
    98 	if (treeEditor) 
    99 		return selModel;
   100 	else 
   101 		std::cout <<"VymView::selectionModel: hey, no treeEditor so far???\n";
   102 	return NULL;
   103 }
   104 
   105 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
   106 {
   107 	// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
   108 	mainWindow->changeSelection (model,newsel,oldsel);	// FIXME-5 maybe connect VymModel <-> MainWindow directly?
   109 	// would require to also get current model in mainWindow
   110 
   111 	//showSelection();
   112 }
   113 
   114 void VymView::expandAll()
   115 {
   116 	treeEditor->expandAll();
   117 }
   118 
   119 void VymView::showSelection()
   120 {
   121 	QModelIndex ix=model->getSelectedIndex();
   122 	treeEditor->scrollTo( ix, QAbstractItemView::EnsureVisible);
   123 	mapEditor->scrollTo ( ix);
   124 }
   125