Skip to content

Commit

Permalink
Re #4282. Added preferences for floating windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mantid-roman committed Dec 23, 2011
1 parent 863eb39 commit 6979634
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 59 deletions.
113 changes: 63 additions & 50 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,18 @@ void file_uncompress(const char *file);


ApplicationWindow::ApplicationWindow(bool factorySettings)
: QMainWindow(), Scripted(ScriptingLangManager::newEnv(this)),blockWindowActivation(false)
: QMainWindow(),
Scripted(ScriptingLangManager::newEnv(this)),
blockWindowActivation(false),
#ifdef Q_OS_MAC // Mac
settings(QSettings::IniFormat,QSettings::UserScope, "ISIS", "MantidPlot")
#else
settings("ISIS", "MantidPlot")
#endif
{
QCoreApplication::setOrganizationName("ISIS");
QCoreApplication::setApplicationName("MantidPlot");
#ifdef SHARED_MENUBAR
#ifdef Q_OS_MAC // Mac
QSettings settings(QSettings::IniFormat,QSettings::UserScope, QCoreApplication::organizationName(), QCoreApplication::applicationName());
#else
QSettings settings;
#endif
if (settings.value("/General/SharedMenuBar",false).toBool())
{
std::cerr << "Shared" << std::endl;
Expand Down Expand Up @@ -440,7 +442,7 @@ void ApplicationWindow::init(bool factorySettings)
showFirstTimeSetup();
}

connect(this,SIGNAL(changeToMDI(FloatingWindow*)),this,SLOT(goMdi(FloatingWindow*)));
connect(this,SIGNAL(changeToMDI(FloatingWindow*)),this,SLOT(changeToDocked(FloatingWindow*)));
QTimer *timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(showActiveWindowInTitle()));
timer->start(100);
Expand Down Expand Up @@ -2425,7 +2427,7 @@ void ApplicationWindow::customPlot3D(Graph3D *plot)
void ApplicationWindow::initPlot3D(Graph3D *plot)
{
//d_workspace->addSubWindow(plot);
addSubWindowToMdiArea(plot);
addMdiSubWindow(plot);
connectSurfacePlot(plot);

plot->setIcon(getQPixmap("trajectory_xpm"));
Expand Down Expand Up @@ -2715,7 +2717,7 @@ void ApplicationWindow::initMultilayerPlot(MultiLayer* g, const QString& name)
while(alreadyUsedName(label))
label = generateUniqueName(tr("Graph"));

this->addSubWindowToMdiArea(g);
this->addMdiSubWindow(g);

g->setWindowTitle(label);
g->setName(label);
Expand Down Expand Up @@ -2934,7 +2936,7 @@ void ApplicationWindow::initTable(Table* w, const QString& caption)
name = generateUniqueName(tr("Table"));

//d_workspace->addSubWindow(w);
addSubWindowToMdiArea(w);
addMdiSubWindow(w);

connectTable(w);
customTable(w);
Expand Down Expand Up @@ -2977,7 +2979,7 @@ Note* ApplicationWindow::newNote(const QString& caption)
m->setDirPath(scriptsDirPath);

//d_workspace->addSubWindow(m);
addSubWindowToMdiArea(m);
addMdiSubWindow(m);
addListViewItem(m);

connect(m, SIGNAL(modifiedWindow(MdiSubWindow*)), this, SLOT(modifiedProject(MdiSubWindow*)));
Expand Down Expand Up @@ -3258,8 +3260,7 @@ void ApplicationWindow::initMatrix(Matrix* m, const QString& caption)
m->askOnCloseEvent(confirmCloseMatrix);
m->setNumericPrecision(d_decimal_digits);

//d_workspace->addSubWindow(m);
addSubWindowToMdiArea(m);
addMdiSubWindow(m);
addListViewItem(m);

QUndoStack *stack = m->undoStack();
Expand Down Expand Up @@ -5117,7 +5118,9 @@ void ApplicationWindow::saveSettings()
settings.setValue("/height", d_app_rect.height());
settings.endGroup();

#ifdef SHARED_MENUBAR
settings.setValue("/SharedMenuBar", m_sharedMenuBar != NULL);
#endif
settings.setValue("/AutoSearchUpdates", autoSearchUpdates);
settings.setValue("/Language", appLanguage);
settings.setValue("/ShowWindowsPolicy", show_windows_policy);
Expand Down Expand Up @@ -17225,7 +17228,7 @@ MultiLayer* ApplicationWindow::waterfallPlot(Table *t, const QStringList& list)
return ml;
}

