7 #include "guiQt/SSignalShortcut.hpp" 9 #include <fwCom/Signal.hxx> 11 #include <fwCore/base.hpp> 13 #include <fwGui/container/fwContainer.hpp> 14 #include <fwGui/GuiRegistry.hpp> 15 #include <fwGui/IGuiContainerSrv.hpp> 17 #include <fwGuiQt/container/QtContainer.hpp> 19 #include <fwServices/macros.hpp> 20 #include <fwServices/op/Get.hpp> 22 #include <QKeySequence> 30 static const ::fwCom::Signals::SignalKeyType s_ACTIVATED_SIG =
"activated";
40 m_shortcutObject(
nullptr)
42 newSignal< ActivatedShortcutSignalType >(s_ACTIVATED_SIG);
56 const auto configShortcut = configTree.get_child(
"config.<xmlattr>");
57 m_shortcut = configShortcut.get<std::string>(
"shortcut", m_shortcut);
58 OSLM_ASSERT(
"Shortcut must not be empty", m_shortcut !=
"");
60 m_wid = configShortcut.get<std::string>(
"wid", m_wid);
61 m_sid = configShortcut.get<std::string>(
"sid", m_sid);
62 OSLM_ASSERT(
"Either The wid or sid attribute must be specified for SSignalShortcut", m_wid !=
"" || m_sid !=
"");
69 ::fwGui::container::fwContainer::sptr fwc =
nullptr;
78 ::fwServices::IService::sptr service = ::fwServices::get( m_sid );
79 ::fwGui::IGuiContainerSrv::sptr containerSrv = ::fwGui::IGuiContainerSrv::dynamicCast(service);
80 fwc = containerSrv->getContainer();
99 ::fwGuiQt::container::QtContainer::sptr qtc =
104 if(!m_shortcutObject)
107 QWidget* widget = qtc->getQtContainer();
109 QKeySequence shortcutSequence = QKeySequence(QString::fromStdString(m_shortcut));
110 m_shortcutObject =
new QShortcut(shortcutSequence, widget);
114 QObject::connect(m_shortcutObject, SIGNAL(activated()),
this, SLOT(onActivation()));
119 OSLM_ERROR(
"Cannot setup shortcut " << m_shortcut <<
" on invalid " 120 << (m_wid !=
"" ?
"wid " + m_wid :
"sid " + m_sid));
131 QObject::disconnect(m_shortcutObject, SIGNAL(activated()),
this, SLOT(onActivation()));
143 void SSignalShortcut::onActivation()
145 this->signal<ActivatedShortcutSignalType>(s_ACTIVATED_SIG)->asyncEmit();
Base class for all services.
static FWGUI_API::fwGui::container::fwContainer::sptr getWIDContainer(std::string wid)
Returns fwContainer associate with window ID, null if not found.
#define OSLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
virtual GUIQT_API void configuring() override
This method configures the service.
GUIQT_API SSignalShortcut() noexcept
Constructor. Do nothing.
#define OSLM_ERROR(message)
This service sends a signal when the associated shortcut is activated.
virtual GUIQT_API void stopping() override
This method deletes the eventFilter.
virtual GUIQT_API void starting() override
This method enables the eventFilter.
virtual GUIQT_API ~SSignalShortcut() noexcept
Destructor. Do nothing.
virtual GUIQT_API void updating() override
This method does nothing.
The namespace guiQt contains the basic services to build the application IHM with Qt...
Defines the QWidget container for UI.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.