Ejemplo n.º 1
0
void ActivityManager::initExtenderItem(Plasma::ExtenderItem *item) {
  // create the widget
  QGraphicsWidget *widget = new QGraphicsWidget(this);
  // TODO: use the size of the longest activity name
  widget->setPreferredWidth(350);
  // create the layout
  QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(widget);
  layout->setOrientation(Qt::Vertical);
  widget->setLayout(layout);
  // set up the widget
  item->setWidget(widget);
  // create a lock/unlock action
  toggleLockAction = new QAction(item);
  toggleLockAction->setIcon(KIcon("object-locked"));
  toggleLockAction->setEnabled(true);
  toggleLockAction->setVisible(true);
  toggleLockAction->setToolTip(i18n("Activities are unlocked. Click to lock."));
  item->addAction("toggleLock", toggleLockAction);
  connect(toggleLockAction, SIGNAL(triggered()), this, SLOT(toggleLock()));
}
void Ut_MPannableViewport::testSizeHint()
{
    struct SquareWidget : public QGraphicsWidget
    {
        SquareWidget() {
            QSizePolicy policy = sizePolicy();
            policy.setHeightForWidth(true);
            setSizePolicy(policy);
        }
        QSizeF sizeHint ( Qt::SizeHint which, const QSizeF & constraint = QSizeF() ) const {
           if (which != Qt::PreferredSize || constraint.width() == -1)
              return QGraphicsWidget::sizeHint(which, constraint);
           else
              return QSizeF( constraint.width(), constraint.width() );
        }
    };

    QFETCH(QString, cssName);
    QFETCH(qreal, width);
    QFETCH(qreal, height);

    QGraphicsWidget *widget = new SquareWidget();
    widget->setPreferredWidth(100);
    subject->setWidget(widget);
    subject->setObjectName(cssName);

    QCOMPARE(widget->preferredSize(), QSizeF(100,100));
    QCOMPARE(widget->effectiveSizeHint(Qt::PreferredSize, QSizeF(200,-1)), QSizeF(200,200));

    QCOMPARE(subject->layout()->preferredSize(), QSizeF(100,100));
    QCOMPARE(subject->layout()->effectiveSizeHint(Qt::PreferredSize, QSizeF(200,-1)), QSizeF(200,200));

    QCOMPARE(subject->preferredSize(), QSizeF(width,height));
    if (cssName == "noCssSize")
        QCOMPARE(subject->effectiveSizeHint(Qt::PreferredSize, QSizeF(200,-1)), QSizeF(200,200));

    // Test that the minimum and maximum size of the viewport is the same as the widget if we cannot pan in that direction
    widget->setMinimumSize(30,30);
    widget->setMaximumSize(200,200);

    QCOMPARE(subject->maximumSize(), QSizeF(200,200));

    subject->setPanDirection(0); //Can't pan in either direction
    QCOMPARE(subject->minimumSize(), QSizeF(30,30));
    subject->setPanDirection(Qt::Vertical);
    QCOMPARE(subject->minimumSize(), QSizeF(30,0));
    subject->setPanDirection(Qt::Horizontal);
    QCOMPARE(subject->minimumSize(), QSizeF(0,30));
    subject->setPanDirection(Qt::Horizontal | Qt::Vertical);
    QCOMPARE(subject->minimumSize(), QSizeF(0,0));

    for (int panDirection = 0; panDirection <= (Qt::Vertical | Qt::Horizontal); ++panDirection) {
        subject->setPanDirection((Qt::Orientations)panDirection);
        QCOMPARE(subject->preferredSize(), QSizeF(width,height));
        QCOMPARE(subject->maximumSize(), QSizeF(200,200));
        subject->setPreferredWidth(200);
        if (cssName == "noCssSize" || cssName == "width50")
            QCOMPARE(subject->preferredSize(), QSizeF(200,200));
        else
            QCOMPARE(subject->preferredSize(), QSizeF(200,50));
        subject->setPreferredWidth(-1);
    }
}