QMdiSubWindow* ApplicationWindow::addSubWindowToMdiArea(MdiSubWindow *w, bool show_normal)
void ApplicationWindow::addMdiSubWindow(MdiSubWindow *w, bool show_normal)
{
connect(w, SIGNAL(modifiedWindow(MdiSubWindow*)), this, SLOT(modifiedProject(MdiSubWindow*)));
connect(w, SIGNAL(resizedWindow(MdiSubWindow*)),this,SLOT(modifiedProject(MdiSubWindow*)));
Expand All @@ -17234,38 +17237,29 @@ QMdiSubWindow* ApplicationWindow::addSubWindowToMdiArea(MdiSubWindow *w, bool sh
connect(w, SIGNAL(statusChanged(MdiSubWindow*)),this, SLOT(updateWindowStatus(MdiSubWindow*)));
connect(w, SIGNAL(showContextMenu()), this, SLOT(showWindowContextMenu()));

QMdiSubWindow* sw = this->d_workspace->addSubWindow(w);
sw->resize(w->size());
QAction *goFloat = new QAction("Float",this);
connect(goFloat,SIGNAL(triggered()),w,SLOT(goFloat()));
sw->systemMenu()->addAction(goFloat);
if (show_normal)
{
sw->showNormal();
}
else
QMdiSubWindow* sw = addMdiSubWindowAsDocked(w);
if (!show_normal)
{
sw->showMinimized();
}
return sw;
}

/**
* Make a subwindow floating.
* @param pos :: Position of created window relative to the main window
*/
void ApplicationWindow::goFloat(MdiSubWindow* w)
FloatingWindow* ApplicationWindow::addMdiSubWindowAsFloating(MdiSubWindow* w, QPoint pos)
{
QMdiSubWindow* sw = dynamic_cast<QMdiSubWindow*>(w->parent());
if (!sw)
FloatingWindow* fw =new FloatingWindow(this);//, Qt::WindowStaysOnTopHint);
#ifdef SHARED_MENUBAR
if (m_sharedMenuBar != NULL)
{
std::cerr << "Oops... " << w->parent()->className() << std::endl;
return;
fw->setMenuBar(m_sharedMenuBar);
}

#endif
// calculate the postion for the new window
QSize sz = sw->size();
QSize sz = w->size();
QPoint p = this->pos() + d_workspace->pos();
QPoint p0 = sw->pos();
QPoint p0 = pos;
if (p0.y() < 0) p0.setY(0);
p += p0;

Expand All @@ -17278,6 +17272,38 @@ void ApplicationWindow::goFloat(MdiSubWindow* w)
if (y > p.y()) p.setY(y + 1);
}

fw->setWindowTitle(w->windowTitle());
fw->setMdiSubWindow(w);
fw->resize(sz);
fw->move(p);
fw->show();
fw->installEventFilter(this);
m_floatingWindows.append(fw);
return fw;
}

QMdiSubWindow* ApplicationWindow::addMdiSubWindowAsDocked(MdiSubWindow* w)
{
QMdiSubWindow* sw = this->d_workspace->addSubWindow(w);
sw->resize(w->size());
QAction *goFloat = new QAction("Float",this);
connect(goFloat,SIGNAL(triggered()),w,SLOT(goFloat()));
sw->systemMenu()->addAction(goFloat);
return sw;
}

/**
* Make a subwindow floating.
*/
void ApplicationWindow::changeToFloating(MdiSubWindow* w)
{
QMdiSubWindow* sw = dynamic_cast<QMdiSubWindow*>(w->parent());
if (!sw)
{
std::cerr << "Oops... " << w->parent()->className() << std::endl;
return;
}

// remove the subwindow from the mdi area
d_workspace->removeSubWindow(w);
sw->close();
Expand All @@ -17286,27 +17312,14 @@ void ApplicationWindow::goFloat(MdiSubWindow* w)
connect(goMdi,SIGNAL(triggered()),w,SLOT(goMdi()));

// create the outer floating window.
FloatingWindow* fw =new FloatingWindow(this);//, Qt::WindowStaysOnTopHint);
#ifdef SHARED_MENUBAR
if (m_sharedMenuBar != NULL)
{
fw->setMenuBar(m_sharedMenuBar);
}
#endif
fw->setWindowTitle(w->windowTitle());
fw->setMdiSubWindow(w);
fw->resize(sz);
fw->move(p);
fw->show();
fw->installEventFilter(this);
m_floatingWindows.append(fw);
addMdiSubWindowAsFloating(w,sw->pos());
activateWindow(w);
}

