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);
333 if ( !modes_.empty() ) {
334 QStringList allToolboxes = modes_[0]->visibleToolboxes;
335 QStringList allToolbars = modes_[0]->visibleToolbars;
336 QStringList allContextMenus = modes_[0]->visibleContextMenus;
338 QStringList availableToolboxList;
339 QStringList availableToolbarList;
340 QStringList availableContextMenuList;
342 for (
int i = 0; i < allToolboxes.size(); ++i ) {
343 if ( ! toolboxes.contains(allToolboxes[i]) )
344 availableToolboxList.push_back(allToolboxes[i]);
347 for (
int i = 0; i < allToolbars.size(); ++i ) {
348 if ( ! toolbars.contains(allToolbars[i]) )
349 availableToolbarList.push_back(allToolbars[i]);
352 for (
int i = 0; i < allContextMenus.size(); ++i ) {
353 if ( ! contextmenus.contains(allContextMenus[i]) )
354 availableContextMenuList.push_back(allContextMenus[i]);
357 availableToolboxes->addItems(availableToolboxList);
358 availableToolbars->addItems(availableToolbarList);
359 availableContextMenus->addItems(availableContextMenuList);
362 std::cerr <<
"Mode not found!" << std::endl;
375 if (toolboxList->itemAt(_pos)){
379 if ( toolbarList->selectedItems().count() != 0 )
382 menu.exec(toolbarList->mapToGlobal( _pos) );
389 if (availableToolbars->itemAt(_pos)){
393 if ( availableToolbars->selectedItems().count() != 0 )
396 menu.exec(availableToolbars->mapToGlobal( _pos) );
407 if (toolboxList->itemAt(_pos)){
411 if (toolboxList->selectedItems().count() == 1){
417 if ( toolboxList->selectedItems().count() != 0 )
420 menu.exec(toolboxList->mapToGlobal( _pos) );
427 if (availableToolboxes->itemAt(_pos)){
431 if ( availableToolboxes->selectedItems().count() != 0 )
434 menu.exec(availableToolboxes->mapToGlobal( _pos) );
445 if (contextMenuList->itemAt(_pos)){
449 if (contextMenuList->selectedItems().count() == 1){
455 if ( contextMenuList->selectedItems().count() != 0 )
458 menu.exec(contextMenuList->mapToGlobal( _pos) );
465 if (availableContextMenus->itemAt(_pos)){
469 if ( availableContextMenus->selectedItems().count() != 0 )
472 menu.exec(availableContextMenus->mapToGlobal( _pos) );
481 QList<QListWidgetItem *> selectedItems = toolbarList->selectedItems ();
482 for (
int i = 0 ; i < selectedItems.size(); ++i )
483 availableToolbars->addItem(selectedItems[i]->text());
485 qDeleteAll(selectedItems);
489 QList<QListWidgetItem *> selectedItems = availableToolbars->selectedItems ();
490 for (
int i = 0 ; i < selectedItems.size(); ++i )
491 toolbarList->addItem(selectedItems[i]->text());
493 qDeleteAll(selectedItems);
501 QList<QListWidgetItem *> selectedItems = toolboxList->selectedItems ();
502 for (
int i = 0 ; i < selectedItems.size(); ++i )
503 availableToolboxes->addItem(selectedItems[i]->text());
505 qDeleteAll(selectedItems);
509 QList<QListWidgetItem *> selectedItems = availableToolboxes->selectedItems ();
510 for (
int i = 0 ; i < selectedItems.size(); ++i )
511 toolboxList->addItem(selectedItems[i]->text());
513 qDeleteAll(selectedItems);
519 if (toolboxList->selectedItems().count() == 1){
520 if (toolboxList->currentRow() == 0)
return;
522 QString item = toolboxList->currentItem()->text();
523 int oldRow = toolboxList->currentRow();
525 for (
int i=0; i < toolboxList->count(); i++)
526 widgets << toolboxList->item(i)->text();
529 QString last = widgets[0];
530 for (
int i=1; i < widgets.size(); i++){
531 if (widgets[i] == item){
538 toolboxList->clear();
539 toolboxList->addItems(widgets);
541 toolboxList->setCurrentRow(oldRow-1);
547 if (toolboxList->selectedItems().count() == 1){
548 if (toolboxList->currentRow() == toolboxList->count()-1)
return;
550 QString item = toolboxList->currentItem()->text();
551 int oldRow = toolboxList->currentRow();
553 for (
int i=0; i < toolboxList->count(); i++)
554 widgets << toolboxList->item(i)->text();
557 QString last = widgets[widgets.size()-1];
558 for (
int i=widgets.size()-2; i >= 0; i--){
559 if (widgets[i] == item){
566 toolboxList->clear();
567 toolboxList->addItems(widgets);
569 toolboxList->setCurrentRow(oldRow+1);
578 QList<QListWidgetItem *> selectedItems = contextMenuList->selectedItems ();
579 for (
int i = 0 ; i < selectedItems.size(); ++i )
580 availableContextMenus->addItem(selectedItems[i]->text());
582 qDeleteAll(selectedItems);
586 QList<QListWidgetItem *> selectedItems = availableContextMenus->selectedItems ();
587 for (
int i = 0 ; i < selectedItems.size(); ++i )
588 contextMenuList->addItem(selectedItems[i]->text());
590 qDeleteAll(selectedItems);
596 if (contextMenuList->selectedItems().count() == 1){
597 if (contextMenuList->currentRow() == 0)
return;
599 QString item = contextMenuList->currentItem()->text();
600 int oldRow = contextMenuList->currentRow();
602 for (
int i=0; i < contextMenuList->count(); i++)
603 widgets << contextMenuList->item(i)->text();
606 QString last = widgets[0];
607 for (
int i=1; i < widgets.size(); i++){
608 if (widgets[i] == item){
615 contextMenuList->clear();
616 contextMenuList->addItems(widgets);
618 contextMenuList->setCurrentRow(oldRow-1);
624 if (contextMenuList->selectedItems().count() == 1){
625 if (contextMenuList->currentRow() == contextMenuList->count()-1)
return;
627 QString item = contextMenuList->currentItem()->text();
628 int oldRow = contextMenuList->currentRow();
630 for (
int i=0; i < contextMenuList->count(); i++)
631 widgets << contextMenuList->item(i)->text();
634 QString last = widgets[widgets.size()-1];
635 for (
int i=widgets.size()-2; i >= 0; i--){
636 if (widgets[i] == item){
643 contextMenuList->clear();
644 contextMenuList->addItems(widgets);
646 contextMenuList->setCurrentRow(oldRow+1);
659 QStringList toolboxes;
660 for (
int i=0; i < toolboxList->count(); i++)
661 toolboxes << toolboxList->item(i)->text();
664 QStringList toolbars;
665 for (
int i=0; i < toolbarList->count(); i++)
666 toolbars << toolbarList->item(i)->text();
669 QStringList contextmenus;
670 for (
int i=0; i < contextMenuList->count(); i++)
671 contextmenus << contextMenuList->item(i)->text();
675 if (viewModeList->selectedItems().size() > 0)
676 mode = viewModeList->selectedItems()[0]->text();
683 if ( viewModeList->selectedItems().count() > 0)
684 for (
int i=0; i < modes_.size(); i++)
685 if (modes_[i]->name == viewModeList->currentItem()->text()){
691 std::cerr <<
"Currently selected Mode not found?!" << std::endl;
695 bool matching =
true;
697 if ( modes_[
id]->visibleToolboxes.size() == toolboxes.size() ) {
698 for (
int i = 0 ; i < modes_[id]->visibleToolboxes.size(); ++i )
699 if ( modes_[
id]->visibleToolboxes[i] != toolboxes[i] )
706 if ( modes_[
id]->visibleToolbars.size() == toolbars.size() ) {
707 for (
int i = 0 ; i < modes_[id]->visibleToolbars.size(); ++i )
708 if ( modes_[
id]->visibleToolbars[i] != toolbars[i] )
715 if ( modes_[
id]->visibleContextMenus.size() == contextmenus.size() ) {
716 for (
int i = 0 ; i < modes_[id]->visibleContextMenus.size(); ++i )
717 if ( modes_[
id]->visibleContextMenus[i] != contextmenus[i] )
724 int ret = QMessageBox::warning(
this,
725 tr(
"Mode has been changed!"),
726 tr(
"You changed the view mode configuration. Do you want to save it?"),
727 QMessageBox::Yes|QMessageBox::No,
729 if (ret == QMessageBox::Yes)
734 emit
changeView(mode,toolboxes,toolbars,contextmenus);
742 if ( viewModeList->selectedItems().count() > 0)
743 for (
int i=0; i < modes_.size(); i++)
744 if (modes_[i]->name == viewModeList->currentItem()->text()){
750 std::cerr <<
"Mode Not found in slotSaveMode" << std::endl;
755 QStringList toolboxes;
756 for (
int i=0; i < toolboxList->count(); i++)
757 toolboxes << toolboxList->item(i)->text();
760 QStringList toolbars;
761 for (
int i=0; i < toolbarList->count(); i++)
762 toolbars << toolbarList->item(i)->text();
765 QStringList contextmenus;
766 for (
int i=0; i < contextMenuList->count(); i++)
767 contextmenus << contextMenuList->item(i)->text();
769 bool createNewMode =
false;
771 QString message = tr(
"You cannot change predefined modes.\n"
772 "Please enter a new Name for the mode.");
775 if ( ! modes_[
id]->custom ) {
776 createNewMode =
true;
779 int ret = QMessageBox::warning(
this,
780 tr(
"View Mode exists"),
781 tr(
"View Mode already exists. Do you want to overwrite it?"),
782 QMessageBox::Yes|QMessageBox::No,
784 if (ret == QMessageBox::No) {
785 message = tr(
"New name for view mode:");
786 createNewMode =
true;
791 if ( createNewMode ) {
795 QString name = QInputDialog::getText(
this, tr(
"Save view Mode"),
800 if (!ok || name.isEmpty()) {
801 std::cerr <<
"Illegal or no name given!" << std::endl;
806 for (
int i=0; i < modes_.size(); i++)
807 if (modes_[i]->name == name){
808 QMessageBox::warning(
this, tr(
"Save View Mode"), tr(
"Cannot Save ViewMode.\nName already taken by a different mode."), QMessageBox::Ok);
812 emit
saveMode(name,
true, toolboxes, toolbars, contextmenus);
815 emit
saveMode(modes_[
id]->name,
true, toolboxes, toolbars, contextmenus);
816 show(modes_[
id]->name);
845 viewModeList->clear();
846 for (
int i=0; i < modes_.size(); i++){
847 QListWidgetItem *item =
new QListWidgetItem(viewModeList);
848 item->setTextAlignment(Qt::AlignHCenter);
849 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
851 QFile iconFile( OpenFlipper::Options::iconDirStr() + QDir::separator () + modes_[i]->icon );
853 if ( iconFile.exists() )
854 item->setIcon( QIcon(iconFile.fileName()) );
856 iconFile.setFileName( OpenFlipper::Options::configDirStr() + QDir::separator() +
"Icons" + QDir::separator() + modes_[i]->icon );
857 if ( iconFile.exists() )
858 item->setIcon( QIcon(iconFile.fileName()) );
860 item->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + QDir::separator () +
"Unknown.png") );
861 std::cerr <<
"Unable to find icon file! " << iconFile.fileName().toStdString() << std::endl;
865 item->setText(modes_[i]->name);
867 if (modes_[i]->custom)
868 viewModeList->item(i)->setForeground( QBrush(QColor(0,0,150) ) );
870 viewModeList->item(i)->setForeground( QBrush(QColor(0,0,0) ) );
874 viewModeList->setCurrentRow(0);
876 for (
int i=0; i < viewModeList->count(); i++)
877 if (viewModeList->item(i)->text() == _lastMode)
878 viewModeList->setCurrentRow(i);
880 removeButton->setEnabled(
false);
892 if (viewModeList->selectedItems().count() > 0){
893 for (
int i=0; i < modes_.size(); i++)
894 if (modes_[i]->name == viewModeList->currentItem()->text()){
895 removeButton->setEnabled(modes_[i]->custom);
void slotModeContextMenu(const QPoint &_pos)
Context Menu View Modes.
void slotMoveToolboxDown()
Move Toolbox down.
viewModeWidget(const QVector< ViewMode * > &_modes, QWidget *parent=0)
Constructor.
void changeView(QString _mode, QStringList _toolboxWidgets, QStringList _toolbars, QStringList _contextmenus)
Changes the view mode to the currently configured one.
void slotRemoveMode()
Button slot to remove the selected view mode.
void show(QString _lastMode)
overloaded show function
void slotMoveToolboxUp()
Move Toolbox up.
void slotLeftArrowToolbox()
add Toolboxes to Mode
void slotAvailableToolboxContextMenu(const QPoint &_pos)
Context Menu Available Toolboxes.
void slotMoveContextMenuDown()
Move Toolbox down.
void slotRightArrowToolbar()
remove Toolbars from Mode
void slotUsedToolbarContextMenu(const QPoint &_pos)
Context Menu Used Toolbars.
void slotLeftArrowContextMenu()
add ContextMenu to Mode
void slotUsedContextMenuContextMenu(const QPoint &_pos)
Context Menu Used ContextMenus.
void slotMoveContextMenuUp()
Move ContextMenu up.
void slotRightArrowContextMenu()
remove ContextMenu from Mode
void slotSetAllWidgets()
Update list views.
void slotSaveMode()
Save the current view mode configuration.
void slotAvailableContextMenuContextMenu(const QPoint &_pos)
Context Menu Available ContextMenus.
void slotChangeView()
Slot for changing the current view to currently configured one.
void slotRightArrowToolbox()
remove Toolboxes from Mode
void saveMode(QString _name, bool _custom, QStringList _toolboxWidgets, QStringList _toolbars, QStringList _contextmenus)
saves the given mode
void slotAvailableToolbarContextMenu(const QPoint &_pos)
Context Menu Available Toolbars.
void slotSetIcon()
Context menu slot to change the icon for a view mode.
void slotCopyMode()
Button slot to copy the selected view mode.
Add normals to mesh item (vertices/faces)
void removeMode(QString _name)
This signal is emitted to remove a mode.
void slotUsedToolboxContextMenu(const QPoint &_pos)
Context Menu Used Toolboxes.
void slotAddMode()
Button slot to add a new empty mode.
void slotLeftArrowToolbar()
add Toolbars to Mode
void slotModeClicked(QModelIndex _id)
Slot for updating removeButton when new mode is selected.
void slotModeChanged(QString _mode)
Slot for updating removeButton when new mode is selected.