Gui/TaskView/TaskWatcher.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2009 Jürgen Riegel <juergen.riegel@web.de>              *
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 
00026 #ifndef _PreComp_
00027 #  include <QPixmap>
00028 #endif
00029 
00030 
00031 #include <QObject>
00032 #include <App/Application.h>
00033 #include <App/Document.h>
00034 #include <Gui/Application.h>
00035 #include <Gui/Command.h>
00036 #include <Gui/BitmapFactory.h>
00037 #include <Gui/TaskView/TaskView.h>
00038 #include <Gui/Action.h>
00039 
00040 #include "TaskWatcher.h"
00041 
00042 
00043 using namespace Gui::TaskView;
00044 
00045 
00046 //**************************************************************************
00047 //**************************************************************************
00048 // TaskWatcher
00049 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00050 
00051 TaskWatcher::TaskWatcher(const char* Filter)
00052     : QObject(0),SelectionFilter(Filter)
00053 {
00054     
00055 }
00056 
00057 TaskWatcher::~TaskWatcher()
00058 {
00059     for (std::vector<QWidget*>::iterator it=Content.begin();it!=Content.end();++it){
00060         delete(*it);
00061         *it = 0;
00062     }
00063 
00064 }
00065 
00066 //==== implementer ===========================================================================
00067 
00068 std::vector<QWidget*> &TaskWatcher::getWatcherContent(void)
00069 {
00070     return Content;
00071 }
00072 
00073 //==== calls from the TaskView ===============================================================
00074 
00075 bool TaskWatcher::shouldShow()
00076 {
00077     return false;
00078 }
00079 
00080 //**************************************************************************
00081 //**************************************************************************
00082 // TaskWatcherCommands
00083 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00084 
00085 TaskWatcherCommands::TaskWatcherCommands(const char* Filter,const char* commands[],
00086                                          const char* name, const char* pixmap)
00087     : TaskWatcher(Filter)
00088 {
00089     CommandManager &mgr = Gui::Application::Instance->commandManager();
00090     Gui::TaskView::TaskBox *tb = new Gui::TaskView::TaskBox
00091         (BitmapFactory().pixmap(pixmap), trUtf8(name), true, 0);
00092 
00093     for (const char** i=commands;*i;i++) {
00094         if(!i) break;
00095         Command *c = mgr.getCommandByName(*i);
00096         if (c) {
00097             // handled in TaskBox::actionEvent()
00098             c->addTo(tb);
00099         }
00100     }
00101 
00102     Content.push_back(tb);
00103 }
00104 
00105 TaskWatcherCommands::~TaskWatcherCommands()
00106 {
00107 }
00108 
00109 //==== implementer ===========================================================================
00110 
00111 
00112 //==== calls from the TaskView ===============================================================
00113 
00114 bool TaskWatcherCommands::shouldShow()
00115 {
00116     return match();
00117 }
00118 
00119 //**************************************************************************
00120 //**************************************************************************
00121 // TaskWatcherCommandsEmptyDoc
00122 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00123 
00124 TaskWatcherCommandsEmptyDoc::TaskWatcherCommandsEmptyDoc(const char* commands[],
00125                                                          const char* name,
00126                                                          const char* pixmap )
00127     : TaskWatcherCommands(0,commands,name,pixmap)
00128 {
00129 }
00130 
00131 TaskWatcherCommandsEmptyDoc::~TaskWatcherCommandsEmptyDoc()
00132 {
00133 }
00134 
00135 //==== implementer ===========================================================================
00136 
00137 
00138 //==== calls from the TaskView ===============================================================
00139 
00140 bool TaskWatcherCommandsEmptyDoc::shouldShow()
00141 {
00142     App::Document* doc = App::GetApplication().getActiveDocument();
00143     return doc && doc->countObjects() == 0;
00144 }
00145 
00146 
00147 #include "moc_TaskWatcher.cpp"

Generated on Wed Nov 23 19:00:44 2011 for FreeCAD by  doxygen 1.6.1