47 #include "viewModeWidget.hh" 58 connect(viewModeList, SIGNAL(itemSelectionChanged()),
this, SLOT(
slotSetAllWidgets()));
64 connect(viewModeList, SIGNAL(currentTextChanged (QString)),
this, SLOT(
slotModeChanged(QString)) );
65 connect(viewModeList, SIGNAL(clicked (QModelIndex)),
this, SLOT(
slotModeClicked(QModelIndex)) );
70 connect(removeButton, SIGNAL(clicked()),
this, SLOT(
slotRemoveMode()));
71 connect(copyButton, SIGNAL(clicked()),
this, SLOT(
slotCopyMode()));
72 connect(addButton, SIGNAL(clicked()),
this, SLOT(
slotAddMode()));
75 viewModeList->setContextMenuPolicy(Qt::CustomContextMenu);
76 connect(viewModeList ,SIGNAL(customContextMenuRequested (
const QPoint & ) ),
81 toolbarList->setContextMenuPolicy(Qt::CustomContextMenu);
82 availableToolbars->setContextMenuPolicy(Qt::CustomContextMenu);
83 connect(toolbarList ,SIGNAL(customContextMenuRequested (
const QPoint & ) ),
85 connect(availableToolbars ,SIGNAL(customContextMenuRequested (
const QPoint & ) ),
90 toolboxList->setContextMenuPolicy(Qt::CustomContextMenu);
91 availableToolboxes->setContextMenuPolicy(Qt::CustomContextMenu);
92 connect(toolboxList ,SIGNAL(customContextMenuRequested (
const QPoint & ) ),
94 connect(availableToolboxes ,SIGNAL(customContextMenuRequested (
const QPoint & ) ),
99 contextMenuList->setContextMenuPolicy(Qt::CustomContextMenu);
100 availableContextMenus->setContextMenuPolicy(Qt::CustomContextMenu);
101 connect(contextMenuList ,SIGNAL(customContextMenuRequested (
const QPoint & ) ),
103 connect(availableContextMenus ,SIGNAL(customContextMenuRequested (
const QPoint & ) ),
109 rightArrowToolbar->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-right.png" ) );
111 leftArrowToolbar->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-left.png" ) );
116 rightArrowToolbox->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-right.png" ) );
118 leftArrowToolbox->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-left.png" ) );
121 upButtonToolbox->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-up.png" ) );
123 downButtonToolbox->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-down.png" ) );
128 rightArrowContextMenu->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-right.png" ) );
130 leftArrowContextMenu->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-left.png" ) );
133 upButtonContextMenu->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-up.png" ) );
135 downButtonContextMenu->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + OpenFlipper::Options::dirSeparator() +
"arrow-down.png" ) );
141 connect(okButton, SIGNAL(clicked()),
this, SLOT(
slotChangeView()));
142 connect(cancelButton, SIGNAL(clicked()),
this, SLOT(close()));
143 connect(saveButton, SIGNAL(clicked()),
this, SLOT(
slotSaveMode()));
151 emit
removeMode( viewModeList->currentItem()->text() );
152 QListWidgetItem* item = viewModeList->takeItem( viewModeList->currentRow() );
160 if ( viewModeList->selectedItems().count() > 0)
161 for (
int i=0; i < modes_.size(); i++)
162 if (modes_[i]->name == viewModeList->currentItem()->text()){
168 std::cerr <<
"Currently selected Mode not found?!" << std::endl;
174 QString name = QInputDialog::getText(
this, tr(
"Copy View Mode"),
175 tr(
"Please enter a name for the new View Mode"), QLineEdit::Normal,
179 if (!ok || name.isEmpty()) {
180 QMessageBox::warning(
this, tr(
"Copy View Mode"), tr(
"Please enter a Name"), QMessageBox::Ok);
185 for (
int i=0; i < modes_.size(); i++)
186 if (modes_[i]->name == name){
187 QMessageBox::warning(
this, tr(
"Copy View Mode"), tr(
"Cannot Copy ViewMode. \nNew Name already in use for a different mode."), QMessageBox::Ok);
191 emit
saveMode(name,
true, modes_[
id]->visibleToolboxes, modes_[
id]->visibleToolbars, modes_[
id]->visibleContextMenus);
193 QListWidgetItem *item =
new QListWidgetItem(viewModeList);
194 item->setTextAlignment(Qt::AlignHCenter);
195 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
196 item->setIcon(QIcon(OpenFlipper::Options::iconDirStr() + QDir::separator () +
"Unknown.png"));
199 item->setForeground( QBrush(QColor(0,0,150) ) );
208 QString name = QInputDialog::getText(
this, tr(
"Add View Mode"),
209 tr(
"Please enter a name for the new View Mode"), QLineEdit::Normal,
213 if (!ok || name.isEmpty()) {
214 QMessageBox::warning(
this, tr(
"Add View Mode"), tr(
"Please enter a Name"), QMessageBox::Ok);
219 for (
int i=0; i < modes_.size(); i++)
220 if (modes_[i]->name == name){
221 QMessageBox::warning(
this, tr(
"Add View Mode"), tr(
"Cannot Add ViewMode. \nNew Name already in use for a different mode."), QMessageBox::Ok);
225 emit
saveMode(name,
true, QStringList(), QStringList(), modes_[0]->visibleContextMenus);
227 QListWidgetItem *item =
new QListWidgetItem(viewModeList);
228 item->setTextAlignment(Qt::AlignHCenter);
229 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
230 item->setIcon(QIcon(OpenFlipper::Options::iconDirStr() + QDir::separator () +
"Unknown.png"));
233 item->setForeground( QBrush(QColor(0,0,150) ) );
243 if (viewModeList->itemAt(_pos)){
247 menu.addAction(tr(
"Remove Mode"),
this, SLOT (
slotRemoveMode() ));
248 menu.addAction(tr(
"Copy Mode"),
this, SLOT (
slotCopyMode() ));
249 menu.addAction(tr(
"Change Icon"),
this, SLOT (
slotSetIcon() ));
252 for (
int i=0; i < modes_.size(); i++)
253 if (modes_[i]->name == viewModeList->currentItem()->text()){
254 menu.actions()[0]->setEnabled(modes_[i]->custom);
255 menu.actions()[2]->setEnabled(modes_[i]->custom);
259 menu.exec(viewModeList->mapToGlobal( _pos) );
266 for (
int i=0; i < modes_.size(); i++)
267 if (modes_[i]->name == viewModeList->currentItem()->text()){
273 std::cerr <<
"Unable to find Mode viewModeWidget::slotSetIcon()" << std::endl;
278 QString fileName = QFileDialog::getOpenFileName (
this, tr(
"Select Image for view Mode ( best size : 150x150px )"), QString(), tr(
"Images (*.png *.xpm *.jpg)") );
280 QFile file(fileName);
281 QFileInfo fileInfo(file);
283 if ( ! file.exists() )
287 file.copy(OpenFlipper::Options::configDirStr() + QDir::separator() +
"Icons" + QDir::separator() +
"viewMode_" + fileInfo.fileName() );
289 modes_[id]->icon =
"viewMode_" + fileInfo.fileName();
291 show(modes_[
id]->name);
298 toolboxList->clear();
299 toolbarList->clear();
300 contextMenuList->clear();
301 availableToolboxes->clear();
302 availableToolbars->clear();
303 availableContextMenus->clear();
305 QStringList toolboxes;
306 QStringList toolbars;
307 QStringList contextmenus;
310 for (
int m=0; m < viewModeList->selectedItems().size(); m++) {
313 for (
int i=0; i < modes_.size(); i++) {
314 if ( modes_[i]->name == (viewModeList->selectedItems()[m])->text() ) {
315 toolboxes = modes_[i]->visibleToolboxes;
316 toolbars = modes_[i]->visibleToolbars;
317 contextmenus = modes_[i]->visibleContextMenus;
318 if (contextmenus.contains(
"ALL_THAT_EXIST"))
319 contextmenus = modes_[0]->visibleContextMenus;
320 toolboxList->addItems(toolboxes);
321 toolbarList->addItems(toolbars);
322 contextMenuList->addItems(contextmenus);
329 if ( !modes_.empty() ) {
330 QStringList allToolboxes = modes_[0]->visibleToolboxes;
331 QStringList allToolbars = modes_[0]->visibleToolbars;
332 QStringList allContextMenus = modes_[0]->visibleContextMenus;
334 QStringList availableToolboxList;
335 QStringList availableToolbarList;
336 QStringList availableContextMenuList;
338 for (
int i = 0; i < allToolboxes.size(); ++i ) {
339 if ( ! toolboxes.contains(allToolboxes[i]) )
340 availableToolboxList.push_back(allToolboxes[i]);
343 for (
int i = 0; i < allToolbars.size(); ++i ) {
344 if ( ! toolbars.contains(allToolbars[i]) )
345 availableToolbarList.push_back(allToolbars[i]);
348 for (
int i = 0; i < allContextMenus.size(); ++i ) {
349 if ( ! contextmenus.contains(allContextMenus[i]) )
350 availableContextMenuList.push_back(allContextMenus[i]);
353 availableToolboxes->addItems(availableToolboxList);
354 availableToolbars->addItems(availableToolbarList);
355 availableContextMenus->addItems(availableContextMenuList);
358 std::cerr <<
"Mode not found!" << std::endl;
371 if (toolboxList->itemAt(_pos)){
375 if ( toolbarList->selectedItems().count() != 0 )
378 menu.exec(toolbarList->mapToGlobal( _pos) );
385 if (availableToolbars->itemAt(_pos)){
389 if ( availableToolbars->selectedItems().count() != 0 )
392 menu.exec(availableToolbars->mapToGlobal( _pos) );
403 if (toolboxList->itemAt(_pos)){
407 if (toolboxList->selectedItems().count() == 1){
413 if ( toolboxList->selectedItems().count() != 0 )
416 menu.exec(toolboxList->mapToGlobal( _pos) );
423 if (availableToolboxes->itemAt(_pos)){
427 if ( availableToolboxes->selectedItems().count() != 0 )
430 menu.exec(availableToolboxes->mapToGlobal( _pos) );
441 if (contextMenuList->itemAt(_pos)){
445 if (contextMenuList->selectedItems().count() == 1){
451 if ( contextMenuList->selectedItems().count() != 0 )
454 menu.exec(contextMenuList->mapToGlobal( _pos) );
461 if (availableContextMenus->itemAt(_pos)){
465 if ( availableContextMenus->selectedItems().count() != 0 )
468 menu.exec(availableContextMenus->mapToGlobal( _pos) );
477 QList<QListWidgetItem *> selectedItems = toolbarList->selectedItems ();
478 for (
int i = 0 ; i < selectedItems.size(); ++i )
479 availableToolbars->addItem(selectedItems[i]->text());
481 qDeleteAll(selectedItems);
485 QList<QListWidgetItem *> selectedItems = availableToolbars->selectedItems ();
486 for (
int i = 0 ; i < selectedItems.size(); ++i )
487 toolbarList->addItem(selectedItems[i]->text());
489 qDeleteAll(selectedItems);
497 QList<QListWidgetItem *> selectedItems = toolboxList->selectedItems ();
498 for (
int i = 0 ; i < selectedItems.size(); ++i )
499 availableToolboxes->addItem(selectedItems[i]->text());
501 qDeleteAll(selectedItems);
505 QList<QListWidgetItem *> selectedItems = availableToolboxes->selectedItems ();
506 for (
int i = 0 ; i < selectedItems.size(); ++i )
507 toolboxList->addItem(selectedItems[i]->text());
509 qDeleteAll(selectedItems);
515 if (toolboxList->selectedItems().count() == 1){
516 if (toolboxList->currentRow() == 0)
return;
518 QString item = toolboxList->currentItem()->text();
519 int oldRow = toolboxList->currentRow();
521 for (
int i=0; i < toolboxList->count(); i++)
522 widgets << toolboxList->item(i)->text();
525 QString last = widgets[0];
526 for (
int i=1; i < widgets.size(); i++){
527 if (widgets[i] == item){
534 toolboxList->clear();
535 toolboxList->addItems(widgets);
537 toolboxList->setCurrentRow(oldRow-1);
543 if (toolboxList->selectedItems().count() == 1){
544 if (toolboxList->currentRow() == toolboxList->count()-1)
return;
546 QString item = toolboxList->currentItem()->text();
547 int oldRow = toolboxList->currentRow();
549 for (
int i=0; i < toolboxList->count(); i++)
550 widgets << toolboxList->item(i)->text();
553 QString last = widgets[widgets.size()-1];
554 for (
int i=widgets.size()-2; i >= 0; i--){
555 if (widgets[i] == item){
562 toolboxList->clear();
563 toolboxList->addItems(widgets);
565 toolboxList->setCurrentRow(oldRow+1);
574 QList<QListWidgetItem *> selectedItems = contextMenuList->selectedItems ();
575 for (
int i = 0 ; i < selectedItems.size(); ++i )
576 availableContextMenus->addItem(selectedItems[i]->text());
578 qDeleteAll(selectedItems);
582 QList<QListWidgetItem *> selectedItems = availableContextMenus->selectedItems ();
583 for (
int i = 0 ; i < selectedItems.size(); ++i )
584 contextMenuList->addItem(selectedItems[i]->text());
586 qDeleteAll(selectedItems);
592 if (contextMenuList->selectedItems().count() == 1){
593 if (contextMenuList->currentRow() == 0)
return;
595 QString item = contextMenuList->currentItem()->text();
596 int oldRow = contextMenuList->currentRow();
598 for (
int i=0; i < contextMenuList->count(); i++)
599 widgets << contextMenuList->item(i)->text();
602 QString last = widgets[0];
603 for (
int i=1; i < widgets.size(); i++){
604 if (widgets[i] == item){
611 contextMenuList->clear();
612 contextMenuList->addItems(widgets);
614 contextMenuList->setCurrentRow(oldRow-1);
620 if (contextMenuList->selectedItems().count() == 1){
621 if (contextMenuList->currentRow() == contextMenuList->count()-1)
return;
623 QString item = contextMenuList->currentItem()->text();
624 int oldRow = contextMenuList->currentRow();
626 for (
int i=0; i < contextMenuList->count(); i++)
627 widgets << contextMenuList->item(i)->text();
630 QString last = widgets[widgets.size()-1];
631 for (
int i=widgets.size()-2; i >= 0; i--){
632 if (widgets[i] == item){
639 contextMenuList->clear();
640 contextMenuList->addItems(widgets);
642 contextMenuList->setCurrentRow(oldRow+1);
655 QStringList toolboxes;
656 for (
int i=0; i < toolboxList->count(); i++)
657 toolboxes << toolboxList->item(i)->text();
660 QStringList toolbars;
661 for (
int i=0; i < toolbarList->count(); i++)
662 toolbars << toolbarList->item(i)->text();
665 QStringList contextmenus;
666 for (
int i=0; i < contextMenuList->count(); i++)
667 contextmenus << contextMenuList->item(i)->text();
671 if (viewModeList->selectedItems().size() > 0)
672 mode = viewModeList->selectedItems()[0]->text();
679 if ( viewModeList->selectedItems().count() > 0)
680 for (
int i=0; i < modes_.size(); i++)
681 if (modes_[i]->name == viewModeList->currentItem()->text()){
687 std::cerr <<
"Currently selected Mode not found?!" << std::endl;
691 bool matching =
true;
693 if ( modes_[
id]->visibleToolboxes.size() == toolboxes.size() ) {
694 for (
int i = 0 ; i < modes_[id]->visibleToolboxes.size(); ++i )
695 if ( modes_[
id]->visibleToolboxes[i] != toolboxes[i] )
702 if ( modes_[
id]->visibleToolbars.size() == toolbars.size() ) {
703 for (
int i = 0 ; i < modes_[id]->visibleToolbars.size(); ++i )
704 if ( modes_[
id]->visibleToolbars[i] != toolbars[i] )
711 if ( modes_[
id]->visibleContextMenus.size() == contextmenus.size() ) {
712 for (
int i = 0 ; i < modes_[id]->visibleContextMenus.size(); ++i )
713 if ( modes_[
id]->visibleContextMenus[i] != contextmenus[i] )
720 int ret = QMessageBox::warning(
this,
721 tr(
"Mode has been changed!"),
722 tr(
"You changed the view mode configuration. Do you want to save it?"),
723 QMessageBox::Yes|QMessageBox::No,
725 if (ret == QMessageBox::Yes)
730 emit
changeView(mode,toolboxes,toolbars,contextmenus);
738 if ( viewModeList->selectedItems().count() > 0)
739 for (
int i=0; i < modes_.size(); i++)
740 if (modes_[i]->name == viewModeList->currentItem()->text()){
746 std::cerr <<
"Mode Not found in slotSaveMode" << std::endl;
751 QStringList toolboxes;
752 for (
int i=0; i < toolboxList->count(); i++)
753 toolboxes << toolboxList->item(i)->text();
756 QStringList toolbars;
757 for (
int i=0; i < toolbarList->count(); i++)
758 toolbars << toolbarList->item(i)->text();
761 QStringList contextmenus;
762 for (
int i=0; i < contextMenuList->count(); i++)
763 contextmenus << contextMenuList->item(i)->text();
765 bool createNewMode =
false;
767 QString message = tr(
"You cannot change predefined modes.\n" 768 "Please enter a new Name for the mode.");
771 if ( ! modes_[
id]->custom ) {
772 createNewMode =
true;
775 int ret = QMessageBox::warning(
this,
776 tr(
"View Mode exists"),
777 tr(
"View Mode already exists. Do you want to overwrite it?"),
778 QMessageBox::Yes|QMessageBox::No,
780 if (ret == QMessageBox::No) {
781 message = tr(
"New name for view mode:");
782 createNewMode =
true;
787 if ( createNewMode ) {
791 QString name = QInputDialog::getText(
this, tr(
"Save view Mode"),
792 message, QLineEdit::Normal,
796 if (!ok || name.isEmpty()) {
797 std::cerr <<
"Illegal or no name given!" << std::endl;
802 for (
int i=0; i < modes_.size(); i++)
803 if (modes_[i]->name == name){
804 QMessageBox::warning(
this, tr(
"Save View Mode"), tr(
"Cannot Save ViewMode.\nName already taken by a different mode."), QMessageBox::Ok);
808 emit
saveMode(name,
true, toolboxes, toolbars, contextmenus);
811 emit
saveMode(modes_[
id]->name,
true, toolboxes, toolbars, contextmenus);
812 show(modes_[
id]->name);
841 viewModeList->clear();
842 for (
int i=0; i < modes_.size(); i++){
843 QListWidgetItem *item =
new QListWidgetItem(viewModeList);
844 item->setTextAlignment(Qt::AlignHCenter);
845 item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
847 QFile iconFile( OpenFlipper::Options::iconDirStr() + QDir::separator () + modes_[i]->icon );
849 if ( iconFile.exists() )
850 item->setIcon( QIcon(iconFile.fileName()) );
852 iconFile.setFileName( OpenFlipper::Options::configDirStr() + QDir::separator() +
"Icons" + QDir::separator() + modes_[i]->icon );
853 if ( iconFile.exists() )
854 item->setIcon( QIcon(iconFile.fileName()) );
856 item->setIcon( QIcon(OpenFlipper::Options::iconDirStr() + QDir::separator () +
"Unknown.png") );
857 std::cerr <<
"Unable to find icon file! " << iconFile.fileName().toStdString() << std::endl;
861 item->setText(modes_[i]->name);
863 if (modes_[i]->custom)
864 viewModeList->item(i)->setForeground( QBrush(QColor(0,0,150) ) );
866 viewModeList->item(i)->setForeground( QBrush(QColor(0,0,0) ) );
870 viewModeList->setCurrentRow(0);
872 for (
int i=0; i < viewModeList->count(); i++)
873 if (viewModeList->item(i)->text() == _lastMode)
874 viewModeList->setCurrentRow(i);
876 removeButton->setEnabled(
false);
888 if (viewModeList->selectedItems().count() > 0){
889 for (
int i=0; i < modes_.size(); i++)
890 if (modes_[i]->name == viewModeList->currentItem()->text()){
891 removeButton->setEnabled(modes_[i]->custom);