void Ut_MGridLayoutPolicy::testLayoutInLayoutRefresh()
{
    m_policy->setSpacing(0);
    m_mockLayout->activate();

    QGraphicsWidget *widget = new QGraphicsWidget;
    MLayout *layout = new MLayout(widget);
    layout->setContentsMargins(0,0,0,0);
    MGridLayoutPolicy *policy = new MGridLayoutPolicy(layout);
    m_policy->addItem(widget,0,0);

    QGraphicsWidget *leftSpacerWithWidget = new QGraphicsWidget;
    policy->addItem(leftSpacerWithWidget, 0, 0);
    policy->addItem(m_mockItem100, 0, 1);
    policy->addItem(new QGraphicsWidget, 0, 2);
    policy->addItem(m_mockItem200, 0, 3);

    m_form->resize(400,200);

    qApp->processEvents();
    qApp->processEvents();

    QCOMPARE(m_mockItem100->geometry(), QRectF(50,0,100,100));
    QCOMPARE(m_mockItem200->geometry(), QRectF(200,0,200,200));

    leftSpacerWithWidget->setMaximumWidth(0);

    qApp->processEvents();

    QCOMPARE(m_mockItem100->geometry(), QRectF(0,0,100,100));
    QCOMPARE(m_mockItem200->geometry(), QRectF(200,0,200,200));
}
QGraphicsWidget *MToolBarLayoutPolicy::insertSpacer(int policyIndex)
{
    //Create an item that will expand if necessary
    QGraphicsWidget *item = new QGraphicsWidget;
    item->setMaximumWidth(spacesBetween ? -1 : 0);
    item->setPreferredSize(1,1); //Ugly hack around QTBUG-11134
    item->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    MLinearLayoutPolicy::insertItem(policyIndex, item);
    return item;
}
Esempio n. 3
0
QGraphicsWidget *WebBrowser::graphicsWidget()
{
    if (m_graphicsWidget) {
        return m_graphicsWidget;
    }

    m_layout = new QGraphicsLinearLayout(Qt::Vertical);
    m_toolbarLayout = new QGraphicsLinearLayout(Qt::Horizontal);
    m_statusbarLayout = new QGraphicsLinearLayout(Qt::Horizontal);

    m_back = addTool("go-previous", m_toolbarLayout);
    m_forward = addTool("go-next", m_toolbarLayout);

    m_nativeHistoryCombo = new KHistoryComboBox();
    m_historyCombo = new Plasma::BrowserHistoryComboBox(this);
    m_historyCombo->setNativeWidget(m_nativeHistoryCombo);
    m_historyCombo->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    m_historyCombo->setZValue(999);

    m_nativeHistoryCombo->setDuplicatesEnabled(false);
    m_pixmapProvider = new KUrlPixmapProvider;
    m_nativeHistoryCombo->setPixmapProvider(m_pixmapProvider);

    m_toolbarLayout->addItem(m_historyCombo);
    m_go = addTool("go-jump-locationbar", m_toolbarLayout);
    m_goAction = m_go->action();
    m_reloadAction = new QAction(KIcon("view-refresh"), QString(), this);

    m_layout->addItem(m_toolbarLayout);

    m_browser = new Plasma::WebView(this);
    m_browser->setPage(new WebBrowserPage(this));
    m_browser->setPreferredSize(400, 400);

    m_browser->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    m_layout->addItem(m_browser);

    //bookmarks
    m_bookmarkManager = KBookmarkManager::userBookmarksManager();
    connect(m_bookmarkManager, SIGNAL(changed(QString,QString)), this, SLOT(bookmarksModelInit()));
    bookmarksModelInit();

    m_bookmarksView = new Plasma::TreeView(this);
    m_bookmarksView->setZValue(1);
    m_bookmarksView->nativeWidget()->setAttribute(Qt::WA_NoSystemBackground, false);
    m_bookmarksView->nativeWidget()->verticalScrollBar()->setStyle(QApplication::style());
    m_bookmarksView->nativeWidget()->horizontalScrollBar()->setStyle(QApplication::style());
    m_bookmarksView->setModel(m_bookmarkModel);
    m_bookmarksView->nativeWidget()->setHeaderHidden(true);
    m_bookmarksView->hide();

    m_bookmarksDelegate = new BookmarksDelegate(this);
    m_bookmarksView->nativeWidget()->setItemDelegate(m_bookmarksDelegate);

    connect(m_bookmarksDelegate, SIGNAL(destroyBookmark(QModelIndex)), this, SLOT(removeBookmark(QModelIndex)));

    m_layout->addItem(m_statusbarLayout);

    m_addBookmark = addTool("bookmark-new", m_statusbarLayout);
    m_addBookmarkAction = m_addBookmark->action();
    m_removeBookmarkAction = new QAction(KIcon("list-remove"), QString(), this);
    m_organizeBookmarks = addTool("bookmarks-organize", m_statusbarLayout);

    m_bookmarksViewAnimation = Plasma::Animator::create(Plasma::Animator::FadeAnimation, this);
    m_bookmarksViewAnimation->setTargetWidget(m_bookmarksView);
    connect(m_bookmarksViewAnimation, SIGNAL(finished()), this, SLOT(bookmarksAnimationFinished()));

    m_stop = addTool("process-stop", m_statusbarLayout);

    QGraphicsWidget *spacer = new QGraphicsWidget(this);
    spacer->setMaximumWidth(INT_MAX);
    spacer->setMaximumHeight(0);
    spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    m_statusbarLayout->addItem(spacer);
    
    m_zoom = new Plasma::Slider(this);
    m_zoom->setMaximum(100);
    m_zoom->setMinimum(0);
    m_zoom->setValue(50);
    m_zoom->setOrientation(Qt::Horizontal);
    m_zoom->hide();
    m_zoom->setMaximumWidth(200);
    m_statusbarLayout->addItem(m_zoom);

    connect(m_zoom, SIGNAL(valueChanged(int)), this, SLOT(zoom(int)));
    m_browser->setUrl(m_url);
    m_browser->update();

    connect(m_back->action(), SIGNAL(triggered()), this, SLOT(back()));
    connect(m_forward->action(), SIGNAL(triggered()), this, SLOT(forward()));
    connect(m_reloadAction, SIGNAL(triggered()), this, SLOT(reload()));
    connect(m_goAction, SIGNAL(triggered()), this, SLOT(returnPressed()));
    connect(m_stop->action(), SIGNAL(triggered()), m_browser->page()->action(QWebPage::Stop), SLOT(trigger()));

    connect(m_historyCombo->nativeWidget(), SIGNAL(returnPressed()), this, SLOT(returnPressed()));
    connect(m_historyCombo->nativeWidget(), SIGNAL(activated(int)), this, SLOT(returnPressed()));
    connect(m_historyCombo, SIGNAL(activated(QString)), this, SLOT(comboTextChanged(QString)));
    connect(m_browser->page()->mainFrame(), SIGNAL(urlChanged(QUrl)), this, SLOT(urlChanged(QUrl)));
    connect(m_browser, SIGNAL(loadProgress(int)), this, SLOT(loadProgress(int)));
    
    connect(m_addBookmarkAction, SIGNAL(triggered()), this, SLOT(addBookmark()));
    connect(m_removeBookmarkAction, SIGNAL(triggered()), this, SLOT(removeBookmark()));
    connect(m_organizeBookmarks->action(), SIGNAL(triggered()), this, SLOT(bookmarksToggle()));
    connect(m_bookmarksView->nativeWidget(), SIGNAL(clicked(QModelIndex)), this, SLOT(bookmarkClicked(QModelIndex)));

    //Autocompletion stuff
    m_completion = new KCompletion();
    m_nativeHistoryCombo->setCompletionObject(m_completion);

    m_graphicsWidget = new QGraphicsWidget(this);
    m_graphicsWidget->setLayout(m_layout);

    m_back->setEnabled(m_browser->page()->history()->canGoBack());
    m_forward->setEnabled(m_browser->page()->history()->canGoForward());

    configChanged();

    connect(this, SIGNAL(messageButtonPressed(MessageButton)), this, SLOT(removeBookmarkMessageButtonPressed(MessageButton)));
    
    return m_graphicsWidget;
}