diff --git a/oscar/Resources.qrc b/oscar/Resources.qrc index 23f9ba55..9b3ab92a 100644 --- a/oscar/Resources.qrc +++ b/oscar/Resources.qrc @@ -59,12 +59,13 @@ icons/up-down.png icons/warning.png icons/exit.png - icons/brick-wall.png icons/plus.png icons/rename.png icons/restore.png icons/trash_can.png icons/update.png icons/cog.png + icons/question_mark.png + icons/return.png diff --git a/oscar/daily.cpp b/oscar/daily.cpp index db836edc..8a1e4757 100644 --- a/oscar/daily.cpp +++ b/oscar/daily.cpp @@ -7,7 +7,7 @@ * License. See the file COPYING in the main directory of the source code * for more details. */ -#define TEST_MACROS_ENABLEDoff +#define TEST_MACROS_ENABLED #include #include diff --git a/oscar/daily.ui b/oscar/daily.ui index 502fbb5b..9dd0ad79 100644 --- a/oscar/daily.ui +++ b/oscar/daily.ui @@ -1567,7 +1567,7 @@ QToolButton:pressed { :/icons/cog.png:/icons/cog.png - Save and Restore graph layout settings + Save and Restore Graph Layout Settings diff --git a/oscar/icons/brick-wall.png b/oscar/icons/brick-wall.png deleted file mode 100644 index b82d5ac4..00000000 Binary files a/oscar/icons/brick-wall.png and /dev/null differ diff --git a/oscar/icons/cog.png b/oscar/icons/cog.png index 98b6bc60..bb8aef89 100644 Binary files a/oscar/icons/cog.png and b/oscar/icons/cog.png differ diff --git a/oscar/icons/exit.png b/oscar/icons/exit.png index d4ba9253..976c77d9 100644 Binary files a/oscar/icons/exit.png and b/oscar/icons/exit.png differ diff --git a/oscar/icons/plus.png b/oscar/icons/plus.png index e1a4dd2f..fdc3b603 100644 Binary files a/oscar/icons/plus.png and b/oscar/icons/plus.png differ diff --git a/oscar/icons/question_mark.png b/oscar/icons/question_mark.png new file mode 100644 index 00000000..ddd4b9d1 Binary files /dev/null and b/oscar/icons/question_mark.png differ diff --git a/oscar/icons/rename.png b/oscar/icons/rename.png index b4976f46..0adf88d0 100644 Binary files a/oscar/icons/rename.png and b/oscar/icons/rename.png differ diff --git a/oscar/icons/restore.png b/oscar/icons/restore.png index 0f6922fe..d0cdac5f 100644 Binary files a/oscar/icons/restore.png and b/oscar/icons/restore.png differ diff --git a/oscar/icons/return.png b/oscar/icons/return.png new file mode 100644 index 00000000..ca57b820 Binary files /dev/null and b/oscar/icons/return.png differ diff --git a/oscar/icons/trash_can.png b/oscar/icons/trash_can.png index 575c7f03..5e745bcd 100644 Binary files a/oscar/icons/trash_can.png and b/oscar/icons/trash_can.png differ diff --git a/oscar/icons/update.png b/oscar/icons/update.png index bb465ba7..8f4d0e9c 100644 Binary files a/oscar/icons/update.png and b/oscar/icons/update.png differ diff --git a/oscar/oscar.pro b/oscar/oscar.pro index 9ebec841..12ce9a97 100644 --- a/oscar/oscar.pro +++ b/oscar/oscar.pro @@ -255,8 +255,8 @@ lessThan(QT_MAJOR_VERSION,5)|lessThan(QT_MINOR_VERSION,12) { SOURCES += \ checkupdates.cpp \ - overview.cpp \ saveGraphLayoutSettings.cpp \ + overview.cpp \ common_gui.cpp \ cprogressbar.cpp \ daily.cpp \ @@ -362,8 +362,8 @@ QMAKE_EXTRA_COMPILERS += optimize HEADERS += \ checkupdates.h \ - overview.h \ saveGraphLayoutSettings.h \ + overview.h \ common_gui.h \ cprogressbar.h \ daily.h \ diff --git a/oscar/overview.ui b/oscar/overview.ui index e7281f70..65483855 100644 --- a/oscar/overview.ui +++ b/oscar/overview.ui @@ -269,7 +269,7 @@ QToolButton:pressed { :/icons/cog.png:/icons/cog.png - Save and Restore graph layout settings + Save and Restore Graph Layout Settings diff --git a/oscar/saveGraphLayoutSettings.cpp b/oscar/saveGraphLayoutSettings.cpp index a754503b..0c3cf1d5 100644 --- a/oscar/saveGraphLayoutSettings.cpp +++ b/oscar/saveGraphLayoutSettings.cpp @@ -18,9 +18,13 @@ #include "SleepLib/profiles.h" #include "saveGraphLayoutSettings.h" +#define USE_FRAMELESS_WINDOW +#define USE_PROFILE_SPECIFIC_FOLDERoff // off implies saved layouts worked for all profiles. SaveGraphLayoutSettings::SaveGraphLayoutSettings(QString title,QWidget* parent) : parent(parent),title(title) { + fontSizeIncrease = 1; + helpFontSizeIncrease = 1; createSaveFolder(); if (dir==nullptr) return; dir->setFilter(QDir::Files | QDir::Readable | QDir::Writable | QDir::NoSymLinks); @@ -30,36 +34,40 @@ SaveGraphLayoutSettings::SaveGraphLayoutSettings(QString title,QWidget* parent) createMenu() ; - menuDialog->connect(menuAddFullBtn, SIGNAL(clicked()), this, SLOT (addFull_feature() )); - menuDialog->connect(menuAddBtn, SIGNAL(clicked()), this, SLOT (add_feature() )); + menuDialog->connect(menuAddFullBtn, SIGNAL(clicked()), this, SLOT (addFull_feature() )); + menuDialog->connect(menuAddBtn, SIGNAL(clicked()), this, SLOT (add_feature() )); menuDialog->connect(menuRestoreBtn, SIGNAL(clicked()), this, SLOT (restore_feature() )); menuDialog->connect(menuUpdateBtn, SIGNAL(clicked()), this, SLOT (update_feature() )); menuDialog->connect(menuRenameBtn, SIGNAL(clicked()), this, SLOT (rename_feature() )); menuDialog->connect(menuDeleteBtn, SIGNAL(clicked()), this, SLOT (delete_feature() )); + menuDialog->connect(menuHelpBtn, SIGNAL(clicked()), this, SLOT (help_feature() )); menuDialog->connect(menuExitBtn, SIGNAL(clicked()), this, SLOT (exit() )); + menuDialog->connect(menuList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*) )); + menuDialog->connect(menuList, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged() )); + - menuDialog->connect(menulist, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*) )); - menuDialog->connect(menulist, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged() )); singleLineRe = new QRegularExpression( QString("^\\s*([^\\r\\n]{0,%1})").arg(1+maxDescriptionLen) ); - fileNumRe = new QRegularExpression( QString("%1(\\d+)(.shg)?$").arg(baseName) ); - parseFilenameRe = new QRegularExpression(QString("^(%1[.](%2(\\d*)))[.]shg$").arg(title).arg(baseName)); + fileNumRe = new QRegularExpression( QString("%1(\\d+)(.shg)?$").arg(fileBaseName) ); + parseFilenameRe = new QRegularExpression(QString("^(%1[.](%2(\\d*)))[.]shg$").arg(title).arg(fileBaseName)); } SaveGraphLayoutSettings::~SaveGraphLayoutSettings() { if (dir==nullptr) {return;} - menuDialog->disconnect(menuAddFullBtn, SIGNAL(clicked()), this, SLOT (addFull_feature() )); - menuDialog->disconnect(menuAddBtn, SIGNAL(clicked()), this, SLOT (add_feature() )); + menuDialog->disconnect(menuAddFullBtn, SIGNAL(clicked()), this, SLOT (addFull_feature() )); + menuDialog->disconnect(menuAddBtn, SIGNAL(clicked()), this, SLOT (add_feature() )); menuDialog->disconnect(menuRestoreBtn, SIGNAL(clicked()), this, SLOT (restore_feature() )); menuDialog->disconnect(menuUpdateBtn, SIGNAL(clicked()), this, SLOT (update_feature() )); - menuDialog->disconnect(menuDeleteBtn, SIGNAL(clicked()), this, SLOT (delete_feature() )); menuDialog->disconnect(menuRenameBtn, SIGNAL(clicked()), this, SLOT (rename_feature() )); + menuDialog->disconnect(menuDeleteBtn, SIGNAL(clicked()), this, SLOT (delete_feature() )); menuDialog->disconnect(menuExitBtn, SIGNAL(clicked()), this, SLOT (exit() )); + menuDialog->disconnect(menuHelpBtn, SIGNAL(clicked()), this, SLOT (help_feature() )); + menuDialog->disconnect(menuList, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*) )); + menuDialog->disconnect(menuList, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged() )); + helpDestructor(); - menuDialog->disconnect(menulist, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(itemChanged(QListWidgetItem*) )); - menuDialog->disconnect(menulist, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged() )); delete descriptionMap; delete singleLineRe; @@ -107,97 +115,239 @@ void SaveGraphLayoutSettings::createSaveFolder() { dir=tmpDir; } -void SaveGraphLayoutSettings::createMenu() { - styleOn= calculateStyle(true,false); - styleOff= calculateStyle(false,false); - styleExitBtn=calculateStyle(true,true); +QPushButton* SaveGraphLayoutSettings::menuBtn(QString name, QIcon* icon, QString style,QSizePolicy::Policy hPolicy,QString tooltip) { + return newBtnRtn(menuLayoutButtons, name, icon, style, hPolicy,tooltip) ; +} +QPushButton* SaveGraphLayoutSettings::helpBtn(QString name, QIcon* icon, QString style,QSizePolicy::Policy hPolicy,QString tooltip) { + return newBtnRtn(helpLayoutButtons, name, icon, style, hPolicy,tooltip) ; +} +QPushButton* SaveGraphLayoutSettings::newBtnRtn(QHBoxLayout* layout,QString name, QIcon* icon, QString style,QSizePolicy::Policy hPolicy,QString tooltip) { + QPushButton* button = new QPushButton(name, menuDialog); + button->setIcon(*icon); + button->setStyleSheet(style); + button->setSizePolicy(hPolicy,QSizePolicy::Fixed); + button->setToolTip(tooltip); + button->setToolTipDuration(AppSetting->tooltipTimeout()); + button->setFont(*mediumfont); + layout->addWidget(button); + return button; +} + +void SaveGraphLayoutSettings::createStyleSheets() { + styleOn= calculateButtonStyle(true,false); + styleOff= calculateButtonStyle(false,false); + styleExit= calculateButtonStyle(true,true); styleMessageBox= "QMessageBox { " "background-color:yellow;" - "color:black;" + //"color:black;" + "color:red;" "border: 2px solid black;" - "text-align: center;" + "text-align: right;" + "font-size: 16px;" "}" - "QPushButton { " - "color:black;" + "QTextEdit {" + "background-color:lightblue;" + //"color:black;" + "color:red;" + "border: 9px solid black;" + "text-align: center;" + "vertical-align:top;" "}" ; styleDialog= "QDialog { " "border: 3px solid black;" - "min-width:30em;" // make large fonts in message box "}"; +} - menuDialog= new QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint|Qt::WindowSystemMenuHint); - menuDialog->setWindowFlag(Qt::FramelessWindowHint); +void SaveGraphLayoutSettings::createMenu() { - menuAddFullBtn =new QPushButton("Add", parent); - menuAddBtn =new QPushButton(tr("Add"), parent); - menuRestoreBtn = new QPushButton(tr("Restore"), parent); - menuUpdateBtn = new QPushButton(tr("Update"), parent); - menuRenameBtn = new QPushButton(tr("Rename"), parent); - menuDeleteBtn = new QPushButton(tr("Delete"), parent); - menuExitBtn = new QPushButton(*m_icon_exit,tr(""),parent); + menuListFont =*defaultfont; + menuListFont.setPointSize(fontSizeIncrease+menuListFont.pointSize()); - menulist=new QListWidget(menuDialog); - menulist->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - menuLayout = new QVBoxLayout(menuDialog); - menuLayout1 = new QHBoxLayout(); - menuLayout2 = new QVBoxLayout(); - menuLayout2->setMargin(6); - menuLayout->addLayout(menuLayout1); - menuLayout->addLayout(menuLayout2); - - menuLayout1->addWidget(menuAddFullBtn); - menuLayout1->addWidget(menuAddBtn); - menuLayout1->addWidget(menuRestoreBtn); - menuLayout1->addWidget(menuRenameBtn); - menuLayout1->addWidget(menuUpdateBtn); - menuLayout1->addWidget(menuDeleteBtn); - menuLayout1->addWidget(menuExitBtn); - menuLayout2->addWidget(menulist, 1); -/*TRANSLATION*/ - menuAddFullBtn-> setToolTip(tr("Add Feature inhibited. The maximum number has been exceeded.")); - menuAddBtn-> setToolTip(tr("Save current settings.")); - menuRestoreBtn-> setToolTip(tr("Restores saved settings.")); - menuRenameBtn-> setToolTip(tr("Renames the selection. Must edit existing name then press enter.")); - menuUpdateBtn-> setToolTip(tr("Updates the selection with current settings.")); - menuDeleteBtn-> setToolTip(tr("Delete the selection.")); - menuExitBtn-> setToolTip(tr("Closes the dialog menu. Returns to previous menu.")); + createStyleSheets(); + #ifdef USE_FRAMELESS_WINDOW + menuDialog= new QDialog(parent, Qt::FramelessWindowHint); + menuDialog->setSizeGripEnabled(true); // allows lower right hand corner to resize dialog + #else + menuDialog= new QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint|Qt::WindowSystemMenuHint); + menuDialog->setWindowTitle(tr("Manage Save Layout Settings")) ; + #endif menuDialog->setStyleSheet(styleDialog); - menuAddFullBtn->setStyleSheet(styleOff); - menuAddBtn->setStyleSheet(styleOn); - menuRestoreBtn->setStyleSheet(styleOn); - menuUpdateBtn->setStyleSheet(styleOn); - menuRenameBtn->setStyleSheet(styleOn); - menuDeleteBtn->setStyleSheet(styleOn); - menuExitBtn->setStyleSheet( styleExitBtn ); + + menuLayout = new QVBoxLayout(menuDialog); + menuLayoutButtons = new QHBoxLayout(); + + menuAddFullBtn = menuBtn(tr("Add" ),m_icon_add , styleOff ,QSizePolicy::Minimum, tr("Add Feature inhibited. The maximum number of Items has been exceeded.") ); + menuAddBtn = menuBtn(tr("Add" ),m_icon_add , styleOn ,QSizePolicy::Minimum, tr("creates new copy of current settings.")); + menuRestoreBtn = menuBtn(tr("Restore"),m_icon_restore , styleOn ,QSizePolicy::Minimum, tr("Restores saved settings from selection.")); + menuRenameBtn = menuBtn(tr("Rename" ),m_icon_rename , styleOn ,QSizePolicy::Minimum, tr("Renames the selection. Must edit existing name then press enter.")); + menuUpdateBtn = menuBtn(tr("Update" ),m_icon_update , styleOn ,QSizePolicy::Minimum, tr("Updates the selection with current settings.")); + menuDeleteBtn = menuBtn(tr("Delete" ),m_icon_delete , styleOn ,QSizePolicy::Minimum, tr("Deletes the selection.")); + menuHelpBtn = menuBtn("" ,m_icon_help , styleOn ,QSizePolicy::Fixed , tr("Expanded Help menu.")); + menuExitBtn = menuBtn("" ,m_icon_exit , styleExit,QSizePolicy::Fixed , tr("Exits the Layout menu.")); + + #ifndef USE_FRAMELESS_WINDOW + menuExitBtn->hide(); + #endif + + menuList = new QListWidget(menuDialog); + menuList->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + menuList->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + menuList->setFont(menuListFont); - menuAddFullBtn->setIcon(*m_icon_add ); - menuAddBtn->setIcon(*m_icon_add ); - menuRestoreBtn->setIcon(*m_icon_restore ); - menuRenameBtn->setIcon(*m_icon_rename ); - menuUpdateBtn->setIcon(*m_icon_update ); - menuDeleteBtn->setIcon(*m_icon_delete ); - menuDeleteBtn->setIcon(*m_icon_delete ); + menuLayout->addLayout(menuLayoutButtons); + menuLayout->addWidget(menuList, 1); + //menuList->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Preferred); + menuList->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum); - int timeout = AppSetting->tooltipTimeout(); - menuAddFullBtn->setToolTipDuration(timeout); - menuAddBtn->setToolTipDuration(timeout); - menuRestoreBtn->setToolTipDuration(timeout); - menuUpdateBtn->setToolTipDuration(timeout); - menuRenameBtn->setToolTipDuration(timeout); - menuDeleteBtn->setToolTipDuration(timeout); - menuExitBtn->setToolTipDuration(timeout); }; -bool SaveGraphLayoutSettings::confirmAction(QString name,QString question,QIcon* icon) { +void SaveGraphLayoutSettings::createHelp() { + if(helpDialog) return; + + helpDialog= new QDialog(parent, Qt::FramelessWindowHint); + helpDialog->setStyleSheet(styleDialog); + menuDialog->setSizeGripEnabled(true); // allows lower right hand corner to resize dialog + + QFont helpInfoFont = menuListFont; + helpInfoFont.setPointSize(helpFontSizeIncrease+helpInfoFont.pointSize()); + + QFont helpInfoLabelFont = helpInfoFont; + helpInfoLabelFont.setPointSize(fontSizeIncrease+ helpInfoFont.pointSize()); + + + //QHBoxLayout* helpLayoutButtons; + //QLabel* helpInfoHeaderLabel; + //QFont helpInfoFont; + //QVBoxLayout* helpLayout; + + + QLabel* helpInfoHeaderLabel = new QLabel("helpInfoHeaderLabel",parent); + helpInfoHeaderLabel->setText(QString( tr("

