@@ -1071,6 +1071,9 @@ namespace AzQtComponents
1071
1071
}
1072
1072
else
1073
1073
{
1074
+ // Store previous selection - will be used if key modifiers are being held.
1075
+ m_previousSelection = selectionModel ()->selection ();
1076
+
1074
1077
// Start the updater to only refresh the selection at regular intervals.
1075
1078
m_selectionUpdater->start (m_selectionUpdateInterval);
1076
1079
@@ -1099,6 +1102,7 @@ namespace AzQtComponents
1099
1102
1100
1103
ClearQueuedMouseEvent ();
1101
1104
1105
+ m_previousSelection.clear ();
1102
1106
m_selectionUpdater->stop ();
1103
1107
m_isDragSelectActive = false ;
1104
1108
@@ -1139,7 +1143,38 @@ namespace AzQtComponents
1139
1143
}
1140
1144
}
1141
1145
1142
- selectionModel ()->select (selection, QItemSelectionModel::ClearAndSelect);
1146
+ switch (QGuiApplication::queryKeyboardModifiers ())
1147
+ {
1148
+ case Qt::ControlModifier:
1149
+ {
1150
+ selection.merge (m_previousSelection, QItemSelectionModel::ToggleCurrent);
1151
+ selectionModel ()->select (selection, QItemSelectionModel::ClearAndSelect);
1152
+ }
1153
+ break ;
1154
+
1155
+ case Qt::ShiftModifier:
1156
+ {
1157
+ // Replicates behavior in Windows explorer.
1158
+ // This will add all newly selected items to the existing selection, but if an item is added
1159
+ // to the selection rect and then removed, it will be removed from the previous selection.
1160
+
1161
+ // Remove new selection from previous selection.
1162
+ m_previousSelection.merge (selection, QItemSelectionModel::Deselect | QItemSelectionModel::Current);
1163
+
1164
+ // Add previous selection to new selection.
1165
+ selection.merge (m_previousSelection, QItemSelectionModel::SelectCurrent);
1166
+
1167
+ // Select both (updated) previous and current selection.
1168
+ selectionModel ()->select (selection, QItemSelectionModel::ClearAndSelect);
1169
+ }
1170
+ break ;
1171
+
1172
+ default :
1173
+ {
1174
+ selectionModel ()->select (selection, QItemSelectionModel::ClearAndSelect);
1175
+ }
1176
+ break ;
1177
+ }
1143
1178
}
1144
1179
1145
1180
void AssetFolderThumbnailView::ClearQueuedMouseEvent ()
@@ -1307,56 +1342,73 @@ namespace AzQtComponents
1307
1342
return QImage ();
1308
1343
}
1309
1344
1310
- QRect rect (6 , 6 , 64 , 64 );
1311
- QImage dragImage (QRect (0 , 0 , 70 , 70 ).size (), QImage::Format_ARGB32_Premultiplied);
1312
- QPainter painter (&dragImage);
1313
-
1314
- painter.setCompositionMode (QPainter::CompositionMode_Source);
1315
- painter.fillRect (dragImage.rect (), Qt::transparent);
1316
- painter.setCompositionMode (QPainter::CompositionMode_SourceOver);
1317
- painter.setOpacity (0 .35f );
1318
- painter.fillRect (rect, QColor (" #222222" ));
1319
- painter.setOpacity (1 .0f );
1345
+ // Define size of rect for asset/folder icons.
1346
+ QRect rect (0 , 9 , 36 , 36 );
1320
1347
1348
+ // Generate a drag image of the dragged element.
1349
+ // We get the configuration of the first item in the list.
1321
1350
auto index = indexList.at (0 );
1351
+ const auto isTopLevel = index.data (static_cast <int >(AssetFolderThumbnailView::Role::IsTopLevel)).value <bool >();
1352
+ const auto & config = isTopLevel ? m_config.rootThumbnail : m_config.childThumbnail ;
1322
1353
1354
+ // Initialize option
1323
1355
QStyleOptionViewItem option;
1324
1356
option.palette = palette ();
1325
1357
option.font = font ();
1326
1358
option.fontMetrics = fontMetrics ();
1327
1359
option.decorationAlignment = Qt::AlignCenter;
1328
1360
option.rect = rect;
1329
1361
1330
- // Generate a drag image of the dragged element.
1331
- const auto isTopLevel = index.data (static_cast <int >(AssetFolderThumbnailView::Role::IsTopLevel)).value <bool >();
1362
+ // Initialize painter from desired output image.
1363
+ QImage dragImage (QRect (0 , 0 , 44 , 56 ).size (), QImage::Format_ARGB32_Premultiplied);
1364
+ QPainter painter (&dragImage);
1365
+ painter.setCompositionMode (QPainter::CompositionMode_Source);
1366
+ painter.fillRect (dragImage.rect (), Qt::transparent);
1367
+ painter.setCompositionMode (QPainter::CompositionMode_SourceOver);
1332
1368
1333
1369
painter.save ();
1334
- painter.setFont (option.font );
1335
1370
1336
- const auto & config = isTopLevel ? m_config.rootThumbnail : m_config.childThumbnail ;
1371
+ // Define border color.
1372
+ if (selectionModel ()->isSelected (index))
1373
+ {
1374
+ painter.setPen (QPen (config.selectedBorderColor , config.selectedBorderThickness ));
1375
+ }
1376
+ else
1377
+ {
1378
+ painter.setPen (QPen (config.borderColor , config.borderThickness ));
1379
+ }
1380
+
1381
+ // Paint additional rectangles under the top one to signify multiple selection.
1382
+ painter.setBrush (QColor (" #555" )); // TODO - move to const members
1383
+
1384
+ if (indexList.size () > 2 )
1385
+ {
1386
+ painter.setOpacity (0 .5f );
1387
+ painter.drawRoundedRect (rect.translated (7 , 7 ), 1 , 1 ); // TODO - move to const members
1388
+ }
1389
+
1390
+ if (indexList.size () > 1 )
1391
+ {
1392
+ painter.setOpacity (1 .0f );
1393
+ painter.drawRoundedRect (rect.translated (3 , 3 ), 1 , 1 ); // TODO - move to const members
1394
+ }
1395
+
1396
+ // Reset opacity to full.
1397
+ painter.setOpacity (1 .0f );
1398
+
1337
1399
1338
- const auto borderRadius = config.borderRadius ;
1339
- const auto padding = 5 ;
1340
1400
1341
1401
const auto thumbnailRect = rect;
1402
+
1403
+ const auto padding = 5 ;
1342
1404
const auto imageRect = thumbnailRect.adjusted (padding, padding, -padding, -padding);
1343
1405
1344
1406
// border
1345
1407
const auto halfBorderThickness = qMax (config.borderThickness , config.selectedBorderThickness ) / 2 ;
1346
1408
const auto borderRect =
1347
1409
QRectF{ thumbnailRect }.adjusted (halfBorderThickness, halfBorderThickness, -halfBorderThickness, -halfBorderThickness);
1348
- QPen borderPen;
1349
- if (option.state & QStyle::State_Selected)
1350
- {
1351
- borderPen = { config.selectedBorderColor , config.selectedBorderThickness };
1352
- }
1353
- else
1354
- {
1355
- borderPen = { config.borderColor , config.borderThickness };
1356
- }
1357
1410
painter.setBrush (config.backgroundColor );
1358
- painter.setPen (borderPen);
1359
- painter.drawRoundedRect (borderRect, borderRadius, borderRadius);
1411
+ painter.drawRoundedRect (borderRect, config.borderRadius , config.borderRadius );
1360
1412
1361
1413
// pixmap
1362
1414
const auto & qVariant = index.data (Qt::DecorationRole);
0 commit comments