예제 #1
0
void HGLayout::setSpacing(int s)
{
    HLayout::setSpacing(s);

    QGraphicsLayout* ll = layout();
    if (!ll) return ;

    switch (layoutType()) {
    case HEnums::kVBox:
    case HEnums::kHBox: {
        QGraphicsLinearLayout* l = static_cast<QGraphicsLinearLayout*>(ll);
        l->setSpacing(s);
        break;
    }
    case HEnums::kGrid: {
        QGraphicsGridLayout* l = static_cast<QGraphicsGridLayout*>(ll);
        l->setSpacing(s);
        break;
    }
    case HEnums::kAnchor: {
        QGraphicsAnchorLayout* l = static_cast<QGraphicsAnchorLayout*>(ll);
        l->setSpacing(s);
        break;
    }
    default:
        break;
    }
}
static QGraphicsLayout* createLayouts(int whichLayout)
{
    QSizeF min(0, 10);
    QSizeF pref(50, 10);
    QSizeF max(100, 10);

    QGraphicsWidget *a = createItem(min, pref, max, "a");
    QGraphicsWidget *b = createItem(min, pref, max, "b");
    QGraphicsWidget *c = createItem(min, pref, max, "c");
    QGraphicsWidget *d = createItem(min, pref, max, "d");

    QGraphicsLayout *l;
    if (whichLayout == 0) {
        l = new QGraphicsLinearLayout;
        QGraphicsLinearLayout *linear = static_cast<QGraphicsLinearLayout *>(l);
        linear->setContentsMargins(0, 0, 0, 0);

        linear->addItem(a);
        linear->addItem(b);
        linear->addItem(c);
        linear->addItem(d);
    } else {
        l = new QGraphicsAnchorLayout;
        QGraphicsAnchorLayout *anchor = static_cast<QGraphicsAnchorLayout *>(l);
        anchor->setContentsMargins(0, 0, 0, 0);

        // Horizontal
        setAnchor(anchor, anchor, Qt::AnchorLeft, a, Qt::AnchorLeft, 0);
        setAnchor(anchor, a, Qt::AnchorRight, b, Qt::AnchorLeft, 0);
        setAnchor(anchor, b, Qt::AnchorRight, c, Qt::AnchorLeft, 0);
        setAnchor(anchor, c, Qt::AnchorRight, d, Qt::AnchorLeft, 0);
        setAnchor(anchor, d, Qt::AnchorRight, anchor, Qt::AnchorRight, 0);

        // Vertical
        anchor->addAnchors(anchor, a, Qt::Vertical);
        anchor->addAnchors(anchor, b, Qt::Vertical);
        anchor->addAnchors(anchor, c, Qt::Vertical);
        anchor->addAnchors(anchor, d, Qt::Vertical);
    }

    return l;
}
예제 #3
0
void MainPage::createContent(void)
{
	m_bluez->start();

	MApplicationPage::createContent();
	setStyleName("CommonApplicationPage");
	setPannable(false);
	
	createObjectMenuActions();
	createActions();

	QGraphicsAnchorLayout *layout = new QGraphicsAnchorLayout();
	layout->setContentsMargins(0, 0, 0, 0);

	ViewHeader *header = new ViewHeader(tr("Stored tags"));
	layout->addCornerAnchors(header, Qt::TopLeftCorner,
				 layout, Qt::TopLeftCorner);

	LabelOrList *list = new LabelOrList(TagStorage::storage(),
					    _getTagListCellCreator,
					    tr("You don't have any "
					       "stored tags currently. "
					       "Create some or harvest "
					       "existing ones by touching "
					       "them."),
					    false,
					    false);
	list->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
	layout->addCornerAnchors(list, Qt::TopLeftCorner,
				 header, Qt::BottomLeftCorner);
	layout->addCornerAnchors(list, Qt::BottomRightCorner,
				 layout, Qt::BottomRightCorner);
	connect(list, SIGNAL(itemClicked(const QModelIndex &)),
		this, SLOT(tagSelected(const QModelIndex &)));
	connect(list, SIGNAL(itemLongTapped(const QModelIndex &,
					    const QPointF &)),
		this, SLOT(tagLongSelected(const QModelIndex &,
					   const QPointF &)));

	centralWidget()->setLayout(layout);
}
static PyObject *meth_QGraphicsAnchorLayout_addAnchor(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        QGraphicsLayoutItem* a0;
        Qt::AnchorPoint a1;
        QGraphicsLayoutItem* a2;
        Qt::AnchorPoint a3;
        QGraphicsAnchorLayout *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "BJ:EJ:E", &sipSelf, sipType_QGraphicsAnchorLayout, &sipCpp, sipType_QGraphicsLayoutItem, &a0, sipType_Qt_AnchorPoint, &a1, sipType_QGraphicsLayoutItem, &a2, sipType_Qt_AnchorPoint, &a3))
        {
            QGraphicsAnchor*sipRes;

            Py_BEGIN_ALLOW_THREADS
            sipRes = sipCpp->addAnchor(a0,a1,a2,a3);
            Py_END_ALLOW_THREADS

            return sipConvertFromType(sipRes,sipType_QGraphicsAnchor,NULL);
        }
    }