Help Menu - Manage Graph Layout Settings

"))); + helpInfoHeaderLabel->setFont(helpInfoLabelFont); + + QLabel* helpInfoLabel = new QLabel("helpInfo",parent); + helpInfoLabel->setFont(helpInfoFont); + helpInfoLabel->setText(helpInfo()) ; + + + helpLayoutButtons = new QHBoxLayout(); + helpLayoutButtons->addWidget(helpInfoHeaderLabel); + helpInfoExitBtn= helpBtn("" ,m_icon_return , styleOn ,QSizePolicy::Fixed , tr("Exits the help menu.")); + helpExitBtn = helpBtn("" ,m_icon_exit , styleExit,QSizePolicy::Fixed , tr("Exits the dialog menu.")); + + QVBoxLayout* helpLayout = new QVBoxLayout(helpDialog); + helpLayout->addLayout(helpLayoutButtons); + helpLayout->addWidget(helpInfoLabel, 1); + + helpDialog->connect(helpInfoExitBtn,SIGNAL(clicked()), this, SLOT (help_off_feature() )); + helpDialog->connect(helpExitBtn, SIGNAL(clicked()), this, SLOT (help_exit_feature() )); + +} + +void SaveGraphLayoutSettings::helpDestructor() { + if(!helpDialog) return; + helpDialog->disconnect(helpInfoExitBtn,SIGNAL(clicked()), this, SLOT (help_off_feature() )); + helpDialog->disconnect(helpExitBtn, SIGNAL(clicked()), this, SLOT (help_exit_feature() )); +} + +QString SaveGraphLayoutSettings::helpInfo() { + +return QString( tr("\ +
Button Description
\ +

