viewModeWidget.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: 7335 $                                                         *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2009-10-07 16:20:45 +0200 (Mi, 07. Okt 2009) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 #include "viewModeWidget.hh"
00047 #include <OpenFlipper/widgets/coreWidget/CoreWidget.hh>
00048 #include <OpenFlipper/common/GlobalOptions.hh>
00049 
00050 #include <QInputDialog>
00051 #include <QFileDialog>
00052 #include <QMessageBox>
00053 
00055 viewModeWidget::viewModeWidget(const QVector< ViewMode* >& _modes, QWidget *_parent)
00056   : QDialog(_parent),
00057     modes_(_modes)
00058 {
00059   setupUi(this);
00060 
00061 
00062   connect(viewModeList, SIGNAL(itemSelectionChanged()), this, SLOT(slotSetToolWidgets()));
00063 
00064   
00065   
00066   
00067   
00068   connect(viewModeList, SIGNAL(currentTextChanged (QString)), this, SLOT(slotModeChanged(QString)) );
00069   connect(viewModeList, SIGNAL(clicked (QModelIndex)), this, SLOT(slotModeClicked(QModelIndex)) );
00070 
00071   
00072   
00073   // View Mode buttons
00074   connect(removeButton, SIGNAL(clicked()), this, SLOT(slotRemoveMode()));
00075   connect(copyButton, SIGNAL(clicked()), this, SLOT(slotCopyMode()));
00076   connect(addButton, SIGNAL(clicked()), this, SLOT(slotAddMode()));
00077   
00078   // View Mode List context Menu
00079   viewModeList->setContextMenuPolicy(Qt::CustomContextMenu);
00080   connect(viewModeList ,SIGNAL(customContextMenuRequested ( const QPoint &  )  ),
00081           this         ,SLOT(slotModeContextMenu ( const QPoint & ) ));
00082   
00083   
00084   // Context Menus Toolbars
00085   toolbarList->setContextMenuPolicy(Qt::CustomContextMenu);
00086   availableToolbars->setContextMenuPolicy(Qt::CustomContextMenu);
00087   connect(toolbarList ,SIGNAL(customContextMenuRequested ( const QPoint &  )  ),
00088           this        ,SLOT(slotUsedToolbarContextMenu ( const QPoint & ) )); 
00089   connect(availableToolbars ,SIGNAL(customContextMenuRequested ( const QPoint &  )  ),
00090           this        ,SLOT(slotAvailableToolbarContextMenu ( const QPoint & ) )); 
00091   
00092   
00093   // Context Menus Toolboxes
00094   toolboxList->setContextMenuPolicy(Qt::CustomContextMenu);
00095   availableToolboxes->setContextMenuPolicy(Qt::CustomContextMenu);
00096   connect(toolboxList ,SIGNAL(customContextMenuRequested ( const QPoint &  )  ),
00097           this        ,SLOT(slotUsedToolboxContextMenu ( const QPoint & ) )); 
00098   connect(availableToolboxes ,SIGNAL(customContextMenuRequested ( const QPoint &  )  ),
00099           this        ,SLOT(slotAvailableToolboxContextMenu ( const QPoint & ) )); 
00100           
00101   
00102   // Toolbar Buttons to add remove toolbars to the given Mode
00103   connect(rightArrowToolbar, SIGNAL(clicked()), this, SLOT(slotRightArrowToolbar()) );
00104   rightArrowToolbar->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-right.png" ) );
00105   connect(leftArrowToolbar, SIGNAL(clicked()), this, SLOT(slotLeftArrowToolbar()) );
00106   leftArrowToolbar->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-left.png" ) );
00107   
00108   
00109   // Toolbar Buttons to add remove toolbars to the given Mode
00110   connect(rightArrowToolbox, SIGNAL(clicked()), this, SLOT(slotRightArrowToolbox()) );
00111   rightArrowToolbox->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-right.png" ) );
00112   connect(leftArrowToolbox, SIGNAL(clicked()), this, SLOT(slotLeftArrowToolbox()) );
00113   leftArrowToolbox->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-left.png" ) );  
00114   
00115   connect(upButton, SIGNAL(clicked()), this, SLOT(slotMoveUp()) );
00116   upButton->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-up.png" ) );
00117   connect(downButton, SIGNAL(clicked()), this, SLOT(slotMoveDown()) );
00118   downButton->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() + "arrow-down.png" ) );
00119   
00120   
00121   // General Buttons
00122   // Apply currently configured Mode
00123   connect(okButton, SIGNAL(clicked()), this, SLOT(slotChangeView()));
00124   connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
00125   connect(saveButton, SIGNAL(clicked()), this, SLOT(slotSaveMode()));
00126 }
00127 
00128 
00129 // =======================================================================================================
00130 // View Mode button slots
00131 // =======================================================================================================
00132 void viewModeWidget::slotRemoveMode(){
00133   emit removeMode( viewModeList->currentItem()->text() );
00134   QListWidgetItem* item =  viewModeList->takeItem( viewModeList->currentRow() );
00135   delete item;
00136 }
00137 
00138 void viewModeWidget::slotCopyMode(){
00139   // Find currently selected Mode
00140   // Search for current mode 
00141   int id = -1;
00142   if ( viewModeList->selectedItems().count() > 0) 
00143     for (int i=0; i < modes_.size(); i++)
00144       if (modes_[i]->name == viewModeList->currentItem()->text()){
00145         id = i;
00146         break;
00147       }
00148       
00149   if ( id == -1 ) {
00150     std::cerr << "Currently selected Mode not found?!" << std::endl; 
00151     return;
00152   }
00153   
00154   //ask for a name for the new viewmode as it is not a custom one
00155   bool ok;
00156   QString name = QInputDialog::getText(this, tr("Copy View Mode"),
00157                                              tr("Please enter a name for the new View Mode"), QLineEdit::Normal,
00158                                                 "", &ok);
00159                      
00160   // Check if valid                                                
00161   if (!ok || name.isEmpty()) {
00162     QMessageBox::warning(this, tr("Copy View Mode"), tr("Please enter a Name"), QMessageBox::Ok);
00163     return; 
00164   }
00165   
00166   //check if name already exists
00167   for (int i=0; i < modes_.size(); i++)
00168     if (modes_[i]->name == name){
00169       QMessageBox::warning(this, tr("Copy View Mode"), tr("Cannot Copy ViewMode. \nNew Name already in use for a different mode."), QMessageBox::Ok);
00170       return;
00171     }
00172   
00173   emit saveMode(name, true, modes_[id]->visibleToolboxes, modes_[id]->visibleToolbars);      
00174   
00175   QListWidgetItem *item = new QListWidgetItem(viewModeList);
00176   item->setTextAlignment(Qt::AlignHCenter);
00177   item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
00178   item->setIcon(QIcon(OpenFlipper::Options::iconDirStr() + QDir::separator () + "Unknown.png"));
00179   item->setText(name);
00180   
00181   item->setForeground( QBrush(QColor(0,0,150) ) );
00182   
00183   show(name);
00184 }
00185 
00186 void viewModeWidget::slotAddMode(){
00187   
00188  //ask for a name for the new viewmode as it is not a custom one
00189   bool ok;
00190   QString name = QInputDialog::getText(this, tr("Add View Mode"),
00191                                              tr("Please enter a name for the new View Mode"), QLineEdit::Normal,
00192                                                 "", &ok);
00193                      
00194   // Check if valid                                                
00195   if (!ok || name.isEmpty()) {
00196     QMessageBox::warning(this, tr("Add View Mode"), tr("Please enter a Name"), QMessageBox::Ok);
00197     return; 
00198   }
00199   
00200   //check if name already exists
00201   for (int i=0; i < modes_.size(); i++)
00202     if (modes_[i]->name == name){
00203       QMessageBox::warning(this, tr("Add View Mode"), tr("Cannot Add ViewMode. \nNew Name already in use for a different mode."), QMessageBox::Ok);
00204       return;
00205     }
00206   
00207   emit saveMode(name, true, QStringList(), QStringList());      
00208   
00209   QListWidgetItem *item = new QListWidgetItem(viewModeList);
00210   item->setTextAlignment(Qt::AlignHCenter);
00211   item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
00212   item->setIcon(QIcon(OpenFlipper::Options::iconDirStr() + QDir::separator () + "Unknown.png"));
00213   item->setText(name);
00214   
00215   item->setForeground( QBrush(QColor(0,0,150) ) );
00216   
00217   show(name);
00218 }
00219 
00220 // =======================================================================================================
00221 // View Mode Context Menu
00222 // =======================================================================================================
00223 void viewModeWidget::slotModeContextMenu ( const QPoint & _pos ){
00224   
00225   if (viewModeList->itemAt(_pos)){
00226     
00227     QMenu menu(0);
00228     
00229     menu.addAction(tr("Remove Mode"), this, SLOT ( slotRemoveMode() ));
00230     menu.addAction(tr("Copy Mode"), this, SLOT ( slotCopyMode() ));      
00231     menu.addAction(tr("Change Icon"), this, SLOT ( slotSetIcon() ));
00232     
00233     //check if mode is custom e.g. that it can be removed
00234     for (int i=0; i < modes_.size(); i++)
00235       if (modes_[i]->name == viewModeList->currentItem()->text()){
00236         menu.actions()[0]->setEnabled(modes_[i]->custom);
00237         menu.actions()[2]->setEnabled(modes_[i]->custom);
00238         break;
00239       }
00240       
00241     menu.exec(viewModeList->mapToGlobal( _pos) );
00242   }
00243 }
00244 
00245 void viewModeWidget::slotSetIcon() {
00246   // Get the correct mode
00247   int id = -1;
00248   for (int i=0; i < modes_.size(); i++)
00249     if (modes_[i]->name == viewModeList->currentItem()->text()){
00250       id = i;
00251       break;
00252     }
00253     
00254   if ( id == -1) {
00255     std::cerr << "Unable to find Mode viewModeWidget::slotSetIcon()" << std::endl;
00256     return;
00257   }
00258 
00259   // Get the filename from the user
00260   QString fileName = QFileDialog::getOpenFileName ( this, tr("Select Image for view Mode ( best size : 150x150px )"), QString(),  tr("Images (*.png *.xpm *.jpg)") );
00261   
00262   QFile file(fileName);
00263   QFileInfo fileInfo(file);
00264   
00265   if ( ! file.exists() )
00266     return;
00267   
00268   
00269   file.copy(OpenFlipper::Options::configDirStr() + QDir::separator() + "Icons" + QDir::separator() + "viewMode_" + fileInfo.fileName() );
00270   
00271   modes_[id]->icon = "viewMode_" + fileInfo.fileName();
00272 
00273   show(modes_[id]->name);
00274 }
00275 
00276 // =======================================================================================================
00277 // ToolBox and ToolBar Lists update functions
00278 // =======================================================================================================
00279 void viewModeWidget::slotSetToolWidgets(){
00280   toolboxList->clear();
00281   toolbarList->clear();
00282   availableToolboxes->clear();
00283   availableToolbars->clear();
00284   
00285   QStringList toolboxes;
00286   QStringList toolbars;
00287   
00288   //iterate over all selected modes
00289   for (int m=0; m < viewModeList->selectedItems().size(); m++)
00290     
00291     // find mode in modeVector modes_
00292     for (int i=0; i < modes_.size(); i++)
00293       if ( modes_[i]->name == (viewModeList->selectedItems()[m])->text() ) {
00294         toolboxes = modes_[i]->visibleToolboxes;
00295         toolbars = modes_[i]->visibleToolbars;
00296         toolboxList->addItems(toolboxes); //add corresponding widgets
00297         toolbarList->addItems(toolbars);
00298         break;
00299       }
00300       
00301       
00302       if ( !modes_.empty() ) {
00303         QStringList allToolboxes = modes_[0]->visibleToolboxes;
00304         QStringList allToolbars  = modes_[0]->visibleToolbars;
00305         
00306         QStringList availableToolboxList;
00307         QStringList availableToolbarList;
00308         
00309         for ( int i = 0; i < allToolboxes.size(); ++i ) {
00310           if ( ! toolboxes.contains(allToolboxes[i]) ) 
00311             availableToolboxList.push_back(allToolboxes[i]);
00312         }
00313         
00314         for ( int i = 0; i < allToolbars.size(); ++i ) {
00315           if ( ! toolbars.contains(allToolbars[i]) ) 
00316             availableToolbarList.push_back(allToolbars[i]);
00317         }
00318         
00319         availableToolboxes->addItems(availableToolboxList);
00320         availableToolbars->addItems(availableToolbarList);
00321         
00322       } else {
00323         std::cerr << "Mode not found!" << std::endl;
00324       }
00325       
00326 }
00327 
00328 
00329 // =======================================================================================================
00330 // ToolBar Context Menus Buttons
00331 // =======================================================================================================
00332 
00334 void viewModeWidget::slotUsedToolbarContextMenu ( const QPoint & _pos ){
00335   
00336   if (toolboxList->itemAt(_pos)){
00337     
00338     QMenu menu(0);
00339     
00340     if ( toolbarList->selectedItems().count() != 0 )
00341       menu.addAction(tr("Remove"), this, SLOT ( slotRightArrowToolbar() ));
00342     
00343     menu.exec(toolbarList->mapToGlobal( _pos) );
00344   }
00345 }
00346 
00348 void viewModeWidget::slotAvailableToolbarContextMenu ( const QPoint & _pos ){
00349   
00350   if (availableToolbars->itemAt(_pos)){
00351     
00352     QMenu menu(0);
00353     
00354     if ( availableToolbars->selectedItems().count() != 0 )
00355       menu.addAction(tr("Add"), this, SLOT ( slotLeftArrowToolbar() ));
00356     
00357     menu.exec(availableToolbars->mapToGlobal( _pos) );
00358   }
00359 }
00360 
00361 // =======================================================================================================
00362 // ToolBox Context Menus Buttons
00363 // =======================================================================================================
00364 
00366 void viewModeWidget::slotUsedToolboxContextMenu ( const QPoint & _pos ){
00367   
00368   if (toolboxList->itemAt(_pos)){
00369     
00370     QMenu menu(0);
00371     
00372     if (toolboxList->selectedItems().count() == 1){
00373       menu.addAction(tr("Move up"), this, SLOT ( slotMoveUp() ));
00374       menu.addAction(tr("Move down"), this, SLOT ( slotMoveDown() ));
00375       menu.addSeparator();
00376     }
00377     
00378     if ( toolboxList->selectedItems().count() != 0 )
00379       menu.addAction(tr("Remove"), this, SLOT ( slotRightArrowToolbox() ));
00380     
00381     menu.exec(toolboxList->mapToGlobal( _pos) );
00382   }
00383 }
00384 
00386 void viewModeWidget::slotAvailableToolboxContextMenu ( const QPoint & _pos ){
00387   
00388   if (availableToolboxes->itemAt(_pos)){
00389     
00390     QMenu menu(0);
00391     
00392     if ( availableToolboxes->selectedItems().count() != 0 )
00393       menu.addAction(tr("Add"), this, SLOT ( slotLeftArrowToolbox() ));
00394     
00395     menu.exec(availableToolboxes->mapToGlobal( _pos) );
00396   }
00397 }
00398 
00399 
00400 // =======================================================================================================
00401 // ToolBar Buttons
00402 // =======================================================================================================
00403 
00404 void viewModeWidget::slotRightArrowToolbar() {
00405   QList<QListWidgetItem *> selectedItems = toolbarList->selectedItems ();
00406   for ( int i = 0 ; i < selectedItems.size(); ++i ) 
00407     availableToolbars->addItem(selectedItems[i]->text());
00408 
00409   qDeleteAll(selectedItems);
00410 }
00411 
00412 void viewModeWidget::slotLeftArrowToolbar() {
00413   QList<QListWidgetItem *> selectedItems = availableToolbars->selectedItems ();
00414   for ( int i = 0 ; i < selectedItems.size(); ++i ) 
00415     toolbarList->addItem(selectedItems[i]->text());
00416   
00417   qDeleteAll(selectedItems);
00418 }
00419 
00420 // =======================================================================================================
00421 // ToolBox Buttons
00422 // =======================================================================================================
00423 
00424 void viewModeWidget::slotRightArrowToolbox() {
00425   QList<QListWidgetItem *> selectedItems = toolboxList->selectedItems ();
00426   for ( int i = 0 ; i < selectedItems.size(); ++i ) 
00427     availableToolboxes->addItem(selectedItems[i]->text());
00428   
00429   qDeleteAll(selectedItems);
00430 }
00431 
00432 void viewModeWidget::slotLeftArrowToolbox() {
00433   QList<QListWidgetItem *> selectedItems = availableToolboxes->selectedItems ();
00434   for ( int i = 0 ; i < selectedItems.size(); ++i ) 
00435     toolboxList->addItem(selectedItems[i]->text());
00436   
00437   qDeleteAll(selectedItems);
00438 }
00439 
00440 
00442 void viewModeWidget::slotMoveUp(){
00443   if (toolboxList->selectedItems().count() == 1){
00444     if (toolboxList->currentRow() == 0) return;
00445     //extract a list of all items
00446     QString item = toolboxList->currentItem()->text();
00447     int oldRow = toolboxList->currentRow();
00448     QStringList widgets;
00449     for (int i=0; i < toolboxList->count(); i++)
00450       widgets << toolboxList->item(i)->text();
00451     
00452     //reorder items
00453     QString last = widgets[0];
00454     for (int i=1; i < widgets.size(); i++){
00455       if (widgets[i] == item){
00456         widgets[i] = last;
00457         widgets[i-1] = item;
00458       }
00459       last = widgets[i];
00460     }
00461     // set new list as elements for the toolboxList
00462     toolboxList->clear();
00463     toolboxList->addItems(widgets);
00464     //highlight active item
00465     toolboxList->setCurrentRow(oldRow-1);
00466   }
00467 }
00468 
00470 void viewModeWidget::slotMoveDown(){
00471   if (toolboxList->selectedItems().count() == 1){
00472     if (toolboxList->currentRow() == toolboxList->count()-1) return;
00473     //extract a list of all items
00474     QString item = toolboxList->currentItem()->text();
00475     int oldRow = toolboxList->currentRow();
00476     QStringList widgets;
00477     for (int i=0; i < toolboxList->count(); i++)
00478       widgets << toolboxList->item(i)->text();
00479     
00480     //reorder items
00481     QString last = widgets[widgets.size()-1];
00482     for (int i=widgets.size()-2; i >= 0; i--){
00483       if (widgets[i] == item){
00484         widgets[i] = last;
00485         widgets[i+1] = item;
00486       }
00487       last = widgets[i];
00488     }
00489     // set new list as elements for the toolboxList
00490     toolboxList->clear();
00491     toolboxList->addItems(widgets);
00492     //highlight active item
00493     toolboxList->setCurrentRow(oldRow+1);
00494   }
00495 }
00496 
00497 
00498 
00499 // =======================================================================================================
00500 // External communication
00501 // =======================================================================================================
00502 
00504 void viewModeWidget::slotChangeView(){
00505   //get toolboxes
00506   QStringList toolboxes;
00507   for (int i=0; i < toolboxList->count(); i++)
00508     toolboxes << toolboxList->item(i)->text();
00509   
00510   //get toolbars
00511   QStringList toolbars;
00512   for (int i=0; i < toolbarList->count(); i++)
00513     toolbars << toolbarList->item(i)->text();
00514   
00515   //get mode
00516   QString mode = "";
00517   if (viewModeList->selectedItems().size() > 0)
00518     mode = viewModeList->selectedItems()[0]->text();
00519   
00520   
00521   // Check current configuration if it is a changed view mode
00522   
00523   // Search for current mode 
00524   int id = -1;
00525   if ( viewModeList->selectedItems().count() > 0) 
00526     for (int i=0; i < modes_.size(); i++)
00527       if (modes_[i]->name == viewModeList->currentItem()->text()){
00528         id = i;
00529         break;
00530       }
00531       
00532   if ( id == -1 ) {
00533     std::cerr << "Currently selected Mode not found?!" << std::endl; 
00534     return;
00535   }
00536   
00537   bool matching = true;
00538   // Check if toolbox list matches:
00539   if ( modes_[id]->visibleToolboxes.size() == toolboxes.size() ) {
00540     for ( int i = 0 ; i < modes_[id]->visibleToolboxes.size(); ++i  ) 
00541       if ( modes_[id]->visibleToolboxes[i] != toolboxes[i] )
00542         matching = false;
00543   } else {
00544       matching = false;
00545   }
00546   
00547   // Check if toolbar list matches:
00548   if ( modes_[id]->visibleToolbars.size() == toolbars.size() ) {
00549     for ( int i = 0 ; i < modes_[id]->visibleToolbars.size(); ++i  ) 
00550       if ( modes_[id]->visibleToolbars[i] != toolbars[i] )
00551         matching = false;
00552   } else {
00553     matching = false;
00554   }
00555   
00556   if ( !matching ) {
00557     int ret = QMessageBox::warning(this, 
00558                                    tr("Mode has been changed!"),
00559                                    tr("You changed the view mode configuration. Do you want to save it?"),
00560                                    QMessageBox::Yes|QMessageBox::No,
00561                                    QMessageBox::No);
00562     if (ret == QMessageBox::Yes) 
00563       slotSaveMode();
00564     
00565   }
00566   
00567   emit changeView(mode,toolboxes,toolbars);
00568   close();
00569 }
00570 
00572 void viewModeWidget::slotSaveMode(){
00573   // Search for current mode vector
00574   int id = -1;
00575   if ( viewModeList->selectedItems().count() > 0) 
00576     for (int i=0; i < modes_.size(); i++)
00577       if (modes_[i]->name == viewModeList->currentItem()->text()){
00578         id = i;
00579         break;
00580       }
00581   
00582   if ( id == -1 ) {
00583     std::cerr << "Mode Not found in slotSaveMode" << std::endl;
00584     return;
00585   }
00586   
00587   // Get Toolboxes
00588   QStringList toolboxes;
00589   for (int i=0; i < toolboxList->count(); i++)
00590     toolboxes << toolboxList->item(i)->text();
00591   
00592   // Get Toolbars
00593   QStringList toolbars;
00594   for (int i=0; i < toolbarList->count(); i++)
00595     toolbars << toolbarList->item(i)->text();
00596    
00597   bool  createNewMode = false;
00598 
00599   QString message = tr("You cannot change predefined modes.\n"
00600                        "Please enter a new Name for the mode.");
00601   
00602   // Check if we want to create a new node.
00603   if ( ! modes_[id]->custom ) {
00604     createNewMode = true;
00605     
00606   } else {
00607     int ret = QMessageBox::warning(this, 
00608                                    tr("View Mode exists"),
00609                                    tr("View Mode already exists. Do you want to overwrite it?"),
00610                                    QMessageBox::Yes|QMessageBox::No,
00611                                    QMessageBox::No);
00612     if (ret == QMessageBox::No) {
00613       message = tr("New name for view mode:");
00614       createNewMode = true;
00615     }
00616   }
00617   
00618   
00619   if ( createNewMode ) {
00620     
00621     //ask for a name for the new viewmode as it is not a custom one
00622     bool ok;
00623     QString name = QInputDialog::getText(this, tr("Save view Mode"),
00624                                                message, QLineEdit::Normal,
00625                                                   "", &ok);
00626                                                     
00627     //Remove Spaces from name
00628     if (!ok || name.isEmpty()) {
00629       std::cerr << "Illegal or no name given!" << std::endl;
00630       return; 
00631     }
00632     
00633     //check if name already exists
00634     for (int i=0; i < modes_.size(); i++)
00635       if (modes_[i]->name == name){
00636         QMessageBox::warning(this, tr("Save View Mode"), tr("Cannot Save ViewMode.\nName already taken by a different mode."), QMessageBox::Ok);
00637         return;
00638       }
00639       
00640     emit saveMode(name, true, toolboxes, toolbars);
00641     show(name);      
00642   } else {
00643     emit saveMode(modes_[id]->name, true, toolboxes, toolbars);
00644     show(modes_[id]->name);    
00645   }
00646   
00647 }  
00648 
00649 
00650 
00651 
00652 
00653 
00654 
00655 
00656 
00657 
00658 
00659 
00660 
00661 
00662 
00663 
00664 
00665 
00666 
00668 void viewModeWidget::show(QString _lastMode){
00669   QDialog::show();
00670   
00671   //fill viewModeList
00672   viewModeList->clear();
00673   for (int i=0; i < modes_.size(); i++){
00674     QListWidgetItem *item = new QListWidgetItem(viewModeList);
00675     item->setTextAlignment(Qt::AlignHCenter);
00676     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
00677     
00678     QFile iconFile( OpenFlipper::Options::iconDirStr() + QDir::separator () + modes_[i]->icon  );
00679     
00680     if ( iconFile.exists() )
00681       item->setIcon( QIcon(iconFile.fileName()) );
00682     else {
00683       iconFile.setFileName( OpenFlipper::Options::configDirStr() + QDir::separator() + "Icons" + QDir::separator() + modes_[i]->icon );
00684       if ( iconFile.exists() )
00685         item->setIcon( QIcon(iconFile.fileName()) );
00686       else {
00687         item->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + QDir::separator () + "Unknown.png")  );
00688         std::cerr << "Unable to find icon file! " << iconFile.fileName().toStdString() <<  std::endl;
00689       }
00690     }
00691     
00692     item->setText(modes_[i]->name);
00693     
00694     if (modes_[i]->custom)
00695       viewModeList->item(i)->setForeground( QBrush(QColor(0,0,150) ) );
00696     else
00697       viewModeList->item(i)->setForeground( QBrush(QColor(0,0,0) ) );
00698   }
00699   
00700   //select given mode
00701   viewModeList->setCurrentRow(0);
00702   
00703   for (int i=0; i < viewModeList->count(); i++)
00704     if (viewModeList->item(i)->text() == _lastMode)
00705       viewModeList->setCurrentRow(i);
00706     
00707     removeButton->setEnabled(false);
00708 }
00709 
00710 
00712 void viewModeWidget::slotModeClicked(QModelIndex /*_id*/){
00713   slotModeChanged(QString());
00714 }
00715 
00717 void viewModeWidget::slotModeChanged(QString /*_mode*/){
00718   //check if mode is custom e.g. that it can be removed
00719   if (viewModeList->selectedItems().count() > 0){
00720     for (int i=0; i < modes_.size(); i++)
00721       if (modes_[i]->name == viewModeList->currentItem()->text()){
00722         removeButton->setEnabled(modes_[i]->custom);
00723         break;
00724       }
00725   }
00726 }
00727 
00728 
00729 
00730 
00731 
00732 
00733 
00734 
00735 
00736 
00737 
00738 
00739 
00740 
00741 
00742 
00743 

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