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