void QgsFontButton::dragEnterEvent( QDragEnterEvent *e ) { //is dragged data valid font data? QColor mimeColor; QgsTextFormat format; QFont font; bool hasAlpha = false; if ( mMode == ModeTextRenderer && formatFromMimeData( e->mimeData(), format ) ) { e->acceptProposedAction(); updatePreview( QColor(), &format ); } else if ( mMode == ModeQFont && fontFromMimeData( e->mimeData(), font ) ) { e->acceptProposedAction(); updatePreview( QColor(), nullptr, &font ); } else if ( mMode == ModeTextRenderer && colorFromMimeData( e->mimeData(), mimeColor, hasAlpha ) ) { //if so, we accept the drag, and temporarily change the button's color //to match the dragged color. This gives immediate feedback to the user //that colors can be dropped here e->acceptProposedAction(); updatePreview( mimeColor ); } }
void QgsColorButton::pasteColor() { QColor clipColor; if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor ) ) { //paste color setColor( clipColor ); addRecentColor( clipColor ); } }
void QgsColorButton::dropEvent( QDropEvent *e ) { const bool isProjectColor = linkedProjectColor().isValid(); if ( isProjectColor ) return; //is dropped data valid color data? QColor mimeColor; if ( colorFromMimeData( e->mimeData(), mimeColor ) ) { //accept drop and set new color e->acceptProposedAction(); setColor( mimeColor ); addRecentColor( mimeColor ); } }
void QgsColorButton::dragEnterEvent( QDragEnterEvent *e ) { const bool isProjectColor = linkedProjectColor().isValid(); if ( isProjectColor ) return; //is dragged data valid color data? QColor mimeColor; if ( colorFromMimeData( e->mimeData(), mimeColor ) ) { //if so, we accept the drag, and temporarily change the button's color //to match the dragged color. This gives immediate feedback to the user //that colors can be dropped here e->acceptProposedAction(); setButtonBackground( mimeColor ); } }
void QgsFontButton::dropEvent( QDropEvent *e ) { //is dropped data valid format data? QColor mimeColor; QgsTextFormat format; QFont font; bool hasAlpha = false; if ( mMode == ModeTextRenderer && formatFromMimeData( e->mimeData(), format ) ) { setTextFormat( format ); QgsFontUtils::addRecentFontFamily( mFormat.font().family() ); return; } else if ( mMode == ModeQFont && fontFromMimeData( e->mimeData(), font ) ) { QgsFontUtils::addRecentFontFamily( font.family() ); setCurrentFont( font ); return; } else if ( mMode == ModeTextRenderer && colorFromMimeData( e->mimeData(), mimeColor, hasAlpha ) ) { //accept drop and set new color e->acceptProposedAction(); if ( hasAlpha ) { mFormat.setOpacity( mimeColor.alphaF() ); } mimeColor.setAlphaF( 1.0 ); mFormat.setColor( mimeColor ); QgsRecentColorScheme::addRecentColor( mimeColor ); updatePreview(); emit changed(); } updatePreview(); }
void QgsColorButton::prepareMenu() { //we need to tear down and rebuild this menu every time it is shown. Otherwise the space allocated to any //QgsColorSwatchGridAction is not recalculated by Qt and the swatch grid may not be the correct size //for the number of colors shown in the grid. Note that we MUST refresh color swatch grids every time this //menu is opened, otherwise color schemes like the recent color scheme grid are meaningless mMenu->clear(); const bool isProjectColor = linkedProjectColor().isValid(); if ( !isProjectColor ) { if ( mShowNull ) { QAction *nullAction = new QAction( tr( "Clear Color" ), this ); nullAction->setIcon( createMenuIcon( Qt::transparent, false ) ); mMenu->addAction( nullAction ); connect( nullAction, &QAction::triggered, this, &QgsColorButton::setToNull ); } //show default color option if set if ( mDefaultColor.isValid() ) { QAction *defaultColorAction = new QAction( tr( "Default Color" ), this ); defaultColorAction->setIcon( createMenuIcon( mDefaultColor ) ); mMenu->addAction( defaultColorAction ); connect( defaultColorAction, &QAction::triggered, this, &QgsColorButton::setToDefaultColor ); } if ( mShowNoColorOption && mAllowOpacity ) { QAction *noColorAction = new QAction( mNoColorString, this ); noColorAction->setIcon( createMenuIcon( Qt::transparent, false ) ); mMenu->addAction( noColorAction ); connect( noColorAction, &QAction::triggered, this, &QgsColorButton::setToNoColor ); } mMenu->addSeparator(); QgsColorWheel *colorWheel = new QgsColorWheel( mMenu ); colorWheel->setColor( color() ); QgsColorWidgetAction *colorAction = new QgsColorWidgetAction( colorWheel, mMenu, mMenu ); colorAction->setDismissOnColorSelection( false ); connect( colorAction, &QgsColorWidgetAction::colorChanged, this, &QgsColorButton::setColor ); mMenu->addAction( colorAction ); if ( mAllowOpacity ) { QgsColorRampWidget *alphaRamp = new QgsColorRampWidget( mMenu, QgsColorWidget::Alpha, QgsColorRampWidget::Horizontal ); alphaRamp->setColor( color() ); QgsColorWidgetAction *alphaAction = new QgsColorWidgetAction( alphaRamp, mMenu, mMenu ); alphaAction->setDismissOnColorSelection( false ); connect( alphaAction, &QgsColorWidgetAction::colorChanged, this, &QgsColorButton::setColor ); connect( alphaAction, &QgsColorWidgetAction::colorChanged, colorWheel, [colorWheel]( const QColor & color ) { colorWheel->setColor( color, false ); } ); connect( colorAction, &QgsColorWidgetAction::colorChanged, alphaRamp, [alphaRamp]( const QColor & color ) { alphaRamp->setColor( color, false ); } ); mMenu->addAction( alphaAction ); } if ( mColorSchemeRegistry ) { //get schemes with ShowInColorButtonMenu flag set QList< QgsColorScheme * > schemeList = mColorSchemeRegistry->schemes( QgsColorScheme::ShowInColorButtonMenu ); QList< QgsColorScheme * >::iterator it = schemeList.begin(); for ( ; it != schemeList.end(); ++it ) { QgsColorSwatchGridAction *colorAction = new QgsColorSwatchGridAction( *it, mMenu, mContext, this ); colorAction->setBaseColor( mColor ); mMenu->addAction( colorAction ); connect( colorAction, &QgsColorSwatchGridAction::colorChanged, this, &QgsColorButton::setValidColor ); connect( colorAction, &QgsColorSwatchGridAction::colorChanged, this, &QgsColorButton::addRecentColor ); } } mMenu->addSeparator(); } if ( isProjectColor ) { QAction *unlinkAction = new QAction( tr( "Unlink Color" ), mMenu ); mMenu->addAction( unlinkAction ); connect( unlinkAction, &QAction::triggered, this, &QgsColorButton::unlink ); } QAction *copyColorAction = new QAction( tr( "Copy Color" ), this ); mMenu->addAction( copyColorAction ); connect( copyColorAction, &QAction::triggered, this, &QgsColorButton::copyColor ); if ( !isProjectColor ) { QAction *pasteColorAction = new QAction( tr( "Paste Color" ), this ); //enable or disable paste action based on current clipboard contents. We always show the paste //action, even if it's disabled, to give hint to the user that pasting colors is possible QColor clipColor; if ( colorFromMimeData( QApplication::clipboard()->mimeData(), clipColor ) ) { pasteColorAction->setIcon( createMenuIcon( clipColor ) ); } else { pasteColorAction->setEnabled( false ); } mMenu->addAction( pasteColorAction ); connect( pasteColorAction, &QAction::triggered, this, &QgsColorButton::pasteColor ); QAction *pickColorAction = new QAction( tr( "Pick Color" ), this ); mMenu->addAction( pickColorAction ); connect( pickColorAction, &QAction::triggered, this, &QgsColorButton::activatePicker ); QAction *chooseColorAction = new QAction( tr( "Choose Color…" ), this ); mMenu->addAction( chooseColorAction ); connect( chooseColorAction, &QAction::triggered, this, &QgsColorButton::showColorDialog ); } }