Esempio n. 1
0
void tst_QDockWidget::task169808_setFloating()
{
    //we try to test if the sizeHint of the dock widget widget is taken into account

    class MyWidget : public QWidget
    {
    public:
        QSize sizeHint() const
        {
            const QRect& deskRect = qApp->desktop()->availableGeometry();
            return QSize(qMin(300, deskRect.width() / 2), qMin(300, deskRect.height() / 2));
        }

        QSize minimumSizeHint() const
        {
            return QSize(20,20);
        }

        void paintEvent(QPaintEvent *)
        {
            QPainter p(this);
            p.fillRect(rect(), Qt::red);
        }
    };
    QMainWindow mw;
    mw.setCentralWidget(new MyWidget);
    QDockWidget *dw = new QDockWidget("my dock");
    dw->setWidget(new MyWidget);
    mw.addDockWidget(Qt::LeftDockWidgetArea, dw);
    dw->setFloating(true);
    mw.show();
    QVERIFY(QTest::qWaitForWindowExposed(&mw));

    QCOMPARE(dw->widget()->size(), dw->widget()->sizeHint());

    //and now we try to test if the contents margin is taken into account
    dw->widget()->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    dw->setFloating(false);
    QVERIFY(QTest::qWaitForWindowExposed(&mw));
    qApp->processEvents(); //leave time processing events


    const QSize oldSize = dw->size();
    const int margin = 20;

    dw->setContentsMargins(margin, margin, margin, margin);

    QVERIFY(QTest::qWaitForWindowExposed(&mw));
    qApp->processEvents(); //leave time processing events

    //widget size shouldn't have changed
    QCOMPARE(dw->widget()->size(), dw->widget()->sizeHint());
    //dockwidget should be bigger
    QCOMPARE(dw->size(), oldSize + QSize(margin * 2, margin * 2));


}
Esempio n. 2
0
void tst_QDockWidget::task248604_infiniteResize()
{
#if defined Q_OS_BLACKBERRY
    QSKIP("Top level window is stretched to fullscreen");
#endif
    QDockWidget d;
    QTabWidget *t = new QTabWidget;
    t->addTab(new QWidget, "Foo");
    d.setWidget(t);
    d.setContentsMargins(2, 2, 2, 2);
    d.setMinimumSize(320, 240);
    d.showNormal();
    QTest::qWait(400);
    QCOMPARE(d.size(), QSize(320, 240));
}
Esempio n. 3
0
WindowImpl::WindowImpl():
    m_ui(new Ui::WindowImpl)
{
    m_ui->setupUi(this);
    QApplication::setStyle(new QNotoStyle);

    QSettings sets(QSettings::IniFormat, QSettings::UserScope, "qnoto", "qnoto");
    restoreGeometry(sets.value("MainWindow/Geometry").toByteArray());

    QDockWidget *dockWidget = new QDockWidget("Left side", this);
    dockWidget->setContentsMargins(0, 0, 0, 0);
    dockWidget->setAllowedAreas(Qt::LeftDockWidgetArea);
    dockWidget->setFloating(false);
    dockWidget->setFeatures(dockWidget->features() ^ QDockWidget::DockWidgetClosable ^ QDockWidget::DockWidgetMovable ^ QDockWidget::DockWidgetFloatable);
    dockWidget->setTitleBarWidget(new QWidget);
    m_split = new SideSplit(this);
    dockWidget->setWidget(m_split);
    addDockWidget(Qt::LeftDockWidgetArea, dockWidget);

    m_editors = qnoto::plugin<qnoto::Editors>();
    connect(m_editors, &qnoto::Editors::updateEditMenu, this, &WindowImpl::updateEditMenu);

    setCentralWidget(m_editors);

    const auto& acts = m_editors->actions();
    for(const auto& it: acts){
        if (it->property("name").toString().startsWith("File_")){
            m_ui->menuFile->addAction(it);
        }
        if (it->property("name").toString().startsWith("Window_")){
            m_ui->menuWindow->addAction(it);
        }
    }

    connect(m_ui->actionPreferences, &QAction::triggered, this, &WindowImpl::showPreferences);

    m_split->restoreState(sets);
    m_editors->restoreState();
}