Ejemplo n.º 1
0
void WaitWidget::setupScene()
{
	// Creamos el objeto efecto
	d->m_effect = new QGraphicsOpacityEffect;
	d->m_effect->setOpacity(0);
	d->m_effect->setEnabled(true);

	// Ahora creamos los proxys para gráficos que nos permita incluirlos en la escena
	QGraphicsProxyWidget *pFrame = d->m_scene.addWidget(d->m_widget);
	pFrame->resize(d->m_widget->width(), d->m_widget->height());

	// Y lo agregamos a un layout gráfico
	QGraphicsLinearLayout *gLayout = new QGraphicsLinearLayout;
	gLayout->setOrientation(Qt::Vertical);
	gLayout->addItem(pFrame);

	// Creamos finalmente un objeto gráfico que lo contiene todo, y lo agregamos a la escena
	QGraphicsWidget *form = new QGraphicsWidget;
	form->setLayout(gLayout);
	form->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
	d->m_scene.addItem(form);

	// Agregamos el efecto de opacidad al aparecer
	form->setGraphicsEffect(d->m_effect);
	form->resize(d->m_widget->width(), d->m_widget->height());
}
Ejemplo n.º 2
0
QGraphicsWidget *LoginSheet::createSpacer() const
{
    QGraphicsWidget *spacer = new QGraphicsWidget;
    spacer->setFlag(QGraphicsItem::ItemHasNoContents);
    spacer->setPreferredHeight(24.0);
    spacer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
    return spacer;
}
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;
}
QGraphicsWidget *createSpacer()
{
    QGraphicsWidget *spacer = new QGraphicsWidget();

    spacer->hide();
    spacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
    spacer->setMinimumSize(0, 0);
    spacer->setPreferredSize(0, 0);

    return spacer;
}
Ejemplo n.º 5
0
bool ImageStripScene::setCurrentDirectory(const QString& path)
{
    QMutexLocker locker(&m_mutex);
    QDir         directory(path);
    QImageReader reader;
    
    if(directory.exists()) {
        clear();
        
        if(m_loader) {
            m_loader->disconnect(this);
            m_loader->stopExecution();
            
            if(!m_loader->wait(500)) {
                m_loader->terminate();
                m_loader->wait();
            }
        }
        
        delete m_loader;
        
        m_numItems = 0;
        m_loader   = new ImageLoader(m_imgSize);
        connect(m_loader, SIGNAL(sigItemContentChanged(ImageItem*)), SLOT(slotItemContentChanged(ImageItem*)));
        
        QStringList            files  = directory.entryList(QDir::Files);
        QGraphicsLinearLayout* layout = new QGraphicsLinearLayout();
        
        for(QStringList::iterator name=files.begin(); name!=files.end(); ++name) {
            QString path = directory.absoluteFilePath(*name);
            reader.setFileName(path);
            
            if(reader.canRead()) {
                ImageItem* item = new ImageItem(m_imgSize, path, m_loader);
                m_loader->addPath(item, path);
                layout->addItem(item);
                ++m_numItems;
            }
        }
        
        QGraphicsWidget* widget = new QGraphicsWidget();
        widget->setLayout(layout);
        widget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
        
        addItem(widget);
        setSceneRect(widget->boundingRect());
        
        m_loader->start(QThread::LowPriority);
        return true;
    }
    
    return false;
}
Ejemplo n.º 6
0
  ChromeSnippet *ChromeDOM::getSnippet(const QString &docElementId, QGraphicsItem* parent) {
    Q_UNUSED(parent)

    ChromeSnippet * snippet = 0;
    QWebElement doc = m_page->mainFrame()->documentElement();
    QWebElement element = doc.findFirst("#" + docElementId);
    QRect rect = element.geometry();
    //TODO: This may not be accurate since final heights may not have been computed at this point!!
    m_height += rect.height();
    
    //    qDebug() << "Snippet: ID: " << docElementId << " Owner Area: " << rect << " Element Rect: " << element.geometry();
  
    if (!rect.isNull()) {
        QString className = element.attribute("data-GinebraNativeClass", "__NO_CLASS__");
        if (className == "__NO_CLASS__") {
            if (element.attribute("data-GinebraContainer", "false") == "true") {
                snippet = new WebChromeContainerSnippet(docElementId, m_chrome, element);
                snippet->setChromeWidget(new ChromeItem(snippet));
            }
            else {
                snippet = new WebChromeSnippet(docElementId, m_chrome, element);
                m_renderer->addRenderItem((static_cast<WebChromeSnippet*> (snippet))->item());
            }
        }
        else {
            snippet = nativeSnippetForClassName(className, docElementId, element);
            //TODO: Is the following still needed?
            QGraphicsWidget * widget = snippet->widget();
            //Have snippet determine its own size when in anchor layout. Again, these will not
            //necessarily be accurate at this point.
            widget->resize(rect.width(), rect.height());
            widget->setPreferredSize(rect.width(), rect.height());
            widget->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
            //Have snippet determine its own location when NOT in anchor layout
            widget->setPos(rect.x(), rect.y());
            
        }

        QWebElement parentElem;

        if (!(parentElem = findChromeParent(element)).isNull()) {
            snippet->setParentId(parentElem.attribute("id"));
        }
        //Set auto-layout attributes
        snippet->setAnchor(element.attribute("data-GinebraAnchor", "AnchorNone"), false);
        snippet->setAnchorOffset(element.attribute("data-GinebraAnchorOffset", "0").toInt());
        snippet->setInitiallyVisible(element.attribute("data-GinebraVisible", "false") == "true");
        snippet->setHidesContent(element.attribute("data-GinebraHidesContent", "false") == "true");
    }
    return snippet;
  }
