12#ifdef MARBLE_NO_WEBKITWIDGETS
13#include "NullMarbleWebView.h"
15#include <QWebEngineView>
16#include <QWebEngineHistory>
17#include <QWebEngineSettings>
18#include "MarbleWebView.h"
24#include <QPrintDialog>
26#include <QApplication>
27#include <QDesktopServices>
28#include <QPixmapCache>
35PopupItem::PopupItem(
QObject* parent ) :
37 BillboardGraphicsItem(),
41 m_needMouseRelease(false)
45 setSize(
QSizeF( 300.0, 320.0 ) );
47 m_ui.setupUi( m_widget );
48 m_ui.goBackButton->setVisible(
false );
49 connect( m_ui.goBackButton, SIGNAL(clicked()),
this, SLOT(goBack()) );
52 m_ui.printButton->setVisible(
false );
54 m_ui.printButton->setVisible(
true );
55 connect( m_ui.printButton, SIGNAL(clicked()),
this, SLOT(printContent()) );
58 m_widget->setVisible(
true);
62 QPalette palette = m_ui.webView->palette();
64#ifndef MARBLE_NO_WEBKITWIDGETS
65 m_ui.webView->setPalette(palette);
66 m_ui.webView->page()->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls,
true);
67 m_ui.webView->page()->settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled,
true);
70 m_ui.webView->setUrl(
QUrl(
"about:blank" ) );
72 connect( m_ui.hideButton, SIGNAL(clicked()),
this, SIGNAL(hide()) );
74#ifndef MARBLE_NO_WEBKITWIDGETS
75 connect( m_ui.webView->page(), SIGNAL(titleChanged(
QString)), m_ui.titleText, SLOT(setText(
QString)) );
76 connect( m_ui.webView->page(), SIGNAL(urlChanged(
QUrl)),
this, SLOT(updateBackButton()) );
78 connect(m_ui.webView, SIGNAL(loadFinished(
bool)),
this, SLOT(requestUpdate()));
82PopupItem::~PopupItem()
87bool PopupItem::isPrintButtonVisible()
const
89 return m_ui.printButton->isVisible();
92void PopupItem::setPrintButtonVisible(
bool display )
94 m_ui.printButton->setVisible( display );
97void PopupItem::setUrl(
const QUrl &url )
99 m_ui.webView->setUrl( url );
101 QPalette palette = m_ui.webView->palette();
103#ifndef MARBLE_NO_WEBKITWIDGETS
104 m_ui.webView->setPalette(palette);
111void PopupItem::setContent(
const QString &html,
const QUrl &baseUrl )
115#ifndef MARBLE_NO_WEBKITWIDGETS
116 m_ui.webView->setHtml( html, baseUrl );
122void PopupItem::setTextColor(
const QColor &color)
124 if(color.
isValid() && m_ui.titleText !=
nullptr) {
126 QPalette palette(m_ui.titleText->palette());
128 m_ui.titleText->setPalette(palette);
134void PopupItem::setBackgroundColor(
const QColor &color)
148void PopupItem::colorize(
QImage &img,
const QColor &col )
150 if (img.
depth() <= 8)
return;
152 unsigned int *data = (
unsigned int *) img.
bits();
153 for (
int i=0; i < pixels; ++i) {
154 int val = qGray(data[i]);
155 data[i] = qRgba(col.
red()*val/255,col.
green()*val/255, col.
blue()*val/255, qAlpha(data[i]));
159void PopupItem::paint(
QPainter *painter )
162 QPixmap image = pixmap(
"marble/webpopup/arrow2_vertical_topright");
166 size().width() - ( image.
width() - 3 ),
168 qDrawBorderPixmap(painter, popupRect,
QMargins( 20, 20, 20, 20 ),
169 pixmap(
"marble/webpopup/webpopup2"));
171 image = pixmap(
"marble/webpopup/arrow2_bottomleft");
174 image = pixmap(
"marble/webpopup/arrow2_topleft");
177 image = pixmap(
"marble/webpopup/arrow2_topleft");
178 painter->
drawPixmap( 0, size().height() / 2, image );
180 m_widget->render( painter,
QPoint( image.
width() - 3, 0 ) );
183 size().width() - ( image.
width() - 3 ),
185 qDrawBorderPixmap(painter, popupRect,
QMargins( 20, 20, 20, 20 ),
186 pixmap(
"marble/webpopup/webpopup2"));
188 image = pixmap(
"marble/webpopup/arrow2_bottomright");
190 size().height() - image.
height(), image );
192 image = pixmap(
"marble/webpopup/arrow2_topright");
196 image = pixmap(
"marble/webpopup/arrow2_topright");
198 size().height() / 2 - image.
height() / 2 + 23, image );
205 image = pixmap(
"marble/webpopup/arrow2_vertical_bottomright");
206 popupRect.
setRect( -10, -10, size().width(),
207 size().height() - image.
height() + 3 );
208 qDrawBorderPixmap(painter, popupRect,
QMargins( 20, 20, 20, 20 ),
209 pixmap(
"marble/webpopup/webpopup2"));
211 size().height() - image.
height(), image );
214 image = pixmap(
"marble/webpopup/arrow2_vertical_topleft");
216 size().height() - image.
height() + 3 );
217 qDrawBorderPixmap(painter, popupRect,
QMargins( 20, 20, 20, 20 ),
218 pixmap(
"marble/webpopup/webpopup2"));
219 painter->
drawPixmap( size().width() / 2, 0, image );
222 popupRect.
setRect( -10, -10, size().width(),
224 qDrawBorderPixmap(painter, popupRect,
QMargins( 20, 20, 20, 20 ),
225 pixmap(
"marble/webpopup/webpopup2"));
229 m_widget->setFixedSize( popupRect.
width() - 20,
230 popupRect.
height() - 20 );
235 MarbleWidget *widget =
dynamic_cast<MarbleWidget*
> ( object );
237 return BillboardGraphicsItem::eventFilter(
object, e );
242 return BillboardGraphicsItem::eventFilter(
object, e );
247 return BillboardGraphicsItem::eventFilter(
object, e );
257 QPoint shiftedPos =
event->pos();
260 if ( child || forcedMouseRelease ) {
262 m_needMouseRelease =
true;
263 }
else if ( forcedMouseRelease ) {
264 m_needMouseRelease =
false;
267 child = m_ui.webView;
271 event->modifiers() );
273 widget->setCursor( child->
cursor() );
274 emit repaintNeeded();
281 QPoint shiftedPos =
event->pos();
286 event->modifiers() );
288 widget->setCursor( child->
cursor() );
289 emit repaintNeeded();
295 return BillboardGraphicsItem::eventFilter(
object, e );
305 point -=
QPoint( 117, 0 );
323 for( ; it != widgetPositions.
constEnd(); ++it ) {
324 if (
QRectF( *it, size() ).contains( point ) ) {
325 point -= it->toPoint();
328 point -= child->
pos();
336void PopupItem::clearHistory()
339 m_ui.webView->setUrl(
QUrl(
"about:blank" ) );
340#ifndef MARBLE_NO_WEBKITWIDGETS
341 m_ui.webView->history()->clear();
345void PopupItem::requestUpdate()
348 emit repaintNeeded();
351void PopupItem::printContent()
const
354#ifndef MARBLE_NO_WEBKITWIDGETS
358 m_ui.webView->page()->print(&printer, [=](
bool){});
365void PopupItem::updateBackButton()
367#ifndef MARBLE_NO_WEBKITWIDGETS
368 bool const hasHistory = m_ui.webView->page()->history()->count() > 1;
369 bool const previousIsHtml = !m_content.isEmpty() && m_ui.webView->page()->history()->currentItemIndex() == 1;
370 bool const atStart = m_ui.webView->page()->history()->currentItemIndex() <= 1;
371 bool const currentIsHtml = m_ui.webView->page()->url() ==
QUrl(
"about:blank" );
373 m_ui.goBackButton->setVisible( hasHistory && !currentIsHtml && ( previousIsHtml || !atStart ) );
377void PopupItem::goBack()
379#ifndef MARBLE_NO_WEBKITWIDGETS
380 if ( m_ui.webView->page()->history()->currentItemIndex() == 1 && !m_content.isEmpty() ) {
381 m_ui.webView->page()->setHtml( m_content, m_baseUrl );
383 m_ui.webView->back();
389void PopupItem::openUrl(
const QUrl &url)
400 colorize( top, m_backColor );
413#include "moc_PopupItem.cpp"
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
void update(Part *part, const QByteArray &data, qint64 dataSize)
Binds a QML item to a specific geodetic location in screen coordinates.
bool isValid() const const
bool sendEvent(QObject *receiver, QEvent *event)
bool openUrl(const QUrl &url)
const_iterator constBegin() const const
const_iterator constEnd() const const
void drawImage(const QPoint &point, const QImage &image)
void drawPixmap(const QPoint &point, const QPixmap &pixmap)
void setBrush(ColorGroup group, ColorRole role, const QBrush &brush)
void setColor(ColorGroup group, ColorRole role, const QColor &color)
QPixmap fromImage(QImage &&image, Qt::ImageConversionFlags flags)
bool find(const Key &key, QPixmap *pixmap)
Key insert(const QPixmap &pixmap)
void remove(const Key &key)
void setRect(int x, int y, int width, int height)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)