22 #include <QColorDialog>    27 #ifdef ENABLE_MODELTEST    28 #include "modeltest.h"    36 #ifdef ENABLE_MODELTEST    37   new ModelTest( mModel, 
this );
    62   mModel->
setScheme( scheme, context, baseColor );
    87   qSort( rowsToRemove.
begin(), rowsToRemove.
end(), qGreater<int>() );
    88   Q_FOREACH ( 
int row, rowsToRemove )
   103   if ( pastedColors.
length() == 0 )
   111   for ( ; colorIt != pastedColors.
constEnd(); ++colorIt )
   128   Q_FOREACH ( 
int row, rowsToCopy )
   130     colorsToCopy << mModel->
colors().
at( row );
   141   if (( event->
key() == Qt::Key_Backspace || 
event->key() == Qt::Key_Delete ) )
   152     qSort( rowsToRemove.
begin(), rowsToRemove.
end(), qGreater<int>() );
   153     Q_FOREACH ( 
int row, rowsToRemove )
   165   if ( event->
button() == Qt::LeftButton )
   168     mDragStartPosition = 
event->pos();
   175   if (( event->
button() == Qt::LeftButton ) &&
   203   if ( importedColors.
length() == 0 )
   211   for ( ; colorIt != importedColors.
constEnd(); ++colorIt )
   246     , mContext( context )
   247     , mBaseColor( baseColor )
   252     mColors = scheme->
fetchColors( context, baseColor );
   269   if ( !parent.
isValid() && row >= 0 && row < mColors.
size() )
   291     return mColors.
size();
   314     case Qt::DisplayRole:
   319           return namedColor.first;
   321           return namedColor.second;
   326     case Qt::TextAlignmentRole:
   327       return QVariant( Qt::AlignLeft | Qt::AlignVCenter );
   340     return flags | Qt::ItemIsDropEnabled;
   349         flags = flags | Qt::ItemIsEditable;
   351       return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled;
   353       return flags | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
   393     case Qt::DisplayRole:
   398           return tr( 
"Color" );
   400           return tr( 
"Label" );
   406     case Qt::TextAlignmentRole:
   410           return QVariant( Qt::AlignHCenter | Qt::AlignVCenter );
   412           return QVariant( Qt::AlignLeft | Qt::AlignVCenter );
   425     return Qt::CopyAction | Qt::MoveAction;
   429     return Qt::CopyAction;
   442   types << 
"text/plain";
   443   types << 
"application/x-color";
   444   types << 
"application/x-colorobject-list";
   452   QModelIndexList::const_iterator indexIt = indexes.
constBegin();
   453   for ( ; indexIt != indexes.constEnd(); ++indexIt )
   455     if (( *indexIt ).column() > 0 )
   458     colorList << qMakePair( mColors[( *indexIt ).row()].
first, mColors[( *indexIt ).row()].second );
   474   if ( action == Qt::IgnoreAction )
   487   if ( droppedColors.
length() == 0 )
   495   for ( ; colorIt != droppedColors.
constEnd(); ++colorIt )
   500     int existingIndex = mColors.
indexOf( color );
   501     if ( existingIndex >= 0 )
   503       if ( existingIndex < beginRow )
   518   for ( ; colorIt != droppedColors.
constEnd(); ++colorIt )
   538   mColors = scheme->
fetchColors( mContext, mBaseColor );
   554   if ( row >= mColors.
count() )
   559   for ( 
int i = row + count - 1; i >= row; --i )
   580   for ( 
int i = row; i < row + count; ++i )
   583     mColors.
insert( i, newColor );
   600   int existingIndex = mColors.
indexOf( newColor );
   601   if ( existingIndex >= 0 )
   630   if ( option.state & QStyle::State_Selected )
   633     if ( option.state & QStyle::State_Active )
   640                                  QPalette::Highlight ) ) );
   651   QRect rect = option.rect;
   653   rect.
setLeft( option.rect.center().x() - 15 );
   655   rect.
adjust( 0, 1, 0, 1 );
   659   painter->
setPen( Qt::NoPen );
   660   if ( color.
alpha() < 255 )
   674 const QPixmap& QgsColorSwatchDelegate::transparentBackground()
 const   678   if ( transpBkgrd.
isNull() )
   688   return QSize( 30, 32 );
   694   if ( event->
type() == QEvent::MouseButtonDblClick )
   696     if ( !index.
model()->
flags( index ).testFlag( Qt::ItemIsEditable ) )
   703     if ( !newColor.isValid() )
   708     return model->
setData( index, newColor, Qt::EditRole );
 bool insertRow(int row, const QModelIndex &parent)