\ + \ + \ + \ + \ + \ + \ + \ + \ + \ +
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.
\ +

Graph Layout Settings
\ + \ + \ + \ +
* Name * Order * Pinning * Height
* Height Options * Event Flags * Plots Enabled * Dotted Lines
\ +
General Information
\ + \ + * Maximum description size = 80 characters.\ + * Maximum Saved Graph Layout Settings = 30 \ + * Saved Graprhg Layout Setting are available for all user profiles\ + * Graph Layout Settings only impact how graphs are displayed.
\ + They do not contains any other data.\ + * The Escape key \"esc\" will always exit a dialog menu - like this help or the layout menu\ + \ +

\ +")); + +} + +const QString SaveGraphLayoutSettings::calculateStyleMessageBox(QFont* font , QString& s1, QString& s2) { + QFontMetrics fm = QFontMetrics(*font); + int width = fm.boundingRect(s1).size().width(); + int width2 = fm.boundingRect(s2).size().width(); + width = qMax(width,width2) + iconWidthMessageBox; + + QString style = QString("%1 QLabel{%2 min-width: %3px;}" ). + arg(styleMessageBox). + arg("text-align: center;" "color:black;"). + arg(width); + + return style; +} + +bool SaveGraphLayoutSettings::verifyItem(QListWidgetItem* item,QString text,QIcon* icon) { + //if (verifyhelp() ) return false; + if (item) return true; + initminMenuListSize(); + confirmAction( text ,"" , icon); + return false; +} + +#if 1 +bool SaveGraphLayoutSettings::confirmAction(QString top ,QString bottom,QIcon* icon,QMessageBox::StandardButtons flags , QMessageBox::StandardButton adefault, QMessageBox::StandardButton success) { + //QString topText=QString("
%1
").arg(top); + //QString bottomText=QString("
%1
").arg(bottom); + QString topText=QString("