/**
* Return a floating subwindow to the mdi area.
*/
void ApplicationWindow::goMdi(FloatingWindow* fw)
void ApplicationWindow::changeToDocked(FloatingWindow* fw)
{
QMenu systemMenu;
QAction* goMdiAction = new QAction("MDI",this);
Expand All @@ -17320,7 +17333,7 @@ void ApplicationWindow::goMdi(FloatingWindow* fw)
MdiSubWindow* w = fw->mdiSubWindow();
if (w)
{
addSubWindowToMdiArea(w);
addMdiSubWindowAsDocked(w);
removeFloatingWindow(fw);
// main window must be closed or application will freeze
fw->close();
Expand Down
12 changes: 8 additions & 4 deletions Code/Mantid/MantidPlot/src/ApplicationWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Description : QtiPlot's main window
#include <QBuffer>
#include <QLocale>
#include <QSet>
#include <QSettings>
#include "Table.h"
#include "ScriptingEnv.h"
#include "Scripted.h"
Expand Down Expand Up @@ -182,7 +183,7 @@ class ApplicationWindow: public QMainWindow, public Scripted
QList<QToolBar *> toolBarsList();

MdiSubWindow *activeWindow(WindowType type = NoWindow);
QMdiSubWindow * addSubWindowToMdiArea(MdiSubWindow *w, bool show_normal = true);
void addMdiSubWindow(MdiSubWindow *w, bool show_normal = true);

int matrixUndoStackSize(){return d_matrix_undo_stack_size;};
void setMatrixUndoStackSize(int size);
Expand Down Expand Up @@ -1029,14 +1030,16 @@ public slots:
/// Activate a subwindow (docked or floating) other than current active one
void activateNewWindow();

FloatingWindow* addMdiSubWindowAsFloating(MdiSubWindow* w, QPoint pos = QPoint(0,0));
QMdiSubWindow* addMdiSubWindowAsDocked(MdiSubWindow* w);
void mdiWindowActivated(MdiSubWindow* w);
void goFloat(MdiSubWindow* w);
void goMdi(FloatingWindow* w);
void changeToFloating(MdiSubWindow* w);
void changeToDocked(FloatingWindow* w);
void setStaysOnTopFlag(FloatingWindow* w);
void removeStaysOnTopFlag(FloatingWindow* w);
void removeFloatingWindow(FloatingWindow* w);
FloatingWindow* getActiveFloating() const;
void showActiveWindowInTitle();
void showActiveWindowInTitle(); // temporary
QMenuBar* myMenuBar();
#ifdef SHARED_MENUBAR
bool isMenuBarShared() const {return m_sharedMenuBar != NULL;}
Expand Down Expand Up @@ -1449,5 +1452,6 @@ public slots:

public:
MantidUI *mantidUI;
QSettings settings;
};
#endif
19 changes: 19 additions & 0 deletions Code/Mantid/MantidPlot/src/ConfigDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,21 @@ void ConfigDialog::initAppPage()

initFileLocationsPage();

// Floating windows page
floatingWindowsPage = new QWidget();
QVBoxLayout *floatLayout = new QVBoxLayout(floatingWindowsPage);
QGroupBox *floatBox = new QGroupBox();
floatLayout->addWidget(floatBox);
QGridLayout *floatPageLayout = new QGridLayout(floatBox);
boxFloatingGraph = new QCheckBox("Floating Graphs");
boxFloatingGraph->setChecked(app->settings.value("/General/FloatingWindows/Graphs",false).toBool());
floatPageLayout->addWidget(boxFloatingGraph,0,0);
boxFloatingTable = new QCheckBox("Floating Tables");
boxFloatingTable->setChecked(app->settings.value("/General/FloatingWindows/Tables",false).toBool());
floatPageLayout->addWidget(boxFloatingTable,1,0);
floatPageLayout->setRowStretch(2,1);
appTabWidget->addTab(floatingWindowsPage, QString());

connect( boxLanguage, SIGNAL( activated(int) ), this, SLOT( switchToLanguage(int) ) );
connect( fontsBtn, SIGNAL( clicked() ), this, SLOT( pickApplicationFont() ) );
connect( boxSave, SIGNAL( toggled(bool) ), boxMinutes, SLOT( setEnabled(bool) ) );
Expand Down Expand Up @@ -1721,6 +1736,7 @@ void ConfigDialog::languageChange()
appTabWidget->setTabText(appTabWidget->indexOf(appColors), tr("Colors"));
appTabWidget->setTabText(appTabWidget->indexOf(numericFormatPage), tr("Numeric Format"));
appTabWidget->setTabText(appTabWidget->indexOf(fileLocationsPage), tr("File Locations"));
appTabWidget->setTabText(appTabWidget->indexOf(floatingWindowsPage), tr("Floating windows"));

//Mantid Page
mtdTabWidget->setTabText(mtdTabWidget->indexOf(instrumentPage), tr("Instrument"));
Expand Down Expand Up @@ -2011,6 +2027,9 @@ void ConfigDialog::apply()
boxNotes->isChecked(),boxInstrWindow->isChecked());
// general page: colors tab
app->setAppColors(btnWorkspace->color(), btnPanels->color(), btnPanelsText->color());
// general page: floating windows tab
app->settings.setValue("/General/FloatingWindows/Graphs",boxFloatingGraph->isChecked());
app->settings.setValue("/General/FloatingWindows/Tables",boxFloatingTable->isChecked());
// 3D plots page
QStringList plot3DColors = QStringList() << btnToColor->color().name() << btnLabels->color().name();
plot3DColors << btnMesh->color().name() << btnGrid->color().name() << btnFromColor->color().name();
Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/MantidPlot/src/ConfigDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ private slots:
QPushButton* buttonTextFont, *buttonHeaderFont;
QStackedWidget * generalDialog;
QWidget *appColors, *tables, *plotOptions, *plotAxes, *plotTicks, *plotFonts, *confirm, *plotPrint;
QWidget *application, *curves, *plots3D, *fitPage, *numericFormatPage;
QWidget *application, *curves, *plots3D, *fitPage, *numericFormatPage, *floatingWindowsPage;
//Mantid
QWidget *instrumentPage;
QComboBox *facility;
Expand Down Expand Up @@ -215,6 +215,7 @@ private slots:
QComboBox *cbXLog, *cbYLog, *cbZLog;
QCheckBox *boxAutoscaling, *boxShowProjection, *boxMatrices, *boxScaleFonts, *boxResize, *boxAspectRatio;
QComboBox *boxMajTicks, *boxMinTicks, *boxStyle, *boxCurveStyle, *boxSeparator, *boxLanguage, *boxDecimalSeparator;
QCheckBox *boxFloatingGraph, *boxFloatingTable;
QSpinBox *boxMinutes, *boxLineWidth, *boxFrameWidth, *boxResolution, *boxMargin, *boxPrecision, *boxAppPrecision;
QSpinBox *boxSymbolSize, *boxMinTicksLength, *boxMajTicksLength, *generatePointsBox;
DoubleSpinBox *boxCurveLineWidth;
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/MantidPlot/src/Mantid/MantidUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ MantidMatrix* MantidUI::importMatrixWorkspace(const QString& wsName, int lower,
}
if ( !w ) return 0;

