vymview.cpp
author insilmaril
Wed, 01 Apr 2009 15:06:57 +0000
changeset 749 9ff332964015
parent 746 ee6b0f3a4c2f
child 753 25a77484ec72
permissions -rw-r--r--
moved scroll functions from BranchObj to BranchItem
     1 #include "vymview.h"
     2 
     3 #include <iostream>
     4 using namespace std;
     5 
     6 #include "mainwindow.h"
     7 #include "mapeditor.h"
     8 
     9 extern Main *mainWindow;
    10 
    11 
    12 VymView::VymView(VymModel *m)
    13 {
    14 	model=m;
    15 
    16 	// Create TreeView
    17 	treeview=new QTreeView;
    18 	treeview->setModel ((QAbstractItemModel*)model);
    19 	treeview->setMinimumWidth (350);
    20 	treeview->setColumnWidth (0,350);
    21 
    22 	selModel=treeview->selectionModel();
    23 	model->setSelectionModel (selModel);
    24 	connect (
    25 		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    26 		this,SLOT (changeSelection(const QItemSelection &,const QItemSelection &)));
    27 
    28 	// Create good old MapEditor
    29 	MapEditor* me=model->getMapEditor();
    30 	if (!me) me=new MapEditor (model);
    31 	connect (
    32 		selModel, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    33 		me,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    34 	connect (
    35 		selModel, SIGNAL (currentChanged(const QModelIndex &, const QModelIndex &)), 
    36 		me,SLOT (updateCurrent(const QModelIndex &,const QModelIndex &)));
    37 
    38 	// VymModel may want to update selection or other data, e.g. during animation
    39 	connect (
    40 		model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    41 		me,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    42 	connect (
    43 		model, SIGNAL (newChildObject(QModelIndex) ),
    44 		this,SLOT (updateChilds (QModelIndex) ) );
    45 	connect (
    46 		model, SIGNAL (contentHasChanged(QModelIndex) ),
    47 		mainWindow, SLOT (updateContent(QModelIndex) ) );
    48 		
    49 
    50 	//me->viewport()->setFocus();	//FIXME-3 needed?
    51 	me->setAntiAlias (mainWindow->isAliased());
    52 	me->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
    53 
    54 	addWidget (treeview);
    55 	addWidget (me);
    56 
    57 	// Set geometry
    58 	QList <int> sizes;
    59 	sizes.append (120);
    60 	sizes.append (600);
    61 	setSizes (sizes);
    62 }
    63 
    64 QItemSelectionModel* VymView::selectionModel() 
    65 {
    66 	if (treeview) 
    67 		return selModel;
    68 	else 
    69 		std::cout <<"VymView::selectionModel: hey, no treeview so far???\n";
    70 	return NULL;
    71 }
    72 
    73 
    74 void VymView::updateChilds (QModelIndex ix)
    75 {
    76 	treeview->setExpanded (ix,true);
    77 }
    78 
    79 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
    80 {
    81 	/*
    82 	cout <<"VymView::changeSelection (";
    83 	if (!newsel.indexes().isEmpty() )
    84 		cout << model->getItem(newsel.indexes().first() )->getHeading().toStdString();
    85 	cout << " <- ";
    86 	if (!oldsel.indexes().isEmpty() )
    87 		cout << model->getItem(oldsel.indexes().first() )->getHeading().toStdString();
    88 	cout << ")\n";
    89 	*/
    90 
    91 	// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
    92 	mainWindow->changeSelection (model,newsel,oldsel);	// FIXME-3 maybe connect VymModel <-> MainWindow directly?
    93 }
    94