/* Test that vertical and horizontal mac-style scrollbars paint their entire area. */ void tst_MacGui::scrollbarPainting() { ColorWidget colorWidget; colorWidget.resize(400, 400); QSize scrollBarSize; QScrollBar verticalScrollbar(&colorWidget); verticalScrollbar.move(10, 10); scrollBarSize = verticalScrollbar.sizeHint(); scrollBarSize.setHeight(200); verticalScrollbar.resize(scrollBarSize); QScrollBar horizontalScrollbar(&colorWidget); horizontalScrollbar.move(30, 10); horizontalScrollbar.setOrientation(Qt::Horizontal); scrollBarSize = horizontalScrollbar.sizeHint(); scrollBarSize.setWidth(200); horizontalScrollbar.resize(scrollBarSize); colorWidget.show(); colorWidget.raise(); QTest::qWait(100); QPixmap pixmap = grabWindowContents(&colorWidget); QVERIFY(isContent(pixmap.toImage(), verticalScrollbar.geometry(), GuiTester::Horizontal)); QVERIFY(isContent(pixmap.toImage(), horizontalScrollbar.geometry(), GuiTester::Vertical)); }
/* Test that the QSpinBox buttons are correctly positioned with the Mac style. */ void tst_MacGui::spinBoxArrowButtons() { ColorWidget colorWidget; colorWidget.resize(200, 200); QSpinBox spinBox(&colorWidget); QSpinBox spinBox2(&colorWidget); spinBox2.move(0, 100); colorWidget.show(); QTest::qWait(100); // Grab an unfocused spin box. const QImage noFocus = grabWindowContents(&colorWidget).toImage(); // Set focus by clicking the less button. InterfaceChildPair lessInterface = wn.find(QAccessible::Name, "Less", &spinBox); QVERIFY(lessInterface.iface); const int delay = 500; clickLater(lessInterface, Qt::LeftButton, delay); const int timeout = 1; QTestEventLoop::instance().enterLoop(timeout); // Grab a focused spin box. const QImage focus = grabWindowContents(&colorWidget).toImage(); // Compare the arrow area of the less button to see if it moved. const QRect lessRect = lessInterface.iface->rect(lessInterface.possibleChild); const QRect lessLocalRect(colorWidget.mapFromGlobal(lessRect.topLeft()), colorWidget.mapFromGlobal(lessRect.bottomRight())); const QRect compareRect = lessLocalRect.adjusted(5, 3, -5, -7); QVERIFY(noFocus.copy(compareRect) == focus.copy(compareRect)); }
/* Test that vertical and horizontal mac-style scrollbars paint their entire area. */ void tst_MacGui::scrollbarPainting() { ColorWidget colorWidget; colorWidget.resize(400, 400); QSize scrollBarSize; QScrollBar verticalScrollbar(&colorWidget); verticalScrollbar.move(10, 10); scrollBarSize = verticalScrollbar.sizeHint(); scrollBarSize.setHeight(200); verticalScrollbar.resize(scrollBarSize); QScrollBar horizontalScrollbar(&colorWidget); horizontalScrollbar.move(30, 10); horizontalScrollbar.setOrientation(Qt::Horizontal); scrollBarSize = horizontalScrollbar.sizeHint(); scrollBarSize.setWidth(200); horizontalScrollbar.resize(scrollBarSize); colorWidget.show(); colorWidget.raise(); QTest::qWait(100); QImage image = grabWindowContents(&colorWidget).toImage(); QVERIFY(isContent(image, verticalScrollbar.geometry(), GuiTester::Horizontal)); #ifdef Q_OS_MAC // this test seems to be unstable on OS X 10.6 (Snow Leopard) if (!isContent(image, horizontalScrollbar.geometry(), GuiTester::Vertical)) { QEXPECT_FAIL("", "QTBUG-20984", Abort); } #endif QVERIFY(isContent(image, horizontalScrollbar.geometry(), GuiTester::Vertical)); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); ColorWidget w; w.show(); return a.exec(); }
// GRID PAGE // GridPage::GridPage(QWidget* parent, QSettings* appSettings) : QWidget(parent), m_pAppSettings(appSettings) { QLabel* gridColor = new QLabel("Grid Color", this); ColorWidget* gridColorSelect = new ColorWidget(this); QLabel* gridSize = new QLabel("Grid Size", this); QSpinBox* sizeSpinBox = new QSpinBox; sizeSpinBox->setRange(0, 200); sizeSpinBox->setSingleStep(1); sizeSpinBox->setValue(16); QLabel* gridCellSize = new QLabel("Grid Cell Size", this); QSpinBox* cellSizeSpinBox = new QSpinBox; cellSizeSpinBox->setRange(1, 200); cellSizeSpinBox->setSingleStep(1); cellSizeSpinBox->setValue(1); QGroupBox* gridGroup = new QGroupBox(); QGridLayout* gridLayout = new QGridLayout; gridLayout->addWidget(gridColor, 0, 0); gridLayout->addWidget(gridColorSelect, 0, 1); gridLayout->addWidget(gridSize, 1, 0); gridLayout->addWidget(sizeSpinBox, 1, 1); gridLayout->addWidget(gridCellSize, 2, 0); gridLayout->addWidget(cellSizeSpinBox, 2, 1); gridGroup->setLayout(gridLayout); QVBoxLayout* mainLayout = new QVBoxLayout; mainLayout->addWidget(gridGroup); mainLayout->addStretch(1); setLayout(mainLayout); // Populate the settings gridColorSelect->setColor(m_pAppSettings->value("GLModelWidget/gridColor", QColor(0,0,0)).value<QColor>()); sizeSpinBox->setValue(m_pAppSettings->value("GLModelWidget/gridSize", 16).toInt()); cellSizeSpinBox->setValue(m_pAppSettings->value("GLModelWidget/gridCellSize", 1).toInt()); // Backup original values m_gridColorOrig = gridColorSelect->color(); m_gridSizeOrig = sizeSpinBox->value(); m_gridCellSizeOrig = cellSizeSpinBox->value(); // Hook up the signals QObject::connect(gridColorSelect, SIGNAL(colorChanged(QColor)), this, SLOT(setGridColor(QColor))); QObject::connect(sizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setGridSize(int))); QObject::connect(cellSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setgridCellSize(int))); }
// MODELVIEW PAGE // ModelViewPage::ModelViewPage(QWidget* parent, QSettings* appSettings) : QWidget(parent), m_pAppSettings(appSettings) { QLabel* backgroundColor = new QLabel("Window Background Color", this); ColorWidget* bgColorSelect = new ColorWidget(this); QCheckBox* dragEnabled = new QCheckBox("Tool Dragging Enabled", this); QCheckBox* previewEnabled = new QCheckBox("Tool Preview Enabled", this); QGroupBox* modelViewGroup = new QGroupBox(); QGridLayout* gridLayout = new QGridLayout; gridLayout->addWidget(backgroundColor, 0, 0); gridLayout->addWidget(bgColorSelect, 0, 1); gridLayout->addWidget(dragEnabled, 2, 0); gridLayout->addWidget(previewEnabled, 3, 0); modelViewGroup->setLayout(gridLayout); QVBoxLayout* mainLayout = new QVBoxLayout; mainLayout->addWidget(modelViewGroup); mainLayout->addStretch(1); setLayout(mainLayout); // Populate the settings bgColorSelect->setColor(m_pAppSettings->value("GLModelWidget/backgroundColor", QColor(161,161,161)).value<QColor>()); if (m_pAppSettings->value("GLModelWidget/dragEnabled", true).toBool()) dragEnabled->setCheckState(Qt::Checked); else dragEnabled->setCheckState(Qt::Unchecked); if (m_pAppSettings->value("GLModelWidget/previewEnabled", true).toBool()) previewEnabled->setCheckState(Qt::Checked); else previewEnabled->setCheckState(Qt::Unchecked); // Backup original values m_backgroundColorOrig = bgColorSelect->color(); m_dragEnabledOrig = dragEnabled->isChecked(); m_previewEnabledOrig = previewEnabled->isChecked(); // Hook up the signals QObject::connect(bgColorSelect, SIGNAL(colorChanged(QColor)), this, SLOT(setBackgroundColor(QColor))); QObject::connect(dragEnabled, SIGNAL(stateChanged(int)), this, SLOT(setDragEnabled(int))); QObject::connect(previewEnabled, SIGNAL(stateChanged(int)), this, SLOT(setPreviewEnabled(int))); }