void Ut_MGridLayoutPolicy::testHeightForWidthInSubLayout()
{
    QFETCH(bool, useMLayout);
    QFETCH(bool, useInnerMLayout);
    QFETCH(bool, putInnerWidgetInWidget);

    QGraphicsWidget *form = new QGraphicsWidget;


    MGridLayoutPolicy *mpolicy = NULL;
    QGraphicsGridLayout *qlayout = NULL;

    if (useMLayout) {
        MLayout *mlayout = new MLayout(form);
        mlayout->setContentsMargins(0, 0, 0, 0);
        mpolicy = new MGridLayoutPolicy(mlayout);
        mpolicy->setSpacing(0);
    } else {
        qlayout = new QGraphicsGridLayout(form);
        qlayout->setContentsMargins(0, 0, 0, 0);
        qlayout->setSpacing(0);
    }

    QGraphicsWidget *topSpacer = createSpacer();
    QGraphicsWidget *leftSpacer = createSpacer();
    QGraphicsWidget *rightSpacer = createSpacer();
    leftSpacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
    rightSpacer->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);

    QGraphicsWidget *square = new SquareWidget;

    QGraphicsLayout *innerLayout = NULL;
    if (useInnerMLayout) {
        innerLayout = new MLayout();
        MLinearLayoutPolicy *policy = new MLinearLayoutPolicy(static_cast<MLayout *>(innerLayout), Qt::Horizontal);
        policy->addItem(square);
    } else {
        innerLayout = new QGraphicsLinearLayout(Qt::Horizontal);
        static_cast<QGraphicsLinearLayout *>(innerLayout)->addItem(square);
    }
    innerLayout->setContentsMargins(0,0,0,0);

    QGraphicsLayoutItem *innerItem;
    if (putInnerWidgetInWidget) {
        QGraphicsWidget *innerWidget = new QGraphicsWidget;
        innerWidget->setLayout(innerLayout);
        innerItem = innerWidget;
    } else {
        innerItem = innerLayout;
    }

    if (useMLayout) {
        mpolicy->addItem(topSpacer, 0, 1);
        mpolicy->addItem(leftSpacer, 1, 0);
        mpolicy->addItem(rightSpacer, 1, 2);
        mpolicy->addItem(innerItem, 1, 1);
    } else {
        qlayout->addItem(topSpacer, 0, 1);
        qlayout->addItem(leftSpacer, 1, 0);
        qlayout->addItem(rightSpacer, 1, 2);
        qlayout->addItem(innerItem, 1, 1);
    }


    QCOMPARE(form->preferredSize(), QSizeF(500,500));
    QCOMPARE(form->effectiveSizeHint(Qt::PreferredSize, QSizeF(100,-1)), QSizeF(100,100));

    delete form;
}
Ejemplo n.º 8
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;
}