Пример #1
0
WebView::WebView( QWidget *parent ) :
  QWebView( parent ),
  _interpretSelection(false)
{
  QtCollider::WebPage *page = new WebPage(this);
  page->setDelegateReload(true);
  setPage( page );

  // Set the style's standard palette to avoid system's palette incoherencies
  // get in the way of rendering web pages
  setPalette( style()->standardPalette() );

  page->action( QWebPage::Copy )->setShortcut( QKeySequence::Copy );
  page->action( QWebPage::Paste )->setShortcut( QKeySequence::Paste );

  connect( this, SIGNAL(linkClicked(QUrl)), this, SLOT(onLinkClicked(QUrl)) );
  connect( page->action(QWebPage::Reload), SIGNAL(triggered(bool)),
           this, SLOT(onPageReload()) );

  connect( this, SIGNAL(interpret(QString)),
           qApp, SLOT(interpret(QString)),
           Qt::QueuedConnection );

  connect( page, SIGNAL(jsConsoleMsg(const QString&, int, const QString&)),
           this, SIGNAL(jsConsoleMsg(const QString&, int, const QString&)) );
}
Пример #2
0
HelpBrowser::HelpBrowser( QWidget * parent ):
    QWidget(parent)
{
    QRect availableScreenRect = qApp->desktop()->availableGeometry(this);
    mSizeHint = QSize( availableScreenRect.width() * 0.4, availableScreenRect.height() * 0.7 );

    QtCollider::WebPage *webPage = new QtCollider::WebPage(this);
    webPage->setDelegateReload(true);
    webPage->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );

    mWebView = new QWebView;
    mWebView->setPage( webPage );
    mWebView->settings()->setAttribute( QWebSettings::LocalStorageEnabled, true );
    mWebView->setContextMenuPolicy( Qt::CustomContextMenu );

    // Set the style's standard palette to avoid system's palette incoherencies
    // get in the way of rendering web pages
    mWebView->setPalette( style()->standardPalette() );

    mWebView->installEventFilter(this);

    mLoadProgressIndicator = new LoadProgressIndicator;
    mLoadProgressIndicator->setIndent(10);

    QVBoxLayout *layout = new QVBoxLayout;
    layout->setContentsMargins(0,0,0,0);
    layout->setSpacing(0);
    layout->addWidget(mWebView);
    setLayout(layout);

    connect( mWebView, SIGNAL(linkClicked(QUrl)), this, SLOT(onLinkClicked(QUrl)) );
    connect( mWebView, SIGNAL(loadStarted()), mLoadProgressIndicator, SLOT(start()) );
    connect( mWebView, SIGNAL(loadFinished(bool)), mLoadProgressIndicator, SLOT(stop()) );
    connect( mWebView, SIGNAL(customContextMenuRequested(QPoint)),
             this, SLOT(onContextMenuRequest(QPoint)) );

    connect( webPage->action(QWebPage::Reload), SIGNAL(triggered(bool)), this, SLOT(onReload()) );
    connect( webPage, SIGNAL(jsConsoleMsg(QString,int,QString)),
             this, SLOT(onJsConsoleMsg(QString,int,QString)) );

    ScProcess * scProcess = Main::scProcess();
    connect( scProcess, SIGNAL(response(QString,QString)),
             this, SLOT(onScResponse(QString,QString)) );
    connect( scProcess, SIGNAL(finished(int)), mLoadProgressIndicator, SLOT(stop()) );
    // FIXME: should actually respond to class library shutdown, but we don't have that signal
    connect( scProcess, SIGNAL(classLibraryRecompiled()), mLoadProgressIndicator, SLOT(stop()) );

    createActions();

    applySettings( Main::settings() );

    setFocusProxy(mWebView);
}
Пример #3
0
AdiumThemeView::AdiumThemeView(QWidget *parent)
        : QWebView(parent),
        // check iconPath docs for minus sign in -KIconLoader::SizeLarge
        m_defaultAvatar(KIconLoader::global()->iconPath(QLatin1String("im-user"),-KIconLoader::SizeLarge)),
        m_displayHeader(true)
{
    //blocks QWebView functionality which allows you to change page by dragging a URL onto it.
    setAcceptDrops(false);

    // don't let QWebView handle the links, we do
    page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);

    QAction *defaultOpenLinkAction = pageAction(QWebPage::OpenLink);
    m_openLinkAction = new KAction(defaultOpenLinkAction->text(), this);
    connect(m_openLinkAction, SIGNAL(triggered()),
            this, SLOT(onOpenLinkActionTriggered()));

    connect(this, SIGNAL(linkClicked(QUrl)), this, SLOT(onLinkClicked(QUrl)));
}
Пример #4
0
void HelpBrowser::onReload()
{
    QWebSettings::clearMemoryCaches();
    onLinkClicked( mWebView->url() );
}
Пример #5
0
void QgsMapTip::showMapTip( QgsMapLayer *pLayer,
                            QgsPoint & mapPosition,
                            QPoint & thePixelPosition,
                            QgsMapCanvas *pMapCanvas )
{
  // Do the search using the active layer and the preferred label field for the
  // layer. The label field must be defined in the layer configuration
  // file/database. The code required to do this is similar to identify, except
  // we only want the first qualifying feature and we will only display the
  // field defined as the label field in the layer configuration file/database

  // Show the maptip on the canvas
  QString tipText, lastTipText, tipHtml, bodyStyle, containerStyle,
  backgroundColor, borderColor;

  delete mWidget;
  mWidget = new QWidget( pMapCanvas );
  mWebView = new QgsWebView( mWidget );


#if WITH_QTWEBKIT
  mWebView->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );//Handle link clicks by yourself
  mWebView->setContextMenuPolicy( Qt::NoContextMenu ); //No context menu is allowed if you don't need it
  connect( mWebView, SIGNAL( linkClicked( QUrl ) ), this, SLOT( onLinkClicked( QUrl ) ) );
