00001 /*************************************************************************** 00002 * Copyright (c) 2010 Werner Mayer <wmayer[at]users.sourceforge.net> * 00003 * * 00004 * This file is part of the FreeCAD CAx development system. * 00005 * * 00006 * This library is free software; you can redistribute it and/or * 00007 * modify it under the terms of the GNU Library General Public * 00008 * License as published by the Free Software Foundation; either * 00009 * version 2 of the License, or (at your option) any later version. * 00010 * * 00011 * This library is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00014 * GNU Library General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Library General Public * 00017 * License along with this library; see the file COPYING.LIB. If not, * 00018 * write to the Free Software Foundation, Inc., 59 Temple Place, * 00019 * Suite 330, Boston, MA 02111-1307, USA * 00020 * * 00021 ***************************************************************************/ 00022 00023 00024 #include "PreCompiled.h" 00025 #ifndef _PreComp_ 00026 # include <QMouseEvent> 00027 #endif 00028 00029 #include "TreeView.h" 00030 #include "DocumentModel.h" 00031 #include "Application.h" 00032 #include "Document.h" 00033 #include "MDIView.h" 00034 #include "MainWindow.h" 00035 #include "ViewProvider.h" 00036 00037 using namespace Gui; 00038 00039 TreeView::TreeView(QWidget* parent) 00040 : QTreeView(parent) 00041 { 00042 setModel(new DocumentModel(this)); 00043 QModelIndex root = this->model()->index(0,0,QModelIndex()); 00044 this->setExpanded(root, true); 00045 this->setDragEnabled(true); 00046 this->setAcceptDrops(true); 00047 this->setDropIndicatorShown(false); 00048 this->setRootIsDecorated(false); 00049 this->setSelectionMode(QAbstractItemView::ExtendedSelection); 00050 #if QT_VERSION >= 0x040200 00051 // causes unexpected drop events (possibly only with Qt4.1.x) 00052 this->setMouseTracking(true); // needed for itemEntered() to work 00053 #endif 00054 } 00055 00056 TreeView::~TreeView() 00057 { 00058 } 00059 00060 void TreeView::mouseDoubleClickEvent (QMouseEvent * event) 00061 { 00062 QModelIndex index = indexAt(event->pos()); 00063 if (!index.isValid() || index.internalPointer() == Application::Instance) 00064 return; 00065 Base::BaseClass* item = 0; 00066 item = static_cast<Base::BaseClass*>(index.internalPointer()); 00067 if (item->getTypeId() == Document::getClassTypeId()) { 00068 QTreeView::mouseDoubleClickEvent(event); 00069 const Gui::Document* doc = static_cast<Gui::Document*>(item); 00070 MDIView *view = doc->getActiveView(); 00071 if (!view) return; 00072 getMainWindow()->setActiveWindow(view); 00073 } 00074 else if (item->getTypeId().isDerivedFrom(ViewProvider::getClassTypeId())) { 00075 if (static_cast<ViewProvider*>(item)->doubleClicked() == false) 00076 QTreeView::mouseDoubleClickEvent(event); 00077 } 00078 } 00079 00080 void TreeView::rowsInserted (const QModelIndex & parent, int start, int end) 00081 { 00082 QTreeView::rowsInserted(parent, start, end); 00083 if (parent.isValid()) { 00084 Base::BaseClass* ptr = static_cast<Base::BaseClass*>(parent.internalPointer()); 00085 // type is defined in DocumentModel.cpp 00086 if (ptr->getTypeId() == Base::Type::fromName("Gui::ApplicationIndex")) { 00087 for (int i=start; i<=end;i++) { 00088 QModelIndex document = this->model()->index(i, 0, parent); 00089 this->expand(document); 00090 } 00091 } 00092 } 00093 } 00094 00095 #include "moc_TreeView.cpp" 00096