File indexing completed on 2023-10-01 04:14:08

0001 /***************************************************************************
0002                                cmaptoolbase.cpp
0003                              -------------------
0004     begin                : Tue May 1 2001
0005     copyright            : (C) 2001 by Kmud Developer Team
0006     email                : kmud-devel@kmud.de
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 
0018 #include "cmaptoolbase.h"
0019 
0020 #include "cmapmanager.h"
0021 #include "cmapview.h"
0022 
0023 #include <kstandarddirs.h>
0024 #include <qactiongroup.h>
0025 #include <kactioncollection.h>
0026 
0027 /** The construtor for the tool */
0028 CMapToolBase::CMapToolBase(KActionCollection *actionCollection,QString description,QIcon icon,CMapManager *manager,QString actionName,QActionGroup *group)
0029 {
0030   mapManager = manager;
0031 
0032   action = new KToggleAction (this);
0033   action->setText (description);
0034   action->setIcon (icon);
0035   connect (action, SIGNAL (triggered (bool)), this, SLOT (slotActionSelected ()));
0036   if (!group) group = manager->getActiveView()->toolGroup();
0037   group->addAction (action);
0038   actionCollection->addAction (actionName, action);
0039 }
0040 
0041 CMapToolBase::~CMapToolBase()
0042 {
0043 }
0044 
0045 /** Used to tell the tool were to find the map manager */
0046 void CMapToolBase::setManager(CMapManager *manager)
0047 {
0048     mapManager = manager;
0049 }
0050 
0051 /** Used to set the checked state of the tool */
0052 void CMapToolBase::setChecked(bool checked)
0053 {
0054     action->setChecked(checked);
0055 }
0056 
0057 /** This is called when the tool button is clicked */
0058 void CMapToolBase::slotActionSelected()
0059 {
0060     if (action->isChecked())
0061     {
0062         emit actionSelected(this);
0063         mapManager->setCurrentTool(this);
0064     }
0065 }
0066 
0067 /** Used to set the whats this text for the tool */
0068 void CMapToolBase::setWhatsThis(QString text)
0069 {
0070     action->setWhatsThis(text);
0071 }
0072 
0073 /** Used to set the toop tip of the tool */
0074 void CMapToolBase::setToolTip(QString tip)
0075 {
0076     action->setToolTip(tip);
0077 }
0078 
0079 void CMapToolBase::plug (QWidget *w)
0080 {
0081     w->addAction(action);
0082 }
0083 
0084 #include "moc_cmaptoolbase.cpp"