#endif

  mWebView->page()->settings()->setAttribute(
    QWebSettings::DeveloperExtrasEnabled, true );
  mWebView->page()->settings()->setAttribute(
    QWebSettings::JavascriptEnabled, true );

  QHBoxLayout* layout = new QHBoxLayout;
  layout->addWidget( mWebView );

  mWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
  mWidget->setLayout( layout );

  //assure the map tip is never larger than half the map canvas
  const int MAX_WIDTH = pMapCanvas->geometry().width() / 2;
  const int MAX_HEIGHT = pMapCanvas->geometry().height() / 2;
  mWidget->setMaximumSize( MAX_WIDTH, MAX_HEIGHT );

  // start with 0 size,
  // the content will automatically make it grow up to MaximumSize
  mWidget->resize( 0, 0 );

  backgroundColor = mWidget->palette().base().color().name();
  borderColor = mWidget->palette().shadow().color().name();
  mWidget->setStyleSheet( QString(
                            ".QWidget{"
                            "border: 1px solid %1;"
                            "background-color: %2;}" ).arg(
                            borderColor, backgroundColor ) );

  tipText = fetchFeature( pLayer, mapPosition, pMapCanvas );

  mMapTipVisible = !tipText.isEmpty();
  if ( !mMapTipVisible )
  {
    clear();
    return;
  }

  if ( tipText == lastTipText )
  {
    return;
  }

  bodyStyle = QString(
                "background-color: %1;"
                "margin: 0;" ).arg( backgroundColor );

  containerStyle = QString(
                     "display: inline-block;"
                     "margin: 0px" );

  tipHtml = QString(
              "<html>"
              "<body style='%1'>"
              "<div id='QgsWebViewContainer' style='%2'>%3</div>"
              "</body>"
              "</html>" ).arg( bodyStyle, containerStyle, tipText );

  mWidget->move( thePixelPosition.x(),
                 thePixelPosition.y() );

  mWebView->setHtml( tipHtml );
  lastTipText = tipText;

  mWidget->show();

#if WITH_QTWEBKIT
  int scrollbarWidth = mWebView->page()->mainFrame()->scrollBarGeometry(
                         Qt::Vertical ).width();
  int scrollbarHeight = mWebView->page()->mainFrame()->scrollBarGeometry(
                          Qt::Horizontal ).height();

  if ( scrollbarWidth > 0 || scrollbarHeight > 0 )
  {
    // Get the content size
    QWebElement container = mWebView->page()->mainFrame()->findFirstElement(
                              QStringLiteral( "#QgsWebViewContainer" ) );
    int width = container.geometry().width() + 5 + scrollbarWidth;
    int height = container.geometry().height() + 5 + scrollbarHeight;

    mWidget->resize( width, height );
  }
