diff --git a/Modules/QtWidgetsExt/src/QmitkColorPropertyEditor.cpp b/Modules/QtWidgetsExt/src/QmitkColorPropertyEditor.cpp index 254c1afea4..dd4d4e1d08 100644 --- a/Modules/QtWidgetsExt/src/QmitkColorPropertyEditor.cpp +++ b/Modules/QtWidgetsExt/src/QmitkColorPropertyEditor.cpp @@ -1,279 +1,271 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkColorPropertyEditor.h" #include #include -#include #include #include #include #include //----- QmitkPopupColorChooser --------------------------------------------------------- QmitkPopupColorChooser::QmitkPopupColorChooser(QWidget *parent, unsigned int steps, unsigned int size) : QFrame(parent, Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Tool | Qt::X11BypassWindowManagerHint), my_parent(parent) { setSteps(steps); setLineWidth(2); setMouseTracking(true); setFrameStyle(QFrame::Panel | QFrame::Raised); setLineWidth(1); ensurePolished(); resize(size, size); hide(); } QmitkPopupColorChooser::~QmitkPopupColorChooser() { } void QmitkPopupColorChooser::setSteps(int steps) { m_Steps = steps; m_Steps2 = m_Steps / 2; m_HStep = 360 / m_Steps; m_SStep = 512 / m_Steps; m_VStep = 512 / m_Steps; } void QmitkPopupColorChooser::keyReleaseEvent(QKeyEvent *) { emit colorSelected(m_OriginalColor); close(); } void QmitkPopupColorChooser::mouseMoveEvent(QMouseEvent *e) { double x(e->pos().x()); double y(e->pos().y()); x /= width(); if (x >= 0.0) { x = (int)(x * (float)(m_Steps - 1)) / (float)(m_Steps - 1); if (x > 1.0) x = 1.0; if (x < 0.0) x = 0.0; } y /= height(); if (y >= 1.0) y = 0.9; if (y < 0.0) y = 0.0; y = (int)(y * (float)m_Steps) / (float)m_Steps; m_H = static_cast(y * 359.0); if (x >= 0.5) { m_S = static_cast((1.0 - x) * 511.0); if (m_S > 255) m_S = 255; m_V = 255; } else { m_S = 255; if (x < 0.0) m_V = 0; else { m_V = static_cast(x * 511.0 + 511.0 / (float)(m_Steps - 1)); if (m_V > 255) m_V = 255; } } QColor color; color.setHsv(m_H, m_S, m_V); emit colorSelected(color); } void QmitkPopupColorChooser::mouseReleaseEvent(QMouseEvent *) { close(); } void QmitkPopupColorChooser::closeEvent(QCloseEvent *e) { e->accept(); releaseKeyboard(); releaseMouse(); if (!m_popupParent) return; // remember that we (as a popup) might recieve the mouse release // event instead of the popupParent. This is due to the fact that // the popupParent popped us up in its mousePressEvent handler. To // avoid the button remaining in pressed state we simply send a // faked mouse button release event to it. // Maleike: parent should not pop us on MouseRelease! QMouseEvent me(QEvent::MouseButtonRelease, QPoint(0, 0), QPoint(0, 0), Qt::LeftButton, Qt::NoButton, Qt::NoModifier); QApplication::sendEvent(m_popupParent, &me); } void QmitkPopupColorChooser::popup(QWidget *parent, const QPoint &point, const mitk::Color *color) { m_popupParent = parent; if (m_popupParent) { QPoint newPos; if (color) { QColor qcolor((int)((*color)[0] * 255.0), (int)((*color)[1] * 255.0), (int)((*color)[2] * 255.0)); int h, s, v; qcolor.getHsv(&h, &s, &v); if (h == -1) // set by Qt if color is achromatic ( but this widget does not display grays ) h = 10; // red int x, y; float cellwidth = (float)width() / (float)(m_Steps); if (s > v) // restrict to the colors we can display { // left side, ramp from v = 255/m_Steps to v = 255 s = 255; x = (int)((((float)v / 255.0) * ((float)m_Steps2) - 1.0) * cellwidth + cellwidth / 2); } else { v = 255; x = (int)(((1.0 - ((float)s / 255.0)) * ((float)m_Steps2)) * cellwidth + cellwidth / 2 + width() / 2); } y = (int)((float)h / 360.0 * (float)m_Steps * cellwidth); m_OriginalColor.setHsv(h, s, v); // move to color newPos.setX(point.x() - x); newPos.setY(point.y() - y); } else { // center widget m_OriginalColor.setHsv(-1, 0, 0); newPos.setX(point.x() - width() / 2); newPos.setY(point.y() - height() / 2); } move(m_popupParent->mapToGlobal(newPos)); } show(); raise(); grabMouse(); grabKeyboard(); } void QmitkPopupColorChooser::paintEvent(QPaintEvent *) { QPainter painter(this); drawGradient(&painter); } void QmitkPopupColorChooser::drawGradient(QPainter *p) { p->setWindow(0, 0, m_Steps - 1, m_Steps); // defines coordinate system p->setPen(Qt::NoPen); QColor c; for (unsigned int h = 0; h < m_Steps; ++h) { for (unsigned int v = 1; v < m_Steps2; ++v) { c.setHsv(h * m_HStep, 255, v * m_VStep); // rainbow effect p->setBrush(c); // solid fill with color c p->drawRect(v - 1, h, m_Steps2, m_Steps); // draw the rectangle } for (unsigned int s = 0; s < m_Steps2; ++s) { c.setHsv(h * m_HStep, 255 - s * m_SStep, 255); // rainbow effect p->setBrush(c); // solid fill with color c p->drawRect(m_Steps2 + s - 1, h, m_Steps2, m_Steps); // draw the rectangle } } } //----- QmitkColorPropertyEditor -------------------------------------------------- // initialization of static pointer to color picker widget QmitkPopupColorChooser *QmitkColorPropertyEditor::colorChooser = nullptr; int QmitkColorPropertyEditor::colorChooserRefCount = 0; QmitkColorPropertyEditor::QmitkColorPropertyEditor(const mitk::ColorProperty *property, QWidget *parent) : QmitkColorPropertyView(property, parent) { - // our popup belongs to the whole screen, so it could be drawn outside the toplevel window's borders - int scr; - if (QApplication::desktop()->isVirtualDesktop()) - scr = QApplication::desktop()->screenNumber(parent->mapToGlobal(pos())); - else - scr = QApplication::desktop()->screenNumber(parent); - if (colorChooserRefCount == 0) { - colorChooser = new QmitkPopupColorChooser(QApplication::desktop()->screen(scr), 50); + colorChooser = new QmitkPopupColorChooser(nullptr, 50); } ++colorChooserRefCount; } QmitkColorPropertyEditor::~QmitkColorPropertyEditor() { --colorChooserRefCount; if (!colorChooserRefCount) { delete colorChooser; colorChooser = nullptr; } } void QmitkColorPropertyEditor::mousePressEvent(QMouseEvent *e) { connect(colorChooser, SIGNAL(colorSelected(QColor)), this, SLOT(onColorSelected(QColor))); if (m_ColorProperty) { colorChooser->popup(this, e->pos(), &(m_ColorProperty->GetColor())); } } void QmitkColorPropertyEditor::mouseReleaseEvent(QMouseEvent *) { disconnect(colorChooser, SIGNAL(colorSelected(QColor)), this, SLOT(onColorSelected(QColor))); } void QmitkColorPropertyEditor::onColorSelected(QColor c) { if (m_ColorProperty) { int r, g, b; c.getRgb(&r, &g, &b); const_cast(m_ColorProperty)->SetColor(r / 255.0, g / 255.0, b / 255.0); m_ColorProperty->Modified(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } diff --git a/Plugins/org.blueberry.ui.qt/src/internal/berryQtWidgetsTweaklet.h b/Plugins/org.blueberry.ui.qt/src/internal/berryQtWidgetsTweaklet.h index b6ea262bba..3197b38fad 100755 --- a/Plugins/org.blueberry.ui.qt/src/internal/berryQtWidgetsTweaklet.h +++ b/Plugins/org.blueberry.ui.qt/src/internal/berryQtWidgetsTweaklet.h @@ -1,127 +1,127 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #ifndef BERRYQTWIDGETSTWEAKLET_H_ #define BERRYQTWIDGETSTWEAKLET_H_ #include #include "berryQtWidgetsTweakletImpl.h" namespace berry { class QtWidgetsTweaklet : public QObject, public GuiWidgetsTweaklet { Q_OBJECT Q_INTERFACES(berry::GuiWidgetsTweaklet) public: QtWidgetsTweaklet(); void AddSelectionListener(QWidget* widget, GuiTk::ISelectionListener::Pointer listener) override; void RemoveSelectionListener(QWidget* widget, GuiTk::ISelectionListener::Pointer listener) override; void AddControlListener(QWidget* widget, GuiTk::IControlListener::Pointer listener) override; void RemoveControlListener(QWidget* widget, GuiTk::IControlListener::Pointer listener) override; bool GetEnabled(QWidget* widget) override; void SetEnabled(QWidget* widget, bool enabled) override; void SetBounds(QWidget* widget, const QRect& bounds) override; QRect GetBounds(QWidget* widget) override; void SetVisible(QWidget* widget, bool visible) override; bool GetVisible(QWidget* widget) override; bool IsVisible(QWidget* widget) override; QRect GetClientArea(QWidget* widget) override; QWidget* GetParent(QWidget* widget) override; bool SetParent(QWidget* widget, QWidget* parent) override; void SetData(QWidget* widget, const QString& id, Object::Pointer data) override; Object::Pointer GetData(QWidget* widget, const QString& id) override; //IMenu::Pointer CreateMenu(QWidget*, IMenu::Style = IMenu::POP_UP); //IMenu::Pointer CreateMenu(IMenu::Pointer parent); //IMenuItem::Pointer CreateMenuItem(IMenu::Pointer, IMenuItem::Style, int index = -1); - QRect GetScreenSize(int i = -1) override; + QRect GetScreenSize(int i = 0) override; unsigned int GetScreenNumber() override; int GetPrimaryScreenNumber() override; QRect GetAvailableScreenSize(int i = -1) override; int GetClosestScreenNumber(const QRect&) override; QPoint GetCursorLocation() override; QWidget* GetCursorControl() override; QWidget* FindControl(const QList& shells, const QPoint& location) override; /** * Determines if one control is a child of another. Returns true iff the second * argument is a child of the first (or the same object). * * @param potentialParent * @param childToTest * @return */ bool IsChild(QWidget* potentialParent, QWidget* childToTest) override; /** * Returns the control which currently has keyboard focus, * or null if keyboard events are not currently going to * any of the controls built by the currently running * application. * * @return the control under the cursor */ QWidget* GetFocusControl() override; bool IsReparentable(QWidget* widget) override; void MoveAbove(QWidget* widgetToMove, QWidget* widget) override; void MoveBelow(QWidget* widgetToMove, QWidget* widget) override; void Dispose(QWidget* widget) override; Shell::Pointer CreateShell(Shell::Pointer parent, int style) override; void DisposeShell(Shell::Pointer shell) override; QWidget* CreateComposite(QWidget* parent) override; QList GetShells() override; Shell::Pointer GetShell(QWidget* widget) override; Shell::Pointer GetActiveShell() override; QRect ToControl(QWidget* coordinateSystem, const QRect& toConvert) override; QPoint ToControl(QWidget* coordinateSystem, const QPoint& toConvert) override; QRect ToDisplay(QWidget* coordinateSystem, const QRect& toConvert) override; QPoint ToDisplay(QWidget* coordinateSystem, const QPoint& toConvert) override; private: QtWidgetsTweakletImpl impl; }; } #endif /* BERRYQTWIDGETSTWEAKLET_H_ */ diff --git a/Plugins/org.blueberry.ui.qt/src/internal/berryQtWidgetsTweakletImpl.cpp b/Plugins/org.blueberry.ui.qt/src/internal/berryQtWidgetsTweakletImpl.cpp index b251d0d7ee..fc03fae215 100755 --- a/Plugins/org.blueberry.ui.qt/src/internal/berryQtWidgetsTweakletImpl.cpp +++ b/Plugins/org.blueberry.ui.qt/src/internal/berryQtWidgetsTweakletImpl.cpp @@ -1,424 +1,437 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "berryLog.h" #include "berryQtWidgetsTweakletImpl.h" #include "berryQtSash.h" #include "berryQtShell.h" #include #include #include -#include #include +#include #include namespace berry { QtSelectionListenerWrapper::QtSelectionListenerWrapper(QWidget* w) : widget(w) { } void QtSelectionListenerWrapper::AddListener(GuiTk::ISelectionListener::Pointer listener) { QAbstractButton* button = qobject_cast(widget); if (button != nullptr) { this->connect(button, "clicked(bool)", this, "QAbstractButtonClicked(bool)"); selectionEvents.AddListener(listener); } BERRY_WARN << "WARNING: QtWidgetsTweaklet: no suitable type for listening for selections found!\n"; } int QtSelectionListenerWrapper::RemoveListener(GuiTk::ISelectionListener::Pointer listener) { selectionEvents.RemoveListener(listener); return static_cast(std::max(selectionEvents.selected.GetListeners().size(), selectionEvents.defaultSelected.GetListeners().size())); } void QtSelectionListenerWrapper::QAbstractButtonClicked(bool /*checked*/) { GuiTk::SelectionEvent::Pointer event(new GuiTk::SelectionEvent(widget)); selectionEvents.selected(event); } void QtWidgetsTweakletImpl::AddSelectionListener(QWidget* widget, GuiTk::ISelectionListener::Pointer listener) { if (widget == nullptr) return; // special handling for berry::QtSash QtSash* sash = qobject_cast(widget); if (sash != nullptr) { sash->AddSelectionListener(listener); return; } // "normal" Qt widgets get wrapped QtSelectionListenerWrapper* wrapper = selectionListenerMap[widget]; if (wrapper == nullptr) { wrapper = new QtSelectionListenerWrapper(widget); selectionListenerMap[widget] = wrapper; } wrapper->AddListener(listener); } void QtWidgetsTweakletImpl::RemoveSelectionListener(QWidget* widget, GuiTk::ISelectionListener::Pointer listener) { if (widget == nullptr) return; // special handling for berry::QtSash QtSash* sash = qobject_cast(widget); if (sash != nullptr) { sash->RemoveSelectionListener(listener); return; } QtSelectionListenerWrapper* wrapper = selectionListenerMap[widget]; if (wrapper == nullptr) return; if (wrapper->RemoveListener(listener) == 0) { selectionListenerMap.remove(widget); delete wrapper; } } QRect QtWidgetsTweakletImpl::GetScreenSize(int i) { - QDesktopWidget *desktop = QApplication::desktop(); - if (i < 0) return desktop->screen()->geometry(); - return desktop->screenGeometry(i); + return QGuiApplication::screens().at(i)->geometry(); } unsigned int QtWidgetsTweakletImpl::GetScreenNumber() { - QDesktopWidget *desktop = QApplication::desktop(); - // get the primary screen - unsigned int numScreens = desktop->numScreens(); - return numScreens; + return QGuiApplication::screens().size(); } int QtWidgetsTweakletImpl::GetPrimaryScreenNumber() { - QDesktopWidget *desktop = QApplication::desktop(); - // get the primary screen - int primaryScreenNr = desktop->primaryScreen(); - return primaryScreenNr; + auto primaryScreenHandle = QGuiApplication::primaryScreen()->handle(); + auto screens = QGuiApplication::screens(); + const auto numberOfScreens = static_cast(screens.size()); + + for (int i = 0; i < numberOfScreens; ++i) + { + if (screens[i]->handle() == primaryScreenHandle) + return i; + } + + return 0; } QRect QtWidgetsTweakletImpl::GetAvailableScreenSize(int i) { - QDesktopWidget *desktop = QApplication::desktop(); - if (i < 0) return desktop->screen()->geometry(); - return desktop->availableGeometry(i); + return QGuiApplication::screens().at(i)->availableGeometry(); } int QtWidgetsTweakletImpl::GetClosestScreenNumber(const QRect& r) { - QDesktopWidget *desktop = QApplication::desktop(); - return desktop->screenNumber(QPoint(r.x() + r.width()/2, r.y() + r.height()/2)); + auto screen = QGuiApplication::screenAt(QPoint(r.x() + r.width() / 2, r.y() + r.height() / 2)); + + if (screen != nullptr) + { + auto screens = QGuiApplication::screens(); + const auto numberOfScreens = static_cast(screens.size()); + + for (int i = 0; i < numberOfScreens; ++i) + { + if (screens[i]->handle() == screen->handle()) + return i; + } + } + + return 0; } void QtWidgetsTweakletImpl::AddControlListener(QtWidgetController* controller, GuiTk::IControlListener::Pointer listener) { controller->AddControlListener(listener); } void QtWidgetsTweakletImpl::RemoveControlListener(QtWidgetController* controller, GuiTk::IControlListener::Pointer listener) { controller->RemoveControlListener(listener); } bool QtWidgetsTweakletImpl::GetEnabled(QWidget* widget) { return widget->isEnabled(); } void QtWidgetsTweakletImpl::SetEnabled(QWidget* widget, bool enabled) { widget->setEnabled(enabled); } void QtWidgetsTweakletImpl::SetBounds(QWidget* widget, const QRect& bounds) { widget->setGeometry(bounds); } QRect QtWidgetsTweakletImpl::GetBounds(QWidget* widget) { const QRect& geometry = widget->geometry(); QRect rect(geometry.x(), geometry.y(), geometry.width(), geometry.height()); return rect; } void QtWidgetsTweakletImpl::SetVisible(QWidget* widget, bool visible) { widget->setVisible(visible); } bool QtWidgetsTweakletImpl::GetVisible(QWidget* widget) { return !widget->isHidden(); } bool QtWidgetsTweakletImpl::IsVisible(QWidget* widget) { return widget->isVisible(); } QRect QtWidgetsTweakletImpl::GetClientArea(QWidget* widget) { return widget->contentsRect(); } QWidget* QtWidgetsTweakletImpl::GetParent(QWidget* widget) { return widget->parentWidget(); } bool QtWidgetsTweakletImpl::SetParent(QWidget* widget, QWidget* parent) { if (parent != widget->parentWidget()) { widget->setParent(parent); return true; } return false; } void QtWidgetsTweakletImpl::SetData(QWidget* object, const QString& id, Object::Pointer data) { if (object == nullptr) return; QVariant variant; if (data != 0) variant.setValue(data); object->setProperty(qPrintable(id), variant); } Object::Pointer QtWidgetsTweakletImpl::GetData(QWidget* object, const QString& id) { if (object == nullptr) return Object::Pointer(nullptr); QVariant variant = object->property(qPrintable(id)); if (variant.isValid()) { return variant.value(); } return Object::Pointer(nullptr); } QPoint QtWidgetsTweakletImpl::GetCursorLocation() { QPoint qpoint = QCursor::pos(); return QPoint(qpoint.x(), qpoint.y()); } QWidget* QtWidgetsTweakletImpl::GetCursorControl() { return QApplication::widgetAt(QCursor::pos()); } QWidget* QtWidgetsTweakletImpl::FindControl(const QList& shells, const QPoint& location) { for (QList::const_iterator iter = shells.begin(); iter != shells.end(); ++iter) { QWidget* shellWidget = static_cast((*iter)->GetControl()); QWidget* control = shellWidget->childAt(location.x(), location.y()); if (control) return control; } return nullptr; } bool QtWidgetsTweakletImpl::IsChild(QObject* parentToTest, QObject* childToTest) { bool found = false; QObject* parent = childToTest->parent(); while (!found && parent != nullptr) { if (parent == parentToTest) found = true; parent = parent->parent(); } return found; } QWidget* QtWidgetsTweakletImpl::GetFocusControl() { return QApplication::focusWidget(); } bool QtWidgetsTweakletImpl::IsReparentable(QWidget* /*widget*/) { return true; } void QtWidgetsTweakletImpl::MoveAbove(QWidget* widgetToMove, QWidget* /*widget*/) { widgetToMove->raise(); } void QtWidgetsTweakletImpl::MoveBelow(QWidget* widgetToMove, QWidget* /*widget*/) { widgetToMove->lower(); } void QtWidgetsTweakletImpl::Dispose(QWidget* widget) { delete widget; widget = nullptr; } Shell::Pointer QtWidgetsTweakletImpl::CreateShell(Shell::Pointer parent, int style) { Qt::WindowFlags qtFlags(Qt::CustomizeWindowHint); if (style & Constants::MAX) qtFlags |= Qt::WindowMaximizeButtonHint; if (style & Constants::MIN) qtFlags |= Qt::WindowMinimizeButtonHint; if (style & Constants::CLOSE) { qtFlags |= Qt::WindowSystemMenuHint; qtFlags |= Qt::WindowCloseButtonHint; } if (!(style & Constants::BORDER)) qtFlags |= Qt::FramelessWindowHint; if (style & Constants::TITLE) qtFlags |= Qt::WindowTitleHint; if (style & Constants::TOOL) qtFlags |= Qt::Tool; QWidget* parentWidget = nullptr; if (parent != 0) parentWidget = static_cast(parent->GetControl()); auto qtshell = new QtShell(parentWidget, qtFlags); Shell::Pointer shell(qtshell); shellList.push_back(shell); if ((style & Constants::APPLICATION_MODAL) || (style & Constants::SYSTEM_MODAL)) qtshell->GetWidget()->setWindowModality(Qt::ApplicationModal); if (style & Constants::PRIMARY_MODAL) qtshell->GetWidget()->setWindowModality(Qt::WindowModal); return shell; } QWidget* QtWidgetsTweakletImpl::CreateComposite(QWidget* parent) { QWidget* composite = new QtControlWidget(parent, nullptr); composite->setObjectName("created composite"); return composite; } void QtWidgetsTweakletImpl::DisposeShell(Shell::Pointer shell) { shellList.removeAll(shell); shell->SetVisible(false); } QList QtWidgetsTweakletImpl::GetShells() { return shellList; } Shell::Pointer QtWidgetsTweakletImpl::GetShell(QWidget* widget) { QWidget* qwindow = widget->window(); QVariant variant = qwindow->property(QtWidgetController::PROPERTY_ID); if (variant.isValid()) { QtWidgetController::Pointer controller = variant.value(); poco_assert(controller != 0); return controller->GetShell(); } return Shell::Pointer(nullptr); } Shell::Pointer QtWidgetsTweakletImpl::GetActiveShell() { QWidget* qwidget = QApplication::activeWindow(); if (qwidget == nullptr) return Shell::Pointer(nullptr); QVariant variant = qwidget->property(QtWidgetController::PROPERTY_ID); if (variant.isValid()) { return variant.value()->GetShell(); } return Shell::Pointer(nullptr); } QRect QtWidgetsTweakletImpl::ToControl(QWidget* coordinateSystem, const QRect& toConvert) { QPoint globalUpperLeft = toConvert.topLeft(); QPoint globalLowerRight = toConvert.bottomRight(); QPoint upperLeft = coordinateSystem->mapFromGlobal(globalUpperLeft); QPoint lowerRight = coordinateSystem->mapFromGlobal(globalLowerRight); return QRect(upperLeft.x(), upperLeft.y(), lowerRight.x() - upperLeft.x(), lowerRight.y() - upperLeft.y()); } QPoint QtWidgetsTweakletImpl::ToControl(QWidget* coordinateSystem, const QPoint& toConvert) { return coordinateSystem->mapFromGlobal(toConvert); } QRect QtWidgetsTweakletImpl::ToDisplay(QWidget* coordinateSystem, const QRect& toConvert) { QPoint upperLeft = toConvert.topLeft(); QPoint lowerRight = toConvert.bottomRight(); QPoint globalUpperLeft = coordinateSystem->mapToGlobal(upperLeft); QPoint globalLowerRight = coordinateSystem->mapToGlobal(lowerRight); return QRect(globalUpperLeft.x(), globalUpperLeft.y(), globalLowerRight.x() - globalUpperLeft.x(), globalLowerRight.y() - globalUpperLeft.y()); } QPoint QtWidgetsTweakletImpl::ToDisplay(QWidget* coordinateSystem, const QPoint& toConvert) { return coordinateSystem->mapToGlobal(toConvert); } } diff --git a/Plugins/org.blueberry.ui.qt/src/internal/berryQtWidgetsTweakletImpl.h b/Plugins/org.blueberry.ui.qt/src/internal/berryQtWidgetsTweakletImpl.h index 9c09a2a200..6a97147d21 100755 --- a/Plugins/org.blueberry.ui.qt/src/internal/berryQtWidgetsTweakletImpl.h +++ b/Plugins/org.blueberry.ui.qt/src/internal/berryQtWidgetsTweakletImpl.h @@ -1,152 +1,152 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #ifndef BERRYQTWIDGETSTWEAKLETIMPL_H_ #define BERRYQTWIDGETSTWEAKLETIMPL_H_ #include #include #include #include #include #include namespace berry { class QtSelectionListenerWrapper : public QObject { Q_OBJECT public: QtSelectionListenerWrapper(QWidget* widget); QWidget* widget; void AddListener(GuiTk::ISelectionListener::Pointer listener); int RemoveListener(GuiTk::ISelectionListener::Pointer listener); protected slots: void QAbstractButtonClicked(bool checked); private: GuiTk::ISelectionListener::Events selectionEvents; }; class QtWidgetsTweakletImpl { public: void AddSelectionListener(QWidget* widget, GuiTk::ISelectionListener::Pointer listener); void RemoveSelectionListener(QWidget* widget, GuiTk::ISelectionListener::Pointer listener); void AddControlListener(QtWidgetController* widget, GuiTk::IControlListener::Pointer listener); void RemoveControlListener(QtWidgetController* widget, GuiTk::IControlListener::Pointer listener); bool GetEnabled(QWidget* widget); void SetEnabled(QWidget* widget, bool enabled); void SetBounds(QWidget* widget, const QRect& bounds); QRect GetBounds(QWidget* widget); void SetVisible(QWidget* widget, bool visible); bool GetVisible(QWidget* widget); bool IsVisible(QWidget* widget); QRect GetClientArea(QWidget* widget); QWidget* GetParent(QWidget* widget); bool SetParent(QWidget* widget, QWidget* parent); void SetData(QWidget* widget, const QString& id, Object::Pointer data); Object::Pointer GetData(QWidget* widget, const QString& id); - QRect GetScreenSize(int i = -1); + QRect GetScreenSize(int i = 0); unsigned int GetScreenNumber(); int GetPrimaryScreenNumber(); - QRect GetAvailableScreenSize(int i = -1); + QRect GetAvailableScreenSize(int i = 0); int GetClosestScreenNumber(const QRect&); QPoint GetCursorLocation(); QWidget* GetCursorControl(); QWidget* FindControl(const QList& shells, const QPoint& location); /** * Determines if one control is a child of another. Returns true iff the second * argument is a child of the first (or the same object). * * @param potentialParent * @param childToTest * @return */ bool IsChild(QObject* potentialParent, QObject* childToTest); /** * Returns the control which currently has keyboard focus, * or null if keyboard events are not currently going to * any of the controls built by the currently running * application. * * @return the control under the cursor */ QWidget* GetFocusControl(); bool IsReparentable(QWidget* widget); void MoveAbove(QWidget* widgetToMove, QWidget* widget); void MoveBelow(QWidget* widgetToMove, QWidget* widget); void Dispose(QWidget* widget); Shell::Pointer CreateShell(Shell::Pointer parent, int style); void DisposeShell(Shell::Pointer shell); QWidget* CreateComposite(QWidget* parent); QList GetShells(); Shell::Pointer GetShell(QWidget* widget); Shell::Pointer GetActiveShell(); QRect ToControl(QWidget* coordinateSystem, const QRect& toConvert); QPoint ToControl(QWidget* coordinateSystem, const QPoint& toConvert); QRect ToDisplay(QWidget* coordinateSystem, const QRect& toConvert); QPoint ToDisplay(QWidget* coordinateSystem, const QPoint& toConvert); private: typedef QHash SelectionListenerMap; SelectionListenerMap selectionListenerMap; QList shellList; friend class QtShell; }; } #endif /* BERRYQTWIDGETSTWEAKLETIMPL_H_ */ diff --git a/Plugins/org.blueberry.ui.qt/src/tweaklets/berryGuiWidgetsTweaklet.h b/Plugins/org.blueberry.ui.qt/src/tweaklets/berryGuiWidgetsTweaklet.h index ce09eb7a02..0edede110d 100755 --- a/Plugins/org.blueberry.ui.qt/src/tweaklets/berryGuiWidgetsTweaklet.h +++ b/Plugins/org.blueberry.ui.qt/src/tweaklets/berryGuiWidgetsTweaklet.h @@ -1,208 +1,208 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #ifndef BERRYGUIWIDGETSTWEAKLET_H_ #define BERRYGUIWIDGETSTWEAKLET_H_ #include "internal/berryTweaklets.h" #include "guitk/berryGuiTkISelectionListener.h" #include "guitk/berryGuiTkIControlListener.h" #include "berryShell.h" //#include "commands/berryIMenu.h" //#include "commands/berryIMenuItem.h" namespace berry { struct BERRY_UI_QT GuiWidgetsTweaklet { static Tweaklets::TweakKey KEY; virtual void AddSelectionListener(QWidget* widget, GuiTk::ISelectionListener::Pointer listener) = 0; virtual void RemoveSelectionListener(QWidget* widget, GuiTk::ISelectionListener::Pointer listener) = 0; /** * Adds the listener to the collection of listeners who will * be notified when the widget is moved or resized, by sending * it one of the messages defined in the IControlListener * interface. * * @param widget * @param listener the listener which should be notified * * @see IControlListener * @see #RemoveControlListener */ virtual void AddControlListener(QWidget* widget, GuiTk::IControlListener::Pointer listener) = 0; /** * Removes the listener from the collection of listeners who will * be notified when the widget is moved or resized. * * @param widget * @param listener the listener which should no longer be notified * * @see IControlListener * @see #AddControlListener */ virtual void RemoveControlListener(QWidget* widget, GuiTk::IControlListener::Pointer listener) = 0; virtual bool GetEnabled(QWidget* widget) = 0; virtual void SetEnabled(QWidget* widget, bool enabled) = 0; virtual void SetBounds(QWidget* widget, const QRect& bounds) = 0; virtual QRect GetBounds(QWidget* widget) = 0; virtual void SetVisible(QWidget* widget, bool visible) = 0; virtual bool GetVisible(QWidget* widget) = 0; virtual bool IsVisible(QWidget* widget) = 0; virtual QRect GetClientArea(QWidget* widget) = 0; virtual QWidget* GetParent(QWidget* widget) = 0; virtual bool SetParent(QWidget* widget, QWidget* parent) = 0; virtual void SetData(QWidget* widget, const QString& id, Object::Pointer data) = 0; virtual Object::Pointer GetData(QWidget* widget, const QString& id) = 0; virtual QPoint GetCursorLocation() = 0; virtual QWidget* GetCursorControl() = 0; virtual QWidget* FindControl(const QList& shells, const QPoint& location) = 0; /** * Determines if one control is a child of another. Returns true iff the second * argument is a child of the first (or the same object). * * @param potentialParent * @param childToTest * @return */ virtual bool IsChild(QWidget* potentialParent, QWidget* childToTest) = 0; /** * Returns the control which currently has keyboard focus, * or null if keyboard events are not currently going to * any of the controls built by the currently running * application. * * @return the control under the cursor */ virtual QWidget* GetFocusControl() = 0; virtual bool IsReparentable(QWidget* widget) = 0; virtual void MoveAbove(QWidget* widgetToMove, QWidget* widget) = 0; virtual void MoveBelow(QWidget* widgetToMove, QWidget* widget) = 0; virtual void Dispose(QWidget* widget) = 0; virtual Shell::Pointer CreateShell(Shell::Pointer parent, int style) = 0; virtual void DisposeShell(Shell::Pointer shell) = 0; virtual QWidget* CreateComposite(QWidget* parent) = 0; virtual QList GetShells() = 0; virtual Shell::Pointer GetShell(QWidget* widget) = 0; virtual Shell::Pointer GetActiveShell() = 0; // command framework interface classes //virtual IMenu::Pointer CreateMenu(QWidget*, IMenu::Style = IMenu::POP_UP) = 0; //virtual IMenu::Pointer CreateMenu(IMenu::Pointer parent) = 0; //virtual IMenuItem::Pointer CreateMenuItem(IMenu::Pointer, IMenuItem::Style, int index = -1) = 0; /** * @brief returns the coordinates of the center point of the primary screen * (where the application starts) of the current desktop. * * @param i the number of the screen (if there are multiple). If i = -1 * a rectangle representing the size of the virtual desktop is returned. * @return the screen Geometry. * @see GetScreenNumber() * @see GetPrimaryScreenNumber() */ - virtual QRect GetScreenSize(int i = -1) = 0; + virtual QRect GetScreenSize(int i = 0) = 0; - virtual QRect GetAvailableScreenSize(int i = -1) = 0; + virtual QRect GetAvailableScreenSize(int i = 0) = 0; virtual int GetClosestScreenNumber(const QRect&) = 0; /** * @brief Gets the number of available screens in a multi-screen environment. * * @return the number of available screens in a multi-screen environment. */ virtual unsigned int GetScreenNumber() = 0; /** * @brief Gets the number of the primary screen. * * @return the number of the primary screen. */ virtual int GetPrimaryScreenNumber() = 0; /** * Converts the given rectangle from display coordinates to the local coordinate system * of the given object * * @param coordinateSystem local coordinate system (widget) being converted to * @param toConvert rectangle to convert * @return a rectangle in control coordinates * @since 3.0 */ virtual QRect ToControl(QWidget* coordinateSystem, const QRect& toConvert) = 0; /** * Converts the given point from display coordinates to the local coordinate system * of the given object * * @param coordinateSystem local coordinate system (widget) being converted to * @param toConvert point to convert * @return a point in control coordinates * @since 3.0 */ virtual QPoint ToControl(QWidget* coordinateSystem, const QPoint& toConvert) = 0; /** * Converts the given rectangle from the local coordinate system of the given object * into display coordinates. * * @param coordinateSystem local coordinate system (widget) being converted from * @param toConvert rectangle to convert * @return a rectangle in display coordinates * @since 3.0 */ virtual QRect ToDisplay(QWidget* coordinateSystem, const QRect& toConvert) = 0; /** * Converts the given point from the local coordinate system of the given object * into display coordinates. * * @param coordinateSystem local coordinate system (widget) being converted from * @param toConvert point to convert * @return a point in display coordinates * @since 3.0 */ virtual QPoint ToDisplay(QWidget* coordinateSystem, const QPoint& toConvert) = 0; }; } Q_DECLARE_INTERFACE(berry::GuiWidgetsTweaklet, "org.blueberry.GuiWidgetsTweaklet") #endif /* BERRYGUIWIDGETSTWEAKLET_H_ */ diff --git a/Plugins/org.mitk.gui.qt.application/src/QmitkStatusBar.cpp b/Plugins/org.mitk.gui.qt.application/src/QmitkStatusBar.cpp index 02584a0aa9..76ec2d1e06 100755 --- a/Plugins/org.mitk.gui.qt.application/src/QmitkStatusBar.cpp +++ b/Plugins/org.mitk.gui.qt.application/src/QmitkStatusBar.cpp @@ -1,89 +1,89 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "QmitkStatusBar.h" #include #include #include #include #include #include /** * Display the text in the statusbar of the application */ void QmitkStatusBar::DisplayText(const char* t) { m_StatusBar->showMessage(t); // TODO bug #1357 //qApp->processEvents(); // produces crashes! } /** * Display the text in the statusbar of the application for ms seconds */ void QmitkStatusBar::DisplayText(const char* t, int ms) { m_StatusBar->showMessage(t, ms); // TODO bug #1357 //qApp->processEvents(); // produces crashes! } /** * Show the grey value text in the statusbar */ void QmitkStatusBar::DisplayGreyValueText(const char* t) { QString text(t); m_GreyValueLabel->setText(text); } /** * Clear the text in the StatusBar */ void QmitkStatusBar::Clear() { if (m_StatusBar != nullptr) m_StatusBar->clearMessage(); // TODO bug #1357 //qApp->processEvents(); // produces crashes! } /** * enable or disable the QSizeGrip */ void QmitkStatusBar::SetSizeGripEnabled(bool enable) { if (m_StatusBar != nullptr) m_StatusBar->setSizeGripEnabled(enable); } QmitkStatusBar::QmitkStatusBar(QStatusBar* instance) :StatusBarImplementation() { m_StatusBar = instance; m_GreyValueLabel = new QLabel(m_StatusBar,nullptr); - int xResolution = QApplication::desktop()->screenGeometry(0).width()-100; + int xResolution = QGuiApplication::primaryScreen()->geometry().width()-100; m_GreyValueLabel->setMaximumSize(QSize(xResolution,50)); m_GreyValueLabel->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Fixed); m_StatusBar->addPermanentWidget(m_GreyValueLabel); mitk::StatusBar::SetImplementation(this); } QmitkStatusBar::~QmitkStatusBar() { }