Newer
Older
18001
18002
18003
18004
18005
18006
18007
18008
18009
18010
18011
18012
18013
18014
18015
18016
18017
18018
18019
18020
18021
18022
18023
18024
18025
18026
18027
18028
18029
18030
18031
18032
18033
18034
18035
18036
18037
18038
18039
18040
18041
18042
18043
18044
18045
18046
18047
18048
18049
18050
18051
18052
18053
18054
18055
18056
18057
18058
18059
18060
18061
18062
18063
18064
18065
18066
18067
18068
18069
18070
18071
18072
18073
18074
18075
18076
18077
18078
18079
18080
18081
18082
18083
18084
18085
18086
18087
18088
18089
18090
18091
18092
18093
18094
18095
18096
18097
18098
18099
18100
18101
18102
18103
18104
18105
18106
18107
18108
18109
18110
{
FloatingWindow* fw = w->getFloatingWindow();
if (!fw) return;
fw->removeMdiSubWindow();
removeFloatingWindow(fw);
// main window must be closed or application will freeze
fw->close();
addMdiSubWindowAsDocked(w);
//activateWindow(w);
w->setNormal();
return;
}
/**
* Remove a closed floating window from internal lists.
* @param w :: Pointer to the closed window.
*/
void ApplicationWindow::removeFloatingWindow(FloatingWindow* w)
{
if (m_floatingWindows.contains(w))
{
m_floatingWindows.remove(w);
if (w->mdiSubWindow())
{
closeWindow(w->mdiSubWindow());
}
// Make the FloatingWindow delete itself
w->deleteLater();
}
}
/**
* Return a pointer to the active FloatingWindow if the active window is floating
* or NULL otherwise.
*/
FloatingWindow* ApplicationWindow::getActiveFloating() const
{
MdiSubWindow* w = getActiveWindow();
if (!w) return NULL;
return w->getFloatingWindow();
}
/**
* Filter out the WindowActivate event and set the active subwindow correctly.
* @param e :: An event.
*/
bool ApplicationWindow::event(QEvent * e)
{
if (e->type() == QEvent::WindowActivate)
{
bool needToActivate = true;
// check if old active window is a floating one and this window was activated by clicking
// on a tool bar - in this case we shouldn't actvate another window
if (getActiveFloating())
{
QPoint cur_pos = this->mapFromGlobal(QCursor::pos());
const QWidget* clickedWidget = NULL;
if (rect().contains(cur_pos))
{
clickedWidget = childAt(cur_pos);
}
if (clickedWidget)
{
QString class_name = clickedWidget->className();
if (class_name == "QToolButton" || class_name == "QToolBar" || class_name == "QMenuBar")
{
needToActivate = false;
}
}
}
if (needToActivate)
{// activate current MDI subwindow
QMdiSubWindow* qCurrent = d_workspace->currentSubWindow();
if (qCurrent)
{
MdiSubWindow* sw = dynamic_cast<MdiSubWindow*>(qCurrent->widget());
if (!sw)
{// this should never happen - all MDI subwindow widgets must inherit from MdiSubwindow
throw std::runtime_error("Non-MdiSubwindow widget found in MDI area");
}
activateWindow(sw);
}
}
}
return QMainWindow::event(e);
}
/**
* Necessary steps to activate a floating window.
* @param w :: Activated window
*/
void ApplicationWindow::mdiWindowActivated(MdiSubWindow* w)
{
if (!w) return;
setActiveWindow(w);
}
/**
* Activate a subwindow (docked or floating) other than current active one.
* This is required when the current window is closing.
*/
void ApplicationWindow::activateNewWindow()
{
MdiSubWindow* current = getActiveWindow();
MdiSubWindow* newone = NULL;
Folder* folder = currentFolder();
// try the docked windows first
QList<QMdiSubWindow*> wl = d_workspace->subWindowList();
foreach(QMdiSubWindow* w,wl)
{
if (w->widget() != static_cast<QWidget*>(current))
{
MdiSubWindow* sw = dynamic_cast<MdiSubWindow*>(w->widget());
if (sw &&
sw->status() != MdiSubWindow::Minimized &&
sw->status() != MdiSubWindow::Hidden &&
folder->hasWindow(sw))
{
newone = sw;
break;
}
}
}
// if unsuccessful try the floating windows
if (!newone)
{
foreach(FloatingWindow* w, m_floatingWindows)
{
MdiSubWindow* sw = w->mdiSubWindow();
if (sw != current)
{
if (sw &&
sw->status() != MdiSubWindow::Minimized &&
sw->status() != MdiSubWindow::Hidden &&
folder->hasWindow(sw))
{
newone = sw;
break;
}
// activate a new sub-window or pass NULL if no window can be activated
activateWindow(newone);
18152
18153
18154
18155
18156
18157
18158
18159
18160
18161
18162
18163
18164
18165
18166
18167
18168
18169
18170
18171
18172
18173
18174
18175
18176
18177
18178
18179
18180
18181
18182
18183
18184
18185
18186
18187
18188
}
/**
* The slot to change the active window from docked to floating.
*/
void ApplicationWindow::changeActiveToFloating()
{
MdiSubWindow* activeWin = activeWindow();
changeToFloating(activeWin);
}
/**
* The slot to change the active window from floating to docked.
*/
void ApplicationWindow::changeActiveToDocked()
{
MdiSubWindow* activeWin = activeWindow();
changeToDocked(activeWin);
}
/**
* Returns if a window should be made floating by default.
* @param w :: Pointer to a MdiSubWindow.
*/
bool ApplicationWindow::isDefaultFloating(const MdiSubWindow* w) const
{
QString wClassName = w->className();
return isDefaultFloating(wClassName);
}
/**
* Returns if a window should be made floating by default.
* @param aClassName :: Class name of a MdiSubWindow or its internal widget in case of custom interfaces.
*/
bool ApplicationWindow::isDefaultFloating(const QString& aClassName) const
{
bool theDefault = false;
if (aClassName == "MultiLayer" || aClassName =="InstrumentWindow" || aClassName == "MdiSubWindow")
{
theDefault = true;
}
return settings.value("/General/FloatingWindows/"+aClassName,theDefault).toBool();
}
18197
18198
18199
18200
18201
18202
18203
18204
18205
18206
18207
18208
18209
18210
18211
18212
18213
18214
18215
18216
18217
18218
18219
18220
18221
18222
18223
18224
18225
18226
18227
18228
18229
18230
/**
* Check that a widow will be visible if moved to these coordinates and
* set them to default values otherwise.
* @param w :: Pointer to a sub-window.
* @param x :: Tested x coordinate
* @param y :: Tested y coordinate
*/
void ApplicationWindow::validateWindowPos(MdiSubWindow* w, int& x, int& y)
{
QSize sz = w->size();
if ( w->getFloatingWindow() )
{
QWidget* desktop = QApplication::desktop()->screen();
QPoint pos(x, y);
pos += desktopTopLeft();
if ( pos.x() < 0 || pos.y() < 0 ||
pos.x() + sz.width() > desktop->width() ||
pos.y() + sz.height() > desktop->height() )
{
pos = positionNewFloatingWindow(sz);
}
x = pos.x();
y = pos.y();
return;
}
else if ( x < 0 || y < 0 ||
x + sz.width() > d_workspace->width() ||
y + sz.height() > d_workspace->height() )
{
x = y = 0;
}
}