viewModeChangeWidget.cc

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 7287 $                                                         *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-10-01 12:43:17 +0200 (Do, 01. Okt 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 #include "viewModeChangeWidget.hh"
00047 #include <OpenFlipper/widgets/coreWidget/CoreWidget.hh>
00048 #include <OpenFlipper/common/GlobalOptions.hh>
00049 
00050 #include <QInputDialog>
00051 #include <QMessageBox>
00052 
00054 viewModeChangeWidget::viewModeChangeWidget(const QVector< ViewMode* >& _modes, QWidget *_parent)
00055   : QDialog(_parent),
00056     modes_(_modes)
00057 {
00058   setupUi(this);
00059 
00060 
00061   connect(viewModeList, SIGNAL(clicked (QModelIndex)), this, SLOT(slotModeClicked(QModelIndex)) );
00062   
00063 
00064 }
00065 
00066 // =======================================================================================================
00067 // External communication
00068 // =======================================================================================================
00069 
00071 void viewModeChangeWidget::slotModeClicked(QModelIndex _idx ){
00072   
00073   // Search for current mode 
00074   int id = -1;
00075   if ( viewModeList->selectedItems().count() > 0) 
00076     for (int i=0; i < modes_.size(); i++)
00077       if (modes_[i]->name == viewModeList->currentItem()->text()){
00078         id = i;
00079         break;
00080       }
00081       
00082   if ( id == -1 ) {
00083     std::cerr << "Currently selected Mode not found?!" << std::endl; 
00084     return;
00085   }
00086 
00087   
00088   emit changeView(modes_[id]->name,modes_[id]->visibleToolboxes,modes_[id]->visibleToolbars);
00089   close();
00090 }
00091 
00092 
00094 void viewModeChangeWidget::show(QString _lastMode){
00095   QDialog::show();
00096   
00097   //fill viewModeList
00098   viewModeList->clear();
00099   for (int i=0; i < modes_.size(); i++){
00100     QListWidgetItem *item = new QListWidgetItem(viewModeList);
00101     item->setTextAlignment(Qt::AlignHCenter);
00102     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
00103     
00104     QFile iconFile( OpenFlipper::Options::iconDirStr() + QDir::separator () + modes_[i]->icon  );
00105     
00106     if ( iconFile.exists() )
00107       item->setIcon( QIcon(iconFile.fileName()) );
00108     else {
00109       iconFile.setFileName( OpenFlipper::Options::configDirStr() + QDir::separator() + "Icons" + QDir::separator() + modes_[i]->icon );
00110       if ( iconFile.exists() )
00111         item->setIcon( QIcon(iconFile.fileName()) );
00112       else {
00113         item->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + QDir::separator () + "Unknown.png")  );
00114         std::cerr << "Unable to find icon file! " << iconFile.fileName().toStdString() <<  std::endl;
00115       }
00116     }
00117     
00118     item->setText(modes_[i]->name);
00119     
00120     if (modes_[i]->custom)
00121       viewModeList->item(i)->setForeground( QBrush(QColor(0,0,150) ) );
00122     else
00123       viewModeList->item(i)->setForeground( QBrush(QColor(0,0,0) ) );
00124   }
00125   
00126   //select given mode
00127   viewModeList->setCurrentRow(0);
00128   
00129   for (int i=0; i < viewModeList->count(); i++)
00130     if (viewModeList->item(i)->text() == _lastMode)
00131       viewModeList->setCurrentRow(i);
00132     
00133 }
00134 

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .