File indexing completed on 2024-04-21 04:03:10

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 <QActionGroup>
0024 #include <kactioncollection.h>
0025 
0026 /** The construtor for the tool */
0027 CMapToolBase::CMapToolBase(KActionCollection *actionCollection,QString description,QIcon icon,CMapManager *manager,QString actionName,QActionGroup *group)
0028 {
0029   mapManager = manager;
0030 
0031   action = new KToggleAction (this);
0032   action->setText (description);
0033   action->setIcon (icon);
0034   connect (action, SIGNAL (triggered (bool)), this, SLOT (slotActionSelected ()));
0035   if (!group) group = manager->getActiveView()->toolGroup();
0036   group->addAction (action);
0037   actionCollection->addAction (actionName, action);
0038 }
0039 
0040 CMapToolBase::~CMapToolBase()
0041 {
0042 }
0043 
0044 /** Used to tell the tool were to find the map manager */
0045 void CMapToolBase::setManager(CMapManager *manager)
0046 {
0047     mapManager = manager;
0048 }
0049 
0050 /** Used to set the checked state of the tool */
0051 void CMapToolBase::setChecked(bool checked)
0052 {
0053     action->setChecked(checked);
0054 }
0055 
0056 /** This is called when the tool button is clicked */
0057 void CMapToolBase::slotActionSelected()
0058 {
0059     if (action->isChecked())
0060     {
0061         emit actionSelected(this);
0062         mapManager->setCurrentTool(this);
0063     }
0064 }
0065 
0066 /** Used to set the whats this text for the tool */
0067 void CMapToolBase::setWhatsThis(QString text)
0068 {
0069     action->setWhatsThis(text);
0070 }
0071 
0072 /** Used to set the toop tip of the tool */
0073 void CMapToolBase::setToolTip(QString tip)
0074 {
0075     action->setToolTip(tip);
0076 }
0077 
0078 void CMapToolBase::plug (QWidget *w)
0079 {
0080     w->addAction(action);
0081 }
0082 
0083 #include "moc_cmaptoolbase.cpp"