7 #include <QApplication> 12 #include <QTextBrowser> 14 #include <QDesktopServices> 17 #include <QHBoxLayout> 18 #include <QPushButton> 19 #include <QVBoxLayout> 21 #include <boost/filesystem/operations.hpp> 22 #include <fwCore/base.hpp> 23 #include <fwServices/macros.hpp> 24 #include <fwRuntime/operations.hpp> 26 #include "uiGenericQt/action/SShowAbout.hpp" 37 SShowAbout::SShowAbout( ) noexcept :
38 m_bServiceIsConfigured(false),
47 SShowAbout::~SShowAbout() noexcept
55 _sstream <<
"SShowAbout" << std::endl;
66 ConfigurationElement cfgFilename =
m_configuration->findConfigurationElement(
"filename");
67 ConfigurationElement cfgTitle =
m_configuration->findConfigurationElement(
"title");
68 ConfigurationElement cfgSize =
m_configuration->findConfigurationElement(
"size");
72 const std::string& filename = cfgFilename->getExistingAttributeValue(
"id");
74 m_fsAboutPath = ::fwRuntime::getBundleResourceFilePath(filename);
76 m_bServiceIsConfigured = ::boost::filesystem::exists(m_fsAboutPath);
77 SLM_WARN_IF(
"About file " + filename +
" doesn't exist", !m_bServiceIsConfigured);
78 SLM_TRACE(
"Filename found '" + filename +
"'");
83 m_title = cfgTitle->getValue();
84 SLM_TRACE(
"Set title to '" + m_title +
"'");
89 const std::string& w = cfgSize->getExistingAttributeValue(
"width");
90 const std::string& h = cfgSize->getExistingAttributeValue(
"height");
92 m_size.setWidth(std::stoi(w));
93 m_size.setHeight(std::stoi(h));
95 OSLM_TRACE(
"Set frame size to (" << m_size.width() <<
", " << m_size.height() <<
")");
104 SLM_ASSERT(
"The service 'SShowAbout' isn't configured properly.", m_bServiceIsConfigured );
106 QDialog* dialog =
new QDialog(qApp->activeWindow());
107 dialog->setWindowTitle(QString::fromStdString(m_title));
108 QUrl url(QString::fromStdString(m_fsAboutPath.string()));
109 #if defined(QT_WEBKIT) 110 QWebView* htmlView =
new QWebView(dialog);
111 htmlView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
112 htmlView->load( url );
113 QObject::connect( htmlView, SIGNAL(linkClicked(
const QUrl &)),
this, SLOT(
onUrlClicked(
const QUrl &)));
115 QTextBrowser* htmlView =
new QTextBrowser(dialog);
116 htmlView->setSource(url);
117 htmlView->setOpenExternalLinks(
true);
118 htmlView->setMinimumSize(m_size);
119 QStringList searchPaths;
120 searchPaths.append(QString::fromStdString(m_fsAboutPath.parent_path().string()));
121 htmlView->setSearchPaths(searchPaths);
123 QPushButton* okButton =
new QPushButton(QObject::tr(
"Ok"));
124 QHBoxLayout* hLayout =
new QHBoxLayout();
125 hLayout->addStretch();
126 hLayout->addWidget(okButton);
127 hLayout->setContentsMargins(5, 5, 5, 5);
129 QFrame* line =
new QFrame(dialog);
130 line->setFrameShape(QFrame::HLine);
131 line->setFrameShadow(QFrame::Sunken);
133 QVBoxLayout* layout =
new QVBoxLayout();
134 layout->addWidget(htmlView, 0);
135 layout->addWidget(line, 0);
136 layout->addLayout(hLayout, 0);
137 layout->setContentsMargins(0, 0, 0, 0);
138 layout->setSpacing(0);
139 dialog->setLayout( layout );
141 QObject::connect(okButton, SIGNAL(clicked()), dialog, SLOT(accept()));
142 QObject::connect(dialog, SIGNAL(accepted()), dialog, SLOT(deleteLater()));
143 dialog->setModal(
true);
165 QDesktopServices::openUrl(url);
void stopping() override
Stops action.
FWGUI_API void actionServiceStarting()
Method called when the action service is starting.
The namespace uiGenericQt contains actions to show help, acknowledgments and about frame...
#define SLM_TRACE_FUNC()
Trace contextual function signature.
FWGUI_API void actionServiceStopping()
Method called when the action service is stopping.
#define OSLM_TRACE(message)
Defines the configuration element class.
Defines the service interface managing the menu items.
void starting() override
Starts action.
This action show the about frame.
void info(std::ostream &_sstream) override
Prints service info.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
FWGUI_API void initialize()
Initialize the action.
Base class for each data object.
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
#define SLM_TRACE(message)
void updating() override
Shows the frame.
void onUrlClicked(const QUrl &url)
Triggered when an URL is clicked in the about frame.
void configuring() override
Configuring method.
#define SLM_WARN_IF(message, cond)