#endif
}
Пример #6
0
HelpBrowser::HelpBrowser( QWidget * parent ):
    QWidget(parent)
{
    QRect availableScreenRect = qApp->desktop()->availableGeometry(this);
    mSizeHint = QSize( availableScreenRect.width() * 0.4, availableScreenRect.height() * 0.7 );

    QtCollider::WebPage *webPage = new QtCollider::WebPage(this);
    webPage->setDelegateReload(true);
    webPage->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );

    mWebView = new QWebView;
    mWebView->setPage( webPage );
    mWebView->settings()->setAttribute( QWebSettings::LocalStorageEnabled, true );

    // NOTE: we assume all web page shortcuts have Qt::WidgetShortcut context
    mWebView->setContextMenuPolicy( Qt::ActionsContextMenu );
    mWebView->addAction( webPage->action( QWebPage::Copy ) );
    mWebView->addAction( webPage->action( QWebPage::Paste ) );

    // Set the style's standard palette to avoid system's palette incoherencies
    // get in the way of rendering web pages
    mWebView->setPalette( style()->standardPalette() );

    mWebView->installEventFilter(this);

    mLoadProgressIndicator = new LoadProgressIndicator;
    mLoadProgressIndicator->setIndent(10);

    QToolBar *toolBar = new QToolBar;
    toolBar->setIconSize( QSize(16,16) );
    QAction *action = toolBar->addAction("Home");
    connect( action, SIGNAL(triggered()), this, SLOT(goHome()) );
    toolBar->addAction( mWebView->pageAction(QWebPage::Back) );
    toolBar->addAction( mWebView->pageAction(QWebPage::Forward) );
    toolBar->addAction( mWebView->pageAction(QWebPage::Reload) );
    toolBar->addWidget(mLoadProgressIndicator);

    QVBoxLayout *layout = new QVBoxLayout;
    layout->setContentsMargins(0,0,0,0);
    layout->setSpacing(0);
    layout->addWidget(toolBar);
    layout->addWidget(mWebView);
    setLayout(layout);

    connect( mWebView, SIGNAL(linkClicked(QUrl)), this, SLOT(onLinkClicked(QUrl)) );
    connect( mWebView, SIGNAL(loadStarted()), mLoadProgressIndicator, SLOT(start()) );
    connect( mWebView, SIGNAL(loadFinished(bool)), mLoadProgressIndicator, SLOT(stop()) );

    connect( webPage->action(QWebPage::Reload), SIGNAL(triggered(bool)), this, SLOT(onReload()) );
    connect( webPage, SIGNAL(jsConsoleMsg(QString,int,QString)),
             this, SLOT(onJsConsoleMsg(QString,int,QString)) );

    ScProcess * scProcess = Main::scProcess();
    connect( scProcess, SIGNAL(response(QString,QString)),
             this, SLOT(onScResponse(QString,QString)) );
    connect( scProcess, SIGNAL(finished(int)), mLoadProgressIndicator, SLOT(stop()) );
    // FIXME: should actually respond to class library shutdown, but we don't have that signal
    connect( scProcess, SIGNAL(classLibraryRecompiled()), mLoadProgressIndicator, SLOT(stop()) );

    mEvaluateShortcut = new QShortcut(this);
    mEvaluateShortcut->setContext( Qt::WidgetWithChildrenShortcut );
    connect( mEvaluateShortcut, SIGNAL(activated()), this, SLOT(evaluateSelection()) );

    applySettings( Main::settings() );
}
Пример #7
0
void AdiumThemeView::onOpenLinkActionTriggered()
{
    QUrl url = m_openLinkAction->data().toUrl();
    onLinkClicked(url);
}
Пример #8
0
void DialogBare::onDownloadRequested(const QNetworkRequest &request)
{
    onLinkClicked(request.url());
}
SwAcctEditPage::SwAcctEditPage(SwClientService *swService, QGraphicsItem *parent) :
        MApplicationPage(parent),
        mService(swService),
        mServiceConfig(mService->getServiceConfig()),
        mFlickrClicked(false)
{
    int adj = 0;
    setEscapeMode(MApplicationPageModel::EscapeManualBack);
    connect(this, SIGNAL(backButtonClicked()),
            this, SLOT(dismiss()));

    connect(mService,
            SIGNAL(CredsStateChanged(SwClientService*,SwClientService::CredsState)),
            this,
            SLOT(onCredsStateChanged(SwClientService *, SwClientService::CredsState)));
    if (!mServiceConfig->isValid())
        dismiss();
    mParams = mServiceConfig->getConfigParams();

    MLayout *layout = new MLayout;
    MGridLayoutPolicy *policy = new MGridLayoutPolicy(layout);

    QString link = mServiceConfig->getLink();
    MLabel *lblServiceName = new MLabel();
    if (!link.isEmpty())
        lblServiceName->setText(QString("<a href=\"%1\">%2</a>").arg(link, mServiceConfig->getDisplayName()));
    else
        lblServiceName->setText(mServiceConfig->getDisplayName());
    lblServiceName->setObjectName("SwAcctEditPageServiceNameLabel");
    policy->addItem(lblServiceName, 0, 0, 1, 2, Qt::AlignHCenter);

    connect(lblServiceName,
            SIGNAL(linkActivated(QString)),
            this,
            SLOT(onLinkClicked(QString)));

    QString desc = mServiceConfig->getDescription();
    if (!desc.isEmpty()) {
        MLabel *lblServiceDesc = new MLabel();
        lblServiceDesc->setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
        lblServiceDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
        //Have to insert a random HTML tag to make word wrap actually work...
        //Should be able to remove at some point once MTF word wrap works properly
        lblServiceDesc->setText(QString("<b></b>").append(desc));
        lblServiceDesc->setObjectName("SwAcctEditPageServiceDescLabel");
        policy->addItem(lblServiceDesc, 1, 0, 1, 2, Qt::AlignLeft);
    } else {
        adj -= 1;
    }

    //This is *ugly*
    if (mServiceConfig->getAuthtype() == SwClientServiceConfig::AuthTypeFlickr) {
        if (!mParams.value(USER_KEY).isEmpty()) {
            //% "User %1"
            MLabel *lblUsername = new MLabel(qtTrId("label_flickr_username").arg(mParams.value(USER_KEY)));
            lblUsername->setObjectName("SwAcctEditPageFlickrUserLabel");
            policy->addItem(lblUsername, 2+adj, 0, 1, 2, Qt::AlignHCenter);
            adj += 1;
        }

        mFlickrButton = new MButton();
        mFlickrButton->setObjectName("SwAcctEditPageFlickrButton");
        policy->addItem(mFlickrButton, 2+adj, 0, 1, 2, Qt::AlignHCenter);

        connect(mFlickrButton,
                SIGNAL(clicked()),
                this,
                SLOT(onFlickrClicked()));

        adj += 1;
    } else {
        MLabel *lblUsername = new MLabel();
        lblUsername->setObjectName("SwAcctEditPageUsernameLabel");
        lblUsername->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
        //% "Username:"******"label_username"));
        policy->addItem(lblUsername, 2+adj, 0);

        mEdtUsername = new MTextEdit(MTextEditModel::SingleLine);
        mEdtUsername->setObjectName("SwAcctEditPageUsernameButton");
        mEdtUsername->setText(mParams.value(USER_KEY));
        //qDebug() << QString("Set username to %1").arg(mParams.value(USER_KEY));
        policy->addItem(mEdtUsername, 2+adj, 1);

        if (mServiceConfig->getAuthtype() == SwClientServiceConfig::AuthTypePassword) {
            MLabel *lblPassword = new MLabel();
            lblPassword->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
            //% "Password:"******"label_password"));
            lblPassword->setObjectName("SwAcctEditPagePasswordLabel");
            policy->addItem(lblPassword, 3+adj, 0);
            mEdtPassword = new MTextEdit(MTextEditModel::SingleLine);
            mEdtPassword->setText(mParams.value(PASS_KEY));
            mEdtPassword->setEchoMode(MTextEditModel::Password);
            mEdtPassword->setObjectName("SwAcctEditPagePasswordButton");
    //        qDebug() << QString("Set password to %1").arg(mParams.value(PASS_KEY));
            policy->addItem(mEdtPassword, 3+adj, 1);
            connect(mEdtPassword,
                    SIGNAL(textChanged()),
                    this,
                    SLOT(onLoginChanged()));
            adj += 1;
        }
    }

    mLblStatus = new MLabel(STATUS_TEXT_UNCONFIGURED);
    mLblStatus->setObjectName("SwAcctEditPageStatusLabel");
    policy->addItem(mLblStatus, 3+adj, 0, 1, 2, Qt::AlignHCenter);

    onCredsStateChanged(mService, mService->credsState());

    MLabel *lblServiceHint = new MLabel();
    lblServiceHint->setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
    lblServiceHint->setObjectName("SwAcctEditPageServiceHintLabel");
    lblServiceHint->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    lblServiceHint->setText(SERVICE_HINT_TEXT.arg(mService->getDisplayName()));
    policy->addItem(lblServiceHint, 4+adj, 0, 1, 2);


    //This, also, is *ugly*
    if (mServiceConfig->getAuthtype() != SwClientServiceConfig::AuthTypeFlickr) {
        //% "Apply"
        mBtnApply = new MButton(qtTrId("button_apply"));
        mBtnApply->setObjectName("SwAcctEditPageApplyButton");
        policy->addItem(mBtnApply, 5+adj, 0, 1, 2, Qt::AlignHCenter);

        //% "Cancel"
        mBtnCancel = new MButton(qtTrId("button_cancel"));
        mBtnCancel->setObjectName("SwAcctEditPageCancelButton");
        policy->addItem(mBtnCancel, 6+adj, 0, 1, 2, Qt::AlignHCenter);

        connect(mEdtUsername,
                SIGNAL(textChanged()),
                this,
                SLOT(onLoginChanged()));

        connect(mBtnApply,
                SIGNAL(clicked()),
                this,
                SLOT(onApplyClicked()));
        connect(mBtnCancel,
                SIGNAL(clicked()),
                this,
                SLOT(dismiss()));
    }


    layout->setPolicy(policy);
    centralWidget()->setLayout(layout);
}