Qt::DropActions supportedDropActions() const override
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override
virtual ~QgsColorSchemeList()
bool exportColorsToGpl(QFile &file)
Export colors to a GPL palette file from the list. 
void addColor(const QColor &color, const QString &label=QString())
Add a color to the list. 
void colorSelected(const QColor &color)
Emitted when a color is selected from the list. 
QgsNamedColorList colors() const
Returns a list of colors shown in the widget. 
void setSelectionMode(QAbstractItemView::SelectionMode mode)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void removeSelection()
Removes any selected colors from the list. 
void setRenderHint(RenderHint hint, bool on)
QColor baseColor() const
Get the base color for the color scheme used by the model. 
Abstract base class for color schemes. 
QString context() const
Get the current color scheme context for the model. 
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
bool removeRow(int row, const QModelIndex &parent)
const T & at(int i) const
void setDragDropMode(DragDropMode behavior)
void setScheme(QgsColorScheme *scheme, const QString &context=QString(), const QColor &baseColor=QColor())
Sets the color scheme to show in the widget. 
Qt::ItemFlags flags(const QModelIndex &index) const override
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
void setScheme(QgsColorScheme *scheme, const QString &context=QString(), const QColor &baseColor=QColor())
Sets the color scheme to show in the list. 
void pasteColors()
Pastes colors from clipboard to the list. 
QgsColorSchemeModel(QgsColorScheme *scheme, const QString &context=QString(), const QColor &baseColor=QColor(), QObject *parent=nullptr)
Constructor. 
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
static QString colorToName(const QColor &color)
Returns a friendly display name for a color. 
void setSelectionBehavior(QAbstractItemView::SelectionBehavior behavior)
bool insertRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
QString tr(const char *sourceText, const char *disambiguation, int n)
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
static QPixmap getThemePixmap(const QString &theName)
Helper to get a theme icon as a pixmap. 
bool importColorsFromGpl(QFile &file)
Import colors from a GPL palette file to the list. 
void mouseReleaseEvent(QMouseEvent *event) override
virtual bool event(QEvent *e)
int indexOf(const T &value, int from) const
QList< T > fromSet(const QSet< T > &set)
void drawRect(const QRectF &rectangle)
const char * name() const
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override
QgsColorScheme * scheme()
Returns the scheme currently selected in the list. 
int count(const T &value) const
void mousePressEvent(QMouseEvent *event) override
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
static QgsNamedColorList importColorsFromGpl(QFile &file, bool &ok, QString &name)
Imports colors from a gpl GIMP palette file. 
void setPen(const QColor &color)
void drawRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
void beginRemoveRows(const QModelIndex &parent, int first, int last)
void setBrush(const QBrush &brush)
virtual QVariant data(const QModelIndex &index, int role) const=0
bool isDirty() const
Returns whether the color scheme list has been modified. 
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex()) override
void setMimeData(QMimeData *src, Mode mode)
virtual void mouseReleaseEvent(QMouseEvent *event)
QModelIndex createIndex(int row, int column, void *ptr) const
QgsColorSwatchDelegate(QWidget *parent=nullptr)
bool saveColorsToScheme()
Saves the current colors shown in the list back to a color scheme, if supported by the color scheme...
void addColor(const QColor &color, const QString &label=QString())
Adds a color to the list. 
void beginInsertRows(const QModelIndex &parent, int first, int last)
virtual bool isEditable() const
Returns whether the color scheme is editable. 
virtual bool event(QEvent *event)
static QColor getColor(const QColor &initialColor, QWidget *parent, const QString &title=QString(), const bool allowAlpha=false)
Return a color selection from a color dialog. 
const QAbstractItemModel * model() const
bool isDirty() const
Returns whether the color scheme model has been modified. 
void copyColors()
Copies colors from the list to the clipboard. 
void insert(int i, const T &value)
static QMimeData * colorListToMimeData(const QgsNamedColorList &colorList, const bool allFormats=true)
Creates mime data from a list of named colors. 
virtual void setModel(QAbstractItemModel *model)
virtual QgsNamedColorList fetchColors(const QString &context=QString(), const QColor &baseColor=QColor())=0
Gets a list of colors from the scheme. 
QStringList mimeTypes() const override
void adjust(int dx1, int dy1, int dx2, int dy2)
QgsColorSchemeList(QWidget *parent=nullptr, QgsColorScheme *scheme=nullptr, const QString &context=QString(), const QColor &baseColor=QColor())
Construct a new color swatch grid. 
virtual QModelIndexList selectedIndexes() const
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
virtual Qt::ItemFlags flags(const QModelIndex &index) const
virtual void mousePressEvent(QMouseEvent *event)
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void keyPressEvent(QKeyEvent *event) override
const QPoint & pos() const
int columnCount(const QModelIndex &parent=QModelIndex()) const override
void setDefaultDropAction(Qt::DropAction dropAction)
const_iterator constEnd() const
const_iterator constBegin() const
void setItemDelegateForColumn(int column, QAbstractItemDelegate *delegate)
virtual void keyPressEvent(QKeyEvent *event)
void setRootIsDecorated(bool show)
void setSize(const QSize &size)
static bool saveColorsToGpl(QFile &file, const QString &paletteName, const QgsNamedColorList &colors)
Exports colors to a gpl GIMP palette file. 
virtual bool setColors(const QgsNamedColorList &colors, const QString &context=QString(), const QColor &baseColor=QColor())
Sets the colors for the scheme. 
A delegate for showing a color swatch in a list. 
QMimeData * mimeData(const QModelIndexList &indexes) const override
void setDropIndicatorShown(bool enable)
void setDragEnabled(bool enable)
A model for colors in a color scheme. 
static QgsNamedColorList colorListFromMimeData(const QMimeData *data)
Attempts to parse mime data as a list of named colors.