Public Member Functions | Public Attributes | Protected Slots | Protected Attributes

QmitkLevelWindowWidgetContextMenu Class Reference
[Widgets]

Provides a contextmenu for Level/Window functionality. Either creates a new contextmenu with standard functions or adds Level/Window standard functions to an predefined contextmenu. More...

#include <QmitkLevelWindowWidgetContextMenu.h>

Collaboration diagram for QmitkLevelWindowWidgetContextMenu:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 QmitkLevelWindowWidgetContextMenu (QWidget *parent, Qt::WindowFlags f=0)
 constructor
virtual ~QmitkLevelWindowWidgetContextMenu ()
void getContextMenu (QMenu *contextmenu)
void getContextMenu ()
 returns the contextmenu with standard functions for Level/Window
void setLevelWindowManager (mitk::LevelWindowManager *levelWindowManager)
 lets this object know about the LevelWindowManager to get all images and tell about changes

Public Attributes

mitk::LevelWindowPresetm_LevelWindowPreset
mitk::LevelWindow m_LevelWindow
QMenu * m_PresetSubmenu
 submenu with all presets for contextmenu
QMenu * m_ImageSubmenu
 submenu with all images for contextmenu
mitk::LevelWindowManagerm_Manager
std::map< QAction
*, mitk::LevelWindowProperty::Pointer
m_Images

Protected Slots

void setPreset (QAction *presetAction)
 sets level and window value of the current image to the values defined for the selected preset
void useAllGreyvaluesFromImage ()
 calls the mitkLevelWindow SetAuto method with guessByCentralSlice false, so that the greyvalues from whole image will be considered
void setFixed ()
 sets the level window slider to be fixed
void addPreset ()
 adds a new Preset for presets-contextmenu
void setDefaultLevelWindow ()
 resets the current images Level/Window to its default values
void setDefaultScaleRange ()
 resets the current images scalerange to its default values
void changeScaleRange ()
 changes the current images scalerange
void setImage (QAction *imageAction)
 sets the selected image or the topmost layer image to the new current image
void setMaximumWindow ()
 sets the window to its maximum Size to fit the scalerange

Protected Attributes

QAction * m_PresetAction
 ID of preset selected in contextmenu.
QAction * m_ImageAction
 ID of image selected in contextmenu.

Detailed Description

Provides a contextmenu for Level/Window functionality. Either creates a new contextmenu with standard functions or adds Level/Window standard functions to an predefined contextmenu.

Definition at line 33 of file QmitkLevelWindowWidgetContextMenu.h.


Constructor & Destructor Documentation

QmitkLevelWindowWidgetContextMenu::QmitkLevelWindowWidgetContextMenu ( QWidget *  parent,
Qt::WindowFlags  f = 0 
)
QmitkLevelWindowWidgetContextMenu::~QmitkLevelWindowWidgetContextMenu (  ) [virtual]

Definition at line 31 of file QmitkLevelWindowWidgetContextMenu.cpp.

References m_LevelWindowPreset.

{
  m_LevelWindowPreset->Delete();
}

Member Function Documentation

void QmitkLevelWindowWidgetContextMenu::addPreset (  ) [protected, slot]
void QmitkLevelWindowWidgetContextMenu::changeScaleRange (  ) [protected, slot]
void QmitkLevelWindowWidgetContextMenu::getContextMenu (  )

returns the contextmenu with standard functions for Level/Window

Definition at line 232 of file QmitkLevelWindowWidgetContextMenu.cpp.

References addPreset(), changeScaleRange(), mitk::LevelWindowPreset::getLevelPresets(), mitk::LevelWindowManager::GetLevelWindow(), mitk::LevelWindowManager::GetLevelWindowProperty(), mitk::DataNode::GetName(), mitk::DataNode::GetProperty(), mitk::LevelWindowManager::GetRelevantNodes(), mitk::LevelWindowManager::isAutoTopMost(), mitk::LevelWindow::IsFixed(), m_ImageAction, m_Images, m_ImageSubmenu, m_LevelWindow, m_LevelWindowPreset, m_Manager, m_PresetAction, m_PresetSubmenu, setDefaultLevelWindow(), setDefaultScaleRange(), setFixed(), setImage(), setMaximumWindow(), setPreset(), and useAllGreyvaluesFromImage().

