vymview.cpp
author insilmaril
Wed, 13 May 2009 08:26:27 +0000
changeset 767 6d2b32f305f9
parent 763 8c028a5d9083
child 769 a6931cd6309a
permissions -rw-r--r--
Started to use QtKinetic for Animation
     1 #include "vymview.h"
     2 
     3 #include <iostream>
     4 using namespace std;
     5 
     6 #include "linkablemapobj.h"
     7 #include "mainwindow.h"
     8 #include "mapeditor.h"
     9 
    10 extern Main *mainWindow;
    11 
    12 
    13 VymView::VymView(VymModel *m)
    14 {
    15 	model=m;
    16 
    17 	// Create TreeView
    18 	treeview=new QTreeView;
    19 	treeview->setModel ((QAbstractItemModel*)model);
    20 	//treeview->setMinimumWidth (50);
    21 
    22 	treeview->setColumnWidth (0,350);
    23 
    24 	selModel=treeview->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 (currentChanged(const QModelIndex &, const QModelIndex &)), 
    39 		me,SLOT (updateCurrent(const QModelIndex &,const QModelIndex &)));
    40 		*/
    41 		/*
    42 */
    43 	connect (
    44 		model, SIGNAL (dataChanged(const QModelIndex &, const QModelIndex &)), 
    45 		mapEditor,SLOT (updateData(const QModelIndex &) ) );
    46 
    47 	// VymModel may want to update selection or other data, e.g. during animation
    48 	connect (
    49 		model, SIGNAL (selectionChanged(const QItemSelection &, const QItemSelection &)), 
    50 		mapEditor,SLOT (updateSelection(const QItemSelection &,const QItemSelection &)));
    51 
    52 	connect (
    53 		model, SIGNAL (noteHasChanged(QModelIndex) ),
    54 		mainWindow, SLOT (updateNoteEditor (QModelIndex) ) );
    55 		
    56 	connect (
    57 		model, SIGNAL (expandAll() ),
    58 		this, SLOT (expandAll () ) );
    59 		
    60 	connect (
    61 		model, SIGNAL (showSelection() ),
    62 		this, SLOT (showSelection() ) );
    63 		
    64 
    65 	//mapEditor->viewport()->setFocus();	//FIXmapEditor-3 needed?
    66 	mapEditor->setAntiAlias (mainWindow->isAliased());
    67 	mapEditor->setSmoothPixmap(mainWindow->hasSmoothPixmapTransform());
    68 
    69 	addWidget (treeview);
    70 	addWidget (mapEditor);
    71 
    72 	// Set geometry
    73 	QList <int> widths;
    74 	widths<<120;
    75 	widths<<600;
    76 	setSizes(widths);
    77 }
    78 
    79 QItemSelectionModel* VymView::selectionModel() 
    80 {
    81 	if (treeview) 
    82 		return selModel;
    83 	else 
    84 		std::cout <<"VymView::selectionModel: hey, no treeview so far???\n";
    85 	return NULL;
    86 }
    87 
    88 void VymView::changeSelection (const QItemSelection &newsel, const QItemSelection &oldsel)
    89 {
    90 	/*
    91 	cout <<"VymView::changeSelection (";
    92 	if (!newsel.indexes().isEmpty() )
    93 		cout << model->getItem(newsel.indexes().first() )->getHeading().toStdString();
    94 	cout << " <- ";
    95 	if (!oldsel.indexes().isEmpty() )
    96 		cout << model->getItem(oldsel.indexes().first() )->getHeading().toStdString();
    97 	cout << ")\n";
    98 	*/
    99 
   100 	// Notify mainwindow to update satellites like NoteEditor, if needed (model==currenModel...)
   101 	mainWindow->changeSelection (model,newsel,oldsel);	// FIXME-3 maybe connect VymModel <-> MainWindow directly?
   102 	showSelection();
   103 }
   104 
   105 void VymView::expandAll()
   106 {
   107 	treeview->expandAll();
   108 }
   109 
   110 void VymView::showSelection()
   111 {
   112 	treeview->scrollTo(
   113 		model->getSelectedIndex(), 
   114 		//QAbstractItemView::PositionAtCenter   
   115 		QAbstractItemView::EnsureVisible
   116 	);
   117 
   118 	LinkableMapObj* lmo=model->getSelectedLMO();
   119 	if (lmo) 
   120 		mapEditor->setScrollBarPosTarget (lmo->getBBox() );
   121 }
   122