21 #include <QMainWindow> 34 Window::WindowShellListener::WindowShellListener(Window* wnd)
43 if (window->CanHandleShellCloseEvent())
45 window->HandleShellCloseEvent();
49 void Window::DefaultExceptionHandler::HandleException(
const std::exception& t)
52 std::cerr << t.what();
68 Shell::Pointer modalChild = Window::GetModalChild(parent->GetShells());
78 Shell::Pointer Window::GetModalChild(
const QList<Shell::Pointer>& toSearch)
82 int size = toSearch.size();
83 for (
int i = size - 1; i < size; i--)
88 QList<Shell::Pointer> children = shell->GetShells();
96 if (shell->IsVisible() && (shell->GetStyle() & modal) != 0)
143 poco_assert(shellProvider != 0);
144 this->parentShell = shellProvider;
156 this->returnCode =
OK;
174 if (defaultImages.size() > 0)
193 newShell->SetImages(defaultImages);
202 CreateTrimWidgets(newShell);
220 return parent->GetControl();
246 newShell->AddShellListener(this->GetShellListener());
249 this->ConfigureShell(newShell);
270 QPoint centerPoint(0,0);
271 QRect parentBounds(0,0,0,0);
272 if (parent !=
nullptr)
275 centerPoint.setX(parentBounds.x() + parentBounds.width()/2);
276 centerPoint.setY(parentBounds.y() - parentBounds.height()/2);
282 centerPoint.setX(parentBounds.width()/2);
283 centerPoint.setY(parentBounds.height()/2);
286 return QPoint(centerPoint.x() - (initialSize.x() / 2),
287 std::max<int>(parentBounds.y(),
288 std::min<int>(centerPoint.y() - (initialSize.y() * 2 / 3),
289 parentBounds.y() + parentBounds.height() - initialSize.y())));
303 if ((this->GetShellStyle() & modal) != 0)
308 parent = defaultModalParent->GetShell();
317 if (windowShellListener.isNull())
318 windowShellListener.reset(
new WindowShellListener(
this));
320 return windowShellListener.data();
330 this->SetReturnCode(CANCEL);
345 QPoint size = this->GetInitialSize();
346 QPoint location = this->GetInitialLocation(size);
347 shell->SetBounds(this->GetConstrainedShellBounds(QRect(location.x(), location.y(), size.x(), size.y())));
352 QRect result(preferredSize);
358 if (result.height() > bounds.height()) {
359 result.setHeight(bounds.height());
362 if (result.width() > bounds.width()) {
363 result.setWidth(bounds.width());
366 result.moveLeft( std::max<int>(bounds.x(), std::min<int>(result.x(), bounds.x()
367 + bounds.width() - result.width())));
368 result.moveTop(std::max<int>(bounds.y(), std::min<int>(result.y(), bounds.y()
369 + bounds.height() - result.height())));
376 poco_assert(shell == 0);
387 shellStyle = newShellStyle;
392 if (GetShell().IsNull() && menuBarManager.IsNull())
394 menuBarManager = CreateMenuManager();
406 if (menuBarManager.IsNotNull())
408 QMainWindow* mw = qobject_cast<QMainWindow*>(shell->GetControl());
411 mw->setMenuBar(menuBarManager->CreateMenuBar(shell->GetControl()));
412 menuBarManager->UpdateAll(
true);
438 if (windowManager !=
nullptr)
441 windowManager =
nullptr;
449 shell->RemoveShellListener(this->GetShellListener());
464 shell = this->CreateShell();
465 contents = this->CreateContents(shell);
469 this->InitializeBounds();
474 return (defaultImages.size() < 1) ? QIcon() : defaultImages[0];
479 return defaultImages;
494 return windowManager;
499 return menuBarManager.GetPointer();
534 defaultImages.push_back(image);
544 windowManager = manager;
548 if (manager !=
nullptr)
550 QList<Window::Pointer> windows = manager->GetWindows();
551 for (
int i = 0; i < windows.size(); i++)
553 if (windows[i] ==
this)
564 if (exceptionHandler == 0)
572 defaultModalParent = provider;
static MsgHandler handler
void SetParentShell(Shell::Pointer newParentShell)
virtual SmartPointer< MenuManager > CreateMenuManager()
MenuManager * GetMenuBarManager() const
void SetReturnCode(int code)
virtual void ConfigureShell(Shell::Pointer newShell)
void SetWindowManager(WindowManager *manager)
virtual IShellListener * GetShellListener()
virtual bool CanHandleShellCloseEvent()
WindowManager * GetWindowManager()
static QIcon GetDefaultImage()
virtual void CreateTrimWidgets(SmartPointer< Shell > shell)
Shell::Pointer GetParentShell()
static const int SHELL_TRIM
static void SetDefaultModalParent(IShellProvider::Pointer provider)
static void SetDefaultImage(const QIcon &image)
Shell::Pointer GetShell() const override
virtual void InitializeBounds()
void SetShellStyle(int newShellStyle)
QRect GetConstrainedShellBounds(const QRect &preferredSize)
berry::SmartPointer< Self > Pointer
virtual void HandleShellCloseEvent()
static const int SYSTEM_MODAL
virtual QWidget * CreateContents(Shell::Pointer parent)
virtual QPoint GetInitialLocation(const QPoint &initialSize)
Window(Shell::Pointer parentShell)
virtual QPoint GetInitialSize()
static const int PRIMARY_MODAL
static QList< QIcon > GetDefaultImages()
mitk::Image::Pointer image
static QList< QIcon > defaultImages
virtual Shell::Pointer CreateShell()
void SetBlockOnOpen(bool shouldBlock)
static const int APPLICATION_MODAL
virtual QWidget * GetContents()
static void SetDefaultImages(const QList< QIcon > &images)
static void SetExceptionHandler(IExceptionHandler::Pointer handler)