{
  try
  {
    m_LevelWindow = m_Manager->GetLevelWindow();

    QMenu* contextMenu = new QMenu( this );
    Q_CHECK_PTR( contextMenu );
    //contextMenu->setCheckable(true);
    QAction* sliderFixed = contextMenu->addAction(tr("Set Slider Fixed"), this, SLOT(setFixed()));
    sliderFixed->setCheckable(true);
    sliderFixed->setChecked(m_LevelWindow.IsFixed());
    contextMenu->addSeparator();
    contextMenu->addAction(tr("Use Whole Image Greyvalues"), this, SLOT(useAllGreyvaluesFromImage()));
    contextMenu->addSeparator();
    contextMenu->addAction(tr("Set Maximum Window"), this, SLOT(setMaximumWindow()));
    contextMenu->addAction(tr("Default Level/Window"), this, SLOT(setDefaultLevelWindow()));
    contextMenu->addSeparator();
    contextMenu->addAction(tr("Change Scale Range"), this, SLOT(changeScaleRange()));
    contextMenu->addAction(tr("Default Scale Range"), this, SLOT(setDefaultScaleRange()));
    contextMenu->addSeparator();

    m_PresetSubmenu = new QMenu( this );
    Q_CHECK_PTR( m_PresetSubmenu );
    m_PresetSubmenu->setTitle("Presets");
    m_PresetAction = m_PresetSubmenu->addAction(tr("Preset Definition"), this, SLOT(addPreset()));
    m_PresetSubmenu->addSeparator();
    std::map<std::string, double> preset = m_LevelWindowPreset->getLevelPresets();
    for( std::map<std::string, double>::iterator iter = preset.begin(); iter != preset.end(); iter++ ) {
      QString item = ((*iter).first.c_str());
      m_PresetSubmenu->addAction(item);
    }
    connect(m_PresetSubmenu, SIGNAL(triggered(QAction*)), this, SLOT(setPreset(QAction*)));
    contextMenu->addMenu( m_PresetSubmenu );
    contextMenu->addSeparator();

    m_ImageSubmenu = new QMenu( this );
    m_ImageSubmenu->setTitle("Images");
    //m_ImageSubmenu->setCheckable(true);
    m_ImageAction = m_ImageSubmenu->addAction(tr("Set Topmost Image"));
    m_ImageAction->setCheckable(true);
    if (m_Manager->isAutoTopMost())
      m_ImageAction->setChecked(true);
    m_ImageSubmenu->addSeparator();
    Q_CHECK_PTR( m_ImageSubmenu );
    mitk::DataStorage::SetOfObjects::ConstPointer allObjects = m_Manager->GetRelevantNodes();
    for ( mitk::DataStorage::SetOfObjects::ConstIterator objectIter = allObjects->Begin(); objectIter != allObjects->End(); ++objectIter)
    {
      mitk::DataNode* node = objectIter->Value();
      if (node)
      {
        mitk::LevelWindowProperty::Pointer levelWindowProperty = dynamic_cast<mitk::LevelWindowProperty*>(node->GetProperty("levelwindow"));
        if (levelWindowProperty.IsNotNull())
        {
          std::string name;
          node->GetName(name);
          QString item = name.c_str();
          QAction* id = m_ImageSubmenu->addAction(item);
          id->setCheckable(true);
          m_Images[id] = levelWindowProperty;
          if (levelWindowProperty == m_Manager->GetLevelWindowProperty())
          {
            id->setChecked(true);
          }
        }
      }
    }
    connect(m_ImageSubmenu, SIGNAL(activated(int)), this, SLOT(setImage(int)));
    contextMenu->addMenu( m_ImageSubmenu );

    contextMenu->exec( QCursor::pos() );
    delete contextMenu;
  }
  catch(...)
  {
  }
}
void QmitkLevelWindowWidgetContextMenu::getContextMenu ( QMenu *  contextmenu )

returns the contextmenu with standard functions for Level/Window

input is a prefilled contextmenu to which standard functions will be added

Definition at line 152 of file QmitkLevelWindowWidgetContextMenu.cpp.

References addPreset(), changeScaleRange(), mitk::LevelWindowPreset::getLevelPresets(), mitk::LevelWindowManager::GetLevelWindow(), mitk::LevelWindowManager::GetLevelWindowProperty(), mitk::DataNode::GetName(), mitk::DataNode::GetProperty(), mitk::LevelWindowManager::GetRelevantNodes(), mitk::LevelWindowManager::isAutoTopMost(), mitk::LevelWindow::IsFixed(), mitk::DataNode::IsVisible(), m_ImageAction, m_Images, m_ImageSubmenu, m_LevelWindow, m_LevelWindowPreset, m_Manager, m_PresetAction, m_PresetSubmenu, setDefaultLevelWindow(), setDefaultScaleRange(), setFixed(), setImage(), setMaximumWindow(), setPreset(), and useAllGreyvaluesFromImage().