%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 #include #include - +#include +#include #include #include + #include "Graphs/gGraphView.h" class DescriptionMap @@ -35,7 +37,7 @@ private: QString filename; QMap descriptions; const QRegularExpression* parseDescriptionsRe; - QChar delimiter = QChar(177); + const QChar delimiter = QChar(':'); }; class SaveGraphLayoutSettings : public QWidget @@ -46,19 +48,35 @@ public: ~SaveGraphLayoutSettings(); void menu(gGraphView* graphView); protected: + QIcon* m_icon_return = new QIcon(":/icons/return.png"); + QIcon* m_icon_help = new QIcon(":/icons/question_mark.png"); QIcon* m_icon_exit = new QIcon(":/icons/exit.png"); QIcon* m_icon_delete = new QIcon(":/icons/trash_can.png"); QIcon* m_icon_update = new QIcon(":/icons/update.png"); QIcon* m_icon_restore = new QIcon(":/icons/restore.png"); QIcon* m_icon_rename = new QIcon(":/icons/rename.png"); QIcon* m_icon_add = new QIcon(":/icons/plus.png"); - QIcon* m_icon_addFull = new QIcon(":/icons/brick-wall.png"); private: - const static int fileNumMaxLength=3; - const static int maxFiles=20; // Max supported design limited is 1000 - based on layoutName has has 3 numeric digits fileNumMaxLength=3. - const static int maxDescriptionLen=80; - const QString baseName=QString("layout"); + const static int fileNumMaxLength = 3; + const static int maxFiles = 30; // Max supported design limited is 1000 10**fileNumMaxLength(3). + const static int iconWidthMessageBox = 50; + const static int maxDescriptionLen = 80; + const QString fileBaseName = QString("layout"); + const int fileNameRole = Qt::UserRole; + int fontSizeIncrease = 0; + int horizontalWidthAdjustment=60; // this seem to make menu size changes work. Testing says it is 60 but what causes it is unknown. + + QSize minMenuListSize = QSize(0,0); + QSize minMenuDialogSize = QSize(0,0); + + QSize dialogListDiff = QSize(0,0); + QSize menuDialogSize = QSize(0,0); + QSize menuListSize = QSize(0,0); + void initminMenuListSize(); + QSize calculateMenuDialogSize(); + QSize maxSize(const QSize AA , const QSize BB ) ; + bool sizeEqual(const QSize AA , const QSize BB ) ; const QRegularExpression* singleLineRe; const QRegularExpression* fileNumRe; @@ -67,10 +85,11 @@ private: QWidget* parent; const QString title; - gGraphView* graphView=nullptr; + gGraphView* graphView = nullptr; + QFont menuListFont; QDialog* menuDialog; - QListWidget* menulist; + QListWidget* menuList; QPushButton* menuAddFullBtn; // Must be first item for workaround. QPushButton* menuAddBtn; @@ -79,31 +98,59 @@ private: QPushButton* menuUpdateBtn; QPushButton* menuRenameBtn; QPushButton* menuExitBtn; + QPushButton* menuHelpBtn; + QVBoxLayout* menuLayout; - QHBoxLayout* menuLayout1; - QVBoxLayout* menuLayout2; + QHBoxLayout* menuLayoutButtons; - QDir* dir=nullptr; + void createHelp(); + void helpDestructor(); + QString helpInfo(); + QDialog* helpDialog=nullptr; + QPushButton* helpInfoExitBtn=nullptr; + QPushButton* helpExitBtn=nullptr; + int helpFontSizeIncrease = 0; + QHBoxLayout* helpLayoutButtons = nullptr; + + + + QDir* dir = nullptr; QString dirName; int nextNumToUse; - QListWidgetItem* updateFileList(QString find=QString()); + QListWidgetItem* updateFileList(QString find = QString()); + QListWidgetItem* widestItem=nullptr; QString styleOn; QString styleOff; - QString styleExitBtn; + QString styleExit; QString styleMessageBox; QString styleDialog; - QString calculateStyle(bool on,bool border); + + QString calculateButtonStyle(bool on,bool border); void looksOn(QPushButton* button,bool on); DescriptionMap* descriptionMap; - bool confirmAction(QString name,QString question,QIcon* icon); + bool confirmAction(QString name,QString question,QIcon* icon, + QMessageBox::StandardButtons flags = (QMessageBox::Cancel|QMessageBox::Yes) , + QMessageBox::StandardButton adefault = QMessageBox::Cancel, + QMessageBox::StandardButton success = QMessageBox::Yes + ); + bool verifyItem(QListWidgetItem* item,QString name,QIcon* icon) ; + + const QString calculateStyleMessageBox( QFont* font, QString& s1, QString& s2); + + void displaywidgets(QWidget* widget); + QSize calculateParagraphSize(QString& text,QFont& font, QString& ); void createMenu(); + void createStyleSheets(); void createSaveFolder(); - void enableButtons(bool enable); - void add_featurertn(); + QPushButton* newBtnRtn(QHBoxLayout*, QString name, QIcon* icon, QString style,QSizePolicy::Policy hPolicy,QString tooltip); + QPushButton* menuBtn( QString name, QIcon* icon, QString style,QSizePolicy::Policy hPolicy,QString tooltip); + QPushButton* helpBtn( QString name, QIcon* icon, QString style,QSizePolicy::Policy hPolicy,QString tooltip); + + void manageButtonApperance(); + void resizeMenu(); - const int fileNameRole = Qt::UserRole; int fileNum(QString fileName); void writeSettings(QString filename); void loadSettings(QString filename); @@ -113,10 +160,13 @@ public slots: private slots: void add_feature(); void addFull_feature(); - void update_feature(); void restore_feature(); - void delete_feature(); void rename_feature(); + void update_feature(); + void help_feature(); + void help_off_feature(); + void help_exit_feature(); + void delete_feature(); void exit(); void itemChanged(QListWidgetItem *item);