appWindow()->addSubWindowToMdiArea(w,makeVisible);
appWindow()->addMdiSubWindow(w,makeVisible);
return w;
}

Expand Down Expand Up @@ -1801,7 +1801,7 @@ InstrumentWindow* MantidUI::getInstrumentView(const QString & wsName, int tab)

insWin->selectTab(tab);

appWindow()->addSubWindowToMdiArea(insWin);
appWindow()->addMdiSubWindow(insWin);
appWindow()->addListViewItem(insWin);

connect(insWin,SIGNAL(plotSpectra(const QString&,const std::set<int>&)),this,
Expand Down Expand Up @@ -3182,7 +3182,7 @@ MantidMatrix* MantidUI::openMatrixWorkspace(ApplicationWindow* parent,const QStr
w = new MantidMatrix(ws, appWindow(), "Mantid",wsName, lower, upper);
if ( !w ) return 0;

appWindow()->addSubWindowToMdiArea(w);
appWindow()->addMdiSubWindow(w);

return w;
}
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/MantidPlot/src/MdiSubWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ QString MdiSubWindow::parseMacAsciiFile(const QString& fname, const QString &com

void MdiSubWindow::goFloat()
{
d_app->goFloat(this);
d_app->changeToFloating(this);
}

void MdiSubWindow::goMdi()
Expand Down

0 comments on commit 6979634

Please sign in to comment.