DlgCustomizeSpaceball.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2011 Thomas Anderson <ta@nextgenengineering>            *
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 #include "PreCompiled.h"
00024 
00025 #ifndef _PreComp_
00026 #include <QHBoxLayout>
00027 #include <QVBoxLayout>
00028 #include <QLabel>
00029 #include <QSplitter>
00030 #include <QPushButton>
00031 #include <QHeaderView>
00032 #include <QPrintDialog>
00033 #include <QPrinter>
00034 #include <QPainter>
00035 #include <QTableView>
00036 #endif
00037 
00038 #include "Base/Console.h"
00039 #include "Application.h"
00040 #include "GuiApplicationNativeEventAware.h"
00041 #include "SpaceballEvent.h"
00042 #include "Command.h"
00043 #include "BitmapFactory.h"
00044 #include "DlgCustomizeSpaceball.h"
00045 
00046 typedef std::vector<Base::Reference<ParameterGrp> > GroupVector;
00047 
00048 using namespace Gui::Dialog;
00049 
00050 ButtonView::ButtonView(QWidget *parent) : QListView(parent)
00051 {
00052 
00053 }
00054 
00055 void ButtonView::selectButton(int number)
00056 {
00057     this->selectionModel()->select(this->model()->index(number, 0), QItemSelectionModel::ClearAndSelect);
00058 }
00059 
00060 void ButtonView::goSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
00061 {
00062     if (selected.indexes().isEmpty())
00063         return;
00064     QModelIndex select(selected.indexes().at(0));
00065     changeCommandSelection(this->model()->data(select, Qt::UserRole).toString());
00066 }
00067 
00068 void ButtonView::goChangedCommand(const QString& commandName)
00069 {
00070     QModelIndex index(this->currentIndex());
00071     ButtonModel *model = dynamic_cast<ButtonModel*>(this->model());
00072     if (model && index.isValid())
00073         model->setCommand(index.row(), commandName);
00074 }
00075 
00077 
00078 ButtonModel::ButtonModel(QObject *parent) : QAbstractListModel(parent)
00079 {
00080 
00081 }
00082 
00083 int ButtonModel::rowCount (const QModelIndex &parent) const
00084 {
00085     return spaceballButtonGroup()->GetGroups().size();
00086 }
00087 
00088 QVariant ButtonModel::data (const QModelIndex &index, int role) const
00089 {
00090     GroupVector groupVector = spaceballButtonGroup()->GetGroups();
00091     if (index.row() >= (int)groupVector.size())
00092     {
00093         Base::Console().Log("index error in ButtonModel::data\n");
00094         return QVariant();
00095     }
00096     if (role == Qt::DisplayRole)
00097         return QVariant(getLabel(index.row()));
00098     if (role == Qt::DecorationRole)
00099     {
00100         static QPixmap icon(BitmapFactory().pixmap("spaceball_button").scaled
00101                             (32, 32, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
00102         return QVariant(icon);
00103     }
00104     if (role == Qt::UserRole)
00105         return QVariant(QString::fromStdString(groupVector.at(index.row())->GetASCII("Command")));
00106     if (role == Qt::SizeHintRole)
00107         return QVariant(QSize(32, 32));
00108     return QVariant();
00109 }
00110 
00111 void ButtonModel::insertRows(int number)
00112 {
00113     int buttonCount = spaceballButtonGroup()->GetGroups().size();
00114     beginInsertRows(QModelIndex(), buttonCount, number-buttonCount+1);
00115     for (int index = buttonCount; index < number + 1; ++index)
00116     {
00117         QString groupName;
00118         groupName.setNum(index);
00119         Base::Reference<ParameterGrp> newGroup = spaceballButtonGroup()->GetGroup(groupName.toAscii());//builds the group.
00120         newGroup->SetASCII("Command", "");
00121     }
00122     endInsertRows();
00123     return;
00124 }
00125 
00126 void ButtonModel::setCommand(int row, QString command)
00127 {
00128     GroupVector groupVector = spaceballButtonGroup()->GetGroups();
00129     groupVector.at(row)->SetASCII("Command", command.toAscii());
00130 }
00131 
00132 void ButtonModel::goButtonPress(int number)
00133 {
00134     QString numberString;
00135     numberString.setNum(number);
00136     if (!spaceballButtonGroup()->HasGroup(numberString.toAscii()))
00137         insertRows(number);
00138 }
00139 
00140 void ButtonModel::goMacroRemoved(const QByteArray& macroName)
00141 {
00142     GroupVector groupVector = spaceballButtonGroup()->GetGroups();
00143     for (GroupVector::iterator it = groupVector.begin(); it != groupVector.end(); ++it)
00144         if (std::string(macroName.data()) == (*it)->GetASCII("Command"))
00145             (*it)->SetASCII("Command", "");
00146 }
00147 
00148 void ButtonModel::goClear()
00149 {
00150     if (this->rowCount() < 1)
00151         return;
00152     this->beginRemoveRows(QModelIndex(), 0, this->rowCount()-1);
00153     spaceballButtonGroup()->Clear();
00154     this->endRemoveRows();
00155 }
00156 
00157 ParameterGrp::handle ButtonModel::spaceballButtonGroup() const
00158 {
00159     static ParameterGrp::handle group = App::GetApplication().GetUserParameter().GetGroup("BaseApp")->
00160             GetGroup("Spaceball")->GetGroup("Buttons");
00161     return group;
00162 }
00163 
00164 QString ButtonModel::getLabel(const int &number) const
00165 {
00166     if (number > -1 && number < 20)
00167         return tr("Button %1").arg(number+1);
00168     else
00169         return tr("Out Of Range");
00170 }
00171 
00173 
00174 CommandView::CommandView(QWidget *parent) : QTreeView(parent)
00175 {
00176     this->setEnabled(false);
00177     connect(this, SIGNAL(clicked(const QModelIndex&)),
00178             this, SLOT(goClicked(const QModelIndex&)));
00179 }
00180 
00181 void CommandView::goChangeCommandSelection(const QString& commandName)
00182 {
00183     if (!this->isEnabled())
00184         this->setEnabled(true);
00185     this->selectionModel()->clear();
00186     this->collapseAll();
00187     if (commandName.isEmpty())
00188         return;
00189     QModelIndexList index(this->model()->match(this->model()->index(0,0), Qt::UserRole, QVariant(commandName), 1,
00190                                                Qt::MatchWrap | Qt::MatchRecursive));
00191     if (index.size() < 1)
00192         return;
00193     this->expand(index.at(0));
00194     this->setCurrentIndex(index.at(0));
00195 }
00196 
00197 void CommandView::goClicked(const QModelIndex &index)
00198 {
00199     if (index.flags() & Qt::ItemIsSelectable)
00200     {
00201         QString commandName = this->model()->data(index, Qt::UserRole).toString();
00202         if (commandName.isEmpty())
00203             return;
00204         changedCommand(commandName);
00205     }
00206 }
00207 
00209 
00210 CommandNode::CommandNode(NodeType typeIn)
00211 {
00212     nodeType = typeIn;
00213     parent = 0;
00214     children.clear();
00215     aCommand = 0;
00216 }
00217 
00218 CommandNode::~CommandNode()
00219 {
00220     qDeleteAll(children);
00221 }
00222 
00224 
00225 CommandModel::CommandModel(QObject *parent) : QAbstractItemModel(parent)
00226 {
00227     rootNode = 0;
00228     initialize();
00229 }
00230 
00231 CommandModel::~CommandModel()
00232 {
00233     delete rootNode;
00234     rootNode = 0;
00235 }
00236 
00237 QModelIndex CommandModel::index(int row, int column, const QModelIndex &parent) const
00238 {
00239     if (!rootNode)
00240         return QModelIndex();
00241     if (!parent.isValid())
00242         return createIndex(row, column, rootNode->children.at(row));
00243 
00244     CommandNode *parentNode = nodeFromIndex(parent);
00245     if (!parentNode)
00246         return QModelIndex();
00247     return createIndex(row, column, parentNode->children.at(row));
00248 }
00249 
00250 QModelIndex CommandModel::parent(const QModelIndex &index) const
00251 {
00252     CommandNode *base = nodeFromIndex(index);
00253     if (!base)
00254         return QModelIndex();
00255     CommandNode *parentNode = base->parent;
00256     if (!parentNode)
00257         return QModelIndex();
00258     CommandNode *grandParentNode = parentNode->parent;
00259     if (!grandParentNode)
00260         return QModelIndex();
00261 
00262     int row = grandParentNode->children.indexOf(parentNode);
00263     if (row == -1)
00264         return QModelIndex();
00265     return createIndex(row, index.column(), parentNode);
00266 }
00267 
00268 int CommandModel::rowCount(const QModelIndex &parent) const
00269 {
00270     if (!parent.isValid())
00271         return rootNode->children.size();
00272 
00273     CommandNode *parentNode = nodeFromIndex(parent);
00274     if (!parentNode)
00275         return 0;
00276     return parentNode->children.count();
00277 }
00278 
00279 int CommandModel::columnCount(const QModelIndex &parent) const
00280 {
00281     return 1;
00282 }
00283 
00284 QVariant CommandModel::data(const QModelIndex &index, int role) const
00285 {
00286     CommandNode *node = nodeFromIndex(index);
00287     if (!node)
00288         return QVariant();
00289     if (role == Qt::DisplayRole)
00290     {
00291         if (node->nodeType == CommandNode::CommandType)
00292             return QVariant(qApp->translate(node->aCommand->className(), node->aCommand->getMenuText()));
00293         if (node->nodeType == CommandNode::GroupType)
00294         {
00295             if (node->children.size() < 1)
00296                 return QVariant();
00297             CommandNode *childNode = node->children.at(0);
00298             return QVariant(qApp->translate(childNode->aCommand->className(), childNode->aCommand->getGroupName()));
00299         }
00300         return QVariant();
00301     }
00302     if (role == Qt::DecorationRole)
00303     {
00304         if (node->nodeType == CommandNode::CommandType)
00305         {
00306             if (node->aCommand->getPixmap())
00307                 return QVariant(BitmapFactory().pixmap(node->aCommand->getPixmap()).scaled
00308                                 (32, 32, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
00309         }
00310     }
00311     if (role == Qt::SizeHintRole)
00312         if (node->nodeType == CommandNode::CommandType)
00313             return QVariant(QSize(32, 32));
00314     if (role == Qt::UserRole)
00315     {
00316         if (node->nodeType == CommandNode::CommandType)
00317             return QVariant(QString::fromAscii(node->aCommand->getName()));
00318         if (node->nodeType == CommandNode::GroupType)
00319         {
00320             if (node->children.size() < 1)
00321                 return QVariant();
00322             CommandNode *childNode = node->children.at(0);
00323             return QVariant(QString::fromAscii(childNode->aCommand->getGroupName()));
00324         }
00325         return QVariant();
00326     }
00327     if (role == Qt::ToolTipRole)
00328         if (node->nodeType == CommandNode::CommandType)
00329             return QVariant(QString::fromAscii(node->aCommand->getToolTipText()));
00330     return QVariant();
00331 }
00332 
00333 QVariant CommandModel::headerData(int section, Qt::Orientation orientation, int role) const
00334 {
00335     if (role == Qt::DisplayRole && orientation == Qt::Horizontal && section == 0)
00336         return QVariant(tr("Commands"));
00337     return QVariant();
00338 }
00339 
00340 Qt::ItemFlags CommandModel::flags (const QModelIndex &index) const
00341 {
00342     if (!index.isValid())
00343         return Qt::NoItemFlags;
00344     CommandNode *node = nodeFromIndex(index);
00345     if (!node)
00346         return Qt::NoItemFlags;
00347     if (node->nodeType == CommandNode::CommandType)
00348         return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
00349     return Qt::NoItemFlags;
00350 }
00351 
00352 CommandNode* CommandModel::nodeFromIndex(const QModelIndex &index) const
00353 {
00354     if (index.isValid())
00355         return static_cast<CommandNode *>(index.internalPointer());
00356     return rootNode;
00357 }
00358 
00359 void CommandModel::goAddMacro(const QByteArray &macroName)
00360 {
00361     QModelIndexList indexList(this->match(this->index(0,0), Qt::UserRole, QVariant(QString::fromAscii("Macros")),
00362                                           1, Qt::MatchWrap | Qt::MatchRecursive));
00363     QModelIndex macrosIndex;
00364     if (indexList.size() < 1)
00365     {
00366         //this is the first macro and we have to add the Macros item.
00367         //figure out where to insert it. Should be in the command groups now.
00368         QStringList groups = orderedGroups();
00369         int location(groups.indexOf(QString::fromAscii("Macros")));
00370         if (location == -1)
00371             location = groups.size();
00372         //add row
00373         this->beginInsertRows(QModelIndex(), location, location);
00374         CommandNode *macroNode = new CommandNode(CommandNode::GroupType);
00375         macroNode->parent = rootNode;
00376         rootNode->children.insert(location, macroNode);
00377         this->endInsertRows();
00378         macrosIndex = this->index(location, 0);
00379     }
00380     else
00381         macrosIndex = indexList.at(0);
00382 
00383     Command *command = 0;
00384     command = Application::Instance->commandManager().getCommandByName(macroName);
00385     if (!command)
00386         return;
00387 
00388     CommandNode *parentNode = nodeFromIndex(macrosIndex);
00389     if (!parentNode)
00390         return;
00391 
00392     this->beginInsertRows(macrosIndex, parentNode->children.size(), parentNode->children.size());
00393     CommandNode *childNode = new CommandNode(CommandNode::CommandType);
00394     childNode->parent = parentNode;
00395     parentNode->children.push_back(childNode);
00396     childNode->aCommand = command;
00397     this->endInsertRows();
00398 }
00399 
00400 void CommandModel::goRemoveMacro(const QByteArray &macroName)
00401 {
00402     QModelIndexList macroList(this->match(this->index(0,0), Qt::UserRole, QVariant(QString::fromAscii(macroName.data())),
00403                                           1, Qt::MatchWrap | Qt::MatchRecursive));
00404     if (macroList.isEmpty())
00405         return;
00406 
00407     QModelIndex childIndex(macroList.at(0));
00408     QModelIndex parentIndex(this->parent(childIndex));
00409     if (!childIndex.isValid() || !parentIndex.isValid())
00410         return;
00411 
00412     CommandNode *parentNode = nodeFromIndex(parentIndex);
00413     if (!parentNode)
00414         return;
00415 
00416     this->beginRemoveRows(parentIndex, childIndex.row(), childIndex.row());
00417     delete parentNode->children.takeAt(childIndex.row());
00418     this->endRemoveRows();
00419     if (parentNode->children.isEmpty())
00420     {
00421         QModelIndex grandParentIndex(this->parent(parentIndex));//this should be root.
00422         CommandNode *grandParentNode = nodeFromIndex(grandParentIndex);
00423         this->beginRemoveRows(grandParentIndex, parentIndex.row(), parentIndex.row());
00424         delete grandParentNode->children.takeAt(parentIndex.row());
00425         this->endRemoveRows();
00426     }
00427 }
00428 
00429 void CommandModel::initialize()
00430 {
00431     rootNode = new CommandNode(CommandNode::RootType);
00432     QStringList groups(orderedGroups());
00433     for (QStringList::iterator it = groups.begin(); it != groups.end(); ++it)
00434         groupCommands(*it);
00435 }
00436 
00437 void CommandModel::groupCommands(const QString& groupName)
00438 {
00439     CommandNode *parentNode = new CommandNode(CommandNode::GroupType);
00440     parentNode->parent = rootNode;
00441     rootNode->children.push_back(parentNode);
00442     std::vector <Command*> commands = Application::Instance->commandManager().getGroupCommands(groupName.toAscii());
00443     for (std::vector <Command*>::iterator it = commands.begin(); it != commands.end(); ++it)
00444     {
00445         CommandNode *childNode = new CommandNode(CommandNode::CommandType);
00446         childNode->parent = parentNode;
00447         parentNode->children.push_back(childNode);
00448         childNode->aCommand = *it;
00449     }
00450 }
00451 
00452 QStringList CommandModel::orderedGroups()
00453 {
00454     QStringList groups;
00455     std::vector <Command*> commands = Application::Instance->commandManager().getAllCommands();
00456     for (std::vector <Command*>::iterator it = commands.begin(); it != commands.end(); ++it)
00457     {
00458         QString groupName(QString::fromAscii((*it)->getGroupName()));
00459         if (!groups.contains(groupName))
00460             groups << groupName;
00461     }
00462     //how to sort?
00463     groups.sort();
00464     return groups;
00465 }
00466 
00468 
00469 PrintModel::PrintModel(QObject *parent, ButtonModel *buttonModelIn, CommandModel *commandModelIn) : QAbstractTableModel(parent)
00470 {
00471     buttonModel = buttonModelIn;
00472     commandModel = commandModelIn;
00473 }
00474 
00475 int PrintModel::rowCount(const QModelIndex &parent) const
00476 {
00477     return buttonModel->rowCount();
00478 }
00479 
00480 int PrintModel::columnCount(const QModelIndex &parent) const
00481 {
00482     return 2;
00483 }
00484 
00485 QVariant PrintModel::data(const QModelIndex &index, int role) const
00486 {
00487     if (index.column() == 0)
00488     {
00489         //button column;
00490         return buttonModel->data(buttonModel->index(index.row(), 0), role);
00491     }
00492 
00493     if (index.column() == 1)
00494     {
00495         //command column;
00496         QString commandName(buttonModel->data(buttonModel->index(index.row(), 0), Qt::UserRole).toString());
00497         if (commandName.isEmpty())
00498             return (QVariant());
00499 
00500         QModelIndexList indexList(commandModel->match(commandModel->index(0,0), Qt::UserRole, QVariant(commandName), 1,
00501                                                    Qt::MatchWrap | Qt::MatchRecursive));
00502         if (indexList.isEmpty())
00503             return QVariant();
00504 
00505         return commandModel->data(indexList.at(0), role);
00506     }
00507     return QVariant();
00508 }
00509 
00510 QVariant PrintModel::headerData(int section, Qt::Orientation orientation, int role) const
00511 {
00512     if (role != Qt::DisplayRole || orientation != Qt::Horizontal)
00513         return QVariant();
00514     if (section == 0)
00515         return QVariant(tr("Button"));
00516     if (section == 1)
00517         return QVariant(tr("Command"));
00518     else
00519         return QVariant();
00520 }
00521 
00523 
00524 DlgCustomizeSpaceball::DlgCustomizeSpaceball(QWidget *parent)
00525   : CustomizeActionPage(parent), buttonView(0), buttonModel(0),
00526     commandView(0), commandModel(0), clearButton(0), printReference(0)
00527 {
00528     this->setWindowTitle(tr("Spaceball"));
00529     GUIApplicationNativeEventAware *app = qobject_cast<GUIApplicationNativeEventAware *>(QApplication::instance());
00530     if (!app)
00531         return;
00532     if (!app->isSpaceballPresent())
00533     {
00534         this->setMessage(tr("No Spaceball Present"));
00535         return;
00536     }
00537 
00538     setupButtonModelView();
00539     setupCommandModelView();
00540     connect(buttonView, SIGNAL(changeCommandSelection(const QString&)),
00541             commandView, SLOT(goChangeCommandSelection(const QString&)));
00542     connect(commandView, SIGNAL(changedCommand(const QString&)),
00543             buttonView, SLOT(goChangedCommand(const QString&)));
00544     setupLayout();
00545     connect(clearButton, SIGNAL(clicked()), this, SLOT(goClear()));
00546     connect(printReference, SIGNAL(clicked()), this, SLOT(goPrint()));
00547 }
00548 
00549 DlgCustomizeSpaceball::~DlgCustomizeSpaceball()
00550 {
00551 
00552 }
00553 
00554 void DlgCustomizeSpaceball::setMessage(const QString& message)
00555 {
00556     QLabel *messageLabel = new QLabel(message,this);
00557     QVBoxLayout *layout = new QVBoxLayout();
00558     layout->addWidget(messageLabel);
00559     this->setLayout(layout);
00560 }
00561 
00562 void DlgCustomizeSpaceball::setupButtonModelView()
00563 {
00564     buttonModel = new ButtonModel(this);
00565     buttonView = new ButtonView(this);
00566     buttonView->setModel(buttonModel);
00567 
00568     //had to do this here as the views default selection model is not created until after construction.
00569     connect(buttonView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
00570             buttonView, SLOT(goSelectionChanged(const QItemSelection&, const QItemSelection&)));
00571 }
00572 
00573 void DlgCustomizeSpaceball::setupCommandModelView()
00574 {
00575     commandModel = new CommandModel(this);
00576     commandView = new CommandView(this);
00577     commandView->setModel(commandModel);
00578 }
00579 
00580 void DlgCustomizeSpaceball::setupLayout()
00581 {
00582     QLabel *buttonLabel = new QLabel(tr("Buttons"), this);
00583     clearButton = new QPushButton(tr("Clear"), this);
00584     QVBoxLayout *buttonGroup = new QVBoxLayout();
00585     buttonGroup->addWidget(buttonLabel);
00586     buttonGroup->addWidget(buttonView);
00587     QHBoxLayout *clearLayout = new QHBoxLayout();
00588     clearLayout->addWidget(clearButton);
00589     clearLayout->addStretch();
00590     buttonGroup->addLayout(clearLayout);
00591 
00592     QSplitter *splitter = new QSplitter(this);
00593     QWidget *leftPane = new QWidget(this);
00594     leftPane->setLayout(buttonGroup);
00595     splitter->addWidget(leftPane);
00596     splitter->addWidget(commandView);
00597 
00598     printReference = new QPushButton(tr("Print Reference"), this);
00599     QHBoxLayout *printLayout = new QHBoxLayout();
00600     printLayout->addStretch();
00601     printLayout->addWidget(printReference);
00602 
00603     QVBoxLayout *layout = new QVBoxLayout();
00604     layout->addWidget(splitter);
00605     layout->addLayout(printLayout);
00606 
00607     this->setLayout(layout);
00608 
00609     QList<int> sizes;
00610     sizes << this->size().width()*0.40;
00611     sizes << this->size().width()-sizes.at(0);
00612     splitter->setSizes(sizes);
00613 }
00614 
00615 void DlgCustomizeSpaceball::goClear()
00616 {
00617     commandView->clearSelection();
00618     commandView->collapseAll();
00619     commandView->setDisabled(true);
00620     buttonModel->goClear();
00621 }
00622 
00623 void DlgCustomizeSpaceball::goPrint()
00624 {
00625     QTableView *view = new QTableView(this);
00626     PrintModel *model = new PrintModel(this, buttonModel, commandModel);
00627     view->horizontalHeader()->setResizeMode(QHeaderView::Fixed);
00628     view->setModel(model);
00629     view->horizontalHeader()->resizeSection(0, 150);
00630     view->horizontalHeader()->resizeSection(1, 300);
00631     view->resize(600, 600);
00632 
00633     QPrinter printer;
00634     QPrintDialog printDialog(&printer, this);
00635     if (printDialog.exec() == QDialog::Accepted)
00636     {
00637         QPainter p(&printer);
00638         view->render(&p);
00639     }
00640 }
00641 
00642 bool DlgCustomizeSpaceball::event(QEvent *event)
00643 {
00644     if (event->type() != Spaceball::ButtonEvent::ButtonEventType)
00645         return CustomizeActionPage::event(event);
00646     Spaceball::ButtonEvent *buttonEvent = dynamic_cast<Spaceball::ButtonEvent *>(event);
00647     if (!buttonEvent)
00648         return true;
00649     buttonEvent->setHandled(true);
00650     if (buttonEvent->buttonStatus() == Spaceball::BUTTON_PRESSED)
00651         buttonModel->goButtonPress(buttonEvent->buttonNumber());
00652     buttonView->selectButton(buttonEvent->buttonNumber());
00653 
00654     return true;
00655 }
00656 
00657 void DlgCustomizeSpaceball::hideEvent(QHideEvent *event)
00658 {
00659     //having a crash with the last item of the macro command list
00660     //being selected and that macro is removed from the macro tab. Hopefully
00661     //clearing the selection will cure the problem.
00662     if (buttonView)
00663         buttonView->selectionModel()->clear();
00664     if (commandView) {
00665         commandView->selectionModel()->clear();
00666         commandView->collapseAll();
00667         commandView->setEnabled(false);
00668     }
00669 
00670     CustomizeActionPage::hideEvent(event);
00671 }
00672 
00673 void DlgCustomizeSpaceball::showEvent (QShowEvent *event)
00674 {
00675     if (buttonView)
00676         buttonView->setFocus();
00677 
00678     CustomizeActionPage::showEvent(event);
00679 }
00680 
00681 void DlgCustomizeSpaceball::changeEvent(QEvent *e)
00682 {
00683     if (e->type() == QEvent::LanguageChange)
00684     {
00685         //I don't think I need do anything here. Qt should take care of it?
00686 //        this->setWindowTitle(tr("Spaceball"));
00687     }
00688     QWidget::changeEvent(e);
00689 }
00690 
00691 void DlgCustomizeSpaceball::onAddMacroAction(const QByteArray &macroName)
00692 {
00693     //need to get the new macro to model.
00694     if (commandModel)
00695         commandModel->goAddMacro(macroName);
00696 }
00697 
00698 void DlgCustomizeSpaceball::onRemoveMacroAction(const QByteArray &macroName)
00699 {
00700     //need to remove macro from model.
00701     if (commandModel)
00702         commandModel->goRemoveMacro(macroName);
00703     //need to change any button mapped to macro to an empty string.
00704     if (buttonModel)
00705         buttonModel->goMacroRemoved(macroName);
00706 }
00707 
00708 void DlgCustomizeSpaceball::onModifyMacroAction(const QByteArray &macroName)
00709 {
00710     //don't think I need to do anything here.
00711 }
00712 
00713 #include "moc_DlgCustomizeSpaceball.cpp"

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