\ +
Add | Creates a new saved Setting item. The default descripton is the currenti date. \ + The description may be changed by the User. \ + The Add button will be greyed out when maximum number of saved layouts is reached. |
Other Buttons | \ +These buttons will be greyed out when no items are selected |
Restore | Loads the current graph layout setting with the swlected saved settings then returns. |
Rename | Allows the user to modify the description of the selected saved session.\ + Same as a double click on the item. |
Update | Saves the current graph layout setting to the selected saved settings. Prompts for confirmation. |
Delete | Deletes the selected graph layout setting. Prompts for confirmation. |
Exit | (Red circle with a white \"X.\") Returns to OSCAR menu. |
* Name | * Order | * Pinning | * Height | \ +
* Height Options | * Event Flags | * Plots Enabled | * Dotted Lines | \ +
%1
").arg(top); + QString bottomText=QString("%1
").arg(bottom); + + QMessageBox msgBox(menuDialog); + msgBox.setText(topText); + msgBox.setInformativeText(bottomText); + if (icon!=nullptr) { + msgBox.setIconPixmap(icon->pixmap(QSize(iconWidthMessageBox,iconWidthMessageBox))); + } + // may be good for help menu. a pull down box with box of data. msgBox.setDetailedText("some detailed string"); + msgBox.setStandardButtons(flags); + msgBox.setDefaultButton(adefault); + msgBox.setWindowFlag(Qt::FramelessWindowHint,true); + + msgBox.setStyleSheet(calculateStyleMessageBox(&menuListFont,top,bottom)); + + // displaywidgets((QWidget*)&msgBox); + bool ret= msgBox.exec()==success; + return ret; +} +#else +bool SaveGraphLayoutSettings::confirmAction(QString name ,QString question,QIcon* icon,QMessageBox::StandardButtons flags , QMessageBox::StandardButton adefault, QMessageBox::StandardButton success) { +//bool SaveGraphLayoutSettings::confirmAction(QString name,QString question,QIcon* icon) + Q_UNUSED(flags); + Q_UNUSED(adefault); + Q_UNUSED(success); QMessageBox msgBox(menuDialog); msgBox.setText(question); if (icon!=nullptr) { @@ -213,8 +363,9 @@ bool SaveGraphLayoutSettings::confirmAction(QString name,QString question,QIcon* Q_UNUSED(name); } +#endif -QString SaveGraphLayoutSettings::calculateStyle(bool on,bool exitBtn){ +QString SaveGraphLayoutSettings::calculateButtonStyle(bool on,bool exitBtn){ QString btnStyle=QString("QPushButton{%1%2}").arg(on ?"color: black;background-color:white;" :"color: darkgray;background-color:#e8e8e8 ;" @@ -239,27 +390,33 @@ QString SaveGraphLayoutSettings::calculateStyle(bool on,bool exitBtn){ } void SaveGraphLayoutSettings::looksOn(QPushButton* button,bool on){ - button->setEnabled(on); + //button->setEnabled(on); button->setStyleSheet(on?styleOn:styleOff); } -void SaveGraphLayoutSettings::enableButtons(bool enable) { +void SaveGraphLayoutSettings::manageButtonApperance() { + + bool enable = menuList->currentItem(); looksOn(menuUpdateBtn,enable); looksOn(menuRestoreBtn,enable); looksOn(menuDeleteBtn,enable); looksOn(menuRenameBtn,enable); + if (nextNumToUse<0) { // check if at Maximum limit + // must always hide first menuAddBtn->hide(); menuAddFullBtn->show(); } else { + // must always hide first menuAddFullBtn->hide(); menuAddBtn->show(); } } + void SaveGraphLayoutSettings::add_feature() { if(!graphView) return; - QString fileName = QString("%1%2").arg(baseName).arg(nextNumToUse,fileNumMaxLength,10,QLatin1Char('0')); + QString fileName = QString("%1%2").arg(fileBaseName).arg(nextNumToUse,fileNumMaxLength,10,QLatin1Char('0')); writeSettings(fileName); // create a default description - use formatted datetime. QString desc=QDateTime::currentDateTime().toString(); @@ -267,25 +424,21 @@ void SaveGraphLayoutSettings::add_feature() { descriptionMap->save(); QListWidgetItem* item = updateFileList( fileName); if (item!=nullptr) { - menulist->setCurrentItem(item,QItemSelectionModel::ClearAndSelect); - menulist->editItem(item); + menuList->setCurrentItem(item,QItemSelectionModel::ClearAndSelect); + menuList->editItem(item); } + menuList->sortItems(); + resizeMenu(); } void SaveGraphLayoutSettings::addFull_feature() { - QMessageBox msgBox(menuDialog); - msgBox.setText(tr("Maximum number exceeded.")); - msgBox.setStandardButtons(QMessageBox::Cancel); - msgBox.setDefaultButton(QMessageBox::Cancel); - msgBox.setWindowFlag(Qt::FramelessWindowHint,true); - msgBox.setStyleSheet(styleMessageBox); - msgBox.setIconPixmap(m_icon_addFull->pixmap(QSize(50,50))); - msgBox.exec(); + verifyItem( nullptr,tr("Maximum number of Items exceeded.") , m_icon_add); } void SaveGraphLayoutSettings::update_feature() { if(!graphView) return; - QListWidgetItem * item=menulist->currentItem(); + QListWidgetItem * item=menuList->currentItem(); + if (!verifyItem(item, tr("No Item Selected") , m_icon_update)) return ; if(!confirmAction( item->text(), tr("Ok to Update?") , m_icon_update) ) return; QString fileName = item->data(fileNameRole).toString(); writeSettings(fileName); @@ -293,8 +446,8 @@ void SaveGraphLayoutSettings::update_feature() { void SaveGraphLayoutSettings::restore_feature() { if(!graphView) return; - QListWidgetItem * item=menulist->currentItem(); - if (!item) return; + QListWidgetItem * item=menuList->currentItem(); + if (!verifyItem(item, tr("No Item Selected") , m_icon_restore)) return ; QString fileName = item->data(fileNameRole).toString(); loadSettings(fileName); exit(); @@ -302,17 +455,35 @@ void SaveGraphLayoutSettings::restore_feature() { void SaveGraphLayoutSettings::rename_feature() { if(!graphView) return; - QListWidgetItem * item=menulist->currentItem(); - if (!item) return; - menulist->editItem(item); + QListWidgetItem * item=menuList->currentItem(); + if (!verifyItem(item, tr("No Item Selected") , m_icon_rename)) return ; + menuList->editItem(item); // SaveGraphLayoutSettings::itemChanged(QListWidgetItem *item) is called when edit changes the entry. // itemChanged will update the description map } +void SaveGraphLayoutSettings::help_exit_feature() { + helpDialog->close(); + exit(); +} + +void SaveGraphLayoutSettings::help_off_feature() { + helpDialog->close(); +} + +void SaveGraphLayoutSettings::help_feature() { + initminMenuListSize(); + createHelp(); + if(!helpDialog) return; + helpDialog->raise(); + helpDialog->exec(); + manageButtonApperance(); +} + void SaveGraphLayoutSettings::delete_feature() { if(!graphView) return; - QListWidgetItem * item=menulist->currentItem(); - if (!item) return; + QListWidgetItem * item=menuList->currentItem(); + if (!verifyItem(item, tr("No Item Selected") , m_icon_delete)) return ; if(!confirmAction(item->text(), tr("Ok To Delete?") ,m_icon_delete) ) return; QString fileName = item->data(fileNameRole).toString(); @@ -323,7 +494,8 @@ void SaveGraphLayoutSettings::delete_feature() { if (nextNumToUse<0) { nextNumToUse=fileNum(fileName); } - enableButtons(true); + manageButtonApperance(); + resizeMenu(); } void SaveGraphLayoutSettings::itemChanged(QListWidgetItem *item) @@ -352,13 +524,34 @@ void SaveGraphLayoutSettings::itemChanged(QListWidgetItem *item) descriptionMap->save(); } item->setText(desc); + menuList->sortItems(); + menuList->setCurrentItem(item); + resizeMenu(); + } void SaveGraphLayoutSettings::itemSelectionChanged() { - enableButtons(true); + initminMenuListSize(); + manageButtonApperance(); } +void SaveGraphLayoutSettings::initminMenuListSize() { + if (minMenuDialogSize.width()==0) { + menuDialogSize = menuDialog->size(); + minMenuDialogSize = menuDialogSize; + + menuListSize = menuList->size(); + minMenuListSize = menuListSize; + + dialogListDiff = menuDialogSize - menuListSize; + + dialogListDiff.setWidth (horizontalWidthAdjustment + dialogListDiff.width()); + + resizeMenu(); + } +}; + void SaveGraphLayoutSettings::writeSettings(QString filename) { graphView->SaveSettings(title+"."+filename,dirName); }; @@ -381,9 +574,79 @@ int SaveGraphLayoutSettings::fileNum(QString fileName) { return value; } + +QSize SaveGraphLayoutSettings::maxSize(const QSize AA , const QSize BB ) { + return QSize ( qMax(AA.width(),BB.width()) , qMax(AA.height(),BB.height() ) ); +} + +bool SaveGraphLayoutSettings::sizeEqual(const QSize AA , const QSize BB ) { + return (AA.width()==BB.width()) && ( AA.height()==BB.height()) ; +} + + + +void SaveGraphLayoutSettings::resizeMenu() { + if (minMenuDialogSize.width()==0) return; + + QSize newSize = calculateMenuDialogSize(); + newSize.setWidth ( newSize.width()); + + menuDialogSize = menuDialog->size(); + + if ( sizeEqual(newSize , menuDialogSize)) { + // no work to do + return; + }; + + if ( menuDialogSize.width() < newSize.width() ) { + menuDialog->setMinimumWidth(newSize.width()); + menuDialog->setMaximumWidth(QWIDGETSIZE_MAX); + } else if ( menuDialogSize.width() > newSize.width() ) { + menuDialog->setMaximumWidth(newSize.width()); + menuDialog->setMinimumWidth(newSize.width()); + } + if ( menuDialogSize.height() < newSize.height() ) { + menuDialog->setMinimumHeight(newSize.height()); + menuDialog->setMaximumHeight(QWIDGETSIZE_MAX); + } else if ( menuDialogSize.height() > newSize.height() ) { + menuDialog->setMaximumHeight(newSize.height()); + menuDialog->setMinimumHeight(newSize.height()); + } + menuDialogSize = newSize; +} + +QSize SaveGraphLayoutSettings::calculateMenuDialogSize() { + if (menuDialogSize.width()==0) return QSize(0,0); + QListWidgetItem* item; + widestItem=nullptr; + QFontMetrics fm = QFontMetrics(menuListFont); + + // account for scrollbars. + QSize returnValue = QSize( 0 , fm.height() ); // add an extra space at the bottom. width didn't work + + // Account for dialog Size + returnValue += dialogListDiff; + QSize size; + + for (int index = 0; index < menuList->count(); ++index) { + item = menuList->item(index); + if (!item) continue; + size = fm.boundingRect(item->text()).size(); + if (returnValue.width() < size.width()) { + returnValue.setWidth( qMax( returnValue.width(),size.width())); + widestItem=item; + } + returnValue.setHeight( returnValue.height()+size.height()); + } + returnValue.setWidth( horizontalWidthAdjustment + returnValue.width() ) ; + + returnValue = maxSize(returnValue, minMenuDialogSize); + return returnValue; +} + QListWidgetItem* SaveGraphLayoutSettings::updateFileList(QString find) { QListWidgetItem* ret=nullptr; - enableButtons(false); + manageButtonApperance(); dir->refresh(); QFileInfoList filelist = dir->entryInfoList( QDir::Files | QDir::Readable | QDir::Writable | QDir::NoSymLinks,QDir::Name); @@ -391,7 +654,7 @@ QListWidgetItem* SaveGraphLayoutSettings::updateFileList(QString find) { int row=0; int count=0; - menulist->clear(); + menuList->clear(); nextNumToUse=-1; descriptionMap->load(); for (int i = 0; i < filelist.size(); ++i) { @@ -414,7 +677,7 @@ QListWidgetItem* SaveGraphLayoutSettings::updateFileList(QString find) { QListWidgetItem *item = new QListWidgetItem(descriptionMap->get(fileName)); item->setData(fileNameRole,fileName); item->setFlags(item->flags() | Qt::ItemIsEditable); - menulist->insertItem(row,item); + menuList->insertItem(row,item); row++; if (find!=nullptr && fileName==find) { ret=item; @@ -429,8 +692,8 @@ QListWidgetItem* SaveGraphLayoutSettings::updateFileList(QString find) { nextNumToUse=count; } } - enableButtons(false); - menulist->sortItems(); + manageButtonApperance(); + menuList->sortItems(); return ret; } @@ -447,6 +710,7 @@ void SaveGraphLayoutSettings::menu(gGraphView* graphView) { } this->graphView=graphView; updateFileList(); + manageButtonApperance(); menuDialog->raise(); menuDialog->exec(); exit(); @@ -569,19 +833,19 @@ switch (ret) { عذرا ، لا يمكن تحديد موقع ملف. - menuDialog->connect(menulist, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(itemActivated(QListWidgetItem*) )); - menuDialog->connect(menulist, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(itemDoubleClicked(QListWidgetItem*) )); - menuDialog->connect(menulist, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemClicked(QListWidgetItem*) )); - menuDialog->connect(menulist, SIGNAL(itemEntered(QListWidgetItem*)), this, SLOT(itemEntered(QListWidgetItem*) )); - menuDialog->connect(menulist, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(itemEntered(QListWidgetItem*) )); + menuDialog->connect(menuList, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(itemActivated(QListWidgetItem*) )); + menuDialog->connect(menuList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(itemDoubleClicked(QListWidgetItem*) )); + menuDialog->connect(menuList, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemClicked(QListWidgetItem*) )); + menuDialog->connect(menuList, SIGNAL(itemEntered(QListWidgetItem*)), this, SLOT(itemEntered(QListWidgetItem*) )); + menuDialog->connect(menuList, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(itemEntered(QListWidgetItem*) )); - menuDialog->disconnect(menulist, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(itemActivated(QListWidgetItem*) )); - menuDialog->disconnect(menulist, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(itemDoubleClicked(QListWidgetItem*) )); - menuDialog->disconnect(menulist, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemClicked(QListWidgetItem*) )); - menuDialog->disconnect(menulist, SIGNAL(itemEntered(QListWidgetItem*)), this, SLOT(itemEntered(QListWidgetItem*) )); - menuDialog->disconnect(menulist, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(itemEntered(QListWidgetItem*) )); + menuDialog->disconnect(menuList, SIGNAL(itemActivated(QListWidgetItem*)), this, SLOT(itemActivated(QListWidgetItem*) )); + menuDialog->disconnect(menuList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(itemDoubleClicked(QListWidgetItem*) )); + menuDialog->disconnect(menuList, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemClicked(QListWidgetItem*) )); + menuDialog->disconnect(menuList, SIGNAL(itemEntered(QListWidgetItem*)), this, SLOT(itemEntered(QListWidgetItem*) )); + menuDialog->disconnect(menuList, SIGNAL(itemPressed(QListWidgetItem*)), this, SLOT(itemEntered(QListWidgetItem*) )); void SaveGraphLayoutSettings::itemActivated(QListWidgetItem *item) diff --git a/oscar/saveGraphLayoutSettings.h b/oscar/saveGraphLayoutSettings.h index c75f2b62..d3e5e3be 100644 --- a/oscar/saveGraphLayoutSettings.h +++ b/oscar/saveGraphLayoutSettings.h @@ -16,9 +16,11 @@ #include