{
  try
  {
    m_LevelWindow = m_Manager->GetLevelWindow();

    QMenu* contextMenu = contextmenu;
    Q_CHECK_PTR( contextMenu );
    //contextMenu->setCheckable(true);
    QAction* sliderFixed = contextMenu->addAction(tr("Set Slider Fixed"), this, SLOT(setFixed()));
    sliderFixed->setCheckable(true);
    sliderFixed->setChecked(m_LevelWindow.IsFixed());
    contextMenu->addSeparator();
    contextMenu->addAction(tr("Use Whole Image Greyvalues"), this, SLOT(useAllGreyvaluesFromImage()));
    contextMenu->addSeparator();
    contextMenu->addAction(tr("Set Maximum Window"), this, SLOT(setMaximumWindow()));
    contextMenu->addAction(tr("Default Level/Window"), this, SLOT(setDefaultLevelWindow()));
    contextMenu->addSeparator();
    contextMenu->addAction(tr("Change Scale Range"), this, SLOT(changeScaleRange()));
    contextMenu->addAction(tr("Default Scale Range"), this, SLOT(setDefaultScaleRange()));
    contextMenu->addSeparator();

    m_PresetSubmenu = new QMenu( this );
    Q_CHECK_PTR( m_PresetSubmenu );
    m_PresetSubmenu->setTitle("Presets");
    m_PresetAction = m_PresetSubmenu->addAction(tr("Preset Definition"), this, SLOT(addPreset()));
    m_PresetSubmenu->addSeparator();
    std::map<std::string, double> preset = m_LevelWindowPreset->getLevelPresets();
    for( std::map<std::string, double>::iterator iter = preset.begin(); iter != preset.end(); iter++ ) {
      QString item = ((*iter).first.c_str());
      m_PresetSubmenu->addAction(item);
    }
    connect(m_PresetSubmenu, SIGNAL(triggered(QAction*)), this, SLOT(setPreset(QAction*)));
    contextMenu->addMenu(m_PresetSubmenu);
    contextMenu->addSeparator();

    m_ImageSubmenu = new QMenu( this );
    m_ImageSubmenu->setTitle("Images");
    //m_ImageSubmenu->setCheckable(true);
    m_ImageAction = m_ImageSubmenu->addAction(tr("Set Topmost Image"));
    m_ImageAction->setCheckable(true);
    if (m_Manager->isAutoTopMost())
      m_ImageAction->setChecked(true);
    m_ImageSubmenu->addSeparator();
    Q_CHECK_PTR( m_ImageSubmenu );
    mitk::DataStorage::SetOfObjects::ConstPointer allObjects = m_Manager->GetRelevantNodes();
    for ( mitk::DataStorage::SetOfObjects::ConstIterator objectIter = allObjects->Begin(); objectIter != allObjects->End(); ++objectIter)
    {
      mitk::DataNode* node = objectIter->Value();
      if (node)
      {
        if (node->IsVisible(NULL) == false)
          continue;
        mitk::LevelWindowProperty::Pointer levelWindowProperty = dynamic_cast<mitk::LevelWindowProperty*>(node->GetProperty("levelwindow"));
        if (levelWindowProperty.IsNotNull())
        {
          std::string name;
          node->GetName(name);
          QString item = name.c_str();
          QAction* id = m_ImageSubmenu->addAction(item);
          id->setCheckable(true);
          m_Images[id] = levelWindowProperty;
          if (levelWindowProperty == m_Manager->GetLevelWindowProperty())
          {
            id->setChecked(true);
          }
        }
      }
    }
    connect(m_ImageSubmenu, SIGNAL(triggered(QAction*)), this, SLOT(setImage(QAction*)));
    contextMenu->addMenu( m_ImageSubmenu );

    contextMenu->exec( QCursor::pos() );
    delete contextMenu;
  }
  catch(...)
  {
  }
}
void QmitkLevelWindowWidgetContextMenu::setDefaultLevelWindow (  ) [protected, slot]
void QmitkLevelWindowWidgetContextMenu::setDefaultScaleRange (  ) [protected, slot]
void QmitkLevelWindowWidgetContextMenu::setFixed (  ) [protected, slot]
void QmitkLevelWindowWidgetContextMenu::setImage ( QAction *  imageAction ) [protected, slot]

sets the selected image or the topmost layer image to the new current image

Definition at line 141 of file QmitkLevelWindowWidgetContextMenu.cpp.

References mitk::LevelWindowManager::isAutoTopMost(), m_ImageAction, m_Images, m_Manager, mitk::LevelWindowManager::SetAutoTopMostImage(), and mitk::LevelWindowManager::SetLevelWindowProperty().

Referenced by getContextMenu().

{
  if (imageAction == m_ImageAction)
    if ( m_Manager->isAutoTopMost() == false)
      m_Manager->SetAutoTopMostImage(true);
    else
      m_Manager->SetAutoTopMostImage(false);
  else
    m_Manager->SetLevelWindowProperty(m_Images[imageAction]);
}
void QmitkLevelWindowWidgetContextMenu::setLevelWindowManager ( mitk::LevelWindowManager levelWindowManager )

