void ColorWheelView::onCreationCompleted() { colorPickerView = (ColorPickerView*) parent(); selectorImageView = findChild<ImageView*>("selectorImageView"); wheelImageView = findChild<ImageView*>("wheelImageView"); fillSelectorCircle(); fillColorWheel(); srand(time(0)); float radius = 0.50 * wheelImageView->preferredWidth(); float distance = rand() % (int) radius; float radian = (rand() % 360) * (180 / M_PI); int randX = radius + round(distance * cos(radian)); int randY = radius + round(distance * sin(radian)); AbsoluteLayoutProperties* wheelLayout = dynamic_cast<AbsoluteLayoutProperties*>(wheelImageView->layoutProperties()); randX += wheelLayout->positionX(); randY += wheelLayout->positionY(); selectColor(randX, randY); }
void ColorWheelView::selectColor(float x, float y) { AbsoluteLayoutProperties* selectorLayout = dynamic_cast<AbsoluteLayoutProperties*>(selectorImageView->layoutProperties()); selectorLayout->setPositionX(x - (0.50 * selectorImageView->preferredWidth())); selectorLayout->setPositionY(y - (0.50 * selectorImageView->preferredHeight())); AbsoluteLayoutProperties* wheelLayout = dynamic_cast<AbsoluteLayoutProperties*>(wheelImageView->layoutProperties()); float radius = 0.50 * wheelImageView->preferredWidth(); float centerX = wheelLayout->positionX() + radius; float centerY = wheelLayout->positionY() + radius; int _x = x - centerX; int _y = y - centerY; float angle = atan2(_y, _x) * (180 / M_PI); angle = (int) (angle + 360) % 360; float s = distance(x, y, centerX, centerY) / radius; colorPickerView->setColor(angle, s); }
void Map::parentHeightChanged(float parentHeight) { const float padding = 10; // Padding of at least 10 on all sides. parentHeight = parentHeight - padding*2; const float cellWidth = m_mapWidth / m_cols; const float cellHeight = parentHeight / m_rows; float oldCellSize = m_cellSize; m_cellSize = std::min(cellWidth, cellHeight); m_mapArea->setPreferredSize(m_cellSize * m_cols, m_cellSize * m_rows); QObjectList list = m_mapArea->children(); if (m_rows * m_cols + 1 != list.count()) { qDebug("Uhoh: List size not correct!"); } int i=0; for (int y=0; y<m_rows; y++) { for (int x=0; x<m_cols; x++) { ImageView *cell = qobject_cast<ImageView*>(list[i]); if (cell) { cell->setPreferredSize(m_cellSize, m_cellSize); AbsoluteLayoutProperties *properties = static_cast<AbsoluteLayoutProperties*>(cell->layoutProperties()); properties->setPositionX(x * m_cellSize); properties->setPositionY(y * m_cellSize); } i++; } } Container *robot = qobject_cast<Container*>(list[i]); if (robot) { robot->setPreferredSize(m_cellSize, m_cellSize); AbsoluteLayoutProperties *properties = static_cast<AbsoluteLayoutProperties*>(robot->layoutProperties()); properties->setPositionX(properties->positionX() * m_cellSize / oldCellSize); properties->setPositionY(properties->positionY() * m_cellSize / oldCellSize); } }
void HelloForeignWindowApp::initForeignWindow() { // Get the foreign window Control specified in QML and attach to the window attached signal. ForeignWindow *foreignWindow = mAppPage->findChild<ForeignWindow*>("myForeignWindow"); AbsoluteLayoutProperties *layoutProperties = dynamic_cast<AbsoluteLayoutProperties*>(foreignWindow->layoutProperties()); // Set up the foreign window at the position specified by its LayoutProperties and the dimensions // given by its preferred width and height. if(createForeignWindow(ForeignWindow::mainWindowGroupId(), "HelloForeignWindowAppID", (int) layoutProperties->positionX(), (int) layoutProperties->positionY(), (int) foreignWindow->preferredWidth(), (int) foreignWindow->preferredHeight()) == false) { qWarning() << "The ForeignWindow was not properly initialized"; } // Initialization of the window has been performed. mTvInitialized = true; }
void ColorWheelView::onTouch(bb::cascades::TouchEvent* touchEvent) { float x = touchEvent->localX(); float y = touchEvent->localY(); AbsoluteLayoutProperties* wheelLayout = dynamic_cast<AbsoluteLayoutProperties*>(wheelImageView->layoutProperties()); int radius = 0.50 * wheelImageView->preferredWidth(); float centerX = wheelLayout->positionX() + radius; float centerY = wheelLayout->positionY() + radius; if (distance(x, y, centerX, centerY) > radius) { return; } selectColor(x, y); }
void HelloForeignWindowApp::initForeignWindow() { // Get the foreign window Control specified in the QML document and attach to the window-attached signal. ForeignWindowControl *foreignWindow = mAppPage->findChild<ForeignWindowControl*>( "myForeignWindow"); AbsoluteLayoutProperties *layoutProperties = dynamic_cast<AbsoluteLayoutProperties*>(foreignWindow->layoutProperties()); // Set up the foreign window at the position specified by its LayoutProperties and the dimensions // given by its preferred width and height. if (createForeignWindow(Application::instance()->mainWindow()->groupId(), "HelloForeignWindowAppID", (int) layoutProperties->positionX(), (int) layoutProperties->positionY(), (int) foreignWindow->preferredWidth(), (int) foreignWindow->preferredHeight())) { // At this point, initialization of the window has been performed, so set the flag to true. mTvInitialized = true; } else { qDebug() << "The ForeginWindow was not properly initialized"; } }