Exemple #1
0
void QgsColorButton::resizeEvent( QResizeEvent *event )
{
  QToolButton::resizeEvent( event );
  //recalculate icon size and redraw icon
  mIconSize = QSize();
  setButtonBackground();
}
Exemple #2
0
QgsColorButton::QgsColorButton( QWidget *parent, const QString &cdt, QgsColorSchemeRegistry *registry )
  : QToolButton( parent )
  , mColorDialogTitle( cdt.isEmpty() ? tr( "Select Color" ) : cdt )
  , mNoColorString( tr( "No color" ) )
{
  //if a color scheme registry was specified, use it, otherwise use the global instance
  mColorSchemeRegistry = registry ? registry : QgsApplication::colorSchemeRegistry();

  setAcceptDrops( true );
  setMinimumSize( QSize( 24, 16 ) );
  connect( this, &QAbstractButton::clicked, this, &QgsColorButton::buttonClicked );

  //setup drop-down menu
  mMenu = new QMenu( this );
  connect( mMenu, &QMenu::aboutToShow, this, &QgsColorButton::prepareMenu );
  setMenu( mMenu );
  setPopupMode( QToolButton::MenuButtonPopup );

#ifdef Q_OS_WIN
  mMinimumSize = QSize( 120, 22 );
#else
  mMinimumSize = QSize( 120, 28 );
#endif

  mMinimumSize.setHeight( std::max( static_cast<int>( Qgis::UI_SCALE_FACTOR * fontMetrics().height() * 1.1 ), mMinimumSize.height() ) );

  // If project colors change, we need to redraw the button, as it may be set to follow a project color
  connect( QgsProject::instance(), &QgsProject::projectColorsChanged, this, [ = ]
  {
    setButtonBackground();
  } );

}
Exemple #3
0
void QgsColorButton::mouseMoveEvent( QMouseEvent *e )
{
  if ( mPickingColor )
  {
    setButtonBackground( sampleColor( e->globalPos() ) );
    e->accept();
    return;
  }

  //handle dragging colors from button
  QColor c = linkedProjectColor();
  if ( !c.isValid() )
    c = mColor;

  if ( !( e->buttons() & Qt::LeftButton ) || !c.isValid() )
  {
    //left button not depressed or no color set, so not a drag
    QToolButton::mouseMoveEvent( e );
    return;
  }

  if ( ( e->pos() - mDragStartPosition ).manhattanLength() < QApplication::startDragDistance() )
  {
    //mouse not moved, so not a drag
    QToolButton::mouseMoveEvent( e );
    return;
  }

  //user is dragging color
  QDrag *drag = new QDrag( this );
  drag->setMimeData( QgsSymbolLayerUtils::colorToMimeData( c ) );
  drag->setPixmap( QgsColorWidget::createDragIcon( c ) );
  drag->exec( Qt::CopyAction );
  setDown( false );
}
Exemple #4
0
void QgsColorButton::changeEvent( QEvent *e )
{
  if ( e->type() == QEvent::EnabledChange )
  {
    setButtonBackground();
  }
  QToolButton::changeEvent( e );
}
Exemple #5
0
void QgsColorRampButton::setShowMenu( const bool showMenu )
{
  setMenu( showMenu ? mMenu : nullptr );
  setPopupMode( showMenu ? QToolButton::MenuButtonPopup : QToolButton::DelayedPopup );
  //force recalculation of icon size
  mIconSize = QSize();
  setButtonBackground( mColorRamp );
}
Exemple #6
0
void QgsColorButton::paintEvent( QPaintEvent *e )
{
  QToolButton::paintEvent( e );

  if ( !mBackgroundSet )
  {
    setButtonBackground();
  }
}
Exemple #7
0
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 );
  }
}
Exemple #8
0
void QgsColorRampButton::setColorRamp( QgsColorRamp *colorramp )
{
  QgsColorRamp *oldColorRamp = mColorRamp;
  mColorRamp = colorramp->clone();

  // handle when initially set color is same as default (Qt::black); consider it a color change
  if ( ( oldColorRamp != mColorRamp ) || !mColorRampSet )
  {
    setButtonBackground();
    if ( isEnabled() )
    {
      emit colorRampChanged();
    }
  }
  delete oldColorRamp;
  mColorRampSet = true;
}
Exemple #9
0
void QgsColorButton::setColor( const QColor &color )
{
  QColor oldColor = mColor;
  mColor = color;

  // handle when initially set color is same as default (Qt::black); consider it a color change
  if ( oldColor != mColor || ( mColor == QColor( Qt::black ) && !mColorSet ) )
  {
    setButtonBackground();
    if ( isEnabled() )
    {
      // TODO: May be beneficial to have the option to set color without emitting this signal.
      //       Now done by blockSignals( bool ) where button is used
      emit colorChanged( mColor );
    }
  }
  mColorSet = true;
}
Exemple #10
0
void QgsColorButton::stopPicking( QPoint eventPos, bool samplingColor )
{
  //release mouse and keyboard, and reset cursor
  releaseMouse();
  releaseKeyboard();
  QgsApplication::restoreOverrideCursor();
  setMouseTracking( false );
  mPickingColor = false;

  if ( !samplingColor )
  {
    //not sampling color, restore old color
    setButtonBackground();
    return;
  }

  setColor( sampleColor( eventPos ) );
  addRecentColor( mColor );
}
Exemple #11
0
void BtStyle::setCurrentStyle(int style) {
    if (style == BtStyle::darkTheme) {

        currentStyle = style;

        BtModuleTextModel::setLinkColor(QColor(0,191,255));
        BtModuleTextModel::setHighlightColor(QColor(255,255,0));
        BtModuleTextModel::setJesusWordsColor(QColor(255,0,0));

        setTextColor(QColor(255,255,255));
        setLinkColor(QColor(0,0,80));
        setTextBackgroundColor(QColor(0,0,0));
        setTextBackgroundHighlightColor(QColor(184,135,11));

        setButtonColor(QColor(0,0,0));
        setButtonBackground(QColor(35,35,100));
        setButtonTextColor(QColor(255,210,0));
        setButtonHighlightedText(QColor(255,255,0));
        setButtonBorder(QColor(110,110,110));
        setButtonRadius(3);
        setButtonGradient0(QColor(125,125,125));
        setButtonGradient1(QColor(60,60,60));
        setButtonGradient2(QColor(50,50,50));
        setButtonGradient3(QColor(20,20,20));

        setWindowTab(QColor(100,100,100));
        setWindowTabSelected(QColor(218,165,3));
        setWindowTabText(QColor(255,255,255));
        setWindowTabTextSelected(QColor(0,0,0));

        setMenu(QColor(255,255,255));
        setMenuBorder(QColor(60,60,60));
        setMenuText(QColor(0,0,0));
        setMenuHeight(34);

        setToolbarColor(QColor(0,0,0));
        setToolbarTextColor(QColor(218,165,3));
        setToolbarButtonText(QColor(255,255,255));
        setToolbarTextPointSize(10);
    }
    else if (style == BtStyle::lightBlueTheme) {

        currentStyle = style;

        BtModuleTextModel::setLinkColor(QColor(0,0,255));
        BtModuleTextModel::setHighlightColor(QColor(0,0,255));
        BtModuleTextModel::setJesusWordsColor(QColor(255,0,0));

        setTextColor(QColor(0,0,0));
        setLinkColor(QColor(0,0,220));
        setTextBackgroundColor(QColor(255,255,255));
        setTextBackgroundHighlightColor(QColor(255,240,170));

        setButtonColor(QColor(0,0,0));
        setButtonBackground(QColor(190,220,255));
        setButtonTextColor(QColor(0,0,0));
        setButtonHighlightedText(QColor(0,0,255));
        setButtonBorder(QColor(80,80,0));
        setButtonRadius(3);
        setButtonGradient0(QColor(180,180,255));
        setButtonGradient1(QColor(255,255,255));
        setButtonGradient2(QColor(255,255,255));
        setButtonGradient3(QColor(180,180,255));

        setWindowTab(QColor(245,245,245));
        setWindowTabSelected(QColor(65,105,225));
        setWindowTabText(QColor(100,100,100));
        setWindowTabTextSelected(QColor(255,255,255));

        setMenu(QColor(255,255,255));
        setMenuBorder(QColor(220,220,220));
        setMenuText(QColor(0,0,0));
        setMenuHeight(40);

        setToolbarColor(QColor(190,220,255));
        setToolbarTextColor(QColor(0,0,0));
        setToolbarButtonText(QColor(0,0,0));
        setToolbarTextPointSize(10);
    }
    else if (style == BtStyle::crimsonTheme) {

        currentStyle = style;

        BtModuleTextModel::setLinkColor(QColor(0,0,255));
        BtModuleTextModel::setHighlightColor(QColor(0,0,255));
        BtModuleTextModel::setJesusWordsColor(QColor(170,0,0));

        setTextColor(QColor(0,0,0));
        setLinkColor(QColor(0,0,220));
        setTextBackgroundColor(QColor(255,255,255));
        setTextBackgroundHighlightColor(QColor(255,240,170));

        setButtonColor(QColor(0,0,0));
        setButtonBackground(QColor(190,220,255));
        setButtonTextColor(QColor(0,0,0));
        setButtonHighlightedText(QColor(0,0,255));
        setButtonBorder(QColor(80,80,0));
        setButtonRadius(3);
        setButtonGradient0(QColor(180,180,255));
        setButtonGradient1(QColor(255,255,255));
        setButtonGradient2(QColor(255,255,255));
        setButtonGradient3(QColor(180,180,255));

        setWindowTab(QColor(245,245,245));
        setWindowTabSelected(QColor(218,165,3));
        setWindowTabText(QColor(100,100,100));
        setWindowTabTextSelected(QColor(0,0,0));

        setMenu(QColor(255,255,255));
        setMenuBorder(QColor(220,220,220));
        setMenuText(QColor(0,0,0));
        setMenuHeight(40);

        setToolbarColor(QColor(99,0,0));
        setToolbarTextColor(QColor(255,255,255));
        setToolbarButtonText(QColor(0,0,0));
        setToolbarTextPointSize(10);
    }
}
Exemple #12
0
void QgsColorButton::linkToProjectColor( const QString &name )
{
  mLinkedColorName = name;
  setButtonBackground();
}
Exemple #13
0
void QgsColorButton::showEvent( QShowEvent *e )
{
  setButtonBackground();
  QToolButton::showEvent( e );
}
Exemple #14
0
void QgsColorButton::dragLeaveEvent( QDragLeaveEvent *e )
{
  Q_UNUSED( e );
  //reset button color
  setButtonBackground();
}
Exemple #15
0
void QgsColorRampButton::invertColorRamp()
{
  mColorRamp->invert();
  setButtonBackground();
  emit colorRampChanged();
}