void StatusIndicatorMenuDropDownView::applyStyle()
{
    MSceneWindowView::applyStyle();

    if (pannableViewport == NULL) {
        QGraphicsAnchorLayout *backgroundLayout = new QGraphicsAnchorLayout;
        backgroundLayout->setContentsMargins(0, 0, 0, 0);
        backgroundLayout->setSpacing(0);
        backgroundLayout->addCornerAnchors(backgroundWidget, Qt::TopLeftCorner, backgroundLayout, Qt::TopLeftCorner);
        backgroundLayout->setMaximumHeight(0);

        // Put all the stuff into the scene window layout
        pannableViewport = createPannableArea();
        topRowWidget = createTopRow();
        QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
        layout->setContentsMargins(0, 0, 0, 0);
        layout->setSpacing(0);
        layout->addItem(topRowWidget);
        layout->addItem(backgroundLayout);
        layout->addItem(pannableViewport);
        controller->setLayout(layout);
    }
}
예제 #6
0
void FoursquareAuthPage::createContent(void)
{
	MApplicationPage::createContent();
	setStyleName("CommonApplicationPage");
	setPannable(false);

	MAction *cancelAction = new MAction(tr("Cancel"), this);
	cancelAction->setLocation(MAction::ToolBarLocation);
	connect(cancelAction, SIGNAL(triggered()),
		this, SLOT(dismiss()));
	addAction(cancelAction);

	QGraphicsAnchorLayout *layout = new QGraphicsAnchorLayout();
	layout->setContentsMargins(0, 0, 0, 0);

	m_header = new ViewHeader(tr("Foursquare authentication"));

	layout->addCornerAnchors(m_header, Qt::TopLeftCorner,
				 layout, Qt::TopLeftCorner);
	layout->addCornerAnchors(m_header, Qt::TopRightCorner,
				 layout, Qt::TopRightCorner);

	QGraphicsGridLayout *subLayout = new QGraphicsGridLayout();
	layout->addCornerAnchors(subLayout, Qt::TopLeftCorner,
				 m_header, Qt::BottomLeftCorner);
 	layout->addCornerAnchors(subLayout, Qt::BottomRightCorner,
 				 layout, Qt::BottomRightCorner);

	m_view = new QGraphicsWebView();
	m_view->setResizesToContents(false);
	m_view->setSizePolicy(QSizePolicy::Ignored,
			      QSizePolicy::Ignored);
	connect(m_view, SIGNAL(loadStarted()),
		this, SLOT(pageLoadStarted()));
	connect(m_view, SIGNAL(loadFinished(bool)),
		this, SLOT(pageLoadFinished(bool)));

	subLayout->addItem(m_view, 0, 0);

	m_nam = new FoursquareAuthNetworkAccessManager(m_view->page()->networkAccessManager(), 
						       REDIRECT_URL,
						       this);
	connect(m_nam, SIGNAL(tokenReceived(QString)),
		this, SLOT(tokenReceived(QString)));

	m_view->page()->setNetworkAccessManager(m_nam);

	centralWidget()->setLayout(layout);

	Q_EMIT(created());
}
예제 #7
0
int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    QGraphicsScene scene;
    scene.setSceneRect(0, 0, 800, 480);

    QSizeF minSize(30, 100);
    QSizeF prefSize(210, 100);
    QSizeF maxSize(300, 100);

    QGraphicsProxyWidget *a = createItem(minSize, prefSize, maxSize, "A");
    QGraphicsProxyWidget *b = createItem(minSize, prefSize, maxSize, "B");
    QGraphicsProxyWidget *c = createItem(minSize, prefSize, maxSize, "C");
    QGraphicsProxyWidget *d = createItem(minSize, prefSize, maxSize, "D");
    QGraphicsProxyWidget *e = createItem(minSize, prefSize, maxSize, "E");
    QGraphicsProxyWidget *f = createItem(QSizeF(30, 50), QSizeF(150, 50), maxSize, "F (overflow)");
    QGraphicsProxyWidget *g = createItem(QSizeF(30, 50), QSizeF(30, 100), maxSize, "G (overflow)");

    QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
    l->setSpacing(0);

    QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window);
    w->setPos(20, 20);
    w->setLayout(l);

    // vertical
    QGraphicsAnchor *anchor = l->addAnchor(a, Qt::AnchorTop, l, Qt::AnchorTop);
    anchor = l->addAnchor(b, Qt::AnchorTop, l, Qt::AnchorTop);

    anchor = l->addAnchor(c, Qt::AnchorTop, a, Qt::AnchorBottom);
    anchor = l->addAnchor(c, Qt::AnchorTop, b, Qt::AnchorBottom);
    anchor = l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop);
    anchor = l->addAnchor(c, Qt::AnchorBottom, e, Qt::AnchorTop);

    anchor = l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom);
    anchor = l->addAnchor(e, Qt::AnchorBottom, l, Qt::AnchorBottom);

    anchor = l->addAnchor(c, Qt::AnchorTop, f, Qt::AnchorTop);
    anchor = l->addAnchor(c, Qt::AnchorVerticalCenter, f, Qt::AnchorBottom);
    anchor = l->addAnchor(f, Qt::AnchorBottom, g, Qt::AnchorTop);
    anchor = l->addAnchor(c, Qt::AnchorBottom, g, Qt::AnchorBottom);

    // horizontal
    anchor = l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft);
    anchor = l->addAnchor(l, Qt::AnchorLeft, d, Qt::AnchorLeft);
    anchor = l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);

    anchor = l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft);
    anchor = l->addAnchor(c, Qt::AnchorRight, e, Qt::AnchorLeft);

    anchor = l->addAnchor(b, Qt::AnchorRight, l, Qt::AnchorRight);
    anchor = l->addAnchor(e, Qt::AnchorRight, l, Qt::AnchorRight);
    anchor = l->addAnchor(d, Qt::AnchorRight, e, Qt::AnchorLeft);

    anchor = l->addAnchor(l, Qt::AnchorLeft, f, Qt::AnchorLeft);
    anchor = l->addAnchor(l, Qt::AnchorLeft, g, Qt::AnchorLeft);
    anchor = l->addAnchor(f, Qt::AnchorRight, g, Qt::AnchorRight);


    scene.addItem(w);
    scene.setBackgroundBrush(Qt::darkGreen);
    QGraphicsView *view = new QGraphicsView(&scene);
    view->show();

    return app.exec();
}
void tst_QGraphicsAnchorLayout::linearVsAnchorNested()
{
    QFETCH(int, whichLayout);

    QSizeF min(10, 10);
    QSizeF pref(80, 80);
    QSizeF max(150, 150);

    QGraphicsWidget *a = createItem(min, pref, max, "a");
    QGraphicsWidget *b = createItem(min, pref, max, "b");
    QGraphicsWidget *c = createItem(min, pref, max, "c");
    QGraphicsWidget *d = createItem(min, pref, max, "d");

    QGraphicsLayout *layout;

    if (whichLayout == 0) {
        QGraphicsLinearLayout *linear1 = new QGraphicsLinearLayout;
        QGraphicsLinearLayout *linear2 = new QGraphicsLinearLayout(Qt::Vertical);
        QGraphicsLinearLayout *linear3 = new QGraphicsLinearLayout;

        linear1->addItem(a);
        linear1->addItem(linear2);
        linear2->addItem(b);
        linear2->addItem(linear3);
        linear3->addItem(c);
        linear3->addItem(d);

        layout = linear1;
    } else if (whichLayout == 1) {
        QGraphicsAnchorLayout *anchor = new QGraphicsAnchorLayout;

        // A
        anchor->addCornerAnchors(a, Qt::TopLeftCorner, anchor, Qt::TopLeftCorner);
        anchor->addCornerAnchors(a, Qt::TopRightCorner, b, Qt::TopLeftCorner);
        anchor->addCornerAnchors(a, Qt::BottomLeftCorner, anchor, Qt::BottomLeftCorner);
        anchor->addCornerAnchors(a, Qt::BottomRightCorner, c, Qt::BottomLeftCorner);

        // B
        anchor->addCornerAnchors(b, Qt::TopRightCorner, anchor, Qt::TopRightCorner);
        anchor->addCornerAnchors(b, Qt::BottomLeftCorner, c, Qt::TopLeftCorner);
        anchor->addCornerAnchors(b, Qt::BottomRightCorner, d, Qt::TopRightCorner);

        // C
        anchor->addCornerAnchors(c, Qt::TopRightCorner, d, Qt::TopLeftCorner);
        anchor->addCornerAnchors(c, Qt::BottomRightCorner, d, Qt::BottomLeftCorner);

        // D
        anchor->addCornerAnchors(d, Qt::BottomRightCorner, anchor, Qt::BottomRightCorner);

        layout = anchor;
    } else {
        QGraphicsAnchorLayout *anchor = new QGraphicsAnchorLayout;

        // A
        anchor->addAnchor(a, Qt::AnchorLeft, anchor, Qt::AnchorLeft);
        anchor->addAnchors(a, anchor, Qt::Vertical);
        anchor->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft);
        anchor->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft);

        // B
        anchor->addAnchor(b, Qt::AnchorTop, anchor, Qt::AnchorTop);
        anchor->addAnchor(b, Qt::AnchorRight, anchor, Qt::AnchorRight);
        anchor->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop);
        anchor->addAnchor(b, Qt::AnchorBottom, d, Qt::AnchorTop);

        // C
        anchor->addAnchor(c, Qt::AnchorRight, d, Qt::AnchorLeft);
        anchor->addAnchor(c, Qt::AnchorBottom, anchor, Qt::AnchorBottom);

        // D
        anchor->addAnchor(d, Qt::AnchorRight, anchor, Qt::AnchorRight);
        anchor->addAnchor(d, Qt::AnchorBottom, anchor, Qt::AnchorBottom);

        layout = anchor;
    }

    QSizeF sizeHint;
    // warm up instruction cache
    layout->invalidate();
    sizeHint = layout->effectiveSizeHint(Qt::PreferredSize);

    // ...then measure...
    QBENCHMARK {
        // To ensure that all sizeHints caches are invalidated in
        // the LinearLayout setup, we must call updateGeometry on the
        // children. If we didn't, only the top level layout would be
        // re-calculated.
        static_cast<QGraphicsLayoutItem *>(a)->updateGeometry();
        static_cast<QGraphicsLayoutItem *>(b)->updateGeometry();
        static_cast<QGraphicsLayoutItem *>(c)->updateGeometry();
        static_cast<QGraphicsLayoutItem *>(d)->updateGeometry();
        layout->invalidate();
        sizeHint = layout->effectiveSizeHint(Qt::PreferredSize);
    }
}
void tst_QGraphicsAnchorLayout::hard_complex()
{
    QFETCH(int, whichSizeHint);

    // Test for "hard" complex case, taken from wiki
    // https://cwiki.nokia.com/S60QTUI/AnchorLayoutComplexCases
    QSizeF min(0, 10);
    QSizeF pref(50, 10);
    QSizeF max(100, 10);

    QGraphicsWidget *a = createItem(min, pref, max, "a");
    QGraphicsWidget *b = createItem(min, pref, max, "b");
    QGraphicsWidget *c = createItem(min, pref, max, "c");
    QGraphicsWidget *d = createItem(min, pref, max, "d");
    QGraphicsWidget *e = createItem(min, pref, max, "e");
    QGraphicsWidget *f = createItem(min, pref, max, "f");
    QGraphicsWidget *g = createItem(min, pref, max, "g");

    QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout;
    l->setContentsMargins(0, 0, 0, 0);

    //<!-- Trunk -->
    setAnchor(l, l, Qt::AnchorLeft, a, Qt::AnchorLeft, 10);
    setAnchor(l, a, Qt::AnchorRight, b, Qt::AnchorLeft, 10);
    setAnchor(l, b, Qt::AnchorRight, c, Qt::AnchorLeft, 10);
    setAnchor(l, c, Qt::AnchorRight, d, Qt::AnchorLeft, 10);
    setAnchor(l, d, Qt::AnchorRight, l, Qt::AnchorRight, 10);

    //<!-- Above trunk -->
    setAnchor(l, b, Qt::AnchorLeft, e, Qt::AnchorLeft, 10);
    setAnchor(l, e, Qt::AnchorRight, d, Qt::AnchorLeft, 10);

    //<!-- Below trunk -->
    setAnchor(l, a, Qt::AnchorHorizontalCenter, g, Qt::AnchorLeft, 10);
    setAnchor(l, g, Qt::AnchorRight, f, Qt::AnchorHorizontalCenter, 10);
    setAnchor(l, c, Qt::AnchorLeft, f, Qt::AnchorLeft, 10);
    setAnchor(l, f, Qt::AnchorRight, d, Qt::AnchorRight, 10);

    //<!-- vertical is simpler -->
    setAnchor(l, l, Qt::AnchorTop, e, Qt::AnchorTop, 0);
    setAnchor(l, e, Qt::AnchorBottom, a, Qt::AnchorTop, 0);
    setAnchor(l, e, Qt::AnchorBottom, b, Qt::AnchorTop, 0);
    setAnchor(l, e, Qt::AnchorBottom, c, Qt::AnchorTop, 0);
    setAnchor(l, e, Qt::AnchorBottom, d, Qt::AnchorTop, 0);
    setAnchor(l, a, Qt::AnchorBottom, f, Qt::AnchorTop, 0);
    setAnchor(l, a, Qt::AnchorBottom, b, Qt::AnchorBottom, 0);
    setAnchor(l, a, Qt::AnchorBottom, c, Qt::AnchorBottom, 0);
    setAnchor(l, a, Qt::AnchorBottom, d, Qt::AnchorBottom, 0);
    setAnchor(l, f, Qt::AnchorBottom, g, Qt::AnchorTop, 0);
    setAnchor(l, g, Qt::AnchorBottom, l, Qt::AnchorBottom, 0);

    // It won't query the size hint if it already has a size set.
    // If only one of the sizes is unset it will query sizeHint only of for that hint type.
    l->setMinimumSize(60,40);
    l->setPreferredSize(220,40);
    l->setMaximumSize(240,40);

    switch (whichSizeHint) {
    case Qt::MinimumSize:
        l->setMinimumSize(-1, -1);
        break;
    case Qt::PreferredSize:
        l->setPreferredSize(-1, -1);
        break;
    case Qt::MaximumSize:
        l->setMaximumSize(-1, -1);
        break;
    default:
        break;
    }

    QSizeF sizeHint;
    // warm up instruction cache
    l->invalidate();
    sizeHint = l->effectiveSizeHint((Qt::SizeHint)whichSizeHint);
    // ...then measure...
    QBENCHMARK {
        l->invalidate();
        sizeHint = l->effectiveSizeHint((Qt::SizeHint)whichSizeHint);
    }
}
예제 #10
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QGraphicsScene *scene = new QGraphicsScene();

    Widget *a = new Widget(Qt::blue, Qt::white, "a");
    a->setPreferredSize(100, 100);
    Widget *b = new Widget(Qt::green, Qt::black, "b");
    b->setPreferredSize(100, 100);
    Widget *c = new Widget(Qt::red, Qt::black, "c");
    c->setPreferredSize(100, 100);

    QGraphicsAnchorLayout *layout = new QGraphicsAnchorLayout();
