53 #include "viewModeWidget.hh" 64 connect(viewModeList, SIGNAL(itemSelectionChanged()),
this, SLOT(
slotSetAllWidgets()));
70 connect(viewModeList, SIGNAL(currentTextChanged (QString)),
this, SLOT(
slotModeChanged(QString)) );
71 connect(viewModeList, SIGNAL(clicked (QModelIndex)),
this, SLOT(
slotModeClicked(QModelIndex)) );
76 connect(removeButton, SIGNAL(clicked()),
this, SLOT(
slotRemoveMode()));
77 connect(copyButton, SIGNAL(clicked()),
this, SLOT(
slotCopyMode()));
78 connect(addButton, SIGNAL(clicked()),
this, SLOT(
slotAddMode()));
81 viewModeList->setContextMenuPolicy(Qt::CustomContextMenu);
82 connect(viewModeList ,SIGNAL(customContextMenuRequested (
const QPoint & ) ),
87 toolbarList->setContextMenuPolicy(Qt::CustomContextMenu);
88 availableToolbars->setContextMenuPolicy(Qt::CustomContextMenu);
89 connect(toolbarList ,SIGNAL(customContextMenuRequested (
const QPoint & ) ),
91 connect(availableToolbars ,SIGNAL(customContextMenuRequested (
const QPoint & ) ),
96 toolboxList->setContextMenuPolicy(Qt::CustomContextMenu);
97 availableToolboxes->setContextMenuPolicy(Qt::CustomContextMenu);
98 connect(toolboxList ,SIGNAL(customContextMenuRequested (
const QPoint & ) ),
100 connect(availableToolboxes ,SIGNAL(customContextMenuRequested (
const QPoint & ) ),
105 contextMenuList->setContextMenuPolicy(Qt::CustomContextMenu);
106 availableContextMenus->setContextMenuPolicy(Qt::CustomContextMenu);
107 connect(contextMenuList ,SIGNAL(customContextMenuRequested (
const QPoint & ) ),
109 connect(availableContextMenus ,SIGNAL(customContextMenuRequested (
const QPoint & ) ),
115 rightArrowToolbar->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-right.png" ) );
117 leftArrowToolbar->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-left.png" ) );
122 rightArrowToolbox->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-right.png" ) );
124 leftArrowToolbox->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-left.png" ) );
127 upButtonToolbox->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-up.png" ) );
129 downButtonToolbox->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-down.png" ) );
134 rightArrowContextMenu->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-right.png" ) );
136 leftArrowContextMenu->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-left.png" ) );
139 upButtonContextMenu->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-up.png" ) );
141 downButtonContextMenu->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-down.png" ) );
147 connect(okButton, SIGNAL(clicked()),
this, SLOT(
slotChangeView()));
148 connect(cancelButton, SIGNAL(clicked()),
this, SLOT(close()));
149 connect(saveButton, SIGNAL(clicked()),
this, SLOT(
slotSaveMode()));
157 emit
removeMode( viewModeList->currentItem()->text() );
158 QListWidgetItem* item = viewModeList->takeItem( viewModeList->currentRow() );
166 if ( viewModeList->selectedItems().count() > 0)
167 for (
int i=0; i < modes_.size(); i++)
168 if (modes_[i]->name == viewModeList->currentItem()->text()){
174 std::cerr <<
"Currently selected Mode not found?!" << std::endl;
180 QString name = QInputDialog::getText(
this, tr(
"Copy View Mode"),
185 if (!ok || name.isEmpty()) {
186 QMessageBox::warning(
this, tr(
"Copy View Mode"), tr(
"Please enter a Name"), QMessageBox::Ok);
191 for (
int i=0; i < modes_.size(); i++)
192 if (modes_[i]->name == name){
193 QMessageBox::warning(
this, tr(
"Copy View Mode"), tr(
"Cannot Copy ViewMode. \nNew Name already in use for a different mode."), QMessageBox::Ok);
197 emit
saveMode(name,
true, modes_[
id]->visibleToolboxes, modes_[
id]->visibleToolbars, modes_[
id]->visibleContextMenus);
199 QListWidgetItem *item =
new QListWidgetItem(viewModeList);
200 item->setTextAlignment(Qt::AlignHCenter);
201 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
202 item->setIcon(QIcon(OpenFlipper::Options::iconDirStr() + QDir::separator () +
"Unknown.png"));
205 item->setForeground( QBrush(QColor(0,0,150) ) );
214 QString name = QInputDialog::getText(
this, tr(
"Add View Mode"),
219 if (!ok || name.isEmpty()) {
220 QMessageBox::warning(
this, tr(
"Add View Mode"), tr(
"Please enter a Name"), QMessageBox::Ok);
225 for (
int i=0; i < modes_.size(); i++)
226 if (modes_[i]->name == name){
227 QMessageBox::warning(
this, tr(
"Add View Mode"), tr(
"Cannot Add ViewMode. \nNew Name already in use for a different mode."), QMessageBox::Ok);
231 emit
saveMode(name,
true, QStringList(), QStringList(), modes_[0]->visibleContextMenus);
233 QListWidgetItem *item =
new QListWidgetItem(viewModeList);
234 item->setTextAlignment(Qt::AlignHCenter);
235 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
236 item->setIcon(QIcon(OpenFlipper::Options::iconDirStr() + QDir::separator () +
"Unknown.png"));
239 item->setForeground( QBrush(QColor(0,0,150) ) );
249 if (viewModeList->itemAt(_pos)){
253 menu.addAction(tr(
"Remove Mode"),
this, SLOT (
slotRemoveMode() ));
254 menu.addAction(tr(
"Copy Mode"),
this, SLOT (
slotCopyMode() ));
255 menu.addAction(tr(
"Change Icon"),
this, SLOT (
slotSetIcon() ));
258 for (
int i=0; i < modes_.size(); i++)
259 if (modes_[i]->name == viewModeList->currentItem()->text()){
260 menu.actions()[0]->setEnabled(modes_[i]->custom);
261 menu.actions()[2]->setEnabled(modes_[i]->custom);
265 menu.exec(viewModeList->mapToGlobal( _pos) );
272 for (
int i=0; i < modes_.size(); i++)
273 if (modes_[i]->name == viewModeList->currentItem()->text()){
279 std::cerr <<
"Unable to find Mode viewModeWidget::slotSetIcon()" << std::endl;
284 QString fileName = QFileDialog::getOpenFileName (
this, tr(
"Select Image for view Mode ( best size : 150x150px )"), QString(), tr(
"Images (*.png *.xpm *.jpg)") );
286 QFile file(fileName);
287 QFileInfo fileInfo(file);
289 if ( ! file.exists() )
293 file.copy(OpenFlipper::Options::configDirStr() + QDir::separator() +
"Icons" + QDir::separator() +
"viewMode_" + fileInfo.fileName() );
295 modes_[id]->icon =
"viewMode_" + fileInfo.fileName();
297 show(modes_[
id]->name);
304 toolboxList->clear();
305 toolbarList->clear();
306 contextMenuList->clear();
307 availableToolboxes->clear();
308 availableToolbars->clear();
309 availableContextMenus->clear();
311 QStringList toolboxes;
312 QStringList toolbars;
313 QStringList contextmenus;
316 for (
int m=0; m < viewModeList->selectedItems().size(); m++) {
319 for (
int i=0; i < modes_.size(); i++) {
320 if ( modes_[i]->name == (viewModeList->selectedItems()[m])->text() ) {
321 toolboxes = modes_[i]->visibleToolboxes;
322 toolbars = modes_[i]->visibleToolbars;
323 contextmenus = modes_[i]->visibleContextMenus;
324 if (contextmenus.contains(
"ALL_THAT_EXIST"))
325 contextmenus = modes_[0]->visibleContextMenus;
326 toolboxList->addItems(toolboxes);
327 toolbarList->addItems(toolbars);
328 contextMenuList->addItems(contextmenus);
335 if ( !modes_.empty() ) {
336 QStringList allToolboxes = modes_[0]->visibleToolboxes;
337 QStringList allToolbars = modes_[0]->visibleToolbars;
338 QStringList allContextMenus = modes_[0]->visibleContextMenus;
340 QStringList availableToolboxList;
341 QStringList availableToolbarList;
342 QStringList availableContextMenuList;
344 for (
int i = 0; i < allToolboxes.size(); ++i ) {
345 if ( ! toolboxes.contains(allToolboxes[i]) )
346 availableToolboxList.push_back(allToolboxes[i]);
349 for (
int i = 0; i < allToolbars.size(); ++i ) {
350 if ( ! toolbars.contains(allToolbars[i]) )
351 availableToolbarList.push_back(allToolbars[i]);
354 for (
int i = 0; i < allContextMenus.size(); ++i ) {
355 if ( ! contextmenus.contains(allContextMenus[i]) )
356 availableContextMenuList.push_back(allContextMenus[i]);
359 availableToolboxes->addItems(availableToolboxList);
360 availableToolbars->addItems(availableToolbarList);
361 availableContextMenus->addItems(availableContextMenuList);
364 std::cerr <<
"Mode not found!" << std::endl;
377 if (toolboxList->itemAt(_pos)){
381 if ( toolbarList->selectedItems().count() != 0 )
384 menu.exec(toolbarList->mapToGlobal( _pos) );
391 if (availableToolbars->itemAt(_pos)){
395 if ( availableToolbars->selectedItems().count() != 0 )
398 menu.exec(availableToolbars->mapToGlobal( _pos) );
409 if (toolboxList->itemAt(_pos)){
413 if (toolboxList->selectedItems().count() == 1){
419 if ( toolboxList->selectedItems().count() != 0 )
422 menu.exec(toolboxList->mapToGlobal( _pos) );
429 if (availableToolboxes->itemAt(_pos)){
433 if ( availableToolboxes->selectedItems().count() != 0 )
436 menu.exec(availableToolboxes->mapToGlobal( _pos) );
447 if (contextMenuList->itemAt(_pos)){
451 if (contextMenuList->selectedItems().count() == 1){
457 if ( contextMenuList->selectedItems().count() != 0 )
460 menu.exec(contextMenuList->mapToGlobal( _pos) );
467 if (availableContextMenus->itemAt(_pos)){
471 if ( availableContextMenus->selectedItems().count() != 0 )
474 menu.exec(availableContextMenus->mapToGlobal( _pos) );
483 QList<QListWidgetItem *> selectedItems = toolbarList->selectedItems ();
484 for (
int i = 0 ; i < selectedItems.size(); ++i )
485 availableToolbars->addItem(selectedItems[i]->text());
487 qDeleteAll(selectedItems);
491 QList<QListWidgetItem *> selectedItems = availableToolbars->selectedItems ();
492 for (
int i = 0 ; i < selectedItems.size(); ++i )
493 toolbarList->addItem(selectedItems[i]->text());
495 qDeleteAll(selectedItems);
503 QList<QListWidgetItem *> selectedItems = toolboxList->selectedItems ();
504 for (
int i = 0 ; i < selectedItems.size(); ++i )
505 availableToolboxes->addItem(selectedItems[i]->text());
507 qDeleteAll(selectedItems);
511 QList<QListWidgetItem *> selectedItems = availableToolboxes->selectedItems ();
512 for (
int i = 0 ; i < selectedItems.size(); ++i )
513 toolboxList->addItem(selectedItems[i]->text());
515 qDeleteAll(selectedItems);
521 if (toolboxList->selectedItems().count() == 1){
522 if (toolboxList->currentRow() == 0)
return;
524 QString item = toolboxList->currentItem()->text();
525 int oldRow = toolboxList->currentRow();
527 for (
int i=0; i < toolboxList->count(); i++)
528 widgets << toolboxList->item(i)->text();
531 QString last = widgets[0];
532 for (
int i=1; i < widgets.size(); i++){
533 if (widgets[i] == item){
540 toolboxList->clear();
541 toolboxList->addItems(widgets);
543 toolboxList->setCurrentRow(oldRow-1);
549 if (toolboxList->selectedItems().count() == 1){
550 if (toolboxList->currentRow() == toolboxList->count()-1)
return;
552 QString item = toolboxList->currentItem()->text();
553 int oldRow = toolboxList->currentRow();
555 for (
int i=0; i < toolboxList->count(); i++)
556 widgets << toolboxList->item(i)->text();
559 QString last = widgets[widgets.size()-1];
560 for (
int i=widgets.size()-2; i >= 0; i--){
561 if (widgets[i] == item){
568 toolboxList->clear();
569 toolboxList->addItems(widgets);
571 toolboxList->setCurrentRow(oldRow+1);
580 QList<QListWidgetItem *> selectedItems = contextMenuList->selectedItems ();
581 for (
int i = 0 ; i < selectedItems.size(); ++i )
582 availableContextMenus->addItem(selectedItems[i]->text());
584 qDeleteAll(selectedItems);
588 QList<QListWidgetItem *> selectedItems = availableContextMenus->selectedItems ();
589 for (
int i = 0 ; i < selectedItems.size(); ++i )
590 contextMenuList->addItem(selectedItems[i]->text());
592 qDeleteAll(selectedItems);
598 if (contextMenuList->selectedItems().count() == 1){
599 if (contextMenuList->currentRow() == 0)
return;
601 QString item = contextMenuList->currentItem()->text();
602 int oldRow = contextMenuList->currentRow();
604 for (
int i=0; i < contextMenuList->count(); i++)
605 widgets << contextMenuList->item(i)->text();
608 QString last = widgets[0];
609 for (
int i=1; i < widgets.size(); i++){
610 if (widgets[i] == item){
617 contextMenuList->clear();
618 contextMenuList->addItems(widgets);
620 contextMenuList->setCurrentRow(oldRow-1);
626 if (contextMenuList->selectedItems().count() == 1){
627 if (contextMenuList->currentRow() == contextMenuList->count()-1)
return;
629 QString item = contextMenuList->currentItem()->text();
630 int oldRow = contextMenuList->currentRow();
632 for (
int i=0; i < contextMenuList->count(); i++)
633 widgets << contextMenuList->item(i)->text();
636 QString last = widgets[widgets.size()-1];
637 for (
int i=widgets.size()-2; i >= 0; i--){
638 if (widgets[i] == item){
645 contextMenuList->clear();
646 contextMenuList->addItems(widgets);
648 contextMenuList->setCurrentRow(oldRow+1);
661 QStringList toolboxes;
662 for (
int i=0; i < toolboxList->count(); i++)
663 toolboxes << toolboxList->item(i)->text();
666 QStringList toolbars;
667 for (
int i=0; i < toolbarList->count(); i++)
668 toolbars << toolbarList->item(i)->text();
671 QStringList contextmenus;
672 for (
int i=0; i < contextMenuList->count(); i++)
673 contextmenus << contextMenuList->item(i)->text();
677 if (viewModeList->selectedItems().size() > 0)
678 mode = viewModeList->selectedItems()[0]->text();
685 if ( viewModeList->selectedItems().count() > 0)
686 for (
int i=0; i < modes_.size(); i++)
687 if (modes_[i]->name == viewModeList->currentItem()->text()){
693 std::cerr <<
"Currently selected Mode not found?!" << std::endl;
697 bool matching =
true;
699 if ( modes_[
id]->visibleToolboxes.size() == toolboxes.size() ) {
700 for (
int i = 0 ; i < modes_[id]->visibleToolboxes.size(); ++i )
701 if ( modes_[
id]->visibleToolboxes[i] != toolboxes[i] )
708 if ( modes_[
id]->visibleToolbars.size() == toolbars.size() ) {
709 for (
int i = 0 ; i < modes_[id]->visibleToolbars.size(); ++i )
710 if ( modes_[
id]->visibleToolbars[i] != toolbars[i] )
717 if ( modes_[
id]->visibleContextMenus.size() == contextmenus.size() ) {
718 for (
int i = 0 ; i < modes_[id]->visibleContextMenus.size(); ++i )
719 if ( modes_[
id]->visibleContextMenus[i] != contextmenus[i] )
726 int ret = QMessageBox::warning(
this,
727 tr(
"Mode has been changed!"),
728 tr(
"You changed the view mode configuration. Do you want to save it?"),
729 QMessageBox::Yes|QMessageBox::No,
731 if (ret == QMessageBox::Yes)
736 emit
changeView(mode,toolboxes,toolbars,contextmenus);
744 if ( viewModeList->selectedItems().count() > 0)
745 for (
int i=0; i < modes_.size(); i++)
746 if (modes_[i]->name == viewModeList->currentItem()->text()){
752 std::cerr <<
"Mode Not found in slotSaveMode" << std::endl;
757 QStringList toolboxes;
758 for (
int i=0; i < toolboxList->count(); i++)
759 toolboxes << toolboxList->item(i)->text();
762 QStringList toolbars;
763 for (
int i=0; i < toolbarList->count(); i++)
764 toolbars << toolbarList->item(i)->text();
767 QStringList contextmenus;
768 for (
int i=0; i < contextMenuList->count(); i++)
769 contextmenus << contextMenuList->item(i)->text();
771 bool createNewMode =
false;
773 QString message = tr(
"You cannot change predefined modes.\n" 774 "Please enter a new Name for the mode.");
777 if ( ! modes_[
id]->custom ) {
778 createNewMode =
true;
781 int ret = QMessageBox::warning(
this,
782 tr(
"View Mode exists"),
783 tr(
"View Mode already exists. Do you want to overwrite it?"),
784 QMessageBox::Yes|QMessageBox::No,
786 if (ret == QMessageBox::No) {
787 message = tr(
"New name for view mode:");
788 createNewMode =
true;
793 if ( createNewMode ) {
797 QString name = QInputDialog::getText(
this, tr(
"Save view Mode"),
802 if (!ok || name.isEmpty()) {
803 std::cerr <<
"Illegal or no name given!" << std::endl;
808 for (
int i=0; i < modes_.size(); i++)
809 if (modes_[i]->name == name){
810 QMessageBox::warning(
this, tr(
"Save View Mode"), tr(
"Cannot Save ViewMode.\nName already taken by a different mode."), QMessageBox::Ok);
814 emit
saveMode(name,
true, toolboxes, toolbars, contextmenus);
817 emit
saveMode(modes_[
id]->name,
true, toolboxes, toolbars, contextmenus);
818 show(modes_[
id]->name);
847 viewModeList->clear();
848 for (
int i=0; i < modes_.size(); i++){
849 QListWidgetItem *item =
new QListWidgetItem(viewModeList);
850 item->setTextAlignment(Qt::AlignHCenter);
851 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
853 QFile iconFile( OpenFlipper::Options::iconDirStr() + QDir::separator () + modes_[i]->icon );
855 if ( iconFile.exists() )
856 item->setIcon( QIcon(iconFile.fileName()) );
858 iconFile.setFileName( OpenFlipper::Options::configDirStr() + QDir::separator() +
"Icons" + QDir::separator() + modes_[i]->icon );
859 if ( iconFile.exists() )
860 item->setIcon( QIcon(iconFile.fileName()) );
862 item->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + QDir::separator () +
"Unknown.png") );
863 std::cerr <<
"Unable to find icon file! " << iconFile.fileName().toStdString() << std::endl;
867 item->setText(modes_[i]->name);
869 if (modes_[i]->custom)
870 viewModeList->item(i)->setForeground( QBrush(QColor(0,0,150) ) );
872 viewModeList->item(i)->setForeground( QBrush(QColor(0,0,0) ) );
876 viewModeList->setCurrentRow(0);
878 for (
int i=0; i < viewModeList->count(); i++)
879 if (viewModeList->item(i)->text() == _lastMode)
880 viewModeList->setCurrentRow(i);
882 removeButton->setEnabled(
false);
894 if (viewModeList->selectedItems().count() > 0){
895 for (
int i=0; i < modes_.size(); i++)
896 if (modes_[i]->name == viewModeList->currentItem()->text()){
897 removeButton->setEnabled(modes_[i]->custom);
void slotMoveToolboxUp()
Move Toolbox up.
void slotUsedToolbarContextMenu(const QPoint &_pos)
Context Menu Used Toolbars.
void slotMoveToolboxDown()
Move Toolbox down.
viewModeWidget(const QVector< ViewMode * > &_modes, QWidget *parent=0)
Constructor.
Add normals to mesh item (vertices/faces)
void show(QString _lastMode)
overloaded show function
void slotSetIcon()
Context menu slot to change the icon for a view mode.
void slotCopyMode()
Button slot to copy the selected view mode.
void slotRightArrowToolbox()
remove Toolboxes from Mode
void slotAvailableContextMenuContextMenu(const QPoint &_pos)
Context Menu Available ContextMenus.
void slotModeContextMenu(const QPoint &_pos)
Context Menu View Modes.
void slotModeClicked(QModelIndex _id)
Slot for updating removeButton when new mode is selected.
void slotRightArrowContextMenu()
remove ContextMenu from Mode
void slotAvailableToolboxContextMenu(const QPoint &_pos)
Context Menu Available Toolboxes.
void slotSetAllWidgets()
Update list views.
void slotChangeView()
Slot for changing the current view to currently configured one.
void slotRightArrowToolbar()
remove Toolbars from Mode
void slotMoveContextMenuUp()
Move ContextMenu up.
void saveMode(QString _name, bool _custom, QStringList _toolboxWidgets, QStringList _toolbars, QStringList _contextmenus)
saves the given mode
void changeView(QString _mode, QStringList _toolboxWidgets, QStringList _toolbars, QStringList _contextmenus)
Changes the view mode to the currently configured one.
void slotAvailableToolbarContextMenu(const QPoint &_pos)
Context Menu Available Toolbars.
void slotModeChanged(QString _mode)
Slot for updating removeButton when new mode is selected.
void slotMoveContextMenuDown()
Move Toolbox down.
void slotUsedContextMenuContextMenu(const QPoint &_pos)
Context Menu Used ContextMenus.
void slotLeftArrowToolbar()
add Toolbars to Mode
void slotLeftArrowContextMenu()
add ContextMenu to Mode
void slotLeftArrowToolbox()
add Toolboxes to Mode
void slotSaveMode()
Save the current view mode configuration.
void slotUsedToolboxContextMenu(const QPoint &_pos)
Context Menu Used Toolboxes.
void removeMode(QString _name)
This signal is emitted to remove a mode.
void slotRemoveMode()
Button slot to remove the selected view mode.
void slotAddMode()
Button slot to add a new empty mode.