/** * \brief Sets the drop properties */ void dropEvent(QDropEvent* event) { // Find the output location drop_index = owner->indexAt(event->pos()); if ( drop_index == -1 ) drop_index = palette.count(); // Gather up the color if ( event->mimeData()->hasColor() ) { drop_color = event->mimeData()->colorData().value<QColor>(); } else if ( event->mimeData()->hasText() ) { drop_color = QColor(event->mimeData()->text()); } drop_overwrite = false; QRectF drop_rect = indexRect(drop_index); if ( drop_index < palette.count() && drop_rect.isValid() ) { // 1 column => vertical style if ( palette.columns() == 1 || forced_columns == 1 ) { // Dragged to the last quarter of the size of the square, add after if ( event->posF().y() >= drop_rect.top() + drop_rect.height() * 3.0 / 4 ) drop_index++; // Dragged to the middle of the square, overwrite existing color else if ( event->posF().x() > drop_rect.top() + drop_rect.height() / 4 && ( event->dropAction() != Qt::MoveAction || event->source() != owner || palette.colorAt(drop_index) == emptyColor ) ) drop_overwrite = true; } else { // Dragged to the last quarter of the size of the square, add after if ( event->posF().x() >= drop_rect.left() + drop_rect.width() * 3.0 / 4 ) drop_index++; // Dragged to the middle of the square, overwrite existing color else if ( event->posF().x() > drop_rect.left() + drop_rect.width() / 4 && ( event->dropAction() != Qt::MoveAction || event->source() != owner || palette.colorAt(drop_index) == emptyColor ) ) drop_overwrite = true; } } owner->update(); }
/** * \brief Number of rows/columns in the palette */ QSize rowcols() { int count = palette.count(); if ( count == 0 ) return QSize(); if ( forced_rows ) return QSize(std::ceil( float(count) / forced_rows ), forced_rows); int columns = palette.columns(); if ( forced_columns ) columns = forced_columns; else if ( columns == 0 ) columns = qMin(palette.count(), owner->width() / color_size.width()); int rows = std::ceil( float(count) / columns ); return QSize(columns, rows); }