lets this object know about the LevelWindowManager to get all images and tell about changes

Definition at line 77 of file QmitkLevelWindowWidgetContextMenu.cpp.

References m_Manager.

{
  m_Manager = levelWindowManager;
}
void QmitkLevelWindowWidgetContextMenu::setMaximumWindow (  ) [protected, slot]
void QmitkLevelWindowWidgetContextMenu::setPreset ( QAction *  presetAction ) [protected, slot]

sets level and window value of the current image to the values defined for the selected preset

Definition at line 36 of file QmitkLevelWindowWidgetContextMenu.cpp.

References mitk::RenderingManager::GetInstance(), mitk::LevelWindowPreset::getLevel(), mitk::LevelWindow::GetRangeMax(), mitk::LevelWindow::GetRangeMin(), mitk::LevelWindowPreset::getWindow(), m_LevelWindow, m_LevelWindowPreset, m_Manager, m_PresetAction, mitk::LevelWindowManager::SetLevelWindow(), and mitk::LevelWindow::SetLevelWindow().

Referenced by getContextMenu().

{
  QString item = presetAction->text();
  if (!(presetAction == m_PresetAction))
  {
    double dlevel = m_LevelWindowPreset->getLevel(item.toStdString());
    double dwindow = m_LevelWindowPreset->getWindow(item.toStdString());
    if ((dlevel + dwindow/2) > m_LevelWindow.GetRangeMax())
    {
      double lowerBound = (dlevel - dwindow/2);
      if (!(lowerBound > m_LevelWindow.GetRangeMax()))
      {
        dwindow = m_LevelWindow.GetRangeMax() - lowerBound;
        dlevel = lowerBound + dwindow/2;
      }
      else
      {
        dlevel = m_LevelWindow.GetRangeMax() - 1;
        dwindow = 2;
      }
    }
    else if ((dlevel - dwindow/2) < m_LevelWindow.GetRangeMin())
    {
      double upperBound = (dlevel + dwindow/2);
      if (!(upperBound < m_LevelWindow.GetRangeMin()))
      {
        dwindow = m_LevelWindow.GetRangeMin() + upperBound;
        dlevel = upperBound - dwindow/2;
      }
      else
      {
        dlevel = m_LevelWindow.GetRangeMin() + 1;
        dwindow = 2;
      }
    }
    m_LevelWindow.SetLevelWindow(dlevel, dwindow);
    m_Manager->SetLevelWindow(m_LevelWindow);
    mitk::RenderingManager::GetInstance()->RequestUpdateAll();
  }
}
void QmitkLevelWindowWidgetContextMenu::useAllGreyvaluesFromImage (  ) [protected, slot]

calls the mitkLevelWindow SetAuto method with guessByCentralSlice false, so that the greyvalues from whole image will be considered

Definition at line 98 of file QmitkLevelWindowWidgetContextMenu.cpp.

References mitk::LevelWindowManager::GetCurrentImage(), mitk::RenderingManager::GetInstance(), m_LevelWindow, m_Manager, mitk::LevelWindow::SetAuto(), and mitk::LevelWindowManager::SetLevelWindow().

Referenced by getContextMenu().


Member Data Documentation

ID of image selected in contextmenu.

Definition at line 87 of file QmitkLevelWindowWidgetContextMenu.h.

Referenced by getContextMenu(), and setImage().

map to hold all image-properties, one can get the image which is selected in the contextmenu with the QAction representing the image for the contextmenu

Definition at line 66 of file QmitkLevelWindowWidgetContextMenu.h.

Referenced by getContextMenu(), and setImage().

submenu with all images for contextmenu

Definition at line 58 of file QmitkLevelWindowWidgetContextMenu.h.

Referenced by getContextMenu().

data structure which reads and writes presets defined in a XML-file

Definition at line 46 of file QmitkLevelWindowWidgetContextMenu.h.

Referenced by addPreset(), getContextMenu(), QmitkLevelWindowWidgetContextMenu(), setPreset(), and ~QmitkLevelWindowWidgetContextMenu().

pointer to the object which manages all Level/Window changes on images and holds the LevelWindowProperty of the current image

Definition at line 62 of file QmitkLevelWindowWidgetContextMenu.h.

Referenced by changeScaleRange(), getContextMenu(), setDefaultLevelWindow(), setDefaultScaleRange(), setFixed(), setImage(), setLevelWindowManager(), setMaximumWindow(), setPreset(), and useAllGreyvaluesFromImage().

ID of preset selected in contextmenu.

Definition at line 84 of file QmitkLevelWindowWidgetContextMenu.h.

Referenced by getContextMenu(), and setPreset().

submenu with all presets for contextmenu

Definition at line 55 of file QmitkLevelWindowWidgetContextMenu.h.

Referenced by getContextMenu().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines