void VConfirmDeletionDialog::currentFileChanged(int p_row) { bool succeed = false; if (p_row > -1 && m_enablePreview) { ConfirmItemWidget *widget = getItemWidget(m_listWidget->item(p_row)); if (widget) { int idx = widget->getIndex(); Q_ASSERT(idx < m_items.size()); QPixmap image(m_items[idx].m_path); if (!image.isNull()) { int width = 512 * VUtils::calculateScaleFactor(); QSize previewSize(width, width); if (image.width() > width || image.height() > width) { m_previewer->setPixmap(image.scaled(previewSize, Qt::KeepAspectRatio)); } else { m_previewer->setPixmap(image); } succeed = true; } } } m_previewer->setVisible(succeed); }
void PosteRazorCore::paintPaperOnCanvas(PaintCanvasInterface *paintCanvas, bool paintOverlapping) const { const QSizeF canvasSize = paintCanvas->size(); const QSizeF paperSize = this->paperSize(); const QSizeF boxSize = previewSize(paperSize, canvasSize.toSize(), true); const QPointF offset((canvasSize.width() - boxSize.width()) / 2.0, (canvasSize.height() - boxSize.height()) / 2.0); const qreal UnitOfLengthToPixelfactor = boxSize.width()/paperSize.width(); const qreal borderTop = paperBorderTop() * UnitOfLengthToPixelfactor; const qreal borderRight = paperBorderRight() * UnitOfLengthToPixelfactor; const qreal borderBottom = paperBorderBottom() * UnitOfLengthToPixelfactor; const qreal borderLeft = paperBorderLeft() * UnitOfLengthToPixelfactor; const QSizeF printableAreaSize(boxSize.width() - borderLeft - borderRight, boxSize.height() - borderTop - borderBottom); paintCanvas->drawFilledRect(QRectF(offset, boxSize), QColor(128, 128, 128)); paintCanvas->drawFilledRect(QRectF(QPointF(borderLeft, borderTop) + offset, printableAreaSize), QColor(230, 230, 230)); if (paintOverlapping) { const qreal overlappingWidth = this->overlappingWidth() * UnitOfLengthToPixelfactor; const qreal overlappingHeight = this->overlappingHeight() * UnitOfLengthToPixelfactor; const Qt::Alignment overlappingPosition = this->overlappingPosition(); const qreal overlappingTop = (overlappingPosition & Qt::AlignTop)? borderTop:boxSize.height() - borderBottom - overlappingHeight; const qreal overlappingLeft = (overlappingPosition & Qt::AlignLeft)? borderLeft:boxSize.width() - borderRight - overlappingWidth; const QColor overlappingBrush(255, 128, 128); paintCanvas->drawFilledRect(QRectF(QPointF(borderLeft, overlappingTop) + offset, QSizeF(printableAreaSize.width(), overlappingHeight)), overlappingBrush); paintCanvas->drawFilledRect(QRectF(QPointF(overlappingLeft, borderTop) + offset, QSizeF(overlappingWidth, printableAreaSize.height())), overlappingBrush); } }
void TabPreview::showOnRect(const QRect &r) { if (m_animation.state() == QTimeLine::Running) { m_animation.stop(); } m_startGeometry = geometry(); bool wasVisible = isVisible(); QRect finishingGeometry; resize(QSize(250, 170)); QFrame::show(); if (m_pixmapLabel->isVisible()) { m_title->setWordWrap(false); m_title->setText(m_title->fontMetrics().elidedText(m_title->text(), Qt::ElideRight, 240)); QSize previewSize(250, 170); finishingGeometry = QRect(calculatePosition(r, previewSize), previewSize); } else { m_title->setWordWrap(true); QSize previewSize = sizeHint(); previewSize.setWidth(qMin(previewSize.width() + 2 * 5, 240)); previewSize.setHeight(qMin(previewSize.height() + 2 * 5, 130)); finishingGeometry = QRect(calculatePosition(r, previewSize), previewSize); } #ifdef ENABLE_OPACITY_EFFECT if (!m_animationsEnabled) { m_opacityEffect.setOpacity(1.0); #else if (!m_animationsEnabled || !wasVisible) { #endif QFrame::setGeometry(finishingGeometry); return; } else { showAnimated(); } if (!wasVisible) { m_startGeometry = finishingGeometry; } QFrame::setGeometry(m_startGeometry); calculateSteps(m_startGeometry, finishingGeometry); m_animation.start(); } #ifdef ENABLE_OPACITY_EFFECT void TabPreview::setOpacity(int opacity) { m_opacityEffect.setOpacity(opacity / 100.0); }
virtual void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ) { Q_UNUSED( option ) Q_UNUSED( widget ) Renderer * r = Renderer::self(); int textAreaHeight = m_size.height() * textToBoxHeightRatio; int padding = boxPaddingRatio * m_size.width(); QSize previewSize( m_size.height() - padding * 2, m_size.height() - padding * 2 - textAreaHeight ); QRect textRect( 0, 0, m_size.width(), textAreaHeight ); if ( m_highlightFadeAmount < 1 ) painter->drawPixmap( 0, 0, r->spritePixmap( "bubble", m_size ) ); if ( m_highlightFadeAmount > 0 ) { if ( m_highlightFadeAmount < 1 ) { // Using QPainter::setOpacity is currently very inefficient, so to // paint a semitransparent pixmap, we have to do some fiddling. QPixmap transPix( m_size ); transPix.fill( Qt::transparent ); QPainter p( &transPix ); p.drawPixmap( 0, 0, r->spritePixmap( "bubble_hover", m_size ) ); p.setCompositionMode( QPainter::CompositionMode_DestinationIn ); p.fillRect( transPix.rect(), QColor( 0, 0, 0, m_highlightFadeAmount * 255 ) ); painter->drawPixmap( 0, 0, transPix ); } else { painter->drawPixmap( 0, 0, r->spritePixmap( "bubble_hover", m_size ) ); } } // Draw game preview if ( m_preview.isNull() ) { QPixmap previewPix( m_previewPath ); m_preview = previewPix.scaled( previewSize, Qt::KeepAspectRatio, Qt::SmoothTransformation ); } painter->drawPixmap( ( m_size.width() - previewSize.width() ) / 2, padding + textAreaHeight, m_preview ); // Draw label painter->setFont( scene()->font() ); painter->setPen( KColorUtils::mix( r->colorOfElement( "bubble_text_color" ), r->colorOfElement( "bubble_hover_text_color" ), m_highlightFadeAmount ) ); painter->drawText( textRect, Qt::AlignCenter, m_label ); }
void TabPreview::showOnRect(const QRect &r) { if (m_animation->state() == QPropertyAnimation::Running) { m_animation->stop(); } QRect oldGeometry = geometry(); bool wasVisible = isVisible(); resize(QSize(250, 170)); QFrame::show(); QRect finishingGeometry; if (m_pixmap->isVisible()) { m_title->setWordWrap(false); m_title->setText(m_title->fontMetrics().elidedText(m_title->text(), Qt::ElideRight, 240)); QSize previewSize(250, 170); finishingGeometry = QRect(calculatePosition(r, previewSize), previewSize); } else { m_title->setWordWrap(true); QSize previewSize = sizeHint(); previewSize.setWidth(qMin(previewSize.width() + 2 * 5, 240)); previewSize.setHeight(qMin(previewSize.height() + 2 * 5, 130)); finishingGeometry = QRect(calculatePosition(r, previewSize), previewSize); } if (!m_animationsEnabled) { m_opacityEffect->setOpacity(1.0); QFrame::setGeometry(finishingGeometry); return; } else { showAnimated(); } if (!wasVisible) { oldGeometry = finishingGeometry; } setFinishingGeometry(oldGeometry, finishingGeometry); m_animation->start(); }
void PosteRazorCore::paintImageOnCanvas(PaintCanvasInterface *paintCanvas) const { if (isImageLoaded()) { const QSizeF canvasSize = paintCanvas->size(); const QSize inputImageSize = inputImageSizePixels(); const QSizeF boxSize = previewSize(inputImageSize, canvasSize.toSize(), false); QPointF offset((canvasSize.width() - boxSize.width()) / 2, (canvasSize.height() - boxSize.height()) / 2); // If the image is not downscaled, make sure that the coordinates are integers in order // to prevent unneeded blurring if (canvasSize.width() >= inputImageSize.width() && canvasSize.height() >= inputImageSize.height()) { offset.setX(floor(offset.x())); offset.setY(floor(offset.y())); } paintCanvas->drawImage(QRectF(offset, boxSize)); } }
void KPrPresenterViewWidget::updateWidget( const QSize &widgetSize, const QSize &canvasSize ) { // a better way to resize the canvas, still need to find optimum value // try to make the height 40% of the widget height int previewHeight = 0.4 * canvasSize.height(); double ratio = (double)canvasSize.width() / canvasSize.height(); int previewWidth = ratio * previewHeight; // if it doesn't fit, make the width 40% of the widget width if ( previewWidth * 2 > 0.8 * widgetSize.width() ) { previewWidth = 0.4 * widgetSize.width(); previewHeight = previewWidth / ratio; } QSize previewSize( previewHeight * ratio, previewHeight ); m_mainWidget->setPreviewSize( previewSize ); }
void RGBMatrixEditor::initPreviewData() { m_previewTimer->stop(); m_previewData.clear(); QSize pSize = previewSize(); for (int i = 0; i < pSize.width() * pSize.height(); i++) m_previewData.append(QVariant(QColor(0, 0, 0, 0))); if (m_matrix == NULL) return; m_previewDirection = m_matrix->direction(); if (m_previewDirection == Function::Forward) { m_matrix->setStepColor(m_matrix->startColor()); } else { if (m_matrix->endColor().isValid()) m_matrix->setStepColor(m_matrix->endColor()); else m_matrix->setStepColor(m_matrix->startColor()); } m_matrix->calculateColorDelta(); if (m_previewDirection == Function::Forward) { m_previewStep = 0; } else { m_previewStep = m_matrix->stepsCount() - 1; } m_previewTimer->start(MasterTimer::tick()); }
void MainScreen::LoadResources() { Vector2 screenSize(GetScreenWidth(), GetScreenHeight()); cellH = GetScreenHeight() / 25; buttonW = GetScreenWidth() / 10; float32 infoAreaWidth = screenSize.x - 960.0f; Vector2 previewSize(screenSize.x - infoAreaWidth, screenSize.y - cellH); //Vector2 previewScale(previewSize.x/screenSize.x, previewSize.y/screenSize.y); preview = new PreviewControl(Rect(0.0f, cellH, previewSize.x, previewSize.y)); //preview->SetScaledRect(Rect(0.0f, cellH, previewSize.x*0.9f, previewSize.y*0.9f)); //preview->SetDebugDraw(true); AddControl(preview); FTFont* font = FTFont::Create("~res:/Fonts/MyriadPro-Regular.otf"); font->SetSize(20.0f); font->SetColor(0.8f, 0.8f, 0.8f, 1.0f); chooseProject = new UIButton(Rect(0.0f, 0.0f, buttonW, cellH)); chooseProject->SetStateDrawType(UIControl::STATE_NORMAL, UIControlBackground::DRAW_FILL); chooseProject->GetStateBackground(UIControl::STATE_NORMAL)->SetColor(Color(0.0f, 0.0f, 0.0f, 0.5f)); chooseProject->SetStateDrawType(UIControl::STATE_PRESSED_INSIDE, UIControlBackground::DRAW_FILL); chooseProject->GetStateBackground(UIControl::STATE_PRESSED_INSIDE)->SetColor(Color(0.5, 0.5, 0.5, 0.5)); chooseProject->SetStateFont(UIControl::STATE_NORMAL, font); chooseProject->SetStateText(UIControl::STATE_NORMAL, LocalizedString("Project")); chooseProject->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &MainScreen::OnButtonPressed)); AddControl(chooseProject); loadUI = new UIButton(Rect(2*buttonW, 0, buttonW, cellH)); loadUI->SetStateDrawType(UIControl::STATE_NORMAL, UIControlBackground::DRAW_FILL); loadUI->GetStateBackground(UIControl::STATE_NORMAL)->SetColor(Color(0.0f, 0.0f, 0.0f, 0.5f)); loadUI->SetStateDrawType(UIControl::STATE_PRESSED_INSIDE, UIControlBackground::DRAW_FILL); loadUI->GetStateBackground(UIControl::STATE_PRESSED_INSIDE)->SetColor(Color(0.5f, 0.5f, 0.5f, 0.5f)); loadUI->SetStateFont(UIControl::STATE_NORMAL, font); loadUI->SetStateText(UIControl::STATE_NORMAL, LocalizedString("Load")); loadUI->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &MainScreen::OnButtonPressed)); AddControl(loadUI); loadUI->SetVisible(false); saveUI = new UIButton(Rect(buttonW*3, 0, buttonW, cellH)); saveUI->SetStateDrawType(UIControl::STATE_NORMAL, UIControlBackground::DRAW_FILL); saveUI->GetStateBackground(UIControl::STATE_NORMAL)->SetColor(Color(0.0f, 0.0f, 0.0f, 0.5f)); saveUI->SetStateDrawType(UIControl::STATE_PRESSED_INSIDE, UIControlBackground::DRAW_FILL); saveUI->GetStateBackground(UIControl::STATE_PRESSED_INSIDE)->SetColor(Color(0.5f, 0.5f, 0.5f, 0.5f)); saveUI->SetStateFont(UIControl::STATE_NORMAL, font); saveUI->SetStateText(UIControl::STATE_NORMAL, LocalizedString("Save")); saveUI->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &MainScreen::OnButtonPressed)); //TODO: add saveUI when uiviewer becomes editor //AddControl(saveUI); selectHoverModeButton = new UIButton(Rect(buttonW*4, 0, 2*buttonW, cellH)); selectHoverModeButton->SetStateDrawType(UIControl::STATE_NORMAL, UIControlBackground::DRAW_FILL); selectHoverModeButton->GetStateBackground(UIControl::STATE_NORMAL)->SetColor(Color(0.0f, 0.0f, 0.0f, 0.5f)); selectHoverModeButton->SetStateFont(UIControl::STATE_NORMAL, font); selectHoverModeButton->SetStateText(UIControl::STATE_NORMAL, LocalizedString("selection.mode.click")); selectHoverModeButton->SetStateDrawType(UIControl::STATE_PRESSED_INSIDE, UIControlBackground::DRAW_FILL); selectHoverModeButton->GetStateBackground(UIControl::STATE_PRESSED_INSIDE)->SetColor(Color(0.5f, 0.5f, 0.5f, 0.5f)); selectHoverModeButton->SetStateDrawType(UIControl::STATE_SELECTED, UIControlBackground::DRAW_FILL); selectHoverModeButton->GetStateBackground(UIControl::STATE_SELECTED)->SetColor(Color(0.0f, 0.0f, 0.0f, 0.5f)); selectHoverModeButton->SetStateFont(UIControl::STATE_SELECTED, font); selectHoverModeButton->SetStateText(UIControl::STATE_SELECTED, LocalizedString("selection.mode.hover")); selectHoverModeButton->AddEvent(UIControl::EVENT_TOUCH_UP_INSIDE, Message(this, &MainScreen::OnButtonPressed)); AddControl(selectHoverModeButton); selectHoverModeButton->SetVisible(false); for (int32 i = 0; i < InfoControl::INFO_TYPES_COUNT; ++i) { keyTexts[i] = new UIStaticText(Rect(screenSize.x - infoAreaWidth, cellH*(2*i+1), infoAreaWidth, cellH)); keyTexts[i]->SetFont(font); keyTexts[i]->SetText(keyNames[i]); AddControl(keyTexts[i]); valueTexts[i] = new UIStaticText(Rect(screenSize.x - infoAreaWidth, cellH*(2*i+2), infoAreaWidth, cellH)); valueTexts[i]->SetFont(font); AddControl(valueTexts[i]); } additionalInfoList = new UIList(Rect(screenSize.x - infoAreaWidth, cellH*(2*InfoControl::INFO_TYPES_COUNT+2), infoAreaWidth, screenSize.y - cellH*(2*InfoControl::INFO_TYPES_COUNT+2) ), UIList::ORIENTATION_VERTICAL); additionalInfoList->SetDelegate(this); AddControl(additionalInfoList); fsDlg = new UIFileSystemDialog("~res:/Fonts/MyriadPro-Regular.otf"); fsDlg->SetDelegate(this); Vector<String> filter; filter.push_back(".yaml"); filter.push_back(".YAML"); fsDlg->SetExtensionFilter(filter); fsDlg->SetTitle(LocalizedString("Dlg.Load")); fsDlg->SetCurrentDir(FileSystem::Instance()->SystemPathForFrameworkPath("~res:/")); fsDlgProject = new UIFileSystemDialog("~res:/Fonts/MyriadPro-Regular.otf"); //default = GetCurrentWorkingDirectory fsDlgProject->SetDelegate(this); fsDlgProject->SetOperationType(UIFileSystemDialog::OPERATION_CHOOSE_DIR); fsDlgProject->SetTitle(LocalizedString("Dlg.ChoosePrj")); KeyedArchive* archive = new KeyedArchive(); if(archive->Load("~doc:/uiviewer.archive")) { if(archive->IsKeyExists("projectPath")) { projectPath = archive->GetString("projectPath"); //TODO: different path formats on different OS OnLoadProject(); fsDlgProject->SetCurrentDir(projectPath); } } SafeRelease(archive); SafeRelease(font); }
void PosteRazorCore::paintPosterOnCanvasOverlapped(PaintCanvasInterface *paintCanvas) const { const QSizeF canvasSize = paintCanvas->size(); QSizeF pagePrintableAreaSize = printablePaperAreaSize(); const QSizeF posterSizePages = posterSize(Types::PosterSizeModePages); const int pagesHorizontal = (int)ceil(posterSizePages.width()); const int pagesVertical = (int)ceil(posterSizePages.height()); const QSizeF posterSize( pagesHorizontal*pagePrintableAreaSize.width() - (pagesHorizontal-1)*overlappingWidth() + paperBorderLeft() + paperBorderRight(), pagesVertical*pagePrintableAreaSize.height() - (pagesVertical-1)*overlappingHeight() + paperBorderTop() + paperBorderBottom() ); const QSizeF boxSize = previewSize(posterSize, canvasSize.toSize(), true); const QPointF offset((canvasSize.width() - boxSize.width()) / 2, (canvasSize.height() - boxSize.height()) / 2); const qreal UnitOfLengthToPixelfactor = boxSize.width()/posterSize.width(); const qreal borderTop = paperBorderTop() * UnitOfLengthToPixelfactor; const qreal borderRight = paperBorderRight() * UnitOfLengthToPixelfactor; const qreal borderBottom = paperBorderBottom() * UnitOfLengthToPixelfactor; const qreal borderLeft = paperBorderLeft() * UnitOfLengthToPixelfactor; const QSizeF posterPrintableAreaSize(boxSize.width() - borderLeft - borderRight, boxSize.height() - borderTop - borderBottom); const QPointF posterPrintableAreaOrigin = QPointF(borderLeft, borderTop) + offset; const QRectF posterPrintableArea(posterPrintableAreaOrigin, posterPrintableAreaSize); paintCanvas->drawFilledRect(QRectF(offset, boxSize), QColor(128, 128, 128)); paintCanvas->drawFilledRect(posterPrintableArea, QColor(230, 230, 230)); const QSizeF posterSizeAbsolute = this->posterSize(Types::PosterSizeModeAbsolute); const QSizeF imageSize = posterSizeAbsolute * UnitOfLengthToPixelfactor; const Qt::Alignment alignment = posterAlignment(); paintCanvas->drawImage( QRectF( QPointF( ( alignment & Qt::AlignLeft?borderLeft :alignment & Qt::AlignHCenter?qBound(borderLeft, (boxSize.width() - imageSize.width()) / 2, borderLeft + posterPrintableAreaSize.width() - imageSize.width()) :(borderLeft + posterPrintableAreaSize.width() - imageSize.width()) ) + offset.x(), ( alignment & Qt::AlignTop?borderTop :alignment & Qt::AlignVCenter?qBound(borderTop, (boxSize.height() - imageSize.height()) / 2, borderTop + posterPrintableAreaSize.height() - imageSize.height()) :(borderTop + posterPrintableAreaSize.height() - imageSize.height()) ) + offset.y() ), imageSize ) ); const qreal overlappingHeight = this->overlappingHeight() * UnitOfLengthToPixelfactor; const qreal overlappingWidth = this->overlappingWidth() * UnitOfLengthToPixelfactor; pagePrintableAreaSize *= UnitOfLengthToPixelfactor; const QColor overlappingColor(255, 128, 128, 128); qreal overlappingRectangleYPosition = borderTop; for (int pagesRow = 0; pagesRow < pagesVertical - 1; pagesRow++) { overlappingRectangleYPosition += pagePrintableAreaSize.height() - overlappingHeight; paintCanvas->drawFilledRect(QRectF(QPointF(0, overlappingRectangleYPosition) + offset, QSizeF(boxSize.width(), overlappingHeight)), overlappingColor); } qreal overlappingRectangleXPosition = borderLeft; for (int pagesColumn = 0; pagesColumn < pagesHorizontal - 1; pagesColumn++) { overlappingRectangleXPosition += pagePrintableAreaSize.width() - overlappingWidth; paintCanvas->drawFilledRect(QRectF(QPointF(overlappingRectangleXPosition, 0) + offset, QSizeF(overlappingWidth, boxSize.height())), overlappingColor); } const int fontSize = int(qMin(pagePrintableAreaSize.width() / 2.5, pagePrintableAreaSize.height() / 1.5)); for (int pagesRow = 0; pagesRow < pagesVertical; ++pagesRow) { for (int pagesColumn = 0; pagesColumn < pagesHorizontal; ++pagesColumn) { const QPointF pagePrintableAreaOrigin = posterPrintableAreaOrigin + QPointF( pagesColumn * (pagePrintableAreaSize.width() - overlappingWidth), pagesRow * (pagePrintableAreaSize.height() - overlappingHeight) ); const QRectF pageNumberArea = QRectF(pagePrintableAreaOrigin, pagePrintableAreaSize).adjusted( pagesColumn == 0 ? 0 : overlappingWidth, pagesRow == 0 ? 0 : overlappingHeight, pagesColumn == pagesHorizontal - 1 ? 0 : -overlappingWidth, pagesRow == pagesVertical - 1 ? 0 : -overlappingHeight ); const int pageNumber = pagesRow * pagesHorizontal + pagesColumn + 1; paintCanvas->drawOverlayText(pageNumberArea.center(), Qt::AlignCenter, fontSize, QString::number(pageNumber)); } } }
QSizeF PosteRazorCore::inputImagePreviewSize(const QSize &boxSize) const { return previewSize(inputImageSizePixels(), boxSize, false); }