/*
    //! [adding a corner anchor in two steps]
    layout->addAnchor(a, Qt::AnchorTop, layout, Qt::AnchorTop);
    layout->addAnchor(a, Qt::AnchorLeft, layout, Qt::AnchorLeft);
    //! [adding a corner anchor in two steps]
*/
    //! [adding a corner anchor]
    layout->addCornerAnchors(a, Qt::TopLeftCorner, layout, Qt::TopLeftCorner);
    //! [adding a corner anchor]

    //! [adding anchors]
    layout->addAnchor(b, Qt::AnchorLeft, a, Qt::AnchorRight);
    layout->addAnchor(b, Qt::AnchorTop, a, Qt::AnchorBottom);
    //! [adding anchors]

    // Place a third widget below the second.
    layout->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop);

/*
    //! [adding anchors to match sizes in two steps]
    layout->addAnchor(b, Qt::AnchorLeft, c, Qt::AnchorLeft);
    layout->addAnchor(b, Qt::AnchorRight, c, Qt::AnchorRight);
    //! [adding anchors to match sizes in two steps]
*/

    //! [adding anchors to match sizes]
    layout->addAnchors(b, c, Qt::Horizontal);
    //! [adding anchors to match sizes]

    // Anchor the bottom-right corner of the third widget to the bottom-right
    // corner of the layout.
    layout->addCornerAnchors(c, Qt::BottomRightCorner, layout, Qt::BottomRightCorner);

    QGraphicsWidget *w = new QGraphicsWidget(0, Qt::Window | Qt::CustomizeWindowHint | Qt::WindowTitleHint);
    w->setPos(20, 20);
    w->setMinimumSize(100, 100);
    w->setPreferredSize(320, 240);
    w->setLayout(layout);
    w->setWindowTitle(QApplication::translate("simpleanchorlayout", "QGraphicsAnchorLayout in use"));
    scene->addItem(w);

    QGraphicsView *view = new QGraphicsView();
    view->setScene(scene);
    view->setWindowTitle(QApplication::translate("simpleanchorlayout", "Simple Anchor Layout"));
    view->resize(360, 320);
    view->show();

    return app.exec();
}
예제 #11
0
void CreateEditPage::createContent(void)
{
	MApplicationPage::createContent();
	setStyleName("CommonApplicationPage");
	setPannable(false);

	createActions();

	QGraphicsAnchorLayout *anchor = new QGraphicsAnchorLayout();
	anchor->setContentsMargins(0, 0, 0, 0);
	anchor->setSizePolicy(QSizePolicy::Minimum, 
			      QSizePolicy::Minimum);

	ViewHeader *header = 
		new ViewHeader(m_tag == TagStorage::NULL_TAG 
			       ? tr("Create tag contents")
			       : tr("Edit tag contents"));
	anchor->addCornerAnchors(header, Qt::TopLeftCorner,
				 anchor, Qt::TopLeftCorner);

#ifdef LABEL_SIZE
	m_size = new MLabel();
	m_size->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
	m_size->setAlignment(Qt::AlignRight);
	anchor->addAnchor(m_size, Qt::AnchorBottom, anchor, Qt::AnchorBottom);
	anchor->addAnchor(m_size, Qt::AnchorRight, anchor, Qt::AnchorRight);
#endif

	MWidget *layoutContainer = new MWidget();
	layoutContainer->setSizePolicy(QSizePolicy::Preferred, 
				       QSizePolicy::Minimum);
	m_layout = new QGraphicsLinearLayout(Qt::Vertical, layoutContainer);
	m_layout->setSizePolicy(QSizePolicy::Preferred, 
				QSizePolicy::Minimum);

	m_name = new LabeledTextEdit(tr("Ok"),
				     LabeledTextEdit::SingleLineEditAndLabel);
	m_name->setLabel(tr("Tag name"));
	m_name->setPrompt(tr("Enter tag name"));
	m_name->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
	m_layout->addItem(m_name);
	m_layout->setAlignment(m_name, Qt::AlignLeft);
	connect(m_name, SIGNAL(contentsChanged(void)),
		this, SLOT(nameChanged(void)));

	MSeparator *sep = new MSeparator;
	sep->setStyleName("CommonHorizontalSeparator");
	sep->setOrientation(Qt::Horizontal);
	layout()->addItem(sep);

	createPageSpecificContent();

	MPannableViewport *view = new MPannableViewport();
	view->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
	view->setPanDirection(Qt::Vertical);
	view->setMinimumSize(100, 100);
	view->setWidget(layoutContainer);

	anchor->addAnchor(view, Qt::AnchorTop, header, Qt::AnchorBottom);
#ifdef LABEL_SIZE
	anchor->addAnchor(view, Qt::AnchorBottom, m_size, Qt::AnchorTop);
#else
	anchor->addAnchor(view, Qt::AnchorBottom, anchor, Qt::AnchorBottom);
#endif
	anchor->addAnchor(view, Qt::AnchorLeft, anchor, Qt::AnchorLeft);
	anchor->addAnchor(view, Qt::AnchorRight, anchor, Qt::AnchorRight);

	centralWidget()->setLayout(anchor);

	if (m_tag == TagStorage::NULL_TAG) {
		setContentValidity(false);
		setNameValidity(false);
		setupNewData();
	} else {
		load();
	}
}
예제 #12
0
void
CurrentTrack::init()
{
    DEBUG_BLOCK
    PERF_LOG( "Begin init" );

    // Call the base implementation.
    Context::Applet::init();

    setToolTip( i18n( "Right-click to configure" ) );

    m_ratingWidget = new RatingWidget( this );
    m_ratingWidget->setSpacing( 2 );
    m_ratingWidget->setMinimumSize( m_albumWidth + 10, 30 );
    m_ratingWidget->setMaximumSize( m_albumWidth + 10, 30 );
    connect( m_ratingWidget, SIGNAL(ratingChanged(int)), SLOT(trackRatingChanged(int)) );

    QLabel *collectionLabel = new QLabel( i18n( "Local Collection" ) );
    collectionLabel->setAttribute( Qt::WA_NoSystemBackground );
    collectionLabel->setAlignment( Qt::AlignCenter );
    m_collectionLabel = new QGraphicsProxyWidget( this );
    m_collectionLabel->setWidget( collectionLabel );

    m_title  = new TextScrollingWidget( this );
    m_artist = new TextScrollingWidget( this );
    m_album  = new TextScrollingWidget( this );
    m_byText = new QGraphicsSimpleTextItem( i18nc( "What artist is this track by", "By" ), this );
    m_onText = new QGraphicsSimpleTextItem( i18nc( "What album is this track on", "On" ), this );

    m_recentWidget = new RecentlyPlayedListWidget( this );
    m_recentHeader = new TextScrollingWidget( this );
    m_recentHeader->setDrawBackground( true );
    m_recentHeader->setAlignment( Qt::AlignLeft );
    QFont recentHeaderFont;
    recentHeaderFont.setPointSize( recentHeaderFont.pointSize() + 2 );
    m_recentHeader->setFont( recentHeaderFont );

    m_title->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_artist->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_album->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_collectionLabel->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_recentHeader->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed );
    m_recentWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    m_recentWidget->setMinimumHeight( 10 );

    m_albumCover = new DropPixmapLayoutItem( this );
    m_albumCover->setPreferredSize( QSizeF( m_albumWidth, m_albumWidth ) );
    connect( m_albumCover, SIGNAL(imageDropped(QPixmap)), SLOT(coverDropped(QPixmap)) );

    const QBrush brush = normalBrush();
    m_title->setBrush( brush );
    m_artist->setBrush( brush );
    m_album->setBrush( brush );
    m_byText->setBrush( brush );
    m_onText->setBrush( brush );

    const QFont tinyFont = KGlobalSettings::smallestReadableFont();
    m_byText->setFont( tinyFont );
    m_onText->setFont( tinyFont );

    m_actionsLayout = new QGraphicsLinearLayout;
    m_actionsLayout->setMinimumWidth( 10 );
    m_actionsLayout->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    QGraphicsLinearLayout *titlesLayout = new QGraphicsLinearLayout( Qt::Vertical );
    titlesLayout->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    titlesLayout->setMinimumWidth( 10 );
    titlesLayout->setSpacing( 2 );
    titlesLayout->addItem( m_title );
    titlesLayout->addItem( m_artist );
    titlesLayout->addItem( m_album );
    titlesLayout->addItem( m_actionsLayout );
    titlesLayout->setItemSpacing( 2, 4 ); // a bit more spacing for the actions row

    const qreal pad = standardPadding();
    QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout( this );
    l->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
    l->addCornerAnchors( m_ratingWidget, Qt::BottomLeftCorner, l, Qt::BottomLeftCorner );
    l->addCornerAnchors( m_ratingWidget, Qt::BottomLeftCorner, m_collectionLabel, Qt::BottomLeftCorner );
    l->addCornerAnchors( m_ratingWidget, Qt::TopRightCorner, m_collectionLabel, Qt::TopRightCorner );
    l->addCornerAnchors( m_recentHeader, Qt::TopRightCorner, l, Qt::TopRightCorner );
    l->addAnchor( m_albumCover, Qt::AnchorBottom, m_ratingWidget, Qt::AnchorTop )->setSpacing( 4 );
    l->addAnchor( m_albumCover, Qt::AnchorHorizontalCenter, m_ratingWidget, Qt::AnchorHorizontalCenter );
    l->addAnchor( titlesLayout, Qt::AnchorTop, l, Qt::AnchorTop )->setSpacing( 18 );
    l->addAnchor( titlesLayout, Qt::AnchorRight, l, Qt::AnchorRight )->setSpacing( pad );
    l->addAnchors( m_recentWidget, m_recentHeader, Qt::Horizontal );
    l->addAnchor( m_recentWidget, Qt::AnchorTop, m_recentHeader, Qt::AnchorBottom );
    l->addAnchor( m_recentWidget, Qt::AnchorRight, m_recentHeader, Qt::AnchorRight );
    l->addAnchor( m_recentWidget, Qt::AnchorLeft, m_ratingWidget, Qt::AnchorRight )->setSpacing( pad * 2 );
    l->addAnchor( m_recentWidget, Qt::AnchorBottom, m_albumCover, Qt::AnchorBottom )->setSpacing( 20 );
    qreal midSpacing = qMax( m_byText->boundingRect().width(), m_onText->boundingRect().width() ) + pad;
    l->addAnchor( titlesLayout, Qt::AnchorLeft, m_ratingWidget, Qt::AnchorRight )->setSpacing( midSpacing );
    l->anchor( m_recentHeader, Qt::AnchorTop, l, Qt::AnchorTop )->setSpacing( 2 );

    // Read config
    KConfigGroup config = Amarok::config("Current Track Applet");
    const QString fontDesc = config.readEntry( "Font", QString() );
    QFont font;
    if( !fontDesc.isEmpty() )
        font.fromString( fontDesc );
    else
        font.setPointSize( font.pointSize() + 3 );

    m_showEditTrackDetailsAction = config.readEntry( "ShowEditTrackAction", true );

    m_title->setFont( font );
    m_artist->setFont( font );
    m_album->setFont( font );

    m_title->setAlignment( Qt::AlignLeft );
    m_artist->setAlignment( Qt::AlignLeft );
    m_album->setAlignment( Qt::AlignLeft );

    dataEngine( "amarok-current" )->setProperty( "coverWidth", m_albumWidth );
    dataEngine( "amarok-current" )->connectSource( "current", this );
    connect( The::paletteHandler(), SIGNAL(newPalette(QPalette)), SLOT(paletteChanged(QPalette)) );
    connect( CollectionManager::instance(), SIGNAL(collectionDataChanged(Collections::Collection*)),
             this, SLOT(queryCollection()), Qt::QueuedConnection );
    queryCollection();
    setView( Stopped );

    PERF_LOG( "Finished init" );
}
예제 #13
0
void StelMainView::init(QSettings* conf)
{
	gui = new StelGui();

#if STEL_USE_NEW_OPENGL_WIDGETS
	//glWidget->initializeGL(); // protected...
	//Q_ASSERT(glWidget->isValid());
#else
	Q_ASSERT(glWidget->isValid());
	glWidget->makeCurrent();
#endif

	// Should be check of requirements disabled?
	if (conf->value("main/check_requirements", true).toBool())
	{
		// Find out lots of debug info about supported version of OpenGL and vendor/renderer.
		processOpenGLdiagnosticsAndWarnings(conf, glWidget);
	}


	stelApp= new StelApp();
	stelApp->setGui(gui);
	stelApp->init(conf);
	StelActionMgr *actionMgr = stelApp->getStelActionManager();
	actionMgr->addAction("actionSave_Screenshot_Global", N_("Miscellaneous"), N_("Save screenshot"), this, "saveScreenShot()", "Ctrl+S");
	actionMgr->addAction("actionSet_Full_Screen_Global", N_("Display Options"), N_("Full-screen mode"), this, "fullScreen", "F11");
	
	StelPainter::initGLShaders();

	skyItem = new StelSkyItem();
	guiItem = new StelGuiItem();
	QGraphicsAnchorLayout* l = new QGraphicsAnchorLayout(rootItem);
	l->setSpacing(0);
	l->setContentsMargins(0,0,0,0);
	l->addCornerAnchors(skyItem, Qt::TopLeftCorner, l, Qt::TopLeftCorner);
	l->addCornerAnchors(skyItem, Qt::BottomRightCorner, l, Qt::BottomRightCorner);
	l->addCornerAnchors(guiItem, Qt::BottomLeftCorner, l, Qt::BottomLeftCorner);
	l->addCornerAnchors(guiItem, Qt::TopRightCorner, l, Qt::TopRightCorner);
	rootItem->setLayout(l);
	scene()->addItem(rootItem);
	nightModeEffect = new NightModeGraphicsEffect(this);
	updateNightModeProperty();
	rootItem->setGraphicsEffect(nightModeEffect);

	QSize size = glWidget->windowHandle()->screen()->size();
	size = QSize(conf->value("video/screen_w", size.width()).toInt(),
		     conf->value("video/screen_h", size.height()).toInt());

	bool fullscreen = conf->value("video/fullscreen", true).toBool();

	// Without this, the screen is not shown on a Mac + we should use resize() for correct work of fullscreen/windowed mode switch. --AW WTF???
	resize(size);

	QDesktopWidget *desktop = QApplication::desktop();
	int screen = conf->value("video/screen_number", 0).toInt();
	if (screen < 0 || screen >= desktop->screenCount())
	{
		qWarning() << "WARNING: screen" << screen << "not found";
		screen = 0;
	}
	QRect screenGeom = desktop->screenGeometry(screen);

	if (fullscreen)
	{
		// The "+1" below is to work around Linux/Gnome problem with mouse focus.
		move(screenGeom.x()+1, screenGeom.y()+1);
		// The fullscreen window appears on screen where is the majority of
		// the normal window. Therefore we crop the normal window to the
		// screen area to ensure that the majority is not on another screen.
		setGeometry(geometry() & screenGeom);
		setFullScreen(true);
	}
	else
	{
		setFullScreen(false);
		int x = conf->value("video/screen_x", 0).toInt();
		int y = conf->value("video/screen_y", 0).toInt();
		move(x + screenGeom.x(), y + screenGeom.y());
	}

	flagInvertScreenShotColors = conf->value("main/invert_screenshots_colors", false).toBool();
	setFlagCursorTimeout(conf->value("gui/flag_mouse_cursor_timeout", false).toBool());
	setCursorTimeout(conf->value("gui/mouse_cursor_timeout", 10.f).toFloat());
	maxfps = conf->value("video/maximum_fps",10000.f).toFloat();
	minfps = conf->value("video/minimum_fps",10000.f).toFloat();
	flagMaxFpsUpdatePending = false;

	// XXX: This should be done in StelApp::init(), unfortunately for the moment we need init the gui before the
	// plugins, because the gui create the QActions needed by some plugins.
	StelApp::getInstance().initPlugIns();

	// activate DE430/431 
	StelApp::getInstance().getCore()->initEphemeridesFunctions();

	// The script manager can only be fully initialized after the plugins have loaded.
	StelApp::getInstance().initScriptMgr();

	// Set the global stylesheet, this is only useful for the tooltips.
	StelGui* gui = dynamic_cast<StelGui*>(StelApp::getInstance().getGui());
	if (gui!=NULL)
		setStyleSheet(gui->getStelStyle().qtStyleSheet);
	connect(&StelApp::getInstance(), SIGNAL(visionNightModeChanged(bool)), this, SLOT(updateNightModeProperty()));

	QThread::currentThread()->setPriority(QThread::HighestPriority);
	startMainLoop();
}
예제 #14
0
파일: kwidget.cpp 프로젝트: kxtry/kxmob
void KWidget::setAnchor( const QString& a )
{
    Q_D(KWidget);
    //检查布局
    KWidget* p = qobject_cast<KWidget*>(parent());
    Q_ASSERT_X(p, __FUNCTION__, "parent is null");
    Q_ASSERT_X(p->layoutType() == KWidget::Anchor, __FUNCTION__, "layout type should be anchor");
    QGraphicsLayout *layout = p->layout();
    QGraphicsAnchorLayout *anchorLayout = static_cast<QGraphicsAnchorLayout*>(layout);
    if(anchorLayout == NULL)
    {
        Q_ASSERT_X(false, __FUNCTION__, "layout is not group layout");
        return ;
    }

    if(d->bAddToAnchor)
    {
        p->removeLayoutItem(this);
    }
    //参数转换
    int index = KWidget::staticMetaObject.indexOfEnumerator("AnchorPoint");
    QMetaEnum enu = KWidget::staticMetaObject.enumerator(index);
    QStringList list = a.split('|');
    Q_ASSERT_X(list.count()==4, __FUNCTION__, QString("%1 is not valide anchor info").arg(a).toLatin1().constData());
    Qt::AnchorPoint anchorPoint[4]={Qt::AnchorLeft};
    int distance[4]={0};
    for (int i = 0; i < list.count() && i < 4; ++i)
    {
        QStringList innerList = list[i].split(':');
        Q_ASSERT_X(innerList.count()==2, __FUNCTION__, QString("%1 is not valide anchor info").arg(a).toLatin1().constData());
        if (innerList.count() >= 2)
        {
            int value = enu.keyToValue(innerList[0].toLatin1().constData());
            Q_ASSERT_X(value != -1, __FUNCTION__, (innerList[0] + "is not a valid enum value").toLatin1().constData());
            if (value == -1)
            {
                value = 0;
            }
            anchorPoint[i] = (Qt::AnchorPoint)value;
            distance[i] = innerList[1].toInt();
        }
    }

    //AnchorLeft:
    int idx = 0;
    QGraphicsAnchor *anchorLeft = anchorLayout->addAnchor(anchorLayout, anchorPoint[idx], this, Qt::AnchorLeft);
    if(anchorLeft)
    {
        anchorLeft->setSpacing(distance[idx]);
    }
    else if(anchorPoint[idx] >= Qt::AnchorTop)
    {
        Q_ASSERT_X(false, __FUNCTION__, QString("it's not the same orientation for AnchorLeft: bad string is[%1]").arg(list.at(idx)).toStdString().c_str());
    }
    else
    {
        Q_ASSERT_X(false, __FUNCTION__, QString("bad parameter.bad string:%1").arg(list.at(idx)).toStdString().c_str());
    }

    //AnchorTop:
    idx = 1;
    QGraphicsAnchor *anchorTop = anchorLayout->addAnchor(anchorLayout, anchorPoint[idx], this, Qt::AnchorTop);
    if(anchorTop)
    {
        anchorTop->setSpacing(distance[idx]);
    }
    else if(anchorPoint[idx] < Qt::AnchorTop)
    {
        Q_ASSERT_X(false, __FUNCTION__, QString("it's not the same orientation for AnchorTop: bad string is[%1]").arg(list.at(idx)).toStdString().c_str());
    }
    else
    {
        Q_ASSERT_X(false, __FUNCTION__, QString("bad parameter.bad string:%1").arg(list.at(idx)).toStdString().c_str());
    }

    //AnchorRight:
    idx = 2;
    QGraphicsAnchor *anchorRight = anchorLayout->addAnchor(this, Qt::AnchorRight, anchorLayout, anchorPoint[idx]);
    if(anchorRight)
    {
        anchorRight->setSpacing(distance[idx]);
    }
    else if(anchorPoint[idx] >= Qt::AnchorTop)
    {
        Q_ASSERT_X(false, __FUNCTION__, QString("it's not the same orientation for AnchorRight: bad string is[%1]").arg(list.at(idx)).toStdString().c_str());
    }
    else
    {
        Q_ASSERT_X(false, __FUNCTION__, QString("bad parameter.bad string:%1").arg(list.at(idx)).toStdString().c_str());
    }

    //AnchorBottom
    idx = 3;
    QGraphicsAnchor *anchorBottom = anchorLayout->addAnchor(this, Qt::AnchorBottom, anchorLayout, anchorPoint[idx]);
    if(anchorBottom)
    {
        anchorBottom->setSpacing(distance[idx]);
    }
    else if(anchorPoint[idx] < Qt::AnchorTop)
    {
        Q_ASSERT_X(false, __FUNCTION__, QString("it's not the same orientation for AnchorBottom: bad string is[%1]").arg(list.at(idx)).toStdString().c_str());
    }
    else
    {
        Q_ASSERT_X(false, __FUNCTION__, QString("bad parameter.bad string:%1").arg(list.at(idx)).toStdString().c_str());
    }
    d->bAddToAnchor = true;
}